blob: 4cb1be18386576346287a0ee2981f9ad8d9e153e [file] [log] [blame]
Tony Barbour65c48b32015-11-17 10:02:56 -07001//
2// Copyright (C) 2015 Valve Corporation
Tobin Ehlis8fab6562015-12-01 09:57:09 -07003// Copyright (C) 2015 Google, Inc.
Tony Barbour65c48b32015-11-17 10:02:56 -07004//
5// Permission is hereby granted, free of charge, to any person obtaining a
6// copy of this software and associated documentation files (the "Software"),
7// to deal in the Software without restriction, including without limitation
8// the rights to use, copy, modify, merge, publish, distribute, sublicense,
9// and/or sell copies of the Software, and to permit persons to whom the
10// Software is furnished to do so, subject to the following conditions:
11//
12// The above copyright notice and this permission notice shall be included
13// in all copies or substantial portions of the Software.
14//
15// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
21// DEALINGS IN THE SOFTWARE.
22//
23// Author: Chia-I Wu <olvaffe@gmail.com>
24// Author: Chris Forbes <chrisf@ijw.co.nz>
25// Author: Courtney Goeltzenleuchter <courtney@LunarG.com>
26// Author: Mark Lobodzinski <mark@lunarg.com>
27// Author: Mike Stroyan <mike@LunarG.com>
Tobin Ehlis8fab6562015-12-01 09:57:09 -070028// Author: Tobin Ehlis <tobine@google.com>
Tony Barbour65c48b32015-11-17 10:02:56 -070029// Author: Tony Barbour <tony@LunarG.com>
30
31
David Pinedo9316d3b2015-11-06 12:54:48 -070032#include <vulkan/vulkan.h>
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -070033#include <vulkan/vk_ext_debug_report.h>
Courtney Goeltzenleuchter58f3eff2015-10-07 13:28:58 -060034#include "test_common.h"
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -060035#include "vkrenderframework.h"
Tobin Ehlisa0cb02e2015-07-03 10:15:26 -060036#include "vk_layer_config.h"
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060037#include "../icd/common/icd-spv.h"
Tony Barbour300a6082015-04-07 13:44:53 -060038
Mark Lobodzinski3780e142015-05-14 15:08:13 -050039#define GLM_FORCE_RADIANS
40#include "glm/glm.hpp"
41#include <glm/gtc/matrix_transform.hpp>
42
Tobin Ehlis0788f522015-05-26 16:11:58 -060043#define MEM_TRACKER_TESTS 1
44#define OBJ_TRACKER_TESTS 1
45#define DRAW_STATE_TESTS 1
46#define THREADING_TESTS 1
Chris Forbes9f7ff632015-05-25 11:13:08 +120047#define SHADER_CHECKER_TESTS 1
Mark Lobodzinski209b5292015-09-17 09:44:05 -060048#define DEVICE_LIMITS_TESTS 1
Tobin Ehliscde08892015-09-22 10:11:37 -060049#define IMAGE_TESTS 1
Tobin Ehlis0788f522015-05-26 16:11:58 -060050
Mark Lobodzinski3780e142015-05-14 15:08:13 -050051//--------------------------------------------------------------------------------------
52// Mesh and VertexFormat Data
53//--------------------------------------------------------------------------------------
54struct Vertex
55{
56 float posX, posY, posZ, posW; // Position data
57 float r, g, b, a; // Color
58};
59
60#define XYZ1(_x_, _y_, _z_) (_x_), (_y_), (_z_), 1.f
61
62typedef enum _BsoFailSelect {
63 BsoFailNone = 0x00000000,
Cody Northrop271ba752015-08-26 10:01:32 -060064 BsoFailLineWidth = 0x00000001,
65 BsoFailDepthBias = 0x00000002,
Cody Northrop12365112015-08-17 11:10:49 -060066 BsoFailViewport = 0x00000004,
Tobin Ehlis963a4042015-09-29 08:18:34 -060067 BsoFailScissor = 0x00000008,
68 BsoFailBlend = 0x00000010,
69 BsoFailDepthBounds = 0x00000020,
70 BsoFailStencilReadMask = 0x00000040,
71 BsoFailStencilWriteMask = 0x00000080,
72 BsoFailStencilReference = 0x00000100,
Mark Lobodzinski3780e142015-05-14 15:08:13 -050073} BsoFailSelect;
74
75struct vktriangle_vs_uniform {
76 // Must start with MVP
77 float mvp[4][4];
78 float position[3][4];
79 float color[3][4];
80};
81
Mark Lobodzinski75a97e62015-06-02 09:41:30 -050082static const char bindStateVertShaderText[] =
Tony Barboure804d202016-01-05 13:37:45 -070083 "#version 400\n"
84 "#extension GL_ARB_separate_shader_objects : require\n"
85 "#extension GL_ARB_shading_language_420pack : require\n"
Mark Lobodzinski3780e142015-05-14 15:08:13 -050086 "vec2 vertices[3];\n"
Tony Barboure804d202016-01-05 13:37:45 -070087 "out gl_PerVertex {\n"
88 " vec4 gl_Position;\n"
89 "};\n"
Mark Lobodzinski3780e142015-05-14 15:08:13 -050090 "void main() {\n"
91 " vertices[0] = vec2(-1.0, -1.0);\n"
92 " vertices[1] = vec2( 1.0, -1.0);\n"
93 " vertices[2] = vec2( 0.0, 1.0);\n"
94 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
95 "}\n";
96
Mark Lobodzinski75a97e62015-06-02 09:41:30 -050097static const char bindStateFragShaderText[] =
Tony Barboure804d202016-01-05 13:37:45 -070098 "#version 400\n"
Cody Northrop8a3bb132015-06-16 17:32:04 -060099 "#extension GL_ARB_separate_shader_objects: require\n"
100 "#extension GL_ARB_shading_language_420pack: require\n"
101 "\n"
102 "layout(location = 0) out vec4 uFragColor;\n"
103 "void main(){\n"
104 " uFragColor = vec4(0,1,0,1);\n"
105 "}\n";
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500106
Jesse Hall4fb40e62015-12-22 21:27:55 -0800107static VKAPI_ATTR VkBool32 VKAPI_CALL myDbgFunc(
Tony Barbour67e99152015-07-10 14:10:27 -0600108 VkFlags msgFlags,
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -0700109 VkDebugReportObjectTypeEXT objType,
Tony Barbour67e99152015-07-10 14:10:27 -0600110 uint64_t srcObject,
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -0600111 size_t location,
112 int32_t msgCode,
113 const char* pLayerPrefix,
114 const char* pMsg,
Courtney Goeltzenleuchteraf5e7552015-11-30 11:52:06 -0700115 const void* pUserData);
Tony Barbour300a6082015-04-07 13:44:53 -0600116
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600117// ********************************************************
118// ErrorMonitor Usage:
119//
120// Call SetDesiredFailureMsg with a string to be compared against all
121// encountered log messages. Passing NULL will match all log messages.
122// logMsg will return true for skipCall only if msg is matched or NULL.
123//
124// Call DesiredMsgFound to determine if the desired failure message
125// was encountered.
126
Tony Barbour300a6082015-04-07 13:44:53 -0600127class ErrorMonitor {
128public:
Tony Barbour15524c32015-04-29 17:34:29 -0600129 ErrorMonitor()
Tony Barbour300a6082015-04-07 13:44:53 -0600130 {
Mike Stroyan4268d1f2015-07-13 14:45:35 -0600131 test_platform_thread_create_mutex(&m_mutex);
132 test_platform_thread_lock_mutex(&m_mutex);
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -0700133 m_msgFlags = VK_DEBUG_REPORT_INFO_BIT_EXT;
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600134 m_bailout = NULL;
Mike Stroyan4268d1f2015-07-13 14:45:35 -0600135 test_platform_thread_unlock_mutex(&m_mutex);
Tony Barbour300a6082015-04-07 13:44:53 -0600136 }
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600137
138 void SetDesiredFailureMsg(VkFlags msgFlags, const char *msgString)
Tony Barbour300a6082015-04-07 13:44:53 -0600139 {
Mike Stroyan4268d1f2015-07-13 14:45:35 -0600140 test_platform_thread_lock_mutex(&m_mutex);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600141 m_desiredMsg.clear();
142 m_failureMsg.clear();
143 m_otherMsgs.clear();
144 m_desiredMsg = msgString;
145 m_msgFound = VK_FALSE;
146 m_msgFlags = msgFlags;
Mike Stroyan4268d1f2015-07-13 14:45:35 -0600147 test_platform_thread_unlock_mutex(&m_mutex);
Tony Barbour300a6082015-04-07 13:44:53 -0600148 }
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600149
150 VkBool32 CheckForDesiredMsg(VkFlags msgFlags, const char *msgString)
Tony Barbour300a6082015-04-07 13:44:53 -0600151 {
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600152 VkBool32 result = VK_FALSE;
Mike Stroyan4268d1f2015-07-13 14:45:35 -0600153 test_platform_thread_lock_mutex(&m_mutex);
Mike Stroyanaccf7692015-05-12 16:00:45 -0600154 if (m_bailout != NULL) {
155 *m_bailout = true;
156 }
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600157 string errorString(msgString);
158 if (msgFlags & m_msgFlags) {
159 if (errorString.find(m_desiredMsg) != string::npos) {
160 m_failureMsg = errorString;
161 m_msgFound = VK_TRUE;
162 result = VK_TRUE;
163 } else {
164 m_otherMsgs.push_back(errorString);
165 }
166 }
Mike Stroyan4268d1f2015-07-13 14:45:35 -0600167 test_platform_thread_unlock_mutex(&m_mutex);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600168 return result;
Mike Stroyanaccf7692015-05-12 16:00:45 -0600169 }
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600170
171 vector<string> GetOtherFailureMsgs(void)
172 {
173 return m_otherMsgs;
174 }
175
176 string GetFailureMsg(void)
177 {
178 return m_failureMsg;
179 }
180
181 VkBool32 DesiredMsgFound(void)
182 {
183 return m_msgFound;
184 }
185
Mike Stroyanaccf7692015-05-12 16:00:45 -0600186 void SetBailout(bool *bailout)
187 {
188 m_bailout = bailout;
Tony Barbour300a6082015-04-07 13:44:53 -0600189 }
190
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600191 void DumpFailureMsgs(void)
192 {
193 vector<string> otherMsgs = GetOtherFailureMsgs();
194 cout << "Other error messages logged for this test were:" << endl;
195 for (auto iter = otherMsgs.begin(); iter != otherMsgs.end(); iter++) {
196 cout << " " << *iter << endl;
197 }
198 }
199
Tony Barbour300a6082015-04-07 13:44:53 -0600200private:
Mike Stroyan4268d1f2015-07-13 14:45:35 -0600201 VkFlags m_msgFlags;
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600202 string m_desiredMsg;
203 string m_failureMsg;
204 vector<string> m_otherMsgs;
Mike Stroyan4268d1f2015-07-13 14:45:35 -0600205 test_platform_thread_mutex m_mutex;
206 bool* m_bailout;
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600207 VkBool32 m_msgFound;
Tony Barbour300a6082015-04-07 13:44:53 -0600208};
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500209
Courtney Goeltzenleuchter06640832015-09-04 13:52:24 -0600210static VkBool32 myDbgFunc(
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -0600211 VkFlags msgFlags,
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -0700212 VkDebugReportObjectTypeEXT objType,
Tony Barbour67e99152015-07-10 14:10:27 -0600213 uint64_t srcObject,
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -0600214 size_t location,
215 int32_t msgCode,
216 const char* pLayerPrefix,
217 const char* pMsg,
Courtney Goeltzenleuchteraf5e7552015-11-30 11:52:06 -0700218 const void* pUserData)
Tony Barbour300a6082015-04-07 13:44:53 -0600219{
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -0700220 if (msgFlags & (VK_DEBUG_REPORT_WARN_BIT_EXT | VK_DEBUG_REPORT_PERF_WARN_BIT_EXT | VK_DEBUG_REPORT_ERROR_BIT_EXT)) {
Tony Barbour0b4d9562015-04-09 10:48:04 -0600221 ErrorMonitor *errMonitor = (ErrorMonitor *)pUserData;
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600222 return errMonitor->CheckForDesiredMsg(msgFlags, pMsg);
Tony Barbour0b4d9562015-04-09 10:48:04 -0600223 }
Courtney Goeltzenleuchter06640832015-09-04 13:52:24 -0600224 return false;
Tony Barbour300a6082015-04-07 13:44:53 -0600225}
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500226
Tony Barbour6918cd52015-04-09 12:58:51 -0600227class VkLayerTest : public VkRenderFramework
Tony Barbour300a6082015-04-07 13:44:53 -0600228{
229public:
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800230 VkResult BeginCommandBuffer(VkCommandBufferObj &commandBuffer);
231 VkResult EndCommandBuffer(VkCommandBufferObj &commandBuffer);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500232 void VKTriangleTest(const char *vertShaderText, const char *fragShaderText, BsoFailSelect failMask);
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800233 void GenericDrawPreparation(VkCommandBufferObj *commandBuffer, VkPipelineObj &pipelineobj, VkDescriptorSetObj &descriptorSet, BsoFailSelect failMask);
Tony Barbourfe3351b2015-07-28 10:17:20 -0600234 void GenericDrawPreparation(VkPipelineObj &pipelineobj, VkDescriptorSetObj &descriptorSet, BsoFailSelect failMask)
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800235 { GenericDrawPreparation(m_commandBuffer, pipelineobj, descriptorSet, failMask); }
Tony Barbour300a6082015-04-07 13:44:53 -0600236
Tony Barbourfe3351b2015-07-28 10:17:20 -0600237 /* Convenience functions that use built-in command buffer */
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800238 VkResult BeginCommandBuffer() { return BeginCommandBuffer(*m_commandBuffer); }
239 VkResult EndCommandBuffer() { return EndCommandBuffer(*m_commandBuffer); }
Courtney Goeltzenleuchter08c26372015-09-23 12:31:50 -0600240 void Draw(uint32_t vertexCount, uint32_t instanceCount, uint32_t firstVertex, uint32_t firstInstance)
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800241 { m_commandBuffer->Draw(vertexCount, instanceCount, firstVertex, firstInstance); }
Courtney Goeltzenleuchter08c26372015-09-23 12:31:50 -0600242 void DrawIndexed(uint32_t indexCount, uint32_t instanceCount, uint32_t firstIndex, int32_t vertexOffset, uint32_t firstInstance)
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800243 { m_commandBuffer->DrawIndexed(indexCount, instanceCount, firstIndex, vertexOffset, firstInstance); }
244 void QueueCommandBuffer() { m_commandBuffer->QueueCommandBuffer(); }
245 void QueueCommandBuffer(const VkFence& fence) { m_commandBuffer->QueueCommandBuffer(fence); }
Tony Barbourfe3351b2015-07-28 10:17:20 -0600246 void BindVertexBuffer(VkConstantBufferObj *vertexBuffer, VkDeviceSize offset, uint32_t binding)
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800247 { m_commandBuffer->BindVertexBuffer(vertexBuffer, offset, binding); }
Tony Barbourfe3351b2015-07-28 10:17:20 -0600248 void BindIndexBuffer(VkIndexBufferObj *indexBuffer, VkDeviceSize offset)
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800249 { m_commandBuffer->BindIndexBuffer(indexBuffer, offset); }
Tony Barbour300a6082015-04-07 13:44:53 -0600250protected:
Tony Barbour6918cd52015-04-09 12:58:51 -0600251 ErrorMonitor *m_errorMonitor;
Tony Barbour300a6082015-04-07 13:44:53 -0600252
253 virtual void SetUp() {
Courtney Goeltzenleuchtercd69eee2015-07-06 09:10:47 -0600254 std::vector<const char *> instance_layer_names;
255 std::vector<const char *> device_layer_names;
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -0600256 std::vector<const char *> instance_extension_names;
257 std::vector<const char *> device_extension_names;
Tony Barbour3fdff9e2015-04-23 12:55:36 -0600258
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -0700259 instance_extension_names.push_back(VK_EXT_DEBUG_REPORT_EXTENSION_NAME);
Courtney Goeltzenleuchterc2b06fe2015-06-16 15:59:11 -0600260 /*
261 * Since CreateDbgMsgCallback is an instance level extension call
262 * any extension / layer that utilizes that feature also needs
263 * to be enabled at create instance time.
264 */
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800265 // Use Threading layer first to protect others from ThreadCommandBufferCollision test
Michael Lentine03107b42015-12-11 10:49:51 -0800266 instance_layer_names.push_back("VK_LAYER_LUNARG_threading");
267 instance_layer_names.push_back("VK_LAYER_LUNARG_object_tracker");
268 instance_layer_names.push_back("VK_LAYER_LUNARG_mem_tracker");
269 instance_layer_names.push_back("VK_LAYER_LUNARG_draw_state");
270 instance_layer_names.push_back("VK_LAYER_LUNARG_device_limits");
271 instance_layer_names.push_back("VK_LAYER_LUNARG_image");
Courtney Goeltzenleuchterd971b612015-06-17 20:51:59 -0600272
Michael Lentine03107b42015-12-11 10:49:51 -0800273 device_layer_names.push_back("VK_LAYER_LUNARG_threading");
274 device_layer_names.push_back("VK_LAYER_LUNARG_object_tracker");
275 device_layer_names.push_back("VK_LAYER_LUNARG_mem_tracker");
276 device_layer_names.push_back("VK_LAYER_LUNARG_draw_state");
277 device_layer_names.push_back("VK_LAYER_LUNARG_device_limits");
278 device_layer_names.push_back("VK_LAYER_LUNARG_image");
Tony Barbour300a6082015-04-07 13:44:53 -0600279
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600280 this->app_info.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO;
Tony Barbour300a6082015-04-07 13:44:53 -0600281 this->app_info.pNext = NULL;
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800282 this->app_info.pApplicationName = "layer_tests";
283 this->app_info.applicationVersion = 1;
Tony Barbour300a6082015-04-07 13:44:53 -0600284 this->app_info.pEngineName = "unittest";
285 this->app_info.engineVersion = 1;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600286 this->app_info.apiVersion = VK_API_VERSION;
Tony Barbour300a6082015-04-07 13:44:53 -0600287
Tony Barbour15524c32015-04-29 17:34:29 -0600288 m_errorMonitor = new ErrorMonitor;
Courtney Goeltzenleuchtercd69eee2015-07-06 09:10:47 -0600289 InitFramework(instance_layer_names, device_layer_names,
290 instance_extension_names, device_extension_names,
291 myDbgFunc, m_errorMonitor);
Tony Barbour300a6082015-04-07 13:44:53 -0600292 }
293
294 virtual void TearDown() {
295 // Clean up resources before we reset
Tony Barbour300a6082015-04-07 13:44:53 -0600296 ShutdownFramework();
Tony Barbour0b4d9562015-04-09 10:48:04 -0600297 delete m_errorMonitor;
Tony Barbour300a6082015-04-07 13:44:53 -0600298 }
299};
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500300
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800301VkResult VkLayerTest::BeginCommandBuffer(VkCommandBufferObj &commandBuffer)
Tony Barbour300a6082015-04-07 13:44:53 -0600302{
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600303 VkResult result;
Tony Barbour300a6082015-04-07 13:44:53 -0600304
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800305 result = commandBuffer.BeginCommandBuffer();
Tony Barbour300a6082015-04-07 13:44:53 -0600306
307 /*
308 * For render test all drawing happens in a single render pass
309 * on a single command buffer.
310 */
Chris Forbes76a5eeb2015-06-16 14:05:59 +1200311 if (VK_SUCCESS == result && renderPass()) {
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800312 commandBuffer.BeginRenderPass(renderPassBeginInfo());
Tony Barbour300a6082015-04-07 13:44:53 -0600313 }
314
315 return result;
316}
317
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800318VkResult VkLayerTest::EndCommandBuffer(VkCommandBufferObj &commandBuffer)
Tony Barbour300a6082015-04-07 13:44:53 -0600319{
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600320 VkResult result;
Tony Barbour300a6082015-04-07 13:44:53 -0600321
Chris Forbes76a5eeb2015-06-16 14:05:59 +1200322 if (renderPass()) {
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800323 commandBuffer.EndRenderPass();
Chris Forbes76a5eeb2015-06-16 14:05:59 +1200324 }
Tony Barbour300a6082015-04-07 13:44:53 -0600325
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800326 result = commandBuffer.EndCommandBuffer();
Tony Barbour300a6082015-04-07 13:44:53 -0600327
328 return result;
329}
330
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500331void VkLayerTest::VKTriangleTest(const char *vertShaderText, const char *fragShaderText, BsoFailSelect failMask)
332{
333 // Create identity matrix
334 int i;
335 struct vktriangle_vs_uniform data;
336
337 glm::mat4 Projection = glm::mat4(1.0f);
338 glm::mat4 View = glm::mat4(1.0f);
339 glm::mat4 Model = glm::mat4(1.0f);
340 glm::mat4 MVP = Projection * View * Model;
341 const int matrixSize = sizeof(MVP);
342 const int bufSize = sizeof(vktriangle_vs_uniform) / sizeof(float);
343
344 memcpy(&data.mvp, &MVP[0][0], matrixSize);
345
346 static const Vertex tri_data[] =
347 {
348 { XYZ1( -1, -1, 0 ), XYZ1( 1.f, 0.f, 0.f ) },
349 { XYZ1( 1, -1, 0 ), XYZ1( 0.f, 1.f, 0.f ) },
350 { XYZ1( 0, 1, 0 ), XYZ1( 0.f, 0.f, 1.f ) },
351 };
352
353 for (i=0; i<3; i++) {
354 data.position[i][0] = tri_data[i].posX;
355 data.position[i][1] = tri_data[i].posY;
356 data.position[i][2] = tri_data[i].posZ;
357 data.position[i][3] = tri_data[i].posW;
358 data.color[i][0] = tri_data[i].r;
359 data.color[i][1] = tri_data[i].g;
360 data.color[i][2] = tri_data[i].b;
361 data.color[i][3] = tri_data[i].a;
362 }
363
364 ASSERT_NO_FATAL_FAILURE(InitState());
365 ASSERT_NO_FATAL_FAILURE(InitViewport());
366
367 VkConstantBufferObj constantBuffer(m_device, bufSize*2, sizeof(float), (const void*) &data);
368
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -0600369 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX_BIT, this);
370 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500371
372 VkPipelineObj pipelineobj(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +0800373 pipelineobj.AddColorAttachment();
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500374 pipelineobj.AddShader(&vs);
375 pipelineobj.AddShader(&ps);
Courtney Goeltzenleuchter507ba972015-09-30 16:16:57 -0600376 if (failMask & BsoFailLineWidth) {
377 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_LINE_WIDTH);
378 }
379 if (failMask & BsoFailDepthBias) {
380 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_DEPTH_BIAS);
381 }
Tobin Ehlisd332f282015-10-02 11:00:56 -0600382 // Viewport and scissors must stay in synch or other errors will occur than the ones we want
Courtney Goeltzenleuchter507ba972015-09-30 16:16:57 -0600383 if (failMask & BsoFailViewport) {
384 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_VIEWPORT);
Tobin Ehlisd332f282015-10-02 11:00:56 -0600385 m_viewports.clear();
386 m_scissors.clear();
Courtney Goeltzenleuchter507ba972015-09-30 16:16:57 -0600387 }
388 if (failMask & BsoFailScissor) {
389 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_SCISSOR);
Tobin Ehlisd332f282015-10-02 11:00:56 -0600390 m_scissors.clear();
391 m_viewports.clear();
Courtney Goeltzenleuchter507ba972015-09-30 16:16:57 -0600392 }
393 if (failMask & BsoFailBlend) {
394 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_BLEND_CONSTANTS);
395 }
396 if (failMask & BsoFailDepthBounds) {
397 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_DEPTH_BOUNDS);
398 }
399 if (failMask & BsoFailStencilReadMask) {
400 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_STENCIL_COMPARE_MASK);
401 }
402 if (failMask & BsoFailStencilWriteMask) {
403 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_STENCIL_WRITE_MASK);
404 }
405 if (failMask & BsoFailStencilReference) {
406 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_STENCIL_REFERENCE);
407 }
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500408
409 VkDescriptorSetObj descriptorSet(m_device);
410 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, constantBuffer);
411
412 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbourfe3351b2015-07-28 10:17:20 -0600413 ASSERT_VK_SUCCESS(BeginCommandBuffer());
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500414
Tony Barbourfe3351b2015-07-28 10:17:20 -0600415 GenericDrawPreparation(pipelineobj, descriptorSet, failMask);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500416
417 // render triangle
Courtney Goeltzenleuchter08c26372015-09-23 12:31:50 -0600418 Draw(3, 1, 0, 0);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500419
420 // finalize recording of the command buffer
Tony Barbourfe3351b2015-07-28 10:17:20 -0600421 EndCommandBuffer();
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500422
Tony Barbourfe3351b2015-07-28 10:17:20 -0600423 QueueCommandBuffer();
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500424}
425
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800426void VkLayerTest::GenericDrawPreparation(VkCommandBufferObj *commandBuffer, VkPipelineObj &pipelineobj, VkDescriptorSetObj &descriptorSet, BsoFailSelect failMask)
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500427{
428 if (m_depthStencil->Initialized()) {
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800429 commandBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color, m_stencil_clear_color, m_depthStencil);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500430 } else {
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800431 commandBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color, m_stencil_clear_color, NULL);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500432 }
433
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800434 commandBuffer->PrepareAttachments();
Cody Northrop82485a82015-08-18 15:21:16 -0600435 // Make sure depthWriteEnable is set so that Depth fail test will work correctly
436 // Make sure stencilTestEnable is set so that Stencil fail test will work correctly
Tony Barboureb254902015-07-15 12:50:33 -0600437 VkStencilOpState stencil = {};
Chia-I Wu1b99bb22015-10-27 19:25:11 +0800438 stencil.failOp = VK_STENCIL_OP_KEEP;
439 stencil.passOp = VK_STENCIL_OP_KEEP;
440 stencil.depthFailOp = VK_STENCIL_OP_KEEP;
441 stencil.compareOp = VK_COMPARE_OP_NEVER;
Tony Barboureb254902015-07-15 12:50:33 -0600442
443 VkPipelineDepthStencilStateCreateInfo ds_ci = {};
444 ds_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DEPTH_STENCIL_STATE_CREATE_INFO;
Courtney Goeltzenleuchter507ba972015-09-30 16:16:57 -0600445 ds_ci.pNext = NULL;
446 ds_ci.depthTestEnable = VK_FALSE;
447 ds_ci.depthWriteEnable = VK_TRUE;
448 ds_ci.depthCompareOp = VK_COMPARE_OP_NEVER;
449 ds_ci.depthBoundsTestEnable = VK_FALSE;
450 ds_ci.stencilTestEnable = VK_TRUE;
451 ds_ci.front = stencil;
452 ds_ci.back = stencil;
Tony Barboureb254902015-07-15 12:50:33 -0600453
Tobin Ehlis4bf96d12015-06-25 11:58:41 -0600454 pipelineobj.SetDepthStencil(&ds_ci);
Tobin Ehlisd332f282015-10-02 11:00:56 -0600455 pipelineobj.SetViewport(m_viewports);
456 pipelineobj.SetScissor(m_scissors);
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800457 descriptorSet.CreateVKDescriptorSet(commandBuffer);
Cody Northrop29a08f22015-08-27 10:20:35 -0600458 VkResult err = pipelineobj.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
459 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800460 commandBuffer->BindPipeline(pipelineobj);
461 commandBuffer->BindDescriptorSet(descriptorSet);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500462}
463
464// ********************************************************************************************************************
465// ********************************************************************************************************************
466// ********************************************************************************************************************
467// ********************************************************************************************************************
Tobin Ehlis0788f522015-05-26 16:11:58 -0600468#if MEM_TRACKER_TESTS
Tobin Ehlis8fab6562015-12-01 09:57:09 -0700469#if 0
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800470TEST_F(VkLayerTest, CallResetCommandBufferBeforeCompletion)
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -0500471{
472 vk_testing::Fence testFence;
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -0500473 VkFenceCreateInfo fenceInfo = {};
474 fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
475 fenceInfo.pNext = NULL;
476 fenceInfo.flags = 0;
477
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -0700478 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Resetting CB");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600479
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -0500480 ASSERT_NO_FATAL_FAILURE(InitState());
Tony Barbourc1eb1a52015-07-20 13:00:10 -0600481
482 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
483 vk_testing::Buffer buffer;
484 buffer.init_as_dst(*m_device, (VkDeviceSize)20, reqs);
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -0500485
Tony Barbourfe3351b2015-07-28 10:17:20 -0600486 BeginCommandBuffer();
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800487 m_commandBuffer->FillBuffer(buffer.handle(), 0, 4, 0x11111111);
Tony Barbourfe3351b2015-07-28 10:17:20 -0600488 EndCommandBuffer();
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -0500489
490 testFence.init(*m_device, fenceInfo);
491
492 // Bypass framework since it does the waits automatically
493 VkResult err = VK_SUCCESS;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -0600494 VkSubmitInfo submit_info;
Chia-I Wuf9be13c2015-10-26 20:37:06 +0800495 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
496 submit_info.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +0800497 submit_info.waitSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -0600498 submit_info.pWaitSemaphores = NULL;
Jon Ashburn7f9716c2015-12-30 16:42:50 -0700499 submit_info.pWaitDstStageMask = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +0800500 submit_info.commandBufferCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800501 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Chia-I Wud50a7d72015-10-26 20:48:51 +0800502 submit_info.signalSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -0600503 submit_info.pSignalSemaphores = NULL;
Courtney Goeltzenleuchter646b9072015-10-20 18:04:07 -0600504
505 err = vkQueueSubmit( m_device->m_queue, 1, &submit_info, testFence.handle());
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -0500506 ASSERT_VK_SUCCESS( err );
507
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -0500508 // Introduce failure by calling begin again before checking fence
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800509 vkResetCommandBuffer(m_commandBuffer->handle(), 0);
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -0500510
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600511 if (!m_errorMonitor->DesiredMsgFound()) {
512 FAIL() << "Did not receive Error 'Resetting CB (0xaddress) before it has completed. You must check CB flag before.'";
513 m_errorMonitor->DumpFailureMsgs();
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -0500514 }
515}
516
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800517TEST_F(VkLayerTest, CallBeginCommandBufferBeforeCompletion)
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -0500518{
519 vk_testing::Fence testFence;
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -0500520 VkFenceCreateInfo fenceInfo = {};
521 fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
522 fenceInfo.pNext = NULL;
523 fenceInfo.flags = 0;
524
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -0700525 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Calling vkBeginCommandBuffer() on active CB");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600526
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -0500527 ASSERT_NO_FATAL_FAILURE(InitState());
528 ASSERT_NO_FATAL_FAILURE(InitViewport());
529 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
530
Tony Barbourfe3351b2015-07-28 10:17:20 -0600531 BeginCommandBuffer();
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800532 m_commandBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color, m_stencil_clear_color, NULL);
Tony Barbourfe3351b2015-07-28 10:17:20 -0600533 EndCommandBuffer();
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -0500534
535 testFence.init(*m_device, fenceInfo);
536
537 // Bypass framework since it does the waits automatically
538 VkResult err = VK_SUCCESS;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -0600539 VkSubmitInfo submit_info;
Chia-I Wuf9be13c2015-10-26 20:37:06 +0800540 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
541 submit_info.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +0800542 submit_info.waitSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -0600543 submit_info.pWaitSemaphores = NULL;
Jon Ashburn7f9716c2015-12-30 16:42:50 -0700544 submit_info.pWaitDstStageMask = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +0800545 submit_info.commandBufferCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800546 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Chia-I Wud50a7d72015-10-26 20:48:51 +0800547 submit_info.signalSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -0600548 submit_info.pSignalSemaphores = NULL;
Courtney Goeltzenleuchter646b9072015-10-20 18:04:07 -0600549
550 err = vkQueueSubmit( m_device->m_queue, 1, &submit_info, testFence.handle());
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -0500551 ASSERT_VK_SUCCESS( err );
552
Mark Lobodzinski5fcc4212015-09-14 17:43:42 -0600553
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800554 VkCommandBufferBeginInfo info = {};
555 info.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT;
556 info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
Mark Lobodzinski5fcc4212015-09-14 17:43:42 -0600557 info.renderPass = VK_NULL_HANDLE;
558 info.subpass = 0;
559 info.framebuffer = VK_NULL_HANDLE;
Chia-I Wub8d47ae2015-11-11 10:18:12 +0800560 info.occlusionQueryEnable = VK_FALSE;
561 info.queryFlags = 0;
562 info.pipelineStatistics = 0;
Mark Lobodzinski5fcc4212015-09-14 17:43:42 -0600563
564 // Introduce failure by calling BCB again before checking fence
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800565 vkBeginCommandBuffer(m_commandBuffer->handle(), &info);
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -0500566
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600567 if (!m_errorMonitor->DesiredMsgFound()) {
568 FAIL() << "Did not receive Error 'Calling vkBeginCommandBuffer() on an active CB (0xaddress) before it has completed'";
569 m_errorMonitor->DumpFailureMsgs();
570
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -0500571 }
572}
Tobin Ehlis8fab6562015-12-01 09:57:09 -0700573#endif
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500574TEST_F(VkLayerTest, MapMemWithoutHostVisibleBit)
575{
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500576 VkResult err;
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -0600577 bool pass;
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500578
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -0700579 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600580 "Mapping Memory without VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT");
581
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500582 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500583
584 // Create an image, allocate memory, free it, and then try to bind it
585 VkImage image;
Mark Lobodzinski23065352015-05-29 09:32:35 -0500586 VkDeviceMemory mem;
587 VkMemoryRequirements mem_reqs;
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500588
589 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
590 const int32_t tex_width = 32;
591 const int32_t tex_height = 32;
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500592
Tony Barboureb254902015-07-15 12:50:33 -0600593 VkImageCreateInfo image_create_info = {};
594 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
595 image_create_info.pNext = NULL;
596 image_create_info.imageType = VK_IMAGE_TYPE_2D;
597 image_create_info.format = tex_format;
598 image_create_info.extent.width = tex_width;
599 image_create_info.extent.height = tex_height;
600 image_create_info.extent.depth = 1;
601 image_create_info.mipLevels = 1;
Courtney Goeltzenleuchter5d2aed42015-10-21 17:57:31 -0600602 image_create_info.arrayLayers = 1;
Chia-I Wu5c17c962015-10-31 00:31:16 +0800603 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Tony Barboureb254902015-07-15 12:50:33 -0600604 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
605 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
606 image_create_info.flags = 0;
Mark Lobodzinski5fcc4212015-09-14 17:43:42 -0600607
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800608 VkMemoryAllocateInfo mem_alloc = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +0800609 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
Tony Barboureb254902015-07-15 12:50:33 -0600610 mem_alloc.pNext = NULL;
611 mem_alloc.allocationSize = 0;
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500612 // Introduce failure, do NOT set memProps to VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT
Tony Barboureb254902015-07-15 12:50:33 -0600613 mem_alloc.memoryTypeIndex = 1;
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500614
Chia-I Wuf7458c52015-10-26 21:10:41 +0800615 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500616 ASSERT_VK_SUCCESS(err);
617
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -0600618 vkGetImageMemoryRequirements(m_device->device(),
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500619 image,
Mark Lobodzinski23065352015-05-29 09:32:35 -0500620 &mem_reqs);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500621
Mark Lobodzinski23065352015-05-29 09:32:35 -0500622 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500623
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -0600624 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT);
625 if(!pass) { // If we can't find any unmappable memory this test doesn't make sense
Chia-I Wuf7458c52015-10-26 21:10:41 +0800626 vkDestroyImage(m_device->device(), image, NULL);
Tony Barbour02fdc7d2015-08-04 16:13:01 -0600627 return;
Mike Stroyand1c84a52015-08-18 14:40:24 -0600628 }
Mike Stroyan713b2d72015-08-04 10:49:29 -0600629
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500630 // allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800631 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500632 ASSERT_VK_SUCCESS(err);
633
634 // Try to bind free memory that has been freed
Tony Barbour67e99152015-07-10 14:10:27 -0600635 err = vkBindImageMemory(m_device->device(), image, mem, 0);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500636 ASSERT_VK_SUCCESS(err);
637
638 // Map memory as if to initialize the image
639 void *mappedAddress = NULL;
Mark Lobodzinskif0670cc2016-01-05 15:30:41 -0700640 err = vkMapMemory(m_device->device(), mem, 0, VK_WHOLE_SIZE, 0, &mappedAddress);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500641
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600642 if (!m_errorMonitor->DesiredMsgFound()) {
643 FAIL() << "Did not receive Error 'Error received did not match expected error message from vkMapMemory in MemTracker'";
644 m_errorMonitor->DumpFailureMsgs();
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500645 }
Mike Stroyand1c84a52015-08-18 14:40:24 -0600646
Chia-I Wuf7458c52015-10-26 21:10:41 +0800647 vkDestroyImage(m_device->device(), image, NULL);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500648}
649
Tobin Ehlis2717d132015-07-10 18:25:07 -0600650// TODO : Is this test still valid. Not sure it is with updates to memory binding model
651// Verify and delete the test of fix the check
652//TEST_F(VkLayerTest, FreeBoundMemory)
653//{
Tobin Ehlis2717d132015-07-10 18:25:07 -0600654// VkResult err;
655//
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -0700656// m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARN_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600657// "Freeing memory object while it still has references");
Tobin Ehlis2717d132015-07-10 18:25:07 -0600658//
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600659// ASSERT_NO_FATAL_FAILURE(InitState());
660
Tobin Ehlis2717d132015-07-10 18:25:07 -0600661// // Create an image, allocate memory, free it, and then try to bind it
662// VkImage image;
663// VkDeviceMemory mem;
664// VkMemoryRequirements mem_reqs;
665//
666// const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
667// const int32_t tex_width = 32;
668// const int32_t tex_height = 32;
669//
670// const VkImageCreateInfo image_create_info = {
671// .sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO,
672// .pNext = NULL,
673// .imageType = VK_IMAGE_TYPE_2D,
674// .format = tex_format,
675// .extent = { tex_width, tex_height, 1 },
676// .mipLevels = 1,
677// .arraySize = 1,
Chia-I Wu5c17c962015-10-31 00:31:16 +0800678// .samples = VK_SAMPLE_COUNT_1_BIT,
Tobin Ehlis2717d132015-07-10 18:25:07 -0600679// .tiling = VK_IMAGE_TILING_LINEAR,
680// .usage = VK_IMAGE_USAGE_SAMPLED_BIT,
681// .flags = 0,
682// };
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800683// VkMemoryAllocateInfo mem_alloc = {
Chia-I Wu00ce5402015-11-10 16:21:09 +0800684// .sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO,
Tobin Ehlis2717d132015-07-10 18:25:07 -0600685// .pNext = NULL,
686// .allocationSize = 0,
687// .memoryTypeIndex = 0,
688// };
689//
Chia-I Wuf7458c52015-10-26 21:10:41 +0800690// err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Tobin Ehlis2717d132015-07-10 18:25:07 -0600691// ASSERT_VK_SUCCESS(err);
692//
693// err = vkGetImageMemoryRequirements(m_device->device(),
694// image,
695// &mem_reqs);
696// ASSERT_VK_SUCCESS(err);
697//
698// mem_alloc.allocationSize = mem_reqs.size;
699//
700// err = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
701// ASSERT_VK_SUCCESS(err);
702//
703// // allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800704// err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
Tobin Ehlis2717d132015-07-10 18:25:07 -0600705// ASSERT_VK_SUCCESS(err);
706//
707// // Bind memory to Image object
708// err = vkBindImageMemory(m_device->device(), image, mem, 0);
709// ASSERT_VK_SUCCESS(err);
710//
711// // Introduce validation failure, free memory while still bound to object
Chia-I Wuf7458c52015-10-26 21:10:41 +0800712// vkFreeMemory(m_device->device(), mem, NULL);
Courtney Goeltzenleuchter06640832015-09-04 13:52:24 -0600713//
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600714// if (!m_errorMonitor->DesiredMsgFound()) {
715// FAIL() << "Did not receive Warning 'Freeing memory object while it still has references'");
716// m_errorMonitor->DumpFailureMsgs();
Tobin Ehlis2717d132015-07-10 18:25:07 -0600717// }
718//}
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500719
Mark Lobodzinski944aab12015-06-05 13:59:04 -0500720TEST_F(VkLayerTest, RebindMemory)
721{
Mark Lobodzinski944aab12015-06-05 13:59:04 -0500722 VkResult err;
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -0600723 bool pass;
Mark Lobodzinski944aab12015-06-05 13:59:04 -0500724
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -0700725 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600726 "which has already been bound to mem object");
727
Mark Lobodzinski944aab12015-06-05 13:59:04 -0500728 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski944aab12015-06-05 13:59:04 -0500729
730 // Create an image, allocate memory, free it, and then try to bind it
731 VkImage image;
732 VkDeviceMemory mem1;
733 VkDeviceMemory mem2;
734 VkMemoryRequirements mem_reqs;
735
736 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
737 const int32_t tex_width = 32;
738 const int32_t tex_height = 32;
Mark Lobodzinski944aab12015-06-05 13:59:04 -0500739
Tony Barboureb254902015-07-15 12:50:33 -0600740 VkImageCreateInfo image_create_info = {};
741 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
742 image_create_info.pNext = NULL;
743 image_create_info.imageType = VK_IMAGE_TYPE_2D;
744 image_create_info.format = tex_format;
745 image_create_info.extent.width = tex_width;
746 image_create_info.extent.height = tex_height;
747 image_create_info.extent.depth = 1;
748 image_create_info.mipLevels = 1;
Courtney Goeltzenleuchter5d2aed42015-10-21 17:57:31 -0600749 image_create_info.arrayLayers = 1;
Chia-I Wu5c17c962015-10-31 00:31:16 +0800750 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Tony Barboureb254902015-07-15 12:50:33 -0600751 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
752 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
753 image_create_info.flags = 0;
Mark Lobodzinski944aab12015-06-05 13:59:04 -0500754
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800755 VkMemoryAllocateInfo mem_alloc = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +0800756 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
Tony Barboureb254902015-07-15 12:50:33 -0600757 mem_alloc.pNext = NULL;
758 mem_alloc.allocationSize = 0;
759 mem_alloc.memoryTypeIndex = 0;
760
761 // Introduce failure, do NOT set memProps to VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT
762 mem_alloc.memoryTypeIndex = 1;
Chia-I Wuf7458c52015-10-26 21:10:41 +0800763 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Mark Lobodzinski944aab12015-06-05 13:59:04 -0500764 ASSERT_VK_SUCCESS(err);
765
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -0600766 vkGetImageMemoryRequirements(m_device->device(),
Mark Lobodzinski944aab12015-06-05 13:59:04 -0500767 image,
Mark Lobodzinski944aab12015-06-05 13:59:04 -0500768 &mem_reqs);
Mark Lobodzinski944aab12015-06-05 13:59:04 -0500769
770 mem_alloc.allocationSize = mem_reqs.size;
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -0600771 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
772 ASSERT_TRUE(pass);
Mark Lobodzinski944aab12015-06-05 13:59:04 -0500773
774 // allocate 2 memory objects
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800775 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem1);
Mark Lobodzinski944aab12015-06-05 13:59:04 -0500776 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800777 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem2);
Mark Lobodzinski944aab12015-06-05 13:59:04 -0500778 ASSERT_VK_SUCCESS(err);
779
780 // Bind first memory object to Image object
Tony Barbour67e99152015-07-10 14:10:27 -0600781 err = vkBindImageMemory(m_device->device(), image, mem1, 0);
Mark Lobodzinski944aab12015-06-05 13:59:04 -0500782 ASSERT_VK_SUCCESS(err);
783
784 // Introduce validation failure, try to bind a different memory object to the same image object
Tony Barbour67e99152015-07-10 14:10:27 -0600785 err = vkBindImageMemory(m_device->device(), image, mem2, 0);
Mark Lobodzinski944aab12015-06-05 13:59:04 -0500786
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600787 if (!m_errorMonitor->DesiredMsgFound()) {
788 FAIL() << "Did not receive Error when rebinding memory to an object";
789 m_errorMonitor->DumpFailureMsgs();
Mark Lobodzinski944aab12015-06-05 13:59:04 -0500790 }
Mike Stroyand1c84a52015-08-18 14:40:24 -0600791
Chia-I Wuf7458c52015-10-26 21:10:41 +0800792 vkDestroyImage(m_device->device(), image, NULL);
793 vkFreeMemory(m_device->device(), mem1, NULL);
794 vkFreeMemory(m_device->device(), mem2, NULL);
Mark Lobodzinski944aab12015-06-05 13:59:04 -0500795}
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500796
Tony Barbour0b4d9562015-04-09 10:48:04 -0600797TEST_F(VkLayerTest, SubmitSignaledFence)
Tony Barbour300a6082015-04-07 13:44:53 -0600798{
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600799 vk_testing::Fence testFence;
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600800
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -0700801 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600802 "submitted in SIGNALED state. Fences must be reset before being submitted");
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600803
804 VkFenceCreateInfo fenceInfo = {};
Tony Barbour0b4d9562015-04-09 10:48:04 -0600805 fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
806 fenceInfo.pNext = NULL;
807 fenceInfo.flags = VK_FENCE_CREATE_SIGNALED_BIT;
Tony Barbour300a6082015-04-07 13:44:53 -0600808
Tony Barbour300a6082015-04-07 13:44:53 -0600809 ASSERT_NO_FATAL_FAILURE(InitState());
810 ASSERT_NO_FATAL_FAILURE(InitViewport());
811 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
812
Tony Barbourfe3351b2015-07-28 10:17:20 -0600813 BeginCommandBuffer();
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800814 m_commandBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color, m_stencil_clear_color, NULL);
Tony Barbourfe3351b2015-07-28 10:17:20 -0600815 EndCommandBuffer();
Tony Barbour300a6082015-04-07 13:44:53 -0600816
817 testFence.init(*m_device, fenceInfo);
Mark Lobodzinski5fcc4212015-09-14 17:43:42 -0600818
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -0600819 VkSubmitInfo submit_info;
Chia-I Wuf9be13c2015-10-26 20:37:06 +0800820 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
821 submit_info.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +0800822 submit_info.waitSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -0600823 submit_info.pWaitSemaphores = NULL;
Jon Ashburn7f9716c2015-12-30 16:42:50 -0700824 submit_info.pWaitDstStageMask = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +0800825 submit_info.commandBufferCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800826 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Chia-I Wud50a7d72015-10-26 20:48:51 +0800827 submit_info.signalSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -0600828 submit_info.pSignalSemaphores = NULL;
Courtney Goeltzenleuchter646b9072015-10-20 18:04:07 -0600829
830 vkQueueSubmit(m_device->m_queue, 1, &submit_info, testFence.handle());
Mark Lobodzinski5fcc4212015-09-14 17:43:42 -0600831 vkQueueWaitIdle(m_device->m_queue );
Mark Lobodzinski5fcc4212015-09-14 17:43:42 -0600832
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600833 if (!m_errorMonitor->DesiredMsgFound()) {
834 FAIL() << "Did not receive Error 'VkQueueSubmit with fence in SIGNALED_STATE'";
835 m_errorMonitor->DumpFailureMsgs();
Tony Barbour0b4d9562015-04-09 10:48:04 -0600836 }
Tony Barbour0b4d9562015-04-09 10:48:04 -0600837}
838
839TEST_F(VkLayerTest, ResetUnsignaledFence)
840{
841 vk_testing::Fence testFence;
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600842 VkFenceCreateInfo fenceInfo = {};
Tony Barbour0b4d9562015-04-09 10:48:04 -0600843 fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
844 fenceInfo.pNext = NULL;
845
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -0700846 // TODO: verify that this matches layer
847 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARN_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600848 "submitted to VkResetFences in UNSIGNALED STATE");
849
Tony Barbour0b4d9562015-04-09 10:48:04 -0600850 ASSERT_NO_FATAL_FAILURE(InitState());
851 testFence.init(*m_device, fenceInfo);
Chia-I Wud9e8e822015-07-03 11:45:55 +0800852 VkFence fences[1] = {testFence.handle()};
Tony Barbour0b4d9562015-04-09 10:48:04 -0600853 vkResetFences(m_device->device(), 1, fences);
Tony Barbour300a6082015-04-07 13:44:53 -0600854
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600855 if (!m_errorMonitor->DesiredMsgFound()) {
856 FAIL() << "Did not receive Error 'VkResetFences with fence in UNSIGNALED_STATE'";
857 m_errorMonitor->DumpFailureMsgs();
858 }
Tony Barbour300a6082015-04-07 13:44:53 -0600859}
Tobin Ehlis41376e12015-07-03 08:45:14 -0600860
Chia-I Wu08accc62015-07-07 11:50:03 +0800861/* TODO: Update for changes due to bug-14075 tiling across render passes */
862#if 0
Tobin Ehlis41376e12015-07-03 08:45:14 -0600863TEST_F(VkLayerTest, InvalidUsageBits)
864{
865 // Initiate Draw w/o a PSO bound
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600866
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -0700867 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600868 "Invalid usage flag for image ");
Tobin Ehlis41376e12015-07-03 08:45:14 -0600869
870 ASSERT_NO_FATAL_FAILURE(InitState());
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800871 VkCommandBufferObj commandBuffer(m_device);
Tony Barbourfe3351b2015-07-28 10:17:20 -0600872 BeginCommandBuffer();
Tobin Ehlis41376e12015-07-03 08:45:14 -0600873
874 const VkExtent3D e3d = {
875 .width = 128,
876 .height = 128,
877 .depth = 1,
878 };
879 const VkImageCreateInfo ici = {
880 .sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO,
881 .pNext = NULL,
882 .imageType = VK_IMAGE_TYPE_2D,
883 .format = VK_FORMAT_D32_SFLOAT_S8_UINT,
884 .extent = e3d,
885 .mipLevels = 1,
886 .arraySize = 1,
Chia-I Wu5c17c962015-10-31 00:31:16 +0800887 .samples = VK_SAMPLE_COUNT_1_BIT,
Tobin Ehlis41376e12015-07-03 08:45:14 -0600888 .tiling = VK_IMAGE_TILING_LINEAR,
Courtney Goeltzenleuchter660f0ca2015-09-10 14:14:11 -0600889 .usage = 0, // Not setting VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT
Tobin Ehlis41376e12015-07-03 08:45:14 -0600890 .flags = 0,
891 };
892
893 VkImage dsi;
Chia-I Wuf7458c52015-10-26 21:10:41 +0800894 vkCreateImage(m_device->device(), &ici, NULL, &dsi);
Tobin Ehlis41376e12015-07-03 08:45:14 -0600895 VkDepthStencilView dsv;
896 const VkDepthStencilViewCreateInfo dsvci = {
897 .sType = VK_STRUCTURE_TYPE_DEPTH_STENCIL_VIEW_CREATE_INFO,
898 .pNext = NULL,
899 .image = dsi,
900 .mipLevel = 0,
Courtney Goeltzenleuchter4a261892015-09-10 16:38:41 -0600901 .baseArrayLayer = 0,
Tobin Ehlis41376e12015-07-03 08:45:14 -0600902 .arraySize = 1,
903 .flags = 0,
904 };
Chia-I Wuf7458c52015-10-26 21:10:41 +0800905 vkCreateDepthStencilView(m_device->device(), &dsvci, NULL, &dsv);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600906
907 if (!m_errorMonitor->DesiredMsgFound()) {
Tobin Ehlis41376e12015-07-03 08:45:14 -0600908 FAIL() << "Error received was not 'Invalid usage flag for image...'";
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600909 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlis41376e12015-07-03 08:45:14 -0600910 }
911}
Mark Lobodzinski209b5292015-09-17 09:44:05 -0600912#endif // 0
913#endif // MEM_TRACKER_TESTS
914
Tobin Ehlis4bf96d12015-06-25 11:58:41 -0600915#if OBJ_TRACKER_TESTS
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -0600916TEST_F(VkLayerTest, PipelineNotBound)
917{
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -0600918 VkResult err;
919
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -0700920 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600921 "Invalid VkPipeline Object ");
922
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -0600923 ASSERT_NO_FATAL_FAILURE(InitState());
924 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -0600925
Chia-I Wu1b99bb22015-10-27 19:25:11 +0800926 VkDescriptorPoolSize ds_type_count = {};
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -0600927 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wud50a7d72015-10-26 20:48:51 +0800928 ds_type_count.descriptorCount = 1;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -0600929
930 VkDescriptorPoolCreateInfo ds_pool_ci = {};
931 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
932 ds_pool_ci.pNext = NULL;
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -0600933 ds_pool_ci.maxSets = 1;
Chia-I Wu1b99bb22015-10-27 19:25:11 +0800934 ds_pool_ci.poolSizeCount = 1;
935 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -0600936
937 VkDescriptorPool ds_pool;
Chia-I Wuf7458c52015-10-26 21:10:41 +0800938 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -0600939 ASSERT_VK_SUCCESS(err);
940
941 VkDescriptorSetLayoutBinding dsl_binding = {};
Chia-I Wud46e6ae2015-10-31 00:31:16 +0800942 dsl_binding.binding = 0;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -0600943 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wu02124482015-11-06 06:42:02 +0800944 dsl_binding.descriptorCount = 1;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -0600945 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
946 dsl_binding.pImmutableSamplers = NULL;
947
948 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
949 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
950 ds_layout_ci.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +0800951 ds_layout_ci.bindingCount = 1;
Jon Ashburn6e23c1f2015-12-30 18:01:16 -0700952 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -0600953
954 VkDescriptorSetLayout ds_layout;
Chia-I Wuf7458c52015-10-26 21:10:41 +0800955 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -0600956 ASSERT_VK_SUCCESS(err);
957
958 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800959 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +0800960 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Chia-I Wud50a7d72015-10-26 20:48:51 +0800961 alloc_info.setLayoutCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -0600962 alloc_info.descriptorPool = ds_pool;
963 alloc_info.pSetLayouts = &ds_layout;
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800964 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -0600965 ASSERT_VK_SUCCESS(err);
966
967 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
968 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
969 pipeline_layout_ci.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +0800970 pipeline_layout_ci.setLayoutCount = 1;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -0600971 pipeline_layout_ci.pSetLayouts = &ds_layout;
972
973 VkPipelineLayout pipeline_layout;
Chia-I Wuf7458c52015-10-26 21:10:41 +0800974 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -0600975 ASSERT_VK_SUCCESS(err);
976
Mark Youngad779052016-01-06 14:26:04 -0700977 VkPipeline badPipeline = (VkPipeline)((size_t)0xbaadb1be);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -0600978
979 BeginCommandBuffer();
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800980 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, badPipeline);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -0600981
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600982 if (!m_errorMonitor->DesiredMsgFound()) {
983 FAIL() << "Error received was not 'Invalid VkPipeline Object 0xbaadb1be'" << endl;
984 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlisec598302015-09-15 15:02:17 -0600985 }
Mike Stroyand1c84a52015-08-18 14:40:24 -0600986
Chia-I Wuf7458c52015-10-26 21:10:41 +0800987 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
988 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
989 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisec598302015-09-15 15:02:17 -0600990}
991
992TEST_F(VkLayerTest, BindInvalidMemory)
993{
Tobin Ehlisec598302015-09-15 15:02:17 -0600994 VkResult err;
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -0600995 bool pass;
Tobin Ehlisec598302015-09-15 15:02:17 -0600996
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -0700997 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600998 "Invalid VkDeviceMemory Object ");
999
Tobin Ehlisec598302015-09-15 15:02:17 -06001000 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisec598302015-09-15 15:02:17 -06001001
1002 // Create an image, allocate memory, free it, and then try to bind it
1003 VkImage image;
1004 VkDeviceMemory mem;
1005 VkMemoryRequirements mem_reqs;
1006
1007 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
1008 const int32_t tex_width = 32;
1009 const int32_t tex_height = 32;
1010
1011 VkImageCreateInfo image_create_info = {};
1012 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
1013 image_create_info.pNext = NULL;
1014 image_create_info.imageType = VK_IMAGE_TYPE_2D;
1015 image_create_info.format = tex_format;
1016 image_create_info.extent.width = tex_width;
1017 image_create_info.extent.height = tex_height;
1018 image_create_info.extent.depth = 1;
1019 image_create_info.mipLevels = 1;
Courtney Goeltzenleuchter5d2aed42015-10-21 17:57:31 -06001020 image_create_info.arrayLayers = 1;
Chia-I Wu5c17c962015-10-31 00:31:16 +08001021 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Tobin Ehlisec598302015-09-15 15:02:17 -06001022 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
1023 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
1024 image_create_info.flags = 0;
1025
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001026 VkMemoryAllocateInfo mem_alloc = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08001027 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
Tobin Ehlisec598302015-09-15 15:02:17 -06001028 mem_alloc.pNext = NULL;
1029 mem_alloc.allocationSize = 0;
1030 mem_alloc.memoryTypeIndex = 0;
1031
Chia-I Wuf7458c52015-10-26 21:10:41 +08001032 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Tobin Ehlisec598302015-09-15 15:02:17 -06001033 ASSERT_VK_SUCCESS(err);
1034
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -06001035 vkGetImageMemoryRequirements(m_device->device(),
Tobin Ehlisec598302015-09-15 15:02:17 -06001036 image,
1037 &mem_reqs);
Tobin Ehlisec598302015-09-15 15:02:17 -06001038
1039 mem_alloc.allocationSize = mem_reqs.size;
1040
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -06001041 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
1042 ASSERT_TRUE(pass);
Tobin Ehlisec598302015-09-15 15:02:17 -06001043
1044 // allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001045 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
Tobin Ehlisec598302015-09-15 15:02:17 -06001046 ASSERT_VK_SUCCESS(err);
1047
1048 // Introduce validation failure, free memory before binding
Chia-I Wuf7458c52015-10-26 21:10:41 +08001049 vkFreeMemory(m_device->device(), mem, NULL);
Tobin Ehlisec598302015-09-15 15:02:17 -06001050
1051 // Try to bind free memory that has been freed
1052 err = vkBindImageMemory(m_device->device(), image, mem, 0);
1053 // This may very well return an error.
1054 (void)err;
1055
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06001056 if (!m_errorMonitor->DesiredMsgFound()) {
1057 FAIL() << "Did not receive Error 'Invalid VkDeviceMemory Object 0x<handle>'";
1058 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlisec598302015-09-15 15:02:17 -06001059 }
Mike Stroyand1c84a52015-08-18 14:40:24 -06001060
Chia-I Wuf7458c52015-10-26 21:10:41 +08001061 vkDestroyImage(m_device->device(), image, NULL);
Tobin Ehlisec598302015-09-15 15:02:17 -06001062}
1063
1064TEST_F(VkLayerTest, BindMemoryToDestroyedObject)
1065{
Tobin Ehlisec598302015-09-15 15:02:17 -06001066 VkResult err;
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -06001067 bool pass;
Tobin Ehlisec598302015-09-15 15:02:17 -06001068
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07001069 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid VkImage Object ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06001070
Tobin Ehlisec598302015-09-15 15:02:17 -06001071 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisec598302015-09-15 15:02:17 -06001072
1073 // Create an image object, allocate memory, destroy the object and then try to bind it
1074 VkImage image;
1075 VkDeviceMemory mem;
1076 VkMemoryRequirements mem_reqs;
1077
1078 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
1079 const int32_t tex_width = 32;
1080 const int32_t tex_height = 32;
1081
1082 VkImageCreateInfo image_create_info = {};
1083 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
1084 image_create_info.pNext = NULL;
1085 image_create_info.imageType = VK_IMAGE_TYPE_2D;
1086 image_create_info.format = tex_format;
1087 image_create_info.extent.width = tex_width;
1088 image_create_info.extent.height = tex_height;
1089 image_create_info.extent.depth = 1;
1090 image_create_info.mipLevels = 1;
Courtney Goeltzenleuchter5d2aed42015-10-21 17:57:31 -06001091 image_create_info.arrayLayers = 1;
Chia-I Wu5c17c962015-10-31 00:31:16 +08001092 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Tobin Ehlisec598302015-09-15 15:02:17 -06001093 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
1094 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
1095 image_create_info.flags = 0;
1096
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001097 VkMemoryAllocateInfo mem_alloc = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08001098 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
Tobin Ehlisec598302015-09-15 15:02:17 -06001099 mem_alloc.pNext = NULL;
1100 mem_alloc.allocationSize = 0;
1101 mem_alloc.memoryTypeIndex = 0;
1102
Chia-I Wuf7458c52015-10-26 21:10:41 +08001103 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Tobin Ehlisec598302015-09-15 15:02:17 -06001104 ASSERT_VK_SUCCESS(err);
1105
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -06001106 vkGetImageMemoryRequirements(m_device->device(),
Tobin Ehlisec598302015-09-15 15:02:17 -06001107 image,
1108 &mem_reqs);
Tobin Ehlisec598302015-09-15 15:02:17 -06001109
1110 mem_alloc.allocationSize = mem_reqs.size;
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -06001111 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
1112 ASSERT_TRUE(pass);
Tobin Ehlisec598302015-09-15 15:02:17 -06001113
1114 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001115 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
Tobin Ehlisec598302015-09-15 15:02:17 -06001116 ASSERT_VK_SUCCESS(err);
1117
1118 // Introduce validation failure, destroy Image object before binding
Chia-I Wuf7458c52015-10-26 21:10:41 +08001119 vkDestroyImage(m_device->device(), image, NULL);
Tobin Ehlisec598302015-09-15 15:02:17 -06001120 ASSERT_VK_SUCCESS(err);
1121
1122 // Now Try to bind memory to this destroyed object
1123 err = vkBindImageMemory(m_device->device(), image, mem, 0);
1124 // This may very well return an error.
1125 (void) err;
1126
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06001127 if (!m_errorMonitor->DesiredMsgFound()) {
1128 FAIL() << "Did not receive Error 'Invalid VkImage Object 0x<handle>'";
1129 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06001130 }
Mike Stroyand1c84a52015-08-18 14:40:24 -06001131
Chia-I Wuf7458c52015-10-26 21:10:41 +08001132 vkFreeMemory(m_device->device(), mem, NULL);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06001133}
Tobin Ehlisa1c28562015-10-23 16:00:08 -06001134
Mark Lobodzinski209b5292015-09-17 09:44:05 -06001135#endif // OBJ_TRACKER_TESTS
1136
Tobin Ehlis0788f522015-05-26 16:11:58 -06001137#if DRAW_STATE_TESTS
Tobin Ehlis963a4042015-09-29 08:18:34 -06001138TEST_F(VkLayerTest, LineWidthStateNotBound)
1139{
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07001140 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06001141 "Dynamic line width state not set for this command buffer");
1142
Tobin Ehlis963a4042015-09-29 08:18:34 -06001143 TEST_DESCRIPTION("Simple Draw Call that validates failure when a line width state object is not bound beforehand");
1144
1145 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailLineWidth);
1146
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06001147 if (!m_errorMonitor->DesiredMsgFound()) {
1148 FAIL() << "Did not receive Error 'Dynamic line width state not set for this command buffer'";
1149 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlis963a4042015-09-29 08:18:34 -06001150 }
1151}
1152
1153TEST_F(VkLayerTest, DepthBiasStateNotBound)
1154{
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07001155 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06001156 "Dynamic depth bias state not set for this command buffer");
1157
Tobin Ehlis963a4042015-09-29 08:18:34 -06001158 TEST_DESCRIPTION("Simple Draw Call that validates failure when a depth bias state object is not bound beforehand");
1159
1160 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailDepthBias);
1161
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06001162 if (!m_errorMonitor->DesiredMsgFound()) {
1163 FAIL() << "Did not receive Error 'Dynamic depth bias state not set for this command buffer'";
1164 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlis963a4042015-09-29 08:18:34 -06001165 }
1166}
1167
Cody Northrop4063c9a2015-10-27 16:54:28 -06001168// Disable these two tests until we can sort out how to track multiple layer errors
Tobin Ehlis963a4042015-09-29 08:18:34 -06001169TEST_F(VkLayerTest, ViewportStateNotBound)
1170{
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07001171 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06001172 "Dynamic viewport state not set for this command buffer");
1173
Tobin Ehlis963a4042015-09-29 08:18:34 -06001174 TEST_DESCRIPTION("Simple Draw Call that validates failure when a viewport state object is not bound beforehand");
1175
1176 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailViewport);
1177
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06001178 if (!m_errorMonitor->DesiredMsgFound()) {
1179 FAIL() << "Did not recieve Error 'Dynamic scissor state not set for this command buffer'";
1180 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlis963a4042015-09-29 08:18:34 -06001181 }
1182}
1183
1184TEST_F(VkLayerTest, ScissorStateNotBound)
1185{
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07001186 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06001187 "Dynamic scissor state not set for this command buffer");
1188
Tobin Ehlis963a4042015-09-29 08:18:34 -06001189 TEST_DESCRIPTION("Simple Draw Call that validates failure when a viewport state object is not bound beforehand");
1190
1191 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailScissor);
1192
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06001193 if (!m_errorMonitor->DesiredMsgFound()) {
1194 FAIL() << "Did not recieve Error ' Expected: 'Dynamic scissor state not set for this command buffer'";
1195 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlis963a4042015-09-29 08:18:34 -06001196 }
1197}
1198
Tobin Ehlis963a4042015-09-29 08:18:34 -06001199TEST_F(VkLayerTest, BlendStateNotBound)
1200{
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07001201 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06001202 "Dynamic blend object state not set for this command buffer");
1203
Tobin Ehlis963a4042015-09-29 08:18:34 -06001204 TEST_DESCRIPTION("Simple Draw Call that validates failure when a blend state object is not bound beforehand");
1205
1206 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailBlend);
1207
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06001208 if (!m_errorMonitor->DesiredMsgFound()) {
1209 FAIL() << "Did not recieve Error 'Dynamic blend object state not set for this command buffer'";
1210 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlis963a4042015-09-29 08:18:34 -06001211 }
1212}
1213
1214TEST_F(VkLayerTest, DepthBoundsStateNotBound)
1215{
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07001216 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06001217 "Dynamic depth bounds state not set for this command buffer");
1218
Tobin Ehlis963a4042015-09-29 08:18:34 -06001219 TEST_DESCRIPTION("Simple Draw Call that validates failure when a depth bounds state object is not bound beforehand");
1220
1221 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailDepthBounds);
1222
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06001223 if (!m_errorMonitor->DesiredMsgFound()) {
1224 FAIL() << "Did not receive Error 'Dynamic depth bounds state not set for this command buffer'";
1225 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlis963a4042015-09-29 08:18:34 -06001226 }
1227}
1228
1229TEST_F(VkLayerTest, StencilReadMaskNotSet)
1230{
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07001231 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06001232 "Dynamic stencil read mask state not set for this command buffer");
1233
Tobin Ehlis963a4042015-09-29 08:18:34 -06001234 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06001235
Tobin Ehlis963a4042015-09-29 08:18:34 -06001236 TEST_DESCRIPTION("Simple Draw Call that validates failure when a stencil read mask is not set beforehand");
1237
1238 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailStencilReadMask);
1239
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06001240 if (!m_errorMonitor->DesiredMsgFound()) {
1241 FAIL() << "Did not receive Error 'Dynamic stencil read mask state not set for this command buffer'";
1242 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlis963a4042015-09-29 08:18:34 -06001243 }
1244}
1245
1246TEST_F(VkLayerTest, StencilWriteMaskNotSet)
1247{
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07001248 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06001249 "Dynamic stencil write mask state not set for this command buffer");
1250
Tobin Ehlis963a4042015-09-29 08:18:34 -06001251 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06001252
Tobin Ehlis963a4042015-09-29 08:18:34 -06001253 TEST_DESCRIPTION("Simple Draw Call that validates failure when a stencil write mask is not set beforehand");
1254
1255 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailStencilWriteMask);
1256
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06001257 if (!m_errorMonitor->DesiredMsgFound()) {
1258 FAIL() << "Did not receive Error 'Dynamic stencil write mask state not set for this command buffer'";
1259 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlis963a4042015-09-29 08:18:34 -06001260 }
1261}
1262
1263TEST_F(VkLayerTest, StencilReferenceNotSet)
1264{
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07001265 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06001266 "Dynamic stencil reference state not set for this command buffer");
1267
Tobin Ehlis963a4042015-09-29 08:18:34 -06001268 TEST_DESCRIPTION("Simple Draw Call that validates failure when a stencil reference is not set beforehand");
1269
1270 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailStencilReference);
1271
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06001272 if (!m_errorMonitor->DesiredMsgFound()) {
1273 FAIL() << "Did not receive Error 'Dynamic stencil reference state not set for this command buffer'";
1274 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlis963a4042015-09-29 08:18:34 -06001275 }
1276}
1277
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001278TEST_F(VkLayerTest, CommandBufferTwoSubmits)
Tobin Ehlis59278bf2015-08-18 07:10:58 -06001279{
1280 vk_testing::Fence testFence;
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06001281
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07001282 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06001283 "was begun w/ VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT set, but has been submitted");
Tobin Ehlis59278bf2015-08-18 07:10:58 -06001284
1285 VkFenceCreateInfo fenceInfo = {};
1286 fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
1287 fenceInfo.pNext = NULL;
1288 fenceInfo.flags = 0;
1289
1290 ASSERT_NO_FATAL_FAILURE(InitState());
1291 ASSERT_NO_FATAL_FAILURE(InitViewport());
1292 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
1293
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001294 // We luck out b/c by default the framework creates CB w/ the VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT set
Tobin Ehlis59278bf2015-08-18 07:10:58 -06001295 BeginCommandBuffer();
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001296 m_commandBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color, m_stencil_clear_color, NULL);
Tobin Ehlis59278bf2015-08-18 07:10:58 -06001297 EndCommandBuffer();
1298
1299 testFence.init(*m_device, fenceInfo);
1300
1301 // Bypass framework since it does the waits automatically
1302 VkResult err = VK_SUCCESS;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06001303 VkSubmitInfo submit_info;
Chia-I Wuf9be13c2015-10-26 20:37:06 +08001304 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
1305 submit_info.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08001306 submit_info.waitSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06001307 submit_info.pWaitSemaphores = NULL;
Jon Ashburn7f9716c2015-12-30 16:42:50 -07001308 submit_info.pWaitDstStageMask = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08001309 submit_info.commandBufferCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001310 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Chia-I Wud50a7d72015-10-26 20:48:51 +08001311 submit_info.signalSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06001312 submit_info.pSignalSemaphores = NULL;
1313
Courtney Goeltzenleuchter646b9072015-10-20 18:04:07 -06001314 err = vkQueueSubmit( m_device->m_queue, 1, &submit_info, testFence.handle());
Tobin Ehlis59278bf2015-08-18 07:10:58 -06001315 ASSERT_VK_SUCCESS( err );
1316
Tobin Ehlis59278bf2015-08-18 07:10:58 -06001317 // Cause validation error by re-submitting cmd buffer that should only be submitted once
Courtney Goeltzenleuchter646b9072015-10-20 18:04:07 -06001318 err = vkQueueSubmit( m_device->m_queue, 1, &submit_info, testFence.handle());
Tobin Ehlis59278bf2015-08-18 07:10:58 -06001319
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06001320 if (!m_errorMonitor->DesiredMsgFound()) {
1321 FAIL() << "Did not receive Error 'CB (0xaddress) was created w/ VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT set...'";
1322 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlis59278bf2015-08-18 07:10:58 -06001323 }
1324}
1325
Mark Lobodzinski74635932015-12-18 15:35:38 -07001326TEST_F(VkLayerTest, BindPipelineNoRenderPass)
1327{
1328 // Initiate Draw w/o a PSO bound
1329 VkResult err;
1330
1331 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
1332 "vkCmdBindPipeline: This call must be issued inside an active render pass");
1333
1334 ASSERT_NO_FATAL_FAILURE(InitState());
1335 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
1336
1337 VkDescriptorPoolSize ds_type_count = {};
1338 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
1339 ds_type_count.descriptorCount = 1;
1340
1341 VkDescriptorPoolCreateInfo ds_pool_ci = {};
1342 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
1343 ds_pool_ci.pNext = NULL;
1344 ds_pool_ci.maxSets = 1;
1345 ds_pool_ci.poolSizeCount = 1;
1346 ds_pool_ci.pPoolSizes = &ds_type_count;
1347
1348 VkDescriptorPool ds_pool;
1349 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
1350 ASSERT_VK_SUCCESS(err);
1351
1352 VkDescriptorSetLayoutBinding dsl_binding = {};
1353 dsl_binding.binding = 0;
1354 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
1355 dsl_binding.descriptorCount = 1;
1356 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
1357 dsl_binding.pImmutableSamplers = NULL;
1358
1359 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
1360 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
1361 ds_layout_ci.pNext = NULL;
1362 ds_layout_ci.bindingCount = 1;
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07001363 ds_layout_ci.pBindings = &dsl_binding;
Mark Lobodzinski74635932015-12-18 15:35:38 -07001364
1365 VkDescriptorSetLayout ds_layout;
1366 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
1367 ASSERT_VK_SUCCESS(err);
1368
1369 VkDescriptorSet descriptorSet;
1370 VkDescriptorSetAllocateInfo alloc_info = {};
1371 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
1372 alloc_info.setLayoutCount = 1;
1373 alloc_info.descriptorPool = ds_pool;
1374 alloc_info.pSetLayouts = &ds_layout;
1375 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
1376 ASSERT_VK_SUCCESS(err);
1377 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
1378 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
1379 pipe_ms_state_ci.pNext = NULL;
1380 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
1381 pipe_ms_state_ci.sampleShadingEnable = 0;
1382 pipe_ms_state_ci.minSampleShading = 1.0;
1383 pipe_ms_state_ci.pSampleMask = NULL;
1384
1385 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
1386 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
1387 pipeline_layout_ci.pNext = NULL;
1388 pipeline_layout_ci.setLayoutCount = 1;
1389 pipeline_layout_ci.pSetLayouts = &ds_layout;
1390 VkPipelineLayout pipeline_layout;
1391
1392 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
1393 ASSERT_VK_SUCCESS(err);
1394
1395 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
1396 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this); // TODO - We shouldn't need a fragment shader
1397 // but add it to be able to run on more devices
1398 VkPipelineObj pipe(m_device);
1399 pipe.AddShader(&vs);
1400 pipe.AddShader(&fs);
1401 pipe.SetMSAA(&pipe_ms_state_ci);
1402 pipe.CreateVKPipeline(pipeline_layout, renderPass());
1403
1404 // Calls AllocateCommandBuffers
1405 VkCommandBufferObj commandBuffer(m_device, m_commandPool);
1406 VkCommandBufferBeginInfo cmd_buf_info = {};
1407 memset(&cmd_buf_info, 0, sizeof(VkCommandBufferBeginInfo));
1408 cmd_buf_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
1409 cmd_buf_info.pNext = NULL;
1410 cmd_buf_info.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT;
1411
1412 vkBeginCommandBuffer(commandBuffer.GetBufferHandle(), &cmd_buf_info);
1413 vkCmdBindPipeline(commandBuffer.GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
1414
1415 if (!m_errorMonitor->DesiredMsgFound()) {
1416 FAIL() << "Did not receive Error 'vkCmdBindPipeline: This call must be issued inside an active render pass'";
1417 m_errorMonitor->DumpFailureMsgs();
1418 }
1419
1420 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
1421 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
1422 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
1423}
1424
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06001425TEST_F(VkLayerTest, AllocDescriptorFromEmptyPool)
1426{
1427 // Initiate Draw w/o a PSO bound
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06001428 VkResult err;
1429
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07001430 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06001431 "Unable to allocate 1 descriptors of type VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER ");
1432
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06001433 ASSERT_NO_FATAL_FAILURE(InitState());
1434 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06001435
1436 // Create Pool w/ 1 Sampler descriptor, but try to alloc Uniform Buffer descriptor from it
Chia-I Wu1b99bb22015-10-27 19:25:11 +08001437 VkDescriptorPoolSize ds_type_count = {};
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06001438 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLER;
Chia-I Wud50a7d72015-10-26 20:48:51 +08001439 ds_type_count.descriptorCount = 1;
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06001440
1441 VkDescriptorPoolCreateInfo ds_pool_ci = {};
1442 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
1443 ds_pool_ci.pNext = NULL;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06001444 ds_pool_ci.flags = 0;
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06001445 ds_pool_ci.maxSets = 1;
Chia-I Wu1b99bb22015-10-27 19:25:11 +08001446 ds_pool_ci.poolSizeCount = 1;
1447 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06001448
1449 VkDescriptorPool ds_pool;
Chia-I Wuf7458c52015-10-26 21:10:41 +08001450 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06001451 ASSERT_VK_SUCCESS(err);
1452
1453 VkDescriptorSetLayoutBinding dsl_binding = {};
Chia-I Wud46e6ae2015-10-31 00:31:16 +08001454 dsl_binding.binding = 0;
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06001455 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wu02124482015-11-06 06:42:02 +08001456 dsl_binding.descriptorCount = 1;
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06001457 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
1458 dsl_binding.pImmutableSamplers = NULL;
1459
1460 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
1461 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
1462 ds_layout_ci.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08001463 ds_layout_ci.bindingCount = 1;
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07001464 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06001465
1466 VkDescriptorSetLayout ds_layout;
Chia-I Wuf7458c52015-10-26 21:10:41 +08001467 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06001468 ASSERT_VK_SUCCESS(err);
1469
1470 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001471 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08001472 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Chia-I Wud50a7d72015-10-26 20:48:51 +08001473 alloc_info.setLayoutCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06001474 alloc_info.descriptorPool = ds_pool;
1475 alloc_info.pSetLayouts = &ds_layout;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001476 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06001477
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06001478 if (!m_errorMonitor->DesiredMsgFound()) {
1479 FAIL() << "Did not receive Error 'Unable to allocate 1 descriptors of type VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER...'";
1480 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06001481 }
1482
Chia-I Wuf7458c52015-10-26 21:10:41 +08001483 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
1484 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06001485}
1486
Tobin Ehlise735c692015-10-08 13:13:50 -06001487TEST_F(VkLayerTest, FreeDescriptorFromOneShotPool)
1488{
Tobin Ehlise735c692015-10-08 13:13:50 -06001489 VkResult err;
1490
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07001491 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06001492 "It is invalid to call vkFreeDescriptorSets() with a pool created without setting VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT.");
1493
Tobin Ehlise735c692015-10-08 13:13:50 -06001494 ASSERT_NO_FATAL_FAILURE(InitState());
1495 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlise735c692015-10-08 13:13:50 -06001496
Chia-I Wu1b99bb22015-10-27 19:25:11 +08001497 VkDescriptorPoolSize ds_type_count = {};
Tobin Ehlise735c692015-10-08 13:13:50 -06001498 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wud50a7d72015-10-26 20:48:51 +08001499 ds_type_count.descriptorCount = 1;
Tobin Ehlise735c692015-10-08 13:13:50 -06001500
1501 VkDescriptorPoolCreateInfo ds_pool_ci = {};
1502 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
1503 ds_pool_ci.pNext = NULL;
Tobin Ehlise735c692015-10-08 13:13:50 -06001504 ds_pool_ci.maxSets = 1;
Chia-I Wu1b99bb22015-10-27 19:25:11 +08001505 ds_pool_ci.poolSizeCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06001506 ds_pool_ci.flags = 0;
1507 // Not specifying VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT means
1508 // app can only call vkResetDescriptorPool on this pool.;
Chia-I Wu1b99bb22015-10-27 19:25:11 +08001509 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlise735c692015-10-08 13:13:50 -06001510
1511 VkDescriptorPool ds_pool;
Chia-I Wuf7458c52015-10-26 21:10:41 +08001512 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlise735c692015-10-08 13:13:50 -06001513 ASSERT_VK_SUCCESS(err);
1514
1515 VkDescriptorSetLayoutBinding dsl_binding = {};
Chia-I Wud46e6ae2015-10-31 00:31:16 +08001516 dsl_binding.binding = 0;
Tobin Ehlise735c692015-10-08 13:13:50 -06001517 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wu02124482015-11-06 06:42:02 +08001518 dsl_binding.descriptorCount = 1;
Tobin Ehlise735c692015-10-08 13:13:50 -06001519 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
1520 dsl_binding.pImmutableSamplers = NULL;
1521
1522 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
1523 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
1524 ds_layout_ci.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08001525 ds_layout_ci.bindingCount = 1;
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07001526 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlise735c692015-10-08 13:13:50 -06001527
1528 VkDescriptorSetLayout ds_layout;
Chia-I Wuf7458c52015-10-26 21:10:41 +08001529 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlise735c692015-10-08 13:13:50 -06001530 ASSERT_VK_SUCCESS(err);
1531
1532 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001533 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08001534 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Chia-I Wud50a7d72015-10-26 20:48:51 +08001535 alloc_info.setLayoutCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06001536 alloc_info.descriptorPool = ds_pool;
1537 alloc_info.pSetLayouts = &ds_layout;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001538 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlise735c692015-10-08 13:13:50 -06001539 ASSERT_VK_SUCCESS(err);
1540
1541 err = vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptorSet);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06001542 if (!m_errorMonitor->DesiredMsgFound()) {
1543 FAIL() << "Did not receive Error 'It is invalid to call vkFreeDescriptorSets() with a pool created with...'";
1544 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlise735c692015-10-08 13:13:50 -06001545 }
1546
Chia-I Wuf7458c52015-10-26 21:10:41 +08001547 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
1548 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlise735c692015-10-08 13:13:50 -06001549}
1550
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06001551TEST_F(VkLayerTest, InvalidDescriptorPool)
1552{
1553 // TODO : Simple check for bad object should be added to ObjectTracker to catch this case
1554 // The DS check for this is after driver has been called to validate DS internal data struct
1555 // Attempt to clear DS Pool with bad object
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06001556/*
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07001557 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06001558 "Unable to find pool node for pool 0xbaad6001 specified in vkResetDescriptorPool() call");
1559
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06001560 VkDescriptorPool badPool = (VkDescriptorPool)0xbaad6001;
1561 vkResetDescriptorPool(device(), badPool);
1562
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06001563 if (!m_errorMonitor->DesiredMsgFound()) {
1564 FAIL() << "Did not receive Error 'Unable to find pool node for pool 0xbaad6001 specified in vkResetDescriptorPool() call'";
1565 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06001566 }*/
1567}
1568
1569TEST_F(VkLayerTest, InvalidDescriptorSet)
1570{
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06001571 // TODO : Simple check for bad object should be added to ObjectTracker to catch this case
1572 // The DS check for this is after driver has been called to validate DS internal data struct
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06001573 // Create a valid cmd buffer
1574 // call vkCmdBindDescriptorSets w/ false DS
1575}
1576
1577TEST_F(VkLayerTest, InvalidDescriptorSetLayout)
1578{
1579 // TODO : Simple check for bad object should be added to ObjectTracker to catch this case
1580 // The DS check for this is after driver has been called to validate DS internal data struct
1581}
1582
1583TEST_F(VkLayerTest, InvalidPipeline)
1584{
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06001585 // TODO : Simple check for bad object should be added to ObjectTracker to catch this case
1586 // The DS check for this is after driver has been called to validate DS internal data struct
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06001587 // Create a valid cmd buffer
1588 // call vkCmdBindPipeline w/ false Pipeline
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06001589//
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07001590// m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06001591// "Attempt to bind Pipeline ");
Tobin Ehlis502480b2015-06-24 15:53:07 -06001592//
1593// ASSERT_NO_FATAL_FAILURE(InitState());
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001594// VkCommandBufferObj commandBuffer(m_device);
Tony Barbourfe3351b2015-07-28 10:17:20 -06001595// BeginCommandBuffer();
Tobin Ehlis502480b2015-06-24 15:53:07 -06001596// VkPipeline badPipeline = (VkPipeline)0xbaadb1be;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001597// vkCmdBindPipeline(commandBuffer.GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, badPipeline);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06001598//
1599// if (!m_errorMonitor->DesiredMsgFound()) {
1600// FAIL() << "Did not receive Error 'Attempt to bind Pipeline 0xbaadb1be that doesn't exist!'";
1601// m_errorMonitor->DumpFailureMsgs();
Tobin Ehlis502480b2015-06-24 15:53:07 -06001602// }
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06001603}
1604
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06001605TEST_F(VkLayerTest, DescriptorSetNotUpdated)
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06001606{
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001607 // Create and update CommandBuffer then call QueueSubmit w/o calling End on CommandBuffer
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06001608 VkResult err;
1609
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07001610 // TODO: verify that this matches layer
1611 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARN_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06001612 " bound but it was never updated. ");
1613
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06001614 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyan713b2d72015-08-04 10:49:29 -06001615 ASSERT_NO_FATAL_FAILURE(InitViewport());
1616 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chia-I Wu1b99bb22015-10-27 19:25:11 +08001617 VkDescriptorPoolSize ds_type_count = {};
Tony Barboureb254902015-07-15 12:50:33 -06001618 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wud50a7d72015-10-26 20:48:51 +08001619 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06001620
1621 VkDescriptorPoolCreateInfo ds_pool_ci = {};
1622 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
1623 ds_pool_ci.pNext = NULL;
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -06001624 ds_pool_ci.maxSets = 1;
Chia-I Wu1b99bb22015-10-27 19:25:11 +08001625 ds_pool_ci.poolSizeCount = 1;
1626 ds_pool_ci.pPoolSizes = &ds_type_count;
Mike Stroyan713b2d72015-08-04 10:49:29 -06001627
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06001628 VkDescriptorPool ds_pool;
Chia-I Wuf7458c52015-10-26 21:10:41 +08001629 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06001630 ASSERT_VK_SUCCESS(err);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06001631
Tony Barboureb254902015-07-15 12:50:33 -06001632 VkDescriptorSetLayoutBinding dsl_binding = {};
Chia-I Wud46e6ae2015-10-31 00:31:16 +08001633 dsl_binding.binding = 0;
Tony Barboureb254902015-07-15 12:50:33 -06001634 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wu02124482015-11-06 06:42:02 +08001635 dsl_binding.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06001636 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
1637 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06001638
Tony Barboureb254902015-07-15 12:50:33 -06001639 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
1640 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
1641 ds_layout_ci.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08001642 ds_layout_ci.bindingCount = 1;
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07001643 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06001644 VkDescriptorSetLayout ds_layout;
Chia-I Wuf7458c52015-10-26 21:10:41 +08001645 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06001646 ASSERT_VK_SUCCESS(err);
1647
1648 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001649 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08001650 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Chia-I Wud50a7d72015-10-26 20:48:51 +08001651 alloc_info.setLayoutCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06001652 alloc_info.descriptorPool = ds_pool;
1653 alloc_info.pSetLayouts = &ds_layout;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001654 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06001655 ASSERT_VK_SUCCESS(err);
1656
Tony Barboureb254902015-07-15 12:50:33 -06001657 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
1658 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
1659 pipeline_layout_ci.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08001660 pipeline_layout_ci.setLayoutCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06001661 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06001662
1663 VkPipelineLayout pipeline_layout;
Chia-I Wuf7458c52015-10-26 21:10:41 +08001664 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06001665 ASSERT_VK_SUCCESS(err);
1666
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06001667 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06001668 // TODO - We shouldn't need a fragment shader but add it to be able to run on more devices
1669 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06001670
Tony Barbourc95e4ac2015-08-04 17:05:26 -06001671 VkPipelineObj pipe(m_device);
1672 pipe.AddShader(&vs);
Tony Barbour1c94d372015-08-06 11:21:08 -06001673 pipe.AddShader(&fs);
Tony Barbourc95e4ac2015-08-04 17:05:26 -06001674 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tony Barbourfe3351b2015-07-28 10:17:20 -06001675
1676 BeginCommandBuffer();
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001677 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
1678 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1, &descriptorSet, 0, NULL);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06001679
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06001680 if (!m_errorMonitor->DesiredMsgFound()) {
1681 FAIL() << "Did not recieve Warning 'DS <blah> bound but it was never updated. You may want to either update it or not bind it.'";
1682 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06001683 }
Mike Stroyand1c84a52015-08-18 14:40:24 -06001684
Chia-I Wuf7458c52015-10-26 21:10:41 +08001685 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
1686 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
1687 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06001688}
1689
Tobin Ehlisba31cab2015-11-02 15:24:32 -07001690TEST_F(VkLayerTest, InvalidBufferViewObject)
1691{
1692 // Create a single TEXEL_BUFFER descriptor and send it an invalid bufferView
1693 VkResult err;
1694
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07001695 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlisba31cab2015-11-02 15:24:32 -07001696 "Attempt to update descriptor with invalid bufferView ");
1697
1698 ASSERT_NO_FATAL_FAILURE(InitState());
1699 VkDescriptorPoolSize ds_type_count = {};
1700 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER;
1701 ds_type_count.descriptorCount = 1;
1702
1703 VkDescriptorPoolCreateInfo ds_pool_ci = {};
1704 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
1705 ds_pool_ci.pNext = NULL;
1706 ds_pool_ci.maxSets = 1;
1707 ds_pool_ci.poolSizeCount = 1;
1708 ds_pool_ci.pPoolSizes = &ds_type_count;
1709
1710 VkDescriptorPool ds_pool;
1711 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
1712 ASSERT_VK_SUCCESS(err);
1713
1714 VkDescriptorSetLayoutBinding dsl_binding = {};
1715 dsl_binding.binding = 0;
1716 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER;
Chia-I Wu02124482015-11-06 06:42:02 +08001717 dsl_binding.descriptorCount = 1;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07001718 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
1719 dsl_binding.pImmutableSamplers = NULL;
1720
1721 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
1722 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
1723 ds_layout_ci.pNext = NULL;
1724 ds_layout_ci.bindingCount = 1;
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07001725 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07001726 VkDescriptorSetLayout ds_layout;
1727 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
1728 ASSERT_VK_SUCCESS(err);
1729
1730 VkDescriptorSet descriptorSet;
1731 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08001732 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07001733 alloc_info.setLayoutCount = 1;
1734 alloc_info.descriptorPool = ds_pool;
1735 alloc_info.pSetLayouts = &ds_layout;
1736 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
1737 ASSERT_VK_SUCCESS(err);
1738
Mark Youngad779052016-01-06 14:26:04 -07001739 VkBufferView view = (VkBufferView)((size_t)0xbaadbeef); // invalid bufferView object
Tobin Ehlisba31cab2015-11-02 15:24:32 -07001740 VkWriteDescriptorSet descriptor_write;
1741 memset(&descriptor_write, 0, sizeof(descriptor_write));
1742 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
1743 descriptor_write.dstSet = descriptorSet;
1744 descriptor_write.dstBinding = 0;
1745 descriptor_write.descriptorCount = 1;
1746 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER;
1747 descriptor_write.pTexelBufferView = &view;
1748
1749 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
1750
1751 if (!m_errorMonitor->DesiredMsgFound()) {
Tobin Ehlis9d80c2d2015-11-05 10:27:49 -07001752 FAIL() << "Did not receive Error 'Attempt to update descriptor with invalid bufferView'";
Tobin Ehlisba31cab2015-11-02 15:24:32 -07001753 m_errorMonitor->DumpFailureMsgs();
1754 }
1755
1756 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
1757 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
1758}
1759
Tobin Ehlisf6585052015-12-17 11:48:42 -07001760TEST_F(VkLayerTest, InvalidDynamicOffsetCases)
Tobin Ehlis49f903e2015-11-04 13:30:34 -07001761{
Tobin Ehlisf6585052015-12-17 11:48:42 -07001762 // Create a descriptorSet w/ dynamic descriptor and then hit 3 offset error cases:
1763 // 1. No dynamicOffset supplied
1764 // 2. Too many dynamicOffsets supplied
1765 // 3. Dynamic offset oversteps buffer being updated
Tobin Ehlis49f903e2015-11-04 13:30:34 -07001766 VkResult err;
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07001767 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlisf6585052015-12-17 11:48:42 -07001768 " requires 1 dynamicOffsets, but only 0 dynamicOffsets are left in pDynamicOffsets ");
Tobin Ehlis49f903e2015-11-04 13:30:34 -07001769
1770 ASSERT_NO_FATAL_FAILURE(InitState());
1771 ASSERT_NO_FATAL_FAILURE(InitViewport());
1772 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
1773
1774 VkDescriptorPoolSize ds_type_count = {};
1775 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
1776 ds_type_count.descriptorCount = 1;
1777
1778 VkDescriptorPoolCreateInfo ds_pool_ci = {};
1779 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
1780 ds_pool_ci.pNext = NULL;
1781 ds_pool_ci.maxSets = 1;
1782 ds_pool_ci.poolSizeCount = 1;
1783 ds_pool_ci.pPoolSizes = &ds_type_count;
1784
1785 VkDescriptorPool ds_pool;
1786 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
1787 ASSERT_VK_SUCCESS(err);
1788
1789 VkDescriptorSetLayoutBinding dsl_binding = {};
1790 dsl_binding.binding = 0;
1791 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
Jon Ashburn4f232582015-11-06 15:31:44 -07001792 dsl_binding.descriptorCount = 1;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07001793 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
1794 dsl_binding.pImmutableSamplers = NULL;
1795
1796 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
1797 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
1798 ds_layout_ci.pNext = NULL;
1799 ds_layout_ci.bindingCount = 1;
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07001800 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07001801 VkDescriptorSetLayout ds_layout;
1802 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
1803 ASSERT_VK_SUCCESS(err);
1804
1805 VkDescriptorSet descriptorSet;
1806 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08001807 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07001808 alloc_info.setLayoutCount = 1;
1809 alloc_info.descriptorPool = ds_pool;
1810 alloc_info.pSetLayouts = &ds_layout;
1811 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
1812 ASSERT_VK_SUCCESS(err);
1813
1814 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
1815 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
1816 pipeline_layout_ci.pNext = NULL;
1817 pipeline_layout_ci.setLayoutCount = 1;
1818 pipeline_layout_ci.pSetLayouts = &ds_layout;
1819
1820 VkPipelineLayout pipeline_layout;
1821 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
1822 ASSERT_VK_SUCCESS(err);
1823
1824 // Create a buffer to update the descriptor with
1825 uint32_t qfi = 0;
1826 VkBufferCreateInfo buffCI = {};
1827 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
1828 buffCI.size = 1024;
1829 buffCI.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
1830 buffCI.queueFamilyIndexCount = 1;
1831 buffCI.pQueueFamilyIndices = &qfi;
1832
1833 VkBuffer dyub;
1834 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &dyub);
1835 ASSERT_VK_SUCCESS(err);
1836 // Correctly update descriptor to avoid "NOT_UPDATED" error
1837 VkDescriptorBufferInfo buffInfo = {};
1838 buffInfo.buffer = dyub;
1839 buffInfo.offset = 0;
1840 buffInfo.range = 1024;
1841
1842 VkWriteDescriptorSet descriptor_write;
1843 memset(&descriptor_write, 0, sizeof(descriptor_write));
1844 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
1845 descriptor_write.dstSet = descriptorSet;
1846 descriptor_write.dstBinding = 0;
1847 descriptor_write.descriptorCount = 1;
1848 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
1849 descriptor_write.pBufferInfo = &buffInfo;
1850
1851 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
1852
1853 BeginCommandBuffer();
1854 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1, &descriptorSet, 0, NULL);
Tobin Ehlisf6585052015-12-17 11:48:42 -07001855 if (!m_errorMonitor->DesiredMsgFound()) {
1856 FAIL() << "Error received was not 'descriptorSet #0 (0x<ADDR>) requires 1 dynamicOffsets, but only 0 dynamicOffsets are left in pDynamicOffsets array...'";
1857 m_errorMonitor->DumpFailureMsgs();
1858 }
1859 uint32_t pDynOff[2] = {512, 756};
1860 // Now cause error b/c too many dynOffsets in array for # of dyn descriptors
1861 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
1862 "Attempting to bind 1 descriptorSets with 1 dynamic descriptors, but ");
1863 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1, &descriptorSet, 2, pDynOff);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07001864 if (!m_errorMonitor->DesiredMsgFound()) {
1865 FAIL() << "Error received was not 'Attempting to bind 1 descriptorSets with 1 dynamic descriptors, but dynamicOffsetCount is 0...'";
1866 m_errorMonitor->DumpFailureMsgs();
1867 }
Tobin Ehlisf6585052015-12-17 11:48:42 -07001868 // Finally cause error due to dynamicOffset being too big
1869 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
1870 " from its update, this oversteps its buffer (");
1871 // Create PSO to be used for draw-time errors below
1872 char const *vsSource =
Tony Barboure804d202016-01-05 13:37:45 -07001873 "#version 400\n"
Tobin Ehlisf6585052015-12-17 11:48:42 -07001874 "#extension GL_ARB_separate_shader_objects: require\n"
1875 "#extension GL_ARB_shading_language_420pack: require\n"
1876 "\n"
Tony Barboure804d202016-01-05 13:37:45 -07001877 "out gl_PerVertex { \n"
1878 " vec4 gl_Position;\n"
1879 "};\n"
Tobin Ehlisf6585052015-12-17 11:48:42 -07001880 "void main(){\n"
1881 " gl_Position = vec4(1);\n"
1882 "}\n";
1883 char const *fsSource =
Tony Barboure804d202016-01-05 13:37:45 -07001884 "#version 400\n"
Tobin Ehlisf6585052015-12-17 11:48:42 -07001885 "#extension GL_ARB_separate_shader_objects: require\n"
1886 "#extension GL_ARB_shading_language_420pack: require\n"
1887 "\n"
1888 "layout(location=0) out vec4 x;\n"
1889 "layout(set=0) layout(binding=0) uniform foo { int x; int y; } bar;\n"
1890 "void main(){\n"
1891 " x = vec4(bar.y);\n"
1892 "}\n";
1893 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
1894 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
1895 VkPipelineObj pipe(m_device);
1896 pipe.AddShader(&vs);
1897 pipe.AddShader(&fs);
1898 pipe.AddColorAttachment();
1899 pipe.CreateVKPipeline(pipeline_layout, renderPass());
1900
1901 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
1902 // This update should succeed, but offset size of 512 will overstep buffer /w range 1024 & size 1024
1903 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1, &descriptorSet, 1, pDynOff);
1904 Draw(1, 0, 0, 0);
1905 if (!m_errorMonitor->DesiredMsgFound()) {
1906 FAIL() << "Error received was not 'VkDescriptorSet (0x<ADDR>) bound as set #0 has dynamic offset 512. Combined with offet 0 and range 1024 from its update, this oversteps...'";
1907 m_errorMonitor->DumpFailureMsgs();
1908 }
Tobin Ehlis49f903e2015-11-04 13:30:34 -07001909
1910 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
1911 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
1912}
1913
Tobin Ehlis559c6382015-11-05 09:52:49 -07001914TEST_F(VkLayerTest, DescriptorSetCompatibility)
1915{
1916 // Test various desriptorSet errors with bad binding combinations
1917 VkResult err;
Tobin Ehlis559c6382015-11-05 09:52:49 -07001918
1919 ASSERT_NO_FATAL_FAILURE(InitState());
1920 ASSERT_NO_FATAL_FAILURE(InitViewport());
1921 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
1922
1923 static const uint32_t NUM_DESCRIPTOR_TYPES = 5;
1924 VkDescriptorPoolSize ds_type_count[NUM_DESCRIPTOR_TYPES] = {};
1925 ds_type_count[0].type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07001926 ds_type_count[0].descriptorCount = 10;
Tobin Ehlis559c6382015-11-05 09:52:49 -07001927 ds_type_count[1].type = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
1928 ds_type_count[1].descriptorCount = 2;
1929 ds_type_count[2].type = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE;
1930 ds_type_count[2].descriptorCount = 2;
1931 ds_type_count[3].type = VK_DESCRIPTOR_TYPE_SAMPLER;
1932 ds_type_count[3].descriptorCount = 5;
1933 // TODO : LunarG ILO driver currently asserts in desc.c w/ INPUT_ATTACHMENT type
1934 //ds_type_count[4].type = VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT;
1935 ds_type_count[4].type = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
1936 ds_type_count[4].descriptorCount = 2;
1937
1938 VkDescriptorPoolCreateInfo ds_pool_ci = {};
1939 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
1940 ds_pool_ci.pNext = NULL;
1941 ds_pool_ci.maxSets = 1;
1942 ds_pool_ci.poolSizeCount = NUM_DESCRIPTOR_TYPES;
1943 ds_pool_ci.pPoolSizes = ds_type_count;
1944
1945 VkDescriptorPool ds_pool;
1946 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
1947 ASSERT_VK_SUCCESS(err);
1948
1949 static const uint32_t MAX_DS_TYPES_IN_LAYOUT = 2;
1950 VkDescriptorSetLayoutBinding dsl_binding[MAX_DS_TYPES_IN_LAYOUT] = {};
1951 dsl_binding[0].binding = 0;
1952 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07001953 dsl_binding[0].descriptorCount = 5;
Tobin Ehlis559c6382015-11-05 09:52:49 -07001954 dsl_binding[0].stageFlags = VK_SHADER_STAGE_ALL;
1955 dsl_binding[0].pImmutableSamplers = NULL;
1956
Tobin Ehlis8fab6562015-12-01 09:57:09 -07001957 // Create layout identical to set0 layout but w/ different stageFlags
1958 VkDescriptorSetLayoutBinding dsl_fs_stage_only = {};
1959 dsl_fs_stage_only.binding = 0;
1960 dsl_fs_stage_only.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
1961 dsl_fs_stage_only.descriptorCount = 5;
1962 dsl_fs_stage_only.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT; // Different stageFlags to cause error at bind time
1963 dsl_fs_stage_only.pImmutableSamplers = NULL;
Tobin Ehlis559c6382015-11-05 09:52:49 -07001964 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
1965 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
1966 ds_layout_ci.pNext = NULL;
1967 ds_layout_ci.bindingCount = 1;
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07001968 ds_layout_ci.pBindings = dsl_binding;
Tobin Ehlis559c6382015-11-05 09:52:49 -07001969 static const uint32_t NUM_LAYOUTS = 4;
1970 VkDescriptorSetLayout ds_layout[NUM_LAYOUTS] = {};
Tobin Ehlis8fab6562015-12-01 09:57:09 -07001971 VkDescriptorSetLayout ds_layout_fs_only = {};
1972 // Create 4 unique layouts for full pipelineLayout, and 1 special fs-only layout for error case
Tobin Ehlis559c6382015-11-05 09:52:49 -07001973 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout[0]);
1974 ASSERT_VK_SUCCESS(err);
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07001975 ds_layout_ci.pBindings = &dsl_fs_stage_only;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07001976 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout_fs_only);
1977 ASSERT_VK_SUCCESS(err);
Tobin Ehlis559c6382015-11-05 09:52:49 -07001978 dsl_binding[0].binding = 0;
1979 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07001980 dsl_binding[0].descriptorCount = 2;
Tobin Ehlis559c6382015-11-05 09:52:49 -07001981 dsl_binding[0].binding = 1;
1982 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07001983 dsl_binding[0].descriptorCount = 2;
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07001984 ds_layout_ci.pBindings = dsl_binding;
Tobin Ehlis559c6382015-11-05 09:52:49 -07001985 ds_layout_ci.bindingCount = 2;
1986 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout[1]);
1987 ASSERT_VK_SUCCESS(err);
1988 dsl_binding[0].binding = 0;
1989 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07001990 dsl_binding[0].descriptorCount = 5;
Tobin Ehlis559c6382015-11-05 09:52:49 -07001991 ds_layout_ci.bindingCount = 1;
1992 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout[2]);
1993 ASSERT_VK_SUCCESS(err);
1994 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07001995 dsl_binding[0].descriptorCount = 2;
Tobin Ehlis559c6382015-11-05 09:52:49 -07001996 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout[3]);
1997 ASSERT_VK_SUCCESS(err);
1998
1999 static const uint32_t NUM_SETS = 4;
2000 VkDescriptorSet descriptorSet[NUM_SETS] = {};
2001 VkDescriptorSetAllocateInfo alloc_info = {};
Tobin Ehlis8fab6562015-12-01 09:57:09 -07002002 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Tobin Ehlis559c6382015-11-05 09:52:49 -07002003 alloc_info.setLayoutCount = NUM_LAYOUTS;
2004 alloc_info.descriptorPool = ds_pool;
2005 alloc_info.pSetLayouts = ds_layout;
2006 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, descriptorSet);
2007 ASSERT_VK_SUCCESS(err);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07002008 VkDescriptorSet ds0_fs_only = {};
2009 alloc_info.setLayoutCount = 1;
2010 alloc_info.pSetLayouts = &ds_layout_fs_only;
2011 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &ds0_fs_only);
2012 ASSERT_VK_SUCCESS(err);
Tobin Ehlis559c6382015-11-05 09:52:49 -07002013
2014 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
2015 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
2016 pipeline_layout_ci.pNext = NULL;
2017 pipeline_layout_ci.setLayoutCount = NUM_LAYOUTS;
2018 pipeline_layout_ci.pSetLayouts = ds_layout;
2019
2020 VkPipelineLayout pipeline_layout;
2021 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
2022 ASSERT_VK_SUCCESS(err);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07002023 // Create pipelineLayout with only one setLayout
2024 pipeline_layout_ci.setLayoutCount = 1;
2025 VkPipelineLayout single_pipe_layout;
2026 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &single_pipe_layout);
2027 ASSERT_VK_SUCCESS(err);
2028 // Create pipelineLayout with 2 descriptor setLayout at index 0
2029 pipeline_layout_ci.pSetLayouts = &ds_layout[3];
2030 VkPipelineLayout pipe_layout_one_desc;
2031 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipe_layout_one_desc);
2032 ASSERT_VK_SUCCESS(err);
2033 // Create pipelineLayout with 5 SAMPLER descriptor setLayout at index 0
2034 pipeline_layout_ci.pSetLayouts = &ds_layout[2];
2035 VkPipelineLayout pipe_layout_five_samp;
2036 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipe_layout_five_samp);
2037 ASSERT_VK_SUCCESS(err);
2038 // Create pipelineLayout with UB type, but stageFlags for FS only
2039 pipeline_layout_ci.pSetLayouts = &ds_layout_fs_only;
2040 VkPipelineLayout pipe_layout_fs_only;
2041 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipe_layout_fs_only);
2042 ASSERT_VK_SUCCESS(err);
2043 // Create pipelineLayout w/ incompatible set0 layout, but set1 is fine
2044 VkDescriptorSetLayout pl_bad_s0[2] = {};
2045 pl_bad_s0[0] = ds_layout_fs_only;
2046 pl_bad_s0[1] = ds_layout[1];
2047 pipeline_layout_ci.setLayoutCount = 2;
2048 pipeline_layout_ci.pSetLayouts = pl_bad_s0;
2049 VkPipelineLayout pipe_layout_bad_set0;
2050 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipe_layout_bad_set0);
2051 ASSERT_VK_SUCCESS(err);
Tobin Ehlis559c6382015-11-05 09:52:49 -07002052
2053 // Create a buffer to update the descriptor with
2054 uint32_t qfi = 0;
2055 VkBufferCreateInfo buffCI = {};
2056 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
2057 buffCI.size = 1024;
2058 buffCI.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
2059 buffCI.queueFamilyIndexCount = 1;
2060 buffCI.pQueueFamilyIndices = &qfi;
2061
2062 VkBuffer dyub;
2063 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &dyub);
2064 ASSERT_VK_SUCCESS(err);
2065 // Correctly update descriptor to avoid "NOT_UPDATED" error
2066 static const uint32_t NUM_BUFFS = 5;
2067 VkDescriptorBufferInfo buffInfo[NUM_BUFFS] = {};
2068 for (uint32_t i=0; i<NUM_BUFFS; ++i) {
2069 buffInfo[i].buffer = dyub;
2070 buffInfo[i].offset = 0;
2071 buffInfo[i].range = 1024;
2072 }
Tobin Ehlis8fab6562015-12-01 09:57:09 -07002073 VkImage image;
2074 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
2075 const int32_t tex_width = 32;
2076 const int32_t tex_height = 32;
2077 VkImageCreateInfo image_create_info = {};
2078 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
2079 image_create_info.pNext = NULL;
2080 image_create_info.imageType = VK_IMAGE_TYPE_2D;
2081 image_create_info.format = tex_format;
2082 image_create_info.extent.width = tex_width;
2083 image_create_info.extent.height = tex_height;
2084 image_create_info.extent.depth = 1;
2085 image_create_info.mipLevels = 1;
2086 image_create_info.arrayLayers = 1;
2087 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
2088 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
2089 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
2090 image_create_info.flags = 0;
2091 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
2092 ASSERT_VK_SUCCESS(err);
Tobin Ehlis559c6382015-11-05 09:52:49 -07002093
Tobin Ehlis8fab6562015-12-01 09:57:09 -07002094 VkImageViewCreateInfo image_view_create_info = {};
2095 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
2096 image_view_create_info.image = image;
2097 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
2098 image_view_create_info.format = tex_format;
2099 image_view_create_info.subresourceRange.layerCount = 1;
2100 image_view_create_info.subresourceRange.baseMipLevel = 0;
2101 image_view_create_info.subresourceRange.levelCount = 1;
2102 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Tobin Ehlis559c6382015-11-05 09:52:49 -07002103
Tobin Ehlis8fab6562015-12-01 09:57:09 -07002104 VkImageView view;
2105 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
2106 ASSERT_VK_SUCCESS(err);
Tobin Ehlis991d45a2016-01-06 08:48:41 -07002107 VkDescriptorImageInfo imageInfo[4] = {};
Tobin Ehlis8fab6562015-12-01 09:57:09 -07002108 imageInfo[0].imageView = view;
2109 imageInfo[0].imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
2110 imageInfo[1].imageView = view;
2111 imageInfo[1].imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
Tobin Ehlis991d45a2016-01-06 08:48:41 -07002112 imageInfo[2].imageView = view;
2113 imageInfo[2].imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
2114 imageInfo[3].imageView = view;
2115 imageInfo[3].imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07002116
2117 static const uint32_t NUM_SET_UPDATES = 3;
2118 VkWriteDescriptorSet descriptor_write[NUM_SET_UPDATES] = {};
2119 descriptor_write[0].sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
2120 descriptor_write[0].dstSet = descriptorSet[0];
2121 descriptor_write[0].dstBinding = 0;
2122 descriptor_write[0].descriptorCount = 5;
2123 descriptor_write[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
2124 descriptor_write[0].pBufferInfo = buffInfo;
2125 descriptor_write[1].sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
2126 descriptor_write[1].dstSet = descriptorSet[1];
2127 descriptor_write[1].dstBinding = 0;
2128 descriptor_write[1].descriptorCount = 2;
2129 descriptor_write[1].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
2130 descriptor_write[1].pImageInfo = imageInfo;
2131 descriptor_write[2].sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
2132 descriptor_write[2].dstSet = descriptorSet[1];
2133 descriptor_write[2].dstBinding = 1;
2134 descriptor_write[2].descriptorCount = 2;
2135 descriptor_write[2].descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE;
Tobin Ehlis991d45a2016-01-06 08:48:41 -07002136 descriptor_write[2].pImageInfo = &imageInfo[2];
Tobin Ehlis8fab6562015-12-01 09:57:09 -07002137
2138 vkUpdateDescriptorSets(m_device->device(), 3, descriptor_write, 0, NULL);
Tobin Ehlis559c6382015-11-05 09:52:49 -07002139
Tobin Ehlis88452832015-12-03 09:40:56 -07002140 // Create PSO to be used for draw-time errors below
2141 char const *vsSource =
Tony Barboure804d202016-01-05 13:37:45 -07002142 "#version 400\n"
Tobin Ehlis88452832015-12-03 09:40:56 -07002143 "#extension GL_ARB_separate_shader_objects: require\n"
2144 "#extension GL_ARB_shading_language_420pack: require\n"
2145 "\n"
Tony Barboure804d202016-01-05 13:37:45 -07002146 "out gl_PerVertex {\n"
2147 " vec4 gl_Position;\n"
2148 "};\n"
Tobin Ehlis88452832015-12-03 09:40:56 -07002149 "void main(){\n"
2150 " gl_Position = vec4(1);\n"
2151 "}\n";
2152 char const *fsSource =
Tony Barboure804d202016-01-05 13:37:45 -07002153 "#version 400\n"
Tobin Ehlis88452832015-12-03 09:40:56 -07002154 "#extension GL_ARB_separate_shader_objects: require\n"
2155 "#extension GL_ARB_shading_language_420pack: require\n"
2156 "\n"
2157 "layout(location=0) out vec4 x;\n"
2158 "layout(set=0) layout(binding=0) uniform foo { int x; int y; } bar;\n"
2159 "void main(){\n"
2160 " x = vec4(bar.y);\n"
2161 "}\n";
2162 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
2163 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Tobin Ehlis559c6382015-11-05 09:52:49 -07002164 VkPipelineObj pipe(m_device);
2165 pipe.AddShader(&vs);
2166 pipe.AddShader(&fs);
Tobin Ehlis88452832015-12-03 09:40:56 -07002167 pipe.AddColorAttachment();
2168 pipe.CreateVKPipeline(pipe_layout_fs_only, renderPass());
Tobin Ehlis559c6382015-11-05 09:52:49 -07002169
2170 BeginCommandBuffer();
Tobin Ehlis88452832015-12-03 09:40:56 -07002171
Tobin Ehlis559c6382015-11-05 09:52:49 -07002172 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
2173 // NOTE : I believe LunarG ilo driver has bug (LX#189) that requires binding of PSO
2174 // here before binding DSs. Otherwise we assert in cmd_copy_dset_data() of cmd_pipeline.c
2175 // due to the fact that cmd_alloc_dset_data() has not been called in cmd_bind_graphics_pipeline()
2176 // TODO : Want to cause various binding incompatibility issues here to test DrawState
2177 // First cause various verify_layout_compatibility() fails
2178 // Second disturb early and late sets and verify INFO msgs
Tobin Ehlis8fab6562015-12-01 09:57:09 -07002179 // verify_set_layout_compatibility fail cases:
2180 // 1. invalid VkPipelineLayout (layout) passed into vkCmdBindDescriptorSets
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07002181 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " due to: invalid VkPipelineLayout ");
Mark Youngad779052016-01-06 14:26:04 -07002182 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, (VkPipelineLayout)((size_t)0xbaadb1be), 0, 1, &descriptorSet[0], 0, NULL);
Tobin Ehlis559c6382015-11-05 09:52:49 -07002183 if (!m_errorMonitor->DesiredMsgFound()) {
Tobin Ehlis8fab6562015-12-01 09:57:09 -07002184 FAIL() << "Did not receive correct error msg when attempting to bind descriptorSets with invalid VkPipelineLayout.";
Tobin Ehlis559c6382015-11-05 09:52:49 -07002185 m_errorMonitor->DumpFailureMsgs();
2186 }
Tobin Ehlis8fab6562015-12-01 09:57:09 -07002187 // 2. layoutIndex exceeds # of layouts in layout
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07002188 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " attempting to bind set to index 1");
Tobin Ehlis8fab6562015-12-01 09:57:09 -07002189 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, single_pipe_layout, 0, 2, &descriptorSet[0], 0, NULL);
2190 if (!m_errorMonitor->DesiredMsgFound()) {
2191 FAIL() << "Did not receive correct error msg when attempting to bind descriptorSet to index 1 when pipelineLayout only has index 0.";
2192 m_errorMonitor->DumpFailureMsgs();
2193 }
2194 vkDestroyPipelineLayout(m_device->device(), single_pipe_layout, NULL);
2195 // 3. Pipeline setLayout[0] has 2 descriptors, but set being bound has 5 descriptors
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07002196 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, ", but corresponding set being bound has 5 descriptors.");
Tobin Ehlis8fab6562015-12-01 09:57:09 -07002197 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe_layout_one_desc, 0, 1, &descriptorSet[0], 0, NULL);
2198 if (!m_errorMonitor->DesiredMsgFound()) {
2199 FAIL() << "Did not receive correct error msg when attempting to bind descriptorSet w/ 5 descriptors to pipelineLayout with only 2 descriptors.";
2200 m_errorMonitor->DumpFailureMsgs();
2201 }
2202 vkDestroyPipelineLayout(m_device->device(), pipe_layout_one_desc, NULL);
2203 // 4. same # of descriptors but mismatch in type
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07002204 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " descriptor from pipelineLayout is type 'VK_DESCRIPTOR_TYPE_SAMPLER'");
Tobin Ehlis8fab6562015-12-01 09:57:09 -07002205 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe_layout_five_samp, 0, 1, &descriptorSet[0], 0, NULL);
2206 if (!m_errorMonitor->DesiredMsgFound()) {
2207 FAIL() << "Did not receive correct error msg when attempting to bind UNIFORM_BUFFER descriptorSet to pipelineLayout with overlapping SAMPLER type.";
2208 m_errorMonitor->DumpFailureMsgs();
2209 }
2210 vkDestroyPipelineLayout(m_device->device(), pipe_layout_five_samp, NULL);
2211 // 5. same # of descriptors but mismatch in stageFlags
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07002212 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " descriptor from pipelineLayout has stageFlags ");
Tobin Ehlis8fab6562015-12-01 09:57:09 -07002213 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe_layout_fs_only, 0, 1, &descriptorSet[0], 0, NULL);
2214 if (!m_errorMonitor->DesiredMsgFound()) {
2215 FAIL() << "Did not receive correct error msg when attempting to bind UNIFORM_BUFFER descriptorSet with ALL stageFlags to pipelineLayout with FS-only stageFlags.";
2216 m_errorMonitor->DumpFailureMsgs();
2217 }
2218 // Cause INFO messages due to disturbing previously bound Sets
2219 // First bind sets 0 & 1
2220 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 2, &descriptorSet[0], 0, NULL);
2221 // 1. Disturb bound set0 by re-binding set1 w/ updated pipelineLayout
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07002222 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERF_WARN_BIT_EXT, " previously bound as set #0 was disturbed ");
Tobin Ehlis8fab6562015-12-01 09:57:09 -07002223 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe_layout_bad_set0, 1, 1, &descriptorSet[1], 0, NULL);
2224 if (!m_errorMonitor->DesiredMsgFound()) {
2225 FAIL() << "Did not receive correct info msg when binding Set1 w/ pipelineLayout that should disturb Set0.";
2226 m_errorMonitor->DumpFailureMsgs();
2227 }
Tobin Ehlis8fab6562015-12-01 09:57:09 -07002228 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 2, &descriptorSet[0], 0, NULL);
2229 // 2. Disturb set after last bound set
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07002230 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERF_WARN_BIT_EXT, " newly bound as set #0 so set #1 and any subsequent sets were disturbed ");
Tobin Ehlis8fab6562015-12-01 09:57:09 -07002231 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe_layout_fs_only, 0, 1, &ds0_fs_only, 0, NULL);
2232 if (!m_errorMonitor->DesiredMsgFound()) {
2233 FAIL() << "Did not receive correct info msg when re-binding Set0 w/ pipelineLayout that should disturb Set1.";
2234 m_errorMonitor->DumpFailureMsgs();
2235 }
Tobin Ehlis88452832015-12-03 09:40:56 -07002236 // Cause draw-time errors due to PSO incompatibilities
2237 // 1. Error due to not binding required set (we actually use same code as above to disturb set0)
2238 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 2, &descriptorSet[0], 0, NULL);
2239 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe_layout_bad_set0, 1, 1, &descriptorSet[1], 0, NULL);
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07002240 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " uses set #0 but that set is not bound.");
Tobin Ehlis88452832015-12-03 09:40:56 -07002241 Draw(1, 0, 0, 0);
2242 if (!m_errorMonitor->DesiredMsgFound()) {
2243 FAIL() << "Did not receive correct error msg when attempting draw requiring Set0 but Set0 is not bound.";
2244 m_errorMonitor->DumpFailureMsgs();
2245 }
Tobin Ehlis991d45a2016-01-06 08:48:41 -07002246 vkDestroyPipelineLayout(m_device->device(), pipe_layout_bad_set0, NULL);
Tobin Ehlis88452832015-12-03 09:40:56 -07002247 // 2. Error due to bound set not being compatible with PSO's VkPipelineLayout (diff stageFlags in this case)
2248 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 2, &descriptorSet[0], 0, NULL);
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07002249 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " bound as set #0 is not compatible with ");
Tobin Ehlis88452832015-12-03 09:40:56 -07002250 Draw(1, 0, 0, 0);
2251 if (!m_errorMonitor->DesiredMsgFound()) {
2252 FAIL() << "Did not receive correct error msg when attempted draw where bound Set0 layout is not compatible PSO Set0 layout.";
2253 m_errorMonitor->DumpFailureMsgs();
2254 }
Tobin Ehlis8fab6562015-12-01 09:57:09 -07002255 // Remaining clean-up
2256 vkDestroyPipelineLayout(m_device->device(), pipe_layout_fs_only, NULL);
2257 for (uint32_t i=0; i<NUM_LAYOUTS; ++i) {
2258 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout[i], NULL);
2259 }
2260 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout_fs_only, NULL);
2261 vkFreeDescriptorSets(m_device->device(), ds_pool, 1, descriptorSet);
2262 vkDestroyBuffer(m_device->device(), dyub, NULL);
Tobin Ehlis559c6382015-11-05 09:52:49 -07002263 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
2264 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
2265}
Tobin Ehlis559c6382015-11-05 09:52:49 -07002266
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002267TEST_F(VkLayerTest, NoBeginCommandBuffer)
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06002268{
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002269
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07002270 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002271 "You must call vkBeginCommandBuffer() before this call to ");
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06002272
2273 ASSERT_NO_FATAL_FAILURE(InitState());
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002274 VkCommandBufferObj commandBuffer(m_device, m_commandPool);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06002275 // Call EndCommandBuffer() w/o calling BeginCommandBuffer()
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002276 vkEndCommandBuffer(commandBuffer.GetBufferHandle());
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002277
2278 if (!m_errorMonitor->DesiredMsgFound()) {
2279 FAIL() << "Did not recieve Error 'You must call vkBeginCommandBuffer() before this call to vkEndCommandBuffer()'";
2280 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06002281 }
2282}
2283
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002284TEST_F(VkLayerTest, PrimaryCommandBufferFramebufferAndRenderpass)
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06002285{
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002286
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07002287 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002288 "may not specify framebuffer or renderpass parameters");
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06002289
2290 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06002291
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002292 // Calls AllocateCommandBuffers
2293 VkCommandBufferObj commandBuffer(m_device, m_commandPool);
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06002294
2295 // Force the failure by setting the Renderpass and Framebuffer fields with (fake) data
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002296 VkCommandBufferBeginInfo cmd_buf_info = {};
2297 cmd_buf_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
Cody Northropb4569702015-08-04 17:35:57 -06002298 cmd_buf_info.pNext = NULL;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002299 cmd_buf_info.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT;
Mark Youngad779052016-01-06 14:26:04 -07002300 cmd_buf_info.renderPass = (VkRenderPass)((size_t)0xcadecade);
2301 cmd_buf_info.framebuffer = (VkFramebuffer)((size_t)0xcadecade);
Cody Northropb4569702015-08-04 17:35:57 -06002302
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06002303
2304 // The error should be caught by validation of the BeginCommandBuffer call
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002305 vkBeginCommandBuffer(commandBuffer.GetBufferHandle(), &cmd_buf_info);
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06002306
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002307 if (!m_errorMonitor->DesiredMsgFound()) {
2308 FAIL() << "Did not receive Error 'vkAllocateCommandBuffers(): Primary Command Buffer may not specify framebuffer or renderpass parameters'";
2309 m_errorMonitor->DumpFailureMsgs();
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06002310 }
2311}
2312
Tobin Ehlis61b36f32015-12-16 08:19:42 -07002313TEST_F(VkLayerTest, SecondaryCommandBufferNullRenderpass)
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06002314{
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06002315 VkResult err;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002316 VkCommandBuffer draw_cmd;
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06002317
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07002318 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis61b36f32015-12-16 08:19:42 -07002319 " must specify a valid renderpass parameter.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002320
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06002321 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06002322
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002323 VkCommandBufferAllocateInfo cmd = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08002324 cmd.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
Cody Northropb4569702015-08-04 17:35:57 -06002325 cmd.pNext = NULL;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002326 cmd.commandPool = m_commandPool;
2327 cmd.level = VK_COMMAND_BUFFER_LEVEL_SECONDARY;
Chia-I Wud50a7d72015-10-26 20:48:51 +08002328 cmd.bufferCount = 1;
Cody Northropb4569702015-08-04 17:35:57 -06002329
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002330 err = vkAllocateCommandBuffers(m_device->device(), &cmd, &draw_cmd);
Mike Stroyand1c84a52015-08-18 14:40:24 -06002331 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06002332
2333 // Force the failure by not setting the Renderpass and Framebuffer fields
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002334 VkCommandBufferBeginInfo cmd_buf_info = {};
2335 cmd_buf_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
Cody Northropb4569702015-08-04 17:35:57 -06002336 cmd_buf_info.pNext = NULL;
Tobin Ehlis651d9b02015-12-16 05:01:22 -07002337 cmd_buf_info.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT | VK_COMMAND_BUFFER_USAGE_RENDER_PASS_CONTINUE_BIT;
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06002338
2339 // The error should be caught by validation of the BeginCommandBuffer call
2340 vkBeginCommandBuffer(draw_cmd, &cmd_buf_info);
2341
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002342 if (!m_errorMonitor->DesiredMsgFound()) {
Tobin Ehlis61b36f32015-12-16 08:19:42 -07002343 FAIL() << "Did not receive Error 'vkBeginCommandBuffer(): Secondary Command Buffers (0x<ADDR>) must specify a valid renderpass parameter.'";
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002344 m_errorMonitor->DumpFailureMsgs();
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06002345 }
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002346 vkFreeCommandBuffers(m_device->device(), m_commandPool, 1, &draw_cmd);
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06002347}
2348
Tobin Ehlisac0ef842015-12-14 13:46:38 -07002349TEST_F(VkLayerTest, CommandBufferResetErrors)
2350{
2351 // Cause error due to Begin while recording CB
2352 // Then cause 2 errors for attempting to reset CB w/o having
2353 // VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT set for the pool from
2354 // which CBs were allocated. Note that this bit is off by default.
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07002355 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlisac0ef842015-12-14 13:46:38 -07002356 "Cannot call Begin on CB");
2357
2358 ASSERT_NO_FATAL_FAILURE(InitState());
2359
2360 // Calls AllocateCommandBuffers
2361 VkCommandBufferObj commandBuffer(m_device, m_commandPool);
2362
2363 // Force the failure by setting the Renderpass and Framebuffer fields with (fake) data
2364 VkCommandBufferBeginInfo cmd_buf_info = {};
2365 cmd_buf_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
2366 cmd_buf_info.pNext = NULL;
2367 cmd_buf_info.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT;
2368
2369 // Begin CB to transition to recording state
2370 vkBeginCommandBuffer(commandBuffer.GetBufferHandle(), &cmd_buf_info);
2371 // Can't re-begin. This should trigger error
2372 vkBeginCommandBuffer(commandBuffer.GetBufferHandle(), &cmd_buf_info);
2373 if (!m_errorMonitor->DesiredMsgFound()) {
2374 FAIL() << "Did not receive Error 'Cannot call Begin on CB (0x<ADDR>) in the RECORDING state...'";
2375 m_errorMonitor->DumpFailureMsgs();
2376 }
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07002377 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attempt to reset command buffer ");
Tobin Ehlisac0ef842015-12-14 13:46:38 -07002378 VkCommandBufferResetFlags flags = 0; // Don't care about flags for this test
2379 // Reset attempt will trigger error due to incorrect CommandPool state
2380 vkResetCommandBuffer(commandBuffer.GetBufferHandle(), flags);
2381 if (!m_errorMonitor->DesiredMsgFound()) {
2382 FAIL() << "Did not receive Error 'Attempt to reset command buffer (0x<ADDR>) created from command pool...'";
2383 m_errorMonitor->DumpFailureMsgs();
2384 }
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07002385 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " attempts to implicitly reset cmdBuffer created from ");
Tobin Ehlisac0ef842015-12-14 13:46:38 -07002386 // Transition CB to RECORDED state
2387 vkEndCommandBuffer(commandBuffer.GetBufferHandle());
2388 // Now attempting to Begin will implicitly reset, which triggers error
2389 vkBeginCommandBuffer(commandBuffer.GetBufferHandle(), &cmd_buf_info);
2390 if (!m_errorMonitor->DesiredMsgFound()) {
2391 FAIL() << "Did not receive Error 'Call to vkBeginCommandBuffer() on command buffer (0x<ADDR>) attempts to implicitly reset...'";
2392 m_errorMonitor->DumpFailureMsgs();
2393 }
2394}
2395
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06002396TEST_F(VkLayerTest, InvalidPipelineCreateState)
2397{
2398 // Attempt to Create Gfx Pipeline w/o a VS
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06002399 VkResult err;
2400
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07002401 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002402 "Invalid Pipeline CreateInfo State: Vtx Shader required");
2403
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06002404 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002405 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinski209b5292015-09-17 09:44:05 -06002406
Chia-I Wu1b99bb22015-10-27 19:25:11 +08002407 VkDescriptorPoolSize ds_type_count = {};
Tony Barboureb254902015-07-15 12:50:33 -06002408 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wud50a7d72015-10-26 20:48:51 +08002409 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06002410
2411 VkDescriptorPoolCreateInfo ds_pool_ci = {};
2412 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
2413 ds_pool_ci.pNext = NULL;
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -06002414 ds_pool_ci.maxSets = 1;
Chia-I Wu1b99bb22015-10-27 19:25:11 +08002415 ds_pool_ci.poolSizeCount = 1;
2416 ds_pool_ci.pPoolSizes = &ds_type_count;
Mark Lobodzinski209b5292015-09-17 09:44:05 -06002417
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06002418 VkDescriptorPool ds_pool;
Chia-I Wuf7458c52015-10-26 21:10:41 +08002419 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06002420 ASSERT_VK_SUCCESS(err);
2421
Tony Barboureb254902015-07-15 12:50:33 -06002422 VkDescriptorSetLayoutBinding dsl_binding = {};
Chia-I Wud46e6ae2015-10-31 00:31:16 +08002423 dsl_binding.binding = 0;
Tony Barboureb254902015-07-15 12:50:33 -06002424 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wu02124482015-11-06 06:42:02 +08002425 dsl_binding.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06002426 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
2427 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06002428
Tony Barboureb254902015-07-15 12:50:33 -06002429 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
2430 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
2431 ds_layout_ci.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08002432 ds_layout_ci.bindingCount = 1;
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07002433 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -06002434
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06002435 VkDescriptorSetLayout ds_layout;
Chia-I Wuf7458c52015-10-26 21:10:41 +08002436 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06002437 ASSERT_VK_SUCCESS(err);
2438
2439 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002440 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08002441 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Chia-I Wud50a7d72015-10-26 20:48:51 +08002442 alloc_info.setLayoutCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06002443 alloc_info.descriptorPool = ds_pool;
2444 alloc_info.pSetLayouts = &ds_layout;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002445 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06002446 ASSERT_VK_SUCCESS(err);
2447
Tony Barboureb254902015-07-15 12:50:33 -06002448 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
2449 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
Chia-I Wud50a7d72015-10-26 20:48:51 +08002450 pipeline_layout_ci.setLayoutCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06002451 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06002452
2453 VkPipelineLayout pipeline_layout;
Chia-I Wuf7458c52015-10-26 21:10:41 +08002454 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06002455 ASSERT_VK_SUCCESS(err);
2456
Tobin Ehlise68360f2015-10-01 11:15:13 -06002457 VkViewport vp = {}; // Just need dummy vp to point to
2458 VkRect2D sc = {}; // dummy scissor to point to
2459
2460 VkPipelineViewportStateCreateInfo vp_state_ci = {};
2461 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
2462 vp_state_ci.scissorCount = 1;
2463 vp_state_ci.pScissors = &sc;
2464 vp_state_ci.viewportCount = 1;
2465 vp_state_ci.pViewports = &vp;
2466
Tony Barboureb254902015-07-15 12:50:33 -06002467 VkGraphicsPipelineCreateInfo gp_ci = {};
2468 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
Tobin Ehlise68360f2015-10-01 11:15:13 -06002469 gp_ci.pViewportState = &vp_state_ci;
Tony Barboureb254902015-07-15 12:50:33 -06002470 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
2471 gp_ci.layout = pipeline_layout;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002472 gp_ci.renderPass = renderPass();
Tony Barboureb254902015-07-15 12:50:33 -06002473
2474 VkPipelineCacheCreateInfo pc_ci = {};
2475 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
Chia-I Wu2bfb33c2015-10-26 17:24:52 +08002476 pc_ci.initialDataSize = 0;
2477 pc_ci.pInitialData = 0;
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06002478
2479 VkPipeline pipeline;
Jon Ashburnc669cc62015-07-09 15:02:25 -06002480 VkPipelineCache pipelineCache;
2481
Chia-I Wuf7458c52015-10-26 21:10:41 +08002482 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Jon Ashburnc669cc62015-07-09 15:02:25 -06002483 ASSERT_VK_SUCCESS(err);
Chia-I Wuf7458c52015-10-26 21:10:41 +08002484 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06002485
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002486 if (!m_errorMonitor->DesiredMsgFound()) {
2487 FAIL() << "Did not receive Error 'Invalid Pipeline CreateInfo State: Vtx Shader required'";
2488 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06002489 }
Mike Stroyand1c84a52015-08-18 14:40:24 -06002490
Chia-I Wuf7458c52015-10-26 21:10:41 +08002491 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
2492 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
2493 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
2494 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06002495}
Tobin Ehlis912df022015-09-17 08:46:18 -06002496/*// TODO : This test should be good, but needs Tess support in compiler to run
2497TEST_F(VkLayerTest, InvalidPatchControlPoints)
2498{
2499 // Attempt to Create Gfx Pipeline w/o a VS
Tobin Ehlis912df022015-09-17 08:46:18 -06002500 VkResult err;
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06002501
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07002502 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002503 "Invalid Pipeline CreateInfo State: VK_PRIMITIVE_TOPOLOGY_PATCH primitive ");
2504
Tobin Ehlis912df022015-09-17 08:46:18 -06002505 ASSERT_NO_FATAL_FAILURE(InitState());
2506 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlis912df022015-09-17 08:46:18 -06002507
Chia-I Wu1b99bb22015-10-27 19:25:11 +08002508 VkDescriptorPoolSize ds_type_count = {};
Tobin Ehlis912df022015-09-17 08:46:18 -06002509 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wud50a7d72015-10-26 20:48:51 +08002510 ds_type_count.descriptorCount = 1;
Tobin Ehlis912df022015-09-17 08:46:18 -06002511
2512 VkDescriptorPoolCreateInfo ds_pool_ci = {};
2513 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
2514 ds_pool_ci.pNext = NULL;
Chia-I Wu1b99bb22015-10-27 19:25:11 +08002515 ds_pool_ci.poolSizeCount = 1;
2516 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlis912df022015-09-17 08:46:18 -06002517
2518 VkDescriptorPool ds_pool;
Chia-I Wuf7458c52015-10-26 21:10:41 +08002519 err = vkCreateDescriptorPool(m_device->device(), VK_DESCRIPTOR_POOL_USAGE_NON_FREE, 1, &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis912df022015-09-17 08:46:18 -06002520 ASSERT_VK_SUCCESS(err);
2521
2522 VkDescriptorSetLayoutBinding dsl_binding = {};
Chia-I Wud46e6ae2015-10-31 00:31:16 +08002523 dsl_binding.binding = 0;
Tobin Ehlis912df022015-09-17 08:46:18 -06002524 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wu02124482015-11-06 06:42:02 +08002525 dsl_binding.descriptorCount = 1;
Tobin Ehlis912df022015-09-17 08:46:18 -06002526 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
2527 dsl_binding.pImmutableSamplers = NULL;
2528
2529 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
2530 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
2531 ds_layout_ci.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08002532 ds_layout_ci.bindingCount = 1;
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07002533 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlis912df022015-09-17 08:46:18 -06002534
2535 VkDescriptorSetLayout ds_layout;
Chia-I Wuf7458c52015-10-26 21:10:41 +08002536 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis912df022015-09-17 08:46:18 -06002537 ASSERT_VK_SUCCESS(err);
2538
2539 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002540 err = vkAllocateDescriptorSets(m_device->device(), ds_pool, VK_DESCRIPTOR_SET_USAGE_NON_FREE, 1, &ds_layout, &descriptorSet);
Tobin Ehlis912df022015-09-17 08:46:18 -06002541 ASSERT_VK_SUCCESS(err);
2542
2543 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
2544 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
2545 pipeline_layout_ci.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08002546 pipeline_layout_ci.setLayoutCount = 1;
Tobin Ehlis912df022015-09-17 08:46:18 -06002547 pipeline_layout_ci.pSetLayouts = &ds_layout;
2548
2549 VkPipelineLayout pipeline_layout;
Chia-I Wuf7458c52015-10-26 21:10:41 +08002550 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis912df022015-09-17 08:46:18 -06002551 ASSERT_VK_SUCCESS(err);
2552
2553 VkPipelineShaderStageCreateInfo shaderStages[3];
2554 memset(&shaderStages, 0, 3 * sizeof(VkPipelineShaderStageCreateInfo));
2555
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06002556 VkShaderObj vs(m_device,bindStateVertShaderText,VK_SHADER_STAGE_VERTEX_BIT, this);
Tobin Ehlis912df022015-09-17 08:46:18 -06002557 // Just using VS txt for Tess shaders as we don't care about functionality
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06002558 VkShaderObj tc(m_device,bindStateVertShaderText,VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT, this);
2559 VkShaderObj te(m_device,bindStateVertShaderText,VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT, this);
Tobin Ehlis912df022015-09-17 08:46:18 -06002560
2561 shaderStages[0].sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06002562 shaderStages[0].stage = VK_SHADER_STAGE_VERTEX_BIT;
Tobin Ehlis912df022015-09-17 08:46:18 -06002563 shaderStages[0].shader = vs.handle();
2564 shaderStages[1].sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06002565 shaderStages[1].stage = VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT;
Tobin Ehlis912df022015-09-17 08:46:18 -06002566 shaderStages[1].shader = tc.handle();
2567 shaderStages[2].sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06002568 shaderStages[2].stage = VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT;
Tobin Ehlis912df022015-09-17 08:46:18 -06002569 shaderStages[2].shader = te.handle();
2570
2571 VkPipelineInputAssemblyStateCreateInfo iaCI = {};
2572 iaCI.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
Chia-I Wu515eb8f2015-10-31 00:31:16 +08002573 iaCI.topology = VK_PRIMITIVE_TOPOLOGY_PATCH_LIST;
Tobin Ehlis912df022015-09-17 08:46:18 -06002574
2575 VkPipelineTessellationStateCreateInfo tsCI = {};
2576 tsCI.sType = VK_STRUCTURE_TYPE_PIPELINE_TESSELLATION_STATE_CREATE_INFO;
2577 tsCI.patchControlPoints = 0; // This will cause an error
2578
2579 VkGraphicsPipelineCreateInfo gp_ci = {};
2580 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
2581 gp_ci.pNext = NULL;
2582 gp_ci.stageCount = 3;
2583 gp_ci.pStages = shaderStages;
2584 gp_ci.pVertexInputState = NULL;
2585 gp_ci.pInputAssemblyState = &iaCI;
2586 gp_ci.pTessellationState = &tsCI;
2587 gp_ci.pViewportState = NULL;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002588 gp_ci.pRasterizationState = NULL;
Tobin Ehlis912df022015-09-17 08:46:18 -06002589 gp_ci.pMultisampleState = NULL;
2590 gp_ci.pDepthStencilState = NULL;
2591 gp_ci.pColorBlendState = NULL;
2592 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
2593 gp_ci.layout = pipeline_layout;
2594 gp_ci.renderPass = renderPass();
2595
2596 VkPipelineCacheCreateInfo pc_ci = {};
2597 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
2598 pc_ci.pNext = NULL;
2599 pc_ci.initialSize = 0;
2600 pc_ci.initialData = 0;
2601 pc_ci.maxSize = 0;
2602
2603 VkPipeline pipeline;
2604 VkPipelineCache pipelineCache;
2605
Chia-I Wuf7458c52015-10-26 21:10:41 +08002606 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Tobin Ehlis912df022015-09-17 08:46:18 -06002607 ASSERT_VK_SUCCESS(err);
Chia-I Wuf7458c52015-10-26 21:10:41 +08002608 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlis912df022015-09-17 08:46:18 -06002609
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002610 if (!m_errorMonitor->DesiredMsgFound()) {
2611 FAIL() << "Did not receive Error 'Invalid Pipeline CreateInfo State: VK_PRIMITIVE_TOPOLOGY_PATCH primitive...'";
2612 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlis912df022015-09-17 08:46:18 -06002613 }
Mike Stroyand1c84a52015-08-18 14:40:24 -06002614
Chia-I Wuf7458c52015-10-26 21:10:41 +08002615 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
2616 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
2617 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
2618 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis912df022015-09-17 08:46:18 -06002619}
2620*/
Tobin Ehlise68360f2015-10-01 11:15:13 -06002621// Set scissor and viewport counts to different numbers
2622TEST_F(VkLayerTest, PSOViewportScissorCountMismatch)
2623{
2624 // Attempt to Create Gfx Pipeline w/o a VS
Tobin Ehlise68360f2015-10-01 11:15:13 -06002625 VkResult err;
2626
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07002627 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002628 "Gfx Pipeline viewport count (1) must match scissor count (0).");
2629
Tobin Ehlise68360f2015-10-01 11:15:13 -06002630 ASSERT_NO_FATAL_FAILURE(InitState());
2631 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlise68360f2015-10-01 11:15:13 -06002632
Chia-I Wu1b99bb22015-10-27 19:25:11 +08002633 VkDescriptorPoolSize ds_type_count = {};
Tobin Ehlise68360f2015-10-01 11:15:13 -06002634 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wud50a7d72015-10-26 20:48:51 +08002635 ds_type_count.descriptorCount = 1;
Tobin Ehlise68360f2015-10-01 11:15:13 -06002636
2637 VkDescriptorPoolCreateInfo ds_pool_ci = {};
2638 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
Tobin Ehlise68360f2015-10-01 11:15:13 -06002639 ds_pool_ci.maxSets = 1;
Chia-I Wu1b99bb22015-10-27 19:25:11 +08002640 ds_pool_ci.poolSizeCount = 1;
2641 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlise68360f2015-10-01 11:15:13 -06002642
2643 VkDescriptorPool ds_pool;
Chia-I Wuf7458c52015-10-26 21:10:41 +08002644 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlise68360f2015-10-01 11:15:13 -06002645 ASSERT_VK_SUCCESS(err);
2646
2647 VkDescriptorSetLayoutBinding dsl_binding = {};
Chia-I Wud46e6ae2015-10-31 00:31:16 +08002648 dsl_binding.binding = 0;
Tobin Ehlise68360f2015-10-01 11:15:13 -06002649 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wu02124482015-11-06 06:42:02 +08002650 dsl_binding.descriptorCount = 1;
Tobin Ehlise68360f2015-10-01 11:15:13 -06002651 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
2652
2653 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
2654 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
Chia-I Wud50a7d72015-10-26 20:48:51 +08002655 ds_layout_ci.bindingCount = 1;
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07002656 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlise68360f2015-10-01 11:15:13 -06002657
2658 VkDescriptorSetLayout ds_layout;
Chia-I Wuf7458c52015-10-26 21:10:41 +08002659 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06002660 ASSERT_VK_SUCCESS(err);
2661
2662 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002663 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08002664 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Chia-I Wud50a7d72015-10-26 20:48:51 +08002665 alloc_info.setLayoutCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06002666 alloc_info.descriptorPool = ds_pool;
2667 alloc_info.pSetLayouts = &ds_layout;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002668 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlise68360f2015-10-01 11:15:13 -06002669 ASSERT_VK_SUCCESS(err);
2670
2671 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
2672 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
Chia-I Wud50a7d72015-10-26 20:48:51 +08002673 pipeline_layout_ci.setLayoutCount = 1;
Tobin Ehlise68360f2015-10-01 11:15:13 -06002674 pipeline_layout_ci.pSetLayouts = &ds_layout;
2675
2676 VkPipelineLayout pipeline_layout;
Chia-I Wuf7458c52015-10-26 21:10:41 +08002677 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06002678 ASSERT_VK_SUCCESS(err);
2679
2680 VkViewport vp = {}; // Just need dummy vp to point to
2681
2682 VkPipelineViewportStateCreateInfo vp_state_ci = {};
2683 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
2684 vp_state_ci.scissorCount = 0;
2685 vp_state_ci.viewportCount = 1; // Count mismatch should cause error
2686 vp_state_ci.pViewports = &vp;
2687
Cody Northropeb3a6c12015-10-05 14:44:45 -06002688 VkPipelineShaderStageCreateInfo shaderStages[2];
2689 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
Tobin Ehlise68360f2015-10-01 11:15:13 -06002690
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06002691 VkShaderObj vs(m_device,bindStateVertShaderText,VK_SHADER_STAGE_VERTEX_BIT, this);
2692 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this); // TODO - We shouldn't need a fragment shader
Cody Northropeb3a6c12015-10-05 14:44:45 -06002693 // but add it to be able to run on more devices
Chia-I Wu28e06912015-10-31 00:31:16 +08002694 shaderStages[0] = vs.GetStageCreateInfo();
2695 shaderStages[1] = fs.GetStageCreateInfo();
Tobin Ehlise68360f2015-10-01 11:15:13 -06002696
2697 VkGraphicsPipelineCreateInfo gp_ci = {};
2698 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
Cody Northropeb3a6c12015-10-05 14:44:45 -06002699 gp_ci.stageCount = 2;
2700 gp_ci.pStages = shaderStages;
Tobin Ehlise68360f2015-10-01 11:15:13 -06002701 gp_ci.pViewportState = &vp_state_ci;
2702 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
2703 gp_ci.layout = pipeline_layout;
2704 gp_ci.renderPass = renderPass();
2705
2706 VkPipelineCacheCreateInfo pc_ci = {};
2707 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
2708
2709 VkPipeline pipeline;
2710 VkPipelineCache pipelineCache;
2711
Chia-I Wuf7458c52015-10-26 21:10:41 +08002712 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Tobin Ehlise68360f2015-10-01 11:15:13 -06002713 ASSERT_VK_SUCCESS(err);
Chia-I Wuf7458c52015-10-26 21:10:41 +08002714 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlise68360f2015-10-01 11:15:13 -06002715
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002716 if (!m_errorMonitor->DesiredMsgFound()) {
2717 FAIL() << "Did not receive Error 'Gfx Pipeline viewport count (1) must match scissor count (0).'";
2718 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlise68360f2015-10-01 11:15:13 -06002719 }
2720
Chia-I Wuf7458c52015-10-26 21:10:41 +08002721 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
2722 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
2723 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
2724 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlise68360f2015-10-01 11:15:13 -06002725}
Tobin Ehlisd332f282015-10-02 11:00:56 -06002726// Don't set viewport state in PSO. This is an error b/c we always need this state
2727// for the counts even if the data is going to be set dynamically.
2728TEST_F(VkLayerTest, PSOViewportStateNotSet)
Tobin Ehlise68360f2015-10-01 11:15:13 -06002729{
2730 // Attempt to Create Gfx Pipeline w/o a VS
Tobin Ehlise68360f2015-10-01 11:15:13 -06002731 VkResult err;
2732
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07002733 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002734 "Gfx Pipeline pViewportState is null. Even if ");
2735
Tobin Ehlise68360f2015-10-01 11:15:13 -06002736 ASSERT_NO_FATAL_FAILURE(InitState());
2737 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlise68360f2015-10-01 11:15:13 -06002738
Chia-I Wu1b99bb22015-10-27 19:25:11 +08002739 VkDescriptorPoolSize ds_type_count = {};
Tobin Ehlise68360f2015-10-01 11:15:13 -06002740 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wud50a7d72015-10-26 20:48:51 +08002741 ds_type_count.descriptorCount = 1;
Tobin Ehlise68360f2015-10-01 11:15:13 -06002742
2743 VkDescriptorPoolCreateInfo ds_pool_ci = {};
2744 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
Tobin Ehlise68360f2015-10-01 11:15:13 -06002745 ds_pool_ci.maxSets = 1;
Chia-I Wu1b99bb22015-10-27 19:25:11 +08002746 ds_pool_ci.poolSizeCount = 1;
2747 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlise68360f2015-10-01 11:15:13 -06002748
2749 VkDescriptorPool ds_pool;
Chia-I Wuf7458c52015-10-26 21:10:41 +08002750 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlise68360f2015-10-01 11:15:13 -06002751 ASSERT_VK_SUCCESS(err);
2752
2753 VkDescriptorSetLayoutBinding dsl_binding = {};
Chia-I Wud46e6ae2015-10-31 00:31:16 +08002754 dsl_binding.binding = 0;
Tobin Ehlise68360f2015-10-01 11:15:13 -06002755 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wu02124482015-11-06 06:42:02 +08002756 dsl_binding.descriptorCount = 1;
Tobin Ehlise68360f2015-10-01 11:15:13 -06002757 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
2758
2759 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
2760 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
Chia-I Wud50a7d72015-10-26 20:48:51 +08002761 ds_layout_ci.bindingCount = 1;
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07002762 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlise68360f2015-10-01 11:15:13 -06002763
2764 VkDescriptorSetLayout ds_layout;
Chia-I Wuf7458c52015-10-26 21:10:41 +08002765 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06002766 ASSERT_VK_SUCCESS(err);
2767
2768 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002769 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08002770 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Chia-I Wud50a7d72015-10-26 20:48:51 +08002771 alloc_info.setLayoutCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06002772 alloc_info.descriptorPool = ds_pool;
2773 alloc_info.pSetLayouts = &ds_layout;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002774 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlise68360f2015-10-01 11:15:13 -06002775 ASSERT_VK_SUCCESS(err);
2776
2777 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
2778 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
Chia-I Wud50a7d72015-10-26 20:48:51 +08002779 pipeline_layout_ci.setLayoutCount = 1;
Tobin Ehlise68360f2015-10-01 11:15:13 -06002780 pipeline_layout_ci.pSetLayouts = &ds_layout;
2781
2782 VkPipelineLayout pipeline_layout;
Chia-I Wuf7458c52015-10-26 21:10:41 +08002783 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06002784 ASSERT_VK_SUCCESS(err);
2785
2786 VkDynamicState sc_state = VK_DYNAMIC_STATE_SCISSOR;
2787 // Set scissor as dynamic to avoid second error
2788 VkPipelineDynamicStateCreateInfo dyn_state_ci = {};
2789 dyn_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
2790 dyn_state_ci.dynamicStateCount = 1;
2791 dyn_state_ci.pDynamicStates = &sc_state;
2792
Cody Northropeb3a6c12015-10-05 14:44:45 -06002793 VkPipelineShaderStageCreateInfo shaderStages[2];
2794 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
Tobin Ehlise68360f2015-10-01 11:15:13 -06002795
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06002796 VkShaderObj vs(m_device,bindStateVertShaderText,VK_SHADER_STAGE_VERTEX_BIT, this);
2797 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this); // TODO - We shouldn't need a fragment shader
Cody Northropeb3a6c12015-10-05 14:44:45 -06002798 // but add it to be able to run on more devices
Chia-I Wu28e06912015-10-31 00:31:16 +08002799 shaderStages[0] = vs.GetStageCreateInfo();
2800 shaderStages[1] = fs.GetStageCreateInfo();
Tobin Ehlise68360f2015-10-01 11:15:13 -06002801
2802 VkGraphicsPipelineCreateInfo gp_ci = {};
2803 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
Cody Northropeb3a6c12015-10-05 14:44:45 -06002804 gp_ci.stageCount = 2;
2805 gp_ci.pStages = shaderStages;
Tobin Ehlise68360f2015-10-01 11:15:13 -06002806 gp_ci.pViewportState = NULL; // Not setting VP state w/o dynamic vp state should cause validation error
2807 gp_ci.pDynamicState = &dyn_state_ci;
2808 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
2809 gp_ci.layout = pipeline_layout;
2810 gp_ci.renderPass = renderPass();
2811
2812 VkPipelineCacheCreateInfo pc_ci = {};
2813 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
2814
2815 VkPipeline pipeline;
2816 VkPipelineCache pipelineCache;
2817
Chia-I Wuf7458c52015-10-26 21:10:41 +08002818 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Tobin Ehlise68360f2015-10-01 11:15:13 -06002819 ASSERT_VK_SUCCESS(err);
Chia-I Wuf7458c52015-10-26 21:10:41 +08002820 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlise68360f2015-10-01 11:15:13 -06002821
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002822 if (!m_errorMonitor->DesiredMsgFound()) {
2823 FAIL() << "Did not receive Error 'Gfx Pipeline pViewportState is null. Even if...'";
2824 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlise68360f2015-10-01 11:15:13 -06002825 }
2826
Chia-I Wuf7458c52015-10-26 21:10:41 +08002827 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
2828 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
2829 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
2830 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlise68360f2015-10-01 11:15:13 -06002831}
2832// Create PSO w/o non-zero viewportCount but no viewport data
Tobin Ehlisd332f282015-10-02 11:00:56 -06002833// Then run second test where dynamic scissor count doesn't match PSO scissor count
2834TEST_F(VkLayerTest, PSOViewportCountWithoutDataAndDynScissorMismatch)
Tobin Ehlise68360f2015-10-01 11:15:13 -06002835{
Tobin Ehlise68360f2015-10-01 11:15:13 -06002836 VkResult err;
2837
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07002838 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002839 "Gfx Pipeline viewportCount is 1, but pViewports is NULL. ");
2840
Tobin Ehlise68360f2015-10-01 11:15:13 -06002841 ASSERT_NO_FATAL_FAILURE(InitState());
2842 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlise68360f2015-10-01 11:15:13 -06002843
Chia-I Wu1b99bb22015-10-27 19:25:11 +08002844 VkDescriptorPoolSize ds_type_count = {};
Tobin Ehlise68360f2015-10-01 11:15:13 -06002845 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wud50a7d72015-10-26 20:48:51 +08002846 ds_type_count.descriptorCount = 1;
Tobin Ehlise68360f2015-10-01 11:15:13 -06002847
2848 VkDescriptorPoolCreateInfo ds_pool_ci = {};
2849 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
Tobin Ehlise68360f2015-10-01 11:15:13 -06002850 ds_pool_ci.maxSets = 1;
Chia-I Wu1b99bb22015-10-27 19:25:11 +08002851 ds_pool_ci.poolSizeCount = 1;
2852 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlise68360f2015-10-01 11:15:13 -06002853
2854 VkDescriptorPool ds_pool;
Chia-I Wuf7458c52015-10-26 21:10:41 +08002855 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlise68360f2015-10-01 11:15:13 -06002856 ASSERT_VK_SUCCESS(err);
2857
2858 VkDescriptorSetLayoutBinding dsl_binding = {};
Chia-I Wud46e6ae2015-10-31 00:31:16 +08002859 dsl_binding.binding = 0;
Tobin Ehlise68360f2015-10-01 11:15:13 -06002860 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wu02124482015-11-06 06:42:02 +08002861 dsl_binding.descriptorCount = 1;
Tobin Ehlise68360f2015-10-01 11:15:13 -06002862 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
2863
2864 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
2865 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
Chia-I Wud50a7d72015-10-26 20:48:51 +08002866 ds_layout_ci.bindingCount = 1;
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07002867 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlise68360f2015-10-01 11:15:13 -06002868
2869 VkDescriptorSetLayout ds_layout;
Chia-I Wuf7458c52015-10-26 21:10:41 +08002870 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06002871 ASSERT_VK_SUCCESS(err);
2872
2873 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002874 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08002875 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Chia-I Wud50a7d72015-10-26 20:48:51 +08002876 alloc_info.setLayoutCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06002877 alloc_info.descriptorPool = ds_pool;
2878 alloc_info.pSetLayouts = &ds_layout;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002879 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlise68360f2015-10-01 11:15:13 -06002880 ASSERT_VK_SUCCESS(err);
2881
2882 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
2883 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
Chia-I Wud50a7d72015-10-26 20:48:51 +08002884 pipeline_layout_ci.setLayoutCount = 1;
Tobin Ehlise68360f2015-10-01 11:15:13 -06002885 pipeline_layout_ci.pSetLayouts = &ds_layout;
2886
2887 VkPipelineLayout pipeline_layout;
Chia-I Wuf7458c52015-10-26 21:10:41 +08002888 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06002889 ASSERT_VK_SUCCESS(err);
2890
2891 VkPipelineViewportStateCreateInfo vp_state_ci = {};
2892 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
2893 vp_state_ci.viewportCount = 1;
2894 vp_state_ci.pViewports = NULL; // Null vp w/ count of 1 should cause error
2895 vp_state_ci.scissorCount = 1;
2896 vp_state_ci.pScissors = NULL; // Scissor is dynamic (below) so this won't cause error
2897
2898 VkDynamicState sc_state = VK_DYNAMIC_STATE_SCISSOR;
2899 // Set scissor as dynamic to avoid that error
2900 VkPipelineDynamicStateCreateInfo dyn_state_ci = {};
2901 dyn_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
2902 dyn_state_ci.dynamicStateCount = 1;
2903 dyn_state_ci.pDynamicStates = &sc_state;
2904
Cody Northropeb3a6c12015-10-05 14:44:45 -06002905 VkPipelineShaderStageCreateInfo shaderStages[2];
2906 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
Tobin Ehlise68360f2015-10-01 11:15:13 -06002907
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06002908 VkShaderObj vs(m_device,bindStateVertShaderText,VK_SHADER_STAGE_VERTEX_BIT, this);
2909 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this); // TODO - We shouldn't need a fragment shader
Cody Northropeb3a6c12015-10-05 14:44:45 -06002910 // but add it to be able to run on more devices
Chia-I Wu28e06912015-10-31 00:31:16 +08002911 shaderStages[0] = vs.GetStageCreateInfo();
2912 shaderStages[1] = fs.GetStageCreateInfo();
Tobin Ehlise68360f2015-10-01 11:15:13 -06002913
Cody Northropf6622dc2015-10-06 10:33:21 -06002914 VkPipelineVertexInputStateCreateInfo vi_ci = {};
2915 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
2916 vi_ci.pNext = nullptr;
Chia-I Wud50a7d72015-10-26 20:48:51 +08002917 vi_ci.vertexBindingDescriptionCount = 0;
Cody Northropf6622dc2015-10-06 10:33:21 -06002918 vi_ci.pVertexBindingDescriptions = nullptr;
Chia-I Wud50a7d72015-10-26 20:48:51 +08002919 vi_ci.vertexAttributeDescriptionCount = 0;
Cody Northropf6622dc2015-10-06 10:33:21 -06002920 vi_ci.pVertexAttributeDescriptions = nullptr;
2921
2922 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
2923 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
2924 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
2925
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002926 VkPipelineRasterizationStateCreateInfo rs_ci = {};
Chia-I Wu1b99bb22015-10-27 19:25:11 +08002927 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
Cody Northropf6622dc2015-10-06 10:33:21 -06002928 rs_ci.pNext = nullptr;
2929
2930 VkPipelineColorBlendStateCreateInfo cb_ci = {};
2931 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
2932 cb_ci.pNext = nullptr;
2933
Tobin Ehlise68360f2015-10-01 11:15:13 -06002934 VkGraphicsPipelineCreateInfo gp_ci = {};
2935 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
Cody Northropeb3a6c12015-10-05 14:44:45 -06002936 gp_ci.stageCount = 2;
2937 gp_ci.pStages = shaderStages;
Cody Northropf6622dc2015-10-06 10:33:21 -06002938 gp_ci.pVertexInputState = &vi_ci;
2939 gp_ci.pInputAssemblyState = &ia_ci;
Tobin Ehlise68360f2015-10-01 11:15:13 -06002940 gp_ci.pViewportState = &vp_state_ci;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002941 gp_ci.pRasterizationState = &rs_ci;
Cody Northropf6622dc2015-10-06 10:33:21 -06002942 gp_ci.pColorBlendState = &cb_ci;
Tobin Ehlise68360f2015-10-01 11:15:13 -06002943 gp_ci.pDynamicState = &dyn_state_ci;
2944 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
2945 gp_ci.layout = pipeline_layout;
2946 gp_ci.renderPass = renderPass();
2947
2948 VkPipelineCacheCreateInfo pc_ci = {};
2949 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
2950
2951 VkPipeline pipeline;
2952 VkPipelineCache pipelineCache;
2953
Chia-I Wuf7458c52015-10-26 21:10:41 +08002954 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Tobin Ehlise68360f2015-10-01 11:15:13 -06002955 ASSERT_VK_SUCCESS(err);
Chia-I Wuf7458c52015-10-26 21:10:41 +08002956 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlise68360f2015-10-01 11:15:13 -06002957
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002958 if (!m_errorMonitor->DesiredMsgFound()) {
2959 FAIL() << "Did not recieve Error 'Gfx Pipeline viewportCount is 1, but pViewports is NULL...'";
2960 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlise68360f2015-10-01 11:15:13 -06002961 }
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002962
2963
Tobin Ehlisd332f282015-10-02 11:00:56 -06002964 // Now hit second fail case where we set scissor w/ different count than PSO
2965 // First need to successfully create the PSO from above by setting pViewports
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07002966 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002967 "Dynamic scissorCount from vkCmdSetScissor() is 2, but PSO scissorCount is 1. These counts must match.");
2968
Tobin Ehlisd332f282015-10-02 11:00:56 -06002969 VkViewport vp = {}; // Just need dummy vp to point to
2970 vp_state_ci.pViewports = &vp;
Chia-I Wuf7458c52015-10-26 21:10:41 +08002971 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlisd332f282015-10-02 11:00:56 -06002972 ASSERT_VK_SUCCESS(err);
2973 BeginCommandBuffer();
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002974 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
Tobin Ehlisd332f282015-10-02 11:00:56 -06002975 VkRect2D scissors[2] = {}; // don't care about data
2976 // Count of 2 doesn't match PSO count of 1
Jon Ashburn19d3bf12015-12-30 14:06:55 -07002977 vkCmdSetScissor(m_commandBuffer->GetBufferHandle(), 0, 2, scissors);
Tobin Ehlisd332f282015-10-02 11:00:56 -06002978 Draw(1, 0, 0, 0);
2979
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002980 if (!m_errorMonitor->DesiredMsgFound()) {
2981 FAIL() << "Did not receive Error 'Dynamic scissorCount from vkCmdSetScissor() is 2, but PSO scissorCount is 1...'";
2982 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlisd332f282015-10-02 11:00:56 -06002983 }
Tobin Ehlise68360f2015-10-01 11:15:13 -06002984
Chia-I Wuf7458c52015-10-26 21:10:41 +08002985 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
2986 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
2987 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
2988 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlise68360f2015-10-01 11:15:13 -06002989}
2990// Create PSO w/o non-zero scissorCount but no scissor data
Tobin Ehlisd332f282015-10-02 11:00:56 -06002991// Then run second test where dynamic viewportCount doesn't match PSO viewportCount
2992TEST_F(VkLayerTest, PSOScissorCountWithoutDataAndDynViewportMismatch)
Tobin Ehlise68360f2015-10-01 11:15:13 -06002993{
Tobin Ehlise68360f2015-10-01 11:15:13 -06002994 VkResult err;
2995
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07002996 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002997 "Gfx Pipeline scissorCount is 1, but pScissors is NULL. ");
2998
Tobin Ehlise68360f2015-10-01 11:15:13 -06002999 ASSERT_NO_FATAL_FAILURE(InitState());
3000 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlise68360f2015-10-01 11:15:13 -06003001
Chia-I Wu1b99bb22015-10-27 19:25:11 +08003002 VkDescriptorPoolSize ds_type_count = {};
Tobin Ehlise68360f2015-10-01 11:15:13 -06003003 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wud50a7d72015-10-26 20:48:51 +08003004 ds_type_count.descriptorCount = 1;
Tobin Ehlise68360f2015-10-01 11:15:13 -06003005
3006 VkDescriptorPoolCreateInfo ds_pool_ci = {};
3007 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
Tobin Ehlise68360f2015-10-01 11:15:13 -06003008 ds_pool_ci.maxSets = 1;
Chia-I Wu1b99bb22015-10-27 19:25:11 +08003009 ds_pool_ci.poolSizeCount = 1;
3010 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlise68360f2015-10-01 11:15:13 -06003011
3012 VkDescriptorPool ds_pool;
Chia-I Wuf7458c52015-10-26 21:10:41 +08003013 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlise68360f2015-10-01 11:15:13 -06003014 ASSERT_VK_SUCCESS(err);
3015
3016 VkDescriptorSetLayoutBinding dsl_binding = {};
Chia-I Wud46e6ae2015-10-31 00:31:16 +08003017 dsl_binding.binding = 0;
Tobin Ehlise68360f2015-10-01 11:15:13 -06003018 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wu02124482015-11-06 06:42:02 +08003019 dsl_binding.descriptorCount = 1;
Tobin Ehlise68360f2015-10-01 11:15:13 -06003020 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
3021
3022 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
3023 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
Chia-I Wud50a7d72015-10-26 20:48:51 +08003024 ds_layout_ci.bindingCount = 1;
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07003025 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlise68360f2015-10-01 11:15:13 -06003026
3027 VkDescriptorSetLayout ds_layout;
Chia-I Wuf7458c52015-10-26 21:10:41 +08003028 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06003029 ASSERT_VK_SUCCESS(err);
3030
3031 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003032 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08003033 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Chia-I Wud50a7d72015-10-26 20:48:51 +08003034 alloc_info.setLayoutCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06003035 alloc_info.descriptorPool = ds_pool;
3036 alloc_info.pSetLayouts = &ds_layout;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003037 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlise68360f2015-10-01 11:15:13 -06003038 ASSERT_VK_SUCCESS(err);
3039
3040 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
3041 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
Chia-I Wud50a7d72015-10-26 20:48:51 +08003042 pipeline_layout_ci.setLayoutCount = 1;
Tobin Ehlise68360f2015-10-01 11:15:13 -06003043 pipeline_layout_ci.pSetLayouts = &ds_layout;
3044
3045 VkPipelineLayout pipeline_layout;
Chia-I Wuf7458c52015-10-26 21:10:41 +08003046 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06003047 ASSERT_VK_SUCCESS(err);
3048
3049 VkPipelineViewportStateCreateInfo vp_state_ci = {};
3050 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
3051 vp_state_ci.scissorCount = 1;
3052 vp_state_ci.pScissors = NULL; // Null scissor w/ count of 1 should cause error
3053 vp_state_ci.viewportCount = 1;
3054 vp_state_ci.pViewports = NULL; // vp is dynamic (below) so this won't cause error
3055
3056 VkDynamicState vp_state = VK_DYNAMIC_STATE_VIEWPORT;
3057 // Set scissor as dynamic to avoid that error
3058 VkPipelineDynamicStateCreateInfo dyn_state_ci = {};
3059 dyn_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
3060 dyn_state_ci.dynamicStateCount = 1;
3061 dyn_state_ci.pDynamicStates = &vp_state;
3062
Cody Northropeb3a6c12015-10-05 14:44:45 -06003063 VkPipelineShaderStageCreateInfo shaderStages[2];
3064 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
Tobin Ehlise68360f2015-10-01 11:15:13 -06003065
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06003066 VkShaderObj vs(m_device,bindStateVertShaderText,VK_SHADER_STAGE_VERTEX_BIT, this);
3067 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this); // TODO - We shouldn't need a fragment shader
Cody Northropeb3a6c12015-10-05 14:44:45 -06003068 // but add it to be able to run on more devices
Chia-I Wu28e06912015-10-31 00:31:16 +08003069 shaderStages[0] = vs.GetStageCreateInfo();
3070 shaderStages[1] = fs.GetStageCreateInfo();
Tobin Ehlise68360f2015-10-01 11:15:13 -06003071
Cody Northropf6622dc2015-10-06 10:33:21 -06003072 VkPipelineVertexInputStateCreateInfo vi_ci = {};
3073 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
3074 vi_ci.pNext = nullptr;
Chia-I Wud50a7d72015-10-26 20:48:51 +08003075 vi_ci.vertexBindingDescriptionCount = 0;
Cody Northropf6622dc2015-10-06 10:33:21 -06003076 vi_ci.pVertexBindingDescriptions = nullptr;
Chia-I Wud50a7d72015-10-26 20:48:51 +08003077 vi_ci.vertexAttributeDescriptionCount = 0;
Cody Northropf6622dc2015-10-06 10:33:21 -06003078 vi_ci.pVertexAttributeDescriptions = nullptr;
3079
3080 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
3081 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
3082 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
3083
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003084 VkPipelineRasterizationStateCreateInfo rs_ci = {};
Chia-I Wu1b99bb22015-10-27 19:25:11 +08003085 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
Cody Northropf6622dc2015-10-06 10:33:21 -06003086 rs_ci.pNext = nullptr;
3087
3088 VkPipelineColorBlendStateCreateInfo cb_ci = {};
3089 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
3090 cb_ci.pNext = nullptr;
3091
Tobin Ehlise68360f2015-10-01 11:15:13 -06003092 VkGraphicsPipelineCreateInfo gp_ci = {};
3093 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
Cody Northropeb3a6c12015-10-05 14:44:45 -06003094 gp_ci.stageCount = 2;
3095 gp_ci.pStages = shaderStages;
Cody Northropf6622dc2015-10-06 10:33:21 -06003096 gp_ci.pVertexInputState = &vi_ci;
3097 gp_ci.pInputAssemblyState = &ia_ci;
Tobin Ehlise68360f2015-10-01 11:15:13 -06003098 gp_ci.pViewportState = &vp_state_ci;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003099 gp_ci.pRasterizationState = &rs_ci;
Cody Northropf6622dc2015-10-06 10:33:21 -06003100 gp_ci.pColorBlendState = &cb_ci;
Tobin Ehlise68360f2015-10-01 11:15:13 -06003101 gp_ci.pDynamicState = &dyn_state_ci;
3102 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
3103 gp_ci.layout = pipeline_layout;
3104 gp_ci.renderPass = renderPass();
3105
3106 VkPipelineCacheCreateInfo pc_ci = {};
3107 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
3108
3109 VkPipeline pipeline;
3110 VkPipelineCache pipelineCache;
3111
Chia-I Wuf7458c52015-10-26 21:10:41 +08003112 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Tobin Ehlise68360f2015-10-01 11:15:13 -06003113 ASSERT_VK_SUCCESS(err);
Chia-I Wuf7458c52015-10-26 21:10:41 +08003114 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlise68360f2015-10-01 11:15:13 -06003115
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06003116 if (!m_errorMonitor->DesiredMsgFound()) {
3117 FAIL() << "Did not recieve Error 'Gfx Pipeline scissorCount is 1, but pScissors is NULL...'";
3118 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlise68360f2015-10-01 11:15:13 -06003119 }
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06003120
Tobin Ehlisd332f282015-10-02 11:00:56 -06003121 // Now hit second fail case where we set scissor w/ different count than PSO
3122 // First need to successfully create the PSO from above by setting pViewports
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07003123 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06003124 "Dynamic viewportCount from vkCmdSetViewport() is 2, but PSO viewportCount is 1. These counts must match.");
3125
Tobin Ehlisd332f282015-10-02 11:00:56 -06003126 VkRect2D sc = {}; // Just need dummy vp to point to
3127 vp_state_ci.pScissors = &sc;
Chia-I Wuf7458c52015-10-26 21:10:41 +08003128 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlisd332f282015-10-02 11:00:56 -06003129 ASSERT_VK_SUCCESS(err);
3130 BeginCommandBuffer();
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003131 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
Tobin Ehlisd332f282015-10-02 11:00:56 -06003132 VkViewport viewports[2] = {}; // don't care about data
3133 // Count of 2 doesn't match PSO count of 1
Jon Ashburn19d3bf12015-12-30 14:06:55 -07003134 vkCmdSetViewport(m_commandBuffer->GetBufferHandle(), 0, 2, viewports);
Tobin Ehlisd332f282015-10-02 11:00:56 -06003135 Draw(1, 0, 0, 0);
3136
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06003137 if (!m_errorMonitor->DesiredMsgFound()) {
3138 FAIL() << "Did not receive Error 'Dynamic viewportCount from vkCmdSetViewport() is 2, but PSO viewportCount is 1...'";
3139 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlisd332f282015-10-02 11:00:56 -06003140 }
Tobin Ehlise68360f2015-10-01 11:15:13 -06003141
Chia-I Wuf7458c52015-10-26 21:10:41 +08003142 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
3143 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
3144 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
3145 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlise68360f2015-10-01 11:15:13 -06003146}
3147
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06003148TEST_F(VkLayerTest, NullRenderPass)
3149{
3150 // Bind a NULL RenderPass
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07003151 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06003152 "You cannot use a NULL RenderPass object in vkCmdBeginRenderPass()");
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06003153
3154 ASSERT_NO_FATAL_FAILURE(InitState());
3155 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06003156
Tony Barbourfe3351b2015-07-28 10:17:20 -06003157 BeginCommandBuffer();
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06003158 // Don't care about RenderPass handle b/c error should be flagged before that
Chia-I Wu1b99bb22015-10-27 19:25:11 +08003159 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), NULL, VK_SUBPASS_CONTENTS_INLINE);
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06003160
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06003161 if (!m_errorMonitor->DesiredMsgFound()) {
3162 FAIL() << "Did not receive Error 'You cannot use a NULL RenderPass object in vkCmdBeginRenderPass()'";
3163 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06003164 }
3165}
3166
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06003167TEST_F(VkLayerTest, RenderPassWithinRenderPass)
3168{
3169 // Bind a BeginRenderPass within an active RenderPass
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07003170 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06003171 "It is invalid to issue this call inside an active render pass");
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06003172
3173 ASSERT_NO_FATAL_FAILURE(InitState());
3174 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06003175
Tony Barbourfe3351b2015-07-28 10:17:20 -06003176 BeginCommandBuffer();
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06003177 // Just create a dummy Renderpass that's non-NULL so we can get to the proper error
Tony Barboureb254902015-07-15 12:50:33 -06003178 VkRenderPassBeginInfo rp_begin = {};
3179 rp_begin.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO;
3180 rp_begin.pNext = NULL;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06003181 rp_begin.renderPass = renderPass();
3182 rp_begin.framebuffer = framebuffer();
Mark Lobodzinski209b5292015-09-17 09:44:05 -06003183
Chia-I Wu1b99bb22015-10-27 19:25:11 +08003184 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &rp_begin, VK_SUBPASS_CONTENTS_INLINE);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06003185
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06003186 if (!m_errorMonitor->DesiredMsgFound()) {
3187 FAIL() << "Did not receive Error 'It is invalid to issue this call inside an active render pass...'";
3188 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06003189 }
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06003190}
3191
Mark Lobodzinskid5639502015-09-24 09:51:47 -06003192TEST_F(VkLayerTest, FillBufferWithinRenderPass)
3193{
3194 // Call CmdFillBuffer within an active renderpass
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07003195 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06003196 "It is invalid to issue this call inside an active render pass");
Mark Lobodzinskid5639502015-09-24 09:51:47 -06003197
3198 ASSERT_NO_FATAL_FAILURE(InitState());
3199 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskid5639502015-09-24 09:51:47 -06003200
3201 // Renderpass is started here
3202 BeginCommandBuffer();
3203
3204 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003205 vk_testing::Buffer dstBuffer;
3206 dstBuffer.init_as_dst(*m_device, (VkDeviceSize)1024, reqs);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06003207
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003208 m_commandBuffer->FillBuffer(dstBuffer.handle(), 0, 4, 0x11111111);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06003209
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06003210 if (!m_errorMonitor->DesiredMsgFound()) {
3211 FAIL() << "Did not receive Error 'It is invalid to issue this call inside an active render pass...'";
3212 m_errorMonitor->DumpFailureMsgs();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06003213 }
3214}
3215
3216TEST_F(VkLayerTest, UpdateBufferWithinRenderPass)
3217{
3218 // Call CmdUpdateBuffer within an active renderpass
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07003219 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06003220 "It is invalid to issue this call inside an active render pass");
Mark Lobodzinskid5639502015-09-24 09:51:47 -06003221
3222 ASSERT_NO_FATAL_FAILURE(InitState());
3223 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskid5639502015-09-24 09:51:47 -06003224
3225 // Renderpass is started here
3226 BeginCommandBuffer();
3227
3228 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003229 vk_testing::Buffer dstBuffer;
3230 dstBuffer.init_as_dst(*m_device, (VkDeviceSize)1024, reqs);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06003231
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003232 VkDeviceSize dstOffset = 0;
Mark Lobodzinskid5639502015-09-24 09:51:47 -06003233 VkDeviceSize dataSize = 1024;
3234 const uint32_t *pData = NULL;
3235
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003236 vkCmdUpdateBuffer(m_commandBuffer->GetBufferHandle(), dstBuffer.handle(), dstOffset, dataSize, pData);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06003237
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06003238 if (!m_errorMonitor->DesiredMsgFound()) {
3239 FAIL() << "Did not receive Error 'It is invalid to issue this call inside an active render pass...'";
3240 m_errorMonitor->DumpFailureMsgs();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06003241 }
3242}
3243
3244TEST_F(VkLayerTest, ClearColorImageWithinRenderPass)
3245{
3246 // Call CmdClearColorImage within an active RenderPass
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07003247 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06003248 "It is invalid to issue this call inside an active render pass");
Mark Lobodzinskid5639502015-09-24 09:51:47 -06003249
3250 ASSERT_NO_FATAL_FAILURE(InitState());
3251 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskid5639502015-09-24 09:51:47 -06003252
3253 // Renderpass is started here
3254 BeginCommandBuffer();
3255
3256 VkClearColorValue clear_color = {0};
3257 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
3258 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
3259 const int32_t tex_width = 32;
3260 const int32_t tex_height = 32;
3261 VkImageCreateInfo image_create_info = {};
3262 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
3263 image_create_info.pNext = NULL;
3264 image_create_info.imageType = VK_IMAGE_TYPE_2D;
3265 image_create_info.format = tex_format;
3266 image_create_info.extent.width = tex_width;
3267 image_create_info.extent.height = tex_height;
3268 image_create_info.extent.depth = 1;
3269 image_create_info.mipLevels = 1;
Courtney Goeltzenleuchter5d2aed42015-10-21 17:57:31 -06003270 image_create_info.arrayLayers = 1;
Chia-I Wu5c17c962015-10-31 00:31:16 +08003271 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Mark Lobodzinskid5639502015-09-24 09:51:47 -06003272 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
3273 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
3274
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003275 vk_testing::Image dstImage;
3276 dstImage.init(*m_device, (const VkImageCreateInfo&)image_create_info, reqs);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06003277
3278 const VkImageSubresourceRange range =
3279 vk_testing::Image::subresource_range(image_create_info, VK_IMAGE_ASPECT_COLOR_BIT);
3280
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003281 vkCmdClearColorImage(m_commandBuffer->GetBufferHandle(),
3282 dstImage.handle(),
Mark Lobodzinskid5639502015-09-24 09:51:47 -06003283 VK_IMAGE_LAYOUT_GENERAL,
3284 &clear_color,
3285 1,
3286 &range);
3287
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06003288 if (!m_errorMonitor->DesiredMsgFound()) {
3289 FAIL() << "Did not receive Error 'It is invalid to issue this call inside an active render pass...'";
3290 m_errorMonitor->DumpFailureMsgs();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06003291 }
3292}
3293
3294TEST_F(VkLayerTest, ClearDepthStencilImageWithinRenderPass)
3295{
3296 // Call CmdClearDepthStencilImage within an active RenderPass
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07003297 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06003298 "It is invalid to issue this call inside an active render pass");
Mark Lobodzinskid5639502015-09-24 09:51:47 -06003299
3300 ASSERT_NO_FATAL_FAILURE(InitState());
3301 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskid5639502015-09-24 09:51:47 -06003302
3303 // Renderpass is started here
3304 BeginCommandBuffer();
3305
3306 VkClearDepthStencilValue clear_value = {0};
3307 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
3308 VkImageCreateInfo image_create_info = vk_testing::Image::create_info();
3309 image_create_info.imageType = VK_IMAGE_TYPE_2D;
3310 image_create_info.format = VK_FORMAT_D24_UNORM_S8_UINT;
3311 image_create_info.extent.width = 64;
3312 image_create_info.extent.height = 64;
3313 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
3314 image_create_info.usage = VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT;
3315
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003316 vk_testing::Image dstImage;
3317 dstImage.init(*m_device, (const VkImageCreateInfo&)image_create_info, reqs);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06003318
3319 const VkImageSubresourceRange range =
3320 vk_testing::Image::subresource_range(image_create_info, VK_IMAGE_ASPECT_DEPTH_BIT);
3321
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003322 vkCmdClearDepthStencilImage(m_commandBuffer->GetBufferHandle(),
3323 dstImage.handle(),
Mark Lobodzinskid5639502015-09-24 09:51:47 -06003324 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL,
3325 &clear_value,
3326 1,
3327 &range);
3328
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06003329 if (!m_errorMonitor->DesiredMsgFound()) {
3330 FAIL() << "Did not receive Error 'It is invalid to issue this call inside an active render pass...'";
3331 m_errorMonitor->DumpFailureMsgs();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06003332 }
3333}
3334
3335TEST_F(VkLayerTest, ClearColorAttachmentsOutsideRenderPass)
3336{
Courtney Goeltzenleuchterc9323e02015-10-15 16:51:05 -06003337 // Call CmdClearAttachmentss outside of an active RenderPass
Mark Lobodzinskid5639502015-09-24 09:51:47 -06003338 VkResult err;
3339
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07003340 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06003341 "vkCmdClearAttachments: This call must be issued inside an active render pass");
3342
Mark Lobodzinskid5639502015-09-24 09:51:47 -06003343 ASSERT_NO_FATAL_FAILURE(InitState());
3344 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskid5639502015-09-24 09:51:47 -06003345
3346 // Start no RenderPass
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003347 err = m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06003348 ASSERT_VK_SUCCESS(err);
3349
Courtney Goeltzenleuchterc9323e02015-10-15 16:51:05 -06003350 VkClearAttachment color_attachment;
3351 color_attachment.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
3352 color_attachment.clearValue.color.float32[0] = 0;
3353 color_attachment.clearValue.color.float32[1] = 0;
3354 color_attachment.clearValue.color.float32[2] = 0;
3355 color_attachment.clearValue.color.float32[3] = 0;
3356 color_attachment.colorAttachment = 0;
Courtney Goeltzenleuchter5d2aed42015-10-21 17:57:31 -06003357 VkClearRect clear_rect = { { { 0, 0 }, { 32, 32 } } };
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003358 vkCmdClearAttachments(m_commandBuffer->GetBufferHandle(),
Courtney Goeltzenleuchterc9323e02015-10-15 16:51:05 -06003359 1, &color_attachment,
3360 1, &clear_rect);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06003361
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06003362 if (!m_errorMonitor->DesiredMsgFound()) {
3363 FAIL() << "Did not receive Error 'vkCmdClearAttachments: This call must be issued inside an active render pass.'";
3364 m_errorMonitor->DumpFailureMsgs();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06003365 }
3366}
3367
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06003368TEST_F(VkLayerTest, InvalidDynamicStateObject)
3369{
3370 // Create a valid cmd buffer
3371 // call vkCmdBindDynamicStateObject w/ false DS Obj
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06003372 // TODO : Simple check for bad object should be added to ObjectTracker to catch this case
3373 // The DS check for this is after driver has been called to validate DS internal data struct
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06003374}
Tobin Ehlis1056d452015-05-27 14:55:35 -06003375
Tobin Ehlisc4c23182015-09-17 12:24:13 -06003376TEST_F(VkLayerTest, IdxBufferAlignmentError)
3377{
3378 // Bind a BeginRenderPass within an active RenderPass
Tobin Ehlisc4c23182015-09-17 12:24:13 -06003379 VkResult err;
3380
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07003381 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06003382 "vkCmdBindIndexBuffer() offset (0x7) does not fall on ");
3383
Tobin Ehlisc4c23182015-09-17 12:24:13 -06003384 ASSERT_NO_FATAL_FAILURE(InitState());
3385 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlisc4c23182015-09-17 12:24:13 -06003386 uint32_t qfi = 0;
3387 VkBufferCreateInfo buffCI = {};
3388 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
3389 buffCI.size = 1024;
3390 buffCI.usage = VK_BUFFER_USAGE_INDEX_BUFFER_BIT;
Chia-I Wud50a7d72015-10-26 20:48:51 +08003391 buffCI.queueFamilyIndexCount = 1;
Tobin Ehlisc4c23182015-09-17 12:24:13 -06003392 buffCI.pQueueFamilyIndices = &qfi;
3393
3394 VkBuffer ib;
Chia-I Wuf7458c52015-10-26 21:10:41 +08003395 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &ib);
Tobin Ehlisc4c23182015-09-17 12:24:13 -06003396 ASSERT_VK_SUCCESS(err);
3397
3398 BeginCommandBuffer();
3399 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003400 //vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlisc4c23182015-09-17 12:24:13 -06003401 // Should error before calling to driver so don't care about actual data
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003402 vkCmdBindIndexBuffer(m_commandBuffer->GetBufferHandle(), ib, 7, VK_INDEX_TYPE_UINT16);
Tobin Ehlisc4c23182015-09-17 12:24:13 -06003403
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06003404 if (!m_errorMonitor->DesiredMsgFound()) {
3405 FAIL() << "Did not receive Error 'vkCmdBindIndexBuffer() offset (0x7) does not fall on ...'";
3406 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlisc4c23182015-09-17 12:24:13 -06003407 }
Mike Stroyand1c84a52015-08-18 14:40:24 -06003408
Chia-I Wuf7458c52015-10-26 21:10:41 +08003409 vkDestroyBuffer(m_device->device(), ib, NULL);
Tobin Ehlisc4c23182015-09-17 12:24:13 -06003410}
3411
Tobin Ehlis4b34ddc2015-09-17 14:18:16 -06003412TEST_F(VkLayerTest, ExecuteCommandsPrimaryCB)
3413{
3414 // Attempt vkCmdExecuteCommands w/ a primary cmd buffer (should only be secondary)
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06003415
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07003416 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06003417 "vkCmdExecuteCommands() called w/ Primary Cmd Buffer ");
Tobin Ehlis4b34ddc2015-09-17 14:18:16 -06003418
3419 ASSERT_NO_FATAL_FAILURE(InitState());
3420 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlis4b34ddc2015-09-17 14:18:16 -06003421
3422 BeginCommandBuffer();
3423 //ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003424 VkCommandBuffer primCB = m_commandBuffer->GetBufferHandle();
3425 vkCmdExecuteCommands(m_commandBuffer->GetBufferHandle(), 1, &primCB);
Tobin Ehlis4b34ddc2015-09-17 14:18:16 -06003426
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06003427 if (!m_errorMonitor->DesiredMsgFound()) {
3428 FAIL() << "Did not receive Error 'vkCmdExecuteCommands() called w/ Primary Cmd Buffer '";
3429 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlis4b34ddc2015-09-17 14:18:16 -06003430 }
3431}
3432
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06003433TEST_F(VkLayerTest, DSTypeMismatch)
3434{
3435 // Create DS w/ layout of one type and attempt Update w/ mis-matched type
Tobin Ehlis3b780662015-05-28 12:11:26 -06003436 VkResult err;
3437
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07003438 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06003439 "Write descriptor update has descriptor type VK_DESCRIPTOR_TYPE_SAMPLER that does not match ");
3440
Tobin Ehlis3b780662015-05-28 12:11:26 -06003441 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlis3b780662015-05-28 12:11:26 -06003442 //VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu1b99bb22015-10-27 19:25:11 +08003443 VkDescriptorPoolSize ds_type_count = {};
Tony Barboureb254902015-07-15 12:50:33 -06003444 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wud50a7d72015-10-26 20:48:51 +08003445 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06003446
3447 VkDescriptorPoolCreateInfo ds_pool_ci = {};
3448 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
3449 ds_pool_ci.pNext = NULL;
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -06003450 ds_pool_ci.maxSets = 1;
Chia-I Wu1b99bb22015-10-27 19:25:11 +08003451 ds_pool_ci.poolSizeCount = 1;
3452 ds_pool_ci.pPoolSizes = &ds_type_count;
Tony Barboureb254902015-07-15 12:50:33 -06003453
Tobin Ehlis3b780662015-05-28 12:11:26 -06003454 VkDescriptorPool ds_pool;
Chia-I Wuf7458c52015-10-26 21:10:41 +08003455 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -06003456 ASSERT_VK_SUCCESS(err);
Tony Barboureb254902015-07-15 12:50:33 -06003457 VkDescriptorSetLayoutBinding dsl_binding = {};
Chia-I Wud46e6ae2015-10-31 00:31:16 +08003458 dsl_binding.binding = 0;
Tony Barboureb254902015-07-15 12:50:33 -06003459 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wu02124482015-11-06 06:42:02 +08003460 dsl_binding.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06003461 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
3462 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis3b780662015-05-28 12:11:26 -06003463
Tony Barboureb254902015-07-15 12:50:33 -06003464 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
3465 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
3466 ds_layout_ci.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08003467 ds_layout_ci.bindingCount = 1;
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07003468 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -06003469
Tobin Ehlis3b780662015-05-28 12:11:26 -06003470 VkDescriptorSetLayout ds_layout;
Chia-I Wuf7458c52015-10-26 21:10:41 +08003471 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -06003472 ASSERT_VK_SUCCESS(err);
3473
3474 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003475 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08003476 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Chia-I Wud50a7d72015-10-26 20:48:51 +08003477 alloc_info.setLayoutCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06003478 alloc_info.descriptorPool = ds_pool;
3479 alloc_info.pSetLayouts = &ds_layout;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003480 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -06003481 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -06003482
Tony Barboureb254902015-07-15 12:50:33 -06003483 VkSamplerCreateInfo sampler_ci = {};
3484 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
3485 sampler_ci.pNext = NULL;
Chia-I Wub99df442015-10-26 16:49:32 +08003486 sampler_ci.magFilter = VK_FILTER_NEAREST;
3487 sampler_ci.minFilter = VK_FILTER_NEAREST;
3488 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_BASE;
Chia-I Wu1efb7e52015-10-26 17:32:47 +08003489 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
3490 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
3491 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
Tony Barboureb254902015-07-15 12:50:33 -06003492 sampler_ci.mipLodBias = 1.0;
Jon Ashburnddc8db52015-12-14 14:59:20 -07003493 sampler_ci.anisotropyEnable = VK_FALSE;
Tony Barboureb254902015-07-15 12:50:33 -06003494 sampler_ci.maxAnisotropy = 1;
3495 sampler_ci.compareEnable = VK_FALSE;
3496 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
3497 sampler_ci.minLod = 1.0;
3498 sampler_ci.maxLod = 1.0;
3499 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
Mark Lobodzinski52ac6582015-09-01 15:42:56 -06003500 sampler_ci.unnormalizedCoordinates = VK_FALSE;
3501
Tobin Ehlis3b780662015-05-28 12:11:26 -06003502 VkSampler sampler;
Chia-I Wuf7458c52015-10-26 21:10:41 +08003503 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
Tobin Ehlis3b780662015-05-28 12:11:26 -06003504 ASSERT_VK_SUCCESS(err);
3505
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -06003506 VkDescriptorImageInfo info = {};
3507 info.sampler = sampler;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08003508
3509 VkWriteDescriptorSet descriptor_write;
3510 memset(&descriptor_write, 0, sizeof(descriptor_write));
3511 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003512 descriptor_write.dstSet = descriptorSet;
Chia-I Wud50a7d72015-10-26 20:48:51 +08003513 descriptor_write.descriptorCount = 1;
Tobin Ehlis3b780662015-05-28 12:11:26 -06003514 // This is a mismatched type for the layout which expects BUFFER
Chia-I Wu9d00ed72015-05-25 16:27:55 +08003515 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -06003516 descriptor_write.pImageInfo = &info;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08003517
3518 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
3519
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06003520 if (!m_errorMonitor->DesiredMsgFound()) {
3521 FAIL() << "Did not receive Error 'Write descriptor update has descriptor type VK_DESCRIPTOR_TYPE_SAMPLER that does not match...'";
3522 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlis3b780662015-05-28 12:11:26 -06003523 }
Mike Stroyand1c84a52015-08-18 14:40:24 -06003524
Chia-I Wuf7458c52015-10-26 21:10:41 +08003525 vkDestroySampler(m_device->device(), sampler, NULL);
3526 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
3527 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06003528}
3529
3530TEST_F(VkLayerTest, DSUpdateOutOfBounds)
3531{
3532 // For overlapping Update, have arrayIndex exceed that of layout
Tobin Ehlis3b780662015-05-28 12:11:26 -06003533 VkResult err;
3534
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07003535 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06003536 "Descriptor update type of VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET is out of bounds for matching binding");
3537
Tobin Ehlis3b780662015-05-28 12:11:26 -06003538 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlis3b780662015-05-28 12:11:26 -06003539 //VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu1b99bb22015-10-27 19:25:11 +08003540 VkDescriptorPoolSize ds_type_count = {};
Tony Barboureb254902015-07-15 12:50:33 -06003541 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wud50a7d72015-10-26 20:48:51 +08003542 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06003543
3544 VkDescriptorPoolCreateInfo ds_pool_ci = {};
3545 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
3546 ds_pool_ci.pNext = NULL;
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -06003547 ds_pool_ci.maxSets = 1;
Chia-I Wu1b99bb22015-10-27 19:25:11 +08003548 ds_pool_ci.poolSizeCount = 1;
3549 ds_pool_ci.pPoolSizes = &ds_type_count;
Tony Barboureb254902015-07-15 12:50:33 -06003550
Tobin Ehlis3b780662015-05-28 12:11:26 -06003551 VkDescriptorPool ds_pool;
Chia-I Wuf7458c52015-10-26 21:10:41 +08003552 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -06003553 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -06003554
Tony Barboureb254902015-07-15 12:50:33 -06003555 VkDescriptorSetLayoutBinding dsl_binding = {};
Chia-I Wud46e6ae2015-10-31 00:31:16 +08003556 dsl_binding.binding = 0;
Tony Barboureb254902015-07-15 12:50:33 -06003557 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wu02124482015-11-06 06:42:02 +08003558 dsl_binding.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06003559 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
3560 dsl_binding.pImmutableSamplers = NULL;
3561
3562 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
3563 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
3564 ds_layout_ci.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08003565 ds_layout_ci.bindingCount = 1;
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07003566 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -06003567
Tobin Ehlis3b780662015-05-28 12:11:26 -06003568 VkDescriptorSetLayout ds_layout;
Chia-I Wuf7458c52015-10-26 21:10:41 +08003569 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -06003570 ASSERT_VK_SUCCESS(err);
3571
3572 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003573 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08003574 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Chia-I Wud50a7d72015-10-26 20:48:51 +08003575 alloc_info.setLayoutCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06003576 alloc_info.descriptorPool = ds_pool;
3577 alloc_info.pSetLayouts = &ds_layout;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003578 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -06003579 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -06003580
Tony Barboureb254902015-07-15 12:50:33 -06003581 VkSamplerCreateInfo sampler_ci = {};
3582 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
3583 sampler_ci.pNext = NULL;
Chia-I Wub99df442015-10-26 16:49:32 +08003584 sampler_ci.magFilter = VK_FILTER_NEAREST;
3585 sampler_ci.minFilter = VK_FILTER_NEAREST;
3586 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_BASE;
Chia-I Wu1efb7e52015-10-26 17:32:47 +08003587 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
3588 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
3589 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
Tony Barboureb254902015-07-15 12:50:33 -06003590 sampler_ci.mipLodBias = 1.0;
Jon Ashburnddc8db52015-12-14 14:59:20 -07003591 sampler_ci.anisotropyEnable = VK_FALSE;
Tony Barboureb254902015-07-15 12:50:33 -06003592 sampler_ci.maxAnisotropy = 1;
3593 sampler_ci.compareEnable = VK_FALSE;
3594 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
3595 sampler_ci.minLod = 1.0;
3596 sampler_ci.maxLod = 1.0;
3597 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
Mark Lobodzinski52ac6582015-09-01 15:42:56 -06003598 sampler_ci.unnormalizedCoordinates = VK_FALSE;
Tony Barboureb254902015-07-15 12:50:33 -06003599
Tobin Ehlis3b780662015-05-28 12:11:26 -06003600 VkSampler sampler;
Chia-I Wuf7458c52015-10-26 21:10:41 +08003601 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
Tobin Ehlis3b780662015-05-28 12:11:26 -06003602 ASSERT_VK_SUCCESS(err);
Chia-I Wu9d00ed72015-05-25 16:27:55 +08003603
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -06003604 VkDescriptorImageInfo info = {};
3605 info.sampler = sampler;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08003606
3607 VkWriteDescriptorSet descriptor_write;
3608 memset(&descriptor_write, 0, sizeof(descriptor_write));
3609 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003610 descriptor_write.dstSet = descriptorSet;
3611 descriptor_write.dstArrayElement = 1; /* This index out of bounds for the update */
Chia-I Wud50a7d72015-10-26 20:48:51 +08003612 descriptor_write.descriptorCount = 1;
Tobin Ehlis3b780662015-05-28 12:11:26 -06003613 // This is the wrong type, but out of bounds will be flagged first
Chia-I Wu9d00ed72015-05-25 16:27:55 +08003614 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -06003615 descriptor_write.pImageInfo = &info;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08003616
3617 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
3618
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06003619 if (!m_errorMonitor->DesiredMsgFound()) {
3620 FAIL() << "Did not receive Error 'Descriptor update type of VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET is out of bounds for matching binding...'";
3621 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlis3b780662015-05-28 12:11:26 -06003622 }
Mike Stroyand1c84a52015-08-18 14:40:24 -06003623
Chia-I Wuf7458c52015-10-26 21:10:41 +08003624 vkDestroySampler(m_device->device(), sampler, NULL);
3625 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
3626 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06003627}
3628
3629TEST_F(VkLayerTest, InvalidDSUpdateIndex)
3630{
Tobin Ehlis3b780662015-05-28 12:11:26 -06003631 // Create layout w/ count of 1 and attempt update to that layout w/ binding index 2
Tobin Ehlis3b780662015-05-28 12:11:26 -06003632 VkResult err;
3633
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07003634 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06003635 " does not have binding to match update binding ");
3636
Tobin Ehlis3b780662015-05-28 12:11:26 -06003637 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlis3b780662015-05-28 12:11:26 -06003638 //VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu1b99bb22015-10-27 19:25:11 +08003639 VkDescriptorPoolSize ds_type_count = {};
Tony Barboureb254902015-07-15 12:50:33 -06003640 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wud50a7d72015-10-26 20:48:51 +08003641 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06003642
3643 VkDescriptorPoolCreateInfo ds_pool_ci = {};
3644 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
3645 ds_pool_ci.pNext = NULL;
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -06003646 ds_pool_ci.maxSets = 1;
Chia-I Wu1b99bb22015-10-27 19:25:11 +08003647 ds_pool_ci.poolSizeCount = 1;
3648 ds_pool_ci.pPoolSizes = &ds_type_count;
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -06003649
Tobin Ehlis3b780662015-05-28 12:11:26 -06003650 VkDescriptorPool ds_pool;
Chia-I Wuf7458c52015-10-26 21:10:41 +08003651 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -06003652 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -06003653
Tony Barboureb254902015-07-15 12:50:33 -06003654 VkDescriptorSetLayoutBinding dsl_binding = {};
Chia-I Wud46e6ae2015-10-31 00:31:16 +08003655 dsl_binding.binding = 0;
Tony Barboureb254902015-07-15 12:50:33 -06003656 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wu02124482015-11-06 06:42:02 +08003657 dsl_binding.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06003658 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
3659 dsl_binding.pImmutableSamplers = NULL;
3660
3661 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
3662 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
3663 ds_layout_ci.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08003664 ds_layout_ci.bindingCount = 1;
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07003665 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlis3b780662015-05-28 12:11:26 -06003666 VkDescriptorSetLayout ds_layout;
Chia-I Wuf7458c52015-10-26 21:10:41 +08003667 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -06003668 ASSERT_VK_SUCCESS(err);
3669
3670 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003671 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08003672 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Chia-I Wud50a7d72015-10-26 20:48:51 +08003673 alloc_info.setLayoutCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06003674 alloc_info.descriptorPool = ds_pool;
3675 alloc_info.pSetLayouts = &ds_layout;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003676 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -06003677 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -06003678
Tony Barboureb254902015-07-15 12:50:33 -06003679 VkSamplerCreateInfo sampler_ci = {};
3680 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
3681 sampler_ci.pNext = NULL;
Chia-I Wub99df442015-10-26 16:49:32 +08003682 sampler_ci.magFilter = VK_FILTER_NEAREST;
3683 sampler_ci.minFilter = VK_FILTER_NEAREST;
3684 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_BASE;
Chia-I Wu1efb7e52015-10-26 17:32:47 +08003685 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
3686 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
3687 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
Tony Barboureb254902015-07-15 12:50:33 -06003688 sampler_ci.mipLodBias = 1.0;
Jon Ashburnddc8db52015-12-14 14:59:20 -07003689 sampler_ci.anisotropyEnable = VK_FALSE;
Tony Barboureb254902015-07-15 12:50:33 -06003690 sampler_ci.maxAnisotropy = 1;
3691 sampler_ci.compareEnable = VK_FALSE;
3692 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
3693 sampler_ci.minLod = 1.0;
3694 sampler_ci.maxLod = 1.0;
3695 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
Mark Lobodzinski52ac6582015-09-01 15:42:56 -06003696 sampler_ci.unnormalizedCoordinates = VK_FALSE;
Tony Barboureb254902015-07-15 12:50:33 -06003697
Tobin Ehlis3b780662015-05-28 12:11:26 -06003698 VkSampler sampler;
Chia-I Wuf7458c52015-10-26 21:10:41 +08003699 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
Tobin Ehlis3b780662015-05-28 12:11:26 -06003700 ASSERT_VK_SUCCESS(err);
Chia-I Wu9d00ed72015-05-25 16:27:55 +08003701
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -06003702 VkDescriptorImageInfo info = {};
3703 info.sampler = sampler;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08003704
3705 VkWriteDescriptorSet descriptor_write;
3706 memset(&descriptor_write, 0, sizeof(descriptor_write));
3707 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003708 descriptor_write.dstSet = descriptorSet;
3709 descriptor_write.dstBinding = 2;
Chia-I Wud50a7d72015-10-26 20:48:51 +08003710 descriptor_write.descriptorCount = 1;
Tobin Ehlis3b780662015-05-28 12:11:26 -06003711 // This is the wrong type, but out of bounds will be flagged first
Chia-I Wu9d00ed72015-05-25 16:27:55 +08003712 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -06003713 descriptor_write.pImageInfo = &info;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08003714
3715 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
3716
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06003717 if (!m_errorMonitor->DesiredMsgFound()) {
3718 FAIL() << "Did not receive Error 'Descriptor Set <blah> does not have binding to match update binding '";
3719 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlis3b780662015-05-28 12:11:26 -06003720 }
Mike Stroyand1c84a52015-08-18 14:40:24 -06003721
Chia-I Wuf7458c52015-10-26 21:10:41 +08003722 vkDestroySampler(m_device->device(), sampler, NULL);
3723 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
3724 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06003725}
3726
3727TEST_F(VkLayerTest, InvalidDSUpdateStruct)
3728{
3729 // Call UpdateDS w/ struct type other than valid VK_STRUCTUR_TYPE_UPDATE_* types
Tobin Ehlis3b780662015-05-28 12:11:26 -06003730 VkResult err;
3731
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07003732 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06003733 "Unexpected UPDATE struct of type ");
3734
Tobin Ehlis3b780662015-05-28 12:11:26 -06003735 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski209b5292015-09-17 09:44:05 -06003736
Chia-I Wu1b99bb22015-10-27 19:25:11 +08003737 VkDescriptorPoolSize ds_type_count = {};
Tony Barboureb254902015-07-15 12:50:33 -06003738 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wud50a7d72015-10-26 20:48:51 +08003739 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06003740
3741 VkDescriptorPoolCreateInfo ds_pool_ci = {};
3742 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
3743 ds_pool_ci.pNext = NULL;
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -06003744 ds_pool_ci.maxSets = 1;
Chia-I Wu1b99bb22015-10-27 19:25:11 +08003745 ds_pool_ci.poolSizeCount = 1;
3746 ds_pool_ci.pPoolSizes = &ds_type_count;
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -06003747
Tobin Ehlis3b780662015-05-28 12:11:26 -06003748 VkDescriptorPool ds_pool;
Chia-I Wuf7458c52015-10-26 21:10:41 +08003749 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -06003750 ASSERT_VK_SUCCESS(err);
Tony Barboureb254902015-07-15 12:50:33 -06003751 VkDescriptorSetLayoutBinding dsl_binding = {};
Chia-I Wud46e6ae2015-10-31 00:31:16 +08003752 dsl_binding.binding = 0;
Tony Barboureb254902015-07-15 12:50:33 -06003753 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wu02124482015-11-06 06:42:02 +08003754 dsl_binding.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06003755 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
3756 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis3b780662015-05-28 12:11:26 -06003757
Tony Barboureb254902015-07-15 12:50:33 -06003758 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
3759 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
3760 ds_layout_ci.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08003761 ds_layout_ci.bindingCount = 1;
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07003762 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -06003763
Tobin Ehlis3b780662015-05-28 12:11:26 -06003764 VkDescriptorSetLayout ds_layout;
Chia-I Wuf7458c52015-10-26 21:10:41 +08003765 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -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;
Chia-I Wud50a7d72015-10-26 20:48:51 +08003771 alloc_info.setLayoutCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06003772 alloc_info.descriptorPool = ds_pool;
3773 alloc_info.pSetLayouts = &ds_layout;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003774 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -06003775 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -06003776
Tony Barboureb254902015-07-15 12:50:33 -06003777 VkSamplerCreateInfo sampler_ci = {};
3778 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
3779 sampler_ci.pNext = NULL;
Chia-I Wub99df442015-10-26 16:49:32 +08003780 sampler_ci.magFilter = VK_FILTER_NEAREST;
3781 sampler_ci.minFilter = VK_FILTER_NEAREST;
3782 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_BASE;
Chia-I Wu1efb7e52015-10-26 17:32:47 +08003783 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
3784 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
3785 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
Tony Barboureb254902015-07-15 12:50:33 -06003786 sampler_ci.mipLodBias = 1.0;
Jon Ashburnddc8db52015-12-14 14:59:20 -07003787 sampler_ci.anisotropyEnable = VK_FALSE;
Tony Barboureb254902015-07-15 12:50:33 -06003788 sampler_ci.maxAnisotropy = 1;
3789 sampler_ci.compareEnable = VK_FALSE;
3790 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
3791 sampler_ci.minLod = 1.0;
3792 sampler_ci.maxLod = 1.0;
3793 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
Mark Lobodzinski52ac6582015-09-01 15:42:56 -06003794 sampler_ci.unnormalizedCoordinates = VK_FALSE;
Tobin Ehlis3b780662015-05-28 12:11:26 -06003795 VkSampler sampler;
Chia-I Wuf7458c52015-10-26 21:10:41 +08003796 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
Tobin Ehlis3b780662015-05-28 12:11:26 -06003797 ASSERT_VK_SUCCESS(err);
Chia-I Wu9d00ed72015-05-25 16:27:55 +08003798
3799
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -06003800 VkDescriptorImageInfo info = {};
3801 info.sampler = sampler;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08003802
3803 VkWriteDescriptorSet descriptor_write;
3804 memset(&descriptor_write, 0, sizeof(descriptor_write));
3805 descriptor_write.sType = (VkStructureType)0x99999999; /* Intentionally broken struct type */
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003806 descriptor_write.dstSet = descriptorSet;
Chia-I Wud50a7d72015-10-26 20:48:51 +08003807 descriptor_write.descriptorCount = 1;
Tobin Ehlis3b780662015-05-28 12:11:26 -06003808 // This is the wrong type, but out of bounds will be flagged first
Chia-I Wu9d00ed72015-05-25 16:27:55 +08003809 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -06003810 descriptor_write.pImageInfo = &info;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08003811
3812 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
3813
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06003814 if (!m_errorMonitor->DesiredMsgFound()) {
3815 FAIL() << "Did not receive Error 'Unexpected UPDATE struct of type '";
3816 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlis3b780662015-05-28 12:11:26 -06003817 }
Mike Stroyand1c84a52015-08-18 14:40:24 -06003818
Chia-I Wuf7458c52015-10-26 21:10:41 +08003819 vkDestroySampler(m_device->device(), sampler, NULL);
3820 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
3821 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06003822}
3823
Tobin Ehlisa1c28562015-10-23 16:00:08 -06003824TEST_F(VkLayerTest, SampleDescriptorUpdateError)
3825{
3826 // Create a single Sampler descriptor and send it an invalid Sampler
Tobin Ehlisa1c28562015-10-23 16:00:08 -06003827 VkResult err;
3828
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07003829 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06003830 "Attempt to update descriptor with invalid sampler 0xbaadbeef");
3831
Tobin Ehlisa1c28562015-10-23 16:00:08 -06003832 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisa1c28562015-10-23 16:00:08 -06003833 // TODO : Farm Descriptor setup code to helper function(s) to reduce copied code
Chia-I Wu1b99bb22015-10-27 19:25:11 +08003834 VkDescriptorPoolSize ds_type_count = {};
Tobin Ehlisa1c28562015-10-23 16:00:08 -06003835 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLER;
Chia-I Wud50a7d72015-10-26 20:48:51 +08003836 ds_type_count.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06003837
3838 VkDescriptorPoolCreateInfo ds_pool_ci = {};
3839 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
3840 ds_pool_ci.pNext = NULL;
3841 ds_pool_ci.maxSets = 1;
Chia-I Wu1b99bb22015-10-27 19:25:11 +08003842 ds_pool_ci.poolSizeCount = 1;
3843 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06003844
3845 VkDescriptorPool ds_pool;
Chia-I Wuf7458c52015-10-26 21:10:41 +08003846 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06003847 ASSERT_VK_SUCCESS(err);
3848
3849 VkDescriptorSetLayoutBinding dsl_binding = {};
Chia-I Wud46e6ae2015-10-31 00:31:16 +08003850 dsl_binding.binding = 0;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06003851 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Chia-I Wu02124482015-11-06 06:42:02 +08003852 dsl_binding.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06003853 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
3854 dsl_binding.pImmutableSamplers = NULL;
3855
3856 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
3857 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
3858 ds_layout_ci.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08003859 ds_layout_ci.bindingCount = 1;
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07003860 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06003861 VkDescriptorSetLayout ds_layout;
Chia-I Wuf7458c52015-10-26 21:10:41 +08003862 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06003863 ASSERT_VK_SUCCESS(err);
3864
3865 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003866 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08003867 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Chia-I Wud50a7d72015-10-26 20:48:51 +08003868 alloc_info.setLayoutCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06003869 alloc_info.descriptorPool = ds_pool;
3870 alloc_info.pSetLayouts = &ds_layout;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003871 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06003872 ASSERT_VK_SUCCESS(err);
3873
Mark Youngad779052016-01-06 14:26:04 -07003874 VkSampler sampler = (VkSampler)((size_t)0xbaadbeef); // Sampler with invalid handle
Tobin Ehlisa1c28562015-10-23 16:00:08 -06003875
3876 VkDescriptorImageInfo descriptor_info;
3877 memset(&descriptor_info, 0, sizeof(VkDescriptorImageInfo));
3878 descriptor_info.sampler = sampler;
3879
3880 VkWriteDescriptorSet descriptor_write;
3881 memset(&descriptor_write, 0, sizeof(descriptor_write));
3882 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003883 descriptor_write.dstSet = descriptorSet;
3884 descriptor_write.dstBinding = 0;
Chia-I Wud50a7d72015-10-26 20:48:51 +08003885 descriptor_write.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06003886 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
3887 descriptor_write.pImageInfo = &descriptor_info;
3888
3889 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
3890
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06003891 if (!m_errorMonitor->DesiredMsgFound()) {
3892 FAIL() << "Did not receive Error 'Attempt to update descriptor with invalid sampler...'";
3893 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlisa1c28562015-10-23 16:00:08 -06003894 }
3895
Chia-I Wuf7458c52015-10-26 21:10:41 +08003896 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
3897 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06003898}
3899
3900TEST_F(VkLayerTest, ImageViewDescriptorUpdateError)
3901{
3902 // Create a single combined Image/Sampler descriptor and send it an invalid imageView
Tobin Ehlisa1c28562015-10-23 16:00:08 -06003903 VkResult err;
3904
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07003905 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06003906 "Attempt to update descriptor with invalid imageView 0xbaadbeef");
3907
Tobin Ehlisa1c28562015-10-23 16:00:08 -06003908 ASSERT_NO_FATAL_FAILURE(InitState());
Chia-I Wu1b99bb22015-10-27 19:25:11 +08003909 VkDescriptorPoolSize ds_type_count = {};
Tobin Ehlisa1c28562015-10-23 16:00:08 -06003910 ds_type_count.type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
Chia-I Wud50a7d72015-10-26 20:48:51 +08003911 ds_type_count.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06003912
3913 VkDescriptorPoolCreateInfo ds_pool_ci = {};
3914 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
3915 ds_pool_ci.pNext = NULL;
3916 ds_pool_ci.maxSets = 1;
Chia-I Wu1b99bb22015-10-27 19:25:11 +08003917 ds_pool_ci.poolSizeCount = 1;
3918 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06003919
3920 VkDescriptorPool ds_pool;
Chia-I Wuf7458c52015-10-26 21:10:41 +08003921 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06003922 ASSERT_VK_SUCCESS(err);
3923
3924 VkDescriptorSetLayoutBinding dsl_binding = {};
Chia-I Wud46e6ae2015-10-31 00:31:16 +08003925 dsl_binding.binding = 0;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06003926 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
Chia-I Wu02124482015-11-06 06:42:02 +08003927 dsl_binding.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06003928 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
3929 dsl_binding.pImmutableSamplers = NULL;
3930
3931 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
3932 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
3933 ds_layout_ci.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08003934 ds_layout_ci.bindingCount = 1;
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07003935 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06003936 VkDescriptorSetLayout ds_layout;
Chia-I Wuf7458c52015-10-26 21:10:41 +08003937 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06003938 ASSERT_VK_SUCCESS(err);
3939
3940 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003941 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08003942 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Chia-I Wud50a7d72015-10-26 20:48:51 +08003943 alloc_info.setLayoutCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06003944 alloc_info.descriptorPool = ds_pool;
3945 alloc_info.pSetLayouts = &ds_layout;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003946 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06003947 ASSERT_VK_SUCCESS(err);
3948
3949 VkSamplerCreateInfo sampler_ci = {};
3950 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
3951 sampler_ci.pNext = NULL;
Chia-I Wub99df442015-10-26 16:49:32 +08003952 sampler_ci.magFilter = VK_FILTER_NEAREST;
3953 sampler_ci.minFilter = VK_FILTER_NEAREST;
3954 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_BASE;
Chia-I Wu1efb7e52015-10-26 17:32:47 +08003955 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
3956 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
3957 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06003958 sampler_ci.mipLodBias = 1.0;
Jon Ashburnddc8db52015-12-14 14:59:20 -07003959 sampler_ci.anisotropyEnable = VK_FALSE;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06003960 sampler_ci.maxAnisotropy = 1;
3961 sampler_ci.compareEnable = VK_FALSE;
3962 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
3963 sampler_ci.minLod = 1.0;
3964 sampler_ci.maxLod = 1.0;
3965 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
3966 sampler_ci.unnormalizedCoordinates = VK_FALSE;
3967
3968 VkSampler sampler;
Chia-I Wuf7458c52015-10-26 21:10:41 +08003969 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06003970 ASSERT_VK_SUCCESS(err);
3971
Mark Youngad779052016-01-06 14:26:04 -07003972 VkImageView view = (VkImageView)((size_t)0xbaadbeef); // invalid imageView object
Tobin Ehlisa1c28562015-10-23 16:00:08 -06003973
3974 VkDescriptorImageInfo descriptor_info;
3975 memset(&descriptor_info, 0, sizeof(VkDescriptorImageInfo));
3976 descriptor_info.sampler = sampler;
3977 descriptor_info.imageView = view;
3978
3979 VkWriteDescriptorSet descriptor_write;
3980 memset(&descriptor_write, 0, sizeof(descriptor_write));
3981 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003982 descriptor_write.dstSet = descriptorSet;
3983 descriptor_write.dstBinding = 0;
Chia-I Wud50a7d72015-10-26 20:48:51 +08003984 descriptor_write.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06003985 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
3986 descriptor_write.pImageInfo = &descriptor_info;
3987
3988 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
3989
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06003990 if (!m_errorMonitor->DesiredMsgFound()) {
3991 FAIL() << "Did not receive Error 'Attempt to update descriptor with invalid imageView...'";
3992 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlisa1c28562015-10-23 16:00:08 -06003993 }
3994
Chia-I Wuf7458c52015-10-26 21:10:41 +08003995 vkDestroySampler(m_device->device(), sampler, NULL);
3996 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
3997 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06003998}
3999
Tobin Ehlis04356f92015-10-27 16:35:27 -06004000TEST_F(VkLayerTest, CopyDescriptorUpdateErrors)
4001{
4002 // Create DS w/ layout of 2 types, write update 1 and attempt to copy-update into the other
Tobin Ehlis04356f92015-10-27 16:35:27 -06004003 VkResult err;
4004
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07004005 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06004006 "Copy descriptor update index 0, update count #1, has src update descriptor type VK_DESCRIPTOR_TYPE_SAMPLER ");
4007
Tobin Ehlis04356f92015-10-27 16:35:27 -06004008 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlis04356f92015-10-27 16:35:27 -06004009 //VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu1b99bb22015-10-27 19:25:11 +08004010 VkDescriptorPoolSize ds_type_count[2] = {};
Tobin Ehlis04356f92015-10-27 16:35:27 -06004011 ds_type_count[0].type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wud50a7d72015-10-26 20:48:51 +08004012 ds_type_count[0].descriptorCount = 1;
Tobin Ehlis04356f92015-10-27 16:35:27 -06004013 ds_type_count[1].type = VK_DESCRIPTOR_TYPE_SAMPLER;
Chia-I Wud50a7d72015-10-26 20:48:51 +08004014 ds_type_count[1].descriptorCount = 1;
Tobin Ehlis04356f92015-10-27 16:35:27 -06004015
4016 VkDescriptorPoolCreateInfo ds_pool_ci = {};
4017 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
4018 ds_pool_ci.pNext = NULL;
4019 ds_pool_ci.maxSets = 1;
Chia-I Wu1b99bb22015-10-27 19:25:11 +08004020 ds_pool_ci.poolSizeCount = 2;
4021 ds_pool_ci.pPoolSizes = ds_type_count;
Tobin Ehlis04356f92015-10-27 16:35:27 -06004022
4023 VkDescriptorPool ds_pool;
Chia-I Wuf7458c52015-10-26 21:10:41 +08004024 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis04356f92015-10-27 16:35:27 -06004025 ASSERT_VK_SUCCESS(err);
4026 VkDescriptorSetLayoutBinding dsl_binding[2] = {};
Chia-I Wud46e6ae2015-10-31 00:31:16 +08004027 dsl_binding[0].binding = 0;
Tobin Ehlis04356f92015-10-27 16:35:27 -06004028 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wu02124482015-11-06 06:42:02 +08004029 dsl_binding[0].descriptorCount = 1;
Tobin Ehlis04356f92015-10-27 16:35:27 -06004030 dsl_binding[0].stageFlags = VK_SHADER_STAGE_ALL;
4031 dsl_binding[0].pImmutableSamplers = NULL;
Chia-I Wud46e6ae2015-10-31 00:31:16 +08004032 dsl_binding[1].binding = 1;
Tobin Ehlis04356f92015-10-27 16:35:27 -06004033 dsl_binding[1].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Chia-I Wu02124482015-11-06 06:42:02 +08004034 dsl_binding[1].descriptorCount = 1;
Tobin Ehlis04356f92015-10-27 16:35:27 -06004035 dsl_binding[1].stageFlags = VK_SHADER_STAGE_ALL;
4036 dsl_binding[1].pImmutableSamplers = NULL;
4037
4038 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
4039 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
4040 ds_layout_ci.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08004041 ds_layout_ci.bindingCount = 2;
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07004042 ds_layout_ci.pBindings = dsl_binding;
Tobin Ehlis04356f92015-10-27 16:35:27 -06004043
4044 VkDescriptorSetLayout ds_layout;
Chia-I Wuf7458c52015-10-26 21:10:41 +08004045 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis04356f92015-10-27 16:35:27 -06004046 ASSERT_VK_SUCCESS(err);
4047
4048 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004049 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08004050 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Chia-I Wud50a7d72015-10-26 20:48:51 +08004051 alloc_info.setLayoutCount = 1;
Tobin Ehlis04356f92015-10-27 16:35:27 -06004052 alloc_info.descriptorPool = ds_pool;
4053 alloc_info.pSetLayouts = &ds_layout;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004054 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis04356f92015-10-27 16:35:27 -06004055 ASSERT_VK_SUCCESS(err);
4056
4057 VkSamplerCreateInfo sampler_ci = {};
4058 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
4059 sampler_ci.pNext = NULL;
Chia-I Wub99df442015-10-26 16:49:32 +08004060 sampler_ci.magFilter = VK_FILTER_NEAREST;
4061 sampler_ci.minFilter = VK_FILTER_NEAREST;
4062 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_BASE;
Chia-I Wu1efb7e52015-10-26 17:32:47 +08004063 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
4064 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
4065 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
Tobin Ehlis04356f92015-10-27 16:35:27 -06004066 sampler_ci.mipLodBias = 1.0;
Jon Ashburnddc8db52015-12-14 14:59:20 -07004067 sampler_ci.anisotropyEnable = VK_FALSE;
Tobin Ehlis04356f92015-10-27 16:35:27 -06004068 sampler_ci.maxAnisotropy = 1;
4069 sampler_ci.compareEnable = VK_FALSE;
4070 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
4071 sampler_ci.minLod = 1.0;
4072 sampler_ci.maxLod = 1.0;
4073 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
4074 sampler_ci.unnormalizedCoordinates = VK_FALSE;
4075
4076 VkSampler sampler;
Chia-I Wuf7458c52015-10-26 21:10:41 +08004077 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
Tobin Ehlis04356f92015-10-27 16:35:27 -06004078 ASSERT_VK_SUCCESS(err);
4079
4080 VkDescriptorImageInfo info = {};
4081 info.sampler = sampler;
4082
4083 VkWriteDescriptorSet descriptor_write;
4084 memset(&descriptor_write, 0, sizeof(VkWriteDescriptorSet));
4085 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004086 descriptor_write.dstSet = descriptorSet;
4087 descriptor_write.dstBinding = 1; // SAMPLER binding from layout above
Chia-I Wud50a7d72015-10-26 20:48:51 +08004088 descriptor_write.descriptorCount = 1;
Tobin Ehlis04356f92015-10-27 16:35:27 -06004089 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
4090 descriptor_write.pImageInfo = &info;
4091 // This write update should succeed
4092 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
4093 // Now perform a copy update that fails due to type mismatch
4094 VkCopyDescriptorSet copy_ds_update;
4095 memset(&copy_ds_update, 0, sizeof(VkCopyDescriptorSet));
4096 copy_ds_update.sType = VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET;
4097 copy_ds_update.srcSet = descriptorSet;
4098 copy_ds_update.srcBinding = 1; // copy from SAMPLER binding
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004099 copy_ds_update.dstSet = descriptorSet;
4100 copy_ds_update.dstBinding = 0; // ERROR : copy to UNIFORM binding
Chia-I Wud50a7d72015-10-26 20:48:51 +08004101 copy_ds_update.descriptorCount = 1; // copy 1 descriptor
Tobin Ehlis04356f92015-10-27 16:35:27 -06004102 vkUpdateDescriptorSets(m_device->device(), 0, NULL, 1, &copy_ds_update);
4103
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06004104 if (!m_errorMonitor->DesiredMsgFound()) {
4105 FAIL() << "Did not receive Error 'Copy descriptor update index 0, update count #1, has src update descriptor type_DESCRIPTOR_TYPE_SAMPLER'";
4106 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlis04356f92015-10-27 16:35:27 -06004107 }
4108 // Now perform a copy update that fails due to binding out of bounds
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07004109 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06004110 "Copy descriptor update 0 has srcBinding 3 which is out of bounds ");
Tobin Ehlis04356f92015-10-27 16:35:27 -06004111 memset(&copy_ds_update, 0, sizeof(VkCopyDescriptorSet));
4112 copy_ds_update.sType = VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET;
4113 copy_ds_update.srcSet = descriptorSet;
4114 copy_ds_update.srcBinding = 3; // ERROR : Invalid binding for matching layout
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004115 copy_ds_update.dstSet = descriptorSet;
4116 copy_ds_update.dstBinding = 0;
Chia-I Wud50a7d72015-10-26 20:48:51 +08004117 copy_ds_update.descriptorCount = 1; // copy 1 descriptor
Tobin Ehlis04356f92015-10-27 16:35:27 -06004118 vkUpdateDescriptorSets(m_device->device(), 0, NULL, 1, &copy_ds_update);
4119
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06004120 if (!m_errorMonitor->DesiredMsgFound()) {
4121 FAIL() << "Did not receive Error 'Copy descriptor update 0 has srcBinding 3 which is out of bounds...'";
4122 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlis04356f92015-10-27 16:35:27 -06004123 }
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06004124
Tobin Ehlis04356f92015-10-27 16:35:27 -06004125 // Now perform a copy update that fails due to binding out of bounds
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07004126 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06004127 "Copy descriptor src update is out of bounds for matching binding 1 ");
4128
Tobin Ehlis04356f92015-10-27 16:35:27 -06004129 memset(&copy_ds_update, 0, sizeof(VkCopyDescriptorSet));
4130 copy_ds_update.sType = VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET;
4131 copy_ds_update.srcSet = descriptorSet;
4132 copy_ds_update.srcBinding = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004133 copy_ds_update.dstSet = descriptorSet;
4134 copy_ds_update.dstBinding = 0;
Chia-I Wud50a7d72015-10-26 20:48:51 +08004135 copy_ds_update.descriptorCount = 5; // ERROR copy 5 descriptors (out of bounds for layout)
Tobin Ehlis04356f92015-10-27 16:35:27 -06004136 vkUpdateDescriptorSets(m_device->device(), 0, NULL, 1, &copy_ds_update);
4137
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06004138 if (!m_errorMonitor->DesiredMsgFound()) {
4139 FAIL() << "Did not receive Error 'Copy descriptor src update is out of bounds for matching binding 1...'";
4140 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlis04356f92015-10-27 16:35:27 -06004141 }
4142
Chia-I Wuf7458c52015-10-26 21:10:41 +08004143 vkDestroySampler(m_device->device(), sampler, NULL);
4144 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
4145 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis04356f92015-10-27 16:35:27 -06004146}
4147
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06004148TEST_F(VkLayerTest, NumSamplesMismatch)
4149{
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004150 // Create CommandBuffer where MSAA samples doesn't match RenderPass sampleCount
Tobin Ehlis3b780662015-05-28 12:11:26 -06004151 VkResult err;
4152
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07004153 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06004154 "Num samples mismatch! ");
4155
Tobin Ehlis3b780662015-05-28 12:11:26 -06004156 ASSERT_NO_FATAL_FAILURE(InitState());
4157 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chia-I Wu1b99bb22015-10-27 19:25:11 +08004158 VkDescriptorPoolSize ds_type_count = {};
Tony Barboureb254902015-07-15 12:50:33 -06004159 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wud50a7d72015-10-26 20:48:51 +08004160 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06004161
4162 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -06004163 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
4164 ds_pool_ci.pNext = NULL;
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -06004165 ds_pool_ci.maxSets = 1;
Chia-I Wu1b99bb22015-10-27 19:25:11 +08004166 ds_pool_ci.poolSizeCount = 1;
4167 ds_pool_ci.pPoolSizes = &ds_type_count;
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -06004168
Tobin Ehlis3b780662015-05-28 12:11:26 -06004169 VkDescriptorPool ds_pool;
Chia-I Wuf7458c52015-10-26 21:10:41 +08004170 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -06004171 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -06004172
Tony Barboureb254902015-07-15 12:50:33 -06004173 VkDescriptorSetLayoutBinding dsl_binding = {};
Chia-I Wud46e6ae2015-10-31 00:31:16 +08004174 dsl_binding.binding = 0;
Tony Barboureb254902015-07-15 12:50:33 -06004175 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wu02124482015-11-06 06:42:02 +08004176 dsl_binding.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06004177 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
4178 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis3b780662015-05-28 12:11:26 -06004179
Tony Barboureb254902015-07-15 12:50:33 -06004180 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
4181 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
4182 ds_layout_ci.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08004183 ds_layout_ci.bindingCount = 1;
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07004184 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -06004185
Tobin Ehlis3b780662015-05-28 12:11:26 -06004186 VkDescriptorSetLayout ds_layout;
Chia-I Wuf7458c52015-10-26 21:10:41 +08004187 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -06004188 ASSERT_VK_SUCCESS(err);
4189
4190 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004191 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08004192 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Chia-I Wud50a7d72015-10-26 20:48:51 +08004193 alloc_info.setLayoutCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06004194 alloc_info.descriptorPool = ds_pool;
4195 alloc_info.pSetLayouts = &ds_layout;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004196 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -06004197 ASSERT_VK_SUCCESS(err);
4198
Tony Barboureb254902015-07-15 12:50:33 -06004199 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
4200 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
4201 pipe_ms_state_ci.pNext = NULL;
Chia-I Wu5c17c962015-10-31 00:31:16 +08004202 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_4_BIT;
Tony Barboureb254902015-07-15 12:50:33 -06004203 pipe_ms_state_ci.sampleShadingEnable = 0;
4204 pipe_ms_state_ci.minSampleShading = 1.0;
Cody Northrop02e61ed2015-08-04 14:34:54 -06004205 pipe_ms_state_ci.pSampleMask = NULL;
Tobin Ehlis3b780662015-05-28 12:11:26 -06004206
Tony Barboureb254902015-07-15 12:50:33 -06004207 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
4208 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
4209 pipeline_layout_ci.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08004210 pipeline_layout_ci.setLayoutCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06004211 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis3b780662015-05-28 12:11:26 -06004212
4213 VkPipelineLayout pipeline_layout;
Chia-I Wuf7458c52015-10-26 21:10:41 +08004214 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -06004215 ASSERT_VK_SUCCESS(err);
4216
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06004217 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
4218 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this); // TODO - We shouldn't need a fragment shader
Tony Barbour1c94d372015-08-06 11:21:08 -06004219 // but add it to be able to run on more devices
Tony Barbour62e1a5b2015-08-06 10:16:07 -06004220 VkPipelineObj pipe(m_device);
4221 pipe.AddShader(&vs);
Tony Barbour1c94d372015-08-06 11:21:08 -06004222 pipe.AddShader(&fs);
Tony Barbour62e1a5b2015-08-06 10:16:07 -06004223 pipe.SetMSAA(&pipe_ms_state_ci);
4224 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tobin Ehlis3b780662015-05-28 12:11:26 -06004225
Tony Barbourfe3351b2015-07-28 10:17:20 -06004226 BeginCommandBuffer();
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004227 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlis3b780662015-05-28 12:11:26 -06004228
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06004229 if (!m_errorMonitor->DesiredMsgFound()) {
4230 FAIL() << "Did not recieve Error 'Num samples mismatch!...'";
4231 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlis3b780662015-05-28 12:11:26 -06004232 }
Mike Stroyand1c84a52015-08-18 14:40:24 -06004233
Chia-I Wuf7458c52015-10-26 21:10:41 +08004234 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
4235 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
4236 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06004237}
Tobin Ehlis53eddda2015-07-01 16:46:13 -06004238
Tobin Ehlis53eddda2015-07-01 16:46:13 -06004239TEST_F(VkLayerTest, ClearCmdNoDraw)
4240{
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004241 // Create CommandBuffer where we add ClearCmd for FB Color attachment prior to issuing a Draw
Tobin Ehlis53eddda2015-07-01 16:46:13 -06004242 VkResult err;
4243
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07004244 // TODO: verify that this matches layer
4245 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARN_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06004246 "vkCmdClearAttachments() issued on CB object ");
4247
Tobin Ehlis53eddda2015-07-01 16:46:13 -06004248 ASSERT_NO_FATAL_FAILURE(InitState());
4249 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barboureb254902015-07-15 12:50:33 -06004250
Chia-I Wu1b99bb22015-10-27 19:25:11 +08004251 VkDescriptorPoolSize ds_type_count = {};
Tony Barboureb254902015-07-15 12:50:33 -06004252 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wud50a7d72015-10-26 20:48:51 +08004253 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06004254
4255 VkDescriptorPoolCreateInfo ds_pool_ci = {};
4256 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
4257 ds_pool_ci.pNext = NULL;
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -06004258 ds_pool_ci.maxSets = 1;
Chia-I Wu1b99bb22015-10-27 19:25:11 +08004259 ds_pool_ci.poolSizeCount = 1;
4260 ds_pool_ci.pPoolSizes = &ds_type_count;
Tony Barboureb254902015-07-15 12:50:33 -06004261
Tobin Ehlis53eddda2015-07-01 16:46:13 -06004262 VkDescriptorPool ds_pool;
Chia-I Wuf7458c52015-10-26 21:10:41 +08004263 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis53eddda2015-07-01 16:46:13 -06004264 ASSERT_VK_SUCCESS(err);
4265
Tony Barboureb254902015-07-15 12:50:33 -06004266 VkDescriptorSetLayoutBinding dsl_binding = {};
Chia-I Wud46e6ae2015-10-31 00:31:16 +08004267 dsl_binding.binding = 0;
Tony Barboureb254902015-07-15 12:50:33 -06004268 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wu02124482015-11-06 06:42:02 +08004269 dsl_binding.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06004270 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
4271 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis53eddda2015-07-01 16:46:13 -06004272
Tony Barboureb254902015-07-15 12:50:33 -06004273 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
4274 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
4275 ds_layout_ci.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08004276 ds_layout_ci.bindingCount = 1;
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07004277 ds_layout_ci.pBindings = &dsl_binding;
Mark Lobodzinski209b5292015-09-17 09:44:05 -06004278
Tobin Ehlis53eddda2015-07-01 16:46:13 -06004279 VkDescriptorSetLayout ds_layout;
Chia-I Wuf7458c52015-10-26 21:10:41 +08004280 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis53eddda2015-07-01 16:46:13 -06004281 ASSERT_VK_SUCCESS(err);
4282
4283 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004284 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08004285 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Chia-I Wud50a7d72015-10-26 20:48:51 +08004286 alloc_info.setLayoutCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06004287 alloc_info.descriptorPool = ds_pool;
4288 alloc_info.pSetLayouts = &ds_layout;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004289 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis53eddda2015-07-01 16:46:13 -06004290 ASSERT_VK_SUCCESS(err);
4291
Tony Barboureb254902015-07-15 12:50:33 -06004292 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
4293 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
4294 pipe_ms_state_ci.pNext = NULL;
Chia-I Wu5c17c962015-10-31 00:31:16 +08004295 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_4_BIT;
Tony Barboureb254902015-07-15 12:50:33 -06004296 pipe_ms_state_ci.sampleShadingEnable = 0;
4297 pipe_ms_state_ci.minSampleShading = 1.0;
Cody Northrop02e61ed2015-08-04 14:34:54 -06004298 pipe_ms_state_ci.pSampleMask = NULL;
Tobin Ehlis53eddda2015-07-01 16:46:13 -06004299
Tony Barboureb254902015-07-15 12:50:33 -06004300 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
4301 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
4302 pipeline_layout_ci.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08004303 pipeline_layout_ci.setLayoutCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06004304 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis53eddda2015-07-01 16:46:13 -06004305
4306 VkPipelineLayout pipeline_layout;
Chia-I Wuf7458c52015-10-26 21:10:41 +08004307 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis53eddda2015-07-01 16:46:13 -06004308 ASSERT_VK_SUCCESS(err);
Mark Lobodzinski209b5292015-09-17 09:44:05 -06004309
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06004310 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06004311 // TODO - We shouldn't need a fragment shader but add it to be able to run on more devices
4312 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
4313
Tony Barbour62e1a5b2015-08-06 10:16:07 -06004314 VkPipelineObj pipe(m_device);
4315 pipe.AddShader(&vs);
Tony Barbour1c94d372015-08-06 11:21:08 -06004316 pipe.AddShader(&fs);
Tony Barbour62e1a5b2015-08-06 10:16:07 -06004317 pipe.SetMSAA(&pipe_ms_state_ci);
4318 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tony Barbourfe3351b2015-07-28 10:17:20 -06004319
4320 BeginCommandBuffer();
Tobin Ehlis53eddda2015-07-01 16:46:13 -06004321
Tobin Ehlis53eddda2015-07-01 16:46:13 -06004322 // Main thing we care about for this test is that the VkImage obj we're clearing matches Color Attachment of FB
4323 // Also pass down other dummy params to keep driver and paramchecker happy
Courtney Goeltzenleuchterc9323e02015-10-15 16:51:05 -06004324 VkClearAttachment color_attachment;
4325 color_attachment.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
4326 color_attachment.clearValue.color.float32[0] = 1.0;
4327 color_attachment.clearValue.color.float32[1] = 1.0;
4328 color_attachment.clearValue.color.float32[2] = 1.0;
4329 color_attachment.clearValue.color.float32[3] = 1.0;
4330 color_attachment.colorAttachment = 0;
Courtney Goeltzenleuchter5d2aed42015-10-21 17:57:31 -06004331 VkClearRect clear_rect = { { { 0, 0 }, { (int)m_width, (int)m_height } } };
Tobin Ehlis53eddda2015-07-01 16:46:13 -06004332
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004333 vkCmdClearAttachments(m_commandBuffer->GetBufferHandle(), 1, &color_attachment, 1, &clear_rect);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06004334
4335 if (!m_errorMonitor->DesiredMsgFound()) {
4336 FAIL() << "Did not receive Error 'vkCommandClearAttachments() issued on CB object...'";
4337 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlis53eddda2015-07-01 16:46:13 -06004338 }
Mike Stroyand1c84a52015-08-18 14:40:24 -06004339
Chia-I Wuf7458c52015-10-26 21:10:41 +08004340 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
4341 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
4342 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis53eddda2015-07-01 16:46:13 -06004343}
4344
Tobin Ehlis502480b2015-06-24 15:53:07 -06004345TEST_F(VkLayerTest, VtxBufferBadIndex)
4346{
Tobin Ehlis502480b2015-06-24 15:53:07 -06004347 VkResult err;
4348
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07004349 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERF_WARN_BIT_EXT,
Mark Lobodzinskidfcd9b62015-12-14 15:14:10 -07004350 "but no vertex buffers are attached to this Pipeline State Object");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06004351
Tobin Ehlis502480b2015-06-24 15:53:07 -06004352 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisd332f282015-10-02 11:00:56 -06004353 ASSERT_NO_FATAL_FAILURE(InitViewport());
Tobin Ehlis502480b2015-06-24 15:53:07 -06004354 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barboureb254902015-07-15 12:50:33 -06004355
Chia-I Wu1b99bb22015-10-27 19:25:11 +08004356 VkDescriptorPoolSize ds_type_count = {};
Tony Barboureb254902015-07-15 12:50:33 -06004357 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wud50a7d72015-10-26 20:48:51 +08004358 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06004359
4360 VkDescriptorPoolCreateInfo ds_pool_ci = {};
4361 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
4362 ds_pool_ci.pNext = NULL;
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -06004363 ds_pool_ci.maxSets = 1;
Chia-I Wu1b99bb22015-10-27 19:25:11 +08004364 ds_pool_ci.poolSizeCount = 1;
4365 ds_pool_ci.pPoolSizes = &ds_type_count;
Tony Barboureb254902015-07-15 12:50:33 -06004366
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -06004367 VkDescriptorPool ds_pool;
Chia-I Wuf7458c52015-10-26 21:10:41 +08004368 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis502480b2015-06-24 15:53:07 -06004369 ASSERT_VK_SUCCESS(err);
4370
Tony Barboureb254902015-07-15 12:50:33 -06004371 VkDescriptorSetLayoutBinding dsl_binding = {};
Chia-I Wud46e6ae2015-10-31 00:31:16 +08004372 dsl_binding.binding = 0;
Tony Barboureb254902015-07-15 12:50:33 -06004373 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wu02124482015-11-06 06:42:02 +08004374 dsl_binding.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06004375 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
4376 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis502480b2015-06-24 15:53:07 -06004377
Tony Barboureb254902015-07-15 12:50:33 -06004378 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
4379 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
4380 ds_layout_ci.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08004381 ds_layout_ci.bindingCount = 1;
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07004382 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -06004383
Tobin Ehlis502480b2015-06-24 15:53:07 -06004384 VkDescriptorSetLayout ds_layout;
Chia-I Wuf7458c52015-10-26 21:10:41 +08004385 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis502480b2015-06-24 15:53:07 -06004386 ASSERT_VK_SUCCESS(err);
4387
4388 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004389 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08004390 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Chia-I Wud50a7d72015-10-26 20:48:51 +08004391 alloc_info.setLayoutCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06004392 alloc_info.descriptorPool = ds_pool;
4393 alloc_info.pSetLayouts = &ds_layout;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004394 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis502480b2015-06-24 15:53:07 -06004395 ASSERT_VK_SUCCESS(err);
4396
Tony Barboureb254902015-07-15 12:50:33 -06004397 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
4398 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
4399 pipe_ms_state_ci.pNext = NULL;
Chia-I Wu5c17c962015-10-31 00:31:16 +08004400 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
Tony Barboureb254902015-07-15 12:50:33 -06004401 pipe_ms_state_ci.sampleShadingEnable = 0;
4402 pipe_ms_state_ci.minSampleShading = 1.0;
Cody Northrop02e61ed2015-08-04 14:34:54 -06004403 pipe_ms_state_ci.pSampleMask = NULL;
Tobin Ehlis502480b2015-06-24 15:53:07 -06004404
Tony Barboureb254902015-07-15 12:50:33 -06004405 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
4406 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
4407 pipeline_layout_ci.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08004408 pipeline_layout_ci.setLayoutCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06004409 pipeline_layout_ci.pSetLayouts = &ds_layout;
4410 VkPipelineLayout pipeline_layout;
Tobin Ehlis502480b2015-06-24 15:53:07 -06004411
Chia-I Wuf7458c52015-10-26 21:10:41 +08004412 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis502480b2015-06-24 15:53:07 -06004413 ASSERT_VK_SUCCESS(err);
4414
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06004415 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
4416 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this); // TODO - We shouldn't need a fragment shader
Tony Barbour1c94d372015-08-06 11:21:08 -06004417 // but add it to be able to run on more devices
Tony Barbour62e1a5b2015-08-06 10:16:07 -06004418 VkPipelineObj pipe(m_device);
4419 pipe.AddShader(&vs);
Tony Barbour1c94d372015-08-06 11:21:08 -06004420 pipe.AddShader(&fs);
Tony Barbour62e1a5b2015-08-06 10:16:07 -06004421 pipe.SetMSAA(&pipe_ms_state_ci);
Tobin Ehlisd332f282015-10-02 11:00:56 -06004422 pipe.SetViewport(m_viewports);
4423 pipe.SetScissor(m_scissors);
Tony Barbour62e1a5b2015-08-06 10:16:07 -06004424 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tony Barbourfe3351b2015-07-28 10:17:20 -06004425
4426 BeginCommandBuffer();
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004427 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlisf7bf4502015-09-09 15:12:35 -06004428 // Don't care about actual data, just need to get to draw to flag error
4429 static const float vbo_data[3] = {1.f, 0.f, 1.f};
4430 VkConstantBufferObj vbo(m_device, sizeof(vbo_data), sizeof(float), (const void*) &vbo_data);
4431 BindVertexBuffer(&vbo, (VkDeviceSize)0, 1); // VBO idx 1, but no VBO in PSO
Courtney Goeltzenleuchter08c26372015-09-23 12:31:50 -06004432 Draw(1, 0, 0, 0);
Tobin Ehlis502480b2015-06-24 15:53:07 -06004433
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06004434 if (!m_errorMonitor->DesiredMsgFound()) {
4435 FAIL() << "Did not receive Error 'Vtx Buffer Index 0 was bound, but no vtx buffers are attached to PSO.'";
4436 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlis502480b2015-06-24 15:53:07 -06004437 }
Mike Stroyand1c84a52015-08-18 14:40:24 -06004438
Chia-I Wuf7458c52015-10-26 21:10:41 +08004439 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
4440 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
4441 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis502480b2015-06-24 15:53:07 -06004442}
Mark Lobodzinski209b5292015-09-17 09:44:05 -06004443#endif // DRAW_STATE_TESTS
4444
Tobin Ehlis0788f522015-05-26 16:11:58 -06004445#if THREADING_TESTS
Mike Stroyanaccf7692015-05-12 16:00:45 -06004446#if GTEST_IS_THREADSAFE
4447struct thread_data_struct {
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004448 VkCommandBuffer commandBuffer;
Mike Stroyanaccf7692015-05-12 16:00:45 -06004449 VkEvent event;
4450 bool bailout;
4451};
4452
4453extern "C" void *AddToCommandBuffer(void *arg)
4454{
4455 struct thread_data_struct *data = (struct thread_data_struct *) arg;
Mike Stroyanaccf7692015-05-12 16:00:45 -06004456
4457 for (int i = 0; i<10000; i++) {
Chia-I Wu89d0f942015-10-31 00:31:16 +08004458 vkCmdSetEvent(data->commandBuffer, data->event, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT);
Mike Stroyanaccf7692015-05-12 16:00:45 -06004459 if (data->bailout) {
4460 break;
4461 }
4462 }
4463 return NULL;
4464}
4465
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004466TEST_F(VkLayerTest, ThreadCommandBufferCollision)
Mike Stroyanaccf7692015-05-12 16:00:45 -06004467{
Mike Stroyan4268d1f2015-07-13 14:45:35 -06004468 test_platform_thread thread;
Mike Stroyanaccf7692015-05-12 16:00:45 -06004469
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07004470 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "THREADING ERROR");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06004471
Mike Stroyanaccf7692015-05-12 16:00:45 -06004472 ASSERT_NO_FATAL_FAILURE(InitState());
4473 ASSERT_NO_FATAL_FAILURE(InitViewport());
4474 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
4475
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004476 // Calls AllocateCommandBuffers
4477 VkCommandBufferObj commandBuffer(m_device, m_commandPool);
Mark Lobodzinski5495d132015-09-30 16:19:16 -06004478
4479 // Avoid creating RenderPass
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004480 commandBuffer.BeginCommandBuffer();
Mike Stroyanaccf7692015-05-12 16:00:45 -06004481
4482 VkEventCreateInfo event_info;
4483 VkEvent event;
Mike Stroyanaccf7692015-05-12 16:00:45 -06004484 VkResult err;
4485
4486 memset(&event_info, 0, sizeof(event_info));
4487 event_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
4488
Chia-I Wuf7458c52015-10-26 21:10:41 +08004489 err = vkCreateEvent(device(), &event_info, NULL, &event);
Mike Stroyanaccf7692015-05-12 16:00:45 -06004490 ASSERT_VK_SUCCESS(err);
4491
Mike Stroyanaccf7692015-05-12 16:00:45 -06004492 err = vkResetEvent(device(), event);
4493 ASSERT_VK_SUCCESS(err);
4494
4495 struct thread_data_struct data;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004496 data.commandBuffer = commandBuffer.GetBufferHandle();
Mike Stroyanaccf7692015-05-12 16:00:45 -06004497 data.event = event;
4498 data.bailout = false;
4499 m_errorMonitor->SetBailout(&data.bailout);
4500 // Add many entries to command buffer from another thread.
Mike Stroyan4268d1f2015-07-13 14:45:35 -06004501 test_platform_thread_create(&thread, AddToCommandBuffer, (void *)&data);
Mike Stroyanaccf7692015-05-12 16:00:45 -06004502 // Add many entries to command buffer from this thread at the same time.
4503 AddToCommandBuffer(&data);
Mark Lobodzinski5495d132015-09-30 16:19:16 -06004504
Mike Stroyan4268d1f2015-07-13 14:45:35 -06004505 test_platform_thread_join(thread, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004506 commandBuffer.EndCommandBuffer();
Mike Stroyanaccf7692015-05-12 16:00:45 -06004507
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06004508 if (!m_errorMonitor->DesiredMsgFound()) {
4509 FAIL() << "Did not receive Error 'THREADING ERROR' from using one VkCommandBufferObj in two threads";
4510 m_errorMonitor->DumpFailureMsgs();
Mike Stroyanaccf7692015-05-12 16:00:45 -06004511 }
4512
Chia-I Wuf7458c52015-10-26 21:10:41 +08004513 vkDestroyEvent(device(), event, NULL);
Mike Stroyanaccf7692015-05-12 16:00:45 -06004514}
Mark Lobodzinski209b5292015-09-17 09:44:05 -06004515#endif // GTEST_IS_THREADSAFE
4516#endif // THREADING_TESTS
4517
Chris Forbes9f7ff632015-05-25 11:13:08 +12004518#if SHADER_CHECKER_TESTS
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -06004519TEST_F(VkLayerTest, InvalidSPIRVCodeSize)
4520{
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07004521 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06004522 "Shader is not SPIR-V");
4523
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -06004524 ASSERT_NO_FATAL_FAILURE(InitState());
4525 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
4526
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -06004527 VkShaderModule module;
4528 VkShaderModuleCreateInfo moduleCreateInfo;
4529 struct icd_spv_header spv;
4530
4531 spv.magic = ICD_SPV_MAGIC;
4532 spv.version = ICD_SPV_VERSION;
4533 spv.gen_magic = 0;
4534
4535 moduleCreateInfo.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;
4536 moduleCreateInfo.pNext = NULL;
Chia-I Wu8094f192015-10-26 19:22:06 +08004537 moduleCreateInfo.pCode = (const uint32_t *) &spv;
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -06004538 moduleCreateInfo.codeSize = 4;
4539 moduleCreateInfo.flags = 0;
Chia-I Wuf7458c52015-10-26 21:10:41 +08004540 vkCreateShaderModule(m_device->device(), &moduleCreateInfo, NULL, &module);
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -06004541
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06004542 if (!m_errorMonitor->DesiredMsgFound()) {
4543 FAIL() << "Did not recieive Error 'Shader is not SPIR-V'";
4544 m_errorMonitor->DumpFailureMsgs();
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -06004545 }
4546}
4547
4548TEST_F(VkLayerTest, InvalidSPIRVMagic)
4549{
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07004550 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06004551 "Shader is not SPIR-V");
4552
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -06004553 ASSERT_NO_FATAL_FAILURE(InitState());
4554 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
4555
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -06004556 VkShaderModule module;
4557 VkShaderModuleCreateInfo moduleCreateInfo;
4558 struct icd_spv_header spv;
4559
4560 spv.magic = ~ICD_SPV_MAGIC;
4561 spv.version = ICD_SPV_VERSION;
4562 spv.gen_magic = 0;
4563
4564 moduleCreateInfo.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;
4565 moduleCreateInfo.pNext = NULL;
Chia-I Wu8094f192015-10-26 19:22:06 +08004566 moduleCreateInfo.pCode = (const uint32_t *) &spv;
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -06004567 moduleCreateInfo.codeSize = sizeof(spv) + 10;
4568 moduleCreateInfo.flags = 0;
Chia-I Wuf7458c52015-10-26 21:10:41 +08004569 vkCreateShaderModule(m_device->device(), &moduleCreateInfo, NULL, &module);
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -06004570
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06004571 if (!m_errorMonitor->DesiredMsgFound()) {
4572 FAIL() << "Did not recieive Error 'Shader is not SPIR-V'";
4573 m_errorMonitor->DumpFailureMsgs();
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -06004574 }
4575}
4576
4577TEST_F(VkLayerTest, InvalidSPIRVVersion)
4578{
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07004579 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06004580 "Shader is not SPIR-V");
4581
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -06004582 ASSERT_NO_FATAL_FAILURE(InitState());
4583 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
4584
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -06004585 VkShaderModule module;
4586 VkShaderModuleCreateInfo moduleCreateInfo;
4587 struct icd_spv_header spv;
4588
4589 spv.magic = ICD_SPV_MAGIC;
4590 spv.version = ~ICD_SPV_VERSION;
4591 spv.gen_magic = 0;
4592
4593 moduleCreateInfo.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;
4594 moduleCreateInfo.pNext = NULL;
4595
Chia-I Wu8094f192015-10-26 19:22:06 +08004596 moduleCreateInfo.pCode = (const uint32_t *) &spv;
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -06004597 moduleCreateInfo.codeSize = sizeof(spv) + 10;
4598 moduleCreateInfo.flags = 0;
Chia-I Wuf7458c52015-10-26 21:10:41 +08004599 vkCreateShaderModule(m_device->device(), &moduleCreateInfo, NULL, &module);
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -06004600
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06004601 if (!m_errorMonitor->DesiredMsgFound()) {
4602 FAIL() << "Did not recieive Error 'Shader is not SPIR-V'";
4603 m_errorMonitor->DumpFailureMsgs();
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -06004604 }
4605}
4606
Chris Forbes9f7ff632015-05-25 11:13:08 +12004607TEST_F(VkLayerTest, CreatePipelineVertexOutputNotConsumed)
4608{
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07004609 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERF_WARN_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06004610 "not consumed by fragment shader");
4611
Chris Forbes9f7ff632015-05-25 11:13:08 +12004612 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06004613 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes9f7ff632015-05-25 11:13:08 +12004614
4615 char const *vsSource =
Tony Barboure804d202016-01-05 13:37:45 -07004616 "#version 400\n"
Chris Forbes9f7ff632015-05-25 11:13:08 +12004617 "#extension GL_ARB_separate_shader_objects: require\n"
4618 "#extension GL_ARB_shading_language_420pack: require\n"
4619 "\n"
4620 "layout(location=0) out float x;\n"
Tony Barboure804d202016-01-05 13:37:45 -07004621 "out gl_PerVertex {\n"
4622 " vec4 gl_Position;\n"
4623 "};\n"
Chris Forbes9f7ff632015-05-25 11:13:08 +12004624 "void main(){\n"
4625 " gl_Position = vec4(1);\n"
4626 " x = 0;\n"
4627 "}\n";
4628 char const *fsSource =
Tony Barboure804d202016-01-05 13:37:45 -07004629 "#version 400\n"
Chris Forbes9f7ff632015-05-25 11:13:08 +12004630 "#extension GL_ARB_separate_shader_objects: require\n"
4631 "#extension GL_ARB_shading_language_420pack: require\n"
4632 "\n"
4633 "layout(location=0) out vec4 color;\n"
4634 "void main(){\n"
4635 " color = vec4(1);\n"
4636 "}\n";
4637
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06004638 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
4639 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes9f7ff632015-05-25 11:13:08 +12004640
4641 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +08004642 pipe.AddColorAttachment();
Chris Forbes9f7ff632015-05-25 11:13:08 +12004643 pipe.AddShader(&vs);
4644 pipe.AddShader(&fs);
4645
Chris Forbes9f7ff632015-05-25 11:13:08 +12004646 VkDescriptorSetObj descriptorSet(m_device);
4647 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004648 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes9f7ff632015-05-25 11:13:08 +12004649
Tony Barbour5781e8f2015-08-04 16:23:11 -06004650 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes9f7ff632015-05-25 11:13:08 +12004651
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06004652 if (!m_errorMonitor->DesiredMsgFound()) {
4653 FAIL() << "Did not receive Warning 'not consumed by fragment shader'";
4654 m_errorMonitor->DumpFailureMsgs();
Chris Forbes9f7ff632015-05-25 11:13:08 +12004655 }
4656}
Chris Forbes9f7ff632015-05-25 11:13:08 +12004657
Chris Forbes59cb88d2015-05-25 11:13:13 +12004658TEST_F(VkLayerTest, CreatePipelineFragmentInputNotProvided)
4659{
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07004660 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06004661 "not written by vertex shader");
4662
Chris Forbes59cb88d2015-05-25 11:13:13 +12004663 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06004664 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes59cb88d2015-05-25 11:13:13 +12004665
4666 char const *vsSource =
Tony Barboure804d202016-01-05 13:37:45 -07004667 "#version 400\n"
Chris Forbes59cb88d2015-05-25 11:13:13 +12004668 "#extension GL_ARB_separate_shader_objects: require\n"
4669 "#extension GL_ARB_shading_language_420pack: require\n"
4670 "\n"
Tony Barboure804d202016-01-05 13:37:45 -07004671 "out gl_PerVertex {\n"
4672 " vec4 gl_Position;\n"
4673 "};\n"
Chris Forbes59cb88d2015-05-25 11:13:13 +12004674 "void main(){\n"
4675 " gl_Position = vec4(1);\n"
4676 "}\n";
4677 char const *fsSource =
Tony Barboure804d202016-01-05 13:37:45 -07004678 "#version 400\n"
Chris Forbes59cb88d2015-05-25 11:13:13 +12004679 "#extension GL_ARB_separate_shader_objects: require\n"
4680 "#extension GL_ARB_shading_language_420pack: require\n"
4681 "\n"
4682 "layout(location=0) in float x;\n"
4683 "layout(location=0) out vec4 color;\n"
4684 "void main(){\n"
4685 " color = vec4(x);\n"
4686 "}\n";
4687
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06004688 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
4689 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes59cb88d2015-05-25 11:13:13 +12004690
4691 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +08004692 pipe.AddColorAttachment();
Chris Forbes59cb88d2015-05-25 11:13:13 +12004693 pipe.AddShader(&vs);
4694 pipe.AddShader(&fs);
4695
Chris Forbes59cb88d2015-05-25 11:13:13 +12004696 VkDescriptorSetObj descriptorSet(m_device);
4697 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004698 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes59cb88d2015-05-25 11:13:13 +12004699
Tony Barbour5781e8f2015-08-04 16:23:11 -06004700 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes59cb88d2015-05-25 11:13:13 +12004701
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06004702 if (!m_errorMonitor->DesiredMsgFound()) {
4703 FAIL() << "Did not receive Error 'not written by vertex shader'";
4704 m_errorMonitor->DumpFailureMsgs();
Chris Forbes59cb88d2015-05-25 11:13:13 +12004705 }
4706}
4707
Chris Forbesb56af562015-05-25 11:13:17 +12004708TEST_F(VkLayerTest, CreatePipelineVsFsTypeMismatch)
4709{
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07004710 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06004711 "Type mismatch on location 0");
4712
Chris Forbesb56af562015-05-25 11:13:17 +12004713 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06004714 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesb56af562015-05-25 11:13:17 +12004715
4716 char const *vsSource =
Tony Barboure804d202016-01-05 13:37:45 -07004717 "#version 400\n"
Chris Forbesb56af562015-05-25 11:13:17 +12004718 "#extension GL_ARB_separate_shader_objects: require\n"
4719 "#extension GL_ARB_shading_language_420pack: require\n"
4720 "\n"
4721 "layout(location=0) out int x;\n"
Tony Barboure804d202016-01-05 13:37:45 -07004722 "out gl_PerVertex {\n"
4723 " vec4 gl_Position;\n"
4724 "};\n"
Chris Forbesb56af562015-05-25 11:13:17 +12004725 "void main(){\n"
4726 " x = 0;\n"
4727 " gl_Position = vec4(1);\n"
4728 "}\n";
4729 char const *fsSource =
Tony Barboure804d202016-01-05 13:37:45 -07004730 "#version 400\n"
Chris Forbesb56af562015-05-25 11:13:17 +12004731 "#extension GL_ARB_separate_shader_objects: require\n"
4732 "#extension GL_ARB_shading_language_420pack: require\n"
4733 "\n"
4734 "layout(location=0) in float x;\n" /* VS writes int */
4735 "layout(location=0) out vec4 color;\n"
4736 "void main(){\n"
4737 " color = vec4(x);\n"
4738 "}\n";
4739
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06004740 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
4741 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesb56af562015-05-25 11:13:17 +12004742
4743 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +08004744 pipe.AddColorAttachment();
Chris Forbesb56af562015-05-25 11:13:17 +12004745 pipe.AddShader(&vs);
4746 pipe.AddShader(&fs);
4747
Chris Forbesb56af562015-05-25 11:13:17 +12004748 VkDescriptorSetObj descriptorSet(m_device);
4749 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004750 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesb56af562015-05-25 11:13:17 +12004751
Tony Barbour5781e8f2015-08-04 16:23:11 -06004752 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesb56af562015-05-25 11:13:17 +12004753
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06004754 if (!m_errorMonitor->DesiredMsgFound()) {
4755 FAIL() << "Did not receive Error 'Type mismatch on location 0'";
4756 m_errorMonitor->DumpFailureMsgs();
Chris Forbesb56af562015-05-25 11:13:17 +12004757 }
4758}
4759
Chris Forbesde136e02015-05-25 11:13:28 +12004760TEST_F(VkLayerTest, CreatePipelineAttribNotConsumed)
4761{
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07004762 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERF_WARN_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06004763 "location 0 not consumed by VS");
4764
Chris Forbesde136e02015-05-25 11:13:28 +12004765 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06004766 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesde136e02015-05-25 11:13:28 +12004767
4768 VkVertexInputBindingDescription input_binding;
4769 memset(&input_binding, 0, sizeof(input_binding));
4770
4771 VkVertexInputAttributeDescription input_attrib;
4772 memset(&input_attrib, 0, sizeof(input_attrib));
4773 input_attrib.format = VK_FORMAT_R32_SFLOAT;
4774
4775 char const *vsSource =
Tony Barboure804d202016-01-05 13:37:45 -07004776 "#version 400\n"
Chris Forbesde136e02015-05-25 11:13:28 +12004777 "#extension GL_ARB_separate_shader_objects: require\n"
4778 "#extension GL_ARB_shading_language_420pack: require\n"
4779 "\n"
Tony Barboure804d202016-01-05 13:37:45 -07004780 "out gl_PerVertex {\n"
4781 " vec4 gl_Position;\n"
4782 "};\n"
Chris Forbesde136e02015-05-25 11:13:28 +12004783 "void main(){\n"
4784 " gl_Position = vec4(1);\n"
4785 "}\n";
4786 char const *fsSource =
Tony Barboure804d202016-01-05 13:37:45 -07004787 "#version 400\n"
Chris Forbesde136e02015-05-25 11:13:28 +12004788 "#extension GL_ARB_separate_shader_objects: require\n"
4789 "#extension GL_ARB_shading_language_420pack: require\n"
4790 "\n"
4791 "layout(location=0) out vec4 color;\n"
4792 "void main(){\n"
4793 " color = vec4(1);\n"
4794 "}\n";
4795
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06004796 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
4797 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesde136e02015-05-25 11:13:28 +12004798
4799 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +08004800 pipe.AddColorAttachment();
Chris Forbesde136e02015-05-25 11:13:28 +12004801 pipe.AddShader(&vs);
4802 pipe.AddShader(&fs);
4803
4804 pipe.AddVertexInputBindings(&input_binding, 1);
4805 pipe.AddVertexInputAttribs(&input_attrib, 1);
4806
Chris Forbesde136e02015-05-25 11:13:28 +12004807 VkDescriptorSetObj descriptorSet(m_device);
4808 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004809 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesde136e02015-05-25 11:13:28 +12004810
Tony Barbour5781e8f2015-08-04 16:23:11 -06004811 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesde136e02015-05-25 11:13:28 +12004812
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06004813 if (!m_errorMonitor->DesiredMsgFound()) {
4814 FAIL() << "Did not receive Warning 'location 0 not consumed by VS'";
4815 m_errorMonitor->DumpFailureMsgs();
Chris Forbesde136e02015-05-25 11:13:28 +12004816 }
4817}
4818
Chris Forbes62e8e502015-05-25 11:13:29 +12004819TEST_F(VkLayerTest, CreatePipelineAttribNotProvided)
4820{
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07004821 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06004822 "VS consumes input at location 0 but not provided");
4823
Chris Forbes62e8e502015-05-25 11:13:29 +12004824 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06004825 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes62e8e502015-05-25 11:13:29 +12004826
4827 char const *vsSource =
Tony Barboure804d202016-01-05 13:37:45 -07004828 "#version 400\n"
Chris Forbes62e8e502015-05-25 11:13:29 +12004829 "#extension GL_ARB_separate_shader_objects: require\n"
4830 "#extension GL_ARB_shading_language_420pack: require\n"
4831 "\n"
4832 "layout(location=0) in vec4 x;\n" /* not provided */
Tony Barboure804d202016-01-05 13:37:45 -07004833 "out gl_PerVertex {\n"
4834 " vec4 gl_Position;\n"
4835 "};\n"
Chris Forbes62e8e502015-05-25 11:13:29 +12004836 "void main(){\n"
4837 " gl_Position = x;\n"
4838 "}\n";
4839 char const *fsSource =
Tony Barboure804d202016-01-05 13:37:45 -07004840 "#version 400\n"
Chris Forbes62e8e502015-05-25 11:13:29 +12004841 "#extension GL_ARB_separate_shader_objects: require\n"
4842 "#extension GL_ARB_shading_language_420pack: require\n"
4843 "\n"
4844 "layout(location=0) out vec4 color;\n"
4845 "void main(){\n"
4846 " color = vec4(1);\n"
4847 "}\n";
4848
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06004849 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
4850 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes62e8e502015-05-25 11:13:29 +12004851
4852 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +08004853 pipe.AddColorAttachment();
Chris Forbes62e8e502015-05-25 11:13:29 +12004854 pipe.AddShader(&vs);
4855 pipe.AddShader(&fs);
4856
Chris Forbes62e8e502015-05-25 11:13:29 +12004857 VkDescriptorSetObj descriptorSet(m_device);
4858 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004859 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes62e8e502015-05-25 11:13:29 +12004860
Tony Barbour5781e8f2015-08-04 16:23:11 -06004861 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes62e8e502015-05-25 11:13:29 +12004862
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06004863 if (!m_errorMonitor->DesiredMsgFound()) {
4864 FAIL() << "Did not receive Error 'VS consumes input at location 0 but not provided'";
4865 m_errorMonitor->DumpFailureMsgs();
Chris Forbes62e8e502015-05-25 11:13:29 +12004866 }
4867}
4868
Chris Forbesc97d98e2015-05-25 11:13:31 +12004869TEST_F(VkLayerTest, CreatePipelineAttribTypeMismatch)
4870{
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07004871 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06004872 "location 0 does not match VS input type");
4873
Chris Forbesc97d98e2015-05-25 11:13:31 +12004874 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06004875 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesc97d98e2015-05-25 11:13:31 +12004876
4877 VkVertexInputBindingDescription input_binding;
4878 memset(&input_binding, 0, sizeof(input_binding));
4879
4880 VkVertexInputAttributeDescription input_attrib;
4881 memset(&input_attrib, 0, sizeof(input_attrib));
4882 input_attrib.format = VK_FORMAT_R32_SFLOAT;
4883
4884 char const *vsSource =
Tony Barboure804d202016-01-05 13:37:45 -07004885 "#version 400\n"
Chris Forbesc97d98e2015-05-25 11:13:31 +12004886 "#extension GL_ARB_separate_shader_objects: require\n"
4887 "#extension GL_ARB_shading_language_420pack: require\n"
4888 "\n"
4889 "layout(location=0) in int x;\n" /* attrib provided float */
Tony Barboure804d202016-01-05 13:37:45 -07004890 "out gl_PerVertex {\n"
4891 " vec4 gl_Position;\n"
4892 "};\n"
Chris Forbesc97d98e2015-05-25 11:13:31 +12004893 "void main(){\n"
4894 " gl_Position = vec4(x);\n"
4895 "}\n";
4896 char const *fsSource =
Tony Barboure804d202016-01-05 13:37:45 -07004897 "#version 400\n"
Chris Forbesc97d98e2015-05-25 11:13:31 +12004898 "#extension GL_ARB_separate_shader_objects: require\n"
4899 "#extension GL_ARB_shading_language_420pack: require\n"
4900 "\n"
4901 "layout(location=0) out vec4 color;\n"
4902 "void main(){\n"
4903 " color = vec4(1);\n"
4904 "}\n";
4905
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06004906 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
4907 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesc97d98e2015-05-25 11:13:31 +12004908
4909 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +08004910 pipe.AddColorAttachment();
Chris Forbesc97d98e2015-05-25 11:13:31 +12004911 pipe.AddShader(&vs);
4912 pipe.AddShader(&fs);
4913
4914 pipe.AddVertexInputBindings(&input_binding, 1);
4915 pipe.AddVertexInputAttribs(&input_attrib, 1);
4916
Chris Forbesc97d98e2015-05-25 11:13:31 +12004917 VkDescriptorSetObj descriptorSet(m_device);
4918 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004919 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesc97d98e2015-05-25 11:13:31 +12004920
Tony Barbour5781e8f2015-08-04 16:23:11 -06004921 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesc97d98e2015-05-25 11:13:31 +12004922
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06004923 if (!m_errorMonitor->DesiredMsgFound()) {
4924 FAIL() << "Did not receive Error 'location 0 does not match VS input type'";
4925 m_errorMonitor->DumpFailureMsgs();
Chris Forbesc97d98e2015-05-25 11:13:31 +12004926 }
4927}
4928
Chris Forbes2682b242015-11-24 11:13:14 +13004929TEST_F(VkLayerTest, CreatePipelineAttribMatrixType)
4930{
4931 m_errorMonitor->SetDesiredFailureMsg(~0u, "");
4932
4933 ASSERT_NO_FATAL_FAILURE(InitState());
4934 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
4935
4936 VkVertexInputBindingDescription input_binding;
4937 memset(&input_binding, 0, sizeof(input_binding));
4938
4939 VkVertexInputAttributeDescription input_attribs[2];
4940 memset(input_attribs, 0, sizeof(input_attribs));
4941
4942 for (int i = 0; i < 2; i++) {
4943 input_attribs[i].format = VK_FORMAT_R32G32B32A32_SFLOAT;
4944 input_attribs[i].location = i;
4945 }
4946
4947 char const *vsSource =
Tony Barboure804d202016-01-05 13:37:45 -07004948 "#version 400\n"
Chris Forbes2682b242015-11-24 11:13:14 +13004949 "#extension GL_ARB_separate_shader_objects: require\n"
4950 "#extension GL_ARB_shading_language_420pack: require\n"
4951 "\n"
4952 "layout(location=0) in mat2x4 x;\n"
Tony Barboure804d202016-01-05 13:37:45 -07004953 "out gl_PerVertex {\n"
4954 " vec4 gl_Position;\n"
4955 "};\n"
Chris Forbes2682b242015-11-24 11:13:14 +13004956 "void main(){\n"
4957 " gl_Position = x[0] + x[1];\n"
4958 "}\n";
4959 char const *fsSource =
Tony Barboure804d202016-01-05 13:37:45 -07004960 "#version 400\n"
Chris Forbes2682b242015-11-24 11:13:14 +13004961 "#extension GL_ARB_separate_shader_objects: require\n"
4962 "#extension GL_ARB_shading_language_420pack: require\n"
4963 "\n"
4964 "layout(location=0) out vec4 color;\n"
4965 "void main(){\n"
4966 " color = vec4(1);\n"
4967 "}\n";
4968
4969 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
4970 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
4971
4972 VkPipelineObj pipe(m_device);
4973 pipe.AddColorAttachment();
4974 pipe.AddShader(&vs);
4975 pipe.AddShader(&fs);
4976
4977 pipe.AddVertexInputBindings(&input_binding, 1);
4978 pipe.AddVertexInputAttribs(input_attribs, 2);
4979
4980 VkDescriptorSetObj descriptorSet(m_device);
4981 descriptorSet.AppendDummy();
4982 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
4983
4984 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
4985
4986 /* expect success */
4987 if (m_errorMonitor->DesiredMsgFound()) {
4988 FAIL() << "Expected to succeed but: " << m_errorMonitor->GetFailureMsg();
4989 m_errorMonitor->DumpFailureMsgs();
4990 }
4991}
4992
4993/*
4994 * Would work, but not supported by glslang! This is similar to the matrix case above.
4995 *
4996TEST_F(VkLayerTest, CreatePipelineAttribArrayType)
4997{
4998 m_errorMonitor->SetDesiredFailureMsg(~0u, "");
4999
5000 ASSERT_NO_FATAL_FAILURE(InitState());
5001 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
5002
5003 VkVertexInputBindingDescription input_binding;
5004 memset(&input_binding, 0, sizeof(input_binding));
5005
5006 VkVertexInputAttributeDescription input_attribs[2];
5007 memset(input_attribs, 0, sizeof(input_attribs));
5008
5009 for (int i = 0; i < 2; i++) {
5010 input_attribs[i].format = VK_FORMAT_R32G32B32A32_SFLOAT;
5011 input_attribs[i].location = i;
5012 }
5013
5014 char const *vsSource =
Tony Barboure804d202016-01-05 13:37:45 -07005015 "#version 400\n"
Chris Forbes2682b242015-11-24 11:13:14 +13005016 "#extension GL_ARB_separate_shader_objects: require\n"
5017 "#extension GL_ARB_shading_language_420pack: require\n"
5018 "\n"
5019 "layout(location=0) in vec4 x[2];\n"
Tony Barboure804d202016-01-05 13:37:45 -07005020 "out gl_PerVertex {\n"
5021 " vec4 gl_Position;\n"
5022 "};\n"
Chris Forbes2682b242015-11-24 11:13:14 +13005023 "void main(){\n"
5024 " gl_Position = x[0] + x[1];\n"
5025 "}\n";
5026 char const *fsSource =
Tony Barboure804d202016-01-05 13:37:45 -07005027 "#version 400\n"
Chris Forbes2682b242015-11-24 11:13:14 +13005028 "#extension GL_ARB_separate_shader_objects: require\n"
5029 "#extension GL_ARB_shading_language_420pack: require\n"
5030 "\n"
5031 "layout(location=0) out vec4 color;\n"
5032 "void main(){\n"
5033 " color = vec4(1);\n"
5034 "}\n";
5035
5036 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
5037 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
5038
5039 VkPipelineObj pipe(m_device);
5040 pipe.AddColorAttachment();
5041 pipe.AddShader(&vs);
5042 pipe.AddShader(&fs);
5043
5044 pipe.AddVertexInputBindings(&input_binding, 1);
5045 pipe.AddVertexInputAttribs(input_attribs, 2);
5046
5047 VkDescriptorSetObj descriptorSet(m_device);
5048 descriptorSet.AppendDummy();
5049 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
5050
5051 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
5052
5053 if (m_errorMonitor->DesiredMsgFound()) {
5054 FAIL() << "Expected to succeed but: " << m_errorMonitor->GetFailureMsg();
5055 m_errorMonitor->DumpFailureMsgs();
5056 }
5057}
5058*/
5059
Chris Forbes280ba2c2015-06-12 11:16:41 +12005060TEST_F(VkLayerTest, CreatePipelineAttribBindingConflict)
5061{
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07005062 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06005063 "Duplicate vertex input binding descriptions for binding 0");
5064
Chris Forbes280ba2c2015-06-12 11:16:41 +12005065 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06005066 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes280ba2c2015-06-12 11:16:41 +12005067
5068 /* Two binding descriptions for binding 0 */
5069 VkVertexInputBindingDescription input_bindings[2];
5070 memset(input_bindings, 0, sizeof(input_bindings));
5071
5072 VkVertexInputAttributeDescription input_attrib;
5073 memset(&input_attrib, 0, sizeof(input_attrib));
5074 input_attrib.format = VK_FORMAT_R32_SFLOAT;
5075
5076 char const *vsSource =
Tony Barboure804d202016-01-05 13:37:45 -07005077 "#version 400\n"
Chris Forbes280ba2c2015-06-12 11:16:41 +12005078 "#extension GL_ARB_separate_shader_objects: require\n"
5079 "#extension GL_ARB_shading_language_420pack: require\n"
5080 "\n"
5081 "layout(location=0) in float x;\n" /* attrib provided float */
Tony Barboure804d202016-01-05 13:37:45 -07005082 "out gl_PerVertex {\n"
5083 " vec4 gl_Position;\n"
5084 "};\n"
Chris Forbes280ba2c2015-06-12 11:16:41 +12005085 "void main(){\n"
5086 " gl_Position = vec4(x);\n"
5087 "}\n";
5088 char const *fsSource =
Tony Barboure804d202016-01-05 13:37:45 -07005089 "#version 400\n"
Chris Forbes280ba2c2015-06-12 11:16:41 +12005090 "#extension GL_ARB_separate_shader_objects: require\n"
5091 "#extension GL_ARB_shading_language_420pack: require\n"
5092 "\n"
5093 "layout(location=0) out vec4 color;\n"
5094 "void main(){\n"
5095 " color = vec4(1);\n"
5096 "}\n";
5097
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06005098 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
5099 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes280ba2c2015-06-12 11:16:41 +12005100
5101 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +08005102 pipe.AddColorAttachment();
Chris Forbes280ba2c2015-06-12 11:16:41 +12005103 pipe.AddShader(&vs);
5104 pipe.AddShader(&fs);
5105
5106 pipe.AddVertexInputBindings(input_bindings, 2);
5107 pipe.AddVertexInputAttribs(&input_attrib, 1);
5108
Chris Forbes280ba2c2015-06-12 11:16:41 +12005109 VkDescriptorSetObj descriptorSet(m_device);
5110 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005111 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes280ba2c2015-06-12 11:16:41 +12005112
Tony Barbour5781e8f2015-08-04 16:23:11 -06005113 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes280ba2c2015-06-12 11:16:41 +12005114
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06005115 if (!m_errorMonitor->DesiredMsgFound()) {
5116 FAIL() << "Did not receive Error 'Duplicate vertex input binding descriptions for binding 0'";
5117 m_errorMonitor->DumpFailureMsgs();
Chris Forbes280ba2c2015-06-12 11:16:41 +12005118 }
5119}
Chris Forbes8f68b562015-05-25 11:13:32 +12005120
Chris Forbes4d6d1e52015-05-25 11:13:40 +12005121TEST_F(VkLayerTest, CreatePipelineFragmentOutputNotWritten)
5122{
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07005123 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06005124 "Attachment 0 not written by FS");
5125
Chris Forbes4d6d1e52015-05-25 11:13:40 +12005126 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbes4d6d1e52015-05-25 11:13:40 +12005127
5128 char const *vsSource =
Tony Barboure804d202016-01-05 13:37:45 -07005129 "#version 400\n"
Chris Forbes4d6d1e52015-05-25 11:13:40 +12005130 "#extension GL_ARB_separate_shader_objects: require\n"
5131 "#extension GL_ARB_shading_language_420pack: require\n"
5132 "\n"
Tony Barboure804d202016-01-05 13:37:45 -07005133 "out gl_PerVertex {\n"
5134 " vec4 gl_Position;\n"
5135 "};\n"
Chris Forbes4d6d1e52015-05-25 11:13:40 +12005136 "void main(){\n"
5137 " gl_Position = vec4(1);\n"
5138 "}\n";
5139 char const *fsSource =
Tony Barboure804d202016-01-05 13:37:45 -07005140 "#version 400\n"
Chris Forbes4d6d1e52015-05-25 11:13:40 +12005141 "#extension GL_ARB_separate_shader_objects: require\n"
5142 "#extension GL_ARB_shading_language_420pack: require\n"
5143 "\n"
5144 "void main(){\n"
5145 "}\n";
5146
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06005147 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
5148 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes4d6d1e52015-05-25 11:13:40 +12005149
5150 VkPipelineObj pipe(m_device);
5151 pipe.AddShader(&vs);
5152 pipe.AddShader(&fs);
5153
Chia-I Wu08accc62015-07-07 11:50:03 +08005154 /* set up CB 0, not written */
5155 pipe.AddColorAttachment();
5156 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes4d6d1e52015-05-25 11:13:40 +12005157
Chris Forbes4d6d1e52015-05-25 11:13:40 +12005158 VkDescriptorSetObj descriptorSet(m_device);
5159 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005160 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes4d6d1e52015-05-25 11:13:40 +12005161
Tony Barbour5781e8f2015-08-04 16:23:11 -06005162 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes4d6d1e52015-05-25 11:13:40 +12005163
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06005164 if (!m_errorMonitor->DesiredMsgFound()) {
5165 FAIL() << "Did not receive Error 'Attachment 0 not written by FS'";
5166 m_errorMonitor->DumpFailureMsgs();
Chris Forbes4d6d1e52015-05-25 11:13:40 +12005167 }
5168}
5169
Chris Forbesf3fffaa2015-05-25 11:13:43 +12005170TEST_F(VkLayerTest, CreatePipelineFragmentOutputNotConsumed)
5171{
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07005172 // TODO: verify that this matches layer
5173 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARN_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06005174 "FS writes to output location 1 with no matching attachment");
5175
Chris Forbesf3fffaa2015-05-25 11:13:43 +12005176 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbesf3fffaa2015-05-25 11:13:43 +12005177
5178 char const *vsSource =
Tony Barboure804d202016-01-05 13:37:45 -07005179 "#version 400\n"
Chris Forbesf3fffaa2015-05-25 11:13:43 +12005180 "#extension GL_ARB_separate_shader_objects: require\n"
5181 "#extension GL_ARB_shading_language_420pack: require\n"
5182 "\n"
Tony Barboure804d202016-01-05 13:37:45 -07005183 "out gl_PerVertex {\n"
5184 " vec4 gl_Position;\n"
5185 "};\n"
Chris Forbesf3fffaa2015-05-25 11:13:43 +12005186 "void main(){\n"
5187 " gl_Position = vec4(1);\n"
5188 "}\n";
5189 char const *fsSource =
Tony Barboure804d202016-01-05 13:37:45 -07005190 "#version 400\n"
Chris Forbesf3fffaa2015-05-25 11:13:43 +12005191 "#extension GL_ARB_separate_shader_objects: require\n"
5192 "#extension GL_ARB_shading_language_420pack: require\n"
5193 "\n"
5194 "layout(location=0) out vec4 x;\n"
5195 "layout(location=1) out vec4 y;\n" /* no matching attachment for this */
5196 "void main(){\n"
5197 " x = vec4(1);\n"
5198 " y = vec4(1);\n"
5199 "}\n";
5200
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06005201 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
5202 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesf3fffaa2015-05-25 11:13:43 +12005203
5204 VkPipelineObj pipe(m_device);
5205 pipe.AddShader(&vs);
5206 pipe.AddShader(&fs);
5207
Chia-I Wu08accc62015-07-07 11:50:03 +08005208 /* set up CB 0, not written */
5209 pipe.AddColorAttachment();
5210 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesf3fffaa2015-05-25 11:13:43 +12005211 /* FS writes CB 1, but we don't configure it */
5212
Chris Forbesf3fffaa2015-05-25 11:13:43 +12005213 VkDescriptorSetObj descriptorSet(m_device);
5214 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005215 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesf3fffaa2015-05-25 11:13:43 +12005216
Tony Barbour5781e8f2015-08-04 16:23:11 -06005217 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesf3fffaa2015-05-25 11:13:43 +12005218
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06005219 if (!m_errorMonitor->DesiredMsgFound()) {
5220 FAIL() << "Did not receive Error 'FS writes to output location 1 with no matching attachment'";
5221 m_errorMonitor->DumpFailureMsgs();
Chris Forbesf3fffaa2015-05-25 11:13:43 +12005222 }
5223}
5224
Chris Forbesa36d69e2015-05-25 11:13:44 +12005225TEST_F(VkLayerTest, CreatePipelineFragmentOutputTypeMismatch)
5226{
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07005227 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06005228 "does not match FS output type");
5229
Chris Forbesa36d69e2015-05-25 11:13:44 +12005230 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbesa36d69e2015-05-25 11:13:44 +12005231
5232 char const *vsSource =
Tony Barboure804d202016-01-05 13:37:45 -07005233 "#version 400\n"
Chris Forbesa36d69e2015-05-25 11:13:44 +12005234 "#extension GL_ARB_separate_shader_objects: require\n"
5235 "#extension GL_ARB_shading_language_420pack: require\n"
5236 "\n"
Tony Barboure804d202016-01-05 13:37:45 -07005237 "out gl_PerVertex {\n"
5238 " vec4 gl_Position;\n"
5239 "};\n"
Chris Forbesa36d69e2015-05-25 11:13:44 +12005240 "void main(){\n"
5241 " gl_Position = vec4(1);\n"
5242 "}\n";
5243 char const *fsSource =
Tony Barboure804d202016-01-05 13:37:45 -07005244 "#version 400\n"
Chris Forbesa36d69e2015-05-25 11:13:44 +12005245 "#extension GL_ARB_separate_shader_objects: require\n"
5246 "#extension GL_ARB_shading_language_420pack: require\n"
5247 "\n"
5248 "layout(location=0) out ivec4 x;\n" /* not UNORM */
5249 "void main(){\n"
5250 " x = ivec4(1);\n"
5251 "}\n";
5252
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06005253 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
5254 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesa36d69e2015-05-25 11:13:44 +12005255
5256 VkPipelineObj pipe(m_device);
5257 pipe.AddShader(&vs);
5258 pipe.AddShader(&fs);
5259
Chia-I Wu08accc62015-07-07 11:50:03 +08005260 /* set up CB 0; type is UNORM by default */
5261 pipe.AddColorAttachment();
5262 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesa36d69e2015-05-25 11:13:44 +12005263
Chris Forbesa36d69e2015-05-25 11:13:44 +12005264 VkDescriptorSetObj descriptorSet(m_device);
5265 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005266 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesa36d69e2015-05-25 11:13:44 +12005267
Tony Barbour5781e8f2015-08-04 16:23:11 -06005268 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesa36d69e2015-05-25 11:13:44 +12005269
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06005270 if (!m_errorMonitor->DesiredMsgFound()) {
5271 FAIL() << "Did not receive Error 'does not match FS output type'";
5272 m_errorMonitor->DumpFailureMsgs();
Chris Forbesa36d69e2015-05-25 11:13:44 +12005273 }
5274}
Chris Forbes7b1b8932015-06-05 14:43:36 +12005275
Chris Forbes556c76c2015-08-14 12:04:59 +12005276TEST_F(VkLayerTest, CreatePipelineUniformBlockNotProvided)
5277{
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07005278 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06005279 "not declared in pipeline layout");
5280
Chris Forbes556c76c2015-08-14 12:04:59 +12005281 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbes556c76c2015-08-14 12:04:59 +12005282
5283 char const *vsSource =
Tony Barboure804d202016-01-05 13:37:45 -07005284 "#version 400\n"
Chris Forbes556c76c2015-08-14 12:04:59 +12005285 "#extension GL_ARB_separate_shader_objects: require\n"
5286 "#extension GL_ARB_shading_language_420pack: require\n"
5287 "\n"
Tony Barboure804d202016-01-05 13:37:45 -07005288 "out gl_PerVertex {\n"
5289 " vec4 gl_Position;\n"
5290 "};\n"
Chris Forbes556c76c2015-08-14 12:04:59 +12005291 "void main(){\n"
5292 " gl_Position = vec4(1);\n"
5293 "}\n";
5294 char const *fsSource =
Tony Barboure804d202016-01-05 13:37:45 -07005295 "#version 400\n"
Chris Forbes556c76c2015-08-14 12:04:59 +12005296 "#extension GL_ARB_separate_shader_objects: require\n"
5297 "#extension GL_ARB_shading_language_420pack: require\n"
5298 "\n"
5299 "layout(location=0) out vec4 x;\n"
5300 "layout(set=0) layout(binding=0) uniform foo { int x; int y; } bar;\n"
5301 "void main(){\n"
5302 " x = vec4(bar.y);\n"
5303 "}\n";
5304
Chris Forbes556c76c2015-08-14 12:04:59 +12005305
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06005306 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
5307 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes556c76c2015-08-14 12:04:59 +12005308
Chris Forbes556c76c2015-08-14 12:04:59 +12005309 VkPipelineObj pipe(m_device);
5310 pipe.AddShader(&vs);
5311 pipe.AddShader(&fs);
5312
5313 /* set up CB 0; type is UNORM by default */
5314 pipe.AddColorAttachment();
5315 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
5316
5317 VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005318 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes556c76c2015-08-14 12:04:59 +12005319
5320 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
5321
5322 /* should have generated an error -- pipeline layout does not
5323 * provide a uniform buffer in 0.0
5324 */
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06005325 if (!m_errorMonitor->DesiredMsgFound()) {
5326 FAIL() << "Did not receive Error 'not declared in pipeline layout'";
5327 m_errorMonitor->DumpFailureMsgs();
Chris Forbes556c76c2015-08-14 12:04:59 +12005328 }
5329}
5330
Mark Lobodzinski209b5292015-09-17 09:44:05 -06005331#endif // SHADER_CHECKER_TESTS
5332
5333#if DEVICE_LIMITS_TESTS
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -06005334TEST_F(VkLayerTest, CreateImageLimitsViolationWidth)
5335{
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07005336 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06005337 "CreateImage extents exceed allowable limits for format");
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -06005338
5339 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -06005340
5341 // Create an image
5342 VkImage image;
5343
5344 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
5345 const int32_t tex_width = 32;
5346 const int32_t tex_height = 32;
5347
5348 VkImageCreateInfo image_create_info = {};
5349 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
5350 image_create_info.pNext = NULL;
5351 image_create_info.imageType = VK_IMAGE_TYPE_2D;
5352 image_create_info.format = tex_format;
5353 image_create_info.extent.width = tex_width;
5354 image_create_info.extent.height = tex_height;
5355 image_create_info.extent.depth = 1;
5356 image_create_info.mipLevels = 1;
Courtney Goeltzenleuchter5d2aed42015-10-21 17:57:31 -06005357 image_create_info.arrayLayers = 1;
Chia-I Wu5c17c962015-10-31 00:31:16 +08005358 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -06005359 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
5360 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
5361 image_create_info.flags = 0;
5362
5363 // Introduce error by sending down a bogus width extent
5364 image_create_info.extent.width = 65536;
Chia-I Wuf7458c52015-10-26 21:10:41 +08005365 vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -06005366
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06005367 if (!m_errorMonitor->DesiredMsgFound()) {
5368 FAIL() << "Did not receive Error 'CreateImage extents exceed allowable limits for format'";
5369 m_errorMonitor->DumpFailureMsgs();
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -06005370 }
5371}
5372
5373TEST_F(VkLayerTest, CreateImageResourceSizeViolation)
5374{
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07005375 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06005376 "CreateImage resource size exceeds allowable maximum");
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -06005377
5378 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -06005379
5380 // Create an image
5381 VkImage image;
5382
5383 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
5384 const int32_t tex_width = 32;
5385 const int32_t tex_height = 32;
5386
5387 VkImageCreateInfo image_create_info = {};
5388 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
5389 image_create_info.pNext = NULL;
5390 image_create_info.imageType = VK_IMAGE_TYPE_2D;
5391 image_create_info.format = tex_format;
5392 image_create_info.extent.width = tex_width;
5393 image_create_info.extent.height = tex_height;
5394 image_create_info.extent.depth = 1;
5395 image_create_info.mipLevels = 1;
Courtney Goeltzenleuchter5d2aed42015-10-21 17:57:31 -06005396 image_create_info.arrayLayers = 1;
Chia-I Wu5c17c962015-10-31 00:31:16 +08005397 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -06005398 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
5399 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
5400 image_create_info.flags = 0;
5401
5402 // Introduce error by sending down individually allowable values that result in a surface size
5403 // exceeding the device maximum
5404 image_create_info.extent.width = 8192;
5405 image_create_info.extent.height = 8192;
5406 image_create_info.extent.depth = 16;
Courtney Goeltzenleuchter5d2aed42015-10-21 17:57:31 -06005407 image_create_info.arrayLayers = 4;
Chia-I Wu5c17c962015-10-31 00:31:16 +08005408 image_create_info.samples = VK_SAMPLE_COUNT_2_BIT;
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -06005409 image_create_info.format = VK_FORMAT_R8G8B8A8_UNORM;
Chia-I Wuf7458c52015-10-26 21:10:41 +08005410 vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -06005411
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06005412 if (!m_errorMonitor->DesiredMsgFound()) {
5413 FAIL() << "Did not receive Error 'CreateImage resource size exceeds allowable maximum'";
5414 m_errorMonitor->DumpFailureMsgs();
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -06005415 }
5416}
5417
Mike Stroyana3082432015-09-25 13:39:21 -06005418TEST_F(VkLayerTest, UpdateBufferAlignment)
5419{
Mike Stroyana3082432015-09-25 13:39:21 -06005420 uint32_t updateData[] = { 1, 2, 3, 4, 5, 6, 7, 8 };
5421
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07005422 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06005423 "dstOffset, is not a multiple of 4");
5424
Mike Stroyana3082432015-09-25 13:39:21 -06005425 ASSERT_NO_FATAL_FAILURE(InitState());
5426
5427 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
5428 vk_testing::Buffer buffer;
5429 buffer.init_as_dst(*m_device, (VkDeviceSize)20, reqs);
5430
5431 BeginCommandBuffer();
5432 // Introduce failure by using offset that is not multiple of 4
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005433 m_commandBuffer->UpdateBuffer(buffer.handle(), 1, 4, updateData);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06005434 if (!m_errorMonitor->DesiredMsgFound()) {
5435 FAIL() << "Did not receive Error 'vkCommandUpdateBuffer parameter, VkDeviceSize dstOffset, is not a multiple of 4'";
5436 m_errorMonitor->DumpFailureMsgs();
Mike Stroyana3082432015-09-25 13:39:21 -06005437 }
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06005438
Mike Stroyana3082432015-09-25 13:39:21 -06005439 // Introduce failure by using size that is not multiple of 4
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07005440 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06005441 "dataSize, is not a multiple of 4");
5442
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005443 m_commandBuffer->UpdateBuffer(buffer.handle(), 0, 6, updateData);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06005444
5445 if (!m_errorMonitor->DesiredMsgFound()) {
5446 FAIL() << "Did not receive Error 'vkCommandUpdateBuffer parameter, VkDeviceSize dataSize, is not a multiple of 4'";
5447 m_errorMonitor->DumpFailureMsgs();
Mike Stroyana3082432015-09-25 13:39:21 -06005448 }
5449 EndCommandBuffer();
5450}
5451
5452TEST_F(VkLayerTest, FillBufferAlignment)
5453{
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07005454 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06005455 "dstOffset, is not a multiple of 4");
Mike Stroyana3082432015-09-25 13:39:21 -06005456
5457 ASSERT_NO_FATAL_FAILURE(InitState());
5458
5459 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
5460 vk_testing::Buffer buffer;
5461 buffer.init_as_dst(*m_device, (VkDeviceSize)20, reqs);
5462
5463 BeginCommandBuffer();
5464 // Introduce failure by using offset that is not multiple of 4
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005465 m_commandBuffer->FillBuffer(buffer.handle(), 1, 4, 0x11111111);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06005466 if (!m_errorMonitor->DesiredMsgFound()) {
5467 FAIL() << "Did not receive Error 'vkCommandFillBuffer parameter, VkDeviceSize dstOffset, is not a multiple of 4'";
5468 m_errorMonitor->DumpFailureMsgs();
Mike Stroyana3082432015-09-25 13:39:21 -06005469 }
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06005470
Mike Stroyana3082432015-09-25 13:39:21 -06005471 // Introduce failure by using size that is not multiple of 4
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07005472 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06005473 "size, is not a multiple of 4");
5474
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005475 m_commandBuffer->FillBuffer(buffer.handle(), 0, 6, 0x11111111);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06005476
5477 if (!m_errorMonitor->DesiredMsgFound()) {
5478 FAIL() << "Did not receive Error 'vkCommandFillBuffer parameter, VkDeviceSize size, is not a multiple of 4'";
5479 m_errorMonitor->DumpFailureMsgs();
Mike Stroyana3082432015-09-25 13:39:21 -06005480 }
5481 EndCommandBuffer();
5482}
5483
Mark Lobodzinski209b5292015-09-17 09:44:05 -06005484#endif // DEVICE_LIMITS_TESTS
Chris Forbesa36d69e2015-05-25 11:13:44 +12005485
Tobin Ehliscde08892015-09-22 10:11:37 -06005486#if IMAGE_TESTS
5487TEST_F(VkLayerTest, InvalidImageView)
5488{
Tobin Ehliscde08892015-09-22 10:11:37 -06005489 VkResult err;
5490
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07005491 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06005492 "vkCreateImageView called with baseMipLevel 10 ");
5493
Tobin Ehliscde08892015-09-22 10:11:37 -06005494 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehliscde08892015-09-22 10:11:37 -06005495
Mike Stroyana3082432015-09-25 13:39:21 -06005496 // Create an image and try to create a view with bad baseMipLevel
Tobin Ehliscde08892015-09-22 10:11:37 -06005497 VkImage image;
5498
5499 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
5500 const int32_t tex_width = 32;
5501 const int32_t tex_height = 32;
5502
5503 VkImageCreateInfo image_create_info = {};
5504 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
5505 image_create_info.pNext = NULL;
5506 image_create_info.imageType = VK_IMAGE_TYPE_2D;
5507 image_create_info.format = tex_format;
5508 image_create_info.extent.width = tex_width;
5509 image_create_info.extent.height = tex_height;
5510 image_create_info.extent.depth = 1;
5511 image_create_info.mipLevels = 1;
Courtney Goeltzenleuchter5d2aed42015-10-21 17:57:31 -06005512 image_create_info.arrayLayers = 1;
Chia-I Wu5c17c962015-10-31 00:31:16 +08005513 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Tobin Ehliscde08892015-09-22 10:11:37 -06005514 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
5515 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
5516 image_create_info.flags = 0;
5517
Chia-I Wuf7458c52015-10-26 21:10:41 +08005518 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Tobin Ehliscde08892015-09-22 10:11:37 -06005519 ASSERT_VK_SUCCESS(err);
5520
5521 VkImageViewCreateInfo image_view_create_info = {};
5522 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
5523 image_view_create_info.image = image;
5524 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
5525 image_view_create_info.format = tex_format;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005526 image_view_create_info.subresourceRange.layerCount = 1;
Tobin Ehliscde08892015-09-22 10:11:37 -06005527 image_view_create_info.subresourceRange.baseMipLevel = 10; // cause an error
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005528 image_view_create_info.subresourceRange.levelCount = 1;
Mark Lobodzinskidc86b852015-10-23 14:20:31 -06005529 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Tobin Ehliscde08892015-09-22 10:11:37 -06005530
5531 VkImageView view;
Chia-I Wuf7458c52015-10-26 21:10:41 +08005532 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
Tobin Ehliscde08892015-09-22 10:11:37 -06005533
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06005534 if (!m_errorMonitor->DesiredMsgFound()) {
5535 FAIL() << "Did not receive Error 'vkCreateImageView called with baseMipLevel 10...'";
5536 m_errorMonitor->DumpFailureMsgs();
Tobin Ehliscde08892015-09-22 10:11:37 -06005537 }
5538}
Mike Stroyana3082432015-09-25 13:39:21 -06005539
Mark Lobodzinskidc86b852015-10-23 14:20:31 -06005540TEST_F(VkLayerTest, InvalidImageViewAspect)
5541{
Mark Lobodzinskidc86b852015-10-23 14:20:31 -06005542 VkResult err;
5543
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07005544 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06005545 "vkCreateImageView: Color image formats must have ONLY the VK_IMAGE_ASPECT_COLOR_BIT set");
5546
Mark Lobodzinskidc86b852015-10-23 14:20:31 -06005547 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskidc86b852015-10-23 14:20:31 -06005548
5549 // Create an image and try to create a view with an invalid aspectMask
5550 VkImage image;
5551
5552 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
5553 const int32_t tex_width = 32;
5554 const int32_t tex_height = 32;
5555
5556 VkImageCreateInfo image_create_info = {};
5557 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
5558 image_create_info.pNext = NULL;
5559 image_create_info.imageType = VK_IMAGE_TYPE_2D;
5560 image_create_info.format = tex_format;
5561 image_create_info.extent.width = tex_width;
5562 image_create_info.extent.height = tex_height;
5563 image_create_info.extent.depth = 1;
5564 image_create_info.mipLevels = 1;
Chia-I Wu5c17c962015-10-31 00:31:16 +08005565 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Mark Lobodzinskidc86b852015-10-23 14:20:31 -06005566 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
5567 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
5568 image_create_info.flags = 0;
5569
Chia-I Wuf7458c52015-10-26 21:10:41 +08005570 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Mark Lobodzinskidc86b852015-10-23 14:20:31 -06005571 ASSERT_VK_SUCCESS(err);
5572
5573 VkImageViewCreateInfo image_view_create_info = {};
5574 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
5575 image_view_create_info.image = image;
5576 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
5577 image_view_create_info.format = tex_format;
5578 image_view_create_info.subresourceRange.baseMipLevel = 0;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005579 image_view_create_info.subresourceRange.levelCount = 1;
Mark Lobodzinskidc86b852015-10-23 14:20:31 -06005580 // Cause an error by setting an invalid image aspect
5581 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_METADATA_BIT;
5582
5583 VkImageView view;
Chia-I Wuf7458c52015-10-26 21:10:41 +08005584 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
Mark Lobodzinskidc86b852015-10-23 14:20:31 -06005585
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06005586 if (!m_errorMonitor->DesiredMsgFound()) {
5587 FAIL() << "Did not receive Error 'VkCreateImageView: Color image formats must have ...'";
5588 m_errorMonitor->DumpFailureMsgs();
Mark Lobodzinskidc86b852015-10-23 14:20:31 -06005589 }
5590}
5591
Mike Stroyana3082432015-09-25 13:39:21 -06005592TEST_F(VkLayerTest, CopyImageTypeMismatch)
5593{
Mike Stroyana3082432015-09-25 13:39:21 -06005594 VkResult err;
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -06005595 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -06005596
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07005597 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06005598 "vkCmdCopyImage called with unmatched source and dest image types");
5599
Mike Stroyana3082432015-09-25 13:39:21 -06005600 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -06005601
5602 // Create two images of different types and try to copy between them
5603 VkImage srcImage;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005604 VkImage dstImage;
Mike Stroyana3082432015-09-25 13:39:21 -06005605 VkDeviceMemory srcMem;
5606 VkDeviceMemory destMem;
5607 VkMemoryRequirements memReqs;
5608
5609 VkImageCreateInfo image_create_info = {};
5610 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
5611 image_create_info.pNext = NULL;
5612 image_create_info.imageType = VK_IMAGE_TYPE_2D;
5613 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
5614 image_create_info.extent.width = 32;
5615 image_create_info.extent.height = 32;
5616 image_create_info.extent.depth = 1;
5617 image_create_info.mipLevels = 1;
Courtney Goeltzenleuchter5d2aed42015-10-21 17:57:31 -06005618 image_create_info.arrayLayers = 1;
Chia-I Wu5c17c962015-10-31 00:31:16 +08005619 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Mike Stroyan91204c32016-01-05 11:44:50 -07005620 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005621 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -06005622 image_create_info.flags = 0;
5623
Chia-I Wuf7458c52015-10-26 21:10:41 +08005624 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -06005625 ASSERT_VK_SUCCESS(err);
5626
5627 image_create_info.imageType = VK_IMAGE_TYPE_1D;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005628 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -06005629
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005630 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -06005631 ASSERT_VK_SUCCESS(err);
5632
5633 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005634 VkMemoryAllocateInfo memAlloc = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08005635 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
Mike Stroyana3082432015-09-25 13:39:21 -06005636 memAlloc.pNext = NULL;
5637 memAlloc.allocationSize = 0;
5638 memAlloc.memoryTypeIndex = 0;
5639
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -06005640 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -06005641 memAlloc.allocationSize = memReqs.size;
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -06005642 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
5643 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005644 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -06005645 ASSERT_VK_SUCCESS(err);
5646
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005647 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -06005648 memAlloc.allocationSize = memReqs.size;
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -06005649 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Mike Stroyana3082432015-09-25 13:39:21 -06005650 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005651 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -06005652 ASSERT_VK_SUCCESS(err);
5653
5654 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
5655 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005656 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -06005657 ASSERT_VK_SUCCESS(err);
5658
5659 BeginCommandBuffer();
5660 VkImageCopy copyRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +08005661 copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -06005662 copyRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -06005663 copyRegion.srcSubresource.baseArrayLayer = 0;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005664 copyRegion.srcSubresource.layerCount = 0;
Mike Stroyana3082432015-09-25 13:39:21 -06005665 copyRegion.srcOffset.x = 0;
5666 copyRegion.srcOffset.y = 0;
5667 copyRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +08005668 copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005669 copyRegion.dstSubresource.mipLevel = 0;
5670 copyRegion.dstSubresource.baseArrayLayer = 0;
5671 copyRegion.dstSubresource.layerCount = 0;
5672 copyRegion.dstOffset.x = 0;
5673 copyRegion.dstOffset.y = 0;
5674 copyRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -06005675 copyRegion.extent.width = 1;
5676 copyRegion.extent.height = 1;
5677 copyRegion.extent.depth = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005678 m_commandBuffer->CopyImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
Mike Stroyana3082432015-09-25 13:39:21 -06005679 EndCommandBuffer();
5680
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06005681 if (!m_errorMonitor->DesiredMsgFound()) {
5682 FAIL() << "Did not receive Error 'vkCmdCopyImage called with unmatched source and dest image types'";
5683 m_errorMonitor->DumpFailureMsgs();
Mike Stroyana3082432015-09-25 13:39:21 -06005684 }
5685
Chia-I Wuf7458c52015-10-26 21:10:41 +08005686 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005687 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +08005688 vkFreeMemory(m_device->device(), srcMem, NULL);
5689 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -06005690}
5691
5692TEST_F(VkLayerTest, CopyImageFormatSizeMismatch)
5693{
5694 // TODO : Create two images with different format sizes and vkCmdCopyImage between them
5695}
5696
5697TEST_F(VkLayerTest, CopyImageDepthStencilFormatMismatch)
5698{
Mike Stroyana3082432015-09-25 13:39:21 -06005699 VkResult err;
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -06005700 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -06005701
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07005702 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06005703 "vkCmdCopyImage called with unmatched source and dest image types");
5704
Mike Stroyana3082432015-09-25 13:39:21 -06005705 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -06005706
5707 // Create two images of different types and try to copy between them
5708 VkImage srcImage;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005709 VkImage dstImage;
Mike Stroyana3082432015-09-25 13:39:21 -06005710 VkDeviceMemory srcMem;
5711 VkDeviceMemory destMem;
5712 VkMemoryRequirements memReqs;
5713
5714 VkImageCreateInfo image_create_info = {};
5715 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
5716 image_create_info.pNext = NULL;
5717 image_create_info.imageType = VK_IMAGE_TYPE_2D;
5718 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
5719 image_create_info.extent.width = 32;
5720 image_create_info.extent.height = 32;
5721 image_create_info.extent.depth = 1;
5722 image_create_info.mipLevels = 1;
Courtney Goeltzenleuchter5d2aed42015-10-21 17:57:31 -06005723 image_create_info.arrayLayers = 1;
Chia-I Wu5c17c962015-10-31 00:31:16 +08005724 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -06005725 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005726 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -06005727 image_create_info.flags = 0;
5728
Chia-I Wuf7458c52015-10-26 21:10:41 +08005729 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -06005730 ASSERT_VK_SUCCESS(err);
5731
5732 image_create_info.imageType = VK_IMAGE_TYPE_1D;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005733 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -06005734
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005735 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -06005736 ASSERT_VK_SUCCESS(err);
5737
5738 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005739 VkMemoryAllocateInfo memAlloc = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08005740 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
Mike Stroyana3082432015-09-25 13:39:21 -06005741 memAlloc.pNext = NULL;
5742 memAlloc.allocationSize = 0;
5743 memAlloc.memoryTypeIndex = 0;
5744
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -06005745 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -06005746 memAlloc.allocationSize = memReqs.size;
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -06005747 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
5748 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005749 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -06005750 ASSERT_VK_SUCCESS(err);
5751
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005752 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -06005753 memAlloc.allocationSize = memReqs.size;
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -06005754 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
5755 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005756 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -06005757 ASSERT_VK_SUCCESS(err);
5758
5759 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
5760 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005761 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -06005762 ASSERT_VK_SUCCESS(err);
5763
5764 BeginCommandBuffer();
5765 VkImageCopy copyRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +08005766 copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -06005767 copyRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -06005768 copyRegion.srcSubresource.baseArrayLayer = 0;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005769 copyRegion.srcSubresource.layerCount = 0;
Mike Stroyana3082432015-09-25 13:39:21 -06005770 copyRegion.srcOffset.x = 0;
5771 copyRegion.srcOffset.y = 0;
5772 copyRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +08005773 copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005774 copyRegion.dstSubresource.mipLevel = 0;
5775 copyRegion.dstSubresource.baseArrayLayer = 0;
5776 copyRegion.dstSubresource.layerCount = 0;
5777 copyRegion.dstOffset.x = 0;
5778 copyRegion.dstOffset.y = 0;
5779 copyRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -06005780 copyRegion.extent.width = 1;
5781 copyRegion.extent.height = 1;
5782 copyRegion.extent.depth = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005783 m_commandBuffer->CopyImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
Mike Stroyana3082432015-09-25 13:39:21 -06005784 EndCommandBuffer();
5785
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06005786 if (!m_errorMonitor->DesiredMsgFound()) {
5787 FAIL() << "Did not receive Error 'vkCmdCopyImage called with unmatched source and dest image types'";
5788 m_errorMonitor->DumpFailureMsgs();
Mike Stroyana3082432015-09-25 13:39:21 -06005789 }
5790
Chia-I Wuf7458c52015-10-26 21:10:41 +08005791 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005792 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +08005793 vkFreeMemory(m_device->device(), srcMem, NULL);
5794 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -06005795}
5796
5797TEST_F(VkLayerTest, ResolveImageLowSampleCount)
5798{
Mike Stroyana3082432015-09-25 13:39:21 -06005799 VkResult err;
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -06005800 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -06005801
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07005802 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06005803 "vkCmdResolveImage called with source sample count less than 2.");
5804
Mike Stroyana3082432015-09-25 13:39:21 -06005805 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -06005806
5807 // Create two images of sample count 1 and try to Resolve between them
5808 VkImage srcImage;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005809 VkImage dstImage;
Mike Stroyana3082432015-09-25 13:39:21 -06005810 VkDeviceMemory srcMem;
5811 VkDeviceMemory destMem;
5812 VkMemoryRequirements memReqs;
5813
5814 VkImageCreateInfo image_create_info = {};
5815 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
5816 image_create_info.pNext = NULL;
5817 image_create_info.imageType = VK_IMAGE_TYPE_2D;
5818 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
5819 image_create_info.extent.width = 32;
5820 image_create_info.extent.height = 1;
5821 image_create_info.extent.depth = 1;
5822 image_create_info.mipLevels = 1;
Courtney Goeltzenleuchter5d2aed42015-10-21 17:57:31 -06005823 image_create_info.arrayLayers = 1;
Chia-I Wu5c17c962015-10-31 00:31:16 +08005824 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Mike Stroyan91204c32016-01-05 11:44:50 -07005825 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005826 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -06005827 image_create_info.flags = 0;
5828
Chia-I Wuf7458c52015-10-26 21:10:41 +08005829 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -06005830 ASSERT_VK_SUCCESS(err);
5831
5832 image_create_info.imageType = VK_IMAGE_TYPE_1D;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005833 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -06005834
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005835 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -06005836 ASSERT_VK_SUCCESS(err);
5837
5838 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005839 VkMemoryAllocateInfo memAlloc = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08005840 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
Mike Stroyana3082432015-09-25 13:39:21 -06005841 memAlloc.pNext = NULL;
5842 memAlloc.allocationSize = 0;
5843 memAlloc.memoryTypeIndex = 0;
5844
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -06005845 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -06005846 memAlloc.allocationSize = memReqs.size;
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -06005847 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
5848 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005849 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -06005850 ASSERT_VK_SUCCESS(err);
5851
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005852 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -06005853 memAlloc.allocationSize = memReqs.size;
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -06005854 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
5855 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005856 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -06005857 ASSERT_VK_SUCCESS(err);
5858
5859 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
5860 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005861 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -06005862 ASSERT_VK_SUCCESS(err);
5863
5864 BeginCommandBuffer();
5865 // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest?
5866 //VK_IMAGE_LAYOUT_UNDEFINED = 0,
5867 //VK_IMAGE_LAYOUT_GENERAL = 1,
5868 VkImageResolve resolveRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +08005869 resolveRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -06005870 resolveRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -06005871 resolveRegion.srcSubresource.baseArrayLayer = 0;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005872 resolveRegion.srcSubresource.layerCount = 0;
Mike Stroyana3082432015-09-25 13:39:21 -06005873 resolveRegion.srcOffset.x = 0;
5874 resolveRegion.srcOffset.y = 0;
5875 resolveRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +08005876 resolveRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005877 resolveRegion.dstSubresource.mipLevel = 0;
5878 resolveRegion.dstSubresource.baseArrayLayer = 0;
5879 resolveRegion.dstSubresource.layerCount = 0;
5880 resolveRegion.dstOffset.x = 0;
5881 resolveRegion.dstOffset.y = 0;
5882 resolveRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -06005883 resolveRegion.extent.width = 1;
5884 resolveRegion.extent.height = 1;
5885 resolveRegion.extent.depth = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005886 m_commandBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion);
Mike Stroyana3082432015-09-25 13:39:21 -06005887 EndCommandBuffer();
5888
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06005889 if (!m_errorMonitor->DesiredMsgFound()) {
5890 FAIL() << "Did not receive Error 'vkCmdResolveImage called with source sample count less than 2.'";
5891 m_errorMonitor->DumpFailureMsgs();
Mike Stroyana3082432015-09-25 13:39:21 -06005892 }
5893
Chia-I Wuf7458c52015-10-26 21:10:41 +08005894 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005895 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +08005896 vkFreeMemory(m_device->device(), srcMem, NULL);
5897 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -06005898}
5899
5900TEST_F(VkLayerTest, ResolveImageHighSampleCount)
5901{
Mike Stroyana3082432015-09-25 13:39:21 -06005902 VkResult err;
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -06005903 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -06005904
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07005905 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06005906 "vkCmdResolveImage called with dest sample count greater than 1.");
5907
Mike Stroyana3082432015-09-25 13:39:21 -06005908 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -06005909
5910 // Create two images of sample count 2 and try to Resolve between them
5911 VkImage srcImage;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005912 VkImage dstImage;
Mike Stroyana3082432015-09-25 13:39:21 -06005913 VkDeviceMemory srcMem;
5914 VkDeviceMemory destMem;
5915 VkMemoryRequirements memReqs;
5916
5917 VkImageCreateInfo image_create_info = {};
5918 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
5919 image_create_info.pNext = NULL;
5920 image_create_info.imageType = VK_IMAGE_TYPE_2D;
5921 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
5922 image_create_info.extent.width = 32;
5923 image_create_info.extent.height = 1;
5924 image_create_info.extent.depth = 1;
5925 image_create_info.mipLevels = 1;
Courtney Goeltzenleuchter5d2aed42015-10-21 17:57:31 -06005926 image_create_info.arrayLayers = 1;
Chia-I Wu5c17c962015-10-31 00:31:16 +08005927 image_create_info.samples = VK_SAMPLE_COUNT_2_BIT;
Mike Stroyan91204c32016-01-05 11:44:50 -07005928 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
Cody Northrop72458c02015-10-27 13:50:04 -06005929 // Note: Some implementations expect color attachment usage for any multisample surface
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005930 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -06005931 image_create_info.flags = 0;
5932
Chia-I Wuf7458c52015-10-26 21:10:41 +08005933 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -06005934 ASSERT_VK_SUCCESS(err);
5935
5936 image_create_info.imageType = VK_IMAGE_TYPE_1D;
Cody Northrop72458c02015-10-27 13:50:04 -06005937 // Note: Some implementations expect color attachment usage for any multisample surface
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005938 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -06005939
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005940 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -06005941 ASSERT_VK_SUCCESS(err);
5942
5943 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005944 VkMemoryAllocateInfo memAlloc = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08005945 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
Mike Stroyana3082432015-09-25 13:39:21 -06005946 memAlloc.pNext = NULL;
5947 memAlloc.allocationSize = 0;
5948 memAlloc.memoryTypeIndex = 0;
5949
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -06005950 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -06005951 memAlloc.allocationSize = memReqs.size;
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -06005952 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
5953 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005954 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -06005955 ASSERT_VK_SUCCESS(err);
5956
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005957 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -06005958 memAlloc.allocationSize = memReqs.size;
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -06005959 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
5960 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005961 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -06005962 ASSERT_VK_SUCCESS(err);
5963
5964 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
5965 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005966 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -06005967 ASSERT_VK_SUCCESS(err);
5968
5969 BeginCommandBuffer();
5970 // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest?
5971 //VK_IMAGE_LAYOUT_UNDEFINED = 0,
5972 //VK_IMAGE_LAYOUT_GENERAL = 1,
5973 VkImageResolve resolveRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +08005974 resolveRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -06005975 resolveRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -06005976 resolveRegion.srcSubresource.baseArrayLayer = 0;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005977 resolveRegion.srcSubresource.layerCount = 0;
Mike Stroyana3082432015-09-25 13:39:21 -06005978 resolveRegion.srcOffset.x = 0;
5979 resolveRegion.srcOffset.y = 0;
5980 resolveRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +08005981 resolveRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005982 resolveRegion.dstSubresource.mipLevel = 0;
5983 resolveRegion.dstSubresource.baseArrayLayer = 0;
5984 resolveRegion.dstSubresource.layerCount = 0;
5985 resolveRegion.dstOffset.x = 0;
5986 resolveRegion.dstOffset.y = 0;
5987 resolveRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -06005988 resolveRegion.extent.width = 1;
5989 resolveRegion.extent.height = 1;
5990 resolveRegion.extent.depth = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005991 m_commandBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion);
Mike Stroyana3082432015-09-25 13:39:21 -06005992 EndCommandBuffer();
5993
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06005994 if (!m_errorMonitor->DesiredMsgFound()) {
5995 FAIL() << "Did not receive Error 'vkCmdResolveImage called with dest sample count greater than 1.'";
5996 m_errorMonitor->DumpFailureMsgs();
Mike Stroyana3082432015-09-25 13:39:21 -06005997 }
5998
Chia-I Wuf7458c52015-10-26 21:10:41 +08005999 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006000 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +08006001 vkFreeMemory(m_device->device(), srcMem, NULL);
6002 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -06006003}
6004
6005TEST_F(VkLayerTest, ResolveImageFormatMismatch)
6006{
Mike Stroyana3082432015-09-25 13:39:21 -06006007 VkResult err;
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -06006008 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -06006009
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07006010 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06006011 "vkCmdResolveImage called with unmatched source and dest formats.");
6012
Mike Stroyana3082432015-09-25 13:39:21 -06006013 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -06006014
6015 // Create two images of different types and try to copy between them
6016 VkImage srcImage;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006017 VkImage dstImage;
Mike Stroyana3082432015-09-25 13:39:21 -06006018 VkDeviceMemory srcMem;
6019 VkDeviceMemory destMem;
6020 VkMemoryRequirements memReqs;
6021
6022 VkImageCreateInfo image_create_info = {};
6023 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
6024 image_create_info.pNext = NULL;
6025 image_create_info.imageType = VK_IMAGE_TYPE_2D;
6026 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
6027 image_create_info.extent.width = 32;
6028 image_create_info.extent.height = 1;
6029 image_create_info.extent.depth = 1;
6030 image_create_info.mipLevels = 1;
Courtney Goeltzenleuchter5d2aed42015-10-21 17:57:31 -06006031 image_create_info.arrayLayers = 1;
Chia-I Wu5c17c962015-10-31 00:31:16 +08006032 image_create_info.samples = VK_SAMPLE_COUNT_2_BIT;
Mike Stroyan91204c32016-01-05 11:44:50 -07006033 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
Cody Northrop72458c02015-10-27 13:50:04 -06006034 // Note: Some implementations expect color attachment usage for any multisample surface
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006035 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -06006036 image_create_info.flags = 0;
6037
Chia-I Wuf7458c52015-10-26 21:10:41 +08006038 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -06006039 ASSERT_VK_SUCCESS(err);
6040
Cody Northrop72458c02015-10-27 13:50:04 -06006041 // Set format to something other than source image
6042 image_create_info.format = VK_FORMAT_R32_SFLOAT;
6043 // Note: Some implementations expect color attachment usage for any multisample surface
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006044 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Chia-I Wu5c17c962015-10-31 00:31:16 +08006045 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -06006046
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006047 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -06006048 ASSERT_VK_SUCCESS(err);
6049
6050 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006051 VkMemoryAllocateInfo memAlloc = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08006052 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
Mike Stroyana3082432015-09-25 13:39:21 -06006053 memAlloc.pNext = NULL;
6054 memAlloc.allocationSize = 0;
6055 memAlloc.memoryTypeIndex = 0;
6056
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -06006057 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -06006058 memAlloc.allocationSize = memReqs.size;
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -06006059 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
6060 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006061 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -06006062 ASSERT_VK_SUCCESS(err);
6063
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006064 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -06006065 memAlloc.allocationSize = memReqs.size;
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -06006066 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
6067 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006068 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -06006069 ASSERT_VK_SUCCESS(err);
6070
6071 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
6072 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006073 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -06006074 ASSERT_VK_SUCCESS(err);
6075
6076 BeginCommandBuffer();
6077 // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest?
6078 //VK_IMAGE_LAYOUT_UNDEFINED = 0,
6079 //VK_IMAGE_LAYOUT_GENERAL = 1,
6080 VkImageResolve resolveRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +08006081 resolveRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -06006082 resolveRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -06006083 resolveRegion.srcSubresource.baseArrayLayer = 0;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006084 resolveRegion.srcSubresource.layerCount = 0;
Mike Stroyana3082432015-09-25 13:39:21 -06006085 resolveRegion.srcOffset.x = 0;
6086 resolveRegion.srcOffset.y = 0;
6087 resolveRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +08006088 resolveRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006089 resolveRegion.dstSubresource.mipLevel = 0;
6090 resolveRegion.dstSubresource.baseArrayLayer = 0;
6091 resolveRegion.dstSubresource.layerCount = 0;
6092 resolveRegion.dstOffset.x = 0;
6093 resolveRegion.dstOffset.y = 0;
6094 resolveRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -06006095 resolveRegion.extent.width = 1;
6096 resolveRegion.extent.height = 1;
6097 resolveRegion.extent.depth = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006098 m_commandBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion);
Mike Stroyana3082432015-09-25 13:39:21 -06006099 EndCommandBuffer();
6100
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06006101 if (!m_errorMonitor->DesiredMsgFound()) {
6102 FAIL() << "Did not receive Error 'vkCmdResolveImage called with unmatched source and dest formats.'";
6103 m_errorMonitor->DumpFailureMsgs();
Mike Stroyana3082432015-09-25 13:39:21 -06006104 }
6105
Chia-I Wuf7458c52015-10-26 21:10:41 +08006106 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006107 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +08006108 vkFreeMemory(m_device->device(), srcMem, NULL);
6109 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -06006110}
6111
6112TEST_F(VkLayerTest, ResolveImageTypeMismatch)
6113{
Mike Stroyana3082432015-09-25 13:39:21 -06006114 VkResult err;
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -06006115 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -06006116
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07006117 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06006118 "vkCmdResolveImage called with unmatched source and dest image types.");
6119
Mike Stroyana3082432015-09-25 13:39:21 -06006120 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -06006121
6122 // Create two images of different types and try to copy between them
6123 VkImage srcImage;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006124 VkImage dstImage;
Mike Stroyana3082432015-09-25 13:39:21 -06006125 VkDeviceMemory srcMem;
6126 VkDeviceMemory destMem;
6127 VkMemoryRequirements memReqs;
6128
6129 VkImageCreateInfo image_create_info = {};
6130 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
6131 image_create_info.pNext = NULL;
6132 image_create_info.imageType = VK_IMAGE_TYPE_2D;
6133 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
6134 image_create_info.extent.width = 32;
6135 image_create_info.extent.height = 1;
6136 image_create_info.extent.depth = 1;
6137 image_create_info.mipLevels = 1;
Courtney Goeltzenleuchter5d2aed42015-10-21 17:57:31 -06006138 image_create_info.arrayLayers = 1;
Chia-I Wu5c17c962015-10-31 00:31:16 +08006139 image_create_info.samples = VK_SAMPLE_COUNT_2_BIT;
Mike Stroyan91204c32016-01-05 11:44:50 -07006140 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
Cody Northrop72458c02015-10-27 13:50:04 -06006141 // Note: Some implementations expect color attachment usage for any multisample surface
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006142 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -06006143 image_create_info.flags = 0;
6144
Chia-I Wuf7458c52015-10-26 21:10:41 +08006145 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -06006146 ASSERT_VK_SUCCESS(err);
6147
6148 image_create_info.imageType = VK_IMAGE_TYPE_1D;
Cody Northrop72458c02015-10-27 13:50:04 -06006149 // Note: Some implementations expect color attachment usage for any multisample surface
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006150 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Chia-I Wu5c17c962015-10-31 00:31:16 +08006151 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -06006152
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006153 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -06006154 ASSERT_VK_SUCCESS(err);
6155
6156 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006157 VkMemoryAllocateInfo memAlloc = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08006158 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
Mike Stroyana3082432015-09-25 13:39:21 -06006159 memAlloc.pNext = NULL;
6160 memAlloc.allocationSize = 0;
6161 memAlloc.memoryTypeIndex = 0;
6162
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -06006163 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -06006164 memAlloc.allocationSize = memReqs.size;
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -06006165 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
6166 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006167 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -06006168 ASSERT_VK_SUCCESS(err);
6169
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006170 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -06006171 memAlloc.allocationSize = memReqs.size;
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -06006172 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
6173 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006174 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -06006175 ASSERT_VK_SUCCESS(err);
6176
6177 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
6178 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006179 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -06006180 ASSERT_VK_SUCCESS(err);
6181
6182 BeginCommandBuffer();
6183 // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest?
6184 //VK_IMAGE_LAYOUT_UNDEFINED = 0,
6185 //VK_IMAGE_LAYOUT_GENERAL = 1,
6186 VkImageResolve resolveRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +08006187 resolveRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -06006188 resolveRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -06006189 resolveRegion.srcSubresource.baseArrayLayer = 0;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006190 resolveRegion.srcSubresource.layerCount = 0;
Mike Stroyana3082432015-09-25 13:39:21 -06006191 resolveRegion.srcOffset.x = 0;
6192 resolveRegion.srcOffset.y = 0;
6193 resolveRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +08006194 resolveRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006195 resolveRegion.dstSubresource.mipLevel = 0;
6196 resolveRegion.dstSubresource.baseArrayLayer = 0;
6197 resolveRegion.dstSubresource.layerCount = 0;
6198 resolveRegion.dstOffset.x = 0;
6199 resolveRegion.dstOffset.y = 0;
6200 resolveRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -06006201 resolveRegion.extent.width = 1;
6202 resolveRegion.extent.height = 1;
6203 resolveRegion.extent.depth = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006204 m_commandBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion);
Mike Stroyana3082432015-09-25 13:39:21 -06006205 EndCommandBuffer();
6206
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06006207 if (!m_errorMonitor->DesiredMsgFound()) {
6208 FAIL() << "Did not receive Error 'vkCmdResolveImage called with unmatched source and dest image types.'";
6209 m_errorMonitor->DumpFailureMsgs();
Mike Stroyana3082432015-09-25 13:39:21 -06006210 }
6211
Chia-I Wuf7458c52015-10-26 21:10:41 +08006212 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006213 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +08006214 vkFreeMemory(m_device->device(), srcMem, NULL);
6215 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -06006216}
Tobin Ehlisa1c28562015-10-23 16:00:08 -06006217
6218TEST_F(VkLayerTest, DepthStencilImageViewWithColorAspectBitError)
6219{
6220 // Create a single Image descriptor and cause it to first hit an error due
6221 // to using a DS format, then cause it to hit error due to COLOR_BIT not set in aspect
6222 // The image format check comes 2nd in validation so we trigger it first,
6223 // then when we cause aspect fail next, bad format check will be preempted
Tobin Ehlisa1c28562015-10-23 16:00:08 -06006224 VkResult err;
6225
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07006226 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06006227 "Combination depth/stencil image formats can have only the ");
6228
Tobin Ehlisa1c28562015-10-23 16:00:08 -06006229 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06006230
Chia-I Wu1b99bb22015-10-27 19:25:11 +08006231 VkDescriptorPoolSize ds_type_count = {};
Tobin Ehlisa1c28562015-10-23 16:00:08 -06006232 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
Chia-I Wud50a7d72015-10-26 20:48:51 +08006233 ds_type_count.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06006234
6235 VkDescriptorPoolCreateInfo ds_pool_ci = {};
6236 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
6237 ds_pool_ci.pNext = NULL;
6238 ds_pool_ci.maxSets = 1;
Chia-I Wu1b99bb22015-10-27 19:25:11 +08006239 ds_pool_ci.poolSizeCount = 1;
6240 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06006241
6242 VkDescriptorPool ds_pool;
Chia-I Wuf7458c52015-10-26 21:10:41 +08006243 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06006244 ASSERT_VK_SUCCESS(err);
6245
6246 VkDescriptorSetLayoutBinding dsl_binding = {};
Chia-I Wud46e6ae2015-10-31 00:31:16 +08006247 dsl_binding.binding = 0;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06006248 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
Chia-I Wu02124482015-11-06 06:42:02 +08006249 dsl_binding.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06006250 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
6251 dsl_binding.pImmutableSamplers = NULL;
6252
6253 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
6254 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
6255 ds_layout_ci.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08006256 ds_layout_ci.bindingCount = 1;
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07006257 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06006258 VkDescriptorSetLayout ds_layout;
Chia-I Wuf7458c52015-10-26 21:10:41 +08006259 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06006260 ASSERT_VK_SUCCESS(err);
6261
6262 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006263 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08006264 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Chia-I Wud50a7d72015-10-26 20:48:51 +08006265 alloc_info.setLayoutCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06006266 alloc_info.descriptorPool = ds_pool;
6267 alloc_info.pSetLayouts = &ds_layout;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006268 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06006269 ASSERT_VK_SUCCESS(err);
6270
6271 VkImage image_bad;
6272 VkImage image_good;
6273 // One bad format and one good format for Color attachment
6274 const VkFormat tex_format_bad = VK_FORMAT_D32_SFLOAT_S8_UINT;
6275 const VkFormat tex_format_good = VK_FORMAT_B8G8R8A8_UNORM;
6276 const int32_t tex_width = 32;
6277 const int32_t tex_height = 32;
6278
6279 VkImageCreateInfo image_create_info = {};
6280 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
6281 image_create_info.pNext = NULL;
6282 image_create_info.imageType = VK_IMAGE_TYPE_2D;
6283 image_create_info.format = tex_format_bad;
6284 image_create_info.extent.width = tex_width;
6285 image_create_info.extent.height = tex_height;
6286 image_create_info.extent.depth = 1;
6287 image_create_info.mipLevels = 1;
6288 image_create_info.arrayLayers = 1;
Chia-I Wu5c17c962015-10-31 00:31:16 +08006289 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06006290 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
6291 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT;
6292 image_create_info.flags = 0;
6293
Chia-I Wuf7458c52015-10-26 21:10:41 +08006294 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image_bad);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06006295 ASSERT_VK_SUCCESS(err);
6296 image_create_info.format = tex_format_good;
6297 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Chia-I Wuf7458c52015-10-26 21:10:41 +08006298 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image_good);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06006299 ASSERT_VK_SUCCESS(err);
6300
6301 VkImageViewCreateInfo image_view_create_info = {};
6302 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
6303 image_view_create_info.image = image_bad;
6304 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
6305 image_view_create_info.format = tex_format_bad;
6306 image_view_create_info.subresourceRange.baseArrayLayer = 0;
6307 image_view_create_info.subresourceRange.baseMipLevel = 0;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006308 image_view_create_info.subresourceRange.layerCount = 1;
6309 image_view_create_info.subresourceRange.levelCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06006310 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
6311
6312 VkImageView view;
Chia-I Wuf7458c52015-10-26 21:10:41 +08006313 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06006314
6315 if (!m_errorMonitor->DesiredMsgFound()) {
6316 FAIL() << "Did not receive Error 'Combination depth-stencil image formats can have only the....'";
6317 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlisa1c28562015-10-23 16:00:08 -06006318 }
6319
Chia-I Wuf7458c52015-10-26 21:10:41 +08006320 vkDestroyImage(m_device->device(), image_bad, NULL);
6321 vkDestroyImage(m_device->device(), image_good, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +08006322 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
6323 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06006324}
Tobin Ehliscde08892015-09-22 10:11:37 -06006325#endif // IMAGE_TESTS
6326
Tony Barbour300a6082015-04-07 13:44:53 -06006327int main(int argc, char **argv) {
6328 int result;
6329
6330 ::testing::InitGoogleTest(&argc, argv);
Tony Barbour6918cd52015-04-09 12:58:51 -06006331 VkTestFramework::InitArgs(&argc, argv);
Tony Barbour300a6082015-04-07 13:44:53 -06006332
6333 ::testing::AddGlobalTestEnvironment(new TestEnvironment);
6334
6335 result = RUN_ALL_TESTS();
6336
Tony Barbour6918cd52015-04-09 12:58:51 -06006337 VkTestFramework::Finish();
Tony Barbour300a6082015-04-07 13:44:53 -06006338 return result;
6339}