blob: eb8087f1bc1d839aa2edd56461b66a2c64e93a74 [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"
GregF7ed37422016-01-21 10:00:36 -070094 " gl_Position = vec4(vertices[gl_VertexIndex % 3], 0.0, 1.0);\n"
Mark Lobodzinski3780e142015-05-14 15:08:13 -050095 "}\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 Goeltzenleuchter23cc9132016-01-18 17:42:08 -0700115 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
Mark Young93ecb1d2016-01-13 13:47:16 -0700210static VKAPI_ATTR VkBool32 VKAPI_CALL 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 Goeltzenleuchter23cc9132016-01-18 17:42:08 -0700218 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
Jon Ashburnf19916e2016-01-11 13:12:43 -0700553 VkCommandBufferInheritanceInfo hinfo = {};
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;
Jon Ashburnf19916e2016-01-11 13:12:43 -0700961 alloc_info.descriptorSetCount = 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;
Jon Ashburnf19916e2016-01-11 13:12:43 -07001372 alloc_info.descriptorSetCount = 1;
Mark Lobodzinski74635932015-12-18 15:35:38 -07001373 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));
Jon Ashburnf19916e2016-01-11 13:12:43 -07001408 VkCommandBufferInheritanceInfo cmd_buf_hinfo = {};
1409 memset(&cmd_buf_hinfo, 0, sizeof(VkCommandBufferInheritanceInfo));
Mark Lobodzinski74635932015-12-18 15:35:38 -07001410 cmd_buf_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
1411 cmd_buf_info.pNext = NULL;
1412 cmd_buf_info.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT;
Jon Ashburnf19916e2016-01-11 13:12:43 -07001413 cmd_buf_info.pInheritanceInfo = &cmd_buf_hinfo;
Mark Lobodzinski74635932015-12-18 15:35:38 -07001414
1415 vkBeginCommandBuffer(commandBuffer.GetBufferHandle(), &cmd_buf_info);
1416 vkCmdBindPipeline(commandBuffer.GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
1417
1418 if (!m_errorMonitor->DesiredMsgFound()) {
1419 FAIL() << "Did not receive Error 'vkCmdBindPipeline: This call must be issued inside an active render pass'";
1420 m_errorMonitor->DumpFailureMsgs();
1421 }
1422
1423 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
1424 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
1425 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
1426}
1427
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06001428TEST_F(VkLayerTest, AllocDescriptorFromEmptyPool)
1429{
1430 // Initiate Draw w/o a PSO bound
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06001431 VkResult err;
1432
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07001433 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06001434 "Unable to allocate 1 descriptors of type VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER ");
1435
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06001436 ASSERT_NO_FATAL_FAILURE(InitState());
1437 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06001438
1439 // Create Pool w/ 1 Sampler descriptor, but try to alloc Uniform Buffer descriptor from it
Chia-I Wu1b99bb22015-10-27 19:25:11 +08001440 VkDescriptorPoolSize ds_type_count = {};
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06001441 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLER;
Chia-I Wud50a7d72015-10-26 20:48:51 +08001442 ds_type_count.descriptorCount = 1;
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06001443
1444 VkDescriptorPoolCreateInfo ds_pool_ci = {};
1445 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
1446 ds_pool_ci.pNext = NULL;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06001447 ds_pool_ci.flags = 0;
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06001448 ds_pool_ci.maxSets = 1;
Chia-I Wu1b99bb22015-10-27 19:25:11 +08001449 ds_pool_ci.poolSizeCount = 1;
1450 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06001451
1452 VkDescriptorPool ds_pool;
Chia-I Wuf7458c52015-10-26 21:10:41 +08001453 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06001454 ASSERT_VK_SUCCESS(err);
1455
1456 VkDescriptorSetLayoutBinding dsl_binding = {};
Chia-I Wud46e6ae2015-10-31 00:31:16 +08001457 dsl_binding.binding = 0;
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06001458 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wu02124482015-11-06 06:42:02 +08001459 dsl_binding.descriptorCount = 1;
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06001460 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
1461 dsl_binding.pImmutableSamplers = NULL;
1462
1463 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
1464 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
1465 ds_layout_ci.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08001466 ds_layout_ci.bindingCount = 1;
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07001467 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06001468
1469 VkDescriptorSetLayout ds_layout;
Chia-I Wuf7458c52015-10-26 21:10:41 +08001470 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06001471 ASSERT_VK_SUCCESS(err);
1472
1473 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001474 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08001475 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07001476 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06001477 alloc_info.descriptorPool = ds_pool;
1478 alloc_info.pSetLayouts = &ds_layout;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001479 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06001480
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06001481 if (!m_errorMonitor->DesiredMsgFound()) {
1482 FAIL() << "Did not receive Error 'Unable to allocate 1 descriptors of type VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER...'";
1483 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06001484 }
1485
Chia-I Wuf7458c52015-10-26 21:10:41 +08001486 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
1487 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06001488}
1489
Tobin Ehlise735c692015-10-08 13:13:50 -06001490TEST_F(VkLayerTest, FreeDescriptorFromOneShotPool)
1491{
Tobin Ehlise735c692015-10-08 13:13:50 -06001492 VkResult err;
1493
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07001494 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06001495 "It is invalid to call vkFreeDescriptorSets() with a pool created without setting VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT.");
1496
Tobin Ehlise735c692015-10-08 13:13:50 -06001497 ASSERT_NO_FATAL_FAILURE(InitState());
1498 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlise735c692015-10-08 13:13:50 -06001499
Chia-I Wu1b99bb22015-10-27 19:25:11 +08001500 VkDescriptorPoolSize ds_type_count = {};
Tobin Ehlise735c692015-10-08 13:13:50 -06001501 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wud50a7d72015-10-26 20:48:51 +08001502 ds_type_count.descriptorCount = 1;
Tobin Ehlise735c692015-10-08 13:13:50 -06001503
1504 VkDescriptorPoolCreateInfo ds_pool_ci = {};
1505 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
1506 ds_pool_ci.pNext = NULL;
Tobin Ehlise735c692015-10-08 13:13:50 -06001507 ds_pool_ci.maxSets = 1;
Chia-I Wu1b99bb22015-10-27 19:25:11 +08001508 ds_pool_ci.poolSizeCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06001509 ds_pool_ci.flags = 0;
1510 // Not specifying VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT means
1511 // app can only call vkResetDescriptorPool on this pool.;
Chia-I Wu1b99bb22015-10-27 19:25:11 +08001512 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlise735c692015-10-08 13:13:50 -06001513
1514 VkDescriptorPool ds_pool;
Chia-I Wuf7458c52015-10-26 21:10:41 +08001515 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlise735c692015-10-08 13:13:50 -06001516 ASSERT_VK_SUCCESS(err);
1517
1518 VkDescriptorSetLayoutBinding dsl_binding = {};
Chia-I Wud46e6ae2015-10-31 00:31:16 +08001519 dsl_binding.binding = 0;
Tobin Ehlise735c692015-10-08 13:13:50 -06001520 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wu02124482015-11-06 06:42:02 +08001521 dsl_binding.descriptorCount = 1;
Tobin Ehlise735c692015-10-08 13:13:50 -06001522 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
1523 dsl_binding.pImmutableSamplers = NULL;
1524
1525 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
1526 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
1527 ds_layout_ci.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08001528 ds_layout_ci.bindingCount = 1;
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07001529 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlise735c692015-10-08 13:13:50 -06001530
1531 VkDescriptorSetLayout ds_layout;
Chia-I Wuf7458c52015-10-26 21:10:41 +08001532 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlise735c692015-10-08 13:13:50 -06001533 ASSERT_VK_SUCCESS(err);
1534
1535 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001536 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08001537 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07001538 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06001539 alloc_info.descriptorPool = ds_pool;
1540 alloc_info.pSetLayouts = &ds_layout;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001541 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlise735c692015-10-08 13:13:50 -06001542 ASSERT_VK_SUCCESS(err);
1543
1544 err = vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptorSet);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06001545 if (!m_errorMonitor->DesiredMsgFound()) {
1546 FAIL() << "Did not receive Error 'It is invalid to call vkFreeDescriptorSets() with a pool created with...'";
1547 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlise735c692015-10-08 13:13:50 -06001548 }
1549
Chia-I Wuf7458c52015-10-26 21:10:41 +08001550 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
1551 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlise735c692015-10-08 13:13:50 -06001552}
1553
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06001554TEST_F(VkLayerTest, InvalidDescriptorPool)
1555{
1556 // TODO : Simple check for bad object should be added to ObjectTracker to catch this case
1557 // The DS check for this is after driver has been called to validate DS internal data struct
1558 // Attempt to clear DS Pool with bad object
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06001559/*
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07001560 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06001561 "Unable to find pool node for pool 0xbaad6001 specified in vkResetDescriptorPool() call");
1562
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06001563 VkDescriptorPool badPool = (VkDescriptorPool)0xbaad6001;
1564 vkResetDescriptorPool(device(), badPool);
1565
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06001566 if (!m_errorMonitor->DesiredMsgFound()) {
1567 FAIL() << "Did not receive Error 'Unable to find pool node for pool 0xbaad6001 specified in vkResetDescriptorPool() call'";
1568 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06001569 }*/
1570}
1571
1572TEST_F(VkLayerTest, InvalidDescriptorSet)
1573{
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06001574 // TODO : Simple check for bad object should be added to ObjectTracker to catch this case
1575 // The DS check for this is after driver has been called to validate DS internal data struct
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06001576 // Create a valid cmd buffer
1577 // call vkCmdBindDescriptorSets w/ false DS
1578}
1579
1580TEST_F(VkLayerTest, InvalidDescriptorSetLayout)
1581{
1582 // TODO : Simple check for bad object should be added to ObjectTracker to catch this case
1583 // The DS check for this is after driver has been called to validate DS internal data struct
1584}
1585
1586TEST_F(VkLayerTest, InvalidPipeline)
1587{
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06001588 // TODO : Simple check for bad object should be added to ObjectTracker to catch this case
1589 // The DS check for this is after driver has been called to validate DS internal data struct
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06001590 // Create a valid cmd buffer
1591 // call vkCmdBindPipeline w/ false Pipeline
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06001592//
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07001593// m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06001594// "Attempt to bind Pipeline ");
Tobin Ehlis502480b2015-06-24 15:53:07 -06001595//
1596// ASSERT_NO_FATAL_FAILURE(InitState());
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001597// VkCommandBufferObj commandBuffer(m_device);
Tony Barbourfe3351b2015-07-28 10:17:20 -06001598// BeginCommandBuffer();
Tobin Ehlis502480b2015-06-24 15:53:07 -06001599// VkPipeline badPipeline = (VkPipeline)0xbaadb1be;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001600// vkCmdBindPipeline(commandBuffer.GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, badPipeline);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06001601//
1602// if (!m_errorMonitor->DesiredMsgFound()) {
1603// FAIL() << "Did not receive Error 'Attempt to bind Pipeline 0xbaadb1be that doesn't exist!'";
1604// m_errorMonitor->DumpFailureMsgs();
Tobin Ehlis502480b2015-06-24 15:53:07 -06001605// }
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06001606}
1607
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06001608TEST_F(VkLayerTest, DescriptorSetNotUpdated)
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06001609{
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001610 // Create and update CommandBuffer then call QueueSubmit w/o calling End on CommandBuffer
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06001611 VkResult err;
1612
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07001613 // TODO: verify that this matches layer
1614 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARN_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06001615 " bound but it was never updated. ");
1616
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06001617 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyan713b2d72015-08-04 10:49:29 -06001618 ASSERT_NO_FATAL_FAILURE(InitViewport());
1619 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chia-I Wu1b99bb22015-10-27 19:25:11 +08001620 VkDescriptorPoolSize ds_type_count = {};
Tony Barboureb254902015-07-15 12:50:33 -06001621 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wud50a7d72015-10-26 20:48:51 +08001622 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06001623
1624 VkDescriptorPoolCreateInfo ds_pool_ci = {};
1625 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
1626 ds_pool_ci.pNext = NULL;
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -06001627 ds_pool_ci.maxSets = 1;
Chia-I Wu1b99bb22015-10-27 19:25:11 +08001628 ds_pool_ci.poolSizeCount = 1;
1629 ds_pool_ci.pPoolSizes = &ds_type_count;
Mike Stroyan713b2d72015-08-04 10:49:29 -06001630
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06001631 VkDescriptorPool ds_pool;
Chia-I Wuf7458c52015-10-26 21:10:41 +08001632 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06001633 ASSERT_VK_SUCCESS(err);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06001634
Tony Barboureb254902015-07-15 12:50:33 -06001635 VkDescriptorSetLayoutBinding dsl_binding = {};
Chia-I Wud46e6ae2015-10-31 00:31:16 +08001636 dsl_binding.binding = 0;
Tony Barboureb254902015-07-15 12:50:33 -06001637 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wu02124482015-11-06 06:42:02 +08001638 dsl_binding.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06001639 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
1640 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06001641
Tony Barboureb254902015-07-15 12:50:33 -06001642 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
1643 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
1644 ds_layout_ci.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08001645 ds_layout_ci.bindingCount = 1;
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07001646 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06001647 VkDescriptorSetLayout ds_layout;
Chia-I Wuf7458c52015-10-26 21:10:41 +08001648 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06001649 ASSERT_VK_SUCCESS(err);
1650
1651 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001652 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08001653 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07001654 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06001655 alloc_info.descriptorPool = ds_pool;
1656 alloc_info.pSetLayouts = &ds_layout;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001657 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06001658 ASSERT_VK_SUCCESS(err);
1659
Tony Barboureb254902015-07-15 12:50:33 -06001660 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
1661 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
1662 pipeline_layout_ci.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08001663 pipeline_layout_ci.setLayoutCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06001664 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06001665
1666 VkPipelineLayout pipeline_layout;
Chia-I Wuf7458c52015-10-26 21:10:41 +08001667 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06001668 ASSERT_VK_SUCCESS(err);
1669
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06001670 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06001671 // TODO - We shouldn't need a fragment shader but add it to be able to run on more devices
1672 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06001673
Tony Barbourc95e4ac2015-08-04 17:05:26 -06001674 VkPipelineObj pipe(m_device);
1675 pipe.AddShader(&vs);
Tony Barbour1c94d372015-08-06 11:21:08 -06001676 pipe.AddShader(&fs);
Tony Barbourc95e4ac2015-08-04 17:05:26 -06001677 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tony Barbourfe3351b2015-07-28 10:17:20 -06001678
1679 BeginCommandBuffer();
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001680 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
1681 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1, &descriptorSet, 0, NULL);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06001682
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06001683 if (!m_errorMonitor->DesiredMsgFound()) {
1684 FAIL() << "Did not recieve Warning 'DS <blah> bound but it was never updated. You may want to either update it or not bind it.'";
1685 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06001686 }
Mike Stroyand1c84a52015-08-18 14:40:24 -06001687
Chia-I Wuf7458c52015-10-26 21:10:41 +08001688 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
1689 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
1690 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06001691}
1692
Tobin Ehlisba31cab2015-11-02 15:24:32 -07001693TEST_F(VkLayerTest, InvalidBufferViewObject)
1694{
1695 // Create a single TEXEL_BUFFER descriptor and send it an invalid bufferView
1696 VkResult err;
1697
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07001698 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlisba31cab2015-11-02 15:24:32 -07001699 "Attempt to update descriptor with invalid bufferView ");
1700
1701 ASSERT_NO_FATAL_FAILURE(InitState());
1702 VkDescriptorPoolSize ds_type_count = {};
1703 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER;
1704 ds_type_count.descriptorCount = 1;
1705
1706 VkDescriptorPoolCreateInfo ds_pool_ci = {};
1707 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
1708 ds_pool_ci.pNext = NULL;
1709 ds_pool_ci.maxSets = 1;
1710 ds_pool_ci.poolSizeCount = 1;
1711 ds_pool_ci.pPoolSizes = &ds_type_count;
1712
1713 VkDescriptorPool ds_pool;
1714 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
1715 ASSERT_VK_SUCCESS(err);
1716
1717 VkDescriptorSetLayoutBinding dsl_binding = {};
1718 dsl_binding.binding = 0;
1719 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER;
Chia-I Wu02124482015-11-06 06:42:02 +08001720 dsl_binding.descriptorCount = 1;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07001721 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
1722 dsl_binding.pImmutableSamplers = NULL;
1723
1724 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
1725 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
1726 ds_layout_ci.pNext = NULL;
1727 ds_layout_ci.bindingCount = 1;
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07001728 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07001729 VkDescriptorSetLayout ds_layout;
1730 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
1731 ASSERT_VK_SUCCESS(err);
1732
1733 VkDescriptorSet descriptorSet;
1734 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08001735 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07001736 alloc_info.descriptorSetCount = 1;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07001737 alloc_info.descriptorPool = ds_pool;
1738 alloc_info.pSetLayouts = &ds_layout;
1739 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
1740 ASSERT_VK_SUCCESS(err);
1741
Mark Youngad779052016-01-06 14:26:04 -07001742 VkBufferView view = (VkBufferView)((size_t)0xbaadbeef); // invalid bufferView object
Tobin Ehlisba31cab2015-11-02 15:24:32 -07001743 VkWriteDescriptorSet descriptor_write;
1744 memset(&descriptor_write, 0, sizeof(descriptor_write));
1745 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
1746 descriptor_write.dstSet = descriptorSet;
1747 descriptor_write.dstBinding = 0;
1748 descriptor_write.descriptorCount = 1;
1749 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER;
1750 descriptor_write.pTexelBufferView = &view;
1751
1752 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
1753
1754 if (!m_errorMonitor->DesiredMsgFound()) {
Tobin Ehlis9d80c2d2015-11-05 10:27:49 -07001755 FAIL() << "Did not receive Error 'Attempt to update descriptor with invalid bufferView'";
Tobin Ehlisba31cab2015-11-02 15:24:32 -07001756 m_errorMonitor->DumpFailureMsgs();
1757 }
1758
1759 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
1760 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
1761}
1762
Tobin Ehlisf6585052015-12-17 11:48:42 -07001763TEST_F(VkLayerTest, InvalidDynamicOffsetCases)
Tobin Ehlis49f903e2015-11-04 13:30:34 -07001764{
Tobin Ehlisf6585052015-12-17 11:48:42 -07001765 // Create a descriptorSet w/ dynamic descriptor and then hit 3 offset error cases:
1766 // 1. No dynamicOffset supplied
1767 // 2. Too many dynamicOffsets supplied
1768 // 3. Dynamic offset oversteps buffer being updated
Tobin Ehlis49f903e2015-11-04 13:30:34 -07001769 VkResult err;
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07001770 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlisf6585052015-12-17 11:48:42 -07001771 " requires 1 dynamicOffsets, but only 0 dynamicOffsets are left in pDynamicOffsets ");
Tobin Ehlis49f903e2015-11-04 13:30:34 -07001772
1773 ASSERT_NO_FATAL_FAILURE(InitState());
1774 ASSERT_NO_FATAL_FAILURE(InitViewport());
1775 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
1776
1777 VkDescriptorPoolSize ds_type_count = {};
1778 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
1779 ds_type_count.descriptorCount = 1;
1780
1781 VkDescriptorPoolCreateInfo ds_pool_ci = {};
1782 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
1783 ds_pool_ci.pNext = NULL;
1784 ds_pool_ci.maxSets = 1;
1785 ds_pool_ci.poolSizeCount = 1;
1786 ds_pool_ci.pPoolSizes = &ds_type_count;
1787
1788 VkDescriptorPool ds_pool;
1789 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
1790 ASSERT_VK_SUCCESS(err);
1791
1792 VkDescriptorSetLayoutBinding dsl_binding = {};
1793 dsl_binding.binding = 0;
1794 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
Jon Ashburn4f232582015-11-06 15:31:44 -07001795 dsl_binding.descriptorCount = 1;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07001796 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
1797 dsl_binding.pImmutableSamplers = NULL;
1798
1799 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
1800 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
1801 ds_layout_ci.pNext = NULL;
1802 ds_layout_ci.bindingCount = 1;
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07001803 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07001804 VkDescriptorSetLayout ds_layout;
1805 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
1806 ASSERT_VK_SUCCESS(err);
1807
1808 VkDescriptorSet descriptorSet;
1809 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08001810 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07001811 alloc_info.descriptorSetCount = 1;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07001812 alloc_info.descriptorPool = ds_pool;
1813 alloc_info.pSetLayouts = &ds_layout;
1814 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
1815 ASSERT_VK_SUCCESS(err);
1816
1817 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
1818 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
1819 pipeline_layout_ci.pNext = NULL;
1820 pipeline_layout_ci.setLayoutCount = 1;
1821 pipeline_layout_ci.pSetLayouts = &ds_layout;
1822
1823 VkPipelineLayout pipeline_layout;
1824 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
1825 ASSERT_VK_SUCCESS(err);
1826
1827 // Create a buffer to update the descriptor with
1828 uint32_t qfi = 0;
1829 VkBufferCreateInfo buffCI = {};
1830 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
1831 buffCI.size = 1024;
1832 buffCI.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
1833 buffCI.queueFamilyIndexCount = 1;
1834 buffCI.pQueueFamilyIndices = &qfi;
1835
1836 VkBuffer dyub;
1837 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &dyub);
1838 ASSERT_VK_SUCCESS(err);
1839 // Correctly update descriptor to avoid "NOT_UPDATED" error
1840 VkDescriptorBufferInfo buffInfo = {};
1841 buffInfo.buffer = dyub;
1842 buffInfo.offset = 0;
1843 buffInfo.range = 1024;
1844
1845 VkWriteDescriptorSet descriptor_write;
1846 memset(&descriptor_write, 0, sizeof(descriptor_write));
1847 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
1848 descriptor_write.dstSet = descriptorSet;
1849 descriptor_write.dstBinding = 0;
1850 descriptor_write.descriptorCount = 1;
1851 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
1852 descriptor_write.pBufferInfo = &buffInfo;
1853
1854 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
1855
1856 BeginCommandBuffer();
1857 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1, &descriptorSet, 0, NULL);
Tobin Ehlisf6585052015-12-17 11:48:42 -07001858 if (!m_errorMonitor->DesiredMsgFound()) {
1859 FAIL() << "Error received was not 'descriptorSet #0 (0x<ADDR>) requires 1 dynamicOffsets, but only 0 dynamicOffsets are left in pDynamicOffsets array...'";
1860 m_errorMonitor->DumpFailureMsgs();
1861 }
1862 uint32_t pDynOff[2] = {512, 756};
1863 // Now cause error b/c too many dynOffsets in array for # of dyn descriptors
1864 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
1865 "Attempting to bind 1 descriptorSets with 1 dynamic descriptors, but ");
1866 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1, &descriptorSet, 2, pDynOff);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07001867 if (!m_errorMonitor->DesiredMsgFound()) {
1868 FAIL() << "Error received was not 'Attempting to bind 1 descriptorSets with 1 dynamic descriptors, but dynamicOffsetCount is 0...'";
1869 m_errorMonitor->DumpFailureMsgs();
1870 }
Tobin Ehlisf6585052015-12-17 11:48:42 -07001871 // Finally cause error due to dynamicOffset being too big
1872 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
1873 " from its update, this oversteps its buffer (");
1874 // Create PSO to be used for draw-time errors below
1875 char const *vsSource =
Tony Barboure804d202016-01-05 13:37:45 -07001876 "#version 400\n"
Tobin Ehlisf6585052015-12-17 11:48:42 -07001877 "#extension GL_ARB_separate_shader_objects: require\n"
1878 "#extension GL_ARB_shading_language_420pack: require\n"
1879 "\n"
Tony Barboure804d202016-01-05 13:37:45 -07001880 "out gl_PerVertex { \n"
1881 " vec4 gl_Position;\n"
1882 "};\n"
Tobin Ehlisf6585052015-12-17 11:48:42 -07001883 "void main(){\n"
1884 " gl_Position = vec4(1);\n"
1885 "}\n";
1886 char const *fsSource =
Tony Barboure804d202016-01-05 13:37:45 -07001887 "#version 400\n"
Tobin Ehlisf6585052015-12-17 11:48:42 -07001888 "#extension GL_ARB_separate_shader_objects: require\n"
1889 "#extension GL_ARB_shading_language_420pack: require\n"
1890 "\n"
1891 "layout(location=0) out vec4 x;\n"
1892 "layout(set=0) layout(binding=0) uniform foo { int x; int y; } bar;\n"
1893 "void main(){\n"
1894 " x = vec4(bar.y);\n"
1895 "}\n";
1896 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
1897 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
1898 VkPipelineObj pipe(m_device);
1899 pipe.AddShader(&vs);
1900 pipe.AddShader(&fs);
1901 pipe.AddColorAttachment();
1902 pipe.CreateVKPipeline(pipeline_layout, renderPass());
1903
1904 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
1905 // This update should succeed, but offset size of 512 will overstep buffer /w range 1024 & size 1024
1906 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1, &descriptorSet, 1, pDynOff);
1907 Draw(1, 0, 0, 0);
1908 if (!m_errorMonitor->DesiredMsgFound()) {
1909 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...'";
1910 m_errorMonitor->DumpFailureMsgs();
1911 }
Tobin Ehlis49f903e2015-11-04 13:30:34 -07001912
1913 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
1914 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
1915}
1916
Tobin Ehlis559c6382015-11-05 09:52:49 -07001917TEST_F(VkLayerTest, DescriptorSetCompatibility)
1918{
1919 // Test various desriptorSet errors with bad binding combinations
1920 VkResult err;
Tobin Ehlis559c6382015-11-05 09:52:49 -07001921
1922 ASSERT_NO_FATAL_FAILURE(InitState());
1923 ASSERT_NO_FATAL_FAILURE(InitViewport());
1924 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
1925
1926 static const uint32_t NUM_DESCRIPTOR_TYPES = 5;
1927 VkDescriptorPoolSize ds_type_count[NUM_DESCRIPTOR_TYPES] = {};
1928 ds_type_count[0].type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07001929 ds_type_count[0].descriptorCount = 10;
Tobin Ehlis559c6382015-11-05 09:52:49 -07001930 ds_type_count[1].type = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
1931 ds_type_count[1].descriptorCount = 2;
1932 ds_type_count[2].type = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE;
1933 ds_type_count[2].descriptorCount = 2;
1934 ds_type_count[3].type = VK_DESCRIPTOR_TYPE_SAMPLER;
1935 ds_type_count[3].descriptorCount = 5;
1936 // TODO : LunarG ILO driver currently asserts in desc.c w/ INPUT_ATTACHMENT type
1937 //ds_type_count[4].type = VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT;
1938 ds_type_count[4].type = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
1939 ds_type_count[4].descriptorCount = 2;
1940
1941 VkDescriptorPoolCreateInfo ds_pool_ci = {};
1942 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
1943 ds_pool_ci.pNext = NULL;
Mike Stroyan9c70cdb2016-01-06 14:14:17 -07001944 ds_pool_ci.maxSets = 5;
Tobin Ehlis559c6382015-11-05 09:52:49 -07001945 ds_pool_ci.poolSizeCount = NUM_DESCRIPTOR_TYPES;
1946 ds_pool_ci.pPoolSizes = ds_type_count;
1947
1948 VkDescriptorPool ds_pool;
1949 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
1950 ASSERT_VK_SUCCESS(err);
1951
1952 static const uint32_t MAX_DS_TYPES_IN_LAYOUT = 2;
1953 VkDescriptorSetLayoutBinding dsl_binding[MAX_DS_TYPES_IN_LAYOUT] = {};
1954 dsl_binding[0].binding = 0;
1955 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07001956 dsl_binding[0].descriptorCount = 5;
Tobin Ehlis559c6382015-11-05 09:52:49 -07001957 dsl_binding[0].stageFlags = VK_SHADER_STAGE_ALL;
1958 dsl_binding[0].pImmutableSamplers = NULL;
1959
Tobin Ehlis8fab6562015-12-01 09:57:09 -07001960 // Create layout identical to set0 layout but w/ different stageFlags
1961 VkDescriptorSetLayoutBinding dsl_fs_stage_only = {};
1962 dsl_fs_stage_only.binding = 0;
1963 dsl_fs_stage_only.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
1964 dsl_fs_stage_only.descriptorCount = 5;
1965 dsl_fs_stage_only.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT; // Different stageFlags to cause error at bind time
1966 dsl_fs_stage_only.pImmutableSamplers = NULL;
Tobin Ehlis559c6382015-11-05 09:52:49 -07001967 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
1968 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
1969 ds_layout_ci.pNext = NULL;
1970 ds_layout_ci.bindingCount = 1;
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07001971 ds_layout_ci.pBindings = dsl_binding;
Tobin Ehlis559c6382015-11-05 09:52:49 -07001972 static const uint32_t NUM_LAYOUTS = 4;
1973 VkDescriptorSetLayout ds_layout[NUM_LAYOUTS] = {};
Tobin Ehlis8fab6562015-12-01 09:57:09 -07001974 VkDescriptorSetLayout ds_layout_fs_only = {};
1975 // Create 4 unique layouts for full pipelineLayout, and 1 special fs-only layout for error case
Tobin Ehlis559c6382015-11-05 09:52:49 -07001976 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout[0]);
1977 ASSERT_VK_SUCCESS(err);
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07001978 ds_layout_ci.pBindings = &dsl_fs_stage_only;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07001979 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout_fs_only);
1980 ASSERT_VK_SUCCESS(err);
Tobin Ehlis559c6382015-11-05 09:52:49 -07001981 dsl_binding[0].binding = 0;
1982 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07001983 dsl_binding[0].descriptorCount = 2;
Mike Stroyan9c70cdb2016-01-06 14:14:17 -07001984 dsl_binding[1].binding = 1;
1985 dsl_binding[1].descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE;
1986 dsl_binding[1].descriptorCount = 2;
1987 dsl_binding[1].stageFlags = VK_SHADER_STAGE_ALL;
1988 dsl_binding[1].pImmutableSamplers = NULL;
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07001989 ds_layout_ci.pBindings = dsl_binding;
Tobin Ehlis559c6382015-11-05 09:52:49 -07001990 ds_layout_ci.bindingCount = 2;
1991 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout[1]);
1992 ASSERT_VK_SUCCESS(err);
1993 dsl_binding[0].binding = 0;
1994 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07001995 dsl_binding[0].descriptorCount = 5;
Tobin Ehlis559c6382015-11-05 09:52:49 -07001996 ds_layout_ci.bindingCount = 1;
1997 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout[2]);
1998 ASSERT_VK_SUCCESS(err);
1999 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07002000 dsl_binding[0].descriptorCount = 2;
Tobin Ehlis559c6382015-11-05 09:52:49 -07002001 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout[3]);
2002 ASSERT_VK_SUCCESS(err);
2003
2004 static const uint32_t NUM_SETS = 4;
2005 VkDescriptorSet descriptorSet[NUM_SETS] = {};
2006 VkDescriptorSetAllocateInfo alloc_info = {};
Tobin Ehlis8fab6562015-12-01 09:57:09 -07002007 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07002008 alloc_info.descriptorSetCount = NUM_LAYOUTS;
Tobin Ehlis559c6382015-11-05 09:52:49 -07002009 alloc_info.descriptorPool = ds_pool;
2010 alloc_info.pSetLayouts = ds_layout;
2011 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, descriptorSet);
2012 ASSERT_VK_SUCCESS(err);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07002013 VkDescriptorSet ds0_fs_only = {};
Jon Ashburnf19916e2016-01-11 13:12:43 -07002014 alloc_info.descriptorSetCount = 1;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07002015 alloc_info.pSetLayouts = &ds_layout_fs_only;
2016 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &ds0_fs_only);
2017 ASSERT_VK_SUCCESS(err);
Tobin Ehlis559c6382015-11-05 09:52:49 -07002018
2019 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
2020 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
2021 pipeline_layout_ci.pNext = NULL;
2022 pipeline_layout_ci.setLayoutCount = NUM_LAYOUTS;
2023 pipeline_layout_ci.pSetLayouts = ds_layout;
2024
2025 VkPipelineLayout pipeline_layout;
2026 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
2027 ASSERT_VK_SUCCESS(err);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07002028 // Create pipelineLayout with only one setLayout
2029 pipeline_layout_ci.setLayoutCount = 1;
2030 VkPipelineLayout single_pipe_layout;
2031 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &single_pipe_layout);
2032 ASSERT_VK_SUCCESS(err);
2033 // Create pipelineLayout with 2 descriptor setLayout at index 0
2034 pipeline_layout_ci.pSetLayouts = &ds_layout[3];
2035 VkPipelineLayout pipe_layout_one_desc;
2036 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipe_layout_one_desc);
2037 ASSERT_VK_SUCCESS(err);
2038 // Create pipelineLayout with 5 SAMPLER descriptor setLayout at index 0
2039 pipeline_layout_ci.pSetLayouts = &ds_layout[2];
2040 VkPipelineLayout pipe_layout_five_samp;
2041 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipe_layout_five_samp);
2042 ASSERT_VK_SUCCESS(err);
2043 // Create pipelineLayout with UB type, but stageFlags for FS only
2044 pipeline_layout_ci.pSetLayouts = &ds_layout_fs_only;
2045 VkPipelineLayout pipe_layout_fs_only;
2046 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipe_layout_fs_only);
2047 ASSERT_VK_SUCCESS(err);
2048 // Create pipelineLayout w/ incompatible set0 layout, but set1 is fine
2049 VkDescriptorSetLayout pl_bad_s0[2] = {};
2050 pl_bad_s0[0] = ds_layout_fs_only;
2051 pl_bad_s0[1] = ds_layout[1];
2052 pipeline_layout_ci.setLayoutCount = 2;
2053 pipeline_layout_ci.pSetLayouts = pl_bad_s0;
2054 VkPipelineLayout pipe_layout_bad_set0;
2055 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipe_layout_bad_set0);
2056 ASSERT_VK_SUCCESS(err);
Tobin Ehlis559c6382015-11-05 09:52:49 -07002057
2058 // Create a buffer to update the descriptor with
2059 uint32_t qfi = 0;
2060 VkBufferCreateInfo buffCI = {};
2061 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
2062 buffCI.size = 1024;
2063 buffCI.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
2064 buffCI.queueFamilyIndexCount = 1;
2065 buffCI.pQueueFamilyIndices = &qfi;
2066
2067 VkBuffer dyub;
2068 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &dyub);
2069 ASSERT_VK_SUCCESS(err);
2070 // Correctly update descriptor to avoid "NOT_UPDATED" error
2071 static const uint32_t NUM_BUFFS = 5;
2072 VkDescriptorBufferInfo buffInfo[NUM_BUFFS] = {};
2073 for (uint32_t i=0; i<NUM_BUFFS; ++i) {
2074 buffInfo[i].buffer = dyub;
2075 buffInfo[i].offset = 0;
2076 buffInfo[i].range = 1024;
2077 }
Tobin Ehlis8fab6562015-12-01 09:57:09 -07002078 VkImage image;
2079 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
2080 const int32_t tex_width = 32;
2081 const int32_t tex_height = 32;
2082 VkImageCreateInfo image_create_info = {};
2083 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
2084 image_create_info.pNext = NULL;
2085 image_create_info.imageType = VK_IMAGE_TYPE_2D;
2086 image_create_info.format = tex_format;
2087 image_create_info.extent.width = tex_width;
2088 image_create_info.extent.height = tex_height;
2089 image_create_info.extent.depth = 1;
2090 image_create_info.mipLevels = 1;
2091 image_create_info.arrayLayers = 1;
2092 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
2093 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
2094 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
2095 image_create_info.flags = 0;
2096 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
2097 ASSERT_VK_SUCCESS(err);
Tobin Ehlis559c6382015-11-05 09:52:49 -07002098
Mike Stroyan9c70cdb2016-01-06 14:14:17 -07002099 VkMemoryRequirements memReqs;
2100 VkDeviceMemory imageMem;
2101 bool pass;
2102 VkMemoryAllocateInfo memAlloc = {};
2103 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
2104 memAlloc.pNext = NULL;
2105 memAlloc.allocationSize = 0;
2106 memAlloc.memoryTypeIndex = 0;
2107 vkGetImageMemoryRequirements(m_device->device(), image, &memReqs);
2108 memAlloc.allocationSize = memReqs.size;
2109 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
2110 ASSERT_TRUE(pass);
2111 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &imageMem);
2112 ASSERT_VK_SUCCESS(err);
2113 err = vkBindImageMemory(m_device->device(), image, imageMem, 0);
2114 ASSERT_VK_SUCCESS(err);
2115
Tobin Ehlis8fab6562015-12-01 09:57:09 -07002116 VkImageViewCreateInfo image_view_create_info = {};
Mike Stroyan9c70cdb2016-01-06 14:14:17 -07002117 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07002118 image_view_create_info.image = image;
2119 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
2120 image_view_create_info.format = tex_format;
2121 image_view_create_info.subresourceRange.layerCount = 1;
2122 image_view_create_info.subresourceRange.baseMipLevel = 0;
2123 image_view_create_info.subresourceRange.levelCount = 1;
2124 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Tobin Ehlis559c6382015-11-05 09:52:49 -07002125
Tobin Ehlis8fab6562015-12-01 09:57:09 -07002126 VkImageView view;
2127 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
2128 ASSERT_VK_SUCCESS(err);
Tobin Ehlis991d45a2016-01-06 08:48:41 -07002129 VkDescriptorImageInfo imageInfo[4] = {};
Tobin Ehlis8fab6562015-12-01 09:57:09 -07002130 imageInfo[0].imageView = view;
2131 imageInfo[0].imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
2132 imageInfo[1].imageView = view;
2133 imageInfo[1].imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
Tobin Ehlis991d45a2016-01-06 08:48:41 -07002134 imageInfo[2].imageView = view;
2135 imageInfo[2].imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
2136 imageInfo[3].imageView = view;
2137 imageInfo[3].imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07002138
2139 static const uint32_t NUM_SET_UPDATES = 3;
2140 VkWriteDescriptorSet descriptor_write[NUM_SET_UPDATES] = {};
2141 descriptor_write[0].sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
2142 descriptor_write[0].dstSet = descriptorSet[0];
2143 descriptor_write[0].dstBinding = 0;
2144 descriptor_write[0].descriptorCount = 5;
2145 descriptor_write[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
2146 descriptor_write[0].pBufferInfo = buffInfo;
2147 descriptor_write[1].sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
2148 descriptor_write[1].dstSet = descriptorSet[1];
2149 descriptor_write[1].dstBinding = 0;
2150 descriptor_write[1].descriptorCount = 2;
2151 descriptor_write[1].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
2152 descriptor_write[1].pImageInfo = imageInfo;
2153 descriptor_write[2].sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
2154 descriptor_write[2].dstSet = descriptorSet[1];
2155 descriptor_write[2].dstBinding = 1;
2156 descriptor_write[2].descriptorCount = 2;
2157 descriptor_write[2].descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE;
Tobin Ehlis991d45a2016-01-06 08:48:41 -07002158 descriptor_write[2].pImageInfo = &imageInfo[2];
Tobin Ehlis8fab6562015-12-01 09:57:09 -07002159
2160 vkUpdateDescriptorSets(m_device->device(), 3, descriptor_write, 0, NULL);
Tobin Ehlis559c6382015-11-05 09:52:49 -07002161
Tobin Ehlis88452832015-12-03 09:40:56 -07002162 // Create PSO to be used for draw-time errors below
2163 char const *vsSource =
Tony Barboure804d202016-01-05 13:37:45 -07002164 "#version 400\n"
Tobin Ehlis88452832015-12-03 09:40:56 -07002165 "#extension GL_ARB_separate_shader_objects: require\n"
2166 "#extension GL_ARB_shading_language_420pack: require\n"
2167 "\n"
Tony Barboure804d202016-01-05 13:37:45 -07002168 "out gl_PerVertex {\n"
2169 " vec4 gl_Position;\n"
2170 "};\n"
Tobin Ehlis88452832015-12-03 09:40:56 -07002171 "void main(){\n"
2172 " gl_Position = vec4(1);\n"
2173 "}\n";
2174 char const *fsSource =
Tony Barboure804d202016-01-05 13:37:45 -07002175 "#version 400\n"
Tobin Ehlis88452832015-12-03 09:40:56 -07002176 "#extension GL_ARB_separate_shader_objects: require\n"
2177 "#extension GL_ARB_shading_language_420pack: require\n"
2178 "\n"
2179 "layout(location=0) out vec4 x;\n"
2180 "layout(set=0) layout(binding=0) uniform foo { int x; int y; } bar;\n"
2181 "void main(){\n"
2182 " x = vec4(bar.y);\n"
2183 "}\n";
2184 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
2185 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Tobin Ehlis559c6382015-11-05 09:52:49 -07002186 VkPipelineObj pipe(m_device);
2187 pipe.AddShader(&vs);
2188 pipe.AddShader(&fs);
Tobin Ehlis88452832015-12-03 09:40:56 -07002189 pipe.AddColorAttachment();
2190 pipe.CreateVKPipeline(pipe_layout_fs_only, renderPass());
Tobin Ehlis559c6382015-11-05 09:52:49 -07002191
2192 BeginCommandBuffer();
Tobin Ehlis88452832015-12-03 09:40:56 -07002193
Tobin Ehlis559c6382015-11-05 09:52:49 -07002194 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
2195 // NOTE : I believe LunarG ilo driver has bug (LX#189) that requires binding of PSO
2196 // here before binding DSs. Otherwise we assert in cmd_copy_dset_data() of cmd_pipeline.c
2197 // due to the fact that cmd_alloc_dset_data() has not been called in cmd_bind_graphics_pipeline()
2198 // TODO : Want to cause various binding incompatibility issues here to test DrawState
2199 // First cause various verify_layout_compatibility() fails
2200 // Second disturb early and late sets and verify INFO msgs
Tobin Ehlis8fab6562015-12-01 09:57:09 -07002201 // verify_set_layout_compatibility fail cases:
2202 // 1. invalid VkPipelineLayout (layout) passed into vkCmdBindDescriptorSets
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07002203 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " due to: invalid VkPipelineLayout ");
Mark Youngad779052016-01-06 14:26:04 -07002204 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 -07002205 if (!m_errorMonitor->DesiredMsgFound()) {
Tobin Ehlis8fab6562015-12-01 09:57:09 -07002206 FAIL() << "Did not receive correct error msg when attempting to bind descriptorSets with invalid VkPipelineLayout.";
Tobin Ehlis559c6382015-11-05 09:52:49 -07002207 m_errorMonitor->DumpFailureMsgs();
2208 }
Tobin Ehlis8fab6562015-12-01 09:57:09 -07002209 // 2. layoutIndex exceeds # of layouts in layout
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07002210 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " attempting to bind set to index 1");
Tobin Ehlis8fab6562015-12-01 09:57:09 -07002211 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, single_pipe_layout, 0, 2, &descriptorSet[0], 0, NULL);
2212 if (!m_errorMonitor->DesiredMsgFound()) {
2213 FAIL() << "Did not receive correct error msg when attempting to bind descriptorSet to index 1 when pipelineLayout only has index 0.";
2214 m_errorMonitor->DumpFailureMsgs();
2215 }
2216 vkDestroyPipelineLayout(m_device->device(), single_pipe_layout, NULL);
2217 // 3. Pipeline setLayout[0] has 2 descriptors, but set being bound has 5 descriptors
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07002218 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, ", but corresponding set being bound has 5 descriptors.");
Tobin Ehlis8fab6562015-12-01 09:57:09 -07002219 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe_layout_one_desc, 0, 1, &descriptorSet[0], 0, NULL);
2220 if (!m_errorMonitor->DesiredMsgFound()) {
2221 FAIL() << "Did not receive correct error msg when attempting to bind descriptorSet w/ 5 descriptors to pipelineLayout with only 2 descriptors.";
2222 m_errorMonitor->DumpFailureMsgs();
2223 }
2224 vkDestroyPipelineLayout(m_device->device(), pipe_layout_one_desc, NULL);
2225 // 4. same # of descriptors but mismatch in type
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07002226 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 -07002227 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe_layout_five_samp, 0, 1, &descriptorSet[0], 0, NULL);
2228 if (!m_errorMonitor->DesiredMsgFound()) {
2229 FAIL() << "Did not receive correct error msg when attempting to bind UNIFORM_BUFFER descriptorSet to pipelineLayout with overlapping SAMPLER type.";
2230 m_errorMonitor->DumpFailureMsgs();
2231 }
2232 vkDestroyPipelineLayout(m_device->device(), pipe_layout_five_samp, NULL);
2233 // 5. same # of descriptors but mismatch in stageFlags
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07002234 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " descriptor from pipelineLayout has stageFlags ");
Tobin Ehlis8fab6562015-12-01 09:57:09 -07002235 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe_layout_fs_only, 0, 1, &descriptorSet[0], 0, NULL);
2236 if (!m_errorMonitor->DesiredMsgFound()) {
2237 FAIL() << "Did not receive correct error msg when attempting to bind UNIFORM_BUFFER descriptorSet with ALL stageFlags to pipelineLayout with FS-only stageFlags.";
2238 m_errorMonitor->DumpFailureMsgs();
2239 }
2240 // Cause INFO messages due to disturbing previously bound Sets
2241 // First bind sets 0 & 1
2242 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 2, &descriptorSet[0], 0, NULL);
2243 // 1. Disturb bound set0 by re-binding set1 w/ updated pipelineLayout
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07002244 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERF_WARN_BIT_EXT, " previously bound as set #0 was disturbed ");
Tobin Ehlis8fab6562015-12-01 09:57:09 -07002245 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe_layout_bad_set0, 1, 1, &descriptorSet[1], 0, NULL);
2246 if (!m_errorMonitor->DesiredMsgFound()) {
2247 FAIL() << "Did not receive correct info msg when binding Set1 w/ pipelineLayout that should disturb Set0.";
2248 m_errorMonitor->DumpFailureMsgs();
2249 }
Tobin Ehlis8fab6562015-12-01 09:57:09 -07002250 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 2, &descriptorSet[0], 0, NULL);
2251 // 2. Disturb set after last bound set
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07002252 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 -07002253 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe_layout_fs_only, 0, 1, &ds0_fs_only, 0, NULL);
2254 if (!m_errorMonitor->DesiredMsgFound()) {
2255 FAIL() << "Did not receive correct info msg when re-binding Set0 w/ pipelineLayout that should disturb Set1.";
2256 m_errorMonitor->DumpFailureMsgs();
2257 }
Tobin Ehlis88452832015-12-03 09:40:56 -07002258 // Cause draw-time errors due to PSO incompatibilities
2259 // 1. Error due to not binding required set (we actually use same code as above to disturb set0)
2260 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 2, &descriptorSet[0], 0, NULL);
2261 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 -07002262 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 -07002263 Draw(1, 0, 0, 0);
2264 if (!m_errorMonitor->DesiredMsgFound()) {
2265 FAIL() << "Did not receive correct error msg when attempting draw requiring Set0 but Set0 is not bound.";
2266 m_errorMonitor->DumpFailureMsgs();
2267 }
Tobin Ehlis991d45a2016-01-06 08:48:41 -07002268 vkDestroyPipelineLayout(m_device->device(), pipe_layout_bad_set0, NULL);
Tobin Ehlis88452832015-12-03 09:40:56 -07002269 // 2. Error due to bound set not being compatible with PSO's VkPipelineLayout (diff stageFlags in this case)
2270 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 2, &descriptorSet[0], 0, NULL);
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07002271 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " bound as set #0 is not compatible with ");
Tobin Ehlis88452832015-12-03 09:40:56 -07002272 Draw(1, 0, 0, 0);
2273 if (!m_errorMonitor->DesiredMsgFound()) {
2274 FAIL() << "Did not receive correct error msg when attempted draw where bound Set0 layout is not compatible PSO Set0 layout.";
2275 m_errorMonitor->DumpFailureMsgs();
2276 }
Tobin Ehlis8fab6562015-12-01 09:57:09 -07002277 // Remaining clean-up
2278 vkDestroyPipelineLayout(m_device->device(), pipe_layout_fs_only, NULL);
2279 for (uint32_t i=0; i<NUM_LAYOUTS; ++i) {
2280 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout[i], NULL);
2281 }
2282 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout_fs_only, NULL);
2283 vkFreeDescriptorSets(m_device->device(), ds_pool, 1, descriptorSet);
2284 vkDestroyBuffer(m_device->device(), dyub, NULL);
Tobin Ehlis559c6382015-11-05 09:52:49 -07002285 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
2286 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
2287}
Tobin Ehlis559c6382015-11-05 09:52:49 -07002288
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002289TEST_F(VkLayerTest, NoBeginCommandBuffer)
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06002290{
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002291
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07002292 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002293 "You must call vkBeginCommandBuffer() before this call to ");
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06002294
2295 ASSERT_NO_FATAL_FAILURE(InitState());
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002296 VkCommandBufferObj commandBuffer(m_device, m_commandPool);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06002297 // Call EndCommandBuffer() w/o calling BeginCommandBuffer()
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002298 vkEndCommandBuffer(commandBuffer.GetBufferHandle());
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002299
2300 if (!m_errorMonitor->DesiredMsgFound()) {
2301 FAIL() << "Did not recieve Error 'You must call vkBeginCommandBuffer() before this call to vkEndCommandBuffer()'";
2302 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06002303 }
2304}
2305
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002306
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06002307
Tobin Ehlis61b36f32015-12-16 08:19:42 -07002308TEST_F(VkLayerTest, SecondaryCommandBufferNullRenderpass)
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06002309{
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06002310 VkResult err;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002311 VkCommandBuffer draw_cmd;
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06002312
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07002313 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis61b36f32015-12-16 08:19:42 -07002314 " must specify a valid renderpass parameter.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002315
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06002316 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06002317
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002318 VkCommandBufferAllocateInfo cmd = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08002319 cmd.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
Cody Northropb4569702015-08-04 17:35:57 -06002320 cmd.pNext = NULL;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002321 cmd.commandPool = m_commandPool;
2322 cmd.level = VK_COMMAND_BUFFER_LEVEL_SECONDARY;
Jon Ashburnf19916e2016-01-11 13:12:43 -07002323 cmd.commandBufferCount = 1;
Cody Northropb4569702015-08-04 17:35:57 -06002324
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002325 err = vkAllocateCommandBuffers(m_device->device(), &cmd, &draw_cmd);
Mike Stroyand1c84a52015-08-18 14:40:24 -06002326 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06002327
2328 // Force the failure by not setting the Renderpass and Framebuffer fields
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002329 VkCommandBufferBeginInfo cmd_buf_info = {};
Jon Ashburnf19916e2016-01-11 13:12:43 -07002330 VkCommandBufferInheritanceInfo cmd_buf_hinfo = {};
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002331 cmd_buf_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
Cody Northropb4569702015-08-04 17:35:57 -06002332 cmd_buf_info.pNext = NULL;
Tobin Ehlis651d9b02015-12-16 05:01:22 -07002333 cmd_buf_info.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT | VK_COMMAND_BUFFER_USAGE_RENDER_PASS_CONTINUE_BIT;
Jon Ashburnf19916e2016-01-11 13:12:43 -07002334 cmd_buf_info.pInheritanceInfo = &cmd_buf_hinfo;
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 = {};
Jon Ashburnf19916e2016-01-11 13:12:43 -07002362 VkCommandBufferInheritanceInfo cmd_buf_hinfo = {};
Tobin Ehlisac0ef842015-12-14 13:46:38 -07002363 cmd_buf_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
2364 cmd_buf_info.pNext = NULL;
2365 cmd_buf_info.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT;
Jon Ashburnf19916e2016-01-11 13:12:43 -07002366 cmd_buf_info.pInheritanceInfo = &cmd_buf_hinfo;
Tobin Ehlisac0ef842015-12-14 13:46:38 -07002367
2368 // Begin CB to transition to recording state
2369 vkBeginCommandBuffer(commandBuffer.GetBufferHandle(), &cmd_buf_info);
2370 // Can't re-begin. This should trigger error
2371 vkBeginCommandBuffer(commandBuffer.GetBufferHandle(), &cmd_buf_info);
2372 if (!m_errorMonitor->DesiredMsgFound()) {
2373 FAIL() << "Did not receive Error 'Cannot call Begin on CB (0x<ADDR>) in the RECORDING state...'";
2374 m_errorMonitor->DumpFailureMsgs();
2375 }
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07002376 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attempt to reset command buffer ");
Tobin Ehlisac0ef842015-12-14 13:46:38 -07002377 VkCommandBufferResetFlags flags = 0; // Don't care about flags for this test
2378 // Reset attempt will trigger error due to incorrect CommandPool state
2379 vkResetCommandBuffer(commandBuffer.GetBufferHandle(), flags);
2380 if (!m_errorMonitor->DesiredMsgFound()) {
2381 FAIL() << "Did not receive Error 'Attempt to reset command buffer (0x<ADDR>) created from command pool...'";
2382 m_errorMonitor->DumpFailureMsgs();
2383 }
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07002384 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " attempts to implicitly reset cmdBuffer created from ");
Tobin Ehlisac0ef842015-12-14 13:46:38 -07002385 // Transition CB to RECORDED state
2386 vkEndCommandBuffer(commandBuffer.GetBufferHandle());
2387 // Now attempting to Begin will implicitly reset, which triggers error
2388 vkBeginCommandBuffer(commandBuffer.GetBufferHandle(), &cmd_buf_info);
2389 if (!m_errorMonitor->DesiredMsgFound()) {
2390 FAIL() << "Did not receive Error 'Call to vkBeginCommandBuffer() on command buffer (0x<ADDR>) attempts to implicitly reset...'";
2391 m_errorMonitor->DumpFailureMsgs();
2392 }
2393}
2394
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06002395TEST_F(VkLayerTest, InvalidPipelineCreateState)
2396{
2397 // Attempt to Create Gfx Pipeline w/o a VS
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06002398 VkResult err;
2399
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07002400 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002401 "Invalid Pipeline CreateInfo State: Vtx Shader required");
2402
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06002403 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002404 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinski209b5292015-09-17 09:44:05 -06002405
Chia-I Wu1b99bb22015-10-27 19:25:11 +08002406 VkDescriptorPoolSize ds_type_count = {};
Tony Barboureb254902015-07-15 12:50:33 -06002407 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wud50a7d72015-10-26 20:48:51 +08002408 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06002409
2410 VkDescriptorPoolCreateInfo ds_pool_ci = {};
2411 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
2412 ds_pool_ci.pNext = NULL;
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -06002413 ds_pool_ci.maxSets = 1;
Chia-I Wu1b99bb22015-10-27 19:25:11 +08002414 ds_pool_ci.poolSizeCount = 1;
2415 ds_pool_ci.pPoolSizes = &ds_type_count;
Mark Lobodzinski209b5292015-09-17 09:44:05 -06002416
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06002417 VkDescriptorPool ds_pool;
Chia-I Wuf7458c52015-10-26 21:10:41 +08002418 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06002419 ASSERT_VK_SUCCESS(err);
2420
Tony Barboureb254902015-07-15 12:50:33 -06002421 VkDescriptorSetLayoutBinding dsl_binding = {};
Chia-I Wud46e6ae2015-10-31 00:31:16 +08002422 dsl_binding.binding = 0;
Tony Barboureb254902015-07-15 12:50:33 -06002423 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wu02124482015-11-06 06:42:02 +08002424 dsl_binding.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06002425 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
2426 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06002427
Tony Barboureb254902015-07-15 12:50:33 -06002428 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
2429 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
2430 ds_layout_ci.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08002431 ds_layout_ci.bindingCount = 1;
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07002432 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -06002433
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06002434 VkDescriptorSetLayout ds_layout;
Chia-I Wuf7458c52015-10-26 21:10:41 +08002435 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06002436 ASSERT_VK_SUCCESS(err);
2437
2438 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002439 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08002440 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07002441 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06002442 alloc_info.descriptorPool = ds_pool;
2443 alloc_info.pSetLayouts = &ds_layout;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002444 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06002445 ASSERT_VK_SUCCESS(err);
2446
Tony Barboureb254902015-07-15 12:50:33 -06002447 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
2448 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
Chia-I Wud50a7d72015-10-26 20:48:51 +08002449 pipeline_layout_ci.setLayoutCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06002450 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06002451
2452 VkPipelineLayout pipeline_layout;
Chia-I Wuf7458c52015-10-26 21:10:41 +08002453 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06002454 ASSERT_VK_SUCCESS(err);
2455
Tobin Ehlise68360f2015-10-01 11:15:13 -06002456 VkViewport vp = {}; // Just need dummy vp to point to
2457 VkRect2D sc = {}; // dummy scissor to point to
2458
2459 VkPipelineViewportStateCreateInfo vp_state_ci = {};
2460 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
2461 vp_state_ci.scissorCount = 1;
2462 vp_state_ci.pScissors = &sc;
2463 vp_state_ci.viewportCount = 1;
2464 vp_state_ci.pViewports = &vp;
2465
Tony Barboureb254902015-07-15 12:50:33 -06002466 VkGraphicsPipelineCreateInfo gp_ci = {};
2467 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
Tobin Ehlise68360f2015-10-01 11:15:13 -06002468 gp_ci.pViewportState = &vp_state_ci;
Tony Barboureb254902015-07-15 12:50:33 -06002469 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
2470 gp_ci.layout = pipeline_layout;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002471 gp_ci.renderPass = renderPass();
Tony Barboureb254902015-07-15 12:50:33 -06002472
2473 VkPipelineCacheCreateInfo pc_ci = {};
2474 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
Chia-I Wu2bfb33c2015-10-26 17:24:52 +08002475 pc_ci.initialDataSize = 0;
2476 pc_ci.pInitialData = 0;
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06002477
2478 VkPipeline pipeline;
Jon Ashburnc669cc62015-07-09 15:02:25 -06002479 VkPipelineCache pipelineCache;
2480
Chia-I Wuf7458c52015-10-26 21:10:41 +08002481 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Jon Ashburnc669cc62015-07-09 15:02:25 -06002482 ASSERT_VK_SUCCESS(err);
Chia-I Wuf7458c52015-10-26 21:10:41 +08002483 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06002484
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002485 if (!m_errorMonitor->DesiredMsgFound()) {
2486 FAIL() << "Did not receive Error 'Invalid Pipeline CreateInfo State: Vtx Shader required'";
2487 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06002488 }
Mike Stroyand1c84a52015-08-18 14:40:24 -06002489
Chia-I Wuf7458c52015-10-26 21:10:41 +08002490 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
2491 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
2492 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
2493 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06002494}
Tobin Ehlis912df022015-09-17 08:46:18 -06002495/*// TODO : This test should be good, but needs Tess support in compiler to run
2496TEST_F(VkLayerTest, InvalidPatchControlPoints)
2497{
2498 // Attempt to Create Gfx Pipeline w/o a VS
Tobin Ehlis912df022015-09-17 08:46:18 -06002499 VkResult err;
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06002500
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07002501 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002502 "Invalid Pipeline CreateInfo State: VK_PRIMITIVE_TOPOLOGY_PATCH primitive ");
2503
Tobin Ehlis912df022015-09-17 08:46:18 -06002504 ASSERT_NO_FATAL_FAILURE(InitState());
2505 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlis912df022015-09-17 08:46:18 -06002506
Chia-I Wu1b99bb22015-10-27 19:25:11 +08002507 VkDescriptorPoolSize ds_type_count = {};
Tobin Ehlis912df022015-09-17 08:46:18 -06002508 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wud50a7d72015-10-26 20:48:51 +08002509 ds_type_count.descriptorCount = 1;
Tobin Ehlis912df022015-09-17 08:46:18 -06002510
2511 VkDescriptorPoolCreateInfo ds_pool_ci = {};
2512 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
2513 ds_pool_ci.pNext = NULL;
Chia-I Wu1b99bb22015-10-27 19:25:11 +08002514 ds_pool_ci.poolSizeCount = 1;
2515 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlis912df022015-09-17 08:46:18 -06002516
2517 VkDescriptorPool ds_pool;
Chia-I Wuf7458c52015-10-26 21:10:41 +08002518 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 -06002519 ASSERT_VK_SUCCESS(err);
2520
2521 VkDescriptorSetLayoutBinding dsl_binding = {};
Chia-I Wud46e6ae2015-10-31 00:31:16 +08002522 dsl_binding.binding = 0;
Tobin Ehlis912df022015-09-17 08:46:18 -06002523 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wu02124482015-11-06 06:42:02 +08002524 dsl_binding.descriptorCount = 1;
Tobin Ehlis912df022015-09-17 08:46:18 -06002525 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
2526 dsl_binding.pImmutableSamplers = NULL;
2527
2528 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
2529 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
2530 ds_layout_ci.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08002531 ds_layout_ci.bindingCount = 1;
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07002532 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlis912df022015-09-17 08:46:18 -06002533
2534 VkDescriptorSetLayout ds_layout;
Chia-I Wuf7458c52015-10-26 21:10:41 +08002535 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis912df022015-09-17 08:46:18 -06002536 ASSERT_VK_SUCCESS(err);
2537
2538 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002539 err = vkAllocateDescriptorSets(m_device->device(), ds_pool, VK_DESCRIPTOR_SET_USAGE_NON_FREE, 1, &ds_layout, &descriptorSet);
Tobin Ehlis912df022015-09-17 08:46:18 -06002540 ASSERT_VK_SUCCESS(err);
2541
2542 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
2543 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
2544 pipeline_layout_ci.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08002545 pipeline_layout_ci.setLayoutCount = 1;
Tobin Ehlis912df022015-09-17 08:46:18 -06002546 pipeline_layout_ci.pSetLayouts = &ds_layout;
2547
2548 VkPipelineLayout pipeline_layout;
Chia-I Wuf7458c52015-10-26 21:10:41 +08002549 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis912df022015-09-17 08:46:18 -06002550 ASSERT_VK_SUCCESS(err);
2551
2552 VkPipelineShaderStageCreateInfo shaderStages[3];
2553 memset(&shaderStages, 0, 3 * sizeof(VkPipelineShaderStageCreateInfo));
2554
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06002555 VkShaderObj vs(m_device,bindStateVertShaderText,VK_SHADER_STAGE_VERTEX_BIT, this);
Tobin Ehlis912df022015-09-17 08:46:18 -06002556 // Just using VS txt for Tess shaders as we don't care about functionality
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06002557 VkShaderObj tc(m_device,bindStateVertShaderText,VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT, this);
2558 VkShaderObj te(m_device,bindStateVertShaderText,VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT, this);
Tobin Ehlis912df022015-09-17 08:46:18 -06002559
2560 shaderStages[0].sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06002561 shaderStages[0].stage = VK_SHADER_STAGE_VERTEX_BIT;
Tobin Ehlis912df022015-09-17 08:46:18 -06002562 shaderStages[0].shader = vs.handle();
2563 shaderStages[1].sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06002564 shaderStages[1].stage = VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT;
Tobin Ehlis912df022015-09-17 08:46:18 -06002565 shaderStages[1].shader = tc.handle();
2566 shaderStages[2].sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06002567 shaderStages[2].stage = VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT;
Tobin Ehlis912df022015-09-17 08:46:18 -06002568 shaderStages[2].shader = te.handle();
2569
2570 VkPipelineInputAssemblyStateCreateInfo iaCI = {};
2571 iaCI.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
Chia-I Wu515eb8f2015-10-31 00:31:16 +08002572 iaCI.topology = VK_PRIMITIVE_TOPOLOGY_PATCH_LIST;
Tobin Ehlis912df022015-09-17 08:46:18 -06002573
2574 VkPipelineTessellationStateCreateInfo tsCI = {};
2575 tsCI.sType = VK_STRUCTURE_TYPE_PIPELINE_TESSELLATION_STATE_CREATE_INFO;
2576 tsCI.patchControlPoints = 0; // This will cause an error
2577
2578 VkGraphicsPipelineCreateInfo gp_ci = {};
2579 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
2580 gp_ci.pNext = NULL;
2581 gp_ci.stageCount = 3;
2582 gp_ci.pStages = shaderStages;
2583 gp_ci.pVertexInputState = NULL;
2584 gp_ci.pInputAssemblyState = &iaCI;
2585 gp_ci.pTessellationState = &tsCI;
2586 gp_ci.pViewportState = NULL;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002587 gp_ci.pRasterizationState = NULL;
Tobin Ehlis912df022015-09-17 08:46:18 -06002588 gp_ci.pMultisampleState = NULL;
2589 gp_ci.pDepthStencilState = NULL;
2590 gp_ci.pColorBlendState = NULL;
2591 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
2592 gp_ci.layout = pipeline_layout;
2593 gp_ci.renderPass = renderPass();
2594
2595 VkPipelineCacheCreateInfo pc_ci = {};
2596 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
2597 pc_ci.pNext = NULL;
2598 pc_ci.initialSize = 0;
2599 pc_ci.initialData = 0;
2600 pc_ci.maxSize = 0;
2601
2602 VkPipeline pipeline;
2603 VkPipelineCache pipelineCache;
2604
Chia-I Wuf7458c52015-10-26 21:10:41 +08002605 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Tobin Ehlis912df022015-09-17 08:46:18 -06002606 ASSERT_VK_SUCCESS(err);
Chia-I Wuf7458c52015-10-26 21:10:41 +08002607 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlis912df022015-09-17 08:46:18 -06002608
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002609 if (!m_errorMonitor->DesiredMsgFound()) {
2610 FAIL() << "Did not receive Error 'Invalid Pipeline CreateInfo State: VK_PRIMITIVE_TOPOLOGY_PATCH primitive...'";
2611 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlis912df022015-09-17 08:46:18 -06002612 }
Mike Stroyand1c84a52015-08-18 14:40:24 -06002613
Chia-I Wuf7458c52015-10-26 21:10:41 +08002614 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
2615 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
2616 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
2617 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis912df022015-09-17 08:46:18 -06002618}
2619*/
Tobin Ehlise68360f2015-10-01 11:15:13 -06002620// Set scissor and viewport counts to different numbers
2621TEST_F(VkLayerTest, PSOViewportScissorCountMismatch)
2622{
2623 // Attempt to Create Gfx Pipeline w/o a VS
Tobin Ehlise68360f2015-10-01 11:15:13 -06002624 VkResult err;
2625
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07002626 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002627 "Gfx Pipeline viewport count (1) must match scissor count (0).");
2628
Tobin Ehlise68360f2015-10-01 11:15:13 -06002629 ASSERT_NO_FATAL_FAILURE(InitState());
2630 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlise68360f2015-10-01 11:15:13 -06002631
Chia-I Wu1b99bb22015-10-27 19:25:11 +08002632 VkDescriptorPoolSize ds_type_count = {};
Tobin Ehlise68360f2015-10-01 11:15:13 -06002633 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wud50a7d72015-10-26 20:48:51 +08002634 ds_type_count.descriptorCount = 1;
Tobin Ehlise68360f2015-10-01 11:15:13 -06002635
2636 VkDescriptorPoolCreateInfo ds_pool_ci = {};
2637 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
Tobin Ehlise68360f2015-10-01 11:15:13 -06002638 ds_pool_ci.maxSets = 1;
Chia-I Wu1b99bb22015-10-27 19:25:11 +08002639 ds_pool_ci.poolSizeCount = 1;
2640 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlise68360f2015-10-01 11:15:13 -06002641
2642 VkDescriptorPool ds_pool;
Chia-I Wuf7458c52015-10-26 21:10:41 +08002643 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlise68360f2015-10-01 11:15:13 -06002644 ASSERT_VK_SUCCESS(err);
2645
2646 VkDescriptorSetLayoutBinding dsl_binding = {};
Chia-I Wud46e6ae2015-10-31 00:31:16 +08002647 dsl_binding.binding = 0;
Tobin Ehlise68360f2015-10-01 11:15:13 -06002648 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wu02124482015-11-06 06:42:02 +08002649 dsl_binding.descriptorCount = 1;
Tobin Ehlise68360f2015-10-01 11:15:13 -06002650 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
2651
2652 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
2653 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
Chia-I Wud50a7d72015-10-26 20:48:51 +08002654 ds_layout_ci.bindingCount = 1;
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07002655 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlise68360f2015-10-01 11:15:13 -06002656
2657 VkDescriptorSetLayout ds_layout;
Chia-I Wuf7458c52015-10-26 21:10:41 +08002658 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06002659 ASSERT_VK_SUCCESS(err);
2660
2661 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002662 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08002663 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07002664 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06002665 alloc_info.descriptorPool = ds_pool;
2666 alloc_info.pSetLayouts = &ds_layout;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002667 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlise68360f2015-10-01 11:15:13 -06002668 ASSERT_VK_SUCCESS(err);
2669
2670 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
2671 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
Chia-I Wud50a7d72015-10-26 20:48:51 +08002672 pipeline_layout_ci.setLayoutCount = 1;
Tobin Ehlise68360f2015-10-01 11:15:13 -06002673 pipeline_layout_ci.pSetLayouts = &ds_layout;
2674
2675 VkPipelineLayout pipeline_layout;
Chia-I Wuf7458c52015-10-26 21:10:41 +08002676 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06002677 ASSERT_VK_SUCCESS(err);
2678
2679 VkViewport vp = {}; // Just need dummy vp to point to
2680
2681 VkPipelineViewportStateCreateInfo vp_state_ci = {};
2682 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
2683 vp_state_ci.scissorCount = 0;
2684 vp_state_ci.viewportCount = 1; // Count mismatch should cause error
2685 vp_state_ci.pViewports = &vp;
2686
Cody Northropeb3a6c12015-10-05 14:44:45 -06002687 VkPipelineShaderStageCreateInfo shaderStages[2];
2688 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
Tobin Ehlise68360f2015-10-01 11:15:13 -06002689
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06002690 VkShaderObj vs(m_device,bindStateVertShaderText,VK_SHADER_STAGE_VERTEX_BIT, this);
2691 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 -06002692 // but add it to be able to run on more devices
Chia-I Wu28e06912015-10-31 00:31:16 +08002693 shaderStages[0] = vs.GetStageCreateInfo();
2694 shaderStages[1] = fs.GetStageCreateInfo();
Tobin Ehlise68360f2015-10-01 11:15:13 -06002695
2696 VkGraphicsPipelineCreateInfo gp_ci = {};
2697 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
Cody Northropeb3a6c12015-10-05 14:44:45 -06002698 gp_ci.stageCount = 2;
2699 gp_ci.pStages = shaderStages;
Tobin Ehlise68360f2015-10-01 11:15:13 -06002700 gp_ci.pViewportState = &vp_state_ci;
2701 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
2702 gp_ci.layout = pipeline_layout;
2703 gp_ci.renderPass = renderPass();
2704
2705 VkPipelineCacheCreateInfo pc_ci = {};
2706 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
2707
2708 VkPipeline pipeline;
2709 VkPipelineCache pipelineCache;
2710
Chia-I Wuf7458c52015-10-26 21:10:41 +08002711 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Tobin Ehlise68360f2015-10-01 11:15:13 -06002712 ASSERT_VK_SUCCESS(err);
Chia-I Wuf7458c52015-10-26 21:10:41 +08002713 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlise68360f2015-10-01 11:15:13 -06002714
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002715 if (!m_errorMonitor->DesiredMsgFound()) {
2716 FAIL() << "Did not receive Error 'Gfx Pipeline viewport count (1) must match scissor count (0).'";
2717 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlise68360f2015-10-01 11:15:13 -06002718 }
2719
Chia-I Wuf7458c52015-10-26 21:10:41 +08002720 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
2721 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
2722 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
2723 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlise68360f2015-10-01 11:15:13 -06002724}
Tobin Ehlisd332f282015-10-02 11:00:56 -06002725// Don't set viewport state in PSO. This is an error b/c we always need this state
2726// for the counts even if the data is going to be set dynamically.
2727TEST_F(VkLayerTest, PSOViewportStateNotSet)
Tobin Ehlise68360f2015-10-01 11:15:13 -06002728{
2729 // Attempt to Create Gfx Pipeline w/o a VS
Tobin Ehlise68360f2015-10-01 11:15:13 -06002730 VkResult err;
2731
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07002732 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002733 "Gfx Pipeline pViewportState is null. Even if ");
2734
Tobin Ehlise68360f2015-10-01 11:15:13 -06002735 ASSERT_NO_FATAL_FAILURE(InitState());
2736 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlise68360f2015-10-01 11:15:13 -06002737
Chia-I Wu1b99bb22015-10-27 19:25:11 +08002738 VkDescriptorPoolSize ds_type_count = {};
Tobin Ehlise68360f2015-10-01 11:15:13 -06002739 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wud50a7d72015-10-26 20:48:51 +08002740 ds_type_count.descriptorCount = 1;
Tobin Ehlise68360f2015-10-01 11:15:13 -06002741
2742 VkDescriptorPoolCreateInfo ds_pool_ci = {};
2743 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
Tobin Ehlise68360f2015-10-01 11:15:13 -06002744 ds_pool_ci.maxSets = 1;
Chia-I Wu1b99bb22015-10-27 19:25:11 +08002745 ds_pool_ci.poolSizeCount = 1;
2746 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlise68360f2015-10-01 11:15:13 -06002747
2748 VkDescriptorPool ds_pool;
Chia-I Wuf7458c52015-10-26 21:10:41 +08002749 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlise68360f2015-10-01 11:15:13 -06002750 ASSERT_VK_SUCCESS(err);
2751
2752 VkDescriptorSetLayoutBinding dsl_binding = {};
Chia-I Wud46e6ae2015-10-31 00:31:16 +08002753 dsl_binding.binding = 0;
Tobin Ehlise68360f2015-10-01 11:15:13 -06002754 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wu02124482015-11-06 06:42:02 +08002755 dsl_binding.descriptorCount = 1;
Tobin Ehlise68360f2015-10-01 11:15:13 -06002756 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
2757
2758 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
2759 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
Chia-I Wud50a7d72015-10-26 20:48:51 +08002760 ds_layout_ci.bindingCount = 1;
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07002761 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlise68360f2015-10-01 11:15:13 -06002762
2763 VkDescriptorSetLayout ds_layout;
Chia-I Wuf7458c52015-10-26 21:10:41 +08002764 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06002765 ASSERT_VK_SUCCESS(err);
2766
2767 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002768 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08002769 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07002770 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06002771 alloc_info.descriptorPool = ds_pool;
2772 alloc_info.pSetLayouts = &ds_layout;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002773 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlise68360f2015-10-01 11:15:13 -06002774 ASSERT_VK_SUCCESS(err);
2775
2776 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
2777 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
Chia-I Wud50a7d72015-10-26 20:48:51 +08002778 pipeline_layout_ci.setLayoutCount = 1;
Tobin Ehlise68360f2015-10-01 11:15:13 -06002779 pipeline_layout_ci.pSetLayouts = &ds_layout;
2780
2781 VkPipelineLayout pipeline_layout;
Chia-I Wuf7458c52015-10-26 21:10:41 +08002782 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06002783 ASSERT_VK_SUCCESS(err);
2784
2785 VkDynamicState sc_state = VK_DYNAMIC_STATE_SCISSOR;
2786 // Set scissor as dynamic to avoid second error
2787 VkPipelineDynamicStateCreateInfo dyn_state_ci = {};
2788 dyn_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
2789 dyn_state_ci.dynamicStateCount = 1;
2790 dyn_state_ci.pDynamicStates = &sc_state;
2791
Cody Northropeb3a6c12015-10-05 14:44:45 -06002792 VkPipelineShaderStageCreateInfo shaderStages[2];
2793 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
Tobin Ehlise68360f2015-10-01 11:15:13 -06002794
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06002795 VkShaderObj vs(m_device,bindStateVertShaderText,VK_SHADER_STAGE_VERTEX_BIT, this);
2796 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 -06002797 // but add it to be able to run on more devices
Chia-I Wu28e06912015-10-31 00:31:16 +08002798 shaderStages[0] = vs.GetStageCreateInfo();
2799 shaderStages[1] = fs.GetStageCreateInfo();
Tobin Ehlise68360f2015-10-01 11:15:13 -06002800
2801 VkGraphicsPipelineCreateInfo gp_ci = {};
2802 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
Cody Northropeb3a6c12015-10-05 14:44:45 -06002803 gp_ci.stageCount = 2;
2804 gp_ci.pStages = shaderStages;
Tobin Ehlise68360f2015-10-01 11:15:13 -06002805 gp_ci.pViewportState = NULL; // Not setting VP state w/o dynamic vp state should cause validation error
2806 gp_ci.pDynamicState = &dyn_state_ci;
2807 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
2808 gp_ci.layout = pipeline_layout;
2809 gp_ci.renderPass = renderPass();
2810
2811 VkPipelineCacheCreateInfo pc_ci = {};
2812 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
2813
2814 VkPipeline pipeline;
2815 VkPipelineCache pipelineCache;
2816
Chia-I Wuf7458c52015-10-26 21:10:41 +08002817 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Tobin Ehlise68360f2015-10-01 11:15:13 -06002818 ASSERT_VK_SUCCESS(err);
Chia-I Wuf7458c52015-10-26 21:10:41 +08002819 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlise68360f2015-10-01 11:15:13 -06002820
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002821 if (!m_errorMonitor->DesiredMsgFound()) {
2822 FAIL() << "Did not receive Error 'Gfx Pipeline pViewportState is null. Even if...'";
2823 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlise68360f2015-10-01 11:15:13 -06002824 }
2825
Chia-I Wuf7458c52015-10-26 21:10:41 +08002826 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
2827 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
2828 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
2829 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlise68360f2015-10-01 11:15:13 -06002830}
2831// Create PSO w/o non-zero viewportCount but no viewport data
Tobin Ehlisd332f282015-10-02 11:00:56 -06002832// Then run second test where dynamic scissor count doesn't match PSO scissor count
2833TEST_F(VkLayerTest, PSOViewportCountWithoutDataAndDynScissorMismatch)
Tobin Ehlise68360f2015-10-01 11:15:13 -06002834{
Tobin Ehlise68360f2015-10-01 11:15:13 -06002835 VkResult err;
2836
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07002837 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002838 "Gfx Pipeline viewportCount is 1, but pViewports is NULL. ");
2839
Tobin Ehlise68360f2015-10-01 11:15:13 -06002840 ASSERT_NO_FATAL_FAILURE(InitState());
2841 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlise68360f2015-10-01 11:15:13 -06002842
Chia-I Wu1b99bb22015-10-27 19:25:11 +08002843 VkDescriptorPoolSize ds_type_count = {};
Tobin Ehlise68360f2015-10-01 11:15:13 -06002844 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wud50a7d72015-10-26 20:48:51 +08002845 ds_type_count.descriptorCount = 1;
Tobin Ehlise68360f2015-10-01 11:15:13 -06002846
2847 VkDescriptorPoolCreateInfo ds_pool_ci = {};
2848 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
Tobin Ehlise68360f2015-10-01 11:15:13 -06002849 ds_pool_ci.maxSets = 1;
Chia-I Wu1b99bb22015-10-27 19:25:11 +08002850 ds_pool_ci.poolSizeCount = 1;
2851 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlise68360f2015-10-01 11:15:13 -06002852
2853 VkDescriptorPool ds_pool;
Chia-I Wuf7458c52015-10-26 21:10:41 +08002854 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlise68360f2015-10-01 11:15:13 -06002855 ASSERT_VK_SUCCESS(err);
2856
2857 VkDescriptorSetLayoutBinding dsl_binding = {};
Chia-I Wud46e6ae2015-10-31 00:31:16 +08002858 dsl_binding.binding = 0;
Tobin Ehlise68360f2015-10-01 11:15:13 -06002859 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wu02124482015-11-06 06:42:02 +08002860 dsl_binding.descriptorCount = 1;
Tobin Ehlise68360f2015-10-01 11:15:13 -06002861 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
2862
2863 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
2864 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
Chia-I Wud50a7d72015-10-26 20:48:51 +08002865 ds_layout_ci.bindingCount = 1;
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07002866 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlise68360f2015-10-01 11:15:13 -06002867
2868 VkDescriptorSetLayout ds_layout;
Chia-I Wuf7458c52015-10-26 21:10:41 +08002869 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06002870 ASSERT_VK_SUCCESS(err);
2871
2872 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002873 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08002874 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07002875 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06002876 alloc_info.descriptorPool = ds_pool;
2877 alloc_info.pSetLayouts = &ds_layout;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002878 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlise68360f2015-10-01 11:15:13 -06002879 ASSERT_VK_SUCCESS(err);
2880
2881 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
2882 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
Chia-I Wud50a7d72015-10-26 20:48:51 +08002883 pipeline_layout_ci.setLayoutCount = 1;
Tobin Ehlise68360f2015-10-01 11:15:13 -06002884 pipeline_layout_ci.pSetLayouts = &ds_layout;
2885
2886 VkPipelineLayout pipeline_layout;
Chia-I Wuf7458c52015-10-26 21:10:41 +08002887 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06002888 ASSERT_VK_SUCCESS(err);
2889
2890 VkPipelineViewportStateCreateInfo vp_state_ci = {};
2891 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
2892 vp_state_ci.viewportCount = 1;
2893 vp_state_ci.pViewports = NULL; // Null vp w/ count of 1 should cause error
2894 vp_state_ci.scissorCount = 1;
2895 vp_state_ci.pScissors = NULL; // Scissor is dynamic (below) so this won't cause error
2896
2897 VkDynamicState sc_state = VK_DYNAMIC_STATE_SCISSOR;
2898 // Set scissor as dynamic to avoid that error
2899 VkPipelineDynamicStateCreateInfo dyn_state_ci = {};
2900 dyn_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
2901 dyn_state_ci.dynamicStateCount = 1;
2902 dyn_state_ci.pDynamicStates = &sc_state;
2903
Cody Northropeb3a6c12015-10-05 14:44:45 -06002904 VkPipelineShaderStageCreateInfo shaderStages[2];
2905 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
Tobin Ehlise68360f2015-10-01 11:15:13 -06002906
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06002907 VkShaderObj vs(m_device,bindStateVertShaderText,VK_SHADER_STAGE_VERTEX_BIT, this);
2908 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 -06002909 // but add it to be able to run on more devices
Chia-I Wu28e06912015-10-31 00:31:16 +08002910 shaderStages[0] = vs.GetStageCreateInfo();
2911 shaderStages[1] = fs.GetStageCreateInfo();
Tobin Ehlise68360f2015-10-01 11:15:13 -06002912
Cody Northropf6622dc2015-10-06 10:33:21 -06002913 VkPipelineVertexInputStateCreateInfo vi_ci = {};
2914 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
2915 vi_ci.pNext = nullptr;
Chia-I Wud50a7d72015-10-26 20:48:51 +08002916 vi_ci.vertexBindingDescriptionCount = 0;
Cody Northropf6622dc2015-10-06 10:33:21 -06002917 vi_ci.pVertexBindingDescriptions = nullptr;
Chia-I Wud50a7d72015-10-26 20:48:51 +08002918 vi_ci.vertexAttributeDescriptionCount = 0;
Cody Northropf6622dc2015-10-06 10:33:21 -06002919 vi_ci.pVertexAttributeDescriptions = nullptr;
2920
2921 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
2922 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
2923 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
2924
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002925 VkPipelineRasterizationStateCreateInfo rs_ci = {};
Chia-I Wu1b99bb22015-10-27 19:25:11 +08002926 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
Cody Northropf6622dc2015-10-06 10:33:21 -06002927 rs_ci.pNext = nullptr;
2928
2929 VkPipelineColorBlendStateCreateInfo cb_ci = {};
2930 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
2931 cb_ci.pNext = nullptr;
2932
Tobin Ehlise68360f2015-10-01 11:15:13 -06002933 VkGraphicsPipelineCreateInfo gp_ci = {};
2934 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
Cody Northropeb3a6c12015-10-05 14:44:45 -06002935 gp_ci.stageCount = 2;
2936 gp_ci.pStages = shaderStages;
Cody Northropf6622dc2015-10-06 10:33:21 -06002937 gp_ci.pVertexInputState = &vi_ci;
2938 gp_ci.pInputAssemblyState = &ia_ci;
Tobin Ehlise68360f2015-10-01 11:15:13 -06002939 gp_ci.pViewportState = &vp_state_ci;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002940 gp_ci.pRasterizationState = &rs_ci;
Cody Northropf6622dc2015-10-06 10:33:21 -06002941 gp_ci.pColorBlendState = &cb_ci;
Tobin Ehlise68360f2015-10-01 11:15:13 -06002942 gp_ci.pDynamicState = &dyn_state_ci;
2943 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
2944 gp_ci.layout = pipeline_layout;
2945 gp_ci.renderPass = renderPass();
2946
2947 VkPipelineCacheCreateInfo pc_ci = {};
2948 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
2949
2950 VkPipeline pipeline;
2951 VkPipelineCache pipelineCache;
2952
Chia-I Wuf7458c52015-10-26 21:10:41 +08002953 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Tobin Ehlise68360f2015-10-01 11:15:13 -06002954 ASSERT_VK_SUCCESS(err);
Chia-I Wuf7458c52015-10-26 21:10:41 +08002955 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlise68360f2015-10-01 11:15:13 -06002956
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002957 if (!m_errorMonitor->DesiredMsgFound()) {
2958 FAIL() << "Did not recieve Error 'Gfx Pipeline viewportCount is 1, but pViewports is NULL...'";
2959 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlise68360f2015-10-01 11:15:13 -06002960 }
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002961
2962
Tobin Ehlisd332f282015-10-02 11:00:56 -06002963 // Now hit second fail case where we set scissor w/ different count than PSO
2964 // First need to successfully create the PSO from above by setting pViewports
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07002965 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002966 "Dynamic scissorCount from vkCmdSetScissor() is 2, but PSO scissorCount is 1. These counts must match.");
2967
Tobin Ehlisd332f282015-10-02 11:00:56 -06002968 VkViewport vp = {}; // Just need dummy vp to point to
2969 vp_state_ci.pViewports = &vp;
Chia-I Wuf7458c52015-10-26 21:10:41 +08002970 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlisd332f282015-10-02 11:00:56 -06002971 ASSERT_VK_SUCCESS(err);
2972 BeginCommandBuffer();
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002973 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
Tobin Ehlisd332f282015-10-02 11:00:56 -06002974 VkRect2D scissors[2] = {}; // don't care about data
2975 // Count of 2 doesn't match PSO count of 1
Jon Ashburn19d3bf12015-12-30 14:06:55 -07002976 vkCmdSetScissor(m_commandBuffer->GetBufferHandle(), 0, 2, scissors);
Tobin Ehlisd332f282015-10-02 11:00:56 -06002977 Draw(1, 0, 0, 0);
2978
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002979 if (!m_errorMonitor->DesiredMsgFound()) {
2980 FAIL() << "Did not receive Error 'Dynamic scissorCount from vkCmdSetScissor() is 2, but PSO scissorCount is 1...'";
2981 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlisd332f282015-10-02 11:00:56 -06002982 }
Tobin Ehlise68360f2015-10-01 11:15:13 -06002983
Chia-I Wuf7458c52015-10-26 21:10:41 +08002984 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
2985 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
2986 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
2987 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlise68360f2015-10-01 11:15:13 -06002988}
2989// Create PSO w/o non-zero scissorCount but no scissor data
Tobin Ehlisd332f282015-10-02 11:00:56 -06002990// Then run second test where dynamic viewportCount doesn't match PSO viewportCount
2991TEST_F(VkLayerTest, PSOScissorCountWithoutDataAndDynViewportMismatch)
Tobin Ehlise68360f2015-10-01 11:15:13 -06002992{
Tobin Ehlise68360f2015-10-01 11:15:13 -06002993 VkResult err;
2994
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07002995 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002996 "Gfx Pipeline scissorCount is 1, but pScissors is NULL. ");
2997
Tobin Ehlise68360f2015-10-01 11:15:13 -06002998 ASSERT_NO_FATAL_FAILURE(InitState());
2999 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlise68360f2015-10-01 11:15:13 -06003000
Chia-I Wu1b99bb22015-10-27 19:25:11 +08003001 VkDescriptorPoolSize ds_type_count = {};
Tobin Ehlise68360f2015-10-01 11:15:13 -06003002 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wud50a7d72015-10-26 20:48:51 +08003003 ds_type_count.descriptorCount = 1;
Tobin Ehlise68360f2015-10-01 11:15:13 -06003004
3005 VkDescriptorPoolCreateInfo ds_pool_ci = {};
3006 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
Tobin Ehlise68360f2015-10-01 11:15:13 -06003007 ds_pool_ci.maxSets = 1;
Chia-I Wu1b99bb22015-10-27 19:25:11 +08003008 ds_pool_ci.poolSizeCount = 1;
3009 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlise68360f2015-10-01 11:15:13 -06003010
3011 VkDescriptorPool ds_pool;
Chia-I Wuf7458c52015-10-26 21:10:41 +08003012 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlise68360f2015-10-01 11:15:13 -06003013 ASSERT_VK_SUCCESS(err);
3014
3015 VkDescriptorSetLayoutBinding dsl_binding = {};
Chia-I Wud46e6ae2015-10-31 00:31:16 +08003016 dsl_binding.binding = 0;
Tobin Ehlise68360f2015-10-01 11:15:13 -06003017 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wu02124482015-11-06 06:42:02 +08003018 dsl_binding.descriptorCount = 1;
Tobin Ehlise68360f2015-10-01 11:15:13 -06003019 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
3020
3021 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
3022 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
Chia-I Wud50a7d72015-10-26 20:48:51 +08003023 ds_layout_ci.bindingCount = 1;
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07003024 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlise68360f2015-10-01 11:15:13 -06003025
3026 VkDescriptorSetLayout ds_layout;
Chia-I Wuf7458c52015-10-26 21:10:41 +08003027 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06003028 ASSERT_VK_SUCCESS(err);
3029
3030 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003031 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08003032 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07003033 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06003034 alloc_info.descriptorPool = ds_pool;
3035 alloc_info.pSetLayouts = &ds_layout;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003036 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlise68360f2015-10-01 11:15:13 -06003037 ASSERT_VK_SUCCESS(err);
3038
3039 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
3040 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
Chia-I Wud50a7d72015-10-26 20:48:51 +08003041 pipeline_layout_ci.setLayoutCount = 1;
Tobin Ehlise68360f2015-10-01 11:15:13 -06003042 pipeline_layout_ci.pSetLayouts = &ds_layout;
3043
3044 VkPipelineLayout pipeline_layout;
Chia-I Wuf7458c52015-10-26 21:10:41 +08003045 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06003046 ASSERT_VK_SUCCESS(err);
3047
3048 VkPipelineViewportStateCreateInfo vp_state_ci = {};
3049 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
3050 vp_state_ci.scissorCount = 1;
3051 vp_state_ci.pScissors = NULL; // Null scissor w/ count of 1 should cause error
3052 vp_state_ci.viewportCount = 1;
3053 vp_state_ci.pViewports = NULL; // vp is dynamic (below) so this won't cause error
3054
3055 VkDynamicState vp_state = VK_DYNAMIC_STATE_VIEWPORT;
3056 // Set scissor as dynamic to avoid that error
3057 VkPipelineDynamicStateCreateInfo dyn_state_ci = {};
3058 dyn_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
3059 dyn_state_ci.dynamicStateCount = 1;
3060 dyn_state_ci.pDynamicStates = &vp_state;
3061
Cody Northropeb3a6c12015-10-05 14:44:45 -06003062 VkPipelineShaderStageCreateInfo shaderStages[2];
3063 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
Tobin Ehlise68360f2015-10-01 11:15:13 -06003064
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06003065 VkShaderObj vs(m_device,bindStateVertShaderText,VK_SHADER_STAGE_VERTEX_BIT, this);
3066 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 -06003067 // but add it to be able to run on more devices
Chia-I Wu28e06912015-10-31 00:31:16 +08003068 shaderStages[0] = vs.GetStageCreateInfo();
3069 shaderStages[1] = fs.GetStageCreateInfo();
Tobin Ehlise68360f2015-10-01 11:15:13 -06003070
Cody Northropf6622dc2015-10-06 10:33:21 -06003071 VkPipelineVertexInputStateCreateInfo vi_ci = {};
3072 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
3073 vi_ci.pNext = nullptr;
Chia-I Wud50a7d72015-10-26 20:48:51 +08003074 vi_ci.vertexBindingDescriptionCount = 0;
Cody Northropf6622dc2015-10-06 10:33:21 -06003075 vi_ci.pVertexBindingDescriptions = nullptr;
Chia-I Wud50a7d72015-10-26 20:48:51 +08003076 vi_ci.vertexAttributeDescriptionCount = 0;
Cody Northropf6622dc2015-10-06 10:33:21 -06003077 vi_ci.pVertexAttributeDescriptions = nullptr;
3078
3079 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
3080 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
3081 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
3082
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003083 VkPipelineRasterizationStateCreateInfo rs_ci = {};
Chia-I Wu1b99bb22015-10-27 19:25:11 +08003084 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
Cody Northropf6622dc2015-10-06 10:33:21 -06003085 rs_ci.pNext = nullptr;
3086
3087 VkPipelineColorBlendStateCreateInfo cb_ci = {};
3088 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
3089 cb_ci.pNext = nullptr;
3090
Tobin Ehlise68360f2015-10-01 11:15:13 -06003091 VkGraphicsPipelineCreateInfo gp_ci = {};
3092 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
Cody Northropeb3a6c12015-10-05 14:44:45 -06003093 gp_ci.stageCount = 2;
3094 gp_ci.pStages = shaderStages;
Cody Northropf6622dc2015-10-06 10:33:21 -06003095 gp_ci.pVertexInputState = &vi_ci;
3096 gp_ci.pInputAssemblyState = &ia_ci;
Tobin Ehlise68360f2015-10-01 11:15:13 -06003097 gp_ci.pViewportState = &vp_state_ci;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003098 gp_ci.pRasterizationState = &rs_ci;
Cody Northropf6622dc2015-10-06 10:33:21 -06003099 gp_ci.pColorBlendState = &cb_ci;
Tobin Ehlise68360f2015-10-01 11:15:13 -06003100 gp_ci.pDynamicState = &dyn_state_ci;
3101 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
3102 gp_ci.layout = pipeline_layout;
3103 gp_ci.renderPass = renderPass();
3104
3105 VkPipelineCacheCreateInfo pc_ci = {};
3106 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
3107
3108 VkPipeline pipeline;
3109 VkPipelineCache pipelineCache;
3110
Chia-I Wuf7458c52015-10-26 21:10:41 +08003111 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Tobin Ehlise68360f2015-10-01 11:15:13 -06003112 ASSERT_VK_SUCCESS(err);
Chia-I Wuf7458c52015-10-26 21:10:41 +08003113 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlise68360f2015-10-01 11:15:13 -06003114
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06003115 if (!m_errorMonitor->DesiredMsgFound()) {
3116 FAIL() << "Did not recieve Error 'Gfx Pipeline scissorCount is 1, but pScissors is NULL...'";
3117 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlise68360f2015-10-01 11:15:13 -06003118 }
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06003119
Tobin Ehlisd332f282015-10-02 11:00:56 -06003120 // Now hit second fail case where we set scissor w/ different count than PSO
3121 // First need to successfully create the PSO from above by setting pViewports
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07003122 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06003123 "Dynamic viewportCount from vkCmdSetViewport() is 2, but PSO viewportCount is 1. These counts must match.");
3124
Tobin Ehlisd332f282015-10-02 11:00:56 -06003125 VkRect2D sc = {}; // Just need dummy vp to point to
3126 vp_state_ci.pScissors = &sc;
Chia-I Wuf7458c52015-10-26 21:10:41 +08003127 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlisd332f282015-10-02 11:00:56 -06003128 ASSERT_VK_SUCCESS(err);
3129 BeginCommandBuffer();
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003130 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
Tobin Ehlisd332f282015-10-02 11:00:56 -06003131 VkViewport viewports[2] = {}; // don't care about data
3132 // Count of 2 doesn't match PSO count of 1
Jon Ashburn19d3bf12015-12-30 14:06:55 -07003133 vkCmdSetViewport(m_commandBuffer->GetBufferHandle(), 0, 2, viewports);
Tobin Ehlisd332f282015-10-02 11:00:56 -06003134 Draw(1, 0, 0, 0);
3135
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06003136 if (!m_errorMonitor->DesiredMsgFound()) {
3137 FAIL() << "Did not receive Error 'Dynamic viewportCount from vkCmdSetViewport() is 2, but PSO viewportCount is 1...'";
3138 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlisd332f282015-10-02 11:00:56 -06003139 }
Tobin Ehlise68360f2015-10-01 11:15:13 -06003140
Chia-I Wuf7458c52015-10-26 21:10:41 +08003141 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
3142 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
3143 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
3144 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlise68360f2015-10-01 11:15:13 -06003145}
3146
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06003147TEST_F(VkLayerTest, NullRenderPass)
3148{
3149 // Bind a NULL RenderPass
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07003150 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06003151 "You cannot use a NULL RenderPass object in vkCmdBeginRenderPass()");
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06003152
3153 ASSERT_NO_FATAL_FAILURE(InitState());
3154 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06003155
Tony Barbourfe3351b2015-07-28 10:17:20 -06003156 BeginCommandBuffer();
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06003157 // Don't care about RenderPass handle b/c error should be flagged before that
Chia-I Wu1b99bb22015-10-27 19:25:11 +08003158 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), NULL, VK_SUBPASS_CONTENTS_INLINE);
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06003159
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06003160 if (!m_errorMonitor->DesiredMsgFound()) {
3161 FAIL() << "Did not receive Error 'You cannot use a NULL RenderPass object in vkCmdBeginRenderPass()'";
3162 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06003163 }
3164}
3165
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06003166TEST_F(VkLayerTest, RenderPassWithinRenderPass)
3167{
3168 // Bind a BeginRenderPass within an active RenderPass
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07003169 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06003170 "It is invalid to issue this call inside an active render pass");
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06003171
3172 ASSERT_NO_FATAL_FAILURE(InitState());
3173 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06003174
Tony Barbourfe3351b2015-07-28 10:17:20 -06003175 BeginCommandBuffer();
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06003176 // Just create a dummy Renderpass that's non-NULL so we can get to the proper error
Tony Barboureb254902015-07-15 12:50:33 -06003177 VkRenderPassBeginInfo rp_begin = {};
3178 rp_begin.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO;
3179 rp_begin.pNext = NULL;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06003180 rp_begin.renderPass = renderPass();
3181 rp_begin.framebuffer = framebuffer();
Mark Lobodzinski209b5292015-09-17 09:44:05 -06003182
Chia-I Wu1b99bb22015-10-27 19:25:11 +08003183 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &rp_begin, VK_SUBPASS_CONTENTS_INLINE);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06003184
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06003185 if (!m_errorMonitor->DesiredMsgFound()) {
3186 FAIL() << "Did not receive Error 'It is invalid to issue this call inside an active render pass...'";
3187 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06003188 }
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06003189}
3190
Mark Lobodzinskid5639502015-09-24 09:51:47 -06003191TEST_F(VkLayerTest, FillBufferWithinRenderPass)
3192{
3193 // Call CmdFillBuffer within an active renderpass
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07003194 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06003195 "It is invalid to issue this call inside an active render pass");
Mark Lobodzinskid5639502015-09-24 09:51:47 -06003196
3197 ASSERT_NO_FATAL_FAILURE(InitState());
3198 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskid5639502015-09-24 09:51:47 -06003199
3200 // Renderpass is started here
3201 BeginCommandBuffer();
3202
3203 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003204 vk_testing::Buffer dstBuffer;
3205 dstBuffer.init_as_dst(*m_device, (VkDeviceSize)1024, reqs);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06003206
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003207 m_commandBuffer->FillBuffer(dstBuffer.handle(), 0, 4, 0x11111111);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06003208
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06003209 if (!m_errorMonitor->DesiredMsgFound()) {
3210 FAIL() << "Did not receive Error 'It is invalid to issue this call inside an active render pass...'";
3211 m_errorMonitor->DumpFailureMsgs();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06003212 }
3213}
3214
3215TEST_F(VkLayerTest, UpdateBufferWithinRenderPass)
3216{
3217 // Call CmdUpdateBuffer within an active renderpass
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07003218 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06003219 "It is invalid to issue this call inside an active render pass");
Mark Lobodzinskid5639502015-09-24 09:51:47 -06003220
3221 ASSERT_NO_FATAL_FAILURE(InitState());
3222 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskid5639502015-09-24 09:51:47 -06003223
3224 // Renderpass is started here
3225 BeginCommandBuffer();
3226
3227 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003228 vk_testing::Buffer dstBuffer;
3229 dstBuffer.init_as_dst(*m_device, (VkDeviceSize)1024, reqs);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06003230
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003231 VkDeviceSize dstOffset = 0;
Mark Lobodzinskid5639502015-09-24 09:51:47 -06003232 VkDeviceSize dataSize = 1024;
3233 const uint32_t *pData = NULL;
3234
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003235 vkCmdUpdateBuffer(m_commandBuffer->GetBufferHandle(), dstBuffer.handle(), dstOffset, dataSize, pData);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06003236
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06003237 if (!m_errorMonitor->DesiredMsgFound()) {
3238 FAIL() << "Did not receive Error 'It is invalid to issue this call inside an active render pass...'";
3239 m_errorMonitor->DumpFailureMsgs();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06003240 }
3241}
3242
3243TEST_F(VkLayerTest, ClearColorImageWithinRenderPass)
3244{
3245 // Call CmdClearColorImage within an active RenderPass
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07003246 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06003247 "It is invalid to issue this call inside an active render pass");
Mark Lobodzinskid5639502015-09-24 09:51:47 -06003248
3249 ASSERT_NO_FATAL_FAILURE(InitState());
3250 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskid5639502015-09-24 09:51:47 -06003251
3252 // Renderpass is started here
3253 BeginCommandBuffer();
3254
3255 VkClearColorValue clear_color = {0};
3256 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
3257 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
3258 const int32_t tex_width = 32;
3259 const int32_t tex_height = 32;
3260 VkImageCreateInfo image_create_info = {};
3261 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
3262 image_create_info.pNext = NULL;
3263 image_create_info.imageType = VK_IMAGE_TYPE_2D;
3264 image_create_info.format = tex_format;
3265 image_create_info.extent.width = tex_width;
3266 image_create_info.extent.height = tex_height;
3267 image_create_info.extent.depth = 1;
3268 image_create_info.mipLevels = 1;
Courtney Goeltzenleuchter5d2aed42015-10-21 17:57:31 -06003269 image_create_info.arrayLayers = 1;
Chia-I Wu5c17c962015-10-31 00:31:16 +08003270 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Mark Lobodzinskid5639502015-09-24 09:51:47 -06003271 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
3272 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
3273
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003274 vk_testing::Image dstImage;
3275 dstImage.init(*m_device, (const VkImageCreateInfo&)image_create_info, reqs);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06003276
3277 const VkImageSubresourceRange range =
3278 vk_testing::Image::subresource_range(image_create_info, VK_IMAGE_ASPECT_COLOR_BIT);
3279
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003280 vkCmdClearColorImage(m_commandBuffer->GetBufferHandle(),
3281 dstImage.handle(),
Mark Lobodzinskid5639502015-09-24 09:51:47 -06003282 VK_IMAGE_LAYOUT_GENERAL,
3283 &clear_color,
3284 1,
3285 &range);
3286
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06003287 if (!m_errorMonitor->DesiredMsgFound()) {
3288 FAIL() << "Did not receive Error 'It is invalid to issue this call inside an active render pass...'";
3289 m_errorMonitor->DumpFailureMsgs();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06003290 }
3291}
3292
3293TEST_F(VkLayerTest, ClearDepthStencilImageWithinRenderPass)
3294{
3295 // Call CmdClearDepthStencilImage within an active RenderPass
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07003296 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06003297 "It is invalid to issue this call inside an active render pass");
Mark Lobodzinskid5639502015-09-24 09:51:47 -06003298
3299 ASSERT_NO_FATAL_FAILURE(InitState());
3300 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskid5639502015-09-24 09:51:47 -06003301
3302 // Renderpass is started here
3303 BeginCommandBuffer();
3304
3305 VkClearDepthStencilValue clear_value = {0};
3306 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
3307 VkImageCreateInfo image_create_info = vk_testing::Image::create_info();
3308 image_create_info.imageType = VK_IMAGE_TYPE_2D;
3309 image_create_info.format = VK_FORMAT_D24_UNORM_S8_UINT;
3310 image_create_info.extent.width = 64;
3311 image_create_info.extent.height = 64;
3312 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
3313 image_create_info.usage = VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT;
3314
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003315 vk_testing::Image dstImage;
3316 dstImage.init(*m_device, (const VkImageCreateInfo&)image_create_info, reqs);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06003317
3318 const VkImageSubresourceRange range =
3319 vk_testing::Image::subresource_range(image_create_info, VK_IMAGE_ASPECT_DEPTH_BIT);
3320
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003321 vkCmdClearDepthStencilImage(m_commandBuffer->GetBufferHandle(),
3322 dstImage.handle(),
Mark Lobodzinskid5639502015-09-24 09:51:47 -06003323 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL,
3324 &clear_value,
3325 1,
3326 &range);
3327
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06003328 if (!m_errorMonitor->DesiredMsgFound()) {
3329 FAIL() << "Did not receive Error 'It is invalid to issue this call inside an active render pass...'";
3330 m_errorMonitor->DumpFailureMsgs();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06003331 }
3332}
3333
3334TEST_F(VkLayerTest, ClearColorAttachmentsOutsideRenderPass)
3335{
Courtney Goeltzenleuchterc9323e02015-10-15 16:51:05 -06003336 // Call CmdClearAttachmentss outside of an active RenderPass
Mark Lobodzinskid5639502015-09-24 09:51:47 -06003337 VkResult err;
3338
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07003339 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06003340 "vkCmdClearAttachments: This call must be issued inside an active render pass");
3341
Mark Lobodzinskid5639502015-09-24 09:51:47 -06003342 ASSERT_NO_FATAL_FAILURE(InitState());
3343 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskid5639502015-09-24 09:51:47 -06003344
3345 // Start no RenderPass
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003346 err = m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06003347 ASSERT_VK_SUCCESS(err);
3348
Courtney Goeltzenleuchterc9323e02015-10-15 16:51:05 -06003349 VkClearAttachment color_attachment;
3350 color_attachment.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
3351 color_attachment.clearValue.color.float32[0] = 0;
3352 color_attachment.clearValue.color.float32[1] = 0;
3353 color_attachment.clearValue.color.float32[2] = 0;
3354 color_attachment.clearValue.color.float32[3] = 0;
3355 color_attachment.colorAttachment = 0;
Courtney Goeltzenleuchter5d2aed42015-10-21 17:57:31 -06003356 VkClearRect clear_rect = { { { 0, 0 }, { 32, 32 } } };
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003357 vkCmdClearAttachments(m_commandBuffer->GetBufferHandle(),
Courtney Goeltzenleuchterc9323e02015-10-15 16:51:05 -06003358 1, &color_attachment,
3359 1, &clear_rect);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06003360
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06003361 if (!m_errorMonitor->DesiredMsgFound()) {
3362 FAIL() << "Did not receive Error 'vkCmdClearAttachments: This call must be issued inside an active render pass.'";
3363 m_errorMonitor->DumpFailureMsgs();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06003364 }
3365}
3366
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06003367TEST_F(VkLayerTest, InvalidDynamicStateObject)
3368{
3369 // Create a valid cmd buffer
3370 // call vkCmdBindDynamicStateObject w/ false DS Obj
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06003371 // TODO : Simple check for bad object should be added to ObjectTracker to catch this case
3372 // The DS check for this is after driver has been called to validate DS internal data struct
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06003373}
Tobin Ehlis1056d452015-05-27 14:55:35 -06003374
Tobin Ehlisc4c23182015-09-17 12:24:13 -06003375TEST_F(VkLayerTest, IdxBufferAlignmentError)
3376{
3377 // Bind a BeginRenderPass within an active RenderPass
Tobin Ehlisc4c23182015-09-17 12:24:13 -06003378 VkResult err;
3379
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07003380 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06003381 "vkCmdBindIndexBuffer() offset (0x7) does not fall on ");
3382
Tobin Ehlisc4c23182015-09-17 12:24:13 -06003383 ASSERT_NO_FATAL_FAILURE(InitState());
3384 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlisc4c23182015-09-17 12:24:13 -06003385 uint32_t qfi = 0;
3386 VkBufferCreateInfo buffCI = {};
3387 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
3388 buffCI.size = 1024;
3389 buffCI.usage = VK_BUFFER_USAGE_INDEX_BUFFER_BIT;
Chia-I Wud50a7d72015-10-26 20:48:51 +08003390 buffCI.queueFamilyIndexCount = 1;
Tobin Ehlisc4c23182015-09-17 12:24:13 -06003391 buffCI.pQueueFamilyIndices = &qfi;
3392
3393 VkBuffer ib;
Chia-I Wuf7458c52015-10-26 21:10:41 +08003394 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &ib);
Tobin Ehlisc4c23182015-09-17 12:24:13 -06003395 ASSERT_VK_SUCCESS(err);
3396
3397 BeginCommandBuffer();
3398 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003399 //vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlisc4c23182015-09-17 12:24:13 -06003400 // Should error before calling to driver so don't care about actual data
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003401 vkCmdBindIndexBuffer(m_commandBuffer->GetBufferHandle(), ib, 7, VK_INDEX_TYPE_UINT16);
Tobin Ehlisc4c23182015-09-17 12:24:13 -06003402
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06003403 if (!m_errorMonitor->DesiredMsgFound()) {
3404 FAIL() << "Did not receive Error 'vkCmdBindIndexBuffer() offset (0x7) does not fall on ...'";
3405 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlisc4c23182015-09-17 12:24:13 -06003406 }
Mike Stroyand1c84a52015-08-18 14:40:24 -06003407
Chia-I Wuf7458c52015-10-26 21:10:41 +08003408 vkDestroyBuffer(m_device->device(), ib, NULL);
Tobin Ehlisc4c23182015-09-17 12:24:13 -06003409}
3410
Tobin Ehlis4b34ddc2015-09-17 14:18:16 -06003411TEST_F(VkLayerTest, ExecuteCommandsPrimaryCB)
3412{
3413 // Attempt vkCmdExecuteCommands w/ a primary cmd buffer (should only be secondary)
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06003414
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07003415 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06003416 "vkCmdExecuteCommands() called w/ Primary Cmd Buffer ");
Tobin Ehlis4b34ddc2015-09-17 14:18:16 -06003417
3418 ASSERT_NO_FATAL_FAILURE(InitState());
3419 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlis4b34ddc2015-09-17 14:18:16 -06003420
3421 BeginCommandBuffer();
3422 //ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003423 VkCommandBuffer primCB = m_commandBuffer->GetBufferHandle();
3424 vkCmdExecuteCommands(m_commandBuffer->GetBufferHandle(), 1, &primCB);
Tobin Ehlis4b34ddc2015-09-17 14:18:16 -06003425
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06003426 if (!m_errorMonitor->DesiredMsgFound()) {
3427 FAIL() << "Did not receive Error 'vkCmdExecuteCommands() called w/ Primary Cmd Buffer '";
3428 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlis4b34ddc2015-09-17 14:18:16 -06003429 }
3430}
3431
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06003432TEST_F(VkLayerTest, DSTypeMismatch)
3433{
3434 // Create DS w/ layout of one type and attempt Update w/ mis-matched type
Tobin Ehlis3b780662015-05-28 12:11:26 -06003435 VkResult err;
3436
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07003437 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06003438 "Write descriptor update has descriptor type VK_DESCRIPTOR_TYPE_SAMPLER that does not match ");
3439
Tobin Ehlis3b780662015-05-28 12:11:26 -06003440 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlis3b780662015-05-28 12:11:26 -06003441 //VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu1b99bb22015-10-27 19:25:11 +08003442 VkDescriptorPoolSize ds_type_count = {};
Tony Barboureb254902015-07-15 12:50:33 -06003443 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wud50a7d72015-10-26 20:48:51 +08003444 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06003445
3446 VkDescriptorPoolCreateInfo ds_pool_ci = {};
3447 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
3448 ds_pool_ci.pNext = NULL;
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -06003449 ds_pool_ci.maxSets = 1;
Chia-I Wu1b99bb22015-10-27 19:25:11 +08003450 ds_pool_ci.poolSizeCount = 1;
3451 ds_pool_ci.pPoolSizes = &ds_type_count;
Tony Barboureb254902015-07-15 12:50:33 -06003452
Tobin Ehlis3b780662015-05-28 12:11:26 -06003453 VkDescriptorPool ds_pool;
Chia-I Wuf7458c52015-10-26 21:10:41 +08003454 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -06003455 ASSERT_VK_SUCCESS(err);
Tony Barboureb254902015-07-15 12:50:33 -06003456 VkDescriptorSetLayoutBinding dsl_binding = {};
Chia-I Wud46e6ae2015-10-31 00:31:16 +08003457 dsl_binding.binding = 0;
Tony Barboureb254902015-07-15 12:50:33 -06003458 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wu02124482015-11-06 06:42:02 +08003459 dsl_binding.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06003460 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
3461 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis3b780662015-05-28 12:11:26 -06003462
Tony Barboureb254902015-07-15 12:50:33 -06003463 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
3464 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
3465 ds_layout_ci.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08003466 ds_layout_ci.bindingCount = 1;
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07003467 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -06003468
Tobin Ehlis3b780662015-05-28 12:11:26 -06003469 VkDescriptorSetLayout ds_layout;
Chia-I Wuf7458c52015-10-26 21:10:41 +08003470 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -06003471 ASSERT_VK_SUCCESS(err);
3472
3473 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003474 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08003475 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07003476 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06003477 alloc_info.descriptorPool = ds_pool;
3478 alloc_info.pSetLayouts = &ds_layout;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003479 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -06003480 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -06003481
Tony Barboureb254902015-07-15 12:50:33 -06003482 VkSamplerCreateInfo sampler_ci = {};
3483 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
3484 sampler_ci.pNext = NULL;
Chia-I Wub99df442015-10-26 16:49:32 +08003485 sampler_ci.magFilter = VK_FILTER_NEAREST;
3486 sampler_ci.minFilter = VK_FILTER_NEAREST;
Jon Ashburnf19916e2016-01-11 13:12:43 -07003487 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
Chia-I Wu1efb7e52015-10-26 17:32:47 +08003488 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
3489 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
3490 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
Tony Barboureb254902015-07-15 12:50:33 -06003491 sampler_ci.mipLodBias = 1.0;
Jon Ashburnddc8db52015-12-14 14:59:20 -07003492 sampler_ci.anisotropyEnable = VK_FALSE;
Tony Barboureb254902015-07-15 12:50:33 -06003493 sampler_ci.maxAnisotropy = 1;
3494 sampler_ci.compareEnable = VK_FALSE;
3495 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
3496 sampler_ci.minLod = 1.0;
3497 sampler_ci.maxLod = 1.0;
3498 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
Mark Lobodzinski52ac6582015-09-01 15:42:56 -06003499 sampler_ci.unnormalizedCoordinates = VK_FALSE;
3500
Tobin Ehlis3b780662015-05-28 12:11:26 -06003501 VkSampler sampler;
Chia-I Wuf7458c52015-10-26 21:10:41 +08003502 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
Tobin Ehlis3b780662015-05-28 12:11:26 -06003503 ASSERT_VK_SUCCESS(err);
3504
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -06003505 VkDescriptorImageInfo info = {};
3506 info.sampler = sampler;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08003507
3508 VkWriteDescriptorSet descriptor_write;
3509 memset(&descriptor_write, 0, sizeof(descriptor_write));
3510 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003511 descriptor_write.dstSet = descriptorSet;
Chia-I Wud50a7d72015-10-26 20:48:51 +08003512 descriptor_write.descriptorCount = 1;
Tobin Ehlis3b780662015-05-28 12:11:26 -06003513 // This is a mismatched type for the layout which expects BUFFER
Chia-I Wu9d00ed72015-05-25 16:27:55 +08003514 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -06003515 descriptor_write.pImageInfo = &info;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08003516
3517 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
3518
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06003519 if (!m_errorMonitor->DesiredMsgFound()) {
3520 FAIL() << "Did not receive Error 'Write descriptor update has descriptor type VK_DESCRIPTOR_TYPE_SAMPLER that does not match...'";
3521 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlis3b780662015-05-28 12:11:26 -06003522 }
Mike Stroyand1c84a52015-08-18 14:40:24 -06003523
Chia-I Wuf7458c52015-10-26 21:10:41 +08003524 vkDestroySampler(m_device->device(), sampler, NULL);
3525 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
3526 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06003527}
3528
3529TEST_F(VkLayerTest, DSUpdateOutOfBounds)
3530{
3531 // For overlapping Update, have arrayIndex exceed that of layout
Tobin Ehlis3b780662015-05-28 12:11:26 -06003532 VkResult err;
3533
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07003534 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06003535 "Descriptor update type of VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET is out of bounds for matching binding");
3536
Tobin Ehlis3b780662015-05-28 12:11:26 -06003537 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlis3b780662015-05-28 12:11:26 -06003538 //VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu1b99bb22015-10-27 19:25:11 +08003539 VkDescriptorPoolSize ds_type_count = {};
Tony Barboureb254902015-07-15 12:50:33 -06003540 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wud50a7d72015-10-26 20:48:51 +08003541 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06003542
3543 VkDescriptorPoolCreateInfo ds_pool_ci = {};
3544 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
3545 ds_pool_ci.pNext = NULL;
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -06003546 ds_pool_ci.maxSets = 1;
Chia-I Wu1b99bb22015-10-27 19:25:11 +08003547 ds_pool_ci.poolSizeCount = 1;
3548 ds_pool_ci.pPoolSizes = &ds_type_count;
Tony Barboureb254902015-07-15 12:50:33 -06003549
Tobin Ehlis3b780662015-05-28 12:11:26 -06003550 VkDescriptorPool ds_pool;
Chia-I Wuf7458c52015-10-26 21:10:41 +08003551 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -06003552 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -06003553
Tony Barboureb254902015-07-15 12:50:33 -06003554 VkDescriptorSetLayoutBinding dsl_binding = {};
Chia-I Wud46e6ae2015-10-31 00:31:16 +08003555 dsl_binding.binding = 0;
Tony Barboureb254902015-07-15 12:50:33 -06003556 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wu02124482015-11-06 06:42:02 +08003557 dsl_binding.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06003558 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
3559 dsl_binding.pImmutableSamplers = NULL;
3560
3561 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
3562 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
3563 ds_layout_ci.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08003564 ds_layout_ci.bindingCount = 1;
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07003565 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -06003566
Tobin Ehlis3b780662015-05-28 12:11:26 -06003567 VkDescriptorSetLayout ds_layout;
Chia-I Wuf7458c52015-10-26 21:10:41 +08003568 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -06003569 ASSERT_VK_SUCCESS(err);
3570
3571 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003572 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08003573 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07003574 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06003575 alloc_info.descriptorPool = ds_pool;
3576 alloc_info.pSetLayouts = &ds_layout;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003577 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -06003578 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -06003579
Tony Barboureb254902015-07-15 12:50:33 -06003580 VkSamplerCreateInfo sampler_ci = {};
3581 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
3582 sampler_ci.pNext = NULL;
Chia-I Wub99df442015-10-26 16:49:32 +08003583 sampler_ci.magFilter = VK_FILTER_NEAREST;
3584 sampler_ci.minFilter = VK_FILTER_NEAREST;
Jon Ashburnf19916e2016-01-11 13:12:43 -07003585 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
Chia-I Wu1efb7e52015-10-26 17:32:47 +08003586 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
3587 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
3588 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
Tony Barboureb254902015-07-15 12:50:33 -06003589 sampler_ci.mipLodBias = 1.0;
Jon Ashburnddc8db52015-12-14 14:59:20 -07003590 sampler_ci.anisotropyEnable = VK_FALSE;
Tony Barboureb254902015-07-15 12:50:33 -06003591 sampler_ci.maxAnisotropy = 1;
3592 sampler_ci.compareEnable = VK_FALSE;
3593 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
3594 sampler_ci.minLod = 1.0;
3595 sampler_ci.maxLod = 1.0;
3596 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
Mark Lobodzinski52ac6582015-09-01 15:42:56 -06003597 sampler_ci.unnormalizedCoordinates = VK_FALSE;
Tony Barboureb254902015-07-15 12:50:33 -06003598
Tobin Ehlis3b780662015-05-28 12:11:26 -06003599 VkSampler sampler;
Chia-I Wuf7458c52015-10-26 21:10:41 +08003600 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
Tobin Ehlis3b780662015-05-28 12:11:26 -06003601 ASSERT_VK_SUCCESS(err);
Chia-I Wu9d00ed72015-05-25 16:27:55 +08003602
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -06003603 VkDescriptorImageInfo info = {};
3604 info.sampler = sampler;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08003605
3606 VkWriteDescriptorSet descriptor_write;
3607 memset(&descriptor_write, 0, sizeof(descriptor_write));
3608 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003609 descriptor_write.dstSet = descriptorSet;
3610 descriptor_write.dstArrayElement = 1; /* This index out of bounds for the update */
Chia-I Wud50a7d72015-10-26 20:48:51 +08003611 descriptor_write.descriptorCount = 1;
Tobin Ehlis3b780662015-05-28 12:11:26 -06003612 // This is the wrong type, but out of bounds will be flagged first
Chia-I Wu9d00ed72015-05-25 16:27:55 +08003613 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -06003614 descriptor_write.pImageInfo = &info;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08003615
3616 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
3617
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06003618 if (!m_errorMonitor->DesiredMsgFound()) {
3619 FAIL() << "Did not receive Error 'Descriptor update type of VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET is out of bounds for matching binding...'";
3620 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlis3b780662015-05-28 12:11:26 -06003621 }
Mike Stroyand1c84a52015-08-18 14:40:24 -06003622
Chia-I Wuf7458c52015-10-26 21:10:41 +08003623 vkDestroySampler(m_device->device(), sampler, NULL);
3624 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
3625 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06003626}
3627
3628TEST_F(VkLayerTest, InvalidDSUpdateIndex)
3629{
Tobin Ehlis3b780662015-05-28 12:11:26 -06003630 // Create layout w/ count of 1 and attempt update to that layout w/ binding index 2
Tobin Ehlis3b780662015-05-28 12:11:26 -06003631 VkResult err;
3632
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07003633 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06003634 " does not have binding to match update binding ");
3635
Tobin Ehlis3b780662015-05-28 12:11:26 -06003636 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlis3b780662015-05-28 12:11:26 -06003637 //VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu1b99bb22015-10-27 19:25:11 +08003638 VkDescriptorPoolSize ds_type_count = {};
Tony Barboureb254902015-07-15 12:50:33 -06003639 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wud50a7d72015-10-26 20:48:51 +08003640 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06003641
3642 VkDescriptorPoolCreateInfo ds_pool_ci = {};
3643 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
3644 ds_pool_ci.pNext = NULL;
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -06003645 ds_pool_ci.maxSets = 1;
Chia-I Wu1b99bb22015-10-27 19:25:11 +08003646 ds_pool_ci.poolSizeCount = 1;
3647 ds_pool_ci.pPoolSizes = &ds_type_count;
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -06003648
Tobin Ehlis3b780662015-05-28 12:11:26 -06003649 VkDescriptorPool ds_pool;
Chia-I Wuf7458c52015-10-26 21:10:41 +08003650 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -06003651 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -06003652
Tony Barboureb254902015-07-15 12:50:33 -06003653 VkDescriptorSetLayoutBinding dsl_binding = {};
Chia-I Wud46e6ae2015-10-31 00:31:16 +08003654 dsl_binding.binding = 0;
Tony Barboureb254902015-07-15 12:50:33 -06003655 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wu02124482015-11-06 06:42:02 +08003656 dsl_binding.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06003657 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
3658 dsl_binding.pImmutableSamplers = NULL;
3659
3660 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
3661 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
3662 ds_layout_ci.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08003663 ds_layout_ci.bindingCount = 1;
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07003664 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlis3b780662015-05-28 12:11:26 -06003665 VkDescriptorSetLayout ds_layout;
Chia-I Wuf7458c52015-10-26 21:10:41 +08003666 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -06003667 ASSERT_VK_SUCCESS(err);
3668
3669 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003670 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08003671 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07003672 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06003673 alloc_info.descriptorPool = ds_pool;
3674 alloc_info.pSetLayouts = &ds_layout;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003675 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -06003676 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -06003677
Tony Barboureb254902015-07-15 12:50:33 -06003678 VkSamplerCreateInfo sampler_ci = {};
3679 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
3680 sampler_ci.pNext = NULL;
Chia-I Wub99df442015-10-26 16:49:32 +08003681 sampler_ci.magFilter = VK_FILTER_NEAREST;
3682 sampler_ci.minFilter = VK_FILTER_NEAREST;
Jon Ashburnf19916e2016-01-11 13:12:43 -07003683 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
Chia-I Wu1efb7e52015-10-26 17:32:47 +08003684 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
3685 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
3686 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
Tony Barboureb254902015-07-15 12:50:33 -06003687 sampler_ci.mipLodBias = 1.0;
Jon Ashburnddc8db52015-12-14 14:59:20 -07003688 sampler_ci.anisotropyEnable = VK_FALSE;
Tony Barboureb254902015-07-15 12:50:33 -06003689 sampler_ci.maxAnisotropy = 1;
3690 sampler_ci.compareEnable = VK_FALSE;
3691 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
3692 sampler_ci.minLod = 1.0;
3693 sampler_ci.maxLod = 1.0;
3694 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
Mark Lobodzinski52ac6582015-09-01 15:42:56 -06003695 sampler_ci.unnormalizedCoordinates = VK_FALSE;
Tony Barboureb254902015-07-15 12:50:33 -06003696
Tobin Ehlis3b780662015-05-28 12:11:26 -06003697 VkSampler sampler;
Chia-I Wuf7458c52015-10-26 21:10:41 +08003698 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
Tobin Ehlis3b780662015-05-28 12:11:26 -06003699 ASSERT_VK_SUCCESS(err);
Chia-I Wu9d00ed72015-05-25 16:27:55 +08003700
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -06003701 VkDescriptorImageInfo info = {};
3702 info.sampler = sampler;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08003703
3704 VkWriteDescriptorSet descriptor_write;
3705 memset(&descriptor_write, 0, sizeof(descriptor_write));
3706 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003707 descriptor_write.dstSet = descriptorSet;
3708 descriptor_write.dstBinding = 2;
Chia-I Wud50a7d72015-10-26 20:48:51 +08003709 descriptor_write.descriptorCount = 1;
Tobin Ehlis3b780662015-05-28 12:11:26 -06003710 // This is the wrong type, but out of bounds will be flagged first
Chia-I Wu9d00ed72015-05-25 16:27:55 +08003711 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -06003712 descriptor_write.pImageInfo = &info;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08003713
3714 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
3715
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06003716 if (!m_errorMonitor->DesiredMsgFound()) {
3717 FAIL() << "Did not receive Error 'Descriptor Set <blah> does not have binding to match update binding '";
3718 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlis3b780662015-05-28 12:11:26 -06003719 }
Mike Stroyand1c84a52015-08-18 14:40:24 -06003720
Chia-I Wuf7458c52015-10-26 21:10:41 +08003721 vkDestroySampler(m_device->device(), sampler, NULL);
3722 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
3723 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06003724}
3725
3726TEST_F(VkLayerTest, InvalidDSUpdateStruct)
3727{
3728 // Call UpdateDS w/ struct type other than valid VK_STRUCTUR_TYPE_UPDATE_* types
Tobin Ehlis3b780662015-05-28 12:11:26 -06003729 VkResult err;
3730
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07003731 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06003732 "Unexpected UPDATE struct of type ");
3733
Tobin Ehlis3b780662015-05-28 12:11:26 -06003734 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski209b5292015-09-17 09:44:05 -06003735
Chia-I Wu1b99bb22015-10-27 19:25:11 +08003736 VkDescriptorPoolSize ds_type_count = {};
Tony Barboureb254902015-07-15 12:50:33 -06003737 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wud50a7d72015-10-26 20:48:51 +08003738 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06003739
3740 VkDescriptorPoolCreateInfo ds_pool_ci = {};
3741 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
3742 ds_pool_ci.pNext = NULL;
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -06003743 ds_pool_ci.maxSets = 1;
Chia-I Wu1b99bb22015-10-27 19:25:11 +08003744 ds_pool_ci.poolSizeCount = 1;
3745 ds_pool_ci.pPoolSizes = &ds_type_count;
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -06003746
Tobin Ehlis3b780662015-05-28 12:11:26 -06003747 VkDescriptorPool ds_pool;
Chia-I Wuf7458c52015-10-26 21:10:41 +08003748 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -06003749 ASSERT_VK_SUCCESS(err);
Tony Barboureb254902015-07-15 12:50:33 -06003750 VkDescriptorSetLayoutBinding dsl_binding = {};
Chia-I Wud46e6ae2015-10-31 00:31:16 +08003751 dsl_binding.binding = 0;
Tony Barboureb254902015-07-15 12:50:33 -06003752 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wu02124482015-11-06 06:42:02 +08003753 dsl_binding.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06003754 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
3755 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis3b780662015-05-28 12:11:26 -06003756
Tony Barboureb254902015-07-15 12:50:33 -06003757 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
3758 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
3759 ds_layout_ci.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08003760 ds_layout_ci.bindingCount = 1;
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07003761 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -06003762
Tobin Ehlis3b780662015-05-28 12:11:26 -06003763 VkDescriptorSetLayout ds_layout;
Chia-I Wuf7458c52015-10-26 21:10:41 +08003764 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -06003765 ASSERT_VK_SUCCESS(err);
3766
3767 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003768 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08003769 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07003770 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06003771 alloc_info.descriptorPool = ds_pool;
3772 alloc_info.pSetLayouts = &ds_layout;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003773 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -06003774 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -06003775
Tony Barboureb254902015-07-15 12:50:33 -06003776 VkSamplerCreateInfo sampler_ci = {};
3777 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
3778 sampler_ci.pNext = NULL;
Chia-I Wub99df442015-10-26 16:49:32 +08003779 sampler_ci.magFilter = VK_FILTER_NEAREST;
3780 sampler_ci.minFilter = VK_FILTER_NEAREST;
Jon Ashburnf19916e2016-01-11 13:12:43 -07003781 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
Chia-I Wu1efb7e52015-10-26 17:32:47 +08003782 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
3783 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
3784 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
Tony Barboureb254902015-07-15 12:50:33 -06003785 sampler_ci.mipLodBias = 1.0;
Jon Ashburnddc8db52015-12-14 14:59:20 -07003786 sampler_ci.anisotropyEnable = VK_FALSE;
Tony Barboureb254902015-07-15 12:50:33 -06003787 sampler_ci.maxAnisotropy = 1;
3788 sampler_ci.compareEnable = VK_FALSE;
3789 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
3790 sampler_ci.minLod = 1.0;
3791 sampler_ci.maxLod = 1.0;
3792 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
Mark Lobodzinski52ac6582015-09-01 15:42:56 -06003793 sampler_ci.unnormalizedCoordinates = VK_FALSE;
Tobin Ehlis3b780662015-05-28 12:11:26 -06003794 VkSampler sampler;
Chia-I Wuf7458c52015-10-26 21:10:41 +08003795 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
Tobin Ehlis3b780662015-05-28 12:11:26 -06003796 ASSERT_VK_SUCCESS(err);
Chia-I Wu9d00ed72015-05-25 16:27:55 +08003797
3798
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -06003799 VkDescriptorImageInfo info = {};
3800 info.sampler = sampler;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08003801
3802 VkWriteDescriptorSet descriptor_write;
3803 memset(&descriptor_write, 0, sizeof(descriptor_write));
3804 descriptor_write.sType = (VkStructureType)0x99999999; /* Intentionally broken struct type */
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003805 descriptor_write.dstSet = descriptorSet;
Chia-I Wud50a7d72015-10-26 20:48:51 +08003806 descriptor_write.descriptorCount = 1;
Tobin Ehlis3b780662015-05-28 12:11:26 -06003807 // This is the wrong type, but out of bounds will be flagged first
Chia-I Wu9d00ed72015-05-25 16:27:55 +08003808 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -06003809 descriptor_write.pImageInfo = &info;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08003810
3811 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
3812
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06003813 if (!m_errorMonitor->DesiredMsgFound()) {
3814 FAIL() << "Did not receive Error 'Unexpected UPDATE struct of type '";
3815 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlis3b780662015-05-28 12:11:26 -06003816 }
Mike Stroyand1c84a52015-08-18 14:40:24 -06003817
Chia-I Wuf7458c52015-10-26 21:10:41 +08003818 vkDestroySampler(m_device->device(), sampler, NULL);
3819 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
3820 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06003821}
3822
Tobin Ehlisa1c28562015-10-23 16:00:08 -06003823TEST_F(VkLayerTest, SampleDescriptorUpdateError)
3824{
3825 // Create a single Sampler descriptor and send it an invalid Sampler
Tobin Ehlisa1c28562015-10-23 16:00:08 -06003826 VkResult err;
3827
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07003828 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06003829 "Attempt to update descriptor with invalid sampler 0xbaadbeef");
3830
Tobin Ehlisa1c28562015-10-23 16:00:08 -06003831 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisa1c28562015-10-23 16:00:08 -06003832 // TODO : Farm Descriptor setup code to helper function(s) to reduce copied code
Chia-I Wu1b99bb22015-10-27 19:25:11 +08003833 VkDescriptorPoolSize ds_type_count = {};
Tobin Ehlisa1c28562015-10-23 16:00:08 -06003834 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLER;
Chia-I Wud50a7d72015-10-26 20:48:51 +08003835 ds_type_count.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06003836
3837 VkDescriptorPoolCreateInfo ds_pool_ci = {};
3838 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
3839 ds_pool_ci.pNext = NULL;
3840 ds_pool_ci.maxSets = 1;
Chia-I Wu1b99bb22015-10-27 19:25:11 +08003841 ds_pool_ci.poolSizeCount = 1;
3842 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06003843
3844 VkDescriptorPool ds_pool;
Chia-I Wuf7458c52015-10-26 21:10:41 +08003845 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06003846 ASSERT_VK_SUCCESS(err);
3847
3848 VkDescriptorSetLayoutBinding dsl_binding = {};
Chia-I Wud46e6ae2015-10-31 00:31:16 +08003849 dsl_binding.binding = 0;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06003850 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Chia-I Wu02124482015-11-06 06:42:02 +08003851 dsl_binding.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06003852 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
3853 dsl_binding.pImmutableSamplers = NULL;
3854
3855 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
3856 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
3857 ds_layout_ci.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08003858 ds_layout_ci.bindingCount = 1;
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07003859 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06003860 VkDescriptorSetLayout ds_layout;
Chia-I Wuf7458c52015-10-26 21:10:41 +08003861 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06003862 ASSERT_VK_SUCCESS(err);
3863
3864 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003865 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08003866 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07003867 alloc_info.descriptorSetCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06003868 alloc_info.descriptorPool = ds_pool;
3869 alloc_info.pSetLayouts = &ds_layout;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003870 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06003871 ASSERT_VK_SUCCESS(err);
3872
Mark Youngad779052016-01-06 14:26:04 -07003873 VkSampler sampler = (VkSampler)((size_t)0xbaadbeef); // Sampler with invalid handle
Tobin Ehlisa1c28562015-10-23 16:00:08 -06003874
3875 VkDescriptorImageInfo descriptor_info;
3876 memset(&descriptor_info, 0, sizeof(VkDescriptorImageInfo));
3877 descriptor_info.sampler = sampler;
3878
3879 VkWriteDescriptorSet descriptor_write;
3880 memset(&descriptor_write, 0, sizeof(descriptor_write));
3881 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003882 descriptor_write.dstSet = descriptorSet;
3883 descriptor_write.dstBinding = 0;
Chia-I Wud50a7d72015-10-26 20:48:51 +08003884 descriptor_write.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06003885 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
3886 descriptor_write.pImageInfo = &descriptor_info;
3887
3888 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
3889
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06003890 if (!m_errorMonitor->DesiredMsgFound()) {
3891 FAIL() << "Did not receive Error 'Attempt to update descriptor with invalid sampler...'";
3892 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlisa1c28562015-10-23 16:00:08 -06003893 }
3894
Chia-I Wuf7458c52015-10-26 21:10:41 +08003895 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
3896 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06003897}
3898
3899TEST_F(VkLayerTest, ImageViewDescriptorUpdateError)
3900{
3901 // Create a single combined Image/Sampler descriptor and send it an invalid imageView
Tobin Ehlisa1c28562015-10-23 16:00:08 -06003902 VkResult err;
3903
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07003904 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06003905 "Attempt to update descriptor with invalid imageView 0xbaadbeef");
3906
Tobin Ehlisa1c28562015-10-23 16:00:08 -06003907 ASSERT_NO_FATAL_FAILURE(InitState());
Chia-I Wu1b99bb22015-10-27 19:25:11 +08003908 VkDescriptorPoolSize ds_type_count = {};
Tobin Ehlisa1c28562015-10-23 16:00:08 -06003909 ds_type_count.type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
Chia-I Wud50a7d72015-10-26 20:48:51 +08003910 ds_type_count.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06003911
3912 VkDescriptorPoolCreateInfo ds_pool_ci = {};
3913 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
3914 ds_pool_ci.pNext = NULL;
3915 ds_pool_ci.maxSets = 1;
Chia-I Wu1b99bb22015-10-27 19:25:11 +08003916 ds_pool_ci.poolSizeCount = 1;
3917 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06003918
3919 VkDescriptorPool ds_pool;
Chia-I Wuf7458c52015-10-26 21:10:41 +08003920 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06003921 ASSERT_VK_SUCCESS(err);
3922
3923 VkDescriptorSetLayoutBinding dsl_binding = {};
Chia-I Wud46e6ae2015-10-31 00:31:16 +08003924 dsl_binding.binding = 0;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06003925 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
Chia-I Wu02124482015-11-06 06:42:02 +08003926 dsl_binding.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06003927 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
3928 dsl_binding.pImmutableSamplers = NULL;
3929
3930 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
3931 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
3932 ds_layout_ci.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08003933 ds_layout_ci.bindingCount = 1;
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07003934 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06003935 VkDescriptorSetLayout ds_layout;
Chia-I Wuf7458c52015-10-26 21:10:41 +08003936 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06003937 ASSERT_VK_SUCCESS(err);
3938
3939 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003940 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08003941 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07003942 alloc_info.descriptorSetCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06003943 alloc_info.descriptorPool = ds_pool;
3944 alloc_info.pSetLayouts = &ds_layout;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003945 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06003946 ASSERT_VK_SUCCESS(err);
3947
3948 VkSamplerCreateInfo sampler_ci = {};
3949 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
3950 sampler_ci.pNext = NULL;
Chia-I Wub99df442015-10-26 16:49:32 +08003951 sampler_ci.magFilter = VK_FILTER_NEAREST;
3952 sampler_ci.minFilter = VK_FILTER_NEAREST;
Jon Ashburnf19916e2016-01-11 13:12:43 -07003953 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
Chia-I Wu1efb7e52015-10-26 17:32:47 +08003954 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
3955 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
3956 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06003957 sampler_ci.mipLodBias = 1.0;
Jon Ashburnddc8db52015-12-14 14:59:20 -07003958 sampler_ci.anisotropyEnable = VK_FALSE;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06003959 sampler_ci.maxAnisotropy = 1;
3960 sampler_ci.compareEnable = VK_FALSE;
3961 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
3962 sampler_ci.minLod = 1.0;
3963 sampler_ci.maxLod = 1.0;
3964 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
3965 sampler_ci.unnormalizedCoordinates = VK_FALSE;
3966
3967 VkSampler sampler;
Chia-I Wuf7458c52015-10-26 21:10:41 +08003968 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06003969 ASSERT_VK_SUCCESS(err);
3970
Mark Youngad779052016-01-06 14:26:04 -07003971 VkImageView view = (VkImageView)((size_t)0xbaadbeef); // invalid imageView object
Tobin Ehlisa1c28562015-10-23 16:00:08 -06003972
3973 VkDescriptorImageInfo descriptor_info;
3974 memset(&descriptor_info, 0, sizeof(VkDescriptorImageInfo));
3975 descriptor_info.sampler = sampler;
3976 descriptor_info.imageView = view;
3977
3978 VkWriteDescriptorSet descriptor_write;
3979 memset(&descriptor_write, 0, sizeof(descriptor_write));
3980 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003981 descriptor_write.dstSet = descriptorSet;
3982 descriptor_write.dstBinding = 0;
Chia-I Wud50a7d72015-10-26 20:48:51 +08003983 descriptor_write.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06003984 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
3985 descriptor_write.pImageInfo = &descriptor_info;
3986
3987 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
3988
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06003989 if (!m_errorMonitor->DesiredMsgFound()) {
3990 FAIL() << "Did not receive Error 'Attempt to update descriptor with invalid imageView...'";
3991 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlisa1c28562015-10-23 16:00:08 -06003992 }
3993
Chia-I Wuf7458c52015-10-26 21:10:41 +08003994 vkDestroySampler(m_device->device(), sampler, NULL);
3995 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
3996 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06003997}
3998
Tobin Ehlis04356f92015-10-27 16:35:27 -06003999TEST_F(VkLayerTest, CopyDescriptorUpdateErrors)
4000{
4001 // 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 -06004002 VkResult err;
4003
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07004004 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06004005 "Copy descriptor update index 0, update count #1, has src update descriptor type VK_DESCRIPTOR_TYPE_SAMPLER ");
4006
Tobin Ehlis04356f92015-10-27 16:35:27 -06004007 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlis04356f92015-10-27 16:35:27 -06004008 //VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu1b99bb22015-10-27 19:25:11 +08004009 VkDescriptorPoolSize ds_type_count[2] = {};
Tobin Ehlis04356f92015-10-27 16:35:27 -06004010 ds_type_count[0].type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wud50a7d72015-10-26 20:48:51 +08004011 ds_type_count[0].descriptorCount = 1;
Tobin Ehlis04356f92015-10-27 16:35:27 -06004012 ds_type_count[1].type = VK_DESCRIPTOR_TYPE_SAMPLER;
Chia-I Wud50a7d72015-10-26 20:48:51 +08004013 ds_type_count[1].descriptorCount = 1;
Tobin Ehlis04356f92015-10-27 16:35:27 -06004014
4015 VkDescriptorPoolCreateInfo ds_pool_ci = {};
4016 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
4017 ds_pool_ci.pNext = NULL;
4018 ds_pool_ci.maxSets = 1;
Chia-I Wu1b99bb22015-10-27 19:25:11 +08004019 ds_pool_ci.poolSizeCount = 2;
4020 ds_pool_ci.pPoolSizes = ds_type_count;
Tobin Ehlis04356f92015-10-27 16:35:27 -06004021
4022 VkDescriptorPool ds_pool;
Chia-I Wuf7458c52015-10-26 21:10:41 +08004023 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis04356f92015-10-27 16:35:27 -06004024 ASSERT_VK_SUCCESS(err);
4025 VkDescriptorSetLayoutBinding dsl_binding[2] = {};
Chia-I Wud46e6ae2015-10-31 00:31:16 +08004026 dsl_binding[0].binding = 0;
Tobin Ehlis04356f92015-10-27 16:35:27 -06004027 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wu02124482015-11-06 06:42:02 +08004028 dsl_binding[0].descriptorCount = 1;
Tobin Ehlis04356f92015-10-27 16:35:27 -06004029 dsl_binding[0].stageFlags = VK_SHADER_STAGE_ALL;
4030 dsl_binding[0].pImmutableSamplers = NULL;
Chia-I Wud46e6ae2015-10-31 00:31:16 +08004031 dsl_binding[1].binding = 1;
Tobin Ehlis04356f92015-10-27 16:35:27 -06004032 dsl_binding[1].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Chia-I Wu02124482015-11-06 06:42:02 +08004033 dsl_binding[1].descriptorCount = 1;
Tobin Ehlis04356f92015-10-27 16:35:27 -06004034 dsl_binding[1].stageFlags = VK_SHADER_STAGE_ALL;
4035 dsl_binding[1].pImmutableSamplers = NULL;
4036
4037 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
4038 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
4039 ds_layout_ci.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08004040 ds_layout_ci.bindingCount = 2;
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07004041 ds_layout_ci.pBindings = dsl_binding;
Tobin Ehlis04356f92015-10-27 16:35:27 -06004042
4043 VkDescriptorSetLayout ds_layout;
Chia-I Wuf7458c52015-10-26 21:10:41 +08004044 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis04356f92015-10-27 16:35:27 -06004045 ASSERT_VK_SUCCESS(err);
4046
4047 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004048 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08004049 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07004050 alloc_info.descriptorSetCount = 1;
Tobin Ehlis04356f92015-10-27 16:35:27 -06004051 alloc_info.descriptorPool = ds_pool;
4052 alloc_info.pSetLayouts = &ds_layout;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004053 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis04356f92015-10-27 16:35:27 -06004054 ASSERT_VK_SUCCESS(err);
4055
4056 VkSamplerCreateInfo sampler_ci = {};
4057 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
4058 sampler_ci.pNext = NULL;
Chia-I Wub99df442015-10-26 16:49:32 +08004059 sampler_ci.magFilter = VK_FILTER_NEAREST;
4060 sampler_ci.minFilter = VK_FILTER_NEAREST;
Jon Ashburnf19916e2016-01-11 13:12:43 -07004061 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
Chia-I Wu1efb7e52015-10-26 17:32:47 +08004062 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
4063 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
4064 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
Tobin Ehlis04356f92015-10-27 16:35:27 -06004065 sampler_ci.mipLodBias = 1.0;
Jon Ashburnddc8db52015-12-14 14:59:20 -07004066 sampler_ci.anisotropyEnable = VK_FALSE;
Tobin Ehlis04356f92015-10-27 16:35:27 -06004067 sampler_ci.maxAnisotropy = 1;
4068 sampler_ci.compareEnable = VK_FALSE;
4069 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
4070 sampler_ci.minLod = 1.0;
4071 sampler_ci.maxLod = 1.0;
4072 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
4073 sampler_ci.unnormalizedCoordinates = VK_FALSE;
4074
4075 VkSampler sampler;
Chia-I Wuf7458c52015-10-26 21:10:41 +08004076 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
Tobin Ehlis04356f92015-10-27 16:35:27 -06004077 ASSERT_VK_SUCCESS(err);
4078
4079 VkDescriptorImageInfo info = {};
4080 info.sampler = sampler;
4081
4082 VkWriteDescriptorSet descriptor_write;
4083 memset(&descriptor_write, 0, sizeof(VkWriteDescriptorSet));
4084 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004085 descriptor_write.dstSet = descriptorSet;
4086 descriptor_write.dstBinding = 1; // SAMPLER binding from layout above
Chia-I Wud50a7d72015-10-26 20:48:51 +08004087 descriptor_write.descriptorCount = 1;
Tobin Ehlis04356f92015-10-27 16:35:27 -06004088 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
4089 descriptor_write.pImageInfo = &info;
4090 // This write update should succeed
4091 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
4092 // Now perform a copy update that fails due to type mismatch
4093 VkCopyDescriptorSet copy_ds_update;
4094 memset(&copy_ds_update, 0, sizeof(VkCopyDescriptorSet));
4095 copy_ds_update.sType = VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET;
4096 copy_ds_update.srcSet = descriptorSet;
4097 copy_ds_update.srcBinding = 1; // copy from SAMPLER binding
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004098 copy_ds_update.dstSet = descriptorSet;
4099 copy_ds_update.dstBinding = 0; // ERROR : copy to UNIFORM binding
Chia-I Wud50a7d72015-10-26 20:48:51 +08004100 copy_ds_update.descriptorCount = 1; // copy 1 descriptor
Tobin Ehlis04356f92015-10-27 16:35:27 -06004101 vkUpdateDescriptorSets(m_device->device(), 0, NULL, 1, &copy_ds_update);
4102
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06004103 if (!m_errorMonitor->DesiredMsgFound()) {
4104 FAIL() << "Did not receive Error 'Copy descriptor update index 0, update count #1, has src update descriptor type_DESCRIPTOR_TYPE_SAMPLER'";
4105 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlis04356f92015-10-27 16:35:27 -06004106 }
4107 // Now perform a copy update that fails due to binding out of bounds
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07004108 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06004109 "Copy descriptor update 0 has srcBinding 3 which is out of bounds ");
Tobin Ehlis04356f92015-10-27 16:35:27 -06004110 memset(&copy_ds_update, 0, sizeof(VkCopyDescriptorSet));
4111 copy_ds_update.sType = VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET;
4112 copy_ds_update.srcSet = descriptorSet;
4113 copy_ds_update.srcBinding = 3; // ERROR : Invalid binding for matching layout
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004114 copy_ds_update.dstSet = descriptorSet;
4115 copy_ds_update.dstBinding = 0;
Chia-I Wud50a7d72015-10-26 20:48:51 +08004116 copy_ds_update.descriptorCount = 1; // copy 1 descriptor
Tobin Ehlis04356f92015-10-27 16:35:27 -06004117 vkUpdateDescriptorSets(m_device->device(), 0, NULL, 1, &copy_ds_update);
4118
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06004119 if (!m_errorMonitor->DesiredMsgFound()) {
4120 FAIL() << "Did not receive Error 'Copy descriptor update 0 has srcBinding 3 which is out of bounds...'";
4121 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlis04356f92015-10-27 16:35:27 -06004122 }
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06004123
Tobin Ehlis04356f92015-10-27 16:35:27 -06004124 // Now perform a copy update that fails due to binding out of bounds
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07004125 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06004126 "Copy descriptor src update is out of bounds for matching binding 1 ");
4127
Tobin Ehlis04356f92015-10-27 16:35:27 -06004128 memset(&copy_ds_update, 0, sizeof(VkCopyDescriptorSet));
4129 copy_ds_update.sType = VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET;
4130 copy_ds_update.srcSet = descriptorSet;
4131 copy_ds_update.srcBinding = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004132 copy_ds_update.dstSet = descriptorSet;
4133 copy_ds_update.dstBinding = 0;
Chia-I Wud50a7d72015-10-26 20:48:51 +08004134 copy_ds_update.descriptorCount = 5; // ERROR copy 5 descriptors (out of bounds for layout)
Tobin Ehlis04356f92015-10-27 16:35:27 -06004135 vkUpdateDescriptorSets(m_device->device(), 0, NULL, 1, &copy_ds_update);
4136
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06004137 if (!m_errorMonitor->DesiredMsgFound()) {
4138 FAIL() << "Did not receive Error 'Copy descriptor src update is out of bounds for matching binding 1...'";
4139 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlis04356f92015-10-27 16:35:27 -06004140 }
4141
Chia-I Wuf7458c52015-10-26 21:10:41 +08004142 vkDestroySampler(m_device->device(), sampler, NULL);
4143 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
4144 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis04356f92015-10-27 16:35:27 -06004145}
4146
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06004147TEST_F(VkLayerTest, NumSamplesMismatch)
4148{
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004149 // Create CommandBuffer where MSAA samples doesn't match RenderPass sampleCount
Tobin Ehlis3b780662015-05-28 12:11:26 -06004150 VkResult err;
4151
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07004152 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06004153 "Num samples mismatch! ");
4154
Tobin Ehlis3b780662015-05-28 12:11:26 -06004155 ASSERT_NO_FATAL_FAILURE(InitState());
4156 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chia-I Wu1b99bb22015-10-27 19:25:11 +08004157 VkDescriptorPoolSize ds_type_count = {};
Tony Barboureb254902015-07-15 12:50:33 -06004158 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wud50a7d72015-10-26 20:48:51 +08004159 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06004160
4161 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -06004162 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
4163 ds_pool_ci.pNext = NULL;
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -06004164 ds_pool_ci.maxSets = 1;
Chia-I Wu1b99bb22015-10-27 19:25:11 +08004165 ds_pool_ci.poolSizeCount = 1;
4166 ds_pool_ci.pPoolSizes = &ds_type_count;
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -06004167
Tobin Ehlis3b780662015-05-28 12:11:26 -06004168 VkDescriptorPool ds_pool;
Chia-I Wuf7458c52015-10-26 21:10:41 +08004169 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -06004170 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -06004171
Tony Barboureb254902015-07-15 12:50:33 -06004172 VkDescriptorSetLayoutBinding dsl_binding = {};
Chia-I Wud46e6ae2015-10-31 00:31:16 +08004173 dsl_binding.binding = 0;
Tony Barboureb254902015-07-15 12:50:33 -06004174 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wu02124482015-11-06 06:42:02 +08004175 dsl_binding.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06004176 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
4177 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis3b780662015-05-28 12:11:26 -06004178
Tony Barboureb254902015-07-15 12:50:33 -06004179 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
4180 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
4181 ds_layout_ci.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08004182 ds_layout_ci.bindingCount = 1;
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07004183 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -06004184
Tobin Ehlis3b780662015-05-28 12:11:26 -06004185 VkDescriptorSetLayout ds_layout;
Chia-I Wuf7458c52015-10-26 21:10:41 +08004186 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -06004187 ASSERT_VK_SUCCESS(err);
4188
4189 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004190 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08004191 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07004192 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06004193 alloc_info.descriptorPool = ds_pool;
4194 alloc_info.pSetLayouts = &ds_layout;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004195 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -06004196 ASSERT_VK_SUCCESS(err);
4197
Tony Barboureb254902015-07-15 12:50:33 -06004198 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
4199 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
4200 pipe_ms_state_ci.pNext = NULL;
Chia-I Wu5c17c962015-10-31 00:31:16 +08004201 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_4_BIT;
Tony Barboureb254902015-07-15 12:50:33 -06004202 pipe_ms_state_ci.sampleShadingEnable = 0;
4203 pipe_ms_state_ci.minSampleShading = 1.0;
Cody Northrop02e61ed2015-08-04 14:34:54 -06004204 pipe_ms_state_ci.pSampleMask = NULL;
Tobin Ehlis3b780662015-05-28 12:11:26 -06004205
Tony Barboureb254902015-07-15 12:50:33 -06004206 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
4207 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
4208 pipeline_layout_ci.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08004209 pipeline_layout_ci.setLayoutCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06004210 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis3b780662015-05-28 12:11:26 -06004211
4212 VkPipelineLayout pipeline_layout;
Chia-I Wuf7458c52015-10-26 21:10:41 +08004213 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -06004214 ASSERT_VK_SUCCESS(err);
4215
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06004216 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
4217 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 -06004218 // but add it to be able to run on more devices
Tony Barbour62e1a5b2015-08-06 10:16:07 -06004219 VkPipelineObj pipe(m_device);
4220 pipe.AddShader(&vs);
Tony Barbour1c94d372015-08-06 11:21:08 -06004221 pipe.AddShader(&fs);
Tony Barbour62e1a5b2015-08-06 10:16:07 -06004222 pipe.SetMSAA(&pipe_ms_state_ci);
4223 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tobin Ehlis3b780662015-05-28 12:11:26 -06004224
Tony Barbourfe3351b2015-07-28 10:17:20 -06004225 BeginCommandBuffer();
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004226 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlis3b780662015-05-28 12:11:26 -06004227
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06004228 if (!m_errorMonitor->DesiredMsgFound()) {
4229 FAIL() << "Did not recieve Error 'Num samples mismatch!...'";
4230 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlis3b780662015-05-28 12:11:26 -06004231 }
Mike Stroyand1c84a52015-08-18 14:40:24 -06004232
Chia-I Wuf7458c52015-10-26 21:10:41 +08004233 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
4234 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
4235 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06004236}
Tobin Ehlis53eddda2015-07-01 16:46:13 -06004237
Tobin Ehlis53eddda2015-07-01 16:46:13 -06004238TEST_F(VkLayerTest, ClearCmdNoDraw)
4239{
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004240 // Create CommandBuffer where we add ClearCmd for FB Color attachment prior to issuing a Draw
Tobin Ehlis53eddda2015-07-01 16:46:13 -06004241 VkResult err;
4242
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07004243 // TODO: verify that this matches layer
4244 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARN_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06004245 "vkCmdClearAttachments() issued on CB object ");
4246
Tobin Ehlis53eddda2015-07-01 16:46:13 -06004247 ASSERT_NO_FATAL_FAILURE(InitState());
4248 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barboureb254902015-07-15 12:50:33 -06004249
Chia-I Wu1b99bb22015-10-27 19:25:11 +08004250 VkDescriptorPoolSize ds_type_count = {};
Tony Barboureb254902015-07-15 12:50:33 -06004251 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wud50a7d72015-10-26 20:48:51 +08004252 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06004253
4254 VkDescriptorPoolCreateInfo ds_pool_ci = {};
4255 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
4256 ds_pool_ci.pNext = NULL;
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -06004257 ds_pool_ci.maxSets = 1;
Chia-I Wu1b99bb22015-10-27 19:25:11 +08004258 ds_pool_ci.poolSizeCount = 1;
4259 ds_pool_ci.pPoolSizes = &ds_type_count;
Tony Barboureb254902015-07-15 12:50:33 -06004260
Tobin Ehlis53eddda2015-07-01 16:46:13 -06004261 VkDescriptorPool ds_pool;
Chia-I Wuf7458c52015-10-26 21:10:41 +08004262 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis53eddda2015-07-01 16:46:13 -06004263 ASSERT_VK_SUCCESS(err);
4264
Tony Barboureb254902015-07-15 12:50:33 -06004265 VkDescriptorSetLayoutBinding dsl_binding = {};
Chia-I Wud46e6ae2015-10-31 00:31:16 +08004266 dsl_binding.binding = 0;
Tony Barboureb254902015-07-15 12:50:33 -06004267 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wu02124482015-11-06 06:42:02 +08004268 dsl_binding.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06004269 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
4270 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis53eddda2015-07-01 16:46:13 -06004271
Tony Barboureb254902015-07-15 12:50:33 -06004272 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
4273 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
4274 ds_layout_ci.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08004275 ds_layout_ci.bindingCount = 1;
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07004276 ds_layout_ci.pBindings = &dsl_binding;
Mark Lobodzinski209b5292015-09-17 09:44:05 -06004277
Tobin Ehlis53eddda2015-07-01 16:46:13 -06004278 VkDescriptorSetLayout ds_layout;
Chia-I Wuf7458c52015-10-26 21:10:41 +08004279 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis53eddda2015-07-01 16:46:13 -06004280 ASSERT_VK_SUCCESS(err);
4281
4282 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004283 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08004284 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07004285 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06004286 alloc_info.descriptorPool = ds_pool;
4287 alloc_info.pSetLayouts = &ds_layout;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004288 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis53eddda2015-07-01 16:46:13 -06004289 ASSERT_VK_SUCCESS(err);
4290
Tony Barboureb254902015-07-15 12:50:33 -06004291 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
4292 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
4293 pipe_ms_state_ci.pNext = NULL;
Chia-I Wu5c17c962015-10-31 00:31:16 +08004294 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_4_BIT;
Tony Barboureb254902015-07-15 12:50:33 -06004295 pipe_ms_state_ci.sampleShadingEnable = 0;
4296 pipe_ms_state_ci.minSampleShading = 1.0;
Cody Northrop02e61ed2015-08-04 14:34:54 -06004297 pipe_ms_state_ci.pSampleMask = NULL;
Tobin Ehlis53eddda2015-07-01 16:46:13 -06004298
Tony Barboureb254902015-07-15 12:50:33 -06004299 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
4300 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
4301 pipeline_layout_ci.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08004302 pipeline_layout_ci.setLayoutCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06004303 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis53eddda2015-07-01 16:46:13 -06004304
4305 VkPipelineLayout pipeline_layout;
Chia-I Wuf7458c52015-10-26 21:10:41 +08004306 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis53eddda2015-07-01 16:46:13 -06004307 ASSERT_VK_SUCCESS(err);
Mark Lobodzinski209b5292015-09-17 09:44:05 -06004308
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06004309 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06004310 // TODO - We shouldn't need a fragment shader but add it to be able to run on more devices
4311 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
4312
Tony Barbour62e1a5b2015-08-06 10:16:07 -06004313 VkPipelineObj pipe(m_device);
4314 pipe.AddShader(&vs);
Tony Barbour1c94d372015-08-06 11:21:08 -06004315 pipe.AddShader(&fs);
Tony Barbour62e1a5b2015-08-06 10:16:07 -06004316 pipe.SetMSAA(&pipe_ms_state_ci);
4317 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tony Barbourfe3351b2015-07-28 10:17:20 -06004318
4319 BeginCommandBuffer();
Tobin Ehlis53eddda2015-07-01 16:46:13 -06004320
Tobin Ehlis53eddda2015-07-01 16:46:13 -06004321 // Main thing we care about for this test is that the VkImage obj we're clearing matches Color Attachment of FB
4322 // Also pass down other dummy params to keep driver and paramchecker happy
Courtney Goeltzenleuchterc9323e02015-10-15 16:51:05 -06004323 VkClearAttachment color_attachment;
4324 color_attachment.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
4325 color_attachment.clearValue.color.float32[0] = 1.0;
4326 color_attachment.clearValue.color.float32[1] = 1.0;
4327 color_attachment.clearValue.color.float32[2] = 1.0;
4328 color_attachment.clearValue.color.float32[3] = 1.0;
4329 color_attachment.colorAttachment = 0;
Jon Ashburnf19916e2016-01-11 13:12:43 -07004330 VkClearRect clear_rect = { { { 0, 0 }, { (uint32_t)m_width, (uint32_t)m_height } } };
Tobin Ehlis53eddda2015-07-01 16:46:13 -06004331
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004332 vkCmdClearAttachments(m_commandBuffer->GetBufferHandle(), 1, &color_attachment, 1, &clear_rect);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06004333
4334 if (!m_errorMonitor->DesiredMsgFound()) {
4335 FAIL() << "Did not receive Error 'vkCommandClearAttachments() issued on CB object...'";
4336 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlis53eddda2015-07-01 16:46:13 -06004337 }
Mike Stroyand1c84a52015-08-18 14:40:24 -06004338
Chia-I Wuf7458c52015-10-26 21:10:41 +08004339 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
4340 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
4341 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis53eddda2015-07-01 16:46:13 -06004342}
4343
Tobin Ehlis502480b2015-06-24 15:53:07 -06004344TEST_F(VkLayerTest, VtxBufferBadIndex)
4345{
Tobin Ehlis502480b2015-06-24 15:53:07 -06004346 VkResult err;
4347
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07004348 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERF_WARN_BIT_EXT,
Mark Lobodzinskidfcd9b62015-12-14 15:14:10 -07004349 "but no vertex buffers are attached to this Pipeline State Object");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06004350
Tobin Ehlis502480b2015-06-24 15:53:07 -06004351 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisd332f282015-10-02 11:00:56 -06004352 ASSERT_NO_FATAL_FAILURE(InitViewport());
Tobin Ehlis502480b2015-06-24 15:53:07 -06004353 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barboureb254902015-07-15 12:50:33 -06004354
Chia-I Wu1b99bb22015-10-27 19:25:11 +08004355 VkDescriptorPoolSize ds_type_count = {};
Tony Barboureb254902015-07-15 12:50:33 -06004356 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wud50a7d72015-10-26 20:48:51 +08004357 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06004358
4359 VkDescriptorPoolCreateInfo ds_pool_ci = {};
4360 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
4361 ds_pool_ci.pNext = NULL;
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -06004362 ds_pool_ci.maxSets = 1;
Chia-I Wu1b99bb22015-10-27 19:25:11 +08004363 ds_pool_ci.poolSizeCount = 1;
4364 ds_pool_ci.pPoolSizes = &ds_type_count;
Tony Barboureb254902015-07-15 12:50:33 -06004365
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -06004366 VkDescriptorPool ds_pool;
Chia-I Wuf7458c52015-10-26 21:10:41 +08004367 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis502480b2015-06-24 15:53:07 -06004368 ASSERT_VK_SUCCESS(err);
4369
Tony Barboureb254902015-07-15 12:50:33 -06004370 VkDescriptorSetLayoutBinding dsl_binding = {};
Chia-I Wud46e6ae2015-10-31 00:31:16 +08004371 dsl_binding.binding = 0;
Tony Barboureb254902015-07-15 12:50:33 -06004372 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wu02124482015-11-06 06:42:02 +08004373 dsl_binding.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06004374 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
4375 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis502480b2015-06-24 15:53:07 -06004376
Tony Barboureb254902015-07-15 12:50:33 -06004377 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
4378 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
4379 ds_layout_ci.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08004380 ds_layout_ci.bindingCount = 1;
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07004381 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -06004382
Tobin Ehlis502480b2015-06-24 15:53:07 -06004383 VkDescriptorSetLayout ds_layout;
Chia-I Wuf7458c52015-10-26 21:10:41 +08004384 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis502480b2015-06-24 15:53:07 -06004385 ASSERT_VK_SUCCESS(err);
4386
4387 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004388 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08004389 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07004390 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06004391 alloc_info.descriptorPool = ds_pool;
4392 alloc_info.pSetLayouts = &ds_layout;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004393 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis502480b2015-06-24 15:53:07 -06004394 ASSERT_VK_SUCCESS(err);
4395
Tony Barboureb254902015-07-15 12:50:33 -06004396 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
4397 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
4398 pipe_ms_state_ci.pNext = NULL;
Chia-I Wu5c17c962015-10-31 00:31:16 +08004399 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
Tony Barboureb254902015-07-15 12:50:33 -06004400 pipe_ms_state_ci.sampleShadingEnable = 0;
4401 pipe_ms_state_ci.minSampleShading = 1.0;
Cody Northrop02e61ed2015-08-04 14:34:54 -06004402 pipe_ms_state_ci.pSampleMask = NULL;
Tobin Ehlis502480b2015-06-24 15:53:07 -06004403
Tony Barboureb254902015-07-15 12:50:33 -06004404 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
4405 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
4406 pipeline_layout_ci.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08004407 pipeline_layout_ci.setLayoutCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06004408 pipeline_layout_ci.pSetLayouts = &ds_layout;
4409 VkPipelineLayout pipeline_layout;
Tobin Ehlis502480b2015-06-24 15:53:07 -06004410
Chia-I Wuf7458c52015-10-26 21:10:41 +08004411 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis502480b2015-06-24 15:53:07 -06004412 ASSERT_VK_SUCCESS(err);
4413
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06004414 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
4415 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 -06004416 // but add it to be able to run on more devices
Tony Barbour62e1a5b2015-08-06 10:16:07 -06004417 VkPipelineObj pipe(m_device);
4418 pipe.AddShader(&vs);
Tony Barbour1c94d372015-08-06 11:21:08 -06004419 pipe.AddShader(&fs);
Tony Barbour62e1a5b2015-08-06 10:16:07 -06004420 pipe.SetMSAA(&pipe_ms_state_ci);
Tobin Ehlisd332f282015-10-02 11:00:56 -06004421 pipe.SetViewport(m_viewports);
4422 pipe.SetScissor(m_scissors);
Tony Barbour62e1a5b2015-08-06 10:16:07 -06004423 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tony Barbourfe3351b2015-07-28 10:17:20 -06004424
4425 BeginCommandBuffer();
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004426 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlisf7bf4502015-09-09 15:12:35 -06004427 // Don't care about actual data, just need to get to draw to flag error
4428 static const float vbo_data[3] = {1.f, 0.f, 1.f};
4429 VkConstantBufferObj vbo(m_device, sizeof(vbo_data), sizeof(float), (const void*) &vbo_data);
4430 BindVertexBuffer(&vbo, (VkDeviceSize)0, 1); // VBO idx 1, but no VBO in PSO
Courtney Goeltzenleuchter08c26372015-09-23 12:31:50 -06004431 Draw(1, 0, 0, 0);
Tobin Ehlis502480b2015-06-24 15:53:07 -06004432
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06004433 if (!m_errorMonitor->DesiredMsgFound()) {
4434 FAIL() << "Did not receive Error 'Vtx Buffer Index 0 was bound, but no vtx buffers are attached to PSO.'";
4435 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlis502480b2015-06-24 15:53:07 -06004436 }
Mike Stroyand1c84a52015-08-18 14:40:24 -06004437
Chia-I Wuf7458c52015-10-26 21:10:41 +08004438 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
4439 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
4440 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis502480b2015-06-24 15:53:07 -06004441}
Mark Lobodzinski209b5292015-09-17 09:44:05 -06004442#endif // DRAW_STATE_TESTS
4443
Tobin Ehlis0788f522015-05-26 16:11:58 -06004444#if THREADING_TESTS
Mike Stroyanaccf7692015-05-12 16:00:45 -06004445#if GTEST_IS_THREADSAFE
4446struct thread_data_struct {
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004447 VkCommandBuffer commandBuffer;
Mike Stroyanaccf7692015-05-12 16:00:45 -06004448 VkEvent event;
4449 bool bailout;
4450};
4451
4452extern "C" void *AddToCommandBuffer(void *arg)
4453{
4454 struct thread_data_struct *data = (struct thread_data_struct *) arg;
Mike Stroyanaccf7692015-05-12 16:00:45 -06004455
4456 for (int i = 0; i<10000; i++) {
Chia-I Wu89d0f942015-10-31 00:31:16 +08004457 vkCmdSetEvent(data->commandBuffer, data->event, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT);
Mike Stroyanaccf7692015-05-12 16:00:45 -06004458 if (data->bailout) {
4459 break;
4460 }
4461 }
4462 return NULL;
4463}
4464
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004465TEST_F(VkLayerTest, ThreadCommandBufferCollision)
Mike Stroyanaccf7692015-05-12 16:00:45 -06004466{
Mike Stroyan4268d1f2015-07-13 14:45:35 -06004467 test_platform_thread thread;
Mike Stroyanaccf7692015-05-12 16:00:45 -06004468
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07004469 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "THREADING ERROR");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06004470
Mike Stroyanaccf7692015-05-12 16:00:45 -06004471 ASSERT_NO_FATAL_FAILURE(InitState());
4472 ASSERT_NO_FATAL_FAILURE(InitViewport());
4473 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
4474
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004475 // Calls AllocateCommandBuffers
4476 VkCommandBufferObj commandBuffer(m_device, m_commandPool);
Mark Lobodzinski5495d132015-09-30 16:19:16 -06004477
4478 // Avoid creating RenderPass
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004479 commandBuffer.BeginCommandBuffer();
Mike Stroyanaccf7692015-05-12 16:00:45 -06004480
4481 VkEventCreateInfo event_info;
4482 VkEvent event;
Mike Stroyanaccf7692015-05-12 16:00:45 -06004483 VkResult err;
4484
4485 memset(&event_info, 0, sizeof(event_info));
4486 event_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
4487
Chia-I Wuf7458c52015-10-26 21:10:41 +08004488 err = vkCreateEvent(device(), &event_info, NULL, &event);
Mike Stroyanaccf7692015-05-12 16:00:45 -06004489 ASSERT_VK_SUCCESS(err);
4490
Mike Stroyanaccf7692015-05-12 16:00:45 -06004491 err = vkResetEvent(device(), event);
4492 ASSERT_VK_SUCCESS(err);
4493
4494 struct thread_data_struct data;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004495 data.commandBuffer = commandBuffer.GetBufferHandle();
Mike Stroyanaccf7692015-05-12 16:00:45 -06004496 data.event = event;
4497 data.bailout = false;
4498 m_errorMonitor->SetBailout(&data.bailout);
4499 // Add many entries to command buffer from another thread.
Mike Stroyan4268d1f2015-07-13 14:45:35 -06004500 test_platform_thread_create(&thread, AddToCommandBuffer, (void *)&data);
Mike Stroyanaccf7692015-05-12 16:00:45 -06004501 // Add many entries to command buffer from this thread at the same time.
4502 AddToCommandBuffer(&data);
Mark Lobodzinski5495d132015-09-30 16:19:16 -06004503
Mike Stroyan4268d1f2015-07-13 14:45:35 -06004504 test_platform_thread_join(thread, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004505 commandBuffer.EndCommandBuffer();
Mike Stroyanaccf7692015-05-12 16:00:45 -06004506
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06004507 if (!m_errorMonitor->DesiredMsgFound()) {
4508 FAIL() << "Did not receive Error 'THREADING ERROR' from using one VkCommandBufferObj in two threads";
4509 m_errorMonitor->DumpFailureMsgs();
Mike Stroyanaccf7692015-05-12 16:00:45 -06004510 }
4511
Chia-I Wuf7458c52015-10-26 21:10:41 +08004512 vkDestroyEvent(device(), event, NULL);
Mike Stroyanaccf7692015-05-12 16:00:45 -06004513}
Mark Lobodzinski209b5292015-09-17 09:44:05 -06004514#endif // GTEST_IS_THREADSAFE
4515#endif // THREADING_TESTS
4516
Chris Forbes9f7ff632015-05-25 11:13:08 +12004517#if SHADER_CHECKER_TESTS
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -06004518TEST_F(VkLayerTest, InvalidSPIRVCodeSize)
4519{
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07004520 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06004521 "Shader is not SPIR-V");
4522
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -06004523 ASSERT_NO_FATAL_FAILURE(InitState());
4524 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
4525
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -06004526 VkShaderModule module;
4527 VkShaderModuleCreateInfo moduleCreateInfo;
4528 struct icd_spv_header spv;
4529
4530 spv.magic = ICD_SPV_MAGIC;
4531 spv.version = ICD_SPV_VERSION;
4532 spv.gen_magic = 0;
4533
4534 moduleCreateInfo.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;
4535 moduleCreateInfo.pNext = NULL;
Chia-I Wu8094f192015-10-26 19:22:06 +08004536 moduleCreateInfo.pCode = (const uint32_t *) &spv;
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -06004537 moduleCreateInfo.codeSize = 4;
4538 moduleCreateInfo.flags = 0;
Chia-I Wuf7458c52015-10-26 21:10:41 +08004539 vkCreateShaderModule(m_device->device(), &moduleCreateInfo, NULL, &module);
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -06004540
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06004541 if (!m_errorMonitor->DesiredMsgFound()) {
4542 FAIL() << "Did not recieive Error 'Shader is not SPIR-V'";
4543 m_errorMonitor->DumpFailureMsgs();
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -06004544 }
4545}
4546
4547TEST_F(VkLayerTest, InvalidSPIRVMagic)
4548{
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07004549 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06004550 "Shader is not SPIR-V");
4551
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -06004552 ASSERT_NO_FATAL_FAILURE(InitState());
4553 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
4554
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -06004555 VkShaderModule module;
4556 VkShaderModuleCreateInfo moduleCreateInfo;
4557 struct icd_spv_header spv;
4558
4559 spv.magic = ~ICD_SPV_MAGIC;
4560 spv.version = ICD_SPV_VERSION;
4561 spv.gen_magic = 0;
4562
4563 moduleCreateInfo.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;
4564 moduleCreateInfo.pNext = NULL;
Chia-I Wu8094f192015-10-26 19:22:06 +08004565 moduleCreateInfo.pCode = (const uint32_t *) &spv;
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -06004566 moduleCreateInfo.codeSize = sizeof(spv) + 10;
4567 moduleCreateInfo.flags = 0;
Chia-I Wuf7458c52015-10-26 21:10:41 +08004568 vkCreateShaderModule(m_device->device(), &moduleCreateInfo, NULL, &module);
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -06004569
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06004570 if (!m_errorMonitor->DesiredMsgFound()) {
4571 FAIL() << "Did not recieive Error 'Shader is not SPIR-V'";
4572 m_errorMonitor->DumpFailureMsgs();
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -06004573 }
4574}
4575
4576TEST_F(VkLayerTest, InvalidSPIRVVersion)
4577{
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07004578 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06004579 "Shader is not SPIR-V");
4580
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -06004581 ASSERT_NO_FATAL_FAILURE(InitState());
4582 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
4583
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -06004584 VkShaderModule module;
4585 VkShaderModuleCreateInfo moduleCreateInfo;
4586 struct icd_spv_header spv;
4587
4588 spv.magic = ICD_SPV_MAGIC;
4589 spv.version = ~ICD_SPV_VERSION;
4590 spv.gen_magic = 0;
4591
4592 moduleCreateInfo.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;
4593 moduleCreateInfo.pNext = NULL;
4594
Chia-I Wu8094f192015-10-26 19:22:06 +08004595 moduleCreateInfo.pCode = (const uint32_t *) &spv;
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -06004596 moduleCreateInfo.codeSize = sizeof(spv) + 10;
4597 moduleCreateInfo.flags = 0;
Chia-I Wuf7458c52015-10-26 21:10:41 +08004598 vkCreateShaderModule(m_device->device(), &moduleCreateInfo, NULL, &module);
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -06004599
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06004600 if (!m_errorMonitor->DesiredMsgFound()) {
4601 FAIL() << "Did not recieive Error 'Shader is not SPIR-V'";
4602 m_errorMonitor->DumpFailureMsgs();
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -06004603 }
4604}
4605
Chris Forbes9f7ff632015-05-25 11:13:08 +12004606TEST_F(VkLayerTest, CreatePipelineVertexOutputNotConsumed)
4607{
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07004608 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERF_WARN_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06004609 "not consumed by fragment shader");
4610
Chris Forbes9f7ff632015-05-25 11:13:08 +12004611 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06004612 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes9f7ff632015-05-25 11:13:08 +12004613
4614 char const *vsSource =
Tony Barboure804d202016-01-05 13:37:45 -07004615 "#version 400\n"
Chris Forbes9f7ff632015-05-25 11:13:08 +12004616 "#extension GL_ARB_separate_shader_objects: require\n"
4617 "#extension GL_ARB_shading_language_420pack: require\n"
4618 "\n"
4619 "layout(location=0) out float x;\n"
Tony Barboure804d202016-01-05 13:37:45 -07004620 "out gl_PerVertex {\n"
4621 " vec4 gl_Position;\n"
4622 "};\n"
Chris Forbes9f7ff632015-05-25 11:13:08 +12004623 "void main(){\n"
4624 " gl_Position = vec4(1);\n"
4625 " x = 0;\n"
4626 "}\n";
4627 char const *fsSource =
Tony Barboure804d202016-01-05 13:37:45 -07004628 "#version 400\n"
Chris Forbes9f7ff632015-05-25 11:13:08 +12004629 "#extension GL_ARB_separate_shader_objects: require\n"
4630 "#extension GL_ARB_shading_language_420pack: require\n"
4631 "\n"
4632 "layout(location=0) out vec4 color;\n"
4633 "void main(){\n"
4634 " color = vec4(1);\n"
4635 "}\n";
4636
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06004637 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
4638 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes9f7ff632015-05-25 11:13:08 +12004639
4640 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +08004641 pipe.AddColorAttachment();
Chris Forbes9f7ff632015-05-25 11:13:08 +12004642 pipe.AddShader(&vs);
4643 pipe.AddShader(&fs);
4644
Chris Forbes9f7ff632015-05-25 11:13:08 +12004645 VkDescriptorSetObj descriptorSet(m_device);
4646 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004647 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes9f7ff632015-05-25 11:13:08 +12004648
Tony Barbour5781e8f2015-08-04 16:23:11 -06004649 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes9f7ff632015-05-25 11:13:08 +12004650
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06004651 if (!m_errorMonitor->DesiredMsgFound()) {
4652 FAIL() << "Did not receive Warning 'not consumed by fragment shader'";
4653 m_errorMonitor->DumpFailureMsgs();
Chris Forbes9f7ff632015-05-25 11:13:08 +12004654 }
4655}
Chris Forbes9f7ff632015-05-25 11:13:08 +12004656
Chris Forbes59cb88d2015-05-25 11:13:13 +12004657TEST_F(VkLayerTest, CreatePipelineFragmentInputNotProvided)
4658{
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07004659 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06004660 "not written by vertex shader");
4661
Chris Forbes59cb88d2015-05-25 11:13:13 +12004662 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06004663 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes59cb88d2015-05-25 11:13:13 +12004664
4665 char const *vsSource =
Tony Barboure804d202016-01-05 13:37:45 -07004666 "#version 400\n"
Chris Forbes59cb88d2015-05-25 11:13:13 +12004667 "#extension GL_ARB_separate_shader_objects: require\n"
4668 "#extension GL_ARB_shading_language_420pack: require\n"
4669 "\n"
Tony Barboure804d202016-01-05 13:37:45 -07004670 "out gl_PerVertex {\n"
4671 " vec4 gl_Position;\n"
4672 "};\n"
Chris Forbes59cb88d2015-05-25 11:13:13 +12004673 "void main(){\n"
4674 " gl_Position = vec4(1);\n"
4675 "}\n";
4676 char const *fsSource =
Tony Barboure804d202016-01-05 13:37:45 -07004677 "#version 400\n"
Chris Forbes59cb88d2015-05-25 11:13:13 +12004678 "#extension GL_ARB_separate_shader_objects: require\n"
4679 "#extension GL_ARB_shading_language_420pack: require\n"
4680 "\n"
4681 "layout(location=0) in float x;\n"
4682 "layout(location=0) out vec4 color;\n"
4683 "void main(){\n"
4684 " color = vec4(x);\n"
4685 "}\n";
4686
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06004687 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
4688 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes59cb88d2015-05-25 11:13:13 +12004689
4690 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +08004691 pipe.AddColorAttachment();
Chris Forbes59cb88d2015-05-25 11:13:13 +12004692 pipe.AddShader(&vs);
4693 pipe.AddShader(&fs);
4694
Chris Forbes59cb88d2015-05-25 11:13:13 +12004695 VkDescriptorSetObj descriptorSet(m_device);
4696 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004697 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes59cb88d2015-05-25 11:13:13 +12004698
Tony Barbour5781e8f2015-08-04 16:23:11 -06004699 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes59cb88d2015-05-25 11:13:13 +12004700
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06004701 if (!m_errorMonitor->DesiredMsgFound()) {
4702 FAIL() << "Did not receive Error 'not written by vertex shader'";
4703 m_errorMonitor->DumpFailureMsgs();
Chris Forbes59cb88d2015-05-25 11:13:13 +12004704 }
4705}
4706
Chris Forbesa3e85f62016-01-15 14:53:11 +13004707TEST_F(VkLayerTest, CreatePipelineFragmentInputNotProvidedInBlock)
4708{
4709 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
4710 "not written by vertex shader");
4711
4712 ASSERT_NO_FATAL_FAILURE(InitState());
4713 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
4714
4715 char const *vsSource =
4716 "#version 400\n"
4717 "#extension GL_ARB_separate_shader_objects: require\n"
4718 "#extension GL_ARB_shading_language_420pack: require\n"
4719 "\n"
4720 "out gl_PerVertex {\n"
4721 " vec4 gl_Position;\n"
4722 "};\n"
4723 "void main(){\n"
4724 " gl_Position = vec4(1);\n"
4725 "}\n";
4726 char const *fsSource =
4727 "#version 450\n"
4728 "#extension GL_ARB_separate_shader_objects: require\n"
4729 "#extension GL_ARB_shading_language_420pack: require\n"
4730 "\n"
4731 "in block { layout(location=0) float x; } ins;\n"
4732 "layout(location=0) out vec4 color;\n"
4733 "void main(){\n"
4734 " color = vec4(ins.x);\n"
4735 "}\n";
4736
4737 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
4738 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
4739
4740 VkPipelineObj pipe(m_device);
4741 pipe.AddColorAttachment();
4742 pipe.AddShader(&vs);
4743 pipe.AddShader(&fs);
4744
4745 VkDescriptorSetObj descriptorSet(m_device);
4746 descriptorSet.AppendDummy();
4747 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
4748
4749 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
4750
4751 if (!m_errorMonitor->DesiredMsgFound()) {
4752 FAIL() << "Did not receive Error 'not written by vertex shader'";
4753 m_errorMonitor->DumpFailureMsgs();
4754 }
4755}
4756
Chris Forbes0036fd12016-01-26 14:19:49 +13004757TEST_F(VkLayerTest, CreatePipelineVsFsTypeMismatchArraySize)
4758{
4759 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
4760 "Type mismatch on location 0: 'ptr to output arr[2] of float32' vs 'ptr to input arr[3] of float32'");
4761
4762 ASSERT_NO_FATAL_FAILURE(InitState());
4763 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
4764
4765 char const *vsSource =
4766 "#version 400\n"
4767 "#extension GL_ARB_separate_shader_objects: require\n"
4768 "#extension GL_ARB_shading_language_420pack: require\n"
4769 "\n"
4770 "layout(location=0) out float x[2];\n"
4771 "out gl_PerVertex {\n"
4772 " vec4 gl_Position;\n"
4773 "};\n"
4774 "void main(){\n"
4775 " x[0] = 0; x[1] = 0;\n"
4776 " gl_Position = vec4(1);\n"
4777 "}\n";
4778 char const *fsSource =
4779 "#version 400\n"
4780 "#extension GL_ARB_separate_shader_objects: require\n"
4781 "#extension GL_ARB_shading_language_420pack: require\n"
4782 "\n"
4783 "layout(location=0) in float x[3];\n"
4784 "layout(location=0) out vec4 color;\n"
4785 "void main(){\n"
4786 " color = vec4(x[0] + x[1] + x[2]);\n"
4787 "}\n";
4788
4789 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
4790 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
4791
4792 VkPipelineObj pipe(m_device);
4793 pipe.AddColorAttachment();
4794 pipe.AddShader(&vs);
4795 pipe.AddShader(&fs);
4796
4797 VkDescriptorSetObj descriptorSet(m_device);
4798 descriptorSet.AppendDummy();
4799 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
4800
4801 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
4802
4803 if (!m_errorMonitor->DesiredMsgFound()) {
4804 m_errorMonitor->DumpFailureMsgs();
4805 FAIL() << "Did not receive Error 'Type mismatch on location 0: 'ptr to output arr[2] of float32' vs 'ptr to input arr[3] of float32''";
4806 }
4807}
4808
Chris Forbesb56af562015-05-25 11:13:17 +12004809TEST_F(VkLayerTest, CreatePipelineVsFsTypeMismatch)
4810{
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07004811 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06004812 "Type mismatch on location 0");
4813
Chris Forbesb56af562015-05-25 11:13:17 +12004814 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06004815 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesb56af562015-05-25 11:13:17 +12004816
4817 char const *vsSource =
Tony Barboure804d202016-01-05 13:37:45 -07004818 "#version 400\n"
Chris Forbesb56af562015-05-25 11:13:17 +12004819 "#extension GL_ARB_separate_shader_objects: require\n"
4820 "#extension GL_ARB_shading_language_420pack: require\n"
4821 "\n"
4822 "layout(location=0) out int x;\n"
Tony Barboure804d202016-01-05 13:37:45 -07004823 "out gl_PerVertex {\n"
4824 " vec4 gl_Position;\n"
4825 "};\n"
Chris Forbesb56af562015-05-25 11:13:17 +12004826 "void main(){\n"
4827 " x = 0;\n"
4828 " gl_Position = vec4(1);\n"
4829 "}\n";
4830 char const *fsSource =
Tony Barboure804d202016-01-05 13:37:45 -07004831 "#version 400\n"
Chris Forbesb56af562015-05-25 11:13:17 +12004832 "#extension GL_ARB_separate_shader_objects: require\n"
4833 "#extension GL_ARB_shading_language_420pack: require\n"
4834 "\n"
4835 "layout(location=0) in float x;\n" /* VS writes int */
4836 "layout(location=0) out vec4 color;\n"
4837 "void main(){\n"
4838 " color = vec4(x);\n"
4839 "}\n";
4840
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06004841 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
4842 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesb56af562015-05-25 11:13:17 +12004843
4844 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +08004845 pipe.AddColorAttachment();
Chris Forbesb56af562015-05-25 11:13:17 +12004846 pipe.AddShader(&vs);
4847 pipe.AddShader(&fs);
4848
Chris Forbesb56af562015-05-25 11:13:17 +12004849 VkDescriptorSetObj descriptorSet(m_device);
4850 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004851 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesb56af562015-05-25 11:13:17 +12004852
Tony Barbour5781e8f2015-08-04 16:23:11 -06004853 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesb56af562015-05-25 11:13:17 +12004854
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06004855 if (!m_errorMonitor->DesiredMsgFound()) {
4856 FAIL() << "Did not receive Error 'Type mismatch on location 0'";
4857 m_errorMonitor->DumpFailureMsgs();
Chris Forbesb56af562015-05-25 11:13:17 +12004858 }
4859}
4860
Chris Forbesa3e85f62016-01-15 14:53:11 +13004861TEST_F(VkLayerTest, CreatePipelineVsFsTypeMismatchInBlock)
4862{
4863 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
4864 "Type mismatch on location 0");
4865
4866 ASSERT_NO_FATAL_FAILURE(InitState());
4867 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
4868
4869 char const *vsSource =
4870 "#version 450\n"
4871 "#extension GL_ARB_separate_shader_objects: require\n"
4872 "#extension GL_ARB_shading_language_420pack: require\n"
4873 "\n"
4874 "out block { layout(location=0) int x; } outs;\n"
4875 "out gl_PerVertex {\n"
4876 " vec4 gl_Position;\n"
4877 "};\n"
4878 "void main(){\n"
4879 " outs.x = 0;\n"
4880 " gl_Position = vec4(1);\n"
4881 "}\n";
4882 char const *fsSource =
4883 "#version 450\n"
4884 "#extension GL_ARB_separate_shader_objects: require\n"
4885 "#extension GL_ARB_shading_language_420pack: require\n"
4886 "\n"
4887 "in block { layout(location=0) float x; } ins;\n" /* VS writes int */
4888 "layout(location=0) out vec4 color;\n"
4889 "void main(){\n"
4890 " color = vec4(ins.x);\n"
4891 "}\n";
4892
4893 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
4894 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
4895
4896 VkPipelineObj pipe(m_device);
4897 pipe.AddColorAttachment();
4898 pipe.AddShader(&vs);
4899 pipe.AddShader(&fs);
4900
4901 VkDescriptorSetObj descriptorSet(m_device);
4902 descriptorSet.AppendDummy();
4903 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
4904
4905 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
4906
4907 if (!m_errorMonitor->DesiredMsgFound()) {
4908 FAIL() << "Did not receive Error 'Type mismatch on location 0'";
4909 m_errorMonitor->DumpFailureMsgs();
4910 }
4911}
4912
4913
Chris Forbesde136e02015-05-25 11:13:28 +12004914TEST_F(VkLayerTest, CreatePipelineAttribNotConsumed)
4915{
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07004916 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERF_WARN_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06004917 "location 0 not consumed by VS");
4918
Chris Forbesde136e02015-05-25 11:13:28 +12004919 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06004920 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesde136e02015-05-25 11:13:28 +12004921
4922 VkVertexInputBindingDescription input_binding;
4923 memset(&input_binding, 0, sizeof(input_binding));
4924
4925 VkVertexInputAttributeDescription input_attrib;
4926 memset(&input_attrib, 0, sizeof(input_attrib));
4927 input_attrib.format = VK_FORMAT_R32_SFLOAT;
4928
4929 char const *vsSource =
Tony Barboure804d202016-01-05 13:37:45 -07004930 "#version 400\n"
Chris Forbesde136e02015-05-25 11:13:28 +12004931 "#extension GL_ARB_separate_shader_objects: require\n"
4932 "#extension GL_ARB_shading_language_420pack: require\n"
4933 "\n"
Tony Barboure804d202016-01-05 13:37:45 -07004934 "out gl_PerVertex {\n"
4935 " vec4 gl_Position;\n"
4936 "};\n"
Chris Forbesde136e02015-05-25 11:13:28 +12004937 "void main(){\n"
4938 " gl_Position = vec4(1);\n"
4939 "}\n";
4940 char const *fsSource =
Tony Barboure804d202016-01-05 13:37:45 -07004941 "#version 400\n"
Chris Forbesde136e02015-05-25 11:13:28 +12004942 "#extension GL_ARB_separate_shader_objects: require\n"
4943 "#extension GL_ARB_shading_language_420pack: require\n"
4944 "\n"
4945 "layout(location=0) out vec4 color;\n"
4946 "void main(){\n"
4947 " color = vec4(1);\n"
4948 "}\n";
4949
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06004950 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
4951 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesde136e02015-05-25 11:13:28 +12004952
4953 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +08004954 pipe.AddColorAttachment();
Chris Forbesde136e02015-05-25 11:13:28 +12004955 pipe.AddShader(&vs);
4956 pipe.AddShader(&fs);
4957
4958 pipe.AddVertexInputBindings(&input_binding, 1);
4959 pipe.AddVertexInputAttribs(&input_attrib, 1);
4960
Chris Forbesde136e02015-05-25 11:13:28 +12004961 VkDescriptorSetObj descriptorSet(m_device);
4962 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004963 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesde136e02015-05-25 11:13:28 +12004964
Tony Barbour5781e8f2015-08-04 16:23:11 -06004965 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesde136e02015-05-25 11:13:28 +12004966
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06004967 if (!m_errorMonitor->DesiredMsgFound()) {
4968 FAIL() << "Did not receive Warning 'location 0 not consumed by VS'";
4969 m_errorMonitor->DumpFailureMsgs();
Chris Forbesde136e02015-05-25 11:13:28 +12004970 }
4971}
4972
Chris Forbesa3e85f62016-01-15 14:53:11 +13004973
Chris Forbes7d83cd52016-01-15 11:32:03 +13004974TEST_F(VkLayerTest, CreatePipelineAttribLocationMismatch)
4975{
4976 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERF_WARN_BIT_EXT,
4977 "location 0 not consumed by VS");
4978
4979 ASSERT_NO_FATAL_FAILURE(InitState());
4980 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
4981
4982 VkVertexInputBindingDescription input_binding;
4983 memset(&input_binding, 0, sizeof(input_binding));
4984
4985 VkVertexInputAttributeDescription input_attrib;
4986 memset(&input_attrib, 0, sizeof(input_attrib));
4987 input_attrib.format = VK_FORMAT_R32_SFLOAT;
4988
4989 char const *vsSource =
4990 "#version 400\n"
4991 "#extension GL_ARB_separate_shader_objects: require\n"
4992 "#extension GL_ARB_shading_language_420pack: require\n"
4993 "\n"
4994 "layout(location=1) in float x;\n"
4995 "out gl_PerVertex {\n"
4996 " vec4 gl_Position;\n"
4997 "};\n"
4998 "void main(){\n"
4999 " gl_Position = vec4(x);\n"
5000 "}\n";
5001 char const *fsSource =
5002 "#version 400\n"
5003 "#extension GL_ARB_separate_shader_objects: require\n"
5004 "#extension GL_ARB_shading_language_420pack: require\n"
5005 "\n"
5006 "layout(location=0) out vec4 color;\n"
5007 "void main(){\n"
5008 " color = vec4(1);\n"
5009 "}\n";
5010
5011 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
5012 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
5013
5014 VkPipelineObj pipe(m_device);
5015 pipe.AddColorAttachment();
5016 pipe.AddShader(&vs);
5017 pipe.AddShader(&fs);
5018
5019 pipe.AddVertexInputBindings(&input_binding, 1);
5020 pipe.AddVertexInputAttribs(&input_attrib, 1);
5021
5022 VkDescriptorSetObj descriptorSet(m_device);
5023 descriptorSet.AppendDummy();
5024 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
5025
5026 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
5027
5028 if (!m_errorMonitor->DesiredMsgFound()) {
5029 m_errorMonitor->DumpFailureMsgs();
5030 FAIL() << "Did not receive Warning 'location 0 not consumed by VS'";
5031 }
5032}
5033
Chris Forbes62e8e502015-05-25 11:13:29 +12005034TEST_F(VkLayerTest, CreatePipelineAttribNotProvided)
5035{
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07005036 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06005037 "VS consumes input at location 0 but not provided");
5038
Chris Forbes62e8e502015-05-25 11:13:29 +12005039 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06005040 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes62e8e502015-05-25 11:13:29 +12005041
5042 char const *vsSource =
Tony Barboure804d202016-01-05 13:37:45 -07005043 "#version 400\n"
Chris Forbes62e8e502015-05-25 11:13:29 +12005044 "#extension GL_ARB_separate_shader_objects: require\n"
5045 "#extension GL_ARB_shading_language_420pack: require\n"
5046 "\n"
5047 "layout(location=0) in vec4 x;\n" /* not provided */
Tony Barboure804d202016-01-05 13:37:45 -07005048 "out gl_PerVertex {\n"
5049 " vec4 gl_Position;\n"
5050 "};\n"
Chris Forbes62e8e502015-05-25 11:13:29 +12005051 "void main(){\n"
5052 " gl_Position = x;\n"
5053 "}\n";
5054 char const *fsSource =
Tony Barboure804d202016-01-05 13:37:45 -07005055 "#version 400\n"
Chris Forbes62e8e502015-05-25 11:13:29 +12005056 "#extension GL_ARB_separate_shader_objects: require\n"
5057 "#extension GL_ARB_shading_language_420pack: require\n"
5058 "\n"
5059 "layout(location=0) out vec4 color;\n"
5060 "void main(){\n"
5061 " color = vec4(1);\n"
5062 "}\n";
5063
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06005064 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
5065 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes62e8e502015-05-25 11:13:29 +12005066
5067 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +08005068 pipe.AddColorAttachment();
Chris Forbes62e8e502015-05-25 11:13:29 +12005069 pipe.AddShader(&vs);
5070 pipe.AddShader(&fs);
5071
Chris Forbes62e8e502015-05-25 11:13:29 +12005072 VkDescriptorSetObj descriptorSet(m_device);
5073 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005074 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes62e8e502015-05-25 11:13:29 +12005075
Tony Barbour5781e8f2015-08-04 16:23:11 -06005076 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes62e8e502015-05-25 11:13:29 +12005077
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06005078 if (!m_errorMonitor->DesiredMsgFound()) {
5079 FAIL() << "Did not receive Error 'VS consumes input at location 0 but not provided'";
5080 m_errorMonitor->DumpFailureMsgs();
Chris Forbes62e8e502015-05-25 11:13:29 +12005081 }
5082}
5083
Chris Forbesc97d98e2015-05-25 11:13:31 +12005084TEST_F(VkLayerTest, CreatePipelineAttribTypeMismatch)
5085{
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07005086 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06005087 "location 0 does not match VS input type");
5088
Chris Forbesc97d98e2015-05-25 11:13:31 +12005089 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06005090 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesc97d98e2015-05-25 11:13:31 +12005091
5092 VkVertexInputBindingDescription input_binding;
5093 memset(&input_binding, 0, sizeof(input_binding));
5094
5095 VkVertexInputAttributeDescription input_attrib;
5096 memset(&input_attrib, 0, sizeof(input_attrib));
5097 input_attrib.format = VK_FORMAT_R32_SFLOAT;
5098
5099 char const *vsSource =
Tony Barboure804d202016-01-05 13:37:45 -07005100 "#version 400\n"
Chris Forbesc97d98e2015-05-25 11:13:31 +12005101 "#extension GL_ARB_separate_shader_objects: require\n"
5102 "#extension GL_ARB_shading_language_420pack: require\n"
5103 "\n"
5104 "layout(location=0) in int x;\n" /* attrib provided float */
Tony Barboure804d202016-01-05 13:37:45 -07005105 "out gl_PerVertex {\n"
5106 " vec4 gl_Position;\n"
5107 "};\n"
Chris Forbesc97d98e2015-05-25 11:13:31 +12005108 "void main(){\n"
5109 " gl_Position = vec4(x);\n"
5110 "}\n";
5111 char const *fsSource =
Tony Barboure804d202016-01-05 13:37:45 -07005112 "#version 400\n"
Chris Forbesc97d98e2015-05-25 11:13:31 +12005113 "#extension GL_ARB_separate_shader_objects: require\n"
5114 "#extension GL_ARB_shading_language_420pack: require\n"
5115 "\n"
5116 "layout(location=0) out vec4 color;\n"
5117 "void main(){\n"
5118 " color = vec4(1);\n"
5119 "}\n";
5120
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06005121 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
5122 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesc97d98e2015-05-25 11:13:31 +12005123
5124 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +08005125 pipe.AddColorAttachment();
Chris Forbesc97d98e2015-05-25 11:13:31 +12005126 pipe.AddShader(&vs);
5127 pipe.AddShader(&fs);
5128
5129 pipe.AddVertexInputBindings(&input_binding, 1);
5130 pipe.AddVertexInputAttribs(&input_attrib, 1);
5131
Chris Forbesc97d98e2015-05-25 11:13:31 +12005132 VkDescriptorSetObj descriptorSet(m_device);
5133 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005134 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesc97d98e2015-05-25 11:13:31 +12005135
Tony Barbour5781e8f2015-08-04 16:23:11 -06005136 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesc97d98e2015-05-25 11:13:31 +12005137
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06005138 if (!m_errorMonitor->DesiredMsgFound()) {
5139 FAIL() << "Did not receive Error 'location 0 does not match VS input type'";
5140 m_errorMonitor->DumpFailureMsgs();
Chris Forbesc97d98e2015-05-25 11:13:31 +12005141 }
5142}
5143
Chris Forbes2682b242015-11-24 11:13:14 +13005144TEST_F(VkLayerTest, CreatePipelineAttribMatrixType)
5145{
5146 m_errorMonitor->SetDesiredFailureMsg(~0u, "");
5147
5148 ASSERT_NO_FATAL_FAILURE(InitState());
5149 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
5150
5151 VkVertexInputBindingDescription input_binding;
5152 memset(&input_binding, 0, sizeof(input_binding));
5153
5154 VkVertexInputAttributeDescription input_attribs[2];
5155 memset(input_attribs, 0, sizeof(input_attribs));
5156
5157 for (int i = 0; i < 2; i++) {
5158 input_attribs[i].format = VK_FORMAT_R32G32B32A32_SFLOAT;
5159 input_attribs[i].location = i;
5160 }
5161
5162 char const *vsSource =
Tony Barboure804d202016-01-05 13:37:45 -07005163 "#version 400\n"
Chris Forbes2682b242015-11-24 11:13:14 +13005164 "#extension GL_ARB_separate_shader_objects: require\n"
5165 "#extension GL_ARB_shading_language_420pack: require\n"
5166 "\n"
5167 "layout(location=0) in mat2x4 x;\n"
Tony Barboure804d202016-01-05 13:37:45 -07005168 "out gl_PerVertex {\n"
5169 " vec4 gl_Position;\n"
5170 "};\n"
Chris Forbes2682b242015-11-24 11:13:14 +13005171 "void main(){\n"
5172 " gl_Position = x[0] + x[1];\n"
5173 "}\n";
5174 char const *fsSource =
Tony Barboure804d202016-01-05 13:37:45 -07005175 "#version 400\n"
Chris Forbes2682b242015-11-24 11:13:14 +13005176 "#extension GL_ARB_separate_shader_objects: require\n"
5177 "#extension GL_ARB_shading_language_420pack: require\n"
5178 "\n"
5179 "layout(location=0) out vec4 color;\n"
5180 "void main(){\n"
5181 " color = vec4(1);\n"
5182 "}\n";
5183
5184 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
5185 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
5186
5187 VkPipelineObj pipe(m_device);
5188 pipe.AddColorAttachment();
5189 pipe.AddShader(&vs);
5190 pipe.AddShader(&fs);
5191
5192 pipe.AddVertexInputBindings(&input_binding, 1);
5193 pipe.AddVertexInputAttribs(input_attribs, 2);
5194
5195 VkDescriptorSetObj descriptorSet(m_device);
5196 descriptorSet.AppendDummy();
5197 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
5198
5199 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
5200
5201 /* expect success */
5202 if (m_errorMonitor->DesiredMsgFound()) {
5203 FAIL() << "Expected to succeed but: " << m_errorMonitor->GetFailureMsg();
5204 m_errorMonitor->DumpFailureMsgs();
5205 }
5206}
5207
5208/*
5209 * Would work, but not supported by glslang! This is similar to the matrix case above.
5210 *
5211TEST_F(VkLayerTest, CreatePipelineAttribArrayType)
5212{
5213 m_errorMonitor->SetDesiredFailureMsg(~0u, "");
5214
5215 ASSERT_NO_FATAL_FAILURE(InitState());
5216 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
5217
5218 VkVertexInputBindingDescription input_binding;
5219 memset(&input_binding, 0, sizeof(input_binding));
5220
5221 VkVertexInputAttributeDescription input_attribs[2];
5222 memset(input_attribs, 0, sizeof(input_attribs));
5223
5224 for (int i = 0; i < 2; i++) {
5225 input_attribs[i].format = VK_FORMAT_R32G32B32A32_SFLOAT;
5226 input_attribs[i].location = i;
5227 }
5228
5229 char const *vsSource =
Tony Barboure804d202016-01-05 13:37:45 -07005230 "#version 400\n"
Chris Forbes2682b242015-11-24 11:13:14 +13005231 "#extension GL_ARB_separate_shader_objects: require\n"
5232 "#extension GL_ARB_shading_language_420pack: require\n"
5233 "\n"
5234 "layout(location=0) in vec4 x[2];\n"
Tony Barboure804d202016-01-05 13:37:45 -07005235 "out gl_PerVertex {\n"
5236 " vec4 gl_Position;\n"
5237 "};\n"
Chris Forbes2682b242015-11-24 11:13:14 +13005238 "void main(){\n"
5239 " gl_Position = x[0] + x[1];\n"
5240 "}\n";
5241 char const *fsSource =
Tony Barboure804d202016-01-05 13:37:45 -07005242 "#version 400\n"
Chris Forbes2682b242015-11-24 11:13:14 +13005243 "#extension GL_ARB_separate_shader_objects: require\n"
5244 "#extension GL_ARB_shading_language_420pack: require\n"
5245 "\n"
5246 "layout(location=0) out vec4 color;\n"
5247 "void main(){\n"
5248 " color = vec4(1);\n"
5249 "}\n";
5250
5251 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
5252 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
5253
5254 VkPipelineObj pipe(m_device);
5255 pipe.AddColorAttachment();
5256 pipe.AddShader(&vs);
5257 pipe.AddShader(&fs);
5258
5259 pipe.AddVertexInputBindings(&input_binding, 1);
5260 pipe.AddVertexInputAttribs(input_attribs, 2);
5261
5262 VkDescriptorSetObj descriptorSet(m_device);
5263 descriptorSet.AppendDummy();
5264 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
5265
5266 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
5267
5268 if (m_errorMonitor->DesiredMsgFound()) {
5269 FAIL() << "Expected to succeed but: " << m_errorMonitor->GetFailureMsg();
5270 m_errorMonitor->DumpFailureMsgs();
5271 }
5272}
5273*/
5274
Chris Forbes280ba2c2015-06-12 11:16:41 +12005275TEST_F(VkLayerTest, CreatePipelineAttribBindingConflict)
5276{
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07005277 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06005278 "Duplicate vertex input binding descriptions for binding 0");
5279
Chris Forbes280ba2c2015-06-12 11:16:41 +12005280 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06005281 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes280ba2c2015-06-12 11:16:41 +12005282
5283 /* Two binding descriptions for binding 0 */
5284 VkVertexInputBindingDescription input_bindings[2];
5285 memset(input_bindings, 0, sizeof(input_bindings));
5286
5287 VkVertexInputAttributeDescription input_attrib;
5288 memset(&input_attrib, 0, sizeof(input_attrib));
5289 input_attrib.format = VK_FORMAT_R32_SFLOAT;
5290
5291 char const *vsSource =
Tony Barboure804d202016-01-05 13:37:45 -07005292 "#version 400\n"
Chris Forbes280ba2c2015-06-12 11:16:41 +12005293 "#extension GL_ARB_separate_shader_objects: require\n"
5294 "#extension GL_ARB_shading_language_420pack: require\n"
5295 "\n"
5296 "layout(location=0) in float x;\n" /* attrib provided float */
Tony Barboure804d202016-01-05 13:37:45 -07005297 "out gl_PerVertex {\n"
5298 " vec4 gl_Position;\n"
5299 "};\n"
Chris Forbes280ba2c2015-06-12 11:16:41 +12005300 "void main(){\n"
5301 " gl_Position = vec4(x);\n"
5302 "}\n";
5303 char const *fsSource =
Tony Barboure804d202016-01-05 13:37:45 -07005304 "#version 400\n"
Chris Forbes280ba2c2015-06-12 11:16:41 +12005305 "#extension GL_ARB_separate_shader_objects: require\n"
5306 "#extension GL_ARB_shading_language_420pack: require\n"
5307 "\n"
5308 "layout(location=0) out vec4 color;\n"
5309 "void main(){\n"
5310 " color = vec4(1);\n"
5311 "}\n";
5312
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06005313 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
5314 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes280ba2c2015-06-12 11:16:41 +12005315
5316 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +08005317 pipe.AddColorAttachment();
Chris Forbes280ba2c2015-06-12 11:16:41 +12005318 pipe.AddShader(&vs);
5319 pipe.AddShader(&fs);
5320
5321 pipe.AddVertexInputBindings(input_bindings, 2);
5322 pipe.AddVertexInputAttribs(&input_attrib, 1);
5323
Chris Forbes280ba2c2015-06-12 11:16:41 +12005324 VkDescriptorSetObj descriptorSet(m_device);
5325 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005326 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes280ba2c2015-06-12 11:16:41 +12005327
Tony Barbour5781e8f2015-08-04 16:23:11 -06005328 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes280ba2c2015-06-12 11:16:41 +12005329
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06005330 if (!m_errorMonitor->DesiredMsgFound()) {
5331 FAIL() << "Did not receive Error 'Duplicate vertex input binding descriptions for binding 0'";
5332 m_errorMonitor->DumpFailureMsgs();
Chris Forbes280ba2c2015-06-12 11:16:41 +12005333 }
5334}
Chris Forbes8f68b562015-05-25 11:13:32 +12005335
Chris Forbes4d6d1e52015-05-25 11:13:40 +12005336TEST_F(VkLayerTest, CreatePipelineFragmentOutputNotWritten)
5337{
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07005338 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06005339 "Attachment 0 not written by FS");
5340
Chris Forbes4d6d1e52015-05-25 11:13:40 +12005341 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbes4d6d1e52015-05-25 11:13:40 +12005342
5343 char const *vsSource =
Tony Barboure804d202016-01-05 13:37:45 -07005344 "#version 400\n"
Chris Forbes4d6d1e52015-05-25 11:13:40 +12005345 "#extension GL_ARB_separate_shader_objects: require\n"
5346 "#extension GL_ARB_shading_language_420pack: require\n"
5347 "\n"
Tony Barboure804d202016-01-05 13:37:45 -07005348 "out gl_PerVertex {\n"
5349 " vec4 gl_Position;\n"
5350 "};\n"
Chris Forbes4d6d1e52015-05-25 11:13:40 +12005351 "void main(){\n"
5352 " gl_Position = vec4(1);\n"
5353 "}\n";
5354 char const *fsSource =
Tony Barboure804d202016-01-05 13:37:45 -07005355 "#version 400\n"
Chris Forbes4d6d1e52015-05-25 11:13:40 +12005356 "#extension GL_ARB_separate_shader_objects: require\n"
5357 "#extension GL_ARB_shading_language_420pack: require\n"
5358 "\n"
5359 "void main(){\n"
5360 "}\n";
5361
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06005362 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
5363 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes4d6d1e52015-05-25 11:13:40 +12005364
5365 VkPipelineObj pipe(m_device);
5366 pipe.AddShader(&vs);
5367 pipe.AddShader(&fs);
5368
Chia-I Wu08accc62015-07-07 11:50:03 +08005369 /* set up CB 0, not written */
5370 pipe.AddColorAttachment();
5371 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes4d6d1e52015-05-25 11:13:40 +12005372
Chris Forbes4d6d1e52015-05-25 11:13:40 +12005373 VkDescriptorSetObj descriptorSet(m_device);
5374 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005375 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes4d6d1e52015-05-25 11:13:40 +12005376
Tony Barbour5781e8f2015-08-04 16:23:11 -06005377 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes4d6d1e52015-05-25 11:13:40 +12005378
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06005379 if (!m_errorMonitor->DesiredMsgFound()) {
5380 FAIL() << "Did not receive Error 'Attachment 0 not written by FS'";
5381 m_errorMonitor->DumpFailureMsgs();
Chris Forbes4d6d1e52015-05-25 11:13:40 +12005382 }
5383}
5384
Chris Forbesf3fffaa2015-05-25 11:13:43 +12005385TEST_F(VkLayerTest, CreatePipelineFragmentOutputNotConsumed)
5386{
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07005387 // TODO: verify that this matches layer
5388 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARN_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06005389 "FS writes to output location 1 with no matching attachment");
5390
Chris Forbesf3fffaa2015-05-25 11:13:43 +12005391 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbesf3fffaa2015-05-25 11:13:43 +12005392
5393 char const *vsSource =
Tony Barboure804d202016-01-05 13:37:45 -07005394 "#version 400\n"
Chris Forbesf3fffaa2015-05-25 11:13:43 +12005395 "#extension GL_ARB_separate_shader_objects: require\n"
5396 "#extension GL_ARB_shading_language_420pack: require\n"
5397 "\n"
Tony Barboure804d202016-01-05 13:37:45 -07005398 "out gl_PerVertex {\n"
5399 " vec4 gl_Position;\n"
5400 "};\n"
Chris Forbesf3fffaa2015-05-25 11:13:43 +12005401 "void main(){\n"
5402 " gl_Position = vec4(1);\n"
5403 "}\n";
5404 char const *fsSource =
Tony Barboure804d202016-01-05 13:37:45 -07005405 "#version 400\n"
Chris Forbesf3fffaa2015-05-25 11:13:43 +12005406 "#extension GL_ARB_separate_shader_objects: require\n"
5407 "#extension GL_ARB_shading_language_420pack: require\n"
5408 "\n"
5409 "layout(location=0) out vec4 x;\n"
5410 "layout(location=1) out vec4 y;\n" /* no matching attachment for this */
5411 "void main(){\n"
5412 " x = vec4(1);\n"
5413 " y = vec4(1);\n"
5414 "}\n";
5415
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06005416 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
5417 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesf3fffaa2015-05-25 11:13:43 +12005418
5419 VkPipelineObj pipe(m_device);
5420 pipe.AddShader(&vs);
5421 pipe.AddShader(&fs);
5422
Chia-I Wu08accc62015-07-07 11:50:03 +08005423 /* set up CB 0, not written */
5424 pipe.AddColorAttachment();
5425 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesf3fffaa2015-05-25 11:13:43 +12005426 /* FS writes CB 1, but we don't configure it */
5427
Chris Forbesf3fffaa2015-05-25 11:13:43 +12005428 VkDescriptorSetObj descriptorSet(m_device);
5429 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005430 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesf3fffaa2015-05-25 11:13:43 +12005431
Tony Barbour5781e8f2015-08-04 16:23:11 -06005432 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesf3fffaa2015-05-25 11:13:43 +12005433
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06005434 if (!m_errorMonitor->DesiredMsgFound()) {
5435 FAIL() << "Did not receive Error 'FS writes to output location 1 with no matching attachment'";
5436 m_errorMonitor->DumpFailureMsgs();
Chris Forbesf3fffaa2015-05-25 11:13:43 +12005437 }
5438}
5439
Chris Forbesa36d69e2015-05-25 11:13:44 +12005440TEST_F(VkLayerTest, CreatePipelineFragmentOutputTypeMismatch)
5441{
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07005442 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06005443 "does not match FS output type");
5444
Chris Forbesa36d69e2015-05-25 11:13:44 +12005445 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbesa36d69e2015-05-25 11:13:44 +12005446
5447 char const *vsSource =
Tony Barboure804d202016-01-05 13:37:45 -07005448 "#version 400\n"
Chris Forbesa36d69e2015-05-25 11:13:44 +12005449 "#extension GL_ARB_separate_shader_objects: require\n"
5450 "#extension GL_ARB_shading_language_420pack: require\n"
5451 "\n"
Tony Barboure804d202016-01-05 13:37:45 -07005452 "out gl_PerVertex {\n"
5453 " vec4 gl_Position;\n"
5454 "};\n"
Chris Forbesa36d69e2015-05-25 11:13:44 +12005455 "void main(){\n"
5456 " gl_Position = vec4(1);\n"
5457 "}\n";
5458 char const *fsSource =
Tony Barboure804d202016-01-05 13:37:45 -07005459 "#version 400\n"
Chris Forbesa36d69e2015-05-25 11:13:44 +12005460 "#extension GL_ARB_separate_shader_objects: require\n"
5461 "#extension GL_ARB_shading_language_420pack: require\n"
5462 "\n"
5463 "layout(location=0) out ivec4 x;\n" /* not UNORM */
5464 "void main(){\n"
5465 " x = ivec4(1);\n"
5466 "}\n";
5467
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06005468 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
5469 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesa36d69e2015-05-25 11:13:44 +12005470
5471 VkPipelineObj pipe(m_device);
5472 pipe.AddShader(&vs);
5473 pipe.AddShader(&fs);
5474
Chia-I Wu08accc62015-07-07 11:50:03 +08005475 /* set up CB 0; type is UNORM by default */
5476 pipe.AddColorAttachment();
5477 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesa36d69e2015-05-25 11:13:44 +12005478
Chris Forbesa36d69e2015-05-25 11:13:44 +12005479 VkDescriptorSetObj descriptorSet(m_device);
5480 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005481 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesa36d69e2015-05-25 11:13:44 +12005482
Tony Barbour5781e8f2015-08-04 16:23:11 -06005483 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesa36d69e2015-05-25 11:13:44 +12005484
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06005485 if (!m_errorMonitor->DesiredMsgFound()) {
5486 FAIL() << "Did not receive Error 'does not match FS output type'";
5487 m_errorMonitor->DumpFailureMsgs();
Chris Forbesa36d69e2015-05-25 11:13:44 +12005488 }
5489}
Chris Forbes7b1b8932015-06-05 14:43:36 +12005490
Chris Forbes556c76c2015-08-14 12:04:59 +12005491TEST_F(VkLayerTest, CreatePipelineUniformBlockNotProvided)
5492{
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07005493 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06005494 "not declared in pipeline layout");
5495
Chris Forbes556c76c2015-08-14 12:04:59 +12005496 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbes556c76c2015-08-14 12:04:59 +12005497
5498 char const *vsSource =
Tony Barboure804d202016-01-05 13:37:45 -07005499 "#version 400\n"
Chris Forbes556c76c2015-08-14 12:04:59 +12005500 "#extension GL_ARB_separate_shader_objects: require\n"
5501 "#extension GL_ARB_shading_language_420pack: require\n"
5502 "\n"
Tony Barboure804d202016-01-05 13:37:45 -07005503 "out gl_PerVertex {\n"
5504 " vec4 gl_Position;\n"
5505 "};\n"
Chris Forbes556c76c2015-08-14 12:04:59 +12005506 "void main(){\n"
5507 " gl_Position = vec4(1);\n"
5508 "}\n";
5509 char const *fsSource =
Tony Barboure804d202016-01-05 13:37:45 -07005510 "#version 400\n"
Chris Forbes556c76c2015-08-14 12:04:59 +12005511 "#extension GL_ARB_separate_shader_objects: require\n"
5512 "#extension GL_ARB_shading_language_420pack: require\n"
5513 "\n"
5514 "layout(location=0) out vec4 x;\n"
5515 "layout(set=0) layout(binding=0) uniform foo { int x; int y; } bar;\n"
5516 "void main(){\n"
5517 " x = vec4(bar.y);\n"
5518 "}\n";
5519
Chris Forbes556c76c2015-08-14 12:04:59 +12005520
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06005521 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
5522 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes556c76c2015-08-14 12:04:59 +12005523
Chris Forbes556c76c2015-08-14 12:04:59 +12005524 VkPipelineObj pipe(m_device);
5525 pipe.AddShader(&vs);
5526 pipe.AddShader(&fs);
5527
5528 /* set up CB 0; type is UNORM by default */
5529 pipe.AddColorAttachment();
5530 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
5531
5532 VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005533 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes556c76c2015-08-14 12:04:59 +12005534
5535 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
5536
5537 /* should have generated an error -- pipeline layout does not
5538 * provide a uniform buffer in 0.0
5539 */
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06005540 if (!m_errorMonitor->DesiredMsgFound()) {
5541 FAIL() << "Did not receive Error 'not declared in pipeline layout'";
5542 m_errorMonitor->DumpFailureMsgs();
Chris Forbes556c76c2015-08-14 12:04:59 +12005543 }
5544}
5545
Mark Lobodzinski209b5292015-09-17 09:44:05 -06005546#endif // SHADER_CHECKER_TESTS
5547
5548#if DEVICE_LIMITS_TESTS
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -06005549TEST_F(VkLayerTest, CreateImageLimitsViolationWidth)
5550{
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07005551 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06005552 "CreateImage extents exceed allowable limits for format");
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -06005553
5554 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -06005555
5556 // Create an image
5557 VkImage image;
5558
5559 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
5560 const int32_t tex_width = 32;
5561 const int32_t tex_height = 32;
5562
5563 VkImageCreateInfo image_create_info = {};
5564 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
5565 image_create_info.pNext = NULL;
5566 image_create_info.imageType = VK_IMAGE_TYPE_2D;
5567 image_create_info.format = tex_format;
5568 image_create_info.extent.width = tex_width;
5569 image_create_info.extent.height = tex_height;
5570 image_create_info.extent.depth = 1;
5571 image_create_info.mipLevels = 1;
Courtney Goeltzenleuchter5d2aed42015-10-21 17:57:31 -06005572 image_create_info.arrayLayers = 1;
Chia-I Wu5c17c962015-10-31 00:31:16 +08005573 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -06005574 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
5575 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
5576 image_create_info.flags = 0;
5577
5578 // Introduce error by sending down a bogus width extent
5579 image_create_info.extent.width = 65536;
Chia-I Wuf7458c52015-10-26 21:10:41 +08005580 vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -06005581
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06005582 if (!m_errorMonitor->DesiredMsgFound()) {
5583 FAIL() << "Did not receive Error 'CreateImage extents exceed allowable limits for format'";
5584 m_errorMonitor->DumpFailureMsgs();
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -06005585 }
5586}
5587
Mike Stroyana3082432015-09-25 13:39:21 -06005588TEST_F(VkLayerTest, UpdateBufferAlignment)
5589{
Mike Stroyana3082432015-09-25 13:39:21 -06005590 uint32_t updateData[] = { 1, 2, 3, 4, 5, 6, 7, 8 };
5591
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07005592 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06005593 "dstOffset, is not a multiple of 4");
5594
Mike Stroyana3082432015-09-25 13:39:21 -06005595 ASSERT_NO_FATAL_FAILURE(InitState());
5596
5597 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
5598 vk_testing::Buffer buffer;
5599 buffer.init_as_dst(*m_device, (VkDeviceSize)20, reqs);
5600
5601 BeginCommandBuffer();
5602 // Introduce failure by using offset that is not multiple of 4
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005603 m_commandBuffer->UpdateBuffer(buffer.handle(), 1, 4, updateData);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06005604 if (!m_errorMonitor->DesiredMsgFound()) {
5605 FAIL() << "Did not receive Error 'vkCommandUpdateBuffer parameter, VkDeviceSize dstOffset, is not a multiple of 4'";
5606 m_errorMonitor->DumpFailureMsgs();
Mike Stroyana3082432015-09-25 13:39:21 -06005607 }
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06005608
Mike Stroyana3082432015-09-25 13:39:21 -06005609 // Introduce failure by using size that is not multiple of 4
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07005610 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06005611 "dataSize, is not a multiple of 4");
5612
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005613 m_commandBuffer->UpdateBuffer(buffer.handle(), 0, 6, updateData);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06005614
5615 if (!m_errorMonitor->DesiredMsgFound()) {
5616 FAIL() << "Did not receive Error 'vkCommandUpdateBuffer parameter, VkDeviceSize dataSize, is not a multiple of 4'";
5617 m_errorMonitor->DumpFailureMsgs();
Mike Stroyana3082432015-09-25 13:39:21 -06005618 }
5619 EndCommandBuffer();
5620}
5621
5622TEST_F(VkLayerTest, FillBufferAlignment)
5623{
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07005624 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06005625 "dstOffset, is not a multiple of 4");
Mike Stroyana3082432015-09-25 13:39:21 -06005626
5627 ASSERT_NO_FATAL_FAILURE(InitState());
5628
5629 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
5630 vk_testing::Buffer buffer;
5631 buffer.init_as_dst(*m_device, (VkDeviceSize)20, reqs);
5632
5633 BeginCommandBuffer();
5634 // Introduce failure by using offset that is not multiple of 4
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005635 m_commandBuffer->FillBuffer(buffer.handle(), 1, 4, 0x11111111);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06005636 if (!m_errorMonitor->DesiredMsgFound()) {
5637 FAIL() << "Did not receive Error 'vkCommandFillBuffer parameter, VkDeviceSize dstOffset, is not a multiple of 4'";
5638 m_errorMonitor->DumpFailureMsgs();
Mike Stroyana3082432015-09-25 13:39:21 -06005639 }
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06005640
Mike Stroyana3082432015-09-25 13:39:21 -06005641 // Introduce failure by using size that is not multiple of 4
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07005642 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06005643 "size, is not a multiple of 4");
5644
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005645 m_commandBuffer->FillBuffer(buffer.handle(), 0, 6, 0x11111111);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06005646
5647 if (!m_errorMonitor->DesiredMsgFound()) {
5648 FAIL() << "Did not receive Error 'vkCommandFillBuffer parameter, VkDeviceSize size, is not a multiple of 4'";
5649 m_errorMonitor->DumpFailureMsgs();
Mike Stroyana3082432015-09-25 13:39:21 -06005650 }
5651 EndCommandBuffer();
5652}
5653
Mark Lobodzinski209b5292015-09-17 09:44:05 -06005654#endif // DEVICE_LIMITS_TESTS
Chris Forbesa36d69e2015-05-25 11:13:44 +12005655
Tobin Ehliscde08892015-09-22 10:11:37 -06005656#if IMAGE_TESTS
5657TEST_F(VkLayerTest, InvalidImageView)
5658{
Tobin Ehliscde08892015-09-22 10:11:37 -06005659 VkResult err;
5660
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07005661 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06005662 "vkCreateImageView called with baseMipLevel 10 ");
5663
Tobin Ehliscde08892015-09-22 10:11:37 -06005664 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehliscde08892015-09-22 10:11:37 -06005665
Mike Stroyana3082432015-09-25 13:39:21 -06005666 // Create an image and try to create a view with bad baseMipLevel
Tobin Ehliscde08892015-09-22 10:11:37 -06005667 VkImage image;
5668
5669 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
5670 const int32_t tex_width = 32;
5671 const int32_t tex_height = 32;
5672
5673 VkImageCreateInfo image_create_info = {};
5674 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
5675 image_create_info.pNext = NULL;
5676 image_create_info.imageType = VK_IMAGE_TYPE_2D;
5677 image_create_info.format = tex_format;
5678 image_create_info.extent.width = tex_width;
5679 image_create_info.extent.height = tex_height;
5680 image_create_info.extent.depth = 1;
5681 image_create_info.mipLevels = 1;
Courtney Goeltzenleuchter5d2aed42015-10-21 17:57:31 -06005682 image_create_info.arrayLayers = 1;
Chia-I Wu5c17c962015-10-31 00:31:16 +08005683 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Tobin Ehliscde08892015-09-22 10:11:37 -06005684 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
5685 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
5686 image_create_info.flags = 0;
5687
Chia-I Wuf7458c52015-10-26 21:10:41 +08005688 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Tobin Ehliscde08892015-09-22 10:11:37 -06005689 ASSERT_VK_SUCCESS(err);
5690
5691 VkImageViewCreateInfo image_view_create_info = {};
5692 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
5693 image_view_create_info.image = image;
5694 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
5695 image_view_create_info.format = tex_format;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005696 image_view_create_info.subresourceRange.layerCount = 1;
Tobin Ehliscde08892015-09-22 10:11:37 -06005697 image_view_create_info.subresourceRange.baseMipLevel = 10; // cause an error
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005698 image_view_create_info.subresourceRange.levelCount = 1;
Mark Lobodzinskidc86b852015-10-23 14:20:31 -06005699 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Tobin Ehliscde08892015-09-22 10:11:37 -06005700
5701 VkImageView view;
Chia-I Wuf7458c52015-10-26 21:10:41 +08005702 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
Tobin Ehliscde08892015-09-22 10:11:37 -06005703
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06005704 if (!m_errorMonitor->DesiredMsgFound()) {
5705 FAIL() << "Did not receive Error 'vkCreateImageView called with baseMipLevel 10...'";
5706 m_errorMonitor->DumpFailureMsgs();
Tobin Ehliscde08892015-09-22 10:11:37 -06005707 }
5708}
Mike Stroyana3082432015-09-25 13:39:21 -06005709
Mark Lobodzinskidc86b852015-10-23 14:20:31 -06005710TEST_F(VkLayerTest, InvalidImageViewAspect)
5711{
Mark Lobodzinskidc86b852015-10-23 14:20:31 -06005712 VkResult err;
5713
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07005714 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06005715 "vkCreateImageView: Color image formats must have ONLY the VK_IMAGE_ASPECT_COLOR_BIT set");
5716
Mark Lobodzinskidc86b852015-10-23 14:20:31 -06005717 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskidc86b852015-10-23 14:20:31 -06005718
5719 // Create an image and try to create a view with an invalid aspectMask
5720 VkImage image;
5721
5722 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
5723 const int32_t tex_width = 32;
5724 const int32_t tex_height = 32;
5725
5726 VkImageCreateInfo image_create_info = {};
5727 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
5728 image_create_info.pNext = NULL;
5729 image_create_info.imageType = VK_IMAGE_TYPE_2D;
5730 image_create_info.format = tex_format;
5731 image_create_info.extent.width = tex_width;
5732 image_create_info.extent.height = tex_height;
5733 image_create_info.extent.depth = 1;
5734 image_create_info.mipLevels = 1;
Chia-I Wu5c17c962015-10-31 00:31:16 +08005735 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Mark Lobodzinskidc86b852015-10-23 14:20:31 -06005736 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
5737 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
5738 image_create_info.flags = 0;
5739
Chia-I Wuf7458c52015-10-26 21:10:41 +08005740 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Mark Lobodzinskidc86b852015-10-23 14:20:31 -06005741 ASSERT_VK_SUCCESS(err);
5742
5743 VkImageViewCreateInfo image_view_create_info = {};
5744 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
5745 image_view_create_info.image = image;
5746 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
5747 image_view_create_info.format = tex_format;
5748 image_view_create_info.subresourceRange.baseMipLevel = 0;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005749 image_view_create_info.subresourceRange.levelCount = 1;
Mark Lobodzinskidc86b852015-10-23 14:20:31 -06005750 // Cause an error by setting an invalid image aspect
5751 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_METADATA_BIT;
5752
5753 VkImageView view;
Chia-I Wuf7458c52015-10-26 21:10:41 +08005754 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
Mark Lobodzinskidc86b852015-10-23 14:20:31 -06005755
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06005756 if (!m_errorMonitor->DesiredMsgFound()) {
5757 FAIL() << "Did not receive Error 'VkCreateImageView: Color image formats must have ...'";
5758 m_errorMonitor->DumpFailureMsgs();
Mark Lobodzinskidc86b852015-10-23 14:20:31 -06005759 }
5760}
5761
Mike Stroyana3082432015-09-25 13:39:21 -06005762TEST_F(VkLayerTest, CopyImageTypeMismatch)
5763{
Mike Stroyana3082432015-09-25 13:39:21 -06005764 VkResult err;
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -06005765 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -06005766
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07005767 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06005768 "vkCmdCopyImage called with unmatched source and dest image types");
5769
Mike Stroyana3082432015-09-25 13:39:21 -06005770 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -06005771
5772 // Create two images of different types and try to copy between them
5773 VkImage srcImage;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005774 VkImage dstImage;
Mike Stroyana3082432015-09-25 13:39:21 -06005775 VkDeviceMemory srcMem;
5776 VkDeviceMemory destMem;
5777 VkMemoryRequirements memReqs;
5778
5779 VkImageCreateInfo image_create_info = {};
5780 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
5781 image_create_info.pNext = NULL;
5782 image_create_info.imageType = VK_IMAGE_TYPE_2D;
5783 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
5784 image_create_info.extent.width = 32;
5785 image_create_info.extent.height = 32;
5786 image_create_info.extent.depth = 1;
5787 image_create_info.mipLevels = 1;
Courtney Goeltzenleuchter5d2aed42015-10-21 17:57:31 -06005788 image_create_info.arrayLayers = 1;
Chia-I Wu5c17c962015-10-31 00:31:16 +08005789 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Mike Stroyan91204c32016-01-05 11:44:50 -07005790 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005791 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -06005792 image_create_info.flags = 0;
5793
Chia-I Wuf7458c52015-10-26 21:10:41 +08005794 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -06005795 ASSERT_VK_SUCCESS(err);
5796
5797 image_create_info.imageType = VK_IMAGE_TYPE_1D;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005798 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -06005799
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005800 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -06005801 ASSERT_VK_SUCCESS(err);
5802
5803 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005804 VkMemoryAllocateInfo memAlloc = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08005805 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
Mike Stroyana3082432015-09-25 13:39:21 -06005806 memAlloc.pNext = NULL;
5807 memAlloc.allocationSize = 0;
5808 memAlloc.memoryTypeIndex = 0;
5809
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -06005810 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -06005811 memAlloc.allocationSize = memReqs.size;
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -06005812 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
5813 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005814 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -06005815 ASSERT_VK_SUCCESS(err);
5816
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005817 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -06005818 memAlloc.allocationSize = memReqs.size;
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -06005819 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Mike Stroyana3082432015-09-25 13:39:21 -06005820 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005821 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -06005822 ASSERT_VK_SUCCESS(err);
5823
5824 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
5825 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005826 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -06005827 ASSERT_VK_SUCCESS(err);
5828
5829 BeginCommandBuffer();
5830 VkImageCopy copyRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +08005831 copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -06005832 copyRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -06005833 copyRegion.srcSubresource.baseArrayLayer = 0;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005834 copyRegion.srcSubresource.layerCount = 0;
Mike Stroyana3082432015-09-25 13:39:21 -06005835 copyRegion.srcOffset.x = 0;
5836 copyRegion.srcOffset.y = 0;
5837 copyRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +08005838 copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005839 copyRegion.dstSubresource.mipLevel = 0;
5840 copyRegion.dstSubresource.baseArrayLayer = 0;
5841 copyRegion.dstSubresource.layerCount = 0;
5842 copyRegion.dstOffset.x = 0;
5843 copyRegion.dstOffset.y = 0;
5844 copyRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -06005845 copyRegion.extent.width = 1;
5846 copyRegion.extent.height = 1;
5847 copyRegion.extent.depth = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005848 m_commandBuffer->CopyImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
Mike Stroyana3082432015-09-25 13:39:21 -06005849 EndCommandBuffer();
5850
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06005851 if (!m_errorMonitor->DesiredMsgFound()) {
5852 FAIL() << "Did not receive Error 'vkCmdCopyImage called with unmatched source and dest image types'";
5853 m_errorMonitor->DumpFailureMsgs();
Mike Stroyana3082432015-09-25 13:39:21 -06005854 }
5855
Chia-I Wuf7458c52015-10-26 21:10:41 +08005856 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005857 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +08005858 vkFreeMemory(m_device->device(), srcMem, NULL);
5859 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -06005860}
5861
5862TEST_F(VkLayerTest, CopyImageFormatSizeMismatch)
5863{
5864 // TODO : Create two images with different format sizes and vkCmdCopyImage between them
5865}
5866
5867TEST_F(VkLayerTest, CopyImageDepthStencilFormatMismatch)
5868{
Mike Stroyana3082432015-09-25 13:39:21 -06005869 VkResult err;
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -06005870 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -06005871
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07005872 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06005873 "vkCmdCopyImage called with unmatched source and dest image types");
5874
Mike Stroyana3082432015-09-25 13:39:21 -06005875 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -06005876
5877 // Create two images of different types and try to copy between them
5878 VkImage srcImage;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005879 VkImage dstImage;
Mike Stroyana3082432015-09-25 13:39:21 -06005880 VkDeviceMemory srcMem;
5881 VkDeviceMemory destMem;
5882 VkMemoryRequirements memReqs;
5883
5884 VkImageCreateInfo image_create_info = {};
5885 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
5886 image_create_info.pNext = NULL;
5887 image_create_info.imageType = VK_IMAGE_TYPE_2D;
5888 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
5889 image_create_info.extent.width = 32;
5890 image_create_info.extent.height = 32;
5891 image_create_info.extent.depth = 1;
5892 image_create_info.mipLevels = 1;
Courtney Goeltzenleuchter5d2aed42015-10-21 17:57:31 -06005893 image_create_info.arrayLayers = 1;
Chia-I Wu5c17c962015-10-31 00:31:16 +08005894 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -06005895 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005896 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -06005897 image_create_info.flags = 0;
5898
Chia-I Wuf7458c52015-10-26 21:10:41 +08005899 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -06005900 ASSERT_VK_SUCCESS(err);
5901
5902 image_create_info.imageType = VK_IMAGE_TYPE_1D;
Tony Barbour5cc47df2016-01-13 12:45:24 -07005903 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005904 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -06005905
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005906 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -06005907 ASSERT_VK_SUCCESS(err);
5908
5909 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005910 VkMemoryAllocateInfo memAlloc = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08005911 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
Mike Stroyana3082432015-09-25 13:39:21 -06005912 memAlloc.pNext = NULL;
5913 memAlloc.allocationSize = 0;
5914 memAlloc.memoryTypeIndex = 0;
5915
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -06005916 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -06005917 memAlloc.allocationSize = memReqs.size;
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -06005918 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
5919 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005920 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -06005921 ASSERT_VK_SUCCESS(err);
5922
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005923 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -06005924 memAlloc.allocationSize = memReqs.size;
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -06005925 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
5926 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005927 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -06005928 ASSERT_VK_SUCCESS(err);
5929
5930 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
5931 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005932 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -06005933 ASSERT_VK_SUCCESS(err);
5934
5935 BeginCommandBuffer();
5936 VkImageCopy copyRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +08005937 copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -06005938 copyRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -06005939 copyRegion.srcSubresource.baseArrayLayer = 0;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005940 copyRegion.srcSubresource.layerCount = 0;
Mike Stroyana3082432015-09-25 13:39:21 -06005941 copyRegion.srcOffset.x = 0;
5942 copyRegion.srcOffset.y = 0;
5943 copyRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +08005944 copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005945 copyRegion.dstSubresource.mipLevel = 0;
5946 copyRegion.dstSubresource.baseArrayLayer = 0;
5947 copyRegion.dstSubresource.layerCount = 0;
5948 copyRegion.dstOffset.x = 0;
5949 copyRegion.dstOffset.y = 0;
5950 copyRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -06005951 copyRegion.extent.width = 1;
5952 copyRegion.extent.height = 1;
5953 copyRegion.extent.depth = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005954 m_commandBuffer->CopyImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
Mike Stroyana3082432015-09-25 13:39:21 -06005955 EndCommandBuffer();
5956
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06005957 if (!m_errorMonitor->DesiredMsgFound()) {
5958 FAIL() << "Did not receive Error 'vkCmdCopyImage called with unmatched source and dest image types'";
5959 m_errorMonitor->DumpFailureMsgs();
Mike Stroyana3082432015-09-25 13:39:21 -06005960 }
5961
Chia-I Wuf7458c52015-10-26 21:10:41 +08005962 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005963 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +08005964 vkFreeMemory(m_device->device(), srcMem, NULL);
5965 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -06005966}
5967
5968TEST_F(VkLayerTest, ResolveImageLowSampleCount)
5969{
Mike Stroyana3082432015-09-25 13:39:21 -06005970 VkResult err;
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -06005971 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -06005972
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07005973 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06005974 "vkCmdResolveImage called with source sample count less than 2.");
5975
Mike Stroyana3082432015-09-25 13:39:21 -06005976 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -06005977
5978 // Create two images of sample count 1 and try to Resolve between them
5979 VkImage srcImage;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005980 VkImage dstImage;
Mike Stroyana3082432015-09-25 13:39:21 -06005981 VkDeviceMemory srcMem;
5982 VkDeviceMemory destMem;
5983 VkMemoryRequirements memReqs;
5984
5985 VkImageCreateInfo image_create_info = {};
5986 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
5987 image_create_info.pNext = NULL;
5988 image_create_info.imageType = VK_IMAGE_TYPE_2D;
5989 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
5990 image_create_info.extent.width = 32;
5991 image_create_info.extent.height = 1;
5992 image_create_info.extent.depth = 1;
5993 image_create_info.mipLevels = 1;
Courtney Goeltzenleuchter5d2aed42015-10-21 17:57:31 -06005994 image_create_info.arrayLayers = 1;
Chia-I Wu5c17c962015-10-31 00:31:16 +08005995 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Mike Stroyan91204c32016-01-05 11:44:50 -07005996 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005997 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -06005998 image_create_info.flags = 0;
5999
Chia-I Wuf7458c52015-10-26 21:10:41 +08006000 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -06006001 ASSERT_VK_SUCCESS(err);
6002
6003 image_create_info.imageType = VK_IMAGE_TYPE_1D;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006004 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -06006005
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006006 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -06006007 ASSERT_VK_SUCCESS(err);
6008
6009 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006010 VkMemoryAllocateInfo memAlloc = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08006011 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
Mike Stroyana3082432015-09-25 13:39:21 -06006012 memAlloc.pNext = NULL;
6013 memAlloc.allocationSize = 0;
6014 memAlloc.memoryTypeIndex = 0;
6015
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -06006016 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -06006017 memAlloc.allocationSize = memReqs.size;
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -06006018 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
6019 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006020 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -06006021 ASSERT_VK_SUCCESS(err);
6022
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006023 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -06006024 memAlloc.allocationSize = memReqs.size;
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -06006025 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
6026 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006027 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -06006028 ASSERT_VK_SUCCESS(err);
6029
6030 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
6031 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006032 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -06006033 ASSERT_VK_SUCCESS(err);
6034
6035 BeginCommandBuffer();
6036 // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest?
6037 //VK_IMAGE_LAYOUT_UNDEFINED = 0,
6038 //VK_IMAGE_LAYOUT_GENERAL = 1,
6039 VkImageResolve resolveRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +08006040 resolveRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -06006041 resolveRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -06006042 resolveRegion.srcSubresource.baseArrayLayer = 0;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006043 resolveRegion.srcSubresource.layerCount = 0;
Mike Stroyana3082432015-09-25 13:39:21 -06006044 resolveRegion.srcOffset.x = 0;
6045 resolveRegion.srcOffset.y = 0;
6046 resolveRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +08006047 resolveRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006048 resolveRegion.dstSubresource.mipLevel = 0;
6049 resolveRegion.dstSubresource.baseArrayLayer = 0;
6050 resolveRegion.dstSubresource.layerCount = 0;
6051 resolveRegion.dstOffset.x = 0;
6052 resolveRegion.dstOffset.y = 0;
6053 resolveRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -06006054 resolveRegion.extent.width = 1;
6055 resolveRegion.extent.height = 1;
6056 resolveRegion.extent.depth = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006057 m_commandBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion);
Mike Stroyana3082432015-09-25 13:39:21 -06006058 EndCommandBuffer();
6059
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06006060 if (!m_errorMonitor->DesiredMsgFound()) {
6061 FAIL() << "Did not receive Error 'vkCmdResolveImage called with source sample count less than 2.'";
6062 m_errorMonitor->DumpFailureMsgs();
Mike Stroyana3082432015-09-25 13:39:21 -06006063 }
6064
Chia-I Wuf7458c52015-10-26 21:10:41 +08006065 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006066 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +08006067 vkFreeMemory(m_device->device(), srcMem, NULL);
6068 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -06006069}
6070
6071TEST_F(VkLayerTest, ResolveImageHighSampleCount)
6072{
Mike Stroyana3082432015-09-25 13:39:21 -06006073 VkResult err;
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -06006074 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -06006075
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07006076 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06006077 "vkCmdResolveImage called with dest sample count greater than 1.");
6078
Mike Stroyana3082432015-09-25 13:39:21 -06006079 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -06006080
6081 // Create two images of sample count 2 and try to Resolve between them
6082 VkImage srcImage;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006083 VkImage dstImage;
Mike Stroyana3082432015-09-25 13:39:21 -06006084 VkDeviceMemory srcMem;
6085 VkDeviceMemory destMem;
6086 VkMemoryRequirements memReqs;
6087
6088 VkImageCreateInfo image_create_info = {};
6089 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
6090 image_create_info.pNext = NULL;
6091 image_create_info.imageType = VK_IMAGE_TYPE_2D;
6092 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
6093 image_create_info.extent.width = 32;
6094 image_create_info.extent.height = 1;
6095 image_create_info.extent.depth = 1;
6096 image_create_info.mipLevels = 1;
Courtney Goeltzenleuchter5d2aed42015-10-21 17:57:31 -06006097 image_create_info.arrayLayers = 1;
Chia-I Wu5c17c962015-10-31 00:31:16 +08006098 image_create_info.samples = VK_SAMPLE_COUNT_2_BIT;
Mike Stroyan91204c32016-01-05 11:44:50 -07006099 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
Cody Northrop72458c02015-10-27 13:50:04 -06006100 // Note: Some implementations expect color attachment usage for any multisample surface
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006101 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -06006102 image_create_info.flags = 0;
6103
Chia-I Wuf7458c52015-10-26 21:10:41 +08006104 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -06006105 ASSERT_VK_SUCCESS(err);
6106
6107 image_create_info.imageType = VK_IMAGE_TYPE_1D;
Cody Northrop72458c02015-10-27 13:50:04 -06006108 // Note: Some implementations expect color attachment usage for any multisample surface
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006109 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -06006110
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006111 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -06006112 ASSERT_VK_SUCCESS(err);
6113
6114 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006115 VkMemoryAllocateInfo memAlloc = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08006116 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
Mike Stroyana3082432015-09-25 13:39:21 -06006117 memAlloc.pNext = NULL;
6118 memAlloc.allocationSize = 0;
6119 memAlloc.memoryTypeIndex = 0;
6120
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -06006121 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -06006122 memAlloc.allocationSize = memReqs.size;
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -06006123 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
6124 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006125 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -06006126 ASSERT_VK_SUCCESS(err);
6127
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006128 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -06006129 memAlloc.allocationSize = memReqs.size;
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -06006130 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
6131 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006132 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -06006133 ASSERT_VK_SUCCESS(err);
6134
6135 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
6136 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006137 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -06006138 ASSERT_VK_SUCCESS(err);
6139
6140 BeginCommandBuffer();
6141 // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest?
6142 //VK_IMAGE_LAYOUT_UNDEFINED = 0,
6143 //VK_IMAGE_LAYOUT_GENERAL = 1,
6144 VkImageResolve resolveRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +08006145 resolveRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -06006146 resolveRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -06006147 resolveRegion.srcSubresource.baseArrayLayer = 0;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006148 resolveRegion.srcSubresource.layerCount = 0;
Mike Stroyana3082432015-09-25 13:39:21 -06006149 resolveRegion.srcOffset.x = 0;
6150 resolveRegion.srcOffset.y = 0;
6151 resolveRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +08006152 resolveRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006153 resolveRegion.dstSubresource.mipLevel = 0;
6154 resolveRegion.dstSubresource.baseArrayLayer = 0;
6155 resolveRegion.dstSubresource.layerCount = 0;
6156 resolveRegion.dstOffset.x = 0;
6157 resolveRegion.dstOffset.y = 0;
6158 resolveRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -06006159 resolveRegion.extent.width = 1;
6160 resolveRegion.extent.height = 1;
6161 resolveRegion.extent.depth = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006162 m_commandBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion);
Mike Stroyana3082432015-09-25 13:39:21 -06006163 EndCommandBuffer();
6164
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06006165 if (!m_errorMonitor->DesiredMsgFound()) {
6166 FAIL() << "Did not receive Error 'vkCmdResolveImage called with dest sample count greater than 1.'";
6167 m_errorMonitor->DumpFailureMsgs();
Mike Stroyana3082432015-09-25 13:39:21 -06006168 }
6169
Chia-I Wuf7458c52015-10-26 21:10:41 +08006170 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006171 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +08006172 vkFreeMemory(m_device->device(), srcMem, NULL);
6173 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -06006174}
6175
6176TEST_F(VkLayerTest, ResolveImageFormatMismatch)
6177{
Mike Stroyana3082432015-09-25 13:39:21 -06006178 VkResult err;
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -06006179 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -06006180
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07006181 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06006182 "vkCmdResolveImage called with unmatched source and dest formats.");
6183
Mike Stroyana3082432015-09-25 13:39:21 -06006184 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -06006185
6186 // Create two images of different types and try to copy between them
6187 VkImage srcImage;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006188 VkImage dstImage;
Mike Stroyana3082432015-09-25 13:39:21 -06006189 VkDeviceMemory srcMem;
6190 VkDeviceMemory destMem;
6191 VkMemoryRequirements memReqs;
6192
6193 VkImageCreateInfo image_create_info = {};
6194 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
6195 image_create_info.pNext = NULL;
6196 image_create_info.imageType = VK_IMAGE_TYPE_2D;
6197 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
6198 image_create_info.extent.width = 32;
6199 image_create_info.extent.height = 1;
6200 image_create_info.extent.depth = 1;
6201 image_create_info.mipLevels = 1;
Courtney Goeltzenleuchter5d2aed42015-10-21 17:57:31 -06006202 image_create_info.arrayLayers = 1;
Chia-I Wu5c17c962015-10-31 00:31:16 +08006203 image_create_info.samples = VK_SAMPLE_COUNT_2_BIT;
Mike Stroyan91204c32016-01-05 11:44:50 -07006204 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
Cody Northrop72458c02015-10-27 13:50:04 -06006205 // Note: Some implementations expect color attachment usage for any multisample surface
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006206 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -06006207 image_create_info.flags = 0;
6208
Chia-I Wuf7458c52015-10-26 21:10:41 +08006209 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -06006210 ASSERT_VK_SUCCESS(err);
6211
Cody Northrop72458c02015-10-27 13:50:04 -06006212 // Set format to something other than source image
6213 image_create_info.format = VK_FORMAT_R32_SFLOAT;
6214 // Note: Some implementations expect color attachment usage for any multisample surface
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006215 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Chia-I Wu5c17c962015-10-31 00:31:16 +08006216 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -06006217
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006218 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -06006219 ASSERT_VK_SUCCESS(err);
6220
6221 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006222 VkMemoryAllocateInfo memAlloc = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08006223 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
Mike Stroyana3082432015-09-25 13:39:21 -06006224 memAlloc.pNext = NULL;
6225 memAlloc.allocationSize = 0;
6226 memAlloc.memoryTypeIndex = 0;
6227
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -06006228 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -06006229 memAlloc.allocationSize = memReqs.size;
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -06006230 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
6231 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006232 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -06006233 ASSERT_VK_SUCCESS(err);
6234
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006235 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -06006236 memAlloc.allocationSize = memReqs.size;
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -06006237 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
6238 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006239 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -06006240 ASSERT_VK_SUCCESS(err);
6241
6242 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
6243 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006244 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -06006245 ASSERT_VK_SUCCESS(err);
6246
6247 BeginCommandBuffer();
6248 // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest?
6249 //VK_IMAGE_LAYOUT_UNDEFINED = 0,
6250 //VK_IMAGE_LAYOUT_GENERAL = 1,
6251 VkImageResolve resolveRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +08006252 resolveRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -06006253 resolveRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -06006254 resolveRegion.srcSubresource.baseArrayLayer = 0;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006255 resolveRegion.srcSubresource.layerCount = 0;
Mike Stroyana3082432015-09-25 13:39:21 -06006256 resolveRegion.srcOffset.x = 0;
6257 resolveRegion.srcOffset.y = 0;
6258 resolveRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +08006259 resolveRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006260 resolveRegion.dstSubresource.mipLevel = 0;
6261 resolveRegion.dstSubresource.baseArrayLayer = 0;
6262 resolveRegion.dstSubresource.layerCount = 0;
6263 resolveRegion.dstOffset.x = 0;
6264 resolveRegion.dstOffset.y = 0;
6265 resolveRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -06006266 resolveRegion.extent.width = 1;
6267 resolveRegion.extent.height = 1;
6268 resolveRegion.extent.depth = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006269 m_commandBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion);
Mike Stroyana3082432015-09-25 13:39:21 -06006270 EndCommandBuffer();
6271
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06006272 if (!m_errorMonitor->DesiredMsgFound()) {
6273 FAIL() << "Did not receive Error 'vkCmdResolveImage called with unmatched source and dest formats.'";
6274 m_errorMonitor->DumpFailureMsgs();
Mike Stroyana3082432015-09-25 13:39:21 -06006275 }
6276
Chia-I Wuf7458c52015-10-26 21:10:41 +08006277 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006278 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +08006279 vkFreeMemory(m_device->device(), srcMem, NULL);
6280 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -06006281}
6282
6283TEST_F(VkLayerTest, ResolveImageTypeMismatch)
6284{
Mike Stroyana3082432015-09-25 13:39:21 -06006285 VkResult err;
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -06006286 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -06006287
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07006288 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06006289 "vkCmdResolveImage called with unmatched source and dest image types.");
6290
Mike Stroyana3082432015-09-25 13:39:21 -06006291 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -06006292
6293 // Create two images of different types and try to copy between them
6294 VkImage srcImage;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006295 VkImage dstImage;
Mike Stroyana3082432015-09-25 13:39:21 -06006296 VkDeviceMemory srcMem;
6297 VkDeviceMemory destMem;
6298 VkMemoryRequirements memReqs;
6299
6300 VkImageCreateInfo image_create_info = {};
6301 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
6302 image_create_info.pNext = NULL;
6303 image_create_info.imageType = VK_IMAGE_TYPE_2D;
6304 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
6305 image_create_info.extent.width = 32;
6306 image_create_info.extent.height = 1;
6307 image_create_info.extent.depth = 1;
6308 image_create_info.mipLevels = 1;
Courtney Goeltzenleuchter5d2aed42015-10-21 17:57:31 -06006309 image_create_info.arrayLayers = 1;
Chia-I Wu5c17c962015-10-31 00:31:16 +08006310 image_create_info.samples = VK_SAMPLE_COUNT_2_BIT;
Mike Stroyan91204c32016-01-05 11:44:50 -07006311 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
Cody Northrop72458c02015-10-27 13:50:04 -06006312 // Note: Some implementations expect color attachment usage for any multisample surface
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006313 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -06006314 image_create_info.flags = 0;
6315
Chia-I Wuf7458c52015-10-26 21:10:41 +08006316 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -06006317 ASSERT_VK_SUCCESS(err);
6318
6319 image_create_info.imageType = VK_IMAGE_TYPE_1D;
Cody Northrop72458c02015-10-27 13:50:04 -06006320 // Note: Some implementations expect color attachment usage for any multisample surface
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006321 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Chia-I Wu5c17c962015-10-31 00:31:16 +08006322 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -06006323
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006324 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -06006325 ASSERT_VK_SUCCESS(err);
6326
6327 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006328 VkMemoryAllocateInfo memAlloc = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08006329 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
Mike Stroyana3082432015-09-25 13:39:21 -06006330 memAlloc.pNext = NULL;
6331 memAlloc.allocationSize = 0;
6332 memAlloc.memoryTypeIndex = 0;
6333
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -06006334 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -06006335 memAlloc.allocationSize = memReqs.size;
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -06006336 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
6337 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006338 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -06006339 ASSERT_VK_SUCCESS(err);
6340
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006341 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -06006342 memAlloc.allocationSize = memReqs.size;
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -06006343 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
6344 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006345 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -06006346 ASSERT_VK_SUCCESS(err);
6347
6348 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
6349 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006350 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -06006351 ASSERT_VK_SUCCESS(err);
6352
6353 BeginCommandBuffer();
6354 // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest?
6355 //VK_IMAGE_LAYOUT_UNDEFINED = 0,
6356 //VK_IMAGE_LAYOUT_GENERAL = 1,
6357 VkImageResolve resolveRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +08006358 resolveRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -06006359 resolveRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -06006360 resolveRegion.srcSubresource.baseArrayLayer = 0;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006361 resolveRegion.srcSubresource.layerCount = 0;
Mike Stroyana3082432015-09-25 13:39:21 -06006362 resolveRegion.srcOffset.x = 0;
6363 resolveRegion.srcOffset.y = 0;
6364 resolveRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +08006365 resolveRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006366 resolveRegion.dstSubresource.mipLevel = 0;
6367 resolveRegion.dstSubresource.baseArrayLayer = 0;
6368 resolveRegion.dstSubresource.layerCount = 0;
6369 resolveRegion.dstOffset.x = 0;
6370 resolveRegion.dstOffset.y = 0;
6371 resolveRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -06006372 resolveRegion.extent.width = 1;
6373 resolveRegion.extent.height = 1;
6374 resolveRegion.extent.depth = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006375 m_commandBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion);
Mike Stroyana3082432015-09-25 13:39:21 -06006376 EndCommandBuffer();
6377
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06006378 if (!m_errorMonitor->DesiredMsgFound()) {
6379 FAIL() << "Did not receive Error 'vkCmdResolveImage called with unmatched source and dest image types.'";
6380 m_errorMonitor->DumpFailureMsgs();
Mike Stroyana3082432015-09-25 13:39:21 -06006381 }
6382
Chia-I Wuf7458c52015-10-26 21:10:41 +08006383 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006384 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +08006385 vkFreeMemory(m_device->device(), srcMem, NULL);
6386 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -06006387}
Tobin Ehlisa1c28562015-10-23 16:00:08 -06006388
6389TEST_F(VkLayerTest, DepthStencilImageViewWithColorAspectBitError)
6390{
6391 // Create a single Image descriptor and cause it to first hit an error due
6392 // to using a DS format, then cause it to hit error due to COLOR_BIT not set in aspect
6393 // The image format check comes 2nd in validation so we trigger it first,
6394 // then when we cause aspect fail next, bad format check will be preempted
Tobin Ehlisa1c28562015-10-23 16:00:08 -06006395 VkResult err;
6396
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07006397 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06006398 "Combination depth/stencil image formats can have only the ");
6399
Tobin Ehlisa1c28562015-10-23 16:00:08 -06006400 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06006401
Chia-I Wu1b99bb22015-10-27 19:25:11 +08006402 VkDescriptorPoolSize ds_type_count = {};
Tobin Ehlisa1c28562015-10-23 16:00:08 -06006403 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
Chia-I Wud50a7d72015-10-26 20:48:51 +08006404 ds_type_count.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06006405
6406 VkDescriptorPoolCreateInfo ds_pool_ci = {};
6407 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
6408 ds_pool_ci.pNext = NULL;
6409 ds_pool_ci.maxSets = 1;
Chia-I Wu1b99bb22015-10-27 19:25:11 +08006410 ds_pool_ci.poolSizeCount = 1;
6411 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06006412
6413 VkDescriptorPool ds_pool;
Chia-I Wuf7458c52015-10-26 21:10:41 +08006414 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06006415 ASSERT_VK_SUCCESS(err);
6416
6417 VkDescriptorSetLayoutBinding dsl_binding = {};
Chia-I Wud46e6ae2015-10-31 00:31:16 +08006418 dsl_binding.binding = 0;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06006419 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
Chia-I Wu02124482015-11-06 06:42:02 +08006420 dsl_binding.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06006421 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
6422 dsl_binding.pImmutableSamplers = NULL;
6423
6424 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
6425 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
6426 ds_layout_ci.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08006427 ds_layout_ci.bindingCount = 1;
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07006428 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06006429 VkDescriptorSetLayout ds_layout;
Chia-I Wuf7458c52015-10-26 21:10:41 +08006430 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06006431 ASSERT_VK_SUCCESS(err);
6432
6433 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006434 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08006435 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07006436 alloc_info.descriptorSetCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06006437 alloc_info.descriptorPool = ds_pool;
6438 alloc_info.pSetLayouts = &ds_layout;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006439 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06006440 ASSERT_VK_SUCCESS(err);
6441
6442 VkImage image_bad;
6443 VkImage image_good;
6444 // One bad format and one good format for Color attachment
6445 const VkFormat tex_format_bad = VK_FORMAT_D32_SFLOAT_S8_UINT;
6446 const VkFormat tex_format_good = VK_FORMAT_B8G8R8A8_UNORM;
6447 const int32_t tex_width = 32;
6448 const int32_t tex_height = 32;
6449
6450 VkImageCreateInfo image_create_info = {};
6451 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
6452 image_create_info.pNext = NULL;
6453 image_create_info.imageType = VK_IMAGE_TYPE_2D;
6454 image_create_info.format = tex_format_bad;
6455 image_create_info.extent.width = tex_width;
6456 image_create_info.extent.height = tex_height;
6457 image_create_info.extent.depth = 1;
6458 image_create_info.mipLevels = 1;
6459 image_create_info.arrayLayers = 1;
Chia-I Wu5c17c962015-10-31 00:31:16 +08006460 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06006461 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
6462 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT;
6463 image_create_info.flags = 0;
6464
Chia-I Wuf7458c52015-10-26 21:10:41 +08006465 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image_bad);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06006466 ASSERT_VK_SUCCESS(err);
6467 image_create_info.format = tex_format_good;
6468 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Chia-I Wuf7458c52015-10-26 21:10:41 +08006469 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image_good);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06006470 ASSERT_VK_SUCCESS(err);
6471
6472 VkImageViewCreateInfo image_view_create_info = {};
6473 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
6474 image_view_create_info.image = image_bad;
6475 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
6476 image_view_create_info.format = tex_format_bad;
6477 image_view_create_info.subresourceRange.baseArrayLayer = 0;
6478 image_view_create_info.subresourceRange.baseMipLevel = 0;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006479 image_view_create_info.subresourceRange.layerCount = 1;
6480 image_view_create_info.subresourceRange.levelCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06006481 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
6482
6483 VkImageView view;
Chia-I Wuf7458c52015-10-26 21:10:41 +08006484 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06006485
6486 if (!m_errorMonitor->DesiredMsgFound()) {
6487 FAIL() << "Did not receive Error 'Combination depth-stencil image formats can have only the....'";
6488 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlisa1c28562015-10-23 16:00:08 -06006489 }
6490
Chia-I Wuf7458c52015-10-26 21:10:41 +08006491 vkDestroyImage(m_device->device(), image_bad, NULL);
6492 vkDestroyImage(m_device->device(), image_good, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +08006493 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
6494 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06006495}
Tobin Ehliscde08892015-09-22 10:11:37 -06006496#endif // IMAGE_TESTS
6497
Tony Barbour300a6082015-04-07 13:44:53 -06006498int main(int argc, char **argv) {
6499 int result;
6500
6501 ::testing::InitGoogleTest(&argc, argv);
Tony Barbour6918cd52015-04-09 12:58:51 -06006502 VkTestFramework::InitArgs(&argc, argv);
Tony Barbour300a6082015-04-07 13:44:53 -06006503
6504 ::testing::AddGlobalTestEnvironment(new TestEnvironment);
6505
6506 result = RUN_ALL_TESTS();
6507
Tony Barbour6918cd52015-04-09 12:58:51 -06006508 VkTestFramework::Finish();
Tony Barbour300a6082015-04-07 13:44:53 -06006509 return result;
6510}