1 /*
2 * Copyright (c) 2015-2016 The Khronos Group Inc.
3 * Copyright (c) 2015-2016 Valve Corporation
4 * Copyright (c) 2015-2016 LunarG, Inc.
5 * Copyright (c) 2015-2016 Google, Inc.
6 *
7 * Permission is hereby granted, free of charge, to any person obtaining a copy
8 * of this software and/or associated documentation files (the "Materials"), to
9 * deal in the Materials without restriction, including without limitation the
10 * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
11 * sell copies of the Materials, and to permit persons to whom the Materials are
12 * furnished to do so, subject to the following conditions:
13 *
14 * The above copyright notice(s) and this permission notice shall be included in
15 * all copies or substantial portions of the Materials.
16 *
17 * THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
20 *
21 * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
22 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
23 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE MATERIALS OR THE
24 * USE OR OTHER DEALINGS IN THE MATERIALS.
25 *
26 * Author: Chia-I Wu <olvaffe@gmail.com>
27 * Author: Chris Forbes <chrisf@ijw.co.nz>
28 * Author: Courtney Goeltzenleuchter <courtney@LunarG.com>
29 * Author: Mark Lobodzinski <mark@lunarg.com>
30 * Author: Mike Stroyan <mike@LunarG.com>
31 * Author: Tobin Ehlis <tobine@google.com>
32 * Author: Tony Barbour <tony@LunarG.com>
33 */
34
35 #include <vulkan/vulkan.h>
36 #include "test_common.h"
37 #include "vkrenderframework.h"
38 #include "vk_layer_config.h"
39 #include "icd-spv.h"
40
41 #define GLM_FORCE_RADIANS
42 #include "glm/glm.hpp"
43 #include <glm/gtc/matrix_transform.hpp>
44
45 #define MEM_TRACKER_TESTS 1
46 #define OBJ_TRACKER_TESTS 1
47 #define DRAW_STATE_TESTS 1
48 #define THREADING_TESTS 1
49 #define SHADER_CHECKER_TESTS 1
50 #define DEVICE_LIMITS_TESTS 1
51 #define IMAGE_TESTS 1
52
53 //--------------------------------------------------------------------------------------
54 // Mesh and VertexFormat Data
55 //--------------------------------------------------------------------------------------
56 struct Vertex {
57 float posX, posY, posZ, posW; // Position data
58 float r, g, b, a; // Color
59 };
60
61 #define XYZ1(_x_, _y_, _z_) (_x_), (_y_), (_z_), 1.f
62
63 typedef enum _BsoFailSelect {
64 BsoFailNone = 0x00000000,
65 BsoFailLineWidth = 0x00000001,
66 BsoFailDepthBias = 0x00000002,
67 BsoFailViewport = 0x00000004,
68 BsoFailScissor = 0x00000008,
69 BsoFailBlend = 0x00000010,
70 BsoFailDepthBounds = 0x00000020,
71 BsoFailStencilReadMask = 0x00000040,
72 BsoFailStencilWriteMask = 0x00000080,
73 BsoFailStencilReference = 0x00000100,
74 } BsoFailSelect;
75
76 struct vktriangle_vs_uniform {
77 // Must start with MVP
78 float mvp[4][4];
79 float position[3][4];
80 float color[3][4];
81 };
82
83 static const char bindStateVertShaderText[] =
84 "#version 400\n"
85 "#extension GL_ARB_separate_shader_objects : require\n"
86 "#extension GL_ARB_shading_language_420pack : require\n"
87 "vec2 vertices[3];\n"
88 "out gl_PerVertex {\n"
89 " vec4 gl_Position;\n"
90 "};\n"
91 "void main() {\n"
92 " vertices[0] = vec2(-1.0, -1.0);\n"
93 " vertices[1] = vec2( 1.0, -1.0);\n"
94 " vertices[2] = vec2( 0.0, 1.0);\n"
95 " gl_Position = vec4(vertices[gl_VertexIndex % 3], 0.0, 1.0);\n"
96 "}\n";
97
98 static const char bindStateFragShaderText[] =
99 "#version 400\n"
100 "#extension GL_ARB_separate_shader_objects: require\n"
101 "#extension GL_ARB_shading_language_420pack: require\n"
102 "\n"
103 "layout(location = 0) out vec4 uFragColor;\n"
104 "void main(){\n"
105 " uFragColor = vec4(0,1,0,1);\n"
106 "}\n";
107
108 static VKAPI_ATTR VkBool32 VKAPI_CALL
109 myDbgFunc(VkFlags msgFlags, VkDebugReportObjectTypeEXT objType,
110 uint64_t srcObject, size_t location, int32_t msgCode,
111 const char *pLayerPrefix, const char *pMsg, void *pUserData);
112
113 // ********************************************************
114 // ErrorMonitor Usage:
115 //
116 // Call SetDesiredFailureMsg with a string to be compared against all
117 // encountered log messages. Passing NULL will match all log messages.
118 // logMsg will return true for skipCall only if msg is matched or NULL.
119 //
120 // Call DesiredMsgFound to determine if the desired failure message
121 // was encountered.
122
123 class ErrorMonitor {
124 public:
ErrorMonitor()125 ErrorMonitor() {
126 test_platform_thread_create_mutex(&m_mutex);
127 test_platform_thread_lock_mutex(&m_mutex);
128 m_msgFlags = VK_DEBUG_REPORT_INFORMATION_BIT_EXT;
129 m_bailout = NULL;
130 test_platform_thread_unlock_mutex(&m_mutex);
131 }
132
SetDesiredFailureMsg(VkFlags msgFlags,const char * msgString)133 void SetDesiredFailureMsg(VkFlags msgFlags, const char *msgString) {
134 test_platform_thread_lock_mutex(&m_mutex);
135 m_desiredMsg.clear();
136 m_failureMsg.clear();
137 m_otherMsgs.clear();
138 m_desiredMsg = msgString;
139 m_msgFound = VK_FALSE;
140 m_msgFlags = msgFlags;
141 test_platform_thread_unlock_mutex(&m_mutex);
142 }
143
CheckForDesiredMsg(VkFlags msgFlags,const char * msgString)144 VkBool32 CheckForDesiredMsg(VkFlags msgFlags, const char *msgString) {
145 VkBool32 result = VK_FALSE;
146 test_platform_thread_lock_mutex(&m_mutex);
147 if (m_bailout != NULL) {
148 *m_bailout = true;
149 }
150 string errorString(msgString);
151 if (msgFlags & m_msgFlags) {
152 if (errorString.find(m_desiredMsg) != string::npos) {
153 m_failureMsg = errorString;
154 m_msgFound = VK_TRUE;
155 result = VK_TRUE;
156 } else {
157 m_otherMsgs.push_back(errorString);
158 }
159 }
160 test_platform_thread_unlock_mutex(&m_mutex);
161 return result;
162 }
163
GetOtherFailureMsgs(void)164 vector<string> GetOtherFailureMsgs(void) { return m_otherMsgs; }
165
GetFailureMsg(void)166 string GetFailureMsg(void) { return m_failureMsg; }
167
DesiredMsgFound(void)168 VkBool32 DesiredMsgFound(void) { return m_msgFound; }
169
SetBailout(bool * bailout)170 void SetBailout(bool *bailout) { m_bailout = bailout; }
171
DumpFailureMsgs(void)172 void DumpFailureMsgs(void) {
173 vector<string> otherMsgs = GetOtherFailureMsgs();
174 cout << "Other error messages logged for this test were:" << endl;
175 for (auto iter = otherMsgs.begin(); iter != otherMsgs.end(); iter++) {
176 cout << " " << *iter << endl;
177 }
178 }
179
180 private:
181 VkFlags m_msgFlags;
182 string m_desiredMsg;
183 string m_failureMsg;
184 vector<string> m_otherMsgs;
185 test_platform_thread_mutex m_mutex;
186 bool *m_bailout;
187 VkBool32 m_msgFound;
188 };
189
190 static VKAPI_ATTR VkBool32 VKAPI_CALL
myDbgFunc(VkFlags msgFlags,VkDebugReportObjectTypeEXT objType,uint64_t srcObject,size_t location,int32_t msgCode,const char * pLayerPrefix,const char * pMsg,void * pUserData)191 myDbgFunc(VkFlags msgFlags, VkDebugReportObjectTypeEXT objType,
192 uint64_t srcObject, size_t location, int32_t msgCode,
193 const char *pLayerPrefix, const char *pMsg, void *pUserData) {
194 if (msgFlags &
195 (VK_DEBUG_REPORT_WARNING_BIT_EXT | VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT |
196 VK_DEBUG_REPORT_ERROR_BIT_EXT)) {
197 ErrorMonitor *errMonitor = (ErrorMonitor *)pUserData;
198 return errMonitor->CheckForDesiredMsg(msgFlags, pMsg);
199 }
200 return false;
201 }
202
203 class VkLayerTest : public VkRenderFramework {
204 public:
205 VkResult BeginCommandBuffer(VkCommandBufferObj &commandBuffer);
206 VkResult EndCommandBuffer(VkCommandBufferObj &commandBuffer);
207 void VKTriangleTest(const char *vertShaderText, const char *fragShaderText,
208 BsoFailSelect failMask);
209 void GenericDrawPreparation(VkCommandBufferObj *commandBuffer,
210 VkPipelineObj &pipelineobj,
211 VkDescriptorSetObj &descriptorSet,
212 BsoFailSelect failMask);
GenericDrawPreparation(VkPipelineObj & pipelineobj,VkDescriptorSetObj & descriptorSet,BsoFailSelect failMask)213 void GenericDrawPreparation(VkPipelineObj &pipelineobj,
214 VkDescriptorSetObj &descriptorSet,
215 BsoFailSelect failMask) {
216 GenericDrawPreparation(m_commandBuffer, pipelineobj, descriptorSet,
217 failMask);
218 }
219
220 /* Convenience functions that use built-in command buffer */
BeginCommandBuffer()221 VkResult BeginCommandBuffer() {
222 return BeginCommandBuffer(*m_commandBuffer);
223 }
EndCommandBuffer()224 VkResult EndCommandBuffer() { return EndCommandBuffer(*m_commandBuffer); }
Draw(uint32_t vertexCount,uint32_t instanceCount,uint32_t firstVertex,uint32_t firstInstance)225 void Draw(uint32_t vertexCount, uint32_t instanceCount,
226 uint32_t firstVertex, uint32_t firstInstance) {
227 m_commandBuffer->Draw(vertexCount, instanceCount, firstVertex,
228 firstInstance);
229 }
DrawIndexed(uint32_t indexCount,uint32_t instanceCount,uint32_t firstIndex,int32_t vertexOffset,uint32_t firstInstance)230 void DrawIndexed(uint32_t indexCount, uint32_t instanceCount,
231 uint32_t firstIndex, int32_t vertexOffset,
232 uint32_t firstInstance) {
233 m_commandBuffer->DrawIndexed(indexCount, instanceCount, firstIndex,
234 vertexOffset, firstInstance);
235 }
QueueCommandBuffer()236 void QueueCommandBuffer() { m_commandBuffer->QueueCommandBuffer(); }
QueueCommandBuffer(const VkFence & fence)237 void QueueCommandBuffer(const VkFence &fence) {
238 m_commandBuffer->QueueCommandBuffer(fence);
239 }
BindVertexBuffer(VkConstantBufferObj * vertexBuffer,VkDeviceSize offset,uint32_t binding)240 void BindVertexBuffer(VkConstantBufferObj *vertexBuffer,
241 VkDeviceSize offset, uint32_t binding) {
242 m_commandBuffer->BindVertexBuffer(vertexBuffer, offset, binding);
243 }
BindIndexBuffer(VkIndexBufferObj * indexBuffer,VkDeviceSize offset)244 void BindIndexBuffer(VkIndexBufferObj *indexBuffer, VkDeviceSize offset) {
245 m_commandBuffer->BindIndexBuffer(indexBuffer, offset);
246 }
247
248 protected:
249 ErrorMonitor *m_errorMonitor;
250
SetUp()251 virtual void SetUp() {
252 std::vector<const char *> instance_layer_names;
253 std::vector<const char *> device_layer_names;
254 std::vector<const char *> instance_extension_names;
255 std::vector<const char *> device_extension_names;
256
257 instance_extension_names.push_back(VK_EXT_DEBUG_REPORT_EXTENSION_NAME);
258 /*
259 * Since CreateDbgMsgCallback is an instance level extension call
260 * any extension / layer that utilizes that feature also needs
261 * to be enabled at create instance time.
262 */
263 // Use Threading layer first to protect others from
264 // ThreadCommandBufferCollision test
265 instance_layer_names.push_back("VK_LAYER_GOOGLE_threading");
266 instance_layer_names.push_back("VK_LAYER_LUNARG_object_tracker");
267 instance_layer_names.push_back("VK_LAYER_LUNARG_core_validation");
268 instance_layer_names.push_back("VK_LAYER_LUNARG_device_limits");
269 instance_layer_names.push_back("VK_LAYER_LUNARG_image");
270 instance_layer_names.push_back("VK_LAYER_GOOGLE_unique_objects");
271
272 device_layer_names.push_back("VK_LAYER_GOOGLE_threading");
273 device_layer_names.push_back("VK_LAYER_LUNARG_object_tracker");
274 device_layer_names.push_back("VK_LAYER_LUNARG_core_validation");
275 device_layer_names.push_back("VK_LAYER_LUNARG_device_limits");
276 device_layer_names.push_back("VK_LAYER_LUNARG_image");
277 device_layer_names.push_back("VK_LAYER_GOOGLE_unique_objects");
278
279 this->app_info.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO;
280 this->app_info.pNext = NULL;
281 this->app_info.pApplicationName = "layer_tests";
282 this->app_info.applicationVersion = 1;
283 this->app_info.pEngineName = "unittest";
284 this->app_info.engineVersion = 1;
285 this->app_info.apiVersion = VK_API_VERSION_1_0;
286
287 m_errorMonitor = new ErrorMonitor;
288 InitFramework(instance_layer_names, device_layer_names,
289 instance_extension_names, device_extension_names,
290 myDbgFunc, m_errorMonitor);
291 }
292
TearDown()293 virtual void TearDown() {
294 // Clean up resources before we reset
295 ShutdownFramework();
296 delete m_errorMonitor;
297 }
298 };
299
BeginCommandBuffer(VkCommandBufferObj & commandBuffer)300 VkResult VkLayerTest::BeginCommandBuffer(VkCommandBufferObj &commandBuffer) {
301 VkResult result;
302
303 result = commandBuffer.BeginCommandBuffer();
304
305 /*
306 * For render test all drawing happens in a single render pass
307 * on a single command buffer.
308 */
309 if (VK_SUCCESS == result && renderPass()) {
310 commandBuffer.BeginRenderPass(renderPassBeginInfo());
311 }
312
313 return result;
314 }
315
EndCommandBuffer(VkCommandBufferObj & commandBuffer)316 VkResult VkLayerTest::EndCommandBuffer(VkCommandBufferObj &commandBuffer) {
317 VkResult result;
318
319 if (renderPass()) {
320 commandBuffer.EndRenderPass();
321 }
322
323 result = commandBuffer.EndCommandBuffer();
324
325 return result;
326 }
327
VKTriangleTest(const char * vertShaderText,const char * fragShaderText,BsoFailSelect failMask)328 void VkLayerTest::VKTriangleTest(const char *vertShaderText,
329 const char *fragShaderText,
330 BsoFailSelect failMask) {
331 // Create identity matrix
332 int i;
333 struct vktriangle_vs_uniform data;
334
335 glm::mat4 Projection = glm::mat4(1.0f);
336 glm::mat4 View = glm::mat4(1.0f);
337 glm::mat4 Model = glm::mat4(1.0f);
338 glm::mat4 MVP = Projection * View * Model;
339 const int matrixSize = sizeof(MVP);
340 const int bufSize = sizeof(vktriangle_vs_uniform) / sizeof(float);
341
342 memcpy(&data.mvp, &MVP[0][0], matrixSize);
343
344 static const Vertex tri_data[] = {
345 {XYZ1(-1, -1, 0), XYZ1(1.f, 0.f, 0.f)},
346 {XYZ1(1, -1, 0), XYZ1(0.f, 1.f, 0.f)},
347 {XYZ1(0, 1, 0), XYZ1(0.f, 0.f, 1.f)},
348 };
349
350 for (i = 0; i < 3; i++) {
351 data.position[i][0] = tri_data[i].posX;
352 data.position[i][1] = tri_data[i].posY;
353 data.position[i][2] = tri_data[i].posZ;
354 data.position[i][3] = tri_data[i].posW;
355 data.color[i][0] = tri_data[i].r;
356 data.color[i][1] = tri_data[i].g;
357 data.color[i][2] = tri_data[i].b;
358 data.color[i][3] = tri_data[i].a;
359 }
360
361 ASSERT_NO_FATAL_FAILURE(InitState());
362 ASSERT_NO_FATAL_FAILURE(InitViewport());
363
364 VkConstantBufferObj constantBuffer(m_device, bufSize * 2, sizeof(float),
365 (const void *)&data);
366
367 VkShaderObj vs(m_device, vertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
368 VkShaderObj ps(m_device, fragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT,
369 this);
370
371 VkPipelineObj pipelineobj(m_device);
372 pipelineobj.AddColorAttachment();
373 pipelineobj.AddShader(&vs);
374 pipelineobj.AddShader(&ps);
375 if (failMask & BsoFailLineWidth) {
376 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_LINE_WIDTH);
377 }
378 if (failMask & BsoFailDepthBias) {
379 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_DEPTH_BIAS);
380 }
381 // Viewport and scissors must stay in synch or other errors will occur than
382 // the ones we want
383 if (failMask & BsoFailViewport) {
384 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_VIEWPORT);
385 m_viewports.clear();
386 m_scissors.clear();
387 }
388 if (failMask & BsoFailScissor) {
389 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_SCISSOR);
390 m_scissors.clear();
391 m_viewports.clear();
392 }
393 if (failMask & BsoFailBlend) {
394 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_BLEND_CONSTANTS);
395 }
396 if (failMask & BsoFailDepthBounds) {
397 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_DEPTH_BOUNDS);
398 }
399 if (failMask & BsoFailStencilReadMask) {
400 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_STENCIL_COMPARE_MASK);
401 }
402 if (failMask & BsoFailStencilWriteMask) {
403 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_STENCIL_WRITE_MASK);
404 }
405 if (failMask & BsoFailStencilReference) {
406 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_STENCIL_REFERENCE);
407 }
408
409 VkDescriptorSetObj descriptorSet(m_device);
410 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER,
411 constantBuffer);
412
413 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
414 ASSERT_VK_SUCCESS(BeginCommandBuffer());
415
416 GenericDrawPreparation(pipelineobj, descriptorSet, failMask);
417
418 // render triangle
419 Draw(3, 1, 0, 0);
420
421 // finalize recording of the command buffer
422 EndCommandBuffer();
423
424 QueueCommandBuffer();
425 }
426
GenericDrawPreparation(VkCommandBufferObj * commandBuffer,VkPipelineObj & pipelineobj,VkDescriptorSetObj & descriptorSet,BsoFailSelect failMask)427 void VkLayerTest::GenericDrawPreparation(VkCommandBufferObj *commandBuffer,
428 VkPipelineObj &pipelineobj,
429 VkDescriptorSetObj &descriptorSet,
430 BsoFailSelect failMask) {
431 if (m_depthStencil->Initialized()) {
432 commandBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color,
433 m_stencil_clear_color, m_depthStencil);
434 } else {
435 commandBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color,
436 m_stencil_clear_color, NULL);
437 }
438
439 commandBuffer->PrepareAttachments();
440 // Make sure depthWriteEnable is set so that Depth fail test will work
441 // correctly
442 // Make sure stencilTestEnable is set so that Stencil fail test will work
443 // correctly
444 VkStencilOpState stencil = {};
445 stencil.failOp = VK_STENCIL_OP_KEEP;
446 stencil.passOp = VK_STENCIL_OP_KEEP;
447 stencil.depthFailOp = VK_STENCIL_OP_KEEP;
448 stencil.compareOp = VK_COMPARE_OP_NEVER;
449
450 VkPipelineDepthStencilStateCreateInfo ds_ci = {};
451 ds_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DEPTH_STENCIL_STATE_CREATE_INFO;
452 ds_ci.pNext = NULL;
453 ds_ci.depthTestEnable = VK_FALSE;
454 ds_ci.depthWriteEnable = VK_TRUE;
455 ds_ci.depthCompareOp = VK_COMPARE_OP_NEVER;
456 ds_ci.depthBoundsTestEnable = VK_FALSE;
457 ds_ci.stencilTestEnable = VK_TRUE;
458 ds_ci.front = stencil;
459 ds_ci.back = stencil;
460
461 pipelineobj.SetDepthStencil(&ds_ci);
462 pipelineobj.SetViewport(m_viewports);
463 pipelineobj.SetScissor(m_scissors);
464 descriptorSet.CreateVKDescriptorSet(commandBuffer);
465 VkResult err = pipelineobj.CreateVKPipeline(
466 descriptorSet.GetPipelineLayout(), renderPass());
467 ASSERT_VK_SUCCESS(err);
468 commandBuffer->BindPipeline(pipelineobj);
469 commandBuffer->BindDescriptorSet(descriptorSet);
470 }
471
472 // ********************************************************************************************************************
473 // ********************************************************************************************************************
474 // ********************************************************************************************************************
475 // ********************************************************************************************************************
476 #if MEM_TRACKER_TESTS
477 #if 0
478 TEST_F(VkLayerTest, CallResetCommandBufferBeforeCompletion)
479 {
480 vk_testing::Fence testFence;
481 VkFenceCreateInfo fenceInfo = {};
482 fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
483 fenceInfo.pNext = NULL;
484 fenceInfo.flags = 0;
485
486 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Resetting CB");
487
488 ASSERT_NO_FATAL_FAILURE(InitState());
489
490 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
491 vk_testing::Buffer buffer;
492 buffer.init_as_dst(*m_device, (VkDeviceSize)20, reqs);
493
494 BeginCommandBuffer();
495 m_commandBuffer->FillBuffer(buffer.handle(), 0, 4, 0x11111111);
496 EndCommandBuffer();
497
498 testFence.init(*m_device, fenceInfo);
499
500 // Bypass framework since it does the waits automatically
501 VkResult err = VK_SUCCESS;
502 VkSubmitInfo submit_info;
503 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
504 submit_info.pNext = NULL;
505 submit_info.waitSemaphoreCount = 0;
506 submit_info.pWaitSemaphores = NULL;
507 submit_info.pWaitDstStageMask = NULL;
508 submit_info.commandBufferCount = 1;
509 submit_info.pCommandBuffers = &m_commandBuffer->handle();
510 submit_info.signalSemaphoreCount = 0;
511 submit_info.pSignalSemaphores = NULL;
512
513 err = vkQueueSubmit( m_device->m_queue, 1, &submit_info, testFence.handle());
514 ASSERT_VK_SUCCESS( err );
515
516 // Introduce failure by calling begin again before checking fence
517 vkResetCommandBuffer(m_commandBuffer->handle(), 0);
518
519 if (!m_errorMonitor->DesiredMsgFound()) {
520 FAIL() << "Did not receive Error 'Resetting CB (0xaddress) before it has completed. You must check CB flag before.'";
521 m_errorMonitor->DumpFailureMsgs();
522 }
523 }
524
525 TEST_F(VkLayerTest, CallBeginCommandBufferBeforeCompletion)
526 {
527 vk_testing::Fence testFence;
528 VkFenceCreateInfo fenceInfo = {};
529 fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
530 fenceInfo.pNext = NULL;
531 fenceInfo.flags = 0;
532
533 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Calling vkBeginCommandBuffer() on active CB");
534
535 ASSERT_NO_FATAL_FAILURE(InitState());
536 ASSERT_NO_FATAL_FAILURE(InitViewport());
537 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
538
539 BeginCommandBuffer();
540 m_commandBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color, m_stencil_clear_color, NULL);
541 EndCommandBuffer();
542
543 testFence.init(*m_device, fenceInfo);
544
545 // Bypass framework since it does the waits automatically
546 VkResult err = VK_SUCCESS;
547 VkSubmitInfo submit_info;
548 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
549 submit_info.pNext = NULL;
550 submit_info.waitSemaphoreCount = 0;
551 submit_info.pWaitSemaphores = NULL;
552 submit_info.pWaitDstStageMask = NULL;
553 submit_info.commandBufferCount = 1;
554 submit_info.pCommandBuffers = &m_commandBuffer->handle();
555 submit_info.signalSemaphoreCount = 0;
556 submit_info.pSignalSemaphores = NULL;
557
558 err = vkQueueSubmit( m_device->m_queue, 1, &submit_info, testFence.handle());
559 ASSERT_VK_SUCCESS( err );
560
561 VkCommandBufferInheritanceInfo hinfo = {};
562 VkCommandBufferBeginInfo info = {};
563 info.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT;
564 info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
565 info.renderPass = VK_NULL_HANDLE;
566 info.subpass = 0;
567 info.framebuffer = VK_NULL_HANDLE;
568 info.occlusionQueryEnable = VK_FALSE;
569 info.queryFlags = 0;
570 info.pipelineStatistics = 0;
571
572 // Introduce failure by calling BCB again before checking fence
573 vkBeginCommandBuffer(m_commandBuffer->handle(), &info);
574
575 if (!m_errorMonitor->DesiredMsgFound()) {
576 FAIL() << "Did not receive Error 'Calling vkBeginCommandBuffer() on an active CB (0xaddress) before it has completed'";
577 m_errorMonitor->DumpFailureMsgs();
578
579 }
580 }
581 #endif
TEST_F(VkLayerTest,MapMemWithoutHostVisibleBit)582 TEST_F(VkLayerTest, MapMemWithoutHostVisibleBit) {
583 VkResult err;
584 bool pass;
585
586 m_errorMonitor->SetDesiredFailureMsg(
587 VK_DEBUG_REPORT_ERROR_BIT_EXT,
588 "Mapping Memory without VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT");
589
590 ASSERT_NO_FATAL_FAILURE(InitState());
591
592 // Create an image, allocate memory, free it, and then try to bind it
593 VkImage image;
594 VkDeviceMemory mem;
595 VkMemoryRequirements mem_reqs;
596
597 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
598 const int32_t tex_width = 32;
599 const int32_t tex_height = 32;
600
601 VkImageCreateInfo image_create_info = {};
602 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
603 image_create_info.pNext = NULL;
604 image_create_info.imageType = VK_IMAGE_TYPE_2D;
605 image_create_info.format = tex_format;
606 image_create_info.extent.width = tex_width;
607 image_create_info.extent.height = tex_height;
608 image_create_info.extent.depth = 1;
609 image_create_info.mipLevels = 1;
610 image_create_info.arrayLayers = 1;
611 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
612 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
613 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
614 image_create_info.flags = 0;
615
616 VkMemoryAllocateInfo mem_alloc = {};
617 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
618 mem_alloc.pNext = NULL;
619 mem_alloc.allocationSize = 0;
620 // Introduce failure, do NOT set memProps to
621 // VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT
622 mem_alloc.memoryTypeIndex = 1;
623
624 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
625 ASSERT_VK_SUCCESS(err);
626
627 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
628
629 mem_alloc.allocationSize = mem_reqs.size;
630
631 pass =
632 m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0,
633 VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT);
634 if (!pass) { // If we can't find any unmappable memory this test doesn't
635 // make sense
636 vkDestroyImage(m_device->device(), image, NULL);
637 return;
638 }
639
640 // allocate memory
641 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
642 ASSERT_VK_SUCCESS(err);
643
644 // Try to bind free memory that has been freed
645 err = vkBindImageMemory(m_device->device(), image, mem, 0);
646 ASSERT_VK_SUCCESS(err);
647
648 // Map memory as if to initialize the image
649 void *mappedAddress = NULL;
650 err = vkMapMemory(m_device->device(), mem, 0, VK_WHOLE_SIZE, 0,
651 &mappedAddress);
652
653 if (!m_errorMonitor->DesiredMsgFound()) {
654 FAIL() << "Did not receive Error 'Error received did not match "
655 "expected error message from vkMapMemory in MemTracker'";
656 m_errorMonitor->DumpFailureMsgs();
657 }
658
659 vkDestroyImage(m_device->device(), image, NULL);
660 }
661
662 // TODO : Is this test still valid. Not sure it is with updates to memory
663 // binding model
664 // Verify and delete the test of fix the check
665 // TEST_F(VkLayerTest, FreeBoundMemory)
666 //{
667 // VkResult err;
668 //
669 // m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT,
670 // "Freeing memory object while it still has references");
671 //
672 // ASSERT_NO_FATAL_FAILURE(InitState());
673
674 // // Create an image, allocate memory, free it, and then try to bind it
675 // VkImage image;
676 // VkDeviceMemory mem;
677 // VkMemoryRequirements mem_reqs;
678 //
679 // const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
680 // const int32_t tex_width = 32;
681 // const int32_t tex_height = 32;
682 //
683 // const VkImageCreateInfo image_create_info = {
684 // .sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO,
685 // .pNext = NULL,
686 // .imageType = VK_IMAGE_TYPE_2D,
687 // .format = tex_format,
688 // .extent = { tex_width, tex_height, 1 },
689 // .mipLevels = 1,
690 // .arraySize = 1,
691 // .samples = VK_SAMPLE_COUNT_1_BIT,
692 // .tiling = VK_IMAGE_TILING_LINEAR,
693 // .usage = VK_IMAGE_USAGE_SAMPLED_BIT,
694 // .flags = 0,
695 // };
696 // VkMemoryAllocateInfo mem_alloc = {
697 // .sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO,
698 // .pNext = NULL,
699 // .allocationSize = 0,
700 // .memoryTypeIndex = 0,
701 // };
702 //
703 // err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
704 // ASSERT_VK_SUCCESS(err);
705 //
706 // err = vkGetImageMemoryRequirements(m_device->device(),
707 // image,
708 // &mem_reqs);
709 // ASSERT_VK_SUCCESS(err);
710 //
711 // mem_alloc.allocationSize = mem_reqs.size;
712 //
713 // err = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc,
714 // 0);
715 // ASSERT_VK_SUCCESS(err);
716 //
717 // // allocate memory
718 // err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
719 // ASSERT_VK_SUCCESS(err);
720 //
721 // // Bind memory to Image object
722 // err = vkBindImageMemory(m_device->device(), image, mem, 0);
723 // ASSERT_VK_SUCCESS(err);
724 //
725 // // Introduce validation failure, free memory while still bound to object
726 // vkFreeMemory(m_device->device(), mem, NULL);
727 //
728 // if (!m_errorMonitor->DesiredMsgFound()) {
729 // FAIL() << "Did not receive Warning 'Freeing memory object while it
730 // still has references'");
731 // m_errorMonitor->DumpFailureMsgs();
732 // }
733 //}
734
TEST_F(VkLayerTest,RebindMemory)735 TEST_F(VkLayerTest, RebindMemory) {
736 VkResult err;
737 bool pass;
738
739 m_errorMonitor->SetDesiredFailureMsg(
740 VK_DEBUG_REPORT_ERROR_BIT_EXT,
741 "which has already been bound to mem object");
742
743 ASSERT_NO_FATAL_FAILURE(InitState());
744
745 // Create an image, allocate memory, free it, and then try to bind it
746 VkImage image;
747 VkDeviceMemory mem1;
748 VkDeviceMemory mem2;
749 VkMemoryRequirements mem_reqs;
750
751 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
752 const int32_t tex_width = 32;
753 const int32_t tex_height = 32;
754
755 VkImageCreateInfo image_create_info = {};
756 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
757 image_create_info.pNext = NULL;
758 image_create_info.imageType = VK_IMAGE_TYPE_2D;
759 image_create_info.format = tex_format;
760 image_create_info.extent.width = tex_width;
761 image_create_info.extent.height = tex_height;
762 image_create_info.extent.depth = 1;
763 image_create_info.mipLevels = 1;
764 image_create_info.arrayLayers = 1;
765 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
766 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
767 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
768 image_create_info.flags = 0;
769
770 VkMemoryAllocateInfo mem_alloc = {};
771 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
772 mem_alloc.pNext = NULL;
773 mem_alloc.allocationSize = 0;
774 mem_alloc.memoryTypeIndex = 0;
775
776 // Introduce failure, do NOT set memProps to
777 // VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT
778 mem_alloc.memoryTypeIndex = 1;
779 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
780 ASSERT_VK_SUCCESS(err);
781
782 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
783
784 mem_alloc.allocationSize = mem_reqs.size;
785 pass =
786 m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
787 ASSERT_TRUE(pass);
788
789 // allocate 2 memory objects
790 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem1);
791 ASSERT_VK_SUCCESS(err);
792 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem2);
793 ASSERT_VK_SUCCESS(err);
794
795 // Bind first memory object to Image object
796 err = vkBindImageMemory(m_device->device(), image, mem1, 0);
797 ASSERT_VK_SUCCESS(err);
798
799 // Introduce validation failure, try to bind a different memory object to
800 // the same image object
801 err = vkBindImageMemory(m_device->device(), image, mem2, 0);
802
803 if (!m_errorMonitor->DesiredMsgFound()) {
804 FAIL() << "Did not receive Error when rebinding memory to an object";
805 m_errorMonitor->DumpFailureMsgs();
806 }
807
808 vkDestroyImage(m_device->device(), image, NULL);
809 vkFreeMemory(m_device->device(), mem1, NULL);
810 vkFreeMemory(m_device->device(), mem2, NULL);
811 }
812
TEST_F(VkLayerTest,SubmitSignaledFence)813 TEST_F(VkLayerTest, SubmitSignaledFence) {
814 vk_testing::Fence testFence;
815
816 m_errorMonitor->SetDesiredFailureMsg(
817 VK_DEBUG_REPORT_ERROR_BIT_EXT, "submitted in SIGNALED state. Fences "
818 "must be reset before being submitted");
819
820 VkFenceCreateInfo fenceInfo = {};
821 fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
822 fenceInfo.pNext = NULL;
823 fenceInfo.flags = VK_FENCE_CREATE_SIGNALED_BIT;
824
825 ASSERT_NO_FATAL_FAILURE(InitState());
826 ASSERT_NO_FATAL_FAILURE(InitViewport());
827 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
828
829 BeginCommandBuffer();
830 m_commandBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color,
831 m_stencil_clear_color, NULL);
832 EndCommandBuffer();
833
834 testFence.init(*m_device, fenceInfo);
835
836 VkSubmitInfo submit_info;
837 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
838 submit_info.pNext = NULL;
839 submit_info.waitSemaphoreCount = 0;
840 submit_info.pWaitSemaphores = NULL;
841 submit_info.pWaitDstStageMask = NULL;
842 submit_info.commandBufferCount = 1;
843 submit_info.pCommandBuffers = &m_commandBuffer->handle();
844 submit_info.signalSemaphoreCount = 0;
845 submit_info.pSignalSemaphores = NULL;
846
847 vkQueueSubmit(m_device->m_queue, 1, &submit_info, testFence.handle());
848 vkQueueWaitIdle(m_device->m_queue);
849
850 if (!m_errorMonitor->DesiredMsgFound()) {
851 FAIL() << "Did not receive Error 'VkQueueSubmit with fence in "
852 "SIGNALED_STATE'";
853 m_errorMonitor->DumpFailureMsgs();
854 }
855 }
856
TEST_F(VkLayerTest,ResetUnsignaledFence)857 TEST_F(VkLayerTest, ResetUnsignaledFence) {
858 vk_testing::Fence testFence;
859 VkFenceCreateInfo fenceInfo = {};
860 fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
861 fenceInfo.pNext = NULL;
862
863 // TODO: verify that this matches layer
864 m_errorMonitor->SetDesiredFailureMsg(
865 VK_DEBUG_REPORT_WARNING_BIT_EXT,
866 "submitted to VkResetFences in UNSIGNALED STATE");
867
868 ASSERT_NO_FATAL_FAILURE(InitState());
869 testFence.init(*m_device, fenceInfo);
870 VkFence fences[1] = {testFence.handle()};
871 vkResetFences(m_device->device(), 1, fences);
872
873 if (!m_errorMonitor->DesiredMsgFound()) {
874 FAIL() << "Did not receive Error 'VkResetFences with fence in "
875 "UNSIGNALED_STATE'";
876 m_errorMonitor->DumpFailureMsgs();
877 }
878 }
879
880 /* TODO: Update for changes due to bug-14075 tiling across render passes */
881 #if 0
882 TEST_F(VkLayerTest, InvalidUsageBits)
883 {
884 // Initiate Draw w/o a PSO bound
885
886 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
887 "Invalid usage flag for image ");
888
889 ASSERT_NO_FATAL_FAILURE(InitState());
890 VkCommandBufferObj commandBuffer(m_device);
891 BeginCommandBuffer();
892
893 const VkExtent3D e3d = {
894 .width = 128,
895 .height = 128,
896 .depth = 1,
897 };
898 const VkImageCreateInfo ici = {
899 .sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO,
900 .pNext = NULL,
901 .imageType = VK_IMAGE_TYPE_2D,
902 .format = VK_FORMAT_D32_SFLOAT_S8_UINT,
903 .extent = e3d,
904 .mipLevels = 1,
905 .arraySize = 1,
906 .samples = VK_SAMPLE_COUNT_1_BIT,
907 .tiling = VK_IMAGE_TILING_LINEAR,
908 .usage = 0, // Not setting VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT
909 .flags = 0,
910 };
911
912 VkImage dsi;
913 vkCreateImage(m_device->device(), &ici, NULL, &dsi);
914 VkDepthStencilView dsv;
915 const VkDepthStencilViewCreateInfo dsvci = {
916 .sType = VK_STRUCTURE_TYPE_DEPTH_STENCIL_VIEW_CREATE_INFO,
917 .pNext = NULL,
918 .image = dsi,
919 .mipLevel = 0,
920 .baseArrayLayer = 0,
921 .arraySize = 1,
922 .flags = 0,
923 };
924 vkCreateDepthStencilView(m_device->device(), &dsvci, NULL, &dsv);
925
926 if (!m_errorMonitor->DesiredMsgFound()) {
927 FAIL() << "Error received was not 'Invalid usage flag for image...'";
928 m_errorMonitor->DumpFailureMsgs();
929 }
930 }
931 #endif // 0
932 #endif // MEM_TRACKER_TESTS
933
934 #if OBJ_TRACKER_TESTS
TEST_F(VkLayerTest,PipelineNotBound)935 TEST_F(VkLayerTest, PipelineNotBound) {
936 VkResult err;
937
938 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
939 "Invalid VkPipeline Object ");
940
941 ASSERT_NO_FATAL_FAILURE(InitState());
942 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
943
944 VkDescriptorPoolSize ds_type_count = {};
945 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
946 ds_type_count.descriptorCount = 1;
947
948 VkDescriptorPoolCreateInfo ds_pool_ci = {};
949 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
950 ds_pool_ci.pNext = NULL;
951 ds_pool_ci.maxSets = 1;
952 ds_pool_ci.poolSizeCount = 1;
953 ds_pool_ci.pPoolSizes = &ds_type_count;
954
955 VkDescriptorPool ds_pool;
956 err =
957 vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
958 ASSERT_VK_SUCCESS(err);
959
960 VkDescriptorSetLayoutBinding dsl_binding = {};
961 dsl_binding.binding = 0;
962 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
963 dsl_binding.descriptorCount = 1;
964 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
965 dsl_binding.pImmutableSamplers = NULL;
966
967 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
968 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
969 ds_layout_ci.pNext = NULL;
970 ds_layout_ci.bindingCount = 1;
971 ds_layout_ci.pBindings = &dsl_binding;
972
973 VkDescriptorSetLayout ds_layout;
974 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
975 &ds_layout);
976 ASSERT_VK_SUCCESS(err);
977
978 VkDescriptorSet descriptorSet;
979 VkDescriptorSetAllocateInfo alloc_info = {};
980 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
981 alloc_info.descriptorSetCount = 1;
982 alloc_info.descriptorPool = ds_pool;
983 alloc_info.pSetLayouts = &ds_layout;
984 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info,
985 &descriptorSet);
986 ASSERT_VK_SUCCESS(err);
987
988 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
989 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
990 pipeline_layout_ci.pNext = NULL;
991 pipeline_layout_ci.setLayoutCount = 1;
992 pipeline_layout_ci.pSetLayouts = &ds_layout;
993
994 VkPipelineLayout pipeline_layout;
995 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL,
996 &pipeline_layout);
997 ASSERT_VK_SUCCESS(err);
998
999 VkPipeline badPipeline = (VkPipeline)((size_t)0xbaadb1be);
1000
1001 BeginCommandBuffer();
1002 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(),
1003 VK_PIPELINE_BIND_POINT_GRAPHICS, badPipeline);
1004
1005 if (!m_errorMonitor->DesiredMsgFound()) {
1006 FAIL()
1007 << "Error received was not 'Invalid VkPipeline Object 0xbaadb1be'"
1008 << endl;
1009 m_errorMonitor->DumpFailureMsgs();
1010 }
1011
1012 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
1013 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
1014 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
1015 }
1016
TEST_F(VkLayerTest,BindInvalidMemory)1017 TEST_F(VkLayerTest, BindInvalidMemory) {
1018 VkResult err;
1019 bool pass;
1020
1021 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
1022 "Invalid VkDeviceMemory Object ");
1023
1024 ASSERT_NO_FATAL_FAILURE(InitState());
1025
1026 // Create an image, allocate memory, free it, and then try to bind it
1027 VkImage image;
1028 VkDeviceMemory mem;
1029 VkMemoryRequirements mem_reqs;
1030
1031 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
1032 const int32_t tex_width = 32;
1033 const int32_t tex_height = 32;
1034
1035 VkImageCreateInfo image_create_info = {};
1036 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
1037 image_create_info.pNext = NULL;
1038 image_create_info.imageType = VK_IMAGE_TYPE_2D;
1039 image_create_info.format = tex_format;
1040 image_create_info.extent.width = tex_width;
1041 image_create_info.extent.height = tex_height;
1042 image_create_info.extent.depth = 1;
1043 image_create_info.mipLevels = 1;
1044 image_create_info.arrayLayers = 1;
1045 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
1046 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
1047 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
1048 image_create_info.flags = 0;
1049
1050 VkMemoryAllocateInfo mem_alloc = {};
1051 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
1052 mem_alloc.pNext = NULL;
1053 mem_alloc.allocationSize = 0;
1054 mem_alloc.memoryTypeIndex = 0;
1055
1056 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
1057 ASSERT_VK_SUCCESS(err);
1058
1059 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
1060
1061 mem_alloc.allocationSize = mem_reqs.size;
1062
1063 pass =
1064 m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
1065 ASSERT_TRUE(pass);
1066
1067 // allocate memory
1068 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
1069 ASSERT_VK_SUCCESS(err);
1070
1071 // Introduce validation failure, free memory before binding
1072 vkFreeMemory(m_device->device(), mem, NULL);
1073
1074 // Try to bind free memory that has been freed
1075 err = vkBindImageMemory(m_device->device(), image, mem, 0);
1076 // This may very well return an error.
1077 (void)err;
1078
1079 if (!m_errorMonitor->DesiredMsgFound()) {
1080 FAIL() << "Did not receive Error 'Invalid VkDeviceMemory Object "
1081 "0x<handle>'";
1082 m_errorMonitor->DumpFailureMsgs();
1083 }
1084
1085 vkDestroyImage(m_device->device(), image, NULL);
1086 }
1087
TEST_F(VkLayerTest,BindMemoryToDestroyedObject)1088 TEST_F(VkLayerTest, BindMemoryToDestroyedObject) {
1089 VkResult err;
1090 bool pass;
1091
1092 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
1093 "Invalid VkImage Object ");
1094
1095 ASSERT_NO_FATAL_FAILURE(InitState());
1096
1097 // Create an image object, allocate memory, destroy the object and then try
1098 // to bind it
1099 VkImage image;
1100 VkDeviceMemory mem;
1101 VkMemoryRequirements mem_reqs;
1102
1103 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
1104 const int32_t tex_width = 32;
1105 const int32_t tex_height = 32;
1106
1107 VkImageCreateInfo image_create_info = {};
1108 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
1109 image_create_info.pNext = NULL;
1110 image_create_info.imageType = VK_IMAGE_TYPE_2D;
1111 image_create_info.format = tex_format;
1112 image_create_info.extent.width = tex_width;
1113 image_create_info.extent.height = tex_height;
1114 image_create_info.extent.depth = 1;
1115 image_create_info.mipLevels = 1;
1116 image_create_info.arrayLayers = 1;
1117 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
1118 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
1119 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
1120 image_create_info.flags = 0;
1121
1122 VkMemoryAllocateInfo mem_alloc = {};
1123 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
1124 mem_alloc.pNext = NULL;
1125 mem_alloc.allocationSize = 0;
1126 mem_alloc.memoryTypeIndex = 0;
1127
1128 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
1129 ASSERT_VK_SUCCESS(err);
1130
1131 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
1132
1133 mem_alloc.allocationSize = mem_reqs.size;
1134 pass =
1135 m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
1136 ASSERT_TRUE(pass);
1137
1138 // Allocate memory
1139 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
1140 ASSERT_VK_SUCCESS(err);
1141
1142 // Introduce validation failure, destroy Image object before binding
1143 vkDestroyImage(m_device->device(), image, NULL);
1144 ASSERT_VK_SUCCESS(err);
1145
1146 // Now Try to bind memory to this destroyed object
1147 err = vkBindImageMemory(m_device->device(), image, mem, 0);
1148 // This may very well return an error.
1149 (void)err;
1150
1151 if (!m_errorMonitor->DesiredMsgFound()) {
1152 FAIL() << "Did not receive Error 'Invalid VkImage Object 0x<handle>'";
1153 m_errorMonitor->DumpFailureMsgs();
1154 }
1155
1156 vkFreeMemory(m_device->device(), mem, NULL);
1157 }
1158
1159 #endif // OBJ_TRACKER_TESTS
1160
1161 #if DRAW_STATE_TESTS
TEST_F(VkLayerTest,LineWidthStateNotBound)1162 TEST_F(VkLayerTest, LineWidthStateNotBound) {
1163 m_errorMonitor->SetDesiredFailureMsg(
1164 VK_DEBUG_REPORT_ERROR_BIT_EXT,
1165 "Dynamic line width state not set for this command buffer");
1166
1167 TEST_DESCRIPTION("Simple Draw Call that validates failure when a line "
1168 "width state object is not bound beforehand");
1169
1170 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText,
1171 BsoFailLineWidth);
1172
1173 if (!m_errorMonitor->DesiredMsgFound()) {
1174 FAIL() << "Did not receive Error 'Dynamic line width state not set for "
1175 "this command buffer'";
1176 m_errorMonitor->DumpFailureMsgs();
1177 }
1178 }
1179
TEST_F(VkLayerTest,DepthBiasStateNotBound)1180 TEST_F(VkLayerTest, DepthBiasStateNotBound) {
1181 m_errorMonitor->SetDesiredFailureMsg(
1182 VK_DEBUG_REPORT_ERROR_BIT_EXT,
1183 "Dynamic depth bias state not set for this command buffer");
1184
1185 TEST_DESCRIPTION("Simple Draw Call that validates failure when a depth "
1186 "bias state object is not bound beforehand");
1187
1188 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText,
1189 BsoFailDepthBias);
1190
1191 if (!m_errorMonitor->DesiredMsgFound()) {
1192 FAIL() << "Did not receive Error 'Dynamic depth bias state not set for "
1193 "this command buffer'";
1194 m_errorMonitor->DumpFailureMsgs();
1195 }
1196 }
1197
1198 // Disable these two tests until we can sort out how to track multiple layer
1199 // errors
TEST_F(VkLayerTest,ViewportStateNotBound)1200 TEST_F(VkLayerTest, ViewportStateNotBound) {
1201 m_errorMonitor->SetDesiredFailureMsg(
1202 VK_DEBUG_REPORT_ERROR_BIT_EXT,
1203 "Dynamic viewport state not set for this command buffer");
1204
1205 TEST_DESCRIPTION("Simple Draw Call that validates failure when a viewport "
1206 "state object is not bound beforehand");
1207
1208 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText,
1209 BsoFailViewport);
1210
1211 if (!m_errorMonitor->DesiredMsgFound()) {
1212 FAIL() << "Did not recieve Error 'Dynamic scissor state not set for "
1213 "this command buffer'";
1214 m_errorMonitor->DumpFailureMsgs();
1215 }
1216 }
1217
TEST_F(VkLayerTest,ScissorStateNotBound)1218 TEST_F(VkLayerTest, ScissorStateNotBound) {
1219 m_errorMonitor->SetDesiredFailureMsg(
1220 VK_DEBUG_REPORT_ERROR_BIT_EXT,
1221 "Dynamic scissor state not set for this command buffer");
1222
1223 TEST_DESCRIPTION("Simple Draw Call that validates failure when a viewport "
1224 "state object is not bound beforehand");
1225
1226 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText,
1227 BsoFailScissor);
1228
1229 if (!m_errorMonitor->DesiredMsgFound()) {
1230 FAIL() << "Did not recieve Error ' Expected: 'Dynamic scissor state "
1231 "not set for this command buffer'";
1232 m_errorMonitor->DumpFailureMsgs();
1233 }
1234 }
1235
TEST_F(VkLayerTest,BlendStateNotBound)1236 TEST_F(VkLayerTest, BlendStateNotBound) {
1237 m_errorMonitor->SetDesiredFailureMsg(
1238 VK_DEBUG_REPORT_ERROR_BIT_EXT,
1239 "Dynamic blend object state not set for this command buffer");
1240
1241 TEST_DESCRIPTION("Simple Draw Call that validates failure when a blend "
1242 "state object is not bound beforehand");
1243
1244 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText,
1245 BsoFailBlend);
1246
1247 if (!m_errorMonitor->DesiredMsgFound()) {
1248 FAIL() << "Did not recieve Error 'Dynamic blend object state not set "
1249 "for this command buffer'";
1250 m_errorMonitor->DumpFailureMsgs();
1251 }
1252 }
1253
TEST_F(VkLayerTest,DepthBoundsStateNotBound)1254 TEST_F(VkLayerTest, DepthBoundsStateNotBound) {
1255 m_errorMonitor->SetDesiredFailureMsg(
1256 VK_DEBUG_REPORT_ERROR_BIT_EXT,
1257 "Dynamic depth bounds state not set for this command buffer");
1258
1259 TEST_DESCRIPTION("Simple Draw Call that validates failure when a depth "
1260 "bounds state object is not bound beforehand");
1261
1262 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText,
1263 BsoFailDepthBounds);
1264
1265 if (!m_errorMonitor->DesiredMsgFound()) {
1266 FAIL() << "Did not receive Error 'Dynamic depth bounds state not set "
1267 "for this command buffer'";
1268 m_errorMonitor->DumpFailureMsgs();
1269 }
1270 }
1271
TEST_F(VkLayerTest,StencilReadMaskNotSet)1272 TEST_F(VkLayerTest, StencilReadMaskNotSet) {
1273 m_errorMonitor->SetDesiredFailureMsg(
1274 VK_DEBUG_REPORT_ERROR_BIT_EXT,
1275 "Dynamic stencil read mask state not set for this command buffer");
1276
1277 ASSERT_NO_FATAL_FAILURE(InitState());
1278
1279 TEST_DESCRIPTION("Simple Draw Call that validates failure when a stencil "
1280 "read mask is not set beforehand");
1281
1282 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText,
1283 BsoFailStencilReadMask);
1284
1285 if (!m_errorMonitor->DesiredMsgFound()) {
1286 FAIL() << "Did not receive Error 'Dynamic stencil read mask state not "
1287 "set for this command buffer'";
1288 m_errorMonitor->DumpFailureMsgs();
1289 }
1290 }
1291
TEST_F(VkLayerTest,StencilWriteMaskNotSet)1292 TEST_F(VkLayerTest, StencilWriteMaskNotSet) {
1293 m_errorMonitor->SetDesiredFailureMsg(
1294 VK_DEBUG_REPORT_ERROR_BIT_EXT,
1295 "Dynamic stencil write mask state not set for this command buffer");
1296
1297 ASSERT_NO_FATAL_FAILURE(InitState());
1298
1299 TEST_DESCRIPTION("Simple Draw Call that validates failure when a stencil "
1300 "write mask is not set beforehand");
1301
1302 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText,
1303 BsoFailStencilWriteMask);
1304
1305 if (!m_errorMonitor->DesiredMsgFound()) {
1306 FAIL() << "Did not receive Error 'Dynamic stencil write mask state not "
1307 "set for this command buffer'";
1308 m_errorMonitor->DumpFailureMsgs();
1309 }
1310 }
1311
TEST_F(VkLayerTest,StencilReferenceNotSet)1312 TEST_F(VkLayerTest, StencilReferenceNotSet) {
1313 m_errorMonitor->SetDesiredFailureMsg(
1314 VK_DEBUG_REPORT_ERROR_BIT_EXT,
1315 "Dynamic stencil reference state not set for this command buffer");
1316
1317 TEST_DESCRIPTION("Simple Draw Call that validates failure when a stencil "
1318 "reference is not set beforehand");
1319
1320 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText,
1321 BsoFailStencilReference);
1322
1323 if (!m_errorMonitor->DesiredMsgFound()) {
1324 FAIL() << "Did not receive Error 'Dynamic stencil reference state not "
1325 "set for this command buffer'";
1326 m_errorMonitor->DumpFailureMsgs();
1327 }
1328 }
1329
TEST_F(VkLayerTest,CommandBufferTwoSubmits)1330 TEST_F(VkLayerTest, CommandBufferTwoSubmits) {
1331 vk_testing::Fence testFence;
1332
1333 m_errorMonitor->SetDesiredFailureMsg(
1334 VK_DEBUG_REPORT_ERROR_BIT_EXT,
1335 "was begun w/ VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT set, but has "
1336 "been submitted");
1337
1338 VkFenceCreateInfo fenceInfo = {};
1339 fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
1340 fenceInfo.pNext = NULL;
1341 fenceInfo.flags = 0;
1342
1343 ASSERT_NO_FATAL_FAILURE(InitState());
1344 ASSERT_NO_FATAL_FAILURE(InitViewport());
1345 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
1346
1347 // We luck out b/c by default the framework creates CB w/ the
1348 // VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT set
1349 BeginCommandBuffer();
1350 m_commandBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color,
1351 m_stencil_clear_color, NULL);
1352 EndCommandBuffer();
1353
1354 testFence.init(*m_device, fenceInfo);
1355
1356 // Bypass framework since it does the waits automatically
1357 VkResult err = VK_SUCCESS;
1358 VkSubmitInfo submit_info;
1359 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
1360 submit_info.pNext = NULL;
1361 submit_info.waitSemaphoreCount = 0;
1362 submit_info.pWaitSemaphores = NULL;
1363 submit_info.pWaitDstStageMask = NULL;
1364 submit_info.commandBufferCount = 1;
1365 submit_info.pCommandBuffers = &m_commandBuffer->handle();
1366 submit_info.signalSemaphoreCount = 0;
1367 submit_info.pSignalSemaphores = NULL;
1368
1369 err = vkQueueSubmit(m_device->m_queue, 1, &submit_info, testFence.handle());
1370 ASSERT_VK_SUCCESS(err);
1371
1372 // Cause validation error by re-submitting cmd buffer that should only be
1373 // submitted once
1374 err = vkQueueSubmit(m_device->m_queue, 1, &submit_info, testFence.handle());
1375
1376 if (!m_errorMonitor->DesiredMsgFound()) {
1377 FAIL() << "Did not receive Error 'CB (0xaddress) was created w/ "
1378 "VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT set...'";
1379 m_errorMonitor->DumpFailureMsgs();
1380 }
1381 }
1382
TEST_F(VkLayerTest,AllocDescriptorFromEmptyPool)1383 TEST_F(VkLayerTest, AllocDescriptorFromEmptyPool) {
1384 // Initiate Draw w/o a PSO bound
1385 VkResult err;
1386
1387 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
1388 "Unable to allocate 1 descriptors of "
1389 "type "
1390 "VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER ");
1391
1392 ASSERT_NO_FATAL_FAILURE(InitState());
1393 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
1394
1395 // Create Pool w/ 1 Sampler descriptor, but try to alloc Uniform Buffer
1396 // descriptor from it
1397 VkDescriptorPoolSize ds_type_count = {};
1398 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLER;
1399 ds_type_count.descriptorCount = 1;
1400
1401 VkDescriptorPoolCreateInfo ds_pool_ci = {};
1402 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
1403 ds_pool_ci.pNext = NULL;
1404 ds_pool_ci.flags = 0;
1405 ds_pool_ci.maxSets = 1;
1406 ds_pool_ci.poolSizeCount = 1;
1407 ds_pool_ci.pPoolSizes = &ds_type_count;
1408
1409 VkDescriptorPool ds_pool;
1410 err =
1411 vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
1412 ASSERT_VK_SUCCESS(err);
1413
1414 VkDescriptorSetLayoutBinding dsl_binding = {};
1415 dsl_binding.binding = 0;
1416 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
1417 dsl_binding.descriptorCount = 1;
1418 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
1419 dsl_binding.pImmutableSamplers = NULL;
1420
1421 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
1422 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
1423 ds_layout_ci.pNext = NULL;
1424 ds_layout_ci.bindingCount = 1;
1425 ds_layout_ci.pBindings = &dsl_binding;
1426
1427 VkDescriptorSetLayout ds_layout;
1428 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
1429 &ds_layout);
1430 ASSERT_VK_SUCCESS(err);
1431
1432 VkDescriptorSet descriptorSet;
1433 VkDescriptorSetAllocateInfo alloc_info = {};
1434 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
1435 alloc_info.descriptorSetCount = 1;
1436 alloc_info.descriptorPool = ds_pool;
1437 alloc_info.pSetLayouts = &ds_layout;
1438 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info,
1439 &descriptorSet);
1440
1441 if (!m_errorMonitor->DesiredMsgFound()) {
1442 FAIL() << "Did not receive Error 'Unable to allocate 1 descriptors of "
1443 "type VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER...'";
1444 m_errorMonitor->DumpFailureMsgs();
1445 }
1446
1447 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
1448 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
1449 }
1450
TEST_F(VkLayerTest,FreeDescriptorFromOneShotPool)1451 TEST_F(VkLayerTest, FreeDescriptorFromOneShotPool) {
1452 VkResult err;
1453
1454 m_errorMonitor->SetDesiredFailureMsg(
1455 VK_DEBUG_REPORT_ERROR_BIT_EXT,
1456 "It is invalid to call vkFreeDescriptorSets() with a pool created "
1457 "without setting VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT.");
1458
1459 ASSERT_NO_FATAL_FAILURE(InitState());
1460 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
1461
1462 VkDescriptorPoolSize ds_type_count = {};
1463 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
1464 ds_type_count.descriptorCount = 1;
1465
1466 VkDescriptorPoolCreateInfo ds_pool_ci = {};
1467 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
1468 ds_pool_ci.pNext = NULL;
1469 ds_pool_ci.maxSets = 1;
1470 ds_pool_ci.poolSizeCount = 1;
1471 ds_pool_ci.flags = 0;
1472 // Not specifying VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT means
1473 // app can only call vkResetDescriptorPool on this pool.;
1474 ds_pool_ci.pPoolSizes = &ds_type_count;
1475
1476 VkDescriptorPool ds_pool;
1477 err =
1478 vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
1479 ASSERT_VK_SUCCESS(err);
1480
1481 VkDescriptorSetLayoutBinding dsl_binding = {};
1482 dsl_binding.binding = 0;
1483 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
1484 dsl_binding.descriptorCount = 1;
1485 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
1486 dsl_binding.pImmutableSamplers = NULL;
1487
1488 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
1489 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
1490 ds_layout_ci.pNext = NULL;
1491 ds_layout_ci.bindingCount = 1;
1492 ds_layout_ci.pBindings = &dsl_binding;
1493
1494 VkDescriptorSetLayout ds_layout;
1495 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
1496 &ds_layout);
1497 ASSERT_VK_SUCCESS(err);
1498
1499 VkDescriptorSet descriptorSet;
1500 VkDescriptorSetAllocateInfo alloc_info = {};
1501 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
1502 alloc_info.descriptorSetCount = 1;
1503 alloc_info.descriptorPool = ds_pool;
1504 alloc_info.pSetLayouts = &ds_layout;
1505 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info,
1506 &descriptorSet);
1507 ASSERT_VK_SUCCESS(err);
1508
1509 err = vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptorSet);
1510 if (!m_errorMonitor->DesiredMsgFound()) {
1511 FAIL() << "Did not receive Error 'It is invalid to call "
1512 "vkFreeDescriptorSets() with a pool created with...'";
1513 m_errorMonitor->DumpFailureMsgs();
1514 }
1515
1516 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
1517 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
1518 }
1519
TEST_F(VkLayerTest,InvalidDescriptorPool)1520 TEST_F(VkLayerTest, InvalidDescriptorPool) {
1521 // TODO : Simple check for bad object should be added to ObjectTracker to
1522 // catch this case
1523 // The DS check for this is after driver has been called to validate DS
1524 // internal data struct
1525 // Attempt to clear DS Pool with bad object
1526 /*
1527 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
1528 "Unable to find pool node for pool 0xbaad6001 specified in
1529 vkResetDescriptorPool() call");
1530
1531 VkDescriptorPool badPool = (VkDescriptorPool)0xbaad6001;
1532 vkResetDescriptorPool(device(), badPool);
1533
1534 if (!m_errorMonitor->DesiredMsgFound()) {
1535 FAIL() << "Did not receive Error 'Unable to find pool node for pool
1536 0xbaad6001 specified in vkResetDescriptorPool() call'";
1537 m_errorMonitor->DumpFailureMsgs();
1538 }*/
1539 }
1540
TEST_F(VkLayerTest,InvalidDescriptorSet)1541 TEST_F(VkLayerTest, InvalidDescriptorSet) {
1542 // TODO : Simple check for bad object should be added to ObjectTracker to
1543 // catch this case
1544 // The DS check for this is after driver has been called to validate DS
1545 // internal data struct
1546 // Create a valid cmd buffer
1547 // call vkCmdBindDescriptorSets w/ false DS
1548 }
1549
TEST_F(VkLayerTest,InvalidDescriptorSetLayout)1550 TEST_F(VkLayerTest, InvalidDescriptorSetLayout) {
1551 // TODO : Simple check for bad object should be added to ObjectTracker to
1552 // catch this case
1553 // The DS check for this is after driver has been called to validate DS
1554 // internal data struct
1555 }
1556
TEST_F(VkLayerTest,InvalidPipeline)1557 TEST_F(VkLayerTest, InvalidPipeline) {
1558 // TODO : Simple check for bad object should be added to ObjectTracker to
1559 // catch this case
1560 // The DS check for this is after driver has been called to validate DS
1561 // internal data struct
1562 // Create a valid cmd buffer
1563 // call vkCmdBindPipeline w/ false Pipeline
1564 //
1565 // m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
1566 // "Attempt to bind Pipeline ");
1567 //
1568 // ASSERT_NO_FATAL_FAILURE(InitState());
1569 // VkCommandBufferObj commandBuffer(m_device);
1570 // BeginCommandBuffer();
1571 // VkPipeline badPipeline = (VkPipeline)0xbaadb1be;
1572 // vkCmdBindPipeline(commandBuffer.GetBufferHandle(),
1573 // VK_PIPELINE_BIND_POINT_GRAPHICS, badPipeline);
1574 //
1575 // if (!m_errorMonitor->DesiredMsgFound()) {
1576 // FAIL() << "Did not receive Error 'Attempt to bind Pipeline
1577 // 0xbaadb1be that doesn't exist!'";
1578 // m_errorMonitor->DumpFailureMsgs();
1579 // }
1580 }
1581
TEST_F(VkLayerTest,DescriptorSetNotUpdated)1582 TEST_F(VkLayerTest, DescriptorSetNotUpdated) {
1583 // Create and update CommandBuffer then call QueueSubmit w/o calling End on
1584 // CommandBuffer
1585 VkResult err;
1586
1587 // TODO: verify that this matches layer
1588 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT,
1589 " bound but it was never updated. ");
1590
1591 ASSERT_NO_FATAL_FAILURE(InitState());
1592 ASSERT_NO_FATAL_FAILURE(InitViewport());
1593 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
1594 VkDescriptorPoolSize ds_type_count = {};
1595 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
1596 ds_type_count.descriptorCount = 1;
1597
1598 VkDescriptorPoolCreateInfo ds_pool_ci = {};
1599 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
1600 ds_pool_ci.pNext = NULL;
1601 ds_pool_ci.maxSets = 1;
1602 ds_pool_ci.poolSizeCount = 1;
1603 ds_pool_ci.pPoolSizes = &ds_type_count;
1604
1605 VkDescriptorPool ds_pool;
1606 err =
1607 vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
1608 ASSERT_VK_SUCCESS(err);
1609
1610 VkDescriptorSetLayoutBinding dsl_binding = {};
1611 dsl_binding.binding = 0;
1612 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
1613 dsl_binding.descriptorCount = 1;
1614 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
1615 dsl_binding.pImmutableSamplers = NULL;
1616
1617 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
1618 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
1619 ds_layout_ci.pNext = NULL;
1620 ds_layout_ci.bindingCount = 1;
1621 ds_layout_ci.pBindings = &dsl_binding;
1622 VkDescriptorSetLayout ds_layout;
1623 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
1624 &ds_layout);
1625 ASSERT_VK_SUCCESS(err);
1626
1627 VkDescriptorSet descriptorSet;
1628 VkDescriptorSetAllocateInfo alloc_info = {};
1629 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
1630 alloc_info.descriptorSetCount = 1;
1631 alloc_info.descriptorPool = ds_pool;
1632 alloc_info.pSetLayouts = &ds_layout;
1633 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info,
1634 &descriptorSet);
1635 ASSERT_VK_SUCCESS(err);
1636
1637 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
1638 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
1639 pipeline_layout_ci.pNext = NULL;
1640 pipeline_layout_ci.setLayoutCount = 1;
1641 pipeline_layout_ci.pSetLayouts = &ds_layout;
1642
1643 VkPipelineLayout pipeline_layout;
1644 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL,
1645 &pipeline_layout);
1646 ASSERT_VK_SUCCESS(err);
1647
1648 VkShaderObj vs(m_device, bindStateVertShaderText,
1649 VK_SHADER_STAGE_VERTEX_BIT, this);
1650 // TODO - We shouldn't need a fragment shader but add it to be able to run
1651 // on more devices
1652 VkShaderObj fs(m_device, bindStateFragShaderText,
1653 VK_SHADER_STAGE_FRAGMENT_BIT, this);
1654
1655 VkPipelineObj pipe(m_device);
1656 pipe.AddShader(&vs);
1657 pipe.AddShader(&fs);
1658 pipe.CreateVKPipeline(pipeline_layout, renderPass());
1659
1660 BeginCommandBuffer();
1661 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(),
1662 VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
1663 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(),
1664 VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0,
1665 1, &descriptorSet, 0, NULL);
1666
1667 if (!m_errorMonitor->DesiredMsgFound()) {
1668 FAIL() << "Did not recieve Warning 'DS <blah> bound but it was never "
1669 "updated. You may want to either update it or not bind it.'";
1670 m_errorMonitor->DumpFailureMsgs();
1671 }
1672
1673 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
1674 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
1675 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
1676 }
1677
TEST_F(VkLayerTest,InvalidBufferViewObject)1678 TEST_F(VkLayerTest, InvalidBufferViewObject) {
1679 // Create a single TEXEL_BUFFER descriptor and send it an invalid bufferView
1680 VkResult err;
1681
1682 m_errorMonitor->SetDesiredFailureMsg(
1683 VK_DEBUG_REPORT_ERROR_BIT_EXT,
1684 "Attempt to update descriptor with invalid bufferView ");
1685
1686 ASSERT_NO_FATAL_FAILURE(InitState());
1687 VkDescriptorPoolSize ds_type_count = {};
1688 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER;
1689 ds_type_count.descriptorCount = 1;
1690
1691 VkDescriptorPoolCreateInfo ds_pool_ci = {};
1692 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
1693 ds_pool_ci.pNext = NULL;
1694 ds_pool_ci.maxSets = 1;
1695 ds_pool_ci.poolSizeCount = 1;
1696 ds_pool_ci.pPoolSizes = &ds_type_count;
1697
1698 VkDescriptorPool ds_pool;
1699 err =
1700 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;
1706 dsl_binding.descriptorCount = 1;
1707 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.pBindings = &dsl_binding;
1715 VkDescriptorSetLayout ds_layout;
1716 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
1717 &ds_layout);
1718 ASSERT_VK_SUCCESS(err);
1719
1720 VkDescriptorSet descriptorSet;
1721 VkDescriptorSetAllocateInfo alloc_info = {};
1722 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
1723 alloc_info.descriptorSetCount = 1;
1724 alloc_info.descriptorPool = ds_pool;
1725 alloc_info.pSetLayouts = &ds_layout;
1726 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info,
1727 &descriptorSet);
1728 ASSERT_VK_SUCCESS(err);
1729
1730 VkBufferView view =
1731 (VkBufferView)((size_t)0xbaadbeef); // invalid bufferView object
1732 VkWriteDescriptorSet descriptor_write;
1733 memset(&descriptor_write, 0, sizeof(descriptor_write));
1734 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
1735 descriptor_write.dstSet = descriptorSet;
1736 descriptor_write.dstBinding = 0;
1737 descriptor_write.descriptorCount = 1;
1738 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER;
1739 descriptor_write.pTexelBufferView = &view;
1740
1741 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
1742
1743 if (!m_errorMonitor->DesiredMsgFound()) {
1744 FAIL() << "Did not receive Error 'Attempt to update descriptor with "
1745 "invalid bufferView'";
1746 m_errorMonitor->DumpFailureMsgs();
1747 }
1748
1749 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
1750 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
1751 }
1752
TEST_F(VkLayerTest,InvalidDynamicOffsetCases)1753 TEST_F(VkLayerTest, InvalidDynamicOffsetCases) {
1754 // Create a descriptorSet w/ dynamic descriptor and then hit 3 offset error
1755 // cases:
1756 // 1. No dynamicOffset supplied
1757 // 2. Too many dynamicOffsets supplied
1758 // 3. Dynamic offset oversteps buffer being updated
1759 VkResult err;
1760 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
1761 " requires 1 dynamicOffsets, but only "
1762 "0 dynamicOffsets are left in "
1763 "pDynamicOffsets ");
1764
1765 ASSERT_NO_FATAL_FAILURE(InitState());
1766 ASSERT_NO_FATAL_FAILURE(InitViewport());
1767 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
1768
1769 VkDescriptorPoolSize ds_type_count = {};
1770 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
1771 ds_type_count.descriptorCount = 1;
1772
1773 VkDescriptorPoolCreateInfo ds_pool_ci = {};
1774 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
1775 ds_pool_ci.pNext = NULL;
1776 ds_pool_ci.maxSets = 1;
1777 ds_pool_ci.poolSizeCount = 1;
1778 ds_pool_ci.pPoolSizes = &ds_type_count;
1779
1780 VkDescriptorPool ds_pool;
1781 err =
1782 vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
1783 ASSERT_VK_SUCCESS(err);
1784
1785 VkDescriptorSetLayoutBinding dsl_binding = {};
1786 dsl_binding.binding = 0;
1787 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
1788 dsl_binding.descriptorCount = 1;
1789 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
1790 dsl_binding.pImmutableSamplers = NULL;
1791
1792 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
1793 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
1794 ds_layout_ci.pNext = NULL;
1795 ds_layout_ci.bindingCount = 1;
1796 ds_layout_ci.pBindings = &dsl_binding;
1797 VkDescriptorSetLayout ds_layout;
1798 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
1799 &ds_layout);
1800 ASSERT_VK_SUCCESS(err);
1801
1802 VkDescriptorSet descriptorSet;
1803 VkDescriptorSetAllocateInfo alloc_info = {};
1804 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
1805 alloc_info.descriptorSetCount = 1;
1806 alloc_info.descriptorPool = ds_pool;
1807 alloc_info.pSetLayouts = &ds_layout;
1808 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info,
1809 &descriptorSet);
1810 ASSERT_VK_SUCCESS(err);
1811
1812 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
1813 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
1814 pipeline_layout_ci.pNext = NULL;
1815 pipeline_layout_ci.setLayoutCount = 1;
1816 pipeline_layout_ci.pSetLayouts = &ds_layout;
1817
1818 VkPipelineLayout pipeline_layout;
1819 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL,
1820 &pipeline_layout);
1821 ASSERT_VK_SUCCESS(err);
1822
1823 // Create a buffer to update the descriptor with
1824 uint32_t qfi = 0;
1825 VkBufferCreateInfo buffCI = {};
1826 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
1827 buffCI.size = 1024;
1828 buffCI.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
1829 buffCI.queueFamilyIndexCount = 1;
1830 buffCI.pQueueFamilyIndices = &qfi;
1831
1832 VkBuffer dyub;
1833 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &dyub);
1834 ASSERT_VK_SUCCESS(err);
1835 // Correctly update descriptor to avoid "NOT_UPDATED" error
1836 VkDescriptorBufferInfo buffInfo = {};
1837 buffInfo.buffer = dyub;
1838 buffInfo.offset = 0;
1839 buffInfo.range = 1024;
1840
1841 VkWriteDescriptorSet descriptor_write;
1842 memset(&descriptor_write, 0, sizeof(descriptor_write));
1843 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
1844 descriptor_write.dstSet = descriptorSet;
1845 descriptor_write.dstBinding = 0;
1846 descriptor_write.descriptorCount = 1;
1847 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
1848 descriptor_write.pBufferInfo = &buffInfo;
1849
1850 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
1851
1852 BeginCommandBuffer();
1853 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(),
1854 VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0,
1855 1, &descriptorSet, 0, NULL);
1856 if (!m_errorMonitor->DesiredMsgFound()) {
1857 FAIL() << "Error received was not 'descriptorSet #0 (0x<ADDR>) "
1858 "requires 1 dynamicOffsets, but only 0 dynamicOffsets are "
1859 "left in pDynamicOffsets array...'";
1860 m_errorMonitor->DumpFailureMsgs();
1861 }
1862 uint32_t pDynOff[2] = {512, 756};
1863 // Now cause error b/c too many dynOffsets in array for # of dyn descriptors
1864 m_errorMonitor->SetDesiredFailureMsg(
1865 VK_DEBUG_REPORT_ERROR_BIT_EXT,
1866 "Attempting to bind 1 descriptorSets with 1 dynamic descriptors, but ");
1867 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(),
1868 VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0,
1869 1, &descriptorSet, 2, pDynOff);
1870 if (!m_errorMonitor->DesiredMsgFound()) {
1871 FAIL() << "Error received was not 'Attempting to bind 1 descriptorSets "
1872 "with 1 dynamic descriptors, but dynamicOffsetCount is 0...'";
1873 m_errorMonitor->DumpFailureMsgs();
1874 }
1875 // Finally cause error due to dynamicOffset being too big
1876 m_errorMonitor->SetDesiredFailureMsg(
1877 VK_DEBUG_REPORT_ERROR_BIT_EXT,
1878 " from its update, this oversteps its buffer (");
1879 // Create PSO to be used for draw-time errors below
1880 char const *vsSource =
1881 "#version 400\n"
1882 "#extension GL_ARB_separate_shader_objects: require\n"
1883 "#extension GL_ARB_shading_language_420pack: require\n"
1884 "\n"
1885 "out gl_PerVertex { \n"
1886 " vec4 gl_Position;\n"
1887 "};\n"
1888 "void main(){\n"
1889 " gl_Position = vec4(1);\n"
1890 "}\n";
1891 char const *fsSource =
1892 "#version 400\n"
1893 "#extension GL_ARB_separate_shader_objects: require\n"
1894 "#extension GL_ARB_shading_language_420pack: require\n"
1895 "\n"
1896 "layout(location=0) out vec4 x;\n"
1897 "layout(set=0) layout(binding=0) uniform foo { int x; int y; } bar;\n"
1898 "void main(){\n"
1899 " x = vec4(bar.y);\n"
1900 "}\n";
1901 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
1902 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
1903 VkPipelineObj pipe(m_device);
1904 pipe.AddShader(&vs);
1905 pipe.AddShader(&fs);
1906 pipe.AddColorAttachment();
1907 pipe.CreateVKPipeline(pipeline_layout, renderPass());
1908
1909 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(),
1910 VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
1911 // This update should succeed, but offset size of 512 will overstep buffer
1912 // /w range 1024 & size 1024
1913 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(),
1914 VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0,
1915 1, &descriptorSet, 1, pDynOff);
1916 Draw(1, 0, 0, 0);
1917 if (!m_errorMonitor->DesiredMsgFound()) {
1918 FAIL() << "Error received was not 'VkDescriptorSet (0x<ADDR>) bound as "
1919 "set #0 has dynamic offset 512. Combined with offet 0 and "
1920 "range 1024 from its update, this oversteps...'";
1921 m_errorMonitor->DumpFailureMsgs();
1922 }
1923
1924 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
1925 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
1926 }
1927
TEST_F(VkLayerTest,InvalidPushConstants)1928 TEST_F(VkLayerTest, InvalidPushConstants) {
1929 // Hit push constant error cases:
1930 // 1. Create PipelineLayout where push constant overstep maxPushConstantSize
1931 // 2. Incorrectly set push constant size to 0
1932 // 3. Incorrectly set push constant size to non-multiple of 4
1933 // 4. Attempt push constant update that exceeds maxPushConstantSize
1934 VkResult err;
1935 m_errorMonitor->SetDesiredFailureMsg(
1936 VK_DEBUG_REPORT_ERROR_BIT_EXT,
1937 "vkCreatePipelineLayout() call has push constants with offset ");
1938
1939 ASSERT_NO_FATAL_FAILURE(InitState());
1940 ASSERT_NO_FATAL_FAILURE(InitViewport());
1941 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
1942
1943 VkPushConstantRange pc_range = {};
1944 pc_range.size = 0xFFFFFFFFu;
1945 pc_range.stageFlags = VK_SHADER_STAGE_VERTEX_BIT;
1946 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
1947 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
1948 pipeline_layout_ci.pushConstantRangeCount = 1;
1949 pipeline_layout_ci.pPushConstantRanges = &pc_range;
1950
1951 VkPipelineLayout pipeline_layout;
1952 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL,
1953 &pipeline_layout);
1954
1955 if (!m_errorMonitor->DesiredMsgFound()) {
1956 FAIL() << "Error received was not 'vkCreatePipelineLayout() call has "
1957 "push constants with offset 0...'";
1958 m_errorMonitor->DumpFailureMsgs();
1959 }
1960 // Now cause errors due to size 0 and non-4 byte aligned size
1961 pc_range.size = 0;
1962 m_errorMonitor->SetDesiredFailureMsg(
1963 VK_DEBUG_REPORT_ERROR_BIT_EXT,
1964 "vkCreatePipelineLayout() call has push constant index 0 with size 0");
1965 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL,
1966 &pipeline_layout);
1967 if (!m_errorMonitor->DesiredMsgFound()) {
1968 FAIL() << "Error received was not 'vkCreatePipelineLayout() call has "
1969 "push constant index 0 with size 0...'";
1970 m_errorMonitor->DumpFailureMsgs();
1971 }
1972 pc_range.size = 1;
1973 m_errorMonitor->SetDesiredFailureMsg(
1974 VK_DEBUG_REPORT_ERROR_BIT_EXT,
1975 "vkCreatePipelineLayout() call has push constant index 0 with size 1");
1976 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL,
1977 &pipeline_layout);
1978 if (!m_errorMonitor->DesiredMsgFound()) {
1979 FAIL() << "Error received was not 'vkCreatePipelineLayout() call has "
1980 "push constant index 0 with size 0...'";
1981 m_errorMonitor->DumpFailureMsgs();
1982 }
1983 // Cause error due to bad size in vkCmdPushConstants() call
1984 m_errorMonitor->SetDesiredFailureMsg(
1985 VK_DEBUG_REPORT_ERROR_BIT_EXT,
1986 "vkCmdPushConstants() call has push constants with offset ");
1987 pipeline_layout_ci.pushConstantRangeCount = 0;
1988 pipeline_layout_ci.pPushConstantRanges = NULL;
1989 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL,
1990 &pipeline_layout);
1991 ASSERT_VK_SUCCESS(err);
1992 BeginCommandBuffer();
1993 vkCmdPushConstants(m_commandBuffer->GetBufferHandle(), pipeline_layout,
1994 VK_SHADER_STAGE_VERTEX_BIT, 0, 0xFFFFFFFFu, NULL);
1995 if (!m_errorMonitor->DesiredMsgFound()) {
1996 FAIL() << "Error received was not 'vkCmdPushConstants() call has push "
1997 "constants with offset 0...'";
1998 m_errorMonitor->DumpFailureMsgs();
1999 }
2000 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
2001 }
2002
TEST_F(VkLayerTest,DescriptorSetCompatibility)2003 TEST_F(VkLayerTest, DescriptorSetCompatibility) {
2004 // Test various desriptorSet errors with bad binding combinations
2005 VkResult err;
2006
2007 ASSERT_NO_FATAL_FAILURE(InitState());
2008 ASSERT_NO_FATAL_FAILURE(InitViewport());
2009 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
2010
2011 static const uint32_t NUM_DESCRIPTOR_TYPES = 5;
2012 VkDescriptorPoolSize ds_type_count[NUM_DESCRIPTOR_TYPES] = {};
2013 ds_type_count[0].type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
2014 ds_type_count[0].descriptorCount = 10;
2015 ds_type_count[1].type = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
2016 ds_type_count[1].descriptorCount = 2;
2017 ds_type_count[2].type = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE;
2018 ds_type_count[2].descriptorCount = 2;
2019 ds_type_count[3].type = VK_DESCRIPTOR_TYPE_SAMPLER;
2020 ds_type_count[3].descriptorCount = 5;
2021 // TODO : LunarG ILO driver currently asserts in desc.c w/ INPUT_ATTACHMENT
2022 // type
2023 // ds_type_count[4].type = VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT;
2024 ds_type_count[4].type = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
2025 ds_type_count[4].descriptorCount = 2;
2026
2027 VkDescriptorPoolCreateInfo ds_pool_ci = {};
2028 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
2029 ds_pool_ci.pNext = NULL;
2030 ds_pool_ci.maxSets = 5;
2031 ds_pool_ci.poolSizeCount = NUM_DESCRIPTOR_TYPES;
2032 ds_pool_ci.pPoolSizes = ds_type_count;
2033
2034 VkDescriptorPool ds_pool;
2035 err =
2036 vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
2037 ASSERT_VK_SUCCESS(err);
2038
2039 static const uint32_t MAX_DS_TYPES_IN_LAYOUT = 2;
2040 VkDescriptorSetLayoutBinding dsl_binding[MAX_DS_TYPES_IN_LAYOUT] = {};
2041 dsl_binding[0].binding = 0;
2042 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
2043 dsl_binding[0].descriptorCount = 5;
2044 dsl_binding[0].stageFlags = VK_SHADER_STAGE_ALL;
2045 dsl_binding[0].pImmutableSamplers = NULL;
2046
2047 // Create layout identical to set0 layout but w/ different stageFlags
2048 VkDescriptorSetLayoutBinding dsl_fs_stage_only = {};
2049 dsl_fs_stage_only.binding = 0;
2050 dsl_fs_stage_only.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
2051 dsl_fs_stage_only.descriptorCount = 5;
2052 dsl_fs_stage_only.stageFlags =
2053 VK_SHADER_STAGE_FRAGMENT_BIT; // Different stageFlags to cause error at
2054 // bind time
2055 dsl_fs_stage_only.pImmutableSamplers = NULL;
2056 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
2057 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
2058 ds_layout_ci.pNext = NULL;
2059 ds_layout_ci.bindingCount = 1;
2060 ds_layout_ci.pBindings = dsl_binding;
2061 static const uint32_t NUM_LAYOUTS = 4;
2062 VkDescriptorSetLayout ds_layout[NUM_LAYOUTS] = {};
2063 VkDescriptorSetLayout ds_layout_fs_only = {};
2064 // Create 4 unique layouts for full pipelineLayout, and 1 special fs-only
2065 // layout for error case
2066 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
2067 &ds_layout[0]);
2068 ASSERT_VK_SUCCESS(err);
2069 ds_layout_ci.pBindings = &dsl_fs_stage_only;
2070 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
2071 &ds_layout_fs_only);
2072 ASSERT_VK_SUCCESS(err);
2073 dsl_binding[0].binding = 0;
2074 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
2075 dsl_binding[0].descriptorCount = 2;
2076 dsl_binding[1].binding = 1;
2077 dsl_binding[1].descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE;
2078 dsl_binding[1].descriptorCount = 2;
2079 dsl_binding[1].stageFlags = VK_SHADER_STAGE_ALL;
2080 dsl_binding[1].pImmutableSamplers = NULL;
2081 ds_layout_ci.pBindings = dsl_binding;
2082 ds_layout_ci.bindingCount = 2;
2083 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
2084 &ds_layout[1]);
2085 ASSERT_VK_SUCCESS(err);
2086 dsl_binding[0].binding = 0;
2087 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
2088 dsl_binding[0].descriptorCount = 5;
2089 ds_layout_ci.bindingCount = 1;
2090 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
2091 &ds_layout[2]);
2092 ASSERT_VK_SUCCESS(err);
2093 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
2094 dsl_binding[0].descriptorCount = 2;
2095 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
2096 &ds_layout[3]);
2097 ASSERT_VK_SUCCESS(err);
2098
2099 static const uint32_t NUM_SETS = 4;
2100 VkDescriptorSet descriptorSet[NUM_SETS] = {};
2101 VkDescriptorSetAllocateInfo alloc_info = {};
2102 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
2103 alloc_info.descriptorSetCount = NUM_LAYOUTS;
2104 alloc_info.descriptorPool = ds_pool;
2105 alloc_info.pSetLayouts = ds_layout;
2106 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info,
2107 descriptorSet);
2108 ASSERT_VK_SUCCESS(err);
2109 VkDescriptorSet ds0_fs_only = {};
2110 alloc_info.descriptorSetCount = 1;
2111 alloc_info.pSetLayouts = &ds_layout_fs_only;
2112 err =
2113 vkAllocateDescriptorSets(m_device->device(), &alloc_info, &ds0_fs_only);
2114 ASSERT_VK_SUCCESS(err);
2115
2116 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
2117 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
2118 pipeline_layout_ci.pNext = NULL;
2119 pipeline_layout_ci.setLayoutCount = NUM_LAYOUTS;
2120 pipeline_layout_ci.pSetLayouts = ds_layout;
2121
2122 VkPipelineLayout pipeline_layout;
2123 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL,
2124 &pipeline_layout);
2125 ASSERT_VK_SUCCESS(err);
2126 // Create pipelineLayout with only one setLayout
2127 pipeline_layout_ci.setLayoutCount = 1;
2128 VkPipelineLayout single_pipe_layout;
2129 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL,
2130 &single_pipe_layout);
2131 ASSERT_VK_SUCCESS(err);
2132 // Create pipelineLayout with 2 descriptor setLayout at index 0
2133 pipeline_layout_ci.pSetLayouts = &ds_layout[3];
2134 VkPipelineLayout pipe_layout_one_desc;
2135 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL,
2136 &pipe_layout_one_desc);
2137 ASSERT_VK_SUCCESS(err);
2138 // Create pipelineLayout with 5 SAMPLER descriptor setLayout at index 0
2139 pipeline_layout_ci.pSetLayouts = &ds_layout[2];
2140 VkPipelineLayout pipe_layout_five_samp;
2141 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL,
2142 &pipe_layout_five_samp);
2143 ASSERT_VK_SUCCESS(err);
2144 // Create pipelineLayout with UB type, but stageFlags for FS only
2145 pipeline_layout_ci.pSetLayouts = &ds_layout_fs_only;
2146 VkPipelineLayout pipe_layout_fs_only;
2147 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL,
2148 &pipe_layout_fs_only);
2149 ASSERT_VK_SUCCESS(err);
2150 // Create pipelineLayout w/ incompatible set0 layout, but set1 is fine
2151 VkDescriptorSetLayout pl_bad_s0[2] = {};
2152 pl_bad_s0[0] = ds_layout_fs_only;
2153 pl_bad_s0[1] = ds_layout[1];
2154 pipeline_layout_ci.setLayoutCount = 2;
2155 pipeline_layout_ci.pSetLayouts = pl_bad_s0;
2156 VkPipelineLayout pipe_layout_bad_set0;
2157 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL,
2158 &pipe_layout_bad_set0);
2159 ASSERT_VK_SUCCESS(err);
2160
2161 // Create a buffer to update the descriptor with
2162 uint32_t qfi = 0;
2163 VkBufferCreateInfo buffCI = {};
2164 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
2165 buffCI.size = 1024;
2166 buffCI.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
2167 buffCI.queueFamilyIndexCount = 1;
2168 buffCI.pQueueFamilyIndices = &qfi;
2169
2170 VkBuffer dyub;
2171 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &dyub);
2172 ASSERT_VK_SUCCESS(err);
2173 // Correctly update descriptor to avoid "NOT_UPDATED" error
2174 static const uint32_t NUM_BUFFS = 5;
2175 VkDescriptorBufferInfo buffInfo[NUM_BUFFS] = {};
2176 for (uint32_t i = 0; i < NUM_BUFFS; ++i) {
2177 buffInfo[i].buffer = dyub;
2178 buffInfo[i].offset = 0;
2179 buffInfo[i].range = 1024;
2180 }
2181 VkImage image;
2182 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
2183 const int32_t tex_width = 32;
2184 const int32_t tex_height = 32;
2185 VkImageCreateInfo image_create_info = {};
2186 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
2187 image_create_info.pNext = NULL;
2188 image_create_info.imageType = VK_IMAGE_TYPE_2D;
2189 image_create_info.format = tex_format;
2190 image_create_info.extent.width = tex_width;
2191 image_create_info.extent.height = tex_height;
2192 image_create_info.extent.depth = 1;
2193 image_create_info.mipLevels = 1;
2194 image_create_info.arrayLayers = 1;
2195 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
2196 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
2197 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
2198 image_create_info.flags = 0;
2199 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
2200 ASSERT_VK_SUCCESS(err);
2201
2202 VkMemoryRequirements memReqs;
2203 VkDeviceMemory imageMem;
2204 bool pass;
2205 VkMemoryAllocateInfo memAlloc = {};
2206 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
2207 memAlloc.pNext = NULL;
2208 memAlloc.allocationSize = 0;
2209 memAlloc.memoryTypeIndex = 0;
2210 vkGetImageMemoryRequirements(m_device->device(), image, &memReqs);
2211 memAlloc.allocationSize = memReqs.size;
2212 pass =
2213 m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
2214 ASSERT_TRUE(pass);
2215 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &imageMem);
2216 ASSERT_VK_SUCCESS(err);
2217 err = vkBindImageMemory(m_device->device(), image, imageMem, 0);
2218 ASSERT_VK_SUCCESS(err);
2219
2220 VkImageViewCreateInfo image_view_create_info = {};
2221 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
2222 image_view_create_info.image = image;
2223 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
2224 image_view_create_info.format = tex_format;
2225 image_view_create_info.subresourceRange.layerCount = 1;
2226 image_view_create_info.subresourceRange.baseMipLevel = 0;
2227 image_view_create_info.subresourceRange.levelCount = 1;
2228 image_view_create_info.subresourceRange.aspectMask =
2229 VK_IMAGE_ASPECT_COLOR_BIT;
2230
2231 VkImageView view;
2232 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL,
2233 &view);
2234 ASSERT_VK_SUCCESS(err);
2235 VkDescriptorImageInfo imageInfo[4] = {};
2236 imageInfo[0].imageView = view;
2237 imageInfo[0].imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
2238 imageInfo[1].imageView = view;
2239 imageInfo[1].imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
2240 imageInfo[2].imageView = view;
2241 imageInfo[2].imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
2242 imageInfo[3].imageView = view;
2243 imageInfo[3].imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
2244
2245 static const uint32_t NUM_SET_UPDATES = 3;
2246 VkWriteDescriptorSet descriptor_write[NUM_SET_UPDATES] = {};
2247 descriptor_write[0].sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
2248 descriptor_write[0].dstSet = descriptorSet[0];
2249 descriptor_write[0].dstBinding = 0;
2250 descriptor_write[0].descriptorCount = 5;
2251 descriptor_write[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
2252 descriptor_write[0].pBufferInfo = buffInfo;
2253 descriptor_write[1].sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
2254 descriptor_write[1].dstSet = descriptorSet[1];
2255 descriptor_write[1].dstBinding = 0;
2256 descriptor_write[1].descriptorCount = 2;
2257 descriptor_write[1].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
2258 descriptor_write[1].pImageInfo = imageInfo;
2259 descriptor_write[2].sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
2260 descriptor_write[2].dstSet = descriptorSet[1];
2261 descriptor_write[2].dstBinding = 1;
2262 descriptor_write[2].descriptorCount = 2;
2263 descriptor_write[2].descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE;
2264 descriptor_write[2].pImageInfo = &imageInfo[2];
2265
2266 vkUpdateDescriptorSets(m_device->device(), 3, descriptor_write, 0, NULL);
2267
2268 // Create PSO to be used for draw-time errors below
2269 char const *vsSource =
2270 "#version 400\n"
2271 "#extension GL_ARB_separate_shader_objects: require\n"
2272 "#extension GL_ARB_shading_language_420pack: require\n"
2273 "\n"
2274 "out gl_PerVertex {\n"
2275 " vec4 gl_Position;\n"
2276 "};\n"
2277 "void main(){\n"
2278 " gl_Position = vec4(1);\n"
2279 "}\n";
2280 char const *fsSource =
2281 "#version 400\n"
2282 "#extension GL_ARB_separate_shader_objects: require\n"
2283 "#extension GL_ARB_shading_language_420pack: require\n"
2284 "\n"
2285 "layout(location=0) out vec4 x;\n"
2286 "layout(set=0) layout(binding=0) uniform foo { int x; int y; } bar;\n"
2287 "void main(){\n"
2288 " x = vec4(bar.y);\n"
2289 "}\n";
2290 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
2291 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
2292 VkPipelineObj pipe(m_device);
2293 pipe.AddShader(&vs);
2294 pipe.AddShader(&fs);
2295 pipe.AddColorAttachment();
2296 pipe.CreateVKPipeline(pipe_layout_fs_only, renderPass());
2297
2298 BeginCommandBuffer();
2299
2300 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(),
2301 VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
2302 // NOTE : I believe LunarG ilo driver has bug (LX#189) that requires binding
2303 // of PSO
2304 // here before binding DSs. Otherwise we assert in cmd_copy_dset_data() of
2305 // cmd_pipeline.c
2306 // due to the fact that cmd_alloc_dset_data() has not been called in
2307 // cmd_bind_graphics_pipeline()
2308 // TODO : Want to cause various binding incompatibility issues here to test
2309 // DrawState
2310 // First cause various verify_layout_compatibility() fails
2311 // Second disturb early and late sets and verify INFO msgs
2312 // verify_set_layout_compatibility fail cases:
2313 // 1. invalid VkPipelineLayout (layout) passed into vkCmdBindDescriptorSets
2314 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
2315 " due to: invalid VkPipelineLayout ");
2316 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(),
2317 VK_PIPELINE_BIND_POINT_GRAPHICS,
2318 (VkPipelineLayout)((size_t)0xbaadb1be), 0, 1,
2319 &descriptorSet[0], 0, NULL);
2320 if (!m_errorMonitor->DesiredMsgFound()) {
2321 FAIL() << "Did not receive correct error msg when attempting to bind "
2322 "descriptorSets with invalid VkPipelineLayout.";
2323 m_errorMonitor->DumpFailureMsgs();
2324 }
2325 // 2. layoutIndex exceeds # of layouts in layout
2326 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
2327 " attempting to bind set to index 1");
2328 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(),
2329 VK_PIPELINE_BIND_POINT_GRAPHICS, single_pipe_layout,
2330 0, 2, &descriptorSet[0], 0, NULL);
2331 if (!m_errorMonitor->DesiredMsgFound()) {
2332 FAIL() << "Did not receive correct error msg when attempting to bind "
2333 "descriptorSet to index 1 when pipelineLayout only has index "
2334 "0.";
2335 m_errorMonitor->DumpFailureMsgs();
2336 }
2337 vkDestroyPipelineLayout(m_device->device(), single_pipe_layout, NULL);
2338 // 3. Pipeline setLayout[0] has 2 descriptors, but set being bound has 5
2339 // descriptors
2340 m_errorMonitor->SetDesiredFailureMsg(
2341 VK_DEBUG_REPORT_ERROR_BIT_EXT,
2342 ", but corresponding set being bound has 5 descriptors.");
2343 vkCmdBindDescriptorSets(
2344 m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS,
2345 pipe_layout_one_desc, 0, 1, &descriptorSet[0], 0, NULL);
2346 if (!m_errorMonitor->DesiredMsgFound()) {
2347 FAIL() << "Did not receive correct error msg when attempting to bind "
2348 "descriptorSet w/ 5 descriptors to pipelineLayout with only "
2349 "2 descriptors.";
2350 m_errorMonitor->DumpFailureMsgs();
2351 }
2352 vkDestroyPipelineLayout(m_device->device(), pipe_layout_one_desc, NULL);
2353 // 4. same # of descriptors but mismatch in type
2354 m_errorMonitor->SetDesiredFailureMsg(
2355 VK_DEBUG_REPORT_ERROR_BIT_EXT,
2356 " descriptor from pipelineLayout is type 'VK_DESCRIPTOR_TYPE_SAMPLER'");
2357 vkCmdBindDescriptorSets(
2358 m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS,
2359 pipe_layout_five_samp, 0, 1, &descriptorSet[0], 0, NULL);
2360 if (!m_errorMonitor->DesiredMsgFound()) {
2361 FAIL() << "Did not receive correct error msg when attempting to bind "
2362 "UNIFORM_BUFFER descriptorSet to pipelineLayout with "
2363 "overlapping SAMPLER type.";
2364 m_errorMonitor->DumpFailureMsgs();
2365 }
2366 vkDestroyPipelineLayout(m_device->device(), pipe_layout_five_samp, NULL);
2367 // 5. same # of descriptors but mismatch in stageFlags
2368 m_errorMonitor->SetDesiredFailureMsg(
2369 VK_DEBUG_REPORT_ERROR_BIT_EXT,
2370 " descriptor from pipelineLayout has stageFlags ");
2371 vkCmdBindDescriptorSets(
2372 m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS,
2373 pipe_layout_fs_only, 0, 1, &descriptorSet[0], 0, NULL);
2374 if (!m_errorMonitor->DesiredMsgFound()) {
2375 FAIL() << "Did not receive correct error msg when attempting to bind "
2376 "UNIFORM_BUFFER descriptorSet with ALL stageFlags to "
2377 "pipelineLayout with FS-only stageFlags.";
2378 m_errorMonitor->DumpFailureMsgs();
2379 }
2380 // Cause INFO messages due to disturbing previously bound Sets
2381 // First bind sets 0 & 1
2382 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(),
2383 VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0,
2384 2, &descriptorSet[0], 0, NULL);
2385 // 1. Disturb bound set0 by re-binding set1 w/ updated pipelineLayout
2386 m_errorMonitor->SetDesiredFailureMsg(
2387 VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
2388 " previously bound as set #0 was disturbed ");
2389 vkCmdBindDescriptorSets(
2390 m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS,
2391 pipe_layout_bad_set0, 1, 1, &descriptorSet[1], 0, NULL);
2392 if (!m_errorMonitor->DesiredMsgFound()) {
2393 FAIL() << "Did not receive correct info msg when binding Set1 w/ "
2394 "pipelineLayout that should disturb Set0.";
2395 m_errorMonitor->DumpFailureMsgs();
2396 }
2397 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(),
2398 VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0,
2399 2, &descriptorSet[0], 0, NULL);
2400 // 2. Disturb set after last bound set
2401 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
2402 " newly bound as set #0 so set #1 and "
2403 "any subsequent sets were disturbed ");
2404 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(),
2405 VK_PIPELINE_BIND_POINT_GRAPHICS,
2406 pipe_layout_fs_only, 0, 1, &ds0_fs_only, 0, NULL);
2407 if (!m_errorMonitor->DesiredMsgFound()) {
2408 FAIL() << "Did not receive correct info msg when re-binding Set0 w/ "
2409 "pipelineLayout that should disturb Set1.";
2410 m_errorMonitor->DumpFailureMsgs();
2411 }
2412 // Cause draw-time errors due to PSO incompatibilities
2413 // 1. Error due to not binding required set (we actually use same code as
2414 // above to disturb set0)
2415 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(),
2416 VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0,
2417 2, &descriptorSet[0], 0, NULL);
2418 vkCmdBindDescriptorSets(
2419 m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS,
2420 pipe_layout_bad_set0, 1, 1, &descriptorSet[1], 0, NULL);
2421 m_errorMonitor->SetDesiredFailureMsg(
2422 VK_DEBUG_REPORT_ERROR_BIT_EXT,
2423 " uses set #0 but that set is not bound.");
2424 Draw(1, 0, 0, 0);
2425 if (!m_errorMonitor->DesiredMsgFound()) {
2426 FAIL() << "Did not receive correct error msg when attempting draw "
2427 "requiring Set0 but Set0 is not bound.";
2428 m_errorMonitor->DumpFailureMsgs();
2429 }
2430 vkDestroyPipelineLayout(m_device->device(), pipe_layout_bad_set0, NULL);
2431 // 2. Error due to bound set not being compatible with PSO's
2432 // VkPipelineLayout (diff stageFlags in this case)
2433 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(),
2434 VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0,
2435 2, &descriptorSet[0], 0, NULL);
2436 m_errorMonitor->SetDesiredFailureMsg(
2437 VK_DEBUG_REPORT_ERROR_BIT_EXT,
2438 " bound as set #0 is not compatible with ");
2439 Draw(1, 0, 0, 0);
2440 if (!m_errorMonitor->DesiredMsgFound()) {
2441 FAIL() << "Did not receive correct error msg when attempted draw where "
2442 "bound Set0 layout is not compatible PSO Set0 layout.";
2443 m_errorMonitor->DumpFailureMsgs();
2444 }
2445 // Remaining clean-up
2446 vkDestroyPipelineLayout(m_device->device(), pipe_layout_fs_only, NULL);
2447 for (uint32_t i = 0; i < NUM_LAYOUTS; ++i) {
2448 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout[i], NULL);
2449 }
2450 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout_fs_only, NULL);
2451 vkFreeDescriptorSets(m_device->device(), ds_pool, 1, descriptorSet);
2452 vkDestroyBuffer(m_device->device(), dyub, NULL);
2453 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
2454 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
2455 }
2456
TEST_F(VkLayerTest,NoBeginCommandBuffer)2457 TEST_F(VkLayerTest, NoBeginCommandBuffer) {
2458
2459 m_errorMonitor->SetDesiredFailureMsg(
2460 VK_DEBUG_REPORT_ERROR_BIT_EXT,
2461 "You must call vkBeginCommandBuffer() before this call to ");
2462
2463 ASSERT_NO_FATAL_FAILURE(InitState());
2464 VkCommandBufferObj commandBuffer(m_device, m_commandPool);
2465 // Call EndCommandBuffer() w/o calling BeginCommandBuffer()
2466 vkEndCommandBuffer(commandBuffer.GetBufferHandle());
2467
2468 if (!m_errorMonitor->DesiredMsgFound()) {
2469 FAIL() << "Did not recieve Error 'You must call vkBeginCommandBuffer() "
2470 "before this call to vkEndCommandBuffer()'";
2471 m_errorMonitor->DumpFailureMsgs();
2472 }
2473 }
2474
TEST_F(VkLayerTest,SecondaryCommandBufferNullRenderpass)2475 TEST_F(VkLayerTest, SecondaryCommandBufferNullRenderpass) {
2476 VkResult err;
2477 VkCommandBuffer draw_cmd;
2478
2479 m_errorMonitor->SetDesiredFailureMsg(
2480 VK_DEBUG_REPORT_ERROR_BIT_EXT,
2481 " must specify a valid renderpass parameter.");
2482
2483 ASSERT_NO_FATAL_FAILURE(InitState());
2484
2485 VkCommandBufferAllocateInfo cmd = {};
2486 cmd.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
2487 cmd.pNext = NULL;
2488 cmd.commandPool = m_commandPool;
2489 cmd.level = VK_COMMAND_BUFFER_LEVEL_SECONDARY;
2490 cmd.commandBufferCount = 1;
2491
2492 err = vkAllocateCommandBuffers(m_device->device(), &cmd, &draw_cmd);
2493 ASSERT_VK_SUCCESS(err);
2494
2495 // Force the failure by not setting the Renderpass and Framebuffer fields
2496 VkCommandBufferBeginInfo cmd_buf_info = {};
2497 VkCommandBufferInheritanceInfo cmd_buf_hinfo = {};
2498 cmd_buf_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
2499 cmd_buf_info.pNext = NULL;
2500 cmd_buf_info.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT |
2501 VK_COMMAND_BUFFER_USAGE_RENDER_PASS_CONTINUE_BIT;
2502 cmd_buf_info.pInheritanceInfo = &cmd_buf_hinfo;
2503
2504 // The error should be caught by validation of the BeginCommandBuffer call
2505 vkBeginCommandBuffer(draw_cmd, &cmd_buf_info);
2506
2507 if (!m_errorMonitor->DesiredMsgFound()) {
2508 FAIL() << "Did not receive Error 'vkBeginCommandBuffer(): Secondary "
2509 "Command Buffers (0x<ADDR>) must specify a valid renderpass "
2510 "parameter.'";
2511 m_errorMonitor->DumpFailureMsgs();
2512 }
2513 vkFreeCommandBuffers(m_device->device(), m_commandPool, 1, &draw_cmd);
2514 }
2515
TEST_F(VkLayerTest,CommandBufferResetErrors)2516 TEST_F(VkLayerTest, CommandBufferResetErrors) {
2517 // Cause error due to Begin while recording CB
2518 // Then cause 2 errors for attempting to reset CB w/o having
2519 // VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT set for the pool from
2520 // which CBs were allocated. Note that this bit is off by default.
2521 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
2522 "Cannot call Begin on CB");
2523
2524 ASSERT_NO_FATAL_FAILURE(InitState());
2525
2526 // Calls AllocateCommandBuffers
2527 VkCommandBufferObj commandBuffer(m_device, m_commandPool);
2528
2529 // Force the failure by setting the Renderpass and Framebuffer fields with
2530 // (fake) data
2531 VkCommandBufferBeginInfo cmd_buf_info = {};
2532 VkCommandBufferInheritanceInfo cmd_buf_hinfo = {};
2533 cmd_buf_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
2534 cmd_buf_info.pNext = NULL;
2535 cmd_buf_info.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT;
2536 cmd_buf_info.pInheritanceInfo = &cmd_buf_hinfo;
2537
2538 // Begin CB to transition to recording state
2539 vkBeginCommandBuffer(commandBuffer.GetBufferHandle(), &cmd_buf_info);
2540 // Can't re-begin. This should trigger error
2541 vkBeginCommandBuffer(commandBuffer.GetBufferHandle(), &cmd_buf_info);
2542 if (!m_errorMonitor->DesiredMsgFound()) {
2543 FAIL() << "Did not receive Error 'Cannot call Begin on CB (0x<ADDR>) "
2544 "in the RECORDING state...'";
2545 m_errorMonitor->DumpFailureMsgs();
2546 }
2547 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
2548 "Attempt to reset command buffer ");
2549 VkCommandBufferResetFlags flags = 0; // Don't care about flags for this test
2550 // Reset attempt will trigger error due to incorrect CommandPool state
2551 vkResetCommandBuffer(commandBuffer.GetBufferHandle(), flags);
2552 if (!m_errorMonitor->DesiredMsgFound()) {
2553 FAIL() << "Did not receive Error 'Attempt to reset command buffer "
2554 "(0x<ADDR>) created from command pool...'";
2555 m_errorMonitor->DumpFailureMsgs();
2556 }
2557 m_errorMonitor->SetDesiredFailureMsg(
2558 VK_DEBUG_REPORT_ERROR_BIT_EXT,
2559 " attempts to implicitly reset cmdBuffer created from ");
2560 // Transition CB to RECORDED state
2561 vkEndCommandBuffer(commandBuffer.GetBufferHandle());
2562 // Now attempting to Begin will implicitly reset, which triggers error
2563 vkBeginCommandBuffer(commandBuffer.GetBufferHandle(), &cmd_buf_info);
2564 if (!m_errorMonitor->DesiredMsgFound()) {
2565 FAIL() << "Did not receive Error 'Call to vkBeginCommandBuffer() on "
2566 "command buffer (0x<ADDR>) attempts to implicitly reset...'";
2567 m_errorMonitor->DumpFailureMsgs();
2568 }
2569 }
2570
TEST_F(VkLayerTest,InvalidPipelineCreateState)2571 TEST_F(VkLayerTest, InvalidPipelineCreateState) {
2572 // Attempt to Create Gfx Pipeline w/o a VS
2573 VkResult err;
2574
2575 m_errorMonitor->SetDesiredFailureMsg(
2576 VK_DEBUG_REPORT_ERROR_BIT_EXT,
2577 "Invalid Pipeline CreateInfo State: Vtx Shader required");
2578
2579 ASSERT_NO_FATAL_FAILURE(InitState());
2580 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
2581
2582 VkDescriptorPoolSize ds_type_count = {};
2583 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
2584 ds_type_count.descriptorCount = 1;
2585
2586 VkDescriptorPoolCreateInfo ds_pool_ci = {};
2587 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
2588 ds_pool_ci.pNext = NULL;
2589 ds_pool_ci.maxSets = 1;
2590 ds_pool_ci.poolSizeCount = 1;
2591 ds_pool_ci.pPoolSizes = &ds_type_count;
2592
2593 VkDescriptorPool ds_pool;
2594 err =
2595 vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
2596 ASSERT_VK_SUCCESS(err);
2597
2598 VkDescriptorSetLayoutBinding dsl_binding = {};
2599 dsl_binding.binding = 0;
2600 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
2601 dsl_binding.descriptorCount = 1;
2602 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
2603 dsl_binding.pImmutableSamplers = NULL;
2604
2605 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
2606 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
2607 ds_layout_ci.pNext = NULL;
2608 ds_layout_ci.bindingCount = 1;
2609 ds_layout_ci.pBindings = &dsl_binding;
2610
2611 VkDescriptorSetLayout ds_layout;
2612 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
2613 &ds_layout);
2614 ASSERT_VK_SUCCESS(err);
2615
2616 VkDescriptorSet descriptorSet;
2617 VkDescriptorSetAllocateInfo alloc_info = {};
2618 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
2619 alloc_info.descriptorSetCount = 1;
2620 alloc_info.descriptorPool = ds_pool;
2621 alloc_info.pSetLayouts = &ds_layout;
2622 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info,
2623 &descriptorSet);
2624 ASSERT_VK_SUCCESS(err);
2625
2626 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
2627 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
2628 pipeline_layout_ci.setLayoutCount = 1;
2629 pipeline_layout_ci.pSetLayouts = &ds_layout;
2630
2631 VkPipelineLayout pipeline_layout;
2632 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL,
2633 &pipeline_layout);
2634 ASSERT_VK_SUCCESS(err);
2635
2636 VkViewport vp = {}; // Just need dummy vp to point to
2637 VkRect2D sc = {}; // dummy scissor to point to
2638
2639 VkPipelineViewportStateCreateInfo vp_state_ci = {};
2640 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
2641 vp_state_ci.scissorCount = 1;
2642 vp_state_ci.pScissors = ≻
2643 vp_state_ci.viewportCount = 1;
2644 vp_state_ci.pViewports = &vp;
2645
2646 VkPipelineRasterizationStateCreateInfo rs_state_ci = {};
2647 rs_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
2648 rs_state_ci.polygonMode = VK_POLYGON_MODE_FILL;
2649 rs_state_ci.cullMode = VK_CULL_MODE_BACK_BIT;
2650 rs_state_ci.frontFace = VK_FRONT_FACE_COUNTER_CLOCKWISE;
2651 rs_state_ci.depthClampEnable = VK_FALSE;
2652 rs_state_ci.rasterizerDiscardEnable = VK_FALSE;
2653 rs_state_ci.depthBiasEnable = VK_FALSE;
2654
2655 VkGraphicsPipelineCreateInfo gp_ci = {};
2656 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
2657 gp_ci.pViewportState = &vp_state_ci;
2658 gp_ci.pRasterizationState = &rs_state_ci;
2659 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
2660 gp_ci.layout = pipeline_layout;
2661 gp_ci.renderPass = renderPass();
2662
2663 VkPipelineCacheCreateInfo pc_ci = {};
2664 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
2665 pc_ci.initialDataSize = 0;
2666 pc_ci.pInitialData = 0;
2667
2668 VkPipeline pipeline;
2669 VkPipelineCache pipelineCache;
2670
2671 err =
2672 vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
2673 ASSERT_VK_SUCCESS(err);
2674 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1,
2675 &gp_ci, NULL, &pipeline);
2676
2677 if (!m_errorMonitor->DesiredMsgFound()) {
2678 FAIL() << "Did not receive Error 'Invalid Pipeline CreateInfo State: "
2679 "Vtx Shader required'";
2680 m_errorMonitor->DumpFailureMsgs();
2681 }
2682
2683 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
2684 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
2685 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
2686 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
2687 }
2688 /*// TODO : This test should be good, but needs Tess support in compiler to run
2689 TEST_F(VkLayerTest, InvalidPatchControlPoints)
2690 {
2691 // Attempt to Create Gfx Pipeline w/o a VS
2692 VkResult err;
2693
2694 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
2695 "Invalid Pipeline CreateInfo State: VK_PRIMITIVE_TOPOLOGY_PATCH
2696 primitive ");
2697
2698 ASSERT_NO_FATAL_FAILURE(InitState());
2699 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
2700
2701 VkDescriptorPoolSize ds_type_count = {};
2702 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
2703 ds_type_count.descriptorCount = 1;
2704
2705 VkDescriptorPoolCreateInfo ds_pool_ci = {};
2706 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
2707 ds_pool_ci.pNext = NULL;
2708 ds_pool_ci.poolSizeCount = 1;
2709 ds_pool_ci.pPoolSizes = &ds_type_count;
2710
2711 VkDescriptorPool ds_pool;
2712 err = vkCreateDescriptorPool(m_device->device(),
2713 VK_DESCRIPTOR_POOL_USAGE_NON_FREE, 1, &ds_pool_ci, NULL, &ds_pool);
2714 ASSERT_VK_SUCCESS(err);
2715
2716 VkDescriptorSetLayoutBinding dsl_binding = {};
2717 dsl_binding.binding = 0;
2718 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
2719 dsl_binding.descriptorCount = 1;
2720 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
2721 dsl_binding.pImmutableSamplers = NULL;
2722
2723 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
2724 ds_layout_ci.sType =
2725 VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
2726 ds_layout_ci.pNext = NULL;
2727 ds_layout_ci.bindingCount = 1;
2728 ds_layout_ci.pBindings = &dsl_binding;
2729
2730 VkDescriptorSetLayout ds_layout;
2731 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
2732 &ds_layout);
2733 ASSERT_VK_SUCCESS(err);
2734
2735 VkDescriptorSet descriptorSet;
2736 err = vkAllocateDescriptorSets(m_device->device(), ds_pool,
2737 VK_DESCRIPTOR_SET_USAGE_NON_FREE, 1, &ds_layout, &descriptorSet);
2738 ASSERT_VK_SUCCESS(err);
2739
2740 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
2741 pipeline_layout_ci.sType =
2742 VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
2743 pipeline_layout_ci.pNext = NULL;
2744 pipeline_layout_ci.setLayoutCount = 1;
2745 pipeline_layout_ci.pSetLayouts = &ds_layout;
2746
2747 VkPipelineLayout pipeline_layout;
2748 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL,
2749 &pipeline_layout);
2750 ASSERT_VK_SUCCESS(err);
2751
2752 VkPipelineShaderStageCreateInfo shaderStages[3];
2753 memset(&shaderStages, 0, 3 * sizeof(VkPipelineShaderStageCreateInfo));
2754
2755 VkShaderObj vs(m_device,bindStateVertShaderText,VK_SHADER_STAGE_VERTEX_BIT,
2756 this);
2757 // Just using VS txt for Tess shaders as we don't care about functionality
2758 VkShaderObj
2759 tc(m_device,bindStateVertShaderText,VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT,
2760 this);
2761 VkShaderObj
2762 te(m_device,bindStateVertShaderText,VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT,
2763 this);
2764
2765 shaderStages[0].sType =
2766 VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
2767 shaderStages[0].stage = VK_SHADER_STAGE_VERTEX_BIT;
2768 shaderStages[0].shader = vs.handle();
2769 shaderStages[1].sType =
2770 VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
2771 shaderStages[1].stage = VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT;
2772 shaderStages[1].shader = tc.handle();
2773 shaderStages[2].sType =
2774 VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
2775 shaderStages[2].stage = VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT;
2776 shaderStages[2].shader = te.handle();
2777
2778 VkPipelineInputAssemblyStateCreateInfo iaCI = {};
2779 iaCI.sType =
2780 VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
2781 iaCI.topology = VK_PRIMITIVE_TOPOLOGY_PATCH_LIST;
2782
2783 VkPipelineTessellationStateCreateInfo tsCI = {};
2784 tsCI.sType = VK_STRUCTURE_TYPE_PIPELINE_TESSELLATION_STATE_CREATE_INFO;
2785 tsCI.patchControlPoints = 0; // This will cause an error
2786
2787 VkGraphicsPipelineCreateInfo gp_ci = {};
2788 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
2789 gp_ci.pNext = NULL;
2790 gp_ci.stageCount = 3;
2791 gp_ci.pStages = shaderStages;
2792 gp_ci.pVertexInputState = NULL;
2793 gp_ci.pInputAssemblyState = &iaCI;
2794 gp_ci.pTessellationState = &tsCI;
2795 gp_ci.pViewportState = NULL;
2796 gp_ci.pRasterizationState = NULL;
2797 gp_ci.pMultisampleState = NULL;
2798 gp_ci.pDepthStencilState = NULL;
2799 gp_ci.pColorBlendState = NULL;
2800 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
2801 gp_ci.layout = pipeline_layout;
2802 gp_ci.renderPass = renderPass();
2803
2804 VkPipelineCacheCreateInfo pc_ci = {};
2805 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
2806 pc_ci.pNext = NULL;
2807 pc_ci.initialSize = 0;
2808 pc_ci.initialData = 0;
2809 pc_ci.maxSize = 0;
2810
2811 VkPipeline pipeline;
2812 VkPipelineCache pipelineCache;
2813
2814 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL,
2815 &pipelineCache);
2816 ASSERT_VK_SUCCESS(err);
2817 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1,
2818 &gp_ci, NULL, &pipeline);
2819
2820 if (!m_errorMonitor->DesiredMsgFound()) {
2821 FAIL() << "Did not receive Error 'Invalid Pipeline CreateInfo State:
2822 VK_PRIMITIVE_TOPOLOGY_PATCH primitive...'";
2823 m_errorMonitor->DumpFailureMsgs();
2824 }
2825
2826 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
2827 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
2828 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
2829 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
2830 }
2831 */
2832 // Set scissor and viewport counts to different numbers
TEST_F(VkLayerTest,PSOViewportScissorCountMismatch)2833 TEST_F(VkLayerTest, PSOViewportScissorCountMismatch) {
2834 // Attempt to Create Gfx Pipeline w/o a VS
2835 VkResult err;
2836
2837 m_errorMonitor->SetDesiredFailureMsg(
2838 VK_DEBUG_REPORT_ERROR_BIT_EXT,
2839 "Gfx Pipeline viewport count (1) must match scissor count (0).");
2840
2841 ASSERT_NO_FATAL_FAILURE(InitState());
2842 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
2843
2844 VkDescriptorPoolSize ds_type_count = {};
2845 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
2846 ds_type_count.descriptorCount = 1;
2847
2848 VkDescriptorPoolCreateInfo ds_pool_ci = {};
2849 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
2850 ds_pool_ci.maxSets = 1;
2851 ds_pool_ci.poolSizeCount = 1;
2852 ds_pool_ci.pPoolSizes = &ds_type_count;
2853
2854 VkDescriptorPool ds_pool;
2855 err =
2856 vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
2857 ASSERT_VK_SUCCESS(err);
2858
2859 VkDescriptorSetLayoutBinding dsl_binding = {};
2860 dsl_binding.binding = 0;
2861 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
2862 dsl_binding.descriptorCount = 1;
2863 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
2864
2865 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
2866 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
2867 ds_layout_ci.bindingCount = 1;
2868 ds_layout_ci.pBindings = &dsl_binding;
2869
2870 VkDescriptorSetLayout ds_layout;
2871 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
2872 &ds_layout);
2873 ASSERT_VK_SUCCESS(err);
2874
2875 VkDescriptorSet descriptorSet;
2876 VkDescriptorSetAllocateInfo alloc_info = {};
2877 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
2878 alloc_info.descriptorSetCount = 1;
2879 alloc_info.descriptorPool = ds_pool;
2880 alloc_info.pSetLayouts = &ds_layout;
2881 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info,
2882 &descriptorSet);
2883 ASSERT_VK_SUCCESS(err);
2884
2885 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
2886 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
2887 pipeline_layout_ci.setLayoutCount = 1;
2888 pipeline_layout_ci.pSetLayouts = &ds_layout;
2889
2890 VkPipelineLayout pipeline_layout;
2891 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL,
2892 &pipeline_layout);
2893 ASSERT_VK_SUCCESS(err);
2894
2895 VkViewport vp = {}; // Just need dummy vp to point to
2896
2897 VkPipelineViewportStateCreateInfo vp_state_ci = {};
2898 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
2899 vp_state_ci.scissorCount = 0;
2900 vp_state_ci.viewportCount = 1; // Count mismatch should cause error
2901 vp_state_ci.pViewports = &vp;
2902
2903 VkPipelineRasterizationStateCreateInfo rs_state_ci = {};
2904 rs_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
2905 rs_state_ci.polygonMode = VK_POLYGON_MODE_FILL;
2906 rs_state_ci.cullMode = VK_CULL_MODE_BACK_BIT;
2907 rs_state_ci.frontFace = VK_FRONT_FACE_COUNTER_CLOCKWISE;
2908 rs_state_ci.depthClampEnable = VK_FALSE;
2909 rs_state_ci.rasterizerDiscardEnable = VK_FALSE;
2910 rs_state_ci.depthBiasEnable = VK_FALSE;
2911
2912 VkPipelineShaderStageCreateInfo shaderStages[2];
2913 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
2914
2915 VkShaderObj vs(m_device, bindStateVertShaderText,
2916 VK_SHADER_STAGE_VERTEX_BIT, this);
2917 VkShaderObj fs(m_device, bindStateFragShaderText,
2918 VK_SHADER_STAGE_FRAGMENT_BIT,
2919 this); // TODO - We shouldn't need a fragment shader
2920 // but add it to be able to run on more devices
2921 shaderStages[0] = vs.GetStageCreateInfo();
2922 shaderStages[1] = fs.GetStageCreateInfo();
2923
2924 VkGraphicsPipelineCreateInfo gp_ci = {};
2925 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
2926 gp_ci.stageCount = 2;
2927 gp_ci.pStages = shaderStages;
2928 gp_ci.pViewportState = &vp_state_ci;
2929 gp_ci.pRasterizationState = &rs_state_ci;
2930 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
2931 gp_ci.layout = pipeline_layout;
2932 gp_ci.renderPass = renderPass();
2933
2934 VkPipelineCacheCreateInfo pc_ci = {};
2935 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
2936
2937 VkPipeline pipeline;
2938 VkPipelineCache pipelineCache;
2939
2940 err =
2941 vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
2942 ASSERT_VK_SUCCESS(err);
2943 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1,
2944 &gp_ci, NULL, &pipeline);
2945
2946 if (!m_errorMonitor->DesiredMsgFound()) {
2947 FAIL() << "Did not receive Error 'Gfx Pipeline viewport count (1) must "
2948 "match scissor count (0).'";
2949 m_errorMonitor->DumpFailureMsgs();
2950 }
2951
2952 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
2953 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
2954 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
2955 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
2956 }
2957 // Don't set viewport state in PSO. This is an error b/c we always need this
2958 // state
2959 // for the counts even if the data is going to be set dynamically.
TEST_F(VkLayerTest,PSOViewportStateNotSet)2960 TEST_F(VkLayerTest, PSOViewportStateNotSet) {
2961 // Attempt to Create Gfx Pipeline w/o a VS
2962 VkResult err;
2963
2964 m_errorMonitor->SetDesiredFailureMsg(
2965 VK_DEBUG_REPORT_ERROR_BIT_EXT,
2966 "Gfx Pipeline pViewportState is null. Even if ");
2967
2968 ASSERT_NO_FATAL_FAILURE(InitState());
2969 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
2970
2971 VkDescriptorPoolSize ds_type_count = {};
2972 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
2973 ds_type_count.descriptorCount = 1;
2974
2975 VkDescriptorPoolCreateInfo ds_pool_ci = {};
2976 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
2977 ds_pool_ci.maxSets = 1;
2978 ds_pool_ci.poolSizeCount = 1;
2979 ds_pool_ci.pPoolSizes = &ds_type_count;
2980
2981 VkDescriptorPool ds_pool;
2982 err =
2983 vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
2984 ASSERT_VK_SUCCESS(err);
2985
2986 VkDescriptorSetLayoutBinding dsl_binding = {};
2987 dsl_binding.binding = 0;
2988 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
2989 dsl_binding.descriptorCount = 1;
2990 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
2991
2992 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
2993 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
2994 ds_layout_ci.bindingCount = 1;
2995 ds_layout_ci.pBindings = &dsl_binding;
2996
2997 VkDescriptorSetLayout ds_layout;
2998 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
2999 &ds_layout);
3000 ASSERT_VK_SUCCESS(err);
3001
3002 VkDescriptorSet descriptorSet;
3003 VkDescriptorSetAllocateInfo alloc_info = {};
3004 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
3005 alloc_info.descriptorSetCount = 1;
3006 alloc_info.descriptorPool = ds_pool;
3007 alloc_info.pSetLayouts = &ds_layout;
3008 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info,
3009 &descriptorSet);
3010 ASSERT_VK_SUCCESS(err);
3011
3012 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
3013 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
3014 pipeline_layout_ci.setLayoutCount = 1;
3015 pipeline_layout_ci.pSetLayouts = &ds_layout;
3016
3017 VkPipelineLayout pipeline_layout;
3018 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL,
3019 &pipeline_layout);
3020 ASSERT_VK_SUCCESS(err);
3021
3022 VkDynamicState sc_state = VK_DYNAMIC_STATE_SCISSOR;
3023 // Set scissor as dynamic to avoid second error
3024 VkPipelineDynamicStateCreateInfo dyn_state_ci = {};
3025 dyn_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
3026 dyn_state_ci.dynamicStateCount = 1;
3027 dyn_state_ci.pDynamicStates = &sc_state;
3028
3029 VkPipelineShaderStageCreateInfo shaderStages[2];
3030 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
3031
3032 VkShaderObj vs(m_device, bindStateVertShaderText,
3033 VK_SHADER_STAGE_VERTEX_BIT, this);
3034 VkShaderObj fs(m_device, bindStateFragShaderText,
3035 VK_SHADER_STAGE_FRAGMENT_BIT,
3036 this); // TODO - We shouldn't need a fragment shader
3037 // but add it to be able to run on more devices
3038 shaderStages[0] = vs.GetStageCreateInfo();
3039 shaderStages[1] = fs.GetStageCreateInfo();
3040
3041
3042 VkPipelineRasterizationStateCreateInfo rs_state_ci = {};
3043 rs_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
3044 rs_state_ci.polygonMode = VK_POLYGON_MODE_FILL;
3045 rs_state_ci.cullMode = VK_CULL_MODE_BACK_BIT;
3046 rs_state_ci.frontFace = VK_FRONT_FACE_COUNTER_CLOCKWISE;
3047 rs_state_ci.depthClampEnable = VK_FALSE;
3048 rs_state_ci.rasterizerDiscardEnable = VK_FALSE;
3049 rs_state_ci.depthBiasEnable = VK_FALSE;
3050
3051 VkGraphicsPipelineCreateInfo gp_ci = {};
3052 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
3053 gp_ci.stageCount = 2;
3054 gp_ci.pStages = shaderStages;
3055 gp_ci.pRasterizationState = &rs_state_ci;
3056 gp_ci.pViewportState = NULL; // Not setting VP state w/o dynamic vp state
3057 // should cause validation error
3058 gp_ci.pDynamicState = &dyn_state_ci;
3059 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
3060 gp_ci.layout = pipeline_layout;
3061 gp_ci.renderPass = renderPass();
3062
3063 VkPipelineCacheCreateInfo pc_ci = {};
3064 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
3065
3066 VkPipeline pipeline;
3067 VkPipelineCache pipelineCache;
3068
3069 err =
3070 vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
3071 ASSERT_VK_SUCCESS(err);
3072 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1,
3073 &gp_ci, NULL, &pipeline);
3074
3075 if (!m_errorMonitor->DesiredMsgFound()) {
3076 FAIL() << "Did not receive Error 'Gfx Pipeline pViewportState is null. "
3077 "Even if...'";
3078 m_errorMonitor->DumpFailureMsgs();
3079 }
3080
3081 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
3082 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
3083 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
3084 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
3085 }
3086 // Create PSO w/o non-zero viewportCount but no viewport data
3087 // Then run second test where dynamic scissor count doesn't match PSO scissor
3088 // count
TEST_F(VkLayerTest,PSOViewportCountWithoutDataAndDynScissorMismatch)3089 TEST_F(VkLayerTest, PSOViewportCountWithoutDataAndDynScissorMismatch) {
3090 VkResult err;
3091
3092 m_errorMonitor->SetDesiredFailureMsg(
3093 VK_DEBUG_REPORT_ERROR_BIT_EXT,
3094 "Gfx Pipeline viewportCount is 1, but pViewports is NULL. ");
3095
3096 ASSERT_NO_FATAL_FAILURE(InitState());
3097 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
3098
3099 VkDescriptorPoolSize ds_type_count = {};
3100 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
3101 ds_type_count.descriptorCount = 1;
3102
3103 VkDescriptorPoolCreateInfo ds_pool_ci = {};
3104 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
3105 ds_pool_ci.maxSets = 1;
3106 ds_pool_ci.poolSizeCount = 1;
3107 ds_pool_ci.pPoolSizes = &ds_type_count;
3108
3109 VkDescriptorPool ds_pool;
3110 err =
3111 vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
3112 ASSERT_VK_SUCCESS(err);
3113
3114 VkDescriptorSetLayoutBinding dsl_binding = {};
3115 dsl_binding.binding = 0;
3116 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
3117 dsl_binding.descriptorCount = 1;
3118 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
3119
3120 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
3121 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
3122 ds_layout_ci.bindingCount = 1;
3123 ds_layout_ci.pBindings = &dsl_binding;
3124
3125 VkDescriptorSetLayout ds_layout;
3126 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
3127 &ds_layout);
3128 ASSERT_VK_SUCCESS(err);
3129
3130 VkDescriptorSet descriptorSet;
3131 VkDescriptorSetAllocateInfo alloc_info = {};
3132 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
3133 alloc_info.descriptorSetCount = 1;
3134 alloc_info.descriptorPool = ds_pool;
3135 alloc_info.pSetLayouts = &ds_layout;
3136 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info,
3137 &descriptorSet);
3138 ASSERT_VK_SUCCESS(err);
3139
3140 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
3141 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
3142 pipeline_layout_ci.setLayoutCount = 1;
3143 pipeline_layout_ci.pSetLayouts = &ds_layout;
3144
3145 VkPipelineLayout pipeline_layout;
3146 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL,
3147 &pipeline_layout);
3148 ASSERT_VK_SUCCESS(err);
3149
3150 VkPipelineViewportStateCreateInfo vp_state_ci = {};
3151 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
3152 vp_state_ci.viewportCount = 1;
3153 vp_state_ci.pViewports = NULL; // Null vp w/ count of 1 should cause error
3154 vp_state_ci.scissorCount = 1;
3155 vp_state_ci.pScissors =
3156 NULL; // Scissor is dynamic (below) so this won't cause error
3157
3158 VkDynamicState sc_state = VK_DYNAMIC_STATE_SCISSOR;
3159 // Set scissor as dynamic to avoid that error
3160 VkPipelineDynamicStateCreateInfo dyn_state_ci = {};
3161 dyn_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
3162 dyn_state_ci.dynamicStateCount = 1;
3163 dyn_state_ci.pDynamicStates = &sc_state;
3164
3165 VkPipelineShaderStageCreateInfo shaderStages[2];
3166 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
3167
3168 VkShaderObj vs(m_device, bindStateVertShaderText,
3169 VK_SHADER_STAGE_VERTEX_BIT, this);
3170 VkShaderObj fs(m_device, bindStateFragShaderText,
3171 VK_SHADER_STAGE_FRAGMENT_BIT,
3172 this); // TODO - We shouldn't need a fragment shader
3173 // but add it to be able to run on more devices
3174 shaderStages[0] = vs.GetStageCreateInfo();
3175 shaderStages[1] = fs.GetStageCreateInfo();
3176
3177 VkPipelineVertexInputStateCreateInfo vi_ci = {};
3178 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
3179 vi_ci.pNext = nullptr;
3180 vi_ci.vertexBindingDescriptionCount = 0;
3181 vi_ci.pVertexBindingDescriptions = nullptr;
3182 vi_ci.vertexAttributeDescriptionCount = 0;
3183 vi_ci.pVertexAttributeDescriptions = nullptr;
3184
3185 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
3186 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
3187 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
3188
3189 VkPipelineRasterizationStateCreateInfo rs_ci = {};
3190 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
3191 rs_ci.pNext = nullptr;
3192
3193 VkPipelineColorBlendStateCreateInfo cb_ci = {};
3194 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
3195 cb_ci.pNext = nullptr;
3196
3197 VkGraphicsPipelineCreateInfo gp_ci = {};
3198 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
3199 gp_ci.stageCount = 2;
3200 gp_ci.pStages = shaderStages;
3201 gp_ci.pVertexInputState = &vi_ci;
3202 gp_ci.pInputAssemblyState = &ia_ci;
3203 gp_ci.pViewportState = &vp_state_ci;
3204 gp_ci.pRasterizationState = &rs_ci;
3205 gp_ci.pColorBlendState = &cb_ci;
3206 gp_ci.pDynamicState = &dyn_state_ci;
3207 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
3208 gp_ci.layout = pipeline_layout;
3209 gp_ci.renderPass = renderPass();
3210
3211 VkPipelineCacheCreateInfo pc_ci = {};
3212 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
3213
3214 VkPipeline pipeline;
3215 VkPipelineCache pipelineCache;
3216
3217 err =
3218 vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
3219 ASSERT_VK_SUCCESS(err);
3220 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1,
3221 &gp_ci, NULL, &pipeline);
3222
3223 if (!m_errorMonitor->DesiredMsgFound()) {
3224 FAIL() << "Did not recieve Error 'Gfx Pipeline viewportCount is 1, but "
3225 "pViewports is NULL...'";
3226 m_errorMonitor->DumpFailureMsgs();
3227 }
3228
3229 // Now hit second fail case where we set scissor w/ different count than PSO
3230 // First need to successfully create the PSO from above by setting
3231 // pViewports
3232 m_errorMonitor->SetDesiredFailureMsg(
3233 VK_DEBUG_REPORT_ERROR_BIT_EXT,
3234 "Dynamic scissorCount from vkCmdSetScissor() is 2, but PSO "
3235 "scissorCount is 1. These counts must match.");
3236
3237 VkViewport vp = {}; // Just need dummy vp to point to
3238 vp_state_ci.pViewports = &vp;
3239 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1,
3240 &gp_ci, NULL, &pipeline);
3241 ASSERT_VK_SUCCESS(err);
3242 BeginCommandBuffer();
3243 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(),
3244 VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
3245 VkRect2D scissors[2] = {}; // don't care about data
3246 // Count of 2 doesn't match PSO count of 1
3247 vkCmdSetScissor(m_commandBuffer->GetBufferHandle(), 0, 2, scissors);
3248 Draw(1, 0, 0, 0);
3249
3250 if (!m_errorMonitor->DesiredMsgFound()) {
3251 FAIL() << "Did not receive Error 'Dynamic scissorCount from "
3252 "vkCmdSetScissor() is 2, but PSO scissorCount is 1...'";
3253 m_errorMonitor->DumpFailureMsgs();
3254 }
3255
3256 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
3257 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
3258 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
3259 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
3260 }
3261 // Create PSO w/o non-zero scissorCount but no scissor data
3262 // Then run second test where dynamic viewportCount doesn't match PSO
3263 // viewportCount
TEST_F(VkLayerTest,PSOScissorCountWithoutDataAndDynViewportMismatch)3264 TEST_F(VkLayerTest, PSOScissorCountWithoutDataAndDynViewportMismatch) {
3265 VkResult err;
3266
3267 m_errorMonitor->SetDesiredFailureMsg(
3268 VK_DEBUG_REPORT_ERROR_BIT_EXT,
3269 "Gfx Pipeline scissorCount is 1, but pScissors is NULL. ");
3270
3271 ASSERT_NO_FATAL_FAILURE(InitState());
3272 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
3273
3274 VkDescriptorPoolSize ds_type_count = {};
3275 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
3276 ds_type_count.descriptorCount = 1;
3277
3278 VkDescriptorPoolCreateInfo ds_pool_ci = {};
3279 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
3280 ds_pool_ci.maxSets = 1;
3281 ds_pool_ci.poolSizeCount = 1;
3282 ds_pool_ci.pPoolSizes = &ds_type_count;
3283
3284 VkDescriptorPool ds_pool;
3285 err =
3286 vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
3287 ASSERT_VK_SUCCESS(err);
3288
3289 VkDescriptorSetLayoutBinding dsl_binding = {};
3290 dsl_binding.binding = 0;
3291 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
3292 dsl_binding.descriptorCount = 1;
3293 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
3294
3295 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
3296 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
3297 ds_layout_ci.bindingCount = 1;
3298 ds_layout_ci.pBindings = &dsl_binding;
3299
3300 VkDescriptorSetLayout ds_layout;
3301 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
3302 &ds_layout);
3303 ASSERT_VK_SUCCESS(err);
3304
3305 VkDescriptorSet descriptorSet;
3306 VkDescriptorSetAllocateInfo alloc_info = {};
3307 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
3308 alloc_info.descriptorSetCount = 1;
3309 alloc_info.descriptorPool = ds_pool;
3310 alloc_info.pSetLayouts = &ds_layout;
3311 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info,
3312 &descriptorSet);
3313 ASSERT_VK_SUCCESS(err);
3314
3315 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
3316 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
3317 pipeline_layout_ci.setLayoutCount = 1;
3318 pipeline_layout_ci.pSetLayouts = &ds_layout;
3319
3320 VkPipelineLayout pipeline_layout;
3321 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL,
3322 &pipeline_layout);
3323 ASSERT_VK_SUCCESS(err);
3324
3325 VkPipelineViewportStateCreateInfo vp_state_ci = {};
3326 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
3327 vp_state_ci.scissorCount = 1;
3328 vp_state_ci.pScissors =
3329 NULL; // Null scissor w/ count of 1 should cause error
3330 vp_state_ci.viewportCount = 1;
3331 vp_state_ci.pViewports =
3332 NULL; // vp is dynamic (below) so this won't cause error
3333
3334 VkDynamicState vp_state = VK_DYNAMIC_STATE_VIEWPORT;
3335 // Set scissor as dynamic to avoid that error
3336 VkPipelineDynamicStateCreateInfo dyn_state_ci = {};
3337 dyn_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
3338 dyn_state_ci.dynamicStateCount = 1;
3339 dyn_state_ci.pDynamicStates = &vp_state;
3340
3341 VkPipelineShaderStageCreateInfo shaderStages[2];
3342 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
3343
3344 VkShaderObj vs(m_device, bindStateVertShaderText,
3345 VK_SHADER_STAGE_VERTEX_BIT, this);
3346 VkShaderObj fs(m_device, bindStateFragShaderText,
3347 VK_SHADER_STAGE_FRAGMENT_BIT,
3348 this); // TODO - We shouldn't need a fragment shader
3349 // but add it to be able to run on more devices
3350 shaderStages[0] = vs.GetStageCreateInfo();
3351 shaderStages[1] = fs.GetStageCreateInfo();
3352
3353 VkPipelineVertexInputStateCreateInfo vi_ci = {};
3354 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
3355 vi_ci.pNext = nullptr;
3356 vi_ci.vertexBindingDescriptionCount = 0;
3357 vi_ci.pVertexBindingDescriptions = nullptr;
3358 vi_ci.vertexAttributeDescriptionCount = 0;
3359 vi_ci.pVertexAttributeDescriptions = nullptr;
3360
3361 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
3362 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
3363 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
3364
3365 VkPipelineRasterizationStateCreateInfo rs_ci = {};
3366 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
3367 rs_ci.pNext = nullptr;
3368
3369 VkPipelineColorBlendStateCreateInfo cb_ci = {};
3370 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
3371 cb_ci.pNext = nullptr;
3372
3373 VkGraphicsPipelineCreateInfo gp_ci = {};
3374 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
3375 gp_ci.stageCount = 2;
3376 gp_ci.pStages = shaderStages;
3377 gp_ci.pVertexInputState = &vi_ci;
3378 gp_ci.pInputAssemblyState = &ia_ci;
3379 gp_ci.pViewportState = &vp_state_ci;
3380 gp_ci.pRasterizationState = &rs_ci;
3381 gp_ci.pColorBlendState = &cb_ci;
3382 gp_ci.pDynamicState = &dyn_state_ci;
3383 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
3384 gp_ci.layout = pipeline_layout;
3385 gp_ci.renderPass = renderPass();
3386
3387 VkPipelineCacheCreateInfo pc_ci = {};
3388 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
3389
3390 VkPipeline pipeline;
3391 VkPipelineCache pipelineCache;
3392
3393 err =
3394 vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
3395 ASSERT_VK_SUCCESS(err);
3396 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1,
3397 &gp_ci, NULL, &pipeline);
3398
3399 if (!m_errorMonitor->DesiredMsgFound()) {
3400 FAIL() << "Did not recieve Error 'Gfx Pipeline scissorCount is 1, but "
3401 "pScissors is NULL...'";
3402 m_errorMonitor->DumpFailureMsgs();
3403 }
3404
3405 // Now hit second fail case where we set scissor w/ different count than PSO
3406 // First need to successfully create the PSO from above by setting
3407 // pViewports
3408 m_errorMonitor->SetDesiredFailureMsg(
3409 VK_DEBUG_REPORT_ERROR_BIT_EXT,
3410 "Dynamic viewportCount from vkCmdSetViewport() is 2, but PSO "
3411 "viewportCount is 1. These counts must match.");
3412
3413 VkRect2D sc = {}; // Just need dummy vp to point to
3414 vp_state_ci.pScissors = ≻
3415 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1,
3416 &gp_ci, NULL, &pipeline);
3417 ASSERT_VK_SUCCESS(err);
3418 BeginCommandBuffer();
3419 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(),
3420 VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
3421 VkViewport viewports[2] = {}; // don't care about data
3422 // Count of 2 doesn't match PSO count of 1
3423 vkCmdSetViewport(m_commandBuffer->GetBufferHandle(), 0, 2, viewports);
3424 Draw(1, 0, 0, 0);
3425
3426 if (!m_errorMonitor->DesiredMsgFound()) {
3427 FAIL() << "Did not receive Error 'Dynamic viewportCount from "
3428 "vkCmdSetViewport() is 2, but PSO viewportCount is 1...'";
3429 m_errorMonitor->DumpFailureMsgs();
3430 }
3431
3432 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
3433 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
3434 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
3435 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
3436 }
3437
TEST_F(VkLayerTest,NullRenderPass)3438 TEST_F(VkLayerTest, NullRenderPass) {
3439 // Bind a NULL RenderPass
3440 m_errorMonitor->SetDesiredFailureMsg(
3441 VK_DEBUG_REPORT_ERROR_BIT_EXT,
3442 "You cannot use a NULL RenderPass object in vkCmdBeginRenderPass()");
3443
3444 ASSERT_NO_FATAL_FAILURE(InitState());
3445 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
3446
3447 BeginCommandBuffer();
3448 // Don't care about RenderPass handle b/c error should be flagged before
3449 // that
3450 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), NULL,
3451 VK_SUBPASS_CONTENTS_INLINE);
3452
3453 if (!m_errorMonitor->DesiredMsgFound()) {
3454 FAIL() << "Did not receive Error 'You cannot use a NULL RenderPass "
3455 "object in vkCmdBeginRenderPass()'";
3456 m_errorMonitor->DumpFailureMsgs();
3457 }
3458 }
3459
TEST_F(VkLayerTest,RenderPassWithinRenderPass)3460 TEST_F(VkLayerTest, RenderPassWithinRenderPass) {
3461 // Bind a BeginRenderPass within an active RenderPass
3462 m_errorMonitor->SetDesiredFailureMsg(
3463 VK_DEBUG_REPORT_ERROR_BIT_EXT,
3464 "It is invalid to issue this call inside an active render pass");
3465
3466 ASSERT_NO_FATAL_FAILURE(InitState());
3467 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
3468
3469 BeginCommandBuffer();
3470 // Just create a dummy Renderpass that's non-NULL so we can get to the
3471 // proper error
3472 VkRenderPassBeginInfo rp_begin = {};
3473 rp_begin.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO;
3474 rp_begin.pNext = NULL;
3475 rp_begin.renderPass = renderPass();
3476 rp_begin.framebuffer = framebuffer();
3477
3478 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &rp_begin,
3479 VK_SUBPASS_CONTENTS_INLINE);
3480
3481 if (!m_errorMonitor->DesiredMsgFound()) {
3482 FAIL() << "Did not receive Error 'It is invalid to issue this call "
3483 "inside an active render pass...'";
3484 m_errorMonitor->DumpFailureMsgs();
3485 }
3486 }
3487
TEST_F(VkLayerTest,FillBufferWithinRenderPass)3488 TEST_F(VkLayerTest, FillBufferWithinRenderPass) {
3489 // Call CmdFillBuffer within an active renderpass
3490 m_errorMonitor->SetDesiredFailureMsg(
3491 VK_DEBUG_REPORT_ERROR_BIT_EXT,
3492 "It is invalid to issue this call inside an active render pass");
3493
3494 ASSERT_NO_FATAL_FAILURE(InitState());
3495 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
3496
3497 // Renderpass is started here
3498 BeginCommandBuffer();
3499
3500 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
3501 vk_testing::Buffer dstBuffer;
3502 dstBuffer.init_as_dst(*m_device, (VkDeviceSize)1024, reqs);
3503
3504 m_commandBuffer->FillBuffer(dstBuffer.handle(), 0, 4, 0x11111111);
3505
3506 if (!m_errorMonitor->DesiredMsgFound()) {
3507 FAIL() << "Did not receive Error 'It is invalid to issue this call "
3508 "inside an active render pass...'";
3509 m_errorMonitor->DumpFailureMsgs();
3510 }
3511 }
3512
TEST_F(VkLayerTest,UpdateBufferWithinRenderPass)3513 TEST_F(VkLayerTest, UpdateBufferWithinRenderPass) {
3514 // Call CmdUpdateBuffer within an active renderpass
3515 m_errorMonitor->SetDesiredFailureMsg(
3516 VK_DEBUG_REPORT_ERROR_BIT_EXT,
3517 "It is invalid to issue this call inside an active render pass");
3518
3519 ASSERT_NO_FATAL_FAILURE(InitState());
3520 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
3521
3522 // Renderpass is started here
3523 BeginCommandBuffer();
3524
3525 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
3526 vk_testing::Buffer dstBuffer;
3527 dstBuffer.init_as_dst(*m_device, (VkDeviceSize)1024, reqs);
3528
3529 VkDeviceSize dstOffset = 0;
3530 VkDeviceSize dataSize = 1024;
3531 const uint32_t *pData = NULL;
3532
3533 vkCmdUpdateBuffer(m_commandBuffer->GetBufferHandle(), dstBuffer.handle(),
3534 dstOffset, dataSize, pData);
3535
3536 if (!m_errorMonitor->DesiredMsgFound()) {
3537 FAIL() << "Did not receive Error 'It is invalid to issue this call "
3538 "inside an active render pass...'";
3539 m_errorMonitor->DumpFailureMsgs();
3540 }
3541 }
3542
TEST_F(VkLayerTest,ClearColorImageWithinRenderPass)3543 TEST_F(VkLayerTest, ClearColorImageWithinRenderPass) {
3544 // Call CmdClearColorImage within an active RenderPass
3545 m_errorMonitor->SetDesiredFailureMsg(
3546 VK_DEBUG_REPORT_ERROR_BIT_EXT,
3547 "It is invalid to issue this call inside an active render pass");
3548
3549 ASSERT_NO_FATAL_FAILURE(InitState());
3550 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
3551
3552 // Renderpass is started here
3553 BeginCommandBuffer();
3554
3555 VkClearColorValue clear_color;
3556 memset(clear_color.uint32, 0, sizeof(uint32_t) * 4);
3557 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
3558 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
3559 const int32_t tex_width = 32;
3560 const int32_t tex_height = 32;
3561 VkImageCreateInfo image_create_info = {};
3562 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
3563 image_create_info.pNext = NULL;
3564 image_create_info.imageType = VK_IMAGE_TYPE_2D;
3565 image_create_info.format = tex_format;
3566 image_create_info.extent.width = tex_width;
3567 image_create_info.extent.height = tex_height;
3568 image_create_info.extent.depth = 1;
3569 image_create_info.mipLevels = 1;
3570 image_create_info.arrayLayers = 1;
3571 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
3572 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
3573 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
3574
3575 vk_testing::Image dstImage;
3576 dstImage.init(*m_device, (const VkImageCreateInfo &)image_create_info,
3577 reqs);
3578
3579 const VkImageSubresourceRange range = vk_testing::Image::subresource_range(
3580 image_create_info, VK_IMAGE_ASPECT_COLOR_BIT);
3581
3582 vkCmdClearColorImage(m_commandBuffer->GetBufferHandle(), dstImage.handle(),
3583 VK_IMAGE_LAYOUT_GENERAL, &clear_color, 1, &range);
3584
3585 if (!m_errorMonitor->DesiredMsgFound()) {
3586 FAIL() << "Did not receive Error 'It is invalid to issue this call "
3587 "inside an active render pass...'";
3588 m_errorMonitor->DumpFailureMsgs();
3589 }
3590 }
3591
TEST_F(VkLayerTest,ClearDepthStencilImageWithinRenderPass)3592 TEST_F(VkLayerTest, ClearDepthStencilImageWithinRenderPass) {
3593 // Call CmdClearDepthStencilImage within an active RenderPass
3594 m_errorMonitor->SetDesiredFailureMsg(
3595 VK_DEBUG_REPORT_ERROR_BIT_EXT,
3596 "It is invalid to issue this call inside an active render pass");
3597
3598 ASSERT_NO_FATAL_FAILURE(InitState());
3599 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
3600
3601 // Renderpass is started here
3602 BeginCommandBuffer();
3603
3604 VkClearDepthStencilValue clear_value = {0};
3605 VkMemoryPropertyFlags reqs = 0;
3606 VkImageCreateInfo image_create_info = vk_testing::Image::create_info();
3607 image_create_info.imageType = VK_IMAGE_TYPE_2D;
3608 image_create_info.format = VK_FORMAT_D24_UNORM_S8_UINT;
3609 image_create_info.extent.width = 64;
3610 image_create_info.extent.height = 64;
3611 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
3612 image_create_info.usage = VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT;
3613
3614 vk_testing::Image dstImage;
3615 dstImage.init(*m_device, (const VkImageCreateInfo &)image_create_info,
3616 reqs);
3617
3618 const VkImageSubresourceRange range = vk_testing::Image::subresource_range(
3619 image_create_info, VK_IMAGE_ASPECT_DEPTH_BIT);
3620
3621 vkCmdClearDepthStencilImage(
3622 m_commandBuffer->GetBufferHandle(), dstImage.handle(),
3623 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL, &clear_value, 1,
3624 &range);
3625
3626 if (!m_errorMonitor->DesiredMsgFound()) {
3627 FAIL() << "Did not receive Error 'It is invalid to issue this call "
3628 "inside an active render pass...'";
3629 m_errorMonitor->DumpFailureMsgs();
3630 }
3631 }
3632
TEST_F(VkLayerTest,ClearColorAttachmentsOutsideRenderPass)3633 TEST_F(VkLayerTest, ClearColorAttachmentsOutsideRenderPass) {
3634 // Call CmdClearAttachmentss outside of an active RenderPass
3635 VkResult err;
3636
3637 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3638 "vkCmdClearAttachments: This call "
3639 "must be issued inside an active "
3640 "render pass");
3641
3642 ASSERT_NO_FATAL_FAILURE(InitState());
3643 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
3644
3645 // Start no RenderPass
3646 err = m_commandBuffer->BeginCommandBuffer();
3647 ASSERT_VK_SUCCESS(err);
3648
3649 VkClearAttachment color_attachment;
3650 color_attachment.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
3651 color_attachment.clearValue.color.float32[0] = 0;
3652 color_attachment.clearValue.color.float32[1] = 0;
3653 color_attachment.clearValue.color.float32[2] = 0;
3654 color_attachment.clearValue.color.float32[3] = 0;
3655 color_attachment.colorAttachment = 0;
3656 VkClearRect clear_rect = {{{0, 0}, {32, 32}}};
3657 vkCmdClearAttachments(m_commandBuffer->GetBufferHandle(), 1,
3658 &color_attachment, 1, &clear_rect);
3659
3660 if (!m_errorMonitor->DesiredMsgFound()) {
3661 FAIL() << "Did not receive Error 'vkCmdClearAttachments: This call "
3662 "must be issued inside an active render pass.'";
3663 m_errorMonitor->DumpFailureMsgs();
3664 }
3665 }
3666
TEST_F(VkLayerTest,InvalidDynamicStateObject)3667 TEST_F(VkLayerTest, InvalidDynamicStateObject) {
3668 // Create a valid cmd buffer
3669 // call vkCmdBindDynamicStateObject w/ false DS Obj
3670 // TODO : Simple check for bad object should be added to ObjectTracker to
3671 // catch this case
3672 // The DS check for this is after driver has been called to validate DS
3673 // internal data struct
3674 }
3675
TEST_F(VkLayerTest,IdxBufferAlignmentError)3676 TEST_F(VkLayerTest, IdxBufferAlignmentError) {
3677 // Bind a BeginRenderPass within an active RenderPass
3678 VkResult err;
3679
3680 m_errorMonitor->SetDesiredFailureMsg(
3681 VK_DEBUG_REPORT_ERROR_BIT_EXT,
3682 "vkCmdBindIndexBuffer() offset (0x7) does not fall on ");
3683
3684 ASSERT_NO_FATAL_FAILURE(InitState());
3685 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
3686 uint32_t qfi = 0;
3687 VkBufferCreateInfo buffCI = {};
3688 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
3689 buffCI.size = 1024;
3690 buffCI.usage = VK_BUFFER_USAGE_INDEX_BUFFER_BIT;
3691 buffCI.queueFamilyIndexCount = 1;
3692 buffCI.pQueueFamilyIndices = &qfi;
3693
3694 VkBuffer ib;
3695 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &ib);
3696 ASSERT_VK_SUCCESS(err);
3697
3698 BeginCommandBuffer();
3699 ASSERT_VK_SUCCESS(err);
3700 // vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(),
3701 // VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
3702 // Should error before calling to driver so don't care about actual data
3703 vkCmdBindIndexBuffer(m_commandBuffer->GetBufferHandle(), ib, 7,
3704 VK_INDEX_TYPE_UINT16);
3705
3706 if (!m_errorMonitor->DesiredMsgFound()) {
3707 FAIL() << "Did not receive Error 'vkCmdBindIndexBuffer() offset (0x7) "
3708 "does not fall on ...'";
3709 m_errorMonitor->DumpFailureMsgs();
3710 }
3711
3712 vkDestroyBuffer(m_device->device(), ib, NULL);
3713 }
3714
TEST_F(VkLayerTest,InvalidQueueFamilyIndex)3715 TEST_F(VkLayerTest, InvalidQueueFamilyIndex) {
3716 // Create an out-of-range queueFamilyIndex
3717 m_errorMonitor->SetDesiredFailureMsg(
3718 VK_DEBUG_REPORT_ERROR_BIT_EXT,
3719 "vkCreateBuffer has QueueFamilyIndex greater than");
3720
3721 ASSERT_NO_FATAL_FAILURE(InitState());
3722 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
3723 VkBufferCreateInfo buffCI = {};
3724 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
3725 buffCI.size = 1024;
3726 buffCI.usage = VK_BUFFER_USAGE_INDEX_BUFFER_BIT;
3727 buffCI.queueFamilyIndexCount = 1;
3728 // Introduce failure by specifying invalid queue_family_index
3729 uint32_t qfi = 777;
3730 buffCI.pQueueFamilyIndices = &qfi;
3731
3732 VkBuffer ib;
3733 vkCreateBuffer(m_device->device(), &buffCI, NULL, &ib);
3734
3735 if (!m_errorMonitor->DesiredMsgFound()) {
3736 FAIL() << "Did not receive Error 'vkCreateBuffer() has "
3737 "QueueFamilyIndex greater than...'";
3738 m_errorMonitor->DumpFailureMsgs();
3739 }
3740 }
3741
TEST_F(VkLayerTest,ExecuteCommandsPrimaryCB)3742 TEST_F(VkLayerTest, ExecuteCommandsPrimaryCB) {
3743 // Attempt vkCmdExecuteCommands w/ a primary cmd buffer (should only be
3744 // secondary)
3745
3746 m_errorMonitor->SetDesiredFailureMsg(
3747 VK_DEBUG_REPORT_ERROR_BIT_EXT,
3748 "vkCmdExecuteCommands() called w/ Primary Cmd Buffer ");
3749
3750 ASSERT_NO_FATAL_FAILURE(InitState());
3751 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
3752
3753 BeginCommandBuffer();
3754 // ASSERT_VK_SUCCESS(err);
3755 VkCommandBuffer primCB = m_commandBuffer->GetBufferHandle();
3756 vkCmdExecuteCommands(m_commandBuffer->GetBufferHandle(), 1, &primCB);
3757
3758 if (!m_errorMonitor->DesiredMsgFound()) {
3759 FAIL() << "Did not receive Error 'vkCmdExecuteCommands() called w/ "
3760 "Primary Cmd Buffer '";
3761 m_errorMonitor->DumpFailureMsgs();
3762 }
3763 }
3764
TEST_F(VkLayerTest,DSTypeMismatch)3765 TEST_F(VkLayerTest, DSTypeMismatch) {
3766 // Create DS w/ layout of one type and attempt Update w/ mis-matched type
3767 VkResult err;
3768
3769 m_errorMonitor->SetDesiredFailureMsg(
3770 VK_DEBUG_REPORT_ERROR_BIT_EXT, "Write descriptor update has descriptor "
3771 "type VK_DESCRIPTOR_TYPE_SAMPLER that "
3772 "does not match ");
3773
3774 ASSERT_NO_FATAL_FAILURE(InitState());
3775 // VkDescriptorSetObj descriptorSet(m_device);
3776 VkDescriptorPoolSize ds_type_count = {};
3777 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
3778 ds_type_count.descriptorCount = 1;
3779
3780 VkDescriptorPoolCreateInfo ds_pool_ci = {};
3781 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
3782 ds_pool_ci.pNext = NULL;
3783 ds_pool_ci.maxSets = 1;
3784 ds_pool_ci.poolSizeCount = 1;
3785 ds_pool_ci.pPoolSizes = &ds_type_count;
3786
3787 VkDescriptorPool ds_pool;
3788 err =
3789 vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
3790 ASSERT_VK_SUCCESS(err);
3791 VkDescriptorSetLayoutBinding dsl_binding = {};
3792 dsl_binding.binding = 0;
3793 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
3794 dsl_binding.descriptorCount = 1;
3795 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
3796 dsl_binding.pImmutableSamplers = NULL;
3797
3798 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
3799 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
3800 ds_layout_ci.pNext = NULL;
3801 ds_layout_ci.bindingCount = 1;
3802 ds_layout_ci.pBindings = &dsl_binding;
3803
3804 VkDescriptorSetLayout ds_layout;
3805 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
3806 &ds_layout);
3807 ASSERT_VK_SUCCESS(err);
3808
3809 VkDescriptorSet descriptorSet;
3810 VkDescriptorSetAllocateInfo alloc_info = {};
3811 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
3812 alloc_info.descriptorSetCount = 1;
3813 alloc_info.descriptorPool = ds_pool;
3814 alloc_info.pSetLayouts = &ds_layout;
3815 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info,
3816 &descriptorSet);
3817 ASSERT_VK_SUCCESS(err);
3818
3819 VkSamplerCreateInfo sampler_ci = {};
3820 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
3821 sampler_ci.pNext = NULL;
3822 sampler_ci.magFilter = VK_FILTER_NEAREST;
3823 sampler_ci.minFilter = VK_FILTER_NEAREST;
3824 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
3825 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
3826 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
3827 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
3828 sampler_ci.mipLodBias = 1.0;
3829 sampler_ci.anisotropyEnable = VK_FALSE;
3830 sampler_ci.maxAnisotropy = 1;
3831 sampler_ci.compareEnable = VK_FALSE;
3832 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
3833 sampler_ci.minLod = 1.0;
3834 sampler_ci.maxLod = 1.0;
3835 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
3836 sampler_ci.unnormalizedCoordinates = VK_FALSE;
3837
3838 VkSampler sampler;
3839 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
3840 ASSERT_VK_SUCCESS(err);
3841
3842 VkDescriptorImageInfo info = {};
3843 info.sampler = sampler;
3844
3845 VkWriteDescriptorSet descriptor_write;
3846 memset(&descriptor_write, 0, sizeof(descriptor_write));
3847 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
3848 descriptor_write.dstSet = descriptorSet;
3849 descriptor_write.descriptorCount = 1;
3850 // This is a mismatched type for the layout which expects BUFFER
3851 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
3852 descriptor_write.pImageInfo = &info;
3853
3854 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
3855
3856 if (!m_errorMonitor->DesiredMsgFound()) {
3857 FAIL() << "Did not receive Error 'Write descriptor update has "
3858 "descriptor type VK_DESCRIPTOR_TYPE_SAMPLER that does not "
3859 "match...'";
3860 m_errorMonitor->DumpFailureMsgs();
3861 }
3862
3863 vkDestroySampler(m_device->device(), sampler, NULL);
3864 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
3865 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
3866 }
3867
TEST_F(VkLayerTest,DSUpdateOutOfBounds)3868 TEST_F(VkLayerTest, DSUpdateOutOfBounds) {
3869 // For overlapping Update, have arrayIndex exceed that of layout
3870 VkResult err;
3871
3872 m_errorMonitor->SetDesiredFailureMsg(
3873 VK_DEBUG_REPORT_ERROR_BIT_EXT, "Descriptor update type of "
3874 "VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET "
3875 "is out of bounds for matching binding");
3876
3877 ASSERT_NO_FATAL_FAILURE(InitState());
3878 // VkDescriptorSetObj descriptorSet(m_device);
3879 VkDescriptorPoolSize ds_type_count = {};
3880 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
3881 ds_type_count.descriptorCount = 1;
3882
3883 VkDescriptorPoolCreateInfo ds_pool_ci = {};
3884 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
3885 ds_pool_ci.pNext = NULL;
3886 ds_pool_ci.maxSets = 1;
3887 ds_pool_ci.poolSizeCount = 1;
3888 ds_pool_ci.pPoolSizes = &ds_type_count;
3889
3890 VkDescriptorPool ds_pool;
3891 err =
3892 vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
3893 ASSERT_VK_SUCCESS(err);
3894
3895 VkDescriptorSetLayoutBinding dsl_binding = {};
3896 dsl_binding.binding = 0;
3897 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
3898 dsl_binding.descriptorCount = 1;
3899 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
3900 dsl_binding.pImmutableSamplers = NULL;
3901
3902 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
3903 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
3904 ds_layout_ci.pNext = NULL;
3905 ds_layout_ci.bindingCount = 1;
3906 ds_layout_ci.pBindings = &dsl_binding;
3907
3908 VkDescriptorSetLayout ds_layout;
3909 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
3910 &ds_layout);
3911 ASSERT_VK_SUCCESS(err);
3912
3913 VkDescriptorSet descriptorSet;
3914 VkDescriptorSetAllocateInfo alloc_info = {};
3915 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
3916 alloc_info.descriptorSetCount = 1;
3917 alloc_info.descriptorPool = ds_pool;
3918 alloc_info.pSetLayouts = &ds_layout;
3919 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info,
3920 &descriptorSet);
3921 ASSERT_VK_SUCCESS(err);
3922
3923 VkSamplerCreateInfo sampler_ci = {};
3924 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
3925 sampler_ci.pNext = NULL;
3926 sampler_ci.magFilter = VK_FILTER_NEAREST;
3927 sampler_ci.minFilter = VK_FILTER_NEAREST;
3928 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
3929 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
3930 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
3931 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
3932 sampler_ci.mipLodBias = 1.0;
3933 sampler_ci.anisotropyEnable = VK_FALSE;
3934 sampler_ci.maxAnisotropy = 1;
3935 sampler_ci.compareEnable = VK_FALSE;
3936 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
3937 sampler_ci.minLod = 1.0;
3938 sampler_ci.maxLod = 1.0;
3939 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
3940 sampler_ci.unnormalizedCoordinates = VK_FALSE;
3941
3942 VkSampler sampler;
3943 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
3944 ASSERT_VK_SUCCESS(err);
3945
3946 VkDescriptorImageInfo info = {};
3947 info.sampler = sampler;
3948
3949 VkWriteDescriptorSet descriptor_write;
3950 memset(&descriptor_write, 0, sizeof(descriptor_write));
3951 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
3952 descriptor_write.dstSet = descriptorSet;
3953 descriptor_write.dstArrayElement =
3954 1; /* This index out of bounds for the update */
3955 descriptor_write.descriptorCount = 1;
3956 // This is the wrong type, but out of bounds will be flagged first
3957 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
3958 descriptor_write.pImageInfo = &info;
3959
3960 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
3961
3962 if (!m_errorMonitor->DesiredMsgFound()) {
3963 FAIL() << "Did not receive Error 'Descriptor update type of "
3964 "VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET is out of bounds for "
3965 "matching binding...'";
3966 m_errorMonitor->DumpFailureMsgs();
3967 }
3968
3969 vkDestroySampler(m_device->device(), sampler, NULL);
3970 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
3971 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
3972 }
3973
TEST_F(VkLayerTest,InvalidDSUpdateIndex)3974 TEST_F(VkLayerTest, InvalidDSUpdateIndex) {
3975 // Create layout w/ count of 1 and attempt update to that layout w/ binding
3976 // index 2
3977 VkResult err;
3978
3979 m_errorMonitor->SetDesiredFailureMsg(
3980 VK_DEBUG_REPORT_ERROR_BIT_EXT,
3981 " does not have binding to match update binding ");
3982
3983 ASSERT_NO_FATAL_FAILURE(InitState());
3984 // VkDescriptorSetObj descriptorSet(m_device);
3985 VkDescriptorPoolSize ds_type_count = {};
3986 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
3987 ds_type_count.descriptorCount = 1;
3988
3989 VkDescriptorPoolCreateInfo ds_pool_ci = {};
3990 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
3991 ds_pool_ci.pNext = NULL;
3992 ds_pool_ci.maxSets = 1;
3993 ds_pool_ci.poolSizeCount = 1;
3994 ds_pool_ci.pPoolSizes = &ds_type_count;
3995
3996 VkDescriptorPool ds_pool;
3997 err =
3998 vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
3999 ASSERT_VK_SUCCESS(err);
4000
4001 VkDescriptorSetLayoutBinding dsl_binding = {};
4002 dsl_binding.binding = 0;
4003 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
4004 dsl_binding.descriptorCount = 1;
4005 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
4006 dsl_binding.pImmutableSamplers = NULL;
4007
4008 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
4009 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
4010 ds_layout_ci.pNext = NULL;
4011 ds_layout_ci.bindingCount = 1;
4012 ds_layout_ci.pBindings = &dsl_binding;
4013 VkDescriptorSetLayout ds_layout;
4014 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
4015 &ds_layout);
4016 ASSERT_VK_SUCCESS(err);
4017
4018 VkDescriptorSet descriptorSet;
4019 VkDescriptorSetAllocateInfo alloc_info = {};
4020 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
4021 alloc_info.descriptorSetCount = 1;
4022 alloc_info.descriptorPool = ds_pool;
4023 alloc_info.pSetLayouts = &ds_layout;
4024 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info,
4025 &descriptorSet);
4026 ASSERT_VK_SUCCESS(err);
4027
4028 VkSamplerCreateInfo sampler_ci = {};
4029 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
4030 sampler_ci.pNext = NULL;
4031 sampler_ci.magFilter = VK_FILTER_NEAREST;
4032 sampler_ci.minFilter = VK_FILTER_NEAREST;
4033 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
4034 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
4035 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
4036 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
4037 sampler_ci.mipLodBias = 1.0;
4038 sampler_ci.anisotropyEnable = VK_FALSE;
4039 sampler_ci.maxAnisotropy = 1;
4040 sampler_ci.compareEnable = VK_FALSE;
4041 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
4042 sampler_ci.minLod = 1.0;
4043 sampler_ci.maxLod = 1.0;
4044 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
4045 sampler_ci.unnormalizedCoordinates = VK_FALSE;
4046
4047 VkSampler sampler;
4048 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
4049 ASSERT_VK_SUCCESS(err);
4050
4051 VkDescriptorImageInfo info = {};
4052 info.sampler = sampler;
4053
4054 VkWriteDescriptorSet descriptor_write;
4055 memset(&descriptor_write, 0, sizeof(descriptor_write));
4056 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
4057 descriptor_write.dstSet = descriptorSet;
4058 descriptor_write.dstBinding = 2;
4059 descriptor_write.descriptorCount = 1;
4060 // This is the wrong type, but out of bounds will be flagged first
4061 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
4062 descriptor_write.pImageInfo = &info;
4063
4064 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
4065
4066 if (!m_errorMonitor->DesiredMsgFound()) {
4067 FAIL() << "Did not receive Error 'Descriptor Set <blah> does not have "
4068 "binding to match update binding '";
4069 m_errorMonitor->DumpFailureMsgs();
4070 }
4071
4072 vkDestroySampler(m_device->device(), sampler, NULL);
4073 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
4074 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
4075 }
4076
TEST_F(VkLayerTest,InvalidDSUpdateStruct)4077 TEST_F(VkLayerTest, InvalidDSUpdateStruct) {
4078 // Call UpdateDS w/ struct type other than valid VK_STRUCTUR_TYPE_UPDATE_*
4079 // types
4080 VkResult err;
4081
4082 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
4083 "Unexpected UPDATE struct of type ");
4084
4085 ASSERT_NO_FATAL_FAILURE(InitState());
4086
4087 VkDescriptorPoolSize ds_type_count = {};
4088 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
4089 ds_type_count.descriptorCount = 1;
4090
4091 VkDescriptorPoolCreateInfo ds_pool_ci = {};
4092 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
4093 ds_pool_ci.pNext = NULL;
4094 ds_pool_ci.maxSets = 1;
4095 ds_pool_ci.poolSizeCount = 1;
4096 ds_pool_ci.pPoolSizes = &ds_type_count;
4097
4098 VkDescriptorPool ds_pool;
4099 err =
4100 vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
4101 ASSERT_VK_SUCCESS(err);
4102 VkDescriptorSetLayoutBinding dsl_binding = {};
4103 dsl_binding.binding = 0;
4104 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
4105 dsl_binding.descriptorCount = 1;
4106 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
4107 dsl_binding.pImmutableSamplers = NULL;
4108
4109 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
4110 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
4111 ds_layout_ci.pNext = NULL;
4112 ds_layout_ci.bindingCount = 1;
4113 ds_layout_ci.pBindings = &dsl_binding;
4114
4115 VkDescriptorSetLayout ds_layout;
4116 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
4117 &ds_layout);
4118 ASSERT_VK_SUCCESS(err);
4119
4120 VkDescriptorSet descriptorSet;
4121 VkDescriptorSetAllocateInfo alloc_info = {};
4122 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
4123 alloc_info.descriptorSetCount = 1;
4124 alloc_info.descriptorPool = ds_pool;
4125 alloc_info.pSetLayouts = &ds_layout;
4126 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info,
4127 &descriptorSet);
4128 ASSERT_VK_SUCCESS(err);
4129
4130 VkSamplerCreateInfo sampler_ci = {};
4131 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
4132 sampler_ci.pNext = NULL;
4133 sampler_ci.magFilter = VK_FILTER_NEAREST;
4134 sampler_ci.minFilter = VK_FILTER_NEAREST;
4135 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
4136 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
4137 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
4138 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
4139 sampler_ci.mipLodBias = 1.0;
4140 sampler_ci.anisotropyEnable = VK_FALSE;
4141 sampler_ci.maxAnisotropy = 1;
4142 sampler_ci.compareEnable = VK_FALSE;
4143 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
4144 sampler_ci.minLod = 1.0;
4145 sampler_ci.maxLod = 1.0;
4146 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
4147 sampler_ci.unnormalizedCoordinates = VK_FALSE;
4148 VkSampler sampler;
4149 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
4150 ASSERT_VK_SUCCESS(err);
4151
4152 VkDescriptorImageInfo info = {};
4153 info.sampler = sampler;
4154
4155 VkWriteDescriptorSet descriptor_write;
4156 memset(&descriptor_write, 0, sizeof(descriptor_write));
4157 descriptor_write.sType =
4158 (VkStructureType)0x99999999; /* Intentionally broken struct type */
4159 descriptor_write.dstSet = descriptorSet;
4160 descriptor_write.descriptorCount = 1;
4161 // This is the wrong type, but out of bounds will be flagged first
4162 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
4163 descriptor_write.pImageInfo = &info;
4164
4165 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
4166
4167 if (!m_errorMonitor->DesiredMsgFound()) {
4168 FAIL() << "Did not receive Error 'Unexpected UPDATE struct of type '";
4169 m_errorMonitor->DumpFailureMsgs();
4170 }
4171
4172 vkDestroySampler(m_device->device(), sampler, NULL);
4173 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
4174 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
4175 }
4176
TEST_F(VkLayerTest,SampleDescriptorUpdateError)4177 TEST_F(VkLayerTest, SampleDescriptorUpdateError) {
4178 // Create a single Sampler descriptor and send it an invalid Sampler
4179 VkResult err;
4180
4181 m_errorMonitor->SetDesiredFailureMsg(
4182 VK_DEBUG_REPORT_ERROR_BIT_EXT,
4183 "Attempt to update descriptor with invalid sampler 0xbaadbeef");
4184
4185 ASSERT_NO_FATAL_FAILURE(InitState());
4186 // TODO : Farm Descriptor setup code to helper function(s) to reduce copied
4187 // code
4188 VkDescriptorPoolSize ds_type_count = {};
4189 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLER;
4190 ds_type_count.descriptorCount = 1;
4191
4192 VkDescriptorPoolCreateInfo ds_pool_ci = {};
4193 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
4194 ds_pool_ci.pNext = NULL;
4195 ds_pool_ci.maxSets = 1;
4196 ds_pool_ci.poolSizeCount = 1;
4197 ds_pool_ci.pPoolSizes = &ds_type_count;
4198
4199 VkDescriptorPool ds_pool;
4200 err =
4201 vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
4202 ASSERT_VK_SUCCESS(err);
4203
4204 VkDescriptorSetLayoutBinding dsl_binding = {};
4205 dsl_binding.binding = 0;
4206 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
4207 dsl_binding.descriptorCount = 1;
4208 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
4209 dsl_binding.pImmutableSamplers = NULL;
4210
4211 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
4212 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
4213 ds_layout_ci.pNext = NULL;
4214 ds_layout_ci.bindingCount = 1;
4215 ds_layout_ci.pBindings = &dsl_binding;
4216 VkDescriptorSetLayout ds_layout;
4217 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
4218 &ds_layout);
4219 ASSERT_VK_SUCCESS(err);
4220
4221 VkDescriptorSet descriptorSet;
4222 VkDescriptorSetAllocateInfo alloc_info = {};
4223 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
4224 alloc_info.descriptorSetCount = 1;
4225 alloc_info.descriptorPool = ds_pool;
4226 alloc_info.pSetLayouts = &ds_layout;
4227 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info,
4228 &descriptorSet);
4229 ASSERT_VK_SUCCESS(err);
4230
4231 VkSampler sampler =
4232 (VkSampler)((size_t)0xbaadbeef); // Sampler with invalid handle
4233
4234 VkDescriptorImageInfo descriptor_info;
4235 memset(&descriptor_info, 0, sizeof(VkDescriptorImageInfo));
4236 descriptor_info.sampler = sampler;
4237
4238 VkWriteDescriptorSet descriptor_write;
4239 memset(&descriptor_write, 0, sizeof(descriptor_write));
4240 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
4241 descriptor_write.dstSet = descriptorSet;
4242 descriptor_write.dstBinding = 0;
4243 descriptor_write.descriptorCount = 1;
4244 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
4245 descriptor_write.pImageInfo = &descriptor_info;
4246
4247 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
4248
4249 if (!m_errorMonitor->DesiredMsgFound()) {
4250 FAIL() << "Did not receive Error 'Attempt to update descriptor with "
4251 "invalid sampler...'";
4252 m_errorMonitor->DumpFailureMsgs();
4253 }
4254
4255 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
4256 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
4257 }
4258
TEST_F(VkLayerTest,ImageViewDescriptorUpdateError)4259 TEST_F(VkLayerTest, ImageViewDescriptorUpdateError) {
4260 // Create a single combined Image/Sampler descriptor and send it an invalid
4261 // imageView
4262 VkResult err;
4263
4264 m_errorMonitor->SetDesiredFailureMsg(
4265 VK_DEBUG_REPORT_ERROR_BIT_EXT,
4266 "Attempt to update descriptor with invalid imageView 0xbaadbeef");
4267
4268 ASSERT_NO_FATAL_FAILURE(InitState());
4269 VkDescriptorPoolSize ds_type_count = {};
4270 ds_type_count.type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
4271 ds_type_count.descriptorCount = 1;
4272
4273 VkDescriptorPoolCreateInfo ds_pool_ci = {};
4274 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
4275 ds_pool_ci.pNext = NULL;
4276 ds_pool_ci.maxSets = 1;
4277 ds_pool_ci.poolSizeCount = 1;
4278 ds_pool_ci.pPoolSizes = &ds_type_count;
4279
4280 VkDescriptorPool ds_pool;
4281 err =
4282 vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
4283 ASSERT_VK_SUCCESS(err);
4284
4285 VkDescriptorSetLayoutBinding dsl_binding = {};
4286 dsl_binding.binding = 0;
4287 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
4288 dsl_binding.descriptorCount = 1;
4289 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
4290 dsl_binding.pImmutableSamplers = NULL;
4291
4292 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
4293 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
4294 ds_layout_ci.pNext = NULL;
4295 ds_layout_ci.bindingCount = 1;
4296 ds_layout_ci.pBindings = &dsl_binding;
4297 VkDescriptorSetLayout ds_layout;
4298 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
4299 &ds_layout);
4300 ASSERT_VK_SUCCESS(err);
4301
4302 VkDescriptorSet descriptorSet;
4303 VkDescriptorSetAllocateInfo alloc_info = {};
4304 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
4305 alloc_info.descriptorSetCount = 1;
4306 alloc_info.descriptorPool = ds_pool;
4307 alloc_info.pSetLayouts = &ds_layout;
4308 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info,
4309 &descriptorSet);
4310 ASSERT_VK_SUCCESS(err);
4311
4312 VkSamplerCreateInfo sampler_ci = {};
4313 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
4314 sampler_ci.pNext = NULL;
4315 sampler_ci.magFilter = VK_FILTER_NEAREST;
4316 sampler_ci.minFilter = VK_FILTER_NEAREST;
4317 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
4318 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
4319 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
4320 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
4321 sampler_ci.mipLodBias = 1.0;
4322 sampler_ci.anisotropyEnable = VK_FALSE;
4323 sampler_ci.maxAnisotropy = 1;
4324 sampler_ci.compareEnable = VK_FALSE;
4325 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
4326 sampler_ci.minLod = 1.0;
4327 sampler_ci.maxLod = 1.0;
4328 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
4329 sampler_ci.unnormalizedCoordinates = VK_FALSE;
4330
4331 VkSampler sampler;
4332 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
4333 ASSERT_VK_SUCCESS(err);
4334
4335 VkImageView view =
4336 (VkImageView)((size_t)0xbaadbeef); // invalid imageView object
4337
4338 VkDescriptorImageInfo descriptor_info;
4339 memset(&descriptor_info, 0, sizeof(VkDescriptorImageInfo));
4340 descriptor_info.sampler = sampler;
4341 descriptor_info.imageView = view;
4342
4343 VkWriteDescriptorSet descriptor_write;
4344 memset(&descriptor_write, 0, sizeof(descriptor_write));
4345 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
4346 descriptor_write.dstSet = descriptorSet;
4347 descriptor_write.dstBinding = 0;
4348 descriptor_write.descriptorCount = 1;
4349 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
4350 descriptor_write.pImageInfo = &descriptor_info;
4351
4352 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
4353
4354 if (!m_errorMonitor->DesiredMsgFound()) {
4355 FAIL() << "Did not receive Error 'Attempt to update descriptor with "
4356 "invalid imageView...'";
4357 m_errorMonitor->DumpFailureMsgs();
4358 }
4359
4360 vkDestroySampler(m_device->device(), sampler, NULL);
4361 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
4362 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
4363 }
4364
TEST_F(VkLayerTest,CopyDescriptorUpdateErrors)4365 TEST_F(VkLayerTest, CopyDescriptorUpdateErrors) {
4366 // Create DS w/ layout of 2 types, write update 1 and attempt to copy-update
4367 // into the other
4368 VkResult err;
4369
4370 m_errorMonitor->SetDesiredFailureMsg(
4371 VK_DEBUG_REPORT_ERROR_BIT_EXT, "Copy descriptor update index 0, update "
4372 "count #1, has src update descriptor "
4373 "type VK_DESCRIPTOR_TYPE_SAMPLER ");
4374
4375 ASSERT_NO_FATAL_FAILURE(InitState());
4376 // VkDescriptorSetObj descriptorSet(m_device);
4377 VkDescriptorPoolSize ds_type_count[2] = {};
4378 ds_type_count[0].type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
4379 ds_type_count[0].descriptorCount = 1;
4380 ds_type_count[1].type = VK_DESCRIPTOR_TYPE_SAMPLER;
4381 ds_type_count[1].descriptorCount = 1;
4382
4383 VkDescriptorPoolCreateInfo ds_pool_ci = {};
4384 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
4385 ds_pool_ci.pNext = NULL;
4386 ds_pool_ci.maxSets = 1;
4387 ds_pool_ci.poolSizeCount = 2;
4388 ds_pool_ci.pPoolSizes = ds_type_count;
4389
4390 VkDescriptorPool ds_pool;
4391 err =
4392 vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
4393 ASSERT_VK_SUCCESS(err);
4394 VkDescriptorSetLayoutBinding dsl_binding[2] = {};
4395 dsl_binding[0].binding = 0;
4396 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
4397 dsl_binding[0].descriptorCount = 1;
4398 dsl_binding[0].stageFlags = VK_SHADER_STAGE_ALL;
4399 dsl_binding[0].pImmutableSamplers = NULL;
4400 dsl_binding[1].binding = 1;
4401 dsl_binding[1].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
4402 dsl_binding[1].descriptorCount = 1;
4403 dsl_binding[1].stageFlags = VK_SHADER_STAGE_ALL;
4404 dsl_binding[1].pImmutableSamplers = NULL;
4405
4406 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
4407 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
4408 ds_layout_ci.pNext = NULL;
4409 ds_layout_ci.bindingCount = 2;
4410 ds_layout_ci.pBindings = dsl_binding;
4411
4412 VkDescriptorSetLayout ds_layout;
4413 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
4414 &ds_layout);
4415 ASSERT_VK_SUCCESS(err);
4416
4417 VkDescriptorSet descriptorSet;
4418 VkDescriptorSetAllocateInfo alloc_info = {};
4419 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
4420 alloc_info.descriptorSetCount = 1;
4421 alloc_info.descriptorPool = ds_pool;
4422 alloc_info.pSetLayouts = &ds_layout;
4423 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info,
4424 &descriptorSet);
4425 ASSERT_VK_SUCCESS(err);
4426
4427 VkSamplerCreateInfo sampler_ci = {};
4428 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
4429 sampler_ci.pNext = NULL;
4430 sampler_ci.magFilter = VK_FILTER_NEAREST;
4431 sampler_ci.minFilter = VK_FILTER_NEAREST;
4432 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
4433 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
4434 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
4435 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
4436 sampler_ci.mipLodBias = 1.0;
4437 sampler_ci.anisotropyEnable = VK_FALSE;
4438 sampler_ci.maxAnisotropy = 1;
4439 sampler_ci.compareEnable = VK_FALSE;
4440 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
4441 sampler_ci.minLod = 1.0;
4442 sampler_ci.maxLod = 1.0;
4443 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
4444 sampler_ci.unnormalizedCoordinates = VK_FALSE;
4445
4446 VkSampler sampler;
4447 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
4448 ASSERT_VK_SUCCESS(err);
4449
4450 VkDescriptorImageInfo info = {};
4451 info.sampler = sampler;
4452
4453 VkWriteDescriptorSet descriptor_write;
4454 memset(&descriptor_write, 0, sizeof(VkWriteDescriptorSet));
4455 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
4456 descriptor_write.dstSet = descriptorSet;
4457 descriptor_write.dstBinding = 1; // SAMPLER binding from layout above
4458 descriptor_write.descriptorCount = 1;
4459 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
4460 descriptor_write.pImageInfo = &info;
4461 // This write update should succeed
4462 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
4463 // Now perform a copy update that fails due to type mismatch
4464 VkCopyDescriptorSet copy_ds_update;
4465 memset(©_ds_update, 0, sizeof(VkCopyDescriptorSet));
4466 copy_ds_update.sType = VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET;
4467 copy_ds_update.srcSet = descriptorSet;
4468 copy_ds_update.srcBinding = 1; // copy from SAMPLER binding
4469 copy_ds_update.dstSet = descriptorSet;
4470 copy_ds_update.dstBinding = 0; // ERROR : copy to UNIFORM binding
4471 copy_ds_update.descriptorCount = 1; // copy 1 descriptor
4472 vkUpdateDescriptorSets(m_device->device(), 0, NULL, 1, ©_ds_update);
4473
4474 if (!m_errorMonitor->DesiredMsgFound()) {
4475 FAIL() << "Did not receive Error 'Copy descriptor update index 0, "
4476 "update count #1, has src update descriptor "
4477 "type_DESCRIPTOR_TYPE_SAMPLER'";
4478 m_errorMonitor->DumpFailureMsgs();
4479 }
4480 // Now perform a copy update that fails due to binding out of bounds
4481 m_errorMonitor->SetDesiredFailureMsg(
4482 VK_DEBUG_REPORT_ERROR_BIT_EXT,
4483 "Copy descriptor update 0 has srcBinding 3 which is out of bounds ");
4484 memset(©_ds_update, 0, sizeof(VkCopyDescriptorSet));
4485 copy_ds_update.sType = VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET;
4486 copy_ds_update.srcSet = descriptorSet;
4487 copy_ds_update.srcBinding =
4488 3; // ERROR : Invalid binding for matching layout
4489 copy_ds_update.dstSet = descriptorSet;
4490 copy_ds_update.dstBinding = 0;
4491 copy_ds_update.descriptorCount = 1; // copy 1 descriptor
4492 vkUpdateDescriptorSets(m_device->device(), 0, NULL, 1, ©_ds_update);
4493
4494 if (!m_errorMonitor->DesiredMsgFound()) {
4495 FAIL() << "Did not receive Error 'Copy descriptor update 0 has "
4496 "srcBinding 3 which is out of bounds...'";
4497 m_errorMonitor->DumpFailureMsgs();
4498 }
4499
4500 // Now perform a copy update that fails due to binding out of bounds
4501 m_errorMonitor->SetDesiredFailureMsg(
4502 VK_DEBUG_REPORT_ERROR_BIT_EXT,
4503 "Copy descriptor src update is out of bounds for matching binding 1 ");
4504
4505 memset(©_ds_update, 0, sizeof(VkCopyDescriptorSet));
4506 copy_ds_update.sType = VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET;
4507 copy_ds_update.srcSet = descriptorSet;
4508 copy_ds_update.srcBinding = 1;
4509 copy_ds_update.dstSet = descriptorSet;
4510 copy_ds_update.dstBinding = 0;
4511 copy_ds_update.descriptorCount =
4512 5; // ERROR copy 5 descriptors (out of bounds for layout)
4513 vkUpdateDescriptorSets(m_device->device(), 0, NULL, 1, ©_ds_update);
4514
4515 if (!m_errorMonitor->DesiredMsgFound()) {
4516 FAIL() << "Did not receive Error 'Copy descriptor src update is out of "
4517 "bounds for matching binding 1...'";
4518 m_errorMonitor->DumpFailureMsgs();
4519 }
4520
4521 vkDestroySampler(m_device->device(), sampler, NULL);
4522 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
4523 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
4524 }
4525
TEST_F(VkLayerTest,NumSamplesMismatch)4526 TEST_F(VkLayerTest, NumSamplesMismatch) {
4527 // Create CommandBuffer where MSAA samples doesn't match RenderPass
4528 // sampleCount
4529 VkResult err;
4530
4531 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
4532 "Num samples mismatch! ");
4533
4534 ASSERT_NO_FATAL_FAILURE(InitState());
4535 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
4536 VkDescriptorPoolSize ds_type_count = {};
4537 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
4538 ds_type_count.descriptorCount = 1;
4539
4540 VkDescriptorPoolCreateInfo ds_pool_ci = {};
4541 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
4542 ds_pool_ci.pNext = NULL;
4543 ds_pool_ci.maxSets = 1;
4544 ds_pool_ci.poolSizeCount = 1;
4545 ds_pool_ci.pPoolSizes = &ds_type_count;
4546
4547 VkDescriptorPool ds_pool;
4548 err =
4549 vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
4550 ASSERT_VK_SUCCESS(err);
4551
4552 VkDescriptorSetLayoutBinding dsl_binding = {};
4553 dsl_binding.binding = 0;
4554 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
4555 dsl_binding.descriptorCount = 1;
4556 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
4557 dsl_binding.pImmutableSamplers = NULL;
4558
4559 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
4560 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
4561 ds_layout_ci.pNext = NULL;
4562 ds_layout_ci.bindingCount = 1;
4563 ds_layout_ci.pBindings = &dsl_binding;
4564
4565 VkDescriptorSetLayout ds_layout;
4566 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
4567 &ds_layout);
4568 ASSERT_VK_SUCCESS(err);
4569
4570 VkDescriptorSet descriptorSet;
4571 VkDescriptorSetAllocateInfo alloc_info = {};
4572 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
4573 alloc_info.descriptorSetCount = 1;
4574 alloc_info.descriptorPool = ds_pool;
4575 alloc_info.pSetLayouts = &ds_layout;
4576 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info,
4577 &descriptorSet);
4578 ASSERT_VK_SUCCESS(err);
4579
4580 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
4581 pipe_ms_state_ci.sType =
4582 VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
4583 pipe_ms_state_ci.pNext = NULL;
4584 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_4_BIT;
4585 pipe_ms_state_ci.sampleShadingEnable = 0;
4586 pipe_ms_state_ci.minSampleShading = 1.0;
4587 pipe_ms_state_ci.pSampleMask = NULL;
4588
4589 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
4590 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
4591 pipeline_layout_ci.pNext = NULL;
4592 pipeline_layout_ci.setLayoutCount = 1;
4593 pipeline_layout_ci.pSetLayouts = &ds_layout;
4594
4595 VkPipelineLayout pipeline_layout;
4596 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL,
4597 &pipeline_layout);
4598 ASSERT_VK_SUCCESS(err);
4599
4600 VkShaderObj vs(m_device, bindStateVertShaderText,
4601 VK_SHADER_STAGE_VERTEX_BIT, this);
4602 VkShaderObj fs(m_device, bindStateFragShaderText,
4603 VK_SHADER_STAGE_FRAGMENT_BIT,
4604 this); // TODO - We shouldn't need a fragment shader
4605 // but add it to be able to run on more devices
4606 VkPipelineObj pipe(m_device);
4607 pipe.AddShader(&vs);
4608 pipe.AddShader(&fs);
4609 pipe.SetMSAA(&pipe_ms_state_ci);
4610 pipe.CreateVKPipeline(pipeline_layout, renderPass());
4611
4612 BeginCommandBuffer();
4613 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(),
4614 VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
4615
4616 if (!m_errorMonitor->DesiredMsgFound()) {
4617 FAIL() << "Did not recieve Error 'Num samples mismatch!...'";
4618 m_errorMonitor->DumpFailureMsgs();
4619 }
4620
4621 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
4622 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
4623 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
4624 }
4625
TEST_F(VkLayerTest,ClearCmdNoDraw)4626 TEST_F(VkLayerTest, ClearCmdNoDraw) {
4627 // Create CommandBuffer where we add ClearCmd for FB Color attachment prior
4628 // to issuing a Draw
4629 VkResult err;
4630
4631 // TODO: verify that this matches layer
4632 m_errorMonitor->SetDesiredFailureMsg(
4633 VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
4634 "vkCmdClearAttachments() issued on CB object ");
4635
4636 ASSERT_NO_FATAL_FAILURE(InitState());
4637 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
4638
4639 VkDescriptorPoolSize ds_type_count = {};
4640 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
4641 ds_type_count.descriptorCount = 1;
4642
4643 VkDescriptorPoolCreateInfo ds_pool_ci = {};
4644 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
4645 ds_pool_ci.pNext = NULL;
4646 ds_pool_ci.maxSets = 1;
4647 ds_pool_ci.poolSizeCount = 1;
4648 ds_pool_ci.pPoolSizes = &ds_type_count;
4649
4650 VkDescriptorPool ds_pool;
4651 err =
4652 vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
4653 ASSERT_VK_SUCCESS(err);
4654
4655 VkDescriptorSetLayoutBinding dsl_binding = {};
4656 dsl_binding.binding = 0;
4657 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
4658 dsl_binding.descriptorCount = 1;
4659 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
4660 dsl_binding.pImmutableSamplers = NULL;
4661
4662 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
4663 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
4664 ds_layout_ci.pNext = NULL;
4665 ds_layout_ci.bindingCount = 1;
4666 ds_layout_ci.pBindings = &dsl_binding;
4667
4668 VkDescriptorSetLayout ds_layout;
4669 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
4670 &ds_layout);
4671 ASSERT_VK_SUCCESS(err);
4672
4673 VkDescriptorSet descriptorSet;
4674 VkDescriptorSetAllocateInfo alloc_info = {};
4675 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
4676 alloc_info.descriptorSetCount = 1;
4677 alloc_info.descriptorPool = ds_pool;
4678 alloc_info.pSetLayouts = &ds_layout;
4679 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info,
4680 &descriptorSet);
4681 ASSERT_VK_SUCCESS(err);
4682
4683 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
4684 pipe_ms_state_ci.sType =
4685 VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
4686 pipe_ms_state_ci.pNext = NULL;
4687 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_4_BIT;
4688 pipe_ms_state_ci.sampleShadingEnable = 0;
4689 pipe_ms_state_ci.minSampleShading = 1.0;
4690 pipe_ms_state_ci.pSampleMask = NULL;
4691
4692 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
4693 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
4694 pipeline_layout_ci.pNext = NULL;
4695 pipeline_layout_ci.setLayoutCount = 1;
4696 pipeline_layout_ci.pSetLayouts = &ds_layout;
4697
4698 VkPipelineLayout pipeline_layout;
4699 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL,
4700 &pipeline_layout);
4701 ASSERT_VK_SUCCESS(err);
4702
4703 VkShaderObj vs(m_device, bindStateVertShaderText,
4704 VK_SHADER_STAGE_VERTEX_BIT, this);
4705 // TODO - We shouldn't need a fragment shader but add it to be able to run
4706 // on more devices
4707 VkShaderObj fs(m_device, bindStateFragShaderText,
4708 VK_SHADER_STAGE_FRAGMENT_BIT, this);
4709
4710 VkPipelineObj pipe(m_device);
4711 pipe.AddShader(&vs);
4712 pipe.AddShader(&fs);
4713 pipe.SetMSAA(&pipe_ms_state_ci);
4714 pipe.CreateVKPipeline(pipeline_layout, renderPass());
4715
4716 BeginCommandBuffer();
4717
4718 // Main thing we care about for this test is that the VkImage obj we're
4719 // clearing matches Color Attachment of FB
4720 // Also pass down other dummy params to keep driver and paramchecker happy
4721 VkClearAttachment color_attachment;
4722 color_attachment.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
4723 color_attachment.clearValue.color.float32[0] = 1.0;
4724 color_attachment.clearValue.color.float32[1] = 1.0;
4725 color_attachment.clearValue.color.float32[2] = 1.0;
4726 color_attachment.clearValue.color.float32[3] = 1.0;
4727 color_attachment.colorAttachment = 0;
4728 VkClearRect clear_rect = {
4729 {{0, 0}, {(uint32_t)m_width, (uint32_t)m_height}}};
4730
4731 vkCmdClearAttachments(m_commandBuffer->GetBufferHandle(), 1,
4732 &color_attachment, 1, &clear_rect);
4733
4734 if (!m_errorMonitor->DesiredMsgFound()) {
4735 FAIL() << "Did not receive Error 'vkCommandClearAttachments() issued "
4736 "on CB object...'";
4737 m_errorMonitor->DumpFailureMsgs();
4738 }
4739
4740 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
4741 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
4742 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
4743 }
4744
TEST_F(VkLayerTest,VtxBufferBadIndex)4745 TEST_F(VkLayerTest, VtxBufferBadIndex) {
4746 VkResult err;
4747
4748 m_errorMonitor->SetDesiredFailureMsg(
4749 VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
4750 "but no vertex buffers are attached to this Pipeline State Object");
4751
4752 ASSERT_NO_FATAL_FAILURE(InitState());
4753 ASSERT_NO_FATAL_FAILURE(InitViewport());
4754 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
4755
4756 VkDescriptorPoolSize ds_type_count = {};
4757 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
4758 ds_type_count.descriptorCount = 1;
4759
4760 VkDescriptorPoolCreateInfo ds_pool_ci = {};
4761 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
4762 ds_pool_ci.pNext = NULL;
4763 ds_pool_ci.maxSets = 1;
4764 ds_pool_ci.poolSizeCount = 1;
4765 ds_pool_ci.pPoolSizes = &ds_type_count;
4766
4767 VkDescriptorPool ds_pool;
4768 err =
4769 vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
4770 ASSERT_VK_SUCCESS(err);
4771
4772 VkDescriptorSetLayoutBinding dsl_binding = {};
4773 dsl_binding.binding = 0;
4774 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
4775 dsl_binding.descriptorCount = 1;
4776 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
4777 dsl_binding.pImmutableSamplers = NULL;
4778
4779 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
4780 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
4781 ds_layout_ci.pNext = NULL;
4782 ds_layout_ci.bindingCount = 1;
4783 ds_layout_ci.pBindings = &dsl_binding;
4784
4785 VkDescriptorSetLayout ds_layout;
4786 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
4787 &ds_layout);
4788 ASSERT_VK_SUCCESS(err);
4789
4790 VkDescriptorSet descriptorSet;
4791 VkDescriptorSetAllocateInfo alloc_info = {};
4792 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
4793 alloc_info.descriptorSetCount = 1;
4794 alloc_info.descriptorPool = ds_pool;
4795 alloc_info.pSetLayouts = &ds_layout;
4796 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info,
4797 &descriptorSet);
4798 ASSERT_VK_SUCCESS(err);
4799
4800 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
4801 pipe_ms_state_ci.sType =
4802 VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
4803 pipe_ms_state_ci.pNext = NULL;
4804 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
4805 pipe_ms_state_ci.sampleShadingEnable = 0;
4806 pipe_ms_state_ci.minSampleShading = 1.0;
4807 pipe_ms_state_ci.pSampleMask = NULL;
4808
4809 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
4810 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
4811 pipeline_layout_ci.pNext = NULL;
4812 pipeline_layout_ci.setLayoutCount = 1;
4813 pipeline_layout_ci.pSetLayouts = &ds_layout;
4814 VkPipelineLayout pipeline_layout;
4815
4816 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL,
4817 &pipeline_layout);
4818 ASSERT_VK_SUCCESS(err);
4819
4820 VkShaderObj vs(m_device, bindStateVertShaderText,
4821 VK_SHADER_STAGE_VERTEX_BIT, this);
4822 VkShaderObj fs(m_device, bindStateFragShaderText,
4823 VK_SHADER_STAGE_FRAGMENT_BIT,
4824 this); // TODO - We shouldn't need a fragment shader
4825 // but add it to be able to run on more devices
4826 VkPipelineObj pipe(m_device);
4827 pipe.AddShader(&vs);
4828 pipe.AddShader(&fs);
4829 pipe.SetMSAA(&pipe_ms_state_ci);
4830 pipe.SetViewport(m_viewports);
4831 pipe.SetScissor(m_scissors);
4832 pipe.CreateVKPipeline(pipeline_layout, renderPass());
4833
4834 BeginCommandBuffer();
4835 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(),
4836 VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
4837 // Don't care about actual data, just need to get to draw to flag error
4838 static const float vbo_data[3] = {1.f, 0.f, 1.f};
4839 VkConstantBufferObj vbo(m_device, sizeof(vbo_data), sizeof(float),
4840 (const void *)&vbo_data);
4841 BindVertexBuffer(&vbo, (VkDeviceSize)0, 1); // VBO idx 1, but no VBO in PSO
4842 Draw(1, 0, 0, 0);
4843
4844 if (!m_errorMonitor->DesiredMsgFound()) {
4845 FAIL() << "Did not receive Error 'Vtx Buffer Index 0 was bound, but no "
4846 "vtx buffers are attached to PSO.'";
4847 m_errorMonitor->DumpFailureMsgs();
4848 }
4849
4850 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
4851 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
4852 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
4853 }
4854 #endif // DRAW_STATE_TESTS
4855
4856 #if THREADING_TESTS
4857 #if GTEST_IS_THREADSAFE
4858 struct thread_data_struct {
4859 VkCommandBuffer commandBuffer;
4860 VkEvent event;
4861 bool bailout;
4862 };
4863
AddToCommandBuffer(void * arg)4864 extern "C" void *AddToCommandBuffer(void *arg) {
4865 struct thread_data_struct *data = (struct thread_data_struct *)arg;
4866
4867 for (int i = 0; i < 10000; i++) {
4868 vkCmdSetEvent(data->commandBuffer, data->event,
4869 VK_PIPELINE_STAGE_ALL_COMMANDS_BIT);
4870 if (data->bailout) {
4871 break;
4872 }
4873 }
4874 return NULL;
4875 }
4876
TEST_F(VkLayerTest,ThreadCommandBufferCollision)4877 TEST_F(VkLayerTest, ThreadCommandBufferCollision) {
4878 test_platform_thread thread;
4879
4880 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
4881 "THREADING ERROR");
4882
4883 ASSERT_NO_FATAL_FAILURE(InitState());
4884 ASSERT_NO_FATAL_FAILURE(InitViewport());
4885 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
4886
4887 // Calls AllocateCommandBuffers
4888 VkCommandBufferObj commandBuffer(m_device, m_commandPool);
4889
4890 // Avoid creating RenderPass
4891 commandBuffer.BeginCommandBuffer();
4892
4893 VkEventCreateInfo event_info;
4894 VkEvent event;
4895 VkResult err;
4896
4897 memset(&event_info, 0, sizeof(event_info));
4898 event_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
4899
4900 err = vkCreateEvent(device(), &event_info, NULL, &event);
4901 ASSERT_VK_SUCCESS(err);
4902
4903 err = vkResetEvent(device(), event);
4904 ASSERT_VK_SUCCESS(err);
4905
4906 struct thread_data_struct data;
4907 data.commandBuffer = commandBuffer.GetBufferHandle();
4908 data.event = event;
4909 data.bailout = false;
4910 m_errorMonitor->SetBailout(&data.bailout);
4911 // Add many entries to command buffer from another thread.
4912 test_platform_thread_create(&thread, AddToCommandBuffer, (void *)&data);
4913 // Add many entries to command buffer from this thread at the same time.
4914 AddToCommandBuffer(&data);
4915
4916 test_platform_thread_join(thread, NULL);
4917 commandBuffer.EndCommandBuffer();
4918
4919 m_errorMonitor->SetBailout(NULL);
4920
4921 if (!m_errorMonitor->DesiredMsgFound()) {
4922 FAIL() << "Did not receive Error 'THREADING ERROR' from using one "
4923 "VkCommandBufferObj in two threads";
4924 m_errorMonitor->DumpFailureMsgs();
4925 }
4926
4927 vkDestroyEvent(device(), event, NULL);
4928 }
4929 #endif // GTEST_IS_THREADSAFE
4930 #endif // THREADING_TESTS
4931
4932 #if SHADER_CHECKER_TESTS
TEST_F(VkLayerTest,InvalidSPIRVCodeSize)4933 TEST_F(VkLayerTest, InvalidSPIRVCodeSize) {
4934 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
4935 "Shader is not SPIR-V");
4936
4937 ASSERT_NO_FATAL_FAILURE(InitState());
4938 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
4939
4940 VkShaderModule module;
4941 VkShaderModuleCreateInfo moduleCreateInfo;
4942 struct icd_spv_header spv;
4943
4944 spv.magic = ICD_SPV_MAGIC;
4945 spv.version = ICD_SPV_VERSION;
4946 spv.gen_magic = 0;
4947
4948 moduleCreateInfo.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;
4949 moduleCreateInfo.pNext = NULL;
4950 moduleCreateInfo.pCode = (const uint32_t *)&spv;
4951 moduleCreateInfo.codeSize = 4;
4952 moduleCreateInfo.flags = 0;
4953 vkCreateShaderModule(m_device->device(), &moduleCreateInfo, NULL, &module);
4954
4955 if (!m_errorMonitor->DesiredMsgFound()) {
4956 FAIL() << "Did not recieive Error 'Shader is not SPIR-V'";
4957 m_errorMonitor->DumpFailureMsgs();
4958 }
4959 }
4960
TEST_F(VkLayerTest,InvalidSPIRVMagic)4961 TEST_F(VkLayerTest, InvalidSPIRVMagic) {
4962 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
4963 "Shader is not SPIR-V");
4964
4965 ASSERT_NO_FATAL_FAILURE(InitState());
4966 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
4967
4968 VkShaderModule module;
4969 VkShaderModuleCreateInfo moduleCreateInfo;
4970 struct icd_spv_header spv;
4971
4972 spv.magic = ~ICD_SPV_MAGIC;
4973 spv.version = ICD_SPV_VERSION;
4974 spv.gen_magic = 0;
4975
4976 moduleCreateInfo.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;
4977 moduleCreateInfo.pNext = NULL;
4978 moduleCreateInfo.pCode = (const uint32_t *)&spv;
4979 moduleCreateInfo.codeSize = sizeof(spv) + 10;
4980 moduleCreateInfo.flags = 0;
4981 vkCreateShaderModule(m_device->device(), &moduleCreateInfo, NULL, &module);
4982
4983 if (!m_errorMonitor->DesiredMsgFound()) {
4984 FAIL() << "Did not recieive Error 'Shader is not SPIR-V'";
4985 m_errorMonitor->DumpFailureMsgs();
4986 }
4987 }
4988
TEST_F(VkLayerTest,InvalidSPIRVVersion)4989 TEST_F(VkLayerTest, InvalidSPIRVVersion) {
4990 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
4991 "Shader is not SPIR-V");
4992
4993 ASSERT_NO_FATAL_FAILURE(InitState());
4994 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
4995
4996 VkShaderModule module;
4997 VkShaderModuleCreateInfo moduleCreateInfo;
4998 struct icd_spv_header spv;
4999
5000 spv.magic = ICD_SPV_MAGIC;
5001 spv.version = ~ICD_SPV_VERSION;
5002 spv.gen_magic = 0;
5003
5004 moduleCreateInfo.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;
5005 moduleCreateInfo.pNext = NULL;
5006
5007 moduleCreateInfo.pCode = (const uint32_t *)&spv;
5008 moduleCreateInfo.codeSize = sizeof(spv) + 10;
5009 moduleCreateInfo.flags = 0;
5010 vkCreateShaderModule(m_device->device(), &moduleCreateInfo, NULL, &module);
5011
5012 if (!m_errorMonitor->DesiredMsgFound()) {
5013 FAIL() << "Did not recieive Error 'Shader is not SPIR-V'";
5014 m_errorMonitor->DumpFailureMsgs();
5015 }
5016 }
5017
TEST_F(VkLayerTest,CreatePipelineVertexOutputNotConsumed)5018 TEST_F(VkLayerTest, CreatePipelineVertexOutputNotConsumed) {
5019 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
5020 "not consumed by fragment shader");
5021
5022 ASSERT_NO_FATAL_FAILURE(InitState());
5023 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
5024
5025 char const *vsSource =
5026 "#version 400\n"
5027 "#extension GL_ARB_separate_shader_objects: require\n"
5028 "#extension GL_ARB_shading_language_420pack: require\n"
5029 "\n"
5030 "layout(location=0) out float x;\n"
5031 "out gl_PerVertex {\n"
5032 " vec4 gl_Position;\n"
5033 "};\n"
5034 "void main(){\n"
5035 " gl_Position = vec4(1);\n"
5036 " x = 0;\n"
5037 "}\n";
5038 char const *fsSource =
5039 "#version 400\n"
5040 "#extension GL_ARB_separate_shader_objects: require\n"
5041 "#extension GL_ARB_shading_language_420pack: require\n"
5042 "\n"
5043 "layout(location=0) out vec4 color;\n"
5044 "void main(){\n"
5045 " color = vec4(1);\n"
5046 "}\n";
5047
5048 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
5049 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
5050
5051 VkPipelineObj pipe(m_device);
5052 pipe.AddColorAttachment();
5053 pipe.AddShader(&vs);
5054 pipe.AddShader(&fs);
5055
5056 VkDescriptorSetObj descriptorSet(m_device);
5057 descriptorSet.AppendDummy();
5058 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
5059
5060 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
5061
5062 if (!m_errorMonitor->DesiredMsgFound()) {
5063 FAIL() << "Did not receive Warning 'not consumed by fragment shader'";
5064 m_errorMonitor->DumpFailureMsgs();
5065 }
5066 }
5067
TEST_F(VkLayerTest,CreatePipelineFragmentInputNotProvided)5068 TEST_F(VkLayerTest, CreatePipelineFragmentInputNotProvided) {
5069 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
5070 "not written by vertex shader");
5071
5072 ASSERT_NO_FATAL_FAILURE(InitState());
5073 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
5074
5075 char const *vsSource =
5076 "#version 400\n"
5077 "#extension GL_ARB_separate_shader_objects: require\n"
5078 "#extension GL_ARB_shading_language_420pack: require\n"
5079 "\n"
5080 "out gl_PerVertex {\n"
5081 " vec4 gl_Position;\n"
5082 "};\n"
5083 "void main(){\n"
5084 " gl_Position = vec4(1);\n"
5085 "}\n";
5086 char const *fsSource =
5087 "#version 400\n"
5088 "#extension GL_ARB_separate_shader_objects: require\n"
5089 "#extension GL_ARB_shading_language_420pack: require\n"
5090 "\n"
5091 "layout(location=0) in float x;\n"
5092 "layout(location=0) out vec4 color;\n"
5093 "void main(){\n"
5094 " color = vec4(x);\n"
5095 "}\n";
5096
5097 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
5098 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
5099
5100 VkPipelineObj pipe(m_device);
5101 pipe.AddColorAttachment();
5102 pipe.AddShader(&vs);
5103 pipe.AddShader(&fs);
5104
5105 VkDescriptorSetObj descriptorSet(m_device);
5106 descriptorSet.AppendDummy();
5107 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
5108
5109 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
5110
5111 if (!m_errorMonitor->DesiredMsgFound()) {
5112 FAIL() << "Did not receive Error 'not written by vertex shader'";
5113 m_errorMonitor->DumpFailureMsgs();
5114 }
5115 }
5116
TEST_F(VkLayerTest,CreatePipelineFragmentInputNotProvidedInBlock)5117 TEST_F(VkLayerTest, CreatePipelineFragmentInputNotProvidedInBlock) {
5118 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
5119 "not written by vertex shader");
5120
5121 ASSERT_NO_FATAL_FAILURE(InitState());
5122 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
5123
5124 char const *vsSource =
5125 "#version 400\n"
5126 "#extension GL_ARB_separate_shader_objects: require\n"
5127 "#extension GL_ARB_shading_language_420pack: require\n"
5128 "\n"
5129 "out gl_PerVertex {\n"
5130 " vec4 gl_Position;\n"
5131 "};\n"
5132 "void main(){\n"
5133 " gl_Position = vec4(1);\n"
5134 "}\n";
5135 char const *fsSource =
5136 "#version 450\n"
5137 "#extension GL_ARB_separate_shader_objects: require\n"
5138 "#extension GL_ARB_shading_language_420pack: require\n"
5139 "\n"
5140 "in block { layout(location=0) float x; } ins;\n"
5141 "layout(location=0) out vec4 color;\n"
5142 "void main(){\n"
5143 " color = vec4(ins.x);\n"
5144 "}\n";
5145
5146 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
5147 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
5148
5149 VkPipelineObj pipe(m_device);
5150 pipe.AddColorAttachment();
5151 pipe.AddShader(&vs);
5152 pipe.AddShader(&fs);
5153
5154 VkDescriptorSetObj descriptorSet(m_device);
5155 descriptorSet.AppendDummy();
5156 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
5157
5158 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
5159
5160 if (!m_errorMonitor->DesiredMsgFound()) {
5161 FAIL() << "Did not receive Error 'not written by vertex shader'";
5162 m_errorMonitor->DumpFailureMsgs();
5163 }
5164 }
5165
TEST_F(VkLayerTest,CreatePipelineVsFsTypeMismatchArraySize)5166 TEST_F(VkLayerTest, CreatePipelineVsFsTypeMismatchArraySize) {
5167 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
5168 "Type mismatch on location 0.0: 'ptr to "
5169 "output arr[2] of float32' vs 'ptr to "
5170 "input arr[3] of float32'");
5171
5172 ASSERT_NO_FATAL_FAILURE(InitState());
5173 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
5174
5175 char const *vsSource =
5176 "#version 400\n"
5177 "#extension GL_ARB_separate_shader_objects: require\n"
5178 "#extension GL_ARB_shading_language_420pack: require\n"
5179 "\n"
5180 "layout(location=0) out float x[2];\n"
5181 "out gl_PerVertex {\n"
5182 " vec4 gl_Position;\n"
5183 "};\n"
5184 "void main(){\n"
5185 " x[0] = 0; x[1] = 0;\n"
5186 " gl_Position = vec4(1);\n"
5187 "}\n";
5188 char const *fsSource =
5189 "#version 400\n"
5190 "#extension GL_ARB_separate_shader_objects: require\n"
5191 "#extension GL_ARB_shading_language_420pack: require\n"
5192 "\n"
5193 "layout(location=0) in float x[3];\n"
5194 "layout(location=0) out vec4 color;\n"
5195 "void main(){\n"
5196 " color = vec4(x[0] + x[1] + x[2]);\n"
5197 "}\n";
5198
5199 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
5200 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
5201
5202 VkPipelineObj pipe(m_device);
5203 pipe.AddColorAttachment();
5204 pipe.AddShader(&vs);
5205 pipe.AddShader(&fs);
5206
5207 VkDescriptorSetObj descriptorSet(m_device);
5208 descriptorSet.AppendDummy();
5209 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
5210
5211 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
5212
5213 if (!m_errorMonitor->DesiredMsgFound()) {
5214 m_errorMonitor->DumpFailureMsgs();
5215 FAIL() << "Did not receive Error 'Type mismatch on location 0.0: 'ptr to "
5216 "output arr[2] of float32' vs 'ptr to input arr[3] of "
5217 "float32''";
5218 }
5219 }
5220
TEST_F(VkLayerTest,CreatePipelineVsFsTypeMismatch)5221 TEST_F(VkLayerTest, CreatePipelineVsFsTypeMismatch) {
5222 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
5223 "Type mismatch on location 0");
5224
5225 ASSERT_NO_FATAL_FAILURE(InitState());
5226 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
5227
5228 char const *vsSource =
5229 "#version 400\n"
5230 "#extension GL_ARB_separate_shader_objects: require\n"
5231 "#extension GL_ARB_shading_language_420pack: require\n"
5232 "\n"
5233 "layout(location=0) out int x;\n"
5234 "out gl_PerVertex {\n"
5235 " vec4 gl_Position;\n"
5236 "};\n"
5237 "void main(){\n"
5238 " x = 0;\n"
5239 " gl_Position = vec4(1);\n"
5240 "}\n";
5241 char const *fsSource =
5242 "#version 400\n"
5243 "#extension GL_ARB_separate_shader_objects: require\n"
5244 "#extension GL_ARB_shading_language_420pack: require\n"
5245 "\n"
5246 "layout(location=0) in float x;\n" /* VS writes int */
5247 "layout(location=0) out vec4 color;\n"
5248 "void main(){\n"
5249 " color = vec4(x);\n"
5250 "}\n";
5251
5252 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
5253 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
5254
5255 VkPipelineObj pipe(m_device);
5256 pipe.AddColorAttachment();
5257 pipe.AddShader(&vs);
5258 pipe.AddShader(&fs);
5259
5260 VkDescriptorSetObj descriptorSet(m_device);
5261 descriptorSet.AppendDummy();
5262 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
5263
5264 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
5265
5266 if (!m_errorMonitor->DesiredMsgFound()) {
5267 FAIL() << "Did not receive Error 'Type mismatch on location 0'";
5268 m_errorMonitor->DumpFailureMsgs();
5269 }
5270 }
5271
TEST_F(VkLayerTest,CreatePipelineVsFsTypeMismatchInBlock)5272 TEST_F(VkLayerTest, CreatePipelineVsFsTypeMismatchInBlock) {
5273 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
5274 "Type mismatch on location 0");
5275
5276 ASSERT_NO_FATAL_FAILURE(InitState());
5277 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
5278
5279 char const *vsSource =
5280 "#version 450\n"
5281 "#extension GL_ARB_separate_shader_objects: require\n"
5282 "#extension GL_ARB_shading_language_420pack: require\n"
5283 "\n"
5284 "out block { layout(location=0) int x; } outs;\n"
5285 "out gl_PerVertex {\n"
5286 " vec4 gl_Position;\n"
5287 "};\n"
5288 "void main(){\n"
5289 " outs.x = 0;\n"
5290 " gl_Position = vec4(1);\n"
5291 "}\n";
5292 char const *fsSource =
5293 "#version 450\n"
5294 "#extension GL_ARB_separate_shader_objects: require\n"
5295 "#extension GL_ARB_shading_language_420pack: require\n"
5296 "\n"
5297 "in block { layout(location=0) float x; } ins;\n" /* VS writes int */
5298 "layout(location=0) out vec4 color;\n"
5299 "void main(){\n"
5300 " color = vec4(ins.x);\n"
5301 "}\n";
5302
5303 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
5304 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
5305
5306 VkPipelineObj pipe(m_device);
5307 pipe.AddColorAttachment();
5308 pipe.AddShader(&vs);
5309 pipe.AddShader(&fs);
5310
5311 VkDescriptorSetObj descriptorSet(m_device);
5312 descriptorSet.AppendDummy();
5313 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
5314
5315 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
5316
5317 if (!m_errorMonitor->DesiredMsgFound()) {
5318 m_errorMonitor->DumpFailureMsgs();
5319 FAIL() << "Did not receive Error 'Type mismatch on location 0'";
5320 }
5321 }
5322
TEST_F(VkLayerTest,CreatePipelineVsFsMismatchByLocation)5323 TEST_F(VkLayerTest, CreatePipelineVsFsMismatchByLocation) {
5324 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
5325 "location 0.0 which is not written by vertex shader");
5326
5327 ASSERT_NO_FATAL_FAILURE(InitState());
5328 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
5329
5330 char const *vsSource =
5331 "#version 450\n"
5332 "#extension GL_ARB_separate_shader_objects: require\n"
5333 "#extension GL_ARB_shading_language_420pack: require\n"
5334 "\n"
5335 "out block { layout(location=1) float x; } outs;\n"
5336 "out gl_PerVertex {\n"
5337 " vec4 gl_Position;\n"
5338 "};\n"
5339 "void main(){\n"
5340 " outs.x = 0;\n"
5341 " gl_Position = vec4(1);\n"
5342 "}\n";
5343 char const *fsSource =
5344 "#version 450\n"
5345 "#extension GL_ARB_separate_shader_objects: require\n"
5346 "#extension GL_ARB_shading_language_420pack: require\n"
5347 "\n"
5348 "in block { layout(location=0) float x; } ins;\n"
5349 "layout(location=0) out vec4 color;\n"
5350 "void main(){\n"
5351 " color = vec4(ins.x);\n"
5352 "}\n";
5353
5354 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
5355 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
5356
5357 VkPipelineObj pipe(m_device);
5358 pipe.AddColorAttachment();
5359 pipe.AddShader(&vs);
5360 pipe.AddShader(&fs);
5361
5362 VkDescriptorSetObj descriptorSet(m_device);
5363 descriptorSet.AppendDummy();
5364 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
5365
5366 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
5367
5368 if (!m_errorMonitor->DesiredMsgFound()) {
5369 m_errorMonitor->DumpFailureMsgs();
5370 FAIL() << "Did not receive Error 'location 0.0 which is not written by vertex shader'";
5371 }
5372 }
5373
TEST_F(VkLayerTest,CreatePipelineVsFsMismatchByComponent)5374 TEST_F(VkLayerTest, CreatePipelineVsFsMismatchByComponent) {
5375 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
5376 "location 0.1 which is not written by vertex shader");
5377
5378 ASSERT_NO_FATAL_FAILURE(InitState());
5379 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
5380
5381 char const *vsSource =
5382 "#version 450\n"
5383 "#extension GL_ARB_separate_shader_objects: require\n"
5384 "#extension GL_ARB_shading_language_420pack: require\n"
5385 "\n"
5386 "out block { layout(location=0, component=0) float x; } outs;\n"
5387 "out gl_PerVertex {\n"
5388 " vec4 gl_Position;\n"
5389 "};\n"
5390 "void main(){\n"
5391 " outs.x = 0;\n"
5392 " gl_Position = vec4(1);\n"
5393 "}\n";
5394 char const *fsSource =
5395 "#version 450\n"
5396 "#extension GL_ARB_separate_shader_objects: require\n"
5397 "#extension GL_ARB_shading_language_420pack: require\n"
5398 "\n"
5399 "in block { layout(location=0, component=1) float x; } ins;\n"
5400 "layout(location=0) out vec4 color;\n"
5401 "void main(){\n"
5402 " color = vec4(ins.x);\n"
5403 "}\n";
5404
5405 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
5406 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
5407
5408 VkPipelineObj pipe(m_device);
5409 pipe.AddColorAttachment();
5410 pipe.AddShader(&vs);
5411 pipe.AddShader(&fs);
5412
5413 VkDescriptorSetObj descriptorSet(m_device);
5414 descriptorSet.AppendDummy();
5415 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
5416
5417 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
5418
5419 if (!m_errorMonitor->DesiredMsgFound()) {
5420 m_errorMonitor->DumpFailureMsgs();
5421 FAIL() << "Did not receive Error 'location 0.1 which is not written by vertex shader'";
5422 }
5423 }
5424
TEST_F(VkLayerTest,CreatePipelineAttribNotConsumed)5425 TEST_F(VkLayerTest, CreatePipelineAttribNotConsumed) {
5426 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
5427 "location 0 not consumed by VS");
5428
5429 ASSERT_NO_FATAL_FAILURE(InitState());
5430 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
5431
5432 VkVertexInputBindingDescription input_binding;
5433 memset(&input_binding, 0, sizeof(input_binding));
5434
5435 VkVertexInputAttributeDescription input_attrib;
5436 memset(&input_attrib, 0, sizeof(input_attrib));
5437 input_attrib.format = VK_FORMAT_R32_SFLOAT;
5438
5439 char const *vsSource =
5440 "#version 400\n"
5441 "#extension GL_ARB_separate_shader_objects: require\n"
5442 "#extension GL_ARB_shading_language_420pack: require\n"
5443 "\n"
5444 "out gl_PerVertex {\n"
5445 " vec4 gl_Position;\n"
5446 "};\n"
5447 "void main(){\n"
5448 " gl_Position = vec4(1);\n"
5449 "}\n";
5450 char const *fsSource =
5451 "#version 400\n"
5452 "#extension GL_ARB_separate_shader_objects: require\n"
5453 "#extension GL_ARB_shading_language_420pack: require\n"
5454 "\n"
5455 "layout(location=0) out vec4 color;\n"
5456 "void main(){\n"
5457 " color = vec4(1);\n"
5458 "}\n";
5459
5460 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
5461 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
5462
5463 VkPipelineObj pipe(m_device);
5464 pipe.AddColorAttachment();
5465 pipe.AddShader(&vs);
5466 pipe.AddShader(&fs);
5467
5468 pipe.AddVertexInputBindings(&input_binding, 1);
5469 pipe.AddVertexInputAttribs(&input_attrib, 1);
5470
5471 VkDescriptorSetObj descriptorSet(m_device);
5472 descriptorSet.AppendDummy();
5473 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
5474
5475 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
5476
5477 if (!m_errorMonitor->DesiredMsgFound()) {
5478 FAIL() << "Did not receive Warning 'location 0 not consumed by VS'";
5479 m_errorMonitor->DumpFailureMsgs();
5480 }
5481 }
5482
TEST_F(VkLayerTest,CreatePipelineAttribLocationMismatch)5483 TEST_F(VkLayerTest, CreatePipelineAttribLocationMismatch) {
5484 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
5485 "location 0 not consumed by VS");
5486
5487 ASSERT_NO_FATAL_FAILURE(InitState());
5488 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
5489
5490 VkVertexInputBindingDescription input_binding;
5491 memset(&input_binding, 0, sizeof(input_binding));
5492
5493 VkVertexInputAttributeDescription input_attrib;
5494 memset(&input_attrib, 0, sizeof(input_attrib));
5495 input_attrib.format = VK_FORMAT_R32_SFLOAT;
5496
5497 char const *vsSource =
5498 "#version 400\n"
5499 "#extension GL_ARB_separate_shader_objects: require\n"
5500 "#extension GL_ARB_shading_language_420pack: require\n"
5501 "\n"
5502 "layout(location=1) in float x;\n"
5503 "out gl_PerVertex {\n"
5504 " vec4 gl_Position;\n"
5505 "};\n"
5506 "void main(){\n"
5507 " gl_Position = vec4(x);\n"
5508 "}\n";
5509 char const *fsSource =
5510 "#version 400\n"
5511 "#extension GL_ARB_separate_shader_objects: require\n"
5512 "#extension GL_ARB_shading_language_420pack: require\n"
5513 "\n"
5514 "layout(location=0) out vec4 color;\n"
5515 "void main(){\n"
5516 " color = vec4(1);\n"
5517 "}\n";
5518
5519 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
5520 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
5521
5522 VkPipelineObj pipe(m_device);
5523 pipe.AddColorAttachment();
5524 pipe.AddShader(&vs);
5525 pipe.AddShader(&fs);
5526
5527 pipe.AddVertexInputBindings(&input_binding, 1);
5528 pipe.AddVertexInputAttribs(&input_attrib, 1);
5529
5530 VkDescriptorSetObj descriptorSet(m_device);
5531 descriptorSet.AppendDummy();
5532 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
5533
5534 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
5535
5536 if (!m_errorMonitor->DesiredMsgFound()) {
5537 m_errorMonitor->DumpFailureMsgs();
5538 FAIL() << "Did not receive Warning 'location 0 not consumed by VS'";
5539 }
5540 }
5541
TEST_F(VkLayerTest,CreatePipelineAttribNotProvided)5542 TEST_F(VkLayerTest, CreatePipelineAttribNotProvided) {
5543 m_errorMonitor->SetDesiredFailureMsg(
5544 VK_DEBUG_REPORT_ERROR_BIT_EXT,
5545 "VS consumes input at location 0 but not provided");
5546
5547 ASSERT_NO_FATAL_FAILURE(InitState());
5548 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
5549
5550 char const *vsSource =
5551 "#version 400\n"
5552 "#extension GL_ARB_separate_shader_objects: require\n"
5553 "#extension GL_ARB_shading_language_420pack: require\n"
5554 "\n"
5555 "layout(location=0) in vec4 x;\n" /* not provided */
5556 "out gl_PerVertex {\n"
5557 " vec4 gl_Position;\n"
5558 "};\n"
5559 "void main(){\n"
5560 " gl_Position = x;\n"
5561 "}\n";
5562 char const *fsSource =
5563 "#version 400\n"
5564 "#extension GL_ARB_separate_shader_objects: require\n"
5565 "#extension GL_ARB_shading_language_420pack: require\n"
5566 "\n"
5567 "layout(location=0) out vec4 color;\n"
5568 "void main(){\n"
5569 " color = vec4(1);\n"
5570 "}\n";
5571
5572 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
5573 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
5574
5575 VkPipelineObj pipe(m_device);
5576 pipe.AddColorAttachment();
5577 pipe.AddShader(&vs);
5578 pipe.AddShader(&fs);
5579
5580 VkDescriptorSetObj descriptorSet(m_device);
5581 descriptorSet.AppendDummy();
5582 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
5583
5584 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
5585
5586 if (!m_errorMonitor->DesiredMsgFound()) {
5587 FAIL() << "Did not receive Error 'VS consumes input at location 0 but "
5588 "not provided'";
5589 m_errorMonitor->DumpFailureMsgs();
5590 }
5591 }
5592
TEST_F(VkLayerTest,CreatePipelineAttribTypeMismatch)5593 TEST_F(VkLayerTest, CreatePipelineAttribTypeMismatch) {
5594 m_errorMonitor->SetDesiredFailureMsg(
5595 VK_DEBUG_REPORT_ERROR_BIT_EXT,
5596 "location 0 does not match VS input type");
5597
5598 ASSERT_NO_FATAL_FAILURE(InitState());
5599 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
5600
5601 VkVertexInputBindingDescription input_binding;
5602 memset(&input_binding, 0, sizeof(input_binding));
5603
5604 VkVertexInputAttributeDescription input_attrib;
5605 memset(&input_attrib, 0, sizeof(input_attrib));
5606 input_attrib.format = VK_FORMAT_R32_SFLOAT;
5607
5608 char const *vsSource =
5609 "#version 400\n"
5610 "#extension GL_ARB_separate_shader_objects: require\n"
5611 "#extension GL_ARB_shading_language_420pack: require\n"
5612 "\n"
5613 "layout(location=0) in int x;\n" /* attrib provided float */
5614 "out gl_PerVertex {\n"
5615 " vec4 gl_Position;\n"
5616 "};\n"
5617 "void main(){\n"
5618 " gl_Position = vec4(x);\n"
5619 "}\n";
5620 char const *fsSource =
5621 "#version 400\n"
5622 "#extension GL_ARB_separate_shader_objects: require\n"
5623 "#extension GL_ARB_shading_language_420pack: require\n"
5624 "\n"
5625 "layout(location=0) out vec4 color;\n"
5626 "void main(){\n"
5627 " color = vec4(1);\n"
5628 "}\n";
5629
5630 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
5631 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
5632
5633 VkPipelineObj pipe(m_device);
5634 pipe.AddColorAttachment();
5635 pipe.AddShader(&vs);
5636 pipe.AddShader(&fs);
5637
5638 pipe.AddVertexInputBindings(&input_binding, 1);
5639 pipe.AddVertexInputAttribs(&input_attrib, 1);
5640
5641 VkDescriptorSetObj descriptorSet(m_device);
5642 descriptorSet.AppendDummy();
5643 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
5644
5645 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
5646
5647 if (!m_errorMonitor->DesiredMsgFound()) {
5648 FAIL() << "Did not receive Error 'location 0 does not match VS input "
5649 "type'";
5650 m_errorMonitor->DumpFailureMsgs();
5651 }
5652 }
5653
TEST_F(VkLayerTest,CreatePipelineAttribMatrixType)5654 TEST_F(VkLayerTest, CreatePipelineAttribMatrixType) {
5655 m_errorMonitor->SetDesiredFailureMsg(~0u, "");
5656
5657 ASSERT_NO_FATAL_FAILURE(InitState());
5658 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
5659
5660 VkVertexInputBindingDescription input_binding;
5661 memset(&input_binding, 0, sizeof(input_binding));
5662
5663 VkVertexInputAttributeDescription input_attribs[2];
5664 memset(input_attribs, 0, sizeof(input_attribs));
5665
5666 for (int i = 0; i < 2; i++) {
5667 input_attribs[i].format = VK_FORMAT_R32G32B32A32_SFLOAT;
5668 input_attribs[i].location = i;
5669 }
5670
5671 char const *vsSource =
5672 "#version 400\n"
5673 "#extension GL_ARB_separate_shader_objects: require\n"
5674 "#extension GL_ARB_shading_language_420pack: require\n"
5675 "\n"
5676 "layout(location=0) in mat2x4 x;\n"
5677 "out gl_PerVertex {\n"
5678 " vec4 gl_Position;\n"
5679 "};\n"
5680 "void main(){\n"
5681 " gl_Position = x[0] + x[1];\n"
5682 "}\n";
5683 char const *fsSource =
5684 "#version 400\n"
5685 "#extension GL_ARB_separate_shader_objects: require\n"
5686 "#extension GL_ARB_shading_language_420pack: require\n"
5687 "\n"
5688 "layout(location=0) out vec4 color;\n"
5689 "void main(){\n"
5690 " color = vec4(1);\n"
5691 "}\n";
5692
5693 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
5694 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
5695
5696 VkPipelineObj pipe(m_device);
5697 pipe.AddColorAttachment();
5698 pipe.AddShader(&vs);
5699 pipe.AddShader(&fs);
5700
5701 pipe.AddVertexInputBindings(&input_binding, 1);
5702 pipe.AddVertexInputAttribs(input_attribs, 2);
5703
5704 VkDescriptorSetObj descriptorSet(m_device);
5705 descriptorSet.AppendDummy();
5706 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
5707
5708 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
5709
5710 /* expect success */
5711 if (m_errorMonitor->DesiredMsgFound()) {
5712 FAIL() << "Expected to succeed but: "
5713 << m_errorMonitor->GetFailureMsg();
5714 m_errorMonitor->DumpFailureMsgs();
5715 }
5716 }
5717
TEST_F(VkLayerTest,CreatePipelineAttribArrayType)5718 TEST_F(VkLayerTest, CreatePipelineAttribArrayType)
5719 {
5720 m_errorMonitor->SetDesiredFailureMsg(~0u, "");
5721
5722 ASSERT_NO_FATAL_FAILURE(InitState());
5723 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
5724
5725 VkVertexInputBindingDescription input_binding;
5726 memset(&input_binding, 0, sizeof(input_binding));
5727
5728 VkVertexInputAttributeDescription input_attribs[2];
5729 memset(input_attribs, 0, sizeof(input_attribs));
5730
5731 for (int i = 0; i < 2; i++) {
5732 input_attribs[i].format = VK_FORMAT_R32G32B32A32_SFLOAT;
5733 input_attribs[i].location = i;
5734 }
5735
5736 char const *vsSource =
5737 "#version 400\n"
5738 "#extension GL_ARB_separate_shader_objects: require\n"
5739 "#extension GL_ARB_shading_language_420pack: require\n"
5740 "\n"
5741 "layout(location=0) in vec4 x[2];\n"
5742 "out gl_PerVertex {\n"
5743 " vec4 gl_Position;\n"
5744 "};\n"
5745 "void main(){\n"
5746 " gl_Position = x[0] + x[1];\n"
5747 "}\n";
5748 char const *fsSource =
5749 "#version 400\n"
5750 "#extension GL_ARB_separate_shader_objects: require\n"
5751 "#extension GL_ARB_shading_language_420pack: require\n"
5752 "\n"
5753 "layout(location=0) out vec4 color;\n"
5754 "void main(){\n"
5755 " color = vec4(1);\n"
5756 "}\n";
5757
5758 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
5759 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
5760
5761 VkPipelineObj pipe(m_device);
5762 pipe.AddColorAttachment();
5763 pipe.AddShader(&vs);
5764 pipe.AddShader(&fs);
5765
5766 pipe.AddVertexInputBindings(&input_binding, 1);
5767 pipe.AddVertexInputAttribs(input_attribs, 2);
5768
5769 VkDescriptorSetObj descriptorSet(m_device);
5770 descriptorSet.AppendDummy();
5771 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
5772
5773 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
5774
5775 if (m_errorMonitor->DesiredMsgFound()) {
5776 FAIL() << "Expected to succeed but: " <<
5777 m_errorMonitor->GetFailureMsg();
5778 m_errorMonitor->DumpFailureMsgs();
5779 }
5780 }
5781
TEST_F(VkLayerTest,CreatePipelineAttribBindingConflict)5782 TEST_F(VkLayerTest, CreatePipelineAttribBindingConflict) {
5783 m_errorMonitor->SetDesiredFailureMsg(
5784 VK_DEBUG_REPORT_ERROR_BIT_EXT,
5785 "Duplicate vertex input binding descriptions for binding 0");
5786
5787 ASSERT_NO_FATAL_FAILURE(InitState());
5788 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
5789
5790 /* Two binding descriptions for binding 0 */
5791 VkVertexInputBindingDescription input_bindings[2];
5792 memset(input_bindings, 0, sizeof(input_bindings));
5793
5794 VkVertexInputAttributeDescription input_attrib;
5795 memset(&input_attrib, 0, sizeof(input_attrib));
5796 input_attrib.format = VK_FORMAT_R32_SFLOAT;
5797
5798 char const *vsSource =
5799 "#version 400\n"
5800 "#extension GL_ARB_separate_shader_objects: require\n"
5801 "#extension GL_ARB_shading_language_420pack: require\n"
5802 "\n"
5803 "layout(location=0) in float x;\n" /* attrib provided float */
5804 "out gl_PerVertex {\n"
5805 " vec4 gl_Position;\n"
5806 "};\n"
5807 "void main(){\n"
5808 " gl_Position = vec4(x);\n"
5809 "}\n";
5810 char const *fsSource =
5811 "#version 400\n"
5812 "#extension GL_ARB_separate_shader_objects: require\n"
5813 "#extension GL_ARB_shading_language_420pack: require\n"
5814 "\n"
5815 "layout(location=0) out vec4 color;\n"
5816 "void main(){\n"
5817 " color = vec4(1);\n"
5818 "}\n";
5819
5820 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
5821 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
5822
5823 VkPipelineObj pipe(m_device);
5824 pipe.AddColorAttachment();
5825 pipe.AddShader(&vs);
5826 pipe.AddShader(&fs);
5827
5828 pipe.AddVertexInputBindings(input_bindings, 2);
5829 pipe.AddVertexInputAttribs(&input_attrib, 1);
5830
5831 VkDescriptorSetObj descriptorSet(m_device);
5832 descriptorSet.AppendDummy();
5833 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
5834
5835 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
5836
5837 if (!m_errorMonitor->DesiredMsgFound()) {
5838 FAIL() << "Did not receive Error 'Duplicate vertex input binding "
5839 "descriptions for binding 0'";
5840 m_errorMonitor->DumpFailureMsgs();
5841 }
5842 }
5843
TEST_F(VkLayerTest,CreatePipelineFragmentOutputNotWritten)5844 TEST_F(VkLayerTest, CreatePipelineFragmentOutputNotWritten) {
5845 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
5846 "Attachment 0 not written by FS");
5847
5848 ASSERT_NO_FATAL_FAILURE(InitState());
5849
5850 char const *vsSource =
5851 "#version 400\n"
5852 "#extension GL_ARB_separate_shader_objects: require\n"
5853 "#extension GL_ARB_shading_language_420pack: require\n"
5854 "\n"
5855 "out gl_PerVertex {\n"
5856 " vec4 gl_Position;\n"
5857 "};\n"
5858 "void main(){\n"
5859 " gl_Position = vec4(1);\n"
5860 "}\n";
5861 char const *fsSource =
5862 "#version 400\n"
5863 "#extension GL_ARB_separate_shader_objects: require\n"
5864 "#extension GL_ARB_shading_language_420pack: require\n"
5865 "\n"
5866 "void main(){\n"
5867 "}\n";
5868
5869 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
5870 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
5871
5872 VkPipelineObj pipe(m_device);
5873 pipe.AddShader(&vs);
5874 pipe.AddShader(&fs);
5875
5876 /* set up CB 0, not written */
5877 pipe.AddColorAttachment();
5878 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
5879
5880 VkDescriptorSetObj descriptorSet(m_device);
5881 descriptorSet.AppendDummy();
5882 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
5883
5884 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
5885
5886 if (!m_errorMonitor->DesiredMsgFound()) {
5887 FAIL() << "Did not receive Error 'Attachment 0 not written by FS'";
5888 m_errorMonitor->DumpFailureMsgs();
5889 }
5890 }
5891
TEST_F(VkLayerTest,CreatePipelineFragmentOutputNotConsumed)5892 TEST_F(VkLayerTest, CreatePipelineFragmentOutputNotConsumed) {
5893 // TODO: verify that this matches layer
5894 m_errorMonitor->SetDesiredFailureMsg(
5895 VK_DEBUG_REPORT_WARNING_BIT_EXT,
5896 "FS writes to output location 1 with no matching attachment");
5897
5898 ASSERT_NO_FATAL_FAILURE(InitState());
5899
5900 char const *vsSource =
5901 "#version 400\n"
5902 "#extension GL_ARB_separate_shader_objects: require\n"
5903 "#extension GL_ARB_shading_language_420pack: require\n"
5904 "\n"
5905 "out gl_PerVertex {\n"
5906 " vec4 gl_Position;\n"
5907 "};\n"
5908 "void main(){\n"
5909 " gl_Position = vec4(1);\n"
5910 "}\n";
5911 char const *fsSource =
5912 "#version 400\n"
5913 "#extension GL_ARB_separate_shader_objects: require\n"
5914 "#extension GL_ARB_shading_language_420pack: require\n"
5915 "\n"
5916 "layout(location=0) out vec4 x;\n"
5917 "layout(location=1) out vec4 y;\n" /* no matching attachment for this */
5918 "void main(){\n"
5919 " x = vec4(1);\n"
5920 " y = vec4(1);\n"
5921 "}\n";
5922
5923 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
5924 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
5925
5926 VkPipelineObj pipe(m_device);
5927 pipe.AddShader(&vs);
5928 pipe.AddShader(&fs);
5929
5930 /* set up CB 0, not written */
5931 pipe.AddColorAttachment();
5932 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
5933 /* FS writes CB 1, but we don't configure it */
5934
5935 VkDescriptorSetObj descriptorSet(m_device);
5936 descriptorSet.AppendDummy();
5937 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
5938
5939 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
5940
5941 if (!m_errorMonitor->DesiredMsgFound()) {
5942 FAIL() << "Did not receive Error 'FS writes to output location 1 with "
5943 "no matching attachment'";
5944 m_errorMonitor->DumpFailureMsgs();
5945 }
5946 }
5947
TEST_F(VkLayerTest,CreatePipelineFragmentOutputTypeMismatch)5948 TEST_F(VkLayerTest, CreatePipelineFragmentOutputTypeMismatch) {
5949 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
5950 "does not match FS output type");
5951
5952 ASSERT_NO_FATAL_FAILURE(InitState());
5953
5954 char const *vsSource =
5955 "#version 400\n"
5956 "#extension GL_ARB_separate_shader_objects: require\n"
5957 "#extension GL_ARB_shading_language_420pack: require\n"
5958 "\n"
5959 "out gl_PerVertex {\n"
5960 " vec4 gl_Position;\n"
5961 "};\n"
5962 "void main(){\n"
5963 " gl_Position = vec4(1);\n"
5964 "}\n";
5965 char const *fsSource =
5966 "#version 400\n"
5967 "#extension GL_ARB_separate_shader_objects: require\n"
5968 "#extension GL_ARB_shading_language_420pack: require\n"
5969 "\n"
5970 "layout(location=0) out ivec4 x;\n" /* not UNORM */
5971 "void main(){\n"
5972 " x = ivec4(1);\n"
5973 "}\n";
5974
5975 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
5976 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
5977
5978 VkPipelineObj pipe(m_device);
5979 pipe.AddShader(&vs);
5980 pipe.AddShader(&fs);
5981
5982 /* set up CB 0; type is UNORM by default */
5983 pipe.AddColorAttachment();
5984 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
5985
5986 VkDescriptorSetObj descriptorSet(m_device);
5987 descriptorSet.AppendDummy();
5988 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
5989
5990 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
5991
5992 if (!m_errorMonitor->DesiredMsgFound()) {
5993 FAIL() << "Did not receive Error 'does not match FS output type'";
5994 m_errorMonitor->DumpFailureMsgs();
5995 }
5996 }
5997
TEST_F(VkLayerTest,CreatePipelineUniformBlockNotProvided)5998 TEST_F(VkLayerTest, CreatePipelineUniformBlockNotProvided) {
5999 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
6000 "not declared in pipeline layout");
6001
6002 ASSERT_NO_FATAL_FAILURE(InitState());
6003
6004 char const *vsSource =
6005 "#version 400\n"
6006 "#extension GL_ARB_separate_shader_objects: require\n"
6007 "#extension GL_ARB_shading_language_420pack: require\n"
6008 "\n"
6009 "out gl_PerVertex {\n"
6010 " vec4 gl_Position;\n"
6011 "};\n"
6012 "void main(){\n"
6013 " gl_Position = vec4(1);\n"
6014 "}\n";
6015 char const *fsSource =
6016 "#version 400\n"
6017 "#extension GL_ARB_separate_shader_objects: require\n"
6018 "#extension GL_ARB_shading_language_420pack: require\n"
6019 "\n"
6020 "layout(location=0) out vec4 x;\n"
6021 "layout(set=0) layout(binding=0) uniform foo { int x; int y; } bar;\n"
6022 "void main(){\n"
6023 " x = vec4(bar.y);\n"
6024 "}\n";
6025
6026 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
6027 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
6028
6029 VkPipelineObj pipe(m_device);
6030 pipe.AddShader(&vs);
6031 pipe.AddShader(&fs);
6032
6033 /* set up CB 0; type is UNORM by default */
6034 pipe.AddColorAttachment();
6035 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
6036
6037 VkDescriptorSetObj descriptorSet(m_device);
6038 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
6039
6040 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
6041
6042 /* should have generated an error -- pipeline layout does not
6043 * provide a uniform buffer in 0.0
6044 */
6045 if (!m_errorMonitor->DesiredMsgFound()) {
6046 FAIL() << "Did not receive Error 'not declared in pipeline layout'";
6047 m_errorMonitor->DumpFailureMsgs();
6048 }
6049 }
6050
TEST_F(VkLayerTest,CreatePipelinePushConstantsNotInLayout)6051 TEST_F(VkLayerTest, CreatePipelinePushConstantsNotInLayout) {
6052 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
6053 "not declared in layout");
6054
6055 ASSERT_NO_FATAL_FAILURE(InitState());
6056
6057 char const *vsSource =
6058 "#version 450\n"
6059 "#extension GL_ARB_separate_shader_objects: require\n"
6060 "#extension GL_ARB_shading_language_420pack: require\n"
6061 "\n"
6062 "layout(push_constant, std430) uniform foo { float x; } consts;\n"
6063 "out gl_PerVertex {\n"
6064 " vec4 gl_Position;\n"
6065 "};\n"
6066 "void main(){\n"
6067 " gl_Position = vec4(consts.x);\n"
6068 "}\n";
6069 char const *fsSource =
6070 "#version 450\n"
6071 "#extension GL_ARB_separate_shader_objects: require\n"
6072 "#extension GL_ARB_shading_language_420pack: require\n"
6073 "\n"
6074 "layout(location=0) out vec4 x;\n"
6075 "void main(){\n"
6076 " x = vec4(1);\n"
6077 "}\n";
6078
6079 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
6080 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
6081
6082 VkPipelineObj pipe(m_device);
6083 pipe.AddShader(&vs);
6084 pipe.AddShader(&fs);
6085
6086 /* set up CB 0; type is UNORM by default */
6087 pipe.AddColorAttachment();
6088 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
6089
6090 VkDescriptorSetObj descriptorSet(m_device);
6091 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
6092
6093 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
6094
6095 /* should have generated an error -- no push constant ranges provided! */
6096 if (!m_errorMonitor->DesiredMsgFound()) {
6097 FAIL() << "Did not receive Error 'not declared in pipeline layout'";
6098 m_errorMonitor->DumpFailureMsgs();
6099 }
6100 }
6101
6102 #endif // SHADER_CHECKER_TESTS
6103
6104 #if DEVICE_LIMITS_TESTS
TEST_F(VkLayerTest,CreateImageLimitsViolationWidth)6105 TEST_F(VkLayerTest, CreateImageLimitsViolationWidth) {
6106 m_errorMonitor->SetDesiredFailureMsg(
6107 VK_DEBUG_REPORT_ERROR_BIT_EXT,
6108 "CreateImage extents exceed allowable limits for format");
6109
6110 ASSERT_NO_FATAL_FAILURE(InitState());
6111
6112 // Create an image
6113 VkImage image;
6114
6115 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
6116 const int32_t tex_width = 32;
6117 const int32_t tex_height = 32;
6118
6119 VkImageCreateInfo image_create_info = {};
6120 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
6121 image_create_info.pNext = NULL;
6122 image_create_info.imageType = VK_IMAGE_TYPE_2D;
6123 image_create_info.format = tex_format;
6124 image_create_info.extent.width = tex_width;
6125 image_create_info.extent.height = tex_height;
6126 image_create_info.extent.depth = 1;
6127 image_create_info.mipLevels = 1;
6128 image_create_info.arrayLayers = 1;
6129 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
6130 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
6131 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
6132 image_create_info.flags = 0;
6133
6134 // Introduce error by sending down a bogus width extent
6135 image_create_info.extent.width = 65536;
6136 vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
6137
6138 if (!m_errorMonitor->DesiredMsgFound()) {
6139 FAIL() << "Did not receive Error 'CreateImage extents exceed allowable "
6140 "limits for format'";
6141 m_errorMonitor->DumpFailureMsgs();
6142 }
6143 }
6144
TEST_F(VkLayerTest,UpdateBufferAlignment)6145 TEST_F(VkLayerTest, UpdateBufferAlignment) {
6146 uint32_t updateData[] = {1, 2, 3, 4, 5, 6, 7, 8};
6147
6148 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
6149 "dstOffset, is not a multiple of 4");
6150
6151 ASSERT_NO_FATAL_FAILURE(InitState());
6152
6153 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
6154 vk_testing::Buffer buffer;
6155 buffer.init_as_dst(*m_device, (VkDeviceSize)20, reqs);
6156
6157 BeginCommandBuffer();
6158 // Introduce failure by using offset that is not multiple of 4
6159 m_commandBuffer->UpdateBuffer(buffer.handle(), 1, 4, updateData);
6160 if (!m_errorMonitor->DesiredMsgFound()) {
6161 FAIL() << "Did not receive Error 'vkCommandUpdateBuffer parameter, "
6162 "VkDeviceSize dstOffset, is not a multiple of 4'";
6163 m_errorMonitor->DumpFailureMsgs();
6164 }
6165
6166 // Introduce failure by using size that is not multiple of 4
6167 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
6168 "dataSize, is not a multiple of 4");
6169
6170 m_commandBuffer->UpdateBuffer(buffer.handle(), 0, 6, updateData);
6171
6172 if (!m_errorMonitor->DesiredMsgFound()) {
6173 FAIL() << "Did not receive Error 'vkCommandUpdateBuffer parameter, "
6174 "VkDeviceSize dataSize, is not a multiple of 4'";
6175 m_errorMonitor->DumpFailureMsgs();
6176 }
6177 EndCommandBuffer();
6178 }
6179
TEST_F(VkLayerTest,FillBufferAlignment)6180 TEST_F(VkLayerTest, FillBufferAlignment) {
6181 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
6182 "dstOffset, is not a multiple of 4");
6183
6184 ASSERT_NO_FATAL_FAILURE(InitState());
6185
6186 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
6187 vk_testing::Buffer buffer;
6188 buffer.init_as_dst(*m_device, (VkDeviceSize)20, reqs);
6189
6190 BeginCommandBuffer();
6191 // Introduce failure by using offset that is not multiple of 4
6192 m_commandBuffer->FillBuffer(buffer.handle(), 1, 4, 0x11111111);
6193 if (!m_errorMonitor->DesiredMsgFound()) {
6194 FAIL() << "Did not receive Error 'vkCommandFillBuffer parameter, "
6195 "VkDeviceSize dstOffset, is not a multiple of 4'";
6196 m_errorMonitor->DumpFailureMsgs();
6197 }
6198
6199 // Introduce failure by using size that is not multiple of 4
6200 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
6201 "size, is not a multiple of 4");
6202
6203 m_commandBuffer->FillBuffer(buffer.handle(), 0, 6, 0x11111111);
6204
6205 if (!m_errorMonitor->DesiredMsgFound()) {
6206 FAIL() << "Did not receive Error 'vkCommandFillBuffer parameter, "
6207 "VkDeviceSize size, is not a multiple of 4'";
6208 m_errorMonitor->DumpFailureMsgs();
6209 }
6210 EndCommandBuffer();
6211 }
6212
6213 #endif // DEVICE_LIMITS_TESTS
6214
6215 #if IMAGE_TESTS
TEST_F(VkLayerTest,InvalidImageView)6216 TEST_F(VkLayerTest, InvalidImageView) {
6217 VkResult err;
6218
6219 m_errorMonitor->SetDesiredFailureMsg(
6220 VK_DEBUG_REPORT_ERROR_BIT_EXT,
6221 "vkCreateImageView called with baseMipLevel 10 ");
6222
6223 ASSERT_NO_FATAL_FAILURE(InitState());
6224
6225 // Create an image and try to create a view with bad baseMipLevel
6226 VkImage image;
6227
6228 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
6229 const int32_t tex_width = 32;
6230 const int32_t tex_height = 32;
6231
6232 VkImageCreateInfo image_create_info = {};
6233 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
6234 image_create_info.pNext = NULL;
6235 image_create_info.imageType = VK_IMAGE_TYPE_2D;
6236 image_create_info.format = tex_format;
6237 image_create_info.extent.width = tex_width;
6238 image_create_info.extent.height = tex_height;
6239 image_create_info.extent.depth = 1;
6240 image_create_info.mipLevels = 1;
6241 image_create_info.arrayLayers = 1;
6242 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
6243 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
6244 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
6245 image_create_info.flags = 0;
6246
6247 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
6248 ASSERT_VK_SUCCESS(err);
6249
6250 VkImageViewCreateInfo image_view_create_info = {};
6251 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
6252 image_view_create_info.image = image;
6253 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
6254 image_view_create_info.format = tex_format;
6255 image_view_create_info.subresourceRange.layerCount = 1;
6256 image_view_create_info.subresourceRange.baseMipLevel = 10; // cause an error
6257 image_view_create_info.subresourceRange.levelCount = 1;
6258 image_view_create_info.subresourceRange.aspectMask =
6259 VK_IMAGE_ASPECT_COLOR_BIT;
6260
6261 VkImageView view;
6262 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL,
6263 &view);
6264
6265 if (!m_errorMonitor->DesiredMsgFound()) {
6266 FAIL() << "Did not receive Error 'vkCreateImageView called with "
6267 "baseMipLevel 10...'";
6268 m_errorMonitor->DumpFailureMsgs();
6269 }
6270 }
6271
TEST_F(VkLayerTest,InvalidImageViewAspect)6272 TEST_F(VkLayerTest, InvalidImageViewAspect) {
6273 VkResult err;
6274
6275 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
6276 "vkCreateImageView: Color image "
6277 "formats must have ONLY the "
6278 "VK_IMAGE_ASPECT_COLOR_BIT set");
6279
6280 ASSERT_NO_FATAL_FAILURE(InitState());
6281
6282 // Create an image and try to create a view with an invalid aspectMask
6283 VkImage image;
6284
6285 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
6286 const int32_t tex_width = 32;
6287 const int32_t tex_height = 32;
6288
6289 VkImageCreateInfo image_create_info = {};
6290 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
6291 image_create_info.pNext = NULL;
6292 image_create_info.imageType = VK_IMAGE_TYPE_2D;
6293 image_create_info.format = tex_format;
6294 image_create_info.extent.width = tex_width;
6295 image_create_info.extent.height = tex_height;
6296 image_create_info.extent.depth = 1;
6297 image_create_info.mipLevels = 1;
6298 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
6299 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
6300 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
6301 image_create_info.flags = 0;
6302
6303 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
6304 ASSERT_VK_SUCCESS(err);
6305
6306 VkImageViewCreateInfo image_view_create_info = {};
6307 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
6308 image_view_create_info.image = image;
6309 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
6310 image_view_create_info.format = tex_format;
6311 image_view_create_info.subresourceRange.baseMipLevel = 0;
6312 image_view_create_info.subresourceRange.levelCount = 1;
6313 // Cause an error by setting an invalid image aspect
6314 image_view_create_info.subresourceRange.aspectMask =
6315 VK_IMAGE_ASPECT_METADATA_BIT;
6316
6317 VkImageView view;
6318 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL,
6319 &view);
6320
6321 if (!m_errorMonitor->DesiredMsgFound()) {
6322 FAIL() << "Did not receive Error 'VkCreateImageView: Color image "
6323 "formats must have ...'";
6324 m_errorMonitor->DumpFailureMsgs();
6325 }
6326 }
6327
TEST_F(VkLayerTest,CopyImageTypeMismatch)6328 TEST_F(VkLayerTest, CopyImageTypeMismatch) {
6329 VkResult err;
6330 bool pass;
6331
6332 m_errorMonitor->SetDesiredFailureMsg(
6333 VK_DEBUG_REPORT_ERROR_BIT_EXT,
6334 "vkCmdCopyImage called with unmatched source and dest image types");
6335
6336 ASSERT_NO_FATAL_FAILURE(InitState());
6337
6338 // Create two images of different types and try to copy between them
6339 VkImage srcImage;
6340 VkImage dstImage;
6341 VkDeviceMemory srcMem;
6342 VkDeviceMemory destMem;
6343 VkMemoryRequirements memReqs;
6344
6345 VkImageCreateInfo image_create_info = {};
6346 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
6347 image_create_info.pNext = NULL;
6348 image_create_info.imageType = VK_IMAGE_TYPE_2D;
6349 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
6350 image_create_info.extent.width = 32;
6351 image_create_info.extent.height = 32;
6352 image_create_info.extent.depth = 1;
6353 image_create_info.mipLevels = 1;
6354 image_create_info.arrayLayers = 1;
6355 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
6356 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
6357 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
6358 image_create_info.flags = 0;
6359
6360 err =
6361 vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
6362 ASSERT_VK_SUCCESS(err);
6363
6364 image_create_info.imageType = VK_IMAGE_TYPE_1D;
6365 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
6366
6367 err =
6368 vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
6369 ASSERT_VK_SUCCESS(err);
6370
6371 // Allocate memory
6372 VkMemoryAllocateInfo memAlloc = {};
6373 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
6374 memAlloc.pNext = NULL;
6375 memAlloc.allocationSize = 0;
6376 memAlloc.memoryTypeIndex = 0;
6377
6378 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
6379 memAlloc.allocationSize = memReqs.size;
6380 pass =
6381 m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
6382 ASSERT_TRUE(pass);
6383 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
6384 ASSERT_VK_SUCCESS(err);
6385
6386 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
6387 memAlloc.allocationSize = memReqs.size;
6388 pass =
6389 m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
6390 ASSERT_VK_SUCCESS(err);
6391 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
6392 ASSERT_VK_SUCCESS(err);
6393
6394 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
6395 ASSERT_VK_SUCCESS(err);
6396 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
6397 ASSERT_VK_SUCCESS(err);
6398
6399 BeginCommandBuffer();
6400 VkImageCopy copyRegion;
6401 copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
6402 copyRegion.srcSubresource.mipLevel = 0;
6403 copyRegion.srcSubresource.baseArrayLayer = 0;
6404 copyRegion.srcSubresource.layerCount = 0;
6405 copyRegion.srcOffset.x = 0;
6406 copyRegion.srcOffset.y = 0;
6407 copyRegion.srcOffset.z = 0;
6408 copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
6409 copyRegion.dstSubresource.mipLevel = 0;
6410 copyRegion.dstSubresource.baseArrayLayer = 0;
6411 copyRegion.dstSubresource.layerCount = 0;
6412 copyRegion.dstOffset.x = 0;
6413 copyRegion.dstOffset.y = 0;
6414 copyRegion.dstOffset.z = 0;
6415 copyRegion.extent.width = 1;
6416 copyRegion.extent.height = 1;
6417 copyRegion.extent.depth = 1;
6418 m_commandBuffer->CopyImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage,
6419 VK_IMAGE_LAYOUT_GENERAL, 1, ©Region);
6420 EndCommandBuffer();
6421
6422 if (!m_errorMonitor->DesiredMsgFound()) {
6423 FAIL() << "Did not receive Error 'vkCmdCopyImage called with unmatched "
6424 "source and dest image types'";
6425 m_errorMonitor->DumpFailureMsgs();
6426 }
6427
6428 vkDestroyImage(m_device->device(), srcImage, NULL);
6429 vkDestroyImage(m_device->device(), dstImage, NULL);
6430 vkFreeMemory(m_device->device(), srcMem, NULL);
6431 vkFreeMemory(m_device->device(), destMem, NULL);
6432 }
6433
TEST_F(VkLayerTest,CopyImageFormatSizeMismatch)6434 TEST_F(VkLayerTest, CopyImageFormatSizeMismatch) {
6435 // TODO : Create two images with different format sizes and vkCmdCopyImage
6436 // between them
6437 }
6438
TEST_F(VkLayerTest,CopyImageDepthStencilFormatMismatch)6439 TEST_F(VkLayerTest, CopyImageDepthStencilFormatMismatch) {
6440 VkResult err;
6441 bool pass;
6442
6443 m_errorMonitor->SetDesiredFailureMsg(
6444 VK_DEBUG_REPORT_ERROR_BIT_EXT,
6445 "vkCmdCopyImage called with unmatched source and dest image types");
6446
6447 ASSERT_NO_FATAL_FAILURE(InitState());
6448
6449 // Create two images of different types and try to copy between them
6450 VkImage srcImage;
6451 VkImage dstImage;
6452 VkDeviceMemory srcMem;
6453 VkDeviceMemory destMem;
6454 VkMemoryRequirements memReqs;
6455
6456 VkImageCreateInfo image_create_info = {};
6457 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
6458 image_create_info.pNext = NULL;
6459 image_create_info.imageType = VK_IMAGE_TYPE_2D;
6460 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
6461 image_create_info.extent.width = 32;
6462 image_create_info.extent.height = 32;
6463 image_create_info.extent.depth = 1;
6464 image_create_info.mipLevels = 1;
6465 image_create_info.arrayLayers = 1;
6466 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
6467 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
6468 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
6469 image_create_info.flags = 0;
6470
6471 err =
6472 vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
6473 ASSERT_VK_SUCCESS(err);
6474
6475 image_create_info.imageType = VK_IMAGE_TYPE_1D;
6476 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
6477 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
6478
6479 err =
6480 vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
6481 ASSERT_VK_SUCCESS(err);
6482
6483 // Allocate memory
6484 VkMemoryAllocateInfo memAlloc = {};
6485 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
6486 memAlloc.pNext = NULL;
6487 memAlloc.allocationSize = 0;
6488 memAlloc.memoryTypeIndex = 0;
6489
6490 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
6491 memAlloc.allocationSize = memReqs.size;
6492 pass =
6493 m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
6494 ASSERT_TRUE(pass);
6495 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
6496 ASSERT_VK_SUCCESS(err);
6497
6498 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
6499 memAlloc.allocationSize = memReqs.size;
6500 pass =
6501 m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
6502 ASSERT_TRUE(pass);
6503 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
6504 ASSERT_VK_SUCCESS(err);
6505
6506 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
6507 ASSERT_VK_SUCCESS(err);
6508 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
6509 ASSERT_VK_SUCCESS(err);
6510
6511 BeginCommandBuffer();
6512 VkImageCopy copyRegion;
6513 copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
6514 copyRegion.srcSubresource.mipLevel = 0;
6515 copyRegion.srcSubresource.baseArrayLayer = 0;
6516 copyRegion.srcSubresource.layerCount = 0;
6517 copyRegion.srcOffset.x = 0;
6518 copyRegion.srcOffset.y = 0;
6519 copyRegion.srcOffset.z = 0;
6520 copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
6521 copyRegion.dstSubresource.mipLevel = 0;
6522 copyRegion.dstSubresource.baseArrayLayer = 0;
6523 copyRegion.dstSubresource.layerCount = 0;
6524 copyRegion.dstOffset.x = 0;
6525 copyRegion.dstOffset.y = 0;
6526 copyRegion.dstOffset.z = 0;
6527 copyRegion.extent.width = 1;
6528 copyRegion.extent.height = 1;
6529 copyRegion.extent.depth = 1;
6530 m_commandBuffer->CopyImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage,
6531 VK_IMAGE_LAYOUT_GENERAL, 1, ©Region);
6532 EndCommandBuffer();
6533
6534 if (!m_errorMonitor->DesiredMsgFound()) {
6535 FAIL() << "Did not receive Error 'vkCmdCopyImage called with unmatched "
6536 "source and dest image types'";
6537 m_errorMonitor->DumpFailureMsgs();
6538 }
6539
6540 vkDestroyImage(m_device->device(), srcImage, NULL);
6541 vkDestroyImage(m_device->device(), dstImage, NULL);
6542 vkFreeMemory(m_device->device(), srcMem, NULL);
6543 vkFreeMemory(m_device->device(), destMem, NULL);
6544 }
6545
TEST_F(VkLayerTest,ResolveImageLowSampleCount)6546 TEST_F(VkLayerTest, ResolveImageLowSampleCount) {
6547 VkResult err;
6548 bool pass;
6549
6550 m_errorMonitor->SetDesiredFailureMsg(
6551 VK_DEBUG_REPORT_ERROR_BIT_EXT,
6552 "vkCmdResolveImage called with source sample count less than 2.");
6553
6554 ASSERT_NO_FATAL_FAILURE(InitState());
6555
6556 // Create two images of sample count 1 and try to Resolve between them
6557 VkImage srcImage;
6558 VkImage dstImage;
6559 VkDeviceMemory srcMem;
6560 VkDeviceMemory destMem;
6561 VkMemoryRequirements memReqs;
6562
6563 VkImageCreateInfo image_create_info = {};
6564 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
6565 image_create_info.pNext = NULL;
6566 image_create_info.imageType = VK_IMAGE_TYPE_2D;
6567 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
6568 image_create_info.extent.width = 32;
6569 image_create_info.extent.height = 1;
6570 image_create_info.extent.depth = 1;
6571 image_create_info.mipLevels = 1;
6572 image_create_info.arrayLayers = 1;
6573 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
6574 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
6575 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
6576 image_create_info.flags = 0;
6577
6578 err =
6579 vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
6580 ASSERT_VK_SUCCESS(err);
6581
6582 image_create_info.imageType = VK_IMAGE_TYPE_1D;
6583 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
6584
6585 err =
6586 vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
6587 ASSERT_VK_SUCCESS(err);
6588
6589 // Allocate memory
6590 VkMemoryAllocateInfo memAlloc = {};
6591 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
6592 memAlloc.pNext = NULL;
6593 memAlloc.allocationSize = 0;
6594 memAlloc.memoryTypeIndex = 0;
6595
6596 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
6597 memAlloc.allocationSize = memReqs.size;
6598 pass =
6599 m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
6600 ASSERT_TRUE(pass);
6601 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
6602 ASSERT_VK_SUCCESS(err);
6603
6604 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
6605 memAlloc.allocationSize = memReqs.size;
6606 pass =
6607 m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
6608 ASSERT_TRUE(pass);
6609 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
6610 ASSERT_VK_SUCCESS(err);
6611
6612 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
6613 ASSERT_VK_SUCCESS(err);
6614 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
6615 ASSERT_VK_SUCCESS(err);
6616
6617 BeginCommandBuffer();
6618 // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest?
6619 // VK_IMAGE_LAYOUT_UNDEFINED = 0,
6620 // VK_IMAGE_LAYOUT_GENERAL = 1,
6621 VkImageResolve resolveRegion;
6622 resolveRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
6623 resolveRegion.srcSubresource.mipLevel = 0;
6624 resolveRegion.srcSubresource.baseArrayLayer = 0;
6625 resolveRegion.srcSubresource.layerCount = 0;
6626 resolveRegion.srcOffset.x = 0;
6627 resolveRegion.srcOffset.y = 0;
6628 resolveRegion.srcOffset.z = 0;
6629 resolveRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
6630 resolveRegion.dstSubresource.mipLevel = 0;
6631 resolveRegion.dstSubresource.baseArrayLayer = 0;
6632 resolveRegion.dstSubresource.layerCount = 0;
6633 resolveRegion.dstOffset.x = 0;
6634 resolveRegion.dstOffset.y = 0;
6635 resolveRegion.dstOffset.z = 0;
6636 resolveRegion.extent.width = 1;
6637 resolveRegion.extent.height = 1;
6638 resolveRegion.extent.depth = 1;
6639 m_commandBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage,
6640 VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion);
6641 EndCommandBuffer();
6642
6643 if (!m_errorMonitor->DesiredMsgFound()) {
6644 FAIL() << "Did not receive Error 'vkCmdResolveImage called with source "
6645 "sample count less than 2.'";
6646 m_errorMonitor->DumpFailureMsgs();
6647 }
6648
6649 vkDestroyImage(m_device->device(), srcImage, NULL);
6650 vkDestroyImage(m_device->device(), dstImage, NULL);
6651 vkFreeMemory(m_device->device(), srcMem, NULL);
6652 vkFreeMemory(m_device->device(), destMem, NULL);
6653 }
6654
TEST_F(VkLayerTest,ResolveImageHighSampleCount)6655 TEST_F(VkLayerTest, ResolveImageHighSampleCount) {
6656 VkResult err;
6657 bool pass;
6658
6659 m_errorMonitor->SetDesiredFailureMsg(
6660 VK_DEBUG_REPORT_ERROR_BIT_EXT,
6661 "vkCmdResolveImage called with dest sample count greater than 1.");
6662
6663 ASSERT_NO_FATAL_FAILURE(InitState());
6664
6665 // Create two images of sample count 2 and try to Resolve between them
6666 VkImage srcImage;
6667 VkImage dstImage;
6668 VkDeviceMemory srcMem;
6669 VkDeviceMemory destMem;
6670 VkMemoryRequirements memReqs;
6671
6672 VkImageCreateInfo image_create_info = {};
6673 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
6674 image_create_info.pNext = NULL;
6675 image_create_info.imageType = VK_IMAGE_TYPE_2D;
6676 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
6677 image_create_info.extent.width = 32;
6678 image_create_info.extent.height = 1;
6679 image_create_info.extent.depth = 1;
6680 image_create_info.mipLevels = 1;
6681 image_create_info.arrayLayers = 1;
6682 image_create_info.samples = VK_SAMPLE_COUNT_2_BIT;
6683 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
6684 // Note: Some implementations expect color attachment usage for any
6685 // multisample surface
6686 image_create_info.usage =
6687 VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
6688 image_create_info.flags = 0;
6689
6690 err =
6691 vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
6692 ASSERT_VK_SUCCESS(err);
6693
6694 image_create_info.imageType = VK_IMAGE_TYPE_1D;
6695 // Note: Some implementations expect color attachment usage for any
6696 // multisample surface
6697 image_create_info.usage =
6698 VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
6699
6700 err =
6701 vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
6702 ASSERT_VK_SUCCESS(err);
6703
6704 // Allocate memory
6705 VkMemoryAllocateInfo memAlloc = {};
6706 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
6707 memAlloc.pNext = NULL;
6708 memAlloc.allocationSize = 0;
6709 memAlloc.memoryTypeIndex = 0;
6710
6711 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
6712 memAlloc.allocationSize = memReqs.size;
6713 pass =
6714 m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
6715 ASSERT_TRUE(pass);
6716 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
6717 ASSERT_VK_SUCCESS(err);
6718
6719 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
6720 memAlloc.allocationSize = memReqs.size;
6721 pass =
6722 m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
6723 ASSERT_TRUE(pass);
6724 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
6725 ASSERT_VK_SUCCESS(err);
6726
6727 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
6728 ASSERT_VK_SUCCESS(err);
6729 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
6730 ASSERT_VK_SUCCESS(err);
6731
6732 BeginCommandBuffer();
6733 // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest?
6734 // VK_IMAGE_LAYOUT_UNDEFINED = 0,
6735 // VK_IMAGE_LAYOUT_GENERAL = 1,
6736 VkImageResolve resolveRegion;
6737 resolveRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
6738 resolveRegion.srcSubresource.mipLevel = 0;
6739 resolveRegion.srcSubresource.baseArrayLayer = 0;
6740 resolveRegion.srcSubresource.layerCount = 0;
6741 resolveRegion.srcOffset.x = 0;
6742 resolveRegion.srcOffset.y = 0;
6743 resolveRegion.srcOffset.z = 0;
6744 resolveRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
6745 resolveRegion.dstSubresource.mipLevel = 0;
6746 resolveRegion.dstSubresource.baseArrayLayer = 0;
6747 resolveRegion.dstSubresource.layerCount = 0;
6748 resolveRegion.dstOffset.x = 0;
6749 resolveRegion.dstOffset.y = 0;
6750 resolveRegion.dstOffset.z = 0;
6751 resolveRegion.extent.width = 1;
6752 resolveRegion.extent.height = 1;
6753 resolveRegion.extent.depth = 1;
6754 m_commandBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage,
6755 VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion);
6756 EndCommandBuffer();
6757
6758 if (!m_errorMonitor->DesiredMsgFound()) {
6759 FAIL() << "Did not receive Error 'vkCmdResolveImage called with dest "
6760 "sample count greater than 1.'";
6761 m_errorMonitor->DumpFailureMsgs();
6762 }
6763
6764 vkDestroyImage(m_device->device(), srcImage, NULL);
6765 vkDestroyImage(m_device->device(), dstImage, NULL);
6766 vkFreeMemory(m_device->device(), srcMem, NULL);
6767 vkFreeMemory(m_device->device(), destMem, NULL);
6768 }
6769
TEST_F(VkLayerTest,ResolveImageFormatMismatch)6770 TEST_F(VkLayerTest, ResolveImageFormatMismatch) {
6771 VkResult err;
6772 bool pass;
6773
6774 m_errorMonitor->SetDesiredFailureMsg(
6775 VK_DEBUG_REPORT_ERROR_BIT_EXT,
6776 "vkCmdResolveImage called with unmatched source and dest formats.");
6777
6778 ASSERT_NO_FATAL_FAILURE(InitState());
6779
6780 // Create two images of different types and try to copy between them
6781 VkImage srcImage;
6782 VkImage dstImage;
6783 VkDeviceMemory srcMem;
6784 VkDeviceMemory destMem;
6785 VkMemoryRequirements memReqs;
6786
6787 VkImageCreateInfo image_create_info = {};
6788 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
6789 image_create_info.pNext = NULL;
6790 image_create_info.imageType = VK_IMAGE_TYPE_2D;
6791 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
6792 image_create_info.extent.width = 32;
6793 image_create_info.extent.height = 1;
6794 image_create_info.extent.depth = 1;
6795 image_create_info.mipLevels = 1;
6796 image_create_info.arrayLayers = 1;
6797 image_create_info.samples = VK_SAMPLE_COUNT_2_BIT;
6798 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
6799 // Note: Some implementations expect color attachment usage for any
6800 // multisample surface
6801 image_create_info.usage =
6802 VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
6803 image_create_info.flags = 0;
6804
6805 err =
6806 vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
6807 ASSERT_VK_SUCCESS(err);
6808
6809 // Set format to something other than source image
6810 image_create_info.format = VK_FORMAT_R32_SFLOAT;
6811 // Note: Some implementations expect color attachment usage for any
6812 // multisample surface
6813 image_create_info.usage =
6814 VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
6815 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
6816
6817 err =
6818 vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
6819 ASSERT_VK_SUCCESS(err);
6820
6821 // Allocate memory
6822 VkMemoryAllocateInfo memAlloc = {};
6823 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
6824 memAlloc.pNext = NULL;
6825 memAlloc.allocationSize = 0;
6826 memAlloc.memoryTypeIndex = 0;
6827
6828 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
6829 memAlloc.allocationSize = memReqs.size;
6830 pass =
6831 m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
6832 ASSERT_TRUE(pass);
6833 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
6834 ASSERT_VK_SUCCESS(err);
6835
6836 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
6837 memAlloc.allocationSize = memReqs.size;
6838 pass =
6839 m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
6840 ASSERT_TRUE(pass);
6841 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
6842 ASSERT_VK_SUCCESS(err);
6843
6844 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
6845 ASSERT_VK_SUCCESS(err);
6846 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
6847 ASSERT_VK_SUCCESS(err);
6848
6849 BeginCommandBuffer();
6850 // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest?
6851 // VK_IMAGE_LAYOUT_UNDEFINED = 0,
6852 // VK_IMAGE_LAYOUT_GENERAL = 1,
6853 VkImageResolve resolveRegion;
6854 resolveRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
6855 resolveRegion.srcSubresource.mipLevel = 0;
6856 resolveRegion.srcSubresource.baseArrayLayer = 0;
6857 resolveRegion.srcSubresource.layerCount = 0;
6858 resolveRegion.srcOffset.x = 0;
6859 resolveRegion.srcOffset.y = 0;
6860 resolveRegion.srcOffset.z = 0;
6861 resolveRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
6862 resolveRegion.dstSubresource.mipLevel = 0;
6863 resolveRegion.dstSubresource.baseArrayLayer = 0;
6864 resolveRegion.dstSubresource.layerCount = 0;
6865 resolveRegion.dstOffset.x = 0;
6866 resolveRegion.dstOffset.y = 0;
6867 resolveRegion.dstOffset.z = 0;
6868 resolveRegion.extent.width = 1;
6869 resolveRegion.extent.height = 1;
6870 resolveRegion.extent.depth = 1;
6871 m_commandBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage,
6872 VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion);
6873 EndCommandBuffer();
6874
6875 if (!m_errorMonitor->DesiredMsgFound()) {
6876 FAIL() << "Did not receive Error 'vkCmdResolveImage called with "
6877 "unmatched source and dest formats.'";
6878 m_errorMonitor->DumpFailureMsgs();
6879 }
6880
6881 vkDestroyImage(m_device->device(), srcImage, NULL);
6882 vkDestroyImage(m_device->device(), dstImage, NULL);
6883 vkFreeMemory(m_device->device(), srcMem, NULL);
6884 vkFreeMemory(m_device->device(), destMem, NULL);
6885 }
6886
TEST_F(VkLayerTest,ResolveImageTypeMismatch)6887 TEST_F(VkLayerTest, ResolveImageTypeMismatch) {
6888 VkResult err;
6889 bool pass;
6890
6891 m_errorMonitor->SetDesiredFailureMsg(
6892 VK_DEBUG_REPORT_ERROR_BIT_EXT,
6893 "vkCmdResolveImage called with unmatched source and dest image types.");
6894
6895 ASSERT_NO_FATAL_FAILURE(InitState());
6896
6897 // Create two images of different types and try to copy between them
6898 VkImage srcImage;
6899 VkImage dstImage;
6900 VkDeviceMemory srcMem;
6901 VkDeviceMemory destMem;
6902 VkMemoryRequirements memReqs;
6903
6904 VkImageCreateInfo image_create_info = {};
6905 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
6906 image_create_info.pNext = NULL;
6907 image_create_info.imageType = VK_IMAGE_TYPE_2D;
6908 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
6909 image_create_info.extent.width = 32;
6910 image_create_info.extent.height = 1;
6911 image_create_info.extent.depth = 1;
6912 image_create_info.mipLevels = 1;
6913 image_create_info.arrayLayers = 1;
6914 image_create_info.samples = VK_SAMPLE_COUNT_2_BIT;
6915 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
6916 // Note: Some implementations expect color attachment usage for any
6917 // multisample surface
6918 image_create_info.usage =
6919 VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
6920 image_create_info.flags = 0;
6921
6922 err =
6923 vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
6924 ASSERT_VK_SUCCESS(err);
6925
6926 image_create_info.imageType = VK_IMAGE_TYPE_1D;
6927 // Note: Some implementations expect color attachment usage for any
6928 // multisample surface
6929 image_create_info.usage =
6930 VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
6931 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
6932
6933 err =
6934 vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
6935 ASSERT_VK_SUCCESS(err);
6936
6937 // Allocate memory
6938 VkMemoryAllocateInfo memAlloc = {};
6939 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
6940 memAlloc.pNext = NULL;
6941 memAlloc.allocationSize = 0;
6942 memAlloc.memoryTypeIndex = 0;
6943
6944 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
6945 memAlloc.allocationSize = memReqs.size;
6946 pass =
6947 m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
6948 ASSERT_TRUE(pass);
6949 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
6950 ASSERT_VK_SUCCESS(err);
6951
6952 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
6953 memAlloc.allocationSize = memReqs.size;
6954 pass =
6955 m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
6956 ASSERT_TRUE(pass);
6957 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
6958 ASSERT_VK_SUCCESS(err);
6959
6960 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
6961 ASSERT_VK_SUCCESS(err);
6962 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
6963 ASSERT_VK_SUCCESS(err);
6964
6965 BeginCommandBuffer();
6966 // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest?
6967 // VK_IMAGE_LAYOUT_UNDEFINED = 0,
6968 // VK_IMAGE_LAYOUT_GENERAL = 1,
6969 VkImageResolve resolveRegion;
6970 resolveRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
6971 resolveRegion.srcSubresource.mipLevel = 0;
6972 resolveRegion.srcSubresource.baseArrayLayer = 0;
6973 resolveRegion.srcSubresource.layerCount = 0;
6974 resolveRegion.srcOffset.x = 0;
6975 resolveRegion.srcOffset.y = 0;
6976 resolveRegion.srcOffset.z = 0;
6977 resolveRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
6978 resolveRegion.dstSubresource.mipLevel = 0;
6979 resolveRegion.dstSubresource.baseArrayLayer = 0;
6980 resolveRegion.dstSubresource.layerCount = 0;
6981 resolveRegion.dstOffset.x = 0;
6982 resolveRegion.dstOffset.y = 0;
6983 resolveRegion.dstOffset.z = 0;
6984 resolveRegion.extent.width = 1;
6985 resolveRegion.extent.height = 1;
6986 resolveRegion.extent.depth = 1;
6987 m_commandBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage,
6988 VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion);
6989 EndCommandBuffer();
6990
6991 if (!m_errorMonitor->DesiredMsgFound()) {
6992 FAIL() << "Did not receive Error 'vkCmdResolveImage called with "
6993 "unmatched source and dest image types.'";
6994 m_errorMonitor->DumpFailureMsgs();
6995 }
6996
6997 vkDestroyImage(m_device->device(), srcImage, NULL);
6998 vkDestroyImage(m_device->device(), dstImage, NULL);
6999 vkFreeMemory(m_device->device(), srcMem, NULL);
7000 vkFreeMemory(m_device->device(), destMem, NULL);
7001 }
7002
TEST_F(VkLayerTest,DepthStencilImageViewWithColorAspectBitError)7003 TEST_F(VkLayerTest, DepthStencilImageViewWithColorAspectBitError) {
7004 // Create a single Image descriptor and cause it to first hit an error due
7005 // to using a DS format, then cause it to hit error due to COLOR_BIT not
7006 // set in aspect
7007 // The image format check comes 2nd in validation so we trigger it first,
7008 // then when we cause aspect fail next, bad format check will be preempted
7009 VkResult err;
7010
7011 m_errorMonitor->SetDesiredFailureMsg(
7012 VK_DEBUG_REPORT_ERROR_BIT_EXT,
7013 "Combination depth/stencil image formats can have only the ");
7014
7015 ASSERT_NO_FATAL_FAILURE(InitState());
7016
7017 VkDescriptorPoolSize ds_type_count = {};
7018 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
7019 ds_type_count.descriptorCount = 1;
7020
7021 VkDescriptorPoolCreateInfo ds_pool_ci = {};
7022 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
7023 ds_pool_ci.pNext = NULL;
7024 ds_pool_ci.maxSets = 1;
7025 ds_pool_ci.poolSizeCount = 1;
7026 ds_pool_ci.pPoolSizes = &ds_type_count;
7027
7028 VkDescriptorPool ds_pool;
7029 err =
7030 vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
7031 ASSERT_VK_SUCCESS(err);
7032
7033 VkDescriptorSetLayoutBinding dsl_binding = {};
7034 dsl_binding.binding = 0;
7035 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
7036 dsl_binding.descriptorCount = 1;
7037 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
7038 dsl_binding.pImmutableSamplers = NULL;
7039
7040 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
7041 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
7042 ds_layout_ci.pNext = NULL;
7043 ds_layout_ci.bindingCount = 1;
7044 ds_layout_ci.pBindings = &dsl_binding;
7045 VkDescriptorSetLayout ds_layout;
7046 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
7047 &ds_layout);
7048 ASSERT_VK_SUCCESS(err);
7049
7050 VkDescriptorSet descriptorSet;
7051 VkDescriptorSetAllocateInfo alloc_info = {};
7052 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
7053 alloc_info.descriptorSetCount = 1;
7054 alloc_info.descriptorPool = ds_pool;
7055 alloc_info.pSetLayouts = &ds_layout;
7056 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info,
7057 &descriptorSet);
7058 ASSERT_VK_SUCCESS(err);
7059
7060 VkImage image_bad;
7061 VkImage image_good;
7062 // One bad format and one good format for Color attachment
7063 const VkFormat tex_format_bad = VK_FORMAT_D32_SFLOAT_S8_UINT;
7064 const VkFormat tex_format_good = VK_FORMAT_B8G8R8A8_UNORM;
7065 const int32_t tex_width = 32;
7066 const int32_t tex_height = 32;
7067
7068 VkImageCreateInfo image_create_info = {};
7069 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
7070 image_create_info.pNext = NULL;
7071 image_create_info.imageType = VK_IMAGE_TYPE_2D;
7072 image_create_info.format = tex_format_bad;
7073 image_create_info.extent.width = tex_width;
7074 image_create_info.extent.height = tex_height;
7075 image_create_info.extent.depth = 1;
7076 image_create_info.mipLevels = 1;
7077 image_create_info.arrayLayers = 1;
7078 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
7079 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
7080 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT |
7081 VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT;
7082 image_create_info.flags = 0;
7083
7084 err =
7085 vkCreateImage(m_device->device(), &image_create_info, NULL, &image_bad);
7086 ASSERT_VK_SUCCESS(err);
7087 image_create_info.format = tex_format_good;
7088 image_create_info.usage =
7089 VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
7090 err = vkCreateImage(m_device->device(), &image_create_info, NULL,
7091 &image_good);
7092 ASSERT_VK_SUCCESS(err);
7093
7094 VkImageViewCreateInfo image_view_create_info = {};
7095 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
7096 image_view_create_info.image = image_bad;
7097 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
7098 image_view_create_info.format = tex_format_bad;
7099 image_view_create_info.subresourceRange.baseArrayLayer = 0;
7100 image_view_create_info.subresourceRange.baseMipLevel = 0;
7101 image_view_create_info.subresourceRange.layerCount = 1;
7102 image_view_create_info.subresourceRange.levelCount = 1;
7103 image_view_create_info.subresourceRange.aspectMask =
7104 VK_IMAGE_ASPECT_COLOR_BIT;
7105
7106 VkImageView view;
7107 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL,
7108 &view);
7109
7110 if (!m_errorMonitor->DesiredMsgFound()) {
7111 FAIL() << "Did not receive Error 'Combination depth-stencil image "
7112 "formats can have only the....'";
7113 m_errorMonitor->DumpFailureMsgs();
7114 }
7115
7116 vkDestroyImage(m_device->device(), image_bad, NULL);
7117 vkDestroyImage(m_device->device(), image_good, NULL);
7118 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
7119 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
7120 }
7121 #endif // IMAGE_TESTS
7122
main(int argc,char ** argv)7123 int main(int argc, char **argv) {
7124 int result;
7125
7126 ::testing::InitGoogleTest(&argc, argv);
7127 VkTestFramework::InitArgs(&argc, argv);
7128
7129 ::testing::AddGlobalTestEnvironment(new TestEnvironment);
7130
7131 result = RUN_ALL_TESTS();
7132
7133 VkTestFramework::Finish();
7134 return result;
7135 }
7136