blob: 3f627b9818dd8487966490f277e010659ae7c7d8 [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
Tobin Ehlis0788f522015-05-26 16:11:58 -060036#define MEM_TRACKER_TESTS 1
37#define OBJ_TRACKER_TESTS 1
38#define DRAW_STATE_TESTS 1
39#define THREADING_TESTS 1
Chris Forbes9f7ff632015-05-25 11:13:08 +120040#define SHADER_CHECKER_TESTS 1
Mark Lobodzinski209b5292015-09-17 09:44:05 -060041#define DEVICE_LIMITS_TESTS 1
Tobin Ehliscde08892015-09-22 10:11:37 -060042#define IMAGE_TESTS 1
Tobin Ehlis0788f522015-05-26 16:11:58 -060043
Mark Lobodzinski3780e142015-05-14 15:08:13 -050044//--------------------------------------------------------------------------------------
45// Mesh and VertexFormat Data
46//--------------------------------------------------------------------------------------
Karl Schultz6addd812016-02-02 17:17:23 -070047struct Vertex {
48 float posX, posY, posZ, posW; // Position data
49 float r, g, b, a; // Color
Mark Lobodzinski3780e142015-05-14 15:08:13 -050050};
51
Karl Schultz6addd812016-02-02 17:17:23 -070052#define XYZ1(_x_, _y_, _z_) (_x_), (_y_), (_z_), 1.f
Mark Lobodzinski3780e142015-05-14 15:08:13 -050053
54typedef enum _BsoFailSelect {
Karl Schultz6addd812016-02-02 17:17:23 -070055 BsoFailNone = 0x00000000,
56 BsoFailLineWidth = 0x00000001,
57 BsoFailDepthBias = 0x00000002,
58 BsoFailViewport = 0x00000004,
59 BsoFailScissor = 0x00000008,
60 BsoFailBlend = 0x00000010,
61 BsoFailDepthBounds = 0x00000020,
62 BsoFailStencilReadMask = 0x00000040,
63 BsoFailStencilWriteMask = 0x00000080,
64 BsoFailStencilReference = 0x00000100,
Mark Lobodzinski3780e142015-05-14 15:08:13 -050065} BsoFailSelect;
66
67struct vktriangle_vs_uniform {
68 // Must start with MVP
Karl Schultz6addd812016-02-02 17:17:23 -070069 float mvp[4][4];
70 float position[3][4];
71 float color[3][4];
Mark Lobodzinski3780e142015-05-14 15:08:13 -050072};
73
Mark Lobodzinski75a97e62015-06-02 09:41:30 -050074static const char bindStateVertShaderText[] =
Chris Forbes7b342802016-04-07 13:20:10 +120075 "#version 450\n"
Karl Schultz6addd812016-02-02 17:17:23 -070076 "vec2 vertices[3];\n"
77 "out gl_PerVertex {\n"
78 " vec4 gl_Position;\n"
79 "};\n"
80 "void main() {\n"
81 " vertices[0] = vec2(-1.0, -1.0);\n"
82 " vertices[1] = vec2( 1.0, -1.0);\n"
83 " vertices[2] = vec2( 0.0, 1.0);\n"
84 " gl_Position = vec4(vertices[gl_VertexIndex % 3], 0.0, 1.0);\n"
85 "}\n";
Mark Lobodzinski3780e142015-05-14 15:08:13 -050086
Mark Lobodzinski75a97e62015-06-02 09:41:30 -050087static const char bindStateFragShaderText[] =
Chris Forbes7b342802016-04-07 13:20:10 +120088 "#version 450\n"
Karl Schultz6addd812016-02-02 17:17:23 -070089 "\n"
90 "layout(location = 0) out vec4 uFragColor;\n"
91 "void main(){\n"
92 " uFragColor = vec4(0,1,0,1);\n"
93 "}\n";
Mark Lobodzinski3780e142015-05-14 15:08:13 -050094
Karl Schultz6addd812016-02-02 17:17:23 -070095static VKAPI_ATTR VkBool32 VKAPI_CALL
96myDbgFunc(VkFlags msgFlags, VkDebugReportObjectTypeEXT objType,
97 uint64_t srcObject, size_t location, int32_t msgCode,
98 const char *pLayerPrefix, const char *pMsg, void *pUserData);
Tony Barbour300a6082015-04-07 13:44:53 -060099
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600100// ********************************************************
101// ErrorMonitor Usage:
102//
103// Call SetDesiredFailureMsg with a string to be compared against all
104// encountered log messages. Passing NULL will match all log messages.
105// logMsg will return true for skipCall only if msg is matched or NULL.
106//
107// Call DesiredMsgFound to determine if the desired failure message
108// was encountered.
109
Tony Barbour300a6082015-04-07 13:44:53 -0600110class ErrorMonitor {
Karl Schultz6addd812016-02-02 17:17:23 -0700111 public:
112 ErrorMonitor() {
Mike Stroyan4268d1f2015-07-13 14:45:35 -0600113 test_platform_thread_create_mutex(&m_mutex);
114 test_platform_thread_lock_mutex(&m_mutex);
Mark Lobodzinski510e20d2016-02-11 09:26:16 -0700115 m_msgFlags = VK_DEBUG_REPORT_INFORMATION_BIT_EXT;
Karl Schultz6addd812016-02-02 17:17:23 -0700116 m_bailout = NULL;
Mike Stroyan4268d1f2015-07-13 14:45:35 -0600117 test_platform_thread_unlock_mutex(&m_mutex);
Tony Barbour300a6082015-04-07 13:44:53 -0600118 }
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600119
Karl Schultz6addd812016-02-02 17:17:23 -0700120 void SetDesiredFailureMsg(VkFlags msgFlags, const char *msgString) {
Chris Forbes8f36a8a2016-04-07 13:21:07 +1200121 // also discard all collected messages to this point
Mike Stroyan4268d1f2015-07-13 14:45:35 -0600122 test_platform_thread_lock_mutex(&m_mutex);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600123 m_failureMsg.clear();
124 m_otherMsgs.clear();
125 m_desiredMsg = msgString;
Karl Schultz6addd812016-02-02 17:17:23 -0700126 m_msgFound = VK_FALSE;
127 m_msgFlags = msgFlags;
Mike Stroyan4268d1f2015-07-13 14:45:35 -0600128 test_platform_thread_unlock_mutex(&m_mutex);
Tony Barbour300a6082015-04-07 13:44:53 -0600129 }
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600130
Karl Schultz6addd812016-02-02 17:17:23 -0700131 VkBool32 CheckForDesiredMsg(VkFlags msgFlags, const char *msgString) {
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600132 VkBool32 result = VK_FALSE;
Mike Stroyan4268d1f2015-07-13 14:45:35 -0600133 test_platform_thread_lock_mutex(&m_mutex);
Mike Stroyanaccf7692015-05-12 16:00:45 -0600134 if (m_bailout != NULL) {
135 *m_bailout = true;
136 }
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600137 string errorString(msgString);
138 if (msgFlags & m_msgFlags) {
139 if (errorString.find(m_desiredMsg) != string::npos) {
Chris Forbesc7b8ad72016-04-04 18:50:38 +1200140 if (m_msgFound) { /* if multiple matches, don't lose all but the last! */
141 m_otherMsgs.push_back(m_failureMsg);
142 }
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600143 m_failureMsg = errorString;
Karl Schultz6addd812016-02-02 17:17:23 -0700144 m_msgFound = VK_TRUE;
145 result = VK_TRUE;
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600146 } else {
147 m_otherMsgs.push_back(errorString);
148 }
149 }
Mike Stroyan4268d1f2015-07-13 14:45:35 -0600150 test_platform_thread_unlock_mutex(&m_mutex);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600151 return result;
Mike Stroyanaccf7692015-05-12 16:00:45 -0600152 }
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600153
Karl Schultz6addd812016-02-02 17:17:23 -0700154 vector<string> GetOtherFailureMsgs(void) { return m_otherMsgs; }
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600155
Karl Schultz6addd812016-02-02 17:17:23 -0700156 string GetFailureMsg(void) { return m_failureMsg; }
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600157
Karl Schultz6addd812016-02-02 17:17:23 -0700158 VkBool32 DesiredMsgFound(void) { return m_msgFound; }
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600159
Karl Schultz6addd812016-02-02 17:17:23 -0700160 void SetBailout(bool *bailout) { m_bailout = bailout; }
Tony Barbour300a6082015-04-07 13:44:53 -0600161
Karl Schultz6addd812016-02-02 17:17:23 -0700162 void DumpFailureMsgs(void) {
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600163 vector<string> otherMsgs = GetOtherFailureMsgs();
164 cout << "Other error messages logged for this test were:" << endl;
165 for (auto iter = otherMsgs.begin(); iter != otherMsgs.end(); iter++) {
166 cout << " " << *iter << endl;
167 }
168 }
169
Chris Forbes8f36a8a2016-04-07 13:21:07 +1200170 /* helpers */
171
172 void ExpectSuccess() {
173 // match anything
174 SetDesiredFailureMsg(~0u, "");
175 }
176
177 void VerifyFound() {
178 // Not seeing the desired message is a failure. /Before/ throwing, dump
179 // any other messages.
180 if (!DesiredMsgFound()) {
181 DumpFailureMsgs();
182 FAIL() << "Did not receive expected error '" << m_desiredMsg << "'";
183 }
184 }
185
186 void VerifyNotFound() {
187 // ExpectSuccess() configured us to match anything. Any error is a
188 // failure.
189 if (DesiredMsgFound()) {
190 DumpFailureMsgs();
191 FAIL() << "Expected to succeed but got error: " << GetFailureMsg();
192 }
193 }
194
Karl Schultz6addd812016-02-02 17:17:23 -0700195 private:
196 VkFlags m_msgFlags;
197 string m_desiredMsg;
198 string m_failureMsg;
199 vector<string> m_otherMsgs;
Mike Stroyan4268d1f2015-07-13 14:45:35 -0600200 test_platform_thread_mutex m_mutex;
Karl Schultz6addd812016-02-02 17:17:23 -0700201 bool *m_bailout;
202 VkBool32 m_msgFound;
Tony Barbour300a6082015-04-07 13:44:53 -0600203};
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500204
Karl Schultz6addd812016-02-02 17:17:23 -0700205static VKAPI_ATTR VkBool32 VKAPI_CALL
206myDbgFunc(VkFlags msgFlags, VkDebugReportObjectTypeEXT objType,
207 uint64_t srcObject, size_t location, int32_t msgCode,
208 const char *pLayerPrefix, const char *pMsg, void *pUserData) {
209 if (msgFlags &
Mark Lobodzinski510e20d2016-02-11 09:26:16 -0700210 (VK_DEBUG_REPORT_WARNING_BIT_EXT | VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT |
Karl Schultz6addd812016-02-02 17:17:23 -0700211 VK_DEBUG_REPORT_ERROR_BIT_EXT)) {
Tony Barbour0b4d9562015-04-09 10:48:04 -0600212 ErrorMonitor *errMonitor = (ErrorMonitor *)pUserData;
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600213 return errMonitor->CheckForDesiredMsg(msgFlags, pMsg);
Tony Barbour0b4d9562015-04-09 10:48:04 -0600214 }
Courtney Goeltzenleuchter06640832015-09-04 13:52:24 -0600215 return false;
Tony Barbour300a6082015-04-07 13:44:53 -0600216}
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500217
Karl Schultz6addd812016-02-02 17:17:23 -0700218class VkLayerTest : public VkRenderFramework {
219 public:
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800220 VkResult BeginCommandBuffer(VkCommandBufferObj &commandBuffer);
221 VkResult EndCommandBuffer(VkCommandBufferObj &commandBuffer);
Karl Schultz6addd812016-02-02 17:17:23 -0700222 void VKTriangleTest(const char *vertShaderText, const char *fragShaderText,
223 BsoFailSelect failMask);
224 void GenericDrawPreparation(VkCommandBufferObj *commandBuffer,
225 VkPipelineObj &pipelineobj,
226 VkDescriptorSetObj &descriptorSet,
227 BsoFailSelect failMask);
228 void GenericDrawPreparation(VkPipelineObj &pipelineobj,
229 VkDescriptorSetObj &descriptorSet,
230 BsoFailSelect failMask) {
231 GenericDrawPreparation(m_commandBuffer, pipelineobj, descriptorSet,
232 failMask);
233 }
Tony Barbour300a6082015-04-07 13:44:53 -0600234
Tony Barbourfe3351b2015-07-28 10:17:20 -0600235 /* Convenience functions that use built-in command buffer */
Karl Schultz6addd812016-02-02 17:17:23 -0700236 VkResult BeginCommandBuffer() {
237 return BeginCommandBuffer(*m_commandBuffer);
238 }
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800239 VkResult EndCommandBuffer() { return EndCommandBuffer(*m_commandBuffer); }
Karl Schultz6addd812016-02-02 17:17:23 -0700240 void Draw(uint32_t vertexCount, uint32_t instanceCount,
241 uint32_t firstVertex, uint32_t firstInstance) {
242 m_commandBuffer->Draw(vertexCount, instanceCount, firstVertex,
243 firstInstance);
244 }
245 void DrawIndexed(uint32_t indexCount, uint32_t instanceCount,
246 uint32_t firstIndex, int32_t vertexOffset,
247 uint32_t firstInstance) {
248 m_commandBuffer->DrawIndexed(indexCount, instanceCount, firstIndex,
249 vertexOffset, firstInstance);
250 }
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800251 void QueueCommandBuffer() { m_commandBuffer->QueueCommandBuffer(); }
Karl Schultz6addd812016-02-02 17:17:23 -0700252 void QueueCommandBuffer(const VkFence &fence) {
253 m_commandBuffer->QueueCommandBuffer(fence);
254 }
255 void BindVertexBuffer(VkConstantBufferObj *vertexBuffer,
256 VkDeviceSize offset, uint32_t binding) {
257 m_commandBuffer->BindVertexBuffer(vertexBuffer, offset, binding);
258 }
259 void BindIndexBuffer(VkIndexBufferObj *indexBuffer, VkDeviceSize offset) {
260 m_commandBuffer->BindIndexBuffer(indexBuffer, offset);
261 }
262
263 protected:
264 ErrorMonitor *m_errorMonitor;
Tony Barbour300a6082015-04-07 13:44:53 -0600265
266 virtual void SetUp() {
Courtney Goeltzenleuchtercd69eee2015-07-06 09:10:47 -0600267 std::vector<const char *> instance_layer_names;
268 std::vector<const char *> device_layer_names;
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -0600269 std::vector<const char *> instance_extension_names;
270 std::vector<const char *> device_extension_names;
Tony Barbour3fdff9e2015-04-23 12:55:36 -0600271
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -0700272 instance_extension_names.push_back(VK_EXT_DEBUG_REPORT_EXTENSION_NAME);
Courtney Goeltzenleuchterc2b06fe2015-06-16 15:59:11 -0600273 /*
274 * Since CreateDbgMsgCallback is an instance level extension call
275 * any extension / layer that utilizes that feature also needs
276 * to be enabled at create instance time.
277 */
Karl Schultz6addd812016-02-02 17:17:23 -0700278 // Use Threading layer first to protect others from
279 // ThreadCommandBufferCollision test
Courtney Goeltzenleuchter76885322016-02-06 17:11:22 -0700280 instance_layer_names.push_back("VK_LAYER_GOOGLE_threading");
Tobin Ehlis24aab042016-03-24 10:54:18 -0600281 instance_layer_names.push_back("VK_LAYER_LUNARG_parameter_validation");
Michael Lentine03107b42015-12-11 10:49:51 -0800282 instance_layer_names.push_back("VK_LAYER_LUNARG_object_tracker");
Tobin Ehlisc96f8062016-03-09 16:12:48 -0700283 instance_layer_names.push_back("VK_LAYER_LUNARG_core_validation");
Michael Lentine03107b42015-12-11 10:49:51 -0800284 instance_layer_names.push_back("VK_LAYER_LUNARG_device_limits");
285 instance_layer_names.push_back("VK_LAYER_LUNARG_image");
Dustin Graveseaa78cd2016-01-26 16:30:22 -0700286 instance_layer_names.push_back("VK_LAYER_GOOGLE_unique_objects");
Courtney Goeltzenleuchterd971b612015-06-17 20:51:59 -0600287
Courtney Goeltzenleuchter76885322016-02-06 17:11:22 -0700288 device_layer_names.push_back("VK_LAYER_GOOGLE_threading");
Tobin Ehlis24aab042016-03-24 10:54:18 -0600289 device_layer_names.push_back("VK_LAYER_LUNARG_parameter_validation");
Michael Lentine03107b42015-12-11 10:49:51 -0800290 device_layer_names.push_back("VK_LAYER_LUNARG_object_tracker");
Tobin Ehlisc96f8062016-03-09 16:12:48 -0700291 device_layer_names.push_back("VK_LAYER_LUNARG_core_validation");
Michael Lentine03107b42015-12-11 10:49:51 -0800292 device_layer_names.push_back("VK_LAYER_LUNARG_device_limits");
293 device_layer_names.push_back("VK_LAYER_LUNARG_image");
Dustin Graveseaa78cd2016-01-26 16:30:22 -0700294 device_layer_names.push_back("VK_LAYER_GOOGLE_unique_objects");
Tony Barbour300a6082015-04-07 13:44:53 -0600295
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600296 this->app_info.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO;
Tony Barbour300a6082015-04-07 13:44:53 -0600297 this->app_info.pNext = NULL;
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800298 this->app_info.pApplicationName = "layer_tests";
299 this->app_info.applicationVersion = 1;
Tony Barbour300a6082015-04-07 13:44:53 -0600300 this->app_info.pEngineName = "unittest";
301 this->app_info.engineVersion = 1;
Jon Ashburnc5012ff2016-03-22 13:57:46 -0600302 this->app_info.apiVersion = VK_API_VERSION_1_0;
Tony Barbour300a6082015-04-07 13:44:53 -0600303
Tony Barbour15524c32015-04-29 17:34:29 -0600304 m_errorMonitor = new ErrorMonitor;
Courtney Goeltzenleuchtercd69eee2015-07-06 09:10:47 -0600305 InitFramework(instance_layer_names, device_layer_names,
306 instance_extension_names, device_extension_names,
307 myDbgFunc, m_errorMonitor);
Tony Barbour300a6082015-04-07 13:44:53 -0600308 }
309
310 virtual void TearDown() {
311 // Clean up resources before we reset
Tony Barbour300a6082015-04-07 13:44:53 -0600312 ShutdownFramework();
Tony Barbour0b4d9562015-04-09 10:48:04 -0600313 delete m_errorMonitor;
Tony Barbour300a6082015-04-07 13:44:53 -0600314 }
315};
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500316
Karl Schultz6addd812016-02-02 17:17:23 -0700317VkResult VkLayerTest::BeginCommandBuffer(VkCommandBufferObj &commandBuffer) {
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600318 VkResult result;
Tony Barbour300a6082015-04-07 13:44:53 -0600319
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800320 result = commandBuffer.BeginCommandBuffer();
Tony Barbour300a6082015-04-07 13:44:53 -0600321
322 /*
323 * For render test all drawing happens in a single render pass
324 * on a single command buffer.
325 */
Chris Forbes76a5eeb2015-06-16 14:05:59 +1200326 if (VK_SUCCESS == result && renderPass()) {
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800327 commandBuffer.BeginRenderPass(renderPassBeginInfo());
Tony Barbour300a6082015-04-07 13:44:53 -0600328 }
329
330 return result;
331}
332
Karl Schultz6addd812016-02-02 17:17:23 -0700333VkResult VkLayerTest::EndCommandBuffer(VkCommandBufferObj &commandBuffer) {
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600334 VkResult result;
Tony Barbour300a6082015-04-07 13:44:53 -0600335
Chris Forbes76a5eeb2015-06-16 14:05:59 +1200336 if (renderPass()) {
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800337 commandBuffer.EndRenderPass();
Chris Forbes76a5eeb2015-06-16 14:05:59 +1200338 }
Tony Barbour300a6082015-04-07 13:44:53 -0600339
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800340 result = commandBuffer.EndCommandBuffer();
Tony Barbour300a6082015-04-07 13:44:53 -0600341
342 return result;
343}
344
Karl Schultz6addd812016-02-02 17:17:23 -0700345void VkLayerTest::VKTriangleTest(const char *vertShaderText,
346 const char *fragShaderText,
347 BsoFailSelect failMask) {
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500348 // Create identity matrix
349 int i;
350 struct vktriangle_vs_uniform data;
351
352 glm::mat4 Projection = glm::mat4(1.0f);
Karl Schultz6addd812016-02-02 17:17:23 -0700353 glm::mat4 View = glm::mat4(1.0f);
354 glm::mat4 Model = glm::mat4(1.0f);
355 glm::mat4 MVP = Projection * View * Model;
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500356 const int matrixSize = sizeof(MVP);
Karl Schultz6addd812016-02-02 17:17:23 -0700357 const int bufSize = sizeof(vktriangle_vs_uniform) / sizeof(float);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500358
359 memcpy(&data.mvp, &MVP[0][0], matrixSize);
360
Karl Schultz6addd812016-02-02 17:17:23 -0700361 static const Vertex tri_data[] = {
362 {XYZ1(-1, -1, 0), XYZ1(1.f, 0.f, 0.f)},
363 {XYZ1(1, -1, 0), XYZ1(0.f, 1.f, 0.f)},
364 {XYZ1(0, 1, 0), XYZ1(0.f, 0.f, 1.f)},
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500365 };
366
Karl Schultz6addd812016-02-02 17:17:23 -0700367 for (i = 0; i < 3; i++) {
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500368 data.position[i][0] = tri_data[i].posX;
369 data.position[i][1] = tri_data[i].posY;
370 data.position[i][2] = tri_data[i].posZ;
371 data.position[i][3] = tri_data[i].posW;
Karl Schultz6addd812016-02-02 17:17:23 -0700372 data.color[i][0] = tri_data[i].r;
373 data.color[i][1] = tri_data[i].g;
374 data.color[i][2] = tri_data[i].b;
375 data.color[i][3] = tri_data[i].a;
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500376 }
377
378 ASSERT_NO_FATAL_FAILURE(InitState());
379 ASSERT_NO_FATAL_FAILURE(InitViewport());
380
Karl Schultz6addd812016-02-02 17:17:23 -0700381 VkConstantBufferObj constantBuffer(m_device, bufSize * 2, sizeof(float),
382 (const void *)&data);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500383
Karl Schultz6addd812016-02-02 17:17:23 -0700384 VkShaderObj vs(m_device, vertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
385 VkShaderObj ps(m_device, fragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT,
386 this);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500387
388 VkPipelineObj pipelineobj(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +0800389 pipelineobj.AddColorAttachment();
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500390 pipelineobj.AddShader(&vs);
391 pipelineobj.AddShader(&ps);
Courtney Goeltzenleuchter507ba972015-09-30 16:16:57 -0600392 if (failMask & BsoFailLineWidth) {
393 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_LINE_WIDTH);
Tobin Ehlis7a1d2352016-03-28 11:18:19 -0600394 VkPipelineInputAssemblyStateCreateInfo ia_state = {};
395 ia_state.sType =
396 VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
397 ia_state.topology = VK_PRIMITIVE_TOPOLOGY_LINE_LIST;
398 pipelineobj.SetInputAssembly(&ia_state);
Courtney Goeltzenleuchter507ba972015-09-30 16:16:57 -0600399 }
400 if (failMask & BsoFailDepthBias) {
401 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_DEPTH_BIAS);
Tobin Ehlis7a1d2352016-03-28 11:18:19 -0600402 VkPipelineRasterizationStateCreateInfo rs_state = {};
403 rs_state.sType =
404 VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
405 rs_state.depthBiasEnable = VK_TRUE;
Mark Young7394fdd2016-03-31 14:56:43 -0600406 rs_state.lineWidth = 1.0f;
Tobin Ehlis7a1d2352016-03-28 11:18:19 -0600407 pipelineobj.SetRasterization(&rs_state);
Courtney Goeltzenleuchter507ba972015-09-30 16:16:57 -0600408 }
Karl Schultz6addd812016-02-02 17:17:23 -0700409 // Viewport and scissors must stay in synch or other errors will occur than
410 // the ones we want
Courtney Goeltzenleuchter507ba972015-09-30 16:16:57 -0600411 if (failMask & BsoFailViewport) {
412 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_VIEWPORT);
Tobin Ehlisd332f282015-10-02 11:00:56 -0600413 m_viewports.clear();
414 m_scissors.clear();
Courtney Goeltzenleuchter507ba972015-09-30 16:16:57 -0600415 }
416 if (failMask & BsoFailScissor) {
417 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_SCISSOR);
Tobin Ehlisd332f282015-10-02 11:00:56 -0600418 m_scissors.clear();
419 m_viewports.clear();
Courtney Goeltzenleuchter507ba972015-09-30 16:16:57 -0600420 }
421 if (failMask & BsoFailBlend) {
422 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_BLEND_CONSTANTS);
Tobin Ehlis7a1d2352016-03-28 11:18:19 -0600423 VkPipelineColorBlendAttachmentState att_state = {};
424 att_state.dstAlphaBlendFactor = VK_BLEND_FACTOR_CONSTANT_COLOR;
425 att_state.blendEnable = VK_TRUE;
426 pipelineobj.AddColorAttachment(0, &att_state);
Courtney Goeltzenleuchter507ba972015-09-30 16:16:57 -0600427 }
428 if (failMask & BsoFailDepthBounds) {
429 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_DEPTH_BOUNDS);
430 }
431 if (failMask & BsoFailStencilReadMask) {
432 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_STENCIL_COMPARE_MASK);
433 }
434 if (failMask & BsoFailStencilWriteMask) {
435 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_STENCIL_WRITE_MASK);
436 }
437 if (failMask & BsoFailStencilReference) {
438 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_STENCIL_REFERENCE);
439 }
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500440
441 VkDescriptorSetObj descriptorSet(m_device);
Karl Schultz6addd812016-02-02 17:17:23 -0700442 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER,
443 constantBuffer);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500444
445 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbourfe3351b2015-07-28 10:17:20 -0600446 ASSERT_VK_SUCCESS(BeginCommandBuffer());
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500447
Tony Barbourfe3351b2015-07-28 10:17:20 -0600448 GenericDrawPreparation(pipelineobj, descriptorSet, failMask);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500449
450 // render triangle
Courtney Goeltzenleuchter08c26372015-09-23 12:31:50 -0600451 Draw(3, 1, 0, 0);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500452
453 // finalize recording of the command buffer
Tony Barbourfe3351b2015-07-28 10:17:20 -0600454 EndCommandBuffer();
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500455
Tony Barbourfe3351b2015-07-28 10:17:20 -0600456 QueueCommandBuffer();
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500457}
458
Karl Schultz6addd812016-02-02 17:17:23 -0700459void VkLayerTest::GenericDrawPreparation(VkCommandBufferObj *commandBuffer,
460 VkPipelineObj &pipelineobj,
461 VkDescriptorSetObj &descriptorSet,
462 BsoFailSelect failMask) {
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500463 if (m_depthStencil->Initialized()) {
Karl Schultz6addd812016-02-02 17:17:23 -0700464 commandBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color,
465 m_stencil_clear_color, m_depthStencil);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500466 } else {
Karl Schultz6addd812016-02-02 17:17:23 -0700467 commandBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color,
468 m_stencil_clear_color, NULL);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500469 }
470
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800471 commandBuffer->PrepareAttachments();
Karl Schultz6addd812016-02-02 17:17:23 -0700472 // Make sure depthWriteEnable is set so that Depth fail test will work
473 // correctly
474 // Make sure stencilTestEnable is set so that Stencil fail test will work
475 // correctly
Tony Barboureb254902015-07-15 12:50:33 -0600476 VkStencilOpState stencil = {};
Chia-I Wu1b99bb22015-10-27 19:25:11 +0800477 stencil.failOp = VK_STENCIL_OP_KEEP;
478 stencil.passOp = VK_STENCIL_OP_KEEP;
479 stencil.depthFailOp = VK_STENCIL_OP_KEEP;
480 stencil.compareOp = VK_COMPARE_OP_NEVER;
Tony Barboureb254902015-07-15 12:50:33 -0600481
482 VkPipelineDepthStencilStateCreateInfo ds_ci = {};
483 ds_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DEPTH_STENCIL_STATE_CREATE_INFO;
Courtney Goeltzenleuchter507ba972015-09-30 16:16:57 -0600484 ds_ci.pNext = NULL;
485 ds_ci.depthTestEnable = VK_FALSE;
486 ds_ci.depthWriteEnable = VK_TRUE;
487 ds_ci.depthCompareOp = VK_COMPARE_OP_NEVER;
488 ds_ci.depthBoundsTestEnable = VK_FALSE;
Tobin Ehlis7a1d2352016-03-28 11:18:19 -0600489 if (failMask & BsoFailDepthBounds) {
490 ds_ci.depthBoundsTestEnable = VK_TRUE;
491 }
Courtney Goeltzenleuchter507ba972015-09-30 16:16:57 -0600492 ds_ci.stencilTestEnable = VK_TRUE;
493 ds_ci.front = stencil;
494 ds_ci.back = stencil;
Tony Barboureb254902015-07-15 12:50:33 -0600495
Tobin Ehlis4bf96d12015-06-25 11:58:41 -0600496 pipelineobj.SetDepthStencil(&ds_ci);
Tobin Ehlisd332f282015-10-02 11:00:56 -0600497 pipelineobj.SetViewport(m_viewports);
498 pipelineobj.SetScissor(m_scissors);
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800499 descriptorSet.CreateVKDescriptorSet(commandBuffer);
Karl Schultz6addd812016-02-02 17:17:23 -0700500 VkResult err = pipelineobj.CreateVKPipeline(
501 descriptorSet.GetPipelineLayout(), renderPass());
Cody Northrop29a08f22015-08-27 10:20:35 -0600502 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800503 commandBuffer->BindPipeline(pipelineobj);
504 commandBuffer->BindDescriptorSet(descriptorSet);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500505}
506
507// ********************************************************************************************************************
508// ********************************************************************************************************************
509// ********************************************************************************************************************
510// ********************************************************************************************************************
Tobin Ehlis0788f522015-05-26 16:11:58 -0600511#if MEM_TRACKER_TESTS
Tobin Ehlis8fab6562015-12-01 09:57:09 -0700512#if 0
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800513TEST_F(VkLayerTest, CallResetCommandBufferBeforeCompletion)
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -0500514{
515 vk_testing::Fence testFence;
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -0500516 VkFenceCreateInfo fenceInfo = {};
517 fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
518 fenceInfo.pNext = NULL;
519 fenceInfo.flags = 0;
520
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -0700521 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Resetting CB");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600522
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -0500523 ASSERT_NO_FATAL_FAILURE(InitState());
Tony Barbourc1eb1a52015-07-20 13:00:10 -0600524
525 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
526 vk_testing::Buffer buffer;
527 buffer.init_as_dst(*m_device, (VkDeviceSize)20, reqs);
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -0500528
Tony Barbourfe3351b2015-07-28 10:17:20 -0600529 BeginCommandBuffer();
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800530 m_commandBuffer->FillBuffer(buffer.handle(), 0, 4, 0x11111111);
Tony Barbourfe3351b2015-07-28 10:17:20 -0600531 EndCommandBuffer();
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -0500532
533 testFence.init(*m_device, fenceInfo);
534
535 // Bypass framework since it does the waits automatically
536 VkResult err = VK_SUCCESS;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -0600537 VkSubmitInfo submit_info;
Chia-I Wuf9be13c2015-10-26 20:37:06 +0800538 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
539 submit_info.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +0800540 submit_info.waitSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -0600541 submit_info.pWaitSemaphores = NULL;
Jon Ashburn7f9716c2015-12-30 16:42:50 -0700542 submit_info.pWaitDstStageMask = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +0800543 submit_info.commandBufferCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800544 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Chia-I Wud50a7d72015-10-26 20:48:51 +0800545 submit_info.signalSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -0600546 submit_info.pSignalSemaphores = NULL;
Courtney Goeltzenleuchter646b9072015-10-20 18:04:07 -0600547
548 err = vkQueueSubmit( m_device->m_queue, 1, &submit_info, testFence.handle());
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -0500549 ASSERT_VK_SUCCESS( err );
550
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -0500551 // Introduce failure by calling begin again before checking fence
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800552 vkResetCommandBuffer(m_commandBuffer->handle(), 0);
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -0500553
Chris Forbes8f36a8a2016-04-07 13:21:07 +1200554 m_errorMonitor->VerifyFound();
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -0500555}
556
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800557TEST_F(VkLayerTest, CallBeginCommandBufferBeforeCompletion)
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -0500558{
559 vk_testing::Fence testFence;
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -0500560 VkFenceCreateInfo fenceInfo = {};
561 fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
562 fenceInfo.pNext = NULL;
563 fenceInfo.flags = 0;
564
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -0700565 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Calling vkBeginCommandBuffer() on active CB");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600566
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -0500567 ASSERT_NO_FATAL_FAILURE(InitState());
568 ASSERT_NO_FATAL_FAILURE(InitViewport());
569 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
570
Tony Barbourfe3351b2015-07-28 10:17:20 -0600571 BeginCommandBuffer();
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800572 m_commandBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color, m_stencil_clear_color, NULL);
Tony Barbourfe3351b2015-07-28 10:17:20 -0600573 EndCommandBuffer();
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -0500574
575 testFence.init(*m_device, fenceInfo);
576
577 // Bypass framework since it does the waits automatically
578 VkResult err = VK_SUCCESS;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -0600579 VkSubmitInfo submit_info;
Chia-I Wuf9be13c2015-10-26 20:37:06 +0800580 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
581 submit_info.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +0800582 submit_info.waitSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -0600583 submit_info.pWaitSemaphores = NULL;
Jon Ashburn7f9716c2015-12-30 16:42:50 -0700584 submit_info.pWaitDstStageMask = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +0800585 submit_info.commandBufferCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800586 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Chia-I Wud50a7d72015-10-26 20:48:51 +0800587 submit_info.signalSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -0600588 submit_info.pSignalSemaphores = NULL;
Courtney Goeltzenleuchter646b9072015-10-20 18:04:07 -0600589
590 err = vkQueueSubmit( m_device->m_queue, 1, &submit_info, testFence.handle());
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -0500591 ASSERT_VK_SUCCESS( err );
592
Jon Ashburnf19916e2016-01-11 13:12:43 -0700593 VkCommandBufferInheritanceInfo hinfo = {};
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800594 VkCommandBufferBeginInfo info = {};
595 info.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT;
596 info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
Mark Lobodzinski5fcc4212015-09-14 17:43:42 -0600597 info.renderPass = VK_NULL_HANDLE;
598 info.subpass = 0;
599 info.framebuffer = VK_NULL_HANDLE;
Chia-I Wub8d47ae2015-11-11 10:18:12 +0800600 info.occlusionQueryEnable = VK_FALSE;
601 info.queryFlags = 0;
602 info.pipelineStatistics = 0;
Mark Lobodzinski5fcc4212015-09-14 17:43:42 -0600603
604 // Introduce failure by calling BCB again before checking fence
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800605 vkBeginCommandBuffer(m_commandBuffer->handle(), &info);
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -0500606
Chris Forbes8f36a8a2016-04-07 13:21:07 +1200607 m_errorMonitor->VerifyFound();
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -0500608}
Tobin Ehlis8fab6562015-12-01 09:57:09 -0700609#endif
Chris Forbes8f36a8a2016-04-07 13:21:07 +1200610
Karl Schultz6addd812016-02-02 17:17:23 -0700611TEST_F(VkLayerTest, MapMemWithoutHostVisibleBit) {
612 VkResult err;
613 bool pass;
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500614
Karl Schultz6addd812016-02-02 17:17:23 -0700615 m_errorMonitor->SetDesiredFailureMsg(
616 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600617 "Mapping Memory without VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT");
618
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500619 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500620
621 // Create an image, allocate memory, free it, and then try to bind it
Karl Schultz6addd812016-02-02 17:17:23 -0700622 VkImage image;
623 VkDeviceMemory mem;
624 VkMemoryRequirements mem_reqs;
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500625
Karl Schultz6addd812016-02-02 17:17:23 -0700626 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
627 const int32_t tex_width = 32;
628 const int32_t tex_height = 32;
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500629
Tony Barboureb254902015-07-15 12:50:33 -0600630 VkImageCreateInfo image_create_info = {};
631 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
Karl Schultz6addd812016-02-02 17:17:23 -0700632 image_create_info.pNext = NULL;
633 image_create_info.imageType = VK_IMAGE_TYPE_2D;
634 image_create_info.format = tex_format;
635 image_create_info.extent.width = tex_width;
636 image_create_info.extent.height = tex_height;
637 image_create_info.extent.depth = 1;
638 image_create_info.mipLevels = 1;
639 image_create_info.arrayLayers = 1;
640 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
641 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
642 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
643 image_create_info.flags = 0;
Mark Lobodzinski5fcc4212015-09-14 17:43:42 -0600644
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800645 VkMemoryAllocateInfo mem_alloc = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +0800646 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
Karl Schultz6addd812016-02-02 17:17:23 -0700647 mem_alloc.pNext = NULL;
648 mem_alloc.allocationSize = 0;
649 // Introduce failure, do NOT set memProps to
650 // VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT
651 mem_alloc.memoryTypeIndex = 1;
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500652
Chia-I Wuf7458c52015-10-26 21:10:41 +0800653 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500654 ASSERT_VK_SUCCESS(err);
655
Karl Schultz6addd812016-02-02 17:17:23 -0700656 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500657
Mark Lobodzinski23065352015-05-29 09:32:35 -0500658 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500659
Karl Schultz6addd812016-02-02 17:17:23 -0700660 pass =
661 m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0,
662 VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT);
663 if (!pass) { // If we can't find any unmappable memory this test doesn't
664 // make sense
Chia-I Wuf7458c52015-10-26 21:10:41 +0800665 vkDestroyImage(m_device->device(), image, NULL);
Tony Barbour02fdc7d2015-08-04 16:13:01 -0600666 return;
Mike Stroyand1c84a52015-08-18 14:40:24 -0600667 }
Mike Stroyan713b2d72015-08-04 10:49:29 -0600668
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500669 // allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800670 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500671 ASSERT_VK_SUCCESS(err);
672
673 // Try to bind free memory that has been freed
Tony Barbour67e99152015-07-10 14:10:27 -0600674 err = vkBindImageMemory(m_device->device(), image, mem, 0);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500675 ASSERT_VK_SUCCESS(err);
676
677 // Map memory as if to initialize the image
678 void *mappedAddress = NULL;
Karl Schultz6addd812016-02-02 17:17:23 -0700679 err = vkMapMemory(m_device->device(), mem, 0, VK_WHOLE_SIZE, 0,
680 &mappedAddress);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500681
Chris Forbes8f36a8a2016-04-07 13:21:07 +1200682 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -0600683
Chia-I Wuf7458c52015-10-26 21:10:41 +0800684 vkDestroyImage(m_device->device(), image, NULL);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500685}
686
Karl Schultz6addd812016-02-02 17:17:23 -0700687TEST_F(VkLayerTest, RebindMemory) {
688 VkResult err;
689 bool pass;
Mark Lobodzinski944aab12015-06-05 13:59:04 -0500690
Karl Schultz6addd812016-02-02 17:17:23 -0700691 m_errorMonitor->SetDesiredFailureMsg(
692 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600693 "which has already been bound to mem object");
694
Mark Lobodzinski944aab12015-06-05 13:59:04 -0500695 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski944aab12015-06-05 13:59:04 -0500696
697 // Create an image, allocate memory, free it, and then try to bind it
Karl Schultz6addd812016-02-02 17:17:23 -0700698 VkImage image;
699 VkDeviceMemory mem1;
700 VkDeviceMemory mem2;
701 VkMemoryRequirements mem_reqs;
Mark Lobodzinski944aab12015-06-05 13:59:04 -0500702
Karl Schultz6addd812016-02-02 17:17:23 -0700703 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
704 const int32_t tex_width = 32;
705 const int32_t tex_height = 32;
Mark Lobodzinski944aab12015-06-05 13:59:04 -0500706
Tony Barboureb254902015-07-15 12:50:33 -0600707 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -0700708 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
709 image_create_info.pNext = NULL;
710 image_create_info.imageType = VK_IMAGE_TYPE_2D;
711 image_create_info.format = tex_format;
712 image_create_info.extent.width = tex_width;
713 image_create_info.extent.height = tex_height;
714 image_create_info.extent.depth = 1;
715 image_create_info.mipLevels = 1;
716 image_create_info.arrayLayers = 1;
717 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
718 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
719 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
720 image_create_info.flags = 0;
Mark Lobodzinski944aab12015-06-05 13:59:04 -0500721
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800722 VkMemoryAllocateInfo mem_alloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -0700723 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
724 mem_alloc.pNext = NULL;
725 mem_alloc.allocationSize = 0;
726 mem_alloc.memoryTypeIndex = 0;
Tony Barboureb254902015-07-15 12:50:33 -0600727
Karl Schultz6addd812016-02-02 17:17:23 -0700728 // Introduce failure, do NOT set memProps to
729 // VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT
Tony Barboureb254902015-07-15 12:50:33 -0600730 mem_alloc.memoryTypeIndex = 1;
Chia-I Wuf7458c52015-10-26 21:10:41 +0800731 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Mark Lobodzinski944aab12015-06-05 13:59:04 -0500732 ASSERT_VK_SUCCESS(err);
733
Karl Schultz6addd812016-02-02 17:17:23 -0700734 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
Mark Lobodzinski944aab12015-06-05 13:59:04 -0500735
736 mem_alloc.allocationSize = mem_reqs.size;
Karl Schultz6addd812016-02-02 17:17:23 -0700737 pass =
738 m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -0600739 ASSERT_TRUE(pass);
Mark Lobodzinski944aab12015-06-05 13:59:04 -0500740
741 // allocate 2 memory objects
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800742 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem1);
Mark Lobodzinski944aab12015-06-05 13:59:04 -0500743 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800744 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem2);
Mark Lobodzinski944aab12015-06-05 13:59:04 -0500745 ASSERT_VK_SUCCESS(err);
746
747 // Bind first memory object to Image object
Tony Barbour67e99152015-07-10 14:10:27 -0600748 err = vkBindImageMemory(m_device->device(), image, mem1, 0);
Mark Lobodzinski944aab12015-06-05 13:59:04 -0500749 ASSERT_VK_SUCCESS(err);
750
Karl Schultz6addd812016-02-02 17:17:23 -0700751 // Introduce validation failure, try to bind a different memory object to
752 // the same image object
Tony Barbour67e99152015-07-10 14:10:27 -0600753 err = vkBindImageMemory(m_device->device(), image, mem2, 0);
Mark Lobodzinski944aab12015-06-05 13:59:04 -0500754
Chris Forbes8f36a8a2016-04-07 13:21:07 +1200755 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -0600756
Chia-I Wuf7458c52015-10-26 21:10:41 +0800757 vkDestroyImage(m_device->device(), image, NULL);
758 vkFreeMemory(m_device->device(), mem1, NULL);
759 vkFreeMemory(m_device->device(), mem2, NULL);
Mark Lobodzinski944aab12015-06-05 13:59:04 -0500760}
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500761
Karl Schultz6addd812016-02-02 17:17:23 -0700762TEST_F(VkLayerTest, SubmitSignaledFence) {
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600763 vk_testing::Fence testFence;
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600764
Karl Schultz6addd812016-02-02 17:17:23 -0700765 m_errorMonitor->SetDesiredFailureMsg(
766 VK_DEBUG_REPORT_ERROR_BIT_EXT, "submitted in SIGNALED state. Fences "
767 "must be reset before being submitted");
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600768
769 VkFenceCreateInfo fenceInfo = {};
Tony Barbour0b4d9562015-04-09 10:48:04 -0600770 fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
771 fenceInfo.pNext = NULL;
772 fenceInfo.flags = VK_FENCE_CREATE_SIGNALED_BIT;
Tony Barbour300a6082015-04-07 13:44:53 -0600773
Tony Barbour300a6082015-04-07 13:44:53 -0600774 ASSERT_NO_FATAL_FAILURE(InitState());
775 ASSERT_NO_FATAL_FAILURE(InitViewport());
776 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
777
Tony Barbourfe3351b2015-07-28 10:17:20 -0600778 BeginCommandBuffer();
Karl Schultz6addd812016-02-02 17:17:23 -0700779 m_commandBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color,
780 m_stencil_clear_color, NULL);
Tony Barbourfe3351b2015-07-28 10:17:20 -0600781 EndCommandBuffer();
Tony Barbour300a6082015-04-07 13:44:53 -0600782
783 testFence.init(*m_device, fenceInfo);
Mark Lobodzinski5fcc4212015-09-14 17:43:42 -0600784
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -0600785 VkSubmitInfo submit_info;
Chia-I Wuf9be13c2015-10-26 20:37:06 +0800786 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
787 submit_info.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +0800788 submit_info.waitSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -0600789 submit_info.pWaitSemaphores = NULL;
Jon Ashburn7f9716c2015-12-30 16:42:50 -0700790 submit_info.pWaitDstStageMask = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +0800791 submit_info.commandBufferCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800792 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Chia-I Wud50a7d72015-10-26 20:48:51 +0800793 submit_info.signalSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -0600794 submit_info.pSignalSemaphores = NULL;
Courtney Goeltzenleuchter646b9072015-10-20 18:04:07 -0600795
796 vkQueueSubmit(m_device->m_queue, 1, &submit_info, testFence.handle());
Karl Schultz6addd812016-02-02 17:17:23 -0700797 vkQueueWaitIdle(m_device->m_queue);
Mark Lobodzinski5fcc4212015-09-14 17:43:42 -0600798
Chris Forbes8f36a8a2016-04-07 13:21:07 +1200799 m_errorMonitor->VerifyFound();
Tony Barbour0b4d9562015-04-09 10:48:04 -0600800}
Tobin Ehlisaff7ae92016-04-18 15:45:20 -0600801// This is a positive test. We used to expect error in this case but spec now
802// allows it
Karl Schultz6addd812016-02-02 17:17:23 -0700803TEST_F(VkLayerTest, ResetUnsignaledFence) {
Tobin Ehlisaff7ae92016-04-18 15:45:20 -0600804 m_errorMonitor->ExpectSuccess();
Tony Barbour0b4d9562015-04-09 10:48:04 -0600805 vk_testing::Fence testFence;
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600806 VkFenceCreateInfo fenceInfo = {};
Tony Barbour0b4d9562015-04-09 10:48:04 -0600807 fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
808 fenceInfo.pNext = NULL;
809
Tony Barbour0b4d9562015-04-09 10:48:04 -0600810 ASSERT_NO_FATAL_FAILURE(InitState());
811 testFence.init(*m_device, fenceInfo);
Chia-I Wud9e8e822015-07-03 11:45:55 +0800812 VkFence fences[1] = {testFence.handle()};
Tobin Ehlisaff7ae92016-04-18 15:45:20 -0600813 VkResult result = vkResetFences(m_device->device(), 1, fences);
814 ASSERT_VK_SUCCESS(result);
Tony Barbour300a6082015-04-07 13:44:53 -0600815
Tobin Ehlisaff7ae92016-04-18 15:45:20 -0600816 m_errorMonitor->VerifyNotFound();
Tony Barbour300a6082015-04-07 13:44:53 -0600817}
Tobin Ehlis41376e12015-07-03 08:45:14 -0600818
Chia-I Wu08accc62015-07-07 11:50:03 +0800819/* TODO: Update for changes due to bug-14075 tiling across render passes */
820#if 0
Tobin Ehlis41376e12015-07-03 08:45:14 -0600821TEST_F(VkLayerTest, InvalidUsageBits)
822{
823 // Initiate Draw w/o a PSO bound
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600824
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -0700825 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600826 "Invalid usage flag for image ");
Tobin Ehlis41376e12015-07-03 08:45:14 -0600827
828 ASSERT_NO_FATAL_FAILURE(InitState());
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800829 VkCommandBufferObj commandBuffer(m_device);
Tony Barbourfe3351b2015-07-28 10:17:20 -0600830 BeginCommandBuffer();
Tobin Ehlis41376e12015-07-03 08:45:14 -0600831
832 const VkExtent3D e3d = {
833 .width = 128,
834 .height = 128,
835 .depth = 1,
836 };
837 const VkImageCreateInfo ici = {
838 .sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO,
839 .pNext = NULL,
840 .imageType = VK_IMAGE_TYPE_2D,
841 .format = VK_FORMAT_D32_SFLOAT_S8_UINT,
842 .extent = e3d,
843 .mipLevels = 1,
844 .arraySize = 1,
Chia-I Wu5c17c962015-10-31 00:31:16 +0800845 .samples = VK_SAMPLE_COUNT_1_BIT,
Tobin Ehlis41376e12015-07-03 08:45:14 -0600846 .tiling = VK_IMAGE_TILING_LINEAR,
Courtney Goeltzenleuchter660f0ca2015-09-10 14:14:11 -0600847 .usage = 0, // Not setting VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT
Tobin Ehlis41376e12015-07-03 08:45:14 -0600848 .flags = 0,
849 };
850
851 VkImage dsi;
Chia-I Wuf7458c52015-10-26 21:10:41 +0800852 vkCreateImage(m_device->device(), &ici, NULL, &dsi);
Tobin Ehlis41376e12015-07-03 08:45:14 -0600853 VkDepthStencilView dsv;
854 const VkDepthStencilViewCreateInfo dsvci = {
855 .sType = VK_STRUCTURE_TYPE_DEPTH_STENCIL_VIEW_CREATE_INFO,
856 .pNext = NULL,
857 .image = dsi,
858 .mipLevel = 0,
Courtney Goeltzenleuchter4a261892015-09-10 16:38:41 -0600859 .baseArrayLayer = 0,
Tobin Ehlis41376e12015-07-03 08:45:14 -0600860 .arraySize = 1,
861 .flags = 0,
862 };
Chia-I Wuf7458c52015-10-26 21:10:41 +0800863 vkCreateDepthStencilView(m_device->device(), &dsvci, NULL, &dsv);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600864
Chris Forbes8f36a8a2016-04-07 13:21:07 +1200865 m_errorMonitor->VerifyFound();
Tobin Ehlis41376e12015-07-03 08:45:14 -0600866}
Mark Lobodzinski209b5292015-09-17 09:44:05 -0600867#endif // 0
868#endif // MEM_TRACKER_TESTS
869
Tobin Ehlis4bf96d12015-06-25 11:58:41 -0600870#if OBJ_TRACKER_TESTS
Karl Schultz6addd812016-02-02 17:17:23 -0700871TEST_F(VkLayerTest, PipelineNotBound) {
872 VkResult err;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -0600873
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -0700874 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Karl Schultz6addd812016-02-02 17:17:23 -0700875 "Invalid VkPipeline Object ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600876
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -0600877 ASSERT_NO_FATAL_FAILURE(InitState());
878 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -0600879
Chia-I Wu1b99bb22015-10-27 19:25:11 +0800880 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -0700881 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
882 ds_type_count.descriptorCount = 1;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -0600883
884 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -0700885 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
886 ds_pool_ci.pNext = NULL;
887 ds_pool_ci.maxSets = 1;
888 ds_pool_ci.poolSizeCount = 1;
889 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -0600890
891 VkDescriptorPool ds_pool;
Karl Schultz6addd812016-02-02 17:17:23 -0700892 err =
893 vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -0600894 ASSERT_VK_SUCCESS(err);
895
896 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -0700897 dsl_binding.binding = 0;
898 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
899 dsl_binding.descriptorCount = 1;
900 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
901 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -0600902
903 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -0700904 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
905 ds_layout_ci.pNext = NULL;
906 ds_layout_ci.bindingCount = 1;
907 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -0600908
909 VkDescriptorSetLayout ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -0700910 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
911 &ds_layout);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -0600912 ASSERT_VK_SUCCESS(err);
913
914 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800915 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +0800916 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -0700917 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -0600918 alloc_info.descriptorPool = ds_pool;
919 alloc_info.pSetLayouts = &ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -0700920 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info,
921 &descriptorSet);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -0600922 ASSERT_VK_SUCCESS(err);
923
924 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -0700925 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
926 pipeline_layout_ci.pNext = NULL;
927 pipeline_layout_ci.setLayoutCount = 1;
928 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -0600929
930 VkPipelineLayout pipeline_layout;
Karl Schultz6addd812016-02-02 17:17:23 -0700931 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL,
932 &pipeline_layout);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -0600933 ASSERT_VK_SUCCESS(err);
934
Mark Youngad779052016-01-06 14:26:04 -0700935 VkPipeline badPipeline = (VkPipeline)((size_t)0xbaadb1be);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -0600936
937 BeginCommandBuffer();
Karl Schultz6addd812016-02-02 17:17:23 -0700938 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(),
939 VK_PIPELINE_BIND_POINT_GRAPHICS, badPipeline);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -0600940
Chris Forbes8f36a8a2016-04-07 13:21:07 +1200941 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -0600942
Chia-I Wuf7458c52015-10-26 21:10:41 +0800943 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
944 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
945 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisec598302015-09-15 15:02:17 -0600946}
947
Karl Schultz6addd812016-02-02 17:17:23 -0700948TEST_F(VkLayerTest, BindInvalidMemory) {
949 VkResult err;
950 bool pass;
Tobin Ehlisec598302015-09-15 15:02:17 -0600951
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -0700952 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Karl Schultz6addd812016-02-02 17:17:23 -0700953 "Invalid VkDeviceMemory Object ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600954
Tobin Ehlisec598302015-09-15 15:02:17 -0600955 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisec598302015-09-15 15:02:17 -0600956
957 // Create an image, allocate memory, free it, and then try to bind it
Karl Schultz6addd812016-02-02 17:17:23 -0700958 VkImage image;
959 VkDeviceMemory mem;
960 VkMemoryRequirements mem_reqs;
Tobin Ehlisec598302015-09-15 15:02:17 -0600961
Karl Schultz6addd812016-02-02 17:17:23 -0700962 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
963 const int32_t tex_width = 32;
964 const int32_t tex_height = 32;
Tobin Ehlisec598302015-09-15 15:02:17 -0600965
966 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -0700967 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
968 image_create_info.pNext = NULL;
969 image_create_info.imageType = VK_IMAGE_TYPE_2D;
970 image_create_info.format = tex_format;
971 image_create_info.extent.width = tex_width;
972 image_create_info.extent.height = tex_height;
973 image_create_info.extent.depth = 1;
974 image_create_info.mipLevels = 1;
975 image_create_info.arrayLayers = 1;
976 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
977 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
978 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
979 image_create_info.flags = 0;
Tobin Ehlisec598302015-09-15 15:02:17 -0600980
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800981 VkMemoryAllocateInfo mem_alloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -0700982 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
983 mem_alloc.pNext = NULL;
984 mem_alloc.allocationSize = 0;
985 mem_alloc.memoryTypeIndex = 0;
Tobin Ehlisec598302015-09-15 15:02:17 -0600986
Chia-I Wuf7458c52015-10-26 21:10:41 +0800987 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Tobin Ehlisec598302015-09-15 15:02:17 -0600988 ASSERT_VK_SUCCESS(err);
989
Karl Schultz6addd812016-02-02 17:17:23 -0700990 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
Tobin Ehlisec598302015-09-15 15:02:17 -0600991
992 mem_alloc.allocationSize = mem_reqs.size;
993
Karl Schultz6addd812016-02-02 17:17:23 -0700994 pass =
995 m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -0600996 ASSERT_TRUE(pass);
Tobin Ehlisec598302015-09-15 15:02:17 -0600997
998 // allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800999 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
Tobin Ehlisec598302015-09-15 15:02:17 -06001000 ASSERT_VK_SUCCESS(err);
1001
1002 // Introduce validation failure, free memory before binding
Chia-I Wuf7458c52015-10-26 21:10:41 +08001003 vkFreeMemory(m_device->device(), mem, NULL);
Tobin Ehlisec598302015-09-15 15:02:17 -06001004
1005 // Try to bind free memory that has been freed
1006 err = vkBindImageMemory(m_device->device(), image, mem, 0);
1007 // This may very well return an error.
1008 (void)err;
1009
Chris Forbes8f36a8a2016-04-07 13:21:07 +12001010 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06001011
Chia-I Wuf7458c52015-10-26 21:10:41 +08001012 vkDestroyImage(m_device->device(), image, NULL);
Tobin Ehlisec598302015-09-15 15:02:17 -06001013}
1014
Karl Schultz6addd812016-02-02 17:17:23 -07001015TEST_F(VkLayerTest, BindMemoryToDestroyedObject) {
1016 VkResult err;
1017 bool pass;
Tobin Ehlisec598302015-09-15 15:02:17 -06001018
Karl Schultz6addd812016-02-02 17:17:23 -07001019 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
1020 "Invalid VkImage Object ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06001021
Tobin Ehlisec598302015-09-15 15:02:17 -06001022 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisec598302015-09-15 15:02:17 -06001023
Karl Schultz6addd812016-02-02 17:17:23 -07001024 // Create an image object, allocate memory, destroy the object and then try
1025 // to bind it
1026 VkImage image;
1027 VkDeviceMemory mem;
1028 VkMemoryRequirements mem_reqs;
Tobin Ehlisec598302015-09-15 15:02:17 -06001029
Karl Schultz6addd812016-02-02 17:17:23 -07001030 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
1031 const int32_t tex_width = 32;
1032 const int32_t tex_height = 32;
Tobin Ehlisec598302015-09-15 15:02:17 -06001033
1034 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -07001035 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
1036 image_create_info.pNext = NULL;
1037 image_create_info.imageType = VK_IMAGE_TYPE_2D;
1038 image_create_info.format = tex_format;
1039 image_create_info.extent.width = tex_width;
1040 image_create_info.extent.height = tex_height;
1041 image_create_info.extent.depth = 1;
1042 image_create_info.mipLevels = 1;
1043 image_create_info.arrayLayers = 1;
1044 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
1045 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
1046 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
1047 image_create_info.flags = 0;
Tobin Ehlisec598302015-09-15 15:02:17 -06001048
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001049 VkMemoryAllocateInfo mem_alloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -07001050 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
1051 mem_alloc.pNext = NULL;
1052 mem_alloc.allocationSize = 0;
1053 mem_alloc.memoryTypeIndex = 0;
Tobin Ehlisec598302015-09-15 15:02:17 -06001054
Chia-I Wuf7458c52015-10-26 21:10:41 +08001055 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Tobin Ehlisec598302015-09-15 15:02:17 -06001056 ASSERT_VK_SUCCESS(err);
1057
Karl Schultz6addd812016-02-02 17:17:23 -07001058 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
Tobin Ehlisec598302015-09-15 15:02:17 -06001059
1060 mem_alloc.allocationSize = mem_reqs.size;
Karl Schultz6addd812016-02-02 17:17:23 -07001061 pass =
1062 m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -06001063 ASSERT_TRUE(pass);
Tobin Ehlisec598302015-09-15 15:02:17 -06001064
1065 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001066 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
Tobin Ehlisec598302015-09-15 15:02:17 -06001067 ASSERT_VK_SUCCESS(err);
1068
1069 // Introduce validation failure, destroy Image object before binding
Chia-I Wuf7458c52015-10-26 21:10:41 +08001070 vkDestroyImage(m_device->device(), image, NULL);
Tobin Ehlisec598302015-09-15 15:02:17 -06001071 ASSERT_VK_SUCCESS(err);
1072
1073 // Now Try to bind memory to this destroyed object
1074 err = vkBindImageMemory(m_device->device(), image, mem, 0);
1075 // This may very well return an error.
Karl Schultz6addd812016-02-02 17:17:23 -07001076 (void)err;
Tobin Ehlisec598302015-09-15 15:02:17 -06001077
Chris Forbes8f36a8a2016-04-07 13:21:07 +12001078 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06001079
Chia-I Wuf7458c52015-10-26 21:10:41 +08001080 vkFreeMemory(m_device->device(), mem, NULL);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06001081}
Tobin Ehlisa1c28562015-10-23 16:00:08 -06001082
Mark Lobodzinski209b5292015-09-17 09:44:05 -06001083#endif // OBJ_TRACKER_TESTS
1084
Tobin Ehlis0788f522015-05-26 16:11:58 -06001085#if DRAW_STATE_TESTS
Mark Lobodzinskic808d442016-04-14 10:57:23 -06001086
1087// This is a positive test. No errors should be generated.
1088TEST_F(VkLayerTest, TwoQueueSubmitsSeparateQueuesWithSemaphoreAndOneFenceQWI) {
1089
1090 TEST_DESCRIPTION("Two command buffers, each in a separate QueueSubmit call "
1091 "submitted on separate queues followed by a QueueWaitIdle.");
1092
1093 m_errorMonitor->ExpectSuccess();
1094
1095 VkSemaphore semaphore;
1096 VkSemaphoreCreateInfo semaphore_create_info{};
1097 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
1098 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr,
1099 &semaphore);
1100
1101 VkCommandPool command_pool;
1102 VkCommandPoolCreateInfo pool_create_info{};
1103 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
1104 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
1105 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
1106 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr,
1107 &command_pool);
1108
1109 VkCommandBuffer command_buffer[2];
1110 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
1111 command_buffer_allocate_info.sType =
1112 VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
1113 command_buffer_allocate_info.commandPool = command_pool;
1114 command_buffer_allocate_info.commandBufferCount = 2;
1115 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
1116 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info,
1117 command_buffer);
1118
1119 VkQueue queue = VK_NULL_HANDLE;
1120 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_,
1121 1, &queue);
1122
1123 {
1124 VkCommandBufferBeginInfo begin_info{};
1125 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
1126 vkBeginCommandBuffer(command_buffer[0], &begin_info);
1127
1128 vkCmdPipelineBarrier(command_buffer[0],
1129 VK_PIPELINE_STAGE_ALL_COMMANDS_BIT,
1130 VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, nullptr,
1131 0, nullptr, 0, nullptr);
1132
1133 VkViewport viewport{};
1134 viewport.maxDepth = 1.0f;
1135 viewport.minDepth = 0.0f;
1136 viewport.width = 512;
1137 viewport.height = 512;
1138 viewport.x = 0;
1139 viewport.y = 0;
1140 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
1141 vkEndCommandBuffer(command_buffer[0]);
1142 }
1143 {
1144 VkCommandBufferBeginInfo begin_info{};
1145 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
1146 vkBeginCommandBuffer(command_buffer[1], &begin_info);
1147
1148 VkViewport viewport{};
1149 viewport.maxDepth = 1.0f;
1150 viewport.minDepth = 0.0f;
1151 viewport.width = 512;
1152 viewport.height = 512;
1153 viewport.x = 0;
1154 viewport.y = 0;
1155 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
1156 vkEndCommandBuffer(command_buffer[1]);
1157 }
1158 {
1159 VkSubmitInfo submit_info{};
1160 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
1161 submit_info.commandBufferCount = 1;
1162 submit_info.pCommandBuffers = &command_buffer[0];
1163 submit_info.signalSemaphoreCount = 1;
1164 submit_info.pSignalSemaphores = &semaphore;
1165 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
1166 }
1167 {
1168 VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT};
1169 VkSubmitInfo submit_info{};
1170 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
1171 submit_info.commandBufferCount = 1;
1172 submit_info.pCommandBuffers = &command_buffer[1];
1173 submit_info.waitSemaphoreCount = 1;
1174 submit_info.pWaitSemaphores = &semaphore;
1175 submit_info.pWaitDstStageMask = flags;
1176 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
1177 }
1178
1179 vkQueueWaitIdle(m_device->m_queue);
1180
1181 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
1182 vkFreeCommandBuffers(m_device->device(), command_pool, 2,
1183 &command_buffer[0]);
1184 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
1185
1186 m_errorMonitor->VerifyNotFound();
1187}
1188
1189// This is a positive test. No errors should be generated.
1190TEST_F(VkLayerTest, TwoQueueSubmitsSeparateQueuesWithSemaphoreAndOneFenceQWIFence) {
1191
1192 TEST_DESCRIPTION("Two command buffers, each in a separate QueueSubmit call "
1193 "submitted on separate queues, the second having a fence"
1194 "followed by a QueueWaitIdle.");
1195
1196 m_errorMonitor->ExpectSuccess();
1197
1198 VkFence fence;
1199 VkFenceCreateInfo fence_create_info{};
1200 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
1201 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
1202
1203 VkSemaphore semaphore;
1204 VkSemaphoreCreateInfo semaphore_create_info{};
1205 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
1206 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr,
1207 &semaphore);
1208
1209 VkCommandPool command_pool;
1210 VkCommandPoolCreateInfo pool_create_info{};
1211 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
1212 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
1213 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
1214 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr,
1215 &command_pool);
1216
1217 VkCommandBuffer command_buffer[2];
1218 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
1219 command_buffer_allocate_info.sType =
1220 VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
1221 command_buffer_allocate_info.commandPool = command_pool;
1222 command_buffer_allocate_info.commandBufferCount = 2;
1223 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
1224 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info,
1225 command_buffer);
1226
1227 VkQueue queue = VK_NULL_HANDLE;
1228 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_,
1229 1, &queue);
1230
1231 {
1232 VkCommandBufferBeginInfo begin_info{};
1233 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
1234 vkBeginCommandBuffer(command_buffer[0], &begin_info);
1235
1236 vkCmdPipelineBarrier(command_buffer[0],
1237 VK_PIPELINE_STAGE_ALL_COMMANDS_BIT,
1238 VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, nullptr,
1239 0, nullptr, 0, nullptr);
1240
1241 VkViewport viewport{};
1242 viewport.maxDepth = 1.0f;
1243 viewport.minDepth = 0.0f;
1244 viewport.width = 512;
1245 viewport.height = 512;
1246 viewport.x = 0;
1247 viewport.y = 0;
1248 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
1249 vkEndCommandBuffer(command_buffer[0]);
1250 }
1251 {
1252 VkCommandBufferBeginInfo begin_info{};
1253 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
1254 vkBeginCommandBuffer(command_buffer[1], &begin_info);
1255
1256 VkViewport viewport{};
1257 viewport.maxDepth = 1.0f;
1258 viewport.minDepth = 0.0f;
1259 viewport.width = 512;
1260 viewport.height = 512;
1261 viewport.x = 0;
1262 viewport.y = 0;
1263 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
1264 vkEndCommandBuffer(command_buffer[1]);
1265 }
1266 {
1267 VkSubmitInfo submit_info{};
1268 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
1269 submit_info.commandBufferCount = 1;
1270 submit_info.pCommandBuffers = &command_buffer[0];
1271 submit_info.signalSemaphoreCount = 1;
1272 submit_info.pSignalSemaphores = &semaphore;
1273 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
1274 }
1275 {
1276 VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT};
1277 VkSubmitInfo submit_info{};
1278 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
1279 submit_info.commandBufferCount = 1;
1280 submit_info.pCommandBuffers = &command_buffer[1];
1281 submit_info.waitSemaphoreCount = 1;
1282 submit_info.pWaitSemaphores = &semaphore;
1283 submit_info.pWaitDstStageMask = flags;
1284 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
1285 }
1286
1287 vkQueueWaitIdle(m_device->m_queue);
1288
1289 vkDestroyFence(m_device->device(), fence, nullptr);
1290 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
1291 vkFreeCommandBuffers(m_device->device(), command_pool, 2,
1292 &command_buffer[0]);
1293 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
1294
1295 m_errorMonitor->VerifyNotFound();
1296}
1297
1298// This is a positive test. No errors should be generated.
1299TEST_F(VkLayerTest,
1300 TwoQueueSubmitsSeparateQueuesWithSemaphoreAndOneFenceTwoWFF) {
1301
1302 TEST_DESCRIPTION(
1303 "Two command buffers, each in a separate QueueSubmit call "
1304 "submitted on separate queues, the second having a fence"
1305 "followed by two consecutive WaitForFences calls on the same fence.");
1306
1307 m_errorMonitor->ExpectSuccess();
1308
1309 VkFence fence;
1310 VkFenceCreateInfo fence_create_info{};
1311 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
1312 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
1313
1314 VkSemaphore semaphore;
1315 VkSemaphoreCreateInfo semaphore_create_info{};
1316 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
1317 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr,
1318 &semaphore);
1319
1320 VkCommandPool command_pool;
1321 VkCommandPoolCreateInfo pool_create_info{};
1322 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
1323 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
1324 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
1325 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr,
1326 &command_pool);
1327
1328 VkCommandBuffer command_buffer[2];
1329 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
1330 command_buffer_allocate_info.sType =
1331 VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
1332 command_buffer_allocate_info.commandPool = command_pool;
1333 command_buffer_allocate_info.commandBufferCount = 2;
1334 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
1335 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info,
1336 command_buffer);
1337
1338 VkQueue queue = VK_NULL_HANDLE;
1339 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_,
1340 1, &queue);
1341
1342 {
1343 VkCommandBufferBeginInfo begin_info{};
1344 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
1345 vkBeginCommandBuffer(command_buffer[0], &begin_info);
1346
1347 vkCmdPipelineBarrier(command_buffer[0],
1348 VK_PIPELINE_STAGE_ALL_COMMANDS_BIT,
1349 VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, nullptr,
1350 0, nullptr, 0, nullptr);
1351
1352 VkViewport viewport{};
1353 viewport.maxDepth = 1.0f;
1354 viewport.minDepth = 0.0f;
1355 viewport.width = 512;
1356 viewport.height = 512;
1357 viewport.x = 0;
1358 viewport.y = 0;
1359 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
1360 vkEndCommandBuffer(command_buffer[0]);
1361 }
1362 {
1363 VkCommandBufferBeginInfo begin_info{};
1364 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
1365 vkBeginCommandBuffer(command_buffer[1], &begin_info);
1366
1367 VkViewport viewport{};
1368 viewport.maxDepth = 1.0f;
1369 viewport.minDepth = 0.0f;
1370 viewport.width = 512;
1371 viewport.height = 512;
1372 viewport.x = 0;
1373 viewport.y = 0;
1374 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
1375 vkEndCommandBuffer(command_buffer[1]);
1376 }
1377 {
1378 VkSubmitInfo submit_info{};
1379 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
1380 submit_info.commandBufferCount = 1;
1381 submit_info.pCommandBuffers = &command_buffer[0];
1382 submit_info.signalSemaphoreCount = 1;
1383 submit_info.pSignalSemaphores = &semaphore;
1384 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
1385 }
1386 {
1387 VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT};
1388 VkSubmitInfo submit_info{};
1389 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
1390 submit_info.commandBufferCount = 1;
1391 submit_info.pCommandBuffers = &command_buffer[1];
1392 submit_info.waitSemaphoreCount = 1;
1393 submit_info.pWaitSemaphores = &semaphore;
1394 submit_info.pWaitDstStageMask = flags;
1395 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
1396 }
1397
1398 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
1399 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
1400
1401 vkDestroyFence(m_device->device(), fence, nullptr);
1402 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
1403 vkFreeCommandBuffers(m_device->device(), command_pool, 2,
1404 &command_buffer[0]);
1405 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
1406
1407 m_errorMonitor->VerifyNotFound();
1408}
1409
1410// This is a positive test. No errors should be generated.
1411TEST_F(VkLayerTest, TwoQueueSubmitsSeparateQueuesWithSemaphoreAndOneFence) {
1412
1413 TEST_DESCRIPTION("Two command buffers, each in a separate QueueSubmit call "
1414 "submitted on separate queues, the second having a fence, "
1415 "followed by a WaitForFences call.");
1416
1417 m_errorMonitor->ExpectSuccess();
1418
1419 VkFence fence;
1420 VkFenceCreateInfo fence_create_info{};
1421 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
1422 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
1423
1424 VkSemaphore semaphore;
1425 VkSemaphoreCreateInfo semaphore_create_info{};
1426 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
1427 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr,
1428 &semaphore);
1429
1430 VkCommandPool command_pool;
1431 VkCommandPoolCreateInfo pool_create_info{};
1432 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
1433 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
1434 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
1435 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr,
1436 &command_pool);
1437
1438 VkCommandBuffer command_buffer[2];
1439 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
1440 command_buffer_allocate_info.sType =
1441 VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
1442 command_buffer_allocate_info.commandPool = command_pool;
1443 command_buffer_allocate_info.commandBufferCount = 2;
1444 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
1445 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info,
1446 command_buffer);
1447
1448 VkQueue queue = VK_NULL_HANDLE;
1449 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_,
1450 1, &queue);
1451
1452
1453 {
1454 VkCommandBufferBeginInfo begin_info{};
1455 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
1456 vkBeginCommandBuffer(command_buffer[0], &begin_info);
1457
1458 vkCmdPipelineBarrier(command_buffer[0],
1459 VK_PIPELINE_STAGE_ALL_COMMANDS_BIT,
1460 VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, nullptr,
1461 0, nullptr, 0, nullptr);
1462
1463 VkViewport viewport{};
1464 viewport.maxDepth = 1.0f;
1465 viewport.minDepth = 0.0f;
1466 viewport.width = 512;
1467 viewport.height = 512;
1468 viewport.x = 0;
1469 viewport.y = 0;
1470 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
1471 vkEndCommandBuffer(command_buffer[0]);
1472 }
1473 {
1474 VkCommandBufferBeginInfo begin_info{};
1475 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
1476 vkBeginCommandBuffer(command_buffer[1], &begin_info);
1477
1478 VkViewport viewport{};
1479 viewport.maxDepth = 1.0f;
1480 viewport.minDepth = 0.0f;
1481 viewport.width = 512;
1482 viewport.height = 512;
1483 viewport.x = 0;
1484 viewport.y = 0;
1485 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
1486 vkEndCommandBuffer(command_buffer[1]);
1487 }
1488 {
1489 VkSubmitInfo submit_info{};
1490 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
1491 submit_info.commandBufferCount = 1;
1492 submit_info.pCommandBuffers = &command_buffer[0];
1493 submit_info.signalSemaphoreCount = 1;
1494 submit_info.pSignalSemaphores = &semaphore;
1495 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
1496 }
1497 {
1498 VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT};
1499 VkSubmitInfo submit_info{};
1500 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
1501 submit_info.commandBufferCount = 1;
1502 submit_info.pCommandBuffers = &command_buffer[1];
1503 submit_info.waitSemaphoreCount = 1;
1504 submit_info.pWaitSemaphores = &semaphore;
1505 submit_info.pWaitDstStageMask = flags;
1506 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
1507 }
1508
1509 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
1510
1511 vkDestroyFence(m_device->device(), fence, nullptr);
1512 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
1513 vkFreeCommandBuffers(m_device->device(), command_pool, 2,
1514 &command_buffer[0]);
1515 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
1516
1517 m_errorMonitor->VerifyNotFound();
1518}
1519
1520// This is a positive test. No errors should be generated.
1521TEST_F(VkLayerTest, TwoQueueSubmitsOneQueueWithSemaphoreAndOneFence) {
1522
1523 TEST_DESCRIPTION("Two command buffers, each in a separate QueueSubmit call "
1524 "on the same queue, sharing a signal/wait semaphore, the "
1525 "second having a fence, "
1526 "followed by a WaitForFences call.");
1527
1528 m_errorMonitor->ExpectSuccess();
1529
1530 VkFence fence;
1531 VkFenceCreateInfo fence_create_info{};
1532 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
1533 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
1534
1535 VkSemaphore semaphore;
1536 VkSemaphoreCreateInfo semaphore_create_info{};
1537 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
1538 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr,
1539 &semaphore);
1540
1541 VkCommandPool command_pool;
1542 VkCommandPoolCreateInfo pool_create_info{};
1543 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
1544 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
1545 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
1546 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr,
1547 &command_pool);
1548
1549 VkCommandBuffer command_buffer[2];
1550 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
1551 command_buffer_allocate_info.sType =
1552 VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
1553 command_buffer_allocate_info.commandPool = command_pool;
1554 command_buffer_allocate_info.commandBufferCount = 2;
1555 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
1556 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info,
1557 command_buffer);
1558
1559 {
1560 VkCommandBufferBeginInfo begin_info{};
1561 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
1562 vkBeginCommandBuffer(command_buffer[0], &begin_info);
1563
1564 vkCmdPipelineBarrier(command_buffer[0],
1565 VK_PIPELINE_STAGE_ALL_COMMANDS_BIT,
1566 VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, nullptr,
1567 0, nullptr, 0, nullptr);
1568
1569 VkViewport viewport{};
1570 viewport.maxDepth = 1.0f;
1571 viewport.minDepth = 0.0f;
1572 viewport.width = 512;
1573 viewport.height = 512;
1574 viewport.x = 0;
1575 viewport.y = 0;
1576 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
1577 vkEndCommandBuffer(command_buffer[0]);
1578 }
1579 {
1580 VkCommandBufferBeginInfo begin_info{};
1581 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
1582 vkBeginCommandBuffer(command_buffer[1], &begin_info);
1583
1584 VkViewport viewport{};
1585 viewport.maxDepth = 1.0f;
1586 viewport.minDepth = 0.0f;
1587 viewport.width = 512;
1588 viewport.height = 512;
1589 viewport.x = 0;
1590 viewport.y = 0;
1591 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
1592 vkEndCommandBuffer(command_buffer[1]);
1593 }
1594 {
1595 VkSubmitInfo submit_info{};
1596 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
1597 submit_info.commandBufferCount = 1;
1598 submit_info.pCommandBuffers = &command_buffer[0];
1599 submit_info.signalSemaphoreCount = 1;
1600 submit_info.pSignalSemaphores = &semaphore;
1601 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
1602 }
1603 {
1604 VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT};
1605 VkSubmitInfo submit_info{};
1606 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
1607 submit_info.commandBufferCount = 1;
1608 submit_info.pCommandBuffers = &command_buffer[1];
1609 submit_info.waitSemaphoreCount = 1;
1610 submit_info.pWaitSemaphores = &semaphore;
1611 submit_info.pWaitDstStageMask = flags;
1612 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
1613 }
1614
1615 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
1616
1617 vkDestroyFence(m_device->device(), fence, nullptr);
1618 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
1619 vkFreeCommandBuffers(m_device->device(), command_pool, 2,
1620 &command_buffer[0]);
1621 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
1622
1623 m_errorMonitor->VerifyNotFound();
1624}
1625
1626// This is a positive test. No errors should be generated.
1627TEST_F(VkLayerTest, TwoQueueSubmitsOneQueueNullQueueSubmitWithFence) {
1628
1629 TEST_DESCRIPTION(
1630 "Two command buffers, each in a separate QueueSubmit call "
1631 "on the same queue, no fences, followed by a third QueueSubmit with NO "
1632 "SubmitInfos but with a fence, followed by a WaitForFences call.");
1633
1634 m_errorMonitor->ExpectSuccess();
1635
1636 VkFence fence;
1637 VkFenceCreateInfo fence_create_info{};
1638 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
1639 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
1640
1641 VkCommandPool command_pool;
1642 VkCommandPoolCreateInfo pool_create_info{};
1643 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
1644 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
1645 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
1646 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr,
1647 &command_pool);
1648
1649 VkCommandBuffer command_buffer[2];
1650 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
1651 command_buffer_allocate_info.sType =
1652 VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
1653 command_buffer_allocate_info.commandPool = command_pool;
1654 command_buffer_allocate_info.commandBufferCount = 2;
1655 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
1656 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info,
1657 command_buffer);
1658
1659 {
1660 VkCommandBufferBeginInfo begin_info{};
1661 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
1662 vkBeginCommandBuffer(command_buffer[0], &begin_info);
1663
1664 vkCmdPipelineBarrier(command_buffer[0],
1665 VK_PIPELINE_STAGE_ALL_COMMANDS_BIT,
1666 VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, nullptr,
1667 0, nullptr, 0, nullptr);
1668
1669 VkViewport viewport{};
1670 viewport.maxDepth = 1.0f;
1671 viewport.minDepth = 0.0f;
1672 viewport.width = 512;
1673 viewport.height = 512;
1674 viewport.x = 0;
1675 viewport.y = 0;
1676 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
1677 vkEndCommandBuffer(command_buffer[0]);
1678 }
1679 {
1680 VkCommandBufferBeginInfo begin_info{};
1681 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
1682 vkBeginCommandBuffer(command_buffer[1], &begin_info);
1683
1684 VkViewport viewport{};
1685 viewport.maxDepth = 1.0f;
1686 viewport.minDepth = 0.0f;
1687 viewport.width = 512;
1688 viewport.height = 512;
1689 viewport.x = 0;
1690 viewport.y = 0;
1691 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
1692 vkEndCommandBuffer(command_buffer[1]);
1693 }
1694 {
1695 VkSubmitInfo submit_info{};
1696 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
1697 submit_info.commandBufferCount = 1;
1698 submit_info.pCommandBuffers = &command_buffer[0];
1699 submit_info.signalSemaphoreCount = 0;
1700 submit_info.pSignalSemaphores = VK_NULL_HANDLE;
1701 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
1702 }
1703 {
1704 VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT};
1705 VkSubmitInfo submit_info{};
1706 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
1707 submit_info.commandBufferCount = 1;
1708 submit_info.pCommandBuffers = &command_buffer[1];
1709 submit_info.waitSemaphoreCount = 0;
1710 submit_info.pWaitSemaphores = VK_NULL_HANDLE;
1711 submit_info.pWaitDstStageMask = flags;
1712 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
1713 }
1714
1715 vkQueueSubmit(m_device->m_queue, 0, NULL, fence);
1716
1717 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
1718
1719 vkDestroyFence(m_device->device(), fence, nullptr);
1720 vkFreeCommandBuffers(m_device->device(), command_pool, 2,
1721 &command_buffer[0]);
1722 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
1723
1724 m_errorMonitor->VerifyNotFound();
1725}
1726
1727// This is a positive test. No errors should be generated.
1728TEST_F(VkLayerTest, TwoQueueSubmitsOneQueueOneFence) {
1729
1730 TEST_DESCRIPTION("Two command buffers, each in a separate QueueSubmit call "
1731 "on the same queue, the second having a fence, followed "
1732 "by a WaitForFences call.");
1733
1734 m_errorMonitor->ExpectSuccess();
1735
1736 VkFence fence;
1737 VkFenceCreateInfo fence_create_info{};
1738 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
1739 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
1740
1741 VkCommandPool command_pool;
1742 VkCommandPoolCreateInfo pool_create_info{};
1743 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
1744 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
1745 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
1746 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr,
1747 &command_pool);
1748
1749 VkCommandBuffer command_buffer[2];
1750 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
1751 command_buffer_allocate_info.sType =
1752 VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
1753 command_buffer_allocate_info.commandPool = command_pool;
1754 command_buffer_allocate_info.commandBufferCount = 2;
1755 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
1756 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info,
1757 command_buffer);
1758
1759 {
1760 VkCommandBufferBeginInfo begin_info{};
1761 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
1762 vkBeginCommandBuffer(command_buffer[0], &begin_info);
1763
1764 vkCmdPipelineBarrier(command_buffer[0],
1765 VK_PIPELINE_STAGE_ALL_COMMANDS_BIT,
1766 VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, nullptr,
1767 0, nullptr, 0, nullptr);
1768
1769 VkViewport viewport{};
1770 viewport.maxDepth = 1.0f;
1771 viewport.minDepth = 0.0f;
1772 viewport.width = 512;
1773 viewport.height = 512;
1774 viewport.x = 0;
1775 viewport.y = 0;
1776 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
1777 vkEndCommandBuffer(command_buffer[0]);
1778 }
1779 {
1780 VkCommandBufferBeginInfo begin_info{};
1781 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
1782 vkBeginCommandBuffer(command_buffer[1], &begin_info);
1783
1784 VkViewport viewport{};
1785 viewport.maxDepth = 1.0f;
1786 viewport.minDepth = 0.0f;
1787 viewport.width = 512;
1788 viewport.height = 512;
1789 viewport.x = 0;
1790 viewport.y = 0;
1791 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
1792 vkEndCommandBuffer(command_buffer[1]);
1793 }
1794 {
1795 VkSubmitInfo submit_info{};
1796 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
1797 submit_info.commandBufferCount = 1;
1798 submit_info.pCommandBuffers = &command_buffer[0];
1799 submit_info.signalSemaphoreCount = 0;
1800 submit_info.pSignalSemaphores = VK_NULL_HANDLE;
1801 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
1802 }
1803 {
1804 VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT};
1805 VkSubmitInfo submit_info{};
1806 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
1807 submit_info.commandBufferCount = 1;
1808 submit_info.pCommandBuffers = &command_buffer[1];
1809 submit_info.waitSemaphoreCount = 0;
1810 submit_info.pWaitSemaphores = VK_NULL_HANDLE;
1811 submit_info.pWaitDstStageMask = flags;
1812 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
1813 }
1814
1815 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
1816
1817 vkDestroyFence(m_device->device(), fence, nullptr);
1818 vkFreeCommandBuffers(m_device->device(), command_pool, 2,
1819 &command_buffer[0]);
1820 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
1821
1822 m_errorMonitor->VerifyNotFound();
1823}
1824
1825// This is a positive test. No errors should be generated.
1826TEST_F(VkLayerTest, TwoSubmitInfosWithSemaphoreOneQueueSubmitsOneFence) {
1827
1828 TEST_DESCRIPTION(
1829 "Two command buffers each in a separate SubmitInfo sent in a single "
1830 "QueueSubmit call followed by a WaitForFences call.");
1831
1832 m_errorMonitor->ExpectSuccess();
1833
1834 VkFence fence;
1835 VkFenceCreateInfo fence_create_info{};
1836 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
1837 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
1838
1839 VkSemaphore semaphore;
1840 VkSemaphoreCreateInfo semaphore_create_info{};
1841 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
1842 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr,
1843 &semaphore);
1844
1845 VkCommandPool command_pool;
1846 VkCommandPoolCreateInfo pool_create_info{};
1847 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
1848 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
1849 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
1850 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr,
1851 &command_pool);
1852
1853 VkCommandBuffer command_buffer[2];
1854 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
1855 command_buffer_allocate_info.sType =
1856 VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
1857 command_buffer_allocate_info.commandPool = command_pool;
1858 command_buffer_allocate_info.commandBufferCount = 2;
1859 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
1860 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info,
1861 command_buffer);
1862
1863 {
1864 VkCommandBufferBeginInfo begin_info{};
1865 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
1866 vkBeginCommandBuffer(command_buffer[0], &begin_info);
1867
1868 vkCmdPipelineBarrier(command_buffer[0],
1869 VK_PIPELINE_STAGE_ALL_COMMANDS_BIT,
1870 VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, nullptr,
1871 0, nullptr, 0, nullptr);
1872
1873 VkViewport viewport{};
1874 viewport.maxDepth = 1.0f;
1875 viewport.minDepth = 0.0f;
1876 viewport.width = 512;
1877 viewport.height = 512;
1878 viewport.x = 0;
1879 viewport.y = 0;
1880 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
1881 vkEndCommandBuffer(command_buffer[0]);
1882 }
1883 {
1884 VkCommandBufferBeginInfo begin_info{};
1885 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
1886 vkBeginCommandBuffer(command_buffer[1], &begin_info);
1887
1888 VkViewport viewport{};
1889 viewport.maxDepth = 1.0f;
1890 viewport.minDepth = 0.0f;
1891 viewport.width = 512;
1892 viewport.height = 512;
1893 viewport.x = 0;
1894 viewport.y = 0;
1895 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
1896 vkEndCommandBuffer(command_buffer[1]);
1897 }
1898 {
1899 VkSubmitInfo submit_info[2];
1900 VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT};
1901
1902 submit_info[0].sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
1903 submit_info[0].pNext = NULL;
1904 submit_info[0].commandBufferCount = 1;
1905 submit_info[0].pCommandBuffers = &command_buffer[0];
1906 submit_info[0].signalSemaphoreCount = 1;
1907 submit_info[0].pSignalSemaphores = &semaphore;
1908 submit_info[0].waitSemaphoreCount = 0;
1909 submit_info[0].pWaitSemaphores = NULL;
1910 submit_info[0].pWaitDstStageMask = 0;
1911
1912 submit_info[1].sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
1913 submit_info[1].pNext = NULL;
1914 submit_info[1].commandBufferCount = 1;
1915 submit_info[1].pCommandBuffers = &command_buffer[1];
1916 submit_info[1].waitSemaphoreCount = 1;
1917 submit_info[1].pWaitSemaphores = &semaphore;
1918 submit_info[1].pWaitDstStageMask = flags;
1919 submit_info[1].signalSemaphoreCount = 0;
1920 submit_info[1].pSignalSemaphores = NULL;
1921 vkQueueSubmit(m_device->m_queue, 2, &submit_info[0], fence);
1922 }
1923
1924 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
1925
1926 vkDestroyFence(m_device->device(), fence, nullptr);
1927 vkFreeCommandBuffers(m_device->device(), command_pool, 2,
1928 &command_buffer[0]);
1929 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
1930
1931 m_errorMonitor->VerifyNotFound();
1932}
1933
Karl Schultz6addd812016-02-02 17:17:23 -07001934TEST_F(VkLayerTest, LineWidthStateNotBound) {
1935 m_errorMonitor->SetDesiredFailureMsg(
1936 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06001937 "Dynamic line width state not set for this command buffer");
1938
Karl Schultz6addd812016-02-02 17:17:23 -07001939 TEST_DESCRIPTION("Simple Draw Call that validates failure when a line "
1940 "width state object is not bound beforehand");
Tobin Ehlis963a4042015-09-29 08:18:34 -06001941
Karl Schultz6addd812016-02-02 17:17:23 -07001942 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText,
1943 BsoFailLineWidth);
Tobin Ehlis963a4042015-09-29 08:18:34 -06001944
Chris Forbes8f36a8a2016-04-07 13:21:07 +12001945 m_errorMonitor->VerifyFound();
Tobin Ehlis963a4042015-09-29 08:18:34 -06001946}
1947
Karl Schultz6addd812016-02-02 17:17:23 -07001948TEST_F(VkLayerTest, DepthBiasStateNotBound) {
1949 m_errorMonitor->SetDesiredFailureMsg(
1950 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06001951 "Dynamic depth bias state not set for this command buffer");
1952
Karl Schultz6addd812016-02-02 17:17:23 -07001953 TEST_DESCRIPTION("Simple Draw Call that validates failure when a depth "
1954 "bias state object is not bound beforehand");
Tobin Ehlis963a4042015-09-29 08:18:34 -06001955
Karl Schultz6addd812016-02-02 17:17:23 -07001956 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText,
1957 BsoFailDepthBias);
Tobin Ehlis963a4042015-09-29 08:18:34 -06001958
Chris Forbes8f36a8a2016-04-07 13:21:07 +12001959 m_errorMonitor->VerifyFound();
Tobin Ehlis963a4042015-09-29 08:18:34 -06001960}
1961
Karl Schultz6addd812016-02-02 17:17:23 -07001962// Disable these two tests until we can sort out how to track multiple layer
1963// errors
1964TEST_F(VkLayerTest, ViewportStateNotBound) {
1965 m_errorMonitor->SetDesiredFailureMsg(
1966 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06001967 "Dynamic viewport state not set for this command buffer");
1968
Karl Schultz6addd812016-02-02 17:17:23 -07001969 TEST_DESCRIPTION("Simple Draw Call that validates failure when a viewport "
1970 "state object is not bound beforehand");
Tobin Ehlis963a4042015-09-29 08:18:34 -06001971
Karl Schultz6addd812016-02-02 17:17:23 -07001972 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText,
1973 BsoFailViewport);
Tobin Ehlis963a4042015-09-29 08:18:34 -06001974
Chris Forbes8f36a8a2016-04-07 13:21:07 +12001975 m_errorMonitor->VerifyFound();
Tobin Ehlis963a4042015-09-29 08:18:34 -06001976}
1977
Karl Schultz6addd812016-02-02 17:17:23 -07001978TEST_F(VkLayerTest, ScissorStateNotBound) {
1979 m_errorMonitor->SetDesiredFailureMsg(
1980 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06001981 "Dynamic scissor state not set for this command buffer");
1982
Karl Schultz6addd812016-02-02 17:17:23 -07001983 TEST_DESCRIPTION("Simple Draw Call that validates failure when a viewport "
1984 "state object is not bound beforehand");
Tobin Ehlis963a4042015-09-29 08:18:34 -06001985
Karl Schultz6addd812016-02-02 17:17:23 -07001986 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText,
1987 BsoFailScissor);
Tobin Ehlis963a4042015-09-29 08:18:34 -06001988
Chris Forbes8f36a8a2016-04-07 13:21:07 +12001989 m_errorMonitor->VerifyFound();
Tobin Ehlis963a4042015-09-29 08:18:34 -06001990}
1991
Karl Schultz6addd812016-02-02 17:17:23 -07001992TEST_F(VkLayerTest, BlendStateNotBound) {
1993 m_errorMonitor->SetDesiredFailureMsg(
1994 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis7a1d2352016-03-28 11:18:19 -06001995 "Dynamic blend constants state not set for this command buffer");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06001996
Karl Schultz6addd812016-02-02 17:17:23 -07001997 TEST_DESCRIPTION("Simple Draw Call that validates failure when a blend "
1998 "state object is not bound beforehand");
Tobin Ehlis963a4042015-09-29 08:18:34 -06001999
Karl Schultz6addd812016-02-02 17:17:23 -07002000 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText,
2001 BsoFailBlend);
Tobin Ehlis963a4042015-09-29 08:18:34 -06002002
Chris Forbes8f36a8a2016-04-07 13:21:07 +12002003 m_errorMonitor->VerifyFound();
Tobin Ehlis963a4042015-09-29 08:18:34 -06002004}
2005
Karl Schultz6addd812016-02-02 17:17:23 -07002006TEST_F(VkLayerTest, DepthBoundsStateNotBound) {
2007 m_errorMonitor->SetDesiredFailureMsg(
2008 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002009 "Dynamic depth bounds state not set for this command buffer");
2010
Karl Schultz6addd812016-02-02 17:17:23 -07002011 TEST_DESCRIPTION("Simple Draw Call that validates failure when a depth "
2012 "bounds state object is not bound beforehand");
Tobin Ehlis963a4042015-09-29 08:18:34 -06002013
Karl Schultz6addd812016-02-02 17:17:23 -07002014 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText,
2015 BsoFailDepthBounds);
Tobin Ehlis963a4042015-09-29 08:18:34 -06002016
Chris Forbes8f36a8a2016-04-07 13:21:07 +12002017 m_errorMonitor->VerifyFound();
Tobin Ehlis963a4042015-09-29 08:18:34 -06002018}
2019
Karl Schultz6addd812016-02-02 17:17:23 -07002020TEST_F(VkLayerTest, StencilReadMaskNotSet) {
2021 m_errorMonitor->SetDesiredFailureMsg(
2022 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002023 "Dynamic stencil read mask state not set for this command buffer");
2024
Tobin Ehlis963a4042015-09-29 08:18:34 -06002025 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002026
Karl Schultz6addd812016-02-02 17:17:23 -07002027 TEST_DESCRIPTION("Simple Draw Call that validates failure when a stencil "
2028 "read mask is not set beforehand");
Tobin Ehlis963a4042015-09-29 08:18:34 -06002029
Karl Schultz6addd812016-02-02 17:17:23 -07002030 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText,
2031 BsoFailStencilReadMask);
Tobin Ehlis963a4042015-09-29 08:18:34 -06002032
Chris Forbes8f36a8a2016-04-07 13:21:07 +12002033 m_errorMonitor->VerifyFound();
Tobin Ehlis963a4042015-09-29 08:18:34 -06002034}
2035
Karl Schultz6addd812016-02-02 17:17:23 -07002036TEST_F(VkLayerTest, StencilWriteMaskNotSet) {
2037 m_errorMonitor->SetDesiredFailureMsg(
2038 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002039 "Dynamic stencil write mask state not set for this command buffer");
2040
Tobin Ehlis963a4042015-09-29 08:18:34 -06002041 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002042
Karl Schultz6addd812016-02-02 17:17:23 -07002043 TEST_DESCRIPTION("Simple Draw Call that validates failure when a stencil "
2044 "write mask is not set beforehand");
Tobin Ehlis963a4042015-09-29 08:18:34 -06002045
Karl Schultz6addd812016-02-02 17:17:23 -07002046 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText,
2047 BsoFailStencilWriteMask);
Tobin Ehlis963a4042015-09-29 08:18:34 -06002048
Chris Forbes8f36a8a2016-04-07 13:21:07 +12002049 m_errorMonitor->VerifyFound();
Tobin Ehlis963a4042015-09-29 08:18:34 -06002050}
2051
Karl Schultz6addd812016-02-02 17:17:23 -07002052TEST_F(VkLayerTest, StencilReferenceNotSet) {
2053 m_errorMonitor->SetDesiredFailureMsg(
2054 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002055 "Dynamic stencil reference state not set for this command buffer");
2056
Karl Schultz6addd812016-02-02 17:17:23 -07002057 TEST_DESCRIPTION("Simple Draw Call that validates failure when a stencil "
2058 "reference is not set beforehand");
Tobin Ehlis963a4042015-09-29 08:18:34 -06002059
Karl Schultz6addd812016-02-02 17:17:23 -07002060 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText,
2061 BsoFailStencilReference);
Tobin Ehlis963a4042015-09-29 08:18:34 -06002062
Chris Forbes8f36a8a2016-04-07 13:21:07 +12002063 m_errorMonitor->VerifyFound();
Tobin Ehlis963a4042015-09-29 08:18:34 -06002064}
2065
Karl Schultz6addd812016-02-02 17:17:23 -07002066TEST_F(VkLayerTest, CommandBufferTwoSubmits) {
Tobin Ehlis59278bf2015-08-18 07:10:58 -06002067 vk_testing::Fence testFence;
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002068
Karl Schultz6addd812016-02-02 17:17:23 -07002069 m_errorMonitor->SetDesiredFailureMsg(
2070 VK_DEBUG_REPORT_ERROR_BIT_EXT,
2071 "was begun w/ VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT set, but has "
2072 "been submitted");
Tobin Ehlis59278bf2015-08-18 07:10:58 -06002073
2074 VkFenceCreateInfo fenceInfo = {};
2075 fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
2076 fenceInfo.pNext = NULL;
2077 fenceInfo.flags = 0;
2078
2079 ASSERT_NO_FATAL_FAILURE(InitState());
2080 ASSERT_NO_FATAL_FAILURE(InitViewport());
2081 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
2082
Karl Schultz6addd812016-02-02 17:17:23 -07002083 // We luck out b/c by default the framework creates CB w/ the
2084 // VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT set
Tobin Ehlis59278bf2015-08-18 07:10:58 -06002085 BeginCommandBuffer();
Karl Schultz6addd812016-02-02 17:17:23 -07002086 m_commandBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color,
2087 m_stencil_clear_color, NULL);
Tobin Ehlis59278bf2015-08-18 07:10:58 -06002088 EndCommandBuffer();
2089
2090 testFence.init(*m_device, fenceInfo);
2091
2092 // Bypass framework since it does the waits automatically
2093 VkResult err = VK_SUCCESS;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06002094 VkSubmitInfo submit_info;
Chia-I Wuf9be13c2015-10-26 20:37:06 +08002095 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
2096 submit_info.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08002097 submit_info.waitSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06002098 submit_info.pWaitSemaphores = NULL;
Jon Ashburn7f9716c2015-12-30 16:42:50 -07002099 submit_info.pWaitDstStageMask = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08002100 submit_info.commandBufferCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002101 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Chia-I Wud50a7d72015-10-26 20:48:51 +08002102 submit_info.signalSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06002103 submit_info.pSignalSemaphores = NULL;
2104
Karl Schultz6addd812016-02-02 17:17:23 -07002105 err = vkQueueSubmit(m_device->m_queue, 1, &submit_info, testFence.handle());
2106 ASSERT_VK_SUCCESS(err);
Tobin Ehlis59278bf2015-08-18 07:10:58 -06002107
Karl Schultz6addd812016-02-02 17:17:23 -07002108 // Cause validation error by re-submitting cmd buffer that should only be
2109 // submitted once
2110 err = vkQueueSubmit(m_device->m_queue, 1, &submit_info, testFence.handle());
Tobin Ehlis59278bf2015-08-18 07:10:58 -06002111
Chris Forbes8f36a8a2016-04-07 13:21:07 +12002112 m_errorMonitor->VerifyFound();
Tobin Ehlis59278bf2015-08-18 07:10:58 -06002113}
2114
Karl Schultz6addd812016-02-02 17:17:23 -07002115TEST_F(VkLayerTest, AllocDescriptorFromEmptyPool) {
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06002116 // Initiate Draw w/o a PSO bound
Karl Schultz6addd812016-02-02 17:17:23 -07002117 VkResult err;
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06002118
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07002119 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Karl Schultz6addd812016-02-02 17:17:23 -07002120 "Unable to allocate 1 descriptors of "
2121 "type "
2122 "VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002123
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06002124 ASSERT_NO_FATAL_FAILURE(InitState());
2125 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06002126
Karl Schultz6addd812016-02-02 17:17:23 -07002127 // Create Pool w/ 1 Sampler descriptor, but try to alloc Uniform Buffer
2128 // descriptor from it
Chia-I Wu1b99bb22015-10-27 19:25:11 +08002129 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002130 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLER;
2131 ds_type_count.descriptorCount = 1;
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06002132
2133 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002134 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
2135 ds_pool_ci.pNext = NULL;
2136 ds_pool_ci.flags = 0;
2137 ds_pool_ci.maxSets = 1;
2138 ds_pool_ci.poolSizeCount = 1;
2139 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06002140
2141 VkDescriptorPool ds_pool;
Karl Schultz6addd812016-02-02 17:17:23 -07002142 err =
2143 vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06002144 ASSERT_VK_SUCCESS(err);
2145
2146 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002147 dsl_binding.binding = 0;
2148 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
2149 dsl_binding.descriptorCount = 1;
2150 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
2151 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06002152
2153 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002154 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
2155 ds_layout_ci.pNext = NULL;
2156 ds_layout_ci.bindingCount = 1;
2157 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06002158
2159 VkDescriptorSetLayout ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07002160 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
2161 &ds_layout);
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06002162 ASSERT_VK_SUCCESS(err);
2163
2164 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002165 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08002166 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07002167 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06002168 alloc_info.descriptorPool = ds_pool;
2169 alloc_info.pSetLayouts = &ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07002170 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info,
2171 &descriptorSet);
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06002172
Chris Forbes8f36a8a2016-04-07 13:21:07 +12002173 m_errorMonitor->VerifyFound();
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06002174
Chia-I Wuf7458c52015-10-26 21:10:41 +08002175 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
2176 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06002177}
2178
Karl Schultz6addd812016-02-02 17:17:23 -07002179TEST_F(VkLayerTest, FreeDescriptorFromOneShotPool) {
2180 VkResult err;
Tobin Ehlise735c692015-10-08 13:13:50 -06002181
Karl Schultz6addd812016-02-02 17:17:23 -07002182 m_errorMonitor->SetDesiredFailureMsg(
2183 VK_DEBUG_REPORT_ERROR_BIT_EXT,
2184 "It is invalid to call vkFreeDescriptorSets() with a pool created "
2185 "without setting VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002186
Tobin Ehlise735c692015-10-08 13:13:50 -06002187 ASSERT_NO_FATAL_FAILURE(InitState());
2188 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlise735c692015-10-08 13:13:50 -06002189
Chia-I Wu1b99bb22015-10-27 19:25:11 +08002190 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002191 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
2192 ds_type_count.descriptorCount = 1;
Tobin Ehlise735c692015-10-08 13:13:50 -06002193
2194 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002195 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
2196 ds_pool_ci.pNext = NULL;
2197 ds_pool_ci.maxSets = 1;
2198 ds_pool_ci.poolSizeCount = 1;
2199 ds_pool_ci.flags = 0;
2200 // Not specifying VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT means
2201 // app can only call vkResetDescriptorPool on this pool.;
2202 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlise735c692015-10-08 13:13:50 -06002203
2204 VkDescriptorPool ds_pool;
Karl Schultz6addd812016-02-02 17:17:23 -07002205 err =
2206 vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlise735c692015-10-08 13:13:50 -06002207 ASSERT_VK_SUCCESS(err);
2208
2209 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002210 dsl_binding.binding = 0;
2211 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
2212 dsl_binding.descriptorCount = 1;
2213 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
2214 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlise735c692015-10-08 13:13:50 -06002215
2216 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002217 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
2218 ds_layout_ci.pNext = NULL;
2219 ds_layout_ci.bindingCount = 1;
2220 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlise735c692015-10-08 13:13:50 -06002221
2222 VkDescriptorSetLayout ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07002223 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
2224 &ds_layout);
Tobin Ehlise735c692015-10-08 13:13:50 -06002225 ASSERT_VK_SUCCESS(err);
2226
2227 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002228 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08002229 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07002230 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06002231 alloc_info.descriptorPool = ds_pool;
2232 alloc_info.pSetLayouts = &ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07002233 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info,
2234 &descriptorSet);
Tobin Ehlise735c692015-10-08 13:13:50 -06002235 ASSERT_VK_SUCCESS(err);
2236
2237 err = vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptorSet);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12002238 m_errorMonitor->VerifyFound();
Tobin Ehlise735c692015-10-08 13:13:50 -06002239
Chia-I Wuf7458c52015-10-26 21:10:41 +08002240 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
2241 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlise735c692015-10-08 13:13:50 -06002242}
2243
Karl Schultz6addd812016-02-02 17:17:23 -07002244TEST_F(VkLayerTest, InvalidDescriptorPool) {
Karl Schultzbdb75952016-04-19 11:36:49 -06002245 // Attempt to clear Descriptor Pool with bad object.
2246 // ObjectTracker should catch this.
2247 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
2248 "Invalid VkDescriptorPool Object 0xbaad6001");
2249 VkDescriptorPool badPool = (VkDescriptorPool)0xbaad6001;
2250 vkResetDescriptorPool(device(), badPool, 0);
2251 m_errorMonitor->VerifyFound();
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06002252}
2253
Karl Schultz6addd812016-02-02 17:17:23 -07002254TEST_F(VkLayerTest, InvalidDescriptorSet) {
Karl Schultzbdb75952016-04-19 11:36:49 -06002255 // Attempt to bind an invalid Descriptor Set to a valid Command Buffer
2256 // ObjectTracker should catch this.
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06002257 // Create a valid cmd buffer
Karl Schultzbdb75952016-04-19 11:36:49 -06002258 // call vkCmdBindDescriptorSets w/ false Descriptor Set
2259 VkDescriptorSet badSet = (VkDescriptorSet)0xbaad6001;
2260 VkResult err;
2261 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
2262 "Invalid VkDescriptorSet Object 0xbaad6001");
2263
2264 ASSERT_NO_FATAL_FAILURE(InitState());
2265
2266 VkDescriptorSetLayoutBinding layout_bindings[1] = {};
2267 layout_bindings[0].binding = 0;
2268 layout_bindings[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
2269 layout_bindings[0].descriptorCount = 1;
2270 layout_bindings[0].stageFlags = VK_SHADER_STAGE_VERTEX_BIT;
2271 layout_bindings[0].pImmutableSamplers = NULL;
2272
2273 VkDescriptorSetLayout descriptor_set_layout;
2274 VkDescriptorSetLayoutCreateInfo dslci = {};
2275 dslci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
2276 dslci.pNext = NULL;
2277 dslci.bindingCount = 1;
2278 dslci.pBindings = layout_bindings;
2279 err = vkCreateDescriptorSetLayout(device(), &dslci, NULL, &descriptor_set_layout);
2280 assert(!err);
2281
2282 VkPipelineLayout pipeline_layout;
2283 VkPipelineLayoutCreateInfo plci = {};
2284 plci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
2285 plci.pNext = NULL;
2286 plci.setLayoutCount = 1;
2287 plci.pSetLayouts = &descriptor_set_layout;
2288 err = vkCreatePipelineLayout(device(), &plci, NULL, &pipeline_layout);
2289 assert(!err);
2290
2291 BeginCommandBuffer();
2292 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS,
2293 pipeline_layout, 0, 1, &badSet, 0, NULL);
2294 m_errorMonitor->VerifyFound();
2295 EndCommandBuffer();
2296 vkDestroyPipelineLayout(device(), pipeline_layout, NULL);
2297 vkDestroyDescriptorSetLayout(device(), descriptor_set_layout, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06002298}
2299
Karl Schultz6addd812016-02-02 17:17:23 -07002300TEST_F(VkLayerTest, InvalidDescriptorSetLayout) {
Karl Schultzbdb75952016-04-19 11:36:49 -06002301 // Attempt to create a Pipeline Layout with an invalid Descriptor Set Layout.
2302 // ObjectTracker should catch this.
2303 VkDescriptorSetLayout bad_layout = (VkDescriptorSetLayout)0xbaad6001;
2304 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
2305 "Invalid VkDescriptorSetLayout Object 0xbaad6001");
2306
2307 VkPipelineLayout pipeline_layout;
2308 VkPipelineLayoutCreateInfo plci = {};
2309 plci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
2310 plci.pNext = NULL;
2311 plci.setLayoutCount = 1;
2312 plci.pSetLayouts = &bad_layout;
2313 vkCreatePipelineLayout(device(), &plci, NULL, &pipeline_layout);
2314
2315 m_errorMonitor->VerifyFound();
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06002316}
2317
Karl Schultz6addd812016-02-02 17:17:23 -07002318TEST_F(VkLayerTest, InvalidPipeline) {
Karl Schultzbdb75952016-04-19 11:36:49 -06002319 // Attempt to bind an invalid Pipeline to a valid Command Buffer
2320 // ObjectTracker should catch this.
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06002321 // Create a valid cmd buffer
2322 // call vkCmdBindPipeline w/ false Pipeline
Karl Schultzbdb75952016-04-19 11:36:49 -06002323 VkPipeline bad_pipeline = (VkPipeline)0xbaad6001;
2324 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
2325 "Invalid VkPipeline Object 0xbaad6001");
2326 ASSERT_NO_FATAL_FAILURE(InitState());
2327 BeginCommandBuffer();
2328 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(),
2329 VK_PIPELINE_BIND_POINT_GRAPHICS, bad_pipeline);
2330 m_errorMonitor->VerifyFound();
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06002331}
2332
Karl Schultz6addd812016-02-02 17:17:23 -07002333TEST_F(VkLayerTest, DescriptorSetNotUpdated) {
2334 // Create and update CommandBuffer then call QueueSubmit w/o calling End on
2335 // CommandBuffer
2336 VkResult err;
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06002337
Mark Lobodzinski510e20d2016-02-11 09:26:16 -07002338 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT,
Karl Schultz6addd812016-02-02 17:17:23 -07002339 " bound but it was never updated. ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002340
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06002341 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyan713b2d72015-08-04 10:49:29 -06002342 ASSERT_NO_FATAL_FAILURE(InitViewport());
2343 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chia-I Wu1b99bb22015-10-27 19:25:11 +08002344 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002345 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
2346 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06002347
2348 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002349 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
2350 ds_pool_ci.pNext = NULL;
2351 ds_pool_ci.maxSets = 1;
2352 ds_pool_ci.poolSizeCount = 1;
2353 ds_pool_ci.pPoolSizes = &ds_type_count;
Mike Stroyan713b2d72015-08-04 10:49:29 -06002354
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06002355 VkDescriptorPool ds_pool;
Karl Schultz6addd812016-02-02 17:17:23 -07002356 err =
2357 vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06002358 ASSERT_VK_SUCCESS(err);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06002359
Tony Barboureb254902015-07-15 12:50:33 -06002360 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002361 dsl_binding.binding = 0;
2362 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
2363 dsl_binding.descriptorCount = 1;
2364 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
2365 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06002366
Tony Barboureb254902015-07-15 12:50:33 -06002367 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002368 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
2369 ds_layout_ci.pNext = NULL;
2370 ds_layout_ci.bindingCount = 1;
2371 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06002372 VkDescriptorSetLayout ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07002373 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
2374 &ds_layout);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06002375 ASSERT_VK_SUCCESS(err);
2376
2377 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002378 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08002379 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07002380 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06002381 alloc_info.descriptorPool = ds_pool;
2382 alloc_info.pSetLayouts = &ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07002383 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info,
2384 &descriptorSet);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06002385 ASSERT_VK_SUCCESS(err);
2386
Tony Barboureb254902015-07-15 12:50:33 -06002387 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002388 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
2389 pipeline_layout_ci.pNext = NULL;
2390 pipeline_layout_ci.setLayoutCount = 1;
2391 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06002392
2393 VkPipelineLayout pipeline_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07002394 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL,
2395 &pipeline_layout);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06002396 ASSERT_VK_SUCCESS(err);
2397
Karl Schultz6addd812016-02-02 17:17:23 -07002398 VkShaderObj vs(m_device, bindStateVertShaderText,
2399 VK_SHADER_STAGE_VERTEX_BIT, this);
Karl Schultzbdb75952016-04-19 11:36:49 -06002400 // We shouldn't need a fragment shader but add it to be able to run
Karl Schultz6addd812016-02-02 17:17:23 -07002401 // on more devices
2402 VkShaderObj fs(m_device, bindStateFragShaderText,
2403 VK_SHADER_STAGE_FRAGMENT_BIT, this);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06002404
Tony Barbourc95e4ac2015-08-04 17:05:26 -06002405 VkPipelineObj pipe(m_device);
2406 pipe.AddShader(&vs);
Tony Barbour1c94d372015-08-06 11:21:08 -06002407 pipe.AddShader(&fs);
Mark Youngc89c6312016-03-31 16:03:20 -06002408 pipe.AddColorAttachment();
Tony Barbourc95e4ac2015-08-04 17:05:26 -06002409 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tony Barbourfe3351b2015-07-28 10:17:20 -06002410
2411 BeginCommandBuffer();
Karl Schultz6addd812016-02-02 17:17:23 -07002412 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(),
2413 VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
2414 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(),
2415 VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0,
2416 1, &descriptorSet, 0, NULL);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06002417
Chris Forbes8f36a8a2016-04-07 13:21:07 +12002418 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06002419
Chia-I Wuf7458c52015-10-26 21:10:41 +08002420 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
2421 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
2422 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06002423}
2424
Karl Schultz6addd812016-02-02 17:17:23 -07002425TEST_F(VkLayerTest, InvalidBufferViewObject) {
Tobin Ehlisba31cab2015-11-02 15:24:32 -07002426 // Create a single TEXEL_BUFFER descriptor and send it an invalid bufferView
Karl Schultz6addd812016-02-02 17:17:23 -07002427 VkResult err;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07002428
Karl Schultz6addd812016-02-02 17:17:23 -07002429 m_errorMonitor->SetDesiredFailureMsg(
2430 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlisba31cab2015-11-02 15:24:32 -07002431 "Attempt to update descriptor with invalid bufferView ");
2432
2433 ASSERT_NO_FATAL_FAILURE(InitState());
2434 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002435 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER;
2436 ds_type_count.descriptorCount = 1;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07002437
2438 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002439 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
2440 ds_pool_ci.pNext = NULL;
2441 ds_pool_ci.maxSets = 1;
2442 ds_pool_ci.poolSizeCount = 1;
2443 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07002444
2445 VkDescriptorPool ds_pool;
Karl Schultz6addd812016-02-02 17:17:23 -07002446 err =
2447 vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisba31cab2015-11-02 15:24:32 -07002448 ASSERT_VK_SUCCESS(err);
2449
2450 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002451 dsl_binding.binding = 0;
2452 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER;
2453 dsl_binding.descriptorCount = 1;
2454 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
2455 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07002456
2457 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002458 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
2459 ds_layout_ci.pNext = NULL;
2460 ds_layout_ci.bindingCount = 1;
2461 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07002462 VkDescriptorSetLayout ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07002463 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
2464 &ds_layout);
Tobin Ehlisba31cab2015-11-02 15:24:32 -07002465 ASSERT_VK_SUCCESS(err);
2466
2467 VkDescriptorSet descriptorSet;
2468 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08002469 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07002470 alloc_info.descriptorSetCount = 1;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07002471 alloc_info.descriptorPool = ds_pool;
2472 alloc_info.pSetLayouts = &ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07002473 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info,
2474 &descriptorSet);
Tobin Ehlisba31cab2015-11-02 15:24:32 -07002475 ASSERT_VK_SUCCESS(err);
2476
Karl Schultz6addd812016-02-02 17:17:23 -07002477 VkBufferView view =
2478 (VkBufferView)((size_t)0xbaadbeef); // invalid bufferView object
Tobin Ehlisba31cab2015-11-02 15:24:32 -07002479 VkWriteDescriptorSet descriptor_write;
2480 memset(&descriptor_write, 0, sizeof(descriptor_write));
2481 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
2482 descriptor_write.dstSet = descriptorSet;
2483 descriptor_write.dstBinding = 0;
2484 descriptor_write.descriptorCount = 1;
2485 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER;
2486 descriptor_write.pTexelBufferView = &view;
2487
2488 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
2489
Chris Forbes8f36a8a2016-04-07 13:21:07 +12002490 m_errorMonitor->VerifyFound();
Tobin Ehlisba31cab2015-11-02 15:24:32 -07002491
2492 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
2493 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
2494}
2495
Karl Schultz6addd812016-02-02 17:17:23 -07002496TEST_F(VkLayerTest, InvalidDynamicOffsetCases) {
2497 // Create a descriptorSet w/ dynamic descriptor and then hit 3 offset error
2498 // cases:
Tobin Ehlisf6585052015-12-17 11:48:42 -07002499 // 1. No dynamicOffset supplied
2500 // 2. Too many dynamicOffsets supplied
2501 // 3. Dynamic offset oversteps buffer being updated
Karl Schultz6addd812016-02-02 17:17:23 -07002502 VkResult err;
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07002503 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Karl Schultz6addd812016-02-02 17:17:23 -07002504 " requires 1 dynamicOffsets, but only "
2505 "0 dynamicOffsets are left in "
2506 "pDynamicOffsets ");
Tobin Ehlis49f903e2015-11-04 13:30:34 -07002507
2508 ASSERT_NO_FATAL_FAILURE(InitState());
2509 ASSERT_NO_FATAL_FAILURE(InitViewport());
2510 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
2511
2512 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002513 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
2514 ds_type_count.descriptorCount = 1;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07002515
2516 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002517 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
2518 ds_pool_ci.pNext = NULL;
2519 ds_pool_ci.maxSets = 1;
2520 ds_pool_ci.poolSizeCount = 1;
2521 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07002522
2523 VkDescriptorPool ds_pool;
Karl Schultz6addd812016-02-02 17:17:23 -07002524 err =
2525 vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07002526 ASSERT_VK_SUCCESS(err);
2527
2528 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002529 dsl_binding.binding = 0;
2530 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
2531 dsl_binding.descriptorCount = 1;
2532 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
2533 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07002534
2535 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002536 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
2537 ds_layout_ci.pNext = NULL;
2538 ds_layout_ci.bindingCount = 1;
2539 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07002540 VkDescriptorSetLayout ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07002541 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
2542 &ds_layout);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07002543 ASSERT_VK_SUCCESS(err);
2544
2545 VkDescriptorSet descriptorSet;
2546 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08002547 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07002548 alloc_info.descriptorSetCount = 1;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07002549 alloc_info.descriptorPool = ds_pool;
2550 alloc_info.pSetLayouts = &ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07002551 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info,
2552 &descriptorSet);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07002553 ASSERT_VK_SUCCESS(err);
2554
2555 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002556 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
2557 pipeline_layout_ci.pNext = NULL;
2558 pipeline_layout_ci.setLayoutCount = 1;
2559 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07002560
2561 VkPipelineLayout pipeline_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07002562 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL,
2563 &pipeline_layout);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07002564 ASSERT_VK_SUCCESS(err);
2565
2566 // Create a buffer to update the descriptor with
2567 uint32_t qfi = 0;
2568 VkBufferCreateInfo buffCI = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002569 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
2570 buffCI.size = 1024;
2571 buffCI.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
2572 buffCI.queueFamilyIndexCount = 1;
2573 buffCI.pQueueFamilyIndices = &qfi;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07002574
2575 VkBuffer dyub;
2576 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &dyub);
2577 ASSERT_VK_SUCCESS(err);
2578 // Correctly update descriptor to avoid "NOT_UPDATED" error
2579 VkDescriptorBufferInfo buffInfo = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002580 buffInfo.buffer = dyub;
2581 buffInfo.offset = 0;
2582 buffInfo.range = 1024;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07002583
2584 VkWriteDescriptorSet descriptor_write;
2585 memset(&descriptor_write, 0, sizeof(descriptor_write));
2586 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
2587 descriptor_write.dstSet = descriptorSet;
2588 descriptor_write.dstBinding = 0;
2589 descriptor_write.descriptorCount = 1;
2590 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
2591 descriptor_write.pBufferInfo = &buffInfo;
2592
2593 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
2594
2595 BeginCommandBuffer();
Karl Schultz6addd812016-02-02 17:17:23 -07002596 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(),
2597 VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0,
2598 1, &descriptorSet, 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12002599 m_errorMonitor->VerifyFound();
Tobin Ehlisf6585052015-12-17 11:48:42 -07002600 uint32_t pDynOff[2] = {512, 756};
2601 // Now cause error b/c too many dynOffsets in array for # of dyn descriptors
Karl Schultz6addd812016-02-02 17:17:23 -07002602 m_errorMonitor->SetDesiredFailureMsg(
2603 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlisf6585052015-12-17 11:48:42 -07002604 "Attempting to bind 1 descriptorSets with 1 dynamic descriptors, but ");
Karl Schultz6addd812016-02-02 17:17:23 -07002605 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(),
2606 VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0,
2607 1, &descriptorSet, 2, pDynOff);
Chris Forbes7b342802016-04-07 13:20:10 +12002608 m_errorMonitor->VerifyFound();
Tobin Ehlisf6585052015-12-17 11:48:42 -07002609 // Finally cause error due to dynamicOffset being too big
Karl Schultz6addd812016-02-02 17:17:23 -07002610 m_errorMonitor->SetDesiredFailureMsg(
2611 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlisf6585052015-12-17 11:48:42 -07002612 " from its update, this oversteps its buffer (");
2613 // Create PSO to be used for draw-time errors below
2614 char const *vsSource =
Chris Forbes7b342802016-04-07 13:20:10 +12002615 "#version 450\n"
Tobin Ehlisf6585052015-12-17 11:48:42 -07002616 "\n"
Tony Barboure804d202016-01-05 13:37:45 -07002617 "out gl_PerVertex { \n"
2618 " vec4 gl_Position;\n"
2619 "};\n"
Tobin Ehlisf6585052015-12-17 11:48:42 -07002620 "void main(){\n"
2621 " gl_Position = vec4(1);\n"
2622 "}\n";
2623 char const *fsSource =
Chris Forbes7b342802016-04-07 13:20:10 +12002624 "#version 450\n"
Tobin Ehlisf6585052015-12-17 11:48:42 -07002625 "\n"
2626 "layout(location=0) out vec4 x;\n"
2627 "layout(set=0) layout(binding=0) uniform foo { int x; int y; } bar;\n"
2628 "void main(){\n"
2629 " x = vec4(bar.y);\n"
2630 "}\n";
2631 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
2632 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
2633 VkPipelineObj pipe(m_device);
2634 pipe.AddShader(&vs);
2635 pipe.AddShader(&fs);
2636 pipe.AddColorAttachment();
2637 pipe.CreateVKPipeline(pipeline_layout, renderPass());
2638
Karl Schultz6addd812016-02-02 17:17:23 -07002639 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(),
2640 VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
2641 // This update should succeed, but offset size of 512 will overstep buffer
2642 // /w range 1024 & size 1024
2643 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(),
2644 VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0,
2645 1, &descriptorSet, 1, pDynOff);
Tobin Ehlisf6585052015-12-17 11:48:42 -07002646 Draw(1, 0, 0, 0);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12002647 m_errorMonitor->VerifyFound();
Tobin Ehlis49f903e2015-11-04 13:30:34 -07002648
2649 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
2650 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
2651}
2652
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07002653TEST_F(VkLayerTest, InvalidPushConstants) {
2654 // Hit push constant error cases:
2655 // 1. Create PipelineLayout where push constant overstep maxPushConstantSize
2656 // 2. Incorrectly set push constant size to 0
2657 // 3. Incorrectly set push constant size to non-multiple of 4
2658 // 4. Attempt push constant update that exceeds maxPushConstantSize
2659 VkResult err;
2660 m_errorMonitor->SetDesiredFailureMsg(
2661 VK_DEBUG_REPORT_ERROR_BIT_EXT,
2662 "vkCreatePipelineLayout() call has push constants with offset ");
2663
2664 ASSERT_NO_FATAL_FAILURE(InitState());
2665 ASSERT_NO_FATAL_FAILURE(InitViewport());
2666 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
2667
2668 VkPushConstantRange pc_range = {};
2669 pc_range.size = 0xFFFFFFFFu;
2670 pc_range.stageFlags = VK_SHADER_STAGE_VERTEX_BIT;
2671 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
2672 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
2673 pipeline_layout_ci.pushConstantRangeCount = 1;
2674 pipeline_layout_ci.pPushConstantRanges = &pc_range;
2675
2676 VkPipelineLayout pipeline_layout;
2677 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL,
2678 &pipeline_layout);
2679
Chris Forbes8f36a8a2016-04-07 13:21:07 +12002680 m_errorMonitor->VerifyFound();
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07002681 // Now cause errors due to size 0 and non-4 byte aligned size
2682 pc_range.size = 0;
2683 m_errorMonitor->SetDesiredFailureMsg(
2684 VK_DEBUG_REPORT_ERROR_BIT_EXT,
2685 "vkCreatePipelineLayout() call has push constant index 0 with size 0");
2686 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL,
2687 &pipeline_layout);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12002688 m_errorMonitor->VerifyFound();
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07002689 pc_range.size = 1;
2690 m_errorMonitor->SetDesiredFailureMsg(
2691 VK_DEBUG_REPORT_ERROR_BIT_EXT,
2692 "vkCreatePipelineLayout() call has push constant index 0 with size 1");
2693 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL,
2694 &pipeline_layout);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12002695 m_errorMonitor->VerifyFound();
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07002696 // Cause error due to bad size in vkCmdPushConstants() call
2697 m_errorMonitor->SetDesiredFailureMsg(
2698 VK_DEBUG_REPORT_ERROR_BIT_EXT,
2699 "vkCmdPushConstants() call has push constants with offset ");
2700 pipeline_layout_ci.pushConstantRangeCount = 0;
2701 pipeline_layout_ci.pPushConstantRanges = NULL;
2702 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL,
2703 &pipeline_layout);
2704 ASSERT_VK_SUCCESS(err);
2705 BeginCommandBuffer();
2706 vkCmdPushConstants(m_commandBuffer->GetBufferHandle(), pipeline_layout,
2707 VK_SHADER_STAGE_VERTEX_BIT, 0, 0xFFFFFFFFu, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12002708 m_errorMonitor->VerifyFound();
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07002709 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
2710}
2711
Karl Schultz6addd812016-02-02 17:17:23 -07002712TEST_F(VkLayerTest, DescriptorSetCompatibility) {
Tobin Ehlis559c6382015-11-05 09:52:49 -07002713 // Test various desriptorSet errors with bad binding combinations
Karl Schultz6addd812016-02-02 17:17:23 -07002714 VkResult err;
Tobin Ehlis559c6382015-11-05 09:52:49 -07002715
2716 ASSERT_NO_FATAL_FAILURE(InitState());
2717 ASSERT_NO_FATAL_FAILURE(InitViewport());
2718 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
2719
2720 static const uint32_t NUM_DESCRIPTOR_TYPES = 5;
2721 VkDescriptorPoolSize ds_type_count[NUM_DESCRIPTOR_TYPES] = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002722 ds_type_count[0].type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
2723 ds_type_count[0].descriptorCount = 10;
2724 ds_type_count[1].type = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
2725 ds_type_count[1].descriptorCount = 2;
2726 ds_type_count[2].type = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE;
2727 ds_type_count[2].descriptorCount = 2;
2728 ds_type_count[3].type = VK_DESCRIPTOR_TYPE_SAMPLER;
2729 ds_type_count[3].descriptorCount = 5;
2730 // TODO : LunarG ILO driver currently asserts in desc.c w/ INPUT_ATTACHMENT
2731 // type
2732 // ds_type_count[4].type = VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT;
2733 ds_type_count[4].type = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
2734 ds_type_count[4].descriptorCount = 2;
Tobin Ehlis559c6382015-11-05 09:52:49 -07002735
2736 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002737 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
2738 ds_pool_ci.pNext = NULL;
2739 ds_pool_ci.maxSets = 5;
2740 ds_pool_ci.poolSizeCount = NUM_DESCRIPTOR_TYPES;
2741 ds_pool_ci.pPoolSizes = ds_type_count;
Tobin Ehlis559c6382015-11-05 09:52:49 -07002742
2743 VkDescriptorPool ds_pool;
Karl Schultz6addd812016-02-02 17:17:23 -07002744 err =
2745 vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis559c6382015-11-05 09:52:49 -07002746 ASSERT_VK_SUCCESS(err);
2747
2748 static const uint32_t MAX_DS_TYPES_IN_LAYOUT = 2;
2749 VkDescriptorSetLayoutBinding dsl_binding[MAX_DS_TYPES_IN_LAYOUT] = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002750 dsl_binding[0].binding = 0;
2751 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
2752 dsl_binding[0].descriptorCount = 5;
2753 dsl_binding[0].stageFlags = VK_SHADER_STAGE_ALL;
2754 dsl_binding[0].pImmutableSamplers = NULL;
Tobin Ehlis559c6382015-11-05 09:52:49 -07002755
Tobin Ehlis8fab6562015-12-01 09:57:09 -07002756 // Create layout identical to set0 layout but w/ different stageFlags
2757 VkDescriptorSetLayoutBinding dsl_fs_stage_only = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002758 dsl_fs_stage_only.binding = 0;
2759 dsl_fs_stage_only.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
2760 dsl_fs_stage_only.descriptorCount = 5;
2761 dsl_fs_stage_only.stageFlags =
2762 VK_SHADER_STAGE_FRAGMENT_BIT; // Different stageFlags to cause error at
2763 // bind time
2764 dsl_fs_stage_only.pImmutableSamplers = NULL;
Tobin Ehlis559c6382015-11-05 09:52:49 -07002765 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002766 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
2767 ds_layout_ci.pNext = NULL;
2768 ds_layout_ci.bindingCount = 1;
2769 ds_layout_ci.pBindings = dsl_binding;
Tobin Ehlis559c6382015-11-05 09:52:49 -07002770 static const uint32_t NUM_LAYOUTS = 4;
2771 VkDescriptorSetLayout ds_layout[NUM_LAYOUTS] = {};
Tobin Ehlis8fab6562015-12-01 09:57:09 -07002772 VkDescriptorSetLayout ds_layout_fs_only = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002773 // Create 4 unique layouts for full pipelineLayout, and 1 special fs-only
2774 // layout for error case
2775 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
2776 &ds_layout[0]);
Tobin Ehlis559c6382015-11-05 09:52:49 -07002777 ASSERT_VK_SUCCESS(err);
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07002778 ds_layout_ci.pBindings = &dsl_fs_stage_only;
Karl Schultz6addd812016-02-02 17:17:23 -07002779 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
2780 &ds_layout_fs_only);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07002781 ASSERT_VK_SUCCESS(err);
Tobin Ehlis559c6382015-11-05 09:52:49 -07002782 dsl_binding[0].binding = 0;
2783 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07002784 dsl_binding[0].descriptorCount = 2;
Mike Stroyan9c70cdb2016-01-06 14:14:17 -07002785 dsl_binding[1].binding = 1;
2786 dsl_binding[1].descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE;
2787 dsl_binding[1].descriptorCount = 2;
2788 dsl_binding[1].stageFlags = VK_SHADER_STAGE_ALL;
2789 dsl_binding[1].pImmutableSamplers = NULL;
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07002790 ds_layout_ci.pBindings = dsl_binding;
Tobin Ehlis559c6382015-11-05 09:52:49 -07002791 ds_layout_ci.bindingCount = 2;
Karl Schultz6addd812016-02-02 17:17:23 -07002792 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
2793 &ds_layout[1]);
Tobin Ehlis559c6382015-11-05 09:52:49 -07002794 ASSERT_VK_SUCCESS(err);
2795 dsl_binding[0].binding = 0;
2796 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07002797 dsl_binding[0].descriptorCount = 5;
Tobin Ehlis559c6382015-11-05 09:52:49 -07002798 ds_layout_ci.bindingCount = 1;
Karl Schultz6addd812016-02-02 17:17:23 -07002799 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
2800 &ds_layout[2]);
Tobin Ehlis559c6382015-11-05 09:52:49 -07002801 ASSERT_VK_SUCCESS(err);
2802 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07002803 dsl_binding[0].descriptorCount = 2;
Karl Schultz6addd812016-02-02 17:17:23 -07002804 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
2805 &ds_layout[3]);
Tobin Ehlis559c6382015-11-05 09:52:49 -07002806 ASSERT_VK_SUCCESS(err);
2807
2808 static const uint32_t NUM_SETS = 4;
2809 VkDescriptorSet descriptorSet[NUM_SETS] = {};
2810 VkDescriptorSetAllocateInfo alloc_info = {};
Tobin Ehlis8fab6562015-12-01 09:57:09 -07002811 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07002812 alloc_info.descriptorSetCount = NUM_LAYOUTS;
Tobin Ehlis559c6382015-11-05 09:52:49 -07002813 alloc_info.descriptorPool = ds_pool;
2814 alloc_info.pSetLayouts = ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07002815 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info,
2816 descriptorSet);
Tobin Ehlis559c6382015-11-05 09:52:49 -07002817 ASSERT_VK_SUCCESS(err);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07002818 VkDescriptorSet ds0_fs_only = {};
Jon Ashburnf19916e2016-01-11 13:12:43 -07002819 alloc_info.descriptorSetCount = 1;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07002820 alloc_info.pSetLayouts = &ds_layout_fs_only;
Karl Schultz6addd812016-02-02 17:17:23 -07002821 err =
2822 vkAllocateDescriptorSets(m_device->device(), &alloc_info, &ds0_fs_only);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07002823 ASSERT_VK_SUCCESS(err);
Tobin Ehlis559c6382015-11-05 09:52:49 -07002824
2825 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002826 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
2827 pipeline_layout_ci.pNext = NULL;
2828 pipeline_layout_ci.setLayoutCount = NUM_LAYOUTS;
2829 pipeline_layout_ci.pSetLayouts = ds_layout;
Tobin Ehlis559c6382015-11-05 09:52:49 -07002830
2831 VkPipelineLayout pipeline_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07002832 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL,
2833 &pipeline_layout);
Tobin Ehlis559c6382015-11-05 09:52:49 -07002834 ASSERT_VK_SUCCESS(err);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07002835 // Create pipelineLayout with only one setLayout
2836 pipeline_layout_ci.setLayoutCount = 1;
2837 VkPipelineLayout single_pipe_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07002838 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL,
2839 &single_pipe_layout);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07002840 ASSERT_VK_SUCCESS(err);
2841 // Create pipelineLayout with 2 descriptor setLayout at index 0
2842 pipeline_layout_ci.pSetLayouts = &ds_layout[3];
2843 VkPipelineLayout pipe_layout_one_desc;
Karl Schultz6addd812016-02-02 17:17:23 -07002844 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL,
2845 &pipe_layout_one_desc);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07002846 ASSERT_VK_SUCCESS(err);
2847 // Create pipelineLayout with 5 SAMPLER descriptor setLayout at index 0
2848 pipeline_layout_ci.pSetLayouts = &ds_layout[2];
2849 VkPipelineLayout pipe_layout_five_samp;
Karl Schultz6addd812016-02-02 17:17:23 -07002850 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL,
2851 &pipe_layout_five_samp);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07002852 ASSERT_VK_SUCCESS(err);
2853 // Create pipelineLayout with UB type, but stageFlags for FS only
2854 pipeline_layout_ci.pSetLayouts = &ds_layout_fs_only;
2855 VkPipelineLayout pipe_layout_fs_only;
Karl Schultz6addd812016-02-02 17:17:23 -07002856 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL,
2857 &pipe_layout_fs_only);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07002858 ASSERT_VK_SUCCESS(err);
2859 // Create pipelineLayout w/ incompatible set0 layout, but set1 is fine
2860 VkDescriptorSetLayout pl_bad_s0[2] = {};
2861 pl_bad_s0[0] = ds_layout_fs_only;
2862 pl_bad_s0[1] = ds_layout[1];
2863 pipeline_layout_ci.setLayoutCount = 2;
2864 pipeline_layout_ci.pSetLayouts = pl_bad_s0;
2865 VkPipelineLayout pipe_layout_bad_set0;
Karl Schultz6addd812016-02-02 17:17:23 -07002866 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL,
2867 &pipe_layout_bad_set0);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07002868 ASSERT_VK_SUCCESS(err);
Tobin Ehlis559c6382015-11-05 09:52:49 -07002869
2870 // Create a buffer to update the descriptor with
2871 uint32_t qfi = 0;
2872 VkBufferCreateInfo buffCI = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002873 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
2874 buffCI.size = 1024;
2875 buffCI.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
2876 buffCI.queueFamilyIndexCount = 1;
2877 buffCI.pQueueFamilyIndices = &qfi;
Tobin Ehlis559c6382015-11-05 09:52:49 -07002878
2879 VkBuffer dyub;
2880 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &dyub);
2881 ASSERT_VK_SUCCESS(err);
2882 // Correctly update descriptor to avoid "NOT_UPDATED" error
2883 static const uint32_t NUM_BUFFS = 5;
2884 VkDescriptorBufferInfo buffInfo[NUM_BUFFS] = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002885 for (uint32_t i = 0; i < NUM_BUFFS; ++i) {
Tobin Ehlis559c6382015-11-05 09:52:49 -07002886 buffInfo[i].buffer = dyub;
2887 buffInfo[i].offset = 0;
2888 buffInfo[i].range = 1024;
2889 }
Karl Schultz6addd812016-02-02 17:17:23 -07002890 VkImage image;
2891 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
2892 const int32_t tex_width = 32;
2893 const int32_t tex_height = 32;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07002894 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002895 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
2896 image_create_info.pNext = NULL;
2897 image_create_info.imageType = VK_IMAGE_TYPE_2D;
2898 image_create_info.format = tex_format;
2899 image_create_info.extent.width = tex_width;
2900 image_create_info.extent.height = tex_height;
2901 image_create_info.extent.depth = 1;
2902 image_create_info.mipLevels = 1;
2903 image_create_info.arrayLayers = 1;
2904 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
2905 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
2906 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
2907 image_create_info.flags = 0;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07002908 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
2909 ASSERT_VK_SUCCESS(err);
Tobin Ehlis559c6382015-11-05 09:52:49 -07002910
Karl Schultz6addd812016-02-02 17:17:23 -07002911 VkMemoryRequirements memReqs;
2912 VkDeviceMemory imageMem;
2913 bool pass;
Mike Stroyan9c70cdb2016-01-06 14:14:17 -07002914 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002915 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
2916 memAlloc.pNext = NULL;
2917 memAlloc.allocationSize = 0;
2918 memAlloc.memoryTypeIndex = 0;
Mike Stroyan9c70cdb2016-01-06 14:14:17 -07002919 vkGetImageMemoryRequirements(m_device->device(), image, &memReqs);
2920 memAlloc.allocationSize = memReqs.size;
Karl Schultz6addd812016-02-02 17:17:23 -07002921 pass =
2922 m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Mike Stroyan9c70cdb2016-01-06 14:14:17 -07002923 ASSERT_TRUE(pass);
2924 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &imageMem);
2925 ASSERT_VK_SUCCESS(err);
2926 err = vkBindImageMemory(m_device->device(), image, imageMem, 0);
2927 ASSERT_VK_SUCCESS(err);
2928
Tobin Ehlis8fab6562015-12-01 09:57:09 -07002929 VkImageViewCreateInfo image_view_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002930 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
2931 image_view_create_info.image = image;
2932 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
2933 image_view_create_info.format = tex_format;
2934 image_view_create_info.subresourceRange.layerCount = 1;
2935 image_view_create_info.subresourceRange.baseMipLevel = 0;
2936 image_view_create_info.subresourceRange.levelCount = 1;
2937 image_view_create_info.subresourceRange.aspectMask =
2938 VK_IMAGE_ASPECT_COLOR_BIT;
Tobin Ehlis559c6382015-11-05 09:52:49 -07002939
Tobin Ehlis8fab6562015-12-01 09:57:09 -07002940 VkImageView view;
Karl Schultz6addd812016-02-02 17:17:23 -07002941 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL,
2942 &view);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07002943 ASSERT_VK_SUCCESS(err);
Tobin Ehlis991d45a2016-01-06 08:48:41 -07002944 VkDescriptorImageInfo imageInfo[4] = {};
Tobin Ehlis8fab6562015-12-01 09:57:09 -07002945 imageInfo[0].imageView = view;
2946 imageInfo[0].imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
2947 imageInfo[1].imageView = view;
2948 imageInfo[1].imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
Tobin Ehlis991d45a2016-01-06 08:48:41 -07002949 imageInfo[2].imageView = view;
2950 imageInfo[2].imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
2951 imageInfo[3].imageView = view;
2952 imageInfo[3].imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07002953
2954 static const uint32_t NUM_SET_UPDATES = 3;
2955 VkWriteDescriptorSet descriptor_write[NUM_SET_UPDATES] = {};
2956 descriptor_write[0].sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
2957 descriptor_write[0].dstSet = descriptorSet[0];
2958 descriptor_write[0].dstBinding = 0;
2959 descriptor_write[0].descriptorCount = 5;
2960 descriptor_write[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
2961 descriptor_write[0].pBufferInfo = buffInfo;
2962 descriptor_write[1].sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
2963 descriptor_write[1].dstSet = descriptorSet[1];
2964 descriptor_write[1].dstBinding = 0;
2965 descriptor_write[1].descriptorCount = 2;
2966 descriptor_write[1].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
2967 descriptor_write[1].pImageInfo = imageInfo;
2968 descriptor_write[2].sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
2969 descriptor_write[2].dstSet = descriptorSet[1];
2970 descriptor_write[2].dstBinding = 1;
2971 descriptor_write[2].descriptorCount = 2;
2972 descriptor_write[2].descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE;
Tobin Ehlis991d45a2016-01-06 08:48:41 -07002973 descriptor_write[2].pImageInfo = &imageInfo[2];
Tobin Ehlis8fab6562015-12-01 09:57:09 -07002974
2975 vkUpdateDescriptorSets(m_device->device(), 3, descriptor_write, 0, NULL);
Tobin Ehlis559c6382015-11-05 09:52:49 -07002976
Tobin Ehlis88452832015-12-03 09:40:56 -07002977 // Create PSO to be used for draw-time errors below
2978 char const *vsSource =
Chris Forbes7b342802016-04-07 13:20:10 +12002979 "#version 450\n"
Tobin Ehlis88452832015-12-03 09:40:56 -07002980 "\n"
Tony Barboure804d202016-01-05 13:37:45 -07002981 "out gl_PerVertex {\n"
2982 " vec4 gl_Position;\n"
2983 "};\n"
Tobin Ehlis88452832015-12-03 09:40:56 -07002984 "void main(){\n"
2985 " gl_Position = vec4(1);\n"
2986 "}\n";
2987 char const *fsSource =
Chris Forbes7b342802016-04-07 13:20:10 +12002988 "#version 450\n"
Tobin Ehlis88452832015-12-03 09:40:56 -07002989 "\n"
2990 "layout(location=0) out vec4 x;\n"
2991 "layout(set=0) layout(binding=0) uniform foo { int x; int y; } bar;\n"
2992 "void main(){\n"
2993 " x = vec4(bar.y);\n"
2994 "}\n";
2995 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
2996 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Tobin Ehlis559c6382015-11-05 09:52:49 -07002997 VkPipelineObj pipe(m_device);
2998 pipe.AddShader(&vs);
2999 pipe.AddShader(&fs);
Tobin Ehlis88452832015-12-03 09:40:56 -07003000 pipe.AddColorAttachment();
3001 pipe.CreateVKPipeline(pipe_layout_fs_only, renderPass());
Tobin Ehlis559c6382015-11-05 09:52:49 -07003002
3003 BeginCommandBuffer();
Tobin Ehlis88452832015-12-03 09:40:56 -07003004
Karl Schultz6addd812016-02-02 17:17:23 -07003005 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(),
3006 VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
3007 // NOTE : I believe LunarG ilo driver has bug (LX#189) that requires binding
3008 // of PSO
3009 // here before binding DSs. Otherwise we assert in cmd_copy_dset_data() of
3010 // cmd_pipeline.c
3011 // due to the fact that cmd_alloc_dset_data() has not been called in
3012 // cmd_bind_graphics_pipeline()
3013 // TODO : Want to cause various binding incompatibility issues here to test
3014 // DrawState
Tobin Ehlis559c6382015-11-05 09:52:49 -07003015 // First cause various verify_layout_compatibility() fails
3016 // Second disturb early and late sets and verify INFO msgs
Tobin Ehlis8fab6562015-12-01 09:57:09 -07003017 // verify_set_layout_compatibility fail cases:
3018 // 1. invalid VkPipelineLayout (layout) passed into vkCmdBindDescriptorSets
Karl Schultz6addd812016-02-02 17:17:23 -07003019 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3020 " due to: invalid VkPipelineLayout ");
3021 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(),
3022 VK_PIPELINE_BIND_POINT_GRAPHICS,
3023 (VkPipelineLayout)((size_t)0xbaadb1be), 0, 1,
3024 &descriptorSet[0], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12003025 m_errorMonitor->VerifyFound();
3026
Tobin Ehlis8fab6562015-12-01 09:57:09 -07003027 // 2. layoutIndex exceeds # of layouts in layout
Karl Schultz6addd812016-02-02 17:17:23 -07003028 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3029 " attempting to bind set to index 1");
3030 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(),
3031 VK_PIPELINE_BIND_POINT_GRAPHICS, single_pipe_layout,
3032 0, 2, &descriptorSet[0], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12003033 m_errorMonitor->VerifyFound();
3034
Tobin Ehlis8fab6562015-12-01 09:57:09 -07003035 vkDestroyPipelineLayout(m_device->device(), single_pipe_layout, NULL);
Karl Schultz6addd812016-02-02 17:17:23 -07003036 // 3. Pipeline setLayout[0] has 2 descriptors, but set being bound has 5
3037 // descriptors
3038 m_errorMonitor->SetDesiredFailureMsg(
3039 VK_DEBUG_REPORT_ERROR_BIT_EXT,
3040 ", but corresponding set being bound has 5 descriptors.");
3041 vkCmdBindDescriptorSets(
3042 m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS,
3043 pipe_layout_one_desc, 0, 1, &descriptorSet[0], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12003044 m_errorMonitor->VerifyFound();
3045
Tobin Ehlis8fab6562015-12-01 09:57:09 -07003046 vkDestroyPipelineLayout(m_device->device(), pipe_layout_one_desc, NULL);
3047 // 4. same # of descriptors but mismatch in type
Karl Schultz6addd812016-02-02 17:17:23 -07003048 m_errorMonitor->SetDesiredFailureMsg(
3049 VK_DEBUG_REPORT_ERROR_BIT_EXT,
3050 " descriptor from pipelineLayout is type 'VK_DESCRIPTOR_TYPE_SAMPLER'");
3051 vkCmdBindDescriptorSets(
3052 m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS,
3053 pipe_layout_five_samp, 0, 1, &descriptorSet[0], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12003054 m_errorMonitor->VerifyFound();
3055
Tobin Ehlis8fab6562015-12-01 09:57:09 -07003056 vkDestroyPipelineLayout(m_device->device(), pipe_layout_five_samp, NULL);
3057 // 5. same # of descriptors but mismatch in stageFlags
Karl Schultz6addd812016-02-02 17:17:23 -07003058 m_errorMonitor->SetDesiredFailureMsg(
3059 VK_DEBUG_REPORT_ERROR_BIT_EXT,
3060 " descriptor from pipelineLayout has stageFlags ");
3061 vkCmdBindDescriptorSets(
3062 m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS,
3063 pipe_layout_fs_only, 0, 1, &descriptorSet[0], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12003064 m_errorMonitor->VerifyFound();
3065
Tobin Ehlis8fab6562015-12-01 09:57:09 -07003066 // Cause INFO messages due to disturbing previously bound Sets
3067 // First bind sets 0 & 1
Karl Schultz6addd812016-02-02 17:17:23 -07003068 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(),
3069 VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0,
3070 2, &descriptorSet[0], 0, NULL);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07003071 // 1. Disturb bound set0 by re-binding set1 w/ updated pipelineLayout
Karl Schultz6addd812016-02-02 17:17:23 -07003072 m_errorMonitor->SetDesiredFailureMsg(
Mark Lobodzinski510e20d2016-02-11 09:26:16 -07003073 VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
Karl Schultz6addd812016-02-02 17:17:23 -07003074 " previously bound as set #0 was disturbed ");
3075 vkCmdBindDescriptorSets(
3076 m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS,
3077 pipe_layout_bad_set0, 1, 1, &descriptorSet[1], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12003078 m_errorMonitor->VerifyFound();
3079
Karl Schultz6addd812016-02-02 17:17:23 -07003080 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(),
3081 VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0,
3082 2, &descriptorSet[0], 0, NULL);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07003083 // 2. Disturb set after last bound set
Mark Lobodzinski510e20d2016-02-11 09:26:16 -07003084 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
Karl Schultz6addd812016-02-02 17:17:23 -07003085 " newly bound as set #0 so set #1 and "
3086 "any subsequent sets were disturbed ");
3087 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(),
3088 VK_PIPELINE_BIND_POINT_GRAPHICS,
3089 pipe_layout_fs_only, 0, 1, &ds0_fs_only, 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12003090 m_errorMonitor->VerifyFound();
3091
Tobin Ehlis88452832015-12-03 09:40:56 -07003092 // Cause draw-time errors due to PSO incompatibilities
Karl Schultz6addd812016-02-02 17:17:23 -07003093 // 1. Error due to not binding required set (we actually use same code as
3094 // above to disturb set0)
3095 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(),
3096 VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0,
3097 2, &descriptorSet[0], 0, NULL);
3098 vkCmdBindDescriptorSets(
3099 m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS,
3100 pipe_layout_bad_set0, 1, 1, &descriptorSet[1], 0, NULL);
3101 m_errorMonitor->SetDesiredFailureMsg(
3102 VK_DEBUG_REPORT_ERROR_BIT_EXT,
3103 " uses set #0 but that set is not bound.");
Tobin Ehlis88452832015-12-03 09:40:56 -07003104 Draw(1, 0, 0, 0);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12003105 m_errorMonitor->VerifyFound();
3106
Tobin Ehlis991d45a2016-01-06 08:48:41 -07003107 vkDestroyPipelineLayout(m_device->device(), pipe_layout_bad_set0, NULL);
Karl Schultz6addd812016-02-02 17:17:23 -07003108 // 2. Error due to bound set not being compatible with PSO's
3109 // VkPipelineLayout (diff stageFlags in this case)
3110 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(),
3111 VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0,
3112 2, &descriptorSet[0], 0, NULL);
3113 m_errorMonitor->SetDesiredFailureMsg(
3114 VK_DEBUG_REPORT_ERROR_BIT_EXT,
3115 " bound as set #0 is not compatible with ");
Tobin Ehlis88452832015-12-03 09:40:56 -07003116 Draw(1, 0, 0, 0);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12003117 m_errorMonitor->VerifyFound();
3118
Tobin Ehlis8fab6562015-12-01 09:57:09 -07003119 // Remaining clean-up
3120 vkDestroyPipelineLayout(m_device->device(), pipe_layout_fs_only, NULL);
Karl Schultz6addd812016-02-02 17:17:23 -07003121 for (uint32_t i = 0; i < NUM_LAYOUTS; ++i) {
Tobin Ehlis8fab6562015-12-01 09:57:09 -07003122 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout[i], NULL);
3123 }
3124 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout_fs_only, NULL);
3125 vkFreeDescriptorSets(m_device->device(), ds_pool, 1, descriptorSet);
3126 vkDestroyBuffer(m_device->device(), dyub, NULL);
Tobin Ehlis559c6382015-11-05 09:52:49 -07003127 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
3128 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
3129}
Tobin Ehlis559c6382015-11-05 09:52:49 -07003130
Karl Schultz6addd812016-02-02 17:17:23 -07003131TEST_F(VkLayerTest, NoBeginCommandBuffer) {
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06003132
Karl Schultz6addd812016-02-02 17:17:23 -07003133 m_errorMonitor->SetDesiredFailureMsg(
3134 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06003135 "You must call vkBeginCommandBuffer() before this call to ");
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06003136
3137 ASSERT_NO_FATAL_FAILURE(InitState());
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003138 VkCommandBufferObj commandBuffer(m_device, m_commandPool);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06003139 // Call EndCommandBuffer() w/o calling BeginCommandBuffer()
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003140 vkEndCommandBuffer(commandBuffer.GetBufferHandle());
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06003141
Chris Forbes8f36a8a2016-04-07 13:21:07 +12003142 m_errorMonitor->VerifyFound();
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06003143}
3144
Karl Schultz6addd812016-02-02 17:17:23 -07003145TEST_F(VkLayerTest, SecondaryCommandBufferNullRenderpass) {
3146 VkResult err;
3147 VkCommandBuffer draw_cmd;
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06003148
Karl Schultz6addd812016-02-02 17:17:23 -07003149 m_errorMonitor->SetDesiredFailureMsg(
3150 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis61b36f32015-12-16 08:19:42 -07003151 " must specify a valid renderpass parameter.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06003152
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06003153 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06003154
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003155 VkCommandBufferAllocateInfo cmd = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08003156 cmd.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
Cody Northropb4569702015-08-04 17:35:57 -06003157 cmd.pNext = NULL;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003158 cmd.commandPool = m_commandPool;
3159 cmd.level = VK_COMMAND_BUFFER_LEVEL_SECONDARY;
Jon Ashburnf19916e2016-01-11 13:12:43 -07003160 cmd.commandBufferCount = 1;
Cody Northropb4569702015-08-04 17:35:57 -06003161
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003162 err = vkAllocateCommandBuffers(m_device->device(), &cmd, &draw_cmd);
Mike Stroyand1c84a52015-08-18 14:40:24 -06003163 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06003164
3165 // Force the failure by not setting the Renderpass and Framebuffer fields
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003166 VkCommandBufferBeginInfo cmd_buf_info = {};
Jon Ashburnf19916e2016-01-11 13:12:43 -07003167 VkCommandBufferInheritanceInfo cmd_buf_hinfo = {};
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003168 cmd_buf_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
Cody Northropb4569702015-08-04 17:35:57 -06003169 cmd_buf_info.pNext = NULL;
Karl Schultz6addd812016-02-02 17:17:23 -07003170 cmd_buf_info.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT |
3171 VK_COMMAND_BUFFER_USAGE_RENDER_PASS_CONTINUE_BIT;
Jon Ashburnf19916e2016-01-11 13:12:43 -07003172 cmd_buf_info.pInheritanceInfo = &cmd_buf_hinfo;
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06003173
3174 // The error should be caught by validation of the BeginCommandBuffer call
3175 vkBeginCommandBuffer(draw_cmd, &cmd_buf_info);
3176
Chris Forbes8f36a8a2016-04-07 13:21:07 +12003177 m_errorMonitor->VerifyFound();
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003178 vkFreeCommandBuffers(m_device->device(), m_commandPool, 1, &draw_cmd);
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06003179}
3180
Karl Schultz6addd812016-02-02 17:17:23 -07003181TEST_F(VkLayerTest, CommandBufferResetErrors) {
Tobin Ehlisac0ef842015-12-14 13:46:38 -07003182 // Cause error due to Begin while recording CB
3183 // Then cause 2 errors for attempting to reset CB w/o having
3184 // VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT set for the pool from
3185 // which CBs were allocated. Note that this bit is off by default.
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07003186 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Karl Schultz6addd812016-02-02 17:17:23 -07003187 "Cannot call Begin on CB");
Tobin Ehlisac0ef842015-12-14 13:46:38 -07003188
3189 ASSERT_NO_FATAL_FAILURE(InitState());
3190
3191 // Calls AllocateCommandBuffers
3192 VkCommandBufferObj commandBuffer(m_device, m_commandPool);
3193
Karl Schultz6addd812016-02-02 17:17:23 -07003194 // Force the failure by setting the Renderpass and Framebuffer fields with
3195 // (fake) data
Tobin Ehlisac0ef842015-12-14 13:46:38 -07003196 VkCommandBufferBeginInfo cmd_buf_info = {};
Jon Ashburnf19916e2016-01-11 13:12:43 -07003197 VkCommandBufferInheritanceInfo cmd_buf_hinfo = {};
Tobin Ehlisac0ef842015-12-14 13:46:38 -07003198 cmd_buf_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
3199 cmd_buf_info.pNext = NULL;
3200 cmd_buf_info.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT;
Jon Ashburnf19916e2016-01-11 13:12:43 -07003201 cmd_buf_info.pInheritanceInfo = &cmd_buf_hinfo;
Tobin Ehlisac0ef842015-12-14 13:46:38 -07003202
3203 // Begin CB to transition to recording state
3204 vkBeginCommandBuffer(commandBuffer.GetBufferHandle(), &cmd_buf_info);
3205 // Can't re-begin. This should trigger error
3206 vkBeginCommandBuffer(commandBuffer.GetBufferHandle(), &cmd_buf_info);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12003207 m_errorMonitor->VerifyFound();
3208
Karl Schultz6addd812016-02-02 17:17:23 -07003209 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3210 "Attempt to reset command buffer ");
Tobin Ehlisac0ef842015-12-14 13:46:38 -07003211 VkCommandBufferResetFlags flags = 0; // Don't care about flags for this test
3212 // Reset attempt will trigger error due to incorrect CommandPool state
3213 vkResetCommandBuffer(commandBuffer.GetBufferHandle(), flags);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12003214 m_errorMonitor->VerifyFound();
3215
Karl Schultz6addd812016-02-02 17:17:23 -07003216 m_errorMonitor->SetDesiredFailureMsg(
3217 VK_DEBUG_REPORT_ERROR_BIT_EXT,
3218 " attempts to implicitly reset cmdBuffer created from ");
Tobin Ehlisac0ef842015-12-14 13:46:38 -07003219 // Transition CB to RECORDED state
3220 vkEndCommandBuffer(commandBuffer.GetBufferHandle());
3221 // Now attempting to Begin will implicitly reset, which triggers error
3222 vkBeginCommandBuffer(commandBuffer.GetBufferHandle(), &cmd_buf_info);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12003223 m_errorMonitor->VerifyFound();
Tobin Ehlisac0ef842015-12-14 13:46:38 -07003224}
3225
Karl Schultz6addd812016-02-02 17:17:23 -07003226TEST_F(VkLayerTest, InvalidPipelineCreateState) {
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06003227 // Attempt to Create Gfx Pipeline w/o a VS
Karl Schultz6addd812016-02-02 17:17:23 -07003228 VkResult err;
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06003229
Karl Schultz6addd812016-02-02 17:17:23 -07003230 m_errorMonitor->SetDesiredFailureMsg(
3231 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06003232 "Invalid Pipeline CreateInfo State: Vtx Shader required");
3233
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06003234 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06003235 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinski209b5292015-09-17 09:44:05 -06003236
Chia-I Wu1b99bb22015-10-27 19:25:11 +08003237 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07003238 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
3239 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06003240
3241 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07003242 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
3243 ds_pool_ci.pNext = NULL;
3244 ds_pool_ci.maxSets = 1;
3245 ds_pool_ci.poolSizeCount = 1;
3246 ds_pool_ci.pPoolSizes = &ds_type_count;
Mark Lobodzinski209b5292015-09-17 09:44:05 -06003247
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06003248 VkDescriptorPool ds_pool;
Karl Schultz6addd812016-02-02 17:17:23 -07003249 err =
3250 vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06003251 ASSERT_VK_SUCCESS(err);
3252
Tony Barboureb254902015-07-15 12:50:33 -06003253 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07003254 dsl_binding.binding = 0;
3255 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
3256 dsl_binding.descriptorCount = 1;
3257 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
3258 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06003259
Tony Barboureb254902015-07-15 12:50:33 -06003260 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07003261 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
3262 ds_layout_ci.pNext = NULL;
3263 ds_layout_ci.bindingCount = 1;
3264 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -06003265
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06003266 VkDescriptorSetLayout ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07003267 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
3268 &ds_layout);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06003269 ASSERT_VK_SUCCESS(err);
3270
3271 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003272 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08003273 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07003274 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06003275 alloc_info.descriptorPool = ds_pool;
3276 alloc_info.pSetLayouts = &ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07003277 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info,
3278 &descriptorSet);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06003279 ASSERT_VK_SUCCESS(err);
3280
Tony Barboureb254902015-07-15 12:50:33 -06003281 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07003282 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
3283 pipeline_layout_ci.setLayoutCount = 1;
3284 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06003285
3286 VkPipelineLayout pipeline_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07003287 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL,
3288 &pipeline_layout);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06003289 ASSERT_VK_SUCCESS(err);
3290
Tobin Ehlise68360f2015-10-01 11:15:13 -06003291 VkViewport vp = {}; // Just need dummy vp to point to
Karl Schultz6addd812016-02-02 17:17:23 -07003292 VkRect2D sc = {}; // dummy scissor to point to
Tobin Ehlise68360f2015-10-01 11:15:13 -06003293
3294 VkPipelineViewportStateCreateInfo vp_state_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07003295 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
3296 vp_state_ci.scissorCount = 1;
3297 vp_state_ci.pScissors = &sc;
3298 vp_state_ci.viewportCount = 1;
3299 vp_state_ci.pViewports = &vp;
Tobin Ehlise68360f2015-10-01 11:15:13 -06003300
Karl Schultzdfdb8d42016-03-08 10:30:21 -07003301 VkPipelineRasterizationStateCreateInfo rs_state_ci = {};
3302 rs_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
3303 rs_state_ci.polygonMode = VK_POLYGON_MODE_FILL;
3304 rs_state_ci.cullMode = VK_CULL_MODE_BACK_BIT;
3305 rs_state_ci.frontFace = VK_FRONT_FACE_COUNTER_CLOCKWISE;
3306 rs_state_ci.depthClampEnable = VK_FALSE;
3307 rs_state_ci.rasterizerDiscardEnable = VK_FALSE;
3308 rs_state_ci.depthBiasEnable = VK_FALSE;
3309
Tony Barboureb254902015-07-15 12:50:33 -06003310 VkGraphicsPipelineCreateInfo gp_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07003311 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
3312 gp_ci.pViewportState = &vp_state_ci;
Karl Schultzdfdb8d42016-03-08 10:30:21 -07003313 gp_ci.pRasterizationState = &rs_state_ci;
Karl Schultz6addd812016-02-02 17:17:23 -07003314 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
3315 gp_ci.layout = pipeline_layout;
3316 gp_ci.renderPass = renderPass();
Tony Barboureb254902015-07-15 12:50:33 -06003317
3318 VkPipelineCacheCreateInfo pc_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07003319 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
3320 pc_ci.initialDataSize = 0;
3321 pc_ci.pInitialData = 0;
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06003322
3323 VkPipeline pipeline;
Jon Ashburnc669cc62015-07-09 15:02:25 -06003324 VkPipelineCache pipelineCache;
3325
Karl Schultz6addd812016-02-02 17:17:23 -07003326 err =
3327 vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Jon Ashburnc669cc62015-07-09 15:02:25 -06003328 ASSERT_VK_SUCCESS(err);
Karl Schultz6addd812016-02-02 17:17:23 -07003329 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1,
3330 &gp_ci, NULL, &pipeline);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06003331
Chris Forbes8f36a8a2016-04-07 13:21:07 +12003332 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06003333
Chia-I Wuf7458c52015-10-26 21:10:41 +08003334 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
3335 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
3336 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
3337 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06003338}
Tobin Ehlis912df022015-09-17 08:46:18 -06003339/*// TODO : This test should be good, but needs Tess support in compiler to run
3340TEST_F(VkLayerTest, InvalidPatchControlPoints)
3341{
3342 // Attempt to Create Gfx Pipeline w/o a VS
Tobin Ehlis912df022015-09-17 08:46:18 -06003343 VkResult err;
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06003344
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07003345 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Karl Schultz6addd812016-02-02 17:17:23 -07003346 "Invalid Pipeline CreateInfo State: VK_PRIMITIVE_TOPOLOGY_PATCH
3347primitive ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06003348
Tobin Ehlis912df022015-09-17 08:46:18 -06003349 ASSERT_NO_FATAL_FAILURE(InitState());
3350 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlis912df022015-09-17 08:46:18 -06003351
Chia-I Wu1b99bb22015-10-27 19:25:11 +08003352 VkDescriptorPoolSize ds_type_count = {};
Tobin Ehlis912df022015-09-17 08:46:18 -06003353 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wud50a7d72015-10-26 20:48:51 +08003354 ds_type_count.descriptorCount = 1;
Tobin Ehlis912df022015-09-17 08:46:18 -06003355
3356 VkDescriptorPoolCreateInfo ds_pool_ci = {};
3357 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
3358 ds_pool_ci.pNext = NULL;
Chia-I Wu1b99bb22015-10-27 19:25:11 +08003359 ds_pool_ci.poolSizeCount = 1;
3360 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlis912df022015-09-17 08:46:18 -06003361
3362 VkDescriptorPool ds_pool;
Karl Schultz6addd812016-02-02 17:17:23 -07003363 err = vkCreateDescriptorPool(m_device->device(),
3364VK_DESCRIPTOR_POOL_USAGE_NON_FREE, 1, &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis912df022015-09-17 08:46:18 -06003365 ASSERT_VK_SUCCESS(err);
3366
3367 VkDescriptorSetLayoutBinding dsl_binding = {};
Chia-I Wud46e6ae2015-10-31 00:31:16 +08003368 dsl_binding.binding = 0;
Tobin Ehlis912df022015-09-17 08:46:18 -06003369 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wu02124482015-11-06 06:42:02 +08003370 dsl_binding.descriptorCount = 1;
Tobin Ehlis912df022015-09-17 08:46:18 -06003371 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
3372 dsl_binding.pImmutableSamplers = NULL;
3373
3374 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07003375 ds_layout_ci.sType =
3376VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
Tobin Ehlis912df022015-09-17 08:46:18 -06003377 ds_layout_ci.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08003378 ds_layout_ci.bindingCount = 1;
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07003379 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlis912df022015-09-17 08:46:18 -06003380
3381 VkDescriptorSetLayout ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07003382 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
3383&ds_layout);
Tobin Ehlis912df022015-09-17 08:46:18 -06003384 ASSERT_VK_SUCCESS(err);
3385
3386 VkDescriptorSet descriptorSet;
Karl Schultz6addd812016-02-02 17:17:23 -07003387 err = vkAllocateDescriptorSets(m_device->device(), ds_pool,
3388VK_DESCRIPTOR_SET_USAGE_NON_FREE, 1, &ds_layout, &descriptorSet);
Tobin Ehlis912df022015-09-17 08:46:18 -06003389 ASSERT_VK_SUCCESS(err);
3390
3391 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07003392 pipeline_layout_ci.sType =
3393VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
Tobin Ehlis912df022015-09-17 08:46:18 -06003394 pipeline_layout_ci.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08003395 pipeline_layout_ci.setLayoutCount = 1;
Tobin Ehlis912df022015-09-17 08:46:18 -06003396 pipeline_layout_ci.pSetLayouts = &ds_layout;
3397
3398 VkPipelineLayout pipeline_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07003399 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL,
3400&pipeline_layout);
Tobin Ehlis912df022015-09-17 08:46:18 -06003401 ASSERT_VK_SUCCESS(err);
3402
3403 VkPipelineShaderStageCreateInfo shaderStages[3];
3404 memset(&shaderStages, 0, 3 * sizeof(VkPipelineShaderStageCreateInfo));
3405
Karl Schultz6addd812016-02-02 17:17:23 -07003406 VkShaderObj vs(m_device,bindStateVertShaderText,VK_SHADER_STAGE_VERTEX_BIT,
3407this);
Tobin Ehlis912df022015-09-17 08:46:18 -06003408 // Just using VS txt for Tess shaders as we don't care about functionality
Karl Schultz6addd812016-02-02 17:17:23 -07003409 VkShaderObj
3410tc(m_device,bindStateVertShaderText,VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT,
3411this);
3412 VkShaderObj
3413te(m_device,bindStateVertShaderText,VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT,
3414this);
Tobin Ehlis912df022015-09-17 08:46:18 -06003415
Karl Schultz6addd812016-02-02 17:17:23 -07003416 shaderStages[0].sType =
3417VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06003418 shaderStages[0].stage = VK_SHADER_STAGE_VERTEX_BIT;
Tobin Ehlis912df022015-09-17 08:46:18 -06003419 shaderStages[0].shader = vs.handle();
Karl Schultz6addd812016-02-02 17:17:23 -07003420 shaderStages[1].sType =
3421VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06003422 shaderStages[1].stage = VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT;
Tobin Ehlis912df022015-09-17 08:46:18 -06003423 shaderStages[1].shader = tc.handle();
Karl Schultz6addd812016-02-02 17:17:23 -07003424 shaderStages[2].sType =
3425VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06003426 shaderStages[2].stage = VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT;
Tobin Ehlis912df022015-09-17 08:46:18 -06003427 shaderStages[2].shader = te.handle();
3428
3429 VkPipelineInputAssemblyStateCreateInfo iaCI = {};
Karl Schultz6addd812016-02-02 17:17:23 -07003430 iaCI.sType =
3431VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
Chia-I Wu515eb8f2015-10-31 00:31:16 +08003432 iaCI.topology = VK_PRIMITIVE_TOPOLOGY_PATCH_LIST;
Tobin Ehlis912df022015-09-17 08:46:18 -06003433
3434 VkPipelineTessellationStateCreateInfo tsCI = {};
3435 tsCI.sType = VK_STRUCTURE_TYPE_PIPELINE_TESSELLATION_STATE_CREATE_INFO;
3436 tsCI.patchControlPoints = 0; // This will cause an error
3437
3438 VkGraphicsPipelineCreateInfo gp_ci = {};
3439 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
3440 gp_ci.pNext = NULL;
3441 gp_ci.stageCount = 3;
3442 gp_ci.pStages = shaderStages;
3443 gp_ci.pVertexInputState = NULL;
3444 gp_ci.pInputAssemblyState = &iaCI;
3445 gp_ci.pTessellationState = &tsCI;
3446 gp_ci.pViewportState = NULL;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003447 gp_ci.pRasterizationState = NULL;
Tobin Ehlis912df022015-09-17 08:46:18 -06003448 gp_ci.pMultisampleState = NULL;
3449 gp_ci.pDepthStencilState = NULL;
3450 gp_ci.pColorBlendState = NULL;
3451 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
3452 gp_ci.layout = pipeline_layout;
3453 gp_ci.renderPass = renderPass();
3454
3455 VkPipelineCacheCreateInfo pc_ci = {};
3456 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
3457 pc_ci.pNext = NULL;
3458 pc_ci.initialSize = 0;
3459 pc_ci.initialData = 0;
3460 pc_ci.maxSize = 0;
3461
3462 VkPipeline pipeline;
3463 VkPipelineCache pipelineCache;
3464
Karl Schultz6addd812016-02-02 17:17:23 -07003465 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL,
3466&pipelineCache);
Tobin Ehlis912df022015-09-17 08:46:18 -06003467 ASSERT_VK_SUCCESS(err);
Karl Schultz6addd812016-02-02 17:17:23 -07003468 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1,
3469&gp_ci, NULL, &pipeline);
Tobin Ehlis912df022015-09-17 08:46:18 -06003470
Chris Forbes8f36a8a2016-04-07 13:21:07 +12003471 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06003472
Chia-I Wuf7458c52015-10-26 21:10:41 +08003473 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
3474 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
3475 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
3476 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis912df022015-09-17 08:46:18 -06003477}
3478*/
Tobin Ehlise68360f2015-10-01 11:15:13 -06003479// Set scissor and viewport counts to different numbers
Karl Schultz6addd812016-02-02 17:17:23 -07003480TEST_F(VkLayerTest, PSOViewportScissorCountMismatch) {
Karl Schultz6addd812016-02-02 17:17:23 -07003481 VkResult err;
Tobin Ehlise68360f2015-10-01 11:15:13 -06003482
Karl Schultz6addd812016-02-02 17:17:23 -07003483 m_errorMonitor->SetDesiredFailureMsg(
3484 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06003485 "Gfx Pipeline viewport count (1) must match scissor count (0).");
3486
Tobin Ehlise68360f2015-10-01 11:15:13 -06003487 ASSERT_NO_FATAL_FAILURE(InitState());
3488 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlise68360f2015-10-01 11:15:13 -06003489
Chia-I Wu1b99bb22015-10-27 19:25:11 +08003490 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07003491 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
3492 ds_type_count.descriptorCount = 1;
Tobin Ehlise68360f2015-10-01 11:15:13 -06003493
3494 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07003495 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
3496 ds_pool_ci.maxSets = 1;
3497 ds_pool_ci.poolSizeCount = 1;
3498 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlise68360f2015-10-01 11:15:13 -06003499
3500 VkDescriptorPool ds_pool;
Karl Schultz6addd812016-02-02 17:17:23 -07003501 err =
3502 vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlise68360f2015-10-01 11:15:13 -06003503 ASSERT_VK_SUCCESS(err);
3504
3505 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07003506 dsl_binding.binding = 0;
3507 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
3508 dsl_binding.descriptorCount = 1;
3509 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
Tobin Ehlise68360f2015-10-01 11:15:13 -06003510
3511 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07003512 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
3513 ds_layout_ci.bindingCount = 1;
3514 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlise68360f2015-10-01 11:15:13 -06003515
3516 VkDescriptorSetLayout ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07003517 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
3518 &ds_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06003519 ASSERT_VK_SUCCESS(err);
3520
3521 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003522 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08003523 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07003524 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06003525 alloc_info.descriptorPool = ds_pool;
3526 alloc_info.pSetLayouts = &ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07003527 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info,
3528 &descriptorSet);
Tobin Ehlise68360f2015-10-01 11:15:13 -06003529 ASSERT_VK_SUCCESS(err);
3530
3531 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07003532 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
3533 pipeline_layout_ci.setLayoutCount = 1;
3534 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlise68360f2015-10-01 11:15:13 -06003535
3536 VkPipelineLayout pipeline_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07003537 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL,
3538 &pipeline_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06003539 ASSERT_VK_SUCCESS(err);
3540
3541 VkViewport vp = {}; // Just need dummy vp to point to
3542
3543 VkPipelineViewportStateCreateInfo vp_state_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07003544 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
3545 vp_state_ci.scissorCount = 0;
3546 vp_state_ci.viewportCount = 1; // Count mismatch should cause error
3547 vp_state_ci.pViewports = &vp;
Tobin Ehlise68360f2015-10-01 11:15:13 -06003548
Karl Schultzdfdb8d42016-03-08 10:30:21 -07003549 VkPipelineRasterizationStateCreateInfo rs_state_ci = {};
3550 rs_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
3551 rs_state_ci.polygonMode = VK_POLYGON_MODE_FILL;
3552 rs_state_ci.cullMode = VK_CULL_MODE_BACK_BIT;
3553 rs_state_ci.frontFace = VK_FRONT_FACE_COUNTER_CLOCKWISE;
3554 rs_state_ci.depthClampEnable = VK_FALSE;
3555 rs_state_ci.rasterizerDiscardEnable = VK_FALSE;
3556 rs_state_ci.depthBiasEnable = VK_FALSE;
3557
Cody Northropeb3a6c12015-10-05 14:44:45 -06003558 VkPipelineShaderStageCreateInfo shaderStages[2];
Karl Schultz6addd812016-02-02 17:17:23 -07003559 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
Tobin Ehlise68360f2015-10-01 11:15:13 -06003560
Karl Schultz6addd812016-02-02 17:17:23 -07003561 VkShaderObj vs(m_device, bindStateVertShaderText,
3562 VK_SHADER_STAGE_VERTEX_BIT, this);
3563 VkShaderObj fs(m_device, bindStateFragShaderText,
3564 VK_SHADER_STAGE_FRAGMENT_BIT,
Karl Schultzbdb75952016-04-19 11:36:49 -06003565 this); // We shouldn't need a fragment shader
Karl Schultz6addd812016-02-02 17:17:23 -07003566 // but add it to be able to run on more devices
Chia-I Wu28e06912015-10-31 00:31:16 +08003567 shaderStages[0] = vs.GetStageCreateInfo();
3568 shaderStages[1] = fs.GetStageCreateInfo();
Tobin Ehlise68360f2015-10-01 11:15:13 -06003569
3570 VkGraphicsPipelineCreateInfo gp_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07003571 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
3572 gp_ci.stageCount = 2;
3573 gp_ci.pStages = shaderStages;
3574 gp_ci.pViewportState = &vp_state_ci;
Karl Schultzdfdb8d42016-03-08 10:30:21 -07003575 gp_ci.pRasterizationState = &rs_state_ci;
Karl Schultz6addd812016-02-02 17:17:23 -07003576 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
3577 gp_ci.layout = pipeline_layout;
3578 gp_ci.renderPass = renderPass();
Tobin Ehlise68360f2015-10-01 11:15:13 -06003579
3580 VkPipelineCacheCreateInfo pc_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07003581 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
Tobin Ehlise68360f2015-10-01 11:15:13 -06003582
3583 VkPipeline pipeline;
3584 VkPipelineCache pipelineCache;
3585
Karl Schultz6addd812016-02-02 17:17:23 -07003586 err =
3587 vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Tobin Ehlise68360f2015-10-01 11:15:13 -06003588 ASSERT_VK_SUCCESS(err);
Karl Schultz6addd812016-02-02 17:17:23 -07003589 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1,
3590 &gp_ci, NULL, &pipeline);
Tobin Ehlise68360f2015-10-01 11:15:13 -06003591
Chris Forbes8f36a8a2016-04-07 13:21:07 +12003592 m_errorMonitor->VerifyFound();
Tobin Ehlise68360f2015-10-01 11:15:13 -06003593
Chia-I Wuf7458c52015-10-26 21:10:41 +08003594 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
3595 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
3596 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
3597 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlise68360f2015-10-01 11:15:13 -06003598}
Karl Schultz6addd812016-02-02 17:17:23 -07003599// Don't set viewport state in PSO. This is an error b/c we always need this
3600// state
Tobin Ehlisd332f282015-10-02 11:00:56 -06003601// for the counts even if the data is going to be set dynamically.
Karl Schultz6addd812016-02-02 17:17:23 -07003602TEST_F(VkLayerTest, PSOViewportStateNotSet) {
Tobin Ehlise68360f2015-10-01 11:15:13 -06003603 // Attempt to Create Gfx Pipeline w/o a VS
Karl Schultz6addd812016-02-02 17:17:23 -07003604 VkResult err;
Tobin Ehlise68360f2015-10-01 11:15:13 -06003605
Karl Schultz6addd812016-02-02 17:17:23 -07003606 m_errorMonitor->SetDesiredFailureMsg(
3607 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06003608 "Gfx Pipeline pViewportState is null. Even if ");
3609
Tobin Ehlise68360f2015-10-01 11:15:13 -06003610 ASSERT_NO_FATAL_FAILURE(InitState());
3611 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlise68360f2015-10-01 11:15:13 -06003612
Chia-I Wu1b99bb22015-10-27 19:25:11 +08003613 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07003614 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
3615 ds_type_count.descriptorCount = 1;
Tobin Ehlise68360f2015-10-01 11:15:13 -06003616
3617 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07003618 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
3619 ds_pool_ci.maxSets = 1;
3620 ds_pool_ci.poolSizeCount = 1;
3621 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlise68360f2015-10-01 11:15:13 -06003622
3623 VkDescriptorPool ds_pool;
Karl Schultz6addd812016-02-02 17:17:23 -07003624 err =
3625 vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlise68360f2015-10-01 11:15:13 -06003626 ASSERT_VK_SUCCESS(err);
3627
3628 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07003629 dsl_binding.binding = 0;
3630 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
3631 dsl_binding.descriptorCount = 1;
3632 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
Tobin Ehlise68360f2015-10-01 11:15:13 -06003633
3634 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07003635 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
3636 ds_layout_ci.bindingCount = 1;
3637 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlise68360f2015-10-01 11:15:13 -06003638
3639 VkDescriptorSetLayout ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07003640 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
3641 &ds_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06003642 ASSERT_VK_SUCCESS(err);
3643
3644 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003645 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08003646 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07003647 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06003648 alloc_info.descriptorPool = ds_pool;
3649 alloc_info.pSetLayouts = &ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07003650 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info,
3651 &descriptorSet);
Tobin Ehlise68360f2015-10-01 11:15:13 -06003652 ASSERT_VK_SUCCESS(err);
3653
3654 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07003655 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
3656 pipeline_layout_ci.setLayoutCount = 1;
3657 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlise68360f2015-10-01 11:15:13 -06003658
3659 VkPipelineLayout pipeline_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07003660 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL,
3661 &pipeline_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06003662 ASSERT_VK_SUCCESS(err);
3663
3664 VkDynamicState sc_state = VK_DYNAMIC_STATE_SCISSOR;
3665 // Set scissor as dynamic to avoid second error
3666 VkPipelineDynamicStateCreateInfo dyn_state_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07003667 dyn_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
3668 dyn_state_ci.dynamicStateCount = 1;
3669 dyn_state_ci.pDynamicStates = &sc_state;
Tobin Ehlise68360f2015-10-01 11:15:13 -06003670
Cody Northropeb3a6c12015-10-05 14:44:45 -06003671 VkPipelineShaderStageCreateInfo shaderStages[2];
Karl Schultz6addd812016-02-02 17:17:23 -07003672 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
Tobin Ehlise68360f2015-10-01 11:15:13 -06003673
Karl Schultz6addd812016-02-02 17:17:23 -07003674 VkShaderObj vs(m_device, bindStateVertShaderText,
3675 VK_SHADER_STAGE_VERTEX_BIT, this);
3676 VkShaderObj fs(m_device, bindStateFragShaderText,
3677 VK_SHADER_STAGE_FRAGMENT_BIT,
Karl Schultzbdb75952016-04-19 11:36:49 -06003678 this); // We shouldn't need a fragment shader
Karl Schultz6addd812016-02-02 17:17:23 -07003679 // but add it to be able to run on more devices
Chia-I Wu28e06912015-10-31 00:31:16 +08003680 shaderStages[0] = vs.GetStageCreateInfo();
3681 shaderStages[1] = fs.GetStageCreateInfo();
Tobin Ehlise68360f2015-10-01 11:15:13 -06003682
Karl Schultzdfdb8d42016-03-08 10:30:21 -07003683
3684 VkPipelineRasterizationStateCreateInfo rs_state_ci = {};
3685 rs_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
3686 rs_state_ci.polygonMode = VK_POLYGON_MODE_FILL;
3687 rs_state_ci.cullMode = VK_CULL_MODE_BACK_BIT;
3688 rs_state_ci.frontFace = VK_FRONT_FACE_COUNTER_CLOCKWISE;
3689 rs_state_ci.depthClampEnable = VK_FALSE;
3690 rs_state_ci.rasterizerDiscardEnable = VK_FALSE;
3691 rs_state_ci.depthBiasEnable = VK_FALSE;
3692
Tobin Ehlise68360f2015-10-01 11:15:13 -06003693 VkGraphicsPipelineCreateInfo gp_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07003694 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
3695 gp_ci.stageCount = 2;
3696 gp_ci.pStages = shaderStages;
Karl Schultzdfdb8d42016-03-08 10:30:21 -07003697 gp_ci.pRasterizationState = &rs_state_ci;
Karl Schultz6addd812016-02-02 17:17:23 -07003698 gp_ci.pViewportState = NULL; // Not setting VP state w/o dynamic vp state
3699 // should cause validation error
3700 gp_ci.pDynamicState = &dyn_state_ci;
3701 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
3702 gp_ci.layout = pipeline_layout;
3703 gp_ci.renderPass = renderPass();
Tobin Ehlise68360f2015-10-01 11:15:13 -06003704
3705 VkPipelineCacheCreateInfo pc_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07003706 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
Tobin Ehlise68360f2015-10-01 11:15:13 -06003707
3708 VkPipeline pipeline;
3709 VkPipelineCache pipelineCache;
3710
Karl Schultz6addd812016-02-02 17:17:23 -07003711 err =
3712 vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Tobin Ehlise68360f2015-10-01 11:15:13 -06003713 ASSERT_VK_SUCCESS(err);
Karl Schultz6addd812016-02-02 17:17:23 -07003714 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1,
3715 &gp_ci, NULL, &pipeline);
Tobin Ehlise68360f2015-10-01 11:15:13 -06003716
Chris Forbes8f36a8a2016-04-07 13:21:07 +12003717 m_errorMonitor->VerifyFound();
Tobin Ehlise68360f2015-10-01 11:15:13 -06003718
Chia-I Wuf7458c52015-10-26 21:10:41 +08003719 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
3720 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
3721 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
3722 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlise68360f2015-10-01 11:15:13 -06003723}
3724// Create PSO w/o non-zero viewportCount but no viewport data
Karl Schultz6addd812016-02-02 17:17:23 -07003725// Then run second test where dynamic scissor count doesn't match PSO scissor
3726// count
3727TEST_F(VkLayerTest, PSOViewportCountWithoutDataAndDynScissorMismatch) {
3728 VkResult err;
Tobin Ehlise68360f2015-10-01 11:15:13 -06003729
Karl Schultz6addd812016-02-02 17:17:23 -07003730 m_errorMonitor->SetDesiredFailureMsg(
3731 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06003732 "Gfx Pipeline viewportCount is 1, but pViewports is NULL. ");
3733
Tobin Ehlise68360f2015-10-01 11:15:13 -06003734 ASSERT_NO_FATAL_FAILURE(InitState());
3735 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlise68360f2015-10-01 11:15:13 -06003736
Chia-I Wu1b99bb22015-10-27 19:25:11 +08003737 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07003738 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
3739 ds_type_count.descriptorCount = 1;
Tobin Ehlise68360f2015-10-01 11:15:13 -06003740
3741 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07003742 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
3743 ds_pool_ci.maxSets = 1;
3744 ds_pool_ci.poolSizeCount = 1;
3745 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlise68360f2015-10-01 11:15:13 -06003746
3747 VkDescriptorPool ds_pool;
Karl Schultz6addd812016-02-02 17:17:23 -07003748 err =
3749 vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlise68360f2015-10-01 11:15:13 -06003750 ASSERT_VK_SUCCESS(err);
3751
3752 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07003753 dsl_binding.binding = 0;
3754 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
3755 dsl_binding.descriptorCount = 1;
3756 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
Tobin Ehlise68360f2015-10-01 11:15:13 -06003757
3758 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07003759 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
3760 ds_layout_ci.bindingCount = 1;
3761 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlise68360f2015-10-01 11:15:13 -06003762
3763 VkDescriptorSetLayout ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07003764 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
3765 &ds_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06003766 ASSERT_VK_SUCCESS(err);
3767
3768 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003769 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08003770 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07003771 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06003772 alloc_info.descriptorPool = ds_pool;
3773 alloc_info.pSetLayouts = &ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07003774 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info,
3775 &descriptorSet);
Tobin Ehlise68360f2015-10-01 11:15:13 -06003776 ASSERT_VK_SUCCESS(err);
3777
3778 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07003779 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
3780 pipeline_layout_ci.setLayoutCount = 1;
3781 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlise68360f2015-10-01 11:15:13 -06003782
3783 VkPipelineLayout pipeline_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07003784 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL,
3785 &pipeline_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06003786 ASSERT_VK_SUCCESS(err);
3787
3788 VkPipelineViewportStateCreateInfo vp_state_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07003789 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
3790 vp_state_ci.viewportCount = 1;
3791 vp_state_ci.pViewports = NULL; // Null vp w/ count of 1 should cause error
3792 vp_state_ci.scissorCount = 1;
3793 vp_state_ci.pScissors =
3794 NULL; // Scissor is dynamic (below) so this won't cause error
Tobin Ehlise68360f2015-10-01 11:15:13 -06003795
3796 VkDynamicState sc_state = VK_DYNAMIC_STATE_SCISSOR;
3797 // Set scissor as dynamic to avoid that error
3798 VkPipelineDynamicStateCreateInfo dyn_state_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07003799 dyn_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
3800 dyn_state_ci.dynamicStateCount = 1;
3801 dyn_state_ci.pDynamicStates = &sc_state;
Tobin Ehlise68360f2015-10-01 11:15:13 -06003802
Cody Northropeb3a6c12015-10-05 14:44:45 -06003803 VkPipelineShaderStageCreateInfo shaderStages[2];
Karl Schultz6addd812016-02-02 17:17:23 -07003804 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
Tobin Ehlise68360f2015-10-01 11:15:13 -06003805
Karl Schultz6addd812016-02-02 17:17:23 -07003806 VkShaderObj vs(m_device, bindStateVertShaderText,
3807 VK_SHADER_STAGE_VERTEX_BIT, this);
3808 VkShaderObj fs(m_device, bindStateFragShaderText,
3809 VK_SHADER_STAGE_FRAGMENT_BIT,
Karl Schultzbdb75952016-04-19 11:36:49 -06003810 this); // We shouldn't need a fragment shader
Karl Schultz6addd812016-02-02 17:17:23 -07003811 // but add it to be able to run on more devices
Chia-I Wu28e06912015-10-31 00:31:16 +08003812 shaderStages[0] = vs.GetStageCreateInfo();
3813 shaderStages[1] = fs.GetStageCreateInfo();
Tobin Ehlise68360f2015-10-01 11:15:13 -06003814
Cody Northropf6622dc2015-10-06 10:33:21 -06003815 VkPipelineVertexInputStateCreateInfo vi_ci = {};
3816 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
3817 vi_ci.pNext = nullptr;
Chia-I Wud50a7d72015-10-26 20:48:51 +08003818 vi_ci.vertexBindingDescriptionCount = 0;
Cody Northropf6622dc2015-10-06 10:33:21 -06003819 vi_ci.pVertexBindingDescriptions = nullptr;
Chia-I Wud50a7d72015-10-26 20:48:51 +08003820 vi_ci.vertexAttributeDescriptionCount = 0;
Cody Northropf6622dc2015-10-06 10:33:21 -06003821 vi_ci.pVertexAttributeDescriptions = nullptr;
3822
3823 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
3824 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
3825 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
3826
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003827 VkPipelineRasterizationStateCreateInfo rs_ci = {};
Chia-I Wu1b99bb22015-10-27 19:25:11 +08003828 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
Cody Northropf6622dc2015-10-06 10:33:21 -06003829 rs_ci.pNext = nullptr;
3830
Mark Youngc89c6312016-03-31 16:03:20 -06003831 VkPipelineColorBlendAttachmentState att = {};
3832 att.blendEnable = VK_FALSE;
3833 att.colorWriteMask = 0xf;
3834
Cody Northropf6622dc2015-10-06 10:33:21 -06003835 VkPipelineColorBlendStateCreateInfo cb_ci = {};
3836 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
3837 cb_ci.pNext = nullptr;
Mark Youngc89c6312016-03-31 16:03:20 -06003838 cb_ci.attachmentCount = 1;
3839 cb_ci.pAttachments = &att;
Cody Northropf6622dc2015-10-06 10:33:21 -06003840
Tobin Ehlise68360f2015-10-01 11:15:13 -06003841 VkGraphicsPipelineCreateInfo gp_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07003842 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
3843 gp_ci.stageCount = 2;
3844 gp_ci.pStages = shaderStages;
3845 gp_ci.pVertexInputState = &vi_ci;
3846 gp_ci.pInputAssemblyState = &ia_ci;
3847 gp_ci.pViewportState = &vp_state_ci;
3848 gp_ci.pRasterizationState = &rs_ci;
3849 gp_ci.pColorBlendState = &cb_ci;
3850 gp_ci.pDynamicState = &dyn_state_ci;
3851 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
3852 gp_ci.layout = pipeline_layout;
3853 gp_ci.renderPass = renderPass();
Tobin Ehlise68360f2015-10-01 11:15:13 -06003854
3855 VkPipelineCacheCreateInfo pc_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07003856 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
Tobin Ehlise68360f2015-10-01 11:15:13 -06003857
3858 VkPipeline pipeline;
3859 VkPipelineCache pipelineCache;
3860
Karl Schultz6addd812016-02-02 17:17:23 -07003861 err =
3862 vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Tobin Ehlise68360f2015-10-01 11:15:13 -06003863 ASSERT_VK_SUCCESS(err);
Karl Schultz6addd812016-02-02 17:17:23 -07003864 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1,
3865 &gp_ci, NULL, &pipeline);
Tobin Ehlise68360f2015-10-01 11:15:13 -06003866
Chris Forbes8f36a8a2016-04-07 13:21:07 +12003867 m_errorMonitor->VerifyFound();
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06003868
Tobin Ehlisd332f282015-10-02 11:00:56 -06003869 // Now hit second fail case where we set scissor w/ different count than PSO
Karl Schultz6addd812016-02-02 17:17:23 -07003870 // First need to successfully create the PSO from above by setting
3871 // pViewports
3872 m_errorMonitor->SetDesiredFailureMsg(
3873 VK_DEBUG_REPORT_ERROR_BIT_EXT,
3874 "Dynamic scissorCount from vkCmdSetScissor() is 2, but PSO "
3875 "scissorCount is 1. These counts must match.");
3876
3877 VkViewport vp = {}; // Just need dummy vp to point to
3878 vp_state_ci.pViewports = &vp;
3879 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1,
3880 &gp_ci, NULL, &pipeline);
3881 ASSERT_VK_SUCCESS(err);
3882 BeginCommandBuffer();
3883 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(),
3884 VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
3885 VkRect2D scissors[2] = {}; // don't care about data
3886 // Count of 2 doesn't match PSO count of 1
3887 vkCmdSetScissor(m_commandBuffer->GetBufferHandle(), 0, 2, scissors);
3888 Draw(1, 0, 0, 0);
3889
Chris Forbes8f36a8a2016-04-07 13:21:07 +12003890 m_errorMonitor->VerifyFound();
Karl Schultz6addd812016-02-02 17:17:23 -07003891
3892 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
3893 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
3894 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
3895 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
3896}
3897// Create PSO w/o non-zero scissorCount but no scissor data
3898// Then run second test where dynamic viewportCount doesn't match PSO
3899// viewportCount
3900TEST_F(VkLayerTest, PSOScissorCountWithoutDataAndDynViewportMismatch) {
3901 VkResult err;
3902
3903 m_errorMonitor->SetDesiredFailureMsg(
3904 VK_DEBUG_REPORT_ERROR_BIT_EXT,
3905 "Gfx Pipeline scissorCount is 1, but pScissors is NULL. ");
3906
3907 ASSERT_NO_FATAL_FAILURE(InitState());
3908 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
3909
3910 VkDescriptorPoolSize ds_type_count = {};
3911 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
3912 ds_type_count.descriptorCount = 1;
3913
3914 VkDescriptorPoolCreateInfo ds_pool_ci = {};
3915 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
3916 ds_pool_ci.maxSets = 1;
3917 ds_pool_ci.poolSizeCount = 1;
3918 ds_pool_ci.pPoolSizes = &ds_type_count;
3919
3920 VkDescriptorPool ds_pool;
3921 err =
3922 vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
3923 ASSERT_VK_SUCCESS(err);
3924
3925 VkDescriptorSetLayoutBinding dsl_binding = {};
3926 dsl_binding.binding = 0;
3927 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
3928 dsl_binding.descriptorCount = 1;
3929 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
3930
3931 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
3932 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
3933 ds_layout_ci.bindingCount = 1;
3934 ds_layout_ci.pBindings = &dsl_binding;
3935
3936 VkDescriptorSetLayout ds_layout;
3937 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
3938 &ds_layout);
3939 ASSERT_VK_SUCCESS(err);
3940
3941 VkDescriptorSet descriptorSet;
3942 VkDescriptorSetAllocateInfo alloc_info = {};
3943 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
3944 alloc_info.descriptorSetCount = 1;
3945 alloc_info.descriptorPool = ds_pool;
3946 alloc_info.pSetLayouts = &ds_layout;
3947 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info,
3948 &descriptorSet);
3949 ASSERT_VK_SUCCESS(err);
3950
3951 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
3952 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
3953 pipeline_layout_ci.setLayoutCount = 1;
3954 pipeline_layout_ci.pSetLayouts = &ds_layout;
3955
3956 VkPipelineLayout pipeline_layout;
3957 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL,
3958 &pipeline_layout);
3959 ASSERT_VK_SUCCESS(err);
3960
3961 VkPipelineViewportStateCreateInfo vp_state_ci = {};
3962 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
3963 vp_state_ci.scissorCount = 1;
3964 vp_state_ci.pScissors =
3965 NULL; // Null scissor w/ count of 1 should cause error
3966 vp_state_ci.viewportCount = 1;
3967 vp_state_ci.pViewports =
3968 NULL; // vp is dynamic (below) so this won't cause error
3969
3970 VkDynamicState vp_state = VK_DYNAMIC_STATE_VIEWPORT;
3971 // Set scissor as dynamic to avoid that error
3972 VkPipelineDynamicStateCreateInfo dyn_state_ci = {};
3973 dyn_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
3974 dyn_state_ci.dynamicStateCount = 1;
3975 dyn_state_ci.pDynamicStates = &vp_state;
3976
3977 VkPipelineShaderStageCreateInfo shaderStages[2];
3978 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
3979
3980 VkShaderObj vs(m_device, bindStateVertShaderText,
3981 VK_SHADER_STAGE_VERTEX_BIT, this);
3982 VkShaderObj fs(m_device, bindStateFragShaderText,
3983 VK_SHADER_STAGE_FRAGMENT_BIT,
Karl Schultzbdb75952016-04-19 11:36:49 -06003984 this); // We shouldn't need a fragment shader
Karl Schultz6addd812016-02-02 17:17:23 -07003985 // but add it to be able to run on more devices
3986 shaderStages[0] = vs.GetStageCreateInfo();
3987 shaderStages[1] = fs.GetStageCreateInfo();
3988
3989 VkPipelineVertexInputStateCreateInfo vi_ci = {};
3990 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
3991 vi_ci.pNext = nullptr;
3992 vi_ci.vertexBindingDescriptionCount = 0;
3993 vi_ci.pVertexBindingDescriptions = nullptr;
3994 vi_ci.vertexAttributeDescriptionCount = 0;
3995 vi_ci.pVertexAttributeDescriptions = nullptr;
3996
3997 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
3998 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
3999 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
4000
4001 VkPipelineRasterizationStateCreateInfo rs_ci = {};
4002 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
4003 rs_ci.pNext = nullptr;
4004
Mark Youngc89c6312016-03-31 16:03:20 -06004005 VkPipelineColorBlendAttachmentState att = {};
4006 att.blendEnable = VK_FALSE;
4007 att.colorWriteMask = 0xf;
4008
Karl Schultz6addd812016-02-02 17:17:23 -07004009 VkPipelineColorBlendStateCreateInfo cb_ci = {};
4010 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
4011 cb_ci.pNext = nullptr;
Mark Youngc89c6312016-03-31 16:03:20 -06004012 cb_ci.attachmentCount = 1;
4013 cb_ci.pAttachments = &att;
Karl Schultz6addd812016-02-02 17:17:23 -07004014
4015 VkGraphicsPipelineCreateInfo gp_ci = {};
4016 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
4017 gp_ci.stageCount = 2;
4018 gp_ci.pStages = shaderStages;
4019 gp_ci.pVertexInputState = &vi_ci;
4020 gp_ci.pInputAssemblyState = &ia_ci;
4021 gp_ci.pViewportState = &vp_state_ci;
4022 gp_ci.pRasterizationState = &rs_ci;
4023 gp_ci.pColorBlendState = &cb_ci;
4024 gp_ci.pDynamicState = &dyn_state_ci;
4025 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
4026 gp_ci.layout = pipeline_layout;
4027 gp_ci.renderPass = renderPass();
4028
4029 VkPipelineCacheCreateInfo pc_ci = {};
4030 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
4031
4032 VkPipeline pipeline;
4033 VkPipelineCache pipelineCache;
4034
4035 err =
4036 vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
4037 ASSERT_VK_SUCCESS(err);
4038 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1,
4039 &gp_ci, NULL, &pipeline);
4040
Chris Forbes8f36a8a2016-04-07 13:21:07 +12004041 m_errorMonitor->VerifyFound();
Karl Schultz6addd812016-02-02 17:17:23 -07004042
4043 // Now hit second fail case where we set scissor w/ different count than PSO
4044 // First need to successfully create the PSO from above by setting
4045 // pViewports
4046 m_errorMonitor->SetDesiredFailureMsg(
4047 VK_DEBUG_REPORT_ERROR_BIT_EXT,
4048 "Dynamic viewportCount from vkCmdSetViewport() is 2, but PSO "
4049 "viewportCount is 1. These counts must match.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06004050
Tobin Ehlisd332f282015-10-02 11:00:56 -06004051 VkRect2D sc = {}; // Just need dummy vp to point to
4052 vp_state_ci.pScissors = &sc;
Karl Schultz6addd812016-02-02 17:17:23 -07004053 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1,
4054 &gp_ci, NULL, &pipeline);
Tobin Ehlisd332f282015-10-02 11:00:56 -06004055 ASSERT_VK_SUCCESS(err);
4056 BeginCommandBuffer();
Karl Schultz6addd812016-02-02 17:17:23 -07004057 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(),
4058 VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
Tobin Ehlisd332f282015-10-02 11:00:56 -06004059 VkViewport viewports[2] = {}; // don't care about data
4060 // Count of 2 doesn't match PSO count of 1
Jon Ashburn19d3bf12015-12-30 14:06:55 -07004061 vkCmdSetViewport(m_commandBuffer->GetBufferHandle(), 0, 2, viewports);
Tobin Ehlisd332f282015-10-02 11:00:56 -06004062 Draw(1, 0, 0, 0);
4063
Chris Forbes8f36a8a2016-04-07 13:21:07 +12004064 m_errorMonitor->VerifyFound();
Tobin Ehlise68360f2015-10-01 11:15:13 -06004065
Chia-I Wuf7458c52015-10-26 21:10:41 +08004066 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
4067 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
4068 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
4069 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlise68360f2015-10-01 11:15:13 -06004070}
4071
Mark Young7394fdd2016-03-31 14:56:43 -06004072TEST_F(VkLayerTest, PSOLineWidthInvalid) {
4073 VkResult err;
4074
4075 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
4076 "Attempt to set lineWidth to 0");
4077
4078 ASSERT_NO_FATAL_FAILURE(InitState());
4079 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
4080
4081 VkDescriptorPoolSize ds_type_count = {};
4082 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
4083 ds_type_count.descriptorCount = 1;
4084
4085 VkDescriptorPoolCreateInfo ds_pool_ci = {};
4086 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
4087 ds_pool_ci.maxSets = 1;
4088 ds_pool_ci.poolSizeCount = 1;
4089 ds_pool_ci.pPoolSizes = &ds_type_count;
4090
4091 VkDescriptorPool ds_pool;
4092 err =
4093 vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
4094 ASSERT_VK_SUCCESS(err);
4095
4096 VkDescriptorSetLayoutBinding dsl_binding = {};
4097 dsl_binding.binding = 0;
4098 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
4099 dsl_binding.descriptorCount = 1;
4100 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
4101
4102 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
4103 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
4104 ds_layout_ci.bindingCount = 1;
4105 ds_layout_ci.pBindings = &dsl_binding;
4106
4107 VkDescriptorSetLayout ds_layout;
4108 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
4109 &ds_layout);
4110 ASSERT_VK_SUCCESS(err);
4111
4112 VkDescriptorSet descriptorSet;
4113 VkDescriptorSetAllocateInfo alloc_info = {};
4114 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
4115 alloc_info.descriptorSetCount = 1;
4116 alloc_info.descriptorPool = ds_pool;
4117 alloc_info.pSetLayouts = &ds_layout;
4118 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info,
4119 &descriptorSet);
4120 ASSERT_VK_SUCCESS(err);
4121
4122 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
4123 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
4124 pipeline_layout_ci.setLayoutCount = 1;
4125 pipeline_layout_ci.pSetLayouts = &ds_layout;
4126
4127 VkPipelineLayout pipeline_layout;
4128 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL,
4129 &pipeline_layout);
4130 ASSERT_VK_SUCCESS(err);
4131
4132 VkPipelineViewportStateCreateInfo vp_state_ci = {};
4133 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
4134 vp_state_ci.scissorCount = 1;
4135 vp_state_ci.pScissors = NULL;
4136 vp_state_ci.viewportCount = 1;
4137 vp_state_ci.pViewports = NULL;
4138
4139 VkDynamicState dynamic_states[3] = {VK_DYNAMIC_STATE_VIEWPORT,
4140 VK_DYNAMIC_STATE_SCISSOR,
4141 VK_DYNAMIC_STATE_LINE_WIDTH};
4142 // Set scissor as dynamic to avoid that error
4143 VkPipelineDynamicStateCreateInfo dyn_state_ci = {};
4144 dyn_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
4145 dyn_state_ci.dynamicStateCount = 2;
4146 dyn_state_ci.pDynamicStates = dynamic_states;
4147
4148 VkPipelineShaderStageCreateInfo shaderStages[2];
4149 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
4150
4151 VkShaderObj vs(m_device, bindStateVertShaderText,
4152 VK_SHADER_STAGE_VERTEX_BIT, this);
4153 VkShaderObj fs(m_device, bindStateFragShaderText,
4154 VK_SHADER_STAGE_FRAGMENT_BIT,
4155 this); // TODO - We shouldn't need a fragment shader
4156 // but add it to be able to run on more devices
4157 shaderStages[0] = vs.GetStageCreateInfo();
4158 shaderStages[1] = fs.GetStageCreateInfo();
4159
4160 VkPipelineVertexInputStateCreateInfo vi_ci = {};
4161 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
4162 vi_ci.pNext = nullptr;
4163 vi_ci.vertexBindingDescriptionCount = 0;
4164 vi_ci.pVertexBindingDescriptions = nullptr;
4165 vi_ci.vertexAttributeDescriptionCount = 0;
4166 vi_ci.pVertexAttributeDescriptions = nullptr;
4167
4168 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
4169 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
4170 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
4171
4172 VkPipelineRasterizationStateCreateInfo rs_ci = {};
4173 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
4174 rs_ci.pNext = nullptr;
4175
4176 // Check too low (line width of 0.0f).
4177 rs_ci.lineWidth = 0.0f;
4178
4179 VkPipelineColorBlendAttachmentState att = {};
4180 att.blendEnable = VK_FALSE;
4181 att.colorWriteMask = 0xf;
4182
4183 VkPipelineColorBlendStateCreateInfo cb_ci = {};
4184 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
4185 cb_ci.pNext = nullptr;
4186 cb_ci.attachmentCount = 1;
4187 cb_ci.pAttachments = &att;
4188
4189 VkGraphicsPipelineCreateInfo gp_ci = {};
4190 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
4191 gp_ci.stageCount = 2;
4192 gp_ci.pStages = shaderStages;
4193 gp_ci.pVertexInputState = &vi_ci;
4194 gp_ci.pInputAssemblyState = &ia_ci;
4195 gp_ci.pViewportState = &vp_state_ci;
4196 gp_ci.pRasterizationState = &rs_ci;
4197 gp_ci.pColorBlendState = &cb_ci;
4198 gp_ci.pDynamicState = &dyn_state_ci;
4199 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
4200 gp_ci.layout = pipeline_layout;
4201 gp_ci.renderPass = renderPass();
4202
4203 VkPipelineCacheCreateInfo pc_ci = {};
4204 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
4205
4206 VkPipeline pipeline;
4207 VkPipelineCache pipelineCache;
4208
4209 err =
4210 vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
4211 ASSERT_VK_SUCCESS(err);
4212 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1,
4213 &gp_ci, NULL, &pipeline);
4214
4215 m_errorMonitor->VerifyFound();
4216
4217 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
4218 "Attempt to set lineWidth to 65536");
4219
4220 // Check too high (line width of 65536.0f).
4221 rs_ci.lineWidth = 65536.0f;
4222
4223 err =
4224 vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
4225 ASSERT_VK_SUCCESS(err);
4226 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1,
4227 &gp_ci, NULL, &pipeline);
4228
4229 m_errorMonitor->VerifyFound();
4230
4231 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
4232 "Attempt to set lineWidth to 0");
4233
4234 dyn_state_ci.dynamicStateCount = 3;
4235
4236 rs_ci.lineWidth = 1.0f;
4237
4238 err =
4239 vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
4240 ASSERT_VK_SUCCESS(err);
4241 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1,
4242 &gp_ci, NULL, &pipeline);
4243 BeginCommandBuffer();
4244 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(),
4245 VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
4246
4247 // Check too low with dynamic setting.
4248 vkCmdSetLineWidth(m_commandBuffer->GetBufferHandle(), 0.0f);
4249 m_errorMonitor->VerifyFound();
4250
4251 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
4252 "Attempt to set lineWidth to 65536");
4253
4254 // Check too high with dynamic setting.
4255 vkCmdSetLineWidth(m_commandBuffer->GetBufferHandle(), 65536.0f);
4256 m_errorMonitor->VerifyFound();
4257 EndCommandBuffer();
4258
4259 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
4260 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
4261 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
4262 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
4263}
4264
Karl Schultz6addd812016-02-02 17:17:23 -07004265TEST_F(VkLayerTest, NullRenderPass) {
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06004266 // Bind a NULL RenderPass
Karl Schultz6addd812016-02-02 17:17:23 -07004267 m_errorMonitor->SetDesiredFailureMsg(
4268 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06004269 "You cannot use a NULL RenderPass object in vkCmdBeginRenderPass()");
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06004270
4271 ASSERT_NO_FATAL_FAILURE(InitState());
4272 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06004273
Tony Barbourfe3351b2015-07-28 10:17:20 -06004274 BeginCommandBuffer();
Karl Schultz6addd812016-02-02 17:17:23 -07004275 // Don't care about RenderPass handle b/c error should be flagged before
4276 // that
4277 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), NULL,
4278 VK_SUBPASS_CONTENTS_INLINE);
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06004279
Chris Forbes8f36a8a2016-04-07 13:21:07 +12004280 m_errorMonitor->VerifyFound();
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06004281}
4282
Karl Schultz6addd812016-02-02 17:17:23 -07004283TEST_F(VkLayerTest, RenderPassWithinRenderPass) {
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06004284 // Bind a BeginRenderPass within an active RenderPass
Karl Schultz6addd812016-02-02 17:17:23 -07004285 m_errorMonitor->SetDesiredFailureMsg(
4286 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06004287 "It is invalid to issue this call inside an active render pass");
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06004288
4289 ASSERT_NO_FATAL_FAILURE(InitState());
4290 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06004291
Tony Barbourfe3351b2015-07-28 10:17:20 -06004292 BeginCommandBuffer();
Karl Schultz6addd812016-02-02 17:17:23 -07004293 // Just create a dummy Renderpass that's non-NULL so we can get to the
4294 // proper error
Tony Barboureb254902015-07-15 12:50:33 -06004295 VkRenderPassBeginInfo rp_begin = {};
Karl Schultz6addd812016-02-02 17:17:23 -07004296 rp_begin.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO;
4297 rp_begin.pNext = NULL;
4298 rp_begin.renderPass = renderPass();
4299 rp_begin.framebuffer = framebuffer();
Mark Lobodzinski209b5292015-09-17 09:44:05 -06004300
Karl Schultz6addd812016-02-02 17:17:23 -07004301 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &rp_begin,
4302 VK_SUBPASS_CONTENTS_INLINE);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06004303
Chris Forbes8f36a8a2016-04-07 13:21:07 +12004304 m_errorMonitor->VerifyFound();
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06004305}
4306
Karl Schultz6addd812016-02-02 17:17:23 -07004307TEST_F(VkLayerTest, FillBufferWithinRenderPass) {
Mark Lobodzinskid5639502015-09-24 09:51:47 -06004308 // Call CmdFillBuffer within an active renderpass
Karl Schultz6addd812016-02-02 17:17:23 -07004309 m_errorMonitor->SetDesiredFailureMsg(
4310 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06004311 "It is invalid to issue this call inside an active render pass");
Mark Lobodzinskid5639502015-09-24 09:51:47 -06004312
4313 ASSERT_NO_FATAL_FAILURE(InitState());
4314 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskid5639502015-09-24 09:51:47 -06004315
4316 // Renderpass is started here
4317 BeginCommandBuffer();
4318
4319 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004320 vk_testing::Buffer dstBuffer;
4321 dstBuffer.init_as_dst(*m_device, (VkDeviceSize)1024, reqs);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06004322
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004323 m_commandBuffer->FillBuffer(dstBuffer.handle(), 0, 4, 0x11111111);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06004324
Chris Forbes8f36a8a2016-04-07 13:21:07 +12004325 m_errorMonitor->VerifyFound();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06004326}
4327
Karl Schultz6addd812016-02-02 17:17:23 -07004328TEST_F(VkLayerTest, UpdateBufferWithinRenderPass) {
Mark Lobodzinskid5639502015-09-24 09:51:47 -06004329 // Call CmdUpdateBuffer within an active renderpass
Karl Schultz6addd812016-02-02 17:17:23 -07004330 m_errorMonitor->SetDesiredFailureMsg(
4331 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06004332 "It is invalid to issue this call inside an active render pass");
Mark Lobodzinskid5639502015-09-24 09:51:47 -06004333
4334 ASSERT_NO_FATAL_FAILURE(InitState());
4335 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskid5639502015-09-24 09:51:47 -06004336
4337 // Renderpass is started here
4338 BeginCommandBuffer();
4339
4340 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004341 vk_testing::Buffer dstBuffer;
4342 dstBuffer.init_as_dst(*m_device, (VkDeviceSize)1024, reqs);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06004343
Karl Schultz6addd812016-02-02 17:17:23 -07004344 VkDeviceSize dstOffset = 0;
4345 VkDeviceSize dataSize = 1024;
4346 const uint32_t *pData = NULL;
Mark Lobodzinskid5639502015-09-24 09:51:47 -06004347
Karl Schultz6addd812016-02-02 17:17:23 -07004348 vkCmdUpdateBuffer(m_commandBuffer->GetBufferHandle(), dstBuffer.handle(),
4349 dstOffset, dataSize, pData);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06004350
Chris Forbes8f36a8a2016-04-07 13:21:07 +12004351 m_errorMonitor->VerifyFound();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06004352}
4353
Karl Schultz6addd812016-02-02 17:17:23 -07004354TEST_F(VkLayerTest, ClearColorImageWithinRenderPass) {
Mark Lobodzinskid5639502015-09-24 09:51:47 -06004355 // Call CmdClearColorImage within an active RenderPass
Karl Schultz6addd812016-02-02 17:17:23 -07004356 m_errorMonitor->SetDesiredFailureMsg(
4357 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06004358 "It is invalid to issue this call inside an active render pass");
Mark Lobodzinskid5639502015-09-24 09:51:47 -06004359
4360 ASSERT_NO_FATAL_FAILURE(InitState());
4361 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskid5639502015-09-24 09:51:47 -06004362
4363 // Renderpass is started here
4364 BeginCommandBuffer();
4365
Michael Lentine0a369f62016-02-03 16:51:46 -06004366 VkClearColorValue clear_color;
4367 memset(clear_color.uint32, 0, sizeof(uint32_t) * 4);
Karl Schultz6addd812016-02-02 17:17:23 -07004368 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
4369 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
4370 const int32_t tex_width = 32;
4371 const int32_t tex_height = 32;
4372 VkImageCreateInfo image_create_info = {};
4373 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
4374 image_create_info.pNext = NULL;
4375 image_create_info.imageType = VK_IMAGE_TYPE_2D;
4376 image_create_info.format = tex_format;
4377 image_create_info.extent.width = tex_width;
4378 image_create_info.extent.height = tex_height;
4379 image_create_info.extent.depth = 1;
4380 image_create_info.mipLevels = 1;
4381 image_create_info.arrayLayers = 1;
4382 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
4383 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
4384 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
Mark Lobodzinskid5639502015-09-24 09:51:47 -06004385
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004386 vk_testing::Image dstImage;
Karl Schultz6addd812016-02-02 17:17:23 -07004387 dstImage.init(*m_device, (const VkImageCreateInfo &)image_create_info,
4388 reqs);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06004389
Karl Schultz6addd812016-02-02 17:17:23 -07004390 const VkImageSubresourceRange range = vk_testing::Image::subresource_range(
4391 image_create_info, VK_IMAGE_ASPECT_COLOR_BIT);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06004392
Karl Schultz6addd812016-02-02 17:17:23 -07004393 vkCmdClearColorImage(m_commandBuffer->GetBufferHandle(), dstImage.handle(),
4394 VK_IMAGE_LAYOUT_GENERAL, &clear_color, 1, &range);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06004395
Chris Forbes8f36a8a2016-04-07 13:21:07 +12004396 m_errorMonitor->VerifyFound();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06004397}
4398
Karl Schultz6addd812016-02-02 17:17:23 -07004399TEST_F(VkLayerTest, ClearDepthStencilImageWithinRenderPass) {
Mark Lobodzinskid5639502015-09-24 09:51:47 -06004400 // Call CmdClearDepthStencilImage within an active RenderPass
Karl Schultz6addd812016-02-02 17:17:23 -07004401 m_errorMonitor->SetDesiredFailureMsg(
4402 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06004403 "It is invalid to issue this call inside an active render pass");
Mark Lobodzinskid5639502015-09-24 09:51:47 -06004404
4405 ASSERT_NO_FATAL_FAILURE(InitState());
4406 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskid5639502015-09-24 09:51:47 -06004407
4408 // Renderpass is started here
4409 BeginCommandBuffer();
4410
4411 VkClearDepthStencilValue clear_value = {0};
Dustin Gravesa2e5c942016-02-11 18:28:06 -07004412 VkMemoryPropertyFlags reqs = 0;
Karl Schultz6addd812016-02-02 17:17:23 -07004413 VkImageCreateInfo image_create_info = vk_testing::Image::create_info();
4414 image_create_info.imageType = VK_IMAGE_TYPE_2D;
4415 image_create_info.format = VK_FORMAT_D24_UNORM_S8_UINT;
4416 image_create_info.extent.width = 64;
4417 image_create_info.extent.height = 64;
4418 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
4419 image_create_info.usage = VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT;
Mark Lobodzinskid5639502015-09-24 09:51:47 -06004420
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004421 vk_testing::Image dstImage;
Karl Schultz6addd812016-02-02 17:17:23 -07004422 dstImage.init(*m_device, (const VkImageCreateInfo &)image_create_info,
4423 reqs);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06004424
Karl Schultz6addd812016-02-02 17:17:23 -07004425 const VkImageSubresourceRange range = vk_testing::Image::subresource_range(
4426 image_create_info, VK_IMAGE_ASPECT_DEPTH_BIT);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06004427
Karl Schultz6addd812016-02-02 17:17:23 -07004428 vkCmdClearDepthStencilImage(
4429 m_commandBuffer->GetBufferHandle(), dstImage.handle(),
4430 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL, &clear_value, 1,
4431 &range);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06004432
Chris Forbes8f36a8a2016-04-07 13:21:07 +12004433 m_errorMonitor->VerifyFound();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06004434}
4435
Karl Schultz6addd812016-02-02 17:17:23 -07004436TEST_F(VkLayerTest, ClearColorAttachmentsOutsideRenderPass) {
Courtney Goeltzenleuchterc9323e02015-10-15 16:51:05 -06004437 // Call CmdClearAttachmentss outside of an active RenderPass
Karl Schultz6addd812016-02-02 17:17:23 -07004438 VkResult err;
Mark Lobodzinskid5639502015-09-24 09:51:47 -06004439
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07004440 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Karl Schultz6addd812016-02-02 17:17:23 -07004441 "vkCmdClearAttachments: This call "
4442 "must be issued inside an active "
4443 "render pass");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06004444
Mark Lobodzinskid5639502015-09-24 09:51:47 -06004445 ASSERT_NO_FATAL_FAILURE(InitState());
4446 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskid5639502015-09-24 09:51:47 -06004447
4448 // Start no RenderPass
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004449 err = m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06004450 ASSERT_VK_SUCCESS(err);
4451
Courtney Goeltzenleuchterc9323e02015-10-15 16:51:05 -06004452 VkClearAttachment color_attachment;
4453 color_attachment.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
4454 color_attachment.clearValue.color.float32[0] = 0;
4455 color_attachment.clearValue.color.float32[1] = 0;
4456 color_attachment.clearValue.color.float32[2] = 0;
4457 color_attachment.clearValue.color.float32[3] = 0;
4458 color_attachment.colorAttachment = 0;
Karl Schultz6addd812016-02-02 17:17:23 -07004459 VkClearRect clear_rect = {{{0, 0}, {32, 32}}};
4460 vkCmdClearAttachments(m_commandBuffer->GetBufferHandle(), 1,
4461 &color_attachment, 1, &clear_rect);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06004462
Chris Forbes8f36a8a2016-04-07 13:21:07 +12004463 m_errorMonitor->VerifyFound();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06004464}
4465
Karl Schultz6addd812016-02-02 17:17:23 -07004466TEST_F(VkLayerTest, IdxBufferAlignmentError) {
Tobin Ehlisc4c23182015-09-17 12:24:13 -06004467 // Bind a BeginRenderPass within an active RenderPass
Karl Schultz6addd812016-02-02 17:17:23 -07004468 VkResult err;
Tobin Ehlisc4c23182015-09-17 12:24:13 -06004469
Karl Schultz6addd812016-02-02 17:17:23 -07004470 m_errorMonitor->SetDesiredFailureMsg(
4471 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06004472 "vkCmdBindIndexBuffer() offset (0x7) does not fall on ");
4473
Tobin Ehlisc4c23182015-09-17 12:24:13 -06004474 ASSERT_NO_FATAL_FAILURE(InitState());
4475 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlisc4c23182015-09-17 12:24:13 -06004476 uint32_t qfi = 0;
4477 VkBufferCreateInfo buffCI = {};
Karl Schultz6addd812016-02-02 17:17:23 -07004478 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
4479 buffCI.size = 1024;
4480 buffCI.usage = VK_BUFFER_USAGE_INDEX_BUFFER_BIT;
4481 buffCI.queueFamilyIndexCount = 1;
4482 buffCI.pQueueFamilyIndices = &qfi;
Tobin Ehlisc4c23182015-09-17 12:24:13 -06004483
4484 VkBuffer ib;
Chia-I Wuf7458c52015-10-26 21:10:41 +08004485 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &ib);
Tobin Ehlisc4c23182015-09-17 12:24:13 -06004486 ASSERT_VK_SUCCESS(err);
4487
4488 BeginCommandBuffer();
4489 ASSERT_VK_SUCCESS(err);
Karl Schultz6addd812016-02-02 17:17:23 -07004490 // vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(),
4491 // VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlisc4c23182015-09-17 12:24:13 -06004492 // Should error before calling to driver so don't care about actual data
Karl Schultz6addd812016-02-02 17:17:23 -07004493 vkCmdBindIndexBuffer(m_commandBuffer->GetBufferHandle(), ib, 7,
4494 VK_INDEX_TYPE_UINT16);
Tobin Ehlisc4c23182015-09-17 12:24:13 -06004495
Chris Forbes8f36a8a2016-04-07 13:21:07 +12004496 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06004497
Chia-I Wuf7458c52015-10-26 21:10:41 +08004498 vkDestroyBuffer(m_device->device(), ib, NULL);
Tobin Ehlisc4c23182015-09-17 12:24:13 -06004499}
4500
Mark Lobodzinski52a6e7d2016-02-25 15:09:52 -07004501TEST_F(VkLayerTest, InvalidQueueFamilyIndex) {
4502 // Create an out-of-range queueFamilyIndex
4503 m_errorMonitor->SetDesiredFailureMsg(
4504 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis24aab042016-03-24 10:54:18 -06004505 "queueFamilyIndex 777, must have been given when the device was created.");
Mark Lobodzinski52a6e7d2016-02-25 15:09:52 -07004506
4507 ASSERT_NO_FATAL_FAILURE(InitState());
4508 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
4509 VkBufferCreateInfo buffCI = {};
4510 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
4511 buffCI.size = 1024;
4512 buffCI.usage = VK_BUFFER_USAGE_INDEX_BUFFER_BIT;
4513 buffCI.queueFamilyIndexCount = 1;
4514 // Introduce failure by specifying invalid queue_family_index
4515 uint32_t qfi = 777;
4516 buffCI.pQueueFamilyIndices = &qfi;
Tobin Ehlis24aab042016-03-24 10:54:18 -06004517 buffCI.sharingMode = VK_SHARING_MODE_CONCURRENT; // qfi only matters in CONCURRENT mode
Mark Lobodzinski52a6e7d2016-02-25 15:09:52 -07004518
4519 VkBuffer ib;
4520 vkCreateBuffer(m_device->device(), &buffCI, NULL, &ib);
4521
Chris Forbes8f36a8a2016-04-07 13:21:07 +12004522 m_errorMonitor->VerifyFound();
Mark Lobodzinski52a6e7d2016-02-25 15:09:52 -07004523}
4524
Karl Schultz6addd812016-02-02 17:17:23 -07004525TEST_F(VkLayerTest, ExecuteCommandsPrimaryCB) {
4526 // Attempt vkCmdExecuteCommands w/ a primary cmd buffer (should only be
4527 // secondary)
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06004528
Karl Schultz6addd812016-02-02 17:17:23 -07004529 m_errorMonitor->SetDesiredFailureMsg(
4530 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06004531 "vkCmdExecuteCommands() called w/ Primary Cmd Buffer ");
Tobin Ehlis4b34ddc2015-09-17 14:18:16 -06004532
4533 ASSERT_NO_FATAL_FAILURE(InitState());
4534 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlis4b34ddc2015-09-17 14:18:16 -06004535
4536 BeginCommandBuffer();
Karl Schultz6addd812016-02-02 17:17:23 -07004537 // ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004538 VkCommandBuffer primCB = m_commandBuffer->GetBufferHandle();
4539 vkCmdExecuteCommands(m_commandBuffer->GetBufferHandle(), 1, &primCB);
Tobin Ehlis4b34ddc2015-09-17 14:18:16 -06004540
Chris Forbes8f36a8a2016-04-07 13:21:07 +12004541 m_errorMonitor->VerifyFound();
Tobin Ehlis4b34ddc2015-09-17 14:18:16 -06004542}
4543
Karl Schultz6addd812016-02-02 17:17:23 -07004544TEST_F(VkLayerTest, DSTypeMismatch) {
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06004545 // Create DS w/ layout of one type and attempt Update w/ mis-matched type
Karl Schultz6addd812016-02-02 17:17:23 -07004546 VkResult err;
Tobin Ehlis3b780662015-05-28 12:11:26 -06004547
Karl Schultz6addd812016-02-02 17:17:23 -07004548 m_errorMonitor->SetDesiredFailureMsg(
4549 VK_DEBUG_REPORT_ERROR_BIT_EXT, "Write descriptor update has descriptor "
4550 "type VK_DESCRIPTOR_TYPE_SAMPLER that "
4551 "does not match ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06004552
Tobin Ehlis3b780662015-05-28 12:11:26 -06004553 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultz6addd812016-02-02 17:17:23 -07004554 // VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu1b99bb22015-10-27 19:25:11 +08004555 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07004556 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
4557 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06004558
4559 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07004560 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
4561 ds_pool_ci.pNext = NULL;
4562 ds_pool_ci.maxSets = 1;
4563 ds_pool_ci.poolSizeCount = 1;
4564 ds_pool_ci.pPoolSizes = &ds_type_count;
Tony Barboureb254902015-07-15 12:50:33 -06004565
Tobin Ehlis3b780662015-05-28 12:11:26 -06004566 VkDescriptorPool ds_pool;
Karl Schultz6addd812016-02-02 17:17:23 -07004567 err =
4568 vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -06004569 ASSERT_VK_SUCCESS(err);
Tony Barboureb254902015-07-15 12:50:33 -06004570 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07004571 dsl_binding.binding = 0;
4572 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
4573 dsl_binding.descriptorCount = 1;
4574 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
4575 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis3b780662015-05-28 12:11:26 -06004576
Tony Barboureb254902015-07-15 12:50:33 -06004577 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07004578 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
4579 ds_layout_ci.pNext = NULL;
4580 ds_layout_ci.bindingCount = 1;
4581 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -06004582
Tobin Ehlis3b780662015-05-28 12:11:26 -06004583 VkDescriptorSetLayout ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07004584 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
4585 &ds_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -06004586 ASSERT_VK_SUCCESS(err);
4587
4588 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004589 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08004590 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07004591 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06004592 alloc_info.descriptorPool = ds_pool;
4593 alloc_info.pSetLayouts = &ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07004594 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info,
4595 &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -06004596 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -06004597
Tony Barboureb254902015-07-15 12:50:33 -06004598 VkSamplerCreateInfo sampler_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07004599 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
4600 sampler_ci.pNext = NULL;
4601 sampler_ci.magFilter = VK_FILTER_NEAREST;
4602 sampler_ci.minFilter = VK_FILTER_NEAREST;
4603 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
4604 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
4605 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
4606 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
4607 sampler_ci.mipLodBias = 1.0;
4608 sampler_ci.anisotropyEnable = VK_FALSE;
4609 sampler_ci.maxAnisotropy = 1;
4610 sampler_ci.compareEnable = VK_FALSE;
4611 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
4612 sampler_ci.minLod = 1.0;
4613 sampler_ci.maxLod = 1.0;
4614 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
4615 sampler_ci.unnormalizedCoordinates = VK_FALSE;
Mark Lobodzinski52ac6582015-09-01 15:42:56 -06004616
Tobin Ehlis3b780662015-05-28 12:11:26 -06004617 VkSampler sampler;
Chia-I Wuf7458c52015-10-26 21:10:41 +08004618 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
Tobin Ehlis3b780662015-05-28 12:11:26 -06004619 ASSERT_VK_SUCCESS(err);
4620
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -06004621 VkDescriptorImageInfo info = {};
4622 info.sampler = sampler;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08004623
4624 VkWriteDescriptorSet descriptor_write;
4625 memset(&descriptor_write, 0, sizeof(descriptor_write));
4626 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004627 descriptor_write.dstSet = descriptorSet;
Chia-I Wud50a7d72015-10-26 20:48:51 +08004628 descriptor_write.descriptorCount = 1;
Tobin Ehlis3b780662015-05-28 12:11:26 -06004629 // This is a mismatched type for the layout which expects BUFFER
Chia-I Wu9d00ed72015-05-25 16:27:55 +08004630 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -06004631 descriptor_write.pImageInfo = &info;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08004632
4633 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
4634
Chris Forbes8f36a8a2016-04-07 13:21:07 +12004635 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06004636
Chia-I Wuf7458c52015-10-26 21:10:41 +08004637 vkDestroySampler(m_device->device(), sampler, NULL);
4638 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
4639 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06004640}
4641
Karl Schultz6addd812016-02-02 17:17:23 -07004642TEST_F(VkLayerTest, DSUpdateOutOfBounds) {
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06004643 // For overlapping Update, have arrayIndex exceed that of layout
Karl Schultz6addd812016-02-02 17:17:23 -07004644 VkResult err;
Tobin Ehlis3b780662015-05-28 12:11:26 -06004645
Karl Schultz6addd812016-02-02 17:17:23 -07004646 m_errorMonitor->SetDesiredFailureMsg(
4647 VK_DEBUG_REPORT_ERROR_BIT_EXT, "Descriptor update type of "
4648 "VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET "
4649 "is out of bounds for matching binding");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06004650
Tobin Ehlis3b780662015-05-28 12:11:26 -06004651 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultz6addd812016-02-02 17:17:23 -07004652 // VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu1b99bb22015-10-27 19:25:11 +08004653 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07004654 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
4655 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06004656
4657 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07004658 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
4659 ds_pool_ci.pNext = NULL;
4660 ds_pool_ci.maxSets = 1;
4661 ds_pool_ci.poolSizeCount = 1;
4662 ds_pool_ci.pPoolSizes = &ds_type_count;
Tony Barboureb254902015-07-15 12:50:33 -06004663
Tobin Ehlis3b780662015-05-28 12:11:26 -06004664 VkDescriptorPool ds_pool;
Karl Schultz6addd812016-02-02 17:17:23 -07004665 err =
4666 vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -06004667 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -06004668
Tony Barboureb254902015-07-15 12:50:33 -06004669 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07004670 dsl_binding.binding = 0;
4671 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
4672 dsl_binding.descriptorCount = 1;
4673 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
4674 dsl_binding.pImmutableSamplers = NULL;
Tony Barboureb254902015-07-15 12:50:33 -06004675
4676 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07004677 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
4678 ds_layout_ci.pNext = NULL;
4679 ds_layout_ci.bindingCount = 1;
4680 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -06004681
Tobin Ehlis3b780662015-05-28 12:11:26 -06004682 VkDescriptorSetLayout ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07004683 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
4684 &ds_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -06004685 ASSERT_VK_SUCCESS(err);
4686
4687 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004688 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08004689 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07004690 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06004691 alloc_info.descriptorPool = ds_pool;
4692 alloc_info.pSetLayouts = &ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07004693 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info,
4694 &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -06004695 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -06004696
Tony Barboureb254902015-07-15 12:50:33 -06004697 VkSamplerCreateInfo sampler_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07004698 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
4699 sampler_ci.pNext = NULL;
4700 sampler_ci.magFilter = VK_FILTER_NEAREST;
4701 sampler_ci.minFilter = VK_FILTER_NEAREST;
4702 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
4703 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
4704 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
4705 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
4706 sampler_ci.mipLodBias = 1.0;
4707 sampler_ci.anisotropyEnable = VK_FALSE;
4708 sampler_ci.maxAnisotropy = 1;
4709 sampler_ci.compareEnable = VK_FALSE;
4710 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
4711 sampler_ci.minLod = 1.0;
4712 sampler_ci.maxLod = 1.0;
4713 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
4714 sampler_ci.unnormalizedCoordinates = VK_FALSE;
Tony Barboureb254902015-07-15 12:50:33 -06004715
Tobin Ehlis3b780662015-05-28 12:11:26 -06004716 VkSampler sampler;
Chia-I Wuf7458c52015-10-26 21:10:41 +08004717 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
Tobin Ehlis3b780662015-05-28 12:11:26 -06004718 ASSERT_VK_SUCCESS(err);
Chia-I Wu9d00ed72015-05-25 16:27:55 +08004719
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -06004720 VkDescriptorImageInfo info = {};
4721 info.sampler = sampler;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08004722
4723 VkWriteDescriptorSet descriptor_write;
4724 memset(&descriptor_write, 0, sizeof(descriptor_write));
4725 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004726 descriptor_write.dstSet = descriptorSet;
Karl Schultz6addd812016-02-02 17:17:23 -07004727 descriptor_write.dstArrayElement =
4728 1; /* This index out of bounds for the update */
Chia-I Wud50a7d72015-10-26 20:48:51 +08004729 descriptor_write.descriptorCount = 1;
Tobin Ehlis3b780662015-05-28 12:11:26 -06004730 // This is the wrong type, but out of bounds will be flagged first
Chia-I Wu9d00ed72015-05-25 16:27:55 +08004731 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -06004732 descriptor_write.pImageInfo = &info;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08004733
4734 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
4735
Chris Forbes8f36a8a2016-04-07 13:21:07 +12004736 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06004737
Chia-I Wuf7458c52015-10-26 21:10:41 +08004738 vkDestroySampler(m_device->device(), sampler, NULL);
4739 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
4740 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06004741}
4742
Karl Schultz6addd812016-02-02 17:17:23 -07004743TEST_F(VkLayerTest, InvalidDSUpdateIndex) {
4744 // Create layout w/ count of 1 and attempt update to that layout w/ binding
4745 // index 2
4746 VkResult err;
Tobin Ehlis3b780662015-05-28 12:11:26 -06004747
Karl Schultz6addd812016-02-02 17:17:23 -07004748 m_errorMonitor->SetDesiredFailureMsg(
4749 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06004750 " does not have binding to match update binding ");
4751
Tobin Ehlis3b780662015-05-28 12:11:26 -06004752 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultz6addd812016-02-02 17:17:23 -07004753 // VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu1b99bb22015-10-27 19:25:11 +08004754 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07004755 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
4756 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06004757
4758 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07004759 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
4760 ds_pool_ci.pNext = NULL;
4761 ds_pool_ci.maxSets = 1;
4762 ds_pool_ci.poolSizeCount = 1;
4763 ds_pool_ci.pPoolSizes = &ds_type_count;
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -06004764
Tobin Ehlis3b780662015-05-28 12:11:26 -06004765 VkDescriptorPool ds_pool;
Karl Schultz6addd812016-02-02 17:17:23 -07004766 err =
4767 vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -06004768 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -06004769
Tony Barboureb254902015-07-15 12:50:33 -06004770 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07004771 dsl_binding.binding = 0;
4772 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
4773 dsl_binding.descriptorCount = 1;
4774 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
4775 dsl_binding.pImmutableSamplers = NULL;
Tony Barboureb254902015-07-15 12:50:33 -06004776
4777 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07004778 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
4779 ds_layout_ci.pNext = NULL;
4780 ds_layout_ci.bindingCount = 1;
4781 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlis3b780662015-05-28 12:11:26 -06004782 VkDescriptorSetLayout ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07004783 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
4784 &ds_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -06004785 ASSERT_VK_SUCCESS(err);
4786
4787 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004788 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08004789 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07004790 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06004791 alloc_info.descriptorPool = ds_pool;
4792 alloc_info.pSetLayouts = &ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07004793 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info,
4794 &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -06004795 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -06004796
Tony Barboureb254902015-07-15 12:50:33 -06004797 VkSamplerCreateInfo sampler_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07004798 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
4799 sampler_ci.pNext = NULL;
4800 sampler_ci.magFilter = VK_FILTER_NEAREST;
4801 sampler_ci.minFilter = VK_FILTER_NEAREST;
4802 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
4803 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
4804 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
4805 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
4806 sampler_ci.mipLodBias = 1.0;
4807 sampler_ci.anisotropyEnable = VK_FALSE;
4808 sampler_ci.maxAnisotropy = 1;
4809 sampler_ci.compareEnable = VK_FALSE;
4810 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
4811 sampler_ci.minLod = 1.0;
4812 sampler_ci.maxLod = 1.0;
4813 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
4814 sampler_ci.unnormalizedCoordinates = VK_FALSE;
Tony Barboureb254902015-07-15 12:50:33 -06004815
Tobin Ehlis3b780662015-05-28 12:11:26 -06004816 VkSampler sampler;
Chia-I Wuf7458c52015-10-26 21:10:41 +08004817 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
Tobin Ehlis3b780662015-05-28 12:11:26 -06004818 ASSERT_VK_SUCCESS(err);
Chia-I Wu9d00ed72015-05-25 16:27:55 +08004819
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -06004820 VkDescriptorImageInfo info = {};
4821 info.sampler = sampler;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08004822
4823 VkWriteDescriptorSet descriptor_write;
4824 memset(&descriptor_write, 0, sizeof(descriptor_write));
4825 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004826 descriptor_write.dstSet = descriptorSet;
4827 descriptor_write.dstBinding = 2;
Chia-I Wud50a7d72015-10-26 20:48:51 +08004828 descriptor_write.descriptorCount = 1;
Tobin Ehlis3b780662015-05-28 12:11:26 -06004829 // This is the wrong type, but out of bounds will be flagged first
Chia-I Wu9d00ed72015-05-25 16:27:55 +08004830 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -06004831 descriptor_write.pImageInfo = &info;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08004832
4833 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
4834
Chris Forbes8f36a8a2016-04-07 13:21:07 +12004835 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06004836
Chia-I Wuf7458c52015-10-26 21:10:41 +08004837 vkDestroySampler(m_device->device(), sampler, NULL);
4838 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
4839 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06004840}
4841
Karl Schultz6addd812016-02-02 17:17:23 -07004842TEST_F(VkLayerTest, InvalidDSUpdateStruct) {
4843 // Call UpdateDS w/ struct type other than valid VK_STRUCTUR_TYPE_UPDATE_*
4844 // types
4845 VkResult err;
Tobin Ehlis3b780662015-05-28 12:11:26 -06004846
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07004847 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Karl Schultz6addd812016-02-02 17:17:23 -07004848 "Unexpected UPDATE struct of type ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06004849
Tobin Ehlis3b780662015-05-28 12:11:26 -06004850 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski209b5292015-09-17 09:44:05 -06004851
Chia-I Wu1b99bb22015-10-27 19:25:11 +08004852 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07004853 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
4854 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06004855
4856 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07004857 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
4858 ds_pool_ci.pNext = NULL;
4859 ds_pool_ci.maxSets = 1;
4860 ds_pool_ci.poolSizeCount = 1;
4861 ds_pool_ci.pPoolSizes = &ds_type_count;
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -06004862
Tobin Ehlis3b780662015-05-28 12:11:26 -06004863 VkDescriptorPool ds_pool;
Karl Schultz6addd812016-02-02 17:17:23 -07004864 err =
4865 vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -06004866 ASSERT_VK_SUCCESS(err);
Tony Barboureb254902015-07-15 12:50:33 -06004867 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07004868 dsl_binding.binding = 0;
4869 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
4870 dsl_binding.descriptorCount = 1;
4871 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
4872 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis3b780662015-05-28 12:11:26 -06004873
Tony Barboureb254902015-07-15 12:50:33 -06004874 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07004875 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
4876 ds_layout_ci.pNext = NULL;
4877 ds_layout_ci.bindingCount = 1;
4878 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -06004879
Tobin Ehlis3b780662015-05-28 12:11:26 -06004880 VkDescriptorSetLayout ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07004881 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
4882 &ds_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -06004883 ASSERT_VK_SUCCESS(err);
4884
4885 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004886 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08004887 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07004888 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06004889 alloc_info.descriptorPool = ds_pool;
4890 alloc_info.pSetLayouts = &ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07004891 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info,
4892 &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -06004893 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -06004894
Tony Barboureb254902015-07-15 12:50:33 -06004895 VkSamplerCreateInfo sampler_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07004896 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
4897 sampler_ci.pNext = NULL;
4898 sampler_ci.magFilter = VK_FILTER_NEAREST;
4899 sampler_ci.minFilter = VK_FILTER_NEAREST;
4900 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
4901 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
4902 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
4903 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
4904 sampler_ci.mipLodBias = 1.0;
4905 sampler_ci.anisotropyEnable = VK_FALSE;
4906 sampler_ci.maxAnisotropy = 1;
4907 sampler_ci.compareEnable = VK_FALSE;
4908 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
4909 sampler_ci.minLod = 1.0;
4910 sampler_ci.maxLod = 1.0;
4911 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
4912 sampler_ci.unnormalizedCoordinates = VK_FALSE;
Tobin Ehlis3b780662015-05-28 12:11:26 -06004913 VkSampler sampler;
Chia-I Wuf7458c52015-10-26 21:10:41 +08004914 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
Tobin Ehlis3b780662015-05-28 12:11:26 -06004915 ASSERT_VK_SUCCESS(err);
Chia-I Wu9d00ed72015-05-25 16:27:55 +08004916
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -06004917 VkDescriptorImageInfo info = {};
4918 info.sampler = sampler;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08004919
4920 VkWriteDescriptorSet descriptor_write;
4921 memset(&descriptor_write, 0, sizeof(descriptor_write));
Karl Schultz6addd812016-02-02 17:17:23 -07004922 descriptor_write.sType =
4923 (VkStructureType)0x99999999; /* Intentionally broken struct type */
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004924 descriptor_write.dstSet = descriptorSet;
Chia-I Wud50a7d72015-10-26 20:48:51 +08004925 descriptor_write.descriptorCount = 1;
Tobin Ehlis3b780662015-05-28 12:11:26 -06004926 // This is the wrong type, but out of bounds will be flagged first
Chia-I Wu9d00ed72015-05-25 16:27:55 +08004927 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -06004928 descriptor_write.pImageInfo = &info;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08004929
4930 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
4931
Chris Forbes8f36a8a2016-04-07 13:21:07 +12004932 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06004933
Chia-I Wuf7458c52015-10-26 21:10:41 +08004934 vkDestroySampler(m_device->device(), sampler, NULL);
4935 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
4936 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06004937}
4938
Karl Schultz6addd812016-02-02 17:17:23 -07004939TEST_F(VkLayerTest, SampleDescriptorUpdateError) {
Tobin Ehlisa1c28562015-10-23 16:00:08 -06004940 // Create a single Sampler descriptor and send it an invalid Sampler
Karl Schultz6addd812016-02-02 17:17:23 -07004941 VkResult err;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06004942
Karl Schultz6addd812016-02-02 17:17:23 -07004943 m_errorMonitor->SetDesiredFailureMsg(
4944 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06004945 "Attempt to update descriptor with invalid sampler 0xbaadbeef");
4946
Tobin Ehlisa1c28562015-10-23 16:00:08 -06004947 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultz6addd812016-02-02 17:17:23 -07004948 // TODO : Farm Descriptor setup code to helper function(s) to reduce copied
4949 // code
Chia-I Wu1b99bb22015-10-27 19:25:11 +08004950 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07004951 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLER;
4952 ds_type_count.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06004953
4954 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07004955 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
4956 ds_pool_ci.pNext = NULL;
4957 ds_pool_ci.maxSets = 1;
4958 ds_pool_ci.poolSizeCount = 1;
4959 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06004960
4961 VkDescriptorPool ds_pool;
Karl Schultz6addd812016-02-02 17:17:23 -07004962 err =
4963 vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06004964 ASSERT_VK_SUCCESS(err);
4965
4966 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07004967 dsl_binding.binding = 0;
4968 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
4969 dsl_binding.descriptorCount = 1;
4970 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
4971 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06004972
4973 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07004974 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
4975 ds_layout_ci.pNext = NULL;
4976 ds_layout_ci.bindingCount = 1;
4977 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06004978 VkDescriptorSetLayout ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07004979 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
4980 &ds_layout);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06004981 ASSERT_VK_SUCCESS(err);
4982
4983 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004984 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08004985 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07004986 alloc_info.descriptorSetCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06004987 alloc_info.descriptorPool = ds_pool;
4988 alloc_info.pSetLayouts = &ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07004989 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info,
4990 &descriptorSet);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06004991 ASSERT_VK_SUCCESS(err);
4992
Karl Schultz6addd812016-02-02 17:17:23 -07004993 VkSampler sampler =
4994 (VkSampler)((size_t)0xbaadbeef); // Sampler with invalid handle
Tobin Ehlisa1c28562015-10-23 16:00:08 -06004995
4996 VkDescriptorImageInfo descriptor_info;
4997 memset(&descriptor_info, 0, sizeof(VkDescriptorImageInfo));
4998 descriptor_info.sampler = sampler;
4999
5000 VkWriteDescriptorSet descriptor_write;
5001 memset(&descriptor_write, 0, sizeof(descriptor_write));
5002 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005003 descriptor_write.dstSet = descriptorSet;
5004 descriptor_write.dstBinding = 0;
Chia-I Wud50a7d72015-10-26 20:48:51 +08005005 descriptor_write.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06005006 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
5007 descriptor_write.pImageInfo = &descriptor_info;
5008
5009 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
5010
Chris Forbes8f36a8a2016-04-07 13:21:07 +12005011 m_errorMonitor->VerifyFound();
Tobin Ehlisa1c28562015-10-23 16:00:08 -06005012
Chia-I Wuf7458c52015-10-26 21:10:41 +08005013 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
5014 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06005015}
5016
Karl Schultz6addd812016-02-02 17:17:23 -07005017TEST_F(VkLayerTest, ImageViewDescriptorUpdateError) {
5018 // Create a single combined Image/Sampler descriptor and send it an invalid
5019 // imageView
5020 VkResult err;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06005021
Karl Schultz6addd812016-02-02 17:17:23 -07005022 m_errorMonitor->SetDesiredFailureMsg(
5023 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06005024 "Attempt to update descriptor with invalid imageView 0xbaadbeef");
5025
Tobin Ehlisa1c28562015-10-23 16:00:08 -06005026 ASSERT_NO_FATAL_FAILURE(InitState());
Chia-I Wu1b99bb22015-10-27 19:25:11 +08005027 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005028 ds_type_count.type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
5029 ds_type_count.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06005030
5031 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005032 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
5033 ds_pool_ci.pNext = NULL;
5034 ds_pool_ci.maxSets = 1;
5035 ds_pool_ci.poolSizeCount = 1;
5036 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06005037
5038 VkDescriptorPool ds_pool;
Karl Schultz6addd812016-02-02 17:17:23 -07005039 err =
5040 vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06005041 ASSERT_VK_SUCCESS(err);
5042
5043 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005044 dsl_binding.binding = 0;
5045 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
5046 dsl_binding.descriptorCount = 1;
5047 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
5048 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06005049
5050 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005051 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
5052 ds_layout_ci.pNext = NULL;
5053 ds_layout_ci.bindingCount = 1;
5054 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06005055 VkDescriptorSetLayout ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07005056 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
5057 &ds_layout);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06005058 ASSERT_VK_SUCCESS(err);
5059
5060 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005061 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08005062 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07005063 alloc_info.descriptorSetCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06005064 alloc_info.descriptorPool = ds_pool;
5065 alloc_info.pSetLayouts = &ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07005066 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info,
5067 &descriptorSet);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06005068 ASSERT_VK_SUCCESS(err);
5069
5070 VkSamplerCreateInfo sampler_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005071 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
5072 sampler_ci.pNext = NULL;
5073 sampler_ci.magFilter = VK_FILTER_NEAREST;
5074 sampler_ci.minFilter = VK_FILTER_NEAREST;
5075 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
5076 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
5077 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
5078 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
5079 sampler_ci.mipLodBias = 1.0;
5080 sampler_ci.anisotropyEnable = VK_FALSE;
5081 sampler_ci.maxAnisotropy = 1;
5082 sampler_ci.compareEnable = VK_FALSE;
5083 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
5084 sampler_ci.minLod = 1.0;
5085 sampler_ci.maxLod = 1.0;
5086 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
5087 sampler_ci.unnormalizedCoordinates = VK_FALSE;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06005088
5089 VkSampler sampler;
Chia-I Wuf7458c52015-10-26 21:10:41 +08005090 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06005091 ASSERT_VK_SUCCESS(err);
5092
Karl Schultz6addd812016-02-02 17:17:23 -07005093 VkImageView view =
5094 (VkImageView)((size_t)0xbaadbeef); // invalid imageView object
Tobin Ehlisa1c28562015-10-23 16:00:08 -06005095
5096 VkDescriptorImageInfo descriptor_info;
5097 memset(&descriptor_info, 0, sizeof(VkDescriptorImageInfo));
5098 descriptor_info.sampler = sampler;
5099 descriptor_info.imageView = view;
5100
5101 VkWriteDescriptorSet descriptor_write;
5102 memset(&descriptor_write, 0, sizeof(descriptor_write));
5103 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005104 descriptor_write.dstSet = descriptorSet;
5105 descriptor_write.dstBinding = 0;
Chia-I Wud50a7d72015-10-26 20:48:51 +08005106 descriptor_write.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06005107 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
5108 descriptor_write.pImageInfo = &descriptor_info;
5109
5110 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
5111
Chris Forbes8f36a8a2016-04-07 13:21:07 +12005112 m_errorMonitor->VerifyFound();
Tobin Ehlisa1c28562015-10-23 16:00:08 -06005113
Chia-I Wuf7458c52015-10-26 21:10:41 +08005114 vkDestroySampler(m_device->device(), sampler, NULL);
5115 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
5116 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06005117}
5118
Karl Schultz6addd812016-02-02 17:17:23 -07005119TEST_F(VkLayerTest, CopyDescriptorUpdateErrors) {
5120 // Create DS w/ layout of 2 types, write update 1 and attempt to copy-update
5121 // into the other
5122 VkResult err;
Tobin Ehlis04356f92015-10-27 16:35:27 -06005123
Karl Schultz6addd812016-02-02 17:17:23 -07005124 m_errorMonitor->SetDesiredFailureMsg(
5125 VK_DEBUG_REPORT_ERROR_BIT_EXT, "Copy descriptor update index 0, update "
5126 "count #1, has src update descriptor "
5127 "type VK_DESCRIPTOR_TYPE_SAMPLER ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06005128
Tobin Ehlis04356f92015-10-27 16:35:27 -06005129 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultz6addd812016-02-02 17:17:23 -07005130 // VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu1b99bb22015-10-27 19:25:11 +08005131 VkDescriptorPoolSize ds_type_count[2] = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005132 ds_type_count[0].type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
5133 ds_type_count[0].descriptorCount = 1;
5134 ds_type_count[1].type = VK_DESCRIPTOR_TYPE_SAMPLER;
5135 ds_type_count[1].descriptorCount = 1;
Tobin Ehlis04356f92015-10-27 16:35:27 -06005136
5137 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005138 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
5139 ds_pool_ci.pNext = NULL;
5140 ds_pool_ci.maxSets = 1;
5141 ds_pool_ci.poolSizeCount = 2;
5142 ds_pool_ci.pPoolSizes = ds_type_count;
Tobin Ehlis04356f92015-10-27 16:35:27 -06005143
5144 VkDescriptorPool ds_pool;
Karl Schultz6addd812016-02-02 17:17:23 -07005145 err =
5146 vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis04356f92015-10-27 16:35:27 -06005147 ASSERT_VK_SUCCESS(err);
5148 VkDescriptorSetLayoutBinding dsl_binding[2] = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005149 dsl_binding[0].binding = 0;
5150 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
5151 dsl_binding[0].descriptorCount = 1;
5152 dsl_binding[0].stageFlags = VK_SHADER_STAGE_ALL;
5153 dsl_binding[0].pImmutableSamplers = NULL;
5154 dsl_binding[1].binding = 1;
5155 dsl_binding[1].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
5156 dsl_binding[1].descriptorCount = 1;
5157 dsl_binding[1].stageFlags = VK_SHADER_STAGE_ALL;
5158 dsl_binding[1].pImmutableSamplers = NULL;
Tobin Ehlis04356f92015-10-27 16:35:27 -06005159
5160 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005161 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
5162 ds_layout_ci.pNext = NULL;
5163 ds_layout_ci.bindingCount = 2;
5164 ds_layout_ci.pBindings = dsl_binding;
Tobin Ehlis04356f92015-10-27 16:35:27 -06005165
5166 VkDescriptorSetLayout ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07005167 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
5168 &ds_layout);
Tobin Ehlis04356f92015-10-27 16:35:27 -06005169 ASSERT_VK_SUCCESS(err);
5170
5171 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005172 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08005173 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07005174 alloc_info.descriptorSetCount = 1;
Tobin Ehlis04356f92015-10-27 16:35:27 -06005175 alloc_info.descriptorPool = ds_pool;
5176 alloc_info.pSetLayouts = &ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07005177 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info,
5178 &descriptorSet);
Tobin Ehlis04356f92015-10-27 16:35:27 -06005179 ASSERT_VK_SUCCESS(err);
5180
5181 VkSamplerCreateInfo sampler_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005182 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
5183 sampler_ci.pNext = NULL;
5184 sampler_ci.magFilter = VK_FILTER_NEAREST;
5185 sampler_ci.minFilter = VK_FILTER_NEAREST;
5186 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
5187 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
5188 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
5189 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
5190 sampler_ci.mipLodBias = 1.0;
5191 sampler_ci.anisotropyEnable = VK_FALSE;
5192 sampler_ci.maxAnisotropy = 1;
5193 sampler_ci.compareEnable = VK_FALSE;
5194 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
5195 sampler_ci.minLod = 1.0;
5196 sampler_ci.maxLod = 1.0;
5197 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
5198 sampler_ci.unnormalizedCoordinates = VK_FALSE;
Tobin Ehlis04356f92015-10-27 16:35:27 -06005199
5200 VkSampler sampler;
Chia-I Wuf7458c52015-10-26 21:10:41 +08005201 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
Tobin Ehlis04356f92015-10-27 16:35:27 -06005202 ASSERT_VK_SUCCESS(err);
5203
5204 VkDescriptorImageInfo info = {};
5205 info.sampler = sampler;
5206
5207 VkWriteDescriptorSet descriptor_write;
5208 memset(&descriptor_write, 0, sizeof(VkWriteDescriptorSet));
5209 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005210 descriptor_write.dstSet = descriptorSet;
5211 descriptor_write.dstBinding = 1; // SAMPLER binding from layout above
Chia-I Wud50a7d72015-10-26 20:48:51 +08005212 descriptor_write.descriptorCount = 1;
Tobin Ehlis04356f92015-10-27 16:35:27 -06005213 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
5214 descriptor_write.pImageInfo = &info;
5215 // This write update should succeed
5216 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
5217 // Now perform a copy update that fails due to type mismatch
5218 VkCopyDescriptorSet copy_ds_update;
5219 memset(&copy_ds_update, 0, sizeof(VkCopyDescriptorSet));
5220 copy_ds_update.sType = VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET;
5221 copy_ds_update.srcSet = descriptorSet;
5222 copy_ds_update.srcBinding = 1; // copy from SAMPLER binding
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005223 copy_ds_update.dstSet = descriptorSet;
Karl Schultz6addd812016-02-02 17:17:23 -07005224 copy_ds_update.dstBinding = 0; // ERROR : copy to UNIFORM binding
Chia-I Wud50a7d72015-10-26 20:48:51 +08005225 copy_ds_update.descriptorCount = 1; // copy 1 descriptor
Tobin Ehlis04356f92015-10-27 16:35:27 -06005226 vkUpdateDescriptorSets(m_device->device(), 0, NULL, 1, &copy_ds_update);
5227
Chris Forbes8f36a8a2016-04-07 13:21:07 +12005228 m_errorMonitor->VerifyFound();
Tobin Ehlis04356f92015-10-27 16:35:27 -06005229 // Now perform a copy update that fails due to binding out of bounds
Karl Schultz6addd812016-02-02 17:17:23 -07005230 m_errorMonitor->SetDesiredFailureMsg(
5231 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06005232 "Copy descriptor update 0 has srcBinding 3 which is out of bounds ");
Tobin Ehlis04356f92015-10-27 16:35:27 -06005233 memset(&copy_ds_update, 0, sizeof(VkCopyDescriptorSet));
5234 copy_ds_update.sType = VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET;
5235 copy_ds_update.srcSet = descriptorSet;
Karl Schultz6addd812016-02-02 17:17:23 -07005236 copy_ds_update.srcBinding =
5237 3; // ERROR : Invalid binding for matching layout
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005238 copy_ds_update.dstSet = descriptorSet;
5239 copy_ds_update.dstBinding = 0;
Chia-I Wud50a7d72015-10-26 20:48:51 +08005240 copy_ds_update.descriptorCount = 1; // copy 1 descriptor
Tobin Ehlis04356f92015-10-27 16:35:27 -06005241 vkUpdateDescriptorSets(m_device->device(), 0, NULL, 1, &copy_ds_update);
5242
Chris Forbes8f36a8a2016-04-07 13:21:07 +12005243 m_errorMonitor->VerifyFound();
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06005244
Tobin Ehlis04356f92015-10-27 16:35:27 -06005245 // Now perform a copy update that fails due to binding out of bounds
Karl Schultz6addd812016-02-02 17:17:23 -07005246 m_errorMonitor->SetDesiredFailureMsg(
5247 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06005248 "Copy descriptor src update is out of bounds for matching binding 1 ");
5249
Tobin Ehlis04356f92015-10-27 16:35:27 -06005250 memset(&copy_ds_update, 0, sizeof(VkCopyDescriptorSet));
5251 copy_ds_update.sType = VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET;
5252 copy_ds_update.srcSet = descriptorSet;
5253 copy_ds_update.srcBinding = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005254 copy_ds_update.dstSet = descriptorSet;
5255 copy_ds_update.dstBinding = 0;
Karl Schultz6addd812016-02-02 17:17:23 -07005256 copy_ds_update.descriptorCount =
5257 5; // ERROR copy 5 descriptors (out of bounds for layout)
Tobin Ehlis04356f92015-10-27 16:35:27 -06005258 vkUpdateDescriptorSets(m_device->device(), 0, NULL, 1, &copy_ds_update);
5259
Chris Forbes8f36a8a2016-04-07 13:21:07 +12005260 m_errorMonitor->VerifyFound();
Tobin Ehlis04356f92015-10-27 16:35:27 -06005261
Chia-I Wuf7458c52015-10-26 21:10:41 +08005262 vkDestroySampler(m_device->device(), sampler, NULL);
5263 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
5264 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis04356f92015-10-27 16:35:27 -06005265}
5266
Karl Schultz6addd812016-02-02 17:17:23 -07005267TEST_F(VkLayerTest, NumSamplesMismatch) {
5268 // Create CommandBuffer where MSAA samples doesn't match RenderPass
5269 // sampleCount
5270 VkResult err;
Tobin Ehlis3b780662015-05-28 12:11:26 -06005271
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07005272 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Karl Schultz6addd812016-02-02 17:17:23 -07005273 "Num samples mismatch! ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06005274
Tobin Ehlis3b780662015-05-28 12:11:26 -06005275 ASSERT_NO_FATAL_FAILURE(InitState());
5276 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chia-I Wu1b99bb22015-10-27 19:25:11 +08005277 VkDescriptorPoolSize ds_type_count = {};
Tony Barboureb254902015-07-15 12:50:33 -06005278 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wud50a7d72015-10-26 20:48:51 +08005279 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06005280
5281 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005282 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
5283 ds_pool_ci.pNext = NULL;
5284 ds_pool_ci.maxSets = 1;
5285 ds_pool_ci.poolSizeCount = 1;
5286 ds_pool_ci.pPoolSizes = &ds_type_count;
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -06005287
Tobin Ehlis3b780662015-05-28 12:11:26 -06005288 VkDescriptorPool ds_pool;
Karl Schultz6addd812016-02-02 17:17:23 -07005289 err =
5290 vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -06005291 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -06005292
Tony Barboureb254902015-07-15 12:50:33 -06005293 VkDescriptorSetLayoutBinding dsl_binding = {};
Chia-I Wud46e6ae2015-10-31 00:31:16 +08005294 dsl_binding.binding = 0;
Tony Barboureb254902015-07-15 12:50:33 -06005295 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wu02124482015-11-06 06:42:02 +08005296 dsl_binding.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06005297 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
5298 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis3b780662015-05-28 12:11:26 -06005299
Tony Barboureb254902015-07-15 12:50:33 -06005300 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
5301 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
5302 ds_layout_ci.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08005303 ds_layout_ci.bindingCount = 1;
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07005304 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -06005305
Tobin Ehlis3b780662015-05-28 12:11:26 -06005306 VkDescriptorSetLayout ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07005307 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
5308 &ds_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -06005309 ASSERT_VK_SUCCESS(err);
5310
5311 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005312 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08005313 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07005314 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06005315 alloc_info.descriptorPool = ds_pool;
5316 alloc_info.pSetLayouts = &ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07005317 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info,
5318 &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -06005319 ASSERT_VK_SUCCESS(err);
5320
Tony Barboureb254902015-07-15 12:50:33 -06005321 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005322 pipe_ms_state_ci.sType =
5323 VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
5324 pipe_ms_state_ci.pNext = NULL;
5325 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_4_BIT;
5326 pipe_ms_state_ci.sampleShadingEnable = 0;
5327 pipe_ms_state_ci.minSampleShading = 1.0;
5328 pipe_ms_state_ci.pSampleMask = NULL;
Tobin Ehlis3b780662015-05-28 12:11:26 -06005329
Tony Barboureb254902015-07-15 12:50:33 -06005330 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005331 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
5332 pipeline_layout_ci.pNext = NULL;
5333 pipeline_layout_ci.setLayoutCount = 1;
5334 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis3b780662015-05-28 12:11:26 -06005335
5336 VkPipelineLayout pipeline_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07005337 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL,
5338 &pipeline_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -06005339 ASSERT_VK_SUCCESS(err);
5340
Karl Schultz6addd812016-02-02 17:17:23 -07005341 VkShaderObj vs(m_device, bindStateVertShaderText,
5342 VK_SHADER_STAGE_VERTEX_BIT, this);
5343 VkShaderObj fs(m_device, bindStateFragShaderText,
5344 VK_SHADER_STAGE_FRAGMENT_BIT,
Karl Schultzbdb75952016-04-19 11:36:49 -06005345 this); // We shouldn't need a fragment shader
Karl Schultz6addd812016-02-02 17:17:23 -07005346 // but add it to be able to run on more devices
Tony Barbour62e1a5b2015-08-06 10:16:07 -06005347 VkPipelineObj pipe(m_device);
5348 pipe.AddShader(&vs);
Tony Barbour1c94d372015-08-06 11:21:08 -06005349 pipe.AddShader(&fs);
Mark Youngc89c6312016-03-31 16:03:20 -06005350 pipe.AddColorAttachment();
Tony Barbour62e1a5b2015-08-06 10:16:07 -06005351 pipe.SetMSAA(&pipe_ms_state_ci);
5352 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tobin Ehlis3b780662015-05-28 12:11:26 -06005353
Tony Barbourfe3351b2015-07-28 10:17:20 -06005354 BeginCommandBuffer();
Karl Schultz6addd812016-02-02 17:17:23 -07005355 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(),
5356 VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlis3b780662015-05-28 12:11:26 -06005357
Chris Forbes8f36a8a2016-04-07 13:21:07 +12005358 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06005359
Chia-I Wuf7458c52015-10-26 21:10:41 +08005360 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
5361 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
5362 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06005363}
Tobin Ehlis0f10db52016-04-04 10:00:21 -06005364#ifdef ADD_BACK_IN_WHEN_CHECK_IS_BACK // TODO : Re-enable when GH256 fixed
Mark Youngc89c6312016-03-31 16:03:20 -06005365TEST_F(VkLayerTest, NumBlendAttachMismatch) {
5366 // Create Pipeline where the number of blend attachments doesn't match the
5367 // number of color attachments. In this case, we don't add any color
5368 // blend attachments even though we have a color attachment.
5369 VkResult err;
5370
5371 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
5372 "Mismatch between blend state attachment");
5373
5374 ASSERT_NO_FATAL_FAILURE(InitState());
5375 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
5376 VkDescriptorPoolSize ds_type_count = {};
5377 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
5378 ds_type_count.descriptorCount = 1;
5379
5380 VkDescriptorPoolCreateInfo ds_pool_ci = {};
5381 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
5382 ds_pool_ci.pNext = NULL;
5383 ds_pool_ci.maxSets = 1;
5384 ds_pool_ci.poolSizeCount = 1;
5385 ds_pool_ci.pPoolSizes = &ds_type_count;
5386
5387 VkDescriptorPool ds_pool;
5388 err =
5389 vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
5390 ASSERT_VK_SUCCESS(err);
5391
5392 VkDescriptorSetLayoutBinding dsl_binding = {};
5393 dsl_binding.binding = 0;
5394 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
5395 dsl_binding.descriptorCount = 1;
5396 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
5397 dsl_binding.pImmutableSamplers = NULL;
5398
5399 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
5400 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
5401 ds_layout_ci.pNext = NULL;
5402 ds_layout_ci.bindingCount = 1;
5403 ds_layout_ci.pBindings = &dsl_binding;
5404
5405 VkDescriptorSetLayout ds_layout;
5406 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
5407 &ds_layout);
5408 ASSERT_VK_SUCCESS(err);
5409
5410 VkDescriptorSet descriptorSet;
5411 VkDescriptorSetAllocateInfo alloc_info = {};
5412 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
5413 alloc_info.descriptorSetCount = 1;
5414 alloc_info.descriptorPool = ds_pool;
5415 alloc_info.pSetLayouts = &ds_layout;
5416 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info,
5417 &descriptorSet);
5418 ASSERT_VK_SUCCESS(err);
5419
5420 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
5421 pipe_ms_state_ci.sType =
5422 VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
5423 pipe_ms_state_ci.pNext = NULL;
5424 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
5425 pipe_ms_state_ci.sampleShadingEnable = 0;
5426 pipe_ms_state_ci.minSampleShading = 1.0;
5427 pipe_ms_state_ci.pSampleMask = NULL;
5428
5429 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
5430 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
5431 pipeline_layout_ci.pNext = NULL;
5432 pipeline_layout_ci.setLayoutCount = 1;
5433 pipeline_layout_ci.pSetLayouts = &ds_layout;
5434
5435 VkPipelineLayout pipeline_layout;
5436 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL,
5437 &pipeline_layout);
5438 ASSERT_VK_SUCCESS(err);
5439
5440 VkShaderObj vs(m_device, bindStateVertShaderText,
5441 VK_SHADER_STAGE_VERTEX_BIT, this);
5442 VkShaderObj fs(m_device, bindStateFragShaderText,
5443 VK_SHADER_STAGE_FRAGMENT_BIT,
Karl Schultzbdb75952016-04-19 11:36:49 -06005444 this); // We shouldn't need a fragment shader
Mark Youngc89c6312016-03-31 16:03:20 -06005445 // but add it to be able to run on more devices
5446 VkPipelineObj pipe(m_device);
5447 pipe.AddShader(&vs);
5448 pipe.AddShader(&fs);
5449 pipe.SetMSAA(&pipe_ms_state_ci);
5450 pipe.CreateVKPipeline(pipeline_layout, renderPass());
5451
5452 BeginCommandBuffer();
5453 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(),
5454 VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
5455
Chris Forbes8f36a8a2016-04-07 13:21:07 +12005456 m_errorMonitor->VerifyFound();
Mark Youngc89c6312016-03-31 16:03:20 -06005457
5458 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
5459 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
5460 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
5461}
Tony Barbour4e81a202016-04-04 11:09:40 -06005462#endif //ADD_BACK_IN_WHEN_CHECK_IS_BACK
Karl Schultz6addd812016-02-02 17:17:23 -07005463TEST_F(VkLayerTest, ClearCmdNoDraw) {
5464 // Create CommandBuffer where we add ClearCmd for FB Color attachment prior
5465 // to issuing a Draw
5466 VkResult err;
Tobin Ehlis53eddda2015-07-01 16:46:13 -06005467
Karl Schultz6addd812016-02-02 17:17:23 -07005468 m_errorMonitor->SetDesiredFailureMsg(
Tony Barbour7e56d302016-03-02 15:12:01 -07005469 VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06005470 "vkCmdClearAttachments() issued on CB object ");
5471
Tobin Ehlis53eddda2015-07-01 16:46:13 -06005472 ASSERT_NO_FATAL_FAILURE(InitState());
5473 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barboureb254902015-07-15 12:50:33 -06005474
Chia-I Wu1b99bb22015-10-27 19:25:11 +08005475 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005476 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
5477 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06005478
5479 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005480 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
5481 ds_pool_ci.pNext = NULL;
5482 ds_pool_ci.maxSets = 1;
5483 ds_pool_ci.poolSizeCount = 1;
5484 ds_pool_ci.pPoolSizes = &ds_type_count;
Tony Barboureb254902015-07-15 12:50:33 -06005485
Tobin Ehlis53eddda2015-07-01 16:46:13 -06005486 VkDescriptorPool ds_pool;
Karl Schultz6addd812016-02-02 17:17:23 -07005487 err =
5488 vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis53eddda2015-07-01 16:46:13 -06005489 ASSERT_VK_SUCCESS(err);
5490
Tony Barboureb254902015-07-15 12:50:33 -06005491 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005492 dsl_binding.binding = 0;
5493 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
5494 dsl_binding.descriptorCount = 1;
5495 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
5496 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis53eddda2015-07-01 16:46:13 -06005497
Tony Barboureb254902015-07-15 12:50:33 -06005498 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005499 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
5500 ds_layout_ci.pNext = NULL;
5501 ds_layout_ci.bindingCount = 1;
5502 ds_layout_ci.pBindings = &dsl_binding;
Mark Lobodzinski209b5292015-09-17 09:44:05 -06005503
Tobin Ehlis53eddda2015-07-01 16:46:13 -06005504 VkDescriptorSetLayout ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07005505 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
5506 &ds_layout);
Tobin Ehlis53eddda2015-07-01 16:46:13 -06005507 ASSERT_VK_SUCCESS(err);
5508
5509 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005510 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08005511 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07005512 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06005513 alloc_info.descriptorPool = ds_pool;
5514 alloc_info.pSetLayouts = &ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07005515 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info,
5516 &descriptorSet);
Tobin Ehlis53eddda2015-07-01 16:46:13 -06005517 ASSERT_VK_SUCCESS(err);
5518
Tony Barboureb254902015-07-15 12:50:33 -06005519 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005520 pipe_ms_state_ci.sType =
5521 VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
5522 pipe_ms_state_ci.pNext = NULL;
5523 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_4_BIT;
5524 pipe_ms_state_ci.sampleShadingEnable = 0;
5525 pipe_ms_state_ci.minSampleShading = 1.0;
5526 pipe_ms_state_ci.pSampleMask = NULL;
Tobin Ehlis53eddda2015-07-01 16:46:13 -06005527
Tony Barboureb254902015-07-15 12:50:33 -06005528 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005529 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
5530 pipeline_layout_ci.pNext = NULL;
5531 pipeline_layout_ci.setLayoutCount = 1;
5532 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis53eddda2015-07-01 16:46:13 -06005533
5534 VkPipelineLayout pipeline_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07005535 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL,
5536 &pipeline_layout);
Tobin Ehlis53eddda2015-07-01 16:46:13 -06005537 ASSERT_VK_SUCCESS(err);
Mark Lobodzinski209b5292015-09-17 09:44:05 -06005538
Karl Schultz6addd812016-02-02 17:17:23 -07005539 VkShaderObj vs(m_device, bindStateVertShaderText,
5540 VK_SHADER_STAGE_VERTEX_BIT, this);
Karl Schultzbdb75952016-04-19 11:36:49 -06005541 // We shouldn't need a fragment shader but add it to be able to run
Karl Schultz6addd812016-02-02 17:17:23 -07005542 // on more devices
5543 VkShaderObj fs(m_device, bindStateFragShaderText,
5544 VK_SHADER_STAGE_FRAGMENT_BIT, this);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06005545
Tony Barbour62e1a5b2015-08-06 10:16:07 -06005546 VkPipelineObj pipe(m_device);
5547 pipe.AddShader(&vs);
Tony Barbour1c94d372015-08-06 11:21:08 -06005548 pipe.AddShader(&fs);
Tony Barbour62e1a5b2015-08-06 10:16:07 -06005549 pipe.SetMSAA(&pipe_ms_state_ci);
5550 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tony Barbourfe3351b2015-07-28 10:17:20 -06005551
5552 BeginCommandBuffer();
Tobin Ehlis53eddda2015-07-01 16:46:13 -06005553
Karl Schultz6addd812016-02-02 17:17:23 -07005554 // Main thing we care about for this test is that the VkImage obj we're
5555 // clearing matches Color Attachment of FB
Tobin Ehlis53eddda2015-07-01 16:46:13 -06005556 // Also pass down other dummy params to keep driver and paramchecker happy
Courtney Goeltzenleuchterc9323e02015-10-15 16:51:05 -06005557 VkClearAttachment color_attachment;
5558 color_attachment.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
5559 color_attachment.clearValue.color.float32[0] = 1.0;
5560 color_attachment.clearValue.color.float32[1] = 1.0;
5561 color_attachment.clearValue.color.float32[2] = 1.0;
5562 color_attachment.clearValue.color.float32[3] = 1.0;
5563 color_attachment.colorAttachment = 0;
Karl Schultz6addd812016-02-02 17:17:23 -07005564 VkClearRect clear_rect = {
5565 {{0, 0}, {(uint32_t)m_width, (uint32_t)m_height}}};
Tobin Ehlis53eddda2015-07-01 16:46:13 -06005566
Karl Schultz6addd812016-02-02 17:17:23 -07005567 vkCmdClearAttachments(m_commandBuffer->GetBufferHandle(), 1,
5568 &color_attachment, 1, &clear_rect);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06005569
Chris Forbes8f36a8a2016-04-07 13:21:07 +12005570 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06005571
Chia-I Wuf7458c52015-10-26 21:10:41 +08005572 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
5573 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
5574 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis53eddda2015-07-01 16:46:13 -06005575}
5576
Karl Schultz6addd812016-02-02 17:17:23 -07005577TEST_F(VkLayerTest, VtxBufferBadIndex) {
5578 VkResult err;
Tobin Ehlis502480b2015-06-24 15:53:07 -06005579
Karl Schultz6addd812016-02-02 17:17:23 -07005580 m_errorMonitor->SetDesiredFailureMsg(
Mark Lobodzinski510e20d2016-02-11 09:26:16 -07005581 VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
Mark Lobodzinskidfcd9b62015-12-14 15:14:10 -07005582 "but no vertex buffers are attached to this Pipeline State Object");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06005583
Tobin Ehlis502480b2015-06-24 15:53:07 -06005584 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisd332f282015-10-02 11:00:56 -06005585 ASSERT_NO_FATAL_FAILURE(InitViewport());
Tobin Ehlis502480b2015-06-24 15:53:07 -06005586 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barboureb254902015-07-15 12:50:33 -06005587
Chia-I Wu1b99bb22015-10-27 19:25:11 +08005588 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005589 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
5590 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06005591
5592 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005593 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
5594 ds_pool_ci.pNext = NULL;
5595 ds_pool_ci.maxSets = 1;
5596 ds_pool_ci.poolSizeCount = 1;
5597 ds_pool_ci.pPoolSizes = &ds_type_count;
Tony Barboureb254902015-07-15 12:50:33 -06005598
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -06005599 VkDescriptorPool ds_pool;
Karl Schultz6addd812016-02-02 17:17:23 -07005600 err =
5601 vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis502480b2015-06-24 15:53:07 -06005602 ASSERT_VK_SUCCESS(err);
5603
Tony Barboureb254902015-07-15 12:50:33 -06005604 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005605 dsl_binding.binding = 0;
5606 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
5607 dsl_binding.descriptorCount = 1;
5608 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
5609 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis502480b2015-06-24 15:53:07 -06005610
Tony Barboureb254902015-07-15 12:50:33 -06005611 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005612 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
5613 ds_layout_ci.pNext = NULL;
5614 ds_layout_ci.bindingCount = 1;
5615 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -06005616
Tobin Ehlis502480b2015-06-24 15:53:07 -06005617 VkDescriptorSetLayout ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07005618 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
5619 &ds_layout);
Tobin Ehlis502480b2015-06-24 15:53:07 -06005620 ASSERT_VK_SUCCESS(err);
5621
5622 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005623 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08005624 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07005625 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06005626 alloc_info.descriptorPool = ds_pool;
5627 alloc_info.pSetLayouts = &ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07005628 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info,
5629 &descriptorSet);
Tobin Ehlis502480b2015-06-24 15:53:07 -06005630 ASSERT_VK_SUCCESS(err);
5631
Tony Barboureb254902015-07-15 12:50:33 -06005632 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005633 pipe_ms_state_ci.sType =
5634 VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
5635 pipe_ms_state_ci.pNext = NULL;
5636 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
5637 pipe_ms_state_ci.sampleShadingEnable = 0;
5638 pipe_ms_state_ci.minSampleShading = 1.0;
5639 pipe_ms_state_ci.pSampleMask = NULL;
Tobin Ehlis502480b2015-06-24 15:53:07 -06005640
Tony Barboureb254902015-07-15 12:50:33 -06005641 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005642 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
5643 pipeline_layout_ci.pNext = NULL;
5644 pipeline_layout_ci.setLayoutCount = 1;
5645 pipeline_layout_ci.pSetLayouts = &ds_layout;
5646 VkPipelineLayout pipeline_layout;
Tobin Ehlis502480b2015-06-24 15:53:07 -06005647
Karl Schultz6addd812016-02-02 17:17:23 -07005648 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL,
5649 &pipeline_layout);
Tobin Ehlis502480b2015-06-24 15:53:07 -06005650 ASSERT_VK_SUCCESS(err);
5651
Karl Schultz6addd812016-02-02 17:17:23 -07005652 VkShaderObj vs(m_device, bindStateVertShaderText,
5653 VK_SHADER_STAGE_VERTEX_BIT, this);
5654 VkShaderObj fs(m_device, bindStateFragShaderText,
5655 VK_SHADER_STAGE_FRAGMENT_BIT,
Karl Schultzbdb75952016-04-19 11:36:49 -06005656 this); // We shouldn't need a fragment shader
Karl Schultz6addd812016-02-02 17:17:23 -07005657 // but add it to be able to run on more devices
Tony Barbour62e1a5b2015-08-06 10:16:07 -06005658 VkPipelineObj pipe(m_device);
5659 pipe.AddShader(&vs);
Tony Barbour1c94d372015-08-06 11:21:08 -06005660 pipe.AddShader(&fs);
Mark Youngc89c6312016-03-31 16:03:20 -06005661 pipe.AddColorAttachment();
Tony Barbour62e1a5b2015-08-06 10:16:07 -06005662 pipe.SetMSAA(&pipe_ms_state_ci);
Tobin Ehlisd332f282015-10-02 11:00:56 -06005663 pipe.SetViewport(m_viewports);
5664 pipe.SetScissor(m_scissors);
Tony Barbour62e1a5b2015-08-06 10:16:07 -06005665 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tony Barbourfe3351b2015-07-28 10:17:20 -06005666
5667 BeginCommandBuffer();
Karl Schultz6addd812016-02-02 17:17:23 -07005668 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(),
5669 VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlisf7bf4502015-09-09 15:12:35 -06005670 // Don't care about actual data, just need to get to draw to flag error
5671 static const float vbo_data[3] = {1.f, 0.f, 1.f};
Karl Schultz6addd812016-02-02 17:17:23 -07005672 VkConstantBufferObj vbo(m_device, sizeof(vbo_data), sizeof(float),
5673 (const void *)&vbo_data);
Tobin Ehlisf7bf4502015-09-09 15:12:35 -06005674 BindVertexBuffer(&vbo, (VkDeviceSize)0, 1); // VBO idx 1, but no VBO in PSO
Courtney Goeltzenleuchter08c26372015-09-23 12:31:50 -06005675 Draw(1, 0, 0, 0);
Tobin Ehlis502480b2015-06-24 15:53:07 -06005676
Chris Forbes8f36a8a2016-04-07 13:21:07 +12005677 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06005678
Chia-I Wuf7458c52015-10-26 21:10:41 +08005679 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
5680 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
5681 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis502480b2015-06-24 15:53:07 -06005682}
Mark Lobodzinski209b5292015-09-17 09:44:05 -06005683#endif // DRAW_STATE_TESTS
5684
Tobin Ehlis0788f522015-05-26 16:11:58 -06005685#if THREADING_TESTS
Mike Stroyanaccf7692015-05-12 16:00:45 -06005686#if GTEST_IS_THREADSAFE
5687struct thread_data_struct {
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005688 VkCommandBuffer commandBuffer;
Mike Stroyanaccf7692015-05-12 16:00:45 -06005689 VkEvent event;
5690 bool bailout;
5691};
5692
Karl Schultz6addd812016-02-02 17:17:23 -07005693extern "C" void *AddToCommandBuffer(void *arg) {
5694 struct thread_data_struct *data = (struct thread_data_struct *)arg;
Mike Stroyanaccf7692015-05-12 16:00:45 -06005695
Karl Schultz6addd812016-02-02 17:17:23 -07005696 for (int i = 0; i < 10000; i++) {
5697 vkCmdSetEvent(data->commandBuffer, data->event,
5698 VK_PIPELINE_STAGE_ALL_COMMANDS_BIT);
Mike Stroyanaccf7692015-05-12 16:00:45 -06005699 if (data->bailout) {
5700 break;
5701 }
5702 }
5703 return NULL;
5704}
5705
Karl Schultz6addd812016-02-02 17:17:23 -07005706TEST_F(VkLayerTest, ThreadCommandBufferCollision) {
Mike Stroyan4268d1f2015-07-13 14:45:35 -06005707 test_platform_thread thread;
Mike Stroyanaccf7692015-05-12 16:00:45 -06005708
Karl Schultz6addd812016-02-02 17:17:23 -07005709 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
5710 "THREADING ERROR");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06005711
Mike Stroyanaccf7692015-05-12 16:00:45 -06005712 ASSERT_NO_FATAL_FAILURE(InitState());
5713 ASSERT_NO_FATAL_FAILURE(InitViewport());
5714 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
5715
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005716 // Calls AllocateCommandBuffers
5717 VkCommandBufferObj commandBuffer(m_device, m_commandPool);
Mark Lobodzinski5495d132015-09-30 16:19:16 -06005718
5719 // Avoid creating RenderPass
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005720 commandBuffer.BeginCommandBuffer();
Mike Stroyanaccf7692015-05-12 16:00:45 -06005721
5722 VkEventCreateInfo event_info;
5723 VkEvent event;
Mike Stroyanaccf7692015-05-12 16:00:45 -06005724 VkResult err;
5725
5726 memset(&event_info, 0, sizeof(event_info));
5727 event_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
5728
Chia-I Wuf7458c52015-10-26 21:10:41 +08005729 err = vkCreateEvent(device(), &event_info, NULL, &event);
Mike Stroyanaccf7692015-05-12 16:00:45 -06005730 ASSERT_VK_SUCCESS(err);
5731
Mike Stroyanaccf7692015-05-12 16:00:45 -06005732 err = vkResetEvent(device(), event);
5733 ASSERT_VK_SUCCESS(err);
5734
5735 struct thread_data_struct data;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005736 data.commandBuffer = commandBuffer.GetBufferHandle();
Mike Stroyanaccf7692015-05-12 16:00:45 -06005737 data.event = event;
5738 data.bailout = false;
5739 m_errorMonitor->SetBailout(&data.bailout);
5740 // Add many entries to command buffer from another thread.
Mike Stroyan4268d1f2015-07-13 14:45:35 -06005741 test_platform_thread_create(&thread, AddToCommandBuffer, (void *)&data);
Mike Stroyanaccf7692015-05-12 16:00:45 -06005742 // Add many entries to command buffer from this thread at the same time.
5743 AddToCommandBuffer(&data);
Mark Lobodzinski5495d132015-09-30 16:19:16 -06005744
Mike Stroyan4268d1f2015-07-13 14:45:35 -06005745 test_platform_thread_join(thread, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005746 commandBuffer.EndCommandBuffer();
Mike Stroyanaccf7692015-05-12 16:00:45 -06005747
Mike Stroyan10b8cb72016-01-22 15:22:03 -07005748 m_errorMonitor->SetBailout(NULL);
5749
Chris Forbes8f36a8a2016-04-07 13:21:07 +12005750 m_errorMonitor->VerifyFound();
Mike Stroyanaccf7692015-05-12 16:00:45 -06005751
Chia-I Wuf7458c52015-10-26 21:10:41 +08005752 vkDestroyEvent(device(), event, NULL);
Mike Stroyanaccf7692015-05-12 16:00:45 -06005753}
Mark Lobodzinski209b5292015-09-17 09:44:05 -06005754#endif // GTEST_IS_THREADSAFE
5755#endif // THREADING_TESTS
5756
Chris Forbes9f7ff632015-05-25 11:13:08 +12005757#if SHADER_CHECKER_TESTS
Karl Schultz6addd812016-02-02 17:17:23 -07005758TEST_F(VkLayerTest, InvalidSPIRVCodeSize) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07005759 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Karl Schultz6addd812016-02-02 17:17:23 -07005760 "Shader is not SPIR-V");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06005761
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -06005762 ASSERT_NO_FATAL_FAILURE(InitState());
5763 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
5764
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -06005765 VkShaderModule module;
5766 VkShaderModuleCreateInfo moduleCreateInfo;
5767 struct icd_spv_header spv;
5768
5769 spv.magic = ICD_SPV_MAGIC;
5770 spv.version = ICD_SPV_VERSION;
5771 spv.gen_magic = 0;
5772
5773 moduleCreateInfo.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;
5774 moduleCreateInfo.pNext = NULL;
Karl Schultz6addd812016-02-02 17:17:23 -07005775 moduleCreateInfo.pCode = (const uint32_t *)&spv;
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -06005776 moduleCreateInfo.codeSize = 4;
5777 moduleCreateInfo.flags = 0;
Chia-I Wuf7458c52015-10-26 21:10:41 +08005778 vkCreateShaderModule(m_device->device(), &moduleCreateInfo, NULL, &module);
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -06005779
Chris Forbes8f36a8a2016-04-07 13:21:07 +12005780 m_errorMonitor->VerifyFound();
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -06005781}
5782
Karl Schultz6addd812016-02-02 17:17:23 -07005783TEST_F(VkLayerTest, InvalidSPIRVMagic) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07005784 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Karl Schultz6addd812016-02-02 17:17:23 -07005785 "Shader is not SPIR-V");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06005786
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -06005787 ASSERT_NO_FATAL_FAILURE(InitState());
5788 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
5789
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -06005790 VkShaderModule module;
5791 VkShaderModuleCreateInfo moduleCreateInfo;
5792 struct icd_spv_header spv;
5793
5794 spv.magic = ~ICD_SPV_MAGIC;
5795 spv.version = ICD_SPV_VERSION;
5796 spv.gen_magic = 0;
5797
5798 moduleCreateInfo.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;
5799 moduleCreateInfo.pNext = NULL;
Karl Schultz6addd812016-02-02 17:17:23 -07005800 moduleCreateInfo.pCode = (const uint32_t *)&spv;
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -06005801 moduleCreateInfo.codeSize = sizeof(spv) + 10;
5802 moduleCreateInfo.flags = 0;
Chia-I Wuf7458c52015-10-26 21:10:41 +08005803 vkCreateShaderModule(m_device->device(), &moduleCreateInfo, NULL, &module);
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -06005804
Chris Forbes8f36a8a2016-04-07 13:21:07 +12005805 m_errorMonitor->VerifyFound();
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -06005806}
5807
Karl Schultz6addd812016-02-02 17:17:23 -07005808TEST_F(VkLayerTest, InvalidSPIRVVersion) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07005809 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Karl Schultz6addd812016-02-02 17:17:23 -07005810 "Shader is not SPIR-V");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06005811
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -06005812 ASSERT_NO_FATAL_FAILURE(InitState());
5813 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
5814
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -06005815 VkShaderModule module;
5816 VkShaderModuleCreateInfo moduleCreateInfo;
5817 struct icd_spv_header spv;
5818
5819 spv.magic = ICD_SPV_MAGIC;
5820 spv.version = ~ICD_SPV_VERSION;
5821 spv.gen_magic = 0;
5822
5823 moduleCreateInfo.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;
5824 moduleCreateInfo.pNext = NULL;
5825
Karl Schultz6addd812016-02-02 17:17:23 -07005826 moduleCreateInfo.pCode = (const uint32_t *)&spv;
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -06005827 moduleCreateInfo.codeSize = sizeof(spv) + 10;
5828 moduleCreateInfo.flags = 0;
Chia-I Wuf7458c52015-10-26 21:10:41 +08005829 vkCreateShaderModule(m_device->device(), &moduleCreateInfo, NULL, &module);
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -06005830
Chris Forbes8f36a8a2016-04-07 13:21:07 +12005831 m_errorMonitor->VerifyFound();
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -06005832}
5833
Karl Schultz6addd812016-02-02 17:17:23 -07005834TEST_F(VkLayerTest, CreatePipelineVertexOutputNotConsumed) {
Mark Lobodzinski510e20d2016-02-11 09:26:16 -07005835 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
Karl Schultz6addd812016-02-02 17:17:23 -07005836 "not consumed by fragment shader");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06005837
Chris Forbes9f7ff632015-05-25 11:13:08 +12005838 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06005839 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes9f7ff632015-05-25 11:13:08 +12005840
5841 char const *vsSource =
Chris Forbes38467712016-04-04 17:28:05 +12005842 "#version 450\n"
Chris Forbes9f7ff632015-05-25 11:13:08 +12005843 "\n"
5844 "layout(location=0) out float x;\n"
Tony Barboure804d202016-01-05 13:37:45 -07005845 "out gl_PerVertex {\n"
5846 " vec4 gl_Position;\n"
5847 "};\n"
Chris Forbes9f7ff632015-05-25 11:13:08 +12005848 "void main(){\n"
5849 " gl_Position = vec4(1);\n"
5850 " x = 0;\n"
5851 "}\n";
5852 char const *fsSource =
Chris Forbes38467712016-04-04 17:28:05 +12005853 "#version 450\n"
Chris Forbes9f7ff632015-05-25 11:13:08 +12005854 "\n"
5855 "layout(location=0) out vec4 color;\n"
5856 "void main(){\n"
5857 " color = vec4(1);\n"
5858 "}\n";
5859
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06005860 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
5861 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes9f7ff632015-05-25 11:13:08 +12005862
5863 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +08005864 pipe.AddColorAttachment();
Chris Forbes9f7ff632015-05-25 11:13:08 +12005865 pipe.AddShader(&vs);
5866 pipe.AddShader(&fs);
5867
Chris Forbes9f7ff632015-05-25 11:13:08 +12005868 VkDescriptorSetObj descriptorSet(m_device);
5869 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005870 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes9f7ff632015-05-25 11:13:08 +12005871
Tony Barbour5781e8f2015-08-04 16:23:11 -06005872 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes9f7ff632015-05-25 11:13:08 +12005873
Chris Forbes8f36a8a2016-04-07 13:21:07 +12005874 m_errorMonitor->VerifyFound();
Chris Forbes9f7ff632015-05-25 11:13:08 +12005875}
Chris Forbes9f7ff632015-05-25 11:13:08 +12005876
Karl Schultz6addd812016-02-02 17:17:23 -07005877TEST_F(VkLayerTest, CreatePipelineFragmentInputNotProvided) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07005878 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Karl Schultz6addd812016-02-02 17:17:23 -07005879 "not written by vertex shader");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06005880
Chris Forbes59cb88d2015-05-25 11:13:13 +12005881 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06005882 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes59cb88d2015-05-25 11:13:13 +12005883
5884 char const *vsSource =
Chris Forbes38467712016-04-04 17:28:05 +12005885 "#version 450\n"
Chris Forbes59cb88d2015-05-25 11:13:13 +12005886 "\n"
Tony Barboure804d202016-01-05 13:37:45 -07005887 "out gl_PerVertex {\n"
5888 " vec4 gl_Position;\n"
5889 "};\n"
Chris Forbes59cb88d2015-05-25 11:13:13 +12005890 "void main(){\n"
5891 " gl_Position = vec4(1);\n"
5892 "}\n";
5893 char const *fsSource =
Chris Forbes38467712016-04-04 17:28:05 +12005894 "#version 450\n"
Chris Forbes59cb88d2015-05-25 11:13:13 +12005895 "\n"
5896 "layout(location=0) in float x;\n"
5897 "layout(location=0) out vec4 color;\n"
5898 "void main(){\n"
5899 " color = vec4(x);\n"
5900 "}\n";
5901
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06005902 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
5903 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes59cb88d2015-05-25 11:13:13 +12005904
5905 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +08005906 pipe.AddColorAttachment();
Chris Forbes59cb88d2015-05-25 11:13:13 +12005907 pipe.AddShader(&vs);
5908 pipe.AddShader(&fs);
5909
Chris Forbes59cb88d2015-05-25 11:13:13 +12005910 VkDescriptorSetObj descriptorSet(m_device);
5911 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005912 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes59cb88d2015-05-25 11:13:13 +12005913
Tony Barbour5781e8f2015-08-04 16:23:11 -06005914 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes59cb88d2015-05-25 11:13:13 +12005915
Chris Forbes8f36a8a2016-04-07 13:21:07 +12005916 m_errorMonitor->VerifyFound();
Chris Forbes59cb88d2015-05-25 11:13:13 +12005917}
5918
Karl Schultz6addd812016-02-02 17:17:23 -07005919TEST_F(VkLayerTest, CreatePipelineFragmentInputNotProvidedInBlock) {
Chris Forbesa3e85f62016-01-15 14:53:11 +13005920 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Karl Schultz6addd812016-02-02 17:17:23 -07005921 "not written by vertex shader");
Chris Forbesa3e85f62016-01-15 14:53:11 +13005922
5923 ASSERT_NO_FATAL_FAILURE(InitState());
5924 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
5925
5926 char const *vsSource =
Chris Forbes38467712016-04-04 17:28:05 +12005927 "#version 450\n"
Chris Forbesa3e85f62016-01-15 14:53:11 +13005928 "\n"
5929 "out gl_PerVertex {\n"
5930 " vec4 gl_Position;\n"
5931 "};\n"
5932 "void main(){\n"
5933 " gl_Position = vec4(1);\n"
5934 "}\n";
5935 char const *fsSource =
5936 "#version 450\n"
Chris Forbesa3e85f62016-01-15 14:53:11 +13005937 "\n"
5938 "in block { layout(location=0) float x; } ins;\n"
5939 "layout(location=0) out vec4 color;\n"
5940 "void main(){\n"
5941 " color = vec4(ins.x);\n"
5942 "}\n";
5943
5944 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
5945 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
5946
5947 VkPipelineObj pipe(m_device);
5948 pipe.AddColorAttachment();
5949 pipe.AddShader(&vs);
5950 pipe.AddShader(&fs);
5951
5952 VkDescriptorSetObj descriptorSet(m_device);
5953 descriptorSet.AppendDummy();
5954 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
5955
5956 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
5957
Chris Forbes8f36a8a2016-04-07 13:21:07 +12005958 m_errorMonitor->VerifyFound();
Chris Forbesa3e85f62016-01-15 14:53:11 +13005959}
5960
Karl Schultz6addd812016-02-02 17:17:23 -07005961TEST_F(VkLayerTest, CreatePipelineVsFsTypeMismatchArraySize) {
Chris Forbes0036fd12016-01-26 14:19:49 +13005962 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Chris Forbese9928822016-02-17 14:44:52 +13005963 "Type mismatch on location 0.0: 'ptr to "
Karl Schultz6addd812016-02-02 17:17:23 -07005964 "output arr[2] of float32' vs 'ptr to "
5965 "input arr[3] of float32'");
Chris Forbes0036fd12016-01-26 14:19:49 +13005966
5967 ASSERT_NO_FATAL_FAILURE(InitState());
5968 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
5969
5970 char const *vsSource =
Chris Forbes38467712016-04-04 17:28:05 +12005971 "#version 450\n"
Chris Forbes0036fd12016-01-26 14:19:49 +13005972 "\n"
5973 "layout(location=0) out float x[2];\n"
5974 "out gl_PerVertex {\n"
5975 " vec4 gl_Position;\n"
5976 "};\n"
5977 "void main(){\n"
5978 " x[0] = 0; x[1] = 0;\n"
5979 " gl_Position = vec4(1);\n"
5980 "}\n";
5981 char const *fsSource =
Chris Forbes38467712016-04-04 17:28:05 +12005982 "#version 450\n"
Chris Forbes0036fd12016-01-26 14:19:49 +13005983 "\n"
5984 "layout(location=0) in float x[3];\n"
5985 "layout(location=0) out vec4 color;\n"
5986 "void main(){\n"
5987 " color = vec4(x[0] + x[1] + x[2]);\n"
5988 "}\n";
5989
5990 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
5991 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
5992
5993 VkPipelineObj pipe(m_device);
5994 pipe.AddColorAttachment();
5995 pipe.AddShader(&vs);
5996 pipe.AddShader(&fs);
5997
5998 VkDescriptorSetObj descriptorSet(m_device);
5999 descriptorSet.AppendDummy();
6000 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
6001
6002 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
6003
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006004 m_errorMonitor->VerifyFound();
Chris Forbes0036fd12016-01-26 14:19:49 +13006005}
6006
Karl Schultz6addd812016-02-02 17:17:23 -07006007TEST_F(VkLayerTest, CreatePipelineVsFsTypeMismatch) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07006008 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Karl Schultz6addd812016-02-02 17:17:23 -07006009 "Type mismatch on location 0");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06006010
Chris Forbesb56af562015-05-25 11:13:17 +12006011 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06006012 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesb56af562015-05-25 11:13:17 +12006013
6014 char const *vsSource =
Chris Forbes38467712016-04-04 17:28:05 +12006015 "#version 450\n"
Chris Forbesb56af562015-05-25 11:13:17 +12006016 "\n"
6017 "layout(location=0) out int x;\n"
Tony Barboure804d202016-01-05 13:37:45 -07006018 "out gl_PerVertex {\n"
6019 " vec4 gl_Position;\n"
6020 "};\n"
Chris Forbesb56af562015-05-25 11:13:17 +12006021 "void main(){\n"
6022 " x = 0;\n"
6023 " gl_Position = vec4(1);\n"
6024 "}\n";
6025 char const *fsSource =
Chris Forbes38467712016-04-04 17:28:05 +12006026 "#version 450\n"
Chris Forbesb56af562015-05-25 11:13:17 +12006027 "\n"
Karl Schultz6addd812016-02-02 17:17:23 -07006028 "layout(location=0) in float x;\n" /* VS writes int */
Chris Forbesb56af562015-05-25 11:13:17 +12006029 "layout(location=0) out vec4 color;\n"
6030 "void main(){\n"
6031 " color = vec4(x);\n"
6032 "}\n";
6033
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06006034 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
6035 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesb56af562015-05-25 11:13:17 +12006036
6037 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +08006038 pipe.AddColorAttachment();
Chris Forbesb56af562015-05-25 11:13:17 +12006039 pipe.AddShader(&vs);
6040 pipe.AddShader(&fs);
6041
Chris Forbesb56af562015-05-25 11:13:17 +12006042 VkDescriptorSetObj descriptorSet(m_device);
6043 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006044 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesb56af562015-05-25 11:13:17 +12006045
Tony Barbour5781e8f2015-08-04 16:23:11 -06006046 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesb56af562015-05-25 11:13:17 +12006047
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006048 m_errorMonitor->VerifyFound();
Chris Forbesb56af562015-05-25 11:13:17 +12006049}
6050
Karl Schultz6addd812016-02-02 17:17:23 -07006051TEST_F(VkLayerTest, CreatePipelineVsFsTypeMismatchInBlock) {
Chris Forbesa3e85f62016-01-15 14:53:11 +13006052 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Karl Schultz6addd812016-02-02 17:17:23 -07006053 "Type mismatch on location 0");
Chris Forbesa3e85f62016-01-15 14:53:11 +13006054
6055 ASSERT_NO_FATAL_FAILURE(InitState());
6056 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
6057
6058 char const *vsSource =
6059 "#version 450\n"
Chris Forbesa3e85f62016-01-15 14:53:11 +13006060 "\n"
6061 "out block { layout(location=0) int x; } outs;\n"
6062 "out gl_PerVertex {\n"
6063 " vec4 gl_Position;\n"
6064 "};\n"
6065 "void main(){\n"
6066 " outs.x = 0;\n"
6067 " gl_Position = vec4(1);\n"
6068 "}\n";
6069 char const *fsSource =
6070 "#version 450\n"
Chris Forbesa3e85f62016-01-15 14:53:11 +13006071 "\n"
Karl Schultz6addd812016-02-02 17:17:23 -07006072 "in block { layout(location=0) float x; } ins;\n" /* VS writes int */
Chris Forbesa3e85f62016-01-15 14:53:11 +13006073 "layout(location=0) out vec4 color;\n"
6074 "void main(){\n"
6075 " color = vec4(ins.x);\n"
6076 "}\n";
6077
6078 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
6079 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
6080
6081 VkPipelineObj pipe(m_device);
6082 pipe.AddColorAttachment();
6083 pipe.AddShader(&vs);
6084 pipe.AddShader(&fs);
6085
6086 VkDescriptorSetObj descriptorSet(m_device);
6087 descriptorSet.AppendDummy();
6088 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
6089
6090 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
6091
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006092 m_errorMonitor->VerifyFound();
Chris Forbese9928822016-02-17 14:44:52 +13006093}
6094
6095TEST_F(VkLayerTest, CreatePipelineVsFsMismatchByLocation) {
6096 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
6097 "location 0.0 which is not written by vertex shader");
6098
6099 ASSERT_NO_FATAL_FAILURE(InitState());
6100 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
6101
6102 char const *vsSource =
6103 "#version 450\n"
Chris Forbese9928822016-02-17 14:44:52 +13006104 "\n"
6105 "out block { layout(location=1) float x; } outs;\n"
6106 "out gl_PerVertex {\n"
6107 " vec4 gl_Position;\n"
6108 "};\n"
6109 "void main(){\n"
6110 " outs.x = 0;\n"
6111 " gl_Position = vec4(1);\n"
6112 "}\n";
6113 char const *fsSource =
6114 "#version 450\n"
Chris Forbese9928822016-02-17 14:44:52 +13006115 "\n"
6116 "in block { layout(location=0) float x; } ins;\n"
6117 "layout(location=0) out vec4 color;\n"
6118 "void main(){\n"
6119 " color = vec4(ins.x);\n"
6120 "}\n";
6121
6122 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
6123 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
6124
6125 VkPipelineObj pipe(m_device);
6126 pipe.AddColorAttachment();
6127 pipe.AddShader(&vs);
6128 pipe.AddShader(&fs);
6129
6130 VkDescriptorSetObj descriptorSet(m_device);
6131 descriptorSet.AppendDummy();
6132 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
6133
6134 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
6135
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006136 m_errorMonitor->VerifyFound();
Chris Forbese9928822016-02-17 14:44:52 +13006137}
6138
6139TEST_F(VkLayerTest, CreatePipelineVsFsMismatchByComponent) {
6140 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
6141 "location 0.1 which is not written by vertex shader");
6142
6143 ASSERT_NO_FATAL_FAILURE(InitState());
6144 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
6145
6146 char const *vsSource =
6147 "#version 450\n"
Chris Forbese9928822016-02-17 14:44:52 +13006148 "\n"
6149 "out block { layout(location=0, component=0) float x; } outs;\n"
6150 "out gl_PerVertex {\n"
6151 " vec4 gl_Position;\n"
6152 "};\n"
6153 "void main(){\n"
6154 " outs.x = 0;\n"
6155 " gl_Position = vec4(1);\n"
6156 "}\n";
6157 char const *fsSource =
6158 "#version 450\n"
Chris Forbese9928822016-02-17 14:44:52 +13006159 "\n"
6160 "in block { layout(location=0, component=1) float x; } ins;\n"
6161 "layout(location=0) out vec4 color;\n"
6162 "void main(){\n"
6163 " color = vec4(ins.x);\n"
6164 "}\n";
6165
6166 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
6167 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
6168
6169 VkPipelineObj pipe(m_device);
6170 pipe.AddColorAttachment();
6171 pipe.AddShader(&vs);
6172 pipe.AddShader(&fs);
6173
6174 VkDescriptorSetObj descriptorSet(m_device);
6175 descriptorSet.AppendDummy();
6176 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
6177
6178 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
6179
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006180 m_errorMonitor->VerifyFound();
Chris Forbesa3e85f62016-01-15 14:53:11 +13006181}
6182
Karl Schultz6addd812016-02-02 17:17:23 -07006183TEST_F(VkLayerTest, CreatePipelineAttribNotConsumed) {
Mark Lobodzinski510e20d2016-02-11 09:26:16 -07006184 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
Karl Schultz6addd812016-02-02 17:17:23 -07006185 "location 0 not consumed by VS");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06006186
Chris Forbesde136e02015-05-25 11:13:28 +12006187 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06006188 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesde136e02015-05-25 11:13:28 +12006189
6190 VkVertexInputBindingDescription input_binding;
6191 memset(&input_binding, 0, sizeof(input_binding));
6192
6193 VkVertexInputAttributeDescription input_attrib;
6194 memset(&input_attrib, 0, sizeof(input_attrib));
6195 input_attrib.format = VK_FORMAT_R32_SFLOAT;
6196
6197 char const *vsSource =
Chris Forbes38467712016-04-04 17:28:05 +12006198 "#version 450\n"
Chris Forbesde136e02015-05-25 11:13:28 +12006199 "\n"
Tony Barboure804d202016-01-05 13:37:45 -07006200 "out gl_PerVertex {\n"
6201 " vec4 gl_Position;\n"
6202 "};\n"
Chris Forbesde136e02015-05-25 11:13:28 +12006203 "void main(){\n"
6204 " gl_Position = vec4(1);\n"
6205 "}\n";
6206 char const *fsSource =
Chris Forbes38467712016-04-04 17:28:05 +12006207 "#version 450\n"
Chris Forbesde136e02015-05-25 11:13:28 +12006208 "\n"
6209 "layout(location=0) out vec4 color;\n"
6210 "void main(){\n"
6211 " color = vec4(1);\n"
6212 "}\n";
6213
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06006214 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
6215 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesde136e02015-05-25 11:13:28 +12006216
6217 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +08006218 pipe.AddColorAttachment();
Chris Forbesde136e02015-05-25 11:13:28 +12006219 pipe.AddShader(&vs);
6220 pipe.AddShader(&fs);
6221
6222 pipe.AddVertexInputBindings(&input_binding, 1);
6223 pipe.AddVertexInputAttribs(&input_attrib, 1);
6224
Chris Forbesde136e02015-05-25 11:13:28 +12006225 VkDescriptorSetObj descriptorSet(m_device);
6226 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006227 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesde136e02015-05-25 11:13:28 +12006228
Tony Barbour5781e8f2015-08-04 16:23:11 -06006229 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesde136e02015-05-25 11:13:28 +12006230
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006231 m_errorMonitor->VerifyFound();
Chris Forbesde136e02015-05-25 11:13:28 +12006232}
6233
Karl Schultz6addd812016-02-02 17:17:23 -07006234TEST_F(VkLayerTest, CreatePipelineAttribLocationMismatch) {
Mark Lobodzinski510e20d2016-02-11 09:26:16 -07006235 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
Karl Schultz6addd812016-02-02 17:17:23 -07006236 "location 0 not consumed by VS");
Chris Forbes7d83cd52016-01-15 11:32:03 +13006237
6238 ASSERT_NO_FATAL_FAILURE(InitState());
6239 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
6240
6241 VkVertexInputBindingDescription input_binding;
6242 memset(&input_binding, 0, sizeof(input_binding));
6243
6244 VkVertexInputAttributeDescription input_attrib;
6245 memset(&input_attrib, 0, sizeof(input_attrib));
6246 input_attrib.format = VK_FORMAT_R32_SFLOAT;
6247
6248 char const *vsSource =
Chris Forbes38467712016-04-04 17:28:05 +12006249 "#version 450\n"
Chris Forbes7d83cd52016-01-15 11:32:03 +13006250 "\n"
6251 "layout(location=1) in float x;\n"
6252 "out gl_PerVertex {\n"
6253 " vec4 gl_Position;\n"
6254 "};\n"
6255 "void main(){\n"
6256 " gl_Position = vec4(x);\n"
6257 "}\n";
6258 char const *fsSource =
Chris Forbes38467712016-04-04 17:28:05 +12006259 "#version 450\n"
Chris Forbes7d83cd52016-01-15 11:32:03 +13006260 "\n"
6261 "layout(location=0) out vec4 color;\n"
6262 "void main(){\n"
6263 " color = vec4(1);\n"
6264 "}\n";
6265
6266 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
6267 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
6268
6269 VkPipelineObj pipe(m_device);
6270 pipe.AddColorAttachment();
6271 pipe.AddShader(&vs);
6272 pipe.AddShader(&fs);
6273
6274 pipe.AddVertexInputBindings(&input_binding, 1);
6275 pipe.AddVertexInputAttribs(&input_attrib, 1);
6276
6277 VkDescriptorSetObj descriptorSet(m_device);
6278 descriptorSet.AppendDummy();
6279 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
6280
6281 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
6282
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006283 m_errorMonitor->VerifyFound();
Chris Forbes7d83cd52016-01-15 11:32:03 +13006284}
6285
Karl Schultz6addd812016-02-02 17:17:23 -07006286TEST_F(VkLayerTest, CreatePipelineAttribNotProvided) {
6287 m_errorMonitor->SetDesiredFailureMsg(
6288 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06006289 "VS consumes input at location 0 but not provided");
6290
Chris Forbes62e8e502015-05-25 11:13:29 +12006291 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06006292 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes62e8e502015-05-25 11:13:29 +12006293
6294 char const *vsSource =
Chris Forbes38467712016-04-04 17:28:05 +12006295 "#version 450\n"
Chris Forbes62e8e502015-05-25 11:13:29 +12006296 "\n"
Karl Schultz6addd812016-02-02 17:17:23 -07006297 "layout(location=0) in vec4 x;\n" /* not provided */
Tony Barboure804d202016-01-05 13:37:45 -07006298 "out gl_PerVertex {\n"
6299 " vec4 gl_Position;\n"
6300 "};\n"
Chris Forbes62e8e502015-05-25 11:13:29 +12006301 "void main(){\n"
6302 " gl_Position = x;\n"
6303 "}\n";
6304 char const *fsSource =
Chris Forbes38467712016-04-04 17:28:05 +12006305 "#version 450\n"
Chris Forbes62e8e502015-05-25 11:13:29 +12006306 "\n"
6307 "layout(location=0) out vec4 color;\n"
6308 "void main(){\n"
6309 " color = vec4(1);\n"
6310 "}\n";
6311
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06006312 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
6313 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes62e8e502015-05-25 11:13:29 +12006314
6315 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +08006316 pipe.AddColorAttachment();
Chris Forbes62e8e502015-05-25 11:13:29 +12006317 pipe.AddShader(&vs);
6318 pipe.AddShader(&fs);
6319
Chris Forbes62e8e502015-05-25 11:13:29 +12006320 VkDescriptorSetObj descriptorSet(m_device);
6321 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006322 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes62e8e502015-05-25 11:13:29 +12006323
Tony Barbour5781e8f2015-08-04 16:23:11 -06006324 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes62e8e502015-05-25 11:13:29 +12006325
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006326 m_errorMonitor->VerifyFound();
Chris Forbes62e8e502015-05-25 11:13:29 +12006327}
6328
Karl Schultz6addd812016-02-02 17:17:23 -07006329TEST_F(VkLayerTest, CreatePipelineAttribTypeMismatch) {
6330 m_errorMonitor->SetDesiredFailureMsg(
6331 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06006332 "location 0 does not match VS input type");
6333
Chris Forbesc97d98e2015-05-25 11:13:31 +12006334 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06006335 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesc97d98e2015-05-25 11:13:31 +12006336
6337 VkVertexInputBindingDescription input_binding;
6338 memset(&input_binding, 0, sizeof(input_binding));
6339
6340 VkVertexInputAttributeDescription input_attrib;
6341 memset(&input_attrib, 0, sizeof(input_attrib));
6342 input_attrib.format = VK_FORMAT_R32_SFLOAT;
6343
6344 char const *vsSource =
Chris Forbes38467712016-04-04 17:28:05 +12006345 "#version 450\n"
Chris Forbesc97d98e2015-05-25 11:13:31 +12006346 "\n"
Karl Schultz6addd812016-02-02 17:17:23 -07006347 "layout(location=0) in int x;\n" /* attrib provided float */
Tony Barboure804d202016-01-05 13:37:45 -07006348 "out gl_PerVertex {\n"
6349 " vec4 gl_Position;\n"
6350 "};\n"
Chris Forbesc97d98e2015-05-25 11:13:31 +12006351 "void main(){\n"
6352 " gl_Position = vec4(x);\n"
6353 "}\n";
6354 char const *fsSource =
Chris Forbes38467712016-04-04 17:28:05 +12006355 "#version 450\n"
Chris Forbesc97d98e2015-05-25 11:13:31 +12006356 "\n"
6357 "layout(location=0) out vec4 color;\n"
6358 "void main(){\n"
6359 " color = vec4(1);\n"
6360 "}\n";
6361
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06006362 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
6363 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesc97d98e2015-05-25 11:13:31 +12006364
6365 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +08006366 pipe.AddColorAttachment();
Chris Forbesc97d98e2015-05-25 11:13:31 +12006367 pipe.AddShader(&vs);
6368 pipe.AddShader(&fs);
6369
6370 pipe.AddVertexInputBindings(&input_binding, 1);
6371 pipe.AddVertexInputAttribs(&input_attrib, 1);
6372
Chris Forbesc97d98e2015-05-25 11:13:31 +12006373 VkDescriptorSetObj descriptorSet(m_device);
6374 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006375 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesc97d98e2015-05-25 11:13:31 +12006376
Tony Barbour5781e8f2015-08-04 16:23:11 -06006377 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesc97d98e2015-05-25 11:13:31 +12006378
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006379 m_errorMonitor->VerifyFound();
Chris Forbesc97d98e2015-05-25 11:13:31 +12006380}
6381
Chris Forbesc68b43c2016-04-06 11:18:47 +12006382TEST_F(VkLayerTest, CreatePipelineDuplicateStage) {
6383 m_errorMonitor->SetDesiredFailureMsg(
6384 VK_DEBUG_REPORT_ERROR_BIT_EXT,
6385 "Multiple shaders provided for stage VK_SHADER_STAGE_VERTEX_BIT");
6386
6387 ASSERT_NO_FATAL_FAILURE(InitState());
6388 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
6389
6390 char const *vsSource =
6391 "#version 450\n"
6392 "\n"
6393 "out gl_PerVertex {\n"
6394 " vec4 gl_Position;\n"
6395 "};\n"
6396 "void main(){\n"
6397 " gl_Position = vec4(1);\n"
6398 "}\n";
6399 char const *fsSource =
6400 "#version 450\n"
6401 "\n"
6402 "layout(location=0) out vec4 color;\n"
6403 "void main(){\n"
6404 " color = vec4(1);\n"
6405 "}\n";
6406
6407 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
6408 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
6409
6410 VkPipelineObj pipe(m_device);
6411 pipe.AddColorAttachment();
6412 pipe.AddShader(&vs);
6413 pipe.AddShader(&vs);
6414 pipe.AddShader(&fs);
6415
6416 VkDescriptorSetObj descriptorSet(m_device);
6417 descriptorSet.AppendDummy();
6418 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
6419
6420 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
6421
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006422 m_errorMonitor->VerifyFound();
Chris Forbesc68b43c2016-04-06 11:18:47 +12006423}
6424
Karl Schultz6addd812016-02-02 17:17:23 -07006425TEST_F(VkLayerTest, CreatePipelineAttribMatrixType) {
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006426 m_errorMonitor->ExpectSuccess();
Chris Forbes2682b242015-11-24 11:13:14 +13006427
6428 ASSERT_NO_FATAL_FAILURE(InitState());
6429 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
6430
6431 VkVertexInputBindingDescription input_binding;
6432 memset(&input_binding, 0, sizeof(input_binding));
6433
6434 VkVertexInputAttributeDescription input_attribs[2];
6435 memset(input_attribs, 0, sizeof(input_attribs));
6436
6437 for (int i = 0; i < 2; i++) {
6438 input_attribs[i].format = VK_FORMAT_R32G32B32A32_SFLOAT;
6439 input_attribs[i].location = i;
6440 }
6441
6442 char const *vsSource =
Chris Forbes38467712016-04-04 17:28:05 +12006443 "#version 450\n"
Chris Forbes2682b242015-11-24 11:13:14 +13006444 "\n"
6445 "layout(location=0) in mat2x4 x;\n"
Tony Barboure804d202016-01-05 13:37:45 -07006446 "out gl_PerVertex {\n"
6447 " vec4 gl_Position;\n"
6448 "};\n"
Chris Forbes2682b242015-11-24 11:13:14 +13006449 "void main(){\n"
6450 " gl_Position = x[0] + x[1];\n"
6451 "}\n";
6452 char const *fsSource =
Chris Forbes38467712016-04-04 17:28:05 +12006453 "#version 450\n"
Chris Forbes2682b242015-11-24 11:13:14 +13006454 "\n"
6455 "layout(location=0) out vec4 color;\n"
6456 "void main(){\n"
6457 " color = vec4(1);\n"
6458 "}\n";
6459
6460 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
6461 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
6462
6463 VkPipelineObj pipe(m_device);
6464 pipe.AddColorAttachment();
6465 pipe.AddShader(&vs);
6466 pipe.AddShader(&fs);
6467
6468 pipe.AddVertexInputBindings(&input_binding, 1);
6469 pipe.AddVertexInputAttribs(input_attribs, 2);
6470
6471 VkDescriptorSetObj descriptorSet(m_device);
6472 descriptorSet.AppendDummy();
6473 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
6474
6475 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
6476
6477 /* expect success */
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006478 m_errorMonitor->VerifyNotFound();
Chris Forbes2682b242015-11-24 11:13:14 +13006479}
6480
Chris Forbes2682b242015-11-24 11:13:14 +13006481TEST_F(VkLayerTest, CreatePipelineAttribArrayType)
6482{
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006483 m_errorMonitor->ExpectSuccess();
Chris Forbes2682b242015-11-24 11:13:14 +13006484
6485 ASSERT_NO_FATAL_FAILURE(InitState());
6486 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
6487
6488 VkVertexInputBindingDescription input_binding;
6489 memset(&input_binding, 0, sizeof(input_binding));
6490
6491 VkVertexInputAttributeDescription input_attribs[2];
6492 memset(input_attribs, 0, sizeof(input_attribs));
6493
6494 for (int i = 0; i < 2; i++) {
6495 input_attribs[i].format = VK_FORMAT_R32G32B32A32_SFLOAT;
6496 input_attribs[i].location = i;
6497 }
6498
6499 char const *vsSource =
Chris Forbes38467712016-04-04 17:28:05 +12006500 "#version 450\n"
Chris Forbes2682b242015-11-24 11:13:14 +13006501 "\n"
6502 "layout(location=0) in vec4 x[2];\n"
Tony Barboure804d202016-01-05 13:37:45 -07006503 "out gl_PerVertex {\n"
6504 " vec4 gl_Position;\n"
6505 "};\n"
Chris Forbes2682b242015-11-24 11:13:14 +13006506 "void main(){\n"
6507 " gl_Position = x[0] + x[1];\n"
6508 "}\n";
6509 char const *fsSource =
Chris Forbes38467712016-04-04 17:28:05 +12006510 "#version 450\n"
Chris Forbes2682b242015-11-24 11:13:14 +13006511 "\n"
6512 "layout(location=0) out vec4 color;\n"
6513 "void main(){\n"
6514 " color = vec4(1);\n"
6515 "}\n";
6516
6517 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
6518 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
6519
6520 VkPipelineObj pipe(m_device);
6521 pipe.AddColorAttachment();
6522 pipe.AddShader(&vs);
6523 pipe.AddShader(&fs);
6524
6525 pipe.AddVertexInputBindings(&input_binding, 1);
6526 pipe.AddVertexInputAttribs(input_attribs, 2);
6527
6528 VkDescriptorSetObj descriptorSet(m_device);
6529 descriptorSet.AppendDummy();
6530 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
6531
6532 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
6533
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006534 m_errorMonitor->VerifyNotFound();
Chris Forbes2682b242015-11-24 11:13:14 +13006535}
Chris Forbes2682b242015-11-24 11:13:14 +13006536
Chris Forbes4ea14fc2016-04-04 18:52:54 +12006537TEST_F(VkLayerTest, CreatePipelineSimplePositive)
6538{
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006539 m_errorMonitor->ExpectSuccess();
Chris Forbes4ea14fc2016-04-04 18:52:54 +12006540
6541 ASSERT_NO_FATAL_FAILURE(InitState());
6542 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
6543
6544 char const *vsSource =
6545 "#version 450\n"
6546 "out gl_PerVertex {\n"
6547 " vec4 gl_Position;\n"
6548 "};\n"
6549 "void main(){\n"
6550 " gl_Position = vec4(0);\n"
6551 "}\n";
6552 char const *fsSource =
6553 "#version 450\n"
6554 "\n"
6555 "layout(location=0) out vec4 color;\n"
6556 "void main(){\n"
6557 " color = vec4(1);\n"
6558 "}\n";
6559
6560 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
6561 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
6562
6563 VkPipelineObj pipe(m_device);
6564 pipe.AddColorAttachment();
6565 pipe.AddShader(&vs);
6566 pipe.AddShader(&fs);
6567
6568 VkDescriptorSetObj descriptorSet(m_device);
6569 descriptorSet.AppendDummy();
6570 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
6571
6572 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
6573
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006574 m_errorMonitor->VerifyNotFound();
Chris Forbes4ea14fc2016-04-04 18:52:54 +12006575}
6576
Chris Forbes912c9192016-04-05 17:50:35 +12006577TEST_F(VkLayerTest, CreatePipelineRelaxedTypeMatch)
6578{
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006579 m_errorMonitor->ExpectSuccess();
Chris Forbes912c9192016-04-05 17:50:35 +12006580
6581 // VK 1.0.8 Specification, 14.1.3 "Additionally,..." block
6582
6583 ASSERT_NO_FATAL_FAILURE(InitState());
6584 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
6585
6586 char const *vsSource =
6587 "#version 450\n"
6588 "out gl_PerVertex {\n"
6589 " vec4 gl_Position;\n"
6590 "};\n"
6591 "layout(location=0) out vec3 x;\n"
6592 "layout(location=1) out ivec3 y;\n"
6593 "layout(location=2) out vec3 z;\n"
6594 "void main(){\n"
6595 " gl_Position = vec4(0);\n"
6596 " x = vec3(0); y = ivec3(0); z = vec3(0);\n"
6597 "}\n";
6598 char const *fsSource =
6599 "#version 450\n"
6600 "\n"
6601 "layout(location=0) out vec4 color;\n"
6602 "layout(location=0) in float x;\n"
6603 "layout(location=1) flat in int y;\n"
6604 "layout(location=2) in vec2 z;\n"
6605 "void main(){\n"
6606 " color = vec4(1 + x + y + z.x);\n"
6607 "}\n";
6608
6609 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
6610 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
6611
6612 VkPipelineObj pipe(m_device);
6613 pipe.AddColorAttachment();
6614 pipe.AddShader(&vs);
6615 pipe.AddShader(&fs);
6616
6617 VkDescriptorSetObj descriptorSet(m_device);
6618 descriptorSet.AppendDummy();
6619 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
6620
6621 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
6622
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006623 m_errorMonitor->VerifyNotFound();
Chris Forbes912c9192016-04-05 17:50:35 +12006624}
6625
Chris Forbes4ea14fc2016-04-04 18:52:54 +12006626TEST_F(VkLayerTest, CreatePipelineTessPerVertex)
6627{
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006628 m_errorMonitor->ExpectSuccess();
Chris Forbes4ea14fc2016-04-04 18:52:54 +12006629
6630 ASSERT_NO_FATAL_FAILURE(InitState());
6631 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
6632
Chris Forbesc1e852d2016-04-04 19:26:42 +12006633 if (!m_device->phy().features().tessellationShader) {
6634 printf("Device does not support tessellation shaders; skipped.\n");
6635 return;
6636 }
6637
Chris Forbes4ea14fc2016-04-04 18:52:54 +12006638 char const *vsSource =
6639 "#version 450\n"
6640 "void main(){}\n";
6641 char const *tcsSource =
6642 "#version 450\n"
6643 "layout(location=0) out int x[];\n"
6644 "layout(vertices=3) out;\n"
6645 "void main(){\n"
6646 " gl_TessLevelOuter[0] = gl_TessLevelOuter[1] = gl_TessLevelOuter[2] = 1;\n"
6647 " gl_TessLevelInner[0] = 1;\n"
6648 " x[gl_InvocationID] = gl_InvocationID;\n"
6649 "}\n";
6650 char const *tesSource =
6651 "#version 450\n"
6652 "layout(triangles, equal_spacing, cw) in;\n"
6653 "layout(location=0) in int x[];\n"
6654 "out gl_PerVertex { vec4 gl_Position; };\n"
6655 "void main(){\n"
6656 " gl_Position.xyz = gl_TessCoord;\n"
6657 " gl_Position.w = x[0] + x[1] + x[2];\n"
6658 "}\n";
6659 char const *fsSource =
6660 "#version 450\n"
6661 "layout(location=0) out vec4 color;\n"
6662 "void main(){\n"
6663 " color = vec4(1);\n"
6664 "}\n";
6665
6666 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
6667 VkShaderObj tcs(m_device, tcsSource, VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT, this);
6668 VkShaderObj tes(m_device, tesSource, VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT, this);
6669 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
6670
6671 VkPipelineInputAssemblyStateCreateInfo iasci{
6672 VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO,
6673 nullptr,
6674 0,
6675 VK_PRIMITIVE_TOPOLOGY_PATCH_LIST,
6676 VK_FALSE};
6677
Chris Forbesb4cacb62016-04-04 19:15:00 +12006678 VkPipelineTessellationStateCreateInfo tsci{
6679 VK_STRUCTURE_TYPE_PIPELINE_TESSELLATION_STATE_CREATE_INFO,
6680 nullptr,
6681 0,
6682 3};
6683
Chris Forbes4ea14fc2016-04-04 18:52:54 +12006684 VkPipelineObj pipe(m_device);
6685 pipe.SetInputAssembly(&iasci);
Chris Forbesb4cacb62016-04-04 19:15:00 +12006686 pipe.SetTessellation(&tsci);
Chris Forbes4ea14fc2016-04-04 18:52:54 +12006687 pipe.AddColorAttachment();
6688 pipe.AddShader(&vs);
6689 pipe.AddShader(&tcs);
6690 pipe.AddShader(&tes);
6691 pipe.AddShader(&fs);
6692
6693 VkDescriptorSetObj descriptorSet(m_device);
6694 descriptorSet.AppendDummy();
6695 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
6696
6697 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
6698
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006699 m_errorMonitor->VerifyNotFound();
Chris Forbes4ea14fc2016-04-04 18:52:54 +12006700}
6701
Chris Forbesa0ab8152016-04-20 13:34:27 +12006702TEST_F(VkLayerTest, CreatePipelineGeometryInputBlockPositive)
6703{
6704 m_errorMonitor->ExpectSuccess();
6705
6706 ASSERT_NO_FATAL_FAILURE(InitState());
6707 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
6708
6709 if (!m_device->phy().features().geometryShader) {
6710 printf("Device does not support geometry shaders; skipped.\n");
6711 return;
6712 }
6713
6714 char const *vsSource =
6715 "#version 450\n"
6716 "layout(location=0) out VertexData { vec4 x; } vs_out;\n"
6717 "void main(){\n"
6718 " vs_out.x = vec4(1);\n"
6719 "}\n";
6720 char const *gsSource =
6721 "#version 450\n"
6722 "layout(triangles) in;\n"
6723 "layout(triangle_strip, max_vertices=3) out;\n"
6724 "layout(location=0) in VertexData { vec4 x; } gs_in[];\n"
6725 "out gl_PerVertex { vec4 gl_Position; };\n"
6726 "void main() {\n"
6727 " gl_Position = gs_in[0].x;\n"
6728 " EmitVertex();\n"
6729 "}\n";
6730 char const *fsSource =
6731 "#version 450\n"
6732 "layout(location=0) out vec4 color;\n"
6733 "void main(){\n"
6734 " color = vec4(1);\n"
6735 "}\n";
6736
6737 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
6738 VkShaderObj gs(m_device, gsSource, VK_SHADER_STAGE_GEOMETRY_BIT, this);
6739 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
6740
6741 VkPipelineObj pipe(m_device);
6742 pipe.AddColorAttachment();
6743 pipe.AddShader(&vs);
6744 pipe.AddShader(&gs);
6745 pipe.AddShader(&fs);
6746
6747 VkDescriptorSetObj descriptorSet(m_device);
6748 descriptorSet.AppendDummy();
6749 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
6750
6751 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
6752
6753 m_errorMonitor->VerifyNotFound();
6754}
6755
Chris Forbesa0193bc2016-04-04 19:19:47 +12006756TEST_F(VkLayerTest, CreatePipelineTessPatchDecorationMismatch)
6757{
6758 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
6759 "is per-vertex in tessellation control shader stage "
6760 "but per-patch in tessellation evaluation shader stage");
6761
6762 ASSERT_NO_FATAL_FAILURE(InitState());
6763 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
6764
Chris Forbesc1e852d2016-04-04 19:26:42 +12006765 if (!m_device->phy().features().tessellationShader) {
6766 printf("Device does not support tessellation shaders; skipped.\n");
6767 return;
6768 }
6769
Chris Forbesa0193bc2016-04-04 19:19:47 +12006770 char const *vsSource =
6771 "#version 450\n"
6772 "void main(){}\n";
6773 char const *tcsSource =
6774 "#version 450\n"
6775 "layout(location=0) out int x[];\n"
6776 "layout(vertices=3) out;\n"
6777 "void main(){\n"
6778 " gl_TessLevelOuter[0] = gl_TessLevelOuter[1] = gl_TessLevelOuter[2] = 1;\n"
6779 " gl_TessLevelInner[0] = 1;\n"
6780 " x[gl_InvocationID] = gl_InvocationID;\n"
6781 "}\n";
6782 char const *tesSource =
6783 "#version 450\n"
6784 "layout(triangles, equal_spacing, cw) in;\n"
6785 "layout(location=0) patch in int x;\n"
6786 "out gl_PerVertex { vec4 gl_Position; };\n"
6787 "void main(){\n"
6788 " gl_Position.xyz = gl_TessCoord;\n"
6789 " gl_Position.w = x;\n"
6790 "}\n";
6791 char const *fsSource =
6792 "#version 450\n"
6793 "layout(location=0) out vec4 color;\n"
6794 "void main(){\n"
6795 " color = vec4(1);\n"
6796 "}\n";
6797
6798 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
6799 VkShaderObj tcs(m_device, tcsSource, VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT, this);
6800 VkShaderObj tes(m_device, tesSource, VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT, this);
6801 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
6802
6803 VkPipelineInputAssemblyStateCreateInfo iasci{
6804 VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO,
6805 nullptr,
6806 0,
6807 VK_PRIMITIVE_TOPOLOGY_PATCH_LIST,
6808 VK_FALSE};
6809
6810 VkPipelineTessellationStateCreateInfo tsci{
6811 VK_STRUCTURE_TYPE_PIPELINE_TESSELLATION_STATE_CREATE_INFO,
6812 nullptr,
6813 0,
6814 3};
6815
6816 VkPipelineObj pipe(m_device);
6817 pipe.SetInputAssembly(&iasci);
6818 pipe.SetTessellation(&tsci);
6819 pipe.AddColorAttachment();
6820 pipe.AddShader(&vs);
6821 pipe.AddShader(&tcs);
6822 pipe.AddShader(&tes);
6823 pipe.AddShader(&fs);
6824
6825 VkDescriptorSetObj descriptorSet(m_device);
6826 descriptorSet.AppendDummy();
6827 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
6828
6829 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
6830
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006831 m_errorMonitor->VerifyFound();
Chris Forbesa0193bc2016-04-04 19:19:47 +12006832}
6833
Karl Schultz6addd812016-02-02 17:17:23 -07006834TEST_F(VkLayerTest, CreatePipelineAttribBindingConflict) {
6835 m_errorMonitor->SetDesiredFailureMsg(
6836 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06006837 "Duplicate vertex input binding descriptions for binding 0");
6838
Chris Forbes280ba2c2015-06-12 11:16:41 +12006839 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06006840 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes280ba2c2015-06-12 11:16:41 +12006841
6842 /* Two binding descriptions for binding 0 */
6843 VkVertexInputBindingDescription input_bindings[2];
6844 memset(input_bindings, 0, sizeof(input_bindings));
6845
6846 VkVertexInputAttributeDescription input_attrib;
6847 memset(&input_attrib, 0, sizeof(input_attrib));
6848 input_attrib.format = VK_FORMAT_R32_SFLOAT;
6849
6850 char const *vsSource =
Chris Forbes38467712016-04-04 17:28:05 +12006851 "#version 450\n"
Chris Forbes280ba2c2015-06-12 11:16:41 +12006852 "\n"
Karl Schultz6addd812016-02-02 17:17:23 -07006853 "layout(location=0) in float x;\n" /* attrib provided float */
Tony Barboure804d202016-01-05 13:37:45 -07006854 "out gl_PerVertex {\n"
6855 " vec4 gl_Position;\n"
6856 "};\n"
Chris Forbes280ba2c2015-06-12 11:16:41 +12006857 "void main(){\n"
6858 " gl_Position = vec4(x);\n"
6859 "}\n";
6860 char const *fsSource =
Chris Forbes38467712016-04-04 17:28:05 +12006861 "#version 450\n"
Chris Forbes280ba2c2015-06-12 11:16:41 +12006862 "\n"
6863 "layout(location=0) out vec4 color;\n"
6864 "void main(){\n"
6865 " color = vec4(1);\n"
6866 "}\n";
6867
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06006868 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
6869 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes280ba2c2015-06-12 11:16:41 +12006870
6871 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +08006872 pipe.AddColorAttachment();
Chris Forbes280ba2c2015-06-12 11:16:41 +12006873 pipe.AddShader(&vs);
6874 pipe.AddShader(&fs);
6875
6876 pipe.AddVertexInputBindings(input_bindings, 2);
6877 pipe.AddVertexInputAttribs(&input_attrib, 1);
6878
Chris Forbes280ba2c2015-06-12 11:16:41 +12006879 VkDescriptorSetObj descriptorSet(m_device);
6880 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006881 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes280ba2c2015-06-12 11:16:41 +12006882
Tony Barbour5781e8f2015-08-04 16:23:11 -06006883 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes280ba2c2015-06-12 11:16:41 +12006884
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006885 m_errorMonitor->VerifyFound();
Chris Forbes280ba2c2015-06-12 11:16:41 +12006886}
Chris Forbes8f68b562015-05-25 11:13:32 +12006887
Chris Forbes35efec72016-04-21 14:32:08 +12006888TEST_F(VkLayerTest, CreatePipeline64BitAttributesPositive) {
6889 m_errorMonitor->ExpectSuccess();
6890
6891 ASSERT_NO_FATAL_FAILURE(InitState());
6892 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
6893
6894 if (!m_device->phy().features().tessellationShader) {
6895 printf("Device does not support 64bit vertex attributes; skipped.\n");
6896 return;
6897 }
6898
6899 VkVertexInputBindingDescription input_bindings[1];
6900 memset(input_bindings, 0, sizeof(input_bindings));
6901
6902 VkVertexInputAttributeDescription input_attribs[4];
6903 memset(input_attribs, 0, sizeof(input_attribs));
6904 input_attribs[0].location = 0;
6905 input_attribs[0].offset = 0;
6906 input_attribs[0].format = VK_FORMAT_R64G64B64A64_SFLOAT;
6907 input_attribs[1].location = 2;
6908 input_attribs[1].offset = 32;
6909 input_attribs[1].format = VK_FORMAT_R64G64B64A64_SFLOAT;
6910 input_attribs[2].location = 4;
6911 input_attribs[2].offset = 64;
6912 input_attribs[2].format = VK_FORMAT_R64G64B64A64_SFLOAT;
6913 input_attribs[3].location = 6;
6914 input_attribs[3].offset = 96;
6915 input_attribs[3].format = VK_FORMAT_R64G64B64A64_SFLOAT;
6916
6917 char const *vsSource =
6918 "#version 450\n"
6919 "\n"
6920 "layout(location=0) in dmat4 x;\n"
6921 "out gl_PerVertex {\n"
6922 " vec4 gl_Position;\n"
6923 "};\n"
6924 "void main(){\n"
6925 " gl_Position = vec4(x[0][0]);\n"
6926 "}\n";
6927 char const *fsSource =
6928 "#version 450\n"
6929 "\n"
6930 "layout(location=0) out vec4 color;\n"
6931 "void main(){\n"
6932 " color = vec4(1);\n"
6933 "}\n";
6934
6935 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
6936 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
6937
6938 VkPipelineObj pipe(m_device);
6939 pipe.AddColorAttachment();
6940 pipe.AddShader(&vs);
6941 pipe.AddShader(&fs);
6942
6943 pipe.AddVertexInputBindings(input_bindings, 1);
6944 pipe.AddVertexInputAttribs(input_attribs, 4);
6945
6946 VkDescriptorSetObj descriptorSet(m_device);
6947 descriptorSet.AppendDummy();
6948 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
6949
6950 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
6951
6952 m_errorMonitor->VerifyNotFound();
6953}
6954
Karl Schultz6addd812016-02-02 17:17:23 -07006955TEST_F(VkLayerTest, CreatePipelineFragmentOutputNotWritten) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07006956 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Karl Schultz6addd812016-02-02 17:17:23 -07006957 "Attachment 0 not written by FS");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06006958
Chris Forbes4d6d1e52015-05-25 11:13:40 +12006959 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbes4d6d1e52015-05-25 11:13:40 +12006960
6961 char const *vsSource =
Chris Forbes38467712016-04-04 17:28:05 +12006962 "#version 450\n"
Chris Forbes4d6d1e52015-05-25 11:13:40 +12006963 "\n"
Tony Barboure804d202016-01-05 13:37:45 -07006964 "out gl_PerVertex {\n"
6965 " vec4 gl_Position;\n"
6966 "};\n"
Chris Forbes4d6d1e52015-05-25 11:13:40 +12006967 "void main(){\n"
6968 " gl_Position = vec4(1);\n"
6969 "}\n";
6970 char const *fsSource =
Chris Forbes38467712016-04-04 17:28:05 +12006971 "#version 450\n"
Chris Forbes4d6d1e52015-05-25 11:13:40 +12006972 "\n"
6973 "void main(){\n"
6974 "}\n";
6975
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06006976 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
6977 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes4d6d1e52015-05-25 11:13:40 +12006978
6979 VkPipelineObj pipe(m_device);
6980 pipe.AddShader(&vs);
6981 pipe.AddShader(&fs);
6982
Chia-I Wu08accc62015-07-07 11:50:03 +08006983 /* set up CB 0, not written */
6984 pipe.AddColorAttachment();
6985 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes4d6d1e52015-05-25 11:13:40 +12006986
Chris Forbes4d6d1e52015-05-25 11:13:40 +12006987 VkDescriptorSetObj descriptorSet(m_device);
6988 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006989 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes4d6d1e52015-05-25 11:13:40 +12006990
Tony Barbour5781e8f2015-08-04 16:23:11 -06006991 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes4d6d1e52015-05-25 11:13:40 +12006992
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006993 m_errorMonitor->VerifyFound();
Chris Forbes4d6d1e52015-05-25 11:13:40 +12006994}
6995
Karl Schultz6addd812016-02-02 17:17:23 -07006996TEST_F(VkLayerTest, CreatePipelineFragmentOutputNotConsumed) {
Karl Schultz6addd812016-02-02 17:17:23 -07006997 m_errorMonitor->SetDesiredFailureMsg(
Mark Lobodzinski510e20d2016-02-11 09:26:16 -07006998 VK_DEBUG_REPORT_WARNING_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06006999 "FS writes to output location 1 with no matching attachment");
7000
Chris Forbesf3fffaa2015-05-25 11:13:43 +12007001 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbesf3fffaa2015-05-25 11:13:43 +12007002
7003 char const *vsSource =
Chris Forbes38467712016-04-04 17:28:05 +12007004 "#version 450\n"
Chris Forbesf3fffaa2015-05-25 11:13:43 +12007005 "\n"
Tony Barboure804d202016-01-05 13:37:45 -07007006 "out gl_PerVertex {\n"
7007 " vec4 gl_Position;\n"
7008 "};\n"
Chris Forbesf3fffaa2015-05-25 11:13:43 +12007009 "void main(){\n"
7010 " gl_Position = vec4(1);\n"
7011 "}\n";
7012 char const *fsSource =
Chris Forbes38467712016-04-04 17:28:05 +12007013 "#version 450\n"
Chris Forbesf3fffaa2015-05-25 11:13:43 +12007014 "\n"
7015 "layout(location=0) out vec4 x;\n"
Karl Schultz6addd812016-02-02 17:17:23 -07007016 "layout(location=1) out vec4 y;\n" /* no matching attachment for this */
Chris Forbesf3fffaa2015-05-25 11:13:43 +12007017 "void main(){\n"
7018 " x = vec4(1);\n"
7019 " y = vec4(1);\n"
7020 "}\n";
7021
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06007022 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
7023 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesf3fffaa2015-05-25 11:13:43 +12007024
7025 VkPipelineObj pipe(m_device);
7026 pipe.AddShader(&vs);
7027 pipe.AddShader(&fs);
7028
Chia-I Wu08accc62015-07-07 11:50:03 +08007029 /* set up CB 0, not written */
7030 pipe.AddColorAttachment();
7031 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesf3fffaa2015-05-25 11:13:43 +12007032 /* FS writes CB 1, but we don't configure it */
7033
Chris Forbesf3fffaa2015-05-25 11:13:43 +12007034 VkDescriptorSetObj descriptorSet(m_device);
7035 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007036 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesf3fffaa2015-05-25 11:13:43 +12007037
Tony Barbour5781e8f2015-08-04 16:23:11 -06007038 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesf3fffaa2015-05-25 11:13:43 +12007039
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007040 m_errorMonitor->VerifyFound();
Chris Forbesf3fffaa2015-05-25 11:13:43 +12007041}
7042
Karl Schultz6addd812016-02-02 17:17:23 -07007043TEST_F(VkLayerTest, CreatePipelineFragmentOutputTypeMismatch) {
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 "does not match FS output type");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06007046
Chris Forbesa36d69e2015-05-25 11:13:44 +12007047 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbesa36d69e2015-05-25 11:13:44 +12007048
7049 char const *vsSource =
Chris Forbes38467712016-04-04 17:28:05 +12007050 "#version 450\n"
Chris Forbesa36d69e2015-05-25 11:13:44 +12007051 "\n"
Tony Barboure804d202016-01-05 13:37:45 -07007052 "out gl_PerVertex {\n"
7053 " vec4 gl_Position;\n"
7054 "};\n"
Chris Forbesa36d69e2015-05-25 11:13:44 +12007055 "void main(){\n"
7056 " gl_Position = vec4(1);\n"
7057 "}\n";
7058 char const *fsSource =
Chris Forbes38467712016-04-04 17:28:05 +12007059 "#version 450\n"
Chris Forbesa36d69e2015-05-25 11:13:44 +12007060 "\n"
Karl Schultz6addd812016-02-02 17:17:23 -07007061 "layout(location=0) out ivec4 x;\n" /* not UNORM */
Chris Forbesa36d69e2015-05-25 11:13:44 +12007062 "void main(){\n"
7063 " x = ivec4(1);\n"
7064 "}\n";
7065
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06007066 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
7067 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesa36d69e2015-05-25 11:13:44 +12007068
7069 VkPipelineObj pipe(m_device);
7070 pipe.AddShader(&vs);
7071 pipe.AddShader(&fs);
7072
Chia-I Wu08accc62015-07-07 11:50:03 +08007073 /* set up CB 0; type is UNORM by default */
7074 pipe.AddColorAttachment();
7075 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesa36d69e2015-05-25 11:13:44 +12007076
Chris Forbesa36d69e2015-05-25 11:13:44 +12007077 VkDescriptorSetObj descriptorSet(m_device);
7078 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007079 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesa36d69e2015-05-25 11:13:44 +12007080
Tony Barbour5781e8f2015-08-04 16:23:11 -06007081 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesa36d69e2015-05-25 11:13:44 +12007082
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007083 m_errorMonitor->VerifyFound();
Chris Forbesa36d69e2015-05-25 11:13:44 +12007084}
Chris Forbes7b1b8932015-06-05 14:43:36 +12007085
Karl Schultz6addd812016-02-02 17:17:23 -07007086TEST_F(VkLayerTest, CreatePipelineUniformBlockNotProvided) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07007087 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Karl Schultz6addd812016-02-02 17:17:23 -07007088 "not declared in pipeline layout");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06007089
Chris Forbes556c76c2015-08-14 12:04:59 +12007090 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbes556c76c2015-08-14 12:04:59 +12007091
7092 char const *vsSource =
Chris Forbes38467712016-04-04 17:28:05 +12007093 "#version 450\n"
Chris Forbes556c76c2015-08-14 12:04:59 +12007094 "\n"
Tony Barboure804d202016-01-05 13:37:45 -07007095 "out gl_PerVertex {\n"
7096 " vec4 gl_Position;\n"
7097 "};\n"
Chris Forbes556c76c2015-08-14 12:04:59 +12007098 "void main(){\n"
7099 " gl_Position = vec4(1);\n"
7100 "}\n";
7101 char const *fsSource =
Chris Forbes38467712016-04-04 17:28:05 +12007102 "#version 450\n"
Chris Forbes556c76c2015-08-14 12:04:59 +12007103 "\n"
7104 "layout(location=0) out vec4 x;\n"
7105 "layout(set=0) layout(binding=0) uniform foo { int x; int y; } bar;\n"
7106 "void main(){\n"
7107 " x = vec4(bar.y);\n"
7108 "}\n";
7109
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06007110 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
7111 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes556c76c2015-08-14 12:04:59 +12007112
Chris Forbes556c76c2015-08-14 12:04:59 +12007113 VkPipelineObj pipe(m_device);
7114 pipe.AddShader(&vs);
7115 pipe.AddShader(&fs);
7116
7117 /* set up CB 0; type is UNORM by default */
7118 pipe.AddColorAttachment();
7119 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
7120
7121 VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007122 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes556c76c2015-08-14 12:04:59 +12007123
7124 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
7125
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007126 m_errorMonitor->VerifyFound();
Chris Forbes556c76c2015-08-14 12:04:59 +12007127}
7128
Chris Forbes5c59e902016-02-26 16:56:09 +13007129TEST_F(VkLayerTest, CreatePipelinePushConstantsNotInLayout) {
7130 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
7131 "not declared in layout");
7132
7133 ASSERT_NO_FATAL_FAILURE(InitState());
7134
7135 char const *vsSource =
7136 "#version 450\n"
Chris Forbes5c59e902016-02-26 16:56:09 +13007137 "\n"
7138 "layout(push_constant, std430) uniform foo { float x; } consts;\n"
7139 "out gl_PerVertex {\n"
7140 " vec4 gl_Position;\n"
7141 "};\n"
7142 "void main(){\n"
7143 " gl_Position = vec4(consts.x);\n"
7144 "}\n";
7145 char const *fsSource =
7146 "#version 450\n"
Chris Forbes5c59e902016-02-26 16:56:09 +13007147 "\n"
7148 "layout(location=0) out vec4 x;\n"
7149 "void main(){\n"
7150 " x = vec4(1);\n"
7151 "}\n";
7152
7153 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
7154 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
7155
7156 VkPipelineObj pipe(m_device);
7157 pipe.AddShader(&vs);
7158 pipe.AddShader(&fs);
7159
7160 /* set up CB 0; type is UNORM by default */
7161 pipe.AddColorAttachment();
7162 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
7163
7164 VkDescriptorSetObj descriptorSet(m_device);
7165 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
7166
7167 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
7168
7169 /* should have generated an error -- no push constant ranges provided! */
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007170 m_errorMonitor->VerifyFound();
Chris Forbes5c59e902016-02-26 16:56:09 +13007171}
7172
Mark Lobodzinski209b5292015-09-17 09:44:05 -06007173#endif // SHADER_CHECKER_TESTS
7174
7175#if DEVICE_LIMITS_TESTS
Mark Youngc48c4c12016-04-11 14:26:49 -06007176TEST_F(VkLayerTest, CreateImageLimitsViolationMaxWidth) {
Karl Schultz6addd812016-02-02 17:17:23 -07007177 m_errorMonitor->SetDesiredFailureMsg(
7178 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06007179 "CreateImage extents exceed allowable limits for format");
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -06007180
7181 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -06007182
7183 // Create an image
7184 VkImage image;
7185
Karl Schultz6addd812016-02-02 17:17:23 -07007186 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
7187 const int32_t tex_width = 32;
7188 const int32_t tex_height = 32;
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -06007189
7190 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007191 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
7192 image_create_info.pNext = NULL;
7193 image_create_info.imageType = VK_IMAGE_TYPE_2D;
7194 image_create_info.format = tex_format;
7195 image_create_info.extent.width = tex_width;
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -06007196 image_create_info.extent.height = tex_height;
Karl Schultz6addd812016-02-02 17:17:23 -07007197 image_create_info.extent.depth = 1;
7198 image_create_info.mipLevels = 1;
7199 image_create_info.arrayLayers = 1;
7200 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
7201 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
7202 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
7203 image_create_info.flags = 0;
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -06007204
7205 // Introduce error by sending down a bogus width extent
7206 image_create_info.extent.width = 65536;
Chia-I Wuf7458c52015-10-26 21:10:41 +08007207 vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -06007208
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007209 m_errorMonitor->VerifyFound();
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -06007210}
7211
Mark Youngc48c4c12016-04-11 14:26:49 -06007212TEST_F(VkLayerTest, CreateImageLimitsViolationMinWidth) {
7213 m_errorMonitor->SetDesiredFailureMsg(
7214 VK_DEBUG_REPORT_ERROR_BIT_EXT,
7215 "CreateImage extents is 0 for at least one required dimension");
7216
7217 ASSERT_NO_FATAL_FAILURE(InitState());
7218
7219 // Create an image
7220 VkImage image;
7221
7222 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
7223 const int32_t tex_width = 32;
7224 const int32_t tex_height = 32;
7225
7226 VkImageCreateInfo image_create_info = {};
7227 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
7228 image_create_info.pNext = NULL;
7229 image_create_info.imageType = VK_IMAGE_TYPE_2D;
7230 image_create_info.format = tex_format;
7231 image_create_info.extent.width = tex_width;
7232 image_create_info.extent.height = tex_height;
7233 image_create_info.extent.depth = 1;
7234 image_create_info.mipLevels = 1;
7235 image_create_info.arrayLayers = 1;
7236 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
7237 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
7238 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
7239 image_create_info.flags = 0;
7240
7241 // Introduce error by sending down a bogus width extent
7242 image_create_info.extent.width = 0;
7243 vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
7244
7245 m_errorMonitor->VerifyFound();
7246}
7247
Karl Schultz6addd812016-02-02 17:17:23 -07007248TEST_F(VkLayerTest, UpdateBufferAlignment) {
7249 uint32_t updateData[] = {1, 2, 3, 4, 5, 6, 7, 8};
Mike Stroyana3082432015-09-25 13:39:21 -06007250
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07007251 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Karl Schultz6addd812016-02-02 17:17:23 -07007252 "dstOffset, is not a multiple of 4");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06007253
Mike Stroyana3082432015-09-25 13:39:21 -06007254 ASSERT_NO_FATAL_FAILURE(InitState());
7255
7256 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
7257 vk_testing::Buffer buffer;
7258 buffer.init_as_dst(*m_device, (VkDeviceSize)20, reqs);
7259
7260 BeginCommandBuffer();
7261 // Introduce failure by using offset that is not multiple of 4
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007262 m_commandBuffer->UpdateBuffer(buffer.handle(), 1, 4, updateData);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007263 m_errorMonitor->VerifyFound();
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06007264
Mike Stroyana3082432015-09-25 13:39:21 -06007265 // Introduce failure by using size that is not multiple of 4
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07007266 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Karl Schultz6addd812016-02-02 17:17:23 -07007267 "dataSize, is not a multiple of 4");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06007268
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007269 m_commandBuffer->UpdateBuffer(buffer.handle(), 0, 6, updateData);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007270 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -06007271 EndCommandBuffer();
7272}
7273
Karl Schultz6addd812016-02-02 17:17:23 -07007274TEST_F(VkLayerTest, FillBufferAlignment) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07007275 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Karl Schultz6addd812016-02-02 17:17:23 -07007276 "dstOffset, is not a multiple of 4");
Mike Stroyana3082432015-09-25 13:39:21 -06007277
7278 ASSERT_NO_FATAL_FAILURE(InitState());
7279
7280 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
7281 vk_testing::Buffer buffer;
7282 buffer.init_as_dst(*m_device, (VkDeviceSize)20, reqs);
7283
7284 BeginCommandBuffer();
7285 // Introduce failure by using offset that is not multiple of 4
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007286 m_commandBuffer->FillBuffer(buffer.handle(), 1, 4, 0x11111111);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007287 m_errorMonitor->VerifyFound();
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06007288
Mike Stroyana3082432015-09-25 13:39:21 -06007289 // Introduce failure by using size that is not multiple of 4
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07007290 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Karl Schultz6addd812016-02-02 17:17:23 -07007291 "size, is not a multiple of 4");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06007292
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007293 m_commandBuffer->FillBuffer(buffer.handle(), 0, 6, 0x11111111);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06007294
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007295 m_errorMonitor->VerifyFound();
7296
Mike Stroyana3082432015-09-25 13:39:21 -06007297 EndCommandBuffer();
7298}
7299
Mark Lobodzinski209b5292015-09-17 09:44:05 -06007300#endif // DEVICE_LIMITS_TESTS
Chris Forbesa36d69e2015-05-25 11:13:44 +12007301
Tobin Ehliscde08892015-09-22 10:11:37 -06007302#if IMAGE_TESTS
Karl Schultz6addd812016-02-02 17:17:23 -07007303TEST_F(VkLayerTest, InvalidImageView) {
7304 VkResult err;
Tobin Ehliscde08892015-09-22 10:11:37 -06007305
Karl Schultz6addd812016-02-02 17:17:23 -07007306 m_errorMonitor->SetDesiredFailureMsg(
7307 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06007308 "vkCreateImageView called with baseMipLevel 10 ");
7309
Tobin Ehliscde08892015-09-22 10:11:37 -06007310 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehliscde08892015-09-22 10:11:37 -06007311
Mike Stroyana3082432015-09-25 13:39:21 -06007312 // Create an image and try to create a view with bad baseMipLevel
Karl Schultz6addd812016-02-02 17:17:23 -07007313 VkImage image;
Tobin Ehliscde08892015-09-22 10:11:37 -06007314
Karl Schultz6addd812016-02-02 17:17:23 -07007315 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
7316 const int32_t tex_width = 32;
7317 const int32_t tex_height = 32;
Tobin Ehliscde08892015-09-22 10:11:37 -06007318
7319 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007320 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
7321 image_create_info.pNext = NULL;
7322 image_create_info.imageType = VK_IMAGE_TYPE_2D;
7323 image_create_info.format = tex_format;
7324 image_create_info.extent.width = tex_width;
7325 image_create_info.extent.height = tex_height;
7326 image_create_info.extent.depth = 1;
7327 image_create_info.mipLevels = 1;
7328 image_create_info.arrayLayers = 1;
7329 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
7330 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
7331 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
7332 image_create_info.flags = 0;
Tobin Ehliscde08892015-09-22 10:11:37 -06007333
Chia-I Wuf7458c52015-10-26 21:10:41 +08007334 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Tobin Ehliscde08892015-09-22 10:11:37 -06007335 ASSERT_VK_SUCCESS(err);
7336
7337 VkImageViewCreateInfo image_view_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007338 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
7339 image_view_create_info.image = image;
7340 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
7341 image_view_create_info.format = tex_format;
7342 image_view_create_info.subresourceRange.layerCount = 1;
7343 image_view_create_info.subresourceRange.baseMipLevel = 10; // cause an error
7344 image_view_create_info.subresourceRange.levelCount = 1;
7345 image_view_create_info.subresourceRange.aspectMask =
7346 VK_IMAGE_ASPECT_COLOR_BIT;
Tobin Ehliscde08892015-09-22 10:11:37 -06007347
7348 VkImageView view;
Karl Schultz6addd812016-02-02 17:17:23 -07007349 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL,
7350 &view);
Tobin Ehliscde08892015-09-22 10:11:37 -06007351
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007352 m_errorMonitor->VerifyFound();
Tobin Ehliscde08892015-09-22 10:11:37 -06007353}
Mike Stroyana3082432015-09-25 13:39:21 -06007354
Karl Schultz6addd812016-02-02 17:17:23 -07007355TEST_F(VkLayerTest, InvalidImageViewAspect) {
7356 VkResult err;
Mark Lobodzinskidc86b852015-10-23 14:20:31 -06007357
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07007358 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Karl Schultz6addd812016-02-02 17:17:23 -07007359 "vkCreateImageView: Color image "
7360 "formats must have ONLY the "
7361 "VK_IMAGE_ASPECT_COLOR_BIT set");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06007362
Mark Lobodzinskidc86b852015-10-23 14:20:31 -06007363 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskidc86b852015-10-23 14:20:31 -06007364
7365 // Create an image and try to create a view with an invalid aspectMask
Karl Schultz6addd812016-02-02 17:17:23 -07007366 VkImage image;
Mark Lobodzinskidc86b852015-10-23 14:20:31 -06007367
Karl Schultz6addd812016-02-02 17:17:23 -07007368 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
7369 const int32_t tex_width = 32;
7370 const int32_t tex_height = 32;
Mark Lobodzinskidc86b852015-10-23 14:20:31 -06007371
7372 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007373 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
7374 image_create_info.pNext = NULL;
7375 image_create_info.imageType = VK_IMAGE_TYPE_2D;
7376 image_create_info.format = tex_format;
7377 image_create_info.extent.width = tex_width;
7378 image_create_info.extent.height = tex_height;
7379 image_create_info.extent.depth = 1;
7380 image_create_info.mipLevels = 1;
7381 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
7382 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
7383 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
7384 image_create_info.flags = 0;
Mark Lobodzinskidc86b852015-10-23 14:20:31 -06007385
Chia-I Wuf7458c52015-10-26 21:10:41 +08007386 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Mark Lobodzinskidc86b852015-10-23 14:20:31 -06007387 ASSERT_VK_SUCCESS(err);
7388
7389 VkImageViewCreateInfo image_view_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007390 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
7391 image_view_create_info.image = image;
7392 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
7393 image_view_create_info.format = tex_format;
7394 image_view_create_info.subresourceRange.baseMipLevel = 0;
7395 image_view_create_info.subresourceRange.levelCount = 1;
7396 // Cause an error by setting an invalid image aspect
7397 image_view_create_info.subresourceRange.aspectMask =
7398 VK_IMAGE_ASPECT_METADATA_BIT;
Mark Lobodzinskidc86b852015-10-23 14:20:31 -06007399
7400 VkImageView view;
Karl Schultz6addd812016-02-02 17:17:23 -07007401 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL,
7402 &view);
Mark Lobodzinskidc86b852015-10-23 14:20:31 -06007403
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007404 m_errorMonitor->VerifyFound();
Mark Lobodzinskidc86b852015-10-23 14:20:31 -06007405}
7406
Mark Lobodzinskidb117632016-03-31 10:45:56 -06007407TEST_F(VkLayerTest, CopyImageLayerCountMismatch) {
Karl Schultz6addd812016-02-02 17:17:23 -07007408 VkResult err;
7409 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -06007410
Karl Schultz6addd812016-02-02 17:17:23 -07007411 m_errorMonitor->SetDesiredFailureMsg(
7412 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinskidb117632016-03-31 10:45:56 -06007413 "vkCmdCopyImage: number of layers in source and destination subresources for pRegions");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06007414
Mike Stroyana3082432015-09-25 13:39:21 -06007415 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -06007416
7417 // Create two images of different types and try to copy between them
Karl Schultz6addd812016-02-02 17:17:23 -07007418 VkImage srcImage;
7419 VkImage dstImage;
7420 VkDeviceMemory srcMem;
7421 VkDeviceMemory destMem;
7422 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -06007423
7424 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007425 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
7426 image_create_info.pNext = NULL;
7427 image_create_info.imageType = VK_IMAGE_TYPE_2D;
7428 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
7429 image_create_info.extent.width = 32;
7430 image_create_info.extent.height = 32;
7431 image_create_info.extent.depth = 1;
7432 image_create_info.mipLevels = 1;
Mark Lobodzinskidb117632016-03-31 10:45:56 -06007433 image_create_info.arrayLayers = 4;
Karl Schultz6addd812016-02-02 17:17:23 -07007434 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
7435 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
7436 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
7437 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -06007438
Karl Schultz6addd812016-02-02 17:17:23 -07007439 err =
7440 vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -06007441 ASSERT_VK_SUCCESS(err);
7442
Karl Schultz6addd812016-02-02 17:17:23 -07007443 err =
7444 vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -06007445 ASSERT_VK_SUCCESS(err);
7446
7447 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007448 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007449 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
7450 memAlloc.pNext = NULL;
7451 memAlloc.allocationSize = 0;
7452 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -06007453
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -06007454 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -06007455 memAlloc.allocationSize = memReqs.size;
Karl Schultz6addd812016-02-02 17:17:23 -07007456 pass =
7457 m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -06007458 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007459 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -06007460 ASSERT_VK_SUCCESS(err);
7461
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007462 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -06007463 memAlloc.allocationSize = memReqs.size;
Karl Schultz6addd812016-02-02 17:17:23 -07007464 pass =
7465 m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Mike Stroyana3082432015-09-25 13:39:21 -06007466 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007467 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -06007468 ASSERT_VK_SUCCESS(err);
7469
7470 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
7471 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007472 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -06007473 ASSERT_VK_SUCCESS(err);
7474
7475 BeginCommandBuffer();
7476 VkImageCopy copyRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +08007477 copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -06007478 copyRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -06007479 copyRegion.srcSubresource.baseArrayLayer = 0;
Mark Lobodzinskidb117632016-03-31 10:45:56 -06007480 copyRegion.srcSubresource.layerCount = 1;
Mike Stroyana3082432015-09-25 13:39:21 -06007481 copyRegion.srcOffset.x = 0;
7482 copyRegion.srcOffset.y = 0;
7483 copyRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +08007484 copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007485 copyRegion.dstSubresource.mipLevel = 0;
7486 copyRegion.dstSubresource.baseArrayLayer = 0;
Mark Lobodzinskidb117632016-03-31 10:45:56 -06007487 // Introduce failure by forcing the dst layerCount to differ from src
7488 copyRegion.dstSubresource.layerCount = 3;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007489 copyRegion.dstOffset.x = 0;
7490 copyRegion.dstOffset.y = 0;
7491 copyRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -06007492 copyRegion.extent.width = 1;
7493 copyRegion.extent.height = 1;
7494 copyRegion.extent.depth = 1;
Karl Schultz6addd812016-02-02 17:17:23 -07007495 m_commandBuffer->CopyImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage,
7496 VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
Mike Stroyana3082432015-09-25 13:39:21 -06007497 EndCommandBuffer();
7498
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007499 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -06007500
Chia-I Wuf7458c52015-10-26 21:10:41 +08007501 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007502 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +08007503 vkFreeMemory(m_device->device(), srcMem, NULL);
7504 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -06007505}
7506
Karl Schultz6addd812016-02-02 17:17:23 -07007507TEST_F(VkLayerTest, CopyImageFormatSizeMismatch) {
Karl Schultzbdb75952016-04-19 11:36:49 -06007508 VkResult err;
7509 bool pass;
7510
7511 // Create color images with different format sizes and try to copy between them
7512 m_errorMonitor->SetDesiredFailureMsg(
7513 VK_DEBUG_REPORT_ERROR_BIT_EXT,
7514 "vkCmdCopyImage called with unmatched source and dest image format sizes");
7515
7516 ASSERT_NO_FATAL_FAILURE(InitState());
7517
7518 // Create two images of different types and try to copy between them
7519 VkImage srcImage;
7520 VkImage dstImage;
7521 VkDeviceMemory srcMem;
7522 VkDeviceMemory destMem;
7523 VkMemoryRequirements memReqs;
7524
7525 VkImageCreateInfo image_create_info = {};
7526 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
7527 image_create_info.pNext = NULL;
7528 image_create_info.imageType = VK_IMAGE_TYPE_2D;
7529 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
7530 image_create_info.extent.width = 32;
7531 image_create_info.extent.height = 32;
7532 image_create_info.extent.depth = 1;
7533 image_create_info.mipLevels = 1;
7534 image_create_info.arrayLayers = 1;
7535 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
7536 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
7537 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
7538 image_create_info.flags = 0;
7539
7540 err =
7541 vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
7542 ASSERT_VK_SUCCESS(err);
7543
7544 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
7545 // Introduce failure by creating second image with a different-sized format.
7546 image_create_info.format = VK_FORMAT_R5G5B5A1_UNORM_PACK16;
7547
7548 err =
7549 vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
7550 ASSERT_VK_SUCCESS(err);
7551
7552 // Allocate memory
7553 VkMemoryAllocateInfo memAlloc = {};
7554 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
7555 memAlloc.pNext = NULL;
7556 memAlloc.allocationSize = 0;
7557 memAlloc.memoryTypeIndex = 0;
7558
7559 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
7560 memAlloc.allocationSize = memReqs.size;
7561 pass =
7562 m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
7563 ASSERT_TRUE(pass);
7564 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
7565 ASSERT_VK_SUCCESS(err);
7566
7567 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
7568 memAlloc.allocationSize = memReqs.size;
7569 pass =
7570 m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
7571 ASSERT_TRUE(pass);
7572 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
7573 ASSERT_VK_SUCCESS(err);
7574
7575 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
7576 ASSERT_VK_SUCCESS(err);
7577 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
7578 ASSERT_VK_SUCCESS(err);
7579
7580 BeginCommandBuffer();
7581 VkImageCopy copyRegion;
7582 copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
7583 copyRegion.srcSubresource.mipLevel = 0;
7584 copyRegion.srcSubresource.baseArrayLayer = 0;
7585 copyRegion.srcSubresource.layerCount = 0;
7586 copyRegion.srcOffset.x = 0;
7587 copyRegion.srcOffset.y = 0;
7588 copyRegion.srcOffset.z = 0;
7589 copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
7590 copyRegion.dstSubresource.mipLevel = 0;
7591 copyRegion.dstSubresource.baseArrayLayer = 0;
7592 copyRegion.dstSubresource.layerCount = 0;
7593 copyRegion.dstOffset.x = 0;
7594 copyRegion.dstOffset.y = 0;
7595 copyRegion.dstOffset.z = 0;
7596 copyRegion.extent.width = 1;
7597 copyRegion.extent.height = 1;
7598 copyRegion.extent.depth = 1;
7599 m_commandBuffer->CopyImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage,
7600 VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
7601 EndCommandBuffer();
7602
7603 m_errorMonitor->VerifyFound();
7604
7605 vkDestroyImage(m_device->device(), srcImage, NULL);
7606 vkDestroyImage(m_device->device(), dstImage, NULL);
7607 vkFreeMemory(m_device->device(), srcMem, NULL);
7608 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -06007609}
7610
Karl Schultz6addd812016-02-02 17:17:23 -07007611TEST_F(VkLayerTest, CopyImageDepthStencilFormatMismatch) {
7612 VkResult err;
7613 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -06007614
Mark Lobodzinskidb117632016-03-31 10:45:56 -06007615 // Create a color image and a depth/stencil image and try to copy between them
Karl Schultz6addd812016-02-02 17:17:23 -07007616 m_errorMonitor->SetDesiredFailureMsg(
7617 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinskidb117632016-03-31 10:45:56 -06007618 "vkCmdCopyImage called with unmatched source and dest image depth");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06007619
Mike Stroyana3082432015-09-25 13:39:21 -06007620 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -06007621
7622 // Create two images of different types and try to copy between them
Karl Schultz6addd812016-02-02 17:17:23 -07007623 VkImage srcImage;
7624 VkImage dstImage;
7625 VkDeviceMemory srcMem;
7626 VkDeviceMemory destMem;
7627 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -06007628
7629 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007630 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
7631 image_create_info.pNext = NULL;
7632 image_create_info.imageType = VK_IMAGE_TYPE_2D;
7633 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
7634 image_create_info.extent.width = 32;
7635 image_create_info.extent.height = 32;
7636 image_create_info.extent.depth = 1;
7637 image_create_info.mipLevels = 1;
7638 image_create_info.arrayLayers = 1;
7639 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
7640 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
7641 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
7642 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -06007643
Karl Schultz6addd812016-02-02 17:17:23 -07007644 err =
7645 vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -06007646 ASSERT_VK_SUCCESS(err);
7647
Karl Schultzbdb75952016-04-19 11:36:49 -06007648 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
7649
Mark Lobodzinskidb117632016-03-31 10:45:56 -06007650 // Introduce failure by creating second image with a depth/stencil format
Karl Schultz6addd812016-02-02 17:17:23 -07007651 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
Mark Lobodzinskidb117632016-03-31 10:45:56 -06007652 image_create_info.format = VK_FORMAT_D24_UNORM_S8_UINT;
7653 image_create_info.usage = VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -06007654
Karl Schultz6addd812016-02-02 17:17:23 -07007655 err =
7656 vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -06007657 ASSERT_VK_SUCCESS(err);
7658
7659 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007660 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007661 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
7662 memAlloc.pNext = NULL;
7663 memAlloc.allocationSize = 0;
7664 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -06007665
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -06007666 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -06007667 memAlloc.allocationSize = memReqs.size;
Karl Schultz6addd812016-02-02 17:17:23 -07007668 pass =
7669 m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -06007670 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007671 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -06007672 ASSERT_VK_SUCCESS(err);
7673
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007674 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -06007675 memAlloc.allocationSize = memReqs.size;
Karl Schultz6addd812016-02-02 17:17:23 -07007676 pass =
7677 m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -06007678 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007679 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -06007680 ASSERT_VK_SUCCESS(err);
7681
7682 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
7683 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007684 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -06007685 ASSERT_VK_SUCCESS(err);
7686
7687 BeginCommandBuffer();
7688 VkImageCopy copyRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +08007689 copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -06007690 copyRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -06007691 copyRegion.srcSubresource.baseArrayLayer = 0;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007692 copyRegion.srcSubresource.layerCount = 0;
Mike Stroyana3082432015-09-25 13:39:21 -06007693 copyRegion.srcOffset.x = 0;
7694 copyRegion.srcOffset.y = 0;
7695 copyRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +08007696 copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007697 copyRegion.dstSubresource.mipLevel = 0;
7698 copyRegion.dstSubresource.baseArrayLayer = 0;
7699 copyRegion.dstSubresource.layerCount = 0;
7700 copyRegion.dstOffset.x = 0;
7701 copyRegion.dstOffset.y = 0;
7702 copyRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -06007703 copyRegion.extent.width = 1;
7704 copyRegion.extent.height = 1;
7705 copyRegion.extent.depth = 1;
Karl Schultz6addd812016-02-02 17:17:23 -07007706 m_commandBuffer->CopyImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage,
7707 VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
Mike Stroyana3082432015-09-25 13:39:21 -06007708 EndCommandBuffer();
7709
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007710 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -06007711
Chia-I Wuf7458c52015-10-26 21:10:41 +08007712 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007713 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +08007714 vkFreeMemory(m_device->device(), srcMem, NULL);
7715 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -06007716}
7717
Karl Schultz6addd812016-02-02 17:17:23 -07007718TEST_F(VkLayerTest, ResolveImageLowSampleCount) {
7719 VkResult err;
7720 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -06007721
Karl Schultz6addd812016-02-02 17:17:23 -07007722 m_errorMonitor->SetDesiredFailureMsg(
7723 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06007724 "vkCmdResolveImage called with source sample count less than 2.");
7725
Mike Stroyana3082432015-09-25 13:39:21 -06007726 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -06007727
7728 // Create two images of sample count 1 and try to Resolve between them
Karl Schultz6addd812016-02-02 17:17:23 -07007729 VkImage srcImage;
7730 VkImage dstImage;
7731 VkDeviceMemory srcMem;
7732 VkDeviceMemory destMem;
7733 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -06007734
7735 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007736 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
7737 image_create_info.pNext = NULL;
7738 image_create_info.imageType = VK_IMAGE_TYPE_2D;
7739 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
7740 image_create_info.extent.width = 32;
7741 image_create_info.extent.height = 1;
7742 image_create_info.extent.depth = 1;
7743 image_create_info.mipLevels = 1;
7744 image_create_info.arrayLayers = 1;
7745 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
7746 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
7747 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
7748 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -06007749
Karl Schultz6addd812016-02-02 17:17:23 -07007750 err =
7751 vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -06007752 ASSERT_VK_SUCCESS(err);
7753
Karl Schultz6addd812016-02-02 17:17:23 -07007754 image_create_info.imageType = VK_IMAGE_TYPE_1D;
7755 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -06007756
Karl Schultz6addd812016-02-02 17:17:23 -07007757 err =
7758 vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -06007759 ASSERT_VK_SUCCESS(err);
7760
7761 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007762 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007763 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
7764 memAlloc.pNext = NULL;
7765 memAlloc.allocationSize = 0;
7766 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -06007767
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -06007768 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -06007769 memAlloc.allocationSize = memReqs.size;
Karl Schultz6addd812016-02-02 17:17:23 -07007770 pass =
7771 m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -06007772 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007773 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -06007774 ASSERT_VK_SUCCESS(err);
7775
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007776 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -06007777 memAlloc.allocationSize = memReqs.size;
Karl Schultz6addd812016-02-02 17:17:23 -07007778 pass =
7779 m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -06007780 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007781 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -06007782 ASSERT_VK_SUCCESS(err);
7783
7784 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
7785 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007786 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -06007787 ASSERT_VK_SUCCESS(err);
7788
7789 BeginCommandBuffer();
7790 // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest?
Karl Schultz6addd812016-02-02 17:17:23 -07007791 // VK_IMAGE_LAYOUT_UNDEFINED = 0,
7792 // VK_IMAGE_LAYOUT_GENERAL = 1,
Mike Stroyana3082432015-09-25 13:39:21 -06007793 VkImageResolve resolveRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +08007794 resolveRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -06007795 resolveRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -06007796 resolveRegion.srcSubresource.baseArrayLayer = 0;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007797 resolveRegion.srcSubresource.layerCount = 0;
Mike Stroyana3082432015-09-25 13:39:21 -06007798 resolveRegion.srcOffset.x = 0;
7799 resolveRegion.srcOffset.y = 0;
7800 resolveRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +08007801 resolveRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007802 resolveRegion.dstSubresource.mipLevel = 0;
7803 resolveRegion.dstSubresource.baseArrayLayer = 0;
7804 resolveRegion.dstSubresource.layerCount = 0;
7805 resolveRegion.dstOffset.x = 0;
7806 resolveRegion.dstOffset.y = 0;
7807 resolveRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -06007808 resolveRegion.extent.width = 1;
7809 resolveRegion.extent.height = 1;
7810 resolveRegion.extent.depth = 1;
Karl Schultz6addd812016-02-02 17:17:23 -07007811 m_commandBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage,
7812 VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion);
Mike Stroyana3082432015-09-25 13:39:21 -06007813 EndCommandBuffer();
7814
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007815 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -06007816
Chia-I Wuf7458c52015-10-26 21:10:41 +08007817 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007818 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +08007819 vkFreeMemory(m_device->device(), srcMem, NULL);
7820 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -06007821}
7822
Karl Schultz6addd812016-02-02 17:17:23 -07007823TEST_F(VkLayerTest, ResolveImageHighSampleCount) {
7824 VkResult err;
7825 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -06007826
Karl Schultz6addd812016-02-02 17:17:23 -07007827 m_errorMonitor->SetDesiredFailureMsg(
7828 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06007829 "vkCmdResolveImage called with dest sample count greater than 1.");
7830
Mike Stroyana3082432015-09-25 13:39:21 -06007831 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -06007832
7833 // Create two images of sample count 2 and try to Resolve between them
Karl Schultz6addd812016-02-02 17:17:23 -07007834 VkImage srcImage;
7835 VkImage dstImage;
7836 VkDeviceMemory srcMem;
7837 VkDeviceMemory destMem;
7838 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -06007839
7840 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007841 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
7842 image_create_info.pNext = NULL;
7843 image_create_info.imageType = VK_IMAGE_TYPE_2D;
7844 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
7845 image_create_info.extent.width = 32;
7846 image_create_info.extent.height = 1;
7847 image_create_info.extent.depth = 1;
7848 image_create_info.mipLevels = 1;
7849 image_create_info.arrayLayers = 1;
7850 image_create_info.samples = VK_SAMPLE_COUNT_2_BIT;
7851 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
7852 // Note: Some implementations expect color attachment usage for any
7853 // multisample surface
7854 image_create_info.usage =
7855 VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
7856 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -06007857
Karl Schultz6addd812016-02-02 17:17:23 -07007858 err =
7859 vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -06007860 ASSERT_VK_SUCCESS(err);
7861
Karl Schultz6addd812016-02-02 17:17:23 -07007862 image_create_info.imageType = VK_IMAGE_TYPE_1D;
7863 // Note: Some implementations expect color attachment usage for any
7864 // multisample surface
7865 image_create_info.usage =
7866 VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -06007867
Karl Schultz6addd812016-02-02 17:17:23 -07007868 err =
7869 vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -06007870 ASSERT_VK_SUCCESS(err);
7871
7872 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007873 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007874 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
7875 memAlloc.pNext = NULL;
7876 memAlloc.allocationSize = 0;
7877 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -06007878
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -06007879 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -06007880 memAlloc.allocationSize = memReqs.size;
Karl Schultz6addd812016-02-02 17:17:23 -07007881 pass =
7882 m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -06007883 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007884 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -06007885 ASSERT_VK_SUCCESS(err);
7886
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007887 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -06007888 memAlloc.allocationSize = memReqs.size;
Karl Schultz6addd812016-02-02 17:17:23 -07007889 pass =
7890 m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -06007891 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007892 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -06007893 ASSERT_VK_SUCCESS(err);
7894
7895 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
7896 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007897 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -06007898 ASSERT_VK_SUCCESS(err);
7899
7900 BeginCommandBuffer();
7901 // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest?
Karl Schultz6addd812016-02-02 17:17:23 -07007902 // VK_IMAGE_LAYOUT_UNDEFINED = 0,
7903 // VK_IMAGE_LAYOUT_GENERAL = 1,
Mike Stroyana3082432015-09-25 13:39:21 -06007904 VkImageResolve resolveRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +08007905 resolveRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -06007906 resolveRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -06007907 resolveRegion.srcSubresource.baseArrayLayer = 0;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007908 resolveRegion.srcSubresource.layerCount = 0;
Mike Stroyana3082432015-09-25 13:39:21 -06007909 resolveRegion.srcOffset.x = 0;
7910 resolveRegion.srcOffset.y = 0;
7911 resolveRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +08007912 resolveRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007913 resolveRegion.dstSubresource.mipLevel = 0;
7914 resolveRegion.dstSubresource.baseArrayLayer = 0;
7915 resolveRegion.dstSubresource.layerCount = 0;
7916 resolveRegion.dstOffset.x = 0;
7917 resolveRegion.dstOffset.y = 0;
7918 resolveRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -06007919 resolveRegion.extent.width = 1;
7920 resolveRegion.extent.height = 1;
7921 resolveRegion.extent.depth = 1;
Karl Schultz6addd812016-02-02 17:17:23 -07007922 m_commandBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage,
7923 VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion);
Mike Stroyana3082432015-09-25 13:39:21 -06007924 EndCommandBuffer();
7925
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007926 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -06007927
Chia-I Wuf7458c52015-10-26 21:10:41 +08007928 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007929 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +08007930 vkFreeMemory(m_device->device(), srcMem, NULL);
7931 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -06007932}
7933
Karl Schultz6addd812016-02-02 17:17:23 -07007934TEST_F(VkLayerTest, ResolveImageFormatMismatch) {
7935 VkResult err;
7936 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -06007937
Karl Schultz6addd812016-02-02 17:17:23 -07007938 m_errorMonitor->SetDesiredFailureMsg(
7939 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06007940 "vkCmdResolveImage called with unmatched source and dest formats.");
7941
Mike Stroyana3082432015-09-25 13:39:21 -06007942 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -06007943
7944 // Create two images of different types and try to copy between them
Karl Schultz6addd812016-02-02 17:17:23 -07007945 VkImage srcImage;
7946 VkImage dstImage;
7947 VkDeviceMemory srcMem;
7948 VkDeviceMemory destMem;
7949 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -06007950
7951 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007952 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
7953 image_create_info.pNext = NULL;
7954 image_create_info.imageType = VK_IMAGE_TYPE_2D;
7955 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
7956 image_create_info.extent.width = 32;
7957 image_create_info.extent.height = 1;
7958 image_create_info.extent.depth = 1;
7959 image_create_info.mipLevels = 1;
7960 image_create_info.arrayLayers = 1;
7961 image_create_info.samples = VK_SAMPLE_COUNT_2_BIT;
7962 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
7963 // Note: Some implementations expect color attachment usage for any
7964 // multisample surface
7965 image_create_info.usage =
7966 VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
7967 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -06007968
Karl Schultz6addd812016-02-02 17:17:23 -07007969 err =
7970 vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -06007971 ASSERT_VK_SUCCESS(err);
7972
Karl Schultz6addd812016-02-02 17:17:23 -07007973 // Set format to something other than source image
7974 image_create_info.format = VK_FORMAT_R32_SFLOAT;
7975 // Note: Some implementations expect color attachment usage for any
7976 // multisample surface
7977 image_create_info.usage =
7978 VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
7979 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -06007980
Karl Schultz6addd812016-02-02 17:17:23 -07007981 err =
7982 vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -06007983 ASSERT_VK_SUCCESS(err);
7984
7985 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007986 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007987 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
7988 memAlloc.pNext = NULL;
7989 memAlloc.allocationSize = 0;
7990 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -06007991
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -06007992 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -06007993 memAlloc.allocationSize = memReqs.size;
Karl Schultz6addd812016-02-02 17:17:23 -07007994 pass =
7995 m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -06007996 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007997 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -06007998 ASSERT_VK_SUCCESS(err);
7999
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008000 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -06008001 memAlloc.allocationSize = memReqs.size;
Karl Schultz6addd812016-02-02 17:17:23 -07008002 pass =
8003 m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -06008004 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008005 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -06008006 ASSERT_VK_SUCCESS(err);
8007
8008 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
8009 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008010 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -06008011 ASSERT_VK_SUCCESS(err);
8012
8013 BeginCommandBuffer();
8014 // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest?
Karl Schultz6addd812016-02-02 17:17:23 -07008015 // VK_IMAGE_LAYOUT_UNDEFINED = 0,
8016 // VK_IMAGE_LAYOUT_GENERAL = 1,
Mike Stroyana3082432015-09-25 13:39:21 -06008017 VkImageResolve resolveRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +08008018 resolveRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -06008019 resolveRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -06008020 resolveRegion.srcSubresource.baseArrayLayer = 0;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008021 resolveRegion.srcSubresource.layerCount = 0;
Mike Stroyana3082432015-09-25 13:39:21 -06008022 resolveRegion.srcOffset.x = 0;
8023 resolveRegion.srcOffset.y = 0;
8024 resolveRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +08008025 resolveRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008026 resolveRegion.dstSubresource.mipLevel = 0;
8027 resolveRegion.dstSubresource.baseArrayLayer = 0;
8028 resolveRegion.dstSubresource.layerCount = 0;
8029 resolveRegion.dstOffset.x = 0;
8030 resolveRegion.dstOffset.y = 0;
8031 resolveRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -06008032 resolveRegion.extent.width = 1;
8033 resolveRegion.extent.height = 1;
8034 resolveRegion.extent.depth = 1;
Karl Schultz6addd812016-02-02 17:17:23 -07008035 m_commandBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage,
8036 VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion);
Mike Stroyana3082432015-09-25 13:39:21 -06008037 EndCommandBuffer();
8038
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008039 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -06008040
Chia-I Wuf7458c52015-10-26 21:10:41 +08008041 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008042 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +08008043 vkFreeMemory(m_device->device(), srcMem, NULL);
8044 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -06008045}
8046
Karl Schultz6addd812016-02-02 17:17:23 -07008047TEST_F(VkLayerTest, ResolveImageTypeMismatch) {
8048 VkResult err;
8049 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -06008050
Karl Schultz6addd812016-02-02 17:17:23 -07008051 m_errorMonitor->SetDesiredFailureMsg(
8052 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06008053 "vkCmdResolveImage called with unmatched source and dest image types.");
8054
Mike Stroyana3082432015-09-25 13:39:21 -06008055 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -06008056
8057 // Create two images of different types and try to copy between them
Karl Schultz6addd812016-02-02 17:17:23 -07008058 VkImage srcImage;
8059 VkImage dstImage;
8060 VkDeviceMemory srcMem;
8061 VkDeviceMemory destMem;
8062 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -06008063
8064 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008065 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
8066 image_create_info.pNext = NULL;
8067 image_create_info.imageType = VK_IMAGE_TYPE_2D;
8068 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
8069 image_create_info.extent.width = 32;
8070 image_create_info.extent.height = 1;
8071 image_create_info.extent.depth = 1;
8072 image_create_info.mipLevels = 1;
8073 image_create_info.arrayLayers = 1;
8074 image_create_info.samples = VK_SAMPLE_COUNT_2_BIT;
8075 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
8076 // Note: Some implementations expect color attachment usage for any
8077 // multisample surface
8078 image_create_info.usage =
8079 VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
8080 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -06008081
Karl Schultz6addd812016-02-02 17:17:23 -07008082 err =
8083 vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -06008084 ASSERT_VK_SUCCESS(err);
8085
Karl Schultz6addd812016-02-02 17:17:23 -07008086 image_create_info.imageType = VK_IMAGE_TYPE_1D;
8087 // Note: Some implementations expect color attachment usage for any
8088 // multisample surface
8089 image_create_info.usage =
8090 VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
8091 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -06008092
Karl Schultz6addd812016-02-02 17:17:23 -07008093 err =
8094 vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -06008095 ASSERT_VK_SUCCESS(err);
8096
8097 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008098 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008099 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
8100 memAlloc.pNext = NULL;
8101 memAlloc.allocationSize = 0;
8102 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -06008103
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -06008104 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -06008105 memAlloc.allocationSize = memReqs.size;
Karl Schultz6addd812016-02-02 17:17:23 -07008106 pass =
8107 m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -06008108 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008109 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -06008110 ASSERT_VK_SUCCESS(err);
8111
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008112 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -06008113 memAlloc.allocationSize = memReqs.size;
Karl Schultz6addd812016-02-02 17:17:23 -07008114 pass =
8115 m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -06008116 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008117 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -06008118 ASSERT_VK_SUCCESS(err);
8119
8120 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
8121 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008122 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -06008123 ASSERT_VK_SUCCESS(err);
8124
8125 BeginCommandBuffer();
8126 // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest?
Karl Schultz6addd812016-02-02 17:17:23 -07008127 // VK_IMAGE_LAYOUT_UNDEFINED = 0,
8128 // VK_IMAGE_LAYOUT_GENERAL = 1,
Mike Stroyana3082432015-09-25 13:39:21 -06008129 VkImageResolve resolveRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +08008130 resolveRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -06008131 resolveRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -06008132 resolveRegion.srcSubresource.baseArrayLayer = 0;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008133 resolveRegion.srcSubresource.layerCount = 0;
Mike Stroyana3082432015-09-25 13:39:21 -06008134 resolveRegion.srcOffset.x = 0;
8135 resolveRegion.srcOffset.y = 0;
8136 resolveRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +08008137 resolveRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008138 resolveRegion.dstSubresource.mipLevel = 0;
8139 resolveRegion.dstSubresource.baseArrayLayer = 0;
8140 resolveRegion.dstSubresource.layerCount = 0;
8141 resolveRegion.dstOffset.x = 0;
8142 resolveRegion.dstOffset.y = 0;
8143 resolveRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -06008144 resolveRegion.extent.width = 1;
8145 resolveRegion.extent.height = 1;
8146 resolveRegion.extent.depth = 1;
Karl Schultz6addd812016-02-02 17:17:23 -07008147 m_commandBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage,
8148 VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion);
Mike Stroyana3082432015-09-25 13:39:21 -06008149 EndCommandBuffer();
8150
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008151 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -06008152
Chia-I Wuf7458c52015-10-26 21:10:41 +08008153 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008154 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +08008155 vkFreeMemory(m_device->device(), srcMem, NULL);
8156 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -06008157}
Tobin Ehlisa1c28562015-10-23 16:00:08 -06008158
Karl Schultz6addd812016-02-02 17:17:23 -07008159TEST_F(VkLayerTest, DepthStencilImageViewWithColorAspectBitError) {
Tobin Ehlisa1c28562015-10-23 16:00:08 -06008160 // Create a single Image descriptor and cause it to first hit an error due
Karl Schultz6addd812016-02-02 17:17:23 -07008161 // to using a DS format, then cause it to hit error due to COLOR_BIT not
8162 // set in aspect
Tobin Ehlisa1c28562015-10-23 16:00:08 -06008163 // The image format check comes 2nd in validation so we trigger it first,
8164 // then when we cause aspect fail next, bad format check will be preempted
Karl Schultz6addd812016-02-02 17:17:23 -07008165 VkResult err;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06008166
Karl Schultz6addd812016-02-02 17:17:23 -07008167 m_errorMonitor->SetDesiredFailureMsg(
8168 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06008169 "Combination depth/stencil image formats can have only the ");
8170
Tobin Ehlisa1c28562015-10-23 16:00:08 -06008171 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06008172
Chia-I Wu1b99bb22015-10-27 19:25:11 +08008173 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008174 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
8175 ds_type_count.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06008176
8177 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008178 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
8179 ds_pool_ci.pNext = NULL;
8180 ds_pool_ci.maxSets = 1;
8181 ds_pool_ci.poolSizeCount = 1;
8182 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06008183
8184 VkDescriptorPool ds_pool;
Karl Schultz6addd812016-02-02 17:17:23 -07008185 err =
8186 vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06008187 ASSERT_VK_SUCCESS(err);
8188
8189 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008190 dsl_binding.binding = 0;
8191 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
8192 dsl_binding.descriptorCount = 1;
8193 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
8194 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06008195
8196 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008197 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
8198 ds_layout_ci.pNext = NULL;
8199 ds_layout_ci.bindingCount = 1;
8200 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06008201 VkDescriptorSetLayout ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07008202 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
8203 &ds_layout);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06008204 ASSERT_VK_SUCCESS(err);
8205
8206 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008207 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08008208 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07008209 alloc_info.descriptorSetCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06008210 alloc_info.descriptorPool = ds_pool;
8211 alloc_info.pSetLayouts = &ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07008212 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info,
8213 &descriptorSet);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06008214 ASSERT_VK_SUCCESS(err);
8215
Karl Schultz6addd812016-02-02 17:17:23 -07008216 VkImage image_bad;
8217 VkImage image_good;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06008218 // One bad format and one good format for Color attachment
Karl Schultz6addd812016-02-02 17:17:23 -07008219 const VkFormat tex_format_bad = VK_FORMAT_D32_SFLOAT_S8_UINT;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06008220 const VkFormat tex_format_good = VK_FORMAT_B8G8R8A8_UNORM;
Karl Schultz6addd812016-02-02 17:17:23 -07008221 const int32_t tex_width = 32;
8222 const int32_t tex_height = 32;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06008223
8224 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008225 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
8226 image_create_info.pNext = NULL;
8227 image_create_info.imageType = VK_IMAGE_TYPE_2D;
8228 image_create_info.format = tex_format_bad;
8229 image_create_info.extent.width = tex_width;
8230 image_create_info.extent.height = tex_height;
8231 image_create_info.extent.depth = 1;
8232 image_create_info.mipLevels = 1;
8233 image_create_info.arrayLayers = 1;
8234 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
8235 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
8236 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT |
8237 VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT;
8238 image_create_info.flags = 0;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06008239
Karl Schultz6addd812016-02-02 17:17:23 -07008240 err =
8241 vkCreateImage(m_device->device(), &image_create_info, NULL, &image_bad);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06008242 ASSERT_VK_SUCCESS(err);
8243 image_create_info.format = tex_format_good;
Karl Schultz6addd812016-02-02 17:17:23 -07008244 image_create_info.usage =
8245 VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
8246 err = vkCreateImage(m_device->device(), &image_create_info, NULL,
8247 &image_good);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06008248 ASSERT_VK_SUCCESS(err);
8249
8250 VkImageViewCreateInfo image_view_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008251 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
8252 image_view_create_info.image = image_bad;
8253 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
8254 image_view_create_info.format = tex_format_bad;
8255 image_view_create_info.subresourceRange.baseArrayLayer = 0;
8256 image_view_create_info.subresourceRange.baseMipLevel = 0;
8257 image_view_create_info.subresourceRange.layerCount = 1;
8258 image_view_create_info.subresourceRange.levelCount = 1;
8259 image_view_create_info.subresourceRange.aspectMask =
8260 VK_IMAGE_ASPECT_COLOR_BIT;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06008261
8262 VkImageView view;
Karl Schultz6addd812016-02-02 17:17:23 -07008263 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL,
8264 &view);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06008265
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008266 m_errorMonitor->VerifyFound();
Tobin Ehlisa1c28562015-10-23 16:00:08 -06008267
Chia-I Wuf7458c52015-10-26 21:10:41 +08008268 vkDestroyImage(m_device->device(), image_bad, NULL);
8269 vkDestroyImage(m_device->device(), image_good, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +08008270 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
8271 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06008272}
Tobin Ehliscde08892015-09-22 10:11:37 -06008273#endif // IMAGE_TESTS
8274
Tony Barbour300a6082015-04-07 13:44:53 -06008275int main(int argc, char **argv) {
8276 int result;
8277
Cody Northrop8e54a402016-03-08 22:25:52 -07008278#ifdef ANDROID
8279 int vulkanSupport = InitVulkan();
8280 if (vulkanSupport == 0)
8281 return 1;
8282#endif
8283
Tony Barbour300a6082015-04-07 13:44:53 -06008284 ::testing::InitGoogleTest(&argc, argv);
Tony Barbour6918cd52015-04-09 12:58:51 -06008285 VkTestFramework::InitArgs(&argc, argv);
Tony Barbour300a6082015-04-07 13:44:53 -06008286
8287 ::testing::AddGlobalTestEnvironment(new TestEnvironment);
8288
8289 result = RUN_ALL_TESTS();
8290
Tony Barbour6918cd52015-04-09 12:58:51 -06008291 VkTestFramework::Finish();
Tony Barbour300a6082015-04-07 13:44:53 -06008292 return result;
8293}