blob: 7e0e50f071e59c10528a34fc2ea717f914113c8f [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>
David Pinedoabd07722015-11-24 09:00:24 -070033#include "vulkan/vk_lunarg_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[] =
Mark Lobodzinski3780e142015-05-14 15:08:13 -050083 "#version 130\n"
84 "vec2 vertices[3];\n"
85 "void main() {\n"
86 " vertices[0] = vec2(-1.0, -1.0);\n"
87 " vertices[1] = vec2( 1.0, -1.0);\n"
88 " vertices[2] = vec2( 0.0, 1.0);\n"
89 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
90 "}\n";
91
Mark Lobodzinski75a97e62015-06-02 09:41:30 -050092static const char bindStateFragShaderText[] =
Cody Northrop8a3bb132015-06-16 17:32:04 -060093 "#version 140\n"
94 "#extension GL_ARB_separate_shader_objects: require\n"
95 "#extension GL_ARB_shading_language_420pack: require\n"
96 "\n"
97 "layout(location = 0) out vec4 uFragColor;\n"
98 "void main(){\n"
99 " uFragColor = vec4(0,1,0,1);\n"
100 "}\n";
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500101
Courtney Goeltzenleuchter06640832015-09-04 13:52:24 -0600102static VkBool32 myDbgFunc(
Tony Barbour67e99152015-07-10 14:10:27 -0600103 VkFlags msgFlags,
Courtney Goeltzenleuchterb19042e2015-11-25 11:38:54 -0700104 VkDebugReportObjectTypeLUNARG objType,
Tony Barbour67e99152015-07-10 14:10:27 -0600105 uint64_t srcObject,
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -0600106 size_t location,
107 int32_t msgCode,
108 const char* pLayerPrefix,
109 const char* pMsg,
Courtney Goeltzenleuchteraf5e7552015-11-30 11:52:06 -0700110 const void* pUserData);
Tony Barbour300a6082015-04-07 13:44:53 -0600111
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600112// ********************************************************
113// ErrorMonitor Usage:
114//
115// Call SetDesiredFailureMsg with a string to be compared against all
116// encountered log messages. Passing NULL will match all log messages.
117// logMsg will return true for skipCall only if msg is matched or NULL.
118//
119// Call DesiredMsgFound to determine if the desired failure message
120// was encountered.
121
Tony Barbour300a6082015-04-07 13:44:53 -0600122class ErrorMonitor {
123public:
Tony Barbour15524c32015-04-29 17:34:29 -0600124 ErrorMonitor()
Tony Barbour300a6082015-04-07 13:44:53 -0600125 {
Mike Stroyan4268d1f2015-07-13 14:45:35 -0600126 test_platform_thread_create_mutex(&m_mutex);
127 test_platform_thread_lock_mutex(&m_mutex);
Courtney Goeltzenleuchterfd4830c2015-11-25 10:30:56 -0700128 m_msgFlags = VK_DEBUG_REPORT_INFO_BIT;
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600129 m_bailout = NULL;
Mike Stroyan4268d1f2015-07-13 14:45:35 -0600130 test_platform_thread_unlock_mutex(&m_mutex);
Tony Barbour300a6082015-04-07 13:44:53 -0600131 }
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600132
133 void SetDesiredFailureMsg(VkFlags msgFlags, const char *msgString)
Tony Barbour300a6082015-04-07 13:44:53 -0600134 {
Mike Stroyan4268d1f2015-07-13 14:45:35 -0600135 test_platform_thread_lock_mutex(&m_mutex);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600136 m_desiredMsg.clear();
137 m_failureMsg.clear();
138 m_otherMsgs.clear();
139 m_desiredMsg = msgString;
140 m_msgFound = VK_FALSE;
141 m_msgFlags = msgFlags;
Mike Stroyan4268d1f2015-07-13 14:45:35 -0600142 test_platform_thread_unlock_mutex(&m_mutex);
Tony Barbour300a6082015-04-07 13:44:53 -0600143 }
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600144
145 VkBool32 CheckForDesiredMsg(VkFlags msgFlags, const char *msgString)
Tony Barbour300a6082015-04-07 13:44:53 -0600146 {
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600147 VkBool32 result = VK_FALSE;
Mike Stroyan4268d1f2015-07-13 14:45:35 -0600148 test_platform_thread_lock_mutex(&m_mutex);
Mike Stroyanaccf7692015-05-12 16:00:45 -0600149 if (m_bailout != NULL) {
150 *m_bailout = true;
151 }
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600152 string errorString(msgString);
153 if (msgFlags & m_msgFlags) {
154 if (errorString.find(m_desiredMsg) != string::npos) {
155 m_failureMsg = errorString;
156 m_msgFound = VK_TRUE;
157 result = VK_TRUE;
158 } else {
159 m_otherMsgs.push_back(errorString);
160 }
161 }
Mike Stroyan4268d1f2015-07-13 14:45:35 -0600162 test_platform_thread_unlock_mutex(&m_mutex);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600163 return result;
Mike Stroyanaccf7692015-05-12 16:00:45 -0600164 }
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600165
166 vector<string> GetOtherFailureMsgs(void)
167 {
168 return m_otherMsgs;
169 }
170
171 string GetFailureMsg(void)
172 {
173 return m_failureMsg;
174 }
175
176 VkBool32 DesiredMsgFound(void)
177 {
178 return m_msgFound;
179 }
180
Mike Stroyanaccf7692015-05-12 16:00:45 -0600181 void SetBailout(bool *bailout)
182 {
183 m_bailout = bailout;
Tony Barbour300a6082015-04-07 13:44:53 -0600184 }
185
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600186 void DumpFailureMsgs(void)
187 {
188 vector<string> otherMsgs = GetOtherFailureMsgs();
189 cout << "Other error messages logged for this test were:" << endl;
190 for (auto iter = otherMsgs.begin(); iter != otherMsgs.end(); iter++) {
191 cout << " " << *iter << endl;
192 }
193 }
194
Tony Barbour300a6082015-04-07 13:44:53 -0600195private:
Mike Stroyan4268d1f2015-07-13 14:45:35 -0600196 VkFlags m_msgFlags;
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600197 string m_desiredMsg;
198 string m_failureMsg;
199 vector<string> m_otherMsgs;
Mike Stroyan4268d1f2015-07-13 14:45:35 -0600200 test_platform_thread_mutex m_mutex;
201 bool* m_bailout;
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600202 VkBool32 m_msgFound;
Tony Barbour300a6082015-04-07 13:44:53 -0600203};
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500204
Courtney Goeltzenleuchter06640832015-09-04 13:52:24 -0600205static VkBool32 myDbgFunc(
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -0600206 VkFlags msgFlags,
Courtney Goeltzenleuchterb19042e2015-11-25 11:38:54 -0700207 VkDebugReportObjectTypeLUNARG objType,
Tony Barbour67e99152015-07-10 14:10:27 -0600208 uint64_t srcObject,
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -0600209 size_t location,
210 int32_t msgCode,
211 const char* pLayerPrefix,
212 const char* pMsg,
Courtney Goeltzenleuchteraf5e7552015-11-30 11:52:06 -0700213 const void* pUserData)
Tony Barbour300a6082015-04-07 13:44:53 -0600214{
Courtney Goeltzenleuchterfd4830c2015-11-25 10:30:56 -0700215 if (msgFlags & (VK_DEBUG_REPORT_WARN_BIT | VK_DEBUG_REPORT_PERF_WARN_BIT | VK_DEBUG_REPORT_ERROR_BIT)) {
Tony Barbour0b4d9562015-04-09 10:48:04 -0600216 ErrorMonitor *errMonitor = (ErrorMonitor *)pUserData;
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600217 return errMonitor->CheckForDesiredMsg(msgFlags, pMsg);
Tony Barbour0b4d9562015-04-09 10:48:04 -0600218 }
Courtney Goeltzenleuchter06640832015-09-04 13:52:24 -0600219 return false;
Tony Barbour300a6082015-04-07 13:44:53 -0600220}
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500221
Tony Barbour6918cd52015-04-09 12:58:51 -0600222class VkLayerTest : public VkRenderFramework
Tony Barbour300a6082015-04-07 13:44:53 -0600223{
224public:
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800225 VkResult BeginCommandBuffer(VkCommandBufferObj &commandBuffer);
226 VkResult EndCommandBuffer(VkCommandBufferObj &commandBuffer);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500227 void VKTriangleTest(const char *vertShaderText, const char *fragShaderText, BsoFailSelect failMask);
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800228 void GenericDrawPreparation(VkCommandBufferObj *commandBuffer, VkPipelineObj &pipelineobj, VkDescriptorSetObj &descriptorSet, BsoFailSelect failMask);
Tony Barbourfe3351b2015-07-28 10:17:20 -0600229 void GenericDrawPreparation(VkPipelineObj &pipelineobj, VkDescriptorSetObj &descriptorSet, BsoFailSelect failMask)
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800230 { GenericDrawPreparation(m_commandBuffer, pipelineobj, descriptorSet, failMask); }
Tony Barbour300a6082015-04-07 13:44:53 -0600231
Tony Barbourfe3351b2015-07-28 10:17:20 -0600232 /* Convenience functions that use built-in command buffer */
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800233 VkResult BeginCommandBuffer() { return BeginCommandBuffer(*m_commandBuffer); }
234 VkResult EndCommandBuffer() { return EndCommandBuffer(*m_commandBuffer); }
Courtney Goeltzenleuchter08c26372015-09-23 12:31:50 -0600235 void Draw(uint32_t vertexCount, uint32_t instanceCount, uint32_t firstVertex, uint32_t firstInstance)
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800236 { m_commandBuffer->Draw(vertexCount, instanceCount, firstVertex, firstInstance); }
Courtney Goeltzenleuchter08c26372015-09-23 12:31:50 -0600237 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 +0800238 { m_commandBuffer->DrawIndexed(indexCount, instanceCount, firstIndex, vertexOffset, firstInstance); }
239 void QueueCommandBuffer() { m_commandBuffer->QueueCommandBuffer(); }
240 void QueueCommandBuffer(const VkFence& fence) { m_commandBuffer->QueueCommandBuffer(fence); }
Tony Barbourfe3351b2015-07-28 10:17:20 -0600241 void BindVertexBuffer(VkConstantBufferObj *vertexBuffer, VkDeviceSize offset, uint32_t binding)
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800242 { m_commandBuffer->BindVertexBuffer(vertexBuffer, offset, binding); }
Tony Barbourfe3351b2015-07-28 10:17:20 -0600243 void BindIndexBuffer(VkIndexBufferObj *indexBuffer, VkDeviceSize offset)
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800244 { m_commandBuffer->BindIndexBuffer(indexBuffer, offset); }
Tony Barbour300a6082015-04-07 13:44:53 -0600245protected:
Tony Barbour6918cd52015-04-09 12:58:51 -0600246 ErrorMonitor *m_errorMonitor;
Tony Barbour300a6082015-04-07 13:44:53 -0600247
248 virtual void SetUp() {
Courtney Goeltzenleuchtercd69eee2015-07-06 09:10:47 -0600249 std::vector<const char *> instance_layer_names;
250 std::vector<const char *> device_layer_names;
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -0600251 std::vector<const char *> instance_extension_names;
252 std::vector<const char *> device_extension_names;
Tony Barbour3fdff9e2015-04-23 12:55:36 -0600253
Courtney Goeltzenleuchter09197ae2015-11-25 13:40:37 -0700254 instance_extension_names.push_back(VK_EXT_LUNARG_DEBUG_REPORT_EXTENSION_NAME);
Courtney Goeltzenleuchterc2b06fe2015-06-16 15:59:11 -0600255 /*
256 * Since CreateDbgMsgCallback is an instance level extension call
257 * any extension / layer that utilizes that feature also needs
258 * to be enabled at create instance time.
259 */
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800260 // Use Threading layer first to protect others from ThreadCommandBufferCollision test
Jon Ashburn59300ec2015-11-25 08:56:58 -0700261 instance_layer_names.push_back("VK_LAYER_LUNARG_Threading");
262 instance_layer_names.push_back("VK_LAYER_LUNARG_ObjectTracker");
263 instance_layer_names.push_back("VK_LAYER_LUNARG_MemTracker");
264 instance_layer_names.push_back("VK_LAYER_LUNARG_DrawState");
Jon Ashburn59300ec2015-11-25 08:56:58 -0700265 instance_layer_names.push_back("VK_LAYER_LUNARG_DeviceLimits");
266 instance_layer_names.push_back("VK_LAYER_LUNARG_Image");
Courtney Goeltzenleuchterd971b612015-06-17 20:51:59 -0600267
Jon Ashburn59300ec2015-11-25 08:56:58 -0700268 device_layer_names.push_back("VK_LAYER_LUNARG_Threading");
269 device_layer_names.push_back("VK_LAYER_LUNARG_ObjectTracker");
270 device_layer_names.push_back("VK_LAYER_LUNARG_MemTracker");
271 device_layer_names.push_back("VK_LAYER_LUNARG_DrawState");
Jon Ashburn59300ec2015-11-25 08:56:58 -0700272 device_layer_names.push_back("VK_LAYER_LUNARG_DeviceLimits");
273 device_layer_names.push_back("VK_LAYER_LUNARG_Image");
Tony Barbour300a6082015-04-07 13:44:53 -0600274
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600275 this->app_info.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO;
Tony Barbour300a6082015-04-07 13:44:53 -0600276 this->app_info.pNext = NULL;
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800277 this->app_info.pApplicationName = "layer_tests";
278 this->app_info.applicationVersion = 1;
Tony Barbour300a6082015-04-07 13:44:53 -0600279 this->app_info.pEngineName = "unittest";
280 this->app_info.engineVersion = 1;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600281 this->app_info.apiVersion = VK_API_VERSION;
Tony Barbour300a6082015-04-07 13:44:53 -0600282
Tony Barbour15524c32015-04-29 17:34:29 -0600283 m_errorMonitor = new ErrorMonitor;
Courtney Goeltzenleuchtercd69eee2015-07-06 09:10:47 -0600284 InitFramework(instance_layer_names, device_layer_names,
285 instance_extension_names, device_extension_names,
286 myDbgFunc, m_errorMonitor);
Tony Barbour300a6082015-04-07 13:44:53 -0600287 }
288
289 virtual void TearDown() {
290 // Clean up resources before we reset
Tony Barbour300a6082015-04-07 13:44:53 -0600291 ShutdownFramework();
Tony Barbour0b4d9562015-04-09 10:48:04 -0600292 delete m_errorMonitor;
Tony Barbour300a6082015-04-07 13:44:53 -0600293 }
294};
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500295
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800296VkResult VkLayerTest::BeginCommandBuffer(VkCommandBufferObj &commandBuffer)
Tony Barbour300a6082015-04-07 13:44:53 -0600297{
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600298 VkResult result;
Tony Barbour300a6082015-04-07 13:44:53 -0600299
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800300 result = commandBuffer.BeginCommandBuffer();
Tony Barbour300a6082015-04-07 13:44:53 -0600301
302 /*
303 * For render test all drawing happens in a single render pass
304 * on a single command buffer.
305 */
Chris Forbes76a5eeb2015-06-16 14:05:59 +1200306 if (VK_SUCCESS == result && renderPass()) {
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800307 commandBuffer.BeginRenderPass(renderPassBeginInfo());
Tony Barbour300a6082015-04-07 13:44:53 -0600308 }
309
310 return result;
311}
312
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800313VkResult VkLayerTest::EndCommandBuffer(VkCommandBufferObj &commandBuffer)
Tony Barbour300a6082015-04-07 13:44:53 -0600314{
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600315 VkResult result;
Tony Barbour300a6082015-04-07 13:44:53 -0600316
Chris Forbes76a5eeb2015-06-16 14:05:59 +1200317 if (renderPass()) {
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800318 commandBuffer.EndRenderPass();
Chris Forbes76a5eeb2015-06-16 14:05:59 +1200319 }
Tony Barbour300a6082015-04-07 13:44:53 -0600320
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800321 result = commandBuffer.EndCommandBuffer();
Tony Barbour300a6082015-04-07 13:44:53 -0600322
323 return result;
324}
325
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500326void VkLayerTest::VKTriangleTest(const char *vertShaderText, const char *fragShaderText, BsoFailSelect failMask)
327{
328 // Create identity matrix
329 int i;
330 struct vktriangle_vs_uniform data;
331
332 glm::mat4 Projection = glm::mat4(1.0f);
333 glm::mat4 View = glm::mat4(1.0f);
334 glm::mat4 Model = glm::mat4(1.0f);
335 glm::mat4 MVP = Projection * View * Model;
336 const int matrixSize = sizeof(MVP);
337 const int bufSize = sizeof(vktriangle_vs_uniform) / sizeof(float);
338
339 memcpy(&data.mvp, &MVP[0][0], matrixSize);
340
341 static const Vertex tri_data[] =
342 {
343 { XYZ1( -1, -1, 0 ), XYZ1( 1.f, 0.f, 0.f ) },
344 { XYZ1( 1, -1, 0 ), XYZ1( 0.f, 1.f, 0.f ) },
345 { XYZ1( 0, 1, 0 ), XYZ1( 0.f, 0.f, 1.f ) },
346 };
347
348 for (i=0; i<3; i++) {
349 data.position[i][0] = tri_data[i].posX;
350 data.position[i][1] = tri_data[i].posY;
351 data.position[i][2] = tri_data[i].posZ;
352 data.position[i][3] = tri_data[i].posW;
353 data.color[i][0] = tri_data[i].r;
354 data.color[i][1] = tri_data[i].g;
355 data.color[i][2] = tri_data[i].b;
356 data.color[i][3] = tri_data[i].a;
357 }
358
359 ASSERT_NO_FATAL_FAILURE(InitState());
360 ASSERT_NO_FATAL_FAILURE(InitViewport());
361
362 VkConstantBufferObj constantBuffer(m_device, bufSize*2, sizeof(float), (const void*) &data);
363
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -0600364 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX_BIT, this);
365 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500366
367 VkPipelineObj pipelineobj(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +0800368 pipelineobj.AddColorAttachment();
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500369 pipelineobj.AddShader(&vs);
370 pipelineobj.AddShader(&ps);
Courtney Goeltzenleuchter507ba972015-09-30 16:16:57 -0600371 if (failMask & BsoFailLineWidth) {
372 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_LINE_WIDTH);
373 }
374 if (failMask & BsoFailDepthBias) {
375 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_DEPTH_BIAS);
376 }
Tobin Ehlisd332f282015-10-02 11:00:56 -0600377 // Viewport and scissors must stay in synch or other errors will occur than the ones we want
Courtney Goeltzenleuchter507ba972015-09-30 16:16:57 -0600378 if (failMask & BsoFailViewport) {
379 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_VIEWPORT);
Tobin Ehlisd332f282015-10-02 11:00:56 -0600380 m_viewports.clear();
381 m_scissors.clear();
Courtney Goeltzenleuchter507ba972015-09-30 16:16:57 -0600382 }
383 if (failMask & BsoFailScissor) {
384 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_SCISSOR);
Tobin Ehlisd332f282015-10-02 11:00:56 -0600385 m_scissors.clear();
386 m_viewports.clear();
Courtney Goeltzenleuchter507ba972015-09-30 16:16:57 -0600387 }
388 if (failMask & BsoFailBlend) {
389 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_BLEND_CONSTANTS);
390 }
391 if (failMask & BsoFailDepthBounds) {
392 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_DEPTH_BOUNDS);
393 }
394 if (failMask & BsoFailStencilReadMask) {
395 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_STENCIL_COMPARE_MASK);
396 }
397 if (failMask & BsoFailStencilWriteMask) {
398 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_STENCIL_WRITE_MASK);
399 }
400 if (failMask & BsoFailStencilReference) {
401 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_STENCIL_REFERENCE);
402 }
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500403
404 VkDescriptorSetObj descriptorSet(m_device);
405 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, constantBuffer);
406
407 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbourfe3351b2015-07-28 10:17:20 -0600408 ASSERT_VK_SUCCESS(BeginCommandBuffer());
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500409
Tony Barbourfe3351b2015-07-28 10:17:20 -0600410 GenericDrawPreparation(pipelineobj, descriptorSet, failMask);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500411
412 // render triangle
Courtney Goeltzenleuchter08c26372015-09-23 12:31:50 -0600413 Draw(3, 1, 0, 0);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500414
415 // finalize recording of the command buffer
Tony Barbourfe3351b2015-07-28 10:17:20 -0600416 EndCommandBuffer();
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500417
Tony Barbourfe3351b2015-07-28 10:17:20 -0600418 QueueCommandBuffer();
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500419}
420
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800421void VkLayerTest::GenericDrawPreparation(VkCommandBufferObj *commandBuffer, VkPipelineObj &pipelineobj, VkDescriptorSetObj &descriptorSet, BsoFailSelect failMask)
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500422{
423 if (m_depthStencil->Initialized()) {
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800424 commandBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color, m_stencil_clear_color, m_depthStencil);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500425 } else {
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800426 commandBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color, m_stencil_clear_color, NULL);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500427 }
428
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800429 commandBuffer->PrepareAttachments();
Cody Northrop82485a82015-08-18 15:21:16 -0600430 // Make sure depthWriteEnable is set so that Depth fail test will work correctly
431 // Make sure stencilTestEnable is set so that Stencil fail test will work correctly
Tony Barboureb254902015-07-15 12:50:33 -0600432 VkStencilOpState stencil = {};
Chia-I Wu1b99bb22015-10-27 19:25:11 +0800433 stencil.failOp = VK_STENCIL_OP_KEEP;
434 stencil.passOp = VK_STENCIL_OP_KEEP;
435 stencil.depthFailOp = VK_STENCIL_OP_KEEP;
436 stencil.compareOp = VK_COMPARE_OP_NEVER;
Tony Barboureb254902015-07-15 12:50:33 -0600437
438 VkPipelineDepthStencilStateCreateInfo ds_ci = {};
439 ds_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DEPTH_STENCIL_STATE_CREATE_INFO;
Courtney Goeltzenleuchter507ba972015-09-30 16:16:57 -0600440 ds_ci.pNext = NULL;
441 ds_ci.depthTestEnable = VK_FALSE;
442 ds_ci.depthWriteEnable = VK_TRUE;
443 ds_ci.depthCompareOp = VK_COMPARE_OP_NEVER;
444 ds_ci.depthBoundsTestEnable = VK_FALSE;
445 ds_ci.stencilTestEnable = VK_TRUE;
446 ds_ci.front = stencil;
447 ds_ci.back = stencil;
Tony Barboureb254902015-07-15 12:50:33 -0600448
Tobin Ehlis4bf96d12015-06-25 11:58:41 -0600449 pipelineobj.SetDepthStencil(&ds_ci);
Tobin Ehlisd332f282015-10-02 11:00:56 -0600450 pipelineobj.SetViewport(m_viewports);
451 pipelineobj.SetScissor(m_scissors);
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800452 descriptorSet.CreateVKDescriptorSet(commandBuffer);
Cody Northrop29a08f22015-08-27 10:20:35 -0600453 VkResult err = pipelineobj.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
454 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800455 commandBuffer->BindPipeline(pipelineobj);
456 commandBuffer->BindDescriptorSet(descriptorSet);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500457}
458
459// ********************************************************************************************************************
460// ********************************************************************************************************************
461// ********************************************************************************************************************
462// ********************************************************************************************************************
Tobin Ehlis0788f522015-05-26 16:11:58 -0600463#if MEM_TRACKER_TESTS
Tobin Ehlis8fab6562015-12-01 09:57:09 -0700464#if 0
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800465TEST_F(VkLayerTest, CallResetCommandBufferBeforeCompletion)
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -0500466{
467 vk_testing::Fence testFence;
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -0500468 VkFenceCreateInfo fenceInfo = {};
469 fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
470 fenceInfo.pNext = NULL;
471 fenceInfo.flags = 0;
472
Courtney Goeltzenleuchterfd4830c2015-11-25 10:30:56 -0700473 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT, "Resetting CB");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600474
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -0500475 ASSERT_NO_FATAL_FAILURE(InitState());
Tony Barbourc1eb1a52015-07-20 13:00:10 -0600476
477 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
478 vk_testing::Buffer buffer;
479 buffer.init_as_dst(*m_device, (VkDeviceSize)20, reqs);
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -0500480
Tony Barbourfe3351b2015-07-28 10:17:20 -0600481 BeginCommandBuffer();
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800482 m_commandBuffer->FillBuffer(buffer.handle(), 0, 4, 0x11111111);
Tony Barbourfe3351b2015-07-28 10:17:20 -0600483 EndCommandBuffer();
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -0500484
485 testFence.init(*m_device, fenceInfo);
486
487 // Bypass framework since it does the waits automatically
488 VkResult err = VK_SUCCESS;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -0600489 VkSubmitInfo submit_info;
Chia-I Wuf9be13c2015-10-26 20:37:06 +0800490 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
491 submit_info.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +0800492 submit_info.waitSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -0600493 submit_info.pWaitSemaphores = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +0800494 submit_info.commandBufferCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800495 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Chia-I Wud50a7d72015-10-26 20:48:51 +0800496 submit_info.signalSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -0600497 submit_info.pSignalSemaphores = NULL;
Courtney Goeltzenleuchter646b9072015-10-20 18:04:07 -0600498
499 err = vkQueueSubmit( m_device->m_queue, 1, &submit_info, testFence.handle());
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -0500500 ASSERT_VK_SUCCESS( err );
501
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -0500502 // Introduce failure by calling begin again before checking fence
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800503 vkResetCommandBuffer(m_commandBuffer->handle(), 0);
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -0500504
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600505 if (!m_errorMonitor->DesiredMsgFound()) {
506 FAIL() << "Did not receive Error 'Resetting CB (0xaddress) before it has completed. You must check CB flag before.'";
507 m_errorMonitor->DumpFailureMsgs();
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -0500508 }
509}
510
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800511TEST_F(VkLayerTest, CallBeginCommandBufferBeforeCompletion)
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -0500512{
513 vk_testing::Fence testFence;
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -0500514 VkFenceCreateInfo fenceInfo = {};
515 fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
516 fenceInfo.pNext = NULL;
517 fenceInfo.flags = 0;
518
Courtney Goeltzenleuchterfd4830c2015-11-25 10:30:56 -0700519 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT, "Calling vkBeginCommandBuffer() on active CB");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600520
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -0500521 ASSERT_NO_FATAL_FAILURE(InitState());
522 ASSERT_NO_FATAL_FAILURE(InitViewport());
523 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
524
Tony Barbourfe3351b2015-07-28 10:17:20 -0600525 BeginCommandBuffer();
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800526 m_commandBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color, m_stencil_clear_color, NULL);
Tony Barbourfe3351b2015-07-28 10:17:20 -0600527 EndCommandBuffer();
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -0500528
529 testFence.init(*m_device, fenceInfo);
530
531 // Bypass framework since it does the waits automatically
532 VkResult err = VK_SUCCESS;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -0600533 VkSubmitInfo submit_info;
Chia-I Wuf9be13c2015-10-26 20:37:06 +0800534 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
535 submit_info.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +0800536 submit_info.waitSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -0600537 submit_info.pWaitSemaphores = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +0800538 submit_info.commandBufferCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800539 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Chia-I Wud50a7d72015-10-26 20:48:51 +0800540 submit_info.signalSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -0600541 submit_info.pSignalSemaphores = NULL;
Courtney Goeltzenleuchter646b9072015-10-20 18:04:07 -0600542
543 err = vkQueueSubmit( m_device->m_queue, 1, &submit_info, testFence.handle());
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -0500544 ASSERT_VK_SUCCESS( err );
545
Mark Lobodzinski5fcc4212015-09-14 17:43:42 -0600546
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800547 VkCommandBufferBeginInfo info = {};
548 info.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT;
549 info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
Mark Lobodzinski5fcc4212015-09-14 17:43:42 -0600550 info.renderPass = VK_NULL_HANDLE;
551 info.subpass = 0;
552 info.framebuffer = VK_NULL_HANDLE;
Chia-I Wub8d47ae2015-11-11 10:18:12 +0800553 info.occlusionQueryEnable = VK_FALSE;
554 info.queryFlags = 0;
555 info.pipelineStatistics = 0;
Mark Lobodzinski5fcc4212015-09-14 17:43:42 -0600556
557 // Introduce failure by calling BCB again before checking fence
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800558 vkBeginCommandBuffer(m_commandBuffer->handle(), &info);
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -0500559
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600560 if (!m_errorMonitor->DesiredMsgFound()) {
561 FAIL() << "Did not receive Error 'Calling vkBeginCommandBuffer() on an active CB (0xaddress) before it has completed'";
562 m_errorMonitor->DumpFailureMsgs();
563
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -0500564 }
565}
Tobin Ehlis8fab6562015-12-01 09:57:09 -0700566#endif
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500567TEST_F(VkLayerTest, MapMemWithoutHostVisibleBit)
568{
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500569 VkResult err;
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -0600570 bool pass;
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500571
Courtney Goeltzenleuchterfd4830c2015-11-25 10:30:56 -0700572 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600573 "Mapping Memory without VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT");
574
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500575 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500576
577 // Create an image, allocate memory, free it, and then try to bind it
578 VkImage image;
Mark Lobodzinski23065352015-05-29 09:32:35 -0500579 VkDeviceMemory mem;
580 VkMemoryRequirements mem_reqs;
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500581
582 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
583 const int32_t tex_width = 32;
584 const int32_t tex_height = 32;
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500585
Tony Barboureb254902015-07-15 12:50:33 -0600586 VkImageCreateInfo image_create_info = {};
587 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
588 image_create_info.pNext = NULL;
589 image_create_info.imageType = VK_IMAGE_TYPE_2D;
590 image_create_info.format = tex_format;
591 image_create_info.extent.width = tex_width;
592 image_create_info.extent.height = tex_height;
593 image_create_info.extent.depth = 1;
594 image_create_info.mipLevels = 1;
Courtney Goeltzenleuchter5d2aed42015-10-21 17:57:31 -0600595 image_create_info.arrayLayers = 1;
Chia-I Wu5c17c962015-10-31 00:31:16 +0800596 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Tony Barboureb254902015-07-15 12:50:33 -0600597 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
598 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
599 image_create_info.flags = 0;
Mark Lobodzinski5fcc4212015-09-14 17:43:42 -0600600
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800601 VkMemoryAllocateInfo mem_alloc = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +0800602 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
Tony Barboureb254902015-07-15 12:50:33 -0600603 mem_alloc.pNext = NULL;
604 mem_alloc.allocationSize = 0;
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500605 // Introduce failure, do NOT set memProps to VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT
Tony Barboureb254902015-07-15 12:50:33 -0600606 mem_alloc.memoryTypeIndex = 1;
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500607
Chia-I Wuf7458c52015-10-26 21:10:41 +0800608 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500609 ASSERT_VK_SUCCESS(err);
610
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -0600611 vkGetImageMemoryRequirements(m_device->device(),
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500612 image,
Mark Lobodzinski23065352015-05-29 09:32:35 -0500613 &mem_reqs);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500614
Mark Lobodzinski23065352015-05-29 09:32:35 -0500615 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500616
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -0600617 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT);
618 if(!pass) { // If we can't find any unmappable memory this test doesn't make sense
Chia-I Wuf7458c52015-10-26 21:10:41 +0800619 vkDestroyImage(m_device->device(), image, NULL);
Tony Barbour02fdc7d2015-08-04 16:13:01 -0600620 return;
Mike Stroyand1c84a52015-08-18 14:40:24 -0600621 }
Mike Stroyan713b2d72015-08-04 10:49:29 -0600622
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500623 // allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800624 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500625 ASSERT_VK_SUCCESS(err);
626
627 // Try to bind free memory that has been freed
Tony Barbour67e99152015-07-10 14:10:27 -0600628 err = vkBindImageMemory(m_device->device(), image, mem, 0);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500629 ASSERT_VK_SUCCESS(err);
630
631 // Map memory as if to initialize the image
632 void *mappedAddress = NULL;
Mark Lobodzinski23065352015-05-29 09:32:35 -0500633 err = vkMapMemory(m_device->device(), mem, 0, 0, 0, &mappedAddress);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500634
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600635 if (!m_errorMonitor->DesiredMsgFound()) {
636 FAIL() << "Did not receive Error 'Error received did not match expected error message from vkMapMemory in MemTracker'";
637 m_errorMonitor->DumpFailureMsgs();
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500638 }
Mike Stroyand1c84a52015-08-18 14:40:24 -0600639
Chia-I Wuf7458c52015-10-26 21:10:41 +0800640 vkDestroyImage(m_device->device(), image, NULL);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500641}
642
Tobin Ehlis2717d132015-07-10 18:25:07 -0600643// TODO : Is this test still valid. Not sure it is with updates to memory binding model
644// Verify and delete the test of fix the check
645//TEST_F(VkLayerTest, FreeBoundMemory)
646//{
Tobin Ehlis2717d132015-07-10 18:25:07 -0600647// VkResult err;
648//
Courtney Goeltzenleuchterfd4830c2015-11-25 10:30:56 -0700649// m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARN_BIT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600650// "Freeing memory object while it still has references");
Tobin Ehlis2717d132015-07-10 18:25:07 -0600651//
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600652// ASSERT_NO_FATAL_FAILURE(InitState());
653
Tobin Ehlis2717d132015-07-10 18:25:07 -0600654// // Create an image, allocate memory, free it, and then try to bind it
655// VkImage image;
656// VkDeviceMemory mem;
657// VkMemoryRequirements mem_reqs;
658//
659// const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
660// const int32_t tex_width = 32;
661// const int32_t tex_height = 32;
662//
663// const VkImageCreateInfo image_create_info = {
664// .sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO,
665// .pNext = NULL,
666// .imageType = VK_IMAGE_TYPE_2D,
667// .format = tex_format,
668// .extent = { tex_width, tex_height, 1 },
669// .mipLevels = 1,
670// .arraySize = 1,
Chia-I Wu5c17c962015-10-31 00:31:16 +0800671// .samples = VK_SAMPLE_COUNT_1_BIT,
Tobin Ehlis2717d132015-07-10 18:25:07 -0600672// .tiling = VK_IMAGE_TILING_LINEAR,
673// .usage = VK_IMAGE_USAGE_SAMPLED_BIT,
674// .flags = 0,
675// };
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800676// VkMemoryAllocateInfo mem_alloc = {
Chia-I Wu00ce5402015-11-10 16:21:09 +0800677// .sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO,
Tobin Ehlis2717d132015-07-10 18:25:07 -0600678// .pNext = NULL,
679// .allocationSize = 0,
680// .memoryTypeIndex = 0,
681// };
682//
Chia-I Wuf7458c52015-10-26 21:10:41 +0800683// err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Tobin Ehlis2717d132015-07-10 18:25:07 -0600684// ASSERT_VK_SUCCESS(err);
685//
686// err = vkGetImageMemoryRequirements(m_device->device(),
687// image,
688// &mem_reqs);
689// ASSERT_VK_SUCCESS(err);
690//
691// mem_alloc.allocationSize = mem_reqs.size;
692//
693// err = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
694// ASSERT_VK_SUCCESS(err);
695//
696// // allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800697// err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
Tobin Ehlis2717d132015-07-10 18:25:07 -0600698// ASSERT_VK_SUCCESS(err);
699//
700// // Bind memory to Image object
701// err = vkBindImageMemory(m_device->device(), image, mem, 0);
702// ASSERT_VK_SUCCESS(err);
703//
704// // Introduce validation failure, free memory while still bound to object
Chia-I Wuf7458c52015-10-26 21:10:41 +0800705// vkFreeMemory(m_device->device(), mem, NULL);
Courtney Goeltzenleuchter06640832015-09-04 13:52:24 -0600706//
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600707// if (!m_errorMonitor->DesiredMsgFound()) {
708// FAIL() << "Did not receive Warning 'Freeing memory object while it still has references'");
709// m_errorMonitor->DumpFailureMsgs();
Tobin Ehlis2717d132015-07-10 18:25:07 -0600710// }
711//}
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500712
Mark Lobodzinski944aab12015-06-05 13:59:04 -0500713TEST_F(VkLayerTest, RebindMemory)
714{
Mark Lobodzinski944aab12015-06-05 13:59:04 -0500715 VkResult err;
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -0600716 bool pass;
Mark Lobodzinski944aab12015-06-05 13:59:04 -0500717
Courtney Goeltzenleuchterfd4830c2015-11-25 10:30:56 -0700718 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600719 "which has already been bound to mem object");
720
Mark Lobodzinski944aab12015-06-05 13:59:04 -0500721 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski944aab12015-06-05 13:59:04 -0500722
723 // Create an image, allocate memory, free it, and then try to bind it
724 VkImage image;
725 VkDeviceMemory mem1;
726 VkDeviceMemory mem2;
727 VkMemoryRequirements mem_reqs;
728
729 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
730 const int32_t tex_width = 32;
731 const int32_t tex_height = 32;
Mark Lobodzinski944aab12015-06-05 13:59:04 -0500732
Tony Barboureb254902015-07-15 12:50:33 -0600733 VkImageCreateInfo image_create_info = {};
734 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
735 image_create_info.pNext = NULL;
736 image_create_info.imageType = VK_IMAGE_TYPE_2D;
737 image_create_info.format = tex_format;
738 image_create_info.extent.width = tex_width;
739 image_create_info.extent.height = tex_height;
740 image_create_info.extent.depth = 1;
741 image_create_info.mipLevels = 1;
Courtney Goeltzenleuchter5d2aed42015-10-21 17:57:31 -0600742 image_create_info.arrayLayers = 1;
Chia-I Wu5c17c962015-10-31 00:31:16 +0800743 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Tony Barboureb254902015-07-15 12:50:33 -0600744 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
745 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
746 image_create_info.flags = 0;
Mark Lobodzinski944aab12015-06-05 13:59:04 -0500747
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800748 VkMemoryAllocateInfo mem_alloc = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +0800749 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
Tony Barboureb254902015-07-15 12:50:33 -0600750 mem_alloc.pNext = NULL;
751 mem_alloc.allocationSize = 0;
752 mem_alloc.memoryTypeIndex = 0;
753
754 // Introduce failure, do NOT set memProps to VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT
755 mem_alloc.memoryTypeIndex = 1;
Chia-I Wuf7458c52015-10-26 21:10:41 +0800756 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Mark Lobodzinski944aab12015-06-05 13:59:04 -0500757 ASSERT_VK_SUCCESS(err);
758
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -0600759 vkGetImageMemoryRequirements(m_device->device(),
Mark Lobodzinski944aab12015-06-05 13:59:04 -0500760 image,
Mark Lobodzinski944aab12015-06-05 13:59:04 -0500761 &mem_reqs);
Mark Lobodzinski944aab12015-06-05 13:59:04 -0500762
763 mem_alloc.allocationSize = mem_reqs.size;
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -0600764 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
765 ASSERT_TRUE(pass);
Mark Lobodzinski944aab12015-06-05 13:59:04 -0500766
767 // allocate 2 memory objects
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800768 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem1);
Mark Lobodzinski944aab12015-06-05 13:59:04 -0500769 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800770 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem2);
Mark Lobodzinski944aab12015-06-05 13:59:04 -0500771 ASSERT_VK_SUCCESS(err);
772
773 // Bind first memory object to Image object
Tony Barbour67e99152015-07-10 14:10:27 -0600774 err = vkBindImageMemory(m_device->device(), image, mem1, 0);
Mark Lobodzinski944aab12015-06-05 13:59:04 -0500775 ASSERT_VK_SUCCESS(err);
776
777 // Introduce validation failure, try to bind a different memory object to the same image object
Tony Barbour67e99152015-07-10 14:10:27 -0600778 err = vkBindImageMemory(m_device->device(), image, mem2, 0);
Mark Lobodzinski944aab12015-06-05 13:59:04 -0500779
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600780 if (!m_errorMonitor->DesiredMsgFound()) {
781 FAIL() << "Did not receive Error when rebinding memory to an object";
782 m_errorMonitor->DumpFailureMsgs();
Mark Lobodzinski944aab12015-06-05 13:59:04 -0500783 }
Mike Stroyand1c84a52015-08-18 14:40:24 -0600784
Chia-I Wuf7458c52015-10-26 21:10:41 +0800785 vkDestroyImage(m_device->device(), image, NULL);
786 vkFreeMemory(m_device->device(), mem1, NULL);
787 vkFreeMemory(m_device->device(), mem2, NULL);
Mark Lobodzinski944aab12015-06-05 13:59:04 -0500788}
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500789
Tony Barbour0b4d9562015-04-09 10:48:04 -0600790TEST_F(VkLayerTest, SubmitSignaledFence)
Tony Barbour300a6082015-04-07 13:44:53 -0600791{
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600792 vk_testing::Fence testFence;
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600793
Courtney Goeltzenleuchterfd4830c2015-11-25 10:30:56 -0700794 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600795 "submitted in SIGNALED state. Fences must be reset before being submitted");
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600796
797 VkFenceCreateInfo fenceInfo = {};
Tony Barbour0b4d9562015-04-09 10:48:04 -0600798 fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
799 fenceInfo.pNext = NULL;
800 fenceInfo.flags = VK_FENCE_CREATE_SIGNALED_BIT;
Tony Barbour300a6082015-04-07 13:44:53 -0600801
Tony Barbour300a6082015-04-07 13:44:53 -0600802 ASSERT_NO_FATAL_FAILURE(InitState());
803 ASSERT_NO_FATAL_FAILURE(InitViewport());
804 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
805
Tony Barbourfe3351b2015-07-28 10:17:20 -0600806 BeginCommandBuffer();
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800807 m_commandBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color, m_stencil_clear_color, NULL);
Tony Barbourfe3351b2015-07-28 10:17:20 -0600808 EndCommandBuffer();
Tony Barbour300a6082015-04-07 13:44:53 -0600809
810 testFence.init(*m_device, fenceInfo);
Mark Lobodzinski5fcc4212015-09-14 17:43:42 -0600811
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -0600812 VkSubmitInfo submit_info;
Chia-I Wuf9be13c2015-10-26 20:37:06 +0800813 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
814 submit_info.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +0800815 submit_info.waitSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -0600816 submit_info.pWaitSemaphores = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +0800817 submit_info.commandBufferCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800818 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Chia-I Wud50a7d72015-10-26 20:48:51 +0800819 submit_info.signalSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -0600820 submit_info.pSignalSemaphores = NULL;
Courtney Goeltzenleuchter646b9072015-10-20 18:04:07 -0600821
822 vkQueueSubmit(m_device->m_queue, 1, &submit_info, testFence.handle());
Mark Lobodzinski5fcc4212015-09-14 17:43:42 -0600823 vkQueueWaitIdle(m_device->m_queue );
Mark Lobodzinski5fcc4212015-09-14 17:43:42 -0600824
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600825 if (!m_errorMonitor->DesiredMsgFound()) {
826 FAIL() << "Did not receive Error 'VkQueueSubmit with fence in SIGNALED_STATE'";
827 m_errorMonitor->DumpFailureMsgs();
Tony Barbour0b4d9562015-04-09 10:48:04 -0600828 }
Tony Barbour0b4d9562015-04-09 10:48:04 -0600829}
830
831TEST_F(VkLayerTest, ResetUnsignaledFence)
832{
833 vk_testing::Fence testFence;
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600834 VkFenceCreateInfo fenceInfo = {};
Tony Barbour0b4d9562015-04-09 10:48:04 -0600835 fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
836 fenceInfo.pNext = NULL;
837
Courtney Goeltzenleuchterfd4830c2015-11-25 10:30:56 -0700838 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARN_BIT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600839 "submitted to VkResetFences in UNSIGNALED STATE");
840
Tony Barbour0b4d9562015-04-09 10:48:04 -0600841 ASSERT_NO_FATAL_FAILURE(InitState());
842 testFence.init(*m_device, fenceInfo);
Chia-I Wud9e8e822015-07-03 11:45:55 +0800843 VkFence fences[1] = {testFence.handle()};
Tony Barbour0b4d9562015-04-09 10:48:04 -0600844 vkResetFences(m_device->device(), 1, fences);
Tony Barbour300a6082015-04-07 13:44:53 -0600845
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600846 if (!m_errorMonitor->DesiredMsgFound()) {
847 FAIL() << "Did not receive Error 'VkResetFences with fence in UNSIGNALED_STATE'";
848 m_errorMonitor->DumpFailureMsgs();
849 }
Tony Barbour300a6082015-04-07 13:44:53 -0600850}
Tobin Ehlis41376e12015-07-03 08:45:14 -0600851
Chia-I Wu08accc62015-07-07 11:50:03 +0800852/* TODO: Update for changes due to bug-14075 tiling across render passes */
853#if 0
Tobin Ehlis41376e12015-07-03 08:45:14 -0600854TEST_F(VkLayerTest, InvalidUsageBits)
855{
856 // Initiate Draw w/o a PSO bound
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600857
Courtney Goeltzenleuchterfd4830c2015-11-25 10:30:56 -0700858 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600859 "Invalid usage flag for image ");
Tobin Ehlis41376e12015-07-03 08:45:14 -0600860
861 ASSERT_NO_FATAL_FAILURE(InitState());
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800862 VkCommandBufferObj commandBuffer(m_device);
Tony Barbourfe3351b2015-07-28 10:17:20 -0600863 BeginCommandBuffer();
Tobin Ehlis41376e12015-07-03 08:45:14 -0600864
865 const VkExtent3D e3d = {
866 .width = 128,
867 .height = 128,
868 .depth = 1,
869 };
870 const VkImageCreateInfo ici = {
871 .sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO,
872 .pNext = NULL,
873 .imageType = VK_IMAGE_TYPE_2D,
874 .format = VK_FORMAT_D32_SFLOAT_S8_UINT,
875 .extent = e3d,
876 .mipLevels = 1,
877 .arraySize = 1,
Chia-I Wu5c17c962015-10-31 00:31:16 +0800878 .samples = VK_SAMPLE_COUNT_1_BIT,
Tobin Ehlis41376e12015-07-03 08:45:14 -0600879 .tiling = VK_IMAGE_TILING_LINEAR,
Courtney Goeltzenleuchter660f0ca2015-09-10 14:14:11 -0600880 .usage = 0, // Not setting VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT
Tobin Ehlis41376e12015-07-03 08:45:14 -0600881 .flags = 0,
882 };
883
884 VkImage dsi;
Chia-I Wuf7458c52015-10-26 21:10:41 +0800885 vkCreateImage(m_device->device(), &ici, NULL, &dsi);
Tobin Ehlis41376e12015-07-03 08:45:14 -0600886 VkDepthStencilView dsv;
887 const VkDepthStencilViewCreateInfo dsvci = {
888 .sType = VK_STRUCTURE_TYPE_DEPTH_STENCIL_VIEW_CREATE_INFO,
889 .pNext = NULL,
890 .image = dsi,
891 .mipLevel = 0,
Courtney Goeltzenleuchter4a261892015-09-10 16:38:41 -0600892 .baseArrayLayer = 0,
Tobin Ehlis41376e12015-07-03 08:45:14 -0600893 .arraySize = 1,
894 .flags = 0,
895 };
Chia-I Wuf7458c52015-10-26 21:10:41 +0800896 vkCreateDepthStencilView(m_device->device(), &dsvci, NULL, &dsv);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600897
898 if (!m_errorMonitor->DesiredMsgFound()) {
Tobin Ehlis41376e12015-07-03 08:45:14 -0600899 FAIL() << "Error received was not 'Invalid usage flag for image...'";
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600900 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlis41376e12015-07-03 08:45:14 -0600901 }
902}
Mark Lobodzinski209b5292015-09-17 09:44:05 -0600903#endif // 0
904#endif // MEM_TRACKER_TESTS
905
Tobin Ehlis4bf96d12015-06-25 11:58:41 -0600906#if OBJ_TRACKER_TESTS
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -0600907TEST_F(VkLayerTest, PipelineNotBound)
908{
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -0600909 VkResult err;
910
Courtney Goeltzenleuchterfd4830c2015-11-25 10:30:56 -0700911 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600912 "Invalid VkPipeline Object ");
913
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -0600914 ASSERT_NO_FATAL_FAILURE(InitState());
915 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -0600916
Chia-I Wu1b99bb22015-10-27 19:25:11 +0800917 VkDescriptorPoolSize ds_type_count = {};
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -0600918 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wud50a7d72015-10-26 20:48:51 +0800919 ds_type_count.descriptorCount = 1;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -0600920
921 VkDescriptorPoolCreateInfo ds_pool_ci = {};
922 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
923 ds_pool_ci.pNext = NULL;
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -0600924 ds_pool_ci.maxSets = 1;
Chia-I Wu1b99bb22015-10-27 19:25:11 +0800925 ds_pool_ci.poolSizeCount = 1;
926 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -0600927
928 VkDescriptorPool ds_pool;
Chia-I Wuf7458c52015-10-26 21:10:41 +0800929 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -0600930 ASSERT_VK_SUCCESS(err);
931
932 VkDescriptorSetLayoutBinding dsl_binding = {};
Chia-I Wud46e6ae2015-10-31 00:31:16 +0800933 dsl_binding.binding = 0;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -0600934 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wu02124482015-11-06 06:42:02 +0800935 dsl_binding.descriptorCount = 1;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -0600936 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
937 dsl_binding.pImmutableSamplers = NULL;
938
939 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
940 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
941 ds_layout_ci.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +0800942 ds_layout_ci.bindingCount = 1;
Chia-I Wua745e512015-10-31 00:31:16 +0800943 ds_layout_ci.pBinding = &dsl_binding;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -0600944
945 VkDescriptorSetLayout ds_layout;
Chia-I Wuf7458c52015-10-26 21:10:41 +0800946 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -0600947 ASSERT_VK_SUCCESS(err);
948
949 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800950 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +0800951 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Chia-I Wud50a7d72015-10-26 20:48:51 +0800952 alloc_info.setLayoutCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -0600953 alloc_info.descriptorPool = ds_pool;
954 alloc_info.pSetLayouts = &ds_layout;
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800955 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -0600956 ASSERT_VK_SUCCESS(err);
957
958 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
959 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
960 pipeline_layout_ci.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +0800961 pipeline_layout_ci.setLayoutCount = 1;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -0600962 pipeline_layout_ci.pSetLayouts = &ds_layout;
963
964 VkPipelineLayout pipeline_layout;
Chia-I Wuf7458c52015-10-26 21:10:41 +0800965 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -0600966 ASSERT_VK_SUCCESS(err);
967
968 VkPipeline badPipeline = (VkPipeline)0xbaadb1be;
969
970 BeginCommandBuffer();
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800971 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, badPipeline);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -0600972
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600973 if (!m_errorMonitor->DesiredMsgFound()) {
974 FAIL() << "Error received was not 'Invalid VkPipeline Object 0xbaadb1be'" << endl;
975 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlisec598302015-09-15 15:02:17 -0600976 }
Mike Stroyand1c84a52015-08-18 14:40:24 -0600977
Chia-I Wuf7458c52015-10-26 21:10:41 +0800978 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
979 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
980 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisec598302015-09-15 15:02:17 -0600981}
982
983TEST_F(VkLayerTest, BindInvalidMemory)
984{
Tobin Ehlisec598302015-09-15 15:02:17 -0600985 VkResult err;
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -0600986 bool pass;
Tobin Ehlisec598302015-09-15 15:02:17 -0600987
Courtney Goeltzenleuchterfd4830c2015-11-25 10:30:56 -0700988 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600989 "Invalid VkDeviceMemory Object ");
990
Tobin Ehlisec598302015-09-15 15:02:17 -0600991 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisec598302015-09-15 15:02:17 -0600992
993 // Create an image, allocate memory, free it, and then try to bind it
994 VkImage image;
995 VkDeviceMemory mem;
996 VkMemoryRequirements mem_reqs;
997
998 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
999 const int32_t tex_width = 32;
1000 const int32_t tex_height = 32;
1001
1002 VkImageCreateInfo image_create_info = {};
1003 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
1004 image_create_info.pNext = NULL;
1005 image_create_info.imageType = VK_IMAGE_TYPE_2D;
1006 image_create_info.format = tex_format;
1007 image_create_info.extent.width = tex_width;
1008 image_create_info.extent.height = tex_height;
1009 image_create_info.extent.depth = 1;
1010 image_create_info.mipLevels = 1;
Courtney Goeltzenleuchter5d2aed42015-10-21 17:57:31 -06001011 image_create_info.arrayLayers = 1;
Chia-I Wu5c17c962015-10-31 00:31:16 +08001012 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Tobin Ehlisec598302015-09-15 15:02:17 -06001013 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
1014 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
1015 image_create_info.flags = 0;
1016
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001017 VkMemoryAllocateInfo mem_alloc = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08001018 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
Tobin Ehlisec598302015-09-15 15:02:17 -06001019 mem_alloc.pNext = NULL;
1020 mem_alloc.allocationSize = 0;
1021 mem_alloc.memoryTypeIndex = 0;
1022
Chia-I Wuf7458c52015-10-26 21:10:41 +08001023 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Tobin Ehlisec598302015-09-15 15:02:17 -06001024 ASSERT_VK_SUCCESS(err);
1025
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -06001026 vkGetImageMemoryRequirements(m_device->device(),
Tobin Ehlisec598302015-09-15 15:02:17 -06001027 image,
1028 &mem_reqs);
Tobin Ehlisec598302015-09-15 15:02:17 -06001029
1030 mem_alloc.allocationSize = mem_reqs.size;
1031
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -06001032 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
1033 ASSERT_TRUE(pass);
Tobin Ehlisec598302015-09-15 15:02:17 -06001034
1035 // allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001036 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
Tobin Ehlisec598302015-09-15 15:02:17 -06001037 ASSERT_VK_SUCCESS(err);
1038
1039 // Introduce validation failure, free memory before binding
Chia-I Wuf7458c52015-10-26 21:10:41 +08001040 vkFreeMemory(m_device->device(), mem, NULL);
Tobin Ehlisec598302015-09-15 15:02:17 -06001041
1042 // Try to bind free memory that has been freed
1043 err = vkBindImageMemory(m_device->device(), image, mem, 0);
1044 // This may very well return an error.
1045 (void)err;
1046
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06001047 if (!m_errorMonitor->DesiredMsgFound()) {
1048 FAIL() << "Did not receive Error 'Invalid VkDeviceMemory Object 0x<handle>'";
1049 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlisec598302015-09-15 15:02:17 -06001050 }
Mike Stroyand1c84a52015-08-18 14:40:24 -06001051
Chia-I Wuf7458c52015-10-26 21:10:41 +08001052 vkDestroyImage(m_device->device(), image, NULL);
Tobin Ehlisec598302015-09-15 15:02:17 -06001053}
1054
1055TEST_F(VkLayerTest, BindMemoryToDestroyedObject)
1056{
Tobin Ehlisec598302015-09-15 15:02:17 -06001057 VkResult err;
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -06001058 bool pass;
Tobin Ehlisec598302015-09-15 15:02:17 -06001059
Courtney Goeltzenleuchterfd4830c2015-11-25 10:30:56 -07001060 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT, "Invalid VkImage Object ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06001061
Tobin Ehlisec598302015-09-15 15:02:17 -06001062 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisec598302015-09-15 15:02:17 -06001063
1064 // Create an image object, allocate memory, destroy the object and then try to bind it
1065 VkImage image;
1066 VkDeviceMemory mem;
1067 VkMemoryRequirements mem_reqs;
1068
1069 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
1070 const int32_t tex_width = 32;
1071 const int32_t tex_height = 32;
1072
1073 VkImageCreateInfo image_create_info = {};
1074 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
1075 image_create_info.pNext = NULL;
1076 image_create_info.imageType = VK_IMAGE_TYPE_2D;
1077 image_create_info.format = tex_format;
1078 image_create_info.extent.width = tex_width;
1079 image_create_info.extent.height = tex_height;
1080 image_create_info.extent.depth = 1;
1081 image_create_info.mipLevels = 1;
Courtney Goeltzenleuchter5d2aed42015-10-21 17:57:31 -06001082 image_create_info.arrayLayers = 1;
Chia-I Wu5c17c962015-10-31 00:31:16 +08001083 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Tobin Ehlisec598302015-09-15 15:02:17 -06001084 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
1085 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
1086 image_create_info.flags = 0;
1087
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001088 VkMemoryAllocateInfo mem_alloc = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08001089 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
Tobin Ehlisec598302015-09-15 15:02:17 -06001090 mem_alloc.pNext = NULL;
1091 mem_alloc.allocationSize = 0;
1092 mem_alloc.memoryTypeIndex = 0;
1093
Chia-I Wuf7458c52015-10-26 21:10:41 +08001094 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Tobin Ehlisec598302015-09-15 15:02:17 -06001095 ASSERT_VK_SUCCESS(err);
1096
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -06001097 vkGetImageMemoryRequirements(m_device->device(),
Tobin Ehlisec598302015-09-15 15:02:17 -06001098 image,
1099 &mem_reqs);
Tobin Ehlisec598302015-09-15 15:02:17 -06001100
1101 mem_alloc.allocationSize = mem_reqs.size;
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -06001102 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
1103 ASSERT_TRUE(pass);
Tobin Ehlisec598302015-09-15 15:02:17 -06001104
1105 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001106 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
Tobin Ehlisec598302015-09-15 15:02:17 -06001107 ASSERT_VK_SUCCESS(err);
1108
1109 // Introduce validation failure, destroy Image object before binding
Chia-I Wuf7458c52015-10-26 21:10:41 +08001110 vkDestroyImage(m_device->device(), image, NULL);
Tobin Ehlisec598302015-09-15 15:02:17 -06001111 ASSERT_VK_SUCCESS(err);
1112
1113 // Now Try to bind memory to this destroyed object
1114 err = vkBindImageMemory(m_device->device(), image, mem, 0);
1115 // This may very well return an error.
1116 (void) err;
1117
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06001118 if (!m_errorMonitor->DesiredMsgFound()) {
1119 FAIL() << "Did not receive Error 'Invalid VkImage Object 0x<handle>'";
1120 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06001121 }
Mike Stroyand1c84a52015-08-18 14:40:24 -06001122
Chia-I Wuf7458c52015-10-26 21:10:41 +08001123 vkFreeMemory(m_device->device(), mem, NULL);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06001124}
Tobin Ehlisa1c28562015-10-23 16:00:08 -06001125
Mark Lobodzinski209b5292015-09-17 09:44:05 -06001126#endif // OBJ_TRACKER_TESTS
1127
Tobin Ehlis0788f522015-05-26 16:11:58 -06001128#if DRAW_STATE_TESTS
Tobin Ehlis963a4042015-09-29 08:18:34 -06001129TEST_F(VkLayerTest, LineWidthStateNotBound)
1130{
Courtney Goeltzenleuchterfd4830c2015-11-25 10:30:56 -07001131 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06001132 "Dynamic line width state not set for this command buffer");
1133
Tobin Ehlis963a4042015-09-29 08:18:34 -06001134 TEST_DESCRIPTION("Simple Draw Call that validates failure when a line width state object is not bound beforehand");
1135
1136 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailLineWidth);
1137
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06001138 if (!m_errorMonitor->DesiredMsgFound()) {
1139 FAIL() << "Did not receive Error 'Dynamic line width state not set for this command buffer'";
1140 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlis963a4042015-09-29 08:18:34 -06001141 }
1142}
1143
1144TEST_F(VkLayerTest, DepthBiasStateNotBound)
1145{
Courtney Goeltzenleuchterfd4830c2015-11-25 10:30:56 -07001146 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06001147 "Dynamic depth bias state not set for this command buffer");
1148
Tobin Ehlis963a4042015-09-29 08:18:34 -06001149 TEST_DESCRIPTION("Simple Draw Call that validates failure when a depth bias state object is not bound beforehand");
1150
1151 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailDepthBias);
1152
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06001153 if (!m_errorMonitor->DesiredMsgFound()) {
1154 FAIL() << "Did not receive Error 'Dynamic depth bias state not set for this command buffer'";
1155 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlis963a4042015-09-29 08:18:34 -06001156 }
1157}
1158
Cody Northrop4063c9a2015-10-27 16:54:28 -06001159// Disable these two tests until we can sort out how to track multiple layer errors
Tobin Ehlis963a4042015-09-29 08:18:34 -06001160TEST_F(VkLayerTest, ViewportStateNotBound)
1161{
Courtney Goeltzenleuchterfd4830c2015-11-25 10:30:56 -07001162 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06001163 "Dynamic viewport state not set for this command buffer");
1164
Tobin Ehlis963a4042015-09-29 08:18:34 -06001165 TEST_DESCRIPTION("Simple Draw Call that validates failure when a viewport state object is not bound beforehand");
1166
1167 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailViewport);
1168
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06001169 if (!m_errorMonitor->DesiredMsgFound()) {
1170 FAIL() << "Did not recieve Error 'Dynamic scissor state not set for this command buffer'";
1171 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlis963a4042015-09-29 08:18:34 -06001172 }
1173}
1174
1175TEST_F(VkLayerTest, ScissorStateNotBound)
1176{
Courtney Goeltzenleuchterfd4830c2015-11-25 10:30:56 -07001177 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06001178 "Dynamic scissor state not set for this command buffer");
1179
Tobin Ehlis963a4042015-09-29 08:18:34 -06001180 TEST_DESCRIPTION("Simple Draw Call that validates failure when a viewport state object is not bound beforehand");
1181
1182 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailScissor);
1183
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06001184 if (!m_errorMonitor->DesiredMsgFound()) {
1185 FAIL() << "Did not recieve Error ' Expected: 'Dynamic scissor state not set for this command buffer'";
1186 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlis963a4042015-09-29 08:18:34 -06001187 }
1188}
1189
Tobin Ehlis963a4042015-09-29 08:18:34 -06001190TEST_F(VkLayerTest, BlendStateNotBound)
1191{
Courtney Goeltzenleuchterfd4830c2015-11-25 10:30:56 -07001192 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06001193 "Dynamic blend object state not set for this command buffer");
1194
Tobin Ehlis963a4042015-09-29 08:18:34 -06001195 TEST_DESCRIPTION("Simple Draw Call that validates failure when a blend state object is not bound beforehand");
1196
1197 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailBlend);
1198
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06001199 if (!m_errorMonitor->DesiredMsgFound()) {
1200 FAIL() << "Did not recieve Error 'Dynamic blend object state not set for this command buffer'";
1201 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlis963a4042015-09-29 08:18:34 -06001202 }
1203}
1204
1205TEST_F(VkLayerTest, DepthBoundsStateNotBound)
1206{
Courtney Goeltzenleuchterfd4830c2015-11-25 10:30:56 -07001207 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06001208 "Dynamic depth bounds state not set for this command buffer");
1209
Tobin Ehlis963a4042015-09-29 08:18:34 -06001210 TEST_DESCRIPTION("Simple Draw Call that validates failure when a depth bounds state object is not bound beforehand");
1211
1212 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailDepthBounds);
1213
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06001214 if (!m_errorMonitor->DesiredMsgFound()) {
1215 FAIL() << "Did not receive Error 'Dynamic depth bounds state not set for this command buffer'";
1216 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlis963a4042015-09-29 08:18:34 -06001217 }
1218}
1219
1220TEST_F(VkLayerTest, StencilReadMaskNotSet)
1221{
Courtney Goeltzenleuchterfd4830c2015-11-25 10:30:56 -07001222 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06001223 "Dynamic stencil read mask state not set for this command buffer");
1224
Tobin Ehlis963a4042015-09-29 08:18:34 -06001225 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06001226
Tobin Ehlis963a4042015-09-29 08:18:34 -06001227 TEST_DESCRIPTION("Simple Draw Call that validates failure when a stencil read mask is not set beforehand");
1228
1229 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailStencilReadMask);
1230
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06001231 if (!m_errorMonitor->DesiredMsgFound()) {
1232 FAIL() << "Did not receive Error 'Dynamic stencil read mask state not set for this command buffer'";
1233 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlis963a4042015-09-29 08:18:34 -06001234 }
1235}
1236
1237TEST_F(VkLayerTest, StencilWriteMaskNotSet)
1238{
Courtney Goeltzenleuchterfd4830c2015-11-25 10:30:56 -07001239 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06001240 "Dynamic stencil write mask state not set for this command buffer");
1241
Tobin Ehlis963a4042015-09-29 08:18:34 -06001242 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06001243
Tobin Ehlis963a4042015-09-29 08:18:34 -06001244 TEST_DESCRIPTION("Simple Draw Call that validates failure when a stencil write mask is not set beforehand");
1245
1246 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailStencilWriteMask);
1247
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06001248 if (!m_errorMonitor->DesiredMsgFound()) {
1249 FAIL() << "Did not receive Error 'Dynamic stencil write mask state not set for this command buffer'";
1250 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlis963a4042015-09-29 08:18:34 -06001251 }
1252}
1253
1254TEST_F(VkLayerTest, StencilReferenceNotSet)
1255{
Courtney Goeltzenleuchterfd4830c2015-11-25 10:30:56 -07001256 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06001257 "Dynamic stencil reference state not set for this command buffer");
1258
Tobin Ehlis963a4042015-09-29 08:18:34 -06001259 TEST_DESCRIPTION("Simple Draw Call that validates failure when a stencil reference is not set beforehand");
1260
1261 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailStencilReference);
1262
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06001263 if (!m_errorMonitor->DesiredMsgFound()) {
1264 FAIL() << "Did not receive Error 'Dynamic stencil reference state not set for this command buffer'";
1265 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlis963a4042015-09-29 08:18:34 -06001266 }
1267}
1268
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001269TEST_F(VkLayerTest, CommandBufferTwoSubmits)
Tobin Ehlis59278bf2015-08-18 07:10:58 -06001270{
1271 vk_testing::Fence testFence;
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06001272
Courtney Goeltzenleuchterfd4830c2015-11-25 10:30:56 -07001273 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06001274 "was begun w/ VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT set, but has been submitted");
Tobin Ehlis59278bf2015-08-18 07:10:58 -06001275
1276 VkFenceCreateInfo fenceInfo = {};
1277 fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
1278 fenceInfo.pNext = NULL;
1279 fenceInfo.flags = 0;
1280
1281 ASSERT_NO_FATAL_FAILURE(InitState());
1282 ASSERT_NO_FATAL_FAILURE(InitViewport());
1283 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
1284
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001285 // 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 -06001286 BeginCommandBuffer();
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001287 m_commandBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color, m_stencil_clear_color, NULL);
Tobin Ehlis59278bf2015-08-18 07:10:58 -06001288 EndCommandBuffer();
1289
1290 testFence.init(*m_device, fenceInfo);
1291
1292 // Bypass framework since it does the waits automatically
1293 VkResult err = VK_SUCCESS;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06001294 VkSubmitInfo submit_info;
Chia-I Wuf9be13c2015-10-26 20:37:06 +08001295 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
1296 submit_info.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08001297 submit_info.waitSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06001298 submit_info.pWaitSemaphores = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08001299 submit_info.commandBufferCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001300 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Chia-I Wud50a7d72015-10-26 20:48:51 +08001301 submit_info.signalSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06001302 submit_info.pSignalSemaphores = NULL;
1303
Courtney Goeltzenleuchter646b9072015-10-20 18:04:07 -06001304 err = vkQueueSubmit( m_device->m_queue, 1, &submit_info, testFence.handle());
Tobin Ehlis59278bf2015-08-18 07:10:58 -06001305 ASSERT_VK_SUCCESS( err );
1306
Tobin Ehlis59278bf2015-08-18 07:10:58 -06001307 // Cause validation error by re-submitting cmd buffer that should only be submitted once
Courtney Goeltzenleuchter646b9072015-10-20 18:04:07 -06001308 err = vkQueueSubmit( m_device->m_queue, 1, &submit_info, testFence.handle());
Tobin Ehlis59278bf2015-08-18 07:10:58 -06001309
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06001310 if (!m_errorMonitor->DesiredMsgFound()) {
1311 FAIL() << "Did not receive Error 'CB (0xaddress) was created w/ VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT set...'";
1312 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlis59278bf2015-08-18 07:10:58 -06001313 }
1314}
1315
Tobin Ehlis502480b2015-06-24 15:53:07 -06001316TEST_F(VkLayerTest, BindPipelineNoRenderPass)
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06001317{
1318 // Initiate Draw w/o a PSO bound
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06001319 VkResult err;
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06001320
Courtney Goeltzenleuchterfd4830c2015-11-25 10:30:56 -07001321 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06001322 "Incorrectly binding graphics pipeline ");
1323
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06001324 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06001325 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06001326
Chia-I Wu1b99bb22015-10-27 19:25:11 +08001327 VkDescriptorPoolSize ds_type_count = {};
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06001328 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wud50a7d72015-10-26 20:48:51 +08001329 ds_type_count.descriptorCount = 1;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06001330
1331 VkDescriptorPoolCreateInfo ds_pool_ci = {};
1332 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
1333 ds_pool_ci.pNext = NULL;
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -06001334 ds_pool_ci.maxSets = 1;
Chia-I Wu1b99bb22015-10-27 19:25:11 +08001335 ds_pool_ci.poolSizeCount = 1;
1336 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06001337
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -06001338 VkDescriptorPool ds_pool;
Chia-I Wuf7458c52015-10-26 21:10:41 +08001339 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06001340 ASSERT_VK_SUCCESS(err);
1341
1342 VkDescriptorSetLayoutBinding dsl_binding = {};
Chia-I Wud46e6ae2015-10-31 00:31:16 +08001343 dsl_binding.binding = 0;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06001344 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wu02124482015-11-06 06:42:02 +08001345 dsl_binding.descriptorCount = 1;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06001346 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
1347 dsl_binding.pImmutableSamplers = NULL;
1348
1349 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
1350 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
1351 ds_layout_ci.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08001352 ds_layout_ci.bindingCount = 1;
Chia-I Wua745e512015-10-31 00:31:16 +08001353 ds_layout_ci.pBinding = &dsl_binding;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06001354
1355 VkDescriptorSetLayout ds_layout;
Chia-I Wuf7458c52015-10-26 21:10:41 +08001356 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06001357 ASSERT_VK_SUCCESS(err);
1358
1359 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001360 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08001361 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Chia-I Wud50a7d72015-10-26 20:48:51 +08001362 alloc_info.setLayoutCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06001363 alloc_info.descriptorPool = ds_pool;
1364 alloc_info.pSetLayouts = &ds_layout;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001365 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06001366 ASSERT_VK_SUCCESS(err);
1367 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
1368 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
1369 pipe_ms_state_ci.pNext = NULL;
Chia-I Wu5c17c962015-10-31 00:31:16 +08001370 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06001371 pipe_ms_state_ci.sampleShadingEnable = 0;
1372 pipe_ms_state_ci.minSampleShading = 1.0;
1373 pipe_ms_state_ci.pSampleMask = NULL;
1374
1375 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
1376 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
1377 pipeline_layout_ci.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08001378 pipeline_layout_ci.setLayoutCount = 1;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06001379 pipeline_layout_ci.pSetLayouts = &ds_layout;
1380 VkPipelineLayout pipeline_layout;
1381
Chia-I Wuf7458c52015-10-26 21:10:41 +08001382 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06001383 ASSERT_VK_SUCCESS(err);
1384
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06001385 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
1386 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this); // TODO - We shouldn't need a fragment shader
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06001387 // but add it to be able to run on more devices
1388 VkPipelineObj pipe(m_device);
1389 pipe.AddShader(&vs);
1390 pipe.AddShader(&fs);
1391 pipe.SetMSAA(&pipe_ms_state_ci);
1392 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06001393
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001394 // Calls AllocateCommandBuffers
1395 VkCommandBufferObj commandBuffer(m_device, m_commandPool);
1396 VkCommandBufferBeginInfo cmd_buf_info = {};
1397 memset(&cmd_buf_info, 0, sizeof(VkCommandBufferBeginInfo));
1398 cmd_buf_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06001399 cmd_buf_info.pNext = NULL;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001400 cmd_buf_info.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06001401
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001402 vkBeginCommandBuffer(commandBuffer.GetBufferHandle(), &cmd_buf_info);
1403 vkCmdBindPipeline(commandBuffer.GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06001404
1405 if (!m_errorMonitor->DesiredMsgFound()) {
1406 FAIL() << "Did not receive Error 'Incorrectly binding graphics pipeline (0x<handle>) without an active RenderPass'";
1407 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06001408 }
Mike Stroyand1c84a52015-08-18 14:40:24 -06001409
Chia-I Wuf7458c52015-10-26 21:10:41 +08001410 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
1411 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
1412 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06001413}
1414
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06001415TEST_F(VkLayerTest, AllocDescriptorFromEmptyPool)
1416{
1417 // Initiate Draw w/o a PSO bound
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06001418 VkResult err;
1419
Courtney Goeltzenleuchterfd4830c2015-11-25 10:30:56 -07001420 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06001421 "Unable to allocate 1 descriptors of type VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER ");
1422
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06001423 ASSERT_NO_FATAL_FAILURE(InitState());
1424 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06001425
1426 // Create Pool w/ 1 Sampler descriptor, but try to alloc Uniform Buffer descriptor from it
Chia-I Wu1b99bb22015-10-27 19:25:11 +08001427 VkDescriptorPoolSize ds_type_count = {};
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06001428 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLER;
Chia-I Wud50a7d72015-10-26 20:48:51 +08001429 ds_type_count.descriptorCount = 1;
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06001430
1431 VkDescriptorPoolCreateInfo ds_pool_ci = {};
1432 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
1433 ds_pool_ci.pNext = NULL;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06001434 ds_pool_ci.flags = 0;
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06001435 ds_pool_ci.maxSets = 1;
Chia-I Wu1b99bb22015-10-27 19:25:11 +08001436 ds_pool_ci.poolSizeCount = 1;
1437 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06001438
1439 VkDescriptorPool ds_pool;
Chia-I Wuf7458c52015-10-26 21:10:41 +08001440 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06001441 ASSERT_VK_SUCCESS(err);
1442
1443 VkDescriptorSetLayoutBinding dsl_binding = {};
Chia-I Wud46e6ae2015-10-31 00:31:16 +08001444 dsl_binding.binding = 0;
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06001445 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wu02124482015-11-06 06:42:02 +08001446 dsl_binding.descriptorCount = 1;
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06001447 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
1448 dsl_binding.pImmutableSamplers = NULL;
1449
1450 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
1451 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
1452 ds_layout_ci.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08001453 ds_layout_ci.bindingCount = 1;
Chia-I Wua745e512015-10-31 00:31:16 +08001454 ds_layout_ci.pBinding = &dsl_binding;
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06001455
1456 VkDescriptorSetLayout ds_layout;
Chia-I Wuf7458c52015-10-26 21:10:41 +08001457 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06001458 ASSERT_VK_SUCCESS(err);
1459
1460 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001461 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08001462 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Chia-I Wud50a7d72015-10-26 20:48:51 +08001463 alloc_info.setLayoutCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06001464 alloc_info.descriptorPool = ds_pool;
1465 alloc_info.pSetLayouts = &ds_layout;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001466 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06001467
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06001468 if (!m_errorMonitor->DesiredMsgFound()) {
1469 FAIL() << "Did not receive Error 'Unable to allocate 1 descriptors of type VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER...'";
1470 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06001471 }
1472
Chia-I Wuf7458c52015-10-26 21:10:41 +08001473 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
1474 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06001475}
1476
Tobin Ehlise735c692015-10-08 13:13:50 -06001477TEST_F(VkLayerTest, FreeDescriptorFromOneShotPool)
1478{
Tobin Ehlise735c692015-10-08 13:13:50 -06001479 VkResult err;
1480
Courtney Goeltzenleuchterfd4830c2015-11-25 10:30:56 -07001481 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06001482 "It is invalid to call vkFreeDescriptorSets() with a pool created without setting VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT.");
1483
Tobin Ehlise735c692015-10-08 13:13:50 -06001484 ASSERT_NO_FATAL_FAILURE(InitState());
1485 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlise735c692015-10-08 13:13:50 -06001486
Chia-I Wu1b99bb22015-10-27 19:25:11 +08001487 VkDescriptorPoolSize ds_type_count = {};
Tobin Ehlise735c692015-10-08 13:13:50 -06001488 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wud50a7d72015-10-26 20:48:51 +08001489 ds_type_count.descriptorCount = 1;
Tobin Ehlise735c692015-10-08 13:13:50 -06001490
1491 VkDescriptorPoolCreateInfo ds_pool_ci = {};
1492 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
1493 ds_pool_ci.pNext = NULL;
Tobin Ehlise735c692015-10-08 13:13:50 -06001494 ds_pool_ci.maxSets = 1;
Chia-I Wu1b99bb22015-10-27 19:25:11 +08001495 ds_pool_ci.poolSizeCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06001496 ds_pool_ci.flags = 0;
1497 // Not specifying VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT means
1498 // app can only call vkResetDescriptorPool on this pool.;
Chia-I Wu1b99bb22015-10-27 19:25:11 +08001499 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlise735c692015-10-08 13:13:50 -06001500
1501 VkDescriptorPool ds_pool;
Chia-I Wuf7458c52015-10-26 21:10:41 +08001502 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlise735c692015-10-08 13:13:50 -06001503 ASSERT_VK_SUCCESS(err);
1504
1505 VkDescriptorSetLayoutBinding dsl_binding = {};
Chia-I Wud46e6ae2015-10-31 00:31:16 +08001506 dsl_binding.binding = 0;
Tobin Ehlise735c692015-10-08 13:13:50 -06001507 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wu02124482015-11-06 06:42:02 +08001508 dsl_binding.descriptorCount = 1;
Tobin Ehlise735c692015-10-08 13:13:50 -06001509 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
1510 dsl_binding.pImmutableSamplers = NULL;
1511
1512 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
1513 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
1514 ds_layout_ci.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08001515 ds_layout_ci.bindingCount = 1;
Chia-I Wua745e512015-10-31 00:31:16 +08001516 ds_layout_ci.pBinding = &dsl_binding;
Tobin Ehlise735c692015-10-08 13:13:50 -06001517
1518 VkDescriptorSetLayout ds_layout;
Chia-I Wuf7458c52015-10-26 21:10:41 +08001519 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlise735c692015-10-08 13:13:50 -06001520 ASSERT_VK_SUCCESS(err);
1521
1522 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001523 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08001524 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Chia-I Wud50a7d72015-10-26 20:48:51 +08001525 alloc_info.setLayoutCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06001526 alloc_info.descriptorPool = ds_pool;
1527 alloc_info.pSetLayouts = &ds_layout;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001528 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlise735c692015-10-08 13:13:50 -06001529 ASSERT_VK_SUCCESS(err);
1530
1531 err = vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptorSet);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06001532 if (!m_errorMonitor->DesiredMsgFound()) {
1533 FAIL() << "Did not receive Error 'It is invalid to call vkFreeDescriptorSets() with a pool created with...'";
1534 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlise735c692015-10-08 13:13:50 -06001535 }
1536
Chia-I Wuf7458c52015-10-26 21:10:41 +08001537 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
1538 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlise735c692015-10-08 13:13:50 -06001539}
1540
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06001541TEST_F(VkLayerTest, InvalidDescriptorPool)
1542{
1543 // TODO : Simple check for bad object should be added to ObjectTracker to catch this case
1544 // The DS check for this is after driver has been called to validate DS internal data struct
1545 // Attempt to clear DS Pool with bad object
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06001546/*
Courtney Goeltzenleuchterfd4830c2015-11-25 10:30:56 -07001547 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06001548 "Unable to find pool node for pool 0xbaad6001 specified in vkResetDescriptorPool() call");
1549
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06001550 VkDescriptorPool badPool = (VkDescriptorPool)0xbaad6001;
1551 vkResetDescriptorPool(device(), badPool);
1552
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06001553 if (!m_errorMonitor->DesiredMsgFound()) {
1554 FAIL() << "Did not receive Error 'Unable to find pool node for pool 0xbaad6001 specified in vkResetDescriptorPool() call'";
1555 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06001556 }*/
1557}
1558
1559TEST_F(VkLayerTest, InvalidDescriptorSet)
1560{
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06001561 // TODO : Simple check for bad object should be added to ObjectTracker to catch this case
1562 // The DS check for this is after driver has been called to validate DS internal data struct
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06001563 // Create a valid cmd buffer
1564 // call vkCmdBindDescriptorSets w/ false DS
1565}
1566
1567TEST_F(VkLayerTest, InvalidDescriptorSetLayout)
1568{
1569 // TODO : Simple check for bad object should be added to ObjectTracker to catch this case
1570 // The DS check for this is after driver has been called to validate DS internal data struct
1571}
1572
1573TEST_F(VkLayerTest, InvalidPipeline)
1574{
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06001575 // TODO : Simple check for bad object should be added to ObjectTracker to catch this case
1576 // The DS check for this is after driver has been called to validate DS internal data struct
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06001577 // Create a valid cmd buffer
1578 // call vkCmdBindPipeline w/ false Pipeline
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06001579//
Courtney Goeltzenleuchterfd4830c2015-11-25 10:30:56 -07001580// m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06001581// "Attempt to bind Pipeline ");
Tobin Ehlis502480b2015-06-24 15:53:07 -06001582//
1583// ASSERT_NO_FATAL_FAILURE(InitState());
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001584// VkCommandBufferObj commandBuffer(m_device);
Tony Barbourfe3351b2015-07-28 10:17:20 -06001585// BeginCommandBuffer();
Tobin Ehlis502480b2015-06-24 15:53:07 -06001586// VkPipeline badPipeline = (VkPipeline)0xbaadb1be;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001587// vkCmdBindPipeline(commandBuffer.GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, badPipeline);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06001588//
1589// if (!m_errorMonitor->DesiredMsgFound()) {
1590// FAIL() << "Did not receive Error 'Attempt to bind Pipeline 0xbaadb1be that doesn't exist!'";
1591// m_errorMonitor->DumpFailureMsgs();
Tobin Ehlis502480b2015-06-24 15:53:07 -06001592// }
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06001593}
1594
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06001595TEST_F(VkLayerTest, DescriptorSetNotUpdated)
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06001596{
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001597 // Create and update CommandBuffer then call QueueSubmit w/o calling End on CommandBuffer
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06001598 VkResult err;
1599
Courtney Goeltzenleuchterfd4830c2015-11-25 10:30:56 -07001600 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARN_BIT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06001601 " bound but it was never updated. ");
1602
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06001603 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyan713b2d72015-08-04 10:49:29 -06001604 ASSERT_NO_FATAL_FAILURE(InitViewport());
1605 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chia-I Wu1b99bb22015-10-27 19:25:11 +08001606 VkDescriptorPoolSize ds_type_count = {};
Tony Barboureb254902015-07-15 12:50:33 -06001607 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wud50a7d72015-10-26 20:48:51 +08001608 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06001609
1610 VkDescriptorPoolCreateInfo ds_pool_ci = {};
1611 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
1612 ds_pool_ci.pNext = NULL;
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -06001613 ds_pool_ci.maxSets = 1;
Chia-I Wu1b99bb22015-10-27 19:25:11 +08001614 ds_pool_ci.poolSizeCount = 1;
1615 ds_pool_ci.pPoolSizes = &ds_type_count;
Mike Stroyan713b2d72015-08-04 10:49:29 -06001616
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06001617 VkDescriptorPool ds_pool;
Chia-I Wuf7458c52015-10-26 21:10:41 +08001618 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06001619 ASSERT_VK_SUCCESS(err);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06001620
Tony Barboureb254902015-07-15 12:50:33 -06001621 VkDescriptorSetLayoutBinding dsl_binding = {};
Chia-I Wud46e6ae2015-10-31 00:31:16 +08001622 dsl_binding.binding = 0;
Tony Barboureb254902015-07-15 12:50:33 -06001623 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wu02124482015-11-06 06:42:02 +08001624 dsl_binding.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06001625 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
1626 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06001627
Tony Barboureb254902015-07-15 12:50:33 -06001628 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
1629 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
1630 ds_layout_ci.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08001631 ds_layout_ci.bindingCount = 1;
Chia-I Wua745e512015-10-31 00:31:16 +08001632 ds_layout_ci.pBinding = &dsl_binding;
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06001633 VkDescriptorSetLayout ds_layout;
Chia-I Wuf7458c52015-10-26 21:10:41 +08001634 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06001635 ASSERT_VK_SUCCESS(err);
1636
1637 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001638 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08001639 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Chia-I Wud50a7d72015-10-26 20:48:51 +08001640 alloc_info.setLayoutCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06001641 alloc_info.descriptorPool = ds_pool;
1642 alloc_info.pSetLayouts = &ds_layout;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001643 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06001644 ASSERT_VK_SUCCESS(err);
1645
Tony Barboureb254902015-07-15 12:50:33 -06001646 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
1647 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
1648 pipeline_layout_ci.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08001649 pipeline_layout_ci.setLayoutCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06001650 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06001651
1652 VkPipelineLayout pipeline_layout;
Chia-I Wuf7458c52015-10-26 21:10:41 +08001653 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06001654 ASSERT_VK_SUCCESS(err);
1655
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06001656 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06001657 // TODO - We shouldn't need a fragment shader but add it to be able to run on more devices
1658 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06001659
Tony Barbourc95e4ac2015-08-04 17:05:26 -06001660 VkPipelineObj pipe(m_device);
1661 pipe.AddShader(&vs);
Tony Barbour1c94d372015-08-06 11:21:08 -06001662 pipe.AddShader(&fs);
Tony Barbourc95e4ac2015-08-04 17:05:26 -06001663 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tony Barbourfe3351b2015-07-28 10:17:20 -06001664
1665 BeginCommandBuffer();
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001666 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
1667 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1, &descriptorSet, 0, NULL);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06001668
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06001669 if (!m_errorMonitor->DesiredMsgFound()) {
1670 FAIL() << "Did not recieve Warning 'DS <blah> bound but it was never updated. You may want to either update it or not bind it.'";
1671 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06001672 }
Mike Stroyand1c84a52015-08-18 14:40:24 -06001673
Chia-I Wuf7458c52015-10-26 21:10:41 +08001674 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
1675 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
1676 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06001677}
1678
Tobin Ehlisba31cab2015-11-02 15:24:32 -07001679TEST_F(VkLayerTest, InvalidBufferViewObject)
1680{
1681 // Create a single TEXEL_BUFFER descriptor and send it an invalid bufferView
1682 VkResult err;
1683
Courtney Goeltzenleuchterfd4830c2015-11-25 10:30:56 -07001684 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT,
Tobin Ehlisba31cab2015-11-02 15:24:32 -07001685 "Attempt to update descriptor with invalid bufferView ");
1686
1687 ASSERT_NO_FATAL_FAILURE(InitState());
1688 VkDescriptorPoolSize ds_type_count = {};
1689 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER;
1690 ds_type_count.descriptorCount = 1;
1691
1692 VkDescriptorPoolCreateInfo ds_pool_ci = {};
1693 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
1694 ds_pool_ci.pNext = NULL;
1695 ds_pool_ci.maxSets = 1;
1696 ds_pool_ci.poolSizeCount = 1;
1697 ds_pool_ci.pPoolSizes = &ds_type_count;
1698
1699 VkDescriptorPool ds_pool;
1700 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
1701 ASSERT_VK_SUCCESS(err);
1702
1703 VkDescriptorSetLayoutBinding dsl_binding = {};
1704 dsl_binding.binding = 0;
1705 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER;
Chia-I Wu02124482015-11-06 06:42:02 +08001706 dsl_binding.descriptorCount = 1;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07001707 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
1708 dsl_binding.pImmutableSamplers = NULL;
1709
1710 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
1711 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
1712 ds_layout_ci.pNext = NULL;
1713 ds_layout_ci.bindingCount = 1;
1714 ds_layout_ci.pBinding = &dsl_binding;
1715 VkDescriptorSetLayout ds_layout;
1716 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
1717 ASSERT_VK_SUCCESS(err);
1718
1719 VkDescriptorSet descriptorSet;
1720 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08001721 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07001722 alloc_info.setLayoutCount = 1;
1723 alloc_info.descriptorPool = ds_pool;
1724 alloc_info.pSetLayouts = &ds_layout;
1725 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
1726 ASSERT_VK_SUCCESS(err);
1727
1728 VkBufferView view = (VkBufferView) 0xbaadbeef; // invalid bufferView object
Tobin Ehlisba31cab2015-11-02 15:24:32 -07001729 VkWriteDescriptorSet descriptor_write;
1730 memset(&descriptor_write, 0, sizeof(descriptor_write));
1731 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
1732 descriptor_write.dstSet = descriptorSet;
1733 descriptor_write.dstBinding = 0;
1734 descriptor_write.descriptorCount = 1;
1735 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER;
1736 descriptor_write.pTexelBufferView = &view;
1737
1738 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
1739
1740 if (!m_errorMonitor->DesiredMsgFound()) {
Tobin Ehlis9d80c2d2015-11-05 10:27:49 -07001741 FAIL() << "Did not receive Error 'Attempt to update descriptor with invalid bufferView'";
Tobin Ehlisba31cab2015-11-02 15:24:32 -07001742 m_errorMonitor->DumpFailureMsgs();
1743 }
1744
1745 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
1746 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
1747}
1748
Tobin Ehlis49f903e2015-11-04 13:30:34 -07001749TEST_F(VkLayerTest, InvalidDynamicOffsetCount)
1750{
1751 // Create a descriptorSet w/ some dynamic descriptors and then don't send offsets when binding
1752 VkResult err;
Courtney Goeltzenleuchterfd4830c2015-11-25 10:30:56 -07001753 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT,
Tobin Ehlis49f903e2015-11-04 13:30:34 -07001754 "Attempting to bind 1 descriptorSets with 1 dynamic descriptors, but dynamicOffsetCount is 0. ");
1755
1756 ASSERT_NO_FATAL_FAILURE(InitState());
1757 ASSERT_NO_FATAL_FAILURE(InitViewport());
1758 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
1759
1760 VkDescriptorPoolSize ds_type_count = {};
1761 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
1762 ds_type_count.descriptorCount = 1;
1763
1764 VkDescriptorPoolCreateInfo ds_pool_ci = {};
1765 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
1766 ds_pool_ci.pNext = NULL;
1767 ds_pool_ci.maxSets = 1;
1768 ds_pool_ci.poolSizeCount = 1;
1769 ds_pool_ci.pPoolSizes = &ds_type_count;
1770
1771 VkDescriptorPool ds_pool;
1772 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
1773 ASSERT_VK_SUCCESS(err);
1774
1775 VkDescriptorSetLayoutBinding dsl_binding = {};
1776 dsl_binding.binding = 0;
1777 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
Jon Ashburn4f232582015-11-06 15:31:44 -07001778 dsl_binding.descriptorCount = 1;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07001779 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
1780 dsl_binding.pImmutableSamplers = NULL;
1781
1782 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
1783 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
1784 ds_layout_ci.pNext = NULL;
1785 ds_layout_ci.bindingCount = 1;
1786 ds_layout_ci.pBinding = &dsl_binding;
1787 VkDescriptorSetLayout ds_layout;
1788 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
1789 ASSERT_VK_SUCCESS(err);
1790
1791 VkDescriptorSet descriptorSet;
1792 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08001793 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07001794 alloc_info.setLayoutCount = 1;
1795 alloc_info.descriptorPool = ds_pool;
1796 alloc_info.pSetLayouts = &ds_layout;
1797 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
1798 ASSERT_VK_SUCCESS(err);
1799
1800 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
1801 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
1802 pipeline_layout_ci.pNext = NULL;
1803 pipeline_layout_ci.setLayoutCount = 1;
1804 pipeline_layout_ci.pSetLayouts = &ds_layout;
1805
1806 VkPipelineLayout pipeline_layout;
1807 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
1808 ASSERT_VK_SUCCESS(err);
1809
1810 // Create a buffer to update the descriptor with
1811 uint32_t qfi = 0;
1812 VkBufferCreateInfo buffCI = {};
1813 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
1814 buffCI.size = 1024;
1815 buffCI.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
1816 buffCI.queueFamilyIndexCount = 1;
1817 buffCI.pQueueFamilyIndices = &qfi;
1818
1819 VkBuffer dyub;
1820 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &dyub);
1821 ASSERT_VK_SUCCESS(err);
1822 // Correctly update descriptor to avoid "NOT_UPDATED" error
1823 VkDescriptorBufferInfo buffInfo = {};
1824 buffInfo.buffer = dyub;
1825 buffInfo.offset = 0;
1826 buffInfo.range = 1024;
1827
1828 VkWriteDescriptorSet descriptor_write;
1829 memset(&descriptor_write, 0, sizeof(descriptor_write));
1830 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
1831 descriptor_write.dstSet = descriptorSet;
1832 descriptor_write.dstBinding = 0;
1833 descriptor_write.descriptorCount = 1;
1834 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
1835 descriptor_write.pBufferInfo = &buffInfo;
1836
1837 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
1838
1839 BeginCommandBuffer();
1840 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1, &descriptorSet, 0, NULL);
1841
1842 if (!m_errorMonitor->DesiredMsgFound()) {
1843 FAIL() << "Error received was not 'Attempting to bind 1 descriptorSets with 1 dynamic descriptors, but dynamicOffsetCount is 0...'";
1844 m_errorMonitor->DumpFailureMsgs();
1845 }
1846
1847 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
1848 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
1849}
1850
Tobin Ehlis559c6382015-11-05 09:52:49 -07001851TEST_F(VkLayerTest, DescriptorSetCompatibility)
1852{
1853 // Test various desriptorSet errors with bad binding combinations
1854 VkResult err;
Tobin Ehlis559c6382015-11-05 09:52:49 -07001855
1856 ASSERT_NO_FATAL_FAILURE(InitState());
1857 ASSERT_NO_FATAL_FAILURE(InitViewport());
1858 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
1859
1860 static const uint32_t NUM_DESCRIPTOR_TYPES = 5;
1861 VkDescriptorPoolSize ds_type_count[NUM_DESCRIPTOR_TYPES] = {};
1862 ds_type_count[0].type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07001863 ds_type_count[0].descriptorCount = 10;
Tobin Ehlis559c6382015-11-05 09:52:49 -07001864 ds_type_count[1].type = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
1865 ds_type_count[1].descriptorCount = 2;
1866 ds_type_count[2].type = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE;
1867 ds_type_count[2].descriptorCount = 2;
1868 ds_type_count[3].type = VK_DESCRIPTOR_TYPE_SAMPLER;
1869 ds_type_count[3].descriptorCount = 5;
1870 // TODO : LunarG ILO driver currently asserts in desc.c w/ INPUT_ATTACHMENT type
1871 //ds_type_count[4].type = VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT;
1872 ds_type_count[4].type = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
1873 ds_type_count[4].descriptorCount = 2;
1874
1875 VkDescriptorPoolCreateInfo ds_pool_ci = {};
1876 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
1877 ds_pool_ci.pNext = NULL;
1878 ds_pool_ci.maxSets = 1;
1879 ds_pool_ci.poolSizeCount = NUM_DESCRIPTOR_TYPES;
1880 ds_pool_ci.pPoolSizes = ds_type_count;
1881
1882 VkDescriptorPool ds_pool;
1883 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
1884 ASSERT_VK_SUCCESS(err);
1885
1886 static const uint32_t MAX_DS_TYPES_IN_LAYOUT = 2;
1887 VkDescriptorSetLayoutBinding dsl_binding[MAX_DS_TYPES_IN_LAYOUT] = {};
1888 dsl_binding[0].binding = 0;
1889 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07001890 dsl_binding[0].descriptorCount = 5;
Tobin Ehlis559c6382015-11-05 09:52:49 -07001891 dsl_binding[0].stageFlags = VK_SHADER_STAGE_ALL;
1892 dsl_binding[0].pImmutableSamplers = NULL;
1893
Tobin Ehlis8fab6562015-12-01 09:57:09 -07001894 // Create layout identical to set0 layout but w/ different stageFlags
1895 VkDescriptorSetLayoutBinding dsl_fs_stage_only = {};
1896 dsl_fs_stage_only.binding = 0;
1897 dsl_fs_stage_only.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
1898 dsl_fs_stage_only.descriptorCount = 5;
1899 dsl_fs_stage_only.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT; // Different stageFlags to cause error at bind time
1900 dsl_fs_stage_only.pImmutableSamplers = NULL;
Tobin Ehlis559c6382015-11-05 09:52:49 -07001901 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
1902 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
1903 ds_layout_ci.pNext = NULL;
1904 ds_layout_ci.bindingCount = 1;
1905 ds_layout_ci.pBinding = dsl_binding;
1906 static const uint32_t NUM_LAYOUTS = 4;
1907 VkDescriptorSetLayout ds_layout[NUM_LAYOUTS] = {};
Tobin Ehlis8fab6562015-12-01 09:57:09 -07001908 VkDescriptorSetLayout ds_layout_fs_only = {};
1909 // Create 4 unique layouts for full pipelineLayout, and 1 special fs-only layout for error case
Tobin Ehlis559c6382015-11-05 09:52:49 -07001910 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout[0]);
1911 ASSERT_VK_SUCCESS(err);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07001912 ds_layout_ci.pBinding = &dsl_fs_stage_only;
1913 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout_fs_only);
1914 ASSERT_VK_SUCCESS(err);
Tobin Ehlis559c6382015-11-05 09:52:49 -07001915 dsl_binding[0].binding = 0;
1916 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07001917 dsl_binding[0].descriptorCount = 2;
Tobin Ehlis559c6382015-11-05 09:52:49 -07001918 dsl_binding[0].binding = 1;
1919 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07001920 dsl_binding[0].descriptorCount = 2;
1921 ds_layout_ci.pBinding = dsl_binding;
Tobin Ehlis559c6382015-11-05 09:52:49 -07001922 ds_layout_ci.bindingCount = 2;
1923 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout[1]);
1924 ASSERT_VK_SUCCESS(err);
1925 dsl_binding[0].binding = 0;
1926 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07001927 dsl_binding[0].descriptorCount = 5;
Tobin Ehlis559c6382015-11-05 09:52:49 -07001928 ds_layout_ci.bindingCount = 1;
1929 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout[2]);
1930 ASSERT_VK_SUCCESS(err);
1931 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07001932 dsl_binding[0].descriptorCount = 2;
Tobin Ehlis559c6382015-11-05 09:52:49 -07001933 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout[3]);
1934 ASSERT_VK_SUCCESS(err);
1935
1936 static const uint32_t NUM_SETS = 4;
1937 VkDescriptorSet descriptorSet[NUM_SETS] = {};
1938 VkDescriptorSetAllocateInfo alloc_info = {};
Tobin Ehlis8fab6562015-12-01 09:57:09 -07001939 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Tobin Ehlis559c6382015-11-05 09:52:49 -07001940 alloc_info.setLayoutCount = NUM_LAYOUTS;
1941 alloc_info.descriptorPool = ds_pool;
1942 alloc_info.pSetLayouts = ds_layout;
1943 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, descriptorSet);
1944 ASSERT_VK_SUCCESS(err);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07001945 VkDescriptorSet ds0_fs_only = {};
1946 alloc_info.setLayoutCount = 1;
1947 alloc_info.pSetLayouts = &ds_layout_fs_only;
1948 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &ds0_fs_only);
1949 ASSERT_VK_SUCCESS(err);
Tobin Ehlis559c6382015-11-05 09:52:49 -07001950
1951 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
1952 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
1953 pipeline_layout_ci.pNext = NULL;
1954 pipeline_layout_ci.setLayoutCount = NUM_LAYOUTS;
1955 pipeline_layout_ci.pSetLayouts = ds_layout;
1956
1957 VkPipelineLayout pipeline_layout;
1958 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
1959 ASSERT_VK_SUCCESS(err);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07001960 // Create pipelineLayout with only one setLayout
1961 pipeline_layout_ci.setLayoutCount = 1;
1962 VkPipelineLayout single_pipe_layout;
1963 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &single_pipe_layout);
1964 ASSERT_VK_SUCCESS(err);
1965 // Create pipelineLayout with 2 descriptor setLayout at index 0
1966 pipeline_layout_ci.pSetLayouts = &ds_layout[3];
1967 VkPipelineLayout pipe_layout_one_desc;
1968 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipe_layout_one_desc);
1969 ASSERT_VK_SUCCESS(err);
1970 // Create pipelineLayout with 5 SAMPLER descriptor setLayout at index 0
1971 pipeline_layout_ci.pSetLayouts = &ds_layout[2];
1972 VkPipelineLayout pipe_layout_five_samp;
1973 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipe_layout_five_samp);
1974 ASSERT_VK_SUCCESS(err);
1975 // Create pipelineLayout with UB type, but stageFlags for FS only
1976 pipeline_layout_ci.pSetLayouts = &ds_layout_fs_only;
1977 VkPipelineLayout pipe_layout_fs_only;
1978 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipe_layout_fs_only);
1979 ASSERT_VK_SUCCESS(err);
1980 // Create pipelineLayout w/ incompatible set0 layout, but set1 is fine
1981 VkDescriptorSetLayout pl_bad_s0[2] = {};
1982 pl_bad_s0[0] = ds_layout_fs_only;
1983 pl_bad_s0[1] = ds_layout[1];
1984 pipeline_layout_ci.setLayoutCount = 2;
1985 pipeline_layout_ci.pSetLayouts = pl_bad_s0;
1986 VkPipelineLayout pipe_layout_bad_set0;
1987 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipe_layout_bad_set0);
1988 ASSERT_VK_SUCCESS(err);
Tobin Ehlis559c6382015-11-05 09:52:49 -07001989
1990 // Create a buffer to update the descriptor with
1991 uint32_t qfi = 0;
1992 VkBufferCreateInfo buffCI = {};
1993 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
1994 buffCI.size = 1024;
1995 buffCI.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
1996 buffCI.queueFamilyIndexCount = 1;
1997 buffCI.pQueueFamilyIndices = &qfi;
1998
1999 VkBuffer dyub;
2000 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &dyub);
2001 ASSERT_VK_SUCCESS(err);
2002 // Correctly update descriptor to avoid "NOT_UPDATED" error
2003 static const uint32_t NUM_BUFFS = 5;
2004 VkDescriptorBufferInfo buffInfo[NUM_BUFFS] = {};
2005 for (uint32_t i=0; i<NUM_BUFFS; ++i) {
2006 buffInfo[i].buffer = dyub;
2007 buffInfo[i].offset = 0;
2008 buffInfo[i].range = 1024;
2009 }
Tobin Ehlis8fab6562015-12-01 09:57:09 -07002010 VkImage image;
2011 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
2012 const int32_t tex_width = 32;
2013 const int32_t tex_height = 32;
2014 VkImageCreateInfo image_create_info = {};
2015 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
2016 image_create_info.pNext = NULL;
2017 image_create_info.imageType = VK_IMAGE_TYPE_2D;
2018 image_create_info.format = tex_format;
2019 image_create_info.extent.width = tex_width;
2020 image_create_info.extent.height = tex_height;
2021 image_create_info.extent.depth = 1;
2022 image_create_info.mipLevels = 1;
2023 image_create_info.arrayLayers = 1;
2024 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
2025 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
2026 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
2027 image_create_info.flags = 0;
2028 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
2029 ASSERT_VK_SUCCESS(err);
Tobin Ehlis559c6382015-11-05 09:52:49 -07002030
Tobin Ehlis8fab6562015-12-01 09:57:09 -07002031 VkImageViewCreateInfo image_view_create_info = {};
2032 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
2033 image_view_create_info.image = image;
2034 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
2035 image_view_create_info.format = tex_format;
2036 image_view_create_info.subresourceRange.layerCount = 1;
2037 image_view_create_info.subresourceRange.baseMipLevel = 0;
2038 image_view_create_info.subresourceRange.levelCount = 1;
2039 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Tobin Ehlis559c6382015-11-05 09:52:49 -07002040
Tobin Ehlis8fab6562015-12-01 09:57:09 -07002041 VkImageView view;
2042 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
2043 ASSERT_VK_SUCCESS(err);
2044 VkDescriptorImageInfo imageInfo[2] = {};
2045 imageInfo[0].imageView = view;
2046 imageInfo[0].imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
2047 imageInfo[1].imageView = view;
2048 imageInfo[1].imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
2049
2050 static const uint32_t NUM_SET_UPDATES = 3;
2051 VkWriteDescriptorSet descriptor_write[NUM_SET_UPDATES] = {};
2052 descriptor_write[0].sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
2053 descriptor_write[0].dstSet = descriptorSet[0];
2054 descriptor_write[0].dstBinding = 0;
2055 descriptor_write[0].descriptorCount = 5;
2056 descriptor_write[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
2057 descriptor_write[0].pBufferInfo = buffInfo;
2058 descriptor_write[1].sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
2059 descriptor_write[1].dstSet = descriptorSet[1];
2060 descriptor_write[1].dstBinding = 0;
2061 descriptor_write[1].descriptorCount = 2;
2062 descriptor_write[1].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
2063 descriptor_write[1].pImageInfo = imageInfo;
2064 descriptor_write[2].sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
2065 descriptor_write[2].dstSet = descriptorSet[1];
2066 descriptor_write[2].dstBinding = 1;
2067 descriptor_write[2].descriptorCount = 2;
2068 descriptor_write[2].descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE;
2069 descriptor_write[2].pImageInfo = imageInfo;
2070
2071 vkUpdateDescriptorSets(m_device->device(), 3, descriptor_write, 0, NULL);
Tobin Ehlis559c6382015-11-05 09:52:49 -07002072
Tobin Ehlis88452832015-12-03 09:40:56 -07002073 // Create PSO to be used for draw-time errors below
2074 char const *vsSource =
2075 "#version 140\n"
2076 "#extension GL_ARB_separate_shader_objects: require\n"
2077 "#extension GL_ARB_shading_language_420pack: require\n"
2078 "\n"
2079 "void main(){\n"
2080 " gl_Position = vec4(1);\n"
2081 "}\n";
2082 char const *fsSource =
2083 "#version 140\n"
2084 "#extension GL_ARB_separate_shader_objects: require\n"
2085 "#extension GL_ARB_shading_language_420pack: require\n"
2086 "\n"
2087 "layout(location=0) out vec4 x;\n"
2088 "layout(set=0) layout(binding=0) uniform foo { int x; int y; } bar;\n"
2089 "void main(){\n"
2090 " x = vec4(bar.y);\n"
2091 "}\n";
2092 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
2093 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Tobin Ehlis559c6382015-11-05 09:52:49 -07002094 VkPipelineObj pipe(m_device);
2095 pipe.AddShader(&vs);
2096 pipe.AddShader(&fs);
Tobin Ehlis88452832015-12-03 09:40:56 -07002097 pipe.AddColorAttachment();
2098 pipe.CreateVKPipeline(pipe_layout_fs_only, renderPass());
Tobin Ehlis559c6382015-11-05 09:52:49 -07002099
2100 BeginCommandBuffer();
Tobin Ehlis88452832015-12-03 09:40:56 -07002101
Tobin Ehlis559c6382015-11-05 09:52:49 -07002102 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
2103 // NOTE : I believe LunarG ilo driver has bug (LX#189) that requires binding of PSO
2104 // here before binding DSs. Otherwise we assert in cmd_copy_dset_data() of cmd_pipeline.c
2105 // due to the fact that cmd_alloc_dset_data() has not been called in cmd_bind_graphics_pipeline()
2106 // TODO : Want to cause various binding incompatibility issues here to test DrawState
2107 // First cause various verify_layout_compatibility() fails
2108 // Second disturb early and late sets and verify INFO msgs
Tobin Ehlis8fab6562015-12-01 09:57:09 -07002109 // verify_set_layout_compatibility fail cases:
2110 // 1. invalid VkPipelineLayout (layout) passed into vkCmdBindDescriptorSets
Courtney Goeltzenleuchterfd4830c2015-11-25 10:30:56 -07002111 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT, " due to: invalid VkPipelineLayout ");
Tobin Ehlis8fab6562015-12-01 09:57:09 -07002112 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, (VkPipelineLayout)0xbaadb1be, 0, 1, &descriptorSet[0], 0, NULL);
Tobin Ehlis559c6382015-11-05 09:52:49 -07002113 if (!m_errorMonitor->DesiredMsgFound()) {
Tobin Ehlis8fab6562015-12-01 09:57:09 -07002114 FAIL() << "Did not receive correct error msg when attempting to bind descriptorSets with invalid VkPipelineLayout.";
Tobin Ehlis559c6382015-11-05 09:52:49 -07002115 m_errorMonitor->DumpFailureMsgs();
2116 }
Tobin Ehlis8fab6562015-12-01 09:57:09 -07002117 // 2. layoutIndex exceeds # of layouts in layout
Courtney Goeltzenleuchterfd4830c2015-11-25 10:30:56 -07002118 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT, " attempting to bind set to index 1");
Tobin Ehlis8fab6562015-12-01 09:57:09 -07002119 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, single_pipe_layout, 0, 2, &descriptorSet[0], 0, NULL);
2120 if (!m_errorMonitor->DesiredMsgFound()) {
2121 FAIL() << "Did not receive correct error msg when attempting to bind descriptorSet to index 1 when pipelineLayout only has index 0.";
2122 m_errorMonitor->DumpFailureMsgs();
2123 }
2124 vkDestroyPipelineLayout(m_device->device(), single_pipe_layout, NULL);
2125 // 3. Pipeline setLayout[0] has 2 descriptors, but set being bound has 5 descriptors
Courtney Goeltzenleuchterfd4830c2015-11-25 10:30:56 -07002126 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT, ", but corresponding set being bound has 5 descriptors.");
Tobin Ehlis8fab6562015-12-01 09:57:09 -07002127 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe_layout_one_desc, 0, 1, &descriptorSet[0], 0, NULL);
2128 if (!m_errorMonitor->DesiredMsgFound()) {
2129 FAIL() << "Did not receive correct error msg when attempting to bind descriptorSet w/ 5 descriptors to pipelineLayout with only 2 descriptors.";
2130 m_errorMonitor->DumpFailureMsgs();
2131 }
2132 vkDestroyPipelineLayout(m_device->device(), pipe_layout_one_desc, NULL);
2133 // 4. same # of descriptors but mismatch in type
Courtney Goeltzenleuchterfd4830c2015-11-25 10:30:56 -07002134 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT, " descriptor from pipelineLayout is type 'VK_DESCRIPTOR_TYPE_SAMPLER'");
Tobin Ehlis8fab6562015-12-01 09:57:09 -07002135 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe_layout_five_samp, 0, 1, &descriptorSet[0], 0, NULL);
2136 if (!m_errorMonitor->DesiredMsgFound()) {
2137 FAIL() << "Did not receive correct error msg when attempting to bind UNIFORM_BUFFER descriptorSet to pipelineLayout with overlapping SAMPLER type.";
2138 m_errorMonitor->DumpFailureMsgs();
2139 }
2140 vkDestroyPipelineLayout(m_device->device(), pipe_layout_five_samp, NULL);
2141 // 5. same # of descriptors but mismatch in stageFlags
Courtney Goeltzenleuchterfd4830c2015-11-25 10:30:56 -07002142 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT, " descriptor from pipelineLayout has stageFlags ");
Tobin Ehlis8fab6562015-12-01 09:57:09 -07002143 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe_layout_fs_only, 0, 1, &descriptorSet[0], 0, NULL);
2144 if (!m_errorMonitor->DesiredMsgFound()) {
2145 FAIL() << "Did not receive correct error msg when attempting to bind UNIFORM_BUFFER descriptorSet with ALL stageFlags to pipelineLayout with FS-only stageFlags.";
2146 m_errorMonitor->DumpFailureMsgs();
2147 }
2148 // Cause INFO messages due to disturbing previously bound Sets
2149 // First bind sets 0 & 1
2150 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 2, &descriptorSet[0], 0, NULL);
2151 // 1. Disturb bound set0 by re-binding set1 w/ updated pipelineLayout
Courtney Goeltzenleuchterfd4830c2015-11-25 10:30:56 -07002152 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERF_WARN_BIT, " previously bound as set #0 was disturbed ");
Tobin Ehlis8fab6562015-12-01 09:57:09 -07002153 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe_layout_bad_set0, 1, 1, &descriptorSet[1], 0, NULL);
2154 if (!m_errorMonitor->DesiredMsgFound()) {
2155 FAIL() << "Did not receive correct info msg when binding Set1 w/ pipelineLayout that should disturb Set0.";
2156 m_errorMonitor->DumpFailureMsgs();
2157 }
2158 vkDestroyPipelineLayout(m_device->device(), pipe_layout_bad_set0, NULL);
2159 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 2, &descriptorSet[0], 0, NULL);
2160 // 2. Disturb set after last bound set
Courtney Goeltzenleuchterfd4830c2015-11-25 10:30:56 -07002161 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERF_WARN_BIT, " newly bound as set #0 so set #1 and any subsequent sets were disturbed ");
Tobin Ehlis8fab6562015-12-01 09:57:09 -07002162 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe_layout_fs_only, 0, 1, &ds0_fs_only, 0, NULL);
2163 if (!m_errorMonitor->DesiredMsgFound()) {
2164 FAIL() << "Did not receive correct info msg when re-binding Set0 w/ pipelineLayout that should disturb Set1.";
2165 m_errorMonitor->DumpFailureMsgs();
2166 }
Tobin Ehlis88452832015-12-03 09:40:56 -07002167
2168 // Cause draw-time errors due to PSO incompatibilities
2169 // 1. Error due to not binding required set (we actually use same code as above to disturb set0)
2170 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 2, &descriptorSet[0], 0, NULL);
2171 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe_layout_bad_set0, 1, 1, &descriptorSet[1], 0, NULL);
Courtney Goeltzenleuchterfd4830c2015-11-25 10:30:56 -07002172 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT, " uses set #0 but that set is not bound.");
Tobin Ehlis88452832015-12-03 09:40:56 -07002173 Draw(1, 0, 0, 0);
2174 if (!m_errorMonitor->DesiredMsgFound()) {
2175 FAIL() << "Did not receive correct error msg when attempting draw requiring Set0 but Set0 is not bound.";
2176 m_errorMonitor->DumpFailureMsgs();
2177 }
2178 // 2. Error due to bound set not being compatible with PSO's VkPipelineLayout (diff stageFlags in this case)
2179 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 2, &descriptorSet[0], 0, NULL);
Courtney Goeltzenleuchterfd4830c2015-11-25 10:30:56 -07002180 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT, " bound as set #0 is not compatible with ");
Tobin Ehlis88452832015-12-03 09:40:56 -07002181 Draw(1, 0, 0, 0);
2182 if (!m_errorMonitor->DesiredMsgFound()) {
2183 FAIL() << "Did not receive correct error msg when attempted draw where bound Set0 layout is not compatible PSO Set0 layout.";
2184 m_errorMonitor->DumpFailureMsgs();
2185 }
Tobin Ehlis8fab6562015-12-01 09:57:09 -07002186 // Remaining clean-up
2187 vkDestroyPipelineLayout(m_device->device(), pipe_layout_fs_only, NULL);
2188 for (uint32_t i=0; i<NUM_LAYOUTS; ++i) {
2189 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout[i], NULL);
2190 }
2191 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout_fs_only, NULL);
2192 vkFreeDescriptorSets(m_device->device(), ds_pool, 1, descriptorSet);
2193 vkDestroyBuffer(m_device->device(), dyub, NULL);
Tobin Ehlis559c6382015-11-05 09:52:49 -07002194 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
2195 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
2196}
Tobin Ehlis559c6382015-11-05 09:52:49 -07002197
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002198TEST_F(VkLayerTest, NoBeginCommandBuffer)
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06002199{
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002200
Courtney Goeltzenleuchterfd4830c2015-11-25 10:30:56 -07002201 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002202 "You must call vkBeginCommandBuffer() before this call to ");
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06002203
2204 ASSERT_NO_FATAL_FAILURE(InitState());
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002205 VkCommandBufferObj commandBuffer(m_device, m_commandPool);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06002206 // Call EndCommandBuffer() w/o calling BeginCommandBuffer()
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002207 vkEndCommandBuffer(commandBuffer.GetBufferHandle());
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002208
2209 if (!m_errorMonitor->DesiredMsgFound()) {
2210 FAIL() << "Did not recieve Error 'You must call vkBeginCommandBuffer() before this call to vkEndCommandBuffer()'";
2211 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06002212 }
2213}
2214
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002215TEST_F(VkLayerTest, PrimaryCommandBufferFramebufferAndRenderpass)
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06002216{
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002217
Courtney Goeltzenleuchterfd4830c2015-11-25 10:30:56 -07002218 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002219 "may not specify framebuffer or renderpass parameters");
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06002220
2221 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06002222
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002223 // Calls AllocateCommandBuffers
2224 VkCommandBufferObj commandBuffer(m_device, m_commandPool);
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06002225
2226 // Force the failure by setting the Renderpass and Framebuffer fields with (fake) data
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002227 VkCommandBufferBeginInfo cmd_buf_info = {};
2228 cmd_buf_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
Cody Northropb4569702015-08-04 17:35:57 -06002229 cmd_buf_info.pNext = NULL;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002230 cmd_buf_info.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT;
Cody Northropb4569702015-08-04 17:35:57 -06002231 cmd_buf_info.renderPass = (VkRenderPass)0xcadecade;
2232 cmd_buf_info.framebuffer = (VkFramebuffer)0xcadecade;
2233
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06002234
2235 // The error should be caught by validation of the BeginCommandBuffer call
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002236 vkBeginCommandBuffer(commandBuffer.GetBufferHandle(), &cmd_buf_info);
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06002237
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002238 if (!m_errorMonitor->DesiredMsgFound()) {
2239 FAIL() << "Did not receive Error 'vkAllocateCommandBuffers(): Primary Command Buffer may not specify framebuffer or renderpass parameters'";
2240 m_errorMonitor->DumpFailureMsgs();
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06002241 }
2242}
2243
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002244TEST_F(VkLayerTest, SecondaryCommandBufferFramebufferAndRenderpass)
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06002245{
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06002246 VkResult err;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002247 VkCommandBuffer draw_cmd;
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06002248
Courtney Goeltzenleuchterfd4830c2015-11-25 10:30:56 -07002249 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002250 "must specify framebuffer and renderpass parameters");
2251
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06002252 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06002253
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002254 VkCommandBufferAllocateInfo cmd = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08002255 cmd.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
Cody Northropb4569702015-08-04 17:35:57 -06002256 cmd.pNext = NULL;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002257 cmd.commandPool = m_commandPool;
2258 cmd.level = VK_COMMAND_BUFFER_LEVEL_SECONDARY;
Chia-I Wud50a7d72015-10-26 20:48:51 +08002259 cmd.bufferCount = 1;
Cody Northropb4569702015-08-04 17:35:57 -06002260
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002261 err = vkAllocateCommandBuffers(m_device->device(), &cmd, &draw_cmd);
Mike Stroyand1c84a52015-08-18 14:40:24 -06002262 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06002263
2264 // Force the failure by not setting the Renderpass and Framebuffer fields
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002265 VkCommandBufferBeginInfo cmd_buf_info = {};
2266 cmd_buf_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
Cody Northropb4569702015-08-04 17:35:57 -06002267 cmd_buf_info.pNext = NULL;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002268 cmd_buf_info.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT;
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06002269
2270 // The error should be caught by validation of the BeginCommandBuffer call
2271 vkBeginCommandBuffer(draw_cmd, &cmd_buf_info);
2272
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002273 if (!m_errorMonitor->DesiredMsgFound()) {
2274 FAIL() << "Did not receive Error 'vkAllocateCommandBuffers(): Secondary Command Buffer must specify framebuffer and renderpass parameters'";
2275 m_errorMonitor->DumpFailureMsgs();
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06002276 }
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002277 vkFreeCommandBuffers(m_device->device(), m_commandPool, 1, &draw_cmd);
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06002278}
2279
Tobin Ehlisac0ef842015-12-14 13:46:38 -07002280TEST_F(VkLayerTest, CommandBufferResetErrors)
2281{
2282 // Cause error due to Begin while recording CB
2283 // Then cause 2 errors for attempting to reset CB w/o having
2284 // VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT set for the pool from
2285 // which CBs were allocated. Note that this bit is off by default.
Courtney Goeltzenleuchterfd4830c2015-11-25 10:30:56 -07002286 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT,
Tobin Ehlisac0ef842015-12-14 13:46:38 -07002287 "Cannot call Begin on CB");
2288
2289 ASSERT_NO_FATAL_FAILURE(InitState());
2290
2291 // Calls AllocateCommandBuffers
2292 VkCommandBufferObj commandBuffer(m_device, m_commandPool);
2293
2294 // Force the failure by setting the Renderpass and Framebuffer fields with (fake) data
2295 VkCommandBufferBeginInfo cmd_buf_info = {};
2296 cmd_buf_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
2297 cmd_buf_info.pNext = NULL;
2298 cmd_buf_info.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT;
2299
2300 // Begin CB to transition to recording state
2301 vkBeginCommandBuffer(commandBuffer.GetBufferHandle(), &cmd_buf_info);
2302 // Can't re-begin. This should trigger error
2303 vkBeginCommandBuffer(commandBuffer.GetBufferHandle(), &cmd_buf_info);
2304 if (!m_errorMonitor->DesiredMsgFound()) {
2305 FAIL() << "Did not receive Error 'Cannot call Begin on CB (0x<ADDR>) in the RECORDING state...'";
2306 m_errorMonitor->DumpFailureMsgs();
2307 }
Courtney Goeltzenleuchterfd4830c2015-11-25 10:30:56 -07002308 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT, "Attempt to reset command buffer ");
Tobin Ehlisac0ef842015-12-14 13:46:38 -07002309 VkCommandBufferResetFlags flags = 0; // Don't care about flags for this test
2310 // Reset attempt will trigger error due to incorrect CommandPool state
2311 vkResetCommandBuffer(commandBuffer.GetBufferHandle(), flags);
2312 if (!m_errorMonitor->DesiredMsgFound()) {
2313 FAIL() << "Did not receive Error 'Attempt to reset command buffer (0x<ADDR>) created from command pool...'";
2314 m_errorMonitor->DumpFailureMsgs();
2315 }
Courtney Goeltzenleuchterfd4830c2015-11-25 10:30:56 -07002316 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT, " attempts to implicitly reset cmdBuffer created from ");
Tobin Ehlisac0ef842015-12-14 13:46:38 -07002317 // Transition CB to RECORDED state
2318 vkEndCommandBuffer(commandBuffer.GetBufferHandle());
2319 // Now attempting to Begin will implicitly reset, which triggers error
2320 vkBeginCommandBuffer(commandBuffer.GetBufferHandle(), &cmd_buf_info);
2321 if (!m_errorMonitor->DesiredMsgFound()) {
2322 FAIL() << "Did not receive Error 'Call to vkBeginCommandBuffer() on command buffer (0x<ADDR>) attempts to implicitly reset...'";
2323 m_errorMonitor->DumpFailureMsgs();
2324 }
2325}
2326
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06002327TEST_F(VkLayerTest, InvalidPipelineCreateState)
2328{
2329 // Attempt to Create Gfx Pipeline w/o a VS
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06002330 VkResult err;
2331
Courtney Goeltzenleuchterfd4830c2015-11-25 10:30:56 -07002332 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002333 "Invalid Pipeline CreateInfo State: Vtx Shader required");
2334
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06002335 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002336 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinski209b5292015-09-17 09:44:05 -06002337
Chia-I Wu1b99bb22015-10-27 19:25:11 +08002338 VkDescriptorPoolSize ds_type_count = {};
Tony Barboureb254902015-07-15 12:50:33 -06002339 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wud50a7d72015-10-26 20:48:51 +08002340 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06002341
2342 VkDescriptorPoolCreateInfo ds_pool_ci = {};
2343 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
2344 ds_pool_ci.pNext = NULL;
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -06002345 ds_pool_ci.maxSets = 1;
Chia-I Wu1b99bb22015-10-27 19:25:11 +08002346 ds_pool_ci.poolSizeCount = 1;
2347 ds_pool_ci.pPoolSizes = &ds_type_count;
Mark Lobodzinski209b5292015-09-17 09:44:05 -06002348
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06002349 VkDescriptorPool ds_pool;
Chia-I Wuf7458c52015-10-26 21:10:41 +08002350 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06002351 ASSERT_VK_SUCCESS(err);
2352
Tony Barboureb254902015-07-15 12:50:33 -06002353 VkDescriptorSetLayoutBinding dsl_binding = {};
Chia-I Wud46e6ae2015-10-31 00:31:16 +08002354 dsl_binding.binding = 0;
Tony Barboureb254902015-07-15 12:50:33 -06002355 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wu02124482015-11-06 06:42:02 +08002356 dsl_binding.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06002357 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
2358 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06002359
Tony Barboureb254902015-07-15 12:50:33 -06002360 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
2361 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
2362 ds_layout_ci.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08002363 ds_layout_ci.bindingCount = 1;
Chia-I Wua745e512015-10-31 00:31:16 +08002364 ds_layout_ci.pBinding = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -06002365
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06002366 VkDescriptorSetLayout ds_layout;
Chia-I Wuf7458c52015-10-26 21:10:41 +08002367 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06002368 ASSERT_VK_SUCCESS(err);
2369
2370 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002371 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08002372 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Chia-I Wud50a7d72015-10-26 20:48:51 +08002373 alloc_info.setLayoutCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06002374 alloc_info.descriptorPool = ds_pool;
2375 alloc_info.pSetLayouts = &ds_layout;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002376 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06002377 ASSERT_VK_SUCCESS(err);
2378
Tony Barboureb254902015-07-15 12:50:33 -06002379 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
2380 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
Chia-I Wud50a7d72015-10-26 20:48:51 +08002381 pipeline_layout_ci.setLayoutCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06002382 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06002383
2384 VkPipelineLayout pipeline_layout;
Chia-I Wuf7458c52015-10-26 21:10:41 +08002385 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06002386 ASSERT_VK_SUCCESS(err);
2387
Tobin Ehlise68360f2015-10-01 11:15:13 -06002388 VkViewport vp = {}; // Just need dummy vp to point to
2389 VkRect2D sc = {}; // dummy scissor to point to
2390
2391 VkPipelineViewportStateCreateInfo vp_state_ci = {};
2392 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
2393 vp_state_ci.scissorCount = 1;
2394 vp_state_ci.pScissors = &sc;
2395 vp_state_ci.viewportCount = 1;
2396 vp_state_ci.pViewports = &vp;
2397
Tony Barboureb254902015-07-15 12:50:33 -06002398 VkGraphicsPipelineCreateInfo gp_ci = {};
2399 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
Tobin Ehlise68360f2015-10-01 11:15:13 -06002400 gp_ci.pViewportState = &vp_state_ci;
Tony Barboureb254902015-07-15 12:50:33 -06002401 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
2402 gp_ci.layout = pipeline_layout;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002403 gp_ci.renderPass = renderPass();
Tony Barboureb254902015-07-15 12:50:33 -06002404
2405 VkPipelineCacheCreateInfo pc_ci = {};
2406 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
Chia-I Wu2bfb33c2015-10-26 17:24:52 +08002407 pc_ci.initialDataSize = 0;
2408 pc_ci.pInitialData = 0;
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06002409
2410 VkPipeline pipeline;
Jon Ashburnc669cc62015-07-09 15:02:25 -06002411 VkPipelineCache pipelineCache;
2412
Chia-I Wuf7458c52015-10-26 21:10:41 +08002413 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Jon Ashburnc669cc62015-07-09 15:02:25 -06002414 ASSERT_VK_SUCCESS(err);
Chia-I Wuf7458c52015-10-26 21:10:41 +08002415 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06002416
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002417 if (!m_errorMonitor->DesiredMsgFound()) {
2418 FAIL() << "Did not receive Error 'Invalid Pipeline CreateInfo State: Vtx Shader required'";
2419 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06002420 }
Mike Stroyand1c84a52015-08-18 14:40:24 -06002421
Chia-I Wuf7458c52015-10-26 21:10:41 +08002422 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
2423 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
2424 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
2425 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06002426}
Tobin Ehlis912df022015-09-17 08:46:18 -06002427/*// TODO : This test should be good, but needs Tess support in compiler to run
2428TEST_F(VkLayerTest, InvalidPatchControlPoints)
2429{
2430 // Attempt to Create Gfx Pipeline w/o a VS
Tobin Ehlis912df022015-09-17 08:46:18 -06002431 VkResult err;
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06002432
Courtney Goeltzenleuchterfd4830c2015-11-25 10:30:56 -07002433 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002434 "Invalid Pipeline CreateInfo State: VK_PRIMITIVE_TOPOLOGY_PATCH primitive ");
2435
Tobin Ehlis912df022015-09-17 08:46:18 -06002436 ASSERT_NO_FATAL_FAILURE(InitState());
2437 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlis912df022015-09-17 08:46:18 -06002438
Chia-I Wu1b99bb22015-10-27 19:25:11 +08002439 VkDescriptorPoolSize ds_type_count = {};
Tobin Ehlis912df022015-09-17 08:46:18 -06002440 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wud50a7d72015-10-26 20:48:51 +08002441 ds_type_count.descriptorCount = 1;
Tobin Ehlis912df022015-09-17 08:46:18 -06002442
2443 VkDescriptorPoolCreateInfo ds_pool_ci = {};
2444 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
2445 ds_pool_ci.pNext = NULL;
Chia-I Wu1b99bb22015-10-27 19:25:11 +08002446 ds_pool_ci.poolSizeCount = 1;
2447 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlis912df022015-09-17 08:46:18 -06002448
2449 VkDescriptorPool ds_pool;
Chia-I Wuf7458c52015-10-26 21:10:41 +08002450 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 -06002451 ASSERT_VK_SUCCESS(err);
2452
2453 VkDescriptorSetLayoutBinding dsl_binding = {};
Chia-I Wud46e6ae2015-10-31 00:31:16 +08002454 dsl_binding.binding = 0;
Tobin Ehlis912df022015-09-17 08:46:18 -06002455 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wu02124482015-11-06 06:42:02 +08002456 dsl_binding.descriptorCount = 1;
Tobin Ehlis912df022015-09-17 08:46:18 -06002457 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
2458 dsl_binding.pImmutableSamplers = NULL;
2459
2460 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
2461 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
2462 ds_layout_ci.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08002463 ds_layout_ci.bindingCount = 1;
Chia-I Wua745e512015-10-31 00:31:16 +08002464 ds_layout_ci.pBinding = &dsl_binding;
Tobin Ehlis912df022015-09-17 08:46:18 -06002465
2466 VkDescriptorSetLayout ds_layout;
Chia-I Wuf7458c52015-10-26 21:10:41 +08002467 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis912df022015-09-17 08:46:18 -06002468 ASSERT_VK_SUCCESS(err);
2469
2470 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002471 err = vkAllocateDescriptorSets(m_device->device(), ds_pool, VK_DESCRIPTOR_SET_USAGE_NON_FREE, 1, &ds_layout, &descriptorSet);
Tobin Ehlis912df022015-09-17 08:46:18 -06002472 ASSERT_VK_SUCCESS(err);
2473
2474 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
2475 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
2476 pipeline_layout_ci.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08002477 pipeline_layout_ci.setLayoutCount = 1;
Tobin Ehlis912df022015-09-17 08:46:18 -06002478 pipeline_layout_ci.pSetLayouts = &ds_layout;
2479
2480 VkPipelineLayout pipeline_layout;
Chia-I Wuf7458c52015-10-26 21:10:41 +08002481 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis912df022015-09-17 08:46:18 -06002482 ASSERT_VK_SUCCESS(err);
2483
2484 VkPipelineShaderStageCreateInfo shaderStages[3];
2485 memset(&shaderStages, 0, 3 * sizeof(VkPipelineShaderStageCreateInfo));
2486
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06002487 VkShaderObj vs(m_device,bindStateVertShaderText,VK_SHADER_STAGE_VERTEX_BIT, this);
Tobin Ehlis912df022015-09-17 08:46:18 -06002488 // Just using VS txt for Tess shaders as we don't care about functionality
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06002489 VkShaderObj tc(m_device,bindStateVertShaderText,VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT, this);
2490 VkShaderObj te(m_device,bindStateVertShaderText,VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT, this);
Tobin Ehlis912df022015-09-17 08:46:18 -06002491
2492 shaderStages[0].sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06002493 shaderStages[0].stage = VK_SHADER_STAGE_VERTEX_BIT;
Tobin Ehlis912df022015-09-17 08:46:18 -06002494 shaderStages[0].shader = vs.handle();
2495 shaderStages[1].sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06002496 shaderStages[1].stage = VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT;
Tobin Ehlis912df022015-09-17 08:46:18 -06002497 shaderStages[1].shader = tc.handle();
2498 shaderStages[2].sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06002499 shaderStages[2].stage = VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT;
Tobin Ehlis912df022015-09-17 08:46:18 -06002500 shaderStages[2].shader = te.handle();
2501
2502 VkPipelineInputAssemblyStateCreateInfo iaCI = {};
2503 iaCI.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
Chia-I Wu515eb8f2015-10-31 00:31:16 +08002504 iaCI.topology = VK_PRIMITIVE_TOPOLOGY_PATCH_LIST;
Tobin Ehlis912df022015-09-17 08:46:18 -06002505
2506 VkPipelineTessellationStateCreateInfo tsCI = {};
2507 tsCI.sType = VK_STRUCTURE_TYPE_PIPELINE_TESSELLATION_STATE_CREATE_INFO;
2508 tsCI.patchControlPoints = 0; // This will cause an error
2509
2510 VkGraphicsPipelineCreateInfo gp_ci = {};
2511 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
2512 gp_ci.pNext = NULL;
2513 gp_ci.stageCount = 3;
2514 gp_ci.pStages = shaderStages;
2515 gp_ci.pVertexInputState = NULL;
2516 gp_ci.pInputAssemblyState = &iaCI;
2517 gp_ci.pTessellationState = &tsCI;
2518 gp_ci.pViewportState = NULL;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002519 gp_ci.pRasterizationState = NULL;
Tobin Ehlis912df022015-09-17 08:46:18 -06002520 gp_ci.pMultisampleState = NULL;
2521 gp_ci.pDepthStencilState = NULL;
2522 gp_ci.pColorBlendState = NULL;
2523 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
2524 gp_ci.layout = pipeline_layout;
2525 gp_ci.renderPass = renderPass();
2526
2527 VkPipelineCacheCreateInfo pc_ci = {};
2528 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
2529 pc_ci.pNext = NULL;
2530 pc_ci.initialSize = 0;
2531 pc_ci.initialData = 0;
2532 pc_ci.maxSize = 0;
2533
2534 VkPipeline pipeline;
2535 VkPipelineCache pipelineCache;
2536
Chia-I Wuf7458c52015-10-26 21:10:41 +08002537 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Tobin Ehlis912df022015-09-17 08:46:18 -06002538 ASSERT_VK_SUCCESS(err);
Chia-I Wuf7458c52015-10-26 21:10:41 +08002539 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlis912df022015-09-17 08:46:18 -06002540
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002541 if (!m_errorMonitor->DesiredMsgFound()) {
2542 FAIL() << "Did not receive Error 'Invalid Pipeline CreateInfo State: VK_PRIMITIVE_TOPOLOGY_PATCH primitive...'";
2543 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlis912df022015-09-17 08:46:18 -06002544 }
Mike Stroyand1c84a52015-08-18 14:40:24 -06002545
Chia-I Wuf7458c52015-10-26 21:10:41 +08002546 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
2547 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
2548 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
2549 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis912df022015-09-17 08:46:18 -06002550}
2551*/
Tobin Ehlise68360f2015-10-01 11:15:13 -06002552// Set scissor and viewport counts to different numbers
2553TEST_F(VkLayerTest, PSOViewportScissorCountMismatch)
2554{
2555 // Attempt to Create Gfx Pipeline w/o a VS
Tobin Ehlise68360f2015-10-01 11:15:13 -06002556 VkResult err;
2557
Courtney Goeltzenleuchterfd4830c2015-11-25 10:30:56 -07002558 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002559 "Gfx Pipeline viewport count (1) must match scissor count (0).");
2560
Tobin Ehlise68360f2015-10-01 11:15:13 -06002561 ASSERT_NO_FATAL_FAILURE(InitState());
2562 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlise68360f2015-10-01 11:15:13 -06002563
Chia-I Wu1b99bb22015-10-27 19:25:11 +08002564 VkDescriptorPoolSize ds_type_count = {};
Tobin Ehlise68360f2015-10-01 11:15:13 -06002565 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wud50a7d72015-10-26 20:48:51 +08002566 ds_type_count.descriptorCount = 1;
Tobin Ehlise68360f2015-10-01 11:15:13 -06002567
2568 VkDescriptorPoolCreateInfo ds_pool_ci = {};
2569 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
Tobin Ehlise68360f2015-10-01 11:15:13 -06002570 ds_pool_ci.maxSets = 1;
Chia-I Wu1b99bb22015-10-27 19:25:11 +08002571 ds_pool_ci.poolSizeCount = 1;
2572 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlise68360f2015-10-01 11:15:13 -06002573
2574 VkDescriptorPool ds_pool;
Chia-I Wuf7458c52015-10-26 21:10:41 +08002575 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlise68360f2015-10-01 11:15:13 -06002576 ASSERT_VK_SUCCESS(err);
2577
2578 VkDescriptorSetLayoutBinding dsl_binding = {};
Chia-I Wud46e6ae2015-10-31 00:31:16 +08002579 dsl_binding.binding = 0;
Tobin Ehlise68360f2015-10-01 11:15:13 -06002580 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wu02124482015-11-06 06:42:02 +08002581 dsl_binding.descriptorCount = 1;
Tobin Ehlise68360f2015-10-01 11:15:13 -06002582 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
2583
2584 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
2585 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
Chia-I Wud50a7d72015-10-26 20:48:51 +08002586 ds_layout_ci.bindingCount = 1;
Chia-I Wua745e512015-10-31 00:31:16 +08002587 ds_layout_ci.pBinding = &dsl_binding;
Tobin Ehlise68360f2015-10-01 11:15:13 -06002588
2589 VkDescriptorSetLayout ds_layout;
Chia-I Wuf7458c52015-10-26 21:10:41 +08002590 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06002591 ASSERT_VK_SUCCESS(err);
2592
2593 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002594 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08002595 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Chia-I Wud50a7d72015-10-26 20:48:51 +08002596 alloc_info.setLayoutCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06002597 alloc_info.descriptorPool = ds_pool;
2598 alloc_info.pSetLayouts = &ds_layout;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002599 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlise68360f2015-10-01 11:15:13 -06002600 ASSERT_VK_SUCCESS(err);
2601
2602 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
2603 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
Chia-I Wud50a7d72015-10-26 20:48:51 +08002604 pipeline_layout_ci.setLayoutCount = 1;
Tobin Ehlise68360f2015-10-01 11:15:13 -06002605 pipeline_layout_ci.pSetLayouts = &ds_layout;
2606
2607 VkPipelineLayout pipeline_layout;
Chia-I Wuf7458c52015-10-26 21:10:41 +08002608 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06002609 ASSERT_VK_SUCCESS(err);
2610
2611 VkViewport vp = {}; // Just need dummy vp to point to
2612
2613 VkPipelineViewportStateCreateInfo vp_state_ci = {};
2614 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
2615 vp_state_ci.scissorCount = 0;
2616 vp_state_ci.viewportCount = 1; // Count mismatch should cause error
2617 vp_state_ci.pViewports = &vp;
2618
Cody Northropeb3a6c12015-10-05 14:44:45 -06002619 VkPipelineShaderStageCreateInfo shaderStages[2];
2620 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
Tobin Ehlise68360f2015-10-01 11:15:13 -06002621
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06002622 VkShaderObj vs(m_device,bindStateVertShaderText,VK_SHADER_STAGE_VERTEX_BIT, this);
2623 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 -06002624 // but add it to be able to run on more devices
Chia-I Wu28e06912015-10-31 00:31:16 +08002625 shaderStages[0] = vs.GetStageCreateInfo();
2626 shaderStages[1] = fs.GetStageCreateInfo();
Tobin Ehlise68360f2015-10-01 11:15:13 -06002627
2628 VkGraphicsPipelineCreateInfo gp_ci = {};
2629 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
Cody Northropeb3a6c12015-10-05 14:44:45 -06002630 gp_ci.stageCount = 2;
2631 gp_ci.pStages = shaderStages;
Tobin Ehlise68360f2015-10-01 11:15:13 -06002632 gp_ci.pViewportState = &vp_state_ci;
2633 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
2634 gp_ci.layout = pipeline_layout;
2635 gp_ci.renderPass = renderPass();
2636
2637 VkPipelineCacheCreateInfo pc_ci = {};
2638 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
2639
2640 VkPipeline pipeline;
2641 VkPipelineCache pipelineCache;
2642
Chia-I Wuf7458c52015-10-26 21:10:41 +08002643 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Tobin Ehlise68360f2015-10-01 11:15:13 -06002644 ASSERT_VK_SUCCESS(err);
Chia-I Wuf7458c52015-10-26 21:10:41 +08002645 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlise68360f2015-10-01 11:15:13 -06002646
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002647 if (!m_errorMonitor->DesiredMsgFound()) {
2648 FAIL() << "Did not receive Error 'Gfx Pipeline viewport count (1) must match scissor count (0).'";
2649 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlise68360f2015-10-01 11:15:13 -06002650 }
2651
Chia-I Wuf7458c52015-10-26 21:10:41 +08002652 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
2653 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
2654 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
2655 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlise68360f2015-10-01 11:15:13 -06002656}
Tobin Ehlisd332f282015-10-02 11:00:56 -06002657// Don't set viewport state in PSO. This is an error b/c we always need this state
2658// for the counts even if the data is going to be set dynamically.
2659TEST_F(VkLayerTest, PSOViewportStateNotSet)
Tobin Ehlise68360f2015-10-01 11:15:13 -06002660{
2661 // Attempt to Create Gfx Pipeline w/o a VS
Tobin Ehlise68360f2015-10-01 11:15:13 -06002662 VkResult err;
2663
Courtney Goeltzenleuchterfd4830c2015-11-25 10:30:56 -07002664 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002665 "Gfx Pipeline pViewportState is null. Even if ");
2666
Tobin Ehlise68360f2015-10-01 11:15:13 -06002667 ASSERT_NO_FATAL_FAILURE(InitState());
2668 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlise68360f2015-10-01 11:15:13 -06002669
Chia-I Wu1b99bb22015-10-27 19:25:11 +08002670 VkDescriptorPoolSize ds_type_count = {};
Tobin Ehlise68360f2015-10-01 11:15:13 -06002671 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wud50a7d72015-10-26 20:48:51 +08002672 ds_type_count.descriptorCount = 1;
Tobin Ehlise68360f2015-10-01 11:15:13 -06002673
2674 VkDescriptorPoolCreateInfo ds_pool_ci = {};
2675 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
Tobin Ehlise68360f2015-10-01 11:15:13 -06002676 ds_pool_ci.maxSets = 1;
Chia-I Wu1b99bb22015-10-27 19:25:11 +08002677 ds_pool_ci.poolSizeCount = 1;
2678 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlise68360f2015-10-01 11:15:13 -06002679
2680 VkDescriptorPool ds_pool;
Chia-I Wuf7458c52015-10-26 21:10:41 +08002681 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlise68360f2015-10-01 11:15:13 -06002682 ASSERT_VK_SUCCESS(err);
2683
2684 VkDescriptorSetLayoutBinding dsl_binding = {};
Chia-I Wud46e6ae2015-10-31 00:31:16 +08002685 dsl_binding.binding = 0;
Tobin Ehlise68360f2015-10-01 11:15:13 -06002686 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wu02124482015-11-06 06:42:02 +08002687 dsl_binding.descriptorCount = 1;
Tobin Ehlise68360f2015-10-01 11:15:13 -06002688 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
2689
2690 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
2691 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
Chia-I Wud50a7d72015-10-26 20:48:51 +08002692 ds_layout_ci.bindingCount = 1;
Chia-I Wua745e512015-10-31 00:31:16 +08002693 ds_layout_ci.pBinding = &dsl_binding;
Tobin Ehlise68360f2015-10-01 11:15:13 -06002694
2695 VkDescriptorSetLayout ds_layout;
Chia-I Wuf7458c52015-10-26 21:10:41 +08002696 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06002697 ASSERT_VK_SUCCESS(err);
2698
2699 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002700 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08002701 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Chia-I Wud50a7d72015-10-26 20:48:51 +08002702 alloc_info.setLayoutCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06002703 alloc_info.descriptorPool = ds_pool;
2704 alloc_info.pSetLayouts = &ds_layout;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002705 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlise68360f2015-10-01 11:15:13 -06002706 ASSERT_VK_SUCCESS(err);
2707
2708 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
2709 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
Chia-I Wud50a7d72015-10-26 20:48:51 +08002710 pipeline_layout_ci.setLayoutCount = 1;
Tobin Ehlise68360f2015-10-01 11:15:13 -06002711 pipeline_layout_ci.pSetLayouts = &ds_layout;
2712
2713 VkPipelineLayout pipeline_layout;
Chia-I Wuf7458c52015-10-26 21:10:41 +08002714 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06002715 ASSERT_VK_SUCCESS(err);
2716
2717 VkDynamicState sc_state = VK_DYNAMIC_STATE_SCISSOR;
2718 // Set scissor as dynamic to avoid second error
2719 VkPipelineDynamicStateCreateInfo dyn_state_ci = {};
2720 dyn_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
2721 dyn_state_ci.dynamicStateCount = 1;
2722 dyn_state_ci.pDynamicStates = &sc_state;
2723
Cody Northropeb3a6c12015-10-05 14:44:45 -06002724 VkPipelineShaderStageCreateInfo shaderStages[2];
2725 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
Tobin Ehlise68360f2015-10-01 11:15:13 -06002726
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06002727 VkShaderObj vs(m_device,bindStateVertShaderText,VK_SHADER_STAGE_VERTEX_BIT, this);
2728 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 -06002729 // but add it to be able to run on more devices
Chia-I Wu28e06912015-10-31 00:31:16 +08002730 shaderStages[0] = vs.GetStageCreateInfo();
2731 shaderStages[1] = fs.GetStageCreateInfo();
Tobin Ehlise68360f2015-10-01 11:15:13 -06002732
2733 VkGraphicsPipelineCreateInfo gp_ci = {};
2734 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
Cody Northropeb3a6c12015-10-05 14:44:45 -06002735 gp_ci.stageCount = 2;
2736 gp_ci.pStages = shaderStages;
Tobin Ehlise68360f2015-10-01 11:15:13 -06002737 gp_ci.pViewportState = NULL; // Not setting VP state w/o dynamic vp state should cause validation error
2738 gp_ci.pDynamicState = &dyn_state_ci;
2739 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
2740 gp_ci.layout = pipeline_layout;
2741 gp_ci.renderPass = renderPass();
2742
2743 VkPipelineCacheCreateInfo pc_ci = {};
2744 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
2745
2746 VkPipeline pipeline;
2747 VkPipelineCache pipelineCache;
2748
Chia-I Wuf7458c52015-10-26 21:10:41 +08002749 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Tobin Ehlise68360f2015-10-01 11:15:13 -06002750 ASSERT_VK_SUCCESS(err);
Chia-I Wuf7458c52015-10-26 21:10:41 +08002751 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlise68360f2015-10-01 11:15:13 -06002752
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002753 if (!m_errorMonitor->DesiredMsgFound()) {
2754 FAIL() << "Did not receive Error 'Gfx Pipeline pViewportState is null. Even if...'";
2755 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlise68360f2015-10-01 11:15:13 -06002756 }
2757
Chia-I Wuf7458c52015-10-26 21:10:41 +08002758 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
2759 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
2760 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
2761 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlise68360f2015-10-01 11:15:13 -06002762}
2763// Create PSO w/o non-zero viewportCount but no viewport data
Tobin Ehlisd332f282015-10-02 11:00:56 -06002764// Then run second test where dynamic scissor count doesn't match PSO scissor count
2765TEST_F(VkLayerTest, PSOViewportCountWithoutDataAndDynScissorMismatch)
Tobin Ehlise68360f2015-10-01 11:15:13 -06002766{
Tobin Ehlise68360f2015-10-01 11:15:13 -06002767 VkResult err;
2768
Courtney Goeltzenleuchterfd4830c2015-11-25 10:30:56 -07002769 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002770 "Gfx Pipeline viewportCount is 1, but pViewports is NULL. ");
2771
Tobin Ehlise68360f2015-10-01 11:15:13 -06002772 ASSERT_NO_FATAL_FAILURE(InitState());
2773 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlise68360f2015-10-01 11:15:13 -06002774
Chia-I Wu1b99bb22015-10-27 19:25:11 +08002775 VkDescriptorPoolSize ds_type_count = {};
Tobin Ehlise68360f2015-10-01 11:15:13 -06002776 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wud50a7d72015-10-26 20:48:51 +08002777 ds_type_count.descriptorCount = 1;
Tobin Ehlise68360f2015-10-01 11:15:13 -06002778
2779 VkDescriptorPoolCreateInfo ds_pool_ci = {};
2780 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
Tobin Ehlise68360f2015-10-01 11:15:13 -06002781 ds_pool_ci.maxSets = 1;
Chia-I Wu1b99bb22015-10-27 19:25:11 +08002782 ds_pool_ci.poolSizeCount = 1;
2783 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlise68360f2015-10-01 11:15:13 -06002784
2785 VkDescriptorPool ds_pool;
Chia-I Wuf7458c52015-10-26 21:10:41 +08002786 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlise68360f2015-10-01 11:15:13 -06002787 ASSERT_VK_SUCCESS(err);
2788
2789 VkDescriptorSetLayoutBinding dsl_binding = {};
Chia-I Wud46e6ae2015-10-31 00:31:16 +08002790 dsl_binding.binding = 0;
Tobin Ehlise68360f2015-10-01 11:15:13 -06002791 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wu02124482015-11-06 06:42:02 +08002792 dsl_binding.descriptorCount = 1;
Tobin Ehlise68360f2015-10-01 11:15:13 -06002793 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
2794
2795 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
2796 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
Chia-I Wud50a7d72015-10-26 20:48:51 +08002797 ds_layout_ci.bindingCount = 1;
Chia-I Wua745e512015-10-31 00:31:16 +08002798 ds_layout_ci.pBinding = &dsl_binding;
Tobin Ehlise68360f2015-10-01 11:15:13 -06002799
2800 VkDescriptorSetLayout ds_layout;
Chia-I Wuf7458c52015-10-26 21:10:41 +08002801 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06002802 ASSERT_VK_SUCCESS(err);
2803
2804 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002805 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08002806 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Chia-I Wud50a7d72015-10-26 20:48:51 +08002807 alloc_info.setLayoutCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06002808 alloc_info.descriptorPool = ds_pool;
2809 alloc_info.pSetLayouts = &ds_layout;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002810 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlise68360f2015-10-01 11:15:13 -06002811 ASSERT_VK_SUCCESS(err);
2812
2813 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
2814 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
Chia-I Wud50a7d72015-10-26 20:48:51 +08002815 pipeline_layout_ci.setLayoutCount = 1;
Tobin Ehlise68360f2015-10-01 11:15:13 -06002816 pipeline_layout_ci.pSetLayouts = &ds_layout;
2817
2818 VkPipelineLayout pipeline_layout;
Chia-I Wuf7458c52015-10-26 21:10:41 +08002819 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06002820 ASSERT_VK_SUCCESS(err);
2821
2822 VkPipelineViewportStateCreateInfo vp_state_ci = {};
2823 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
2824 vp_state_ci.viewportCount = 1;
2825 vp_state_ci.pViewports = NULL; // Null vp w/ count of 1 should cause error
2826 vp_state_ci.scissorCount = 1;
2827 vp_state_ci.pScissors = NULL; // Scissor is dynamic (below) so this won't cause error
2828
2829 VkDynamicState sc_state = VK_DYNAMIC_STATE_SCISSOR;
2830 // Set scissor as dynamic to avoid that error
2831 VkPipelineDynamicStateCreateInfo dyn_state_ci = {};
2832 dyn_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
2833 dyn_state_ci.dynamicStateCount = 1;
2834 dyn_state_ci.pDynamicStates = &sc_state;
2835
Cody Northropeb3a6c12015-10-05 14:44:45 -06002836 VkPipelineShaderStageCreateInfo shaderStages[2];
2837 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
Tobin Ehlise68360f2015-10-01 11:15:13 -06002838
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06002839 VkShaderObj vs(m_device,bindStateVertShaderText,VK_SHADER_STAGE_VERTEX_BIT, this);
2840 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 -06002841 // but add it to be able to run on more devices
Chia-I Wu28e06912015-10-31 00:31:16 +08002842 shaderStages[0] = vs.GetStageCreateInfo();
2843 shaderStages[1] = fs.GetStageCreateInfo();
Tobin Ehlise68360f2015-10-01 11:15:13 -06002844
Cody Northropf6622dc2015-10-06 10:33:21 -06002845 VkPipelineVertexInputStateCreateInfo vi_ci = {};
2846 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
2847 vi_ci.pNext = nullptr;
Chia-I Wud50a7d72015-10-26 20:48:51 +08002848 vi_ci.vertexBindingDescriptionCount = 0;
Cody Northropf6622dc2015-10-06 10:33:21 -06002849 vi_ci.pVertexBindingDescriptions = nullptr;
Chia-I Wud50a7d72015-10-26 20:48:51 +08002850 vi_ci.vertexAttributeDescriptionCount = 0;
Cody Northropf6622dc2015-10-06 10:33:21 -06002851 vi_ci.pVertexAttributeDescriptions = nullptr;
2852
2853 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
2854 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
2855 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
2856
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002857 VkPipelineRasterizationStateCreateInfo rs_ci = {};
Chia-I Wu1b99bb22015-10-27 19:25:11 +08002858 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
Cody Northropf6622dc2015-10-06 10:33:21 -06002859 rs_ci.pNext = nullptr;
2860
2861 VkPipelineColorBlendStateCreateInfo cb_ci = {};
2862 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
2863 cb_ci.pNext = nullptr;
2864
Tobin Ehlise68360f2015-10-01 11:15:13 -06002865 VkGraphicsPipelineCreateInfo gp_ci = {};
2866 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
Cody Northropeb3a6c12015-10-05 14:44:45 -06002867 gp_ci.stageCount = 2;
2868 gp_ci.pStages = shaderStages;
Cody Northropf6622dc2015-10-06 10:33:21 -06002869 gp_ci.pVertexInputState = &vi_ci;
2870 gp_ci.pInputAssemblyState = &ia_ci;
Tobin Ehlise68360f2015-10-01 11:15:13 -06002871 gp_ci.pViewportState = &vp_state_ci;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002872 gp_ci.pRasterizationState = &rs_ci;
Cody Northropf6622dc2015-10-06 10:33:21 -06002873 gp_ci.pColorBlendState = &cb_ci;
Tobin Ehlise68360f2015-10-01 11:15:13 -06002874 gp_ci.pDynamicState = &dyn_state_ci;
2875 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
2876 gp_ci.layout = pipeline_layout;
2877 gp_ci.renderPass = renderPass();
2878
2879 VkPipelineCacheCreateInfo pc_ci = {};
2880 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
2881
2882 VkPipeline pipeline;
2883 VkPipelineCache pipelineCache;
2884
Chia-I Wuf7458c52015-10-26 21:10:41 +08002885 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Tobin Ehlise68360f2015-10-01 11:15:13 -06002886 ASSERT_VK_SUCCESS(err);
Chia-I Wuf7458c52015-10-26 21:10:41 +08002887 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlise68360f2015-10-01 11:15:13 -06002888
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002889 if (!m_errorMonitor->DesiredMsgFound()) {
2890 FAIL() << "Did not recieve Error 'Gfx Pipeline viewportCount is 1, but pViewports is NULL...'";
2891 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlise68360f2015-10-01 11:15:13 -06002892 }
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002893
2894
Tobin Ehlisd332f282015-10-02 11:00:56 -06002895 // Now hit second fail case where we set scissor w/ different count than PSO
2896 // First need to successfully create the PSO from above by setting pViewports
Courtney Goeltzenleuchterfd4830c2015-11-25 10:30:56 -07002897 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002898 "Dynamic scissorCount from vkCmdSetScissor() is 2, but PSO scissorCount is 1. These counts must match.");
2899
Tobin Ehlisd332f282015-10-02 11:00:56 -06002900 VkViewport vp = {}; // Just need dummy vp to point to
2901 vp_state_ci.pViewports = &vp;
Chia-I Wuf7458c52015-10-26 21:10:41 +08002902 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlisd332f282015-10-02 11:00:56 -06002903 ASSERT_VK_SUCCESS(err);
2904 BeginCommandBuffer();
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002905 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
Tobin Ehlisd332f282015-10-02 11:00:56 -06002906 VkRect2D scissors[2] = {}; // don't care about data
2907 // Count of 2 doesn't match PSO count of 1
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002908 vkCmdSetScissor(m_commandBuffer->GetBufferHandle(), 2, scissors);
Tobin Ehlisd332f282015-10-02 11:00:56 -06002909 Draw(1, 0, 0, 0);
2910
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002911 if (!m_errorMonitor->DesiredMsgFound()) {
2912 FAIL() << "Did not receive Error 'Dynamic scissorCount from vkCmdSetScissor() is 2, but PSO scissorCount is 1...'";
2913 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlisd332f282015-10-02 11:00:56 -06002914 }
Tobin Ehlise68360f2015-10-01 11:15:13 -06002915
Chia-I Wuf7458c52015-10-26 21:10:41 +08002916 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
2917 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
2918 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
2919 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlise68360f2015-10-01 11:15:13 -06002920}
2921// Create PSO w/o non-zero scissorCount but no scissor data
Tobin Ehlisd332f282015-10-02 11:00:56 -06002922// Then run second test where dynamic viewportCount doesn't match PSO viewportCount
2923TEST_F(VkLayerTest, PSOScissorCountWithoutDataAndDynViewportMismatch)
Tobin Ehlise68360f2015-10-01 11:15:13 -06002924{
Tobin Ehlise68360f2015-10-01 11:15:13 -06002925 VkResult err;
2926
Courtney Goeltzenleuchterfd4830c2015-11-25 10:30:56 -07002927 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002928 "Gfx Pipeline scissorCount is 1, but pScissors is NULL. ");
2929
Tobin Ehlise68360f2015-10-01 11:15:13 -06002930 ASSERT_NO_FATAL_FAILURE(InitState());
2931 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlise68360f2015-10-01 11:15:13 -06002932
Chia-I Wu1b99bb22015-10-27 19:25:11 +08002933 VkDescriptorPoolSize ds_type_count = {};
Tobin Ehlise68360f2015-10-01 11:15:13 -06002934 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wud50a7d72015-10-26 20:48:51 +08002935 ds_type_count.descriptorCount = 1;
Tobin Ehlise68360f2015-10-01 11:15:13 -06002936
2937 VkDescriptorPoolCreateInfo ds_pool_ci = {};
2938 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
Tobin Ehlise68360f2015-10-01 11:15:13 -06002939 ds_pool_ci.maxSets = 1;
Chia-I Wu1b99bb22015-10-27 19:25:11 +08002940 ds_pool_ci.poolSizeCount = 1;
2941 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlise68360f2015-10-01 11:15:13 -06002942
2943 VkDescriptorPool ds_pool;
Chia-I Wuf7458c52015-10-26 21:10:41 +08002944 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlise68360f2015-10-01 11:15:13 -06002945 ASSERT_VK_SUCCESS(err);
2946
2947 VkDescriptorSetLayoutBinding dsl_binding = {};
Chia-I Wud46e6ae2015-10-31 00:31:16 +08002948 dsl_binding.binding = 0;
Tobin Ehlise68360f2015-10-01 11:15:13 -06002949 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wu02124482015-11-06 06:42:02 +08002950 dsl_binding.descriptorCount = 1;
Tobin Ehlise68360f2015-10-01 11:15:13 -06002951 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
2952
2953 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
2954 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
Chia-I Wud50a7d72015-10-26 20:48:51 +08002955 ds_layout_ci.bindingCount = 1;
Chia-I Wua745e512015-10-31 00:31:16 +08002956 ds_layout_ci.pBinding = &dsl_binding;
Tobin Ehlise68360f2015-10-01 11:15:13 -06002957
2958 VkDescriptorSetLayout ds_layout;
Chia-I Wuf7458c52015-10-26 21:10:41 +08002959 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06002960 ASSERT_VK_SUCCESS(err);
2961
2962 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002963 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08002964 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Chia-I Wud50a7d72015-10-26 20:48:51 +08002965 alloc_info.setLayoutCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06002966 alloc_info.descriptorPool = ds_pool;
2967 alloc_info.pSetLayouts = &ds_layout;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002968 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlise68360f2015-10-01 11:15:13 -06002969 ASSERT_VK_SUCCESS(err);
2970
2971 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
2972 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
Chia-I Wud50a7d72015-10-26 20:48:51 +08002973 pipeline_layout_ci.setLayoutCount = 1;
Tobin Ehlise68360f2015-10-01 11:15:13 -06002974 pipeline_layout_ci.pSetLayouts = &ds_layout;
2975
2976 VkPipelineLayout pipeline_layout;
Chia-I Wuf7458c52015-10-26 21:10:41 +08002977 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06002978 ASSERT_VK_SUCCESS(err);
2979
2980 VkPipelineViewportStateCreateInfo vp_state_ci = {};
2981 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
2982 vp_state_ci.scissorCount = 1;
2983 vp_state_ci.pScissors = NULL; // Null scissor w/ count of 1 should cause error
2984 vp_state_ci.viewportCount = 1;
2985 vp_state_ci.pViewports = NULL; // vp is dynamic (below) so this won't cause error
2986
2987 VkDynamicState vp_state = VK_DYNAMIC_STATE_VIEWPORT;
2988 // Set scissor as dynamic to avoid that error
2989 VkPipelineDynamicStateCreateInfo dyn_state_ci = {};
2990 dyn_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
2991 dyn_state_ci.dynamicStateCount = 1;
2992 dyn_state_ci.pDynamicStates = &vp_state;
2993
Cody Northropeb3a6c12015-10-05 14:44:45 -06002994 VkPipelineShaderStageCreateInfo shaderStages[2];
2995 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
Tobin Ehlise68360f2015-10-01 11:15:13 -06002996
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06002997 VkShaderObj vs(m_device,bindStateVertShaderText,VK_SHADER_STAGE_VERTEX_BIT, this);
2998 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 -06002999 // but add it to be able to run on more devices
Chia-I Wu28e06912015-10-31 00:31:16 +08003000 shaderStages[0] = vs.GetStageCreateInfo();
3001 shaderStages[1] = fs.GetStageCreateInfo();
Tobin Ehlise68360f2015-10-01 11:15:13 -06003002
Cody Northropf6622dc2015-10-06 10:33:21 -06003003 VkPipelineVertexInputStateCreateInfo vi_ci = {};
3004 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
3005 vi_ci.pNext = nullptr;
Chia-I Wud50a7d72015-10-26 20:48:51 +08003006 vi_ci.vertexBindingDescriptionCount = 0;
Cody Northropf6622dc2015-10-06 10:33:21 -06003007 vi_ci.pVertexBindingDescriptions = nullptr;
Chia-I Wud50a7d72015-10-26 20:48:51 +08003008 vi_ci.vertexAttributeDescriptionCount = 0;
Cody Northropf6622dc2015-10-06 10:33:21 -06003009 vi_ci.pVertexAttributeDescriptions = nullptr;
3010
3011 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
3012 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
3013 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
3014
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003015 VkPipelineRasterizationStateCreateInfo rs_ci = {};
Chia-I Wu1b99bb22015-10-27 19:25:11 +08003016 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
Cody Northropf6622dc2015-10-06 10:33:21 -06003017 rs_ci.pNext = nullptr;
3018
3019 VkPipelineColorBlendStateCreateInfo cb_ci = {};
3020 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
3021 cb_ci.pNext = nullptr;
3022
Tobin Ehlise68360f2015-10-01 11:15:13 -06003023 VkGraphicsPipelineCreateInfo gp_ci = {};
3024 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
Cody Northropeb3a6c12015-10-05 14:44:45 -06003025 gp_ci.stageCount = 2;
3026 gp_ci.pStages = shaderStages;
Cody Northropf6622dc2015-10-06 10:33:21 -06003027 gp_ci.pVertexInputState = &vi_ci;
3028 gp_ci.pInputAssemblyState = &ia_ci;
Tobin Ehlise68360f2015-10-01 11:15:13 -06003029 gp_ci.pViewportState = &vp_state_ci;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003030 gp_ci.pRasterizationState = &rs_ci;
Cody Northropf6622dc2015-10-06 10:33:21 -06003031 gp_ci.pColorBlendState = &cb_ci;
Tobin Ehlise68360f2015-10-01 11:15:13 -06003032 gp_ci.pDynamicState = &dyn_state_ci;
3033 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
3034 gp_ci.layout = pipeline_layout;
3035 gp_ci.renderPass = renderPass();
3036
3037 VkPipelineCacheCreateInfo pc_ci = {};
3038 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
3039
3040 VkPipeline pipeline;
3041 VkPipelineCache pipelineCache;
3042
Chia-I Wuf7458c52015-10-26 21:10:41 +08003043 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Tobin Ehlise68360f2015-10-01 11:15:13 -06003044 ASSERT_VK_SUCCESS(err);
Chia-I Wuf7458c52015-10-26 21:10:41 +08003045 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlise68360f2015-10-01 11:15:13 -06003046
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06003047 if (!m_errorMonitor->DesiredMsgFound()) {
3048 FAIL() << "Did not recieve Error 'Gfx Pipeline scissorCount is 1, but pScissors is NULL...'";
3049 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlise68360f2015-10-01 11:15:13 -06003050 }
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06003051
Tobin Ehlisd332f282015-10-02 11:00:56 -06003052 // Now hit second fail case where we set scissor w/ different count than PSO
3053 // First need to successfully create the PSO from above by setting pViewports
Courtney Goeltzenleuchterfd4830c2015-11-25 10:30:56 -07003054 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06003055 "Dynamic viewportCount from vkCmdSetViewport() is 2, but PSO viewportCount is 1. These counts must match.");
3056
Tobin Ehlisd332f282015-10-02 11:00:56 -06003057 VkRect2D sc = {}; // Just need dummy vp to point to
3058 vp_state_ci.pScissors = &sc;
Chia-I Wuf7458c52015-10-26 21:10:41 +08003059 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlisd332f282015-10-02 11:00:56 -06003060 ASSERT_VK_SUCCESS(err);
3061 BeginCommandBuffer();
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003062 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
Tobin Ehlisd332f282015-10-02 11:00:56 -06003063 VkViewport viewports[2] = {}; // don't care about data
3064 // Count of 2 doesn't match PSO count of 1
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003065 vkCmdSetViewport(m_commandBuffer->GetBufferHandle(), 2, viewports);
Tobin Ehlisd332f282015-10-02 11:00:56 -06003066 Draw(1, 0, 0, 0);
3067
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06003068 if (!m_errorMonitor->DesiredMsgFound()) {
3069 FAIL() << "Did not receive Error 'Dynamic viewportCount from vkCmdSetViewport() is 2, but PSO viewportCount is 1...'";
3070 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlisd332f282015-10-02 11:00:56 -06003071 }
Tobin Ehlise68360f2015-10-01 11:15:13 -06003072
Chia-I Wuf7458c52015-10-26 21:10:41 +08003073 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
3074 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
3075 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
3076 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlise68360f2015-10-01 11:15:13 -06003077}
3078
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06003079TEST_F(VkLayerTest, NullRenderPass)
3080{
3081 // Bind a NULL RenderPass
Courtney Goeltzenleuchterfd4830c2015-11-25 10:30:56 -07003082 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06003083 "You cannot use a NULL RenderPass object in vkCmdBeginRenderPass()");
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06003084
3085 ASSERT_NO_FATAL_FAILURE(InitState());
3086 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06003087
Tony Barbourfe3351b2015-07-28 10:17:20 -06003088 BeginCommandBuffer();
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06003089 // Don't care about RenderPass handle b/c error should be flagged before that
Chia-I Wu1b99bb22015-10-27 19:25:11 +08003090 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), NULL, VK_SUBPASS_CONTENTS_INLINE);
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06003091
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06003092 if (!m_errorMonitor->DesiredMsgFound()) {
3093 FAIL() << "Did not receive Error 'You cannot use a NULL RenderPass object in vkCmdBeginRenderPass()'";
3094 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06003095 }
3096}
3097
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06003098TEST_F(VkLayerTest, RenderPassWithinRenderPass)
3099{
3100 // Bind a BeginRenderPass within an active RenderPass
Courtney Goeltzenleuchterfd4830c2015-11-25 10:30:56 -07003101 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06003102 "It is invalid to issue this call inside an active render pass");
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06003103
3104 ASSERT_NO_FATAL_FAILURE(InitState());
3105 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06003106
Tony Barbourfe3351b2015-07-28 10:17:20 -06003107 BeginCommandBuffer();
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06003108 // Just create a dummy Renderpass that's non-NULL so we can get to the proper error
Tony Barboureb254902015-07-15 12:50:33 -06003109 VkRenderPassBeginInfo rp_begin = {};
3110 rp_begin.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO;
3111 rp_begin.pNext = NULL;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06003112 rp_begin.renderPass = renderPass();
3113 rp_begin.framebuffer = framebuffer();
Mark Lobodzinski209b5292015-09-17 09:44:05 -06003114
Chia-I Wu1b99bb22015-10-27 19:25:11 +08003115 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &rp_begin, VK_SUBPASS_CONTENTS_INLINE);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06003116
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06003117 if (!m_errorMonitor->DesiredMsgFound()) {
3118 FAIL() << "Did not receive Error 'It is invalid to issue this call inside an active render pass...'";
3119 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06003120 }
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06003121}
3122
Mark Lobodzinskid5639502015-09-24 09:51:47 -06003123TEST_F(VkLayerTest, FillBufferWithinRenderPass)
3124{
3125 // Call CmdFillBuffer within an active renderpass
Courtney Goeltzenleuchterfd4830c2015-11-25 10:30:56 -07003126 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06003127 "It is invalid to issue this call inside an active render pass");
Mark Lobodzinskid5639502015-09-24 09:51:47 -06003128
3129 ASSERT_NO_FATAL_FAILURE(InitState());
3130 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskid5639502015-09-24 09:51:47 -06003131
3132 // Renderpass is started here
3133 BeginCommandBuffer();
3134
3135 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003136 vk_testing::Buffer dstBuffer;
3137 dstBuffer.init_as_dst(*m_device, (VkDeviceSize)1024, reqs);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06003138
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003139 m_commandBuffer->FillBuffer(dstBuffer.handle(), 0, 4, 0x11111111);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06003140
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06003141 if (!m_errorMonitor->DesiredMsgFound()) {
3142 FAIL() << "Did not receive Error 'It is invalid to issue this call inside an active render pass...'";
3143 m_errorMonitor->DumpFailureMsgs();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06003144 }
3145}
3146
3147TEST_F(VkLayerTest, UpdateBufferWithinRenderPass)
3148{
3149 // Call CmdUpdateBuffer within an active renderpass
Courtney Goeltzenleuchterfd4830c2015-11-25 10:30:56 -07003150 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06003151 "It is invalid to issue this call inside an active render pass");
Mark Lobodzinskid5639502015-09-24 09:51:47 -06003152
3153 ASSERT_NO_FATAL_FAILURE(InitState());
3154 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskid5639502015-09-24 09:51:47 -06003155
3156 // Renderpass is started here
3157 BeginCommandBuffer();
3158
3159 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003160 vk_testing::Buffer dstBuffer;
3161 dstBuffer.init_as_dst(*m_device, (VkDeviceSize)1024, reqs);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06003162
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003163 VkDeviceSize dstOffset = 0;
Mark Lobodzinskid5639502015-09-24 09:51:47 -06003164 VkDeviceSize dataSize = 1024;
3165 const uint32_t *pData = NULL;
3166
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003167 vkCmdUpdateBuffer(m_commandBuffer->GetBufferHandle(), dstBuffer.handle(), dstOffset, dataSize, pData);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06003168
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06003169 if (!m_errorMonitor->DesiredMsgFound()) {
3170 FAIL() << "Did not receive Error 'It is invalid to issue this call inside an active render pass...'";
3171 m_errorMonitor->DumpFailureMsgs();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06003172 }
3173}
3174
3175TEST_F(VkLayerTest, ClearColorImageWithinRenderPass)
3176{
3177 // Call CmdClearColorImage within an active RenderPass
Courtney Goeltzenleuchterfd4830c2015-11-25 10:30:56 -07003178 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06003179 "It is invalid to issue this call inside an active render pass");
Mark Lobodzinskid5639502015-09-24 09:51:47 -06003180
3181 ASSERT_NO_FATAL_FAILURE(InitState());
3182 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskid5639502015-09-24 09:51:47 -06003183
3184 // Renderpass is started here
3185 BeginCommandBuffer();
3186
3187 VkClearColorValue clear_color = {0};
3188 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
3189 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
3190 const int32_t tex_width = 32;
3191 const int32_t tex_height = 32;
3192 VkImageCreateInfo image_create_info = {};
3193 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
3194 image_create_info.pNext = NULL;
3195 image_create_info.imageType = VK_IMAGE_TYPE_2D;
3196 image_create_info.format = tex_format;
3197 image_create_info.extent.width = tex_width;
3198 image_create_info.extent.height = tex_height;
3199 image_create_info.extent.depth = 1;
3200 image_create_info.mipLevels = 1;
Courtney Goeltzenleuchter5d2aed42015-10-21 17:57:31 -06003201 image_create_info.arrayLayers = 1;
Chia-I Wu5c17c962015-10-31 00:31:16 +08003202 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Mark Lobodzinskid5639502015-09-24 09:51:47 -06003203 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
3204 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
3205
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003206 vk_testing::Image dstImage;
3207 dstImage.init(*m_device, (const VkImageCreateInfo&)image_create_info, reqs);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06003208
3209 const VkImageSubresourceRange range =
3210 vk_testing::Image::subresource_range(image_create_info, VK_IMAGE_ASPECT_COLOR_BIT);
3211
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003212 vkCmdClearColorImage(m_commandBuffer->GetBufferHandle(),
3213 dstImage.handle(),
Mark Lobodzinskid5639502015-09-24 09:51:47 -06003214 VK_IMAGE_LAYOUT_GENERAL,
3215 &clear_color,
3216 1,
3217 &range);
3218
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06003219 if (!m_errorMonitor->DesiredMsgFound()) {
3220 FAIL() << "Did not receive Error 'It is invalid to issue this call inside an active render pass...'";
3221 m_errorMonitor->DumpFailureMsgs();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06003222 }
3223}
3224
3225TEST_F(VkLayerTest, ClearDepthStencilImageWithinRenderPass)
3226{
3227 // Call CmdClearDepthStencilImage within an active RenderPass
Courtney Goeltzenleuchterfd4830c2015-11-25 10:30:56 -07003228 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06003229 "It is invalid to issue this call inside an active render pass");
Mark Lobodzinskid5639502015-09-24 09:51:47 -06003230
3231 ASSERT_NO_FATAL_FAILURE(InitState());
3232 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskid5639502015-09-24 09:51:47 -06003233
3234 // Renderpass is started here
3235 BeginCommandBuffer();
3236
3237 VkClearDepthStencilValue clear_value = {0};
3238 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
3239 VkImageCreateInfo image_create_info = vk_testing::Image::create_info();
3240 image_create_info.imageType = VK_IMAGE_TYPE_2D;
3241 image_create_info.format = VK_FORMAT_D24_UNORM_S8_UINT;
3242 image_create_info.extent.width = 64;
3243 image_create_info.extent.height = 64;
3244 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
3245 image_create_info.usage = VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT;
3246
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003247 vk_testing::Image dstImage;
3248 dstImage.init(*m_device, (const VkImageCreateInfo&)image_create_info, reqs);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06003249
3250 const VkImageSubresourceRange range =
3251 vk_testing::Image::subresource_range(image_create_info, VK_IMAGE_ASPECT_DEPTH_BIT);
3252
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003253 vkCmdClearDepthStencilImage(m_commandBuffer->GetBufferHandle(),
3254 dstImage.handle(),
Mark Lobodzinskid5639502015-09-24 09:51:47 -06003255 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL,
3256 &clear_value,
3257 1,
3258 &range);
3259
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06003260 if (!m_errorMonitor->DesiredMsgFound()) {
3261 FAIL() << "Did not receive Error 'It is invalid to issue this call inside an active render pass...'";
3262 m_errorMonitor->DumpFailureMsgs();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06003263 }
3264}
3265
3266TEST_F(VkLayerTest, ClearColorAttachmentsOutsideRenderPass)
3267{
Courtney Goeltzenleuchterc9323e02015-10-15 16:51:05 -06003268 // Call CmdClearAttachmentss outside of an active RenderPass
Mark Lobodzinskid5639502015-09-24 09:51:47 -06003269 VkResult err;
3270
Courtney Goeltzenleuchterfd4830c2015-11-25 10:30:56 -07003271 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06003272 "vkCmdClearAttachments: This call must be issued inside an active render pass");
3273
Mark Lobodzinskid5639502015-09-24 09:51:47 -06003274 ASSERT_NO_FATAL_FAILURE(InitState());
3275 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskid5639502015-09-24 09:51:47 -06003276
3277 // Start no RenderPass
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003278 err = m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06003279 ASSERT_VK_SUCCESS(err);
3280
Courtney Goeltzenleuchterc9323e02015-10-15 16:51:05 -06003281 VkClearAttachment color_attachment;
3282 color_attachment.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
3283 color_attachment.clearValue.color.float32[0] = 0;
3284 color_attachment.clearValue.color.float32[1] = 0;
3285 color_attachment.clearValue.color.float32[2] = 0;
3286 color_attachment.clearValue.color.float32[3] = 0;
3287 color_attachment.colorAttachment = 0;
Courtney Goeltzenleuchter5d2aed42015-10-21 17:57:31 -06003288 VkClearRect clear_rect = { { { 0, 0 }, { 32, 32 } } };
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003289 vkCmdClearAttachments(m_commandBuffer->GetBufferHandle(),
Courtney Goeltzenleuchterc9323e02015-10-15 16:51:05 -06003290 1, &color_attachment,
3291 1, &clear_rect);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06003292
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06003293 if (!m_errorMonitor->DesiredMsgFound()) {
3294 FAIL() << "Did not receive Error 'vkCmdClearAttachments: This call must be issued inside an active render pass.'";
3295 m_errorMonitor->DumpFailureMsgs();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06003296 }
3297}
3298
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06003299TEST_F(VkLayerTest, InvalidDynamicStateObject)
3300{
3301 // Create a valid cmd buffer
3302 // call vkCmdBindDynamicStateObject w/ false DS Obj
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06003303 // TODO : Simple check for bad object should be added to ObjectTracker to catch this case
3304 // The DS check for this is after driver has been called to validate DS internal data struct
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06003305}
Tobin Ehlis1056d452015-05-27 14:55:35 -06003306
Tobin Ehlisc4c23182015-09-17 12:24:13 -06003307TEST_F(VkLayerTest, IdxBufferAlignmentError)
3308{
3309 // Bind a BeginRenderPass within an active RenderPass
Tobin Ehlisc4c23182015-09-17 12:24:13 -06003310 VkResult err;
3311
Courtney Goeltzenleuchterfd4830c2015-11-25 10:30:56 -07003312 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06003313 "vkCmdBindIndexBuffer() offset (0x7) does not fall on ");
3314
Tobin Ehlisc4c23182015-09-17 12:24:13 -06003315 ASSERT_NO_FATAL_FAILURE(InitState());
3316 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlisc4c23182015-09-17 12:24:13 -06003317 uint32_t qfi = 0;
3318 VkBufferCreateInfo buffCI = {};
3319 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
3320 buffCI.size = 1024;
3321 buffCI.usage = VK_BUFFER_USAGE_INDEX_BUFFER_BIT;
Chia-I Wud50a7d72015-10-26 20:48:51 +08003322 buffCI.queueFamilyIndexCount = 1;
Tobin Ehlisc4c23182015-09-17 12:24:13 -06003323 buffCI.pQueueFamilyIndices = &qfi;
3324
3325 VkBuffer ib;
Chia-I Wuf7458c52015-10-26 21:10:41 +08003326 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &ib);
Tobin Ehlisc4c23182015-09-17 12:24:13 -06003327 ASSERT_VK_SUCCESS(err);
3328
3329 BeginCommandBuffer();
3330 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003331 //vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlisc4c23182015-09-17 12:24:13 -06003332 // Should error before calling to driver so don't care about actual data
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003333 vkCmdBindIndexBuffer(m_commandBuffer->GetBufferHandle(), ib, 7, VK_INDEX_TYPE_UINT16);
Tobin Ehlisc4c23182015-09-17 12:24:13 -06003334
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06003335 if (!m_errorMonitor->DesiredMsgFound()) {
3336 FAIL() << "Did not receive Error 'vkCmdBindIndexBuffer() offset (0x7) does not fall on ...'";
3337 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlisc4c23182015-09-17 12:24:13 -06003338 }
Mike Stroyand1c84a52015-08-18 14:40:24 -06003339
Chia-I Wuf7458c52015-10-26 21:10:41 +08003340 vkDestroyBuffer(m_device->device(), ib, NULL);
Tobin Ehlisc4c23182015-09-17 12:24:13 -06003341}
3342
Tobin Ehlis4b34ddc2015-09-17 14:18:16 -06003343TEST_F(VkLayerTest, ExecuteCommandsPrimaryCB)
3344{
3345 // Attempt vkCmdExecuteCommands w/ a primary cmd buffer (should only be secondary)
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06003346
Courtney Goeltzenleuchterfd4830c2015-11-25 10:30:56 -07003347 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06003348 "vkCmdExecuteCommands() called w/ Primary Cmd Buffer ");
Tobin Ehlis4b34ddc2015-09-17 14:18:16 -06003349
3350 ASSERT_NO_FATAL_FAILURE(InitState());
3351 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlis4b34ddc2015-09-17 14:18:16 -06003352
3353 BeginCommandBuffer();
3354 //ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003355 VkCommandBuffer primCB = m_commandBuffer->GetBufferHandle();
3356 vkCmdExecuteCommands(m_commandBuffer->GetBufferHandle(), 1, &primCB);
Tobin Ehlis4b34ddc2015-09-17 14:18:16 -06003357
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06003358 if (!m_errorMonitor->DesiredMsgFound()) {
3359 FAIL() << "Did not receive Error 'vkCmdExecuteCommands() called w/ Primary Cmd Buffer '";
3360 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlis4b34ddc2015-09-17 14:18:16 -06003361 }
3362}
3363
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06003364TEST_F(VkLayerTest, DSTypeMismatch)
3365{
3366 // Create DS w/ layout of one type and attempt Update w/ mis-matched type
Tobin Ehlis3b780662015-05-28 12:11:26 -06003367 VkResult err;
3368
Courtney Goeltzenleuchterfd4830c2015-11-25 10:30:56 -07003369 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06003370 "Write descriptor update has descriptor type VK_DESCRIPTOR_TYPE_SAMPLER that does not match ");
3371
Tobin Ehlis3b780662015-05-28 12:11:26 -06003372 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlis3b780662015-05-28 12:11:26 -06003373 //VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu1b99bb22015-10-27 19:25:11 +08003374 VkDescriptorPoolSize ds_type_count = {};
Tony Barboureb254902015-07-15 12:50:33 -06003375 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wud50a7d72015-10-26 20:48:51 +08003376 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06003377
3378 VkDescriptorPoolCreateInfo ds_pool_ci = {};
3379 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
3380 ds_pool_ci.pNext = NULL;
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -06003381 ds_pool_ci.maxSets = 1;
Chia-I Wu1b99bb22015-10-27 19:25:11 +08003382 ds_pool_ci.poolSizeCount = 1;
3383 ds_pool_ci.pPoolSizes = &ds_type_count;
Tony Barboureb254902015-07-15 12:50:33 -06003384
Tobin Ehlis3b780662015-05-28 12:11:26 -06003385 VkDescriptorPool ds_pool;
Chia-I Wuf7458c52015-10-26 21:10:41 +08003386 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -06003387 ASSERT_VK_SUCCESS(err);
Tony Barboureb254902015-07-15 12:50:33 -06003388 VkDescriptorSetLayoutBinding dsl_binding = {};
Chia-I Wud46e6ae2015-10-31 00:31:16 +08003389 dsl_binding.binding = 0;
Tony Barboureb254902015-07-15 12:50:33 -06003390 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wu02124482015-11-06 06:42:02 +08003391 dsl_binding.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06003392 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
3393 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis3b780662015-05-28 12:11:26 -06003394
Tony Barboureb254902015-07-15 12:50:33 -06003395 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
3396 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
3397 ds_layout_ci.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08003398 ds_layout_ci.bindingCount = 1;
Chia-I Wua745e512015-10-31 00:31:16 +08003399 ds_layout_ci.pBinding = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -06003400
Tobin Ehlis3b780662015-05-28 12:11:26 -06003401 VkDescriptorSetLayout ds_layout;
Chia-I Wuf7458c52015-10-26 21:10:41 +08003402 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -06003403 ASSERT_VK_SUCCESS(err);
3404
3405 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003406 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08003407 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Chia-I Wud50a7d72015-10-26 20:48:51 +08003408 alloc_info.setLayoutCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06003409 alloc_info.descriptorPool = ds_pool;
3410 alloc_info.pSetLayouts = &ds_layout;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003411 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -06003412 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -06003413
Tony Barboureb254902015-07-15 12:50:33 -06003414 VkSamplerCreateInfo sampler_ci = {};
3415 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
3416 sampler_ci.pNext = NULL;
Chia-I Wub99df442015-10-26 16:49:32 +08003417 sampler_ci.magFilter = VK_FILTER_NEAREST;
3418 sampler_ci.minFilter = VK_FILTER_NEAREST;
3419 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_BASE;
Chia-I Wu1efb7e52015-10-26 17:32:47 +08003420 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
3421 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
3422 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
Tony Barboureb254902015-07-15 12:50:33 -06003423 sampler_ci.mipLodBias = 1.0;
Jon Ashburnddc8db52015-12-14 14:59:20 -07003424 sampler_ci.anisotropyEnable = VK_FALSE;
Tony Barboureb254902015-07-15 12:50:33 -06003425 sampler_ci.maxAnisotropy = 1;
3426 sampler_ci.compareEnable = VK_FALSE;
3427 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
3428 sampler_ci.minLod = 1.0;
3429 sampler_ci.maxLod = 1.0;
3430 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
Mark Lobodzinski52ac6582015-09-01 15:42:56 -06003431 sampler_ci.unnormalizedCoordinates = VK_FALSE;
3432
Tobin Ehlis3b780662015-05-28 12:11:26 -06003433 VkSampler sampler;
Chia-I Wuf7458c52015-10-26 21:10:41 +08003434 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
Tobin Ehlis3b780662015-05-28 12:11:26 -06003435 ASSERT_VK_SUCCESS(err);
3436
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -06003437 VkDescriptorImageInfo info = {};
3438 info.sampler = sampler;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08003439
3440 VkWriteDescriptorSet descriptor_write;
3441 memset(&descriptor_write, 0, sizeof(descriptor_write));
3442 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003443 descriptor_write.dstSet = descriptorSet;
Chia-I Wud50a7d72015-10-26 20:48:51 +08003444 descriptor_write.descriptorCount = 1;
Tobin Ehlis3b780662015-05-28 12:11:26 -06003445 // This is a mismatched type for the layout which expects BUFFER
Chia-I Wu9d00ed72015-05-25 16:27:55 +08003446 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -06003447 descriptor_write.pImageInfo = &info;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08003448
3449 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
3450
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06003451 if (!m_errorMonitor->DesiredMsgFound()) {
3452 FAIL() << "Did not receive Error 'Write descriptor update has descriptor type VK_DESCRIPTOR_TYPE_SAMPLER that does not match...'";
3453 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlis3b780662015-05-28 12:11:26 -06003454 }
Mike Stroyand1c84a52015-08-18 14:40:24 -06003455
Chia-I Wuf7458c52015-10-26 21:10:41 +08003456 vkDestroySampler(m_device->device(), sampler, NULL);
3457 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
3458 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06003459}
3460
3461TEST_F(VkLayerTest, DSUpdateOutOfBounds)
3462{
3463 // For overlapping Update, have arrayIndex exceed that of layout
Tobin Ehlis3b780662015-05-28 12:11:26 -06003464 VkResult err;
3465
Courtney Goeltzenleuchterfd4830c2015-11-25 10:30:56 -07003466 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06003467 "Descriptor update type of VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET is out of bounds for matching binding");
3468
Tobin Ehlis3b780662015-05-28 12:11:26 -06003469 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlis3b780662015-05-28 12:11:26 -06003470 //VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu1b99bb22015-10-27 19:25:11 +08003471 VkDescriptorPoolSize ds_type_count = {};
Tony Barboureb254902015-07-15 12:50:33 -06003472 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wud50a7d72015-10-26 20:48:51 +08003473 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06003474
3475 VkDescriptorPoolCreateInfo ds_pool_ci = {};
3476 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
3477 ds_pool_ci.pNext = NULL;
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -06003478 ds_pool_ci.maxSets = 1;
Chia-I Wu1b99bb22015-10-27 19:25:11 +08003479 ds_pool_ci.poolSizeCount = 1;
3480 ds_pool_ci.pPoolSizes = &ds_type_count;
Tony Barboureb254902015-07-15 12:50:33 -06003481
Tobin Ehlis3b780662015-05-28 12:11:26 -06003482 VkDescriptorPool ds_pool;
Chia-I Wuf7458c52015-10-26 21:10:41 +08003483 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -06003484 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -06003485
Tony Barboureb254902015-07-15 12:50:33 -06003486 VkDescriptorSetLayoutBinding dsl_binding = {};
Chia-I Wud46e6ae2015-10-31 00:31:16 +08003487 dsl_binding.binding = 0;
Tony Barboureb254902015-07-15 12:50:33 -06003488 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wu02124482015-11-06 06:42:02 +08003489 dsl_binding.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06003490 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
3491 dsl_binding.pImmutableSamplers = NULL;
3492
3493 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
3494 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
3495 ds_layout_ci.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08003496 ds_layout_ci.bindingCount = 1;
Chia-I Wua745e512015-10-31 00:31:16 +08003497 ds_layout_ci.pBinding = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -06003498
Tobin Ehlis3b780662015-05-28 12:11:26 -06003499 VkDescriptorSetLayout ds_layout;
Chia-I Wuf7458c52015-10-26 21:10:41 +08003500 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -06003501 ASSERT_VK_SUCCESS(err);
3502
3503 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003504 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08003505 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Chia-I Wud50a7d72015-10-26 20:48:51 +08003506 alloc_info.setLayoutCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06003507 alloc_info.descriptorPool = ds_pool;
3508 alloc_info.pSetLayouts = &ds_layout;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003509 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -06003510 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -06003511
Tony Barboureb254902015-07-15 12:50:33 -06003512 VkSamplerCreateInfo sampler_ci = {};
3513 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
3514 sampler_ci.pNext = NULL;
Chia-I Wub99df442015-10-26 16:49:32 +08003515 sampler_ci.magFilter = VK_FILTER_NEAREST;
3516 sampler_ci.minFilter = VK_FILTER_NEAREST;
3517 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_BASE;
Chia-I Wu1efb7e52015-10-26 17:32:47 +08003518 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
3519 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
3520 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
Tony Barboureb254902015-07-15 12:50:33 -06003521 sampler_ci.mipLodBias = 1.0;
Jon Ashburnddc8db52015-12-14 14:59:20 -07003522 sampler_ci.anisotropyEnable = VK_FALSE;
Tony Barboureb254902015-07-15 12:50:33 -06003523 sampler_ci.maxAnisotropy = 1;
3524 sampler_ci.compareEnable = VK_FALSE;
3525 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
3526 sampler_ci.minLod = 1.0;
3527 sampler_ci.maxLod = 1.0;
3528 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
Mark Lobodzinski52ac6582015-09-01 15:42:56 -06003529 sampler_ci.unnormalizedCoordinates = VK_FALSE;
Tony Barboureb254902015-07-15 12:50:33 -06003530
Tobin Ehlis3b780662015-05-28 12:11:26 -06003531 VkSampler sampler;
Chia-I Wuf7458c52015-10-26 21:10:41 +08003532 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
Tobin Ehlis3b780662015-05-28 12:11:26 -06003533 ASSERT_VK_SUCCESS(err);
Chia-I Wu9d00ed72015-05-25 16:27:55 +08003534
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -06003535 VkDescriptorImageInfo info = {};
3536 info.sampler = sampler;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08003537
3538 VkWriteDescriptorSet descriptor_write;
3539 memset(&descriptor_write, 0, sizeof(descriptor_write));
3540 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003541 descriptor_write.dstSet = descriptorSet;
3542 descriptor_write.dstArrayElement = 1; /* This index out of bounds for the update */
Chia-I Wud50a7d72015-10-26 20:48:51 +08003543 descriptor_write.descriptorCount = 1;
Tobin Ehlis3b780662015-05-28 12:11:26 -06003544 // This is the wrong type, but out of bounds will be flagged first
Chia-I Wu9d00ed72015-05-25 16:27:55 +08003545 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -06003546 descriptor_write.pImageInfo = &info;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08003547
3548 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
3549
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06003550 if (!m_errorMonitor->DesiredMsgFound()) {
3551 FAIL() << "Did not receive Error 'Descriptor update type of VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET is out of bounds for matching binding...'";
3552 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlis3b780662015-05-28 12:11:26 -06003553 }
Mike Stroyand1c84a52015-08-18 14:40:24 -06003554
Chia-I Wuf7458c52015-10-26 21:10:41 +08003555 vkDestroySampler(m_device->device(), sampler, NULL);
3556 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
3557 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06003558}
3559
3560TEST_F(VkLayerTest, InvalidDSUpdateIndex)
3561{
Tobin Ehlis3b780662015-05-28 12:11:26 -06003562 // Create layout w/ count of 1 and attempt update to that layout w/ binding index 2
Tobin Ehlis3b780662015-05-28 12:11:26 -06003563 VkResult err;
3564
Courtney Goeltzenleuchterfd4830c2015-11-25 10:30:56 -07003565 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06003566 " does not have binding to match update binding ");
3567
Tobin Ehlis3b780662015-05-28 12:11:26 -06003568 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlis3b780662015-05-28 12:11:26 -06003569 //VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu1b99bb22015-10-27 19:25:11 +08003570 VkDescriptorPoolSize ds_type_count = {};
Tony Barboureb254902015-07-15 12:50:33 -06003571 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wud50a7d72015-10-26 20:48:51 +08003572 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06003573
3574 VkDescriptorPoolCreateInfo ds_pool_ci = {};
3575 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
3576 ds_pool_ci.pNext = NULL;
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -06003577 ds_pool_ci.maxSets = 1;
Chia-I Wu1b99bb22015-10-27 19:25:11 +08003578 ds_pool_ci.poolSizeCount = 1;
3579 ds_pool_ci.pPoolSizes = &ds_type_count;
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -06003580
Tobin Ehlis3b780662015-05-28 12:11:26 -06003581 VkDescriptorPool ds_pool;
Chia-I Wuf7458c52015-10-26 21:10:41 +08003582 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -06003583 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -06003584
Tony Barboureb254902015-07-15 12:50:33 -06003585 VkDescriptorSetLayoutBinding dsl_binding = {};
Chia-I Wud46e6ae2015-10-31 00:31:16 +08003586 dsl_binding.binding = 0;
Tony Barboureb254902015-07-15 12:50:33 -06003587 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wu02124482015-11-06 06:42:02 +08003588 dsl_binding.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06003589 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
3590 dsl_binding.pImmutableSamplers = NULL;
3591
3592 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
3593 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
3594 ds_layout_ci.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08003595 ds_layout_ci.bindingCount = 1;
Chia-I Wua745e512015-10-31 00:31:16 +08003596 ds_layout_ci.pBinding = &dsl_binding;
Tobin Ehlis3b780662015-05-28 12:11:26 -06003597 VkDescriptorSetLayout ds_layout;
Chia-I Wuf7458c52015-10-26 21:10:41 +08003598 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -06003599 ASSERT_VK_SUCCESS(err);
3600
3601 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003602 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08003603 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Chia-I Wud50a7d72015-10-26 20:48:51 +08003604 alloc_info.setLayoutCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06003605 alloc_info.descriptorPool = ds_pool;
3606 alloc_info.pSetLayouts = &ds_layout;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003607 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -06003608 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -06003609
Tony Barboureb254902015-07-15 12:50:33 -06003610 VkSamplerCreateInfo sampler_ci = {};
3611 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
3612 sampler_ci.pNext = NULL;
Chia-I Wub99df442015-10-26 16:49:32 +08003613 sampler_ci.magFilter = VK_FILTER_NEAREST;
3614 sampler_ci.minFilter = VK_FILTER_NEAREST;
3615 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_BASE;
Chia-I Wu1efb7e52015-10-26 17:32:47 +08003616 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
3617 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
3618 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
Tony Barboureb254902015-07-15 12:50:33 -06003619 sampler_ci.mipLodBias = 1.0;
Jon Ashburnddc8db52015-12-14 14:59:20 -07003620 sampler_ci.anisotropyEnable = VK_FALSE;
Tony Barboureb254902015-07-15 12:50:33 -06003621 sampler_ci.maxAnisotropy = 1;
3622 sampler_ci.compareEnable = VK_FALSE;
3623 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
3624 sampler_ci.minLod = 1.0;
3625 sampler_ci.maxLod = 1.0;
3626 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
Mark Lobodzinski52ac6582015-09-01 15:42:56 -06003627 sampler_ci.unnormalizedCoordinates = VK_FALSE;
Tony Barboureb254902015-07-15 12:50:33 -06003628
Tobin Ehlis3b780662015-05-28 12:11:26 -06003629 VkSampler sampler;
Chia-I Wuf7458c52015-10-26 21:10:41 +08003630 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
Tobin Ehlis3b780662015-05-28 12:11:26 -06003631 ASSERT_VK_SUCCESS(err);
Chia-I Wu9d00ed72015-05-25 16:27:55 +08003632
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -06003633 VkDescriptorImageInfo info = {};
3634 info.sampler = sampler;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08003635
3636 VkWriteDescriptorSet descriptor_write;
3637 memset(&descriptor_write, 0, sizeof(descriptor_write));
3638 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003639 descriptor_write.dstSet = descriptorSet;
3640 descriptor_write.dstBinding = 2;
Chia-I Wud50a7d72015-10-26 20:48:51 +08003641 descriptor_write.descriptorCount = 1;
Tobin Ehlis3b780662015-05-28 12:11:26 -06003642 // This is the wrong type, but out of bounds will be flagged first
Chia-I Wu9d00ed72015-05-25 16:27:55 +08003643 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -06003644 descriptor_write.pImageInfo = &info;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08003645
3646 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
3647
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06003648 if (!m_errorMonitor->DesiredMsgFound()) {
3649 FAIL() << "Did not receive Error 'Descriptor Set <blah> does not have binding to match update binding '";
3650 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlis3b780662015-05-28 12:11:26 -06003651 }
Mike Stroyand1c84a52015-08-18 14:40:24 -06003652
Chia-I Wuf7458c52015-10-26 21:10:41 +08003653 vkDestroySampler(m_device->device(), sampler, NULL);
3654 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
3655 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06003656}
3657
3658TEST_F(VkLayerTest, InvalidDSUpdateStruct)
3659{
3660 // Call UpdateDS w/ struct type other than valid VK_STRUCTUR_TYPE_UPDATE_* types
Tobin Ehlis3b780662015-05-28 12:11:26 -06003661 VkResult err;
3662
Courtney Goeltzenleuchterfd4830c2015-11-25 10:30:56 -07003663 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06003664 "Unexpected UPDATE struct of type ");
3665
Tobin Ehlis3b780662015-05-28 12:11:26 -06003666 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski209b5292015-09-17 09:44:05 -06003667
Chia-I Wu1b99bb22015-10-27 19:25:11 +08003668 VkDescriptorPoolSize ds_type_count = {};
Tony Barboureb254902015-07-15 12:50:33 -06003669 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wud50a7d72015-10-26 20:48:51 +08003670 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06003671
3672 VkDescriptorPoolCreateInfo ds_pool_ci = {};
3673 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
3674 ds_pool_ci.pNext = NULL;
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -06003675 ds_pool_ci.maxSets = 1;
Chia-I Wu1b99bb22015-10-27 19:25:11 +08003676 ds_pool_ci.poolSizeCount = 1;
3677 ds_pool_ci.pPoolSizes = &ds_type_count;
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -06003678
Tobin Ehlis3b780662015-05-28 12:11:26 -06003679 VkDescriptorPool ds_pool;
Chia-I Wuf7458c52015-10-26 21:10:41 +08003680 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -06003681 ASSERT_VK_SUCCESS(err);
Tony Barboureb254902015-07-15 12:50:33 -06003682 VkDescriptorSetLayoutBinding dsl_binding = {};
Chia-I Wud46e6ae2015-10-31 00:31:16 +08003683 dsl_binding.binding = 0;
Tony Barboureb254902015-07-15 12:50:33 -06003684 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wu02124482015-11-06 06:42:02 +08003685 dsl_binding.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06003686 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
3687 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis3b780662015-05-28 12:11:26 -06003688
Tony Barboureb254902015-07-15 12:50:33 -06003689 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
3690 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
3691 ds_layout_ci.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08003692 ds_layout_ci.bindingCount = 1;
Chia-I Wua745e512015-10-31 00:31:16 +08003693 ds_layout_ci.pBinding = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -06003694
Tobin Ehlis3b780662015-05-28 12:11:26 -06003695 VkDescriptorSetLayout ds_layout;
Chia-I Wuf7458c52015-10-26 21:10:41 +08003696 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -06003697 ASSERT_VK_SUCCESS(err);
3698
3699 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003700 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08003701 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Chia-I Wud50a7d72015-10-26 20:48:51 +08003702 alloc_info.setLayoutCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06003703 alloc_info.descriptorPool = ds_pool;
3704 alloc_info.pSetLayouts = &ds_layout;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003705 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -06003706 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -06003707
Tony Barboureb254902015-07-15 12:50:33 -06003708 VkSamplerCreateInfo sampler_ci = {};
3709 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
3710 sampler_ci.pNext = NULL;
Chia-I Wub99df442015-10-26 16:49:32 +08003711 sampler_ci.magFilter = VK_FILTER_NEAREST;
3712 sampler_ci.minFilter = VK_FILTER_NEAREST;
3713 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_BASE;
Chia-I Wu1efb7e52015-10-26 17:32:47 +08003714 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
3715 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
3716 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
Tony Barboureb254902015-07-15 12:50:33 -06003717 sampler_ci.mipLodBias = 1.0;
Jon Ashburnddc8db52015-12-14 14:59:20 -07003718 sampler_ci.anisotropyEnable = VK_FALSE;
Tony Barboureb254902015-07-15 12:50:33 -06003719 sampler_ci.maxAnisotropy = 1;
3720 sampler_ci.compareEnable = VK_FALSE;
3721 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
3722 sampler_ci.minLod = 1.0;
3723 sampler_ci.maxLod = 1.0;
3724 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
Mark Lobodzinski52ac6582015-09-01 15:42:56 -06003725 sampler_ci.unnormalizedCoordinates = VK_FALSE;
Tobin Ehlis3b780662015-05-28 12:11:26 -06003726 VkSampler sampler;
Chia-I Wuf7458c52015-10-26 21:10:41 +08003727 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
Tobin Ehlis3b780662015-05-28 12:11:26 -06003728 ASSERT_VK_SUCCESS(err);
Chia-I Wu9d00ed72015-05-25 16:27:55 +08003729
3730
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -06003731 VkDescriptorImageInfo info = {};
3732 info.sampler = sampler;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08003733
3734 VkWriteDescriptorSet descriptor_write;
3735 memset(&descriptor_write, 0, sizeof(descriptor_write));
3736 descriptor_write.sType = (VkStructureType)0x99999999; /* Intentionally broken struct type */
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003737 descriptor_write.dstSet = descriptorSet;
Chia-I Wud50a7d72015-10-26 20:48:51 +08003738 descriptor_write.descriptorCount = 1;
Tobin Ehlis3b780662015-05-28 12:11:26 -06003739 // This is the wrong type, but out of bounds will be flagged first
Chia-I Wu9d00ed72015-05-25 16:27:55 +08003740 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -06003741 descriptor_write.pImageInfo = &info;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08003742
3743 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
3744
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06003745 if (!m_errorMonitor->DesiredMsgFound()) {
3746 FAIL() << "Did not receive Error 'Unexpected UPDATE struct of type '";
3747 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlis3b780662015-05-28 12:11:26 -06003748 }
Mike Stroyand1c84a52015-08-18 14:40:24 -06003749
Chia-I Wuf7458c52015-10-26 21:10:41 +08003750 vkDestroySampler(m_device->device(), sampler, NULL);
3751 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
3752 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06003753}
3754
Tobin Ehlisa1c28562015-10-23 16:00:08 -06003755TEST_F(VkLayerTest, SampleDescriptorUpdateError)
3756{
3757 // Create a single Sampler descriptor and send it an invalid Sampler
Tobin Ehlisa1c28562015-10-23 16:00:08 -06003758 VkResult err;
3759
Courtney Goeltzenleuchterfd4830c2015-11-25 10:30:56 -07003760 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06003761 "Attempt to update descriptor with invalid sampler 0xbaadbeef");
3762
Tobin Ehlisa1c28562015-10-23 16:00:08 -06003763 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisa1c28562015-10-23 16:00:08 -06003764 // TODO : Farm Descriptor setup code to helper function(s) to reduce copied code
Chia-I Wu1b99bb22015-10-27 19:25:11 +08003765 VkDescriptorPoolSize ds_type_count = {};
Tobin Ehlisa1c28562015-10-23 16:00:08 -06003766 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLER;
Chia-I Wud50a7d72015-10-26 20:48:51 +08003767 ds_type_count.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06003768
3769 VkDescriptorPoolCreateInfo ds_pool_ci = {};
3770 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
3771 ds_pool_ci.pNext = NULL;
3772 ds_pool_ci.maxSets = 1;
Chia-I Wu1b99bb22015-10-27 19:25:11 +08003773 ds_pool_ci.poolSizeCount = 1;
3774 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06003775
3776 VkDescriptorPool ds_pool;
Chia-I Wuf7458c52015-10-26 21:10:41 +08003777 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06003778 ASSERT_VK_SUCCESS(err);
3779
3780 VkDescriptorSetLayoutBinding dsl_binding = {};
Chia-I Wud46e6ae2015-10-31 00:31:16 +08003781 dsl_binding.binding = 0;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06003782 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Chia-I Wu02124482015-11-06 06:42:02 +08003783 dsl_binding.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06003784 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
3785 dsl_binding.pImmutableSamplers = NULL;
3786
3787 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
3788 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
3789 ds_layout_ci.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08003790 ds_layout_ci.bindingCount = 1;
Chia-I Wua745e512015-10-31 00:31:16 +08003791 ds_layout_ci.pBinding = &dsl_binding;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06003792 VkDescriptorSetLayout ds_layout;
Chia-I Wuf7458c52015-10-26 21:10:41 +08003793 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06003794 ASSERT_VK_SUCCESS(err);
3795
3796 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003797 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08003798 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Chia-I Wud50a7d72015-10-26 20:48:51 +08003799 alloc_info.setLayoutCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06003800 alloc_info.descriptorPool = ds_pool;
3801 alloc_info.pSetLayouts = &ds_layout;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003802 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06003803 ASSERT_VK_SUCCESS(err);
3804
Chia-I Wue2fc5522015-10-26 20:04:44 +08003805 VkSampler sampler = (VkSampler) 0xbaadbeef; // Sampler with invalid handle
Tobin Ehlisa1c28562015-10-23 16:00:08 -06003806
3807 VkDescriptorImageInfo descriptor_info;
3808 memset(&descriptor_info, 0, sizeof(VkDescriptorImageInfo));
3809 descriptor_info.sampler = sampler;
3810
3811 VkWriteDescriptorSet descriptor_write;
3812 memset(&descriptor_write, 0, sizeof(descriptor_write));
3813 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003814 descriptor_write.dstSet = descriptorSet;
3815 descriptor_write.dstBinding = 0;
Chia-I Wud50a7d72015-10-26 20:48:51 +08003816 descriptor_write.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06003817 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
3818 descriptor_write.pImageInfo = &descriptor_info;
3819
3820 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
3821
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06003822 if (!m_errorMonitor->DesiredMsgFound()) {
3823 FAIL() << "Did not receive Error 'Attempt to update descriptor with invalid sampler...'";
3824 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlisa1c28562015-10-23 16:00:08 -06003825 }
3826
Chia-I Wuf7458c52015-10-26 21:10:41 +08003827 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
3828 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06003829}
3830
3831TEST_F(VkLayerTest, ImageViewDescriptorUpdateError)
3832{
3833 // Create a single combined Image/Sampler descriptor and send it an invalid imageView
Tobin Ehlisa1c28562015-10-23 16:00:08 -06003834 VkResult err;
3835
Courtney Goeltzenleuchterfd4830c2015-11-25 10:30:56 -07003836 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06003837 "Attempt to update descriptor with invalid imageView 0xbaadbeef");
3838
Tobin Ehlisa1c28562015-10-23 16:00:08 -06003839 ASSERT_NO_FATAL_FAILURE(InitState());
Chia-I Wu1b99bb22015-10-27 19:25:11 +08003840 VkDescriptorPoolSize ds_type_count = {};
Tobin Ehlisa1c28562015-10-23 16:00:08 -06003841 ds_type_count.type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
Chia-I Wud50a7d72015-10-26 20:48:51 +08003842 ds_type_count.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06003843
3844 VkDescriptorPoolCreateInfo ds_pool_ci = {};
3845 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
3846 ds_pool_ci.pNext = NULL;
3847 ds_pool_ci.maxSets = 1;
Chia-I Wu1b99bb22015-10-27 19:25:11 +08003848 ds_pool_ci.poolSizeCount = 1;
3849 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06003850
3851 VkDescriptorPool ds_pool;
Chia-I Wuf7458c52015-10-26 21:10:41 +08003852 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06003853 ASSERT_VK_SUCCESS(err);
3854
3855 VkDescriptorSetLayoutBinding dsl_binding = {};
Chia-I Wud46e6ae2015-10-31 00:31:16 +08003856 dsl_binding.binding = 0;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06003857 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
Chia-I Wu02124482015-11-06 06:42:02 +08003858 dsl_binding.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06003859 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
3860 dsl_binding.pImmutableSamplers = NULL;
3861
3862 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
3863 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
3864 ds_layout_ci.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08003865 ds_layout_ci.bindingCount = 1;
Chia-I Wua745e512015-10-31 00:31:16 +08003866 ds_layout_ci.pBinding = &dsl_binding;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06003867 VkDescriptorSetLayout ds_layout;
Chia-I Wuf7458c52015-10-26 21:10:41 +08003868 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06003869 ASSERT_VK_SUCCESS(err);
3870
3871 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003872 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08003873 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Chia-I Wud50a7d72015-10-26 20:48:51 +08003874 alloc_info.setLayoutCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06003875 alloc_info.descriptorPool = ds_pool;
3876 alloc_info.pSetLayouts = &ds_layout;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003877 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06003878 ASSERT_VK_SUCCESS(err);
3879
3880 VkSamplerCreateInfo sampler_ci = {};
3881 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
3882 sampler_ci.pNext = NULL;
Chia-I Wub99df442015-10-26 16:49:32 +08003883 sampler_ci.magFilter = VK_FILTER_NEAREST;
3884 sampler_ci.minFilter = VK_FILTER_NEAREST;
3885 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_BASE;
Chia-I Wu1efb7e52015-10-26 17:32:47 +08003886 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
3887 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
3888 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06003889 sampler_ci.mipLodBias = 1.0;
Jon Ashburnddc8db52015-12-14 14:59:20 -07003890 sampler_ci.anisotropyEnable = VK_FALSE;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06003891 sampler_ci.maxAnisotropy = 1;
3892 sampler_ci.compareEnable = VK_FALSE;
3893 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
3894 sampler_ci.minLod = 1.0;
3895 sampler_ci.maxLod = 1.0;
3896 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
3897 sampler_ci.unnormalizedCoordinates = VK_FALSE;
3898
3899 VkSampler sampler;
Chia-I Wuf7458c52015-10-26 21:10:41 +08003900 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06003901 ASSERT_VK_SUCCESS(err);
3902
Chia-I Wue2fc5522015-10-26 20:04:44 +08003903 VkImageView view = (VkImageView) 0xbaadbeef; // invalid imageView object
Tobin Ehlisa1c28562015-10-23 16:00:08 -06003904
3905 VkDescriptorImageInfo descriptor_info;
3906 memset(&descriptor_info, 0, sizeof(VkDescriptorImageInfo));
3907 descriptor_info.sampler = sampler;
3908 descriptor_info.imageView = view;
3909
3910 VkWriteDescriptorSet descriptor_write;
3911 memset(&descriptor_write, 0, sizeof(descriptor_write));
3912 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003913 descriptor_write.dstSet = descriptorSet;
3914 descriptor_write.dstBinding = 0;
Chia-I Wud50a7d72015-10-26 20:48:51 +08003915 descriptor_write.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06003916 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
3917 descriptor_write.pImageInfo = &descriptor_info;
3918
3919 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
3920
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06003921 if (!m_errorMonitor->DesiredMsgFound()) {
3922 FAIL() << "Did not receive Error 'Attempt to update descriptor with invalid imageView...'";
3923 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlisa1c28562015-10-23 16:00:08 -06003924 }
3925
Chia-I Wuf7458c52015-10-26 21:10:41 +08003926 vkDestroySampler(m_device->device(), sampler, NULL);
3927 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
3928 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06003929}
3930
Tobin Ehlis04356f92015-10-27 16:35:27 -06003931TEST_F(VkLayerTest, CopyDescriptorUpdateErrors)
3932{
3933 // 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 -06003934 VkResult err;
3935
Courtney Goeltzenleuchterfd4830c2015-11-25 10:30:56 -07003936 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06003937 "Copy descriptor update index 0, update count #1, has src update descriptor type VK_DESCRIPTOR_TYPE_SAMPLER ");
3938
Tobin Ehlis04356f92015-10-27 16:35:27 -06003939 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlis04356f92015-10-27 16:35:27 -06003940 //VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu1b99bb22015-10-27 19:25:11 +08003941 VkDescriptorPoolSize ds_type_count[2] = {};
Tobin Ehlis04356f92015-10-27 16:35:27 -06003942 ds_type_count[0].type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wud50a7d72015-10-26 20:48:51 +08003943 ds_type_count[0].descriptorCount = 1;
Tobin Ehlis04356f92015-10-27 16:35:27 -06003944 ds_type_count[1].type = VK_DESCRIPTOR_TYPE_SAMPLER;
Chia-I Wud50a7d72015-10-26 20:48:51 +08003945 ds_type_count[1].descriptorCount = 1;
Tobin Ehlis04356f92015-10-27 16:35:27 -06003946
3947 VkDescriptorPoolCreateInfo ds_pool_ci = {};
3948 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
3949 ds_pool_ci.pNext = NULL;
3950 ds_pool_ci.maxSets = 1;
Chia-I Wu1b99bb22015-10-27 19:25:11 +08003951 ds_pool_ci.poolSizeCount = 2;
3952 ds_pool_ci.pPoolSizes = ds_type_count;
Tobin Ehlis04356f92015-10-27 16:35:27 -06003953
3954 VkDescriptorPool ds_pool;
Chia-I Wuf7458c52015-10-26 21:10:41 +08003955 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis04356f92015-10-27 16:35:27 -06003956 ASSERT_VK_SUCCESS(err);
3957 VkDescriptorSetLayoutBinding dsl_binding[2] = {};
Chia-I Wud46e6ae2015-10-31 00:31:16 +08003958 dsl_binding[0].binding = 0;
Tobin Ehlis04356f92015-10-27 16:35:27 -06003959 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wu02124482015-11-06 06:42:02 +08003960 dsl_binding[0].descriptorCount = 1;
Tobin Ehlis04356f92015-10-27 16:35:27 -06003961 dsl_binding[0].stageFlags = VK_SHADER_STAGE_ALL;
3962 dsl_binding[0].pImmutableSamplers = NULL;
Chia-I Wud46e6ae2015-10-31 00:31:16 +08003963 dsl_binding[1].binding = 1;
Tobin Ehlis04356f92015-10-27 16:35:27 -06003964 dsl_binding[1].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Chia-I Wu02124482015-11-06 06:42:02 +08003965 dsl_binding[1].descriptorCount = 1;
Tobin Ehlis04356f92015-10-27 16:35:27 -06003966 dsl_binding[1].stageFlags = VK_SHADER_STAGE_ALL;
3967 dsl_binding[1].pImmutableSamplers = NULL;
3968
3969 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
3970 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
3971 ds_layout_ci.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08003972 ds_layout_ci.bindingCount = 2;
Chia-I Wua745e512015-10-31 00:31:16 +08003973 ds_layout_ci.pBinding = dsl_binding;
Tobin Ehlis04356f92015-10-27 16:35:27 -06003974
3975 VkDescriptorSetLayout ds_layout;
Chia-I Wuf7458c52015-10-26 21:10:41 +08003976 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis04356f92015-10-27 16:35:27 -06003977 ASSERT_VK_SUCCESS(err);
3978
3979 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003980 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08003981 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Chia-I Wud50a7d72015-10-26 20:48:51 +08003982 alloc_info.setLayoutCount = 1;
Tobin Ehlis04356f92015-10-27 16:35:27 -06003983 alloc_info.descriptorPool = ds_pool;
3984 alloc_info.pSetLayouts = &ds_layout;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003985 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis04356f92015-10-27 16:35:27 -06003986 ASSERT_VK_SUCCESS(err);
3987
3988 VkSamplerCreateInfo sampler_ci = {};
3989 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
3990 sampler_ci.pNext = NULL;
Chia-I Wub99df442015-10-26 16:49:32 +08003991 sampler_ci.magFilter = VK_FILTER_NEAREST;
3992 sampler_ci.minFilter = VK_FILTER_NEAREST;
3993 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_BASE;
Chia-I Wu1efb7e52015-10-26 17:32:47 +08003994 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
3995 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
3996 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
Tobin Ehlis04356f92015-10-27 16:35:27 -06003997 sampler_ci.mipLodBias = 1.0;
Jon Ashburnddc8db52015-12-14 14:59:20 -07003998 sampler_ci.anisotropyEnable = VK_FALSE;
Tobin Ehlis04356f92015-10-27 16:35:27 -06003999 sampler_ci.maxAnisotropy = 1;
4000 sampler_ci.compareEnable = VK_FALSE;
4001 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
4002 sampler_ci.minLod = 1.0;
4003 sampler_ci.maxLod = 1.0;
4004 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
4005 sampler_ci.unnormalizedCoordinates = VK_FALSE;
4006
4007 VkSampler sampler;
Chia-I Wuf7458c52015-10-26 21:10:41 +08004008 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
Tobin Ehlis04356f92015-10-27 16:35:27 -06004009 ASSERT_VK_SUCCESS(err);
4010
4011 VkDescriptorImageInfo info = {};
4012 info.sampler = sampler;
4013
4014 VkWriteDescriptorSet descriptor_write;
4015 memset(&descriptor_write, 0, sizeof(VkWriteDescriptorSet));
4016 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004017 descriptor_write.dstSet = descriptorSet;
4018 descriptor_write.dstBinding = 1; // SAMPLER binding from layout above
Chia-I Wud50a7d72015-10-26 20:48:51 +08004019 descriptor_write.descriptorCount = 1;
Tobin Ehlis04356f92015-10-27 16:35:27 -06004020 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
4021 descriptor_write.pImageInfo = &info;
4022 // This write update should succeed
4023 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
4024 // Now perform a copy update that fails due to type mismatch
4025 VkCopyDescriptorSet copy_ds_update;
4026 memset(&copy_ds_update, 0, sizeof(VkCopyDescriptorSet));
4027 copy_ds_update.sType = VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET;
4028 copy_ds_update.srcSet = descriptorSet;
4029 copy_ds_update.srcBinding = 1; // copy from SAMPLER binding
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004030 copy_ds_update.dstSet = descriptorSet;
4031 copy_ds_update.dstBinding = 0; // ERROR : copy to UNIFORM binding
Chia-I Wud50a7d72015-10-26 20:48:51 +08004032 copy_ds_update.descriptorCount = 1; // copy 1 descriptor
Tobin Ehlis04356f92015-10-27 16:35:27 -06004033 vkUpdateDescriptorSets(m_device->device(), 0, NULL, 1, &copy_ds_update);
4034
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06004035 if (!m_errorMonitor->DesiredMsgFound()) {
4036 FAIL() << "Did not receive Error 'Copy descriptor update index 0, update count #1, has src update descriptor type_DESCRIPTOR_TYPE_SAMPLER'";
4037 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlis04356f92015-10-27 16:35:27 -06004038 }
4039 // Now perform a copy update that fails due to binding out of bounds
Courtney Goeltzenleuchterfd4830c2015-11-25 10:30:56 -07004040 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06004041 "Copy descriptor update 0 has srcBinding 3 which is out of bounds ");
Tobin Ehlis04356f92015-10-27 16:35:27 -06004042 memset(&copy_ds_update, 0, sizeof(VkCopyDescriptorSet));
4043 copy_ds_update.sType = VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET;
4044 copy_ds_update.srcSet = descriptorSet;
4045 copy_ds_update.srcBinding = 3; // ERROR : Invalid binding for matching layout
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004046 copy_ds_update.dstSet = descriptorSet;
4047 copy_ds_update.dstBinding = 0;
Chia-I Wud50a7d72015-10-26 20:48:51 +08004048 copy_ds_update.descriptorCount = 1; // copy 1 descriptor
Tobin Ehlis04356f92015-10-27 16:35:27 -06004049 vkUpdateDescriptorSets(m_device->device(), 0, NULL, 1, &copy_ds_update);
4050
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06004051 if (!m_errorMonitor->DesiredMsgFound()) {
4052 FAIL() << "Did not receive Error 'Copy descriptor update 0 has srcBinding 3 which is out of bounds...'";
4053 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlis04356f92015-10-27 16:35:27 -06004054 }
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06004055
Tobin Ehlis04356f92015-10-27 16:35:27 -06004056 // Now perform a copy update that fails due to binding out of bounds
Courtney Goeltzenleuchterfd4830c2015-11-25 10:30:56 -07004057 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06004058 "Copy descriptor src update is out of bounds for matching binding 1 ");
4059
Tobin Ehlis04356f92015-10-27 16:35:27 -06004060 memset(&copy_ds_update, 0, sizeof(VkCopyDescriptorSet));
4061 copy_ds_update.sType = VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET;
4062 copy_ds_update.srcSet = descriptorSet;
4063 copy_ds_update.srcBinding = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004064 copy_ds_update.dstSet = descriptorSet;
4065 copy_ds_update.dstBinding = 0;
Chia-I Wud50a7d72015-10-26 20:48:51 +08004066 copy_ds_update.descriptorCount = 5; // ERROR copy 5 descriptors (out of bounds for layout)
Tobin Ehlis04356f92015-10-27 16:35:27 -06004067 vkUpdateDescriptorSets(m_device->device(), 0, NULL, 1, &copy_ds_update);
4068
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06004069 if (!m_errorMonitor->DesiredMsgFound()) {
4070 FAIL() << "Did not receive Error 'Copy descriptor src update is out of bounds for matching binding 1...'";
4071 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlis04356f92015-10-27 16:35:27 -06004072 }
4073
Chia-I Wuf7458c52015-10-26 21:10:41 +08004074 vkDestroySampler(m_device->device(), sampler, NULL);
4075 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
4076 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis04356f92015-10-27 16:35:27 -06004077}
4078
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06004079TEST_F(VkLayerTest, NumSamplesMismatch)
4080{
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004081 // Create CommandBuffer where MSAA samples doesn't match RenderPass sampleCount
Tobin Ehlis3b780662015-05-28 12:11:26 -06004082 VkResult err;
4083
Courtney Goeltzenleuchterfd4830c2015-11-25 10:30:56 -07004084 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06004085 "Num samples mismatch! ");
4086
Tobin Ehlis3b780662015-05-28 12:11:26 -06004087 ASSERT_NO_FATAL_FAILURE(InitState());
4088 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chia-I Wu1b99bb22015-10-27 19:25:11 +08004089 VkDescriptorPoolSize ds_type_count = {};
Tony Barboureb254902015-07-15 12:50:33 -06004090 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wud50a7d72015-10-26 20:48:51 +08004091 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06004092
4093 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -06004094 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
4095 ds_pool_ci.pNext = NULL;
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -06004096 ds_pool_ci.maxSets = 1;
Chia-I Wu1b99bb22015-10-27 19:25:11 +08004097 ds_pool_ci.poolSizeCount = 1;
4098 ds_pool_ci.pPoolSizes = &ds_type_count;
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -06004099
Tobin Ehlis3b780662015-05-28 12:11:26 -06004100 VkDescriptorPool ds_pool;
Chia-I Wuf7458c52015-10-26 21:10:41 +08004101 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -06004102 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -06004103
Tony Barboureb254902015-07-15 12:50:33 -06004104 VkDescriptorSetLayoutBinding dsl_binding = {};
Chia-I Wud46e6ae2015-10-31 00:31:16 +08004105 dsl_binding.binding = 0;
Tony Barboureb254902015-07-15 12:50:33 -06004106 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wu02124482015-11-06 06:42:02 +08004107 dsl_binding.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06004108 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
4109 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis3b780662015-05-28 12:11:26 -06004110
Tony Barboureb254902015-07-15 12:50:33 -06004111 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
4112 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
4113 ds_layout_ci.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08004114 ds_layout_ci.bindingCount = 1;
Chia-I Wua745e512015-10-31 00:31:16 +08004115 ds_layout_ci.pBinding = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -06004116
Tobin Ehlis3b780662015-05-28 12:11:26 -06004117 VkDescriptorSetLayout ds_layout;
Chia-I Wuf7458c52015-10-26 21:10:41 +08004118 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -06004119 ASSERT_VK_SUCCESS(err);
4120
4121 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004122 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08004123 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Chia-I Wud50a7d72015-10-26 20:48:51 +08004124 alloc_info.setLayoutCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06004125 alloc_info.descriptorPool = ds_pool;
4126 alloc_info.pSetLayouts = &ds_layout;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004127 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -06004128 ASSERT_VK_SUCCESS(err);
4129
Tony Barboureb254902015-07-15 12:50:33 -06004130 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
4131 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
4132 pipe_ms_state_ci.pNext = NULL;
Chia-I Wu5c17c962015-10-31 00:31:16 +08004133 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_4_BIT;
Tony Barboureb254902015-07-15 12:50:33 -06004134 pipe_ms_state_ci.sampleShadingEnable = 0;
4135 pipe_ms_state_ci.minSampleShading = 1.0;
Cody Northrop02e61ed2015-08-04 14:34:54 -06004136 pipe_ms_state_ci.pSampleMask = NULL;
Tobin Ehlis3b780662015-05-28 12:11:26 -06004137
Tony Barboureb254902015-07-15 12:50:33 -06004138 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
4139 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
4140 pipeline_layout_ci.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08004141 pipeline_layout_ci.setLayoutCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06004142 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis3b780662015-05-28 12:11:26 -06004143
4144 VkPipelineLayout pipeline_layout;
Chia-I Wuf7458c52015-10-26 21:10:41 +08004145 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -06004146 ASSERT_VK_SUCCESS(err);
4147
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06004148 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
4149 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 -06004150 // but add it to be able to run on more devices
Tony Barbour62e1a5b2015-08-06 10:16:07 -06004151 VkPipelineObj pipe(m_device);
4152 pipe.AddShader(&vs);
Tony Barbour1c94d372015-08-06 11:21:08 -06004153 pipe.AddShader(&fs);
Tony Barbour62e1a5b2015-08-06 10:16:07 -06004154 pipe.SetMSAA(&pipe_ms_state_ci);
4155 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tobin Ehlis3b780662015-05-28 12:11:26 -06004156
Tony Barbourfe3351b2015-07-28 10:17:20 -06004157 BeginCommandBuffer();
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004158 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlis3b780662015-05-28 12:11:26 -06004159
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06004160 if (!m_errorMonitor->DesiredMsgFound()) {
4161 FAIL() << "Did not recieve Error 'Num samples mismatch!...'";
4162 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlis3b780662015-05-28 12:11:26 -06004163 }
Mike Stroyand1c84a52015-08-18 14:40:24 -06004164
Chia-I Wuf7458c52015-10-26 21:10:41 +08004165 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
4166 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
4167 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06004168}
Tobin Ehlis53eddda2015-07-01 16:46:13 -06004169
Tobin Ehlis53eddda2015-07-01 16:46:13 -06004170TEST_F(VkLayerTest, ClearCmdNoDraw)
4171{
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004172 // Create CommandBuffer where we add ClearCmd for FB Color attachment prior to issuing a Draw
Tobin Ehlis53eddda2015-07-01 16:46:13 -06004173 VkResult err;
4174
Courtney Goeltzenleuchterfd4830c2015-11-25 10:30:56 -07004175 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARN_BIT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06004176 "vkCmdClearAttachments() issued on CB object ");
4177
Tobin Ehlis53eddda2015-07-01 16:46:13 -06004178 ASSERT_NO_FATAL_FAILURE(InitState());
4179 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barboureb254902015-07-15 12:50:33 -06004180
Chia-I Wu1b99bb22015-10-27 19:25:11 +08004181 VkDescriptorPoolSize ds_type_count = {};
Tony Barboureb254902015-07-15 12:50:33 -06004182 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wud50a7d72015-10-26 20:48:51 +08004183 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06004184
4185 VkDescriptorPoolCreateInfo ds_pool_ci = {};
4186 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
4187 ds_pool_ci.pNext = NULL;
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -06004188 ds_pool_ci.maxSets = 1;
Chia-I Wu1b99bb22015-10-27 19:25:11 +08004189 ds_pool_ci.poolSizeCount = 1;
4190 ds_pool_ci.pPoolSizes = &ds_type_count;
Tony Barboureb254902015-07-15 12:50:33 -06004191
Tobin Ehlis53eddda2015-07-01 16:46:13 -06004192 VkDescriptorPool ds_pool;
Chia-I Wuf7458c52015-10-26 21:10:41 +08004193 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis53eddda2015-07-01 16:46:13 -06004194 ASSERT_VK_SUCCESS(err);
4195
Tony Barboureb254902015-07-15 12:50:33 -06004196 VkDescriptorSetLayoutBinding dsl_binding = {};
Chia-I Wud46e6ae2015-10-31 00:31:16 +08004197 dsl_binding.binding = 0;
Tony Barboureb254902015-07-15 12:50:33 -06004198 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wu02124482015-11-06 06:42:02 +08004199 dsl_binding.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06004200 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
4201 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis53eddda2015-07-01 16:46:13 -06004202
Tony Barboureb254902015-07-15 12:50:33 -06004203 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
4204 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
4205 ds_layout_ci.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08004206 ds_layout_ci.bindingCount = 1;
Chia-I Wua745e512015-10-31 00:31:16 +08004207 ds_layout_ci.pBinding = &dsl_binding;
Mark Lobodzinski209b5292015-09-17 09:44:05 -06004208
Tobin Ehlis53eddda2015-07-01 16:46:13 -06004209 VkDescriptorSetLayout ds_layout;
Chia-I Wuf7458c52015-10-26 21:10:41 +08004210 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis53eddda2015-07-01 16:46:13 -06004211 ASSERT_VK_SUCCESS(err);
4212
4213 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004214 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08004215 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Chia-I Wud50a7d72015-10-26 20:48:51 +08004216 alloc_info.setLayoutCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06004217 alloc_info.descriptorPool = ds_pool;
4218 alloc_info.pSetLayouts = &ds_layout;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004219 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis53eddda2015-07-01 16:46:13 -06004220 ASSERT_VK_SUCCESS(err);
4221
Tony Barboureb254902015-07-15 12:50:33 -06004222 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
4223 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
4224 pipe_ms_state_ci.pNext = NULL;
Chia-I Wu5c17c962015-10-31 00:31:16 +08004225 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_4_BIT;
Tony Barboureb254902015-07-15 12:50:33 -06004226 pipe_ms_state_ci.sampleShadingEnable = 0;
4227 pipe_ms_state_ci.minSampleShading = 1.0;
Cody Northrop02e61ed2015-08-04 14:34:54 -06004228 pipe_ms_state_ci.pSampleMask = NULL;
Tobin Ehlis53eddda2015-07-01 16:46:13 -06004229
Tony Barboureb254902015-07-15 12:50:33 -06004230 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
4231 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
4232 pipeline_layout_ci.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08004233 pipeline_layout_ci.setLayoutCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06004234 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis53eddda2015-07-01 16:46:13 -06004235
4236 VkPipelineLayout pipeline_layout;
Chia-I Wuf7458c52015-10-26 21:10:41 +08004237 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis53eddda2015-07-01 16:46:13 -06004238 ASSERT_VK_SUCCESS(err);
Mark Lobodzinski209b5292015-09-17 09:44:05 -06004239
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06004240 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06004241 // TODO - We shouldn't need a fragment shader but add it to be able to run on more devices
4242 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
4243
Tony Barbour62e1a5b2015-08-06 10:16:07 -06004244 VkPipelineObj pipe(m_device);
4245 pipe.AddShader(&vs);
Tony Barbour1c94d372015-08-06 11:21:08 -06004246 pipe.AddShader(&fs);
Tony Barbour62e1a5b2015-08-06 10:16:07 -06004247 pipe.SetMSAA(&pipe_ms_state_ci);
4248 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tony Barbourfe3351b2015-07-28 10:17:20 -06004249
4250 BeginCommandBuffer();
Tobin Ehlis53eddda2015-07-01 16:46:13 -06004251
Tobin Ehlis53eddda2015-07-01 16:46:13 -06004252 // Main thing we care about for this test is that the VkImage obj we're clearing matches Color Attachment of FB
4253 // Also pass down other dummy params to keep driver and paramchecker happy
Courtney Goeltzenleuchterc9323e02015-10-15 16:51:05 -06004254 VkClearAttachment color_attachment;
4255 color_attachment.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
4256 color_attachment.clearValue.color.float32[0] = 1.0;
4257 color_attachment.clearValue.color.float32[1] = 1.0;
4258 color_attachment.clearValue.color.float32[2] = 1.0;
4259 color_attachment.clearValue.color.float32[3] = 1.0;
4260 color_attachment.colorAttachment = 0;
Courtney Goeltzenleuchter5d2aed42015-10-21 17:57:31 -06004261 VkClearRect clear_rect = { { { 0, 0 }, { (int)m_width, (int)m_height } } };
Tobin Ehlis53eddda2015-07-01 16:46:13 -06004262
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004263 vkCmdClearAttachments(m_commandBuffer->GetBufferHandle(), 1, &color_attachment, 1, &clear_rect);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06004264
4265 if (!m_errorMonitor->DesiredMsgFound()) {
4266 FAIL() << "Did not receive Error 'vkCommandClearAttachments() issued on CB object...'";
4267 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlis53eddda2015-07-01 16:46:13 -06004268 }
Mike Stroyand1c84a52015-08-18 14:40:24 -06004269
Chia-I Wuf7458c52015-10-26 21:10:41 +08004270 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
4271 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
4272 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis53eddda2015-07-01 16:46:13 -06004273}
4274
Tobin Ehlis502480b2015-06-24 15:53:07 -06004275TEST_F(VkLayerTest, VtxBufferBadIndex)
4276{
Tobin Ehlis502480b2015-06-24 15:53:07 -06004277 VkResult err;
4278
Mark Lobodzinskidfcd9b62015-12-14 15:14:10 -07004279 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERF_WARN_BIT,
4280 "but no vertex buffers are attached to this Pipeline State Object");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06004281
Tobin Ehlis502480b2015-06-24 15:53:07 -06004282 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisd332f282015-10-02 11:00:56 -06004283 ASSERT_NO_FATAL_FAILURE(InitViewport());
Tobin Ehlis502480b2015-06-24 15:53:07 -06004284 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barboureb254902015-07-15 12:50:33 -06004285
Chia-I Wu1b99bb22015-10-27 19:25:11 +08004286 VkDescriptorPoolSize ds_type_count = {};
Tony Barboureb254902015-07-15 12:50:33 -06004287 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wud50a7d72015-10-26 20:48:51 +08004288 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06004289
4290 VkDescriptorPoolCreateInfo ds_pool_ci = {};
4291 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
4292 ds_pool_ci.pNext = NULL;
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -06004293 ds_pool_ci.maxSets = 1;
Chia-I Wu1b99bb22015-10-27 19:25:11 +08004294 ds_pool_ci.poolSizeCount = 1;
4295 ds_pool_ci.pPoolSizes = &ds_type_count;
Tony Barboureb254902015-07-15 12:50:33 -06004296
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -06004297 VkDescriptorPool ds_pool;
Chia-I Wuf7458c52015-10-26 21:10:41 +08004298 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis502480b2015-06-24 15:53:07 -06004299 ASSERT_VK_SUCCESS(err);
4300
Tony Barboureb254902015-07-15 12:50:33 -06004301 VkDescriptorSetLayoutBinding dsl_binding = {};
Chia-I Wud46e6ae2015-10-31 00:31:16 +08004302 dsl_binding.binding = 0;
Tony Barboureb254902015-07-15 12:50:33 -06004303 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wu02124482015-11-06 06:42:02 +08004304 dsl_binding.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06004305 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
4306 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis502480b2015-06-24 15:53:07 -06004307
Tony Barboureb254902015-07-15 12:50:33 -06004308 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
4309 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
4310 ds_layout_ci.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08004311 ds_layout_ci.bindingCount = 1;
Chia-I Wua745e512015-10-31 00:31:16 +08004312 ds_layout_ci.pBinding = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -06004313
Tobin Ehlis502480b2015-06-24 15:53:07 -06004314 VkDescriptorSetLayout ds_layout;
Chia-I Wuf7458c52015-10-26 21:10:41 +08004315 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis502480b2015-06-24 15:53:07 -06004316 ASSERT_VK_SUCCESS(err);
4317
4318 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004319 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08004320 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Chia-I Wud50a7d72015-10-26 20:48:51 +08004321 alloc_info.setLayoutCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06004322 alloc_info.descriptorPool = ds_pool;
4323 alloc_info.pSetLayouts = &ds_layout;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004324 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis502480b2015-06-24 15:53:07 -06004325 ASSERT_VK_SUCCESS(err);
4326
Tony Barboureb254902015-07-15 12:50:33 -06004327 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
4328 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
4329 pipe_ms_state_ci.pNext = NULL;
Chia-I Wu5c17c962015-10-31 00:31:16 +08004330 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
Tony Barboureb254902015-07-15 12:50:33 -06004331 pipe_ms_state_ci.sampleShadingEnable = 0;
4332 pipe_ms_state_ci.minSampleShading = 1.0;
Cody Northrop02e61ed2015-08-04 14:34:54 -06004333 pipe_ms_state_ci.pSampleMask = NULL;
Tobin Ehlis502480b2015-06-24 15:53:07 -06004334
Tony Barboureb254902015-07-15 12:50:33 -06004335 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
4336 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
4337 pipeline_layout_ci.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08004338 pipeline_layout_ci.setLayoutCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06004339 pipeline_layout_ci.pSetLayouts = &ds_layout;
4340 VkPipelineLayout pipeline_layout;
Tobin Ehlis502480b2015-06-24 15:53:07 -06004341
Chia-I Wuf7458c52015-10-26 21:10:41 +08004342 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis502480b2015-06-24 15:53:07 -06004343 ASSERT_VK_SUCCESS(err);
4344
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06004345 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
4346 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 -06004347 // but add it to be able to run on more devices
Tony Barbour62e1a5b2015-08-06 10:16:07 -06004348 VkPipelineObj pipe(m_device);
4349 pipe.AddShader(&vs);
Tony Barbour1c94d372015-08-06 11:21:08 -06004350 pipe.AddShader(&fs);
Tony Barbour62e1a5b2015-08-06 10:16:07 -06004351 pipe.SetMSAA(&pipe_ms_state_ci);
Tobin Ehlisd332f282015-10-02 11:00:56 -06004352 pipe.SetViewport(m_viewports);
4353 pipe.SetScissor(m_scissors);
Tony Barbour62e1a5b2015-08-06 10:16:07 -06004354 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tony Barbourfe3351b2015-07-28 10:17:20 -06004355
4356 BeginCommandBuffer();
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004357 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlisf7bf4502015-09-09 15:12:35 -06004358 // Don't care about actual data, just need to get to draw to flag error
4359 static const float vbo_data[3] = {1.f, 0.f, 1.f};
4360 VkConstantBufferObj vbo(m_device, sizeof(vbo_data), sizeof(float), (const void*) &vbo_data);
4361 BindVertexBuffer(&vbo, (VkDeviceSize)0, 1); // VBO idx 1, but no VBO in PSO
Courtney Goeltzenleuchter08c26372015-09-23 12:31:50 -06004362 Draw(1, 0, 0, 0);
Tobin Ehlis502480b2015-06-24 15:53:07 -06004363
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06004364 if (!m_errorMonitor->DesiredMsgFound()) {
4365 FAIL() << "Did not receive Error 'Vtx Buffer Index 0 was bound, but no vtx buffers are attached to PSO.'";
4366 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlis502480b2015-06-24 15:53:07 -06004367 }
Mike Stroyand1c84a52015-08-18 14:40:24 -06004368
Chia-I Wuf7458c52015-10-26 21:10:41 +08004369 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
4370 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
4371 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis502480b2015-06-24 15:53:07 -06004372}
Mark Lobodzinski209b5292015-09-17 09:44:05 -06004373#endif // DRAW_STATE_TESTS
4374
Tobin Ehlis0788f522015-05-26 16:11:58 -06004375#if THREADING_TESTS
Mike Stroyanaccf7692015-05-12 16:00:45 -06004376#if GTEST_IS_THREADSAFE
4377struct thread_data_struct {
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004378 VkCommandBuffer commandBuffer;
Mike Stroyanaccf7692015-05-12 16:00:45 -06004379 VkEvent event;
4380 bool bailout;
4381};
4382
4383extern "C" void *AddToCommandBuffer(void *arg)
4384{
4385 struct thread_data_struct *data = (struct thread_data_struct *) arg;
Mike Stroyanaccf7692015-05-12 16:00:45 -06004386
4387 for (int i = 0; i<10000; i++) {
Chia-I Wu89d0f942015-10-31 00:31:16 +08004388 vkCmdSetEvent(data->commandBuffer, data->event, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT);
Mike Stroyanaccf7692015-05-12 16:00:45 -06004389 if (data->bailout) {
4390 break;
4391 }
4392 }
4393 return NULL;
4394}
4395
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004396TEST_F(VkLayerTest, ThreadCommandBufferCollision)
Mike Stroyanaccf7692015-05-12 16:00:45 -06004397{
Mike Stroyan4268d1f2015-07-13 14:45:35 -06004398 test_platform_thread thread;
Mike Stroyanaccf7692015-05-12 16:00:45 -06004399
Courtney Goeltzenleuchterfd4830c2015-11-25 10:30:56 -07004400 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT, "THREADING ERROR");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06004401
Mike Stroyanaccf7692015-05-12 16:00:45 -06004402 ASSERT_NO_FATAL_FAILURE(InitState());
4403 ASSERT_NO_FATAL_FAILURE(InitViewport());
4404 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
4405
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004406 // Calls AllocateCommandBuffers
4407 VkCommandBufferObj commandBuffer(m_device, m_commandPool);
Mark Lobodzinski5495d132015-09-30 16:19:16 -06004408
4409 // Avoid creating RenderPass
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004410 commandBuffer.BeginCommandBuffer();
Mike Stroyanaccf7692015-05-12 16:00:45 -06004411
4412 VkEventCreateInfo event_info;
4413 VkEvent event;
Mike Stroyanaccf7692015-05-12 16:00:45 -06004414 VkResult err;
4415
4416 memset(&event_info, 0, sizeof(event_info));
4417 event_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
4418
Chia-I Wuf7458c52015-10-26 21:10:41 +08004419 err = vkCreateEvent(device(), &event_info, NULL, &event);
Mike Stroyanaccf7692015-05-12 16:00:45 -06004420 ASSERT_VK_SUCCESS(err);
4421
Mike Stroyanaccf7692015-05-12 16:00:45 -06004422 err = vkResetEvent(device(), event);
4423 ASSERT_VK_SUCCESS(err);
4424
4425 struct thread_data_struct data;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004426 data.commandBuffer = commandBuffer.GetBufferHandle();
Mike Stroyanaccf7692015-05-12 16:00:45 -06004427 data.event = event;
4428 data.bailout = false;
4429 m_errorMonitor->SetBailout(&data.bailout);
4430 // Add many entries to command buffer from another thread.
Mike Stroyan4268d1f2015-07-13 14:45:35 -06004431 test_platform_thread_create(&thread, AddToCommandBuffer, (void *)&data);
Mike Stroyanaccf7692015-05-12 16:00:45 -06004432 // Add many entries to command buffer from this thread at the same time.
4433 AddToCommandBuffer(&data);
Mark Lobodzinski5495d132015-09-30 16:19:16 -06004434
Mike Stroyan4268d1f2015-07-13 14:45:35 -06004435 test_platform_thread_join(thread, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004436 commandBuffer.EndCommandBuffer();
Mike Stroyanaccf7692015-05-12 16:00:45 -06004437
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06004438 if (!m_errorMonitor->DesiredMsgFound()) {
4439 FAIL() << "Did not receive Error 'THREADING ERROR' from using one VkCommandBufferObj in two threads";
4440 m_errorMonitor->DumpFailureMsgs();
Mike Stroyanaccf7692015-05-12 16:00:45 -06004441 }
4442
Chia-I Wuf7458c52015-10-26 21:10:41 +08004443 vkDestroyEvent(device(), event, NULL);
Mike Stroyanaccf7692015-05-12 16:00:45 -06004444}
Mark Lobodzinski209b5292015-09-17 09:44:05 -06004445#endif // GTEST_IS_THREADSAFE
4446#endif // THREADING_TESTS
4447
Chris Forbes9f7ff632015-05-25 11:13:08 +12004448#if SHADER_CHECKER_TESTS
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -06004449TEST_F(VkLayerTest, InvalidSPIRVCodeSize)
4450{
Courtney Goeltzenleuchterfd4830c2015-11-25 10:30:56 -07004451 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06004452 "Shader is not SPIR-V");
4453
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -06004454 ASSERT_NO_FATAL_FAILURE(InitState());
4455 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
4456
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -06004457 VkShaderModule module;
4458 VkShaderModuleCreateInfo moduleCreateInfo;
4459 struct icd_spv_header spv;
4460
4461 spv.magic = ICD_SPV_MAGIC;
4462 spv.version = ICD_SPV_VERSION;
4463 spv.gen_magic = 0;
4464
4465 moduleCreateInfo.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;
4466 moduleCreateInfo.pNext = NULL;
Chia-I Wu8094f192015-10-26 19:22:06 +08004467 moduleCreateInfo.pCode = (const uint32_t *) &spv;
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -06004468 moduleCreateInfo.codeSize = 4;
4469 moduleCreateInfo.flags = 0;
Chia-I Wuf7458c52015-10-26 21:10:41 +08004470 vkCreateShaderModule(m_device->device(), &moduleCreateInfo, NULL, &module);
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -06004471
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06004472 if (!m_errorMonitor->DesiredMsgFound()) {
4473 FAIL() << "Did not recieive Error 'Shader is not SPIR-V'";
4474 m_errorMonitor->DumpFailureMsgs();
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -06004475 }
4476}
4477
4478TEST_F(VkLayerTest, InvalidSPIRVMagic)
4479{
Courtney Goeltzenleuchterfd4830c2015-11-25 10:30:56 -07004480 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06004481 "Shader is not SPIR-V");
4482
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -06004483 ASSERT_NO_FATAL_FAILURE(InitState());
4484 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
4485
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -06004486 VkShaderModule module;
4487 VkShaderModuleCreateInfo moduleCreateInfo;
4488 struct icd_spv_header spv;
4489
4490 spv.magic = ~ICD_SPV_MAGIC;
4491 spv.version = ICD_SPV_VERSION;
4492 spv.gen_magic = 0;
4493
4494 moduleCreateInfo.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;
4495 moduleCreateInfo.pNext = NULL;
Chia-I Wu8094f192015-10-26 19:22:06 +08004496 moduleCreateInfo.pCode = (const uint32_t *) &spv;
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -06004497 moduleCreateInfo.codeSize = sizeof(spv) + 10;
4498 moduleCreateInfo.flags = 0;
Chia-I Wuf7458c52015-10-26 21:10:41 +08004499 vkCreateShaderModule(m_device->device(), &moduleCreateInfo, NULL, &module);
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -06004500
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06004501 if (!m_errorMonitor->DesiredMsgFound()) {
4502 FAIL() << "Did not recieive Error 'Shader is not SPIR-V'";
4503 m_errorMonitor->DumpFailureMsgs();
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -06004504 }
4505}
4506
4507TEST_F(VkLayerTest, InvalidSPIRVVersion)
4508{
Courtney Goeltzenleuchterfd4830c2015-11-25 10:30:56 -07004509 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06004510 "Shader is not SPIR-V");
4511
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -06004512 ASSERT_NO_FATAL_FAILURE(InitState());
4513 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
4514
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -06004515 VkShaderModule module;
4516 VkShaderModuleCreateInfo moduleCreateInfo;
4517 struct icd_spv_header spv;
4518
4519 spv.magic = ICD_SPV_MAGIC;
4520 spv.version = ~ICD_SPV_VERSION;
4521 spv.gen_magic = 0;
4522
4523 moduleCreateInfo.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;
4524 moduleCreateInfo.pNext = NULL;
4525
Chia-I Wu8094f192015-10-26 19:22:06 +08004526 moduleCreateInfo.pCode = (const uint32_t *) &spv;
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -06004527 moduleCreateInfo.codeSize = sizeof(spv) + 10;
4528 moduleCreateInfo.flags = 0;
Chia-I Wuf7458c52015-10-26 21:10:41 +08004529 vkCreateShaderModule(m_device->device(), &moduleCreateInfo, NULL, &module);
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -06004530
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06004531 if (!m_errorMonitor->DesiredMsgFound()) {
4532 FAIL() << "Did not recieive Error 'Shader is not SPIR-V'";
4533 m_errorMonitor->DumpFailureMsgs();
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -06004534 }
4535}
4536
Chris Forbes9f7ff632015-05-25 11:13:08 +12004537TEST_F(VkLayerTest, CreatePipelineVertexOutputNotConsumed)
4538{
Courtney Goeltzenleuchterfd4830c2015-11-25 10:30:56 -07004539 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERF_WARN_BIT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06004540 "not consumed by fragment shader");
4541
Chris Forbes9f7ff632015-05-25 11:13:08 +12004542 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06004543 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes9f7ff632015-05-25 11:13:08 +12004544
4545 char const *vsSource =
4546 "#version 140\n"
4547 "#extension GL_ARB_separate_shader_objects: require\n"
4548 "#extension GL_ARB_shading_language_420pack: require\n"
4549 "\n"
4550 "layout(location=0) out float x;\n"
4551 "void main(){\n"
4552 " gl_Position = vec4(1);\n"
4553 " x = 0;\n"
4554 "}\n";
4555 char const *fsSource =
4556 "#version 140\n"
4557 "#extension GL_ARB_separate_shader_objects: require\n"
4558 "#extension GL_ARB_shading_language_420pack: require\n"
4559 "\n"
4560 "layout(location=0) out vec4 color;\n"
4561 "void main(){\n"
4562 " color = vec4(1);\n"
4563 "}\n";
4564
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06004565 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
4566 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes9f7ff632015-05-25 11:13:08 +12004567
4568 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +08004569 pipe.AddColorAttachment();
Chris Forbes9f7ff632015-05-25 11:13:08 +12004570 pipe.AddShader(&vs);
4571 pipe.AddShader(&fs);
4572
Chris Forbes9f7ff632015-05-25 11:13:08 +12004573 VkDescriptorSetObj descriptorSet(m_device);
4574 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004575 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes9f7ff632015-05-25 11:13:08 +12004576
Tony Barbour5781e8f2015-08-04 16:23:11 -06004577 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes9f7ff632015-05-25 11:13:08 +12004578
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06004579 if (!m_errorMonitor->DesiredMsgFound()) {
4580 FAIL() << "Did not receive Warning 'not consumed by fragment shader'";
4581 m_errorMonitor->DumpFailureMsgs();
Chris Forbes9f7ff632015-05-25 11:13:08 +12004582 }
4583}
Chris Forbes9f7ff632015-05-25 11:13:08 +12004584
Chris Forbes59cb88d2015-05-25 11:13:13 +12004585TEST_F(VkLayerTest, CreatePipelineFragmentInputNotProvided)
4586{
Courtney Goeltzenleuchterfd4830c2015-11-25 10:30:56 -07004587 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06004588 "not written by vertex shader");
4589
Chris Forbes59cb88d2015-05-25 11:13:13 +12004590 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06004591 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes59cb88d2015-05-25 11:13:13 +12004592
4593 char const *vsSource =
4594 "#version 140\n"
4595 "#extension GL_ARB_separate_shader_objects: require\n"
4596 "#extension GL_ARB_shading_language_420pack: require\n"
4597 "\n"
4598 "void main(){\n"
4599 " gl_Position = vec4(1);\n"
4600 "}\n";
4601 char const *fsSource =
4602 "#version 140\n"
4603 "#extension GL_ARB_separate_shader_objects: require\n"
4604 "#extension GL_ARB_shading_language_420pack: require\n"
4605 "\n"
4606 "layout(location=0) in float x;\n"
4607 "layout(location=0) out vec4 color;\n"
4608 "void main(){\n"
4609 " color = vec4(x);\n"
4610 "}\n";
4611
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06004612 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
4613 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes59cb88d2015-05-25 11:13:13 +12004614
4615 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +08004616 pipe.AddColorAttachment();
Chris Forbes59cb88d2015-05-25 11:13:13 +12004617 pipe.AddShader(&vs);
4618 pipe.AddShader(&fs);
4619
Chris Forbes59cb88d2015-05-25 11:13:13 +12004620 VkDescriptorSetObj descriptorSet(m_device);
4621 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004622 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes59cb88d2015-05-25 11:13:13 +12004623
Tony Barbour5781e8f2015-08-04 16:23:11 -06004624 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes59cb88d2015-05-25 11:13:13 +12004625
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06004626 if (!m_errorMonitor->DesiredMsgFound()) {
4627 FAIL() << "Did not receive Error 'not written by vertex shader'";
4628 m_errorMonitor->DumpFailureMsgs();
Chris Forbes59cb88d2015-05-25 11:13:13 +12004629 }
4630}
4631
Chris Forbesb56af562015-05-25 11:13:17 +12004632TEST_F(VkLayerTest, CreatePipelineVsFsTypeMismatch)
4633{
Courtney Goeltzenleuchterfd4830c2015-11-25 10:30:56 -07004634 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06004635 "Type mismatch on location 0");
4636
Chris Forbesb56af562015-05-25 11:13:17 +12004637 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06004638 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesb56af562015-05-25 11:13:17 +12004639
4640 char const *vsSource =
4641 "#version 140\n"
4642 "#extension GL_ARB_separate_shader_objects: require\n"
4643 "#extension GL_ARB_shading_language_420pack: require\n"
4644 "\n"
4645 "layout(location=0) out int x;\n"
4646 "void main(){\n"
4647 " x = 0;\n"
4648 " gl_Position = vec4(1);\n"
4649 "}\n";
4650 char const *fsSource =
4651 "#version 140\n"
4652 "#extension GL_ARB_separate_shader_objects: require\n"
4653 "#extension GL_ARB_shading_language_420pack: require\n"
4654 "\n"
4655 "layout(location=0) in float x;\n" /* VS writes int */
4656 "layout(location=0) out vec4 color;\n"
4657 "void main(){\n"
4658 " color = vec4(x);\n"
4659 "}\n";
4660
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06004661 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
4662 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesb56af562015-05-25 11:13:17 +12004663
4664 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +08004665 pipe.AddColorAttachment();
Chris Forbesb56af562015-05-25 11:13:17 +12004666 pipe.AddShader(&vs);
4667 pipe.AddShader(&fs);
4668
Chris Forbesb56af562015-05-25 11:13:17 +12004669 VkDescriptorSetObj descriptorSet(m_device);
4670 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004671 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesb56af562015-05-25 11:13:17 +12004672
Tony Barbour5781e8f2015-08-04 16:23:11 -06004673 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesb56af562015-05-25 11:13:17 +12004674
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06004675 if (!m_errorMonitor->DesiredMsgFound()) {
4676 FAIL() << "Did not receive Error 'Type mismatch on location 0'";
4677 m_errorMonitor->DumpFailureMsgs();
Chris Forbesb56af562015-05-25 11:13:17 +12004678 }
4679}
4680
Chris Forbesde136e02015-05-25 11:13:28 +12004681TEST_F(VkLayerTest, CreatePipelineAttribNotConsumed)
4682{
Courtney Goeltzenleuchterfd4830c2015-11-25 10:30:56 -07004683 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERF_WARN_BIT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06004684 "location 0 not consumed by VS");
4685
Chris Forbesde136e02015-05-25 11:13:28 +12004686 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06004687 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesde136e02015-05-25 11:13:28 +12004688
4689 VkVertexInputBindingDescription input_binding;
4690 memset(&input_binding, 0, sizeof(input_binding));
4691
4692 VkVertexInputAttributeDescription input_attrib;
4693 memset(&input_attrib, 0, sizeof(input_attrib));
4694 input_attrib.format = VK_FORMAT_R32_SFLOAT;
4695
4696 char const *vsSource =
4697 "#version 140\n"
4698 "#extension GL_ARB_separate_shader_objects: require\n"
4699 "#extension GL_ARB_shading_language_420pack: require\n"
4700 "\n"
4701 "void main(){\n"
4702 " gl_Position = vec4(1);\n"
4703 "}\n";
4704 char const *fsSource =
4705 "#version 140\n"
4706 "#extension GL_ARB_separate_shader_objects: require\n"
4707 "#extension GL_ARB_shading_language_420pack: require\n"
4708 "\n"
4709 "layout(location=0) out vec4 color;\n"
4710 "void main(){\n"
4711 " color = vec4(1);\n"
4712 "}\n";
4713
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06004714 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
4715 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesde136e02015-05-25 11:13:28 +12004716
4717 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +08004718 pipe.AddColorAttachment();
Chris Forbesde136e02015-05-25 11:13:28 +12004719 pipe.AddShader(&vs);
4720 pipe.AddShader(&fs);
4721
4722 pipe.AddVertexInputBindings(&input_binding, 1);
4723 pipe.AddVertexInputAttribs(&input_attrib, 1);
4724
Chris Forbesde136e02015-05-25 11:13:28 +12004725 VkDescriptorSetObj descriptorSet(m_device);
4726 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004727 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesde136e02015-05-25 11:13:28 +12004728
Tony Barbour5781e8f2015-08-04 16:23:11 -06004729 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesde136e02015-05-25 11:13:28 +12004730
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06004731 if (!m_errorMonitor->DesiredMsgFound()) {
4732 FAIL() << "Did not receive Warning 'location 0 not consumed by VS'";
4733 m_errorMonitor->DumpFailureMsgs();
Chris Forbesde136e02015-05-25 11:13:28 +12004734 }
4735}
4736
Chris Forbes62e8e502015-05-25 11:13:29 +12004737TEST_F(VkLayerTest, CreatePipelineAttribNotProvided)
4738{
Courtney Goeltzenleuchterfd4830c2015-11-25 10:30:56 -07004739 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06004740 "VS consumes input at location 0 but not provided");
4741
Chris Forbes62e8e502015-05-25 11:13:29 +12004742 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06004743 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes62e8e502015-05-25 11:13:29 +12004744
4745 char const *vsSource =
4746 "#version 140\n"
4747 "#extension GL_ARB_separate_shader_objects: require\n"
4748 "#extension GL_ARB_shading_language_420pack: require\n"
4749 "\n"
4750 "layout(location=0) in vec4 x;\n" /* not provided */
4751 "void main(){\n"
4752 " gl_Position = x;\n"
4753 "}\n";
4754 char const *fsSource =
4755 "#version 140\n"
4756 "#extension GL_ARB_separate_shader_objects: require\n"
4757 "#extension GL_ARB_shading_language_420pack: require\n"
4758 "\n"
4759 "layout(location=0) out vec4 color;\n"
4760 "void main(){\n"
4761 " color = vec4(1);\n"
4762 "}\n";
4763
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06004764 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
4765 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes62e8e502015-05-25 11:13:29 +12004766
4767 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +08004768 pipe.AddColorAttachment();
Chris Forbes62e8e502015-05-25 11:13:29 +12004769 pipe.AddShader(&vs);
4770 pipe.AddShader(&fs);
4771
Chris Forbes62e8e502015-05-25 11:13:29 +12004772 VkDescriptorSetObj descriptorSet(m_device);
4773 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004774 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes62e8e502015-05-25 11:13:29 +12004775
Tony Barbour5781e8f2015-08-04 16:23:11 -06004776 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes62e8e502015-05-25 11:13:29 +12004777
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06004778 if (!m_errorMonitor->DesiredMsgFound()) {
4779 FAIL() << "Did not receive Error 'VS consumes input at location 0 but not provided'";
4780 m_errorMonitor->DumpFailureMsgs();
Chris Forbes62e8e502015-05-25 11:13:29 +12004781 }
4782}
4783
Chris Forbesc97d98e2015-05-25 11:13:31 +12004784TEST_F(VkLayerTest, CreatePipelineAttribTypeMismatch)
4785{
Courtney Goeltzenleuchterfd4830c2015-11-25 10:30:56 -07004786 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06004787 "location 0 does not match VS input type");
4788
Chris Forbesc97d98e2015-05-25 11:13:31 +12004789 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06004790 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesc97d98e2015-05-25 11:13:31 +12004791
4792 VkVertexInputBindingDescription input_binding;
4793 memset(&input_binding, 0, sizeof(input_binding));
4794
4795 VkVertexInputAttributeDescription input_attrib;
4796 memset(&input_attrib, 0, sizeof(input_attrib));
4797 input_attrib.format = VK_FORMAT_R32_SFLOAT;
4798
4799 char const *vsSource =
4800 "#version 140\n"
4801 "#extension GL_ARB_separate_shader_objects: require\n"
4802 "#extension GL_ARB_shading_language_420pack: require\n"
4803 "\n"
4804 "layout(location=0) in int x;\n" /* attrib provided float */
4805 "void main(){\n"
4806 " gl_Position = vec4(x);\n"
4807 "}\n";
4808 char const *fsSource =
4809 "#version 140\n"
4810 "#extension GL_ARB_separate_shader_objects: require\n"
4811 "#extension GL_ARB_shading_language_420pack: require\n"
4812 "\n"
4813 "layout(location=0) out vec4 color;\n"
4814 "void main(){\n"
4815 " color = vec4(1);\n"
4816 "}\n";
4817
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06004818 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
4819 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesc97d98e2015-05-25 11:13:31 +12004820
4821 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +08004822 pipe.AddColorAttachment();
Chris Forbesc97d98e2015-05-25 11:13:31 +12004823 pipe.AddShader(&vs);
4824 pipe.AddShader(&fs);
4825
4826 pipe.AddVertexInputBindings(&input_binding, 1);
4827 pipe.AddVertexInputAttribs(&input_attrib, 1);
4828
Chris Forbesc97d98e2015-05-25 11:13:31 +12004829 VkDescriptorSetObj descriptorSet(m_device);
4830 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004831 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesc97d98e2015-05-25 11:13:31 +12004832
Tony Barbour5781e8f2015-08-04 16:23:11 -06004833 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesc97d98e2015-05-25 11:13:31 +12004834
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06004835 if (!m_errorMonitor->DesiredMsgFound()) {
4836 FAIL() << "Did not receive Error 'location 0 does not match VS input type'";
4837 m_errorMonitor->DumpFailureMsgs();
Chris Forbesc97d98e2015-05-25 11:13:31 +12004838 }
4839}
4840
Chris Forbes2682b242015-11-24 11:13:14 +13004841TEST_F(VkLayerTest, CreatePipelineAttribMatrixType)
4842{
4843 m_errorMonitor->SetDesiredFailureMsg(~0u, "");
4844
4845 ASSERT_NO_FATAL_FAILURE(InitState());
4846 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
4847
4848 VkVertexInputBindingDescription input_binding;
4849 memset(&input_binding, 0, sizeof(input_binding));
4850
4851 VkVertexInputAttributeDescription input_attribs[2];
4852 memset(input_attribs, 0, sizeof(input_attribs));
4853
4854 for (int i = 0; i < 2; i++) {
4855 input_attribs[i].format = VK_FORMAT_R32G32B32A32_SFLOAT;
4856 input_attribs[i].location = i;
4857 }
4858
4859 char const *vsSource =
4860 "#version 140\n"
4861 "#extension GL_ARB_separate_shader_objects: require\n"
4862 "#extension GL_ARB_shading_language_420pack: require\n"
4863 "\n"
4864 "layout(location=0) in mat2x4 x;\n"
4865 "void main(){\n"
4866 " gl_Position = x[0] + x[1];\n"
4867 "}\n";
4868 char const *fsSource =
4869 "#version 140\n"
4870 "#extension GL_ARB_separate_shader_objects: require\n"
4871 "#extension GL_ARB_shading_language_420pack: require\n"
4872 "\n"
4873 "layout(location=0) out vec4 color;\n"
4874 "void main(){\n"
4875 " color = vec4(1);\n"
4876 "}\n";
4877
4878 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
4879 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
4880
4881 VkPipelineObj pipe(m_device);
4882 pipe.AddColorAttachment();
4883 pipe.AddShader(&vs);
4884 pipe.AddShader(&fs);
4885
4886 pipe.AddVertexInputBindings(&input_binding, 1);
4887 pipe.AddVertexInputAttribs(input_attribs, 2);
4888
4889 VkDescriptorSetObj descriptorSet(m_device);
4890 descriptorSet.AppendDummy();
4891 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
4892
4893 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
4894
4895 /* expect success */
4896 if (m_errorMonitor->DesiredMsgFound()) {
4897 FAIL() << "Expected to succeed but: " << m_errorMonitor->GetFailureMsg();
4898 m_errorMonitor->DumpFailureMsgs();
4899 }
4900}
4901
4902/*
4903 * Would work, but not supported by glslang! This is similar to the matrix case above.
4904 *
4905TEST_F(VkLayerTest, CreatePipelineAttribArrayType)
4906{
4907 m_errorMonitor->SetDesiredFailureMsg(~0u, "");
4908
4909 ASSERT_NO_FATAL_FAILURE(InitState());
4910 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
4911
4912 VkVertexInputBindingDescription input_binding;
4913 memset(&input_binding, 0, sizeof(input_binding));
4914
4915 VkVertexInputAttributeDescription input_attribs[2];
4916 memset(input_attribs, 0, sizeof(input_attribs));
4917
4918 for (int i = 0; i < 2; i++) {
4919 input_attribs[i].format = VK_FORMAT_R32G32B32A32_SFLOAT;
4920 input_attribs[i].location = i;
4921 }
4922
4923 char const *vsSource =
4924 "#version 140\n"
4925 "#extension GL_ARB_separate_shader_objects: require\n"
4926 "#extension GL_ARB_shading_language_420pack: require\n"
4927 "\n"
4928 "layout(location=0) in vec4 x[2];\n"
4929 "void main(){\n"
4930 " gl_Position = x[0] + x[1];\n"
4931 "}\n";
4932 char const *fsSource =
4933 "#version 140\n"
4934 "#extension GL_ARB_separate_shader_objects: require\n"
4935 "#extension GL_ARB_shading_language_420pack: require\n"
4936 "\n"
4937 "layout(location=0) out vec4 color;\n"
4938 "void main(){\n"
4939 " color = vec4(1);\n"
4940 "}\n";
4941
4942 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
4943 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
4944
4945 VkPipelineObj pipe(m_device);
4946 pipe.AddColorAttachment();
4947 pipe.AddShader(&vs);
4948 pipe.AddShader(&fs);
4949
4950 pipe.AddVertexInputBindings(&input_binding, 1);
4951 pipe.AddVertexInputAttribs(input_attribs, 2);
4952
4953 VkDescriptorSetObj descriptorSet(m_device);
4954 descriptorSet.AppendDummy();
4955 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
4956
4957 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
4958
4959 if (m_errorMonitor->DesiredMsgFound()) {
4960 FAIL() << "Expected to succeed but: " << m_errorMonitor->GetFailureMsg();
4961 m_errorMonitor->DumpFailureMsgs();
4962 }
4963}
4964*/
4965
Chris Forbes280ba2c2015-06-12 11:16:41 +12004966TEST_F(VkLayerTest, CreatePipelineAttribBindingConflict)
4967{
Courtney Goeltzenleuchterfd4830c2015-11-25 10:30:56 -07004968 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06004969 "Duplicate vertex input binding descriptions for binding 0");
4970
Chris Forbes280ba2c2015-06-12 11:16:41 +12004971 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06004972 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes280ba2c2015-06-12 11:16:41 +12004973
4974 /* Two binding descriptions for binding 0 */
4975 VkVertexInputBindingDescription input_bindings[2];
4976 memset(input_bindings, 0, sizeof(input_bindings));
4977
4978 VkVertexInputAttributeDescription input_attrib;
4979 memset(&input_attrib, 0, sizeof(input_attrib));
4980 input_attrib.format = VK_FORMAT_R32_SFLOAT;
4981
4982 char const *vsSource =
4983 "#version 140\n"
4984 "#extension GL_ARB_separate_shader_objects: require\n"
4985 "#extension GL_ARB_shading_language_420pack: require\n"
4986 "\n"
4987 "layout(location=0) in float x;\n" /* attrib provided float */
4988 "void main(){\n"
4989 " gl_Position = vec4(x);\n"
4990 "}\n";
4991 char const *fsSource =
4992 "#version 140\n"
4993 "#extension GL_ARB_separate_shader_objects: require\n"
4994 "#extension GL_ARB_shading_language_420pack: require\n"
4995 "\n"
4996 "layout(location=0) out vec4 color;\n"
4997 "void main(){\n"
4998 " color = vec4(1);\n"
4999 "}\n";
5000
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06005001 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
5002 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes280ba2c2015-06-12 11:16:41 +12005003
5004 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +08005005 pipe.AddColorAttachment();
Chris Forbes280ba2c2015-06-12 11:16:41 +12005006 pipe.AddShader(&vs);
5007 pipe.AddShader(&fs);
5008
5009 pipe.AddVertexInputBindings(input_bindings, 2);
5010 pipe.AddVertexInputAttribs(&input_attrib, 1);
5011
Chris Forbes280ba2c2015-06-12 11:16:41 +12005012 VkDescriptorSetObj descriptorSet(m_device);
5013 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005014 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes280ba2c2015-06-12 11:16:41 +12005015
Tony Barbour5781e8f2015-08-04 16:23:11 -06005016 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes280ba2c2015-06-12 11:16:41 +12005017
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06005018 if (!m_errorMonitor->DesiredMsgFound()) {
5019 FAIL() << "Did not receive Error 'Duplicate vertex input binding descriptions for binding 0'";
5020 m_errorMonitor->DumpFailureMsgs();
Chris Forbes280ba2c2015-06-12 11:16:41 +12005021 }
5022}
Chris Forbes8f68b562015-05-25 11:13:32 +12005023
Chris Forbes4d6d1e52015-05-25 11:13:40 +12005024TEST_F(VkLayerTest, CreatePipelineFragmentOutputNotWritten)
5025{
Courtney Goeltzenleuchterfd4830c2015-11-25 10:30:56 -07005026 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06005027 "Attachment 0 not written by FS");
5028
Chris Forbes4d6d1e52015-05-25 11:13:40 +12005029 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbes4d6d1e52015-05-25 11:13:40 +12005030
5031 char const *vsSource =
5032 "#version 140\n"
5033 "#extension GL_ARB_separate_shader_objects: require\n"
5034 "#extension GL_ARB_shading_language_420pack: require\n"
5035 "\n"
5036 "void main(){\n"
5037 " gl_Position = vec4(1);\n"
5038 "}\n";
5039 char const *fsSource =
5040 "#version 140\n"
5041 "#extension GL_ARB_separate_shader_objects: require\n"
5042 "#extension GL_ARB_shading_language_420pack: require\n"
5043 "\n"
5044 "void main(){\n"
5045 "}\n";
5046
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06005047 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
5048 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes4d6d1e52015-05-25 11:13:40 +12005049
5050 VkPipelineObj pipe(m_device);
5051 pipe.AddShader(&vs);
5052 pipe.AddShader(&fs);
5053
Chia-I Wu08accc62015-07-07 11:50:03 +08005054 /* set up CB 0, not written */
5055 pipe.AddColorAttachment();
5056 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes4d6d1e52015-05-25 11:13:40 +12005057
Chris Forbes4d6d1e52015-05-25 11:13:40 +12005058 VkDescriptorSetObj descriptorSet(m_device);
5059 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005060 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes4d6d1e52015-05-25 11:13:40 +12005061
Tony Barbour5781e8f2015-08-04 16:23:11 -06005062 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes4d6d1e52015-05-25 11:13:40 +12005063
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06005064 if (!m_errorMonitor->DesiredMsgFound()) {
5065 FAIL() << "Did not receive Error 'Attachment 0 not written by FS'";
5066 m_errorMonitor->DumpFailureMsgs();
Chris Forbes4d6d1e52015-05-25 11:13:40 +12005067 }
5068}
5069
Chris Forbesf3fffaa2015-05-25 11:13:43 +12005070TEST_F(VkLayerTest, CreatePipelineFragmentOutputNotConsumed)
5071{
Courtney Goeltzenleuchterfd4830c2015-11-25 10:30:56 -07005072 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARN_BIT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06005073 "FS writes to output location 1 with no matching attachment");
5074
Chris Forbesf3fffaa2015-05-25 11:13:43 +12005075 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbesf3fffaa2015-05-25 11:13:43 +12005076
5077 char const *vsSource =
5078 "#version 140\n"
5079 "#extension GL_ARB_separate_shader_objects: require\n"
5080 "#extension GL_ARB_shading_language_420pack: require\n"
5081 "\n"
5082 "void main(){\n"
5083 " gl_Position = vec4(1);\n"
5084 "}\n";
5085 char const *fsSource =
5086 "#version 140\n"
5087 "#extension GL_ARB_separate_shader_objects: require\n"
5088 "#extension GL_ARB_shading_language_420pack: require\n"
5089 "\n"
5090 "layout(location=0) out vec4 x;\n"
5091 "layout(location=1) out vec4 y;\n" /* no matching attachment for this */
5092 "void main(){\n"
5093 " x = vec4(1);\n"
5094 " y = vec4(1);\n"
5095 "}\n";
5096
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06005097 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
5098 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesf3fffaa2015-05-25 11:13:43 +12005099
5100 VkPipelineObj pipe(m_device);
5101 pipe.AddShader(&vs);
5102 pipe.AddShader(&fs);
5103
Chia-I Wu08accc62015-07-07 11:50:03 +08005104 /* set up CB 0, not written */
5105 pipe.AddColorAttachment();
5106 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesf3fffaa2015-05-25 11:13:43 +12005107 /* FS writes CB 1, but we don't configure it */
5108
Chris Forbesf3fffaa2015-05-25 11:13:43 +12005109 VkDescriptorSetObj descriptorSet(m_device);
5110 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005111 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesf3fffaa2015-05-25 11:13:43 +12005112
Tony Barbour5781e8f2015-08-04 16:23:11 -06005113 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesf3fffaa2015-05-25 11:13:43 +12005114
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06005115 if (!m_errorMonitor->DesiredMsgFound()) {
5116 FAIL() << "Did not receive Error 'FS writes to output location 1 with no matching attachment'";
5117 m_errorMonitor->DumpFailureMsgs();
Chris Forbesf3fffaa2015-05-25 11:13:43 +12005118 }
5119}
5120
Chris Forbesa36d69e2015-05-25 11:13:44 +12005121TEST_F(VkLayerTest, CreatePipelineFragmentOutputTypeMismatch)
5122{
Courtney Goeltzenleuchterfd4830c2015-11-25 10:30:56 -07005123 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06005124 "does not match FS output type");
5125
Chris Forbesa36d69e2015-05-25 11:13:44 +12005126 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbesa36d69e2015-05-25 11:13:44 +12005127
5128 char const *vsSource =
5129 "#version 140\n"
5130 "#extension GL_ARB_separate_shader_objects: require\n"
5131 "#extension GL_ARB_shading_language_420pack: require\n"
5132 "\n"
5133 "void main(){\n"
5134 " gl_Position = vec4(1);\n"
5135 "}\n";
5136 char const *fsSource =
5137 "#version 140\n"
5138 "#extension GL_ARB_separate_shader_objects: require\n"
5139 "#extension GL_ARB_shading_language_420pack: require\n"
5140 "\n"
5141 "layout(location=0) out ivec4 x;\n" /* not UNORM */
5142 "void main(){\n"
5143 " x = ivec4(1);\n"
5144 "}\n";
5145
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06005146 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
5147 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesa36d69e2015-05-25 11:13:44 +12005148
5149 VkPipelineObj pipe(m_device);
5150 pipe.AddShader(&vs);
5151 pipe.AddShader(&fs);
5152
Chia-I Wu08accc62015-07-07 11:50:03 +08005153 /* set up CB 0; type is UNORM by default */
5154 pipe.AddColorAttachment();
5155 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesa36d69e2015-05-25 11:13:44 +12005156
Chris Forbesa36d69e2015-05-25 11:13:44 +12005157 VkDescriptorSetObj descriptorSet(m_device);
5158 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005159 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesa36d69e2015-05-25 11:13:44 +12005160
Tony Barbour5781e8f2015-08-04 16:23:11 -06005161 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesa36d69e2015-05-25 11:13:44 +12005162
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06005163 if (!m_errorMonitor->DesiredMsgFound()) {
5164 FAIL() << "Did not receive Error 'does not match FS output type'";
5165 m_errorMonitor->DumpFailureMsgs();
Chris Forbesa36d69e2015-05-25 11:13:44 +12005166 }
5167}
Chris Forbes7b1b8932015-06-05 14:43:36 +12005168
Chris Forbes556c76c2015-08-14 12:04:59 +12005169TEST_F(VkLayerTest, CreatePipelineUniformBlockNotProvided)
5170{
Courtney Goeltzenleuchterfd4830c2015-11-25 10:30:56 -07005171 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06005172 "not declared in pipeline layout");
5173
Chris Forbes556c76c2015-08-14 12:04:59 +12005174 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbes556c76c2015-08-14 12:04:59 +12005175
5176 char const *vsSource =
5177 "#version 140\n"
5178 "#extension GL_ARB_separate_shader_objects: require\n"
5179 "#extension GL_ARB_shading_language_420pack: require\n"
5180 "\n"
5181 "void main(){\n"
5182 " gl_Position = vec4(1);\n"
5183 "}\n";
5184 char const *fsSource =
5185 "#version 140\n"
5186 "#extension GL_ARB_separate_shader_objects: require\n"
5187 "#extension GL_ARB_shading_language_420pack: require\n"
5188 "\n"
5189 "layout(location=0) out vec4 x;\n"
5190 "layout(set=0) layout(binding=0) uniform foo { int x; int y; } bar;\n"
5191 "void main(){\n"
5192 " x = vec4(bar.y);\n"
5193 "}\n";
5194
Chris Forbes556c76c2015-08-14 12:04:59 +12005195
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06005196 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
5197 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes556c76c2015-08-14 12:04:59 +12005198
Chris Forbes556c76c2015-08-14 12:04:59 +12005199 VkPipelineObj pipe(m_device);
5200 pipe.AddShader(&vs);
5201 pipe.AddShader(&fs);
5202
5203 /* set up CB 0; type is UNORM by default */
5204 pipe.AddColorAttachment();
5205 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
5206
5207 VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005208 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes556c76c2015-08-14 12:04:59 +12005209
5210 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
5211
5212 /* should have generated an error -- pipeline layout does not
5213 * provide a uniform buffer in 0.0
5214 */
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06005215 if (!m_errorMonitor->DesiredMsgFound()) {
5216 FAIL() << "Did not receive Error 'not declared in pipeline layout'";
5217 m_errorMonitor->DumpFailureMsgs();
Chris Forbes556c76c2015-08-14 12:04:59 +12005218 }
5219}
5220
Mark Lobodzinski209b5292015-09-17 09:44:05 -06005221#endif // SHADER_CHECKER_TESTS
5222
5223#if DEVICE_LIMITS_TESTS
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -06005224TEST_F(VkLayerTest, CreateImageLimitsViolationWidth)
5225{
Courtney Goeltzenleuchterfd4830c2015-11-25 10:30:56 -07005226 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06005227 "CreateImage extents exceed allowable limits for format");
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -06005228
5229 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -06005230
5231 // Create an image
5232 VkImage image;
5233
5234 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
5235 const int32_t tex_width = 32;
5236 const int32_t tex_height = 32;
5237
5238 VkImageCreateInfo image_create_info = {};
5239 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
5240 image_create_info.pNext = NULL;
5241 image_create_info.imageType = VK_IMAGE_TYPE_2D;
5242 image_create_info.format = tex_format;
5243 image_create_info.extent.width = tex_width;
5244 image_create_info.extent.height = tex_height;
5245 image_create_info.extent.depth = 1;
5246 image_create_info.mipLevels = 1;
Courtney Goeltzenleuchter5d2aed42015-10-21 17:57:31 -06005247 image_create_info.arrayLayers = 1;
Chia-I Wu5c17c962015-10-31 00:31:16 +08005248 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -06005249 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
5250 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
5251 image_create_info.flags = 0;
5252
5253 // Introduce error by sending down a bogus width extent
5254 image_create_info.extent.width = 65536;
Chia-I Wuf7458c52015-10-26 21:10:41 +08005255 vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -06005256
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06005257 if (!m_errorMonitor->DesiredMsgFound()) {
5258 FAIL() << "Did not receive Error 'CreateImage extents exceed allowable limits for format'";
5259 m_errorMonitor->DumpFailureMsgs();
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -06005260 }
5261}
5262
5263TEST_F(VkLayerTest, CreateImageResourceSizeViolation)
5264{
Courtney Goeltzenleuchterfd4830c2015-11-25 10:30:56 -07005265 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06005266 "CreateImage resource size exceeds allowable maximum");
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -06005267
5268 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -06005269
5270 // Create an image
5271 VkImage image;
5272
5273 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
5274 const int32_t tex_width = 32;
5275 const int32_t tex_height = 32;
5276
5277 VkImageCreateInfo image_create_info = {};
5278 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
5279 image_create_info.pNext = NULL;
5280 image_create_info.imageType = VK_IMAGE_TYPE_2D;
5281 image_create_info.format = tex_format;
5282 image_create_info.extent.width = tex_width;
5283 image_create_info.extent.height = tex_height;
5284 image_create_info.extent.depth = 1;
5285 image_create_info.mipLevels = 1;
Courtney Goeltzenleuchter5d2aed42015-10-21 17:57:31 -06005286 image_create_info.arrayLayers = 1;
Chia-I Wu5c17c962015-10-31 00:31:16 +08005287 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -06005288 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
5289 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
5290 image_create_info.flags = 0;
5291
5292 // Introduce error by sending down individually allowable values that result in a surface size
5293 // exceeding the device maximum
5294 image_create_info.extent.width = 8192;
5295 image_create_info.extent.height = 8192;
5296 image_create_info.extent.depth = 16;
Courtney Goeltzenleuchter5d2aed42015-10-21 17:57:31 -06005297 image_create_info.arrayLayers = 4;
Chia-I Wu5c17c962015-10-31 00:31:16 +08005298 image_create_info.samples = VK_SAMPLE_COUNT_2_BIT;
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -06005299 image_create_info.format = VK_FORMAT_R8G8B8A8_UNORM;
Chia-I Wuf7458c52015-10-26 21:10:41 +08005300 vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -06005301
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06005302 if (!m_errorMonitor->DesiredMsgFound()) {
5303 FAIL() << "Did not receive Error 'CreateImage resource size exceeds allowable maximum'";
5304 m_errorMonitor->DumpFailureMsgs();
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -06005305 }
5306}
5307
Mike Stroyana3082432015-09-25 13:39:21 -06005308TEST_F(VkLayerTest, UpdateBufferAlignment)
5309{
Mike Stroyana3082432015-09-25 13:39:21 -06005310 uint32_t updateData[] = { 1, 2, 3, 4, 5, 6, 7, 8 };
5311
Courtney Goeltzenleuchterfd4830c2015-11-25 10:30:56 -07005312 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06005313 "dstOffset, is not a multiple of 4");
5314
Mike Stroyana3082432015-09-25 13:39:21 -06005315 ASSERT_NO_FATAL_FAILURE(InitState());
5316
5317 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
5318 vk_testing::Buffer buffer;
5319 buffer.init_as_dst(*m_device, (VkDeviceSize)20, reqs);
5320
5321 BeginCommandBuffer();
5322 // Introduce failure by using offset that is not multiple of 4
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005323 m_commandBuffer->UpdateBuffer(buffer.handle(), 1, 4, updateData);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06005324 if (!m_errorMonitor->DesiredMsgFound()) {
5325 FAIL() << "Did not receive Error 'vkCommandUpdateBuffer parameter, VkDeviceSize dstOffset, is not a multiple of 4'";
5326 m_errorMonitor->DumpFailureMsgs();
Mike Stroyana3082432015-09-25 13:39:21 -06005327 }
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06005328
Mike Stroyana3082432015-09-25 13:39:21 -06005329 // Introduce failure by using size that is not multiple of 4
Courtney Goeltzenleuchterfd4830c2015-11-25 10:30:56 -07005330 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06005331 "dataSize, is not a multiple of 4");
5332
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005333 m_commandBuffer->UpdateBuffer(buffer.handle(), 0, 6, updateData);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06005334
5335 if (!m_errorMonitor->DesiredMsgFound()) {
5336 FAIL() << "Did not receive Error 'vkCommandUpdateBuffer parameter, VkDeviceSize dataSize, is not a multiple of 4'";
5337 m_errorMonitor->DumpFailureMsgs();
Mike Stroyana3082432015-09-25 13:39:21 -06005338 }
5339 EndCommandBuffer();
5340}
5341
5342TEST_F(VkLayerTest, FillBufferAlignment)
5343{
Courtney Goeltzenleuchterfd4830c2015-11-25 10:30:56 -07005344 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06005345 "dstOffset, is not a multiple of 4");
Mike Stroyana3082432015-09-25 13:39:21 -06005346
5347 ASSERT_NO_FATAL_FAILURE(InitState());
5348
5349 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
5350 vk_testing::Buffer buffer;
5351 buffer.init_as_dst(*m_device, (VkDeviceSize)20, reqs);
5352
5353 BeginCommandBuffer();
5354 // Introduce failure by using offset that is not multiple of 4
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005355 m_commandBuffer->FillBuffer(buffer.handle(), 1, 4, 0x11111111);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06005356 if (!m_errorMonitor->DesiredMsgFound()) {
5357 FAIL() << "Did not receive Error 'vkCommandFillBuffer parameter, VkDeviceSize dstOffset, is not a multiple of 4'";
5358 m_errorMonitor->DumpFailureMsgs();
Mike Stroyana3082432015-09-25 13:39:21 -06005359 }
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06005360
Mike Stroyana3082432015-09-25 13:39:21 -06005361 // Introduce failure by using size that is not multiple of 4
Courtney Goeltzenleuchterfd4830c2015-11-25 10:30:56 -07005362 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06005363 "size, is not a multiple of 4");
5364
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005365 m_commandBuffer->FillBuffer(buffer.handle(), 0, 6, 0x11111111);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06005366
5367 if (!m_errorMonitor->DesiredMsgFound()) {
5368 FAIL() << "Did not receive Error 'vkCommandFillBuffer parameter, VkDeviceSize size, is not a multiple of 4'";
5369 m_errorMonitor->DumpFailureMsgs();
Mike Stroyana3082432015-09-25 13:39:21 -06005370 }
5371 EndCommandBuffer();
5372}
5373
Mark Lobodzinski209b5292015-09-17 09:44:05 -06005374#endif // DEVICE_LIMITS_TESTS
Chris Forbesa36d69e2015-05-25 11:13:44 +12005375
Tobin Ehliscde08892015-09-22 10:11:37 -06005376#if IMAGE_TESTS
5377TEST_F(VkLayerTest, InvalidImageView)
5378{
Tobin Ehliscde08892015-09-22 10:11:37 -06005379 VkResult err;
5380
Courtney Goeltzenleuchterfd4830c2015-11-25 10:30:56 -07005381 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06005382 "vkCreateImageView called with baseMipLevel 10 ");
5383
Tobin Ehliscde08892015-09-22 10:11:37 -06005384 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehliscde08892015-09-22 10:11:37 -06005385
Mike Stroyana3082432015-09-25 13:39:21 -06005386 // Create an image and try to create a view with bad baseMipLevel
Tobin Ehliscde08892015-09-22 10:11:37 -06005387 VkImage image;
5388
5389 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
5390 const int32_t tex_width = 32;
5391 const int32_t tex_height = 32;
5392
5393 VkImageCreateInfo image_create_info = {};
5394 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
5395 image_create_info.pNext = NULL;
5396 image_create_info.imageType = VK_IMAGE_TYPE_2D;
5397 image_create_info.format = tex_format;
5398 image_create_info.extent.width = tex_width;
5399 image_create_info.extent.height = tex_height;
5400 image_create_info.extent.depth = 1;
5401 image_create_info.mipLevels = 1;
Courtney Goeltzenleuchter5d2aed42015-10-21 17:57:31 -06005402 image_create_info.arrayLayers = 1;
Chia-I Wu5c17c962015-10-31 00:31:16 +08005403 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Tobin Ehliscde08892015-09-22 10:11:37 -06005404 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
5405 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
5406 image_create_info.flags = 0;
5407
Chia-I Wuf7458c52015-10-26 21:10:41 +08005408 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Tobin Ehliscde08892015-09-22 10:11:37 -06005409 ASSERT_VK_SUCCESS(err);
5410
5411 VkImageViewCreateInfo image_view_create_info = {};
5412 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
5413 image_view_create_info.image = image;
5414 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
5415 image_view_create_info.format = tex_format;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005416 image_view_create_info.subresourceRange.layerCount = 1;
Tobin Ehliscde08892015-09-22 10:11:37 -06005417 image_view_create_info.subresourceRange.baseMipLevel = 10; // cause an error
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005418 image_view_create_info.subresourceRange.levelCount = 1;
Mark Lobodzinskidc86b852015-10-23 14:20:31 -06005419 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Tobin Ehliscde08892015-09-22 10:11:37 -06005420
5421 VkImageView view;
Chia-I Wuf7458c52015-10-26 21:10:41 +08005422 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
Tobin Ehliscde08892015-09-22 10:11:37 -06005423
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06005424 if (!m_errorMonitor->DesiredMsgFound()) {
5425 FAIL() << "Did not receive Error 'vkCreateImageView called with baseMipLevel 10...'";
5426 m_errorMonitor->DumpFailureMsgs();
Tobin Ehliscde08892015-09-22 10:11:37 -06005427 }
5428}
Mike Stroyana3082432015-09-25 13:39:21 -06005429
Mark Lobodzinskidc86b852015-10-23 14:20:31 -06005430TEST_F(VkLayerTest, InvalidImageViewAspect)
5431{
Mark Lobodzinskidc86b852015-10-23 14:20:31 -06005432 VkResult err;
5433
Courtney Goeltzenleuchterfd4830c2015-11-25 10:30:56 -07005434 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06005435 "vkCreateImageView: Color image formats must have ONLY the VK_IMAGE_ASPECT_COLOR_BIT set");
5436
Mark Lobodzinskidc86b852015-10-23 14:20:31 -06005437 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskidc86b852015-10-23 14:20:31 -06005438
5439 // Create an image and try to create a view with an invalid aspectMask
5440 VkImage image;
5441
5442 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
5443 const int32_t tex_width = 32;
5444 const int32_t tex_height = 32;
5445
5446 VkImageCreateInfo image_create_info = {};
5447 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
5448 image_create_info.pNext = NULL;
5449 image_create_info.imageType = VK_IMAGE_TYPE_2D;
5450 image_create_info.format = tex_format;
5451 image_create_info.extent.width = tex_width;
5452 image_create_info.extent.height = tex_height;
5453 image_create_info.extent.depth = 1;
5454 image_create_info.mipLevels = 1;
Chia-I Wu5c17c962015-10-31 00:31:16 +08005455 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Mark Lobodzinskidc86b852015-10-23 14:20:31 -06005456 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
5457 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
5458 image_create_info.flags = 0;
5459
Chia-I Wuf7458c52015-10-26 21:10:41 +08005460 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Mark Lobodzinskidc86b852015-10-23 14:20:31 -06005461 ASSERT_VK_SUCCESS(err);
5462
5463 VkImageViewCreateInfo image_view_create_info = {};
5464 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
5465 image_view_create_info.image = image;
5466 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
5467 image_view_create_info.format = tex_format;
5468 image_view_create_info.subresourceRange.baseMipLevel = 0;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005469 image_view_create_info.subresourceRange.levelCount = 1;
Mark Lobodzinskidc86b852015-10-23 14:20:31 -06005470 // Cause an error by setting an invalid image aspect
5471 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_METADATA_BIT;
5472
5473 VkImageView view;
Chia-I Wuf7458c52015-10-26 21:10:41 +08005474 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
Mark Lobodzinskidc86b852015-10-23 14:20:31 -06005475
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06005476 if (!m_errorMonitor->DesiredMsgFound()) {
5477 FAIL() << "Did not receive Error 'VkCreateImageView: Color image formats must have ...'";
5478 m_errorMonitor->DumpFailureMsgs();
Mark Lobodzinskidc86b852015-10-23 14:20:31 -06005479 }
5480}
5481
Mike Stroyana3082432015-09-25 13:39:21 -06005482TEST_F(VkLayerTest, CopyImageTypeMismatch)
5483{
Mike Stroyana3082432015-09-25 13:39:21 -06005484 VkResult err;
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -06005485 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -06005486
Courtney Goeltzenleuchterfd4830c2015-11-25 10:30:56 -07005487 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06005488 "vkCmdCopyImage called with unmatched source and dest image types");
5489
Mike Stroyana3082432015-09-25 13:39:21 -06005490 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -06005491
5492 // Create two images of different types and try to copy between them
5493 VkImage srcImage;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005494 VkImage dstImage;
Mike Stroyana3082432015-09-25 13:39:21 -06005495 VkDeviceMemory srcMem;
5496 VkDeviceMemory destMem;
5497 VkMemoryRequirements memReqs;
5498
5499 VkImageCreateInfo image_create_info = {};
5500 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
5501 image_create_info.pNext = NULL;
5502 image_create_info.imageType = VK_IMAGE_TYPE_2D;
5503 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
5504 image_create_info.extent.width = 32;
5505 image_create_info.extent.height = 32;
5506 image_create_info.extent.depth = 1;
5507 image_create_info.mipLevels = 1;
Courtney Goeltzenleuchter5d2aed42015-10-21 17:57:31 -06005508 image_create_info.arrayLayers = 1;
Chia-I Wu5c17c962015-10-31 00:31:16 +08005509 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -06005510 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005511 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -06005512 image_create_info.flags = 0;
5513
Chia-I Wuf7458c52015-10-26 21:10:41 +08005514 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -06005515 ASSERT_VK_SUCCESS(err);
5516
5517 image_create_info.imageType = VK_IMAGE_TYPE_1D;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005518 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -06005519
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005520 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -06005521 ASSERT_VK_SUCCESS(err);
5522
5523 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005524 VkMemoryAllocateInfo memAlloc = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08005525 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
Mike Stroyana3082432015-09-25 13:39:21 -06005526 memAlloc.pNext = NULL;
5527 memAlloc.allocationSize = 0;
5528 memAlloc.memoryTypeIndex = 0;
5529
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -06005530 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -06005531 memAlloc.allocationSize = memReqs.size;
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -06005532 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
5533 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005534 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -06005535 ASSERT_VK_SUCCESS(err);
5536
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005537 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -06005538 memAlloc.allocationSize = memReqs.size;
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -06005539 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Mike Stroyana3082432015-09-25 13:39:21 -06005540 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005541 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -06005542 ASSERT_VK_SUCCESS(err);
5543
5544 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
5545 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005546 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -06005547 ASSERT_VK_SUCCESS(err);
5548
5549 BeginCommandBuffer();
5550 VkImageCopy copyRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +08005551 copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -06005552 copyRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -06005553 copyRegion.srcSubresource.baseArrayLayer = 0;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005554 copyRegion.srcSubresource.layerCount = 0;
Mike Stroyana3082432015-09-25 13:39:21 -06005555 copyRegion.srcOffset.x = 0;
5556 copyRegion.srcOffset.y = 0;
5557 copyRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +08005558 copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005559 copyRegion.dstSubresource.mipLevel = 0;
5560 copyRegion.dstSubresource.baseArrayLayer = 0;
5561 copyRegion.dstSubresource.layerCount = 0;
5562 copyRegion.dstOffset.x = 0;
5563 copyRegion.dstOffset.y = 0;
5564 copyRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -06005565 copyRegion.extent.width = 1;
5566 copyRegion.extent.height = 1;
5567 copyRegion.extent.depth = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005568 m_commandBuffer->CopyImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
Mike Stroyana3082432015-09-25 13:39:21 -06005569 EndCommandBuffer();
5570
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06005571 if (!m_errorMonitor->DesiredMsgFound()) {
5572 FAIL() << "Did not receive Error 'vkCmdCopyImage called with unmatched source and dest image types'";
5573 m_errorMonitor->DumpFailureMsgs();
Mike Stroyana3082432015-09-25 13:39:21 -06005574 }
5575
Chia-I Wuf7458c52015-10-26 21:10:41 +08005576 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005577 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +08005578 vkFreeMemory(m_device->device(), srcMem, NULL);
5579 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -06005580}
5581
5582TEST_F(VkLayerTest, CopyImageFormatSizeMismatch)
5583{
5584 // TODO : Create two images with different format sizes and vkCmdCopyImage between them
5585}
5586
5587TEST_F(VkLayerTest, CopyImageDepthStencilFormatMismatch)
5588{
Mike Stroyana3082432015-09-25 13:39:21 -06005589 VkResult err;
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -06005590 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -06005591
Courtney Goeltzenleuchterfd4830c2015-11-25 10:30:56 -07005592 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06005593 "vkCmdCopyImage called with unmatched source and dest image types");
5594
Mike Stroyana3082432015-09-25 13:39:21 -06005595 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -06005596
5597 // Create two images of different types and try to copy between them
5598 VkImage srcImage;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005599 VkImage dstImage;
Mike Stroyana3082432015-09-25 13:39:21 -06005600 VkDeviceMemory srcMem;
5601 VkDeviceMemory destMem;
5602 VkMemoryRequirements memReqs;
5603
5604 VkImageCreateInfo image_create_info = {};
5605 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
5606 image_create_info.pNext = NULL;
5607 image_create_info.imageType = VK_IMAGE_TYPE_2D;
5608 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
5609 image_create_info.extent.width = 32;
5610 image_create_info.extent.height = 32;
5611 image_create_info.extent.depth = 1;
5612 image_create_info.mipLevels = 1;
Courtney Goeltzenleuchter5d2aed42015-10-21 17:57:31 -06005613 image_create_info.arrayLayers = 1;
Chia-I Wu5c17c962015-10-31 00:31:16 +08005614 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -06005615 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005616 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -06005617 image_create_info.flags = 0;
5618
Chia-I Wuf7458c52015-10-26 21:10:41 +08005619 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -06005620 ASSERT_VK_SUCCESS(err);
5621
5622 image_create_info.imageType = VK_IMAGE_TYPE_1D;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005623 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -06005624
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005625 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -06005626 ASSERT_VK_SUCCESS(err);
5627
5628 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005629 VkMemoryAllocateInfo memAlloc = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08005630 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
Mike Stroyana3082432015-09-25 13:39:21 -06005631 memAlloc.pNext = NULL;
5632 memAlloc.allocationSize = 0;
5633 memAlloc.memoryTypeIndex = 0;
5634
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -06005635 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -06005636 memAlloc.allocationSize = memReqs.size;
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -06005637 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
5638 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005639 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -06005640 ASSERT_VK_SUCCESS(err);
5641
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005642 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -06005643 memAlloc.allocationSize = memReqs.size;
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -06005644 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
5645 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005646 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -06005647 ASSERT_VK_SUCCESS(err);
5648
5649 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
5650 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005651 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -06005652 ASSERT_VK_SUCCESS(err);
5653
5654 BeginCommandBuffer();
5655 VkImageCopy copyRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +08005656 copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -06005657 copyRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -06005658 copyRegion.srcSubresource.baseArrayLayer = 0;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005659 copyRegion.srcSubresource.layerCount = 0;
Mike Stroyana3082432015-09-25 13:39:21 -06005660 copyRegion.srcOffset.x = 0;
5661 copyRegion.srcOffset.y = 0;
5662 copyRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +08005663 copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005664 copyRegion.dstSubresource.mipLevel = 0;
5665 copyRegion.dstSubresource.baseArrayLayer = 0;
5666 copyRegion.dstSubresource.layerCount = 0;
5667 copyRegion.dstOffset.x = 0;
5668 copyRegion.dstOffset.y = 0;
5669 copyRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -06005670 copyRegion.extent.width = 1;
5671 copyRegion.extent.height = 1;
5672 copyRegion.extent.depth = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005673 m_commandBuffer->CopyImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
Mike Stroyana3082432015-09-25 13:39:21 -06005674 EndCommandBuffer();
5675
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06005676 if (!m_errorMonitor->DesiredMsgFound()) {
5677 FAIL() << "Did not receive Error 'vkCmdCopyImage called with unmatched source and dest image types'";
5678 m_errorMonitor->DumpFailureMsgs();
Mike Stroyana3082432015-09-25 13:39:21 -06005679 }
5680
Chia-I Wuf7458c52015-10-26 21:10:41 +08005681 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005682 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +08005683 vkFreeMemory(m_device->device(), srcMem, NULL);
5684 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -06005685}
5686
5687TEST_F(VkLayerTest, ResolveImageLowSampleCount)
5688{
Mike Stroyana3082432015-09-25 13:39:21 -06005689 VkResult err;
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -06005690 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -06005691
Courtney Goeltzenleuchterfd4830c2015-11-25 10:30:56 -07005692 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06005693 "vkCmdResolveImage called with source sample count less than 2.");
5694
Mike Stroyana3082432015-09-25 13:39:21 -06005695 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -06005696
5697 // Create two images of sample count 1 and try to Resolve between them
5698 VkImage srcImage;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005699 VkImage dstImage;
Mike Stroyana3082432015-09-25 13:39:21 -06005700 VkDeviceMemory srcMem;
5701 VkDeviceMemory destMem;
5702 VkMemoryRequirements memReqs;
5703
5704 VkImageCreateInfo image_create_info = {};
5705 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
5706 image_create_info.pNext = NULL;
5707 image_create_info.imageType = VK_IMAGE_TYPE_2D;
5708 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
5709 image_create_info.extent.width = 32;
5710 image_create_info.extent.height = 1;
5711 image_create_info.extent.depth = 1;
5712 image_create_info.mipLevels = 1;
Courtney Goeltzenleuchter5d2aed42015-10-21 17:57:31 -06005713 image_create_info.arrayLayers = 1;
Chia-I Wu5c17c962015-10-31 00:31:16 +08005714 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -06005715 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005716 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -06005717 image_create_info.flags = 0;
5718
Chia-I Wuf7458c52015-10-26 21:10:41 +08005719 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -06005720 ASSERT_VK_SUCCESS(err);
5721
5722 image_create_info.imageType = VK_IMAGE_TYPE_1D;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005723 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -06005724
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005725 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -06005726 ASSERT_VK_SUCCESS(err);
5727
5728 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005729 VkMemoryAllocateInfo memAlloc = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08005730 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
Mike Stroyana3082432015-09-25 13:39:21 -06005731 memAlloc.pNext = NULL;
5732 memAlloc.allocationSize = 0;
5733 memAlloc.memoryTypeIndex = 0;
5734
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -06005735 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -06005736 memAlloc.allocationSize = memReqs.size;
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -06005737 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
5738 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005739 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -06005740 ASSERT_VK_SUCCESS(err);
5741
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005742 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -06005743 memAlloc.allocationSize = memReqs.size;
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -06005744 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
5745 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005746 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -06005747 ASSERT_VK_SUCCESS(err);
5748
5749 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
5750 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005751 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -06005752 ASSERT_VK_SUCCESS(err);
5753
5754 BeginCommandBuffer();
5755 // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest?
5756 //VK_IMAGE_LAYOUT_UNDEFINED = 0,
5757 //VK_IMAGE_LAYOUT_GENERAL = 1,
5758 VkImageResolve resolveRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +08005759 resolveRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -06005760 resolveRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -06005761 resolveRegion.srcSubresource.baseArrayLayer = 0;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005762 resolveRegion.srcSubresource.layerCount = 0;
Mike Stroyana3082432015-09-25 13:39:21 -06005763 resolveRegion.srcOffset.x = 0;
5764 resolveRegion.srcOffset.y = 0;
5765 resolveRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +08005766 resolveRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005767 resolveRegion.dstSubresource.mipLevel = 0;
5768 resolveRegion.dstSubresource.baseArrayLayer = 0;
5769 resolveRegion.dstSubresource.layerCount = 0;
5770 resolveRegion.dstOffset.x = 0;
5771 resolveRegion.dstOffset.y = 0;
5772 resolveRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -06005773 resolveRegion.extent.width = 1;
5774 resolveRegion.extent.height = 1;
5775 resolveRegion.extent.depth = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005776 m_commandBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion);
Mike Stroyana3082432015-09-25 13:39:21 -06005777 EndCommandBuffer();
5778
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06005779 if (!m_errorMonitor->DesiredMsgFound()) {
5780 FAIL() << "Did not receive Error 'vkCmdResolveImage called with source sample count less than 2.'";
5781 m_errorMonitor->DumpFailureMsgs();
Mike Stroyana3082432015-09-25 13:39:21 -06005782 }
5783
Chia-I Wuf7458c52015-10-26 21:10:41 +08005784 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005785 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +08005786 vkFreeMemory(m_device->device(), srcMem, NULL);
5787 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -06005788}
5789
5790TEST_F(VkLayerTest, ResolveImageHighSampleCount)
5791{
Mike Stroyana3082432015-09-25 13:39:21 -06005792 VkResult err;
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -06005793 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -06005794
Courtney Goeltzenleuchterfd4830c2015-11-25 10:30:56 -07005795 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06005796 "vkCmdResolveImage called with dest sample count greater than 1.");
5797
Mike Stroyana3082432015-09-25 13:39:21 -06005798 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -06005799
5800 // Create two images of sample count 2 and try to Resolve between them
5801 VkImage srcImage;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005802 VkImage dstImage;
Mike Stroyana3082432015-09-25 13:39:21 -06005803 VkDeviceMemory srcMem;
5804 VkDeviceMemory destMem;
5805 VkMemoryRequirements memReqs;
5806
5807 VkImageCreateInfo image_create_info = {};
5808 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
5809 image_create_info.pNext = NULL;
5810 image_create_info.imageType = VK_IMAGE_TYPE_2D;
5811 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
5812 image_create_info.extent.width = 32;
5813 image_create_info.extent.height = 1;
5814 image_create_info.extent.depth = 1;
5815 image_create_info.mipLevels = 1;
Courtney Goeltzenleuchter5d2aed42015-10-21 17:57:31 -06005816 image_create_info.arrayLayers = 1;
Chia-I Wu5c17c962015-10-31 00:31:16 +08005817 image_create_info.samples = VK_SAMPLE_COUNT_2_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -06005818 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
Cody Northrop72458c02015-10-27 13:50:04 -06005819 // Note: Some implementations expect color attachment usage for any multisample surface
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005820 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -06005821 image_create_info.flags = 0;
5822
Chia-I Wuf7458c52015-10-26 21:10:41 +08005823 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -06005824 ASSERT_VK_SUCCESS(err);
5825
5826 image_create_info.imageType = VK_IMAGE_TYPE_1D;
Cody Northrop72458c02015-10-27 13:50:04 -06005827 // Note: Some implementations expect color attachment usage for any multisample surface
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005828 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -06005829
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005830 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -06005831 ASSERT_VK_SUCCESS(err);
5832
5833 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005834 VkMemoryAllocateInfo memAlloc = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08005835 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
Mike Stroyana3082432015-09-25 13:39:21 -06005836 memAlloc.pNext = NULL;
5837 memAlloc.allocationSize = 0;
5838 memAlloc.memoryTypeIndex = 0;
5839
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -06005840 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -06005841 memAlloc.allocationSize = memReqs.size;
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -06005842 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
5843 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005844 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -06005845 ASSERT_VK_SUCCESS(err);
5846
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005847 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -06005848 memAlloc.allocationSize = memReqs.size;
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -06005849 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
5850 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005851 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -06005852 ASSERT_VK_SUCCESS(err);
5853
5854 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
5855 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005856 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -06005857 ASSERT_VK_SUCCESS(err);
5858
5859 BeginCommandBuffer();
5860 // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest?
5861 //VK_IMAGE_LAYOUT_UNDEFINED = 0,
5862 //VK_IMAGE_LAYOUT_GENERAL = 1,
5863 VkImageResolve resolveRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +08005864 resolveRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -06005865 resolveRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -06005866 resolveRegion.srcSubresource.baseArrayLayer = 0;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005867 resolveRegion.srcSubresource.layerCount = 0;
Mike Stroyana3082432015-09-25 13:39:21 -06005868 resolveRegion.srcOffset.x = 0;
5869 resolveRegion.srcOffset.y = 0;
5870 resolveRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +08005871 resolveRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005872 resolveRegion.dstSubresource.mipLevel = 0;
5873 resolveRegion.dstSubresource.baseArrayLayer = 0;
5874 resolveRegion.dstSubresource.layerCount = 0;
5875 resolveRegion.dstOffset.x = 0;
5876 resolveRegion.dstOffset.y = 0;
5877 resolveRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -06005878 resolveRegion.extent.width = 1;
5879 resolveRegion.extent.height = 1;
5880 resolveRegion.extent.depth = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005881 m_commandBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion);
Mike Stroyana3082432015-09-25 13:39:21 -06005882 EndCommandBuffer();
5883
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06005884 if (!m_errorMonitor->DesiredMsgFound()) {
5885 FAIL() << "Did not receive Error 'vkCmdResolveImage called with dest sample count greater than 1.'";
5886 m_errorMonitor->DumpFailureMsgs();
Mike Stroyana3082432015-09-25 13:39:21 -06005887 }
5888
Chia-I Wuf7458c52015-10-26 21:10:41 +08005889 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005890 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +08005891 vkFreeMemory(m_device->device(), srcMem, NULL);
5892 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -06005893}
5894
5895TEST_F(VkLayerTest, ResolveImageFormatMismatch)
5896{
Mike Stroyana3082432015-09-25 13:39:21 -06005897 VkResult err;
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -06005898 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -06005899
Courtney Goeltzenleuchterfd4830c2015-11-25 10:30:56 -07005900 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06005901 "vkCmdResolveImage called with unmatched source and dest formats.");
5902
Mike Stroyana3082432015-09-25 13:39:21 -06005903 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -06005904
5905 // Create two images of different types and try to copy between them
5906 VkImage srcImage;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005907 VkImage dstImage;
Mike Stroyana3082432015-09-25 13:39:21 -06005908 VkDeviceMemory srcMem;
5909 VkDeviceMemory destMem;
5910 VkMemoryRequirements memReqs;
5911
5912 VkImageCreateInfo image_create_info = {};
5913 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
5914 image_create_info.pNext = NULL;
5915 image_create_info.imageType = VK_IMAGE_TYPE_2D;
5916 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
5917 image_create_info.extent.width = 32;
5918 image_create_info.extent.height = 1;
5919 image_create_info.extent.depth = 1;
5920 image_create_info.mipLevels = 1;
Courtney Goeltzenleuchter5d2aed42015-10-21 17:57:31 -06005921 image_create_info.arrayLayers = 1;
Chia-I Wu5c17c962015-10-31 00:31:16 +08005922 image_create_info.samples = VK_SAMPLE_COUNT_2_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -06005923 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
Cody Northrop72458c02015-10-27 13:50:04 -06005924 // Note: Some implementations expect color attachment usage for any multisample surface
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005925 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -06005926 image_create_info.flags = 0;
5927
Chia-I Wuf7458c52015-10-26 21:10:41 +08005928 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -06005929 ASSERT_VK_SUCCESS(err);
5930
Cody Northrop72458c02015-10-27 13:50:04 -06005931 // Set format to something other than source image
5932 image_create_info.format = VK_FORMAT_R32_SFLOAT;
5933 // Note: Some implementations expect color attachment usage for any multisample surface
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005934 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Chia-I Wu5c17c962015-10-31 00:31:16 +08005935 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -06005936
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005937 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -06005938 ASSERT_VK_SUCCESS(err);
5939
5940 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005941 VkMemoryAllocateInfo memAlloc = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08005942 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
Mike Stroyana3082432015-09-25 13:39:21 -06005943 memAlloc.pNext = NULL;
5944 memAlloc.allocationSize = 0;
5945 memAlloc.memoryTypeIndex = 0;
5946
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -06005947 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -06005948 memAlloc.allocationSize = memReqs.size;
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -06005949 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
5950 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005951 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -06005952 ASSERT_VK_SUCCESS(err);
5953
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005954 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -06005955 memAlloc.allocationSize = memReqs.size;
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -06005956 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
5957 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005958 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -06005959 ASSERT_VK_SUCCESS(err);
5960
5961 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
5962 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005963 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -06005964 ASSERT_VK_SUCCESS(err);
5965
5966 BeginCommandBuffer();
5967 // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest?
5968 //VK_IMAGE_LAYOUT_UNDEFINED = 0,
5969 //VK_IMAGE_LAYOUT_GENERAL = 1,
5970 VkImageResolve resolveRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +08005971 resolveRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -06005972 resolveRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -06005973 resolveRegion.srcSubresource.baseArrayLayer = 0;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005974 resolveRegion.srcSubresource.layerCount = 0;
Mike Stroyana3082432015-09-25 13:39:21 -06005975 resolveRegion.srcOffset.x = 0;
5976 resolveRegion.srcOffset.y = 0;
5977 resolveRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +08005978 resolveRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005979 resolveRegion.dstSubresource.mipLevel = 0;
5980 resolveRegion.dstSubresource.baseArrayLayer = 0;
5981 resolveRegion.dstSubresource.layerCount = 0;
5982 resolveRegion.dstOffset.x = 0;
5983 resolveRegion.dstOffset.y = 0;
5984 resolveRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -06005985 resolveRegion.extent.width = 1;
5986 resolveRegion.extent.height = 1;
5987 resolveRegion.extent.depth = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005988 m_commandBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion);
Mike Stroyana3082432015-09-25 13:39:21 -06005989 EndCommandBuffer();
5990
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06005991 if (!m_errorMonitor->DesiredMsgFound()) {
5992 FAIL() << "Did not receive Error 'vkCmdResolveImage called with unmatched source and dest formats.'";
5993 m_errorMonitor->DumpFailureMsgs();
Mike Stroyana3082432015-09-25 13:39:21 -06005994 }
5995
Chia-I Wuf7458c52015-10-26 21:10:41 +08005996 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005997 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +08005998 vkFreeMemory(m_device->device(), srcMem, NULL);
5999 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -06006000}
6001
6002TEST_F(VkLayerTest, ResolveImageTypeMismatch)
6003{
Mike Stroyana3082432015-09-25 13:39:21 -06006004 VkResult err;
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -06006005 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -06006006
Courtney Goeltzenleuchterfd4830c2015-11-25 10:30:56 -07006007 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06006008 "vkCmdResolveImage called with unmatched source and dest image types.");
6009
Mike Stroyana3082432015-09-25 13:39:21 -06006010 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -06006011
6012 // Create two images of different types and try to copy between them
6013 VkImage srcImage;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006014 VkImage dstImage;
Mike Stroyana3082432015-09-25 13:39:21 -06006015 VkDeviceMemory srcMem;
6016 VkDeviceMemory destMem;
6017 VkMemoryRequirements memReqs;
6018
6019 VkImageCreateInfo image_create_info = {};
6020 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
6021 image_create_info.pNext = NULL;
6022 image_create_info.imageType = VK_IMAGE_TYPE_2D;
6023 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
6024 image_create_info.extent.width = 32;
6025 image_create_info.extent.height = 1;
6026 image_create_info.extent.depth = 1;
6027 image_create_info.mipLevels = 1;
Courtney Goeltzenleuchter5d2aed42015-10-21 17:57:31 -06006028 image_create_info.arrayLayers = 1;
Chia-I Wu5c17c962015-10-31 00:31:16 +08006029 image_create_info.samples = VK_SAMPLE_COUNT_2_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -06006030 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
Cody Northrop72458c02015-10-27 13:50:04 -06006031 // Note: Some implementations expect color attachment usage for any multisample surface
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006032 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -06006033 image_create_info.flags = 0;
6034
Chia-I Wuf7458c52015-10-26 21:10:41 +08006035 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -06006036 ASSERT_VK_SUCCESS(err);
6037
6038 image_create_info.imageType = VK_IMAGE_TYPE_1D;
Cody Northrop72458c02015-10-27 13:50:04 -06006039 // Note: Some implementations expect color attachment usage for any multisample surface
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006040 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Chia-I Wu5c17c962015-10-31 00:31:16 +08006041 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -06006042
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006043 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -06006044 ASSERT_VK_SUCCESS(err);
6045
6046 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006047 VkMemoryAllocateInfo memAlloc = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08006048 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
Mike Stroyana3082432015-09-25 13:39:21 -06006049 memAlloc.pNext = NULL;
6050 memAlloc.allocationSize = 0;
6051 memAlloc.memoryTypeIndex = 0;
6052
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -06006053 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -06006054 memAlloc.allocationSize = memReqs.size;
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -06006055 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
6056 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006057 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -06006058 ASSERT_VK_SUCCESS(err);
6059
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006060 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -06006061 memAlloc.allocationSize = memReqs.size;
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -06006062 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
6063 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006064 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -06006065 ASSERT_VK_SUCCESS(err);
6066
6067 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
6068 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006069 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -06006070 ASSERT_VK_SUCCESS(err);
6071
6072 BeginCommandBuffer();
6073 // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest?
6074 //VK_IMAGE_LAYOUT_UNDEFINED = 0,
6075 //VK_IMAGE_LAYOUT_GENERAL = 1,
6076 VkImageResolve resolveRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +08006077 resolveRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -06006078 resolveRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -06006079 resolveRegion.srcSubresource.baseArrayLayer = 0;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006080 resolveRegion.srcSubresource.layerCount = 0;
Mike Stroyana3082432015-09-25 13:39:21 -06006081 resolveRegion.srcOffset.x = 0;
6082 resolveRegion.srcOffset.y = 0;
6083 resolveRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +08006084 resolveRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006085 resolveRegion.dstSubresource.mipLevel = 0;
6086 resolveRegion.dstSubresource.baseArrayLayer = 0;
6087 resolveRegion.dstSubresource.layerCount = 0;
6088 resolveRegion.dstOffset.x = 0;
6089 resolveRegion.dstOffset.y = 0;
6090 resolveRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -06006091 resolveRegion.extent.width = 1;
6092 resolveRegion.extent.height = 1;
6093 resolveRegion.extent.depth = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006094 m_commandBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion);
Mike Stroyana3082432015-09-25 13:39:21 -06006095 EndCommandBuffer();
6096
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06006097 if (!m_errorMonitor->DesiredMsgFound()) {
6098 FAIL() << "Did not receive Error 'vkCmdResolveImage called with unmatched source and dest image types.'";
6099 m_errorMonitor->DumpFailureMsgs();
Mike Stroyana3082432015-09-25 13:39:21 -06006100 }
6101
Chia-I Wuf7458c52015-10-26 21:10:41 +08006102 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006103 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +08006104 vkFreeMemory(m_device->device(), srcMem, NULL);
6105 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -06006106}
Tobin Ehlisa1c28562015-10-23 16:00:08 -06006107
6108TEST_F(VkLayerTest, DepthStencilImageViewWithColorAspectBitError)
6109{
6110 // Create a single Image descriptor and cause it to first hit an error due
6111 // to using a DS format, then cause it to hit error due to COLOR_BIT not set in aspect
6112 // The image format check comes 2nd in validation so we trigger it first,
6113 // then when we cause aspect fail next, bad format check will be preempted
Tobin Ehlisa1c28562015-10-23 16:00:08 -06006114 VkResult err;
6115
Courtney Goeltzenleuchterfd4830c2015-11-25 10:30:56 -07006116 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06006117 "Combination depth/stencil image formats can have only the ");
6118
Tobin Ehlisa1c28562015-10-23 16:00:08 -06006119 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06006120
Chia-I Wu1b99bb22015-10-27 19:25:11 +08006121 VkDescriptorPoolSize ds_type_count = {};
Tobin Ehlisa1c28562015-10-23 16:00:08 -06006122 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
Chia-I Wud50a7d72015-10-26 20:48:51 +08006123 ds_type_count.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06006124
6125 VkDescriptorPoolCreateInfo ds_pool_ci = {};
6126 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
6127 ds_pool_ci.pNext = NULL;
6128 ds_pool_ci.maxSets = 1;
Chia-I Wu1b99bb22015-10-27 19:25:11 +08006129 ds_pool_ci.poolSizeCount = 1;
6130 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06006131
6132 VkDescriptorPool ds_pool;
Chia-I Wuf7458c52015-10-26 21:10:41 +08006133 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06006134 ASSERT_VK_SUCCESS(err);
6135
6136 VkDescriptorSetLayoutBinding dsl_binding = {};
Chia-I Wud46e6ae2015-10-31 00:31:16 +08006137 dsl_binding.binding = 0;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06006138 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
Chia-I Wu02124482015-11-06 06:42:02 +08006139 dsl_binding.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06006140 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
6141 dsl_binding.pImmutableSamplers = NULL;
6142
6143 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
6144 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
6145 ds_layout_ci.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08006146 ds_layout_ci.bindingCount = 1;
Chia-I Wua745e512015-10-31 00:31:16 +08006147 ds_layout_ci.pBinding = &dsl_binding;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06006148 VkDescriptorSetLayout ds_layout;
Chia-I Wuf7458c52015-10-26 21:10:41 +08006149 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06006150 ASSERT_VK_SUCCESS(err);
6151
6152 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006153 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08006154 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Chia-I Wud50a7d72015-10-26 20:48:51 +08006155 alloc_info.setLayoutCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06006156 alloc_info.descriptorPool = ds_pool;
6157 alloc_info.pSetLayouts = &ds_layout;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006158 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06006159 ASSERT_VK_SUCCESS(err);
6160
6161 VkImage image_bad;
6162 VkImage image_good;
6163 // One bad format and one good format for Color attachment
6164 const VkFormat tex_format_bad = VK_FORMAT_D32_SFLOAT_S8_UINT;
6165 const VkFormat tex_format_good = VK_FORMAT_B8G8R8A8_UNORM;
6166 const int32_t tex_width = 32;
6167 const int32_t tex_height = 32;
6168
6169 VkImageCreateInfo image_create_info = {};
6170 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
6171 image_create_info.pNext = NULL;
6172 image_create_info.imageType = VK_IMAGE_TYPE_2D;
6173 image_create_info.format = tex_format_bad;
6174 image_create_info.extent.width = tex_width;
6175 image_create_info.extent.height = tex_height;
6176 image_create_info.extent.depth = 1;
6177 image_create_info.mipLevels = 1;
6178 image_create_info.arrayLayers = 1;
Chia-I Wu5c17c962015-10-31 00:31:16 +08006179 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06006180 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
6181 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT;
6182 image_create_info.flags = 0;
6183
Chia-I Wuf7458c52015-10-26 21:10:41 +08006184 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image_bad);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06006185 ASSERT_VK_SUCCESS(err);
6186 image_create_info.format = tex_format_good;
6187 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Chia-I Wuf7458c52015-10-26 21:10:41 +08006188 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image_good);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06006189 ASSERT_VK_SUCCESS(err);
6190
6191 VkImageViewCreateInfo image_view_create_info = {};
6192 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
6193 image_view_create_info.image = image_bad;
6194 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
6195 image_view_create_info.format = tex_format_bad;
6196 image_view_create_info.subresourceRange.baseArrayLayer = 0;
6197 image_view_create_info.subresourceRange.baseMipLevel = 0;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006198 image_view_create_info.subresourceRange.layerCount = 1;
6199 image_view_create_info.subresourceRange.levelCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06006200 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
6201
6202 VkImageView view;
Chia-I Wuf7458c52015-10-26 21:10:41 +08006203 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06006204
6205 if (!m_errorMonitor->DesiredMsgFound()) {
6206 FAIL() << "Did not receive Error 'Combination depth-stencil image formats can have only the....'";
6207 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlisa1c28562015-10-23 16:00:08 -06006208 }
6209
Chia-I Wuf7458c52015-10-26 21:10:41 +08006210 vkDestroyImage(m_device->device(), image_bad, NULL);
6211 vkDestroyImage(m_device->device(), image_good, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +08006212 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
6213 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06006214}
Tobin Ehliscde08892015-09-22 10:11:37 -06006215#endif // IMAGE_TESTS
6216
Tony Barbour300a6082015-04-07 13:44:53 -06006217int main(int argc, char **argv) {
6218 int result;
6219
6220 ::testing::InitGoogleTest(&argc, argv);
Tony Barbour6918cd52015-04-09 12:58:51 -06006221 VkTestFramework::InitArgs(&argc, argv);
Tony Barbour300a6082015-04-07 13:44:53 -06006222
6223 ::testing::AddGlobalTestEnvironment(new TestEnvironment);
6224
6225 result = RUN_ALL_TESTS();
6226
Tony Barbour6918cd52015-04-09 12:58:51 -06006227 VkTestFramework::Finish();
Tony Barbour300a6082015-04-07 13:44:53 -06006228 return result;
6229}