blob: b48172359f03d7022f99177d5c09923c591b09d0 [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);
2107 VkDescriptorImageInfo imageInfo[2] = {};
2108 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;
2112
2113 static const uint32_t NUM_SET_UPDATES = 3;
2114 VkWriteDescriptorSet descriptor_write[NUM_SET_UPDATES] = {};
2115 descriptor_write[0].sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
2116 descriptor_write[0].dstSet = descriptorSet[0];
2117 descriptor_write[0].dstBinding = 0;
2118 descriptor_write[0].descriptorCount = 5;
2119 descriptor_write[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
2120 descriptor_write[0].pBufferInfo = buffInfo;
2121 descriptor_write[1].sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
2122 descriptor_write[1].dstSet = descriptorSet[1];
2123 descriptor_write[1].dstBinding = 0;
2124 descriptor_write[1].descriptorCount = 2;
2125 descriptor_write[1].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
2126 descriptor_write[1].pImageInfo = imageInfo;
2127 descriptor_write[2].sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
2128 descriptor_write[2].dstSet = descriptorSet[1];
2129 descriptor_write[2].dstBinding = 1;
2130 descriptor_write[2].descriptorCount = 2;
2131 descriptor_write[2].descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE;
2132 descriptor_write[2].pImageInfo = imageInfo;
2133
2134 vkUpdateDescriptorSets(m_device->device(), 3, descriptor_write, 0, NULL);
Tobin Ehlis559c6382015-11-05 09:52:49 -07002135
Tobin Ehlis88452832015-12-03 09:40:56 -07002136 // Create PSO to be used for draw-time errors below
2137 char const *vsSource =
Tony Barboure804d202016-01-05 13:37:45 -07002138 "#version 400\n"
Tobin Ehlis88452832015-12-03 09:40:56 -07002139 "#extension GL_ARB_separate_shader_objects: require\n"
2140 "#extension GL_ARB_shading_language_420pack: require\n"
2141 "\n"
Tony Barboure804d202016-01-05 13:37:45 -07002142 "out gl_PerVertex {\n"
2143 " vec4 gl_Position;\n"
2144 "};\n"
Tobin Ehlis88452832015-12-03 09:40:56 -07002145 "void main(){\n"
2146 " gl_Position = vec4(1);\n"
2147 "}\n";
2148 char const *fsSource =
Tony Barboure804d202016-01-05 13:37:45 -07002149 "#version 400\n"
Tobin Ehlis88452832015-12-03 09:40:56 -07002150 "#extension GL_ARB_separate_shader_objects: require\n"
2151 "#extension GL_ARB_shading_language_420pack: require\n"
2152 "\n"
2153 "layout(location=0) out vec4 x;\n"
2154 "layout(set=0) layout(binding=0) uniform foo { int x; int y; } bar;\n"
2155 "void main(){\n"
2156 " x = vec4(bar.y);\n"
2157 "}\n";
2158 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
2159 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Tobin Ehlis559c6382015-11-05 09:52:49 -07002160 VkPipelineObj pipe(m_device);
2161 pipe.AddShader(&vs);
2162 pipe.AddShader(&fs);
Tobin Ehlis88452832015-12-03 09:40:56 -07002163 pipe.AddColorAttachment();
2164 pipe.CreateVKPipeline(pipe_layout_fs_only, renderPass());
Tobin Ehlis559c6382015-11-05 09:52:49 -07002165
2166 BeginCommandBuffer();
Tobin Ehlis88452832015-12-03 09:40:56 -07002167
Tobin Ehlis559c6382015-11-05 09:52:49 -07002168 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
2169 // NOTE : I believe LunarG ilo driver has bug (LX#189) that requires binding of PSO
2170 // here before binding DSs. Otherwise we assert in cmd_copy_dset_data() of cmd_pipeline.c
2171 // due to the fact that cmd_alloc_dset_data() has not been called in cmd_bind_graphics_pipeline()
2172 // TODO : Want to cause various binding incompatibility issues here to test DrawState
2173 // First cause various verify_layout_compatibility() fails
2174 // Second disturb early and late sets and verify INFO msgs
Tobin Ehlis8fab6562015-12-01 09:57:09 -07002175 // verify_set_layout_compatibility fail cases:
2176 // 1. invalid VkPipelineLayout (layout) passed into vkCmdBindDescriptorSets
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07002177 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " due to: invalid VkPipelineLayout ");
Mark Youngad779052016-01-06 14:26:04 -07002178 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 -07002179 if (!m_errorMonitor->DesiredMsgFound()) {
Tobin Ehlis8fab6562015-12-01 09:57:09 -07002180 FAIL() << "Did not receive correct error msg when attempting to bind descriptorSets with invalid VkPipelineLayout.";
Tobin Ehlis559c6382015-11-05 09:52:49 -07002181 m_errorMonitor->DumpFailureMsgs();
2182 }
Tobin Ehlis8fab6562015-12-01 09:57:09 -07002183 // 2. layoutIndex exceeds # of layouts in layout
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07002184 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " attempting to bind set to index 1");
Tobin Ehlis8fab6562015-12-01 09:57:09 -07002185 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, single_pipe_layout, 0, 2, &descriptorSet[0], 0, NULL);
2186 if (!m_errorMonitor->DesiredMsgFound()) {
2187 FAIL() << "Did not receive correct error msg when attempting to bind descriptorSet to index 1 when pipelineLayout only has index 0.";
2188 m_errorMonitor->DumpFailureMsgs();
2189 }
2190 vkDestroyPipelineLayout(m_device->device(), single_pipe_layout, NULL);
2191 // 3. Pipeline setLayout[0] has 2 descriptors, but set being bound has 5 descriptors
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07002192 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, ", but corresponding set being bound has 5 descriptors.");
Tobin Ehlis8fab6562015-12-01 09:57:09 -07002193 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe_layout_one_desc, 0, 1, &descriptorSet[0], 0, NULL);
2194 if (!m_errorMonitor->DesiredMsgFound()) {
2195 FAIL() << "Did not receive correct error msg when attempting to bind descriptorSet w/ 5 descriptors to pipelineLayout with only 2 descriptors.";
2196 m_errorMonitor->DumpFailureMsgs();
2197 }
2198 vkDestroyPipelineLayout(m_device->device(), pipe_layout_one_desc, NULL);
2199 // 4. same # of descriptors but mismatch in type
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07002200 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 -07002201 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe_layout_five_samp, 0, 1, &descriptorSet[0], 0, NULL);
2202 if (!m_errorMonitor->DesiredMsgFound()) {
2203 FAIL() << "Did not receive correct error msg when attempting to bind UNIFORM_BUFFER descriptorSet to pipelineLayout with overlapping SAMPLER type.";
2204 m_errorMonitor->DumpFailureMsgs();
2205 }
2206 vkDestroyPipelineLayout(m_device->device(), pipe_layout_five_samp, NULL);
2207 // 5. same # of descriptors but mismatch in stageFlags
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07002208 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " descriptor from pipelineLayout has stageFlags ");
Tobin Ehlis8fab6562015-12-01 09:57:09 -07002209 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe_layout_fs_only, 0, 1, &descriptorSet[0], 0, NULL);
2210 if (!m_errorMonitor->DesiredMsgFound()) {
2211 FAIL() << "Did not receive correct error msg when attempting to bind UNIFORM_BUFFER descriptorSet with ALL stageFlags to pipelineLayout with FS-only stageFlags.";
2212 m_errorMonitor->DumpFailureMsgs();
2213 }
2214 // Cause INFO messages due to disturbing previously bound Sets
2215 // First bind sets 0 & 1
2216 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 2, &descriptorSet[0], 0, NULL);
2217 // 1. Disturb bound set0 by re-binding set1 w/ updated pipelineLayout
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07002218 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERF_WARN_BIT_EXT, " previously bound as set #0 was disturbed ");
Tobin Ehlis8fab6562015-12-01 09:57:09 -07002219 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe_layout_bad_set0, 1, 1, &descriptorSet[1], 0, NULL);
2220 if (!m_errorMonitor->DesiredMsgFound()) {
2221 FAIL() << "Did not receive correct info msg when binding Set1 w/ pipelineLayout that should disturb Set0.";
2222 m_errorMonitor->DumpFailureMsgs();
2223 }
2224 vkDestroyPipelineLayout(m_device->device(), pipe_layout_bad_set0, NULL);
2225 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 2, &descriptorSet[0], 0, NULL);
2226 // 2. Disturb set after last bound set
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07002227 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 -07002228 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe_layout_fs_only, 0, 1, &ds0_fs_only, 0, NULL);
2229 if (!m_errorMonitor->DesiredMsgFound()) {
2230 FAIL() << "Did not receive correct info msg when re-binding Set0 w/ pipelineLayout that should disturb Set1.";
2231 m_errorMonitor->DumpFailureMsgs();
2232 }
Tobin Ehlis88452832015-12-03 09:40:56 -07002233
2234 // Cause draw-time errors due to PSO incompatibilities
2235 // 1. Error due to not binding required set (we actually use same code as above to disturb set0)
2236 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 2, &descriptorSet[0], 0, NULL);
2237 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 -07002238 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 -07002239 Draw(1, 0, 0, 0);
2240 if (!m_errorMonitor->DesiredMsgFound()) {
2241 FAIL() << "Did not receive correct error msg when attempting draw requiring Set0 but Set0 is not bound.";
2242 m_errorMonitor->DumpFailureMsgs();
2243 }
2244 // 2. Error due to bound set not being compatible with PSO's VkPipelineLayout (diff stageFlags in this case)
2245 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 2, &descriptorSet[0], 0, NULL);
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07002246 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " bound as set #0 is not compatible with ");
Tobin Ehlis88452832015-12-03 09:40:56 -07002247 Draw(1, 0, 0, 0);
2248 if (!m_errorMonitor->DesiredMsgFound()) {
2249 FAIL() << "Did not receive correct error msg when attempted draw where bound Set0 layout is not compatible PSO Set0 layout.";
2250 m_errorMonitor->DumpFailureMsgs();
2251 }
Tobin Ehlis8fab6562015-12-01 09:57:09 -07002252 // Remaining clean-up
2253 vkDestroyPipelineLayout(m_device->device(), pipe_layout_fs_only, NULL);
2254 for (uint32_t i=0; i<NUM_LAYOUTS; ++i) {
2255 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout[i], NULL);
2256 }
2257 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout_fs_only, NULL);
2258 vkFreeDescriptorSets(m_device->device(), ds_pool, 1, descriptorSet);
2259 vkDestroyBuffer(m_device->device(), dyub, NULL);
Tobin Ehlis559c6382015-11-05 09:52:49 -07002260 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
2261 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
2262}
Tobin Ehlis559c6382015-11-05 09:52:49 -07002263
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002264TEST_F(VkLayerTest, NoBeginCommandBuffer)
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06002265{
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002266
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07002267 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002268 "You must call vkBeginCommandBuffer() before this call to ");
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06002269
2270 ASSERT_NO_FATAL_FAILURE(InitState());
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002271 VkCommandBufferObj commandBuffer(m_device, m_commandPool);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06002272 // Call EndCommandBuffer() w/o calling BeginCommandBuffer()
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002273 vkEndCommandBuffer(commandBuffer.GetBufferHandle());
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002274
2275 if (!m_errorMonitor->DesiredMsgFound()) {
2276 FAIL() << "Did not recieve Error 'You must call vkBeginCommandBuffer() before this call to vkEndCommandBuffer()'";
2277 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06002278 }
2279}
2280
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002281TEST_F(VkLayerTest, PrimaryCommandBufferFramebufferAndRenderpass)
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06002282{
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002283
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07002284 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002285 "may not specify framebuffer or renderpass parameters");
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06002286
2287 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06002288
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002289 // Calls AllocateCommandBuffers
2290 VkCommandBufferObj commandBuffer(m_device, m_commandPool);
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06002291
2292 // Force the failure by setting the Renderpass and Framebuffer fields with (fake) data
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002293 VkCommandBufferBeginInfo cmd_buf_info = {};
2294 cmd_buf_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
Cody Northropb4569702015-08-04 17:35:57 -06002295 cmd_buf_info.pNext = NULL;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002296 cmd_buf_info.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT;
Mark Youngad779052016-01-06 14:26:04 -07002297 cmd_buf_info.renderPass = (VkRenderPass)((size_t)0xcadecade);
2298 cmd_buf_info.framebuffer = (VkFramebuffer)((size_t)0xcadecade);
Cody Northropb4569702015-08-04 17:35:57 -06002299
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06002300
2301 // The error should be caught by validation of the BeginCommandBuffer call
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002302 vkBeginCommandBuffer(commandBuffer.GetBufferHandle(), &cmd_buf_info);
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06002303
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002304 if (!m_errorMonitor->DesiredMsgFound()) {
2305 FAIL() << "Did not receive Error 'vkAllocateCommandBuffers(): Primary Command Buffer may not specify framebuffer or renderpass parameters'";
2306 m_errorMonitor->DumpFailureMsgs();
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06002307 }
2308}
2309
Tobin Ehlis61b36f32015-12-16 08:19:42 -07002310TEST_F(VkLayerTest, SecondaryCommandBufferNullRenderpass)
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06002311{
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06002312 VkResult err;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002313 VkCommandBuffer draw_cmd;
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06002314
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07002315 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis61b36f32015-12-16 08:19:42 -07002316 " must specify a valid renderpass parameter.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002317
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06002318 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06002319
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002320 VkCommandBufferAllocateInfo cmd = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08002321 cmd.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
Cody Northropb4569702015-08-04 17:35:57 -06002322 cmd.pNext = NULL;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002323 cmd.commandPool = m_commandPool;
2324 cmd.level = VK_COMMAND_BUFFER_LEVEL_SECONDARY;
Chia-I Wud50a7d72015-10-26 20:48:51 +08002325 cmd.bufferCount = 1;
Cody Northropb4569702015-08-04 17:35:57 -06002326
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002327 err = vkAllocateCommandBuffers(m_device->device(), &cmd, &draw_cmd);
Mike Stroyand1c84a52015-08-18 14:40:24 -06002328 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06002329
2330 // Force the failure by not setting the Renderpass and Framebuffer fields
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002331 VkCommandBufferBeginInfo cmd_buf_info = {};
2332 cmd_buf_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
Cody Northropb4569702015-08-04 17:35:57 -06002333 cmd_buf_info.pNext = NULL;
Tobin Ehlis651d9b02015-12-16 05:01:22 -07002334 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 -06002335
2336 // The error should be caught by validation of the BeginCommandBuffer call
2337 vkBeginCommandBuffer(draw_cmd, &cmd_buf_info);
2338
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002339 if (!m_errorMonitor->DesiredMsgFound()) {
Tobin Ehlis61b36f32015-12-16 08:19:42 -07002340 FAIL() << "Did not receive Error 'vkBeginCommandBuffer(): Secondary Command Buffers (0x<ADDR>) must specify a valid renderpass parameter.'";
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002341 m_errorMonitor->DumpFailureMsgs();
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06002342 }
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002343 vkFreeCommandBuffers(m_device->device(), m_commandPool, 1, &draw_cmd);
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06002344}
2345
Tobin Ehlisac0ef842015-12-14 13:46:38 -07002346TEST_F(VkLayerTest, CommandBufferResetErrors)
2347{
2348 // Cause error due to Begin while recording CB
2349 // Then cause 2 errors for attempting to reset CB w/o having
2350 // VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT set for the pool from
2351 // which CBs were allocated. Note that this bit is off by default.
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07002352 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlisac0ef842015-12-14 13:46:38 -07002353 "Cannot call Begin on CB");
2354
2355 ASSERT_NO_FATAL_FAILURE(InitState());
2356
2357 // Calls AllocateCommandBuffers
2358 VkCommandBufferObj commandBuffer(m_device, m_commandPool);
2359
2360 // Force the failure by setting the Renderpass and Framebuffer fields with (fake) data
2361 VkCommandBufferBeginInfo cmd_buf_info = {};
2362 cmd_buf_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
2363 cmd_buf_info.pNext = NULL;
2364 cmd_buf_info.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT;
2365
2366 // Begin CB to transition to recording state
2367 vkBeginCommandBuffer(commandBuffer.GetBufferHandle(), &cmd_buf_info);
2368 // Can't re-begin. This should trigger error
2369 vkBeginCommandBuffer(commandBuffer.GetBufferHandle(), &cmd_buf_info);
2370 if (!m_errorMonitor->DesiredMsgFound()) {
2371 FAIL() << "Did not receive Error 'Cannot call Begin on CB (0x<ADDR>) in the RECORDING state...'";
2372 m_errorMonitor->DumpFailureMsgs();
2373 }
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07002374 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attempt to reset command buffer ");
Tobin Ehlisac0ef842015-12-14 13:46:38 -07002375 VkCommandBufferResetFlags flags = 0; // Don't care about flags for this test
2376 // Reset attempt will trigger error due to incorrect CommandPool state
2377 vkResetCommandBuffer(commandBuffer.GetBufferHandle(), flags);
2378 if (!m_errorMonitor->DesiredMsgFound()) {
2379 FAIL() << "Did not receive Error 'Attempt to reset command buffer (0x<ADDR>) created from command pool...'";
2380 m_errorMonitor->DumpFailureMsgs();
2381 }
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07002382 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " attempts to implicitly reset cmdBuffer created from ");
Tobin Ehlisac0ef842015-12-14 13:46:38 -07002383 // Transition CB to RECORDED state
2384 vkEndCommandBuffer(commandBuffer.GetBufferHandle());
2385 // Now attempting to Begin will implicitly reset, which triggers error
2386 vkBeginCommandBuffer(commandBuffer.GetBufferHandle(), &cmd_buf_info);
2387 if (!m_errorMonitor->DesiredMsgFound()) {
2388 FAIL() << "Did not receive Error 'Call to vkBeginCommandBuffer() on command buffer (0x<ADDR>) attempts to implicitly reset...'";
2389 m_errorMonitor->DumpFailureMsgs();
2390 }
2391}
2392
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06002393TEST_F(VkLayerTest, InvalidPipelineCreateState)
2394{
2395 // Attempt to Create Gfx Pipeline w/o a VS
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06002396 VkResult err;
2397
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07002398 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002399 "Invalid Pipeline CreateInfo State: Vtx Shader required");
2400
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06002401 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002402 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinski209b5292015-09-17 09:44:05 -06002403
Chia-I Wu1b99bb22015-10-27 19:25:11 +08002404 VkDescriptorPoolSize ds_type_count = {};
Tony Barboureb254902015-07-15 12:50:33 -06002405 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wud50a7d72015-10-26 20:48:51 +08002406 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06002407
2408 VkDescriptorPoolCreateInfo ds_pool_ci = {};
2409 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
2410 ds_pool_ci.pNext = NULL;
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -06002411 ds_pool_ci.maxSets = 1;
Chia-I Wu1b99bb22015-10-27 19:25:11 +08002412 ds_pool_ci.poolSizeCount = 1;
2413 ds_pool_ci.pPoolSizes = &ds_type_count;
Mark Lobodzinski209b5292015-09-17 09:44:05 -06002414
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06002415 VkDescriptorPool ds_pool;
Chia-I Wuf7458c52015-10-26 21:10:41 +08002416 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06002417 ASSERT_VK_SUCCESS(err);
2418
Tony Barboureb254902015-07-15 12:50:33 -06002419 VkDescriptorSetLayoutBinding dsl_binding = {};
Chia-I Wud46e6ae2015-10-31 00:31:16 +08002420 dsl_binding.binding = 0;
Tony Barboureb254902015-07-15 12:50:33 -06002421 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wu02124482015-11-06 06:42:02 +08002422 dsl_binding.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06002423 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
2424 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06002425
Tony Barboureb254902015-07-15 12:50:33 -06002426 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
2427 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
2428 ds_layout_ci.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08002429 ds_layout_ci.bindingCount = 1;
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07002430 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -06002431
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06002432 VkDescriptorSetLayout ds_layout;
Chia-I Wuf7458c52015-10-26 21:10:41 +08002433 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06002434 ASSERT_VK_SUCCESS(err);
2435
2436 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002437 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08002438 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Chia-I Wud50a7d72015-10-26 20:48:51 +08002439 alloc_info.setLayoutCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06002440 alloc_info.descriptorPool = ds_pool;
2441 alloc_info.pSetLayouts = &ds_layout;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002442 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06002443 ASSERT_VK_SUCCESS(err);
2444
Tony Barboureb254902015-07-15 12:50:33 -06002445 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
2446 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
Chia-I Wud50a7d72015-10-26 20:48:51 +08002447 pipeline_layout_ci.setLayoutCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06002448 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06002449
2450 VkPipelineLayout pipeline_layout;
Chia-I Wuf7458c52015-10-26 21:10:41 +08002451 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06002452 ASSERT_VK_SUCCESS(err);
2453
Tobin Ehlise68360f2015-10-01 11:15:13 -06002454 VkViewport vp = {}; // Just need dummy vp to point to
2455 VkRect2D sc = {}; // dummy scissor to point to
2456
2457 VkPipelineViewportStateCreateInfo vp_state_ci = {};
2458 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
2459 vp_state_ci.scissorCount = 1;
2460 vp_state_ci.pScissors = &sc;
2461 vp_state_ci.viewportCount = 1;
2462 vp_state_ci.pViewports = &vp;
2463
Tony Barboureb254902015-07-15 12:50:33 -06002464 VkGraphicsPipelineCreateInfo gp_ci = {};
2465 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
Tobin Ehlise68360f2015-10-01 11:15:13 -06002466 gp_ci.pViewportState = &vp_state_ci;
Tony Barboureb254902015-07-15 12:50:33 -06002467 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
2468 gp_ci.layout = pipeline_layout;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002469 gp_ci.renderPass = renderPass();
Tony Barboureb254902015-07-15 12:50:33 -06002470
2471 VkPipelineCacheCreateInfo pc_ci = {};
2472 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
Chia-I Wu2bfb33c2015-10-26 17:24:52 +08002473 pc_ci.initialDataSize = 0;
2474 pc_ci.pInitialData = 0;
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06002475
2476 VkPipeline pipeline;
Jon Ashburnc669cc62015-07-09 15:02:25 -06002477 VkPipelineCache pipelineCache;
2478
Chia-I Wuf7458c52015-10-26 21:10:41 +08002479 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Jon Ashburnc669cc62015-07-09 15:02:25 -06002480 ASSERT_VK_SUCCESS(err);
Chia-I Wuf7458c52015-10-26 21:10:41 +08002481 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06002482
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002483 if (!m_errorMonitor->DesiredMsgFound()) {
2484 FAIL() << "Did not receive Error 'Invalid Pipeline CreateInfo State: Vtx Shader required'";
2485 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06002486 }
Mike Stroyand1c84a52015-08-18 14:40:24 -06002487
Chia-I Wuf7458c52015-10-26 21:10:41 +08002488 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
2489 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
2490 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
2491 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06002492}
Tobin Ehlis912df022015-09-17 08:46:18 -06002493/*// TODO : This test should be good, but needs Tess support in compiler to run
2494TEST_F(VkLayerTest, InvalidPatchControlPoints)
2495{
2496 // Attempt to Create Gfx Pipeline w/o a VS
Tobin Ehlis912df022015-09-17 08:46:18 -06002497 VkResult err;
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06002498
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07002499 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002500 "Invalid Pipeline CreateInfo State: VK_PRIMITIVE_TOPOLOGY_PATCH primitive ");
2501
Tobin Ehlis912df022015-09-17 08:46:18 -06002502 ASSERT_NO_FATAL_FAILURE(InitState());
2503 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlis912df022015-09-17 08:46:18 -06002504
Chia-I Wu1b99bb22015-10-27 19:25:11 +08002505 VkDescriptorPoolSize ds_type_count = {};
Tobin Ehlis912df022015-09-17 08:46:18 -06002506 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wud50a7d72015-10-26 20:48:51 +08002507 ds_type_count.descriptorCount = 1;
Tobin Ehlis912df022015-09-17 08:46:18 -06002508
2509 VkDescriptorPoolCreateInfo ds_pool_ci = {};
2510 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
2511 ds_pool_ci.pNext = NULL;
Chia-I Wu1b99bb22015-10-27 19:25:11 +08002512 ds_pool_ci.poolSizeCount = 1;
2513 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlis912df022015-09-17 08:46:18 -06002514
2515 VkDescriptorPool ds_pool;
Chia-I Wuf7458c52015-10-26 21:10:41 +08002516 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 -06002517 ASSERT_VK_SUCCESS(err);
2518
2519 VkDescriptorSetLayoutBinding dsl_binding = {};
Chia-I Wud46e6ae2015-10-31 00:31:16 +08002520 dsl_binding.binding = 0;
Tobin Ehlis912df022015-09-17 08:46:18 -06002521 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wu02124482015-11-06 06:42:02 +08002522 dsl_binding.descriptorCount = 1;
Tobin Ehlis912df022015-09-17 08:46:18 -06002523 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
2524 dsl_binding.pImmutableSamplers = NULL;
2525
2526 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
2527 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
2528 ds_layout_ci.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08002529 ds_layout_ci.bindingCount = 1;
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07002530 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlis912df022015-09-17 08:46:18 -06002531
2532 VkDescriptorSetLayout ds_layout;
Chia-I Wuf7458c52015-10-26 21:10:41 +08002533 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis912df022015-09-17 08:46:18 -06002534 ASSERT_VK_SUCCESS(err);
2535
2536 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002537 err = vkAllocateDescriptorSets(m_device->device(), ds_pool, VK_DESCRIPTOR_SET_USAGE_NON_FREE, 1, &ds_layout, &descriptorSet);
Tobin Ehlis912df022015-09-17 08:46:18 -06002538 ASSERT_VK_SUCCESS(err);
2539
2540 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
2541 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
2542 pipeline_layout_ci.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08002543 pipeline_layout_ci.setLayoutCount = 1;
Tobin Ehlis912df022015-09-17 08:46:18 -06002544 pipeline_layout_ci.pSetLayouts = &ds_layout;
2545
2546 VkPipelineLayout pipeline_layout;
Chia-I Wuf7458c52015-10-26 21:10:41 +08002547 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis912df022015-09-17 08:46:18 -06002548 ASSERT_VK_SUCCESS(err);
2549
2550 VkPipelineShaderStageCreateInfo shaderStages[3];
2551 memset(&shaderStages, 0, 3 * sizeof(VkPipelineShaderStageCreateInfo));
2552
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06002553 VkShaderObj vs(m_device,bindStateVertShaderText,VK_SHADER_STAGE_VERTEX_BIT, this);
Tobin Ehlis912df022015-09-17 08:46:18 -06002554 // Just using VS txt for Tess shaders as we don't care about functionality
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06002555 VkShaderObj tc(m_device,bindStateVertShaderText,VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT, this);
2556 VkShaderObj te(m_device,bindStateVertShaderText,VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT, this);
Tobin Ehlis912df022015-09-17 08:46:18 -06002557
2558 shaderStages[0].sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06002559 shaderStages[0].stage = VK_SHADER_STAGE_VERTEX_BIT;
Tobin Ehlis912df022015-09-17 08:46:18 -06002560 shaderStages[0].shader = vs.handle();
2561 shaderStages[1].sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06002562 shaderStages[1].stage = VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT;
Tobin Ehlis912df022015-09-17 08:46:18 -06002563 shaderStages[1].shader = tc.handle();
2564 shaderStages[2].sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06002565 shaderStages[2].stage = VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT;
Tobin Ehlis912df022015-09-17 08:46:18 -06002566 shaderStages[2].shader = te.handle();
2567
2568 VkPipelineInputAssemblyStateCreateInfo iaCI = {};
2569 iaCI.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
Chia-I Wu515eb8f2015-10-31 00:31:16 +08002570 iaCI.topology = VK_PRIMITIVE_TOPOLOGY_PATCH_LIST;
Tobin Ehlis912df022015-09-17 08:46:18 -06002571
2572 VkPipelineTessellationStateCreateInfo tsCI = {};
2573 tsCI.sType = VK_STRUCTURE_TYPE_PIPELINE_TESSELLATION_STATE_CREATE_INFO;
2574 tsCI.patchControlPoints = 0; // This will cause an error
2575
2576 VkGraphicsPipelineCreateInfo gp_ci = {};
2577 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
2578 gp_ci.pNext = NULL;
2579 gp_ci.stageCount = 3;
2580 gp_ci.pStages = shaderStages;
2581 gp_ci.pVertexInputState = NULL;
2582 gp_ci.pInputAssemblyState = &iaCI;
2583 gp_ci.pTessellationState = &tsCI;
2584 gp_ci.pViewportState = NULL;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002585 gp_ci.pRasterizationState = NULL;
Tobin Ehlis912df022015-09-17 08:46:18 -06002586 gp_ci.pMultisampleState = NULL;
2587 gp_ci.pDepthStencilState = NULL;
2588 gp_ci.pColorBlendState = NULL;
2589 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
2590 gp_ci.layout = pipeline_layout;
2591 gp_ci.renderPass = renderPass();
2592
2593 VkPipelineCacheCreateInfo pc_ci = {};
2594 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
2595 pc_ci.pNext = NULL;
2596 pc_ci.initialSize = 0;
2597 pc_ci.initialData = 0;
2598 pc_ci.maxSize = 0;
2599
2600 VkPipeline pipeline;
2601 VkPipelineCache pipelineCache;
2602
Chia-I Wuf7458c52015-10-26 21:10:41 +08002603 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Tobin Ehlis912df022015-09-17 08:46:18 -06002604 ASSERT_VK_SUCCESS(err);
Chia-I Wuf7458c52015-10-26 21:10:41 +08002605 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlis912df022015-09-17 08:46:18 -06002606
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002607 if (!m_errorMonitor->DesiredMsgFound()) {
2608 FAIL() << "Did not receive Error 'Invalid Pipeline CreateInfo State: VK_PRIMITIVE_TOPOLOGY_PATCH primitive...'";
2609 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlis912df022015-09-17 08:46:18 -06002610 }
Mike Stroyand1c84a52015-08-18 14:40:24 -06002611
Chia-I Wuf7458c52015-10-26 21:10:41 +08002612 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
2613 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
2614 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
2615 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis912df022015-09-17 08:46:18 -06002616}
2617*/
Tobin Ehlise68360f2015-10-01 11:15:13 -06002618// Set scissor and viewport counts to different numbers
2619TEST_F(VkLayerTest, PSOViewportScissorCountMismatch)
2620{
2621 // Attempt to Create Gfx Pipeline w/o a VS
Tobin Ehlise68360f2015-10-01 11:15:13 -06002622 VkResult err;
2623
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07002624 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002625 "Gfx Pipeline viewport count (1) must match scissor count (0).");
2626
Tobin Ehlise68360f2015-10-01 11:15:13 -06002627 ASSERT_NO_FATAL_FAILURE(InitState());
2628 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlise68360f2015-10-01 11:15:13 -06002629
Chia-I Wu1b99bb22015-10-27 19:25:11 +08002630 VkDescriptorPoolSize ds_type_count = {};
Tobin Ehlise68360f2015-10-01 11:15:13 -06002631 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wud50a7d72015-10-26 20:48:51 +08002632 ds_type_count.descriptorCount = 1;
Tobin Ehlise68360f2015-10-01 11:15:13 -06002633
2634 VkDescriptorPoolCreateInfo ds_pool_ci = {};
2635 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
Tobin Ehlise68360f2015-10-01 11:15:13 -06002636 ds_pool_ci.maxSets = 1;
Chia-I Wu1b99bb22015-10-27 19:25:11 +08002637 ds_pool_ci.poolSizeCount = 1;
2638 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlise68360f2015-10-01 11:15:13 -06002639
2640 VkDescriptorPool ds_pool;
Chia-I Wuf7458c52015-10-26 21:10:41 +08002641 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlise68360f2015-10-01 11:15:13 -06002642 ASSERT_VK_SUCCESS(err);
2643
2644 VkDescriptorSetLayoutBinding dsl_binding = {};
Chia-I Wud46e6ae2015-10-31 00:31:16 +08002645 dsl_binding.binding = 0;
Tobin Ehlise68360f2015-10-01 11:15:13 -06002646 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wu02124482015-11-06 06:42:02 +08002647 dsl_binding.descriptorCount = 1;
Tobin Ehlise68360f2015-10-01 11:15:13 -06002648 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
2649
2650 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
2651 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
Chia-I Wud50a7d72015-10-26 20:48:51 +08002652 ds_layout_ci.bindingCount = 1;
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07002653 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlise68360f2015-10-01 11:15:13 -06002654
2655 VkDescriptorSetLayout ds_layout;
Chia-I Wuf7458c52015-10-26 21:10:41 +08002656 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06002657 ASSERT_VK_SUCCESS(err);
2658
2659 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002660 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08002661 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Chia-I Wud50a7d72015-10-26 20:48:51 +08002662 alloc_info.setLayoutCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06002663 alloc_info.descriptorPool = ds_pool;
2664 alloc_info.pSetLayouts = &ds_layout;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002665 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlise68360f2015-10-01 11:15:13 -06002666 ASSERT_VK_SUCCESS(err);
2667
2668 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
2669 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
Chia-I Wud50a7d72015-10-26 20:48:51 +08002670 pipeline_layout_ci.setLayoutCount = 1;
Tobin Ehlise68360f2015-10-01 11:15:13 -06002671 pipeline_layout_ci.pSetLayouts = &ds_layout;
2672
2673 VkPipelineLayout pipeline_layout;
Chia-I Wuf7458c52015-10-26 21:10:41 +08002674 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06002675 ASSERT_VK_SUCCESS(err);
2676
2677 VkViewport vp = {}; // Just need dummy vp to point to
2678
2679 VkPipelineViewportStateCreateInfo vp_state_ci = {};
2680 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
2681 vp_state_ci.scissorCount = 0;
2682 vp_state_ci.viewportCount = 1; // Count mismatch should cause error
2683 vp_state_ci.pViewports = &vp;
2684
Cody Northropeb3a6c12015-10-05 14:44:45 -06002685 VkPipelineShaderStageCreateInfo shaderStages[2];
2686 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
Tobin Ehlise68360f2015-10-01 11:15:13 -06002687
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06002688 VkShaderObj vs(m_device,bindStateVertShaderText,VK_SHADER_STAGE_VERTEX_BIT, this);
2689 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 -06002690 // but add it to be able to run on more devices
Chia-I Wu28e06912015-10-31 00:31:16 +08002691 shaderStages[0] = vs.GetStageCreateInfo();
2692 shaderStages[1] = fs.GetStageCreateInfo();
Tobin Ehlise68360f2015-10-01 11:15:13 -06002693
2694 VkGraphicsPipelineCreateInfo gp_ci = {};
2695 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
Cody Northropeb3a6c12015-10-05 14:44:45 -06002696 gp_ci.stageCount = 2;
2697 gp_ci.pStages = shaderStages;
Tobin Ehlise68360f2015-10-01 11:15:13 -06002698 gp_ci.pViewportState = &vp_state_ci;
2699 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
2700 gp_ci.layout = pipeline_layout;
2701 gp_ci.renderPass = renderPass();
2702
2703 VkPipelineCacheCreateInfo pc_ci = {};
2704 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
2705
2706 VkPipeline pipeline;
2707 VkPipelineCache pipelineCache;
2708
Chia-I Wuf7458c52015-10-26 21:10:41 +08002709 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Tobin Ehlise68360f2015-10-01 11:15:13 -06002710 ASSERT_VK_SUCCESS(err);
Chia-I Wuf7458c52015-10-26 21:10:41 +08002711 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlise68360f2015-10-01 11:15:13 -06002712
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002713 if (!m_errorMonitor->DesiredMsgFound()) {
2714 FAIL() << "Did not receive Error 'Gfx Pipeline viewport count (1) must match scissor count (0).'";
2715 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlise68360f2015-10-01 11:15:13 -06002716 }
2717
Chia-I Wuf7458c52015-10-26 21:10:41 +08002718 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
2719 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
2720 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
2721 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlise68360f2015-10-01 11:15:13 -06002722}
Tobin Ehlisd332f282015-10-02 11:00:56 -06002723// Don't set viewport state in PSO. This is an error b/c we always need this state
2724// for the counts even if the data is going to be set dynamically.
2725TEST_F(VkLayerTest, PSOViewportStateNotSet)
Tobin Ehlise68360f2015-10-01 11:15:13 -06002726{
2727 // Attempt to Create Gfx Pipeline w/o a VS
Tobin Ehlise68360f2015-10-01 11:15:13 -06002728 VkResult err;
2729
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07002730 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002731 "Gfx Pipeline pViewportState is null. Even if ");
2732
Tobin Ehlise68360f2015-10-01 11:15:13 -06002733 ASSERT_NO_FATAL_FAILURE(InitState());
2734 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlise68360f2015-10-01 11:15:13 -06002735
Chia-I Wu1b99bb22015-10-27 19:25:11 +08002736 VkDescriptorPoolSize ds_type_count = {};
Tobin Ehlise68360f2015-10-01 11:15:13 -06002737 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wud50a7d72015-10-26 20:48:51 +08002738 ds_type_count.descriptorCount = 1;
Tobin Ehlise68360f2015-10-01 11:15:13 -06002739
2740 VkDescriptorPoolCreateInfo ds_pool_ci = {};
2741 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
Tobin Ehlise68360f2015-10-01 11:15:13 -06002742 ds_pool_ci.maxSets = 1;
Chia-I Wu1b99bb22015-10-27 19:25:11 +08002743 ds_pool_ci.poolSizeCount = 1;
2744 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlise68360f2015-10-01 11:15:13 -06002745
2746 VkDescriptorPool ds_pool;
Chia-I Wuf7458c52015-10-26 21:10:41 +08002747 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlise68360f2015-10-01 11:15:13 -06002748 ASSERT_VK_SUCCESS(err);
2749
2750 VkDescriptorSetLayoutBinding dsl_binding = {};
Chia-I Wud46e6ae2015-10-31 00:31:16 +08002751 dsl_binding.binding = 0;
Tobin Ehlise68360f2015-10-01 11:15:13 -06002752 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wu02124482015-11-06 06:42:02 +08002753 dsl_binding.descriptorCount = 1;
Tobin Ehlise68360f2015-10-01 11:15:13 -06002754 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
2755
2756 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
2757 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
Chia-I Wud50a7d72015-10-26 20:48:51 +08002758 ds_layout_ci.bindingCount = 1;
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07002759 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlise68360f2015-10-01 11:15:13 -06002760
2761 VkDescriptorSetLayout ds_layout;
Chia-I Wuf7458c52015-10-26 21:10:41 +08002762 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06002763 ASSERT_VK_SUCCESS(err);
2764
2765 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002766 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08002767 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Chia-I Wud50a7d72015-10-26 20:48:51 +08002768 alloc_info.setLayoutCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06002769 alloc_info.descriptorPool = ds_pool;
2770 alloc_info.pSetLayouts = &ds_layout;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002771 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlise68360f2015-10-01 11:15:13 -06002772 ASSERT_VK_SUCCESS(err);
2773
2774 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
2775 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
Chia-I Wud50a7d72015-10-26 20:48:51 +08002776 pipeline_layout_ci.setLayoutCount = 1;
Tobin Ehlise68360f2015-10-01 11:15:13 -06002777 pipeline_layout_ci.pSetLayouts = &ds_layout;
2778
2779 VkPipelineLayout pipeline_layout;
Chia-I Wuf7458c52015-10-26 21:10:41 +08002780 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06002781 ASSERT_VK_SUCCESS(err);
2782
2783 VkDynamicState sc_state = VK_DYNAMIC_STATE_SCISSOR;
2784 // Set scissor as dynamic to avoid second error
2785 VkPipelineDynamicStateCreateInfo dyn_state_ci = {};
2786 dyn_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
2787 dyn_state_ci.dynamicStateCount = 1;
2788 dyn_state_ci.pDynamicStates = &sc_state;
2789
Cody Northropeb3a6c12015-10-05 14:44:45 -06002790 VkPipelineShaderStageCreateInfo shaderStages[2];
2791 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
Tobin Ehlise68360f2015-10-01 11:15:13 -06002792
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06002793 VkShaderObj vs(m_device,bindStateVertShaderText,VK_SHADER_STAGE_VERTEX_BIT, this);
2794 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 -06002795 // but add it to be able to run on more devices
Chia-I Wu28e06912015-10-31 00:31:16 +08002796 shaderStages[0] = vs.GetStageCreateInfo();
2797 shaderStages[1] = fs.GetStageCreateInfo();
Tobin Ehlise68360f2015-10-01 11:15:13 -06002798
2799 VkGraphicsPipelineCreateInfo gp_ci = {};
2800 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
Cody Northropeb3a6c12015-10-05 14:44:45 -06002801 gp_ci.stageCount = 2;
2802 gp_ci.pStages = shaderStages;
Tobin Ehlise68360f2015-10-01 11:15:13 -06002803 gp_ci.pViewportState = NULL; // Not setting VP state w/o dynamic vp state should cause validation error
2804 gp_ci.pDynamicState = &dyn_state_ci;
2805 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
2806 gp_ci.layout = pipeline_layout;
2807 gp_ci.renderPass = renderPass();
2808
2809 VkPipelineCacheCreateInfo pc_ci = {};
2810 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
2811
2812 VkPipeline pipeline;
2813 VkPipelineCache pipelineCache;
2814
Chia-I Wuf7458c52015-10-26 21:10:41 +08002815 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Tobin Ehlise68360f2015-10-01 11:15:13 -06002816 ASSERT_VK_SUCCESS(err);
Chia-I Wuf7458c52015-10-26 21:10:41 +08002817 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlise68360f2015-10-01 11:15:13 -06002818
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002819 if (!m_errorMonitor->DesiredMsgFound()) {
2820 FAIL() << "Did not receive Error 'Gfx Pipeline pViewportState is null. Even if...'";
2821 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlise68360f2015-10-01 11:15:13 -06002822 }
2823
Chia-I Wuf7458c52015-10-26 21:10:41 +08002824 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
2825 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
2826 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
2827 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlise68360f2015-10-01 11:15:13 -06002828}
2829// Create PSO w/o non-zero viewportCount but no viewport data
Tobin Ehlisd332f282015-10-02 11:00:56 -06002830// Then run second test where dynamic scissor count doesn't match PSO scissor count
2831TEST_F(VkLayerTest, PSOViewportCountWithoutDataAndDynScissorMismatch)
Tobin Ehlise68360f2015-10-01 11:15:13 -06002832{
Tobin Ehlise68360f2015-10-01 11:15:13 -06002833 VkResult err;
2834
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07002835 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002836 "Gfx Pipeline viewportCount is 1, but pViewports is NULL. ");
2837
Tobin Ehlise68360f2015-10-01 11:15:13 -06002838 ASSERT_NO_FATAL_FAILURE(InitState());
2839 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlise68360f2015-10-01 11:15:13 -06002840
Chia-I Wu1b99bb22015-10-27 19:25:11 +08002841 VkDescriptorPoolSize ds_type_count = {};
Tobin Ehlise68360f2015-10-01 11:15:13 -06002842 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wud50a7d72015-10-26 20:48:51 +08002843 ds_type_count.descriptorCount = 1;
Tobin Ehlise68360f2015-10-01 11:15:13 -06002844
2845 VkDescriptorPoolCreateInfo ds_pool_ci = {};
2846 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
Tobin Ehlise68360f2015-10-01 11:15:13 -06002847 ds_pool_ci.maxSets = 1;
Chia-I Wu1b99bb22015-10-27 19:25:11 +08002848 ds_pool_ci.poolSizeCount = 1;
2849 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlise68360f2015-10-01 11:15:13 -06002850
2851 VkDescriptorPool ds_pool;
Chia-I Wuf7458c52015-10-26 21:10:41 +08002852 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlise68360f2015-10-01 11:15:13 -06002853 ASSERT_VK_SUCCESS(err);
2854
2855 VkDescriptorSetLayoutBinding dsl_binding = {};
Chia-I Wud46e6ae2015-10-31 00:31:16 +08002856 dsl_binding.binding = 0;
Tobin Ehlise68360f2015-10-01 11:15:13 -06002857 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wu02124482015-11-06 06:42:02 +08002858 dsl_binding.descriptorCount = 1;
Tobin Ehlise68360f2015-10-01 11:15:13 -06002859 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
2860
2861 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
2862 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
Chia-I Wud50a7d72015-10-26 20:48:51 +08002863 ds_layout_ci.bindingCount = 1;
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07002864 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlise68360f2015-10-01 11:15:13 -06002865
2866 VkDescriptorSetLayout ds_layout;
Chia-I Wuf7458c52015-10-26 21:10:41 +08002867 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06002868 ASSERT_VK_SUCCESS(err);
2869
2870 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002871 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08002872 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Chia-I Wud50a7d72015-10-26 20:48:51 +08002873 alloc_info.setLayoutCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06002874 alloc_info.descriptorPool = ds_pool;
2875 alloc_info.pSetLayouts = &ds_layout;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002876 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlise68360f2015-10-01 11:15:13 -06002877 ASSERT_VK_SUCCESS(err);
2878
2879 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
2880 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
Chia-I Wud50a7d72015-10-26 20:48:51 +08002881 pipeline_layout_ci.setLayoutCount = 1;
Tobin Ehlise68360f2015-10-01 11:15:13 -06002882 pipeline_layout_ci.pSetLayouts = &ds_layout;
2883
2884 VkPipelineLayout pipeline_layout;
Chia-I Wuf7458c52015-10-26 21:10:41 +08002885 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06002886 ASSERT_VK_SUCCESS(err);
2887
2888 VkPipelineViewportStateCreateInfo vp_state_ci = {};
2889 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
2890 vp_state_ci.viewportCount = 1;
2891 vp_state_ci.pViewports = NULL; // Null vp w/ count of 1 should cause error
2892 vp_state_ci.scissorCount = 1;
2893 vp_state_ci.pScissors = NULL; // Scissor is dynamic (below) so this won't cause error
2894
2895 VkDynamicState sc_state = VK_DYNAMIC_STATE_SCISSOR;
2896 // Set scissor as dynamic to avoid that error
2897 VkPipelineDynamicStateCreateInfo dyn_state_ci = {};
2898 dyn_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
2899 dyn_state_ci.dynamicStateCount = 1;
2900 dyn_state_ci.pDynamicStates = &sc_state;
2901
Cody Northropeb3a6c12015-10-05 14:44:45 -06002902 VkPipelineShaderStageCreateInfo shaderStages[2];
2903 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
Tobin Ehlise68360f2015-10-01 11:15:13 -06002904
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06002905 VkShaderObj vs(m_device,bindStateVertShaderText,VK_SHADER_STAGE_VERTEX_BIT, this);
2906 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 -06002907 // but add it to be able to run on more devices
Chia-I Wu28e06912015-10-31 00:31:16 +08002908 shaderStages[0] = vs.GetStageCreateInfo();
2909 shaderStages[1] = fs.GetStageCreateInfo();
Tobin Ehlise68360f2015-10-01 11:15:13 -06002910
Cody Northropf6622dc2015-10-06 10:33:21 -06002911 VkPipelineVertexInputStateCreateInfo vi_ci = {};
2912 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
2913 vi_ci.pNext = nullptr;
Chia-I Wud50a7d72015-10-26 20:48:51 +08002914 vi_ci.vertexBindingDescriptionCount = 0;
Cody Northropf6622dc2015-10-06 10:33:21 -06002915 vi_ci.pVertexBindingDescriptions = nullptr;
Chia-I Wud50a7d72015-10-26 20:48:51 +08002916 vi_ci.vertexAttributeDescriptionCount = 0;
Cody Northropf6622dc2015-10-06 10:33:21 -06002917 vi_ci.pVertexAttributeDescriptions = nullptr;
2918
2919 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
2920 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
2921 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
2922
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002923 VkPipelineRasterizationStateCreateInfo rs_ci = {};
Chia-I Wu1b99bb22015-10-27 19:25:11 +08002924 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
Cody Northropf6622dc2015-10-06 10:33:21 -06002925 rs_ci.pNext = nullptr;
2926
2927 VkPipelineColorBlendStateCreateInfo cb_ci = {};
2928 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
2929 cb_ci.pNext = nullptr;
2930
Tobin Ehlise68360f2015-10-01 11:15:13 -06002931 VkGraphicsPipelineCreateInfo gp_ci = {};
2932 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
Cody Northropeb3a6c12015-10-05 14:44:45 -06002933 gp_ci.stageCount = 2;
2934 gp_ci.pStages = shaderStages;
Cody Northropf6622dc2015-10-06 10:33:21 -06002935 gp_ci.pVertexInputState = &vi_ci;
2936 gp_ci.pInputAssemblyState = &ia_ci;
Tobin Ehlise68360f2015-10-01 11:15:13 -06002937 gp_ci.pViewportState = &vp_state_ci;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002938 gp_ci.pRasterizationState = &rs_ci;
Cody Northropf6622dc2015-10-06 10:33:21 -06002939 gp_ci.pColorBlendState = &cb_ci;
Tobin Ehlise68360f2015-10-01 11:15:13 -06002940 gp_ci.pDynamicState = &dyn_state_ci;
2941 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
2942 gp_ci.layout = pipeline_layout;
2943 gp_ci.renderPass = renderPass();
2944
2945 VkPipelineCacheCreateInfo pc_ci = {};
2946 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
2947
2948 VkPipeline pipeline;
2949 VkPipelineCache pipelineCache;
2950
Chia-I Wuf7458c52015-10-26 21:10:41 +08002951 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Tobin Ehlise68360f2015-10-01 11:15:13 -06002952 ASSERT_VK_SUCCESS(err);
Chia-I Wuf7458c52015-10-26 21:10:41 +08002953 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlise68360f2015-10-01 11:15:13 -06002954
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002955 if (!m_errorMonitor->DesiredMsgFound()) {
2956 FAIL() << "Did not recieve Error 'Gfx Pipeline viewportCount is 1, but pViewports is NULL...'";
2957 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlise68360f2015-10-01 11:15:13 -06002958 }
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002959
2960
Tobin Ehlisd332f282015-10-02 11:00:56 -06002961 // Now hit second fail case where we set scissor w/ different count than PSO
2962 // First need to successfully create the PSO from above by setting pViewports
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07002963 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002964 "Dynamic scissorCount from vkCmdSetScissor() is 2, but PSO scissorCount is 1. These counts must match.");
2965
Tobin Ehlisd332f282015-10-02 11:00:56 -06002966 VkViewport vp = {}; // Just need dummy vp to point to
2967 vp_state_ci.pViewports = &vp;
Chia-I Wuf7458c52015-10-26 21:10:41 +08002968 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlisd332f282015-10-02 11:00:56 -06002969 ASSERT_VK_SUCCESS(err);
2970 BeginCommandBuffer();
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002971 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
Tobin Ehlisd332f282015-10-02 11:00:56 -06002972 VkRect2D scissors[2] = {}; // don't care about data
2973 // Count of 2 doesn't match PSO count of 1
Jon Ashburn19d3bf12015-12-30 14:06:55 -07002974 vkCmdSetScissor(m_commandBuffer->GetBufferHandle(), 0, 2, scissors);
Tobin Ehlisd332f282015-10-02 11:00:56 -06002975 Draw(1, 0, 0, 0);
2976
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002977 if (!m_errorMonitor->DesiredMsgFound()) {
2978 FAIL() << "Did not receive Error 'Dynamic scissorCount from vkCmdSetScissor() is 2, but PSO scissorCount is 1...'";
2979 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlisd332f282015-10-02 11:00:56 -06002980 }
Tobin Ehlise68360f2015-10-01 11:15:13 -06002981
Chia-I Wuf7458c52015-10-26 21:10:41 +08002982 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
2983 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
2984 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
2985 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlise68360f2015-10-01 11:15:13 -06002986}
2987// Create PSO w/o non-zero scissorCount but no scissor data
Tobin Ehlisd332f282015-10-02 11:00:56 -06002988// Then run second test where dynamic viewportCount doesn't match PSO viewportCount
2989TEST_F(VkLayerTest, PSOScissorCountWithoutDataAndDynViewportMismatch)
Tobin Ehlise68360f2015-10-01 11:15:13 -06002990{
Tobin Ehlise68360f2015-10-01 11:15:13 -06002991 VkResult err;
2992
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07002993 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002994 "Gfx Pipeline scissorCount is 1, but pScissors is NULL. ");
2995
Tobin Ehlise68360f2015-10-01 11:15:13 -06002996 ASSERT_NO_FATAL_FAILURE(InitState());
2997 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlise68360f2015-10-01 11:15:13 -06002998
Chia-I Wu1b99bb22015-10-27 19:25:11 +08002999 VkDescriptorPoolSize ds_type_count = {};
Tobin Ehlise68360f2015-10-01 11:15:13 -06003000 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wud50a7d72015-10-26 20:48:51 +08003001 ds_type_count.descriptorCount = 1;
Tobin Ehlise68360f2015-10-01 11:15:13 -06003002
3003 VkDescriptorPoolCreateInfo ds_pool_ci = {};
3004 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
Tobin Ehlise68360f2015-10-01 11:15:13 -06003005 ds_pool_ci.maxSets = 1;
Chia-I Wu1b99bb22015-10-27 19:25:11 +08003006 ds_pool_ci.poolSizeCount = 1;
3007 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlise68360f2015-10-01 11:15:13 -06003008
3009 VkDescriptorPool ds_pool;
Chia-I Wuf7458c52015-10-26 21:10:41 +08003010 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlise68360f2015-10-01 11:15:13 -06003011 ASSERT_VK_SUCCESS(err);
3012
3013 VkDescriptorSetLayoutBinding dsl_binding = {};
Chia-I Wud46e6ae2015-10-31 00:31:16 +08003014 dsl_binding.binding = 0;
Tobin Ehlise68360f2015-10-01 11:15:13 -06003015 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wu02124482015-11-06 06:42:02 +08003016 dsl_binding.descriptorCount = 1;
Tobin Ehlise68360f2015-10-01 11:15:13 -06003017 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
3018
3019 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
3020 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
Chia-I Wud50a7d72015-10-26 20:48:51 +08003021 ds_layout_ci.bindingCount = 1;
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07003022 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlise68360f2015-10-01 11:15:13 -06003023
3024 VkDescriptorSetLayout ds_layout;
Chia-I Wuf7458c52015-10-26 21:10:41 +08003025 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06003026 ASSERT_VK_SUCCESS(err);
3027
3028 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003029 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08003030 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Chia-I Wud50a7d72015-10-26 20:48:51 +08003031 alloc_info.setLayoutCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06003032 alloc_info.descriptorPool = ds_pool;
3033 alloc_info.pSetLayouts = &ds_layout;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003034 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlise68360f2015-10-01 11:15:13 -06003035 ASSERT_VK_SUCCESS(err);
3036
3037 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
3038 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
Chia-I Wud50a7d72015-10-26 20:48:51 +08003039 pipeline_layout_ci.setLayoutCount = 1;
Tobin Ehlise68360f2015-10-01 11:15:13 -06003040 pipeline_layout_ci.pSetLayouts = &ds_layout;
3041
3042 VkPipelineLayout pipeline_layout;
Chia-I Wuf7458c52015-10-26 21:10:41 +08003043 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06003044 ASSERT_VK_SUCCESS(err);
3045
3046 VkPipelineViewportStateCreateInfo vp_state_ci = {};
3047 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
3048 vp_state_ci.scissorCount = 1;
3049 vp_state_ci.pScissors = NULL; // Null scissor w/ count of 1 should cause error
3050 vp_state_ci.viewportCount = 1;
3051 vp_state_ci.pViewports = NULL; // vp is dynamic (below) so this won't cause error
3052
3053 VkDynamicState vp_state = VK_DYNAMIC_STATE_VIEWPORT;
3054 // Set scissor as dynamic to avoid that error
3055 VkPipelineDynamicStateCreateInfo dyn_state_ci = {};
3056 dyn_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
3057 dyn_state_ci.dynamicStateCount = 1;
3058 dyn_state_ci.pDynamicStates = &vp_state;
3059
Cody Northropeb3a6c12015-10-05 14:44:45 -06003060 VkPipelineShaderStageCreateInfo shaderStages[2];
3061 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
Tobin Ehlise68360f2015-10-01 11:15:13 -06003062
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06003063 VkShaderObj vs(m_device,bindStateVertShaderText,VK_SHADER_STAGE_VERTEX_BIT, this);
3064 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 -06003065 // but add it to be able to run on more devices
Chia-I Wu28e06912015-10-31 00:31:16 +08003066 shaderStages[0] = vs.GetStageCreateInfo();
3067 shaderStages[1] = fs.GetStageCreateInfo();
Tobin Ehlise68360f2015-10-01 11:15:13 -06003068
Cody Northropf6622dc2015-10-06 10:33:21 -06003069 VkPipelineVertexInputStateCreateInfo vi_ci = {};
3070 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
3071 vi_ci.pNext = nullptr;
Chia-I Wud50a7d72015-10-26 20:48:51 +08003072 vi_ci.vertexBindingDescriptionCount = 0;
Cody Northropf6622dc2015-10-06 10:33:21 -06003073 vi_ci.pVertexBindingDescriptions = nullptr;
Chia-I Wud50a7d72015-10-26 20:48:51 +08003074 vi_ci.vertexAttributeDescriptionCount = 0;
Cody Northropf6622dc2015-10-06 10:33:21 -06003075 vi_ci.pVertexAttributeDescriptions = nullptr;
3076
3077 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
3078 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
3079 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
3080
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003081 VkPipelineRasterizationStateCreateInfo rs_ci = {};
Chia-I Wu1b99bb22015-10-27 19:25:11 +08003082 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
Cody Northropf6622dc2015-10-06 10:33:21 -06003083 rs_ci.pNext = nullptr;
3084
3085 VkPipelineColorBlendStateCreateInfo cb_ci = {};
3086 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
3087 cb_ci.pNext = nullptr;
3088
Tobin Ehlise68360f2015-10-01 11:15:13 -06003089 VkGraphicsPipelineCreateInfo gp_ci = {};
3090 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
Cody Northropeb3a6c12015-10-05 14:44:45 -06003091 gp_ci.stageCount = 2;
3092 gp_ci.pStages = shaderStages;
Cody Northropf6622dc2015-10-06 10:33:21 -06003093 gp_ci.pVertexInputState = &vi_ci;
3094 gp_ci.pInputAssemblyState = &ia_ci;
Tobin Ehlise68360f2015-10-01 11:15:13 -06003095 gp_ci.pViewportState = &vp_state_ci;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003096 gp_ci.pRasterizationState = &rs_ci;
Cody Northropf6622dc2015-10-06 10:33:21 -06003097 gp_ci.pColorBlendState = &cb_ci;
Tobin Ehlise68360f2015-10-01 11:15:13 -06003098 gp_ci.pDynamicState = &dyn_state_ci;
3099 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
3100 gp_ci.layout = pipeline_layout;
3101 gp_ci.renderPass = renderPass();
3102
3103 VkPipelineCacheCreateInfo pc_ci = {};
3104 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
3105
3106 VkPipeline pipeline;
3107 VkPipelineCache pipelineCache;
3108
Chia-I Wuf7458c52015-10-26 21:10:41 +08003109 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Tobin Ehlise68360f2015-10-01 11:15:13 -06003110 ASSERT_VK_SUCCESS(err);
Chia-I Wuf7458c52015-10-26 21:10:41 +08003111 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlise68360f2015-10-01 11:15:13 -06003112
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06003113 if (!m_errorMonitor->DesiredMsgFound()) {
3114 FAIL() << "Did not recieve Error 'Gfx Pipeline scissorCount is 1, but pScissors is NULL...'";
3115 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlise68360f2015-10-01 11:15:13 -06003116 }
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06003117
Tobin Ehlisd332f282015-10-02 11:00:56 -06003118 // Now hit second fail case where we set scissor w/ different count than PSO
3119 // First need to successfully create the PSO from above by setting pViewports
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07003120 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06003121 "Dynamic viewportCount from vkCmdSetViewport() is 2, but PSO viewportCount is 1. These counts must match.");
3122
Tobin Ehlisd332f282015-10-02 11:00:56 -06003123 VkRect2D sc = {}; // Just need dummy vp to point to
3124 vp_state_ci.pScissors = &sc;
Chia-I Wuf7458c52015-10-26 21:10:41 +08003125 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlisd332f282015-10-02 11:00:56 -06003126 ASSERT_VK_SUCCESS(err);
3127 BeginCommandBuffer();
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003128 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
Tobin Ehlisd332f282015-10-02 11:00:56 -06003129 VkViewport viewports[2] = {}; // don't care about data
3130 // Count of 2 doesn't match PSO count of 1
Jon Ashburn19d3bf12015-12-30 14:06:55 -07003131 vkCmdSetViewport(m_commandBuffer->GetBufferHandle(), 0, 2, viewports);
Tobin Ehlisd332f282015-10-02 11:00:56 -06003132 Draw(1, 0, 0, 0);
3133
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06003134 if (!m_errorMonitor->DesiredMsgFound()) {
3135 FAIL() << "Did not receive Error 'Dynamic viewportCount from vkCmdSetViewport() is 2, but PSO viewportCount is 1...'";
3136 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlisd332f282015-10-02 11:00:56 -06003137 }
Tobin Ehlise68360f2015-10-01 11:15:13 -06003138
Chia-I Wuf7458c52015-10-26 21:10:41 +08003139 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
3140 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
3141 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
3142 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlise68360f2015-10-01 11:15:13 -06003143}
3144
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06003145TEST_F(VkLayerTest, NullRenderPass)
3146{
3147 // Bind a NULL RenderPass
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07003148 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06003149 "You cannot use a NULL RenderPass object in vkCmdBeginRenderPass()");
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06003150
3151 ASSERT_NO_FATAL_FAILURE(InitState());
3152 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06003153
Tony Barbourfe3351b2015-07-28 10:17:20 -06003154 BeginCommandBuffer();
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06003155 // Don't care about RenderPass handle b/c error should be flagged before that
Chia-I Wu1b99bb22015-10-27 19:25:11 +08003156 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), NULL, VK_SUBPASS_CONTENTS_INLINE);
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06003157
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06003158 if (!m_errorMonitor->DesiredMsgFound()) {
3159 FAIL() << "Did not receive Error 'You cannot use a NULL RenderPass object in vkCmdBeginRenderPass()'";
3160 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06003161 }
3162}
3163
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06003164TEST_F(VkLayerTest, RenderPassWithinRenderPass)
3165{
3166 // Bind a BeginRenderPass within an active RenderPass
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07003167 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06003168 "It is invalid to issue this call inside an active render pass");
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06003169
3170 ASSERT_NO_FATAL_FAILURE(InitState());
3171 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06003172
Tony Barbourfe3351b2015-07-28 10:17:20 -06003173 BeginCommandBuffer();
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06003174 // Just create a dummy Renderpass that's non-NULL so we can get to the proper error
Tony Barboureb254902015-07-15 12:50:33 -06003175 VkRenderPassBeginInfo rp_begin = {};
3176 rp_begin.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO;
3177 rp_begin.pNext = NULL;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06003178 rp_begin.renderPass = renderPass();
3179 rp_begin.framebuffer = framebuffer();
Mark Lobodzinski209b5292015-09-17 09:44:05 -06003180
Chia-I Wu1b99bb22015-10-27 19:25:11 +08003181 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &rp_begin, VK_SUBPASS_CONTENTS_INLINE);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06003182
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06003183 if (!m_errorMonitor->DesiredMsgFound()) {
3184 FAIL() << "Did not receive Error 'It is invalid to issue this call inside an active render pass...'";
3185 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06003186 }
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06003187}
3188
Mark Lobodzinskid5639502015-09-24 09:51:47 -06003189TEST_F(VkLayerTest, FillBufferWithinRenderPass)
3190{
3191 // Call CmdFillBuffer within an active renderpass
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07003192 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06003193 "It is invalid to issue this call inside an active render pass");
Mark Lobodzinskid5639502015-09-24 09:51:47 -06003194
3195 ASSERT_NO_FATAL_FAILURE(InitState());
3196 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskid5639502015-09-24 09:51:47 -06003197
3198 // Renderpass is started here
3199 BeginCommandBuffer();
3200
3201 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003202 vk_testing::Buffer dstBuffer;
3203 dstBuffer.init_as_dst(*m_device, (VkDeviceSize)1024, reqs);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06003204
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003205 m_commandBuffer->FillBuffer(dstBuffer.handle(), 0, 4, 0x11111111);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06003206
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06003207 if (!m_errorMonitor->DesiredMsgFound()) {
3208 FAIL() << "Did not receive Error 'It is invalid to issue this call inside an active render pass...'";
3209 m_errorMonitor->DumpFailureMsgs();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06003210 }
3211}
3212
3213TEST_F(VkLayerTest, UpdateBufferWithinRenderPass)
3214{
3215 // Call CmdUpdateBuffer within an active renderpass
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07003216 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06003217 "It is invalid to issue this call inside an active render pass");
Mark Lobodzinskid5639502015-09-24 09:51:47 -06003218
3219 ASSERT_NO_FATAL_FAILURE(InitState());
3220 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskid5639502015-09-24 09:51:47 -06003221
3222 // Renderpass is started here
3223 BeginCommandBuffer();
3224
3225 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003226 vk_testing::Buffer dstBuffer;
3227 dstBuffer.init_as_dst(*m_device, (VkDeviceSize)1024, reqs);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06003228
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003229 VkDeviceSize dstOffset = 0;
Mark Lobodzinskid5639502015-09-24 09:51:47 -06003230 VkDeviceSize dataSize = 1024;
3231 const uint32_t *pData = NULL;
3232
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003233 vkCmdUpdateBuffer(m_commandBuffer->GetBufferHandle(), dstBuffer.handle(), dstOffset, dataSize, pData);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06003234
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06003235 if (!m_errorMonitor->DesiredMsgFound()) {
3236 FAIL() << "Did not receive Error 'It is invalid to issue this call inside an active render pass...'";
3237 m_errorMonitor->DumpFailureMsgs();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06003238 }
3239}
3240
3241TEST_F(VkLayerTest, ClearColorImageWithinRenderPass)
3242{
3243 // Call CmdClearColorImage within an active RenderPass
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07003244 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06003245 "It is invalid to issue this call inside an active render pass");
Mark Lobodzinskid5639502015-09-24 09:51:47 -06003246
3247 ASSERT_NO_FATAL_FAILURE(InitState());
3248 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskid5639502015-09-24 09:51:47 -06003249
3250 // Renderpass is started here
3251 BeginCommandBuffer();
3252
3253 VkClearColorValue clear_color = {0};
3254 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
3255 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
3256 const int32_t tex_width = 32;
3257 const int32_t tex_height = 32;
3258 VkImageCreateInfo image_create_info = {};
3259 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
3260 image_create_info.pNext = NULL;
3261 image_create_info.imageType = VK_IMAGE_TYPE_2D;
3262 image_create_info.format = tex_format;
3263 image_create_info.extent.width = tex_width;
3264 image_create_info.extent.height = tex_height;
3265 image_create_info.extent.depth = 1;
3266 image_create_info.mipLevels = 1;
Courtney Goeltzenleuchter5d2aed42015-10-21 17:57:31 -06003267 image_create_info.arrayLayers = 1;
Chia-I Wu5c17c962015-10-31 00:31:16 +08003268 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Mark Lobodzinskid5639502015-09-24 09:51:47 -06003269 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
3270 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
3271
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003272 vk_testing::Image dstImage;
3273 dstImage.init(*m_device, (const VkImageCreateInfo&)image_create_info, reqs);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06003274
3275 const VkImageSubresourceRange range =
3276 vk_testing::Image::subresource_range(image_create_info, VK_IMAGE_ASPECT_COLOR_BIT);
3277
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003278 vkCmdClearColorImage(m_commandBuffer->GetBufferHandle(),
3279 dstImage.handle(),
Mark Lobodzinskid5639502015-09-24 09:51:47 -06003280 VK_IMAGE_LAYOUT_GENERAL,
3281 &clear_color,
3282 1,
3283 &range);
3284
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06003285 if (!m_errorMonitor->DesiredMsgFound()) {
3286 FAIL() << "Did not receive Error 'It is invalid to issue this call inside an active render pass...'";
3287 m_errorMonitor->DumpFailureMsgs();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06003288 }
3289}
3290
3291TEST_F(VkLayerTest, ClearDepthStencilImageWithinRenderPass)
3292{
3293 // Call CmdClearDepthStencilImage within an active RenderPass
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07003294 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06003295 "It is invalid to issue this call inside an active render pass");
Mark Lobodzinskid5639502015-09-24 09:51:47 -06003296
3297 ASSERT_NO_FATAL_FAILURE(InitState());
3298 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskid5639502015-09-24 09:51:47 -06003299
3300 // Renderpass is started here
3301 BeginCommandBuffer();
3302
3303 VkClearDepthStencilValue clear_value = {0};
3304 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
3305 VkImageCreateInfo image_create_info = vk_testing::Image::create_info();
3306 image_create_info.imageType = VK_IMAGE_TYPE_2D;
3307 image_create_info.format = VK_FORMAT_D24_UNORM_S8_UINT;
3308 image_create_info.extent.width = 64;
3309 image_create_info.extent.height = 64;
3310 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
3311 image_create_info.usage = VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT;
3312
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003313 vk_testing::Image dstImage;
3314 dstImage.init(*m_device, (const VkImageCreateInfo&)image_create_info, reqs);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06003315
3316 const VkImageSubresourceRange range =
3317 vk_testing::Image::subresource_range(image_create_info, VK_IMAGE_ASPECT_DEPTH_BIT);
3318
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003319 vkCmdClearDepthStencilImage(m_commandBuffer->GetBufferHandle(),
3320 dstImage.handle(),
Mark Lobodzinskid5639502015-09-24 09:51:47 -06003321 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL,
3322 &clear_value,
3323 1,
3324 &range);
3325
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06003326 if (!m_errorMonitor->DesiredMsgFound()) {
3327 FAIL() << "Did not receive Error 'It is invalid to issue this call inside an active render pass...'";
3328 m_errorMonitor->DumpFailureMsgs();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06003329 }
3330}
3331
3332TEST_F(VkLayerTest, ClearColorAttachmentsOutsideRenderPass)
3333{
Courtney Goeltzenleuchterc9323e02015-10-15 16:51:05 -06003334 // Call CmdClearAttachmentss outside of an active RenderPass
Mark Lobodzinskid5639502015-09-24 09:51:47 -06003335 VkResult err;
3336
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07003337 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06003338 "vkCmdClearAttachments: This call must be issued inside an active render pass");
3339
Mark Lobodzinskid5639502015-09-24 09:51:47 -06003340 ASSERT_NO_FATAL_FAILURE(InitState());
3341 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskid5639502015-09-24 09:51:47 -06003342
3343 // Start no RenderPass
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003344 err = m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06003345 ASSERT_VK_SUCCESS(err);
3346
Courtney Goeltzenleuchterc9323e02015-10-15 16:51:05 -06003347 VkClearAttachment color_attachment;
3348 color_attachment.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
3349 color_attachment.clearValue.color.float32[0] = 0;
3350 color_attachment.clearValue.color.float32[1] = 0;
3351 color_attachment.clearValue.color.float32[2] = 0;
3352 color_attachment.clearValue.color.float32[3] = 0;
3353 color_attachment.colorAttachment = 0;
Courtney Goeltzenleuchter5d2aed42015-10-21 17:57:31 -06003354 VkClearRect clear_rect = { { { 0, 0 }, { 32, 32 } } };
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003355 vkCmdClearAttachments(m_commandBuffer->GetBufferHandle(),
Courtney Goeltzenleuchterc9323e02015-10-15 16:51:05 -06003356 1, &color_attachment,
3357 1, &clear_rect);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06003358
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06003359 if (!m_errorMonitor->DesiredMsgFound()) {
3360 FAIL() << "Did not receive Error 'vkCmdClearAttachments: This call must be issued inside an active render pass.'";
3361 m_errorMonitor->DumpFailureMsgs();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06003362 }
3363}
3364
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06003365TEST_F(VkLayerTest, InvalidDynamicStateObject)
3366{
3367 // Create a valid cmd buffer
3368 // call vkCmdBindDynamicStateObject w/ false DS Obj
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06003369 // TODO : Simple check for bad object should be added to ObjectTracker to catch this case
3370 // The DS check for this is after driver has been called to validate DS internal data struct
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06003371}
Tobin Ehlis1056d452015-05-27 14:55:35 -06003372
Tobin Ehlisc4c23182015-09-17 12:24:13 -06003373TEST_F(VkLayerTest, IdxBufferAlignmentError)
3374{
3375 // Bind a BeginRenderPass within an active RenderPass
Tobin Ehlisc4c23182015-09-17 12:24:13 -06003376 VkResult err;
3377
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07003378 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06003379 "vkCmdBindIndexBuffer() offset (0x7) does not fall on ");
3380
Tobin Ehlisc4c23182015-09-17 12:24:13 -06003381 ASSERT_NO_FATAL_FAILURE(InitState());
3382 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlisc4c23182015-09-17 12:24:13 -06003383 uint32_t qfi = 0;
3384 VkBufferCreateInfo buffCI = {};
3385 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
3386 buffCI.size = 1024;
3387 buffCI.usage = VK_BUFFER_USAGE_INDEX_BUFFER_BIT;
Chia-I Wud50a7d72015-10-26 20:48:51 +08003388 buffCI.queueFamilyIndexCount = 1;
Tobin Ehlisc4c23182015-09-17 12:24:13 -06003389 buffCI.pQueueFamilyIndices = &qfi;
3390
3391 VkBuffer ib;
Chia-I Wuf7458c52015-10-26 21:10:41 +08003392 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &ib);
Tobin Ehlisc4c23182015-09-17 12:24:13 -06003393 ASSERT_VK_SUCCESS(err);
3394
3395 BeginCommandBuffer();
3396 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003397 //vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlisc4c23182015-09-17 12:24:13 -06003398 // Should error before calling to driver so don't care about actual data
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003399 vkCmdBindIndexBuffer(m_commandBuffer->GetBufferHandle(), ib, 7, VK_INDEX_TYPE_UINT16);
Tobin Ehlisc4c23182015-09-17 12:24:13 -06003400
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06003401 if (!m_errorMonitor->DesiredMsgFound()) {
3402 FAIL() << "Did not receive Error 'vkCmdBindIndexBuffer() offset (0x7) does not fall on ...'";
3403 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlisc4c23182015-09-17 12:24:13 -06003404 }
Mike Stroyand1c84a52015-08-18 14:40:24 -06003405
Chia-I Wuf7458c52015-10-26 21:10:41 +08003406 vkDestroyBuffer(m_device->device(), ib, NULL);
Tobin Ehlisc4c23182015-09-17 12:24:13 -06003407}
3408
Tobin Ehlis4b34ddc2015-09-17 14:18:16 -06003409TEST_F(VkLayerTest, ExecuteCommandsPrimaryCB)
3410{
3411 // Attempt vkCmdExecuteCommands w/ a primary cmd buffer (should only be secondary)
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06003412
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07003413 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06003414 "vkCmdExecuteCommands() called w/ Primary Cmd Buffer ");
Tobin Ehlis4b34ddc2015-09-17 14:18:16 -06003415
3416 ASSERT_NO_FATAL_FAILURE(InitState());
3417 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlis4b34ddc2015-09-17 14:18:16 -06003418
3419 BeginCommandBuffer();
3420 //ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003421 VkCommandBuffer primCB = m_commandBuffer->GetBufferHandle();
3422 vkCmdExecuteCommands(m_commandBuffer->GetBufferHandle(), 1, &primCB);
Tobin Ehlis4b34ddc2015-09-17 14:18:16 -06003423
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06003424 if (!m_errorMonitor->DesiredMsgFound()) {
3425 FAIL() << "Did not receive Error 'vkCmdExecuteCommands() called w/ Primary Cmd Buffer '";
3426 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlis4b34ddc2015-09-17 14:18:16 -06003427 }
3428}
3429
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06003430TEST_F(VkLayerTest, DSTypeMismatch)
3431{
3432 // Create DS w/ layout of one type and attempt Update w/ mis-matched type
Tobin Ehlis3b780662015-05-28 12:11:26 -06003433 VkResult err;
3434
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07003435 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06003436 "Write descriptor update has descriptor type VK_DESCRIPTOR_TYPE_SAMPLER that does not match ");
3437
Tobin Ehlis3b780662015-05-28 12:11:26 -06003438 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlis3b780662015-05-28 12:11:26 -06003439 //VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu1b99bb22015-10-27 19:25:11 +08003440 VkDescriptorPoolSize ds_type_count = {};
Tony Barboureb254902015-07-15 12:50:33 -06003441 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wud50a7d72015-10-26 20:48:51 +08003442 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06003443
3444 VkDescriptorPoolCreateInfo ds_pool_ci = {};
3445 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
3446 ds_pool_ci.pNext = NULL;
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -06003447 ds_pool_ci.maxSets = 1;
Chia-I Wu1b99bb22015-10-27 19:25:11 +08003448 ds_pool_ci.poolSizeCount = 1;
3449 ds_pool_ci.pPoolSizes = &ds_type_count;
Tony Barboureb254902015-07-15 12:50:33 -06003450
Tobin Ehlis3b780662015-05-28 12:11:26 -06003451 VkDescriptorPool ds_pool;
Chia-I Wuf7458c52015-10-26 21:10:41 +08003452 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -06003453 ASSERT_VK_SUCCESS(err);
Tony Barboureb254902015-07-15 12:50:33 -06003454 VkDescriptorSetLayoutBinding dsl_binding = {};
Chia-I Wud46e6ae2015-10-31 00:31:16 +08003455 dsl_binding.binding = 0;
Tony Barboureb254902015-07-15 12:50:33 -06003456 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wu02124482015-11-06 06:42:02 +08003457 dsl_binding.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06003458 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
3459 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis3b780662015-05-28 12:11:26 -06003460
Tony Barboureb254902015-07-15 12:50:33 -06003461 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
3462 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
3463 ds_layout_ci.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08003464 ds_layout_ci.bindingCount = 1;
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07003465 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -06003466
Tobin Ehlis3b780662015-05-28 12:11:26 -06003467 VkDescriptorSetLayout ds_layout;
Chia-I Wuf7458c52015-10-26 21:10:41 +08003468 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -06003469 ASSERT_VK_SUCCESS(err);
3470
3471 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003472 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08003473 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Chia-I Wud50a7d72015-10-26 20:48:51 +08003474 alloc_info.setLayoutCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06003475 alloc_info.descriptorPool = ds_pool;
3476 alloc_info.pSetLayouts = &ds_layout;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003477 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -06003478 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -06003479
Tony Barboureb254902015-07-15 12:50:33 -06003480 VkSamplerCreateInfo sampler_ci = {};
3481 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
3482 sampler_ci.pNext = NULL;
Chia-I Wub99df442015-10-26 16:49:32 +08003483 sampler_ci.magFilter = VK_FILTER_NEAREST;
3484 sampler_ci.minFilter = VK_FILTER_NEAREST;
3485 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_BASE;
Chia-I Wu1efb7e52015-10-26 17:32:47 +08003486 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
3487 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
3488 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
Tony Barboureb254902015-07-15 12:50:33 -06003489 sampler_ci.mipLodBias = 1.0;
Jon Ashburnddc8db52015-12-14 14:59:20 -07003490 sampler_ci.anisotropyEnable = VK_FALSE;
Tony Barboureb254902015-07-15 12:50:33 -06003491 sampler_ci.maxAnisotropy = 1;
3492 sampler_ci.compareEnable = VK_FALSE;
3493 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
3494 sampler_ci.minLod = 1.0;
3495 sampler_ci.maxLod = 1.0;
3496 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
Mark Lobodzinski52ac6582015-09-01 15:42:56 -06003497 sampler_ci.unnormalizedCoordinates = VK_FALSE;
3498
Tobin Ehlis3b780662015-05-28 12:11:26 -06003499 VkSampler sampler;
Chia-I Wuf7458c52015-10-26 21:10:41 +08003500 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
Tobin Ehlis3b780662015-05-28 12:11:26 -06003501 ASSERT_VK_SUCCESS(err);
3502
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -06003503 VkDescriptorImageInfo info = {};
3504 info.sampler = sampler;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08003505
3506 VkWriteDescriptorSet descriptor_write;
3507 memset(&descriptor_write, 0, sizeof(descriptor_write));
3508 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003509 descriptor_write.dstSet = descriptorSet;
Chia-I Wud50a7d72015-10-26 20:48:51 +08003510 descriptor_write.descriptorCount = 1;
Tobin Ehlis3b780662015-05-28 12:11:26 -06003511 // This is a mismatched type for the layout which expects BUFFER
Chia-I Wu9d00ed72015-05-25 16:27:55 +08003512 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -06003513 descriptor_write.pImageInfo = &info;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08003514
3515 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
3516
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06003517 if (!m_errorMonitor->DesiredMsgFound()) {
3518 FAIL() << "Did not receive Error 'Write descriptor update has descriptor type VK_DESCRIPTOR_TYPE_SAMPLER that does not match...'";
3519 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlis3b780662015-05-28 12:11:26 -06003520 }
Mike Stroyand1c84a52015-08-18 14:40:24 -06003521
Chia-I Wuf7458c52015-10-26 21:10:41 +08003522 vkDestroySampler(m_device->device(), sampler, NULL);
3523 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
3524 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06003525}
3526
3527TEST_F(VkLayerTest, DSUpdateOutOfBounds)
3528{
3529 // For overlapping Update, have arrayIndex exceed that of layout
Tobin Ehlis3b780662015-05-28 12:11:26 -06003530 VkResult err;
3531
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07003532 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06003533 "Descriptor update type of VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET is out of bounds for matching binding");
3534
Tobin Ehlis3b780662015-05-28 12:11:26 -06003535 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlis3b780662015-05-28 12:11:26 -06003536 //VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu1b99bb22015-10-27 19:25:11 +08003537 VkDescriptorPoolSize ds_type_count = {};
Tony Barboureb254902015-07-15 12:50:33 -06003538 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wud50a7d72015-10-26 20:48:51 +08003539 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06003540
3541 VkDescriptorPoolCreateInfo ds_pool_ci = {};
3542 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
3543 ds_pool_ci.pNext = NULL;
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -06003544 ds_pool_ci.maxSets = 1;
Chia-I Wu1b99bb22015-10-27 19:25:11 +08003545 ds_pool_ci.poolSizeCount = 1;
3546 ds_pool_ci.pPoolSizes = &ds_type_count;
Tony Barboureb254902015-07-15 12:50:33 -06003547
Tobin Ehlis3b780662015-05-28 12:11:26 -06003548 VkDescriptorPool ds_pool;
Chia-I Wuf7458c52015-10-26 21:10:41 +08003549 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -06003550 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -06003551
Tony Barboureb254902015-07-15 12:50:33 -06003552 VkDescriptorSetLayoutBinding dsl_binding = {};
Chia-I Wud46e6ae2015-10-31 00:31:16 +08003553 dsl_binding.binding = 0;
Tony Barboureb254902015-07-15 12:50:33 -06003554 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wu02124482015-11-06 06:42:02 +08003555 dsl_binding.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06003556 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
3557 dsl_binding.pImmutableSamplers = NULL;
3558
3559 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
3560 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
3561 ds_layout_ci.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08003562 ds_layout_ci.bindingCount = 1;
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07003563 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -06003564
Tobin Ehlis3b780662015-05-28 12:11:26 -06003565 VkDescriptorSetLayout ds_layout;
Chia-I Wuf7458c52015-10-26 21:10:41 +08003566 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -06003567 ASSERT_VK_SUCCESS(err);
3568
3569 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003570 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08003571 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Chia-I Wud50a7d72015-10-26 20:48:51 +08003572 alloc_info.setLayoutCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06003573 alloc_info.descriptorPool = ds_pool;
3574 alloc_info.pSetLayouts = &ds_layout;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003575 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -06003576 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -06003577
Tony Barboureb254902015-07-15 12:50:33 -06003578 VkSamplerCreateInfo sampler_ci = {};
3579 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
3580 sampler_ci.pNext = NULL;
Chia-I Wub99df442015-10-26 16:49:32 +08003581 sampler_ci.magFilter = VK_FILTER_NEAREST;
3582 sampler_ci.minFilter = VK_FILTER_NEAREST;
3583 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_BASE;
Chia-I Wu1efb7e52015-10-26 17:32:47 +08003584 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
3585 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
3586 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
Tony Barboureb254902015-07-15 12:50:33 -06003587 sampler_ci.mipLodBias = 1.0;
Jon Ashburnddc8db52015-12-14 14:59:20 -07003588 sampler_ci.anisotropyEnable = VK_FALSE;
Tony Barboureb254902015-07-15 12:50:33 -06003589 sampler_ci.maxAnisotropy = 1;
3590 sampler_ci.compareEnable = VK_FALSE;
3591 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
3592 sampler_ci.minLod = 1.0;
3593 sampler_ci.maxLod = 1.0;
3594 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
Mark Lobodzinski52ac6582015-09-01 15:42:56 -06003595 sampler_ci.unnormalizedCoordinates = VK_FALSE;
Tony Barboureb254902015-07-15 12:50:33 -06003596
Tobin Ehlis3b780662015-05-28 12:11:26 -06003597 VkSampler sampler;
Chia-I Wuf7458c52015-10-26 21:10:41 +08003598 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
Tobin Ehlis3b780662015-05-28 12:11:26 -06003599 ASSERT_VK_SUCCESS(err);
Chia-I Wu9d00ed72015-05-25 16:27:55 +08003600
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -06003601 VkDescriptorImageInfo info = {};
3602 info.sampler = sampler;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08003603
3604 VkWriteDescriptorSet descriptor_write;
3605 memset(&descriptor_write, 0, sizeof(descriptor_write));
3606 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003607 descriptor_write.dstSet = descriptorSet;
3608 descriptor_write.dstArrayElement = 1; /* This index out of bounds for the update */
Chia-I Wud50a7d72015-10-26 20:48:51 +08003609 descriptor_write.descriptorCount = 1;
Tobin Ehlis3b780662015-05-28 12:11:26 -06003610 // This is the wrong type, but out of bounds will be flagged first
Chia-I Wu9d00ed72015-05-25 16:27:55 +08003611 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -06003612 descriptor_write.pImageInfo = &info;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08003613
3614 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
3615
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06003616 if (!m_errorMonitor->DesiredMsgFound()) {
3617 FAIL() << "Did not receive Error 'Descriptor update type of VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET is out of bounds for matching binding...'";
3618 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlis3b780662015-05-28 12:11:26 -06003619 }
Mike Stroyand1c84a52015-08-18 14:40:24 -06003620
Chia-I Wuf7458c52015-10-26 21:10:41 +08003621 vkDestroySampler(m_device->device(), sampler, NULL);
3622 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
3623 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06003624}
3625
3626TEST_F(VkLayerTest, InvalidDSUpdateIndex)
3627{
Tobin Ehlis3b780662015-05-28 12:11:26 -06003628 // Create layout w/ count of 1 and attempt update to that layout w/ binding index 2
Tobin Ehlis3b780662015-05-28 12:11:26 -06003629 VkResult err;
3630
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07003631 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06003632 " does not have binding to match update binding ");
3633
Tobin Ehlis3b780662015-05-28 12:11:26 -06003634 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlis3b780662015-05-28 12:11:26 -06003635 //VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu1b99bb22015-10-27 19:25:11 +08003636 VkDescriptorPoolSize ds_type_count = {};
Tony Barboureb254902015-07-15 12:50:33 -06003637 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wud50a7d72015-10-26 20:48:51 +08003638 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06003639
3640 VkDescriptorPoolCreateInfo ds_pool_ci = {};
3641 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
3642 ds_pool_ci.pNext = NULL;
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -06003643 ds_pool_ci.maxSets = 1;
Chia-I Wu1b99bb22015-10-27 19:25:11 +08003644 ds_pool_ci.poolSizeCount = 1;
3645 ds_pool_ci.pPoolSizes = &ds_type_count;
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -06003646
Tobin Ehlis3b780662015-05-28 12:11:26 -06003647 VkDescriptorPool ds_pool;
Chia-I Wuf7458c52015-10-26 21:10:41 +08003648 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -06003649 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -06003650
Tony Barboureb254902015-07-15 12:50:33 -06003651 VkDescriptorSetLayoutBinding dsl_binding = {};
Chia-I Wud46e6ae2015-10-31 00:31:16 +08003652 dsl_binding.binding = 0;
Tony Barboureb254902015-07-15 12:50:33 -06003653 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wu02124482015-11-06 06:42:02 +08003654 dsl_binding.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06003655 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
3656 dsl_binding.pImmutableSamplers = NULL;
3657
3658 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
3659 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
3660 ds_layout_ci.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08003661 ds_layout_ci.bindingCount = 1;
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07003662 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlis3b780662015-05-28 12:11:26 -06003663 VkDescriptorSetLayout ds_layout;
Chia-I Wuf7458c52015-10-26 21:10:41 +08003664 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -06003665 ASSERT_VK_SUCCESS(err);
3666
3667 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003668 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08003669 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Chia-I Wud50a7d72015-10-26 20:48:51 +08003670 alloc_info.setLayoutCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06003671 alloc_info.descriptorPool = ds_pool;
3672 alloc_info.pSetLayouts = &ds_layout;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003673 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -06003674 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -06003675
Tony Barboureb254902015-07-15 12:50:33 -06003676 VkSamplerCreateInfo sampler_ci = {};
3677 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
3678 sampler_ci.pNext = NULL;
Chia-I Wub99df442015-10-26 16:49:32 +08003679 sampler_ci.magFilter = VK_FILTER_NEAREST;
3680 sampler_ci.minFilter = VK_FILTER_NEAREST;
3681 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_BASE;
Chia-I Wu1efb7e52015-10-26 17:32:47 +08003682 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
3683 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
3684 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
Tony Barboureb254902015-07-15 12:50:33 -06003685 sampler_ci.mipLodBias = 1.0;
Jon Ashburnddc8db52015-12-14 14:59:20 -07003686 sampler_ci.anisotropyEnable = VK_FALSE;
Tony Barboureb254902015-07-15 12:50:33 -06003687 sampler_ci.maxAnisotropy = 1;
3688 sampler_ci.compareEnable = VK_FALSE;
3689 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
3690 sampler_ci.minLod = 1.0;
3691 sampler_ci.maxLod = 1.0;
3692 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
Mark Lobodzinski52ac6582015-09-01 15:42:56 -06003693 sampler_ci.unnormalizedCoordinates = VK_FALSE;
Tony Barboureb254902015-07-15 12:50:33 -06003694
Tobin Ehlis3b780662015-05-28 12:11:26 -06003695 VkSampler sampler;
Chia-I Wuf7458c52015-10-26 21:10:41 +08003696 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
Tobin Ehlis3b780662015-05-28 12:11:26 -06003697 ASSERT_VK_SUCCESS(err);
Chia-I Wu9d00ed72015-05-25 16:27:55 +08003698
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -06003699 VkDescriptorImageInfo info = {};
3700 info.sampler = sampler;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08003701
3702 VkWriteDescriptorSet descriptor_write;
3703 memset(&descriptor_write, 0, sizeof(descriptor_write));
3704 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003705 descriptor_write.dstSet = descriptorSet;
3706 descriptor_write.dstBinding = 2;
Chia-I Wud50a7d72015-10-26 20:48:51 +08003707 descriptor_write.descriptorCount = 1;
Tobin Ehlis3b780662015-05-28 12:11:26 -06003708 // This is the wrong type, but out of bounds will be flagged first
Chia-I Wu9d00ed72015-05-25 16:27:55 +08003709 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -06003710 descriptor_write.pImageInfo = &info;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08003711
3712 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
3713
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06003714 if (!m_errorMonitor->DesiredMsgFound()) {
3715 FAIL() << "Did not receive Error 'Descriptor Set <blah> does not have binding to match update binding '";
3716 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlis3b780662015-05-28 12:11:26 -06003717 }
Mike Stroyand1c84a52015-08-18 14:40:24 -06003718
Chia-I Wuf7458c52015-10-26 21:10:41 +08003719 vkDestroySampler(m_device->device(), sampler, NULL);
3720 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
3721 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06003722}
3723
3724TEST_F(VkLayerTest, InvalidDSUpdateStruct)
3725{
3726 // Call UpdateDS w/ struct type other than valid VK_STRUCTUR_TYPE_UPDATE_* types
Tobin Ehlis3b780662015-05-28 12:11:26 -06003727 VkResult err;
3728
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07003729 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06003730 "Unexpected UPDATE struct of type ");
3731
Tobin Ehlis3b780662015-05-28 12:11:26 -06003732 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski209b5292015-09-17 09:44:05 -06003733
Chia-I Wu1b99bb22015-10-27 19:25:11 +08003734 VkDescriptorPoolSize ds_type_count = {};
Tony Barboureb254902015-07-15 12:50:33 -06003735 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wud50a7d72015-10-26 20:48:51 +08003736 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06003737
3738 VkDescriptorPoolCreateInfo ds_pool_ci = {};
3739 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
3740 ds_pool_ci.pNext = NULL;
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -06003741 ds_pool_ci.maxSets = 1;
Chia-I Wu1b99bb22015-10-27 19:25:11 +08003742 ds_pool_ci.poolSizeCount = 1;
3743 ds_pool_ci.pPoolSizes = &ds_type_count;
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -06003744
Tobin Ehlis3b780662015-05-28 12:11:26 -06003745 VkDescriptorPool ds_pool;
Chia-I Wuf7458c52015-10-26 21:10:41 +08003746 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -06003747 ASSERT_VK_SUCCESS(err);
Tony Barboureb254902015-07-15 12:50:33 -06003748 VkDescriptorSetLayoutBinding dsl_binding = {};
Chia-I Wud46e6ae2015-10-31 00:31:16 +08003749 dsl_binding.binding = 0;
Tony Barboureb254902015-07-15 12:50:33 -06003750 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wu02124482015-11-06 06:42:02 +08003751 dsl_binding.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06003752 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
3753 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis3b780662015-05-28 12:11:26 -06003754
Tony Barboureb254902015-07-15 12:50:33 -06003755 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
3756 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
3757 ds_layout_ci.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08003758 ds_layout_ci.bindingCount = 1;
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07003759 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -06003760
Tobin Ehlis3b780662015-05-28 12:11:26 -06003761 VkDescriptorSetLayout ds_layout;
Chia-I Wuf7458c52015-10-26 21:10:41 +08003762 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -06003763 ASSERT_VK_SUCCESS(err);
3764
3765 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003766 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08003767 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Chia-I Wud50a7d72015-10-26 20:48:51 +08003768 alloc_info.setLayoutCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06003769 alloc_info.descriptorPool = ds_pool;
3770 alloc_info.pSetLayouts = &ds_layout;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003771 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -06003772 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -06003773
Tony Barboureb254902015-07-15 12:50:33 -06003774 VkSamplerCreateInfo sampler_ci = {};
3775 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
3776 sampler_ci.pNext = NULL;
Chia-I Wub99df442015-10-26 16:49:32 +08003777 sampler_ci.magFilter = VK_FILTER_NEAREST;
3778 sampler_ci.minFilter = VK_FILTER_NEAREST;
3779 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_BASE;
Chia-I Wu1efb7e52015-10-26 17:32:47 +08003780 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
3781 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
3782 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
Tony Barboureb254902015-07-15 12:50:33 -06003783 sampler_ci.mipLodBias = 1.0;
Jon Ashburnddc8db52015-12-14 14:59:20 -07003784 sampler_ci.anisotropyEnable = VK_FALSE;
Tony Barboureb254902015-07-15 12:50:33 -06003785 sampler_ci.maxAnisotropy = 1;
3786 sampler_ci.compareEnable = VK_FALSE;
3787 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
3788 sampler_ci.minLod = 1.0;
3789 sampler_ci.maxLod = 1.0;
3790 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
Mark Lobodzinski52ac6582015-09-01 15:42:56 -06003791 sampler_ci.unnormalizedCoordinates = VK_FALSE;
Tobin Ehlis3b780662015-05-28 12:11:26 -06003792 VkSampler sampler;
Chia-I Wuf7458c52015-10-26 21:10:41 +08003793 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
Tobin Ehlis3b780662015-05-28 12:11:26 -06003794 ASSERT_VK_SUCCESS(err);
Chia-I Wu9d00ed72015-05-25 16:27:55 +08003795
3796
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -06003797 VkDescriptorImageInfo info = {};
3798 info.sampler = sampler;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08003799
3800 VkWriteDescriptorSet descriptor_write;
3801 memset(&descriptor_write, 0, sizeof(descriptor_write));
3802 descriptor_write.sType = (VkStructureType)0x99999999; /* Intentionally broken struct type */
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003803 descriptor_write.dstSet = descriptorSet;
Chia-I Wud50a7d72015-10-26 20:48:51 +08003804 descriptor_write.descriptorCount = 1;
Tobin Ehlis3b780662015-05-28 12:11:26 -06003805 // This is the wrong type, but out of bounds will be flagged first
Chia-I Wu9d00ed72015-05-25 16:27:55 +08003806 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -06003807 descriptor_write.pImageInfo = &info;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08003808
3809 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
3810
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06003811 if (!m_errorMonitor->DesiredMsgFound()) {
3812 FAIL() << "Did not receive Error 'Unexpected UPDATE struct of type '";
3813 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlis3b780662015-05-28 12:11:26 -06003814 }
Mike Stroyand1c84a52015-08-18 14:40:24 -06003815
Chia-I Wuf7458c52015-10-26 21:10:41 +08003816 vkDestroySampler(m_device->device(), sampler, NULL);
3817 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
3818 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06003819}
3820
Tobin Ehlisa1c28562015-10-23 16:00:08 -06003821TEST_F(VkLayerTest, SampleDescriptorUpdateError)
3822{
3823 // Create a single Sampler descriptor and send it an invalid Sampler
Tobin Ehlisa1c28562015-10-23 16:00:08 -06003824 VkResult err;
3825
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07003826 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06003827 "Attempt to update descriptor with invalid sampler 0xbaadbeef");
3828
Tobin Ehlisa1c28562015-10-23 16:00:08 -06003829 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisa1c28562015-10-23 16:00:08 -06003830 // TODO : Farm Descriptor setup code to helper function(s) to reduce copied code
Chia-I Wu1b99bb22015-10-27 19:25:11 +08003831 VkDescriptorPoolSize ds_type_count = {};
Tobin Ehlisa1c28562015-10-23 16:00:08 -06003832 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLER;
Chia-I Wud50a7d72015-10-26 20:48:51 +08003833 ds_type_count.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06003834
3835 VkDescriptorPoolCreateInfo ds_pool_ci = {};
3836 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
3837 ds_pool_ci.pNext = NULL;
3838 ds_pool_ci.maxSets = 1;
Chia-I Wu1b99bb22015-10-27 19:25:11 +08003839 ds_pool_ci.poolSizeCount = 1;
3840 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06003841
3842 VkDescriptorPool ds_pool;
Chia-I Wuf7458c52015-10-26 21:10:41 +08003843 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06003844 ASSERT_VK_SUCCESS(err);
3845
3846 VkDescriptorSetLayoutBinding dsl_binding = {};
Chia-I Wud46e6ae2015-10-31 00:31:16 +08003847 dsl_binding.binding = 0;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06003848 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Chia-I Wu02124482015-11-06 06:42:02 +08003849 dsl_binding.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06003850 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
3851 dsl_binding.pImmutableSamplers = NULL;
3852
3853 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
3854 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
3855 ds_layout_ci.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08003856 ds_layout_ci.bindingCount = 1;
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07003857 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06003858 VkDescriptorSetLayout ds_layout;
Chia-I Wuf7458c52015-10-26 21:10:41 +08003859 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06003860 ASSERT_VK_SUCCESS(err);
3861
3862 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003863 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08003864 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Chia-I Wud50a7d72015-10-26 20:48:51 +08003865 alloc_info.setLayoutCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06003866 alloc_info.descriptorPool = ds_pool;
3867 alloc_info.pSetLayouts = &ds_layout;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003868 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06003869 ASSERT_VK_SUCCESS(err);
3870
Mark Youngad779052016-01-06 14:26:04 -07003871 VkSampler sampler = (VkSampler)((size_t)0xbaadbeef); // Sampler with invalid handle
Tobin Ehlisa1c28562015-10-23 16:00:08 -06003872
3873 VkDescriptorImageInfo descriptor_info;
3874 memset(&descriptor_info, 0, sizeof(VkDescriptorImageInfo));
3875 descriptor_info.sampler = sampler;
3876
3877 VkWriteDescriptorSet descriptor_write;
3878 memset(&descriptor_write, 0, sizeof(descriptor_write));
3879 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003880 descriptor_write.dstSet = descriptorSet;
3881 descriptor_write.dstBinding = 0;
Chia-I Wud50a7d72015-10-26 20:48:51 +08003882 descriptor_write.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06003883 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
3884 descriptor_write.pImageInfo = &descriptor_info;
3885
3886 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
3887
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06003888 if (!m_errorMonitor->DesiredMsgFound()) {
3889 FAIL() << "Did not receive Error 'Attempt to update descriptor with invalid sampler...'";
3890 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlisa1c28562015-10-23 16:00:08 -06003891 }
3892
Chia-I Wuf7458c52015-10-26 21:10:41 +08003893 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
3894 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06003895}
3896
3897TEST_F(VkLayerTest, ImageViewDescriptorUpdateError)
3898{
3899 // Create a single combined Image/Sampler descriptor and send it an invalid imageView
Tobin Ehlisa1c28562015-10-23 16:00:08 -06003900 VkResult err;
3901
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07003902 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06003903 "Attempt to update descriptor with invalid imageView 0xbaadbeef");
3904
Tobin Ehlisa1c28562015-10-23 16:00:08 -06003905 ASSERT_NO_FATAL_FAILURE(InitState());
Chia-I Wu1b99bb22015-10-27 19:25:11 +08003906 VkDescriptorPoolSize ds_type_count = {};
Tobin Ehlisa1c28562015-10-23 16:00:08 -06003907 ds_type_count.type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
Chia-I Wud50a7d72015-10-26 20:48:51 +08003908 ds_type_count.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06003909
3910 VkDescriptorPoolCreateInfo ds_pool_ci = {};
3911 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
3912 ds_pool_ci.pNext = NULL;
3913 ds_pool_ci.maxSets = 1;
Chia-I Wu1b99bb22015-10-27 19:25:11 +08003914 ds_pool_ci.poolSizeCount = 1;
3915 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06003916
3917 VkDescriptorPool ds_pool;
Chia-I Wuf7458c52015-10-26 21:10:41 +08003918 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06003919 ASSERT_VK_SUCCESS(err);
3920
3921 VkDescriptorSetLayoutBinding dsl_binding = {};
Chia-I Wud46e6ae2015-10-31 00:31:16 +08003922 dsl_binding.binding = 0;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06003923 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
Chia-I Wu02124482015-11-06 06:42:02 +08003924 dsl_binding.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06003925 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
3926 dsl_binding.pImmutableSamplers = NULL;
3927
3928 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
3929 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
3930 ds_layout_ci.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08003931 ds_layout_ci.bindingCount = 1;
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07003932 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06003933 VkDescriptorSetLayout ds_layout;
Chia-I Wuf7458c52015-10-26 21:10:41 +08003934 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06003935 ASSERT_VK_SUCCESS(err);
3936
3937 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003938 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08003939 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Chia-I Wud50a7d72015-10-26 20:48:51 +08003940 alloc_info.setLayoutCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06003941 alloc_info.descriptorPool = ds_pool;
3942 alloc_info.pSetLayouts = &ds_layout;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003943 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06003944 ASSERT_VK_SUCCESS(err);
3945
3946 VkSamplerCreateInfo sampler_ci = {};
3947 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
3948 sampler_ci.pNext = NULL;
Chia-I Wub99df442015-10-26 16:49:32 +08003949 sampler_ci.magFilter = VK_FILTER_NEAREST;
3950 sampler_ci.minFilter = VK_FILTER_NEAREST;
3951 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_BASE;
Chia-I Wu1efb7e52015-10-26 17:32:47 +08003952 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
3953 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
3954 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06003955 sampler_ci.mipLodBias = 1.0;
Jon Ashburnddc8db52015-12-14 14:59:20 -07003956 sampler_ci.anisotropyEnable = VK_FALSE;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06003957 sampler_ci.maxAnisotropy = 1;
3958 sampler_ci.compareEnable = VK_FALSE;
3959 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
3960 sampler_ci.minLod = 1.0;
3961 sampler_ci.maxLod = 1.0;
3962 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
3963 sampler_ci.unnormalizedCoordinates = VK_FALSE;
3964
3965 VkSampler sampler;
Chia-I Wuf7458c52015-10-26 21:10:41 +08003966 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06003967 ASSERT_VK_SUCCESS(err);
3968
Mark Youngad779052016-01-06 14:26:04 -07003969 VkImageView view = (VkImageView)((size_t)0xbaadbeef); // invalid imageView object
Tobin Ehlisa1c28562015-10-23 16:00:08 -06003970
3971 VkDescriptorImageInfo descriptor_info;
3972 memset(&descriptor_info, 0, sizeof(VkDescriptorImageInfo));
3973 descriptor_info.sampler = sampler;
3974 descriptor_info.imageView = view;
3975
3976 VkWriteDescriptorSet descriptor_write;
3977 memset(&descriptor_write, 0, sizeof(descriptor_write));
3978 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003979 descriptor_write.dstSet = descriptorSet;
3980 descriptor_write.dstBinding = 0;
Chia-I Wud50a7d72015-10-26 20:48:51 +08003981 descriptor_write.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06003982 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
3983 descriptor_write.pImageInfo = &descriptor_info;
3984
3985 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
3986
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06003987 if (!m_errorMonitor->DesiredMsgFound()) {
3988 FAIL() << "Did not receive Error 'Attempt to update descriptor with invalid imageView...'";
3989 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlisa1c28562015-10-23 16:00:08 -06003990 }
3991
Chia-I Wuf7458c52015-10-26 21:10:41 +08003992 vkDestroySampler(m_device->device(), sampler, NULL);
3993 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
3994 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06003995}
3996
Tobin Ehlis04356f92015-10-27 16:35:27 -06003997TEST_F(VkLayerTest, CopyDescriptorUpdateErrors)
3998{
3999 // 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 -06004000 VkResult err;
4001
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07004002 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06004003 "Copy descriptor update index 0, update count #1, has src update descriptor type VK_DESCRIPTOR_TYPE_SAMPLER ");
4004
Tobin Ehlis04356f92015-10-27 16:35:27 -06004005 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlis04356f92015-10-27 16:35:27 -06004006 //VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu1b99bb22015-10-27 19:25:11 +08004007 VkDescriptorPoolSize ds_type_count[2] = {};
Tobin Ehlis04356f92015-10-27 16:35:27 -06004008 ds_type_count[0].type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wud50a7d72015-10-26 20:48:51 +08004009 ds_type_count[0].descriptorCount = 1;
Tobin Ehlis04356f92015-10-27 16:35:27 -06004010 ds_type_count[1].type = VK_DESCRIPTOR_TYPE_SAMPLER;
Chia-I Wud50a7d72015-10-26 20:48:51 +08004011 ds_type_count[1].descriptorCount = 1;
Tobin Ehlis04356f92015-10-27 16:35:27 -06004012
4013 VkDescriptorPoolCreateInfo ds_pool_ci = {};
4014 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
4015 ds_pool_ci.pNext = NULL;
4016 ds_pool_ci.maxSets = 1;
Chia-I Wu1b99bb22015-10-27 19:25:11 +08004017 ds_pool_ci.poolSizeCount = 2;
4018 ds_pool_ci.pPoolSizes = ds_type_count;
Tobin Ehlis04356f92015-10-27 16:35:27 -06004019
4020 VkDescriptorPool ds_pool;
Chia-I Wuf7458c52015-10-26 21:10:41 +08004021 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis04356f92015-10-27 16:35:27 -06004022 ASSERT_VK_SUCCESS(err);
4023 VkDescriptorSetLayoutBinding dsl_binding[2] = {};
Chia-I Wud46e6ae2015-10-31 00:31:16 +08004024 dsl_binding[0].binding = 0;
Tobin Ehlis04356f92015-10-27 16:35:27 -06004025 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wu02124482015-11-06 06:42:02 +08004026 dsl_binding[0].descriptorCount = 1;
Tobin Ehlis04356f92015-10-27 16:35:27 -06004027 dsl_binding[0].stageFlags = VK_SHADER_STAGE_ALL;
4028 dsl_binding[0].pImmutableSamplers = NULL;
Chia-I Wud46e6ae2015-10-31 00:31:16 +08004029 dsl_binding[1].binding = 1;
Tobin Ehlis04356f92015-10-27 16:35:27 -06004030 dsl_binding[1].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Chia-I Wu02124482015-11-06 06:42:02 +08004031 dsl_binding[1].descriptorCount = 1;
Tobin Ehlis04356f92015-10-27 16:35:27 -06004032 dsl_binding[1].stageFlags = VK_SHADER_STAGE_ALL;
4033 dsl_binding[1].pImmutableSamplers = NULL;
4034
4035 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
4036 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
4037 ds_layout_ci.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08004038 ds_layout_ci.bindingCount = 2;
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07004039 ds_layout_ci.pBindings = dsl_binding;
Tobin Ehlis04356f92015-10-27 16:35:27 -06004040
4041 VkDescriptorSetLayout ds_layout;
Chia-I Wuf7458c52015-10-26 21:10:41 +08004042 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis04356f92015-10-27 16:35:27 -06004043 ASSERT_VK_SUCCESS(err);
4044
4045 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004046 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08004047 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Chia-I Wud50a7d72015-10-26 20:48:51 +08004048 alloc_info.setLayoutCount = 1;
Tobin Ehlis04356f92015-10-27 16:35:27 -06004049 alloc_info.descriptorPool = ds_pool;
4050 alloc_info.pSetLayouts = &ds_layout;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004051 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis04356f92015-10-27 16:35:27 -06004052 ASSERT_VK_SUCCESS(err);
4053
4054 VkSamplerCreateInfo sampler_ci = {};
4055 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
4056 sampler_ci.pNext = NULL;
Chia-I Wub99df442015-10-26 16:49:32 +08004057 sampler_ci.magFilter = VK_FILTER_NEAREST;
4058 sampler_ci.minFilter = VK_FILTER_NEAREST;
4059 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_BASE;
Chia-I Wu1efb7e52015-10-26 17:32:47 +08004060 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
4061 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
4062 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
Tobin Ehlis04356f92015-10-27 16:35:27 -06004063 sampler_ci.mipLodBias = 1.0;
Jon Ashburnddc8db52015-12-14 14:59:20 -07004064 sampler_ci.anisotropyEnable = VK_FALSE;
Tobin Ehlis04356f92015-10-27 16:35:27 -06004065 sampler_ci.maxAnisotropy = 1;
4066 sampler_ci.compareEnable = VK_FALSE;
4067 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
4068 sampler_ci.minLod = 1.0;
4069 sampler_ci.maxLod = 1.0;
4070 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
4071 sampler_ci.unnormalizedCoordinates = VK_FALSE;
4072
4073 VkSampler sampler;
Chia-I Wuf7458c52015-10-26 21:10:41 +08004074 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
Tobin Ehlis04356f92015-10-27 16:35:27 -06004075 ASSERT_VK_SUCCESS(err);
4076
4077 VkDescriptorImageInfo info = {};
4078 info.sampler = sampler;
4079
4080 VkWriteDescriptorSet descriptor_write;
4081 memset(&descriptor_write, 0, sizeof(VkWriteDescriptorSet));
4082 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004083 descriptor_write.dstSet = descriptorSet;
4084 descriptor_write.dstBinding = 1; // SAMPLER binding from layout above
Chia-I Wud50a7d72015-10-26 20:48:51 +08004085 descriptor_write.descriptorCount = 1;
Tobin Ehlis04356f92015-10-27 16:35:27 -06004086 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
4087 descriptor_write.pImageInfo = &info;
4088 // This write update should succeed
4089 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
4090 // Now perform a copy update that fails due to type mismatch
4091 VkCopyDescriptorSet copy_ds_update;
4092 memset(&copy_ds_update, 0, sizeof(VkCopyDescriptorSet));
4093 copy_ds_update.sType = VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET;
4094 copy_ds_update.srcSet = descriptorSet;
4095 copy_ds_update.srcBinding = 1; // copy from SAMPLER binding
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004096 copy_ds_update.dstSet = descriptorSet;
4097 copy_ds_update.dstBinding = 0; // ERROR : copy to UNIFORM binding
Chia-I Wud50a7d72015-10-26 20:48:51 +08004098 copy_ds_update.descriptorCount = 1; // copy 1 descriptor
Tobin Ehlis04356f92015-10-27 16:35:27 -06004099 vkUpdateDescriptorSets(m_device->device(), 0, NULL, 1, &copy_ds_update);
4100
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06004101 if (!m_errorMonitor->DesiredMsgFound()) {
4102 FAIL() << "Did not receive Error 'Copy descriptor update index 0, update count #1, has src update descriptor type_DESCRIPTOR_TYPE_SAMPLER'";
4103 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlis04356f92015-10-27 16:35:27 -06004104 }
4105 // Now perform a copy update that fails due to binding out of bounds
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07004106 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06004107 "Copy descriptor update 0 has srcBinding 3 which is out of bounds ");
Tobin Ehlis04356f92015-10-27 16:35:27 -06004108 memset(&copy_ds_update, 0, sizeof(VkCopyDescriptorSet));
4109 copy_ds_update.sType = VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET;
4110 copy_ds_update.srcSet = descriptorSet;
4111 copy_ds_update.srcBinding = 3; // ERROR : Invalid binding for matching layout
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004112 copy_ds_update.dstSet = descriptorSet;
4113 copy_ds_update.dstBinding = 0;
Chia-I Wud50a7d72015-10-26 20:48:51 +08004114 copy_ds_update.descriptorCount = 1; // copy 1 descriptor
Tobin Ehlis04356f92015-10-27 16:35:27 -06004115 vkUpdateDescriptorSets(m_device->device(), 0, NULL, 1, &copy_ds_update);
4116
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06004117 if (!m_errorMonitor->DesiredMsgFound()) {
4118 FAIL() << "Did not receive Error 'Copy descriptor update 0 has srcBinding 3 which is out of bounds...'";
4119 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlis04356f92015-10-27 16:35:27 -06004120 }
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06004121
Tobin Ehlis04356f92015-10-27 16:35:27 -06004122 // Now perform a copy update that fails due to binding out of bounds
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07004123 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06004124 "Copy descriptor src update is out of bounds for matching binding 1 ");
4125
Tobin Ehlis04356f92015-10-27 16:35:27 -06004126 memset(&copy_ds_update, 0, sizeof(VkCopyDescriptorSet));
4127 copy_ds_update.sType = VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET;
4128 copy_ds_update.srcSet = descriptorSet;
4129 copy_ds_update.srcBinding = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004130 copy_ds_update.dstSet = descriptorSet;
4131 copy_ds_update.dstBinding = 0;
Chia-I Wud50a7d72015-10-26 20:48:51 +08004132 copy_ds_update.descriptorCount = 5; // ERROR copy 5 descriptors (out of bounds for layout)
Tobin Ehlis04356f92015-10-27 16:35:27 -06004133 vkUpdateDescriptorSets(m_device->device(), 0, NULL, 1, &copy_ds_update);
4134
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06004135 if (!m_errorMonitor->DesiredMsgFound()) {
4136 FAIL() << "Did not receive Error 'Copy descriptor src update is out of bounds for matching binding 1...'";
4137 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlis04356f92015-10-27 16:35:27 -06004138 }
4139
Chia-I Wuf7458c52015-10-26 21:10:41 +08004140 vkDestroySampler(m_device->device(), sampler, NULL);
4141 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
4142 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis04356f92015-10-27 16:35:27 -06004143}
4144
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06004145TEST_F(VkLayerTest, NumSamplesMismatch)
4146{
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004147 // Create CommandBuffer where MSAA samples doesn't match RenderPass sampleCount
Tobin Ehlis3b780662015-05-28 12:11:26 -06004148 VkResult err;
4149
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07004150 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06004151 "Num samples mismatch! ");
4152
Tobin Ehlis3b780662015-05-28 12:11:26 -06004153 ASSERT_NO_FATAL_FAILURE(InitState());
4154 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chia-I Wu1b99bb22015-10-27 19:25:11 +08004155 VkDescriptorPoolSize ds_type_count = {};
Tony Barboureb254902015-07-15 12:50:33 -06004156 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wud50a7d72015-10-26 20:48:51 +08004157 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06004158
4159 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -06004160 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
4161 ds_pool_ci.pNext = NULL;
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -06004162 ds_pool_ci.maxSets = 1;
Chia-I Wu1b99bb22015-10-27 19:25:11 +08004163 ds_pool_ci.poolSizeCount = 1;
4164 ds_pool_ci.pPoolSizes = &ds_type_count;
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -06004165
Tobin Ehlis3b780662015-05-28 12:11:26 -06004166 VkDescriptorPool ds_pool;
Chia-I Wuf7458c52015-10-26 21:10:41 +08004167 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -06004168 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -06004169
Tony Barboureb254902015-07-15 12:50:33 -06004170 VkDescriptorSetLayoutBinding dsl_binding = {};
Chia-I Wud46e6ae2015-10-31 00:31:16 +08004171 dsl_binding.binding = 0;
Tony Barboureb254902015-07-15 12:50:33 -06004172 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wu02124482015-11-06 06:42:02 +08004173 dsl_binding.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06004174 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
4175 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis3b780662015-05-28 12:11:26 -06004176
Tony Barboureb254902015-07-15 12:50:33 -06004177 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
4178 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
4179 ds_layout_ci.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08004180 ds_layout_ci.bindingCount = 1;
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07004181 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -06004182
Tobin Ehlis3b780662015-05-28 12:11:26 -06004183 VkDescriptorSetLayout ds_layout;
Chia-I Wuf7458c52015-10-26 21:10:41 +08004184 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -06004185 ASSERT_VK_SUCCESS(err);
4186
4187 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004188 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08004189 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Chia-I Wud50a7d72015-10-26 20:48:51 +08004190 alloc_info.setLayoutCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06004191 alloc_info.descriptorPool = ds_pool;
4192 alloc_info.pSetLayouts = &ds_layout;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004193 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -06004194 ASSERT_VK_SUCCESS(err);
4195
Tony Barboureb254902015-07-15 12:50:33 -06004196 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
4197 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
4198 pipe_ms_state_ci.pNext = NULL;
Chia-I Wu5c17c962015-10-31 00:31:16 +08004199 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_4_BIT;
Tony Barboureb254902015-07-15 12:50:33 -06004200 pipe_ms_state_ci.sampleShadingEnable = 0;
4201 pipe_ms_state_ci.minSampleShading = 1.0;
Cody Northrop02e61ed2015-08-04 14:34:54 -06004202 pipe_ms_state_ci.pSampleMask = NULL;
Tobin Ehlis3b780662015-05-28 12:11:26 -06004203
Tony Barboureb254902015-07-15 12:50:33 -06004204 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
4205 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
4206 pipeline_layout_ci.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08004207 pipeline_layout_ci.setLayoutCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06004208 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis3b780662015-05-28 12:11:26 -06004209
4210 VkPipelineLayout pipeline_layout;
Chia-I Wuf7458c52015-10-26 21:10:41 +08004211 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -06004212 ASSERT_VK_SUCCESS(err);
4213
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06004214 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
4215 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 -06004216 // but add it to be able to run on more devices
Tony Barbour62e1a5b2015-08-06 10:16:07 -06004217 VkPipelineObj pipe(m_device);
4218 pipe.AddShader(&vs);
Tony Barbour1c94d372015-08-06 11:21:08 -06004219 pipe.AddShader(&fs);
Tony Barbour62e1a5b2015-08-06 10:16:07 -06004220 pipe.SetMSAA(&pipe_ms_state_ci);
4221 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tobin Ehlis3b780662015-05-28 12:11:26 -06004222
Tony Barbourfe3351b2015-07-28 10:17:20 -06004223 BeginCommandBuffer();
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004224 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlis3b780662015-05-28 12:11:26 -06004225
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06004226 if (!m_errorMonitor->DesiredMsgFound()) {
4227 FAIL() << "Did not recieve Error 'Num samples mismatch!...'";
4228 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlis3b780662015-05-28 12:11:26 -06004229 }
Mike Stroyand1c84a52015-08-18 14:40:24 -06004230
Chia-I Wuf7458c52015-10-26 21:10:41 +08004231 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
4232 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
4233 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06004234}
Tobin Ehlis53eddda2015-07-01 16:46:13 -06004235
Tobin Ehlis53eddda2015-07-01 16:46:13 -06004236TEST_F(VkLayerTest, ClearCmdNoDraw)
4237{
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004238 // Create CommandBuffer where we add ClearCmd for FB Color attachment prior to issuing a Draw
Tobin Ehlis53eddda2015-07-01 16:46:13 -06004239 VkResult err;
4240
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07004241 // TODO: verify that this matches layer
4242 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARN_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06004243 "vkCmdClearAttachments() issued on CB object ");
4244
Tobin Ehlis53eddda2015-07-01 16:46:13 -06004245 ASSERT_NO_FATAL_FAILURE(InitState());
4246 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barboureb254902015-07-15 12:50:33 -06004247
Chia-I Wu1b99bb22015-10-27 19:25:11 +08004248 VkDescriptorPoolSize ds_type_count = {};
Tony Barboureb254902015-07-15 12:50:33 -06004249 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wud50a7d72015-10-26 20:48:51 +08004250 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06004251
4252 VkDescriptorPoolCreateInfo ds_pool_ci = {};
4253 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
4254 ds_pool_ci.pNext = NULL;
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -06004255 ds_pool_ci.maxSets = 1;
Chia-I Wu1b99bb22015-10-27 19:25:11 +08004256 ds_pool_ci.poolSizeCount = 1;
4257 ds_pool_ci.pPoolSizes = &ds_type_count;
Tony Barboureb254902015-07-15 12:50:33 -06004258
Tobin Ehlis53eddda2015-07-01 16:46:13 -06004259 VkDescriptorPool ds_pool;
Chia-I Wuf7458c52015-10-26 21:10:41 +08004260 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis53eddda2015-07-01 16:46:13 -06004261 ASSERT_VK_SUCCESS(err);
4262
Tony Barboureb254902015-07-15 12:50:33 -06004263 VkDescriptorSetLayoutBinding dsl_binding = {};
Chia-I Wud46e6ae2015-10-31 00:31:16 +08004264 dsl_binding.binding = 0;
Tony Barboureb254902015-07-15 12:50:33 -06004265 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wu02124482015-11-06 06:42:02 +08004266 dsl_binding.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06004267 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
4268 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis53eddda2015-07-01 16:46:13 -06004269
Tony Barboureb254902015-07-15 12:50:33 -06004270 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
4271 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
4272 ds_layout_ci.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08004273 ds_layout_ci.bindingCount = 1;
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07004274 ds_layout_ci.pBindings = &dsl_binding;
Mark Lobodzinski209b5292015-09-17 09:44:05 -06004275
Tobin Ehlis53eddda2015-07-01 16:46:13 -06004276 VkDescriptorSetLayout ds_layout;
Chia-I Wuf7458c52015-10-26 21:10:41 +08004277 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis53eddda2015-07-01 16:46:13 -06004278 ASSERT_VK_SUCCESS(err);
4279
4280 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004281 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08004282 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Chia-I Wud50a7d72015-10-26 20:48:51 +08004283 alloc_info.setLayoutCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06004284 alloc_info.descriptorPool = ds_pool;
4285 alloc_info.pSetLayouts = &ds_layout;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004286 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis53eddda2015-07-01 16:46:13 -06004287 ASSERT_VK_SUCCESS(err);
4288
Tony Barboureb254902015-07-15 12:50:33 -06004289 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
4290 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
4291 pipe_ms_state_ci.pNext = NULL;
Chia-I Wu5c17c962015-10-31 00:31:16 +08004292 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_4_BIT;
Tony Barboureb254902015-07-15 12:50:33 -06004293 pipe_ms_state_ci.sampleShadingEnable = 0;
4294 pipe_ms_state_ci.minSampleShading = 1.0;
Cody Northrop02e61ed2015-08-04 14:34:54 -06004295 pipe_ms_state_ci.pSampleMask = NULL;
Tobin Ehlis53eddda2015-07-01 16:46:13 -06004296
Tony Barboureb254902015-07-15 12:50:33 -06004297 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
4298 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
4299 pipeline_layout_ci.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08004300 pipeline_layout_ci.setLayoutCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06004301 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis53eddda2015-07-01 16:46:13 -06004302
4303 VkPipelineLayout pipeline_layout;
Chia-I Wuf7458c52015-10-26 21:10:41 +08004304 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis53eddda2015-07-01 16:46:13 -06004305 ASSERT_VK_SUCCESS(err);
Mark Lobodzinski209b5292015-09-17 09:44:05 -06004306
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06004307 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06004308 // TODO - We shouldn't need a fragment shader but add it to be able to run on more devices
4309 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
4310
Tony Barbour62e1a5b2015-08-06 10:16:07 -06004311 VkPipelineObj pipe(m_device);
4312 pipe.AddShader(&vs);
Tony Barbour1c94d372015-08-06 11:21:08 -06004313 pipe.AddShader(&fs);
Tony Barbour62e1a5b2015-08-06 10:16:07 -06004314 pipe.SetMSAA(&pipe_ms_state_ci);
4315 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tony Barbourfe3351b2015-07-28 10:17:20 -06004316
4317 BeginCommandBuffer();
Tobin Ehlis53eddda2015-07-01 16:46:13 -06004318
Tobin Ehlis53eddda2015-07-01 16:46:13 -06004319 // Main thing we care about for this test is that the VkImage obj we're clearing matches Color Attachment of FB
4320 // Also pass down other dummy params to keep driver and paramchecker happy
Courtney Goeltzenleuchterc9323e02015-10-15 16:51:05 -06004321 VkClearAttachment color_attachment;
4322 color_attachment.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
4323 color_attachment.clearValue.color.float32[0] = 1.0;
4324 color_attachment.clearValue.color.float32[1] = 1.0;
4325 color_attachment.clearValue.color.float32[2] = 1.0;
4326 color_attachment.clearValue.color.float32[3] = 1.0;
4327 color_attachment.colorAttachment = 0;
Courtney Goeltzenleuchter5d2aed42015-10-21 17:57:31 -06004328 VkClearRect clear_rect = { { { 0, 0 }, { (int)m_width, (int)m_height } } };
Tobin Ehlis53eddda2015-07-01 16:46:13 -06004329
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004330 vkCmdClearAttachments(m_commandBuffer->GetBufferHandle(), 1, &color_attachment, 1, &clear_rect);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06004331
4332 if (!m_errorMonitor->DesiredMsgFound()) {
4333 FAIL() << "Did not receive Error 'vkCommandClearAttachments() issued on CB object...'";
4334 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlis53eddda2015-07-01 16:46:13 -06004335 }
Mike Stroyand1c84a52015-08-18 14:40:24 -06004336
Chia-I Wuf7458c52015-10-26 21:10:41 +08004337 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
4338 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
4339 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis53eddda2015-07-01 16:46:13 -06004340}
4341
Tobin Ehlis502480b2015-06-24 15:53:07 -06004342TEST_F(VkLayerTest, VtxBufferBadIndex)
4343{
Tobin Ehlis502480b2015-06-24 15:53:07 -06004344 VkResult err;
4345
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07004346 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERF_WARN_BIT_EXT,
Mark Lobodzinskidfcd9b62015-12-14 15:14:10 -07004347 "but no vertex buffers are attached to this Pipeline State Object");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06004348
Tobin Ehlis502480b2015-06-24 15:53:07 -06004349 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisd332f282015-10-02 11:00:56 -06004350 ASSERT_NO_FATAL_FAILURE(InitViewport());
Tobin Ehlis502480b2015-06-24 15:53:07 -06004351 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barboureb254902015-07-15 12:50:33 -06004352
Chia-I Wu1b99bb22015-10-27 19:25:11 +08004353 VkDescriptorPoolSize ds_type_count = {};
Tony Barboureb254902015-07-15 12:50:33 -06004354 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wud50a7d72015-10-26 20:48:51 +08004355 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06004356
4357 VkDescriptorPoolCreateInfo ds_pool_ci = {};
4358 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
4359 ds_pool_ci.pNext = NULL;
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -06004360 ds_pool_ci.maxSets = 1;
Chia-I Wu1b99bb22015-10-27 19:25:11 +08004361 ds_pool_ci.poolSizeCount = 1;
4362 ds_pool_ci.pPoolSizes = &ds_type_count;
Tony Barboureb254902015-07-15 12:50:33 -06004363
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -06004364 VkDescriptorPool ds_pool;
Chia-I Wuf7458c52015-10-26 21:10:41 +08004365 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis502480b2015-06-24 15:53:07 -06004366 ASSERT_VK_SUCCESS(err);
4367
Tony Barboureb254902015-07-15 12:50:33 -06004368 VkDescriptorSetLayoutBinding dsl_binding = {};
Chia-I Wud46e6ae2015-10-31 00:31:16 +08004369 dsl_binding.binding = 0;
Tony Barboureb254902015-07-15 12:50:33 -06004370 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wu02124482015-11-06 06:42:02 +08004371 dsl_binding.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06004372 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
4373 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis502480b2015-06-24 15:53:07 -06004374
Tony Barboureb254902015-07-15 12:50:33 -06004375 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
4376 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
4377 ds_layout_ci.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08004378 ds_layout_ci.bindingCount = 1;
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07004379 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -06004380
Tobin Ehlis502480b2015-06-24 15:53:07 -06004381 VkDescriptorSetLayout ds_layout;
Chia-I Wuf7458c52015-10-26 21:10:41 +08004382 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis502480b2015-06-24 15:53:07 -06004383 ASSERT_VK_SUCCESS(err);
4384
4385 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004386 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08004387 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Chia-I Wud50a7d72015-10-26 20:48:51 +08004388 alloc_info.setLayoutCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06004389 alloc_info.descriptorPool = ds_pool;
4390 alloc_info.pSetLayouts = &ds_layout;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004391 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis502480b2015-06-24 15:53:07 -06004392 ASSERT_VK_SUCCESS(err);
4393
Tony Barboureb254902015-07-15 12:50:33 -06004394 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
4395 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
4396 pipe_ms_state_ci.pNext = NULL;
Chia-I Wu5c17c962015-10-31 00:31:16 +08004397 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
Tony Barboureb254902015-07-15 12:50:33 -06004398 pipe_ms_state_ci.sampleShadingEnable = 0;
4399 pipe_ms_state_ci.minSampleShading = 1.0;
Cody Northrop02e61ed2015-08-04 14:34:54 -06004400 pipe_ms_state_ci.pSampleMask = NULL;
Tobin Ehlis502480b2015-06-24 15:53:07 -06004401
Tony Barboureb254902015-07-15 12:50:33 -06004402 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
4403 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
4404 pipeline_layout_ci.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08004405 pipeline_layout_ci.setLayoutCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06004406 pipeline_layout_ci.pSetLayouts = &ds_layout;
4407 VkPipelineLayout pipeline_layout;
Tobin Ehlis502480b2015-06-24 15:53:07 -06004408
Chia-I Wuf7458c52015-10-26 21:10:41 +08004409 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis502480b2015-06-24 15:53:07 -06004410 ASSERT_VK_SUCCESS(err);
4411
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06004412 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
4413 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 -06004414 // but add it to be able to run on more devices
Tony Barbour62e1a5b2015-08-06 10:16:07 -06004415 VkPipelineObj pipe(m_device);
4416 pipe.AddShader(&vs);
Tony Barbour1c94d372015-08-06 11:21:08 -06004417 pipe.AddShader(&fs);
Tony Barbour62e1a5b2015-08-06 10:16:07 -06004418 pipe.SetMSAA(&pipe_ms_state_ci);
Tobin Ehlisd332f282015-10-02 11:00:56 -06004419 pipe.SetViewport(m_viewports);
4420 pipe.SetScissor(m_scissors);
Tony Barbour62e1a5b2015-08-06 10:16:07 -06004421 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tony Barbourfe3351b2015-07-28 10:17:20 -06004422
4423 BeginCommandBuffer();
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004424 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlisf7bf4502015-09-09 15:12:35 -06004425 // Don't care about actual data, just need to get to draw to flag error
4426 static const float vbo_data[3] = {1.f, 0.f, 1.f};
4427 VkConstantBufferObj vbo(m_device, sizeof(vbo_data), sizeof(float), (const void*) &vbo_data);
4428 BindVertexBuffer(&vbo, (VkDeviceSize)0, 1); // VBO idx 1, but no VBO in PSO
Courtney Goeltzenleuchter08c26372015-09-23 12:31:50 -06004429 Draw(1, 0, 0, 0);
Tobin Ehlis502480b2015-06-24 15:53:07 -06004430
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06004431 if (!m_errorMonitor->DesiredMsgFound()) {
4432 FAIL() << "Did not receive Error 'Vtx Buffer Index 0 was bound, but no vtx buffers are attached to PSO.'";
4433 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlis502480b2015-06-24 15:53:07 -06004434 }
Mike Stroyand1c84a52015-08-18 14:40:24 -06004435
Chia-I Wuf7458c52015-10-26 21:10:41 +08004436 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
4437 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
4438 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis502480b2015-06-24 15:53:07 -06004439}
Mark Lobodzinski209b5292015-09-17 09:44:05 -06004440#endif // DRAW_STATE_TESTS
4441
Tobin Ehlis0788f522015-05-26 16:11:58 -06004442#if THREADING_TESTS
Mike Stroyanaccf7692015-05-12 16:00:45 -06004443#if GTEST_IS_THREADSAFE
4444struct thread_data_struct {
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004445 VkCommandBuffer commandBuffer;
Mike Stroyanaccf7692015-05-12 16:00:45 -06004446 VkEvent event;
4447 bool bailout;
4448};
4449
4450extern "C" void *AddToCommandBuffer(void *arg)
4451{
4452 struct thread_data_struct *data = (struct thread_data_struct *) arg;
Mike Stroyanaccf7692015-05-12 16:00:45 -06004453
4454 for (int i = 0; i<10000; i++) {
Chia-I Wu89d0f942015-10-31 00:31:16 +08004455 vkCmdSetEvent(data->commandBuffer, data->event, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT);
Mike Stroyanaccf7692015-05-12 16:00:45 -06004456 if (data->bailout) {
4457 break;
4458 }
4459 }
4460 return NULL;
4461}
4462
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004463TEST_F(VkLayerTest, ThreadCommandBufferCollision)
Mike Stroyanaccf7692015-05-12 16:00:45 -06004464{
Mike Stroyan4268d1f2015-07-13 14:45:35 -06004465 test_platform_thread thread;
Mike Stroyanaccf7692015-05-12 16:00:45 -06004466
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07004467 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "THREADING ERROR");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06004468
Mike Stroyanaccf7692015-05-12 16:00:45 -06004469 ASSERT_NO_FATAL_FAILURE(InitState());
4470 ASSERT_NO_FATAL_FAILURE(InitViewport());
4471 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
4472
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004473 // Calls AllocateCommandBuffers
4474 VkCommandBufferObj commandBuffer(m_device, m_commandPool);
Mark Lobodzinski5495d132015-09-30 16:19:16 -06004475
4476 // Avoid creating RenderPass
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004477 commandBuffer.BeginCommandBuffer();
Mike Stroyanaccf7692015-05-12 16:00:45 -06004478
4479 VkEventCreateInfo event_info;
4480 VkEvent event;
Mike Stroyanaccf7692015-05-12 16:00:45 -06004481 VkResult err;
4482
4483 memset(&event_info, 0, sizeof(event_info));
4484 event_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
4485
Chia-I Wuf7458c52015-10-26 21:10:41 +08004486 err = vkCreateEvent(device(), &event_info, NULL, &event);
Mike Stroyanaccf7692015-05-12 16:00:45 -06004487 ASSERT_VK_SUCCESS(err);
4488
Mike Stroyanaccf7692015-05-12 16:00:45 -06004489 err = vkResetEvent(device(), event);
4490 ASSERT_VK_SUCCESS(err);
4491
4492 struct thread_data_struct data;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004493 data.commandBuffer = commandBuffer.GetBufferHandle();
Mike Stroyanaccf7692015-05-12 16:00:45 -06004494 data.event = event;
4495 data.bailout = false;
4496 m_errorMonitor->SetBailout(&data.bailout);
4497 // Add many entries to command buffer from another thread.
Mike Stroyan4268d1f2015-07-13 14:45:35 -06004498 test_platform_thread_create(&thread, AddToCommandBuffer, (void *)&data);
Mike Stroyanaccf7692015-05-12 16:00:45 -06004499 // Add many entries to command buffer from this thread at the same time.
4500 AddToCommandBuffer(&data);
Mark Lobodzinski5495d132015-09-30 16:19:16 -06004501
Mike Stroyan4268d1f2015-07-13 14:45:35 -06004502 test_platform_thread_join(thread, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004503 commandBuffer.EndCommandBuffer();
Mike Stroyanaccf7692015-05-12 16:00:45 -06004504
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06004505 if (!m_errorMonitor->DesiredMsgFound()) {
4506 FAIL() << "Did not receive Error 'THREADING ERROR' from using one VkCommandBufferObj in two threads";
4507 m_errorMonitor->DumpFailureMsgs();
Mike Stroyanaccf7692015-05-12 16:00:45 -06004508 }
4509
Chia-I Wuf7458c52015-10-26 21:10:41 +08004510 vkDestroyEvent(device(), event, NULL);
Mike Stroyanaccf7692015-05-12 16:00:45 -06004511}
Mark Lobodzinski209b5292015-09-17 09:44:05 -06004512#endif // GTEST_IS_THREADSAFE
4513#endif // THREADING_TESTS
4514
Chris Forbes9f7ff632015-05-25 11:13:08 +12004515#if SHADER_CHECKER_TESTS
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -06004516TEST_F(VkLayerTest, InvalidSPIRVCodeSize)
4517{
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07004518 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06004519 "Shader is not SPIR-V");
4520
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -06004521 ASSERT_NO_FATAL_FAILURE(InitState());
4522 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
4523
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -06004524 VkShaderModule module;
4525 VkShaderModuleCreateInfo moduleCreateInfo;
4526 struct icd_spv_header spv;
4527
4528 spv.magic = ICD_SPV_MAGIC;
4529 spv.version = ICD_SPV_VERSION;
4530 spv.gen_magic = 0;
4531
4532 moduleCreateInfo.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;
4533 moduleCreateInfo.pNext = NULL;
Chia-I Wu8094f192015-10-26 19:22:06 +08004534 moduleCreateInfo.pCode = (const uint32_t *) &spv;
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -06004535 moduleCreateInfo.codeSize = 4;
4536 moduleCreateInfo.flags = 0;
Chia-I Wuf7458c52015-10-26 21:10:41 +08004537 vkCreateShaderModule(m_device->device(), &moduleCreateInfo, NULL, &module);
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -06004538
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06004539 if (!m_errorMonitor->DesiredMsgFound()) {
4540 FAIL() << "Did not recieive Error 'Shader is not SPIR-V'";
4541 m_errorMonitor->DumpFailureMsgs();
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -06004542 }
4543}
4544
4545TEST_F(VkLayerTest, InvalidSPIRVMagic)
4546{
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07004547 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06004548 "Shader is not SPIR-V");
4549
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -06004550 ASSERT_NO_FATAL_FAILURE(InitState());
4551 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
4552
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -06004553 VkShaderModule module;
4554 VkShaderModuleCreateInfo moduleCreateInfo;
4555 struct icd_spv_header spv;
4556
4557 spv.magic = ~ICD_SPV_MAGIC;
4558 spv.version = ICD_SPV_VERSION;
4559 spv.gen_magic = 0;
4560
4561 moduleCreateInfo.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;
4562 moduleCreateInfo.pNext = NULL;
Chia-I Wu8094f192015-10-26 19:22:06 +08004563 moduleCreateInfo.pCode = (const uint32_t *) &spv;
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -06004564 moduleCreateInfo.codeSize = sizeof(spv) + 10;
4565 moduleCreateInfo.flags = 0;
Chia-I Wuf7458c52015-10-26 21:10:41 +08004566 vkCreateShaderModule(m_device->device(), &moduleCreateInfo, NULL, &module);
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -06004567
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06004568 if (!m_errorMonitor->DesiredMsgFound()) {
4569 FAIL() << "Did not recieive Error 'Shader is not SPIR-V'";
4570 m_errorMonitor->DumpFailureMsgs();
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -06004571 }
4572}
4573
4574TEST_F(VkLayerTest, InvalidSPIRVVersion)
4575{
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07004576 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06004577 "Shader is not SPIR-V");
4578
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -06004579 ASSERT_NO_FATAL_FAILURE(InitState());
4580 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
4581
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -06004582 VkShaderModule module;
4583 VkShaderModuleCreateInfo moduleCreateInfo;
4584 struct icd_spv_header spv;
4585
4586 spv.magic = ICD_SPV_MAGIC;
4587 spv.version = ~ICD_SPV_VERSION;
4588 spv.gen_magic = 0;
4589
4590 moduleCreateInfo.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;
4591 moduleCreateInfo.pNext = NULL;
4592
Chia-I Wu8094f192015-10-26 19:22:06 +08004593 moduleCreateInfo.pCode = (const uint32_t *) &spv;
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -06004594 moduleCreateInfo.codeSize = sizeof(spv) + 10;
4595 moduleCreateInfo.flags = 0;
Chia-I Wuf7458c52015-10-26 21:10:41 +08004596 vkCreateShaderModule(m_device->device(), &moduleCreateInfo, NULL, &module);
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -06004597
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06004598 if (!m_errorMonitor->DesiredMsgFound()) {
4599 FAIL() << "Did not recieive Error 'Shader is not SPIR-V'";
4600 m_errorMonitor->DumpFailureMsgs();
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -06004601 }
4602}
4603
Chris Forbes9f7ff632015-05-25 11:13:08 +12004604TEST_F(VkLayerTest, CreatePipelineVertexOutputNotConsumed)
4605{
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07004606 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERF_WARN_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06004607 "not consumed by fragment shader");
4608
Chris Forbes9f7ff632015-05-25 11:13:08 +12004609 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06004610 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes9f7ff632015-05-25 11:13:08 +12004611
4612 char const *vsSource =
Tony Barboure804d202016-01-05 13:37:45 -07004613 "#version 400\n"
Chris Forbes9f7ff632015-05-25 11:13:08 +12004614 "#extension GL_ARB_separate_shader_objects: require\n"
4615 "#extension GL_ARB_shading_language_420pack: require\n"
4616 "\n"
4617 "layout(location=0) out float x;\n"
Tony Barboure804d202016-01-05 13:37:45 -07004618 "out gl_PerVertex {\n"
4619 " vec4 gl_Position;\n"
4620 "};\n"
Chris Forbes9f7ff632015-05-25 11:13:08 +12004621 "void main(){\n"
4622 " gl_Position = vec4(1);\n"
4623 " x = 0;\n"
4624 "}\n";
4625 char const *fsSource =
Tony Barboure804d202016-01-05 13:37:45 -07004626 "#version 400\n"
Chris Forbes9f7ff632015-05-25 11:13:08 +12004627 "#extension GL_ARB_separate_shader_objects: require\n"
4628 "#extension GL_ARB_shading_language_420pack: require\n"
4629 "\n"
4630 "layout(location=0) out vec4 color;\n"
4631 "void main(){\n"
4632 " color = vec4(1);\n"
4633 "}\n";
4634
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06004635 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
4636 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes9f7ff632015-05-25 11:13:08 +12004637
4638 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +08004639 pipe.AddColorAttachment();
Chris Forbes9f7ff632015-05-25 11:13:08 +12004640 pipe.AddShader(&vs);
4641 pipe.AddShader(&fs);
4642
Chris Forbes9f7ff632015-05-25 11:13:08 +12004643 VkDescriptorSetObj descriptorSet(m_device);
4644 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004645 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes9f7ff632015-05-25 11:13:08 +12004646
Tony Barbour5781e8f2015-08-04 16:23:11 -06004647 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes9f7ff632015-05-25 11:13:08 +12004648
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06004649 if (!m_errorMonitor->DesiredMsgFound()) {
4650 FAIL() << "Did not receive Warning 'not consumed by fragment shader'";
4651 m_errorMonitor->DumpFailureMsgs();
Chris Forbes9f7ff632015-05-25 11:13:08 +12004652 }
4653}
Chris Forbes9f7ff632015-05-25 11:13:08 +12004654
Chris Forbes59cb88d2015-05-25 11:13:13 +12004655TEST_F(VkLayerTest, CreatePipelineFragmentInputNotProvided)
4656{
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07004657 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06004658 "not written by vertex shader");
4659
Chris Forbes59cb88d2015-05-25 11:13:13 +12004660 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06004661 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes59cb88d2015-05-25 11:13:13 +12004662
4663 char const *vsSource =
Tony Barboure804d202016-01-05 13:37:45 -07004664 "#version 400\n"
Chris Forbes59cb88d2015-05-25 11:13:13 +12004665 "#extension GL_ARB_separate_shader_objects: require\n"
4666 "#extension GL_ARB_shading_language_420pack: require\n"
4667 "\n"
Tony Barboure804d202016-01-05 13:37:45 -07004668 "out gl_PerVertex {\n"
4669 " vec4 gl_Position;\n"
4670 "};\n"
Chris Forbes59cb88d2015-05-25 11:13:13 +12004671 "void main(){\n"
4672 " gl_Position = vec4(1);\n"
4673 "}\n";
4674 char const *fsSource =
Tony Barboure804d202016-01-05 13:37:45 -07004675 "#version 400\n"
Chris Forbes59cb88d2015-05-25 11:13:13 +12004676 "#extension GL_ARB_separate_shader_objects: require\n"
4677 "#extension GL_ARB_shading_language_420pack: require\n"
4678 "\n"
4679 "layout(location=0) in float x;\n"
4680 "layout(location=0) out vec4 color;\n"
4681 "void main(){\n"
4682 " color = vec4(x);\n"
4683 "}\n";
4684
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06004685 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
4686 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes59cb88d2015-05-25 11:13:13 +12004687
4688 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +08004689 pipe.AddColorAttachment();
Chris Forbes59cb88d2015-05-25 11:13:13 +12004690 pipe.AddShader(&vs);
4691 pipe.AddShader(&fs);
4692
Chris Forbes59cb88d2015-05-25 11:13:13 +12004693 VkDescriptorSetObj descriptorSet(m_device);
4694 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004695 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes59cb88d2015-05-25 11:13:13 +12004696
Tony Barbour5781e8f2015-08-04 16:23:11 -06004697 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes59cb88d2015-05-25 11:13:13 +12004698
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06004699 if (!m_errorMonitor->DesiredMsgFound()) {
4700 FAIL() << "Did not receive Error 'not written by vertex shader'";
4701 m_errorMonitor->DumpFailureMsgs();
Chris Forbes59cb88d2015-05-25 11:13:13 +12004702 }
4703}
4704
Chris Forbesb56af562015-05-25 11:13:17 +12004705TEST_F(VkLayerTest, CreatePipelineVsFsTypeMismatch)
4706{
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07004707 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06004708 "Type mismatch on location 0");
4709
Chris Forbesb56af562015-05-25 11:13:17 +12004710 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06004711 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesb56af562015-05-25 11:13:17 +12004712
4713 char const *vsSource =
Tony Barboure804d202016-01-05 13:37:45 -07004714 "#version 400\n"
Chris Forbesb56af562015-05-25 11:13:17 +12004715 "#extension GL_ARB_separate_shader_objects: require\n"
4716 "#extension GL_ARB_shading_language_420pack: require\n"
4717 "\n"
4718 "layout(location=0) out int x;\n"
Tony Barboure804d202016-01-05 13:37:45 -07004719 "out gl_PerVertex {\n"
4720 " vec4 gl_Position;\n"
4721 "};\n"
Chris Forbesb56af562015-05-25 11:13:17 +12004722 "void main(){\n"
4723 " x = 0;\n"
4724 " gl_Position = vec4(1);\n"
4725 "}\n";
4726 char const *fsSource =
Tony Barboure804d202016-01-05 13:37:45 -07004727 "#version 400\n"
Chris Forbesb56af562015-05-25 11:13:17 +12004728 "#extension GL_ARB_separate_shader_objects: require\n"
4729 "#extension GL_ARB_shading_language_420pack: require\n"
4730 "\n"
4731 "layout(location=0) in float x;\n" /* VS writes int */
4732 "layout(location=0) out vec4 color;\n"
4733 "void main(){\n"
4734 " color = vec4(x);\n"
4735 "}\n";
4736
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06004737 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
4738 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesb56af562015-05-25 11:13:17 +12004739
4740 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +08004741 pipe.AddColorAttachment();
Chris Forbesb56af562015-05-25 11:13:17 +12004742 pipe.AddShader(&vs);
4743 pipe.AddShader(&fs);
4744
Chris Forbesb56af562015-05-25 11:13:17 +12004745 VkDescriptorSetObj descriptorSet(m_device);
4746 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004747 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesb56af562015-05-25 11:13:17 +12004748
Tony Barbour5781e8f2015-08-04 16:23:11 -06004749 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesb56af562015-05-25 11:13:17 +12004750
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06004751 if (!m_errorMonitor->DesiredMsgFound()) {
4752 FAIL() << "Did not receive Error 'Type mismatch on location 0'";
4753 m_errorMonitor->DumpFailureMsgs();
Chris Forbesb56af562015-05-25 11:13:17 +12004754 }
4755}
4756
Chris Forbesde136e02015-05-25 11:13:28 +12004757TEST_F(VkLayerTest, CreatePipelineAttribNotConsumed)
4758{
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07004759 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERF_WARN_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06004760 "location 0 not consumed by VS");
4761
Chris Forbesde136e02015-05-25 11:13:28 +12004762 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06004763 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesde136e02015-05-25 11:13:28 +12004764
4765 VkVertexInputBindingDescription input_binding;
4766 memset(&input_binding, 0, sizeof(input_binding));
4767
4768 VkVertexInputAttributeDescription input_attrib;
4769 memset(&input_attrib, 0, sizeof(input_attrib));
4770 input_attrib.format = VK_FORMAT_R32_SFLOAT;
4771
4772 char const *vsSource =
Tony Barboure804d202016-01-05 13:37:45 -07004773 "#version 400\n"
Chris Forbesde136e02015-05-25 11:13:28 +12004774 "#extension GL_ARB_separate_shader_objects: require\n"
4775 "#extension GL_ARB_shading_language_420pack: require\n"
4776 "\n"
Tony Barboure804d202016-01-05 13:37:45 -07004777 "out gl_PerVertex {\n"
4778 " vec4 gl_Position;\n"
4779 "};\n"
Chris Forbesde136e02015-05-25 11:13:28 +12004780 "void main(){\n"
4781 " gl_Position = vec4(1);\n"
4782 "}\n";
4783 char const *fsSource =
Tony Barboure804d202016-01-05 13:37:45 -07004784 "#version 400\n"
Chris Forbesde136e02015-05-25 11:13:28 +12004785 "#extension GL_ARB_separate_shader_objects: require\n"
4786 "#extension GL_ARB_shading_language_420pack: require\n"
4787 "\n"
4788 "layout(location=0) out vec4 color;\n"
4789 "void main(){\n"
4790 " color = vec4(1);\n"
4791 "}\n";
4792
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06004793 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
4794 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesde136e02015-05-25 11:13:28 +12004795
4796 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +08004797 pipe.AddColorAttachment();
Chris Forbesde136e02015-05-25 11:13:28 +12004798 pipe.AddShader(&vs);
4799 pipe.AddShader(&fs);
4800
4801 pipe.AddVertexInputBindings(&input_binding, 1);
4802 pipe.AddVertexInputAttribs(&input_attrib, 1);
4803
Chris Forbesde136e02015-05-25 11:13:28 +12004804 VkDescriptorSetObj descriptorSet(m_device);
4805 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004806 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesde136e02015-05-25 11:13:28 +12004807
Tony Barbour5781e8f2015-08-04 16:23:11 -06004808 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesde136e02015-05-25 11:13:28 +12004809
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06004810 if (!m_errorMonitor->DesiredMsgFound()) {
4811 FAIL() << "Did not receive Warning 'location 0 not consumed by VS'";
4812 m_errorMonitor->DumpFailureMsgs();
Chris Forbesde136e02015-05-25 11:13:28 +12004813 }
4814}
4815
Chris Forbes62e8e502015-05-25 11:13:29 +12004816TEST_F(VkLayerTest, CreatePipelineAttribNotProvided)
4817{
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07004818 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06004819 "VS consumes input at location 0 but not provided");
4820
Chris Forbes62e8e502015-05-25 11:13:29 +12004821 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06004822 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes62e8e502015-05-25 11:13:29 +12004823
4824 char const *vsSource =
Tony Barboure804d202016-01-05 13:37:45 -07004825 "#version 400\n"
Chris Forbes62e8e502015-05-25 11:13:29 +12004826 "#extension GL_ARB_separate_shader_objects: require\n"
4827 "#extension GL_ARB_shading_language_420pack: require\n"
4828 "\n"
4829 "layout(location=0) in vec4 x;\n" /* not provided */
Tony Barboure804d202016-01-05 13:37:45 -07004830 "out gl_PerVertex {\n"
4831 " vec4 gl_Position;\n"
4832 "};\n"
Chris Forbes62e8e502015-05-25 11:13:29 +12004833 "void main(){\n"
4834 " gl_Position = x;\n"
4835 "}\n";
4836 char const *fsSource =
Tony Barboure804d202016-01-05 13:37:45 -07004837 "#version 400\n"
Chris Forbes62e8e502015-05-25 11:13:29 +12004838 "#extension GL_ARB_separate_shader_objects: require\n"
4839 "#extension GL_ARB_shading_language_420pack: require\n"
4840 "\n"
4841 "layout(location=0) out vec4 color;\n"
4842 "void main(){\n"
4843 " color = vec4(1);\n"
4844 "}\n";
4845
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06004846 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
4847 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes62e8e502015-05-25 11:13:29 +12004848
4849 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +08004850 pipe.AddColorAttachment();
Chris Forbes62e8e502015-05-25 11:13:29 +12004851 pipe.AddShader(&vs);
4852 pipe.AddShader(&fs);
4853
Chris Forbes62e8e502015-05-25 11:13:29 +12004854 VkDescriptorSetObj descriptorSet(m_device);
4855 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004856 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes62e8e502015-05-25 11:13:29 +12004857
Tony Barbour5781e8f2015-08-04 16:23:11 -06004858 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes62e8e502015-05-25 11:13:29 +12004859
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06004860 if (!m_errorMonitor->DesiredMsgFound()) {
4861 FAIL() << "Did not receive Error 'VS consumes input at location 0 but not provided'";
4862 m_errorMonitor->DumpFailureMsgs();
Chris Forbes62e8e502015-05-25 11:13:29 +12004863 }
4864}
4865
Chris Forbesc97d98e2015-05-25 11:13:31 +12004866TEST_F(VkLayerTest, CreatePipelineAttribTypeMismatch)
4867{
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07004868 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06004869 "location 0 does not match VS input type");
4870
Chris Forbesc97d98e2015-05-25 11:13:31 +12004871 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06004872 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesc97d98e2015-05-25 11:13:31 +12004873
4874 VkVertexInputBindingDescription input_binding;
4875 memset(&input_binding, 0, sizeof(input_binding));
4876
4877 VkVertexInputAttributeDescription input_attrib;
4878 memset(&input_attrib, 0, sizeof(input_attrib));
4879 input_attrib.format = VK_FORMAT_R32_SFLOAT;
4880
4881 char const *vsSource =
Tony Barboure804d202016-01-05 13:37:45 -07004882 "#version 400\n"
Chris Forbesc97d98e2015-05-25 11:13:31 +12004883 "#extension GL_ARB_separate_shader_objects: require\n"
4884 "#extension GL_ARB_shading_language_420pack: require\n"
4885 "\n"
4886 "layout(location=0) in int x;\n" /* attrib provided float */
Tony Barboure804d202016-01-05 13:37:45 -07004887 "out gl_PerVertex {\n"
4888 " vec4 gl_Position;\n"
4889 "};\n"
Chris Forbesc97d98e2015-05-25 11:13:31 +12004890 "void main(){\n"
4891 " gl_Position = vec4(x);\n"
4892 "}\n";
4893 char const *fsSource =
Tony Barboure804d202016-01-05 13:37:45 -07004894 "#version 400\n"
Chris Forbesc97d98e2015-05-25 11:13:31 +12004895 "#extension GL_ARB_separate_shader_objects: require\n"
4896 "#extension GL_ARB_shading_language_420pack: require\n"
4897 "\n"
4898 "layout(location=0) out vec4 color;\n"
4899 "void main(){\n"
4900 " color = vec4(1);\n"
4901 "}\n";
4902
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06004903 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
4904 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesc97d98e2015-05-25 11:13:31 +12004905
4906 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +08004907 pipe.AddColorAttachment();
Chris Forbesc97d98e2015-05-25 11:13:31 +12004908 pipe.AddShader(&vs);
4909 pipe.AddShader(&fs);
4910
4911 pipe.AddVertexInputBindings(&input_binding, 1);
4912 pipe.AddVertexInputAttribs(&input_attrib, 1);
4913
Chris Forbesc97d98e2015-05-25 11:13:31 +12004914 VkDescriptorSetObj descriptorSet(m_device);
4915 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004916 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesc97d98e2015-05-25 11:13:31 +12004917
Tony Barbour5781e8f2015-08-04 16:23:11 -06004918 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesc97d98e2015-05-25 11:13:31 +12004919
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06004920 if (!m_errorMonitor->DesiredMsgFound()) {
4921 FAIL() << "Did not receive Error 'location 0 does not match VS input type'";
4922 m_errorMonitor->DumpFailureMsgs();
Chris Forbesc97d98e2015-05-25 11:13:31 +12004923 }
4924}
4925
Chris Forbes2682b242015-11-24 11:13:14 +13004926TEST_F(VkLayerTest, CreatePipelineAttribMatrixType)
4927{
4928 m_errorMonitor->SetDesiredFailureMsg(~0u, "");
4929
4930 ASSERT_NO_FATAL_FAILURE(InitState());
4931 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
4932
4933 VkVertexInputBindingDescription input_binding;
4934 memset(&input_binding, 0, sizeof(input_binding));
4935
4936 VkVertexInputAttributeDescription input_attribs[2];
4937 memset(input_attribs, 0, sizeof(input_attribs));
4938
4939 for (int i = 0; i < 2; i++) {
4940 input_attribs[i].format = VK_FORMAT_R32G32B32A32_SFLOAT;
4941 input_attribs[i].location = i;
4942 }
4943
4944 char const *vsSource =
Tony Barboure804d202016-01-05 13:37:45 -07004945 "#version 400\n"
Chris Forbes2682b242015-11-24 11:13:14 +13004946 "#extension GL_ARB_separate_shader_objects: require\n"
4947 "#extension GL_ARB_shading_language_420pack: require\n"
4948 "\n"
4949 "layout(location=0) in mat2x4 x;\n"
Tony Barboure804d202016-01-05 13:37:45 -07004950 "out gl_PerVertex {\n"
4951 " vec4 gl_Position;\n"
4952 "};\n"
Chris Forbes2682b242015-11-24 11:13:14 +13004953 "void main(){\n"
4954 " gl_Position = x[0] + x[1];\n"
4955 "}\n";
4956 char const *fsSource =
Tony Barboure804d202016-01-05 13:37:45 -07004957 "#version 400\n"
Chris Forbes2682b242015-11-24 11:13:14 +13004958 "#extension GL_ARB_separate_shader_objects: require\n"
4959 "#extension GL_ARB_shading_language_420pack: require\n"
4960 "\n"
4961 "layout(location=0) out vec4 color;\n"
4962 "void main(){\n"
4963 " color = vec4(1);\n"
4964 "}\n";
4965
4966 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
4967 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
4968
4969 VkPipelineObj pipe(m_device);
4970 pipe.AddColorAttachment();
4971 pipe.AddShader(&vs);
4972 pipe.AddShader(&fs);
4973
4974 pipe.AddVertexInputBindings(&input_binding, 1);
4975 pipe.AddVertexInputAttribs(input_attribs, 2);
4976
4977 VkDescriptorSetObj descriptorSet(m_device);
4978 descriptorSet.AppendDummy();
4979 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
4980
4981 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
4982
4983 /* expect success */
4984 if (m_errorMonitor->DesiredMsgFound()) {
4985 FAIL() << "Expected to succeed but: " << m_errorMonitor->GetFailureMsg();
4986 m_errorMonitor->DumpFailureMsgs();
4987 }
4988}
4989
4990/*
4991 * Would work, but not supported by glslang! This is similar to the matrix case above.
4992 *
4993TEST_F(VkLayerTest, CreatePipelineAttribArrayType)
4994{
4995 m_errorMonitor->SetDesiredFailureMsg(~0u, "");
4996
4997 ASSERT_NO_FATAL_FAILURE(InitState());
4998 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
4999
5000 VkVertexInputBindingDescription input_binding;
5001 memset(&input_binding, 0, sizeof(input_binding));
5002
5003 VkVertexInputAttributeDescription input_attribs[2];
5004 memset(input_attribs, 0, sizeof(input_attribs));
5005
5006 for (int i = 0; i < 2; i++) {
5007 input_attribs[i].format = VK_FORMAT_R32G32B32A32_SFLOAT;
5008 input_attribs[i].location = i;
5009 }
5010
5011 char const *vsSource =
Tony Barboure804d202016-01-05 13:37:45 -07005012 "#version 400\n"
Chris Forbes2682b242015-11-24 11:13:14 +13005013 "#extension GL_ARB_separate_shader_objects: require\n"
5014 "#extension GL_ARB_shading_language_420pack: require\n"
5015 "\n"
5016 "layout(location=0) in vec4 x[2];\n"
Tony Barboure804d202016-01-05 13:37:45 -07005017 "out gl_PerVertex {\n"
5018 " vec4 gl_Position;\n"
5019 "};\n"
Chris Forbes2682b242015-11-24 11:13:14 +13005020 "void main(){\n"
5021 " gl_Position = x[0] + x[1];\n"
5022 "}\n";
5023 char const *fsSource =
Tony Barboure804d202016-01-05 13:37:45 -07005024 "#version 400\n"
Chris Forbes2682b242015-11-24 11:13:14 +13005025 "#extension GL_ARB_separate_shader_objects: require\n"
5026 "#extension GL_ARB_shading_language_420pack: require\n"
5027 "\n"
5028 "layout(location=0) out vec4 color;\n"
5029 "void main(){\n"
5030 " color = vec4(1);\n"
5031 "}\n";
5032
5033 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
5034 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
5035
5036 VkPipelineObj pipe(m_device);
5037 pipe.AddColorAttachment();
5038 pipe.AddShader(&vs);
5039 pipe.AddShader(&fs);
5040
5041 pipe.AddVertexInputBindings(&input_binding, 1);
5042 pipe.AddVertexInputAttribs(input_attribs, 2);
5043
5044 VkDescriptorSetObj descriptorSet(m_device);
5045 descriptorSet.AppendDummy();
5046 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
5047
5048 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
5049
5050 if (m_errorMonitor->DesiredMsgFound()) {
5051 FAIL() << "Expected to succeed but: " << m_errorMonitor->GetFailureMsg();
5052 m_errorMonitor->DumpFailureMsgs();
5053 }
5054}
5055*/
5056
Chris Forbes280ba2c2015-06-12 11:16:41 +12005057TEST_F(VkLayerTest, CreatePipelineAttribBindingConflict)
5058{
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07005059 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06005060 "Duplicate vertex input binding descriptions for binding 0");
5061
Chris Forbes280ba2c2015-06-12 11:16:41 +12005062 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06005063 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes280ba2c2015-06-12 11:16:41 +12005064
5065 /* Two binding descriptions for binding 0 */
5066 VkVertexInputBindingDescription input_bindings[2];
5067 memset(input_bindings, 0, sizeof(input_bindings));
5068
5069 VkVertexInputAttributeDescription input_attrib;
5070 memset(&input_attrib, 0, sizeof(input_attrib));
5071 input_attrib.format = VK_FORMAT_R32_SFLOAT;
5072
5073 char const *vsSource =
Tony Barboure804d202016-01-05 13:37:45 -07005074 "#version 400\n"
Chris Forbes280ba2c2015-06-12 11:16:41 +12005075 "#extension GL_ARB_separate_shader_objects: require\n"
5076 "#extension GL_ARB_shading_language_420pack: require\n"
5077 "\n"
5078 "layout(location=0) in float x;\n" /* attrib provided float */
Tony Barboure804d202016-01-05 13:37:45 -07005079 "out gl_PerVertex {\n"
5080 " vec4 gl_Position;\n"
5081 "};\n"
Chris Forbes280ba2c2015-06-12 11:16:41 +12005082 "void main(){\n"
5083 " gl_Position = vec4(x);\n"
5084 "}\n";
5085 char const *fsSource =
Tony Barboure804d202016-01-05 13:37:45 -07005086 "#version 400\n"
Chris Forbes280ba2c2015-06-12 11:16:41 +12005087 "#extension GL_ARB_separate_shader_objects: require\n"
5088 "#extension GL_ARB_shading_language_420pack: require\n"
5089 "\n"
5090 "layout(location=0) out vec4 color;\n"
5091 "void main(){\n"
5092 " color = vec4(1);\n"
5093 "}\n";
5094
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06005095 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
5096 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes280ba2c2015-06-12 11:16:41 +12005097
5098 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +08005099 pipe.AddColorAttachment();
Chris Forbes280ba2c2015-06-12 11:16:41 +12005100 pipe.AddShader(&vs);
5101 pipe.AddShader(&fs);
5102
5103 pipe.AddVertexInputBindings(input_bindings, 2);
5104 pipe.AddVertexInputAttribs(&input_attrib, 1);
5105
Chris Forbes280ba2c2015-06-12 11:16:41 +12005106 VkDescriptorSetObj descriptorSet(m_device);
5107 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005108 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes280ba2c2015-06-12 11:16:41 +12005109
Tony Barbour5781e8f2015-08-04 16:23:11 -06005110 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes280ba2c2015-06-12 11:16:41 +12005111
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06005112 if (!m_errorMonitor->DesiredMsgFound()) {
5113 FAIL() << "Did not receive Error 'Duplicate vertex input binding descriptions for binding 0'";
5114 m_errorMonitor->DumpFailureMsgs();
Chris Forbes280ba2c2015-06-12 11:16:41 +12005115 }
5116}
Chris Forbes8f68b562015-05-25 11:13:32 +12005117
Chris Forbes4d6d1e52015-05-25 11:13:40 +12005118TEST_F(VkLayerTest, CreatePipelineFragmentOutputNotWritten)
5119{
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07005120 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06005121 "Attachment 0 not written by FS");
5122
Chris Forbes4d6d1e52015-05-25 11:13:40 +12005123 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbes4d6d1e52015-05-25 11:13:40 +12005124
5125 char const *vsSource =
Tony Barboure804d202016-01-05 13:37:45 -07005126 "#version 400\n"
Chris Forbes4d6d1e52015-05-25 11:13:40 +12005127 "#extension GL_ARB_separate_shader_objects: require\n"
5128 "#extension GL_ARB_shading_language_420pack: require\n"
5129 "\n"
Tony Barboure804d202016-01-05 13:37:45 -07005130 "out gl_PerVertex {\n"
5131 " vec4 gl_Position;\n"
5132 "};\n"
Chris Forbes4d6d1e52015-05-25 11:13:40 +12005133 "void main(){\n"
5134 " gl_Position = vec4(1);\n"
5135 "}\n";
5136 char const *fsSource =
Tony Barboure804d202016-01-05 13:37:45 -07005137 "#version 400\n"
Chris Forbes4d6d1e52015-05-25 11:13:40 +12005138 "#extension GL_ARB_separate_shader_objects: require\n"
5139 "#extension GL_ARB_shading_language_420pack: require\n"
5140 "\n"
5141 "void main(){\n"
5142 "}\n";
5143
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06005144 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
5145 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes4d6d1e52015-05-25 11:13:40 +12005146
5147 VkPipelineObj pipe(m_device);
5148 pipe.AddShader(&vs);
5149 pipe.AddShader(&fs);
5150
Chia-I Wu08accc62015-07-07 11:50:03 +08005151 /* set up CB 0, not written */
5152 pipe.AddColorAttachment();
5153 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes4d6d1e52015-05-25 11:13:40 +12005154
Chris Forbes4d6d1e52015-05-25 11:13:40 +12005155 VkDescriptorSetObj descriptorSet(m_device);
5156 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005157 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes4d6d1e52015-05-25 11:13:40 +12005158
Tony Barbour5781e8f2015-08-04 16:23:11 -06005159 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes4d6d1e52015-05-25 11:13:40 +12005160
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06005161 if (!m_errorMonitor->DesiredMsgFound()) {
5162 FAIL() << "Did not receive Error 'Attachment 0 not written by FS'";
5163 m_errorMonitor->DumpFailureMsgs();
Chris Forbes4d6d1e52015-05-25 11:13:40 +12005164 }
5165}
5166
Chris Forbesf3fffaa2015-05-25 11:13:43 +12005167TEST_F(VkLayerTest, CreatePipelineFragmentOutputNotConsumed)
5168{
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07005169 // TODO: verify that this matches layer
5170 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARN_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06005171 "FS writes to output location 1 with no matching attachment");
5172
Chris Forbesf3fffaa2015-05-25 11:13:43 +12005173 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbesf3fffaa2015-05-25 11:13:43 +12005174
5175 char const *vsSource =
Tony Barboure804d202016-01-05 13:37:45 -07005176 "#version 400\n"
Chris Forbesf3fffaa2015-05-25 11:13:43 +12005177 "#extension GL_ARB_separate_shader_objects: require\n"
5178 "#extension GL_ARB_shading_language_420pack: require\n"
5179 "\n"
Tony Barboure804d202016-01-05 13:37:45 -07005180 "out gl_PerVertex {\n"
5181 " vec4 gl_Position;\n"
5182 "};\n"
Chris Forbesf3fffaa2015-05-25 11:13:43 +12005183 "void main(){\n"
5184 " gl_Position = vec4(1);\n"
5185 "}\n";
5186 char const *fsSource =
Tony Barboure804d202016-01-05 13:37:45 -07005187 "#version 400\n"
Chris Forbesf3fffaa2015-05-25 11:13:43 +12005188 "#extension GL_ARB_separate_shader_objects: require\n"
5189 "#extension GL_ARB_shading_language_420pack: require\n"
5190 "\n"
5191 "layout(location=0) out vec4 x;\n"
5192 "layout(location=1) out vec4 y;\n" /* no matching attachment for this */
5193 "void main(){\n"
5194 " x = vec4(1);\n"
5195 " y = vec4(1);\n"
5196 "}\n";
5197
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06005198 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
5199 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesf3fffaa2015-05-25 11:13:43 +12005200
5201 VkPipelineObj pipe(m_device);
5202 pipe.AddShader(&vs);
5203 pipe.AddShader(&fs);
5204
Chia-I Wu08accc62015-07-07 11:50:03 +08005205 /* set up CB 0, not written */
5206 pipe.AddColorAttachment();
5207 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesf3fffaa2015-05-25 11:13:43 +12005208 /* FS writes CB 1, but we don't configure it */
5209
Chris Forbesf3fffaa2015-05-25 11:13:43 +12005210 VkDescriptorSetObj descriptorSet(m_device);
5211 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005212 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesf3fffaa2015-05-25 11:13:43 +12005213
Tony Barbour5781e8f2015-08-04 16:23:11 -06005214 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesf3fffaa2015-05-25 11:13:43 +12005215
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06005216 if (!m_errorMonitor->DesiredMsgFound()) {
5217 FAIL() << "Did not receive Error 'FS writes to output location 1 with no matching attachment'";
5218 m_errorMonitor->DumpFailureMsgs();
Chris Forbesf3fffaa2015-05-25 11:13:43 +12005219 }
5220}
5221
Chris Forbesa36d69e2015-05-25 11:13:44 +12005222TEST_F(VkLayerTest, CreatePipelineFragmentOutputTypeMismatch)
5223{
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07005224 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06005225 "does not match FS output type");
5226
Chris Forbesa36d69e2015-05-25 11:13:44 +12005227 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbesa36d69e2015-05-25 11:13:44 +12005228
5229 char const *vsSource =
Tony Barboure804d202016-01-05 13:37:45 -07005230 "#version 400\n"
Chris Forbesa36d69e2015-05-25 11:13:44 +12005231 "#extension GL_ARB_separate_shader_objects: require\n"
5232 "#extension GL_ARB_shading_language_420pack: require\n"
5233 "\n"
Tony Barboure804d202016-01-05 13:37:45 -07005234 "out gl_PerVertex {\n"
5235 " vec4 gl_Position;\n"
5236 "};\n"
Chris Forbesa36d69e2015-05-25 11:13:44 +12005237 "void main(){\n"
5238 " gl_Position = vec4(1);\n"
5239 "}\n";
5240 char const *fsSource =
Tony Barboure804d202016-01-05 13:37:45 -07005241 "#version 400\n"
Chris Forbesa36d69e2015-05-25 11:13:44 +12005242 "#extension GL_ARB_separate_shader_objects: require\n"
5243 "#extension GL_ARB_shading_language_420pack: require\n"
5244 "\n"
5245 "layout(location=0) out ivec4 x;\n" /* not UNORM */
5246 "void main(){\n"
5247 " x = ivec4(1);\n"
5248 "}\n";
5249
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06005250 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
5251 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesa36d69e2015-05-25 11:13:44 +12005252
5253 VkPipelineObj pipe(m_device);
5254 pipe.AddShader(&vs);
5255 pipe.AddShader(&fs);
5256
Chia-I Wu08accc62015-07-07 11:50:03 +08005257 /* set up CB 0; type is UNORM by default */
5258 pipe.AddColorAttachment();
5259 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesa36d69e2015-05-25 11:13:44 +12005260
Chris Forbesa36d69e2015-05-25 11:13:44 +12005261 VkDescriptorSetObj descriptorSet(m_device);
5262 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005263 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesa36d69e2015-05-25 11:13:44 +12005264
Tony Barbour5781e8f2015-08-04 16:23:11 -06005265 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesa36d69e2015-05-25 11:13:44 +12005266
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06005267 if (!m_errorMonitor->DesiredMsgFound()) {
5268 FAIL() << "Did not receive Error 'does not match FS output type'";
5269 m_errorMonitor->DumpFailureMsgs();
Chris Forbesa36d69e2015-05-25 11:13:44 +12005270 }
5271}
Chris Forbes7b1b8932015-06-05 14:43:36 +12005272
Chris Forbes556c76c2015-08-14 12:04:59 +12005273TEST_F(VkLayerTest, CreatePipelineUniformBlockNotProvided)
5274{
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07005275 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06005276 "not declared in pipeline layout");
5277
Chris Forbes556c76c2015-08-14 12:04:59 +12005278 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbes556c76c2015-08-14 12:04:59 +12005279
5280 char const *vsSource =
Tony Barboure804d202016-01-05 13:37:45 -07005281 "#version 400\n"
Chris Forbes556c76c2015-08-14 12:04:59 +12005282 "#extension GL_ARB_separate_shader_objects: require\n"
5283 "#extension GL_ARB_shading_language_420pack: require\n"
5284 "\n"
Tony Barboure804d202016-01-05 13:37:45 -07005285 "out gl_PerVertex {\n"
5286 " vec4 gl_Position;\n"
5287 "};\n"
Chris Forbes556c76c2015-08-14 12:04:59 +12005288 "void main(){\n"
5289 " gl_Position = vec4(1);\n"
5290 "}\n";
5291 char const *fsSource =
Tony Barboure804d202016-01-05 13:37:45 -07005292 "#version 400\n"
Chris Forbes556c76c2015-08-14 12:04:59 +12005293 "#extension GL_ARB_separate_shader_objects: require\n"
5294 "#extension GL_ARB_shading_language_420pack: require\n"
5295 "\n"
5296 "layout(location=0) out vec4 x;\n"
5297 "layout(set=0) layout(binding=0) uniform foo { int x; int y; } bar;\n"
5298 "void main(){\n"
5299 " x = vec4(bar.y);\n"
5300 "}\n";
5301
Chris Forbes556c76c2015-08-14 12:04:59 +12005302
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06005303 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
5304 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes556c76c2015-08-14 12:04:59 +12005305
Chris Forbes556c76c2015-08-14 12:04:59 +12005306 VkPipelineObj pipe(m_device);
5307 pipe.AddShader(&vs);
5308 pipe.AddShader(&fs);
5309
5310 /* set up CB 0; type is UNORM by default */
5311 pipe.AddColorAttachment();
5312 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
5313
5314 VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005315 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes556c76c2015-08-14 12:04:59 +12005316
5317 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
5318
5319 /* should have generated an error -- pipeline layout does not
5320 * provide a uniform buffer in 0.0
5321 */
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06005322 if (!m_errorMonitor->DesiredMsgFound()) {
5323 FAIL() << "Did not receive Error 'not declared in pipeline layout'";
5324 m_errorMonitor->DumpFailureMsgs();
Chris Forbes556c76c2015-08-14 12:04:59 +12005325 }
5326}
5327
Mark Lobodzinski209b5292015-09-17 09:44:05 -06005328#endif // SHADER_CHECKER_TESTS
5329
5330#if DEVICE_LIMITS_TESTS
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -06005331TEST_F(VkLayerTest, CreateImageLimitsViolationWidth)
5332{
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07005333 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06005334 "CreateImage extents exceed allowable limits for format");
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -06005335
5336 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -06005337
5338 // Create an image
5339 VkImage image;
5340
5341 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
5342 const int32_t tex_width = 32;
5343 const int32_t tex_height = 32;
5344
5345 VkImageCreateInfo image_create_info = {};
5346 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
5347 image_create_info.pNext = NULL;
5348 image_create_info.imageType = VK_IMAGE_TYPE_2D;
5349 image_create_info.format = tex_format;
5350 image_create_info.extent.width = tex_width;
5351 image_create_info.extent.height = tex_height;
5352 image_create_info.extent.depth = 1;
5353 image_create_info.mipLevels = 1;
Courtney Goeltzenleuchter5d2aed42015-10-21 17:57:31 -06005354 image_create_info.arrayLayers = 1;
Chia-I Wu5c17c962015-10-31 00:31:16 +08005355 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -06005356 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
5357 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
5358 image_create_info.flags = 0;
5359
5360 // Introduce error by sending down a bogus width extent
5361 image_create_info.extent.width = 65536;
Chia-I Wuf7458c52015-10-26 21:10:41 +08005362 vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -06005363
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06005364 if (!m_errorMonitor->DesiredMsgFound()) {
5365 FAIL() << "Did not receive Error 'CreateImage extents exceed allowable limits for format'";
5366 m_errorMonitor->DumpFailureMsgs();
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -06005367 }
5368}
5369
5370TEST_F(VkLayerTest, CreateImageResourceSizeViolation)
5371{
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07005372 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06005373 "CreateImage resource size exceeds allowable maximum");
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -06005374
5375 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -06005376
5377 // Create an image
5378 VkImage image;
5379
5380 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
5381 const int32_t tex_width = 32;
5382 const int32_t tex_height = 32;
5383
5384 VkImageCreateInfo image_create_info = {};
5385 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
5386 image_create_info.pNext = NULL;
5387 image_create_info.imageType = VK_IMAGE_TYPE_2D;
5388 image_create_info.format = tex_format;
5389 image_create_info.extent.width = tex_width;
5390 image_create_info.extent.height = tex_height;
5391 image_create_info.extent.depth = 1;
5392 image_create_info.mipLevels = 1;
Courtney Goeltzenleuchter5d2aed42015-10-21 17:57:31 -06005393 image_create_info.arrayLayers = 1;
Chia-I Wu5c17c962015-10-31 00:31:16 +08005394 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -06005395 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
5396 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
5397 image_create_info.flags = 0;
5398
5399 // Introduce error by sending down individually allowable values that result in a surface size
5400 // exceeding the device maximum
5401 image_create_info.extent.width = 8192;
5402 image_create_info.extent.height = 8192;
5403 image_create_info.extent.depth = 16;
Courtney Goeltzenleuchter5d2aed42015-10-21 17:57:31 -06005404 image_create_info.arrayLayers = 4;
Chia-I Wu5c17c962015-10-31 00:31:16 +08005405 image_create_info.samples = VK_SAMPLE_COUNT_2_BIT;
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -06005406 image_create_info.format = VK_FORMAT_R8G8B8A8_UNORM;
Chia-I Wuf7458c52015-10-26 21:10:41 +08005407 vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -06005408
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06005409 if (!m_errorMonitor->DesiredMsgFound()) {
5410 FAIL() << "Did not receive Error 'CreateImage resource size exceeds allowable maximum'";
5411 m_errorMonitor->DumpFailureMsgs();
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -06005412 }
5413}
5414
Mike Stroyana3082432015-09-25 13:39:21 -06005415TEST_F(VkLayerTest, UpdateBufferAlignment)
5416{
Mike Stroyana3082432015-09-25 13:39:21 -06005417 uint32_t updateData[] = { 1, 2, 3, 4, 5, 6, 7, 8 };
5418
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07005419 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06005420 "dstOffset, is not a multiple of 4");
5421
Mike Stroyana3082432015-09-25 13:39:21 -06005422 ASSERT_NO_FATAL_FAILURE(InitState());
5423
5424 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
5425 vk_testing::Buffer buffer;
5426 buffer.init_as_dst(*m_device, (VkDeviceSize)20, reqs);
5427
5428 BeginCommandBuffer();
5429 // Introduce failure by using offset that is not multiple of 4
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005430 m_commandBuffer->UpdateBuffer(buffer.handle(), 1, 4, updateData);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06005431 if (!m_errorMonitor->DesiredMsgFound()) {
5432 FAIL() << "Did not receive Error 'vkCommandUpdateBuffer parameter, VkDeviceSize dstOffset, is not a multiple of 4'";
5433 m_errorMonitor->DumpFailureMsgs();
Mike Stroyana3082432015-09-25 13:39:21 -06005434 }
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06005435
Mike Stroyana3082432015-09-25 13:39:21 -06005436 // Introduce failure by using size that is not multiple of 4
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07005437 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06005438 "dataSize, is not a multiple of 4");
5439
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005440 m_commandBuffer->UpdateBuffer(buffer.handle(), 0, 6, updateData);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06005441
5442 if (!m_errorMonitor->DesiredMsgFound()) {
5443 FAIL() << "Did not receive Error 'vkCommandUpdateBuffer parameter, VkDeviceSize dataSize, is not a multiple of 4'";
5444 m_errorMonitor->DumpFailureMsgs();
Mike Stroyana3082432015-09-25 13:39:21 -06005445 }
5446 EndCommandBuffer();
5447}
5448
5449TEST_F(VkLayerTest, FillBufferAlignment)
5450{
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07005451 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06005452 "dstOffset, is not a multiple of 4");
Mike Stroyana3082432015-09-25 13:39:21 -06005453
5454 ASSERT_NO_FATAL_FAILURE(InitState());
5455
5456 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
5457 vk_testing::Buffer buffer;
5458 buffer.init_as_dst(*m_device, (VkDeviceSize)20, reqs);
5459
5460 BeginCommandBuffer();
5461 // Introduce failure by using offset that is not multiple of 4
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005462 m_commandBuffer->FillBuffer(buffer.handle(), 1, 4, 0x11111111);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06005463 if (!m_errorMonitor->DesiredMsgFound()) {
5464 FAIL() << "Did not receive Error 'vkCommandFillBuffer parameter, VkDeviceSize dstOffset, is not a multiple of 4'";
5465 m_errorMonitor->DumpFailureMsgs();
Mike Stroyana3082432015-09-25 13:39:21 -06005466 }
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06005467
Mike Stroyana3082432015-09-25 13:39:21 -06005468 // Introduce failure by using size that is not multiple of 4
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07005469 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06005470 "size, is not a multiple of 4");
5471
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005472 m_commandBuffer->FillBuffer(buffer.handle(), 0, 6, 0x11111111);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06005473
5474 if (!m_errorMonitor->DesiredMsgFound()) {
5475 FAIL() << "Did not receive Error 'vkCommandFillBuffer parameter, VkDeviceSize size, is not a multiple of 4'";
5476 m_errorMonitor->DumpFailureMsgs();
Mike Stroyana3082432015-09-25 13:39:21 -06005477 }
5478 EndCommandBuffer();
5479}
5480
Mark Lobodzinski209b5292015-09-17 09:44:05 -06005481#endif // DEVICE_LIMITS_TESTS
Chris Forbesa36d69e2015-05-25 11:13:44 +12005482
Tobin Ehliscde08892015-09-22 10:11:37 -06005483#if IMAGE_TESTS
5484TEST_F(VkLayerTest, InvalidImageView)
5485{
Tobin Ehliscde08892015-09-22 10:11:37 -06005486 VkResult err;
5487
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07005488 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06005489 "vkCreateImageView called with baseMipLevel 10 ");
5490
Tobin Ehliscde08892015-09-22 10:11:37 -06005491 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehliscde08892015-09-22 10:11:37 -06005492
Mike Stroyana3082432015-09-25 13:39:21 -06005493 // Create an image and try to create a view with bad baseMipLevel
Tobin Ehliscde08892015-09-22 10:11:37 -06005494 VkImage image;
5495
5496 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
5497 const int32_t tex_width = 32;
5498 const int32_t tex_height = 32;
5499
5500 VkImageCreateInfo image_create_info = {};
5501 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
5502 image_create_info.pNext = NULL;
5503 image_create_info.imageType = VK_IMAGE_TYPE_2D;
5504 image_create_info.format = tex_format;
5505 image_create_info.extent.width = tex_width;
5506 image_create_info.extent.height = tex_height;
5507 image_create_info.extent.depth = 1;
5508 image_create_info.mipLevels = 1;
Courtney Goeltzenleuchter5d2aed42015-10-21 17:57:31 -06005509 image_create_info.arrayLayers = 1;
Chia-I Wu5c17c962015-10-31 00:31:16 +08005510 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Tobin Ehliscde08892015-09-22 10:11:37 -06005511 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
5512 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
5513 image_create_info.flags = 0;
5514
Chia-I Wuf7458c52015-10-26 21:10:41 +08005515 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Tobin Ehliscde08892015-09-22 10:11:37 -06005516 ASSERT_VK_SUCCESS(err);
5517
5518 VkImageViewCreateInfo image_view_create_info = {};
5519 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
5520 image_view_create_info.image = image;
5521 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
5522 image_view_create_info.format = tex_format;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005523 image_view_create_info.subresourceRange.layerCount = 1;
Tobin Ehliscde08892015-09-22 10:11:37 -06005524 image_view_create_info.subresourceRange.baseMipLevel = 10; // cause an error
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005525 image_view_create_info.subresourceRange.levelCount = 1;
Mark Lobodzinskidc86b852015-10-23 14:20:31 -06005526 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Tobin Ehliscde08892015-09-22 10:11:37 -06005527
5528 VkImageView view;
Chia-I Wuf7458c52015-10-26 21:10:41 +08005529 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
Tobin Ehliscde08892015-09-22 10:11:37 -06005530
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06005531 if (!m_errorMonitor->DesiredMsgFound()) {
5532 FAIL() << "Did not receive Error 'vkCreateImageView called with baseMipLevel 10...'";
5533 m_errorMonitor->DumpFailureMsgs();
Tobin Ehliscde08892015-09-22 10:11:37 -06005534 }
5535}
Mike Stroyana3082432015-09-25 13:39:21 -06005536
Mark Lobodzinskidc86b852015-10-23 14:20:31 -06005537TEST_F(VkLayerTest, InvalidImageViewAspect)
5538{
Mark Lobodzinskidc86b852015-10-23 14:20:31 -06005539 VkResult err;
5540
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07005541 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06005542 "vkCreateImageView: Color image formats must have ONLY the VK_IMAGE_ASPECT_COLOR_BIT set");
5543
Mark Lobodzinskidc86b852015-10-23 14:20:31 -06005544 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskidc86b852015-10-23 14:20:31 -06005545
5546 // Create an image and try to create a view with an invalid aspectMask
5547 VkImage image;
5548
5549 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
5550 const int32_t tex_width = 32;
5551 const int32_t tex_height = 32;
5552
5553 VkImageCreateInfo image_create_info = {};
5554 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
5555 image_create_info.pNext = NULL;
5556 image_create_info.imageType = VK_IMAGE_TYPE_2D;
5557 image_create_info.format = tex_format;
5558 image_create_info.extent.width = tex_width;
5559 image_create_info.extent.height = tex_height;
5560 image_create_info.extent.depth = 1;
5561 image_create_info.mipLevels = 1;
Chia-I Wu5c17c962015-10-31 00:31:16 +08005562 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Mark Lobodzinskidc86b852015-10-23 14:20:31 -06005563 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
5564 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
5565 image_create_info.flags = 0;
5566
Chia-I Wuf7458c52015-10-26 21:10:41 +08005567 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Mark Lobodzinskidc86b852015-10-23 14:20:31 -06005568 ASSERT_VK_SUCCESS(err);
5569
5570 VkImageViewCreateInfo image_view_create_info = {};
5571 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
5572 image_view_create_info.image = image;
5573 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
5574 image_view_create_info.format = tex_format;
5575 image_view_create_info.subresourceRange.baseMipLevel = 0;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005576 image_view_create_info.subresourceRange.levelCount = 1;
Mark Lobodzinskidc86b852015-10-23 14:20:31 -06005577 // Cause an error by setting an invalid image aspect
5578 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_METADATA_BIT;
5579
5580 VkImageView view;
Chia-I Wuf7458c52015-10-26 21:10:41 +08005581 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
Mark Lobodzinskidc86b852015-10-23 14:20:31 -06005582
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06005583 if (!m_errorMonitor->DesiredMsgFound()) {
5584 FAIL() << "Did not receive Error 'VkCreateImageView: Color image formats must have ...'";
5585 m_errorMonitor->DumpFailureMsgs();
Mark Lobodzinskidc86b852015-10-23 14:20:31 -06005586 }
5587}
5588
Mike Stroyana3082432015-09-25 13:39:21 -06005589TEST_F(VkLayerTest, CopyImageTypeMismatch)
5590{
Mike Stroyana3082432015-09-25 13:39:21 -06005591 VkResult err;
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -06005592 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -06005593
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07005594 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06005595 "vkCmdCopyImage called with unmatched source and dest image types");
5596
Mike Stroyana3082432015-09-25 13:39:21 -06005597 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -06005598
5599 // Create two images of different types and try to copy between them
5600 VkImage srcImage;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005601 VkImage dstImage;
Mike Stroyana3082432015-09-25 13:39:21 -06005602 VkDeviceMemory srcMem;
5603 VkDeviceMemory destMem;
5604 VkMemoryRequirements memReqs;
5605
5606 VkImageCreateInfo image_create_info = {};
5607 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
5608 image_create_info.pNext = NULL;
5609 image_create_info.imageType = VK_IMAGE_TYPE_2D;
5610 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
5611 image_create_info.extent.width = 32;
5612 image_create_info.extent.height = 32;
5613 image_create_info.extent.depth = 1;
5614 image_create_info.mipLevels = 1;
Courtney Goeltzenleuchter5d2aed42015-10-21 17:57:31 -06005615 image_create_info.arrayLayers = 1;
Chia-I Wu5c17c962015-10-31 00:31:16 +08005616 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -06005617 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005618 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -06005619 image_create_info.flags = 0;
5620
Chia-I Wuf7458c52015-10-26 21:10:41 +08005621 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -06005622 ASSERT_VK_SUCCESS(err);
5623
5624 image_create_info.imageType = VK_IMAGE_TYPE_1D;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005625 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -06005626
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005627 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -06005628 ASSERT_VK_SUCCESS(err);
5629
5630 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005631 VkMemoryAllocateInfo memAlloc = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08005632 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
Mike Stroyana3082432015-09-25 13:39:21 -06005633 memAlloc.pNext = NULL;
5634 memAlloc.allocationSize = 0;
5635 memAlloc.memoryTypeIndex = 0;
5636
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -06005637 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -06005638 memAlloc.allocationSize = memReqs.size;
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -06005639 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
5640 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005641 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -06005642 ASSERT_VK_SUCCESS(err);
5643
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005644 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -06005645 memAlloc.allocationSize = memReqs.size;
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -06005646 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Mike Stroyana3082432015-09-25 13:39:21 -06005647 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005648 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -06005649 ASSERT_VK_SUCCESS(err);
5650
5651 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
5652 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005653 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -06005654 ASSERT_VK_SUCCESS(err);
5655
5656 BeginCommandBuffer();
5657 VkImageCopy copyRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +08005658 copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -06005659 copyRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -06005660 copyRegion.srcSubresource.baseArrayLayer = 0;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005661 copyRegion.srcSubresource.layerCount = 0;
Mike Stroyana3082432015-09-25 13:39:21 -06005662 copyRegion.srcOffset.x = 0;
5663 copyRegion.srcOffset.y = 0;
5664 copyRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +08005665 copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005666 copyRegion.dstSubresource.mipLevel = 0;
5667 copyRegion.dstSubresource.baseArrayLayer = 0;
5668 copyRegion.dstSubresource.layerCount = 0;
5669 copyRegion.dstOffset.x = 0;
5670 copyRegion.dstOffset.y = 0;
5671 copyRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -06005672 copyRegion.extent.width = 1;
5673 copyRegion.extent.height = 1;
5674 copyRegion.extent.depth = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005675 m_commandBuffer->CopyImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
Mike Stroyana3082432015-09-25 13:39:21 -06005676 EndCommandBuffer();
5677
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06005678 if (!m_errorMonitor->DesiredMsgFound()) {
5679 FAIL() << "Did not receive Error 'vkCmdCopyImage called with unmatched source and dest image types'";
5680 m_errorMonitor->DumpFailureMsgs();
Mike Stroyana3082432015-09-25 13:39:21 -06005681 }
5682
Chia-I Wuf7458c52015-10-26 21:10:41 +08005683 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005684 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +08005685 vkFreeMemory(m_device->device(), srcMem, NULL);
5686 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -06005687}
5688
5689TEST_F(VkLayerTest, CopyImageFormatSizeMismatch)
5690{
5691 // TODO : Create two images with different format sizes and vkCmdCopyImage between them
5692}
5693
5694TEST_F(VkLayerTest, CopyImageDepthStencilFormatMismatch)
5695{
Mike Stroyana3082432015-09-25 13:39:21 -06005696 VkResult err;
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -06005697 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -06005698
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07005699 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06005700 "vkCmdCopyImage called with unmatched source and dest image types");
5701
Mike Stroyana3082432015-09-25 13:39:21 -06005702 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -06005703
5704 // Create two images of different types and try to copy between them
5705 VkImage srcImage;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005706 VkImage dstImage;
Mike Stroyana3082432015-09-25 13:39:21 -06005707 VkDeviceMemory srcMem;
5708 VkDeviceMemory destMem;
5709 VkMemoryRequirements memReqs;
5710
5711 VkImageCreateInfo image_create_info = {};
5712 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
5713 image_create_info.pNext = NULL;
5714 image_create_info.imageType = VK_IMAGE_TYPE_2D;
5715 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
5716 image_create_info.extent.width = 32;
5717 image_create_info.extent.height = 32;
5718 image_create_info.extent.depth = 1;
5719 image_create_info.mipLevels = 1;
Courtney Goeltzenleuchter5d2aed42015-10-21 17:57:31 -06005720 image_create_info.arrayLayers = 1;
Chia-I Wu5c17c962015-10-31 00:31:16 +08005721 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -06005722 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005723 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -06005724 image_create_info.flags = 0;
5725
Chia-I Wuf7458c52015-10-26 21:10:41 +08005726 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -06005727 ASSERT_VK_SUCCESS(err);
5728
5729 image_create_info.imageType = VK_IMAGE_TYPE_1D;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005730 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -06005731
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005732 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -06005733 ASSERT_VK_SUCCESS(err);
5734
5735 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005736 VkMemoryAllocateInfo memAlloc = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08005737 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
Mike Stroyana3082432015-09-25 13:39:21 -06005738 memAlloc.pNext = NULL;
5739 memAlloc.allocationSize = 0;
5740 memAlloc.memoryTypeIndex = 0;
5741
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -06005742 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -06005743 memAlloc.allocationSize = memReqs.size;
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -06005744 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
5745 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005746 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -06005747 ASSERT_VK_SUCCESS(err);
5748
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005749 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -06005750 memAlloc.allocationSize = memReqs.size;
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -06005751 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
5752 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005753 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -06005754 ASSERT_VK_SUCCESS(err);
5755
5756 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
5757 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005758 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -06005759 ASSERT_VK_SUCCESS(err);
5760
5761 BeginCommandBuffer();
5762 VkImageCopy copyRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +08005763 copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -06005764 copyRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -06005765 copyRegion.srcSubresource.baseArrayLayer = 0;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005766 copyRegion.srcSubresource.layerCount = 0;
Mike Stroyana3082432015-09-25 13:39:21 -06005767 copyRegion.srcOffset.x = 0;
5768 copyRegion.srcOffset.y = 0;
5769 copyRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +08005770 copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005771 copyRegion.dstSubresource.mipLevel = 0;
5772 copyRegion.dstSubresource.baseArrayLayer = 0;
5773 copyRegion.dstSubresource.layerCount = 0;
5774 copyRegion.dstOffset.x = 0;
5775 copyRegion.dstOffset.y = 0;
5776 copyRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -06005777 copyRegion.extent.width = 1;
5778 copyRegion.extent.height = 1;
5779 copyRegion.extent.depth = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005780 m_commandBuffer->CopyImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
Mike Stroyana3082432015-09-25 13:39:21 -06005781 EndCommandBuffer();
5782
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06005783 if (!m_errorMonitor->DesiredMsgFound()) {
5784 FAIL() << "Did not receive Error 'vkCmdCopyImage called with unmatched source and dest image types'";
5785 m_errorMonitor->DumpFailureMsgs();
Mike Stroyana3082432015-09-25 13:39:21 -06005786 }
5787
Chia-I Wuf7458c52015-10-26 21:10:41 +08005788 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005789 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +08005790 vkFreeMemory(m_device->device(), srcMem, NULL);
5791 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -06005792}
5793
5794TEST_F(VkLayerTest, ResolveImageLowSampleCount)
5795{
Mike Stroyana3082432015-09-25 13:39:21 -06005796 VkResult err;
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -06005797 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -06005798
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07005799 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06005800 "vkCmdResolveImage called with source sample count less than 2.");
5801
Mike Stroyana3082432015-09-25 13:39:21 -06005802 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -06005803
5804 // Create two images of sample count 1 and try to Resolve between them
5805 VkImage srcImage;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005806 VkImage dstImage;
Mike Stroyana3082432015-09-25 13:39:21 -06005807 VkDeviceMemory srcMem;
5808 VkDeviceMemory destMem;
5809 VkMemoryRequirements memReqs;
5810
5811 VkImageCreateInfo image_create_info = {};
5812 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
5813 image_create_info.pNext = NULL;
5814 image_create_info.imageType = VK_IMAGE_TYPE_2D;
5815 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
5816 image_create_info.extent.width = 32;
5817 image_create_info.extent.height = 1;
5818 image_create_info.extent.depth = 1;
5819 image_create_info.mipLevels = 1;
Courtney Goeltzenleuchter5d2aed42015-10-21 17:57:31 -06005820 image_create_info.arrayLayers = 1;
Chia-I Wu5c17c962015-10-31 00:31:16 +08005821 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -06005822 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005823 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -06005824 image_create_info.flags = 0;
5825
Chia-I Wuf7458c52015-10-26 21:10:41 +08005826 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -06005827 ASSERT_VK_SUCCESS(err);
5828
5829 image_create_info.imageType = VK_IMAGE_TYPE_1D;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005830 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -06005831
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005832 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -06005833 ASSERT_VK_SUCCESS(err);
5834
5835 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005836 VkMemoryAllocateInfo memAlloc = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08005837 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
Mike Stroyana3082432015-09-25 13:39:21 -06005838 memAlloc.pNext = NULL;
5839 memAlloc.allocationSize = 0;
5840 memAlloc.memoryTypeIndex = 0;
5841
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -06005842 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -06005843 memAlloc.allocationSize = memReqs.size;
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -06005844 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
5845 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005846 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -06005847 ASSERT_VK_SUCCESS(err);
5848
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005849 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -06005850 memAlloc.allocationSize = memReqs.size;
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -06005851 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
5852 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005853 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -06005854 ASSERT_VK_SUCCESS(err);
5855
5856 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
5857 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005858 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -06005859 ASSERT_VK_SUCCESS(err);
5860
5861 BeginCommandBuffer();
5862 // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest?
5863 //VK_IMAGE_LAYOUT_UNDEFINED = 0,
5864 //VK_IMAGE_LAYOUT_GENERAL = 1,
5865 VkImageResolve resolveRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +08005866 resolveRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -06005867 resolveRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -06005868 resolveRegion.srcSubresource.baseArrayLayer = 0;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005869 resolveRegion.srcSubresource.layerCount = 0;
Mike Stroyana3082432015-09-25 13:39:21 -06005870 resolveRegion.srcOffset.x = 0;
5871 resolveRegion.srcOffset.y = 0;
5872 resolveRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +08005873 resolveRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005874 resolveRegion.dstSubresource.mipLevel = 0;
5875 resolveRegion.dstSubresource.baseArrayLayer = 0;
5876 resolveRegion.dstSubresource.layerCount = 0;
5877 resolveRegion.dstOffset.x = 0;
5878 resolveRegion.dstOffset.y = 0;
5879 resolveRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -06005880 resolveRegion.extent.width = 1;
5881 resolveRegion.extent.height = 1;
5882 resolveRegion.extent.depth = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005883 m_commandBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion);
Mike Stroyana3082432015-09-25 13:39:21 -06005884 EndCommandBuffer();
5885
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06005886 if (!m_errorMonitor->DesiredMsgFound()) {
5887 FAIL() << "Did not receive Error 'vkCmdResolveImage called with source sample count less than 2.'";
5888 m_errorMonitor->DumpFailureMsgs();
Mike Stroyana3082432015-09-25 13:39:21 -06005889 }
5890
Chia-I Wuf7458c52015-10-26 21:10:41 +08005891 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005892 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +08005893 vkFreeMemory(m_device->device(), srcMem, NULL);
5894 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -06005895}
5896
5897TEST_F(VkLayerTest, ResolveImageHighSampleCount)
5898{
Mike Stroyana3082432015-09-25 13:39:21 -06005899 VkResult err;
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -06005900 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -06005901
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07005902 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06005903 "vkCmdResolveImage called with dest sample count greater than 1.");
5904
Mike Stroyana3082432015-09-25 13:39:21 -06005905 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -06005906
5907 // Create two images of sample count 2 and try to Resolve between them
5908 VkImage srcImage;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005909 VkImage dstImage;
Mike Stroyana3082432015-09-25 13:39:21 -06005910 VkDeviceMemory srcMem;
5911 VkDeviceMemory destMem;
5912 VkMemoryRequirements memReqs;
5913
5914 VkImageCreateInfo image_create_info = {};
5915 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
5916 image_create_info.pNext = NULL;
5917 image_create_info.imageType = VK_IMAGE_TYPE_2D;
5918 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
5919 image_create_info.extent.width = 32;
5920 image_create_info.extent.height = 1;
5921 image_create_info.extent.depth = 1;
5922 image_create_info.mipLevels = 1;
Courtney Goeltzenleuchter5d2aed42015-10-21 17:57:31 -06005923 image_create_info.arrayLayers = 1;
Chia-I Wu5c17c962015-10-31 00:31:16 +08005924 image_create_info.samples = VK_SAMPLE_COUNT_2_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -06005925 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
Cody Northrop72458c02015-10-27 13:50:04 -06005926 // Note: Some implementations expect color attachment usage for any multisample surface
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005927 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -06005928 image_create_info.flags = 0;
5929
Chia-I Wuf7458c52015-10-26 21:10:41 +08005930 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -06005931 ASSERT_VK_SUCCESS(err);
5932
5933 image_create_info.imageType = VK_IMAGE_TYPE_1D;
Cody Northrop72458c02015-10-27 13:50:04 -06005934 // Note: Some implementations expect color attachment usage for any multisample surface
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005935 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -06005936
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005937 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -06005938 ASSERT_VK_SUCCESS(err);
5939
5940 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005941 VkMemoryAllocateInfo memAlloc = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08005942 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
Mike Stroyana3082432015-09-25 13:39:21 -06005943 memAlloc.pNext = NULL;
5944 memAlloc.allocationSize = 0;
5945 memAlloc.memoryTypeIndex = 0;
5946
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -06005947 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -06005948 memAlloc.allocationSize = memReqs.size;
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -06005949 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
5950 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005951 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -06005952 ASSERT_VK_SUCCESS(err);
5953
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005954 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -06005955 memAlloc.allocationSize = memReqs.size;
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -06005956 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
5957 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005958 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -06005959 ASSERT_VK_SUCCESS(err);
5960
5961 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
5962 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005963 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -06005964 ASSERT_VK_SUCCESS(err);
5965
5966 BeginCommandBuffer();
5967 // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest?
5968 //VK_IMAGE_LAYOUT_UNDEFINED = 0,
5969 //VK_IMAGE_LAYOUT_GENERAL = 1,
5970 VkImageResolve resolveRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +08005971 resolveRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -06005972 resolveRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -06005973 resolveRegion.srcSubresource.baseArrayLayer = 0;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005974 resolveRegion.srcSubresource.layerCount = 0;
Mike Stroyana3082432015-09-25 13:39:21 -06005975 resolveRegion.srcOffset.x = 0;
5976 resolveRegion.srcOffset.y = 0;
5977 resolveRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +08005978 resolveRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005979 resolveRegion.dstSubresource.mipLevel = 0;
5980 resolveRegion.dstSubresource.baseArrayLayer = 0;
5981 resolveRegion.dstSubresource.layerCount = 0;
5982 resolveRegion.dstOffset.x = 0;
5983 resolveRegion.dstOffset.y = 0;
5984 resolveRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -06005985 resolveRegion.extent.width = 1;
5986 resolveRegion.extent.height = 1;
5987 resolveRegion.extent.depth = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005988 m_commandBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion);
Mike Stroyana3082432015-09-25 13:39:21 -06005989 EndCommandBuffer();
5990
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06005991 if (!m_errorMonitor->DesiredMsgFound()) {
5992 FAIL() << "Did not receive Error 'vkCmdResolveImage called with dest sample count greater than 1.'";
5993 m_errorMonitor->DumpFailureMsgs();
Mike Stroyana3082432015-09-25 13:39:21 -06005994 }
5995
Chia-I Wuf7458c52015-10-26 21:10:41 +08005996 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005997 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +08005998 vkFreeMemory(m_device->device(), srcMem, NULL);
5999 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -06006000}
6001
6002TEST_F(VkLayerTest, ResolveImageFormatMismatch)
6003{
Mike Stroyana3082432015-09-25 13:39:21 -06006004 VkResult err;
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -06006005 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -06006006
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07006007 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06006008 "vkCmdResolveImage called with unmatched source and dest formats.");
6009
Mike Stroyana3082432015-09-25 13:39:21 -06006010 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -06006011
6012 // Create two images of different types and try to copy between them
6013 VkImage srcImage;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006014 VkImage dstImage;
Mike Stroyana3082432015-09-25 13:39:21 -06006015 VkDeviceMemory srcMem;
6016 VkDeviceMemory destMem;
6017 VkMemoryRequirements memReqs;
6018
6019 VkImageCreateInfo image_create_info = {};
6020 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
6021 image_create_info.pNext = NULL;
6022 image_create_info.imageType = VK_IMAGE_TYPE_2D;
6023 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
6024 image_create_info.extent.width = 32;
6025 image_create_info.extent.height = 1;
6026 image_create_info.extent.depth = 1;
6027 image_create_info.mipLevels = 1;
Courtney Goeltzenleuchter5d2aed42015-10-21 17:57:31 -06006028 image_create_info.arrayLayers = 1;
Chia-I Wu5c17c962015-10-31 00:31:16 +08006029 image_create_info.samples = VK_SAMPLE_COUNT_2_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -06006030 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
Cody Northrop72458c02015-10-27 13:50:04 -06006031 // Note: Some implementations expect color attachment usage for any multisample surface
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006032 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -06006033 image_create_info.flags = 0;
6034
Chia-I Wuf7458c52015-10-26 21:10:41 +08006035 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -06006036 ASSERT_VK_SUCCESS(err);
6037
Cody Northrop72458c02015-10-27 13:50:04 -06006038 // Set format to something other than source image
6039 image_create_info.format = VK_FORMAT_R32_SFLOAT;
6040 // Note: Some implementations expect color attachment usage for any multisample surface
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006041 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Chia-I Wu5c17c962015-10-31 00:31:16 +08006042 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -06006043
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006044 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -06006045 ASSERT_VK_SUCCESS(err);
6046
6047 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006048 VkMemoryAllocateInfo memAlloc = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08006049 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
Mike Stroyana3082432015-09-25 13:39:21 -06006050 memAlloc.pNext = NULL;
6051 memAlloc.allocationSize = 0;
6052 memAlloc.memoryTypeIndex = 0;
6053
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -06006054 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -06006055 memAlloc.allocationSize = memReqs.size;
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -06006056 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
6057 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006058 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -06006059 ASSERT_VK_SUCCESS(err);
6060
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006061 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -06006062 memAlloc.allocationSize = memReqs.size;
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -06006063 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
6064 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006065 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -06006066 ASSERT_VK_SUCCESS(err);
6067
6068 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
6069 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006070 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -06006071 ASSERT_VK_SUCCESS(err);
6072
6073 BeginCommandBuffer();
6074 // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest?
6075 //VK_IMAGE_LAYOUT_UNDEFINED = 0,
6076 //VK_IMAGE_LAYOUT_GENERAL = 1,
6077 VkImageResolve resolveRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +08006078 resolveRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -06006079 resolveRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -06006080 resolveRegion.srcSubresource.baseArrayLayer = 0;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006081 resolveRegion.srcSubresource.layerCount = 0;
Mike Stroyana3082432015-09-25 13:39:21 -06006082 resolveRegion.srcOffset.x = 0;
6083 resolveRegion.srcOffset.y = 0;
6084 resolveRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +08006085 resolveRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006086 resolveRegion.dstSubresource.mipLevel = 0;
6087 resolveRegion.dstSubresource.baseArrayLayer = 0;
6088 resolveRegion.dstSubresource.layerCount = 0;
6089 resolveRegion.dstOffset.x = 0;
6090 resolveRegion.dstOffset.y = 0;
6091 resolveRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -06006092 resolveRegion.extent.width = 1;
6093 resolveRegion.extent.height = 1;
6094 resolveRegion.extent.depth = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006095 m_commandBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion);
Mike Stroyana3082432015-09-25 13:39:21 -06006096 EndCommandBuffer();
6097
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06006098 if (!m_errorMonitor->DesiredMsgFound()) {
6099 FAIL() << "Did not receive Error 'vkCmdResolveImage called with unmatched source and dest formats.'";
6100 m_errorMonitor->DumpFailureMsgs();
Mike Stroyana3082432015-09-25 13:39:21 -06006101 }
6102
Chia-I Wuf7458c52015-10-26 21:10:41 +08006103 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006104 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +08006105 vkFreeMemory(m_device->device(), srcMem, NULL);
6106 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -06006107}
6108
6109TEST_F(VkLayerTest, ResolveImageTypeMismatch)
6110{
Mike Stroyana3082432015-09-25 13:39:21 -06006111 VkResult err;
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -06006112 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -06006113
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07006114 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06006115 "vkCmdResolveImage called with unmatched source and dest image types.");
6116
Mike Stroyana3082432015-09-25 13:39:21 -06006117 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -06006118
6119 // Create two images of different types and try to copy between them
6120 VkImage srcImage;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006121 VkImage dstImage;
Mike Stroyana3082432015-09-25 13:39:21 -06006122 VkDeviceMemory srcMem;
6123 VkDeviceMemory destMem;
6124 VkMemoryRequirements memReqs;
6125
6126 VkImageCreateInfo image_create_info = {};
6127 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
6128 image_create_info.pNext = NULL;
6129 image_create_info.imageType = VK_IMAGE_TYPE_2D;
6130 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
6131 image_create_info.extent.width = 32;
6132 image_create_info.extent.height = 1;
6133 image_create_info.extent.depth = 1;
6134 image_create_info.mipLevels = 1;
Courtney Goeltzenleuchter5d2aed42015-10-21 17:57:31 -06006135 image_create_info.arrayLayers = 1;
Chia-I Wu5c17c962015-10-31 00:31:16 +08006136 image_create_info.samples = VK_SAMPLE_COUNT_2_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -06006137 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
Cody Northrop72458c02015-10-27 13:50:04 -06006138 // Note: Some implementations expect color attachment usage for any multisample surface
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006139 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -06006140 image_create_info.flags = 0;
6141
Chia-I Wuf7458c52015-10-26 21:10:41 +08006142 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -06006143 ASSERT_VK_SUCCESS(err);
6144
6145 image_create_info.imageType = VK_IMAGE_TYPE_1D;
Cody Northrop72458c02015-10-27 13:50:04 -06006146 // Note: Some implementations expect color attachment usage for any multisample surface
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006147 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Chia-I Wu5c17c962015-10-31 00:31:16 +08006148 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -06006149
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006150 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -06006151 ASSERT_VK_SUCCESS(err);
6152
6153 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006154 VkMemoryAllocateInfo memAlloc = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08006155 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
Mike Stroyana3082432015-09-25 13:39:21 -06006156 memAlloc.pNext = NULL;
6157 memAlloc.allocationSize = 0;
6158 memAlloc.memoryTypeIndex = 0;
6159
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -06006160 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -06006161 memAlloc.allocationSize = memReqs.size;
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -06006162 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
6163 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006164 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -06006165 ASSERT_VK_SUCCESS(err);
6166
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006167 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -06006168 memAlloc.allocationSize = memReqs.size;
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -06006169 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
6170 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006171 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -06006172 ASSERT_VK_SUCCESS(err);
6173
6174 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
6175 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006176 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -06006177 ASSERT_VK_SUCCESS(err);
6178
6179 BeginCommandBuffer();
6180 // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest?
6181 //VK_IMAGE_LAYOUT_UNDEFINED = 0,
6182 //VK_IMAGE_LAYOUT_GENERAL = 1,
6183 VkImageResolve resolveRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +08006184 resolveRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -06006185 resolveRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -06006186 resolveRegion.srcSubresource.baseArrayLayer = 0;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006187 resolveRegion.srcSubresource.layerCount = 0;
Mike Stroyana3082432015-09-25 13:39:21 -06006188 resolveRegion.srcOffset.x = 0;
6189 resolveRegion.srcOffset.y = 0;
6190 resolveRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +08006191 resolveRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006192 resolveRegion.dstSubresource.mipLevel = 0;
6193 resolveRegion.dstSubresource.baseArrayLayer = 0;
6194 resolveRegion.dstSubresource.layerCount = 0;
6195 resolveRegion.dstOffset.x = 0;
6196 resolveRegion.dstOffset.y = 0;
6197 resolveRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -06006198 resolveRegion.extent.width = 1;
6199 resolveRegion.extent.height = 1;
6200 resolveRegion.extent.depth = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006201 m_commandBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion);
Mike Stroyana3082432015-09-25 13:39:21 -06006202 EndCommandBuffer();
6203
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06006204 if (!m_errorMonitor->DesiredMsgFound()) {
6205 FAIL() << "Did not receive Error 'vkCmdResolveImage called with unmatched source and dest image types.'";
6206 m_errorMonitor->DumpFailureMsgs();
Mike Stroyana3082432015-09-25 13:39:21 -06006207 }
6208
Chia-I Wuf7458c52015-10-26 21:10:41 +08006209 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006210 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +08006211 vkFreeMemory(m_device->device(), srcMem, NULL);
6212 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -06006213}
Tobin Ehlisa1c28562015-10-23 16:00:08 -06006214
6215TEST_F(VkLayerTest, DepthStencilImageViewWithColorAspectBitError)
6216{
6217 // Create a single Image descriptor and cause it to first hit an error due
6218 // to using a DS format, then cause it to hit error due to COLOR_BIT not set in aspect
6219 // The image format check comes 2nd in validation so we trigger it first,
6220 // then when we cause aspect fail next, bad format check will be preempted
Tobin Ehlisa1c28562015-10-23 16:00:08 -06006221 VkResult err;
6222
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07006223 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06006224 "Combination depth/stencil image formats can have only the ");
6225
Tobin Ehlisa1c28562015-10-23 16:00:08 -06006226 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06006227
Chia-I Wu1b99bb22015-10-27 19:25:11 +08006228 VkDescriptorPoolSize ds_type_count = {};
Tobin Ehlisa1c28562015-10-23 16:00:08 -06006229 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
Chia-I Wud50a7d72015-10-26 20:48:51 +08006230 ds_type_count.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06006231
6232 VkDescriptorPoolCreateInfo ds_pool_ci = {};
6233 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
6234 ds_pool_ci.pNext = NULL;
6235 ds_pool_ci.maxSets = 1;
Chia-I Wu1b99bb22015-10-27 19:25:11 +08006236 ds_pool_ci.poolSizeCount = 1;
6237 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06006238
6239 VkDescriptorPool ds_pool;
Chia-I Wuf7458c52015-10-26 21:10:41 +08006240 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06006241 ASSERT_VK_SUCCESS(err);
6242
6243 VkDescriptorSetLayoutBinding dsl_binding = {};
Chia-I Wud46e6ae2015-10-31 00:31:16 +08006244 dsl_binding.binding = 0;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06006245 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
Chia-I Wu02124482015-11-06 06:42:02 +08006246 dsl_binding.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06006247 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
6248 dsl_binding.pImmutableSamplers = NULL;
6249
6250 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
6251 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
6252 ds_layout_ci.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08006253 ds_layout_ci.bindingCount = 1;
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07006254 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06006255 VkDescriptorSetLayout ds_layout;
Chia-I Wuf7458c52015-10-26 21:10:41 +08006256 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06006257 ASSERT_VK_SUCCESS(err);
6258
6259 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006260 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08006261 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Chia-I Wud50a7d72015-10-26 20:48:51 +08006262 alloc_info.setLayoutCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06006263 alloc_info.descriptorPool = ds_pool;
6264 alloc_info.pSetLayouts = &ds_layout;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006265 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06006266 ASSERT_VK_SUCCESS(err);
6267
6268 VkImage image_bad;
6269 VkImage image_good;
6270 // One bad format and one good format for Color attachment
6271 const VkFormat tex_format_bad = VK_FORMAT_D32_SFLOAT_S8_UINT;
6272 const VkFormat tex_format_good = VK_FORMAT_B8G8R8A8_UNORM;
6273 const int32_t tex_width = 32;
6274 const int32_t tex_height = 32;
6275
6276 VkImageCreateInfo image_create_info = {};
6277 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
6278 image_create_info.pNext = NULL;
6279 image_create_info.imageType = VK_IMAGE_TYPE_2D;
6280 image_create_info.format = tex_format_bad;
6281 image_create_info.extent.width = tex_width;
6282 image_create_info.extent.height = tex_height;
6283 image_create_info.extent.depth = 1;
6284 image_create_info.mipLevels = 1;
6285 image_create_info.arrayLayers = 1;
Chia-I Wu5c17c962015-10-31 00:31:16 +08006286 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06006287 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
6288 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT;
6289 image_create_info.flags = 0;
6290
Chia-I Wuf7458c52015-10-26 21:10:41 +08006291 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image_bad);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06006292 ASSERT_VK_SUCCESS(err);
6293 image_create_info.format = tex_format_good;
6294 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Chia-I Wuf7458c52015-10-26 21:10:41 +08006295 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image_good);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06006296 ASSERT_VK_SUCCESS(err);
6297
6298 VkImageViewCreateInfo image_view_create_info = {};
6299 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
6300 image_view_create_info.image = image_bad;
6301 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
6302 image_view_create_info.format = tex_format_bad;
6303 image_view_create_info.subresourceRange.baseArrayLayer = 0;
6304 image_view_create_info.subresourceRange.baseMipLevel = 0;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006305 image_view_create_info.subresourceRange.layerCount = 1;
6306 image_view_create_info.subresourceRange.levelCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06006307 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
6308
6309 VkImageView view;
Chia-I Wuf7458c52015-10-26 21:10:41 +08006310 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06006311
6312 if (!m_errorMonitor->DesiredMsgFound()) {
6313 FAIL() << "Did not receive Error 'Combination depth-stencil image formats can have only the....'";
6314 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlisa1c28562015-10-23 16:00:08 -06006315 }
6316
Chia-I Wuf7458c52015-10-26 21:10:41 +08006317 vkDestroyImage(m_device->device(), image_bad, NULL);
6318 vkDestroyImage(m_device->device(), image_good, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +08006319 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
6320 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06006321}
Tobin Ehliscde08892015-09-22 10:11:37 -06006322#endif // IMAGE_TESTS
6323
Tony Barbour300a6082015-04-07 13:44:53 -06006324int main(int argc, char **argv) {
6325 int result;
6326
6327 ::testing::InitGoogleTest(&argc, argv);
Tony Barbour6918cd52015-04-09 12:58:51 -06006328 VkTestFramework::InitArgs(&argc, argv);
Tony Barbour300a6082015-04-07 13:44:53 -06006329
6330 ::testing::AddGlobalTestEnvironment(new TestEnvironment);
6331
6332 result = RUN_ALL_TESTS();
6333
Tony Barbour6918cd52015-04-09 12:58:51 -06006334 VkTestFramework::Finish();
Tony Barbour300a6082015-04-07 13:44:53 -06006335 return result;
6336}