Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2015-2016 The Khronos Group Inc. |
| 3 | * Copyright (c) 2015-2016 Valve Corporation |
| 4 | * Copyright (c) 2015-2016 LunarG, Inc. |
Michael Lentine | 0a369f6 | 2016-02-03 16:51:46 -0600 | [diff] [blame] | 5 | * Copyright (c) 2015-2016 Google, Inc. |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6 | * |
Jon Ashburn | 3ebf125 | 2016-04-19 11:30:31 -0600 | [diff] [blame] | 7 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 8 | * you may not use this file except in compliance with the License. |
| 9 | * You may obtain a copy of the License at |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 10 | * |
Jon Ashburn | 3ebf125 | 2016-04-19 11:30:31 -0600 | [diff] [blame] | 11 | * http://www.apache.org/licenses/LICENSE-2.0 |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12 | * |
| 13 | * Author: Chia-I Wu <olvaffe@gmail.com> |
| 14 | * Author: Chris Forbes <chrisf@ijw.co.nz> |
| 15 | * Author: Courtney Goeltzenleuchter <courtney@LunarG.com> |
| 16 | * Author: Mark Lobodzinski <mark@lunarg.com> |
| 17 | * Author: Mike Stroyan <mike@LunarG.com> |
| 18 | * Author: Tobin Ehlis <tobine@google.com> |
| 19 | * Author: Tony Barbour <tony@LunarG.com> |
| 20 | */ |
Tony Barbour | 65c48b3 | 2015-11-17 10:02:56 -0700 | [diff] [blame] | 21 | |
Cody Northrop | 8e54a40 | 2016-03-08 22:25:52 -0700 | [diff] [blame] | 22 | #ifdef ANDROID |
| 23 | #include "vulkan_wrapper.h" |
| 24 | #else |
David Pinedo | 9316d3b | 2015-11-06 12:54:48 -0700 | [diff] [blame] | 25 | #include <vulkan/vulkan.h> |
Cody Northrop | 8e54a40 | 2016-03-08 22:25:52 -0700 | [diff] [blame] | 26 | #endif |
Courtney Goeltzenleuchter | 58f3eff | 2015-10-07 13:28:58 -0600 | [diff] [blame] | 27 | #include "test_common.h" |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 28 | #include "vkrenderframework.h" |
Tobin Ehlis | a0cb02e | 2015-07-03 10:15:26 -0600 | [diff] [blame] | 29 | #include "vk_layer_config.h" |
Jon Ashburn | 7fa7e22 | 2016-02-02 12:08:10 -0700 | [diff] [blame] | 30 | #include "icd-spv.h" |
Tony Barbour | 300a608 | 2015-04-07 13:44:53 -0600 | [diff] [blame] | 31 | |
Mark Lobodzinski | 3780e14 | 2015-05-14 15:08:13 -0500 | [diff] [blame] | 32 | #define GLM_FORCE_RADIANS |
| 33 | #include "glm/glm.hpp" |
| 34 | #include <glm/gtc/matrix_transform.hpp> |
| 35 | |
Dustin Graves | ffa90fa | 2016-05-06 11:20:38 -0600 | [diff] [blame] | 36 | #define PARAMETER_VALIDATION_TESTS 1 |
Tobin Ehlis | 0788f52 | 2015-05-26 16:11:58 -0600 | [diff] [blame] | 37 | #define MEM_TRACKER_TESTS 1 |
| 38 | #define OBJ_TRACKER_TESTS 1 |
| 39 | #define DRAW_STATE_TESTS 1 |
| 40 | #define THREADING_TESTS 1 |
Chris Forbes | 9f7ff63 | 2015-05-25 11:13:08 +1200 | [diff] [blame] | 41 | #define SHADER_CHECKER_TESTS 1 |
Mark Lobodzinski | 209b529 | 2015-09-17 09:44:05 -0600 | [diff] [blame] | 42 | #define DEVICE_LIMITS_TESTS 1 |
Tobin Ehlis | cde0889 | 2015-09-22 10:11:37 -0600 | [diff] [blame] | 43 | #define IMAGE_TESTS 1 |
Tobin Ehlis | 0788f52 | 2015-05-26 16:11:58 -0600 | [diff] [blame] | 44 | |
Mark Lobodzinski | 3780e14 | 2015-05-14 15:08:13 -0500 | [diff] [blame] | 45 | //-------------------------------------------------------------------------------------- |
| 46 | // Mesh and VertexFormat Data |
| 47 | //-------------------------------------------------------------------------------------- |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 48 | struct Vertex { |
| 49 | float posX, posY, posZ, posW; // Position data |
| 50 | float r, g, b, a; // Color |
Mark Lobodzinski | 3780e14 | 2015-05-14 15:08:13 -0500 | [diff] [blame] | 51 | }; |
| 52 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 53 | #define XYZ1(_x_, _y_, _z_) (_x_), (_y_), (_z_), 1.f |
Mark Lobodzinski | 3780e14 | 2015-05-14 15:08:13 -0500 | [diff] [blame] | 54 | |
| 55 | typedef enum _BsoFailSelect { |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 56 | BsoFailNone = 0x00000000, |
| 57 | BsoFailLineWidth = 0x00000001, |
| 58 | BsoFailDepthBias = 0x00000002, |
| 59 | BsoFailViewport = 0x00000004, |
| 60 | BsoFailScissor = 0x00000008, |
| 61 | BsoFailBlend = 0x00000010, |
| 62 | BsoFailDepthBounds = 0x00000020, |
| 63 | BsoFailStencilReadMask = 0x00000040, |
| 64 | BsoFailStencilWriteMask = 0x00000080, |
| 65 | BsoFailStencilReference = 0x00000100, |
Mark Mueller | d491441 | 2016-06-13 17:52:06 -0600 | [diff] [blame] | 66 | BsoFailCmdClearAttachments = 0x00000200, |
Mark Lobodzinski | 3780e14 | 2015-05-14 15:08:13 -0500 | [diff] [blame] | 67 | } BsoFailSelect; |
| 68 | |
| 69 | struct vktriangle_vs_uniform { |
| 70 | // Must start with MVP |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 71 | float mvp[4][4]; |
| 72 | float position[3][4]; |
| 73 | float color[3][4]; |
Mark Lobodzinski | 3780e14 | 2015-05-14 15:08:13 -0500 | [diff] [blame] | 74 | }; |
| 75 | |
Mark Lobodzinski | 75a97e6 | 2015-06-02 09:41:30 -0500 | [diff] [blame] | 76 | static const char bindStateVertShaderText[] = |
Chris Forbes | 7b34280 | 2016-04-07 13:20:10 +1200 | [diff] [blame] | 77 | "#version 450\n" |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 78 | "vec2 vertices[3];\n" |
| 79 | "out gl_PerVertex {\n" |
| 80 | " vec4 gl_Position;\n" |
| 81 | "};\n" |
| 82 | "void main() {\n" |
| 83 | " vertices[0] = vec2(-1.0, -1.0);\n" |
| 84 | " vertices[1] = vec2( 1.0, -1.0);\n" |
| 85 | " vertices[2] = vec2( 0.0, 1.0);\n" |
| 86 | " gl_Position = vec4(vertices[gl_VertexIndex % 3], 0.0, 1.0);\n" |
| 87 | "}\n"; |
Mark Lobodzinski | 3780e14 | 2015-05-14 15:08:13 -0500 | [diff] [blame] | 88 | |
Mark Lobodzinski | 75a97e6 | 2015-06-02 09:41:30 -0500 | [diff] [blame] | 89 | static const char bindStateFragShaderText[] = |
Chris Forbes | 7b34280 | 2016-04-07 13:20:10 +1200 | [diff] [blame] | 90 | "#version 450\n" |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 91 | "\n" |
| 92 | "layout(location = 0) out vec4 uFragColor;\n" |
| 93 | "void main(){\n" |
| 94 | " uFragColor = vec4(0,1,0,1);\n" |
| 95 | "}\n"; |
Mark Lobodzinski | 3780e14 | 2015-05-14 15:08:13 -0500 | [diff] [blame] | 96 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 97 | static VKAPI_ATTR VkBool32 VKAPI_CALL |
| 98 | myDbgFunc(VkFlags msgFlags, VkDebugReportObjectTypeEXT objType, |
| 99 | uint64_t srcObject, size_t location, int32_t msgCode, |
| 100 | const char *pLayerPrefix, const char *pMsg, void *pUserData); |
Tony Barbour | 300a608 | 2015-04-07 13:44:53 -0600 | [diff] [blame] | 101 | |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 102 | // ******************************************************** |
| 103 | // ErrorMonitor Usage: |
| 104 | // |
| 105 | // Call SetDesiredFailureMsg with a string to be compared against all |
| 106 | // encountered log messages. Passing NULL will match all log messages. |
| 107 | // logMsg will return true for skipCall only if msg is matched or NULL. |
| 108 | // |
| 109 | // Call DesiredMsgFound to determine if the desired failure message |
| 110 | // was encountered. |
| 111 | |
Tony Barbour | 300a608 | 2015-04-07 13:44:53 -0600 | [diff] [blame] | 112 | class ErrorMonitor { |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 113 | public: |
| 114 | ErrorMonitor() { |
Mike Stroyan | 4268d1f | 2015-07-13 14:45:35 -0600 | [diff] [blame] | 115 | test_platform_thread_create_mutex(&m_mutex); |
| 116 | test_platform_thread_lock_mutex(&m_mutex); |
Mark Lobodzinski | 510e20d | 2016-02-11 09:26:16 -0700 | [diff] [blame] | 117 | m_msgFlags = VK_DEBUG_REPORT_INFORMATION_BIT_EXT; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 118 | m_bailout = NULL; |
Mike Stroyan | 4268d1f | 2015-07-13 14:45:35 -0600 | [diff] [blame] | 119 | test_platform_thread_unlock_mutex(&m_mutex); |
Tony Barbour | 300a608 | 2015-04-07 13:44:53 -0600 | [diff] [blame] | 120 | } |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 121 | |
Dustin Graves | 4845814 | 2016-04-29 16:11:55 -0600 | [diff] [blame] | 122 | ~ErrorMonitor() { test_platform_thread_delete_mutex(&m_mutex); } |
| 123 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 124 | void SetDesiredFailureMsg(VkFlags msgFlags, const char *msgString) { |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 125 | // also discard all collected messages to this point |
Mike Stroyan | 4268d1f | 2015-07-13 14:45:35 -0600 | [diff] [blame] | 126 | test_platform_thread_lock_mutex(&m_mutex); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 127 | m_failureMsg.clear(); |
| 128 | m_otherMsgs.clear(); |
| 129 | m_desiredMsg = msgString; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 130 | m_msgFound = VK_FALSE; |
| 131 | m_msgFlags = msgFlags; |
Mike Stroyan | 4268d1f | 2015-07-13 14:45:35 -0600 | [diff] [blame] | 132 | test_platform_thread_unlock_mutex(&m_mutex); |
Tony Barbour | 300a608 | 2015-04-07 13:44:53 -0600 | [diff] [blame] | 133 | } |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 134 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 135 | VkBool32 CheckForDesiredMsg(VkFlags msgFlags, const char *msgString) { |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 136 | VkBool32 result = VK_FALSE; |
Mike Stroyan | 4268d1f | 2015-07-13 14:45:35 -0600 | [diff] [blame] | 137 | test_platform_thread_lock_mutex(&m_mutex); |
Mike Stroyan | accf769 | 2015-05-12 16:00:45 -0600 | [diff] [blame] | 138 | if (m_bailout != NULL) { |
| 139 | *m_bailout = true; |
| 140 | } |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 141 | string errorString(msgString); |
| 142 | if (msgFlags & m_msgFlags) { |
| 143 | if (errorString.find(m_desiredMsg) != string::npos) { |
Chris Forbes | c7b8ad7 | 2016-04-04 18:50:38 +1200 | [diff] [blame] | 144 | if (m_msgFound) { /* if multiple matches, don't lose all but the last! */ |
| 145 | m_otherMsgs.push_back(m_failureMsg); |
| 146 | } |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 147 | m_failureMsg = errorString; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 148 | m_msgFound = VK_TRUE; |
| 149 | result = VK_TRUE; |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 150 | } else { |
| 151 | m_otherMsgs.push_back(errorString); |
| 152 | } |
| 153 | } |
Mike Stroyan | 4268d1f | 2015-07-13 14:45:35 -0600 | [diff] [blame] | 154 | test_platform_thread_unlock_mutex(&m_mutex); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 155 | return result; |
Mike Stroyan | accf769 | 2015-05-12 16:00:45 -0600 | [diff] [blame] | 156 | } |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 157 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 158 | vector<string> GetOtherFailureMsgs(void) { return m_otherMsgs; } |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 159 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 160 | string GetFailureMsg(void) { return m_failureMsg; } |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 161 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 162 | VkBool32 DesiredMsgFound(void) { return m_msgFound; } |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 163 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 164 | void SetBailout(bool *bailout) { m_bailout = bailout; } |
Tony Barbour | 300a608 | 2015-04-07 13:44:53 -0600 | [diff] [blame] | 165 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 166 | void DumpFailureMsgs(void) { |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 167 | vector<string> otherMsgs = GetOtherFailureMsgs(); |
| 168 | cout << "Other error messages logged for this test were:" << endl; |
| 169 | for (auto iter = otherMsgs.begin(); iter != otherMsgs.end(); iter++) { |
| 170 | cout << " " << *iter << endl; |
| 171 | } |
| 172 | } |
| 173 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 174 | /* helpers */ |
| 175 | |
| 176 | void ExpectSuccess() { |
| 177 | // match anything |
| 178 | SetDesiredFailureMsg(~0u, ""); |
| 179 | } |
| 180 | |
| 181 | void VerifyFound() { |
| 182 | // Not seeing the desired message is a failure. /Before/ throwing, dump |
| 183 | // any other messages. |
| 184 | if (!DesiredMsgFound()) { |
| 185 | DumpFailureMsgs(); |
| 186 | FAIL() << "Did not receive expected error '" << m_desiredMsg << "'"; |
| 187 | } |
| 188 | } |
| 189 | |
| 190 | void VerifyNotFound() { |
| 191 | // ExpectSuccess() configured us to match anything. Any error is a |
| 192 | // failure. |
| 193 | if (DesiredMsgFound()) { |
| 194 | DumpFailureMsgs(); |
| 195 | FAIL() << "Expected to succeed but got error: " << GetFailureMsg(); |
| 196 | } |
| 197 | } |
| 198 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 199 | private: |
| 200 | VkFlags m_msgFlags; |
| 201 | string m_desiredMsg; |
| 202 | string m_failureMsg; |
| 203 | vector<string> m_otherMsgs; |
Mike Stroyan | 4268d1f | 2015-07-13 14:45:35 -0600 | [diff] [blame] | 204 | test_platform_thread_mutex m_mutex; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 205 | bool *m_bailout; |
| 206 | VkBool32 m_msgFound; |
Tony Barbour | 300a608 | 2015-04-07 13:44:53 -0600 | [diff] [blame] | 207 | }; |
Mark Lobodzinski | 3780e14 | 2015-05-14 15:08:13 -0500 | [diff] [blame] | 208 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 209 | static VKAPI_ATTR VkBool32 VKAPI_CALL |
| 210 | myDbgFunc(VkFlags msgFlags, VkDebugReportObjectTypeEXT objType, |
| 211 | uint64_t srcObject, size_t location, int32_t msgCode, |
| 212 | const char *pLayerPrefix, const char *pMsg, void *pUserData) { |
| 213 | if (msgFlags & |
Mark Lobodzinski | 510e20d | 2016-02-11 09:26:16 -0700 | [diff] [blame] | 214 | (VK_DEBUG_REPORT_WARNING_BIT_EXT | VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 215 | VK_DEBUG_REPORT_ERROR_BIT_EXT)) { |
Tony Barbour | 0b4d956 | 2015-04-09 10:48:04 -0600 | [diff] [blame] | 216 | ErrorMonitor *errMonitor = (ErrorMonitor *)pUserData; |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 217 | return errMonitor->CheckForDesiredMsg(msgFlags, pMsg); |
Tony Barbour | 0b4d956 | 2015-04-09 10:48:04 -0600 | [diff] [blame] | 218 | } |
Courtney Goeltzenleuchter | 0664083 | 2015-09-04 13:52:24 -0600 | [diff] [blame] | 219 | return false; |
Tony Barbour | 300a608 | 2015-04-07 13:44:53 -0600 | [diff] [blame] | 220 | } |
Mark Lobodzinski | 3780e14 | 2015-05-14 15:08:13 -0500 | [diff] [blame] | 221 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 222 | class VkLayerTest : public VkRenderFramework { |
| 223 | public: |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 224 | VkResult BeginCommandBuffer(VkCommandBufferObj &commandBuffer); |
| 225 | VkResult EndCommandBuffer(VkCommandBufferObj &commandBuffer); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 226 | void VKTriangleTest(const char *vertShaderText, const char *fragShaderText, |
| 227 | BsoFailSelect failMask); |
| 228 | void GenericDrawPreparation(VkCommandBufferObj *commandBuffer, |
| 229 | VkPipelineObj &pipelineobj, |
| 230 | VkDescriptorSetObj &descriptorSet, |
| 231 | BsoFailSelect failMask); |
| 232 | void GenericDrawPreparation(VkPipelineObj &pipelineobj, |
| 233 | VkDescriptorSetObj &descriptorSet, |
| 234 | BsoFailSelect failMask) { |
| 235 | GenericDrawPreparation(m_commandBuffer, pipelineobj, descriptorSet, |
| 236 | failMask); |
| 237 | } |
Tony Barbour | 300a608 | 2015-04-07 13:44:53 -0600 | [diff] [blame] | 238 | |
Tony Barbour | fe3351b | 2015-07-28 10:17:20 -0600 | [diff] [blame] | 239 | /* Convenience functions that use built-in command buffer */ |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 240 | VkResult BeginCommandBuffer() { |
| 241 | return BeginCommandBuffer(*m_commandBuffer); |
| 242 | } |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 243 | VkResult EndCommandBuffer() { return EndCommandBuffer(*m_commandBuffer); } |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 244 | void Draw(uint32_t vertexCount, uint32_t instanceCount, |
| 245 | uint32_t firstVertex, uint32_t firstInstance) { |
| 246 | m_commandBuffer->Draw(vertexCount, instanceCount, firstVertex, |
| 247 | firstInstance); |
| 248 | } |
| 249 | void DrawIndexed(uint32_t indexCount, uint32_t instanceCount, |
| 250 | uint32_t firstIndex, int32_t vertexOffset, |
| 251 | uint32_t firstInstance) { |
| 252 | m_commandBuffer->DrawIndexed(indexCount, instanceCount, firstIndex, |
| 253 | vertexOffset, firstInstance); |
| 254 | } |
Mark Lobodzinski | cf0ae75 | 2016-06-23 10:02:24 -0600 | [diff] [blame] | 255 | void QueueCommandBuffer() { m_commandBuffer->QueueCommandBuffer(); } |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 256 | void QueueCommandBuffer(const VkFence &fence) { |
| 257 | m_commandBuffer->QueueCommandBuffer(fence); |
| 258 | } |
| 259 | void BindVertexBuffer(VkConstantBufferObj *vertexBuffer, |
| 260 | VkDeviceSize offset, uint32_t binding) { |
| 261 | m_commandBuffer->BindVertexBuffer(vertexBuffer, offset, binding); |
| 262 | } |
| 263 | void BindIndexBuffer(VkIndexBufferObj *indexBuffer, VkDeviceSize offset) { |
| 264 | m_commandBuffer->BindIndexBuffer(indexBuffer, offset); |
| 265 | } |
| 266 | |
| 267 | protected: |
| 268 | ErrorMonitor *m_errorMonitor; |
Ian Elliott | 2c1daf5 | 2016-05-12 09:41:46 -0600 | [diff] [blame] | 269 | bool m_enableWSI; |
Tony Barbour | 300a608 | 2015-04-07 13:44:53 -0600 | [diff] [blame] | 270 | |
| 271 | virtual void SetUp() { |
Courtney Goeltzenleuchter | cd69eee | 2015-07-06 09:10:47 -0600 | [diff] [blame] | 272 | std::vector<const char *> instance_layer_names; |
| 273 | std::vector<const char *> device_layer_names; |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 274 | std::vector<const char *> instance_extension_names; |
| 275 | std::vector<const char *> device_extension_names; |
Tony Barbour | 3fdff9e | 2015-04-23 12:55:36 -0600 | [diff] [blame] | 276 | |
Courtney Goeltzenleuchter | 7415d5a | 2015-12-09 15:48:16 -0700 | [diff] [blame] | 277 | instance_extension_names.push_back(VK_EXT_DEBUG_REPORT_EXTENSION_NAME); |
Courtney Goeltzenleuchter | c2b06fe | 2015-06-16 15:59:11 -0600 | [diff] [blame] | 278 | /* |
| 279 | * Since CreateDbgMsgCallback is an instance level extension call |
| 280 | * any extension / layer that utilizes that feature also needs |
| 281 | * to be enabled at create instance time. |
| 282 | */ |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 283 | // Use Threading layer first to protect others from |
| 284 | // ThreadCommandBufferCollision test |
Courtney Goeltzenleuchter | 7688532 | 2016-02-06 17:11:22 -0700 | [diff] [blame] | 285 | instance_layer_names.push_back("VK_LAYER_GOOGLE_threading"); |
Tobin Ehlis | 24aab04 | 2016-03-24 10:54:18 -0600 | [diff] [blame] | 286 | instance_layer_names.push_back("VK_LAYER_LUNARG_parameter_validation"); |
Michael Lentine | 03107b4 | 2015-12-11 10:49:51 -0800 | [diff] [blame] | 287 | instance_layer_names.push_back("VK_LAYER_LUNARG_object_tracker"); |
Tobin Ehlis | c96f806 | 2016-03-09 16:12:48 -0700 | [diff] [blame] | 288 | instance_layer_names.push_back("VK_LAYER_LUNARG_core_validation"); |
Michael Lentine | 03107b4 | 2015-12-11 10:49:51 -0800 | [diff] [blame] | 289 | instance_layer_names.push_back("VK_LAYER_LUNARG_device_limits"); |
| 290 | instance_layer_names.push_back("VK_LAYER_LUNARG_image"); |
Ian Elliott | e48a138 | 2016-04-28 14:22:58 -0600 | [diff] [blame] | 291 | instance_layer_names.push_back("VK_LAYER_LUNARG_swapchain"); |
Dustin Graves | eaa78cd | 2016-01-26 16:30:22 -0700 | [diff] [blame] | 292 | instance_layer_names.push_back("VK_LAYER_GOOGLE_unique_objects"); |
Courtney Goeltzenleuchter | d971b61 | 2015-06-17 20:51:59 -0600 | [diff] [blame] | 293 | |
Courtney Goeltzenleuchter | 7688532 | 2016-02-06 17:11:22 -0700 | [diff] [blame] | 294 | device_layer_names.push_back("VK_LAYER_GOOGLE_threading"); |
Tobin Ehlis | 24aab04 | 2016-03-24 10:54:18 -0600 | [diff] [blame] | 295 | device_layer_names.push_back("VK_LAYER_LUNARG_parameter_validation"); |
Michael Lentine | 03107b4 | 2015-12-11 10:49:51 -0800 | [diff] [blame] | 296 | device_layer_names.push_back("VK_LAYER_LUNARG_object_tracker"); |
Tobin Ehlis | c96f806 | 2016-03-09 16:12:48 -0700 | [diff] [blame] | 297 | device_layer_names.push_back("VK_LAYER_LUNARG_core_validation"); |
Michael Lentine | 03107b4 | 2015-12-11 10:49:51 -0800 | [diff] [blame] | 298 | device_layer_names.push_back("VK_LAYER_LUNARG_device_limits"); |
| 299 | device_layer_names.push_back("VK_LAYER_LUNARG_image"); |
Ian Elliott | e48a138 | 2016-04-28 14:22:58 -0600 | [diff] [blame] | 300 | device_layer_names.push_back("VK_LAYER_LUNARG_swapchain"); |
Dustin Graves | eaa78cd | 2016-01-26 16:30:22 -0700 | [diff] [blame] | 301 | device_layer_names.push_back("VK_LAYER_GOOGLE_unique_objects"); |
Tony Barbour | 300a608 | 2015-04-07 13:44:53 -0600 | [diff] [blame] | 302 | |
Ian Elliott | 2c1daf5 | 2016-05-12 09:41:46 -0600 | [diff] [blame] | 303 | if (m_enableWSI) { |
| 304 | instance_extension_names.push_back(VK_KHR_SURFACE_EXTENSION_NAME); |
| 305 | device_extension_names.push_back(VK_KHR_SWAPCHAIN_EXTENSION_NAME); |
| 306 | #ifdef NEED_TO_TEST_THIS_ON_PLATFORM |
| 307 | #if defined(VK_USE_PLATFORM_ANDROID_KHR) |
| 308 | instance_extension_names.push_back(VK_KHR_ANDROID_SURFACE_EXTENSION_NAME); |
| 309 | #endif // VK_USE_PLATFORM_ANDROID_KHR |
| 310 | #if defined(VK_USE_PLATFORM_MIR_KHR) |
| 311 | instance_extension_names.push_back(VK_KHR_MIR_SURFACE_EXTENSION_NAME); |
| 312 | #endif // VK_USE_PLATFORM_MIR_KHR |
| 313 | #if defined(VK_USE_PLATFORM_WAYLAND_KHR) |
| 314 | instance_extension_names.push_back(VK_KHR_WAYLAND_SURFACE_EXTENSION_NAME); |
| 315 | #endif // VK_USE_PLATFORM_WAYLAND_KHR |
| 316 | #if defined(VK_USE_PLATFORM_WIN32_KHR) |
| 317 | instance_extension_names.push_back(VK_KHR_WIN32_SURFACE_EXTENSION_NAME); |
| 318 | #endif // VK_USE_PLATFORM_WIN32_KHR |
| 319 | #endif // NEED_TO_TEST_THIS_ON_PLATFORM |
| 320 | #if defined(VK_USE_PLATFORM_XCB_KHR) |
| 321 | instance_extension_names.push_back(VK_KHR_XCB_SURFACE_EXTENSION_NAME); |
| 322 | #elif defined(VK_USE_PLATFORM_XLIB_KHR) |
| 323 | instance_extension_names.push_back(VK_KHR_XLIB_SURFACE_EXTENSION_NAME); |
| 324 | #endif // VK_USE_PLATFORM_XLIB_KHR |
| 325 | } |
| 326 | |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 327 | this->app_info.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO; |
Tony Barbour | 300a608 | 2015-04-07 13:44:53 -0600 | [diff] [blame] | 328 | this->app_info.pNext = NULL; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 329 | this->app_info.pApplicationName = "layer_tests"; |
| 330 | this->app_info.applicationVersion = 1; |
Tony Barbour | 300a608 | 2015-04-07 13:44:53 -0600 | [diff] [blame] | 331 | this->app_info.pEngineName = "unittest"; |
| 332 | this->app_info.engineVersion = 1; |
Jon Ashburn | c5012ff | 2016-03-22 13:57:46 -0600 | [diff] [blame] | 333 | this->app_info.apiVersion = VK_API_VERSION_1_0; |
Tony Barbour | 300a608 | 2015-04-07 13:44:53 -0600 | [diff] [blame] | 334 | |
Tony Barbour | 15524c3 | 2015-04-29 17:34:29 -0600 | [diff] [blame] | 335 | m_errorMonitor = new ErrorMonitor; |
Courtney Goeltzenleuchter | cd69eee | 2015-07-06 09:10:47 -0600 | [diff] [blame] | 336 | InitFramework(instance_layer_names, device_layer_names, |
| 337 | instance_extension_names, device_extension_names, |
| 338 | myDbgFunc, m_errorMonitor); |
Tony Barbour | 300a608 | 2015-04-07 13:44:53 -0600 | [diff] [blame] | 339 | } |
| 340 | |
| 341 | virtual void TearDown() { |
| 342 | // Clean up resources before we reset |
Tony Barbour | 300a608 | 2015-04-07 13:44:53 -0600 | [diff] [blame] | 343 | ShutdownFramework(); |
Tony Barbour | 0b4d956 | 2015-04-09 10:48:04 -0600 | [diff] [blame] | 344 | delete m_errorMonitor; |
Tony Barbour | 300a608 | 2015-04-07 13:44:53 -0600 | [diff] [blame] | 345 | } |
Ian Elliott | 2c1daf5 | 2016-05-12 09:41:46 -0600 | [diff] [blame] | 346 | |
| 347 | VkLayerTest() { |
| 348 | m_enableWSI = false; |
| 349 | } |
Tony Barbour | 300a608 | 2015-04-07 13:44:53 -0600 | [diff] [blame] | 350 | }; |
Mark Lobodzinski | 3780e14 | 2015-05-14 15:08:13 -0500 | [diff] [blame] | 351 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 352 | VkResult VkLayerTest::BeginCommandBuffer(VkCommandBufferObj &commandBuffer) { |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 353 | VkResult result; |
Tony Barbour | 300a608 | 2015-04-07 13:44:53 -0600 | [diff] [blame] | 354 | |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 355 | result = commandBuffer.BeginCommandBuffer(); |
Tony Barbour | 300a608 | 2015-04-07 13:44:53 -0600 | [diff] [blame] | 356 | |
| 357 | /* |
| 358 | * For render test all drawing happens in a single render pass |
| 359 | * on a single command buffer. |
| 360 | */ |
Chris Forbes | 76a5eeb | 2015-06-16 14:05:59 +1200 | [diff] [blame] | 361 | if (VK_SUCCESS == result && renderPass()) { |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 362 | commandBuffer.BeginRenderPass(renderPassBeginInfo()); |
Tony Barbour | 300a608 | 2015-04-07 13:44:53 -0600 | [diff] [blame] | 363 | } |
| 364 | |
| 365 | return result; |
| 366 | } |
| 367 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 368 | VkResult VkLayerTest::EndCommandBuffer(VkCommandBufferObj &commandBuffer) { |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 369 | VkResult result; |
Tony Barbour | 300a608 | 2015-04-07 13:44:53 -0600 | [diff] [blame] | 370 | |
Chris Forbes | 76a5eeb | 2015-06-16 14:05:59 +1200 | [diff] [blame] | 371 | if (renderPass()) { |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 372 | commandBuffer.EndRenderPass(); |
Chris Forbes | 76a5eeb | 2015-06-16 14:05:59 +1200 | [diff] [blame] | 373 | } |
Tony Barbour | 300a608 | 2015-04-07 13:44:53 -0600 | [diff] [blame] | 374 | |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 375 | result = commandBuffer.EndCommandBuffer(); |
Tony Barbour | 300a608 | 2015-04-07 13:44:53 -0600 | [diff] [blame] | 376 | |
| 377 | return result; |
| 378 | } |
| 379 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 380 | void VkLayerTest::VKTriangleTest(const char *vertShaderText, |
| 381 | const char *fragShaderText, |
| 382 | BsoFailSelect failMask) { |
Mark Lobodzinski | 3780e14 | 2015-05-14 15:08:13 -0500 | [diff] [blame] | 383 | // Create identity matrix |
| 384 | int i; |
| 385 | struct vktriangle_vs_uniform data; |
| 386 | |
| 387 | glm::mat4 Projection = glm::mat4(1.0f); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 388 | glm::mat4 View = glm::mat4(1.0f); |
| 389 | glm::mat4 Model = glm::mat4(1.0f); |
| 390 | glm::mat4 MVP = Projection * View * Model; |
Mark Lobodzinski | 3780e14 | 2015-05-14 15:08:13 -0500 | [diff] [blame] | 391 | const int matrixSize = sizeof(MVP); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 392 | const int bufSize = sizeof(vktriangle_vs_uniform) / sizeof(float); |
Mark Lobodzinski | 3780e14 | 2015-05-14 15:08:13 -0500 | [diff] [blame] | 393 | |
| 394 | memcpy(&data.mvp, &MVP[0][0], matrixSize); |
| 395 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 396 | static const Vertex tri_data[] = { |
| 397 | {XYZ1(-1, -1, 0), XYZ1(1.f, 0.f, 0.f)}, |
| 398 | {XYZ1(1, -1, 0), XYZ1(0.f, 1.f, 0.f)}, |
| 399 | {XYZ1(0, 1, 0), XYZ1(0.f, 0.f, 1.f)}, |
Mark Lobodzinski | 3780e14 | 2015-05-14 15:08:13 -0500 | [diff] [blame] | 400 | }; |
| 401 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 402 | for (i = 0; i < 3; i++) { |
Mark Lobodzinski | 3780e14 | 2015-05-14 15:08:13 -0500 | [diff] [blame] | 403 | data.position[i][0] = tri_data[i].posX; |
| 404 | data.position[i][1] = tri_data[i].posY; |
| 405 | data.position[i][2] = tri_data[i].posZ; |
| 406 | data.position[i][3] = tri_data[i].posW; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 407 | data.color[i][0] = tri_data[i].r; |
| 408 | data.color[i][1] = tri_data[i].g; |
| 409 | data.color[i][2] = tri_data[i].b; |
| 410 | data.color[i][3] = tri_data[i].a; |
Mark Lobodzinski | 3780e14 | 2015-05-14 15:08:13 -0500 | [diff] [blame] | 411 | } |
| 412 | |
| 413 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 414 | ASSERT_NO_FATAL_FAILURE(InitViewport()); |
| 415 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 416 | VkConstantBufferObj constantBuffer(m_device, bufSize * 2, sizeof(float), |
| 417 | (const void *)&data); |
Mark Lobodzinski | 3780e14 | 2015-05-14 15:08:13 -0500 | [diff] [blame] | 418 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 419 | VkShaderObj vs(m_device, vertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this); |
| 420 | VkShaderObj ps(m_device, fragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, |
| 421 | this); |
Mark Lobodzinski | 3780e14 | 2015-05-14 15:08:13 -0500 | [diff] [blame] | 422 | |
| 423 | VkPipelineObj pipelineobj(m_device); |
Chia-I Wu | 08accc6 | 2015-07-07 11:50:03 +0800 | [diff] [blame] | 424 | pipelineobj.AddColorAttachment(); |
Mark Lobodzinski | 3780e14 | 2015-05-14 15:08:13 -0500 | [diff] [blame] | 425 | pipelineobj.AddShader(&vs); |
| 426 | pipelineobj.AddShader(&ps); |
Courtney Goeltzenleuchter | 507ba97 | 2015-09-30 16:16:57 -0600 | [diff] [blame] | 427 | if (failMask & BsoFailLineWidth) { |
| 428 | pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_LINE_WIDTH); |
Tobin Ehlis | 7a1d235 | 2016-03-28 11:18:19 -0600 | [diff] [blame] | 429 | VkPipelineInputAssemblyStateCreateInfo ia_state = {}; |
| 430 | ia_state.sType = |
| 431 | VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO; |
| 432 | ia_state.topology = VK_PRIMITIVE_TOPOLOGY_LINE_LIST; |
| 433 | pipelineobj.SetInputAssembly(&ia_state); |
Courtney Goeltzenleuchter | 507ba97 | 2015-09-30 16:16:57 -0600 | [diff] [blame] | 434 | } |
| 435 | if (failMask & BsoFailDepthBias) { |
| 436 | pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_DEPTH_BIAS); |
Tobin Ehlis | 7a1d235 | 2016-03-28 11:18:19 -0600 | [diff] [blame] | 437 | VkPipelineRasterizationStateCreateInfo rs_state = {}; |
| 438 | rs_state.sType = |
| 439 | VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO; |
| 440 | rs_state.depthBiasEnable = VK_TRUE; |
Mark Young | 7394fdd | 2016-03-31 14:56:43 -0600 | [diff] [blame] | 441 | rs_state.lineWidth = 1.0f; |
Tobin Ehlis | 7a1d235 | 2016-03-28 11:18:19 -0600 | [diff] [blame] | 442 | pipelineobj.SetRasterization(&rs_state); |
Courtney Goeltzenleuchter | 507ba97 | 2015-09-30 16:16:57 -0600 | [diff] [blame] | 443 | } |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 444 | // Viewport and scissors must stay in synch or other errors will occur than |
| 445 | // the ones we want |
Courtney Goeltzenleuchter | 507ba97 | 2015-09-30 16:16:57 -0600 | [diff] [blame] | 446 | if (failMask & BsoFailViewport) { |
| 447 | pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_VIEWPORT); |
Tobin Ehlis | d332f28 | 2015-10-02 11:00:56 -0600 | [diff] [blame] | 448 | m_viewports.clear(); |
| 449 | m_scissors.clear(); |
Courtney Goeltzenleuchter | 507ba97 | 2015-09-30 16:16:57 -0600 | [diff] [blame] | 450 | } |
| 451 | if (failMask & BsoFailScissor) { |
| 452 | pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_SCISSOR); |
Tobin Ehlis | d332f28 | 2015-10-02 11:00:56 -0600 | [diff] [blame] | 453 | m_scissors.clear(); |
| 454 | m_viewports.clear(); |
Courtney Goeltzenleuchter | 507ba97 | 2015-09-30 16:16:57 -0600 | [diff] [blame] | 455 | } |
| 456 | if (failMask & BsoFailBlend) { |
| 457 | pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_BLEND_CONSTANTS); |
Tobin Ehlis | 7a1d235 | 2016-03-28 11:18:19 -0600 | [diff] [blame] | 458 | VkPipelineColorBlendAttachmentState att_state = {}; |
| 459 | att_state.dstAlphaBlendFactor = VK_BLEND_FACTOR_CONSTANT_COLOR; |
| 460 | att_state.blendEnable = VK_TRUE; |
| 461 | pipelineobj.AddColorAttachment(0, &att_state); |
Courtney Goeltzenleuchter | 507ba97 | 2015-09-30 16:16:57 -0600 | [diff] [blame] | 462 | } |
| 463 | if (failMask & BsoFailDepthBounds) { |
| 464 | pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_DEPTH_BOUNDS); |
| 465 | } |
| 466 | if (failMask & BsoFailStencilReadMask) { |
| 467 | pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_STENCIL_COMPARE_MASK); |
| 468 | } |
| 469 | if (failMask & BsoFailStencilWriteMask) { |
| 470 | pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_STENCIL_WRITE_MASK); |
| 471 | } |
| 472 | if (failMask & BsoFailStencilReference) { |
| 473 | pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_STENCIL_REFERENCE); |
| 474 | } |
Mark Lobodzinski | 3780e14 | 2015-05-14 15:08:13 -0500 | [diff] [blame] | 475 | |
| 476 | VkDescriptorSetObj descriptorSet(m_device); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 477 | descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, |
| 478 | constantBuffer); |
Mark Lobodzinski | 3780e14 | 2015-05-14 15:08:13 -0500 | [diff] [blame] | 479 | |
| 480 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
Tony Barbour | fe3351b | 2015-07-28 10:17:20 -0600 | [diff] [blame] | 481 | ASSERT_VK_SUCCESS(BeginCommandBuffer()); |
Mark Lobodzinski | 3780e14 | 2015-05-14 15:08:13 -0500 | [diff] [blame] | 482 | |
Tony Barbour | fe3351b | 2015-07-28 10:17:20 -0600 | [diff] [blame] | 483 | GenericDrawPreparation(pipelineobj, descriptorSet, failMask); |
Mark Lobodzinski | 3780e14 | 2015-05-14 15:08:13 -0500 | [diff] [blame] | 484 | |
| 485 | // render triangle |
Courtney Goeltzenleuchter | 08c2637 | 2015-09-23 12:31:50 -0600 | [diff] [blame] | 486 | Draw(3, 1, 0, 0); |
Mark Lobodzinski | 3780e14 | 2015-05-14 15:08:13 -0500 | [diff] [blame] | 487 | |
Mark Mueller | d491441 | 2016-06-13 17:52:06 -0600 | [diff] [blame] | 488 | if (failMask & BsoFailCmdClearAttachments) { |
| 489 | VkClearAttachment color_attachment = {}; |
| 490 | color_attachment.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; |
| 491 | color_attachment.colorAttachment = 1; // Someone who knew what they were doing would use 0 for the index; |
| 492 | VkClearRect clear_rect = {{{0, 0}, {static_cast<uint32_t>(m_width), static_cast<uint32_t>(m_height)}}, 0, 0}; |
| 493 | |
| 494 | vkCmdClearAttachments(m_commandBuffer->GetBufferHandle(), 1, |
| 495 | &color_attachment, 1, &clear_rect); |
| 496 | } |
| 497 | |
Mark Lobodzinski | 3780e14 | 2015-05-14 15:08:13 -0500 | [diff] [blame] | 498 | // finalize recording of the command buffer |
Tony Barbour | fe3351b | 2015-07-28 10:17:20 -0600 | [diff] [blame] | 499 | EndCommandBuffer(); |
Mark Lobodzinski | 3780e14 | 2015-05-14 15:08:13 -0500 | [diff] [blame] | 500 | |
Tony Barbour | fe3351b | 2015-07-28 10:17:20 -0600 | [diff] [blame] | 501 | QueueCommandBuffer(); |
Mark Lobodzinski | 3780e14 | 2015-05-14 15:08:13 -0500 | [diff] [blame] | 502 | } |
| 503 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 504 | void VkLayerTest::GenericDrawPreparation(VkCommandBufferObj *commandBuffer, |
| 505 | VkPipelineObj &pipelineobj, |
| 506 | VkDescriptorSetObj &descriptorSet, |
| 507 | BsoFailSelect failMask) { |
Mark Lobodzinski | 3780e14 | 2015-05-14 15:08:13 -0500 | [diff] [blame] | 508 | if (m_depthStencil->Initialized()) { |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 509 | commandBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color, |
| 510 | m_stencil_clear_color, m_depthStencil); |
Mark Lobodzinski | 3780e14 | 2015-05-14 15:08:13 -0500 | [diff] [blame] | 511 | } else { |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 512 | commandBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color, |
| 513 | m_stencil_clear_color, NULL); |
Mark Lobodzinski | 3780e14 | 2015-05-14 15:08:13 -0500 | [diff] [blame] | 514 | } |
| 515 | |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 516 | commandBuffer->PrepareAttachments(); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 517 | // Make sure depthWriteEnable is set so that Depth fail test will work |
| 518 | // correctly |
| 519 | // Make sure stencilTestEnable is set so that Stencil fail test will work |
| 520 | // correctly |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 521 | VkStencilOpState stencil = {}; |
Chia-I Wu | 1b99bb2 | 2015-10-27 19:25:11 +0800 | [diff] [blame] | 522 | stencil.failOp = VK_STENCIL_OP_KEEP; |
| 523 | stencil.passOp = VK_STENCIL_OP_KEEP; |
| 524 | stencil.depthFailOp = VK_STENCIL_OP_KEEP; |
| 525 | stencil.compareOp = VK_COMPARE_OP_NEVER; |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 526 | |
| 527 | VkPipelineDepthStencilStateCreateInfo ds_ci = {}; |
| 528 | ds_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DEPTH_STENCIL_STATE_CREATE_INFO; |
Courtney Goeltzenleuchter | 507ba97 | 2015-09-30 16:16:57 -0600 | [diff] [blame] | 529 | ds_ci.pNext = NULL; |
| 530 | ds_ci.depthTestEnable = VK_FALSE; |
| 531 | ds_ci.depthWriteEnable = VK_TRUE; |
| 532 | ds_ci.depthCompareOp = VK_COMPARE_OP_NEVER; |
| 533 | ds_ci.depthBoundsTestEnable = VK_FALSE; |
Tobin Ehlis | 7a1d235 | 2016-03-28 11:18:19 -0600 | [diff] [blame] | 534 | if (failMask & BsoFailDepthBounds) { |
| 535 | ds_ci.depthBoundsTestEnable = VK_TRUE; |
Tobin Ehlis | 21c8835 | 2016-05-26 06:15:45 -0600 | [diff] [blame] | 536 | ds_ci.maxDepthBounds = 0.0f; |
| 537 | ds_ci.minDepthBounds = 0.0f; |
Tobin Ehlis | 7a1d235 | 2016-03-28 11:18:19 -0600 | [diff] [blame] | 538 | } |
Courtney Goeltzenleuchter | 507ba97 | 2015-09-30 16:16:57 -0600 | [diff] [blame] | 539 | ds_ci.stencilTestEnable = VK_TRUE; |
| 540 | ds_ci.front = stencil; |
| 541 | ds_ci.back = stencil; |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 542 | |
Tobin Ehlis | 4bf96d1 | 2015-06-25 11:58:41 -0600 | [diff] [blame] | 543 | pipelineobj.SetDepthStencil(&ds_ci); |
Tobin Ehlis | d332f28 | 2015-10-02 11:00:56 -0600 | [diff] [blame] | 544 | pipelineobj.SetViewport(m_viewports); |
| 545 | pipelineobj.SetScissor(m_scissors); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 546 | descriptorSet.CreateVKDescriptorSet(commandBuffer); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 547 | VkResult err = pipelineobj.CreateVKPipeline( |
| 548 | descriptorSet.GetPipelineLayout(), renderPass()); |
Cody Northrop | 29a08f2 | 2015-08-27 10:20:35 -0600 | [diff] [blame] | 549 | ASSERT_VK_SUCCESS(err); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 550 | commandBuffer->BindPipeline(pipelineobj); |
| 551 | commandBuffer->BindDescriptorSet(descriptorSet); |
Mark Lobodzinski | 3780e14 | 2015-05-14 15:08:13 -0500 | [diff] [blame] | 552 | } |
| 553 | |
Ian Elliott | 2c1daf5 | 2016-05-12 09:41:46 -0600 | [diff] [blame] | 554 | class VkWsiEnabledLayerTest : public VkLayerTest { |
| 555 | public: |
| 556 | protected: |
| 557 | VkWsiEnabledLayerTest() { |
| 558 | m_enableWSI = true; |
| 559 | } |
| 560 | }; |
| 561 | |
Mark Lobodzinski | 3780e14 | 2015-05-14 15:08:13 -0500 | [diff] [blame] | 562 | // ******************************************************************************************************************** |
| 563 | // ******************************************************************************************************************** |
| 564 | // ******************************************************************************************************************** |
| 565 | // ******************************************************************************************************************** |
Dustin Graves | ffa90fa | 2016-05-06 11:20:38 -0600 | [diff] [blame] | 566 | #if PARAMETER_VALIDATION_TESTS |
| 567 | TEST_F(VkLayerTest, RequiredParameter) { |
| 568 | TEST_DESCRIPTION("Specify VK_NULL_HANDLE, NULL, and 0 for required handle, " |
| 569 | "pointer, array, and array count parameters"); |
| 570 | |
| 571 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 572 | |
| 573 | m_errorMonitor->SetDesiredFailureMsg( |
| 574 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 575 | "required parameter pFeatures specified as NULL"); |
| 576 | // Specify NULL for a pointer to a handle |
| 577 | // Expected to trigger an error with |
| 578 | // parameter_validation::validate_required_pointer |
| 579 | vkGetPhysicalDeviceFeatures(gpu(), NULL); |
| 580 | m_errorMonitor->VerifyFound(); |
| 581 | |
| 582 | m_errorMonitor->SetDesiredFailureMsg( |
| 583 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Dustin Graves | a4bb8c1 | 2016-05-16 17:22:51 -0600 | [diff] [blame] | 584 | "required parameter pQueueFamilyPropertyCount specified as NULL"); |
Dustin Graves | ffa90fa | 2016-05-06 11:20:38 -0600 | [diff] [blame] | 585 | // Specify NULL for pointer to array count |
| 586 | // Expected to trigger an error with parameter_validation::validate_array |
Dustin Graves | a4bb8c1 | 2016-05-16 17:22:51 -0600 | [diff] [blame] | 587 | vkGetPhysicalDeviceQueueFamilyProperties(gpu(), NULL, NULL); |
Dustin Graves | ffa90fa | 2016-05-06 11:20:38 -0600 | [diff] [blame] | 588 | m_errorMonitor->VerifyFound(); |
| 589 | |
| 590 | m_errorMonitor->SetDesiredFailureMsg( |
| 591 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 592 | "parameter viewportCount must be greater than 0"); |
| 593 | // Specify 0 for a required array count |
| 594 | // Expected to trigger an error with parameter_validation::validate_array |
| 595 | VkViewport view_port = {}; |
| 596 | m_commandBuffer->SetViewport(0, 0, &view_port); |
| 597 | m_errorMonitor->VerifyFound(); |
| 598 | |
| 599 | m_errorMonitor->SetDesiredFailureMsg( |
| 600 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 601 | "required parameter pViewports specified as NULL"); |
| 602 | // Specify NULL for a required array |
| 603 | // Expected to trigger an error with parameter_validation::validate_array |
| 604 | m_commandBuffer->SetViewport(0, 1, NULL); |
| 605 | m_errorMonitor->VerifyFound(); |
| 606 | |
| 607 | m_errorMonitor->SetDesiredFailureMsg( |
| 608 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 609 | "required parameter memory specified as VK_NULL_HANDLE"); |
| 610 | // Specify VK_NULL_HANDLE for a required handle |
| 611 | // Expected to trigger an error with |
| 612 | // parameter_validation::validate_required_handle |
| 613 | vkUnmapMemory(device(), VK_NULL_HANDLE); |
| 614 | m_errorMonitor->VerifyFound(); |
| 615 | |
| 616 | m_errorMonitor->SetDesiredFailureMsg( |
| 617 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 618 | "required parameter pFences[0] specified as VK_NULL_HANDLE"); |
| 619 | // Specify VK_NULL_HANDLE for a required handle array entry |
| 620 | // Expected to trigger an error with |
| 621 | // parameter_validation::validate_required_handle_array |
| 622 | VkFence fence = VK_NULL_HANDLE; |
| 623 | vkResetFences(device(), 1, &fence); |
| 624 | m_errorMonitor->VerifyFound(); |
| 625 | |
| 626 | m_errorMonitor->SetDesiredFailureMsg( |
| 627 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 628 | "required parameter pAllocateInfo specified as NULL"); |
| 629 | // Specify NULL for a required struct pointer |
| 630 | // Expected to trigger an error with |
| 631 | // parameter_validation::validate_struct_type |
| 632 | VkDeviceMemory memory = VK_NULL_HANDLE; |
| 633 | vkAllocateMemory(device(), NULL, NULL, &memory); |
| 634 | m_errorMonitor->VerifyFound(); |
| 635 | |
| 636 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 637 | "value of faceMask must not be 0"); |
| 638 | // Specify 0 for a required VkFlags parameter |
| 639 | // Expected to trigger an error with parameter_validation::validate_flags |
| 640 | m_commandBuffer->SetStencilReference(0, 0); |
| 641 | m_errorMonitor->VerifyFound(); |
| 642 | |
| 643 | m_errorMonitor->SetDesiredFailureMsg( |
| 644 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 645 | "value of pSubmits[i].pWaitDstStageMask[0] must not be 0"); |
| 646 | // Specify 0 for a required VkFlags array entry |
| 647 | // Expected to trigger an error with |
| 648 | // parameter_validation::validate_flags_array |
| 649 | VkSemaphore semaphore = VK_NULL_HANDLE; |
| 650 | VkPipelineStageFlags stageFlags = 0; |
| 651 | VkSubmitInfo submitInfo = {}; |
| 652 | submitInfo.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO; |
| 653 | submitInfo.waitSemaphoreCount = 1; |
| 654 | submitInfo.pWaitSemaphores = &semaphore; |
| 655 | submitInfo.pWaitDstStageMask = &stageFlags; |
| 656 | vkQueueSubmit(m_device->m_queue, 1, &submitInfo, VK_NULL_HANDLE); |
| 657 | m_errorMonitor->VerifyFound(); |
| 658 | } |
Dustin Graves | c99cf5a | 2016-05-09 14:40:29 -0600 | [diff] [blame] | 659 | |
Dustin Graves | fce74c0 | 2016-05-10 11:42:58 -0600 | [diff] [blame] | 660 | TEST_F(VkLayerTest, ReservedParameter) { |
| 661 | TEST_DESCRIPTION("Specify a non-zero value for a reserved parameter"); |
| 662 | |
| 663 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 664 | |
| 665 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 666 | " must be 0"); |
| 667 | // Specify 0 for a reserved VkFlags parameter |
| 668 | // Expected to trigger an error with |
| 669 | // parameter_validation::validate_reserved_flags |
| 670 | VkEvent event_handle = VK_NULL_HANDLE; |
| 671 | VkEventCreateInfo event_info = {}; |
| 672 | event_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO; |
| 673 | event_info.flags = 1; |
| 674 | vkCreateEvent(device(), &event_info, NULL, &event_handle); |
| 675 | m_errorMonitor->VerifyFound(); |
| 676 | } |
| 677 | |
Dustin Graves | c99cf5a | 2016-05-09 14:40:29 -0600 | [diff] [blame] | 678 | TEST_F(VkLayerTest, InvalidStructSType) { |
| 679 | TEST_DESCRIPTION("Specify an invalid VkStructureType for a Vulkan " |
| 680 | "structure's sType field"); |
| 681 | |
| 682 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 683 | |
| 684 | m_errorMonitor->SetDesiredFailureMsg( |
| 685 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 686 | "parameter pAllocateInfo->sType must be"); |
| 687 | // Zero struct memory, effectively setting sType to |
| 688 | // VK_STRUCTURE_TYPE_APPLICATION_INFO |
| 689 | // Expected to trigger an error with |
| 690 | // parameter_validation::validate_struct_type |
| 691 | VkMemoryAllocateInfo alloc_info = {}; |
| 692 | VkDeviceMemory memory = VK_NULL_HANDLE; |
| 693 | vkAllocateMemory(device(), &alloc_info, NULL, &memory); |
| 694 | m_errorMonitor->VerifyFound(); |
| 695 | |
| 696 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 697 | "parameter pSubmits[0].sType must be"); |
| 698 | // Zero struct memory, effectively setting sType to |
| 699 | // VK_STRUCTURE_TYPE_APPLICATION_INFO |
| 700 | // Expected to trigger an error with |
| 701 | // parameter_validation::validate_struct_type_array |
| 702 | VkSubmitInfo submit_info = {}; |
| 703 | vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE); |
| 704 | m_errorMonitor->VerifyFound(); |
| 705 | } |
| 706 | |
| 707 | TEST_F(VkLayerTest, InvalidStructPNext) { |
| 708 | TEST_DESCRIPTION( |
| 709 | "Specify an invalid value for a Vulkan structure's pNext field"); |
| 710 | |
| 711 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 712 | |
| 713 | m_errorMonitor->SetDesiredFailureMsg( |
| 714 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 715 | "value of pAllocateInfo->pNext must be NULL"); |
| 716 | // Set VkMemoryAllocateInfo::pNext to a non-NULL value, when pNext must be |
| 717 | // NULL |
| 718 | // Expected to trigger an error with |
| 719 | // parameter_validation::validate_struct_pnext |
| 720 | VkDeviceMemory memory = VK_NULL_HANDLE; |
| 721 | // Zero-initialization will provide the correct sType |
| 722 | VkApplicationInfo app_info = {}; |
Dustin Graves | 47b6cba | 2016-05-10 17:34:38 -0600 | [diff] [blame] | 723 | VkMemoryAllocateInfo memory_alloc_info = {}; |
| 724 | memory_alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO; |
| 725 | memory_alloc_info.pNext = &app_info; |
| 726 | vkAllocateMemory(device(), &memory_alloc_info, NULL, &memory); |
Dustin Graves | c99cf5a | 2016-05-09 14:40:29 -0600 | [diff] [blame] | 727 | m_errorMonitor->VerifyFound(); |
| 728 | |
Dustin Graves | 47b6cba | 2016-05-10 17:34:38 -0600 | [diff] [blame] | 729 | m_errorMonitor->SetDesiredFailureMsg( |
| 730 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 731 | " chain includes a structure with unexpected VkStructureType "); |
| 732 | // Set VkGraphicsPipelineCreateInfo::VkPipelineRasterizationStateCreateInfo::pNext to an invalid structure, when pNext is allowed to be a non-NULL value |
| 733 | // Expected to trigger an error with |
| 734 | // parameter_validation::validate_struct_pnext |
| 735 | VkDescriptorPoolSize ds_type_count = {}; |
| 736 | ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 737 | ds_type_count.descriptorCount = 1; |
| 738 | |
| 739 | VkDescriptorPoolCreateInfo ds_pool_ci = {}; |
| 740 | ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO; |
| 741 | ds_pool_ci.pNext = NULL; |
| 742 | ds_pool_ci.maxSets = 1; |
| 743 | ds_pool_ci.poolSizeCount = 1; |
| 744 | ds_pool_ci.pPoolSizes = &ds_type_count; |
| 745 | |
| 746 | VkDescriptorPool ds_pool; |
| 747 | VkResult err = |
| 748 | vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool); |
| 749 | ASSERT_VK_SUCCESS(err); |
| 750 | |
| 751 | VkDescriptorSetLayoutBinding dsl_binding = {}; |
| 752 | dsl_binding.binding = 0; |
| 753 | dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 754 | dsl_binding.descriptorCount = 1; |
| 755 | dsl_binding.stageFlags = VK_SHADER_STAGE_ALL; |
| 756 | dsl_binding.pImmutableSamplers = NULL; |
| 757 | |
| 758 | VkDescriptorSetLayoutCreateInfo ds_layout_ci = {}; |
| 759 | ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO; |
| 760 | ds_layout_ci.pNext = NULL; |
| 761 | ds_layout_ci.bindingCount = 1; |
| 762 | ds_layout_ci.pBindings = &dsl_binding; |
| 763 | |
| 764 | VkDescriptorSetLayout ds_layout; |
| 765 | err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, |
| 766 | &ds_layout); |
| 767 | ASSERT_VK_SUCCESS(err); |
| 768 | |
| 769 | VkDescriptorSet descriptorSet; |
| 770 | VkDescriptorSetAllocateInfo ds_alloc_info = {}; |
| 771 | ds_alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO; |
| 772 | ds_alloc_info.descriptorSetCount = 1; |
| 773 | ds_alloc_info.descriptorPool = ds_pool; |
| 774 | ds_alloc_info.pSetLayouts = &ds_layout; |
| 775 | err = vkAllocateDescriptorSets(m_device->device(), &ds_alloc_info, |
| 776 | &descriptorSet); |
| 777 | ASSERT_VK_SUCCESS(err); |
| 778 | |
| 779 | VkPipelineLayoutCreateInfo pipeline_layout_ci = {}; |
| 780 | pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO; |
| 781 | pipeline_layout_ci.setLayoutCount = 1; |
| 782 | pipeline_layout_ci.pSetLayouts = &ds_layout; |
| 783 | |
| 784 | VkPipelineLayout pipeline_layout; |
| 785 | err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, |
| 786 | &pipeline_layout); |
| 787 | ASSERT_VK_SUCCESS(err); |
| 788 | |
| 789 | VkViewport vp = {}; // Just need dummy vp to point to |
| 790 | VkRect2D sc = {}; // dummy scissor to point to |
| 791 | |
| 792 | VkPipelineViewportStateCreateInfo vp_state_ci = {}; |
| 793 | vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO; |
| 794 | vp_state_ci.scissorCount = 1; |
| 795 | vp_state_ci.pScissors = ≻ |
| 796 | vp_state_ci.viewportCount = 1; |
| 797 | vp_state_ci.pViewports = &vp; |
| 798 | |
| 799 | VkPipelineRasterizationStateCreateInfo rs_state_ci = {}; |
| 800 | rs_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO; |
| 801 | rs_state_ci.polygonMode = VK_POLYGON_MODE_FILL; |
| 802 | rs_state_ci.cullMode = VK_CULL_MODE_BACK_BIT; |
| 803 | rs_state_ci.frontFace = VK_FRONT_FACE_COUNTER_CLOCKWISE; |
| 804 | rs_state_ci.depthClampEnable = VK_FALSE; |
| 805 | rs_state_ci.rasterizerDiscardEnable = VK_FALSE; |
| 806 | rs_state_ci.depthBiasEnable = VK_FALSE; |
| 807 | |
| 808 | VkGraphicsPipelineCreateInfo gp_ci = {}; |
| 809 | gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO; |
| 810 | gp_ci.pViewportState = &vp_state_ci; |
| 811 | gp_ci.pRasterizationState = &rs_state_ci; |
| 812 | gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT; |
| 813 | gp_ci.layout = pipeline_layout; |
| 814 | gp_ci.renderPass = renderPass(); |
| 815 | |
| 816 | VkPipelineCacheCreateInfo pc_ci = {}; |
| 817 | pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO; |
| 818 | pc_ci.initialDataSize = 0; |
| 819 | pc_ci.pInitialData = 0; |
| 820 | |
| 821 | VkPipeline pipeline; |
| 822 | VkPipelineCache pipelineCache; |
| 823 | |
| 824 | err = |
| 825 | vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache); |
| 826 | ASSERT_VK_SUCCESS(err); |
| 827 | |
| 828 | // Set VkPipelineRasterizationStateCreateInfo::pNext to an invalid value |
| 829 | VkApplicationInfo invalid_pnext_struct = {}; |
| 830 | rs_state_ci.pNext = &invalid_pnext_struct; |
| 831 | |
| 832 | vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, |
| 833 | &gp_ci, NULL, &pipeline); |
| 834 | m_errorMonitor->VerifyFound(); |
Tony Barbour | df4c004 | 2016-06-01 15:55:43 -0600 | [diff] [blame] | 835 | vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL); |
| 836 | vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL); |
| 837 | vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL); |
| 838 | vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL); |
| 839 | |
Dustin Graves | c99cf5a | 2016-05-09 14:40:29 -0600 | [diff] [blame] | 840 | } |
Dustin Graves | 5d33d53 | 2016-05-09 16:21:12 -0600 | [diff] [blame] | 841 | |
| 842 | TEST_F(VkLayerTest, UnrecognizedValue) { |
| 843 | TEST_DESCRIPTION( |
| 844 | "Specify unrecognized Vulkan enumeration, flags, and VkBool32 values"); |
| 845 | |
| 846 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 847 | |
| 848 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 849 | "does not fall within the begin..end " |
| 850 | "range of the core VkFormat " |
| 851 | "enumeration tokens"); |
| 852 | // Specify an invalid VkFormat value |
| 853 | // Expected to trigger an error with |
| 854 | // parameter_validation::validate_ranged_enum |
| 855 | VkFormatProperties format_properties; |
| 856 | vkGetPhysicalDeviceFormatProperties(gpu(), static_cast<VkFormat>(8000), |
| 857 | &format_properties); |
| 858 | m_errorMonitor->VerifyFound(); |
| 859 | |
| 860 | m_errorMonitor->SetDesiredFailureMsg( |
| 861 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 862 | "contains flag bits that are not recognized members of"); |
| 863 | // Specify an invalid VkFlags bitmask value |
| 864 | // Expected to trigger an error with parameter_validation::validate_flags |
| 865 | VkImageFormatProperties image_format_properties; |
| 866 | vkGetPhysicalDeviceImageFormatProperties( |
| 867 | gpu(), VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_TYPE_2D, |
| 868 | VK_IMAGE_TILING_OPTIMAL, static_cast<VkImageUsageFlags>(1 << 25), 0, |
| 869 | &image_format_properties); |
| 870 | m_errorMonitor->VerifyFound(); |
| 871 | |
| 872 | m_errorMonitor->SetDesiredFailureMsg( |
| 873 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 874 | "contains flag bits that are not recognized members of"); |
| 875 | // Specify an invalid VkFlags array entry |
| 876 | // Expected to trigger an error with |
| 877 | // parameter_validation::validate_flags_array |
| 878 | VkSemaphore semaphore = VK_NULL_HANDLE; |
| 879 | VkPipelineStageFlags stage_flags = |
| 880 | static_cast<VkPipelineStageFlags>(1 << 25); |
| 881 | VkSubmitInfo submit_info = {}; |
| 882 | submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO; |
| 883 | submit_info.waitSemaphoreCount = 1; |
| 884 | submit_info.pWaitSemaphores = &semaphore; |
| 885 | submit_info.pWaitDstStageMask = &stage_flags; |
| 886 | vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE); |
| 887 | m_errorMonitor->VerifyFound(); |
| 888 | |
| 889 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, |
| 890 | "is neither VK_TRUE nor VK_FALSE"); |
| 891 | // Specify an invalid VkBool32 value |
| 892 | // Expected to trigger a warning with |
| 893 | // parameter_validation::validate_bool32 |
| 894 | VkSampler sampler = VK_NULL_HANDLE; |
| 895 | VkSamplerCreateInfo sampler_info = {}; |
| 896 | sampler_info.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO; |
| 897 | sampler_info.pNext = NULL; |
| 898 | sampler_info.magFilter = VK_FILTER_NEAREST; |
| 899 | sampler_info.minFilter = VK_FILTER_NEAREST; |
| 900 | sampler_info.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST; |
| 901 | sampler_info.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE; |
| 902 | sampler_info.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE; |
| 903 | sampler_info.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE; |
| 904 | sampler_info.mipLodBias = 1.0; |
| 905 | sampler_info.maxAnisotropy = 1; |
| 906 | sampler_info.compareEnable = VK_FALSE; |
| 907 | sampler_info.compareOp = VK_COMPARE_OP_NEVER; |
| 908 | sampler_info.minLod = 1.0; |
| 909 | sampler_info.maxLod = 1.0; |
| 910 | sampler_info.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE; |
| 911 | sampler_info.unnormalizedCoordinates = VK_FALSE; |
| 912 | // Not VK_TRUE or VK_FALSE |
| 913 | sampler_info.anisotropyEnable = 3; |
| 914 | vkCreateSampler(m_device->device(), &sampler_info, NULL, &sampler); |
| 915 | m_errorMonitor->VerifyFound(); |
| 916 | } |
Dustin Graves | fce74c0 | 2016-05-10 11:42:58 -0600 | [diff] [blame] | 917 | |
| 918 | TEST_F(VkLayerTest, FailedReturnValue) { |
| 919 | TEST_DESCRIPTION("Check for a message describing a VkResult failure code"); |
| 920 | |
| 921 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 922 | |
Dustin Graves | 13c1e2b | 2016-05-16 15:31:02 -0600 | [diff] [blame] | 923 | // Find an unsupported image format |
| 924 | VkFormat unsupported = VK_FORMAT_UNDEFINED; |
| 925 | for (int f = VK_FORMAT_BEGIN_RANGE; f <= VK_FORMAT_END_RANGE; f++) { |
| 926 | VkFormat format = static_cast<VkFormat>(f); |
| 927 | VkFormatProperties fProps = m_device->format_properties(format); |
| 928 | if (format != VK_FORMAT_UNDEFINED && fProps.linearTilingFeatures == 0 && |
| 929 | fProps.optimalTilingFeatures == 0) { |
| 930 | unsupported = format; |
| 931 | break; |
| 932 | } |
| 933 | } |
| 934 | |
| 935 | if (unsupported != VK_FORMAT_UNDEFINED) { |
| 936 | m_errorMonitor->SetDesiredFailureMsg( |
| 937 | VK_DEBUG_REPORT_WARNING_BIT_EXT, |
| 938 | "the requested format is not supported on this device"); |
| 939 | // Specify an unsupported VkFormat value to generate a |
| 940 | // VK_ERROR_FORMAT_NOT_SUPPORTED return code |
| 941 | // Expected to trigger a warning from |
| 942 | // parameter_validation::validate_result |
| 943 | VkImageFormatProperties image_format_properties; |
| 944 | VkResult err = vkGetPhysicalDeviceImageFormatProperties( |
| 945 | gpu(), unsupported, VK_IMAGE_TYPE_2D, VK_IMAGE_TILING_OPTIMAL, |
| 946 | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, 0, &image_format_properties); |
| 947 | ASSERT_TRUE(err == VK_ERROR_FORMAT_NOT_SUPPORTED); |
| 948 | m_errorMonitor->VerifyFound(); |
| 949 | } |
Dustin Graves | fce74c0 | 2016-05-10 11:42:58 -0600 | [diff] [blame] | 950 | } |
Mark Lobodzinski | e090fef | 2016-06-09 17:04:56 -0600 | [diff] [blame] | 951 | |
| 952 | TEST_F(VkLayerTest, UpdateBufferAlignment) { |
| 953 | TEST_DESCRIPTION("Check alignment parameters for vkCmdUpdateBuffer"); |
| 954 | uint32_t updateData[] = { 1, 2, 3, 4, 5, 6, 7, 8 }; |
| 955 | |
| 956 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 957 | |
| 958 | VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT; |
| 959 | vk_testing::Buffer buffer; |
| 960 | buffer.init_as_dst(*m_device, (VkDeviceSize)20, reqs); |
| 961 | |
| 962 | BeginCommandBuffer(); |
| 963 | // Introduce failure by using dstOffset that is not multiple of 4 |
| 964 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 965 | " is not a multiple of 4"); |
| 966 | m_commandBuffer->UpdateBuffer(buffer.handle(), 1, 4, updateData); |
| 967 | m_errorMonitor->VerifyFound(); |
| 968 | |
| 969 | // Introduce failure by using dataSize that is not multiple of 4 |
| 970 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 971 | " is not a multiple of 4"); |
| 972 | m_commandBuffer->UpdateBuffer(buffer.handle(), 0, 6, updateData); |
| 973 | m_errorMonitor->VerifyFound(); |
| 974 | |
| 975 | // Introduce failure by using dataSize that is < 0 |
| 976 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 977 | "must be greater than zero and less than or equal to 65536"); |
| 978 | m_commandBuffer->UpdateBuffer(buffer.handle(), 0, -44, updateData); |
| 979 | m_errorMonitor->VerifyFound(); |
| 980 | |
| 981 | // Introduce failure by using dataSize that is > 65536 |
| 982 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 983 | "must be greater than zero and less than or equal to 65536"); |
| 984 | m_commandBuffer->UpdateBuffer(buffer.handle(), 0, 80000, updateData); |
| 985 | m_errorMonitor->VerifyFound(); |
| 986 | |
| 987 | EndCommandBuffer(); |
| 988 | } |
| 989 | |
| 990 | TEST_F(VkLayerTest, FillBufferAlignment) { |
| 991 | TEST_DESCRIPTION("Check alignment parameters for vkCmdFillBuffer"); |
| 992 | |
| 993 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 994 | |
| 995 | VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT; |
| 996 | vk_testing::Buffer buffer; |
| 997 | buffer.init_as_dst(*m_device, (VkDeviceSize)20, reqs); |
| 998 | |
| 999 | BeginCommandBuffer(); |
| 1000 | |
| 1001 | // Introduce failure by using dstOffset that is not multiple of 4 |
| 1002 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 1003 | " is not a multiple of 4"); |
| 1004 | m_commandBuffer->FillBuffer(buffer.handle(), 1, 4, 0x11111111); |
| 1005 | m_errorMonitor->VerifyFound(); |
| 1006 | |
| 1007 | // Introduce failure by using size that is not multiple of 4 |
| 1008 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 1009 | " is not a multiple of 4"); |
| 1010 | m_commandBuffer->FillBuffer(buffer.handle(), 0, 6, 0x11111111); |
| 1011 | m_errorMonitor->VerifyFound(); |
| 1012 | |
| 1013 | // Introduce failure by using size that is zero |
| 1014 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 1015 | "must be greater than zero"); |
| 1016 | m_commandBuffer->FillBuffer(buffer.handle(), 0, 0, 0x11111111); |
| 1017 | m_errorMonitor->VerifyFound(); |
| 1018 | |
| 1019 | EndCommandBuffer(); |
| 1020 | } |
Dustin Graves | ffa90fa | 2016-05-06 11:20:38 -0600 | [diff] [blame] | 1021 | #endif // PARAMETER_VALIDATION_TESTS |
| 1022 | |
Tobin Ehlis | 0788f52 | 2015-05-26 16:11:58 -0600 | [diff] [blame] | 1023 | #if MEM_TRACKER_TESTS |
Tobin Ehlis | 8fab656 | 2015-12-01 09:57:09 -0700 | [diff] [blame] | 1024 | #if 0 |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 1025 | TEST_F(VkLayerTest, CallResetCommandBufferBeforeCompletion) |
Mark Lobodzinski | ccb2b04 | 2015-05-19 10:28:29 -0500 | [diff] [blame] | 1026 | { |
| 1027 | vk_testing::Fence testFence; |
Mark Lobodzinski | ccb2b04 | 2015-05-19 10:28:29 -0500 | [diff] [blame] | 1028 | VkFenceCreateInfo fenceInfo = {}; |
| 1029 | fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO; |
| 1030 | fenceInfo.pNext = NULL; |
| 1031 | fenceInfo.flags = 0; |
| 1032 | |
Courtney Goeltzenleuchter | 7415d5a | 2015-12-09 15:48:16 -0700 | [diff] [blame] | 1033 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Resetting CB"); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 1034 | |
Mark Lobodzinski | ccb2b04 | 2015-05-19 10:28:29 -0500 | [diff] [blame] | 1035 | ASSERT_NO_FATAL_FAILURE(InitState()); |
Tony Barbour | c1eb1a5 | 2015-07-20 13:00:10 -0600 | [diff] [blame] | 1036 | |
| 1037 | VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT; |
| 1038 | vk_testing::Buffer buffer; |
| 1039 | buffer.init_as_dst(*m_device, (VkDeviceSize)20, reqs); |
Mark Lobodzinski | ccb2b04 | 2015-05-19 10:28:29 -0500 | [diff] [blame] | 1040 | |
Tony Barbour | fe3351b | 2015-07-28 10:17:20 -0600 | [diff] [blame] | 1041 | BeginCommandBuffer(); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 1042 | m_commandBuffer->FillBuffer(buffer.handle(), 0, 4, 0x11111111); |
Tony Barbour | fe3351b | 2015-07-28 10:17:20 -0600 | [diff] [blame] | 1043 | EndCommandBuffer(); |
Mark Lobodzinski | ccb2b04 | 2015-05-19 10:28:29 -0500 | [diff] [blame] | 1044 | |
| 1045 | testFence.init(*m_device, fenceInfo); |
| 1046 | |
| 1047 | // Bypass framework since it does the waits automatically |
| 1048 | VkResult err = VK_SUCCESS; |
Courtney Goeltzenleuchter | 806c700 | 2015-10-27 11:22:14 -0600 | [diff] [blame] | 1049 | VkSubmitInfo submit_info; |
Chia-I Wu | f9be13c | 2015-10-26 20:37:06 +0800 | [diff] [blame] | 1050 | submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO; |
| 1051 | submit_info.pNext = NULL; |
Chia-I Wu | d50a7d7 | 2015-10-26 20:48:51 +0800 | [diff] [blame] | 1052 | submit_info.waitSemaphoreCount = 0; |
Courtney Goeltzenleuchter | 806c700 | 2015-10-27 11:22:14 -0600 | [diff] [blame] | 1053 | submit_info.pWaitSemaphores = NULL; |
Jon Ashburn | 7f9716c | 2015-12-30 16:42:50 -0700 | [diff] [blame] | 1054 | submit_info.pWaitDstStageMask = NULL; |
Chia-I Wu | d50a7d7 | 2015-10-26 20:48:51 +0800 | [diff] [blame] | 1055 | submit_info.commandBufferCount = 1; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 1056 | submit_info.pCommandBuffers = &m_commandBuffer->handle(); |
Chia-I Wu | d50a7d7 | 2015-10-26 20:48:51 +0800 | [diff] [blame] | 1057 | submit_info.signalSemaphoreCount = 0; |
Courtney Goeltzenleuchter | 806c700 | 2015-10-27 11:22:14 -0600 | [diff] [blame] | 1058 | submit_info.pSignalSemaphores = NULL; |
Courtney Goeltzenleuchter | 646b907 | 2015-10-20 18:04:07 -0600 | [diff] [blame] | 1059 | |
| 1060 | err = vkQueueSubmit( m_device->m_queue, 1, &submit_info, testFence.handle()); |
Mark Lobodzinski | ccb2b04 | 2015-05-19 10:28:29 -0500 | [diff] [blame] | 1061 | ASSERT_VK_SUCCESS( err ); |
| 1062 | |
Mark Lobodzinski | ccb2b04 | 2015-05-19 10:28:29 -0500 | [diff] [blame] | 1063 | // Introduce failure by calling begin again before checking fence |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 1064 | vkResetCommandBuffer(m_commandBuffer->handle(), 0); |
Mark Lobodzinski | ccb2b04 | 2015-05-19 10:28:29 -0500 | [diff] [blame] | 1065 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 1066 | m_errorMonitor->VerifyFound(); |
Mark Lobodzinski | ccb2b04 | 2015-05-19 10:28:29 -0500 | [diff] [blame] | 1067 | } |
| 1068 | |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 1069 | TEST_F(VkLayerTest, CallBeginCommandBufferBeforeCompletion) |
Mark Lobodzinski | ccb2b04 | 2015-05-19 10:28:29 -0500 | [diff] [blame] | 1070 | { |
| 1071 | vk_testing::Fence testFence; |
Mark Lobodzinski | ccb2b04 | 2015-05-19 10:28:29 -0500 | [diff] [blame] | 1072 | VkFenceCreateInfo fenceInfo = {}; |
| 1073 | fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO; |
| 1074 | fenceInfo.pNext = NULL; |
| 1075 | fenceInfo.flags = 0; |
| 1076 | |
Courtney Goeltzenleuchter | 7415d5a | 2015-12-09 15:48:16 -0700 | [diff] [blame] | 1077 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Calling vkBeginCommandBuffer() on active CB"); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 1078 | |
Mark Lobodzinski | ccb2b04 | 2015-05-19 10:28:29 -0500 | [diff] [blame] | 1079 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 1080 | ASSERT_NO_FATAL_FAILURE(InitViewport()); |
| 1081 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 1082 | |
Tony Barbour | fe3351b | 2015-07-28 10:17:20 -0600 | [diff] [blame] | 1083 | BeginCommandBuffer(); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 1084 | m_commandBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color, m_stencil_clear_color, NULL); |
Tony Barbour | fe3351b | 2015-07-28 10:17:20 -0600 | [diff] [blame] | 1085 | EndCommandBuffer(); |
Mark Lobodzinski | ccb2b04 | 2015-05-19 10:28:29 -0500 | [diff] [blame] | 1086 | |
| 1087 | testFence.init(*m_device, fenceInfo); |
| 1088 | |
| 1089 | // Bypass framework since it does the waits automatically |
| 1090 | VkResult err = VK_SUCCESS; |
Courtney Goeltzenleuchter | 806c700 | 2015-10-27 11:22:14 -0600 | [diff] [blame] | 1091 | VkSubmitInfo submit_info; |
Chia-I Wu | f9be13c | 2015-10-26 20:37:06 +0800 | [diff] [blame] | 1092 | submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO; |
| 1093 | submit_info.pNext = NULL; |
Chia-I Wu | d50a7d7 | 2015-10-26 20:48:51 +0800 | [diff] [blame] | 1094 | submit_info.waitSemaphoreCount = 0; |
Courtney Goeltzenleuchter | 806c700 | 2015-10-27 11:22:14 -0600 | [diff] [blame] | 1095 | submit_info.pWaitSemaphores = NULL; |
Jon Ashburn | 7f9716c | 2015-12-30 16:42:50 -0700 | [diff] [blame] | 1096 | submit_info.pWaitDstStageMask = NULL; |
Chia-I Wu | d50a7d7 | 2015-10-26 20:48:51 +0800 | [diff] [blame] | 1097 | submit_info.commandBufferCount = 1; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 1098 | submit_info.pCommandBuffers = &m_commandBuffer->handle(); |
Chia-I Wu | d50a7d7 | 2015-10-26 20:48:51 +0800 | [diff] [blame] | 1099 | submit_info.signalSemaphoreCount = 0; |
Courtney Goeltzenleuchter | 806c700 | 2015-10-27 11:22:14 -0600 | [diff] [blame] | 1100 | submit_info.pSignalSemaphores = NULL; |
Courtney Goeltzenleuchter | 646b907 | 2015-10-20 18:04:07 -0600 | [diff] [blame] | 1101 | |
| 1102 | err = vkQueueSubmit( m_device->m_queue, 1, &submit_info, testFence.handle()); |
Mark Lobodzinski | ccb2b04 | 2015-05-19 10:28:29 -0500 | [diff] [blame] | 1103 | ASSERT_VK_SUCCESS( err ); |
| 1104 | |
Jon Ashburn | f19916e | 2016-01-11 13:12:43 -0700 | [diff] [blame] | 1105 | VkCommandBufferInheritanceInfo hinfo = {}; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 1106 | VkCommandBufferBeginInfo info = {}; |
| 1107 | info.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT; |
| 1108 | info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO; |
Mark Lobodzinski | 5fcc421 | 2015-09-14 17:43:42 -0600 | [diff] [blame] | 1109 | info.renderPass = VK_NULL_HANDLE; |
| 1110 | info.subpass = 0; |
| 1111 | info.framebuffer = VK_NULL_HANDLE; |
Chia-I Wu | b8d47ae | 2015-11-11 10:18:12 +0800 | [diff] [blame] | 1112 | info.occlusionQueryEnable = VK_FALSE; |
| 1113 | info.queryFlags = 0; |
| 1114 | info.pipelineStatistics = 0; |
Mark Lobodzinski | 5fcc421 | 2015-09-14 17:43:42 -0600 | [diff] [blame] | 1115 | |
| 1116 | // Introduce failure by calling BCB again before checking fence |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 1117 | vkBeginCommandBuffer(m_commandBuffer->handle(), &info); |
Mark Lobodzinski | ccb2b04 | 2015-05-19 10:28:29 -0500 | [diff] [blame] | 1118 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 1119 | m_errorMonitor->VerifyFound(); |
Mark Lobodzinski | ccb2b04 | 2015-05-19 10:28:29 -0500 | [diff] [blame] | 1120 | } |
Tobin Ehlis | 8fab656 | 2015-12-01 09:57:09 -0700 | [diff] [blame] | 1121 | #endif |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 1122 | |
Mark Lobodzinski | 152fe25 | 2016-05-03 16:49:15 -0600 | [diff] [blame] | 1123 | // This is a positive test. No failures are expected. |
| 1124 | TEST_F(VkLayerTest, TestAliasedMemoryTracking) { |
| 1125 | VkResult err; |
| 1126 | bool pass; |
| 1127 | |
| 1128 | TEST_DESCRIPTION("Create a buffer, allocate memory, bind memory, destroy " |
| 1129 | "the buffer, create an image, and bind the same memory to " |
| 1130 | "it"); |
| 1131 | |
| 1132 | m_errorMonitor->ExpectSuccess(); |
| 1133 | |
| 1134 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 1135 | |
| 1136 | VkBuffer buffer; |
| 1137 | VkImage image; |
| 1138 | VkDeviceMemory mem; |
| 1139 | VkMemoryRequirements mem_reqs; |
| 1140 | |
| 1141 | VkBufferCreateInfo buf_info = {}; |
| 1142 | buf_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO; |
| 1143 | buf_info.pNext = NULL; |
| 1144 | buf_info.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT; |
| 1145 | buf_info.size = 256; |
| 1146 | buf_info.queueFamilyIndexCount = 0; |
| 1147 | buf_info.pQueueFamilyIndices = NULL; |
| 1148 | buf_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE; |
| 1149 | buf_info.flags = 0; |
| 1150 | err = vkCreateBuffer(m_device->device(), &buf_info, NULL, &buffer); |
| 1151 | ASSERT_VK_SUCCESS(err); |
| 1152 | |
| 1153 | vkGetBufferMemoryRequirements(m_device->device(), buffer, &mem_reqs); |
| 1154 | |
| 1155 | VkMemoryAllocateInfo alloc_info = {}; |
| 1156 | alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO; |
| 1157 | alloc_info.pNext = NULL; |
| 1158 | alloc_info.memoryTypeIndex = 0; |
| 1159 | |
| 1160 | // Ensure memory is big enough for both bindings |
| 1161 | alloc_info.allocationSize = 0x10000; |
| 1162 | |
| 1163 | pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &alloc_info, |
| 1164 | VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT); |
| 1165 | if (!pass) { |
| 1166 | vkDestroyBuffer(m_device->device(), buffer, NULL); |
| 1167 | return; |
| 1168 | } |
| 1169 | |
| 1170 | err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem); |
| 1171 | ASSERT_VK_SUCCESS(err); |
| 1172 | |
| 1173 | uint8_t *pData; |
| 1174 | err = vkMapMemory(m_device->device(), mem, 0, mem_reqs.size, 0, |
| 1175 | (void **)&pData); |
| 1176 | ASSERT_VK_SUCCESS(err); |
| 1177 | |
Mark Lobodzinski | 2abefa9 | 2016-05-05 11:45:57 -0600 | [diff] [blame] | 1178 | memset(pData, 0xCADECADE, static_cast<size_t>(mem_reqs.size)); |
Mark Lobodzinski | 152fe25 | 2016-05-03 16:49:15 -0600 | [diff] [blame] | 1179 | |
| 1180 | vkUnmapMemory(m_device->device(), mem); |
| 1181 | |
| 1182 | err = vkBindBufferMemory(m_device->device(), buffer, mem, 0); |
| 1183 | ASSERT_VK_SUCCESS(err); |
| 1184 | |
| 1185 | // NOW, destroy the buffer. Obviously, the resource no longer occupies this |
| 1186 | // memory. In fact, it was never used by the GPU. |
| 1187 | // Just be be sure, wait for idle. |
| 1188 | vkDestroyBuffer(m_device->device(), buffer, NULL); |
| 1189 | vkDeviceWaitIdle(m_device->device()); |
| 1190 | |
| 1191 | VkImageCreateInfo image_create_info = {}; |
| 1192 | image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO; |
| 1193 | image_create_info.pNext = NULL; |
| 1194 | image_create_info.imageType = VK_IMAGE_TYPE_2D; |
| 1195 | image_create_info.format = VK_FORMAT_R8G8B8A8_UNORM; |
| 1196 | image_create_info.extent.width = 64; |
| 1197 | image_create_info.extent.height = 64; |
| 1198 | image_create_info.extent.depth = 1; |
| 1199 | image_create_info.mipLevels = 1; |
| 1200 | image_create_info.arrayLayers = 1; |
| 1201 | image_create_info.samples = VK_SAMPLE_COUNT_1_BIT; |
| 1202 | image_create_info.tiling = VK_IMAGE_TILING_LINEAR; |
| 1203 | image_create_info.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED; |
| 1204 | image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT; |
| 1205 | image_create_info.queueFamilyIndexCount = 0; |
| 1206 | image_create_info.pQueueFamilyIndices = NULL; |
| 1207 | image_create_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE; |
| 1208 | image_create_info.flags = 0; |
| 1209 | |
| 1210 | VkMemoryAllocateInfo mem_alloc = {}; |
| 1211 | mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO; |
| 1212 | mem_alloc.pNext = NULL; |
| 1213 | mem_alloc.allocationSize = 0; |
| 1214 | mem_alloc.memoryTypeIndex = 0; |
| 1215 | |
| 1216 | /* Create a mappable image. It will be the texture if linear images are ok |
| 1217 | * to be textures or it will be the staging image if they are not. |
| 1218 | */ |
| 1219 | err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image); |
| 1220 | ASSERT_VK_SUCCESS(err); |
| 1221 | |
| 1222 | vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs); |
| 1223 | |
| 1224 | mem_alloc.allocationSize = mem_reqs.size; |
| 1225 | |
| 1226 | pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, |
| 1227 | VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT); |
| 1228 | if (!pass) { |
| 1229 | vkDestroyImage(m_device->device(), image, NULL); |
| 1230 | return; |
| 1231 | } |
| 1232 | |
Tobin Ehlis | 077ded3 | 2016-05-12 17:39:13 -0600 | [diff] [blame] | 1233 | // VALIDATION FAILURE: |
Mark Lobodzinski | 152fe25 | 2016-05-03 16:49:15 -0600 | [diff] [blame] | 1234 | err = vkBindImageMemory(m_device->device(), image, mem, 0); |
| 1235 | ASSERT_VK_SUCCESS(err); |
| 1236 | |
| 1237 | m_errorMonitor->VerifyNotFound(); |
| 1238 | |
Tony Barbour | df4c004 | 2016-06-01 15:55:43 -0600 | [diff] [blame] | 1239 | vkFreeMemory(m_device->device(), mem, NULL); |
Mark Lobodzinski | 152fe25 | 2016-05-03 16:49:15 -0600 | [diff] [blame] | 1240 | vkDestroyBuffer(m_device->device(), buffer, NULL); |
| 1241 | vkDestroyImage(m_device->device(), image, NULL); |
| 1242 | } |
| 1243 | |
Tobin Ehlis | f11be98 | 2016-05-11 13:52:53 -0600 | [diff] [blame] | 1244 | TEST_F(VkLayerTest, InvalidMemoryAliasing) { |
| 1245 | TEST_DESCRIPTION("Create a buffer and image, allocate memory, and bind the " |
| 1246 | "buffer and image to memory such that they will alias."); |
| 1247 | VkResult err; |
| 1248 | bool pass; |
| 1249 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 1250 | |
Tobin Ehlis | 077ded3 | 2016-05-12 17:39:13 -0600 | [diff] [blame] | 1251 | VkBuffer buffer, buffer2; |
Tobin Ehlis | f11be98 | 2016-05-11 13:52:53 -0600 | [diff] [blame] | 1252 | VkImage image; |
| 1253 | VkDeviceMemory mem; // buffer will be bound first |
| 1254 | VkDeviceMemory mem_img; // image bound first |
Tobin Ehlis | 077ded3 | 2016-05-12 17:39:13 -0600 | [diff] [blame] | 1255 | VkMemoryRequirements buff_mem_reqs, img_mem_reqs; |
Tobin Ehlis | f11be98 | 2016-05-11 13:52:53 -0600 | [diff] [blame] | 1256 | |
| 1257 | VkBufferCreateInfo buf_info = {}; |
| 1258 | buf_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO; |
| 1259 | buf_info.pNext = NULL; |
| 1260 | buf_info.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT; |
| 1261 | buf_info.size = 256; |
| 1262 | buf_info.queueFamilyIndexCount = 0; |
| 1263 | buf_info.pQueueFamilyIndices = NULL; |
| 1264 | buf_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE; |
| 1265 | buf_info.flags = 0; |
| 1266 | err = vkCreateBuffer(m_device->device(), &buf_info, NULL, &buffer); |
| 1267 | ASSERT_VK_SUCCESS(err); |
| 1268 | |
Tobin Ehlis | 077ded3 | 2016-05-12 17:39:13 -0600 | [diff] [blame] | 1269 | vkGetBufferMemoryRequirements(m_device->device(), buffer, &buff_mem_reqs); |
Tobin Ehlis | f11be98 | 2016-05-11 13:52:53 -0600 | [diff] [blame] | 1270 | |
| 1271 | VkImageCreateInfo image_create_info = {}; |
| 1272 | image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO; |
| 1273 | image_create_info.pNext = NULL; |
| 1274 | image_create_info.imageType = VK_IMAGE_TYPE_2D; |
| 1275 | image_create_info.format = VK_FORMAT_R8G8B8A8_UNORM; |
| 1276 | image_create_info.extent.width = 64; |
| 1277 | image_create_info.extent.height = 64; |
| 1278 | image_create_info.extent.depth = 1; |
| 1279 | image_create_info.mipLevels = 1; |
| 1280 | image_create_info.arrayLayers = 1; |
| 1281 | image_create_info.samples = VK_SAMPLE_COUNT_1_BIT; |
| 1282 | image_create_info.tiling = VK_IMAGE_TILING_LINEAR; |
| 1283 | image_create_info.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED; |
| 1284 | image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT; |
| 1285 | image_create_info.queueFamilyIndexCount = 0; |
| 1286 | image_create_info.pQueueFamilyIndices = NULL; |
| 1287 | image_create_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE; |
| 1288 | image_create_info.flags = 0; |
| 1289 | |
Tobin Ehlis | f11be98 | 2016-05-11 13:52:53 -0600 | [diff] [blame] | 1290 | err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image); |
| 1291 | ASSERT_VK_SUCCESS(err); |
| 1292 | |
Tobin Ehlis | 077ded3 | 2016-05-12 17:39:13 -0600 | [diff] [blame] | 1293 | vkGetImageMemoryRequirements(m_device->device(), image, &img_mem_reqs); |
| 1294 | |
| 1295 | VkMemoryAllocateInfo alloc_info = {}; |
| 1296 | alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO; |
| 1297 | alloc_info.pNext = NULL; |
| 1298 | alloc_info.memoryTypeIndex = 0; |
| 1299 | // Ensure memory is big enough for both bindings |
| 1300 | alloc_info.allocationSize = buff_mem_reqs.size + img_mem_reqs.size; |
| 1301 | pass = m_device->phy().set_memory_type( |
| 1302 | buff_mem_reqs.memoryTypeBits | img_mem_reqs.memoryTypeBits, &alloc_info, |
| 1303 | VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT); |
Tobin Ehlis | f11be98 | 2016-05-11 13:52:53 -0600 | [diff] [blame] | 1304 | if (!pass) { |
Tobin Ehlis | 077ded3 | 2016-05-12 17:39:13 -0600 | [diff] [blame] | 1305 | vkDestroyBuffer(m_device->device(), buffer, NULL); |
Tobin Ehlis | f11be98 | 2016-05-11 13:52:53 -0600 | [diff] [blame] | 1306 | vkDestroyImage(m_device->device(), image, NULL); |
| 1307 | return; |
| 1308 | } |
Tobin Ehlis | 077ded3 | 2016-05-12 17:39:13 -0600 | [diff] [blame] | 1309 | err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem); |
| 1310 | ASSERT_VK_SUCCESS(err); |
| 1311 | err = vkBindBufferMemory(m_device->device(), buffer, mem, 0); |
| 1312 | ASSERT_VK_SUCCESS(err); |
| 1313 | |
Tobin Ehlis | f11be98 | 2016-05-11 13:52:53 -0600 | [diff] [blame] | 1314 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 1315 | " is aliased with buffer 0x"); |
Tobin Ehlis | 077ded3 | 2016-05-12 17:39:13 -0600 | [diff] [blame] | 1316 | // VALIDATION FAILURE due to image mapping overlapping buffer mapping |
Tobin Ehlis | f11be98 | 2016-05-11 13:52:53 -0600 | [diff] [blame] | 1317 | err = vkBindImageMemory(m_device->device(), image, mem, 0); |
| 1318 | m_errorMonitor->VerifyFound(); |
| 1319 | |
| 1320 | // Now correctly bind image to second mem allocation before incorrectly |
Tobin Ehlis | 077ded3 | 2016-05-12 17:39:13 -0600 | [diff] [blame] | 1321 | // aliasing buffer2 |
| 1322 | err = vkCreateBuffer(m_device->device(), &buf_info, NULL, &buffer2); |
| 1323 | ASSERT_VK_SUCCESS(err); |
Tobin Ehlis | f11be98 | 2016-05-11 13:52:53 -0600 | [diff] [blame] | 1324 | err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem_img); |
| 1325 | ASSERT_VK_SUCCESS(err); |
| 1326 | err = vkBindImageMemory(m_device->device(), image, mem_img, 0); |
| 1327 | ASSERT_VK_SUCCESS(err); |
| 1328 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 1329 | " is aliased with image 0x"); |
Tobin Ehlis | 077ded3 | 2016-05-12 17:39:13 -0600 | [diff] [blame] | 1330 | err = vkBindBufferMemory(m_device->device(), buffer2, mem_img, 0); |
Tobin Ehlis | f11be98 | 2016-05-11 13:52:53 -0600 | [diff] [blame] | 1331 | m_errorMonitor->VerifyFound(); |
| 1332 | |
| 1333 | vkDestroyBuffer(m_device->device(), buffer, NULL); |
Tobin Ehlis | 077ded3 | 2016-05-12 17:39:13 -0600 | [diff] [blame] | 1334 | vkDestroyBuffer(m_device->device(), buffer2, NULL); |
Tobin Ehlis | f11be98 | 2016-05-11 13:52:53 -0600 | [diff] [blame] | 1335 | vkDestroyImage(m_device->device(), image, NULL); |
| 1336 | vkFreeMemory(m_device->device(), mem, NULL); |
| 1337 | vkFreeMemory(m_device->device(), mem_img, NULL); |
| 1338 | } |
| 1339 | |
Tobin Ehlis | 3537252 | 2016-05-12 08:32:31 -0600 | [diff] [blame] | 1340 | TEST_F(VkLayerTest, InvalidMemoryMapping) { |
| 1341 | TEST_DESCRIPTION("Attempt to map memory in a number of incorrect ways"); |
| 1342 | VkResult err; |
| 1343 | bool pass; |
| 1344 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 1345 | |
| 1346 | VkBuffer buffer; |
| 1347 | VkDeviceMemory mem; |
| 1348 | VkMemoryRequirements mem_reqs; |
| 1349 | |
| 1350 | VkBufferCreateInfo buf_info = {}; |
| 1351 | buf_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO; |
| 1352 | buf_info.pNext = NULL; |
| 1353 | buf_info.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT; |
| 1354 | buf_info.size = 256; |
| 1355 | buf_info.queueFamilyIndexCount = 0; |
| 1356 | buf_info.pQueueFamilyIndices = NULL; |
| 1357 | buf_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE; |
| 1358 | buf_info.flags = 0; |
| 1359 | err = vkCreateBuffer(m_device->device(), &buf_info, NULL, &buffer); |
| 1360 | ASSERT_VK_SUCCESS(err); |
| 1361 | |
| 1362 | vkGetBufferMemoryRequirements(m_device->device(), buffer, &mem_reqs); |
| 1363 | VkMemoryAllocateInfo alloc_info = {}; |
| 1364 | alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO; |
| 1365 | alloc_info.pNext = NULL; |
| 1366 | alloc_info.memoryTypeIndex = 0; |
| 1367 | |
| 1368 | // Ensure memory is big enough for both bindings |
| 1369 | static const VkDeviceSize allocation_size = 0x10000; |
| 1370 | alloc_info.allocationSize = allocation_size; |
| 1371 | pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &alloc_info, |
| 1372 | VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT); |
| 1373 | if (!pass) { |
| 1374 | vkDestroyBuffer(m_device->device(), buffer, NULL); |
| 1375 | return; |
| 1376 | } |
| 1377 | err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem); |
| 1378 | ASSERT_VK_SUCCESS(err); |
| 1379 | |
| 1380 | uint8_t *pData; |
| 1381 | // Attempt to map memory size 0 is invalid |
| 1382 | m_errorMonitor->SetDesiredFailureMsg( |
| 1383 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 1384 | "VkMapMemory: Attempting to map memory range of size zero"); |
| 1385 | err = vkMapMemory(m_device->device(), mem, 0, 0, 0, (void **)&pData); |
| 1386 | m_errorMonitor->VerifyFound(); |
| 1387 | // Map memory twice |
| 1388 | err = vkMapMemory(m_device->device(), mem, 0, mem_reqs.size, 0, |
| 1389 | (void **)&pData); |
| 1390 | ASSERT_VK_SUCCESS(err); |
| 1391 | m_errorMonitor->SetDesiredFailureMsg( |
| 1392 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 1393 | "VkMapMemory: Attempting to map memory on an already-mapped object "); |
| 1394 | err = vkMapMemory(m_device->device(), mem, 0, mem_reqs.size, 0, |
| 1395 | (void **)&pData); |
| 1396 | m_errorMonitor->VerifyFound(); |
| 1397 | |
| 1398 | // Unmap the memory to avoid re-map error |
| 1399 | vkUnmapMemory(m_device->device(), mem); |
| 1400 | // overstep allocation with VK_WHOLE_SIZE |
| 1401 | m_errorMonitor->SetDesiredFailureMsg( |
| 1402 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 1403 | " with size of VK_WHOLE_SIZE oversteps total array size 0x"); |
| 1404 | err = vkMapMemory(m_device->device(), mem, allocation_size + 1, |
| 1405 | VK_WHOLE_SIZE, 0, (void **)&pData); |
| 1406 | m_errorMonitor->VerifyFound(); |
| 1407 | // overstep allocation w/o VK_WHOLE_SIZE |
| 1408 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 1409 | " oversteps total array size 0x"); |
| 1410 | err = vkMapMemory(m_device->device(), mem, 1, allocation_size, 0, |
| 1411 | (void **)&pData); |
| 1412 | m_errorMonitor->VerifyFound(); |
| 1413 | // Now error due to unmapping memory that's not mapped |
| 1414 | m_errorMonitor->SetDesiredFailureMsg( |
| 1415 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 1416 | "Unmapping Memory without memory being mapped: "); |
| 1417 | vkUnmapMemory(m_device->device(), mem); |
| 1418 | m_errorMonitor->VerifyFound(); |
| 1419 | // Now map memory and cause errors due to flushing invalid ranges |
| 1420 | err = vkMapMemory(m_device->device(), mem, 16, VK_WHOLE_SIZE, 0, |
| 1421 | (void **)&pData); |
| 1422 | ASSERT_VK_SUCCESS(err); |
| 1423 | VkMappedMemoryRange mmr = {}; |
Chris Forbes | 3aec089 | 2016-06-13 10:29:26 +1200 | [diff] [blame] | 1424 | mmr.sType = VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE; |
Tobin Ehlis | 3537252 | 2016-05-12 08:32:31 -0600 | [diff] [blame] | 1425 | mmr.memory = mem; |
| 1426 | mmr.offset = 15; // Error b/c offset less than offset of mapped mem |
| 1427 | m_errorMonitor->SetDesiredFailureMsg( |
| 1428 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 1429 | ") is less than Memory Object's offset ("); |
| 1430 | vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr); |
| 1431 | m_errorMonitor->VerifyFound(); |
| 1432 | // Now flush range that oversteps mapped range |
| 1433 | vkUnmapMemory(m_device->device(), mem); |
| 1434 | err = vkMapMemory(m_device->device(), mem, 0, 256, 0, (void **)&pData); |
| 1435 | ASSERT_VK_SUCCESS(err); |
| 1436 | mmr.offset = 16; |
| 1437 | mmr.size = 256; // flushing bounds (272) exceed mapped bounds (256) |
| 1438 | m_errorMonitor->SetDesiredFailureMsg( |
| 1439 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 1440 | ") exceeds the Memory Object's upper-bound ("); |
| 1441 | vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr); |
| 1442 | m_errorMonitor->VerifyFound(); |
| 1443 | |
| 1444 | pass = |
| 1445 | m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &alloc_info, |
| 1446 | VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT, |
| 1447 | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT); |
| 1448 | if (!pass) { |
| 1449 | vkFreeMemory(m_device->device(), mem, NULL); |
| 1450 | vkDestroyBuffer(m_device->device(), buffer, NULL); |
| 1451 | return; |
| 1452 | } |
| 1453 | // TODO : If we can get HOST_VISIBLE w/o HOST_COHERENT we can test cases of |
| 1454 | // MEMTRACK_INVALID_MAP in validateAndCopyNoncoherentMemoryToDriver() |
| 1455 | |
| 1456 | vkDestroyBuffer(m_device->device(), buffer, NULL); |
| 1457 | vkFreeMemory(m_device->device(), mem, NULL); |
| 1458 | } |
| 1459 | |
Ian Elliott | 1c32c77 | 2016-04-28 14:47:13 -0600 | [diff] [blame] | 1460 | TEST_F(VkLayerTest, EnableWsiBeforeUse) { |
| 1461 | VkResult err; |
| 1462 | bool pass; |
| 1463 | |
Ian Elliott | 489eec0 | 2016-05-05 14:12:44 -0600 | [diff] [blame] | 1464 | // FIXME: After we turn on this code for non-Linux platforms, uncomment the |
| 1465 | // following declaration (which is temporarily being moved below): |
| 1466 | // VkSurfaceKHR surface = VK_NULL_HANDLE; |
Ian Elliott | 1c32c77 | 2016-04-28 14:47:13 -0600 | [diff] [blame] | 1467 | VkSwapchainKHR swapchain = VK_NULL_HANDLE; |
| 1468 | VkSwapchainCreateInfoKHR swapchain_create_info = {}; |
| 1469 | uint32_t swapchain_image_count = 0; |
| 1470 | // VkImage swapchain_images[1] = {VK_NULL_HANDLE}; |
| 1471 | uint32_t image_index = 0; |
| 1472 | // VkPresentInfoKHR present_info = {}; |
| 1473 | |
| 1474 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 1475 | |
Ian Elliott | 3f06ce5 | 2016-04-29 14:46:21 -0600 | [diff] [blame] | 1476 | #ifdef NEED_TO_TEST_THIS_ON_PLATFORM |
| 1477 | #if defined(VK_USE_PLATFORM_ANDROID_KHR) |
| 1478 | // Use the functions from the VK_KHR_android_surface extension without |
| 1479 | // enabling that extension: |
| 1480 | |
| 1481 | // Create a surface: |
| 1482 | VkAndroidSurfaceCreateInfoKHR android_create_info = {}; |
Ian Elliott | 3f06ce5 | 2016-04-29 14:46:21 -0600 | [diff] [blame] | 1483 | m_errorMonitor->SetDesiredFailureMsg( |
| 1484 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 1485 | "extension was not enabled for this"); |
| 1486 | err = vkCreateAndroidSurfaceKHR(instance(), &android_create_info, NULL, |
| 1487 | &surface); |
| 1488 | pass = (err != VK_SUCCESS); |
| 1489 | ASSERT_TRUE(pass); |
| 1490 | m_errorMonitor->VerifyFound(); |
| 1491 | #endif // VK_USE_PLATFORM_ANDROID_KHR |
| 1492 | |
| 1493 | |
| 1494 | #if defined(VK_USE_PLATFORM_MIR_KHR) |
| 1495 | // Use the functions from the VK_KHR_mir_surface extension without enabling |
| 1496 | // that extension: |
| 1497 | |
| 1498 | // Create a surface: |
| 1499 | VkMirSurfaceCreateInfoKHR mir_create_info = {}; |
Ian Elliott | 3f06ce5 | 2016-04-29 14:46:21 -0600 | [diff] [blame] | 1500 | m_errorMonitor->SetDesiredFailureMsg( |
| 1501 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 1502 | "extension was not enabled for this"); |
| 1503 | err = vkCreateMirSurfaceKHR(instance(), &mir_create_info, NULL, &surface); |
| 1504 | pass = (err != VK_SUCCESS); |
| 1505 | ASSERT_TRUE(pass); |
| 1506 | m_errorMonitor->VerifyFound(); |
| 1507 | |
| 1508 | // Tell whether an mir_connection supports presentation: |
| 1509 | MirConnection *mir_connection = NULL; |
| 1510 | m_errorMonitor->SetDesiredFailureMsg( |
| 1511 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 1512 | "extension was not enabled for this"); |
| 1513 | vkGetPhysicalDeviceMirPresentationSupportKHR(gpu(), 0, mir_connection, |
| 1514 | visual_id); |
| 1515 | m_errorMonitor->VerifyFound(); |
| 1516 | #endif // VK_USE_PLATFORM_MIR_KHR |
| 1517 | |
| 1518 | |
| 1519 | #if defined(VK_USE_PLATFORM_WAYLAND_KHR) |
| 1520 | // Use the functions from the VK_KHR_wayland_surface extension without |
| 1521 | // enabling that extension: |
| 1522 | |
| 1523 | // Create a surface: |
| 1524 | VkWaylandSurfaceCreateInfoKHR wayland_create_info = {}; |
Ian Elliott | 3f06ce5 | 2016-04-29 14:46:21 -0600 | [diff] [blame] | 1525 | m_errorMonitor->SetDesiredFailureMsg( |
| 1526 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 1527 | "extension was not enabled for this"); |
| 1528 | err = vkCreateWaylandSurfaceKHR(instance(), &wayland_create_info, NULL, |
| 1529 | &surface); |
| 1530 | pass = (err != VK_SUCCESS); |
| 1531 | ASSERT_TRUE(pass); |
| 1532 | m_errorMonitor->VerifyFound(); |
| 1533 | |
| 1534 | // Tell whether an wayland_display supports presentation: |
| 1535 | struct wl_display wayland_display = {}; |
| 1536 | m_errorMonitor->SetDesiredFailureMsg( |
| 1537 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 1538 | "extension was not enabled for this"); |
| 1539 | vkGetPhysicalDeviceWaylandPresentationSupportKHR(gpu(), 0, |
| 1540 | &wayland_display); |
| 1541 | m_errorMonitor->VerifyFound(); |
| 1542 | #endif // VK_USE_PLATFORM_WAYLAND_KHR |
Ian Elliott | 489eec0 | 2016-05-05 14:12:44 -0600 | [diff] [blame] | 1543 | #endif // NEED_TO_TEST_THIS_ON_PLATFORM |
Ian Elliott | 3f06ce5 | 2016-04-29 14:46:21 -0600 | [diff] [blame] | 1544 | |
| 1545 | |
| 1546 | #if defined(VK_USE_PLATFORM_WIN32_KHR) |
Ian Elliott | 489eec0 | 2016-05-05 14:12:44 -0600 | [diff] [blame] | 1547 | // FIXME: REMOVE THIS HERE, AND UNCOMMENT ABOVE, WHEN THIS TEST HAS BEEN PORTED |
| 1548 | // TO NON-LINUX PLATFORMS: |
| 1549 | VkSurfaceKHR surface = VK_NULL_HANDLE; |
Ian Elliott | 3f06ce5 | 2016-04-29 14:46:21 -0600 | [diff] [blame] | 1550 | // Use the functions from the VK_KHR_win32_surface extension without |
| 1551 | // enabling that extension: |
| 1552 | |
| 1553 | // Create a surface: |
| 1554 | VkWin32SurfaceCreateInfoKHR win32_create_info = {}; |
Ian Elliott | 3f06ce5 | 2016-04-29 14:46:21 -0600 | [diff] [blame] | 1555 | m_errorMonitor->SetDesiredFailureMsg( |
| 1556 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 1557 | "extension was not enabled for this"); |
| 1558 | err = vkCreateWin32SurfaceKHR(instance(), &win32_create_info, NULL, |
| 1559 | &surface); |
| 1560 | pass = (err != VK_SUCCESS); |
| 1561 | ASSERT_TRUE(pass); |
| 1562 | m_errorMonitor->VerifyFound(); |
| 1563 | |
| 1564 | // Tell whether win32 supports presentation: |
Ian Elliott | 3f06ce5 | 2016-04-29 14:46:21 -0600 | [diff] [blame] | 1565 | m_errorMonitor->SetDesiredFailureMsg( |
| 1566 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 1567 | "extension was not enabled for this"); |
Ian Elliott | 489eec0 | 2016-05-05 14:12:44 -0600 | [diff] [blame] | 1568 | vkGetPhysicalDeviceWin32PresentationSupportKHR(gpu(), 0); |
Ian Elliott | 3f06ce5 | 2016-04-29 14:46:21 -0600 | [diff] [blame] | 1569 | m_errorMonitor->VerifyFound(); |
Ian Elliott | 489eec0 | 2016-05-05 14:12:44 -0600 | [diff] [blame] | 1570 | // Set this (for now, until all platforms are supported and tested): |
| 1571 | #define NEED_TO_TEST_THIS_ON_PLATFORM |
| 1572 | #endif // VK_USE_PLATFORM_WIN32_KHR |
Ian Elliott | 3f06ce5 | 2016-04-29 14:46:21 -0600 | [diff] [blame] | 1573 | |
| 1574 | |
Ian Elliott | 1c32c77 | 2016-04-28 14:47:13 -0600 | [diff] [blame] | 1575 | #if defined(VK_USE_PLATFORM_XCB_KHR) |
Ian Elliott | 489eec0 | 2016-05-05 14:12:44 -0600 | [diff] [blame] | 1576 | // FIXME: REMOVE THIS HERE, AND UNCOMMENT ABOVE, WHEN THIS TEST HAS BEEN PORTED |
| 1577 | // TO NON-LINUX PLATFORMS: |
| 1578 | VkSurfaceKHR surface = VK_NULL_HANDLE; |
Ian Elliott | 1c32c77 | 2016-04-28 14:47:13 -0600 | [diff] [blame] | 1579 | // Use the functions from the VK_KHR_xcb_surface extension without enabling |
| 1580 | // that extension: |
| 1581 | |
| 1582 | // Create a surface: |
| 1583 | VkXcbSurfaceCreateInfoKHR xcb_create_info = {}; |
Ian Elliott | 1c32c77 | 2016-04-28 14:47:13 -0600 | [diff] [blame] | 1584 | m_errorMonitor->SetDesiredFailureMsg( |
| 1585 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 1586 | "extension was not enabled for this"); |
| 1587 | err = vkCreateXcbSurfaceKHR(instance(), &xcb_create_info, NULL, &surface); |
| 1588 | pass = (err != VK_SUCCESS); |
| 1589 | ASSERT_TRUE(pass); |
| 1590 | m_errorMonitor->VerifyFound(); |
| 1591 | |
| 1592 | // Tell whether an xcb_visualid_t supports presentation: |
Ian Elliott | 3f06ce5 | 2016-04-29 14:46:21 -0600 | [diff] [blame] | 1593 | xcb_connection_t *xcb_connection = NULL; |
Ian Elliott | 1c32c77 | 2016-04-28 14:47:13 -0600 | [diff] [blame] | 1594 | xcb_visualid_t visual_id = 0; |
| 1595 | m_errorMonitor->SetDesiredFailureMsg( |
| 1596 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 1597 | "extension was not enabled for this"); |
Ian Elliott | 3f06ce5 | 2016-04-29 14:46:21 -0600 | [diff] [blame] | 1598 | vkGetPhysicalDeviceXcbPresentationSupportKHR(gpu(), 0, xcb_connection, |
Ian Elliott | 1c32c77 | 2016-04-28 14:47:13 -0600 | [diff] [blame] | 1599 | visual_id); |
| 1600 | m_errorMonitor->VerifyFound(); |
Ian Elliott | 489eec0 | 2016-05-05 14:12:44 -0600 | [diff] [blame] | 1601 | // Set this (for now, until all platforms are supported and tested): |
| 1602 | #define NEED_TO_TEST_THIS_ON_PLATFORM |
Ian Elliott | 1c32c77 | 2016-04-28 14:47:13 -0600 | [diff] [blame] | 1603 | #endif // VK_USE_PLATFORM_XCB_KHR |
| 1604 | |
| 1605 | |
Ian Elliott | 1263081 | 2016-04-29 14:35:43 -0600 | [diff] [blame] | 1606 | #if defined(VK_USE_PLATFORM_XLIB_KHR) |
| 1607 | // Use the functions from the VK_KHR_xlib_surface extension without enabling |
| 1608 | // that extension: |
| 1609 | |
| 1610 | // Create a surface: |
| 1611 | VkXlibSurfaceCreateInfoKHR xlib_create_info = {}; |
Ian Elliott | 1263081 | 2016-04-29 14:35:43 -0600 | [diff] [blame] | 1612 | m_errorMonitor->SetDesiredFailureMsg( |
| 1613 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 1614 | "extension was not enabled for this"); |
| 1615 | err = vkCreateXlibSurfaceKHR(instance(), &xlib_create_info, NULL, &surface); |
| 1616 | pass = (err != VK_SUCCESS); |
| 1617 | ASSERT_TRUE(pass); |
| 1618 | m_errorMonitor->VerifyFound(); |
| 1619 | |
| 1620 | // Tell whether an Xlib VisualID supports presentation: |
| 1621 | Display *dpy = NULL; |
| 1622 | VisualID visual = 0; |
| 1623 | m_errorMonitor->SetDesiredFailureMsg( |
| 1624 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 1625 | "extension was not enabled for this"); |
| 1626 | vkGetPhysicalDeviceXlibPresentationSupportKHR(gpu(), 0, dpy, visual); |
| 1627 | m_errorMonitor->VerifyFound(); |
Ian Elliott | 489eec0 | 2016-05-05 14:12:44 -0600 | [diff] [blame] | 1628 | // Set this (for now, until all platforms are supported and tested): |
| 1629 | #define NEED_TO_TEST_THIS_ON_PLATFORM |
Ian Elliott | 1263081 | 2016-04-29 14:35:43 -0600 | [diff] [blame] | 1630 | #endif // VK_USE_PLATFORM_XLIB_KHR |
| 1631 | |
| 1632 | |
Ian Elliott | 1c32c77 | 2016-04-28 14:47:13 -0600 | [diff] [blame] | 1633 | // Use the functions from the VK_KHR_surface extension without enabling |
| 1634 | // that extension: |
| 1635 | |
Ian Elliott | 489eec0 | 2016-05-05 14:12:44 -0600 | [diff] [blame] | 1636 | #ifdef NEED_TO_TEST_THIS_ON_PLATFORM |
Ian Elliott | 1c32c77 | 2016-04-28 14:47:13 -0600 | [diff] [blame] | 1637 | // Destroy a surface: |
| 1638 | m_errorMonitor->SetDesiredFailureMsg( |
| 1639 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 1640 | "extension was not enabled for this"); |
| 1641 | vkDestroySurfaceKHR(instance(), surface, NULL); |
| 1642 | m_errorMonitor->VerifyFound(); |
| 1643 | |
| 1644 | // Check if surface supports presentation: |
| 1645 | VkBool32 supported = false; |
| 1646 | m_errorMonitor->SetDesiredFailureMsg( |
| 1647 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 1648 | "extension was not enabled for this"); |
| 1649 | err = vkGetPhysicalDeviceSurfaceSupportKHR(gpu(), 0, surface, &supported); |
| 1650 | pass = (err != VK_SUCCESS); |
| 1651 | ASSERT_TRUE(pass); |
| 1652 | m_errorMonitor->VerifyFound(); |
| 1653 | |
| 1654 | // Check surface capabilities: |
| 1655 | VkSurfaceCapabilitiesKHR capabilities = {}; |
| 1656 | m_errorMonitor->SetDesiredFailureMsg( |
| 1657 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 1658 | "extension was not enabled for this"); |
| 1659 | err = vkGetPhysicalDeviceSurfaceCapabilitiesKHR(gpu(), surface, |
| 1660 | &capabilities); |
| 1661 | pass = (err != VK_SUCCESS); |
| 1662 | ASSERT_TRUE(pass); |
| 1663 | m_errorMonitor->VerifyFound(); |
| 1664 | |
| 1665 | // Check surface formats: |
| 1666 | uint32_t format_count = 0; |
| 1667 | VkSurfaceFormatKHR *formats = NULL; |
| 1668 | m_errorMonitor->SetDesiredFailureMsg( |
| 1669 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 1670 | "extension was not enabled for this"); |
| 1671 | err = vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, |
| 1672 | &format_count, formats); |
| 1673 | pass = (err != VK_SUCCESS); |
| 1674 | ASSERT_TRUE(pass); |
| 1675 | m_errorMonitor->VerifyFound(); |
| 1676 | |
| 1677 | // Check surface present modes: |
| 1678 | uint32_t present_mode_count = 0; |
| 1679 | VkSurfaceFormatKHR *present_modes = NULL; |
| 1680 | m_errorMonitor->SetDesiredFailureMsg( |
| 1681 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 1682 | "extension was not enabled for this"); |
| 1683 | err = vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, |
| 1684 | &present_mode_count, present_modes); |
| 1685 | pass = (err != VK_SUCCESS); |
| 1686 | ASSERT_TRUE(pass); |
| 1687 | m_errorMonitor->VerifyFound(); |
Ian Elliott | 489eec0 | 2016-05-05 14:12:44 -0600 | [diff] [blame] | 1688 | #endif // NEED_TO_TEST_THIS_ON_PLATFORM |
Ian Elliott | 1c32c77 | 2016-04-28 14:47:13 -0600 | [diff] [blame] | 1689 | |
| 1690 | |
| 1691 | // Use the functions from the VK_KHR_swapchain extension without enabling |
| 1692 | // that extension: |
| 1693 | |
| 1694 | // Create a swapchain: |
| 1695 | m_errorMonitor->SetDesiredFailureMsg( |
| 1696 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 1697 | "extension was not enabled for this"); |
| 1698 | swapchain_create_info.sType = VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR; |
| 1699 | swapchain_create_info.pNext = NULL; |
Ian Elliott | 1c32c77 | 2016-04-28 14:47:13 -0600 | [diff] [blame] | 1700 | err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, |
| 1701 | NULL, &swapchain); |
| 1702 | pass = (err != VK_SUCCESS); |
| 1703 | ASSERT_TRUE(pass); |
| 1704 | m_errorMonitor->VerifyFound(); |
| 1705 | |
| 1706 | // Get the images from the swapchain: |
| 1707 | m_errorMonitor->SetDesiredFailureMsg( |
| 1708 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 1709 | "extension was not enabled for this"); |
| 1710 | err = vkGetSwapchainImagesKHR(m_device->device(), swapchain, |
| 1711 | &swapchain_image_count, NULL); |
| 1712 | pass = (err != VK_SUCCESS); |
| 1713 | ASSERT_TRUE(pass); |
| 1714 | m_errorMonitor->VerifyFound(); |
| 1715 | |
| 1716 | // Try to acquire an image: |
| 1717 | m_errorMonitor->SetDesiredFailureMsg( |
| 1718 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 1719 | "extension was not enabled for this"); |
| 1720 | err = vkAcquireNextImageKHR(m_device->device(), swapchain, 0, |
| 1721 | VK_NULL_HANDLE, VK_NULL_HANDLE, &image_index); |
| 1722 | pass = (err != VK_SUCCESS); |
| 1723 | ASSERT_TRUE(pass); |
| 1724 | m_errorMonitor->VerifyFound(); |
| 1725 | |
| 1726 | // Try to present an image: |
Ian Elliott | 2c1daf5 | 2016-05-12 09:41:46 -0600 | [diff] [blame] | 1727 | // |
| 1728 | // NOTE: Currently can't test this because a real swapchain is needed (as |
| 1729 | // opposed to the fake one we created) in order for the layer to lookup the |
| 1730 | // VkDevice used to enable the extension: |
Ian Elliott | 1c32c77 | 2016-04-28 14:47:13 -0600 | [diff] [blame] | 1731 | |
| 1732 | // Destroy the swapchain: |
| 1733 | m_errorMonitor->SetDesiredFailureMsg( |
| 1734 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 1735 | "extension was not enabled for this"); |
| 1736 | vkDestroySwapchainKHR(m_device->device(), swapchain, NULL); |
| 1737 | m_errorMonitor->VerifyFound(); |
| 1738 | } |
| 1739 | |
Ian Elliott | 2c1daf5 | 2016-05-12 09:41:46 -0600 | [diff] [blame] | 1740 | TEST_F(VkWsiEnabledLayerTest, TestEnabledWsi) { |
Ian Elliott | 2c1daf5 | 2016-05-12 09:41:46 -0600 | [diff] [blame] | 1741 | |
Dustin Graves | 6c6d898 | 2016-05-17 10:09:21 -0600 | [diff] [blame] | 1742 | #if defined(VK_USE_PLATFORM_XCB_KHR) |
Ian Elliott | 2c1daf5 | 2016-05-12 09:41:46 -0600 | [diff] [blame] | 1743 | VkSurfaceKHR surface = VK_NULL_HANDLE; |
Mark Lobodzinski | 085d27a | 2016-05-17 09:34:26 -0600 | [diff] [blame] | 1744 | |
Mark Lobodzinski | 085d27a | 2016-05-17 09:34:26 -0600 | [diff] [blame] | 1745 | VkResult err; |
| 1746 | bool pass; |
Ian Elliott | 2c1daf5 | 2016-05-12 09:41:46 -0600 | [diff] [blame] | 1747 | VkSwapchainKHR swapchain = VK_NULL_HANDLE; |
| 1748 | VkSwapchainCreateInfoKHR swapchain_create_info = {}; |
Mark Lobodzinski | 085d27a | 2016-05-17 09:34:26 -0600 | [diff] [blame] | 1749 | // uint32_t swapchain_image_count = 0; |
| 1750 | // VkImage swapchain_images[1] = {VK_NULL_HANDLE}; |
| 1751 | // uint32_t image_index = 0; |
| 1752 | // VkPresentInfoKHR present_info = {}; |
Ian Elliott | 2c1daf5 | 2016-05-12 09:41:46 -0600 | [diff] [blame] | 1753 | |
| 1754 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 1755 | |
| 1756 | // Use the create function from one of the VK_KHR_*_surface extension in |
| 1757 | // order to create a surface, testing all known errors in the process, |
| 1758 | // before successfully creating a surface: |
| 1759 | // First, try to create a surface without a VkXcbSurfaceCreateInfoKHR: |
Mark Lobodzinski | 085d27a | 2016-05-17 09:34:26 -0600 | [diff] [blame] | 1760 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 1761 | "called with NULL pointer"); |
Ian Elliott | 2c1daf5 | 2016-05-12 09:41:46 -0600 | [diff] [blame] | 1762 | err = vkCreateXcbSurfaceKHR(instance(), NULL, NULL, &surface); |
| 1763 | pass = (err != VK_SUCCESS); |
| 1764 | ASSERT_TRUE(pass); |
| 1765 | m_errorMonitor->VerifyFound(); |
| 1766 | |
| 1767 | // Next, try to create a surface with the wrong |
| 1768 | // VkXcbSurfaceCreateInfoKHR::sType: |
| 1769 | VkXcbSurfaceCreateInfoKHR xcb_create_info = {}; |
| 1770 | xcb_create_info.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO; |
Mark Lobodzinski | 085d27a | 2016-05-17 09:34:26 -0600 | [diff] [blame] | 1771 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 1772 | "called with the wrong value for"); |
Ian Elliott | 2c1daf5 | 2016-05-12 09:41:46 -0600 | [diff] [blame] | 1773 | err = vkCreateXcbSurfaceKHR(instance(), &xcb_create_info, NULL, &surface); |
| 1774 | pass = (err != VK_SUCCESS); |
| 1775 | ASSERT_TRUE(pass); |
| 1776 | m_errorMonitor->VerifyFound(); |
| 1777 | |
Ian Elliott | 2c1daf5 | 2016-05-12 09:41:46 -0600 | [diff] [blame] | 1778 | // Create a native window, and then correctly create a surface: |
| 1779 | xcb_connection_t *connection; |
| 1780 | xcb_screen_t *screen; |
| 1781 | xcb_window_t xcb_window; |
| 1782 | xcb_intern_atom_reply_t *atom_wm_delete_window; |
| 1783 | |
| 1784 | const xcb_setup_t *setup; |
| 1785 | xcb_screen_iterator_t iter; |
| 1786 | int scr; |
| 1787 | uint32_t value_mask, value_list[32]; |
| 1788 | int width = 1; |
| 1789 | int height = 1; |
| 1790 | |
| 1791 | connection = xcb_connect(NULL, &scr); |
| 1792 | ASSERT_TRUE(connection != NULL); |
| 1793 | setup = xcb_get_setup(connection); |
| 1794 | iter = xcb_setup_roots_iterator(setup); |
| 1795 | while (scr-- > 0) |
| 1796 | xcb_screen_next(&iter); |
| 1797 | screen = iter.data; |
| 1798 | |
| 1799 | xcb_window = xcb_generate_id(connection); |
| 1800 | |
| 1801 | value_mask = XCB_CW_BACK_PIXEL | XCB_CW_EVENT_MASK; |
| 1802 | value_list[0] = screen->black_pixel; |
| 1803 | value_list[1] = XCB_EVENT_MASK_KEY_RELEASE | XCB_EVENT_MASK_EXPOSURE | |
| 1804 | XCB_EVENT_MASK_STRUCTURE_NOTIFY; |
| 1805 | |
| 1806 | xcb_create_window(connection, XCB_COPY_FROM_PARENT, xcb_window, |
| 1807 | screen->root, 0, 0, width, height, 0, |
| 1808 | XCB_WINDOW_CLASS_INPUT_OUTPUT, screen->root_visual, |
| 1809 | value_mask, value_list); |
| 1810 | |
| 1811 | /* Magic code that will send notification when window is destroyed */ |
| 1812 | xcb_intern_atom_cookie_t cookie = |
| 1813 | xcb_intern_atom(connection, 1, 12, "WM_PROTOCOLS"); |
| 1814 | xcb_intern_atom_reply_t *reply = |
| 1815 | xcb_intern_atom_reply(connection, cookie, 0); |
| 1816 | |
| 1817 | xcb_intern_atom_cookie_t cookie2 = |
| 1818 | xcb_intern_atom(connection, 0, 16, "WM_DELETE_WINDOW"); |
Mark Lobodzinski | 085d27a | 2016-05-17 09:34:26 -0600 | [diff] [blame] | 1819 | atom_wm_delete_window = xcb_intern_atom_reply(connection, cookie2, 0); |
Ian Elliott | 2c1daf5 | 2016-05-12 09:41:46 -0600 | [diff] [blame] | 1820 | xcb_change_property(connection, XCB_PROP_MODE_REPLACE, xcb_window, |
| 1821 | (*reply).atom, 4, 32, 1, |
| 1822 | &(*atom_wm_delete_window).atom); |
| 1823 | free(reply); |
| 1824 | |
| 1825 | xcb_map_window(connection, xcb_window); |
| 1826 | |
| 1827 | // Force the x/y coordinates to 100,100 results are identical in consecutive |
| 1828 | // runs |
| 1829 | const uint32_t coords[] = {100, 100}; |
| 1830 | xcb_configure_window(connection, xcb_window, |
| 1831 | XCB_CONFIG_WINDOW_X | XCB_CONFIG_WINDOW_Y, coords); |
| 1832 | |
Ian Elliott | 2c1daf5 | 2016-05-12 09:41:46 -0600 | [diff] [blame] | 1833 | // Finally, try to correctly create a surface: |
| 1834 | xcb_create_info.sType = VK_STRUCTURE_TYPE_XCB_SURFACE_CREATE_INFO_KHR; |
| 1835 | xcb_create_info.pNext = NULL; |
| 1836 | xcb_create_info.flags = 0; |
| 1837 | xcb_create_info.connection = connection; |
| 1838 | xcb_create_info.window = xcb_window; |
| 1839 | err = vkCreateXcbSurfaceKHR(instance(), &xcb_create_info, NULL, &surface); |
| 1840 | pass = (err == VK_SUCCESS); |
| 1841 | ASSERT_TRUE(pass); |
| 1842 | |
Ian Elliott | 2c1daf5 | 2016-05-12 09:41:46 -0600 | [diff] [blame] | 1843 | // Check if surface supports presentation: |
| 1844 | |
| 1845 | // 1st, do so without having queried the queue families: |
| 1846 | VkBool32 supported = false; |
| 1847 | // TODO: Get the following error to come out: |
| 1848 | m_errorMonitor->SetDesiredFailureMsg( |
| 1849 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 1850 | "called before calling the vkGetPhysicalDeviceQueueFamilyProperties " |
| 1851 | "function"); |
| 1852 | err = vkGetPhysicalDeviceSurfaceSupportKHR(gpu(), 0, surface, &supported); |
| 1853 | pass = (err != VK_SUCCESS); |
Mark Lobodzinski | 085d27a | 2016-05-17 09:34:26 -0600 | [diff] [blame] | 1854 | // ASSERT_TRUE(pass); |
| 1855 | // m_errorMonitor->VerifyFound(); |
Ian Elliott | 2c1daf5 | 2016-05-12 09:41:46 -0600 | [diff] [blame] | 1856 | |
| 1857 | // Next, query a queue family index that's too large: |
| 1858 | m_errorMonitor->SetDesiredFailureMsg( |
| 1859 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 1860 | "called with a queueFamilyIndex that is too large"); |
Mark Lobodzinski | 085d27a | 2016-05-17 09:34:26 -0600 | [diff] [blame] | 1861 | err = vkGetPhysicalDeviceSurfaceSupportKHR(gpu(), 100000, surface, |
| 1862 | &supported); |
Ian Elliott | 2c1daf5 | 2016-05-12 09:41:46 -0600 | [diff] [blame] | 1863 | pass = (err != VK_SUCCESS); |
| 1864 | ASSERT_TRUE(pass); |
| 1865 | m_errorMonitor->VerifyFound(); |
| 1866 | |
| 1867 | // Finally, do so correctly: |
Mark Lobodzinski | 085d27a | 2016-05-17 09:34:26 -0600 | [diff] [blame] | 1868 | // FIXME: THIS ISN'T CORRECT--MUST QUERY UNTIL WE FIND A QUEUE FAMILY THAT'S |
| 1869 | // SUPPORTED |
Ian Elliott | 2c1daf5 | 2016-05-12 09:41:46 -0600 | [diff] [blame] | 1870 | err = vkGetPhysicalDeviceSurfaceSupportKHR(gpu(), 0, surface, &supported); |
| 1871 | pass = (err == VK_SUCCESS); |
| 1872 | ASSERT_TRUE(pass); |
| 1873 | |
Ian Elliott | 2c1daf5 | 2016-05-12 09:41:46 -0600 | [diff] [blame] | 1874 | // Before proceeding, try to create a swapchain without having called |
| 1875 | // vkGetPhysicalDeviceSurfaceCapabilitiesKHR(): |
| 1876 | swapchain_create_info.sType = VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR; |
| 1877 | swapchain_create_info.pNext = NULL; |
| 1878 | swapchain_create_info.flags = 0; |
| 1879 | m_errorMonitor->SetDesiredFailureMsg( |
| 1880 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 1881 | "called before calling vkGetPhysicalDeviceSurfaceCapabilitiesKHR()."); |
Mark Lobodzinski | 085d27a | 2016-05-17 09:34:26 -0600 | [diff] [blame] | 1882 | err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, |
| 1883 | &swapchain); |
Ian Elliott | 2c1daf5 | 2016-05-12 09:41:46 -0600 | [diff] [blame] | 1884 | pass = (err != VK_SUCCESS); |
| 1885 | ASSERT_TRUE(pass); |
| 1886 | m_errorMonitor->VerifyFound(); |
| 1887 | |
Ian Elliott | 2c1daf5 | 2016-05-12 09:41:46 -0600 | [diff] [blame] | 1888 | // Get the surface capabilities: |
| 1889 | VkSurfaceCapabilitiesKHR surface_capabilities; |
| 1890 | |
| 1891 | // Do so correctly (only error logged by this entrypoint is if the |
| 1892 | // extension isn't enabled): |
| 1893 | err = vkGetPhysicalDeviceSurfaceCapabilitiesKHR(gpu(), surface, |
| 1894 | &surface_capabilities); |
| 1895 | pass = (err == VK_SUCCESS); |
| 1896 | ASSERT_TRUE(pass); |
| 1897 | |
Ian Elliott | 2c1daf5 | 2016-05-12 09:41:46 -0600 | [diff] [blame] | 1898 | // Get the surface formats: |
| 1899 | uint32_t surface_format_count; |
| 1900 | |
| 1901 | // First, try without a pointer to surface_format_count: |
Mark Lobodzinski | 085d27a | 2016-05-17 09:34:26 -0600 | [diff] [blame] | 1902 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 1903 | "called with NULL pointer"); |
Ian Elliott | 2c1daf5 | 2016-05-12 09:41:46 -0600 | [diff] [blame] | 1904 | vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, NULL, NULL); |
| 1905 | pass = (err == VK_SUCCESS); |
| 1906 | ASSERT_TRUE(pass); |
| 1907 | m_errorMonitor->VerifyFound(); |
| 1908 | |
| 1909 | // Next, call with a non-NULL pSurfaceFormats, even though we haven't |
| 1910 | // correctly done a 1st try (to get the count): |
| 1911 | m_errorMonitor->SetDesiredFailureMsg( |
| 1912 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 1913 | "but no prior positive value has been seen for"); |
| 1914 | surface_format_count = 0; |
| 1915 | vkGetPhysicalDeviceSurfaceFormatsKHR( |
Mark Lobodzinski | 085d27a | 2016-05-17 09:34:26 -0600 | [diff] [blame] | 1916 | gpu(), surface, &surface_format_count, |
| 1917 | (VkSurfaceFormatKHR *)&surface_format_count); |
Ian Elliott | 2c1daf5 | 2016-05-12 09:41:46 -0600 | [diff] [blame] | 1918 | pass = (err == VK_SUCCESS); |
| 1919 | ASSERT_TRUE(pass); |
| 1920 | m_errorMonitor->VerifyFound(); |
| 1921 | |
| 1922 | // Next, correctly do a 1st try (with a NULL pointer to surface_formats): |
Mark Lobodzinski | 085d27a | 2016-05-17 09:34:26 -0600 | [diff] [blame] | 1923 | vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &surface_format_count, |
| 1924 | NULL); |
Ian Elliott | 2c1daf5 | 2016-05-12 09:41:46 -0600 | [diff] [blame] | 1925 | pass = (err == VK_SUCCESS); |
| 1926 | ASSERT_TRUE(pass); |
| 1927 | |
| 1928 | // Allocate memory for the correct number of VkSurfaceFormatKHR's: |
Mark Lobodzinski | 085d27a | 2016-05-17 09:34:26 -0600 | [diff] [blame] | 1929 | VkSurfaceFormatKHR *surface_formats = (VkSurfaceFormatKHR *)malloc( |
| 1930 | surface_format_count * sizeof(VkSurfaceFormatKHR)); |
Ian Elliott | 2c1daf5 | 2016-05-12 09:41:46 -0600 | [diff] [blame] | 1931 | |
| 1932 | // Next, do a 2nd try with surface_format_count being set too high: |
| 1933 | surface_format_count += 5; |
Mark Lobodzinski | 085d27a | 2016-05-17 09:34:26 -0600 | [diff] [blame] | 1934 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 1935 | "that is greater than the value"); |
| 1936 | vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &surface_format_count, |
Ian Elliott | 2c1daf5 | 2016-05-12 09:41:46 -0600 | [diff] [blame] | 1937 | surface_formats); |
| 1938 | pass = (err == VK_SUCCESS); |
| 1939 | ASSERT_TRUE(pass); |
| 1940 | m_errorMonitor->VerifyFound(); |
| 1941 | |
| 1942 | // Finally, do a correct 1st and 2nd try: |
Mark Lobodzinski | 085d27a | 2016-05-17 09:34:26 -0600 | [diff] [blame] | 1943 | vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &surface_format_count, |
| 1944 | NULL); |
Ian Elliott | 2c1daf5 | 2016-05-12 09:41:46 -0600 | [diff] [blame] | 1945 | pass = (err == VK_SUCCESS); |
| 1946 | ASSERT_TRUE(pass); |
Mark Lobodzinski | 085d27a | 2016-05-17 09:34:26 -0600 | [diff] [blame] | 1947 | vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &surface_format_count, |
Ian Elliott | 2c1daf5 | 2016-05-12 09:41:46 -0600 | [diff] [blame] | 1948 | surface_formats); |
| 1949 | pass = (err == VK_SUCCESS); |
| 1950 | ASSERT_TRUE(pass); |
| 1951 | |
Ian Elliott | 2c1daf5 | 2016-05-12 09:41:46 -0600 | [diff] [blame] | 1952 | // Get the surface present modes: |
| 1953 | uint32_t surface_present_mode_count; |
| 1954 | |
| 1955 | // First, try without a pointer to surface_format_count: |
Mark Lobodzinski | 085d27a | 2016-05-17 09:34:26 -0600 | [diff] [blame] | 1956 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 1957 | "called with NULL pointer"); |
Ian Elliott | 2c1daf5 | 2016-05-12 09:41:46 -0600 | [diff] [blame] | 1958 | vkGetPhysicalDeviceSurfacePresentModesKHR(gpu(), surface, NULL, NULL); |
| 1959 | pass = (err == VK_SUCCESS); |
| 1960 | ASSERT_TRUE(pass); |
| 1961 | m_errorMonitor->VerifyFound(); |
| 1962 | |
| 1963 | // Next, call with a non-NULL VkPresentModeKHR, even though we haven't |
| 1964 | // correctly done a 1st try (to get the count): |
| 1965 | m_errorMonitor->SetDesiredFailureMsg( |
| 1966 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 1967 | "but no prior positive value has been seen for"); |
| 1968 | surface_present_mode_count = 0; |
| 1969 | vkGetPhysicalDeviceSurfacePresentModesKHR( |
Mark Lobodzinski | 085d27a | 2016-05-17 09:34:26 -0600 | [diff] [blame] | 1970 | gpu(), surface, &surface_present_mode_count, |
| 1971 | (VkPresentModeKHR *)&surface_present_mode_count); |
Ian Elliott | 2c1daf5 | 2016-05-12 09:41:46 -0600 | [diff] [blame] | 1972 | pass = (err == VK_SUCCESS); |
| 1973 | ASSERT_TRUE(pass); |
| 1974 | m_errorMonitor->VerifyFound(); |
| 1975 | |
| 1976 | // Next, correctly do a 1st try (with a NULL pointer to surface_formats): |
Mark Lobodzinski | 085d27a | 2016-05-17 09:34:26 -0600 | [diff] [blame] | 1977 | vkGetPhysicalDeviceSurfacePresentModesKHR( |
| 1978 | gpu(), surface, &surface_present_mode_count, NULL); |
Ian Elliott | 2c1daf5 | 2016-05-12 09:41:46 -0600 | [diff] [blame] | 1979 | pass = (err == VK_SUCCESS); |
| 1980 | ASSERT_TRUE(pass); |
| 1981 | |
| 1982 | // Allocate memory for the correct number of VkSurfaceFormatKHR's: |
Mark Lobodzinski | 085d27a | 2016-05-17 09:34:26 -0600 | [diff] [blame] | 1983 | VkPresentModeKHR *surface_present_modes = (VkPresentModeKHR *)malloc( |
| 1984 | surface_present_mode_count * sizeof(VkPresentModeKHR)); |
Ian Elliott | 2c1daf5 | 2016-05-12 09:41:46 -0600 | [diff] [blame] | 1985 | |
| 1986 | // Next, do a 2nd try with surface_format_count being set too high: |
| 1987 | surface_present_mode_count += 5; |
Mark Lobodzinski | 085d27a | 2016-05-17 09:34:26 -0600 | [diff] [blame] | 1988 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 1989 | "that is greater than the value"); |
| 1990 | vkGetPhysicalDeviceSurfacePresentModesKHR( |
| 1991 | gpu(), surface, &surface_present_mode_count, surface_present_modes); |
Ian Elliott | 2c1daf5 | 2016-05-12 09:41:46 -0600 | [diff] [blame] | 1992 | pass = (err == VK_SUCCESS); |
| 1993 | ASSERT_TRUE(pass); |
| 1994 | m_errorMonitor->VerifyFound(); |
| 1995 | |
| 1996 | // Finally, do a correct 1st and 2nd try: |
Mark Lobodzinski | 085d27a | 2016-05-17 09:34:26 -0600 | [diff] [blame] | 1997 | vkGetPhysicalDeviceSurfacePresentModesKHR( |
| 1998 | gpu(), surface, &surface_present_mode_count, NULL); |
Ian Elliott | 2c1daf5 | 2016-05-12 09:41:46 -0600 | [diff] [blame] | 1999 | pass = (err == VK_SUCCESS); |
| 2000 | ASSERT_TRUE(pass); |
Mark Lobodzinski | 085d27a | 2016-05-17 09:34:26 -0600 | [diff] [blame] | 2001 | vkGetPhysicalDeviceSurfacePresentModesKHR( |
| 2002 | gpu(), surface, &surface_present_mode_count, surface_present_modes); |
Ian Elliott | 2c1daf5 | 2016-05-12 09:41:46 -0600 | [diff] [blame] | 2003 | pass = (err == VK_SUCCESS); |
| 2004 | ASSERT_TRUE(pass); |
| 2005 | |
Ian Elliott | 2c1daf5 | 2016-05-12 09:41:46 -0600 | [diff] [blame] | 2006 | // Create a swapchain: |
| 2007 | |
| 2008 | // First, try without a pointer to swapchain_create_info: |
Mark Lobodzinski | 085d27a | 2016-05-17 09:34:26 -0600 | [diff] [blame] | 2009 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 2010 | "called with NULL pointer"); |
Ian Elliott | 2c1daf5 | 2016-05-12 09:41:46 -0600 | [diff] [blame] | 2011 | err = vkCreateSwapchainKHR(m_device->device(), NULL, NULL, &swapchain); |
| 2012 | pass = (err != VK_SUCCESS); |
| 2013 | ASSERT_TRUE(pass); |
| 2014 | m_errorMonitor->VerifyFound(); |
| 2015 | |
| 2016 | // Next, call with a non-NULL swapchain_create_info, that has the wrong |
| 2017 | // sType: |
| 2018 | swapchain_create_info.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO; |
Mark Lobodzinski | 085d27a | 2016-05-17 09:34:26 -0600 | [diff] [blame] | 2019 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 2020 | "called with the wrong value for"); |
| 2021 | err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, |
| 2022 | &swapchain); |
Ian Elliott | 2c1daf5 | 2016-05-12 09:41:46 -0600 | [diff] [blame] | 2023 | pass = (err != VK_SUCCESS); |
| 2024 | ASSERT_TRUE(pass); |
| 2025 | m_errorMonitor->VerifyFound(); |
| 2026 | |
| 2027 | // Next, call with a NULL swapchain pointer: |
| 2028 | swapchain_create_info.sType = VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR; |
| 2029 | swapchain_create_info.pNext = NULL; |
| 2030 | swapchain_create_info.flags = 0; |
Mark Lobodzinski | 085d27a | 2016-05-17 09:34:26 -0600 | [diff] [blame] | 2031 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 2032 | "called with NULL pointer"); |
| 2033 | err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, |
| 2034 | NULL); |
Ian Elliott | 2c1daf5 | 2016-05-12 09:41:46 -0600 | [diff] [blame] | 2035 | pass = (err != VK_SUCCESS); |
| 2036 | ASSERT_TRUE(pass); |
| 2037 | m_errorMonitor->VerifyFound(); |
| 2038 | |
Mark Lobodzinski | 085d27a | 2016-05-17 09:34:26 -0600 | [diff] [blame] | 2039 | // TODO: Enhance swapchain layer so that |
| 2040 | // swapchain_create_info.queueFamilyIndexCount is checked against something? |
Ian Elliott | 2c1daf5 | 2016-05-12 09:41:46 -0600 | [diff] [blame] | 2041 | |
| 2042 | // Next, call with a queue family index that's too large: |
| 2043 | uint32_t queueFamilyIndex[2] = {100000, 0}; |
| 2044 | swapchain_create_info.imageSharingMode = VK_SHARING_MODE_CONCURRENT; |
| 2045 | swapchain_create_info.queueFamilyIndexCount = 2; |
| 2046 | swapchain_create_info.pQueueFamilyIndices = queueFamilyIndex; |
| 2047 | m_errorMonitor->SetDesiredFailureMsg( |
| 2048 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 2049 | "called with a queueFamilyIndex that is too large"); |
Mark Lobodzinski | 085d27a | 2016-05-17 09:34:26 -0600 | [diff] [blame] | 2050 | err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, |
| 2051 | &swapchain); |
Ian Elliott | 2c1daf5 | 2016-05-12 09:41:46 -0600 | [diff] [blame] | 2052 | pass = (err != VK_SUCCESS); |
| 2053 | ASSERT_TRUE(pass); |
| 2054 | m_errorMonitor->VerifyFound(); |
| 2055 | |
| 2056 | // Next, call a queueFamilyIndexCount that's too small for CONCURRENT: |
| 2057 | swapchain_create_info.imageSharingMode = VK_SHARING_MODE_CONCURRENT; |
| 2058 | swapchain_create_info.queueFamilyIndexCount = 1; |
| 2059 | m_errorMonitor->SetDesiredFailureMsg( |
| 2060 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 2061 | "but with a bad value(s) for pCreateInfo->queueFamilyIndexCount or " |
| 2062 | "pCreateInfo->pQueueFamilyIndices)."); |
Mark Lobodzinski | 085d27a | 2016-05-17 09:34:26 -0600 | [diff] [blame] | 2063 | err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, |
| 2064 | &swapchain); |
Ian Elliott | 2c1daf5 | 2016-05-12 09:41:46 -0600 | [diff] [blame] | 2065 | pass = (err != VK_SUCCESS); |
| 2066 | ASSERT_TRUE(pass); |
| 2067 | m_errorMonitor->VerifyFound(); |
| 2068 | |
| 2069 | // Next, call with an invalid imageSharingMode: |
| 2070 | swapchain_create_info.imageSharingMode = VK_SHARING_MODE_MAX_ENUM; |
| 2071 | swapchain_create_info.queueFamilyIndexCount = 1; |
| 2072 | m_errorMonitor->SetDesiredFailureMsg( |
| 2073 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 2074 | "called with a non-supported pCreateInfo->imageSharingMode (i.e."); |
Mark Lobodzinski | 085d27a | 2016-05-17 09:34:26 -0600 | [diff] [blame] | 2075 | err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, |
| 2076 | &swapchain); |
Ian Elliott | 2c1daf5 | 2016-05-12 09:41:46 -0600 | [diff] [blame] | 2077 | pass = (err != VK_SUCCESS); |
| 2078 | ASSERT_TRUE(pass); |
| 2079 | m_errorMonitor->VerifyFound(); |
| 2080 | // Fix for the future: |
Mark Lobodzinski | 085d27a | 2016-05-17 09:34:26 -0600 | [diff] [blame] | 2081 | // FIXME: THIS ISN'T CORRECT--MUST QUERY UNTIL WE FIND A QUEUE FAMILY THAT'S |
| 2082 | // SUPPORTED |
Ian Elliott | 2c1daf5 | 2016-05-12 09:41:46 -0600 | [diff] [blame] | 2083 | swapchain_create_info.queueFamilyIndexCount = 0; |
| 2084 | queueFamilyIndex[0] = 0; |
| 2085 | swapchain_create_info.imageSharingMode = VK_SHARING_MODE_EXCLUSIVE; |
| 2086 | |
Mark Lobodzinski | 085d27a | 2016-05-17 09:34:26 -0600 | [diff] [blame] | 2087 | // TODO: CONTINUE TESTING VALIDATION OF vkCreateSwapchainKHR() ... |
Ian Elliott | 2c1daf5 | 2016-05-12 09:41:46 -0600 | [diff] [blame] | 2088 | // Get the images from a swapchain: |
Ian Elliott | 2c1daf5 | 2016-05-12 09:41:46 -0600 | [diff] [blame] | 2089 | // Acquire an image from a swapchain: |
Ian Elliott | 2c1daf5 | 2016-05-12 09:41:46 -0600 | [diff] [blame] | 2090 | // Present an image to a swapchain: |
Ian Elliott | 2c1daf5 | 2016-05-12 09:41:46 -0600 | [diff] [blame] | 2091 | // Destroy the swapchain: |
| 2092 | |
Mark Lobodzinski | 085d27a | 2016-05-17 09:34:26 -0600 | [diff] [blame] | 2093 | // TODOs: |
| 2094 | // |
| 2095 | // - Try destroying the device without first destroying the swapchain |
| 2096 | // |
| 2097 | // - Try destroying the device without first destroying the surface |
| 2098 | // |
| 2099 | // - Try destroying the surface without first destroying the swapchain |
Ian Elliott | 2c1daf5 | 2016-05-12 09:41:46 -0600 | [diff] [blame] | 2100 | |
| 2101 | // Destroy the surface: |
| 2102 | vkDestroySurfaceKHR(instance(), surface, NULL); |
| 2103 | |
Ian Elliott | 2c1daf5 | 2016-05-12 09:41:46 -0600 | [diff] [blame] | 2104 | // Tear down the window: |
| 2105 | xcb_destroy_window(connection, xcb_window); |
| 2106 | xcb_disconnect(connection); |
| 2107 | |
| 2108 | #else // VK_USE_PLATFORM_XCB_KHR |
Mark Lobodzinski | 085d27a | 2016-05-17 09:34:26 -0600 | [diff] [blame] | 2109 | return; |
Ian Elliott | 2c1daf5 | 2016-05-12 09:41:46 -0600 | [diff] [blame] | 2110 | #endif // VK_USE_PLATFORM_XCB_KHR |
| 2111 | } |
| 2112 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 2113 | TEST_F(VkLayerTest, MapMemWithoutHostVisibleBit) { |
| 2114 | VkResult err; |
| 2115 | bool pass; |
Mark Lobodzinski | 3780e14 | 2015-05-14 15:08:13 -0500 | [diff] [blame] | 2116 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 2117 | m_errorMonitor->SetDesiredFailureMsg( |
| 2118 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 2119 | "Mapping Memory without VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT"); |
| 2120 | |
Mark Lobodzinski | 3780e14 | 2015-05-14 15:08:13 -0500 | [diff] [blame] | 2121 | ASSERT_NO_FATAL_FAILURE(InitState()); |
Mark Lobodzinski | 3780e14 | 2015-05-14 15:08:13 -0500 | [diff] [blame] | 2122 | |
| 2123 | // Create an image, allocate memory, free it, and then try to bind it |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 2124 | VkImage image; |
| 2125 | VkDeviceMemory mem; |
| 2126 | VkMemoryRequirements mem_reqs; |
Mark Lobodzinski | 3780e14 | 2015-05-14 15:08:13 -0500 | [diff] [blame] | 2127 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 2128 | const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM; |
| 2129 | const int32_t tex_width = 32; |
| 2130 | const int32_t tex_height = 32; |
Mark Lobodzinski | 3780e14 | 2015-05-14 15:08:13 -0500 | [diff] [blame] | 2131 | |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 2132 | VkImageCreateInfo image_create_info = {}; |
| 2133 | image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 2134 | image_create_info.pNext = NULL; |
| 2135 | image_create_info.imageType = VK_IMAGE_TYPE_2D; |
| 2136 | image_create_info.format = tex_format; |
| 2137 | image_create_info.extent.width = tex_width; |
| 2138 | image_create_info.extent.height = tex_height; |
| 2139 | image_create_info.extent.depth = 1; |
| 2140 | image_create_info.mipLevels = 1; |
| 2141 | image_create_info.arrayLayers = 1; |
| 2142 | image_create_info.samples = VK_SAMPLE_COUNT_1_BIT; |
| 2143 | image_create_info.tiling = VK_IMAGE_TILING_LINEAR; |
| 2144 | image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT; |
| 2145 | image_create_info.flags = 0; |
Mark Lobodzinski | 5fcc421 | 2015-09-14 17:43:42 -0600 | [diff] [blame] | 2146 | |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 2147 | VkMemoryAllocateInfo mem_alloc = {}; |
Chia-I Wu | 00ce540 | 2015-11-10 16:21:09 +0800 | [diff] [blame] | 2148 | mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 2149 | mem_alloc.pNext = NULL; |
| 2150 | mem_alloc.allocationSize = 0; |
| 2151 | // Introduce failure, do NOT set memProps to |
| 2152 | // VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT |
| 2153 | mem_alloc.memoryTypeIndex = 1; |
Mark Lobodzinski | 3780e14 | 2015-05-14 15:08:13 -0500 | [diff] [blame] | 2154 | |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 2155 | err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image); |
Mark Lobodzinski | 3780e14 | 2015-05-14 15:08:13 -0500 | [diff] [blame] | 2156 | ASSERT_VK_SUCCESS(err); |
| 2157 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 2158 | vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs); |
Mark Lobodzinski | 3780e14 | 2015-05-14 15:08:13 -0500 | [diff] [blame] | 2159 | |
Mark Lobodzinski | 2306535 | 2015-05-29 09:32:35 -0500 | [diff] [blame] | 2160 | mem_alloc.allocationSize = mem_reqs.size; |
Mark Lobodzinski | 3780e14 | 2015-05-14 15:08:13 -0500 | [diff] [blame] | 2161 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 2162 | pass = |
| 2163 | m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0, |
| 2164 | VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT); |
| 2165 | if (!pass) { // If we can't find any unmappable memory this test doesn't |
| 2166 | // make sense |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 2167 | vkDestroyImage(m_device->device(), image, NULL); |
Tony Barbour | 02fdc7d | 2015-08-04 16:13:01 -0600 | [diff] [blame] | 2168 | return; |
Mike Stroyan | d1c84a5 | 2015-08-18 14:40:24 -0600 | [diff] [blame] | 2169 | } |
Mike Stroyan | 713b2d7 | 2015-08-04 10:49:29 -0600 | [diff] [blame] | 2170 | |
Mark Lobodzinski | 3780e14 | 2015-05-14 15:08:13 -0500 | [diff] [blame] | 2171 | // allocate memory |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 2172 | err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem); |
Mark Lobodzinski | 3780e14 | 2015-05-14 15:08:13 -0500 | [diff] [blame] | 2173 | ASSERT_VK_SUCCESS(err); |
| 2174 | |
| 2175 | // Try to bind free memory that has been freed |
Tony Barbour | 67e9915 | 2015-07-10 14:10:27 -0600 | [diff] [blame] | 2176 | err = vkBindImageMemory(m_device->device(), image, mem, 0); |
Mark Lobodzinski | 3780e14 | 2015-05-14 15:08:13 -0500 | [diff] [blame] | 2177 | ASSERT_VK_SUCCESS(err); |
| 2178 | |
| 2179 | // Map memory as if to initialize the image |
| 2180 | void *mappedAddress = NULL; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 2181 | err = vkMapMemory(m_device->device(), mem, 0, VK_WHOLE_SIZE, 0, |
| 2182 | &mappedAddress); |
Mark Lobodzinski | 3780e14 | 2015-05-14 15:08:13 -0500 | [diff] [blame] | 2183 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 2184 | m_errorMonitor->VerifyFound(); |
Mike Stroyan | d1c84a5 | 2015-08-18 14:40:24 -0600 | [diff] [blame] | 2185 | |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 2186 | vkDestroyImage(m_device->device(), image, NULL); |
Tony Barbour | df4c004 | 2016-06-01 15:55:43 -0600 | [diff] [blame] | 2187 | vkFreeMemory(m_device->device(), mem, NULL); |
Mark Lobodzinski | 3780e14 | 2015-05-14 15:08:13 -0500 | [diff] [blame] | 2188 | } |
| 2189 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 2190 | TEST_F(VkLayerTest, RebindMemory) { |
| 2191 | VkResult err; |
| 2192 | bool pass; |
Mark Lobodzinski | 944aab1 | 2015-06-05 13:59:04 -0500 | [diff] [blame] | 2193 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 2194 | m_errorMonitor->SetDesiredFailureMsg( |
| 2195 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 2196 | "which has already been bound to mem object"); |
| 2197 | |
Mark Lobodzinski | 944aab1 | 2015-06-05 13:59:04 -0500 | [diff] [blame] | 2198 | ASSERT_NO_FATAL_FAILURE(InitState()); |
Mark Lobodzinski | 944aab1 | 2015-06-05 13:59:04 -0500 | [diff] [blame] | 2199 | |
| 2200 | // Create an image, allocate memory, free it, and then try to bind it |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 2201 | VkImage image; |
| 2202 | VkDeviceMemory mem1; |
| 2203 | VkDeviceMemory mem2; |
| 2204 | VkMemoryRequirements mem_reqs; |
Mark Lobodzinski | 944aab1 | 2015-06-05 13:59:04 -0500 | [diff] [blame] | 2205 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 2206 | const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM; |
| 2207 | const int32_t tex_width = 32; |
| 2208 | const int32_t tex_height = 32; |
Mark Lobodzinski | 944aab1 | 2015-06-05 13:59:04 -0500 | [diff] [blame] | 2209 | |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 2210 | VkImageCreateInfo image_create_info = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 2211 | image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO; |
| 2212 | image_create_info.pNext = NULL; |
| 2213 | image_create_info.imageType = VK_IMAGE_TYPE_2D; |
| 2214 | image_create_info.format = tex_format; |
| 2215 | image_create_info.extent.width = tex_width; |
| 2216 | image_create_info.extent.height = tex_height; |
| 2217 | image_create_info.extent.depth = 1; |
| 2218 | image_create_info.mipLevels = 1; |
| 2219 | image_create_info.arrayLayers = 1; |
| 2220 | image_create_info.samples = VK_SAMPLE_COUNT_1_BIT; |
| 2221 | image_create_info.tiling = VK_IMAGE_TILING_LINEAR; |
| 2222 | image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT; |
| 2223 | image_create_info.flags = 0; |
Mark Lobodzinski | 944aab1 | 2015-06-05 13:59:04 -0500 | [diff] [blame] | 2224 | |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 2225 | VkMemoryAllocateInfo mem_alloc = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 2226 | mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO; |
| 2227 | mem_alloc.pNext = NULL; |
| 2228 | mem_alloc.allocationSize = 0; |
| 2229 | mem_alloc.memoryTypeIndex = 0; |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 2230 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 2231 | // Introduce failure, do NOT set memProps to |
| 2232 | // VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 2233 | mem_alloc.memoryTypeIndex = 1; |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 2234 | err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image); |
Mark Lobodzinski | 944aab1 | 2015-06-05 13:59:04 -0500 | [diff] [blame] | 2235 | ASSERT_VK_SUCCESS(err); |
| 2236 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 2237 | vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs); |
Mark Lobodzinski | 944aab1 | 2015-06-05 13:59:04 -0500 | [diff] [blame] | 2238 | |
| 2239 | mem_alloc.allocationSize = mem_reqs.size; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 2240 | pass = |
| 2241 | m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0); |
Courtney Goeltzenleuchter | 1d2f0dd | 2015-10-22 11:03:31 -0600 | [diff] [blame] | 2242 | ASSERT_TRUE(pass); |
Mark Lobodzinski | 944aab1 | 2015-06-05 13:59:04 -0500 | [diff] [blame] | 2243 | |
| 2244 | // allocate 2 memory objects |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 2245 | err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem1); |
Mark Lobodzinski | 944aab1 | 2015-06-05 13:59:04 -0500 | [diff] [blame] | 2246 | ASSERT_VK_SUCCESS(err); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 2247 | err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem2); |
Mark Lobodzinski | 944aab1 | 2015-06-05 13:59:04 -0500 | [diff] [blame] | 2248 | ASSERT_VK_SUCCESS(err); |
| 2249 | |
| 2250 | // Bind first memory object to Image object |
Tony Barbour | 67e9915 | 2015-07-10 14:10:27 -0600 | [diff] [blame] | 2251 | err = vkBindImageMemory(m_device->device(), image, mem1, 0); |
Mark Lobodzinski | 944aab1 | 2015-06-05 13:59:04 -0500 | [diff] [blame] | 2252 | ASSERT_VK_SUCCESS(err); |
| 2253 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 2254 | // Introduce validation failure, try to bind a different memory object to |
| 2255 | // the same image object |
Tony Barbour | 67e9915 | 2015-07-10 14:10:27 -0600 | [diff] [blame] | 2256 | err = vkBindImageMemory(m_device->device(), image, mem2, 0); |
Mark Lobodzinski | 944aab1 | 2015-06-05 13:59:04 -0500 | [diff] [blame] | 2257 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 2258 | m_errorMonitor->VerifyFound(); |
Mike Stroyan | d1c84a5 | 2015-08-18 14:40:24 -0600 | [diff] [blame] | 2259 | |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 2260 | vkDestroyImage(m_device->device(), image, NULL); |
| 2261 | vkFreeMemory(m_device->device(), mem1, NULL); |
| 2262 | vkFreeMemory(m_device->device(), mem2, NULL); |
Mark Lobodzinski | 944aab1 | 2015-06-05 13:59:04 -0500 | [diff] [blame] | 2263 | } |
Mark Lobodzinski | 3780e14 | 2015-05-14 15:08:13 -0500 | [diff] [blame] | 2264 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 2265 | TEST_F(VkLayerTest, SubmitSignaledFence) { |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 2266 | vk_testing::Fence testFence; |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 2267 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 2268 | m_errorMonitor->SetDesiredFailureMsg( |
| 2269 | VK_DEBUG_REPORT_ERROR_BIT_EXT, "submitted in SIGNALED state. Fences " |
| 2270 | "must be reset before being submitted"); |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 2271 | |
| 2272 | VkFenceCreateInfo fenceInfo = {}; |
Tony Barbour | 0b4d956 | 2015-04-09 10:48:04 -0600 | [diff] [blame] | 2273 | fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO; |
| 2274 | fenceInfo.pNext = NULL; |
| 2275 | fenceInfo.flags = VK_FENCE_CREATE_SIGNALED_BIT; |
Tony Barbour | 300a608 | 2015-04-07 13:44:53 -0600 | [diff] [blame] | 2276 | |
Tony Barbour | 300a608 | 2015-04-07 13:44:53 -0600 | [diff] [blame] | 2277 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 2278 | ASSERT_NO_FATAL_FAILURE(InitViewport()); |
| 2279 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 2280 | |
Tony Barbour | fe3351b | 2015-07-28 10:17:20 -0600 | [diff] [blame] | 2281 | BeginCommandBuffer(); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 2282 | m_commandBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color, |
| 2283 | m_stencil_clear_color, NULL); |
Tony Barbour | fe3351b | 2015-07-28 10:17:20 -0600 | [diff] [blame] | 2284 | EndCommandBuffer(); |
Tony Barbour | 300a608 | 2015-04-07 13:44:53 -0600 | [diff] [blame] | 2285 | |
| 2286 | testFence.init(*m_device, fenceInfo); |
Mark Lobodzinski | 5fcc421 | 2015-09-14 17:43:42 -0600 | [diff] [blame] | 2287 | |
Courtney Goeltzenleuchter | 806c700 | 2015-10-27 11:22:14 -0600 | [diff] [blame] | 2288 | VkSubmitInfo submit_info; |
Chia-I Wu | f9be13c | 2015-10-26 20:37:06 +0800 | [diff] [blame] | 2289 | submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO; |
| 2290 | submit_info.pNext = NULL; |
Chia-I Wu | d50a7d7 | 2015-10-26 20:48:51 +0800 | [diff] [blame] | 2291 | submit_info.waitSemaphoreCount = 0; |
Courtney Goeltzenleuchter | 806c700 | 2015-10-27 11:22:14 -0600 | [diff] [blame] | 2292 | submit_info.pWaitSemaphores = NULL; |
Jon Ashburn | 7f9716c | 2015-12-30 16:42:50 -0700 | [diff] [blame] | 2293 | submit_info.pWaitDstStageMask = NULL; |
Chia-I Wu | d50a7d7 | 2015-10-26 20:48:51 +0800 | [diff] [blame] | 2294 | submit_info.commandBufferCount = 1; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 2295 | submit_info.pCommandBuffers = &m_commandBuffer->handle(); |
Chia-I Wu | d50a7d7 | 2015-10-26 20:48:51 +0800 | [diff] [blame] | 2296 | submit_info.signalSemaphoreCount = 0; |
Courtney Goeltzenleuchter | 806c700 | 2015-10-27 11:22:14 -0600 | [diff] [blame] | 2297 | submit_info.pSignalSemaphores = NULL; |
Courtney Goeltzenleuchter | 646b907 | 2015-10-20 18:04:07 -0600 | [diff] [blame] | 2298 | |
| 2299 | vkQueueSubmit(m_device->m_queue, 1, &submit_info, testFence.handle()); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 2300 | vkQueueWaitIdle(m_device->m_queue); |
Mark Lobodzinski | 5fcc421 | 2015-09-14 17:43:42 -0600 | [diff] [blame] | 2301 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 2302 | m_errorMonitor->VerifyFound(); |
Tony Barbour | 0b4d956 | 2015-04-09 10:48:04 -0600 | [diff] [blame] | 2303 | } |
Tobin Ehlis | aff7ae9 | 2016-04-18 15:45:20 -0600 | [diff] [blame] | 2304 | // This is a positive test. We used to expect error in this case but spec now |
| 2305 | // allows it |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 2306 | TEST_F(VkLayerTest, ResetUnsignaledFence) { |
Tobin Ehlis | aff7ae9 | 2016-04-18 15:45:20 -0600 | [diff] [blame] | 2307 | m_errorMonitor->ExpectSuccess(); |
Tony Barbour | 0b4d956 | 2015-04-09 10:48:04 -0600 | [diff] [blame] | 2308 | vk_testing::Fence testFence; |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 2309 | VkFenceCreateInfo fenceInfo = {}; |
Tony Barbour | 0b4d956 | 2015-04-09 10:48:04 -0600 | [diff] [blame] | 2310 | fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO; |
| 2311 | fenceInfo.pNext = NULL; |
| 2312 | |
Tony Barbour | 0b4d956 | 2015-04-09 10:48:04 -0600 | [diff] [blame] | 2313 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 2314 | testFence.init(*m_device, fenceInfo); |
Chia-I Wu | d9e8e82 | 2015-07-03 11:45:55 +0800 | [diff] [blame] | 2315 | VkFence fences[1] = {testFence.handle()}; |
Tobin Ehlis | aff7ae9 | 2016-04-18 15:45:20 -0600 | [diff] [blame] | 2316 | VkResult result = vkResetFences(m_device->device(), 1, fences); |
| 2317 | ASSERT_VK_SUCCESS(result); |
Tony Barbour | 300a608 | 2015-04-07 13:44:53 -0600 | [diff] [blame] | 2318 | |
Tobin Ehlis | aff7ae9 | 2016-04-18 15:45:20 -0600 | [diff] [blame] | 2319 | m_errorMonitor->VerifyNotFound(); |
Tony Barbour | 300a608 | 2015-04-07 13:44:53 -0600 | [diff] [blame] | 2320 | } |
Tobin Ehlis | 41376e1 | 2015-07-03 08:45:14 -0600 | [diff] [blame] | 2321 | |
Chris Forbes | e70b7d3 | 2016-06-15 15:49:12 +1200 | [diff] [blame] | 2322 | #if 0 |
| 2323 | TEST_F(VkLayerTest, LongFenceChain) |
| 2324 | { |
| 2325 | m_errorMonitor->ExpectSuccess(); |
| 2326 | |
| 2327 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 2328 | VkResult err; |
| 2329 | |
| 2330 | std::vector<VkFence> fences; |
| 2331 | |
| 2332 | const int chainLength = 32768; |
| 2333 | |
| 2334 | for (int i = 0; i < chainLength; i++) { |
| 2335 | VkFenceCreateInfo fci = { VK_STRUCTURE_TYPE_FENCE_CREATE_INFO, nullptr, 0 }; |
| 2336 | VkFence fence; |
| 2337 | err = vkCreateFence(m_device->device(), &fci, nullptr, &fence); |
| 2338 | ASSERT_VK_SUCCESS(err); |
| 2339 | |
| 2340 | fences.push_back(fence); |
| 2341 | |
| 2342 | VkSubmitInfo si = { VK_STRUCTURE_TYPE_SUBMIT_INFO, nullptr, 0, nullptr, nullptr, |
| 2343 | 0, nullptr, 0, nullptr }; |
| 2344 | err = vkQueueSubmit(m_device->m_queue, 1, &si, fence); |
| 2345 | ASSERT_VK_SUCCESS(err); |
| 2346 | |
| 2347 | } |
| 2348 | |
| 2349 | // BOOM, stack overflow. |
| 2350 | vkWaitForFences(m_device->device(), 1, &fences.back(), VK_TRUE, UINT64_MAX); |
| 2351 | |
| 2352 | for (auto fence : fences) |
| 2353 | vkDestroyFence(m_device->device(), fence, nullptr); |
| 2354 | |
| 2355 | m_errorMonitor->VerifyNotFound(); |
| 2356 | } |
| 2357 | #endif |
| 2358 | |
Chris Forbes | 18127d1 | 2016-06-08 16:52:28 +1200 | [diff] [blame] | 2359 | TEST_F(VkLayerTest, CommandBufferSimultaneousUseSync) |
| 2360 | { |
| 2361 | m_errorMonitor->ExpectSuccess(); |
| 2362 | |
| 2363 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 2364 | VkResult err; |
| 2365 | |
| 2366 | // Record (empty!) command buffer that can be submitted multiple times |
| 2367 | // simultaneously. |
| 2368 | VkCommandBufferBeginInfo cbbi = { |
| 2369 | VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO, nullptr, |
| 2370 | VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT, nullptr |
| 2371 | }; |
| 2372 | m_commandBuffer->BeginCommandBuffer(&cbbi); |
| 2373 | m_commandBuffer->EndCommandBuffer(); |
| 2374 | |
| 2375 | VkFenceCreateInfo fci = { VK_STRUCTURE_TYPE_FENCE_CREATE_INFO, nullptr, 0 }; |
| 2376 | VkFence fence; |
| 2377 | err = vkCreateFence(m_device->device(), &fci, nullptr, &fence); |
| 2378 | ASSERT_VK_SUCCESS(err); |
| 2379 | |
| 2380 | VkSemaphoreCreateInfo sci = { VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO, nullptr, 0 }; |
| 2381 | VkSemaphore s1, s2; |
| 2382 | err = vkCreateSemaphore(m_device->device(), &sci, nullptr, &s1); |
| 2383 | ASSERT_VK_SUCCESS(err); |
| 2384 | err = vkCreateSemaphore(m_device->device(), &sci, nullptr, &s2); |
| 2385 | ASSERT_VK_SUCCESS(err); |
| 2386 | |
| 2387 | // Submit CB once signaling s1, with fence so we can roll forward to its retirement. |
| 2388 | VkSubmitInfo si = { VK_STRUCTURE_TYPE_SUBMIT_INFO, nullptr, 0, nullptr, nullptr, |
| 2389 | 1, &m_commandBuffer->handle(), 1, &s1 }; |
| 2390 | err = vkQueueSubmit(m_device->m_queue, 1, &si, fence); |
| 2391 | ASSERT_VK_SUCCESS(err); |
| 2392 | |
| 2393 | // Submit CB again, signaling s2. |
| 2394 | si.pSignalSemaphores = &s2; |
| 2395 | err = vkQueueSubmit(m_device->m_queue, 1, &si, VK_NULL_HANDLE); |
| 2396 | ASSERT_VK_SUCCESS(err); |
| 2397 | |
| 2398 | // Wait for fence. |
| 2399 | err = vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX); |
| 2400 | ASSERT_VK_SUCCESS(err); |
| 2401 | |
| 2402 | // CB is still in flight from second submission, but semaphore s1 is no |
| 2403 | // longer in flight. delete it. |
| 2404 | vkDestroySemaphore(m_device->device(), s1, nullptr); |
| 2405 | |
| 2406 | m_errorMonitor->VerifyNotFound(); |
| 2407 | |
| 2408 | // Force device idle and clean up remaining objects |
| 2409 | vkDeviceWaitIdle(m_device->device()); |
| 2410 | vkDestroySemaphore(m_device->device(), s2, nullptr); |
| 2411 | vkDestroyFence(m_device->device(), fence, nullptr); |
| 2412 | } |
| 2413 | |
Chris Forbes | 4e44c91 | 2016-06-16 10:20:00 +1200 | [diff] [blame] | 2414 | TEST_F(VkLayerTest, FenceCreateSignaledWaitHandling) |
| 2415 | { |
| 2416 | m_errorMonitor->ExpectSuccess(); |
| 2417 | |
| 2418 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 2419 | VkResult err; |
| 2420 | |
| 2421 | // A fence created signaled |
| 2422 | VkFenceCreateInfo fci1 = { VK_STRUCTURE_TYPE_FENCE_CREATE_INFO, nullptr, VK_FENCE_CREATE_SIGNALED_BIT }; |
| 2423 | VkFence f1; |
| 2424 | err = vkCreateFence(m_device->device(), &fci1, nullptr, &f1); |
| 2425 | ASSERT_VK_SUCCESS(err); |
| 2426 | |
| 2427 | // A fence created not |
| 2428 | VkFenceCreateInfo fci2 = { VK_STRUCTURE_TYPE_FENCE_CREATE_INFO, nullptr, 0 }; |
| 2429 | VkFence f2; |
| 2430 | err = vkCreateFence(m_device->device(), &fci2, nullptr, &f2); |
| 2431 | ASSERT_VK_SUCCESS(err); |
| 2432 | |
| 2433 | // Submit the unsignaled fence |
| 2434 | VkSubmitInfo si = { VK_STRUCTURE_TYPE_SUBMIT_INFO, nullptr, 0, nullptr, nullptr, |
| 2435 | 0, nullptr, 0, nullptr }; |
| 2436 | err = vkQueueSubmit(m_device->m_queue, 1, &si, f2); |
| 2437 | |
| 2438 | // Wait on both fences, with signaled first. |
| 2439 | VkFence fences[] = { f1, f2 }; |
| 2440 | vkWaitForFences(m_device->device(), 2, fences, VK_TRUE, UINT64_MAX); |
| 2441 | |
| 2442 | // Should have both retired! |
| 2443 | vkDestroyFence(m_device->device(), f1, nullptr); |
| 2444 | vkDestroyFence(m_device->device(), f2, nullptr); |
| 2445 | |
| 2446 | m_errorMonitor->VerifyNotFound(); |
| 2447 | } |
| 2448 | |
Tobin Ehlis | 41376e1 | 2015-07-03 08:45:14 -0600 | [diff] [blame] | 2449 | TEST_F(VkLayerTest, InvalidUsageBits) |
| 2450 | { |
Tony Barbour | f92621a | 2016-05-02 14:28:12 -0600 | [diff] [blame] | 2451 | TEST_DESCRIPTION( |
Karl Schultz | b5bc11e | 2016-05-04 08:36:08 -0600 | [diff] [blame] | 2452 | "Specify wrong usage for image then create conflicting view of image " |
Tony Barbour | f92621a | 2016-05-02 14:28:12 -0600 | [diff] [blame] | 2453 | "Initialize buffer with wrong usage then perform copy expecting errors " |
| 2454 | "from both the image and the buffer (2 calls)"); |
Courtney Goeltzenleuchter | 7415d5a | 2015-12-09 15:48:16 -0700 | [diff] [blame] | 2455 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 2456 | "Invalid usage flag for image "); |
Tobin Ehlis | 41376e1 | 2015-07-03 08:45:14 -0600 | [diff] [blame] | 2457 | |
| 2458 | ASSERT_NO_FATAL_FAILURE(InitState()); |
Tony Barbour | f92621a | 2016-05-02 14:28:12 -0600 | [diff] [blame] | 2459 | VkImageObj image(m_device); |
| 2460 | // Initialize image with USAGE_INPUT_ATTACHMENT |
Tobin Ehlis | 8b313c0 | 2016-05-25 15:01:52 -0600 | [diff] [blame] | 2461 | image.init(128, 128, VK_FORMAT_D24_UNORM_S8_UINT, |
Karl Schultz | b5bc11e | 2016-05-04 08:36:08 -0600 | [diff] [blame] | 2462 | VK_IMAGE_USAGE_INPUT_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0); |
| 2463 | ASSERT_TRUE(image.initialized()); |
Tobin Ehlis | 41376e1 | 2015-07-03 08:45:14 -0600 | [diff] [blame] | 2464 | |
Tony Barbour | f92621a | 2016-05-02 14:28:12 -0600 | [diff] [blame] | 2465 | VkImageView dsv; |
| 2466 | VkImageViewCreateInfo dsvci = {}; |
| 2467 | dsvci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO; |
| 2468 | dsvci.image = image.handle(); |
| 2469 | dsvci.viewType = VK_IMAGE_VIEW_TYPE_2D; |
| 2470 | dsvci.format = VK_FORMAT_D32_SFLOAT_S8_UINT; |
| 2471 | dsvci.subresourceRange.layerCount = 1; |
| 2472 | dsvci.subresourceRange.baseMipLevel = 0; |
| 2473 | dsvci.subresourceRange.levelCount = 1; |
| 2474 | dsvci.subresourceRange.aspectMask = |
| 2475 | VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT; |
Tobin Ehlis | 41376e1 | 2015-07-03 08:45:14 -0600 | [diff] [blame] | 2476 | |
Tony Barbour | f92621a | 2016-05-02 14:28:12 -0600 | [diff] [blame] | 2477 | // Create a view with depth / stencil aspect for image with different usage |
| 2478 | vkCreateImageView(m_device->device(), &dsvci, NULL, &dsv); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 2479 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 2480 | m_errorMonitor->VerifyFound(); |
Tony Barbour | f92621a | 2016-05-02 14:28:12 -0600 | [diff] [blame] | 2481 | |
| 2482 | // Initialize buffer with TRANSFER_DST usage |
| 2483 | vk_testing::Buffer buffer; |
| 2484 | VkMemoryPropertyFlags reqs = 0; |
| 2485 | buffer.init_as_dst(*m_device, 128 * 128, reqs); |
| 2486 | VkBufferImageCopy region = {}; |
| 2487 | region.bufferRowLength = 128; |
| 2488 | region.bufferImageHeight = 128; |
| 2489 | region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; |
| 2490 | region.imageSubresource.layerCount = 1; |
| 2491 | region.imageExtent.height = 16; |
| 2492 | region.imageExtent.width = 16; |
| 2493 | region.imageExtent.depth = 1; |
| 2494 | |
| 2495 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 2496 | "Invalid usage flag for buffer "); |
| 2497 | // Buffer usage not set to TRANSFER_SRC and image usage not set to |
| 2498 | // TRANSFER_DST |
| 2499 | BeginCommandBuffer(); |
| 2500 | vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), |
| 2501 | image.handle(), VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, |
| 2502 | 1, ®ion); |
| 2503 | m_errorMonitor->VerifyFound(); |
| 2504 | |
| 2505 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 2506 | "Invalid usage flag for image "); |
| 2507 | vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), |
| 2508 | image.handle(), VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, |
| 2509 | 1, ®ion); |
| 2510 | m_errorMonitor->VerifyFound(); |
Tobin Ehlis | 41376e1 | 2015-07-03 08:45:14 -0600 | [diff] [blame] | 2511 | } |
Mark Lobodzinski | 209b529 | 2015-09-17 09:44:05 -0600 | [diff] [blame] | 2512 | #endif // MEM_TRACKER_TESTS |
| 2513 | |
Tobin Ehlis | 4bf96d1 | 2015-06-25 11:58:41 -0600 | [diff] [blame] | 2514 | #if OBJ_TRACKER_TESTS |
Mark Lobodzinski | fc5cc66 | 2016-05-02 17:17:41 -0600 | [diff] [blame] | 2515 | |
| 2516 | TEST_F(VkLayerTest, LeakAnObject) { |
| 2517 | VkResult err; |
| 2518 | |
| 2519 | TEST_DESCRIPTION( |
| 2520 | "Create a fence and destroy its device without first destroying the fence."); |
| 2521 | |
| 2522 | // Note that we have to create a new device since destroying the |
| 2523 | // framework's device causes Teardown() to fail and just calling Teardown |
| 2524 | // will destroy the errorMonitor. |
| 2525 | |
| 2526 | m_errorMonitor->SetDesiredFailureMsg( |
| 2527 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 2528 | "OBJ ERROR : VK_DEBUG_REPORT_OBJECT_TYPE_FENCE_EXT object"); |
| 2529 | |
| 2530 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 2531 | |
| 2532 | const std::vector<VkQueueFamilyProperties> queue_props = |
| 2533 | m_device->queue_props; |
| 2534 | std::vector<VkDeviceQueueCreateInfo> queue_info; |
| 2535 | queue_info.reserve(queue_props.size()); |
| 2536 | std::vector<std::vector<float>> queue_priorities; |
| 2537 | for (uint32_t i = 0; i < (uint32_t)queue_props.size(); i++) { |
| 2538 | VkDeviceQueueCreateInfo qi = {}; |
| 2539 | qi.sType = VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO; |
| 2540 | qi.pNext = NULL; |
| 2541 | qi.queueFamilyIndex = i; |
| 2542 | qi.queueCount = queue_props[i].queueCount; |
| 2543 | queue_priorities.emplace_back(qi.queueCount, 0.0f); |
| 2544 | qi.pQueuePriorities = queue_priorities[i].data(); |
| 2545 | queue_info.push_back(qi); |
| 2546 | } |
| 2547 | |
| 2548 | std::vector<const char *> device_layer_names; |
| 2549 | std::vector<const char *> device_extension_names; |
| 2550 | device_layer_names.push_back("VK_LAYER_GOOGLE_threading"); |
| 2551 | device_layer_names.push_back("VK_LAYER_LUNARG_parameter_validation"); |
| 2552 | device_layer_names.push_back("VK_LAYER_LUNARG_object_tracker"); |
| 2553 | device_layer_names.push_back("VK_LAYER_LUNARG_core_validation"); |
| 2554 | device_layer_names.push_back("VK_LAYER_LUNARG_device_limits"); |
| 2555 | device_layer_names.push_back("VK_LAYER_LUNARG_image"); |
| 2556 | device_layer_names.push_back("VK_LAYER_GOOGLE_unique_objects"); |
| 2557 | |
| 2558 | // The sacrificial device object |
| 2559 | VkDevice testDevice; |
| 2560 | VkDeviceCreateInfo device_create_info = {}; |
| 2561 | auto features = m_device->phy().features(); |
| 2562 | device_create_info.sType = VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO; |
| 2563 | device_create_info.pNext = NULL; |
| 2564 | device_create_info.queueCreateInfoCount = queue_info.size(); |
| 2565 | device_create_info.pQueueCreateInfos = queue_info.data(); |
| 2566 | device_create_info.enabledLayerCount = device_layer_names.size(); |
| 2567 | device_create_info.ppEnabledLayerNames = device_layer_names.data(); |
| 2568 | device_create_info.pEnabledFeatures = &features; |
| 2569 | err = vkCreateDevice(gpu(), &device_create_info, NULL, &testDevice); |
| 2570 | ASSERT_VK_SUCCESS(err); |
| 2571 | |
| 2572 | VkFence fence; |
| 2573 | VkFenceCreateInfo fence_create_info = {}; |
| 2574 | fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO; |
| 2575 | fence_create_info.pNext = NULL; |
| 2576 | fence_create_info.flags = 0; |
| 2577 | err = vkCreateFence(testDevice, &fence_create_info, NULL, &fence); |
| 2578 | ASSERT_VK_SUCCESS(err); |
| 2579 | |
| 2580 | // Induce failure by not calling vkDestroyFence |
| 2581 | vkDestroyDevice(testDevice, NULL); |
| 2582 | m_errorMonitor->VerifyFound(); |
| 2583 | } |
| 2584 | |
| 2585 | TEST_F(VkLayerTest, InvalidCommandPoolConsistency) { |
| 2586 | |
| 2587 | TEST_DESCRIPTION("Allocate command buffers from one command pool and " |
| 2588 | "attempt to delete them from another."); |
| 2589 | |
| 2590 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 2591 | "FreeCommandBuffers is attempting to free Command Buffer"); |
| 2592 | |
| 2593 | VkCommandPool command_pool_one; |
| 2594 | VkCommandPool command_pool_two; |
| 2595 | |
| 2596 | VkCommandPoolCreateInfo pool_create_info{}; |
| 2597 | pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO; |
| 2598 | pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_; |
| 2599 | pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT; |
| 2600 | |
| 2601 | vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, |
| 2602 | &command_pool_one); |
| 2603 | |
| 2604 | vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, |
| 2605 | &command_pool_two); |
| 2606 | |
| 2607 | VkCommandBuffer command_buffer[9]; |
| 2608 | VkCommandBufferAllocateInfo command_buffer_allocate_info{}; |
| 2609 | command_buffer_allocate_info.sType = |
| 2610 | VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO; |
| 2611 | command_buffer_allocate_info.commandPool = command_pool_one; |
| 2612 | command_buffer_allocate_info.commandBufferCount = 9; |
| 2613 | command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY; |
| 2614 | vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, |
| 2615 | command_buffer); |
| 2616 | |
| 2617 | vkFreeCommandBuffers(m_device->device(), command_pool_two, 4, |
| 2618 | &command_buffer[3]); |
| 2619 | |
| 2620 | m_errorMonitor->VerifyFound(); |
| 2621 | |
| 2622 | vkDestroyCommandPool(m_device->device(), command_pool_one, NULL); |
| 2623 | vkDestroyCommandPool(m_device->device(), command_pool_two, NULL); |
| 2624 | } |
| 2625 | |
| 2626 | TEST_F(VkLayerTest, InvalidDescriptorPoolConsistency) { |
| 2627 | VkResult err; |
| 2628 | |
| 2629 | TEST_DESCRIPTION("Allocate descriptor sets from one DS pool and " |
| 2630 | "attempt to delete them from another."); |
| 2631 | |
| 2632 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 2633 | "FreeDescriptorSets is attempting to free descriptorSet"); |
| 2634 | |
| 2635 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 2636 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 2637 | |
| 2638 | VkDescriptorPoolSize ds_type_count = {}; |
| 2639 | ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLER; |
| 2640 | ds_type_count.descriptorCount = 1; |
| 2641 | |
| 2642 | VkDescriptorPoolCreateInfo ds_pool_ci = {}; |
| 2643 | ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO; |
| 2644 | ds_pool_ci.pNext = NULL; |
| 2645 | ds_pool_ci.flags = 0; |
| 2646 | ds_pool_ci.maxSets = 1; |
| 2647 | ds_pool_ci.poolSizeCount = 1; |
| 2648 | ds_pool_ci.pPoolSizes = &ds_type_count; |
| 2649 | |
| 2650 | VkDescriptorPool ds_pool_one; |
| 2651 | err = |
| 2652 | vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool_one); |
| 2653 | ASSERT_VK_SUCCESS(err); |
| 2654 | |
| 2655 | // Create a second descriptor pool |
| 2656 | VkDescriptorPool ds_pool_two; |
| 2657 | err = |
| 2658 | vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool_two); |
| 2659 | ASSERT_VK_SUCCESS(err); |
| 2660 | |
| 2661 | VkDescriptorSetLayoutBinding dsl_binding = {}; |
| 2662 | dsl_binding.binding = 0; |
| 2663 | dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER; |
| 2664 | dsl_binding.descriptorCount = 1; |
| 2665 | dsl_binding.stageFlags = VK_SHADER_STAGE_ALL; |
| 2666 | dsl_binding.pImmutableSamplers = NULL; |
| 2667 | |
| 2668 | VkDescriptorSetLayoutCreateInfo ds_layout_ci = {}; |
| 2669 | ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO; |
| 2670 | ds_layout_ci.pNext = NULL; |
| 2671 | ds_layout_ci.bindingCount = 1; |
| 2672 | ds_layout_ci.pBindings = &dsl_binding; |
| 2673 | |
| 2674 | VkDescriptorSetLayout ds_layout; |
| 2675 | err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, |
| 2676 | &ds_layout); |
| 2677 | ASSERT_VK_SUCCESS(err); |
| 2678 | |
| 2679 | VkDescriptorSet descriptorSet; |
| 2680 | VkDescriptorSetAllocateInfo alloc_info = {}; |
| 2681 | alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO; |
| 2682 | alloc_info.descriptorSetCount = 1; |
| 2683 | alloc_info.descriptorPool = ds_pool_one; |
| 2684 | alloc_info.pSetLayouts = &ds_layout; |
| 2685 | err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, |
| 2686 | &descriptorSet); |
| 2687 | ASSERT_VK_SUCCESS(err); |
| 2688 | |
| 2689 | err = vkFreeDescriptorSets(m_device->device(), ds_pool_two, 1, &descriptorSet); |
| 2690 | |
| 2691 | m_errorMonitor->VerifyFound(); |
| 2692 | |
| 2693 | vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL); |
| 2694 | vkDestroyDescriptorPool(m_device->device(), ds_pool_one, NULL); |
| 2695 | vkDestroyDescriptorPool(m_device->device(), ds_pool_two, NULL); |
| 2696 | } |
| 2697 | |
| 2698 | TEST_F(VkLayerTest, CreateUnknownObject) { |
| 2699 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 2700 | "Invalid VkImage Object "); |
| 2701 | |
| 2702 | TEST_DESCRIPTION( |
| 2703 | "Pass an invalid image object handle into a Vulkan API call."); |
| 2704 | |
| 2705 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 2706 | |
| 2707 | // Pass bogus handle into GetImageMemoryRequirements |
| 2708 | VkMemoryRequirements mem_reqs; |
| 2709 | uint64_t fakeImageHandle = 0xCADECADE; |
| 2710 | VkImage fauxImage = reinterpret_cast<VkImage &>(fakeImageHandle); |
| 2711 | |
| 2712 | vkGetImageMemoryRequirements(m_device->device(), fauxImage, &mem_reqs); |
| 2713 | |
| 2714 | m_errorMonitor->VerifyFound(); |
| 2715 | } |
| 2716 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 2717 | TEST_F(VkLayerTest, PipelineNotBound) { |
| 2718 | VkResult err; |
Tobin Ehlis | c9ac2b6 | 2015-09-11 12:57:55 -0600 | [diff] [blame] | 2719 | |
Mark Lobodzinski | fc5cc66 | 2016-05-02 17:17:41 -0600 | [diff] [blame] | 2720 | TEST_DESCRIPTION( |
| 2721 | "Pass in an invalid pipeline object handle into a Vulkan API call."); |
| 2722 | |
Courtney Goeltzenleuchter | 7415d5a | 2015-12-09 15:48:16 -0700 | [diff] [blame] | 2723 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 2724 | "Invalid VkPipeline Object "); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 2725 | |
Tobin Ehlis | c9ac2b6 | 2015-09-11 12:57:55 -0600 | [diff] [blame] | 2726 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 2727 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
Tobin Ehlis | c9ac2b6 | 2015-09-11 12:57:55 -0600 | [diff] [blame] | 2728 | |
Chia-I Wu | 1b99bb2 | 2015-10-27 19:25:11 +0800 | [diff] [blame] | 2729 | VkDescriptorPoolSize ds_type_count = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 2730 | ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 2731 | ds_type_count.descriptorCount = 1; |
Tobin Ehlis | c9ac2b6 | 2015-09-11 12:57:55 -0600 | [diff] [blame] | 2732 | |
| 2733 | VkDescriptorPoolCreateInfo ds_pool_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 2734 | ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO; |
| 2735 | ds_pool_ci.pNext = NULL; |
| 2736 | ds_pool_ci.maxSets = 1; |
| 2737 | ds_pool_ci.poolSizeCount = 1; |
| 2738 | ds_pool_ci.pPoolSizes = &ds_type_count; |
Tobin Ehlis | c9ac2b6 | 2015-09-11 12:57:55 -0600 | [diff] [blame] | 2739 | |
| 2740 | VkDescriptorPool ds_pool; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 2741 | err = |
| 2742 | vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool); |
Tobin Ehlis | c9ac2b6 | 2015-09-11 12:57:55 -0600 | [diff] [blame] | 2743 | ASSERT_VK_SUCCESS(err); |
| 2744 | |
| 2745 | VkDescriptorSetLayoutBinding dsl_binding = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 2746 | dsl_binding.binding = 0; |
| 2747 | dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 2748 | dsl_binding.descriptorCount = 1; |
| 2749 | dsl_binding.stageFlags = VK_SHADER_STAGE_ALL; |
| 2750 | dsl_binding.pImmutableSamplers = NULL; |
Tobin Ehlis | c9ac2b6 | 2015-09-11 12:57:55 -0600 | [diff] [blame] | 2751 | |
| 2752 | VkDescriptorSetLayoutCreateInfo ds_layout_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 2753 | ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO; |
| 2754 | ds_layout_ci.pNext = NULL; |
| 2755 | ds_layout_ci.bindingCount = 1; |
| 2756 | ds_layout_ci.pBindings = &dsl_binding; |
Tobin Ehlis | c9ac2b6 | 2015-09-11 12:57:55 -0600 | [diff] [blame] | 2757 | |
| 2758 | VkDescriptorSetLayout ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 2759 | err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, |
| 2760 | &ds_layout); |
Tobin Ehlis | c9ac2b6 | 2015-09-11 12:57:55 -0600 | [diff] [blame] | 2761 | ASSERT_VK_SUCCESS(err); |
| 2762 | |
| 2763 | VkDescriptorSet descriptorSet; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 2764 | VkDescriptorSetAllocateInfo alloc_info = {}; |
Chia-I Wu | 00ce540 | 2015-11-10 16:21:09 +0800 | [diff] [blame] | 2765 | alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO; |
Jon Ashburn | f19916e | 2016-01-11 13:12:43 -0700 | [diff] [blame] | 2766 | alloc_info.descriptorSetCount = 1; |
Courtney Goeltzenleuchter | bee18a9 | 2015-10-23 14:21:05 -0600 | [diff] [blame] | 2767 | alloc_info.descriptorPool = ds_pool; |
| 2768 | alloc_info.pSetLayouts = &ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 2769 | err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, |
| 2770 | &descriptorSet); |
Tobin Ehlis | c9ac2b6 | 2015-09-11 12:57:55 -0600 | [diff] [blame] | 2771 | ASSERT_VK_SUCCESS(err); |
| 2772 | |
| 2773 | VkPipelineLayoutCreateInfo pipeline_layout_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 2774 | pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO; |
| 2775 | pipeline_layout_ci.pNext = NULL; |
| 2776 | pipeline_layout_ci.setLayoutCount = 1; |
| 2777 | pipeline_layout_ci.pSetLayouts = &ds_layout; |
Tobin Ehlis | c9ac2b6 | 2015-09-11 12:57:55 -0600 | [diff] [blame] | 2778 | |
| 2779 | VkPipelineLayout pipeline_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 2780 | err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, |
| 2781 | &pipeline_layout); |
Tobin Ehlis | c9ac2b6 | 2015-09-11 12:57:55 -0600 | [diff] [blame] | 2782 | ASSERT_VK_SUCCESS(err); |
| 2783 | |
Mark Young | ad77905 | 2016-01-06 14:26:04 -0700 | [diff] [blame] | 2784 | VkPipeline badPipeline = (VkPipeline)((size_t)0xbaadb1be); |
Tobin Ehlis | c9ac2b6 | 2015-09-11 12:57:55 -0600 | [diff] [blame] | 2785 | |
| 2786 | BeginCommandBuffer(); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 2787 | vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), |
| 2788 | VK_PIPELINE_BIND_POINT_GRAPHICS, badPipeline); |
Tobin Ehlis | c9ac2b6 | 2015-09-11 12:57:55 -0600 | [diff] [blame] | 2789 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 2790 | m_errorMonitor->VerifyFound(); |
Mike Stroyan | d1c84a5 | 2015-08-18 14:40:24 -0600 | [diff] [blame] | 2791 | |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 2792 | vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL); |
| 2793 | vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL); |
| 2794 | vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL); |
Tobin Ehlis | ec59830 | 2015-09-15 15:02:17 -0600 | [diff] [blame] | 2795 | } |
Tobin Ehlis | 93d57e1 | 2016-06-20 11:32:13 -0600 | [diff] [blame] | 2796 | #if 0 // Disabling this test for now, needs to be updated |
Mark Lobodzinski | bc18576 | 2016-06-15 16:28:53 -0600 | [diff] [blame] | 2797 | TEST_F(VkLayerTest, BindImageInvalidMemoryType) { |
| 2798 | VkResult err; |
| 2799 | |
| 2800 | TEST_DESCRIPTION("Test validation check for an invalid memory type index " |
| 2801 | "during bind[Buffer|Image]Memory time"); |
| 2802 | |
| 2803 | m_errorMonitor->SetDesiredFailureMsg( |
| 2804 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 2805 | "for this object type are not compatible with the memory"); |
| 2806 | |
| 2807 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 2808 | |
| 2809 | // Create an image, allocate memory, set a bad typeIndex and then try to |
| 2810 | // bind it |
| 2811 | VkImage image; |
| 2812 | VkDeviceMemory mem; |
| 2813 | VkMemoryRequirements mem_reqs; |
| 2814 | const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM; |
| 2815 | const int32_t tex_width = 32; |
| 2816 | const int32_t tex_height = 32; |
| 2817 | |
| 2818 | VkImageCreateInfo image_create_info = {}; |
| 2819 | image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO; |
| 2820 | image_create_info.pNext = NULL; |
| 2821 | image_create_info.imageType = VK_IMAGE_TYPE_2D; |
| 2822 | image_create_info.format = tex_format; |
| 2823 | image_create_info.extent.width = tex_width; |
| 2824 | image_create_info.extent.height = tex_height; |
| 2825 | image_create_info.extent.depth = 1; |
| 2826 | image_create_info.mipLevels = 1; |
| 2827 | image_create_info.arrayLayers = 1; |
| 2828 | image_create_info.samples = VK_SAMPLE_COUNT_1_BIT; |
| 2829 | image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL; |
| 2830 | image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT; |
| 2831 | image_create_info.flags = 0; |
| 2832 | |
| 2833 | VkMemoryAllocateInfo mem_alloc = {}; |
| 2834 | mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO; |
| 2835 | mem_alloc.pNext = NULL; |
| 2836 | mem_alloc.allocationSize = 0; |
| 2837 | mem_alloc.memoryTypeIndex = 0; |
| 2838 | |
| 2839 | err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image); |
| 2840 | ASSERT_VK_SUCCESS(err); |
| 2841 | |
| 2842 | vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs); |
| 2843 | mem_alloc.allocationSize = mem_reqs.size; |
Tobin Ehlis | 93d57e1 | 2016-06-20 11:32:13 -0600 | [diff] [blame] | 2844 | // TODO : This is not an ideal way to cause the error and triggers a segF |
| 2845 | // on at least one android driver when attempting to Allocate the memory. |
| 2846 | // That segF may or may not be a driver bug, but really what we want to do |
| 2847 | // here is find a device-supported memory type that is also not supported |
| 2848 | // for the particular image we're binding the memory too. If no such |
| 2849 | // type exists, then we can print a message and skip the test. |
Mark Lobodzinski | bc18576 | 2016-06-15 16:28:53 -0600 | [diff] [blame] | 2850 | // Introduce Failure, select likely invalid TypeIndex |
| 2851 | mem_alloc.memoryTypeIndex = 31; |
| 2852 | |
| 2853 | err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem); |
| 2854 | ASSERT_VK_SUCCESS(err); |
| 2855 | |
| 2856 | err = vkBindImageMemory(m_device->device(), image, mem, 0); |
| 2857 | (void)err; |
| 2858 | |
| 2859 | m_errorMonitor->VerifyFound(); |
| 2860 | |
| 2861 | vkDestroyImage(m_device->device(), image, NULL); |
| 2862 | vkFreeMemory(m_device->device(), mem, NULL); |
| 2863 | } |
Tobin Ehlis | 93d57e1 | 2016-06-20 11:32:13 -0600 | [diff] [blame] | 2864 | #endif |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 2865 | TEST_F(VkLayerTest, BindInvalidMemory) { |
| 2866 | VkResult err; |
| 2867 | bool pass; |
Tobin Ehlis | ec59830 | 2015-09-15 15:02:17 -0600 | [diff] [blame] | 2868 | |
Courtney Goeltzenleuchter | 7415d5a | 2015-12-09 15:48:16 -0700 | [diff] [blame] | 2869 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 2870 | "Invalid VkDeviceMemory Object "); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 2871 | |
Tobin Ehlis | ec59830 | 2015-09-15 15:02:17 -0600 | [diff] [blame] | 2872 | ASSERT_NO_FATAL_FAILURE(InitState()); |
Tobin Ehlis | ec59830 | 2015-09-15 15:02:17 -0600 | [diff] [blame] | 2873 | |
| 2874 | // Create an image, allocate memory, free it, and then try to bind it |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 2875 | VkImage image; |
| 2876 | VkDeviceMemory mem; |
| 2877 | VkMemoryRequirements mem_reqs; |
Tobin Ehlis | ec59830 | 2015-09-15 15:02:17 -0600 | [diff] [blame] | 2878 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 2879 | const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM; |
| 2880 | const int32_t tex_width = 32; |
| 2881 | const int32_t tex_height = 32; |
Tobin Ehlis | ec59830 | 2015-09-15 15:02:17 -0600 | [diff] [blame] | 2882 | |
| 2883 | VkImageCreateInfo image_create_info = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 2884 | image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO; |
| 2885 | image_create_info.pNext = NULL; |
| 2886 | image_create_info.imageType = VK_IMAGE_TYPE_2D; |
| 2887 | image_create_info.format = tex_format; |
| 2888 | image_create_info.extent.width = tex_width; |
| 2889 | image_create_info.extent.height = tex_height; |
| 2890 | image_create_info.extent.depth = 1; |
| 2891 | image_create_info.mipLevels = 1; |
| 2892 | image_create_info.arrayLayers = 1; |
| 2893 | image_create_info.samples = VK_SAMPLE_COUNT_1_BIT; |
| 2894 | image_create_info.tiling = VK_IMAGE_TILING_LINEAR; |
| 2895 | image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT; |
| 2896 | image_create_info.flags = 0; |
Tobin Ehlis | ec59830 | 2015-09-15 15:02:17 -0600 | [diff] [blame] | 2897 | |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 2898 | VkMemoryAllocateInfo mem_alloc = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 2899 | mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO; |
| 2900 | mem_alloc.pNext = NULL; |
| 2901 | mem_alloc.allocationSize = 0; |
| 2902 | mem_alloc.memoryTypeIndex = 0; |
Tobin Ehlis | ec59830 | 2015-09-15 15:02:17 -0600 | [diff] [blame] | 2903 | |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 2904 | err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image); |
Tobin Ehlis | ec59830 | 2015-09-15 15:02:17 -0600 | [diff] [blame] | 2905 | ASSERT_VK_SUCCESS(err); |
| 2906 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 2907 | vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs); |
Tobin Ehlis | ec59830 | 2015-09-15 15:02:17 -0600 | [diff] [blame] | 2908 | |
| 2909 | mem_alloc.allocationSize = mem_reqs.size; |
| 2910 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 2911 | pass = |
| 2912 | m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0); |
Courtney Goeltzenleuchter | 1d2f0dd | 2015-10-22 11:03:31 -0600 | [diff] [blame] | 2913 | ASSERT_TRUE(pass); |
Tobin Ehlis | ec59830 | 2015-09-15 15:02:17 -0600 | [diff] [blame] | 2914 | |
| 2915 | // allocate memory |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 2916 | err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem); |
Tobin Ehlis | ec59830 | 2015-09-15 15:02:17 -0600 | [diff] [blame] | 2917 | ASSERT_VK_SUCCESS(err); |
| 2918 | |
| 2919 | // Introduce validation failure, free memory before binding |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 2920 | vkFreeMemory(m_device->device(), mem, NULL); |
Tobin Ehlis | ec59830 | 2015-09-15 15:02:17 -0600 | [diff] [blame] | 2921 | |
| 2922 | // Try to bind free memory that has been freed |
| 2923 | err = vkBindImageMemory(m_device->device(), image, mem, 0); |
| 2924 | // This may very well return an error. |
| 2925 | (void)err; |
| 2926 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 2927 | m_errorMonitor->VerifyFound(); |
Mike Stroyan | d1c84a5 | 2015-08-18 14:40:24 -0600 | [diff] [blame] | 2928 | |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 2929 | vkDestroyImage(m_device->device(), image, NULL); |
Tobin Ehlis | ec59830 | 2015-09-15 15:02:17 -0600 | [diff] [blame] | 2930 | } |
| 2931 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 2932 | TEST_F(VkLayerTest, BindMemoryToDestroyedObject) { |
| 2933 | VkResult err; |
| 2934 | bool pass; |
Tobin Ehlis | ec59830 | 2015-09-15 15:02:17 -0600 | [diff] [blame] | 2935 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 2936 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 2937 | "Invalid VkImage Object "); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 2938 | |
Tobin Ehlis | ec59830 | 2015-09-15 15:02:17 -0600 | [diff] [blame] | 2939 | ASSERT_NO_FATAL_FAILURE(InitState()); |
Tobin Ehlis | ec59830 | 2015-09-15 15:02:17 -0600 | [diff] [blame] | 2940 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 2941 | // Create an image object, allocate memory, destroy the object and then try |
| 2942 | // to bind it |
| 2943 | VkImage image; |
| 2944 | VkDeviceMemory mem; |
| 2945 | VkMemoryRequirements mem_reqs; |
Tobin Ehlis | ec59830 | 2015-09-15 15:02:17 -0600 | [diff] [blame] | 2946 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 2947 | const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM; |
| 2948 | const int32_t tex_width = 32; |
| 2949 | const int32_t tex_height = 32; |
Tobin Ehlis | ec59830 | 2015-09-15 15:02:17 -0600 | [diff] [blame] | 2950 | |
| 2951 | VkImageCreateInfo image_create_info = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 2952 | image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO; |
| 2953 | image_create_info.pNext = NULL; |
| 2954 | image_create_info.imageType = VK_IMAGE_TYPE_2D; |
| 2955 | image_create_info.format = tex_format; |
| 2956 | image_create_info.extent.width = tex_width; |
| 2957 | image_create_info.extent.height = tex_height; |
| 2958 | image_create_info.extent.depth = 1; |
| 2959 | image_create_info.mipLevels = 1; |
| 2960 | image_create_info.arrayLayers = 1; |
| 2961 | image_create_info.samples = VK_SAMPLE_COUNT_1_BIT; |
| 2962 | image_create_info.tiling = VK_IMAGE_TILING_LINEAR; |
| 2963 | image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT; |
| 2964 | image_create_info.flags = 0; |
Tobin Ehlis | ec59830 | 2015-09-15 15:02:17 -0600 | [diff] [blame] | 2965 | |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 2966 | VkMemoryAllocateInfo mem_alloc = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 2967 | mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO; |
| 2968 | mem_alloc.pNext = NULL; |
| 2969 | mem_alloc.allocationSize = 0; |
| 2970 | mem_alloc.memoryTypeIndex = 0; |
Tobin Ehlis | ec59830 | 2015-09-15 15:02:17 -0600 | [diff] [blame] | 2971 | |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 2972 | err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image); |
Tobin Ehlis | ec59830 | 2015-09-15 15:02:17 -0600 | [diff] [blame] | 2973 | ASSERT_VK_SUCCESS(err); |
| 2974 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 2975 | vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs); |
Tobin Ehlis | ec59830 | 2015-09-15 15:02:17 -0600 | [diff] [blame] | 2976 | |
| 2977 | mem_alloc.allocationSize = mem_reqs.size; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 2978 | pass = |
| 2979 | m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0); |
Courtney Goeltzenleuchter | 1d2f0dd | 2015-10-22 11:03:31 -0600 | [diff] [blame] | 2980 | ASSERT_TRUE(pass); |
Tobin Ehlis | ec59830 | 2015-09-15 15:02:17 -0600 | [diff] [blame] | 2981 | |
| 2982 | // Allocate memory |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 2983 | err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem); |
Tobin Ehlis | ec59830 | 2015-09-15 15:02:17 -0600 | [diff] [blame] | 2984 | ASSERT_VK_SUCCESS(err); |
| 2985 | |
| 2986 | // Introduce validation failure, destroy Image object before binding |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 2987 | vkDestroyImage(m_device->device(), image, NULL); |
Tobin Ehlis | ec59830 | 2015-09-15 15:02:17 -0600 | [diff] [blame] | 2988 | ASSERT_VK_SUCCESS(err); |
| 2989 | |
| 2990 | // Now Try to bind memory to this destroyed object |
| 2991 | err = vkBindImageMemory(m_device->device(), image, mem, 0); |
| 2992 | // This may very well return an error. |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 2993 | (void)err; |
Tobin Ehlis | ec59830 | 2015-09-15 15:02:17 -0600 | [diff] [blame] | 2994 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 2995 | m_errorMonitor->VerifyFound(); |
Mike Stroyan | d1c84a5 | 2015-08-18 14:40:24 -0600 | [diff] [blame] | 2996 | |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 2997 | vkFreeMemory(m_device->device(), mem, NULL); |
Tobin Ehlis | c9ac2b6 | 2015-09-11 12:57:55 -0600 | [diff] [blame] | 2998 | } |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 2999 | |
Mark Lobodzinski | 209b529 | 2015-09-17 09:44:05 -0600 | [diff] [blame] | 3000 | #endif // OBJ_TRACKER_TESTS |
| 3001 | |
Tobin Ehlis | 0788f52 | 2015-05-26 16:11:58 -0600 | [diff] [blame] | 3002 | #if DRAW_STATE_TESTS |
Mark Lobodzinski | c808d44 | 2016-04-14 10:57:23 -0600 | [diff] [blame] | 3003 | |
Mark Lobodzinski | ce7eee7 | 2016-06-14 16:33:29 -0600 | [diff] [blame] | 3004 | // This is a positive test. No errors are expected. |
| 3005 | TEST_F(VkLayerTest, StencilLoadOp) { |
| 3006 | TEST_DESCRIPTION("Create a stencil-only attachment with a LOAD_OP set to " |
| 3007 | "CLEAR. stencil[Load|Store]Op used to be ignored."); |
| 3008 | VkResult result = VK_SUCCESS; |
| 3009 | VkImageFormatProperties formatProps; |
| 3010 | vkGetPhysicalDeviceImageFormatProperties( |
| 3011 | gpu(), VK_FORMAT_D24_UNORM_S8_UINT, VK_IMAGE_TYPE_2D, |
| 3012 | VK_IMAGE_TILING_OPTIMAL, VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT | |
| 3013 | VK_IMAGE_USAGE_TRANSFER_SRC_BIT, |
| 3014 | 0, &formatProps); |
| 3015 | if (formatProps.maxExtent.width < 100 || formatProps.maxExtent.height < 100) { |
| 3016 | return; |
| 3017 | } |
| 3018 | |
| 3019 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 3020 | VkFormat depth_stencil_fmt = VK_FORMAT_D24_UNORM_S8_UINT; |
| 3021 | m_depthStencil->Init(m_device, 100, 100, depth_stencil_fmt, |
| 3022 | VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT | |
| 3023 | VK_IMAGE_USAGE_TRANSFER_SRC_BIT); |
| 3024 | VkAttachmentDescription att = {}; |
| 3025 | VkAttachmentReference ref = {}; |
| 3026 | att.format = depth_stencil_fmt; |
| 3027 | att.loadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE; |
| 3028 | att.storeOp = VK_ATTACHMENT_STORE_OP_DONT_CARE; |
| 3029 | att.stencilLoadOp = VK_ATTACHMENT_LOAD_OP_CLEAR; |
| 3030 | att.stencilStoreOp = VK_ATTACHMENT_STORE_OP_STORE; |
| 3031 | att.initialLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL; |
| 3032 | att.finalLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL; |
| 3033 | |
| 3034 | VkClearValue clear; |
| 3035 | clear.depthStencil.depth = 1.0; |
| 3036 | clear.depthStencil.stencil = 0; |
| 3037 | ref.attachment = 0; |
| 3038 | ref.layout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL; |
| 3039 | |
| 3040 | VkSubpassDescription subpass = {}; |
| 3041 | subpass.pipelineBindPoint = VK_PIPELINE_BIND_POINT_GRAPHICS; |
| 3042 | subpass.flags = 0; |
| 3043 | subpass.inputAttachmentCount = 0; |
| 3044 | subpass.pInputAttachments = NULL; |
| 3045 | subpass.colorAttachmentCount = 0; |
| 3046 | subpass.pColorAttachments = NULL; |
| 3047 | subpass.pResolveAttachments = NULL; |
| 3048 | subpass.pDepthStencilAttachment = &ref; |
| 3049 | subpass.preserveAttachmentCount = 0; |
| 3050 | subpass.pPreserveAttachments = NULL; |
| 3051 | |
| 3052 | VkRenderPass rp; |
| 3053 | VkRenderPassCreateInfo rp_info = {}; |
| 3054 | rp_info.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO; |
| 3055 | rp_info.attachmentCount = 1; |
| 3056 | rp_info.pAttachments = &att; |
| 3057 | rp_info.subpassCount = 1; |
| 3058 | rp_info.pSubpasses = &subpass; |
| 3059 | result = vkCreateRenderPass(device(), &rp_info, NULL, &rp); |
| 3060 | ASSERT_VK_SUCCESS(result); |
| 3061 | |
| 3062 | VkImageView *depthView = m_depthStencil->BindInfo(); |
| 3063 | VkFramebufferCreateInfo fb_info = {}; |
| 3064 | fb_info.sType = VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO; |
| 3065 | fb_info.pNext = NULL; |
| 3066 | fb_info.renderPass = rp; |
| 3067 | fb_info.attachmentCount = 1; |
| 3068 | fb_info.pAttachments = depthView; |
| 3069 | fb_info.width = 100; |
| 3070 | fb_info.height = 100; |
| 3071 | fb_info.layers = 1; |
| 3072 | VkFramebuffer fb; |
| 3073 | result = vkCreateFramebuffer(device(), &fb_info, NULL, &fb); |
| 3074 | ASSERT_VK_SUCCESS(result); |
| 3075 | |
| 3076 | |
| 3077 | VkRenderPassBeginInfo rpbinfo = {}; |
| 3078 | rpbinfo.clearValueCount = 1; |
| 3079 | rpbinfo.pClearValues = &clear; |
| 3080 | rpbinfo.pNext = NULL; |
| 3081 | rpbinfo.renderPass = rp; |
| 3082 | rpbinfo.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO; |
| 3083 | rpbinfo.renderArea.extent.width = 100; |
| 3084 | rpbinfo.renderArea.extent.height = 100; |
| 3085 | rpbinfo.renderArea.offset.x = 0; |
| 3086 | rpbinfo.renderArea.offset.y = 0; |
| 3087 | rpbinfo.framebuffer = fb; |
| 3088 | |
| 3089 | VkFence fence = {}; |
| 3090 | VkFenceCreateInfo fence_ci = {}; |
| 3091 | fence_ci.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO; |
| 3092 | fence_ci.pNext = nullptr; |
| 3093 | fence_ci.flags = 0; |
| 3094 | result = vkCreateFence(m_device->device(), &fence_ci, nullptr, &fence); |
| 3095 | ASSERT_VK_SUCCESS(result); |
| 3096 | |
| 3097 | |
| 3098 | m_commandBuffer->BeginCommandBuffer(); |
| 3099 | m_commandBuffer->BeginRenderPass(rpbinfo); |
| 3100 | m_commandBuffer->EndRenderPass(); |
| 3101 | m_commandBuffer->EndCommandBuffer(); |
| 3102 | m_commandBuffer->QueueCommandBuffer(fence); |
| 3103 | |
| 3104 | VkImageObj destImage(m_device); |
| 3105 | destImage.init(100, 100, depth_stencil_fmt, |
| 3106 | VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT | |
| 3107 | VK_IMAGE_USAGE_TRANSFER_DST_BIT, |
| 3108 | VK_IMAGE_TILING_OPTIMAL, 0); |
| 3109 | VkImageMemoryBarrier barrier = {}; |
| 3110 | VkImageSubresourceRange range; |
| 3111 | barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER; |
| 3112 | barrier.srcAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT | |
| 3113 | VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT; |
| 3114 | barrier.dstAccessMask = VK_ACCESS_TRANSFER_READ_BIT | |
| 3115 | VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_READ_BIT; |
| 3116 | barrier.oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL; |
| 3117 | barrier.newLayout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL; |
| 3118 | barrier.image = m_depthStencil->handle(); |
| 3119 | range.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT; |
| 3120 | range.baseMipLevel = 0; |
| 3121 | range.levelCount = 1; |
| 3122 | range.baseArrayLayer = 0; |
| 3123 | range.layerCount = 1; |
| 3124 | barrier.subresourceRange = range; |
| 3125 | vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX); |
| 3126 | VkCommandBufferObj cmdbuf(m_device, m_commandPool); |
| 3127 | cmdbuf.BeginCommandBuffer(); |
| 3128 | cmdbuf.PipelineBarrier(VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, |
| 3129 | VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, nullptr, 0, |
| 3130 | nullptr, 1, &barrier); |
| 3131 | barrier.srcAccessMask = 0; |
| 3132 | barrier.oldLayout = VK_IMAGE_LAYOUT_UNDEFINED; |
| 3133 | barrier.newLayout = VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL; |
| 3134 | barrier.image = destImage.handle(); |
| 3135 | barrier.dstAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT | |
| 3136 | VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT; |
| 3137 | cmdbuf.PipelineBarrier(VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, |
| 3138 | VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, nullptr, 0, |
| 3139 | nullptr, 1, &barrier); |
| 3140 | VkImageCopy cregion; |
| 3141 | cregion.srcSubresource.aspectMask = |
| 3142 | VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT; |
| 3143 | cregion.srcSubresource.mipLevel = 0; |
| 3144 | cregion.srcSubresource.baseArrayLayer = 0; |
| 3145 | cregion.srcSubresource.layerCount = 1; |
| 3146 | cregion.srcOffset.x = 0; |
| 3147 | cregion.srcOffset.y = 0; |
| 3148 | cregion.srcOffset.z = 0; |
| 3149 | cregion.dstSubresource.aspectMask = |
| 3150 | VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT; |
| 3151 | cregion.dstSubresource.mipLevel = 0; |
| 3152 | cregion.dstSubresource.baseArrayLayer = 0; |
| 3153 | cregion.dstSubresource.layerCount = 1; |
| 3154 | cregion.dstOffset.x = 0; |
| 3155 | cregion.dstOffset.y = 0; |
| 3156 | cregion.dstOffset.z = 0; |
| 3157 | cregion.extent.width = 100; |
| 3158 | cregion.extent.height = 100; |
| 3159 | cregion.extent.depth = 1; |
| 3160 | cmdbuf.CopyImage(m_depthStencil->handle(), |
| 3161 | VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, destImage.handle(), |
| 3162 | VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &cregion); |
| 3163 | cmdbuf.EndCommandBuffer(); |
| 3164 | |
| 3165 | VkSubmitInfo submit_info; |
| 3166 | submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO; |
| 3167 | submit_info.pNext = NULL; |
| 3168 | submit_info.waitSemaphoreCount = 0; |
| 3169 | submit_info.pWaitSemaphores = NULL; |
| 3170 | submit_info.pWaitDstStageMask = NULL; |
| 3171 | submit_info.commandBufferCount = 1; |
| 3172 | submit_info.pCommandBuffers = &cmdbuf.handle(); |
| 3173 | submit_info.signalSemaphoreCount = 0; |
| 3174 | submit_info.pSignalSemaphores = NULL; |
| 3175 | |
| 3176 | m_errorMonitor->ExpectSuccess(); |
| 3177 | vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE); |
| 3178 | m_errorMonitor->VerifyNotFound(); |
| 3179 | |
Mark Lobodzinski | d0440da | 2016-06-17 15:10:03 -0600 | [diff] [blame] | 3180 | vkQueueWaitIdle(m_device->m_queue); |
Mark Lobodzinski | ce7eee7 | 2016-06-14 16:33:29 -0600 | [diff] [blame] | 3181 | vkDestroyFence(m_device->device(), fence, nullptr); |
| 3182 | vkDestroyRenderPass(m_device->device(), rp, nullptr); |
| 3183 | vkDestroyFramebuffer(m_device->device(), fb, nullptr); |
| 3184 | } |
| 3185 | |
Mark Lobodzinski | 6d17b9f | 2016-06-16 13:21:38 -0600 | [diff] [blame] | 3186 | TEST_F(VkLayerTest, UnusedPreserveAttachment) { |
| 3187 | TEST_DESCRIPTION("Create a framebuffer where a subpass has a preserve " |
| 3188 | "attachment reference of VK_ATTACHMENT_UNUSED"); |
| 3189 | |
| 3190 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 3191 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 3192 | |
| 3193 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 3194 | "must not be VK_ATTACHMENT_UNUSED"); |
| 3195 | |
| 3196 | VkAttachmentReference color_attach = {}; |
| 3197 | color_attach.layout = VK_IMAGE_LAYOUT_GENERAL; |
| 3198 | color_attach.attachment = 0; |
| 3199 | uint32_t preserve_attachment = VK_ATTACHMENT_UNUSED; |
| 3200 | VkSubpassDescription subpass = {}; |
| 3201 | subpass.colorAttachmentCount = 1; |
| 3202 | subpass.pColorAttachments = &color_attach; |
| 3203 | subpass.preserveAttachmentCount = 1; |
| 3204 | subpass.pPreserveAttachments = &preserve_attachment; |
| 3205 | |
| 3206 | VkRenderPassCreateInfo rpci = {}; |
| 3207 | rpci.subpassCount = 1; |
| 3208 | rpci.pSubpasses = &subpass; |
| 3209 | rpci.attachmentCount = 1; |
| 3210 | VkAttachmentDescription attach_desc = {}; |
| 3211 | attach_desc.format = VK_FORMAT_UNDEFINED; |
| 3212 | rpci.pAttachments = &attach_desc; |
| 3213 | rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO; |
| 3214 | VkRenderPass rp; |
Mark Lobodzinski | a4feeeb | 2016-06-17 12:00:46 -0600 | [diff] [blame] | 3215 | VkResult result = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp); |
Mark Lobodzinski | 6d17b9f | 2016-06-16 13:21:38 -0600 | [diff] [blame] | 3216 | |
| 3217 | m_errorMonitor->VerifyFound(); |
| 3218 | |
Mark Lobodzinski | a4feeeb | 2016-06-17 12:00:46 -0600 | [diff] [blame] | 3219 | if (result == VK_SUCCESS) { |
| 3220 | vkDestroyRenderPass(m_device->device(), rp, NULL); |
| 3221 | } |
Mark Lobodzinski | 6d17b9f | 2016-06-16 13:21:38 -0600 | [diff] [blame] | 3222 | } |
| 3223 | |
Tobin Ehlis | 2545e6f | 2016-06-22 10:42:19 -0600 | [diff] [blame] | 3224 | TEST_F(VkLayerTest, FramebufferCreateErrors) { |
| 3225 | TEST_DESCRIPTION("Hit errors when attempting to create a framebuffer :\n" |
| 3226 | " 1. Mismatch between fb & renderPass attachmentCount\n" |
Tobin Ehlis | d3bb23a | 2016-06-22 13:34:46 -0600 | [diff] [blame] | 3227 | " 2. Use a color image as depthStencil attachment\n" |
Tobin Ehlis | 77d717c | 2016-06-22 14:19:19 -0600 | [diff] [blame] | 3228 | " 3. Mismatch fb & renderPass attachment formats\n" |
Tobin Ehlis | 6cfda64 | 2016-06-22 16:12:58 -0600 | [diff] [blame] | 3229 | " 4. Mismatch fb & renderPass attachment #samples\n" |
Tobin Ehlis | 27f2ae8 | 2016-06-23 07:36:57 -0600 | [diff] [blame] | 3230 | " 5. FB attachment w/ non-1 mip-levels\n" |
Tobin Ehlis | b1f303b | 2016-06-23 08:19:55 -0600 | [diff] [blame] | 3231 | " 6. FB attachment where dimensions don't match\n" |
Tobin Ehlis | 08d4b5e | 2016-06-23 08:52:39 -0600 | [diff] [blame] | 3232 | " 7. FB attachment w/o identity swizzle\n" |
| 3233 | " 8. FB dimensions exceed physical device limits\n"); |
Mark Lobodzinski | 6d17b9f | 2016-06-16 13:21:38 -0600 | [diff] [blame] | 3234 | |
| 3235 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 3236 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 3237 | |
| 3238 | m_errorMonitor->SetDesiredFailureMsg( |
| 3239 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Tobin Ehlis | 2545e6f | 2016-06-22 10:42:19 -0600 | [diff] [blame] | 3240 | "vkCreateFramebuffer(): VkFramebufferCreateInfo attachmentCount of 2 " |
| 3241 | "does not match attachmentCount of 1 of "); |
Mark Lobodzinski | 6d17b9f | 2016-06-16 13:21:38 -0600 | [diff] [blame] | 3242 | |
Tobin Ehlis | 2545e6f | 2016-06-22 10:42:19 -0600 | [diff] [blame] | 3243 | // Create a renderPass with a single color attachment |
Mark Lobodzinski | 6d17b9f | 2016-06-16 13:21:38 -0600 | [diff] [blame] | 3244 | VkAttachmentReference attach = {}; |
| 3245 | attach.layout = VK_IMAGE_LAYOUT_GENERAL; |
| 3246 | VkSubpassDescription subpass = {}; |
Tobin Ehlis | 2545e6f | 2016-06-22 10:42:19 -0600 | [diff] [blame] | 3247 | subpass.pColorAttachments = &attach; |
Mark Lobodzinski | 6d17b9f | 2016-06-16 13:21:38 -0600 | [diff] [blame] | 3248 | VkRenderPassCreateInfo rpci = {}; |
| 3249 | rpci.subpassCount = 1; |
| 3250 | rpci.pSubpasses = &subpass; |
| 3251 | rpci.attachmentCount = 1; |
| 3252 | VkAttachmentDescription attach_desc = {}; |
Tobin Ehlis | d3bb23a | 2016-06-22 13:34:46 -0600 | [diff] [blame] | 3253 | attach_desc.format = VK_FORMAT_B8G8R8A8_UNORM; |
Tobin Ehlis | 77d717c | 2016-06-22 14:19:19 -0600 | [diff] [blame] | 3254 | attach_desc.samples = VK_SAMPLE_COUNT_1_BIT; |
Mark Lobodzinski | 6d17b9f | 2016-06-16 13:21:38 -0600 | [diff] [blame] | 3255 | rpci.pAttachments = &attach_desc; |
| 3256 | rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO; |
| 3257 | VkRenderPass rp; |
| 3258 | VkResult err = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp); |
| 3259 | ASSERT_VK_SUCCESS(err); |
| 3260 | |
Tobin Ehlis | 2545e6f | 2016-06-22 10:42:19 -0600 | [diff] [blame] | 3261 | VkImageView ivs[2]; |
| 3262 | ivs[0] = m_renderTargets[0]->targetView(VK_FORMAT_B8G8R8A8_UNORM); |
| 3263 | ivs[1] = m_renderTargets[0]->targetView(VK_FORMAT_B8G8R8A8_UNORM); |
Mark Lobodzinski | 6d17b9f | 2016-06-16 13:21:38 -0600 | [diff] [blame] | 3264 | VkFramebufferCreateInfo fb_info = {}; |
| 3265 | fb_info.sType = VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO; |
| 3266 | fb_info.pNext = NULL; |
| 3267 | fb_info.renderPass = rp; |
Tobin Ehlis | 2545e6f | 2016-06-22 10:42:19 -0600 | [diff] [blame] | 3268 | // Set mis-matching attachmentCount |
| 3269 | fb_info.attachmentCount = 2; |
| 3270 | fb_info.pAttachments = ivs; |
Mark Lobodzinski | 6d17b9f | 2016-06-16 13:21:38 -0600 | [diff] [blame] | 3271 | fb_info.width = 100; |
| 3272 | fb_info.height = 100; |
| 3273 | fb_info.layers = 1; |
| 3274 | |
| 3275 | VkFramebuffer fb; |
| 3276 | err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb); |
| 3277 | |
| 3278 | m_errorMonitor->VerifyFound(); |
Mark Lobodzinski | 6d17b9f | 2016-06-16 13:21:38 -0600 | [diff] [blame] | 3279 | if (err == VK_SUCCESS) { |
| 3280 | vkDestroyFramebuffer(m_device->device(), fb, NULL); |
| 3281 | } |
| 3282 | vkDestroyRenderPass(m_device->device(), rp, NULL); |
Tobin Ehlis | 2545e6f | 2016-06-22 10:42:19 -0600 | [diff] [blame] | 3283 | |
| 3284 | // Create a renderPass with a depth-stencil attachment created with |
| 3285 | // IMAGE_USAGE_COLOR_ATTACHMENT |
| 3286 | // Add our color attachment to pDepthStencilAttachment |
| 3287 | subpass.pDepthStencilAttachment = &attach; |
| 3288 | subpass.pColorAttachments = NULL; |
| 3289 | VkRenderPass rp_ds; |
| 3290 | err = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp_ds); |
| 3291 | ASSERT_VK_SUCCESS(err); |
| 3292 | // Set correct attachment count, but attachment has COLOR usage bit set |
| 3293 | fb_info.attachmentCount = 1; |
| 3294 | fb_info.renderPass = rp_ds; |
| 3295 | |
| 3296 | m_errorMonitor->SetDesiredFailureMsg( |
| 3297 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 3298 | " conflicts with the image's IMAGE_USAGE flags "); |
| 3299 | err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb); |
| 3300 | |
| 3301 | m_errorMonitor->VerifyFound(); |
| 3302 | if (err == VK_SUCCESS) { |
| 3303 | vkDestroyFramebuffer(m_device->device(), fb, NULL); |
| 3304 | } |
| 3305 | vkDestroyRenderPass(m_device->device(), rp_ds, NULL); |
Tobin Ehlis | d3bb23a | 2016-06-22 13:34:46 -0600 | [diff] [blame] | 3306 | |
| 3307 | // Create new renderpass with alternate attachment format from fb |
| 3308 | attach_desc.format = VK_FORMAT_R8G8B8A8_UNORM; |
| 3309 | subpass.pDepthStencilAttachment = NULL; |
| 3310 | subpass.pColorAttachments = &attach; |
| 3311 | err = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp); |
| 3312 | ASSERT_VK_SUCCESS(err); |
| 3313 | |
| 3314 | // Cause error due to mis-matched formats between rp & fb |
| 3315 | // rp attachment 0 now has RGBA8 but corresponding fb attach is BGRA8 |
| 3316 | fb_info.renderPass = rp; |
| 3317 | m_errorMonitor->SetDesiredFailureMsg( |
| 3318 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 3319 | " has format of VK_FORMAT_B8G8R8A8_UNORM that does not match "); |
| 3320 | err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb); |
| 3321 | |
| 3322 | m_errorMonitor->VerifyFound(); |
| 3323 | if (err == VK_SUCCESS) { |
| 3324 | vkDestroyFramebuffer(m_device->device(), fb, NULL); |
| 3325 | } |
Tobin Ehlis | 77d717c | 2016-06-22 14:19:19 -0600 | [diff] [blame] | 3326 | vkDestroyRenderPass(m_device->device(), rp, NULL); |
| 3327 | |
| 3328 | // Create new renderpass with alternate sample count from fb |
| 3329 | attach_desc.format = VK_FORMAT_B8G8R8A8_UNORM; |
| 3330 | attach_desc.samples = VK_SAMPLE_COUNT_4_BIT; |
| 3331 | err = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp); |
| 3332 | ASSERT_VK_SUCCESS(err); |
| 3333 | |
| 3334 | // Cause error due to mis-matched sample count between rp & fb |
| 3335 | fb_info.renderPass = rp; |
| 3336 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 3337 | " has VK_SAMPLE_COUNT_1_BIT samples " |
| 3338 | "that do not match the " |
| 3339 | "VK_SAMPLE_COUNT_4_BIT "); |
| 3340 | err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb); |
| 3341 | |
| 3342 | m_errorMonitor->VerifyFound(); |
| 3343 | if (err == VK_SUCCESS) { |
| 3344 | vkDestroyFramebuffer(m_device->device(), fb, NULL); |
| 3345 | } |
Tobin Ehlis | d3bb23a | 2016-06-22 13:34:46 -0600 | [diff] [blame] | 3346 | |
| 3347 | vkDestroyRenderPass(m_device->device(), rp, NULL); |
Tobin Ehlis | 6cfda64 | 2016-06-22 16:12:58 -0600 | [diff] [blame] | 3348 | |
| 3349 | // Create a custom imageView with non-1 mip levels |
| 3350 | VkImageObj image(m_device); |
| 3351 | image.init(128, 128, VK_FORMAT_B8G8R8A8_UNORM, |
| 3352 | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0); |
| 3353 | ASSERT_TRUE(image.initialized()); |
| 3354 | |
| 3355 | VkImageView view; |
| 3356 | VkImageViewCreateInfo ivci = {}; |
| 3357 | ivci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO; |
| 3358 | ivci.image = image.handle(); |
| 3359 | ivci.viewType = VK_IMAGE_VIEW_TYPE_2D; |
| 3360 | ivci.format = VK_FORMAT_B8G8R8A8_UNORM; |
| 3361 | ivci.subresourceRange.layerCount = 1; |
| 3362 | ivci.subresourceRange.baseMipLevel = 0; |
| 3363 | // Set level count 2 (only 1 is allowed for FB attachment) |
| 3364 | ivci.subresourceRange.levelCount = 2; |
| 3365 | ivci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; |
| 3366 | err = vkCreateImageView(m_device->device(), &ivci, NULL, &view); |
| 3367 | ASSERT_VK_SUCCESS(err); |
| 3368 | // Re-create renderpass to have matching sample count |
| 3369 | attach_desc.samples = VK_SAMPLE_COUNT_1_BIT; |
| 3370 | err = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp); |
| 3371 | ASSERT_VK_SUCCESS(err); |
| 3372 | |
| 3373 | fb_info.renderPass = rp; |
| 3374 | fb_info.pAttachments = &view; |
| 3375 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 3376 | " has mip levelCount of 2 but only "); |
| 3377 | err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb); |
| 3378 | |
| 3379 | m_errorMonitor->VerifyFound(); |
| 3380 | if (err == VK_SUCCESS) { |
| 3381 | vkDestroyFramebuffer(m_device->device(), fb, NULL); |
| 3382 | } |
Tobin Ehlis | 6cfda64 | 2016-06-22 16:12:58 -0600 | [diff] [blame] | 3383 | vkDestroyImageView(m_device->device(), view, NULL); |
Tobin Ehlis | 27f2ae8 | 2016-06-23 07:36:57 -0600 | [diff] [blame] | 3384 | // Update view to original color buffer and grow FB dimensions too big |
| 3385 | fb_info.pAttachments = ivs; |
| 3386 | fb_info.height = 1024; |
| 3387 | fb_info.width = 1024; |
| 3388 | fb_info.layers = 2; |
| 3389 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 3390 | " Attachment dimensions must be at " |
| 3391 | "least as large. "); |
| 3392 | err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb); |
| 3393 | |
| 3394 | m_errorMonitor->VerifyFound(); |
| 3395 | if (err == VK_SUCCESS) { |
| 3396 | vkDestroyFramebuffer(m_device->device(), fb, NULL); |
| 3397 | } |
Tobin Ehlis | b1f303b | 2016-06-23 08:19:55 -0600 | [diff] [blame] | 3398 | // Create view attachment with non-identity swizzle |
| 3399 | ivci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO; |
| 3400 | ivci.image = image.handle(); |
| 3401 | ivci.viewType = VK_IMAGE_VIEW_TYPE_2D; |
| 3402 | ivci.format = VK_FORMAT_B8G8R8A8_UNORM; |
| 3403 | ivci.subresourceRange.layerCount = 1; |
| 3404 | ivci.subresourceRange.baseMipLevel = 0; |
| 3405 | ivci.subresourceRange.levelCount = 1; |
| 3406 | ivci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; |
| 3407 | ivci.components.r = VK_COMPONENT_SWIZZLE_G; |
| 3408 | ivci.components.g = VK_COMPONENT_SWIZZLE_R; |
| 3409 | ivci.components.b = VK_COMPONENT_SWIZZLE_A; |
| 3410 | ivci.components.a = VK_COMPONENT_SWIZZLE_B; |
| 3411 | err = vkCreateImageView(m_device->device(), &ivci, NULL, &view); |
| 3412 | ASSERT_VK_SUCCESS(err); |
| 3413 | |
| 3414 | fb_info.pAttachments = &view; |
| 3415 | fb_info.height = 100; |
| 3416 | fb_info.width = 100; |
| 3417 | fb_info.layers = 1; |
| 3418 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 3419 | " has non-identy swizzle. All " |
| 3420 | "framebuffer attachments must have " |
| 3421 | "been created with the identity " |
| 3422 | "swizzle. "); |
| 3423 | err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb); |
| 3424 | |
| 3425 | m_errorMonitor->VerifyFound(); |
| 3426 | if (err == VK_SUCCESS) { |
| 3427 | vkDestroyFramebuffer(m_device->device(), fb, NULL); |
| 3428 | } |
| 3429 | vkDestroyImageView(m_device->device(), view, NULL); |
Tobin Ehlis | 08d4b5e | 2016-06-23 08:52:39 -0600 | [diff] [blame] | 3430 | // Request fb that exceeds max dimensions |
| 3431 | // reset attachment to color attachment |
| 3432 | fb_info.pAttachments = ivs; |
| 3433 | fb_info.width = m_device->props.limits.maxFramebufferWidth + 1; |
| 3434 | fb_info.height = m_device->props.limits.maxFramebufferHeight + 1; |
| 3435 | fb_info.layers = m_device->props.limits.maxFramebufferLayers + 1; |
| 3436 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 3437 | " Requested VkFramebufferCreateInfo " |
| 3438 | "dimensions exceed physical device " |
| 3439 | "limits. "); |
| 3440 | err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb); |
| 3441 | |
| 3442 | m_errorMonitor->VerifyFound(); |
| 3443 | if (err == VK_SUCCESS) { |
| 3444 | vkDestroyFramebuffer(m_device->device(), fb, NULL); |
| 3445 | } |
Tobin Ehlis | 27f2ae8 | 2016-06-23 07:36:57 -0600 | [diff] [blame] | 3446 | |
Tobin Ehlis | 6cfda64 | 2016-06-22 16:12:58 -0600 | [diff] [blame] | 3447 | vkDestroyRenderPass(m_device->device(), rp, NULL); |
Mark Lobodzinski | 6d17b9f | 2016-06-16 13:21:38 -0600 | [diff] [blame] | 3448 | } |
| 3449 | |
Mark Lobodzinski | c808d44 | 2016-04-14 10:57:23 -0600 | [diff] [blame] | 3450 | // This is a positive test. No errors should be generated. |
Michael Lentine | 860b0fe | 2016-05-20 10:14:00 -0500 | [diff] [blame] | 3451 | TEST_F(VkLayerTest, WaitEventThenSet) { |
| 3452 | TEST_DESCRIPTION( |
| 3453 | "Wait on a event then set it after the wait has been submitted."); |
| 3454 | |
Michael Lentine | 860b0fe | 2016-05-20 10:14:00 -0500 | [diff] [blame] | 3455 | m_errorMonitor->ExpectSuccess(); |
| 3456 | |
| 3457 | VkEvent event; |
| 3458 | VkEventCreateInfo event_create_info{}; |
| 3459 | event_create_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO; |
| 3460 | vkCreateEvent(m_device->device(), &event_create_info, nullptr, &event); |
| 3461 | |
| 3462 | VkCommandPool command_pool; |
| 3463 | VkCommandPoolCreateInfo pool_create_info{}; |
| 3464 | pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO; |
| 3465 | pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_; |
| 3466 | pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT; |
| 3467 | vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, |
| 3468 | &command_pool); |
| 3469 | |
| 3470 | VkCommandBuffer command_buffer; |
| 3471 | VkCommandBufferAllocateInfo command_buffer_allocate_info{}; |
| 3472 | command_buffer_allocate_info.sType = |
| 3473 | VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO; |
| 3474 | command_buffer_allocate_info.commandPool = command_pool; |
| 3475 | command_buffer_allocate_info.commandBufferCount = 1; |
| 3476 | command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY; |
| 3477 | vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, |
| 3478 | &command_buffer); |
| 3479 | |
| 3480 | VkQueue queue = VK_NULL_HANDLE; |
| 3481 | vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, |
Tony Barbour | fe302c0 | 2016-06-06 13:05:19 -0600 | [diff] [blame] | 3482 | 0, &queue); |
Michael Lentine | 860b0fe | 2016-05-20 10:14:00 -0500 | [diff] [blame] | 3483 | |
| 3484 | { |
| 3485 | VkCommandBufferBeginInfo begin_info{}; |
| 3486 | begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO; |
| 3487 | vkBeginCommandBuffer(command_buffer, &begin_info); |
| 3488 | |
| 3489 | vkCmdWaitEvents(command_buffer, 1, &event, VK_PIPELINE_STAGE_HOST_BIT, |
| 3490 | VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, nullptr, 0, |
| 3491 | nullptr, 0, nullptr); |
| 3492 | vkCmdResetEvent(command_buffer, event, |
| 3493 | VK_PIPELINE_STAGE_ALL_COMMANDS_BIT); |
| 3494 | vkEndCommandBuffer(command_buffer); |
| 3495 | } |
| 3496 | { |
| 3497 | VkSubmitInfo submit_info{}; |
| 3498 | submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO; |
| 3499 | submit_info.commandBufferCount = 1; |
| 3500 | submit_info.pCommandBuffers = &command_buffer; |
| 3501 | submit_info.signalSemaphoreCount = 0; |
| 3502 | submit_info.pSignalSemaphores = nullptr; |
| 3503 | vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE); |
| 3504 | } |
| 3505 | { vkSetEvent(m_device->device(), event); } |
| 3506 | |
| 3507 | vkQueueWaitIdle(queue); |
| 3508 | |
| 3509 | vkDestroyEvent(m_device->device(), event, nullptr); |
| 3510 | vkFreeCommandBuffers(m_device->device(), command_pool, 1, &command_buffer); |
| 3511 | vkDestroyCommandPool(m_device->device(), command_pool, NULL); |
| 3512 | |
| 3513 | m_errorMonitor->VerifyNotFound(); |
| 3514 | } |
Michael Lentine | 5627e69 | 2016-05-20 17:45:02 -0500 | [diff] [blame] | 3515 | // This is a positive test. No errors should be generated. |
| 3516 | TEST_F(VkLayerTest, QueryAndCopyMultipleCommandBuffers) { |
| 3517 | TEST_DESCRIPTION( |
| 3518 | "Issue a query and copy from it on a second command buffer."); |
| 3519 | |
| 3520 | if ((m_device->queue_props.empty()) || |
| 3521 | (m_device->queue_props[0].queueCount < 2)) |
| 3522 | return; |
| 3523 | |
| 3524 | m_errorMonitor->ExpectSuccess(); |
| 3525 | |
| 3526 | VkQueryPool query_pool; |
| 3527 | VkQueryPoolCreateInfo query_pool_create_info{}; |
| 3528 | query_pool_create_info.sType = VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO; |
| 3529 | query_pool_create_info.queryType = VK_QUERY_TYPE_TIMESTAMP; |
| 3530 | query_pool_create_info.queryCount = 1; |
| 3531 | vkCreateQueryPool(m_device->device(), &query_pool_create_info, nullptr, |
| 3532 | &query_pool); |
| 3533 | |
| 3534 | VkCommandPool command_pool; |
| 3535 | VkCommandPoolCreateInfo pool_create_info{}; |
| 3536 | pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO; |
| 3537 | pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_; |
| 3538 | pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT; |
| 3539 | vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, |
| 3540 | &command_pool); |
| 3541 | |
| 3542 | VkCommandBuffer command_buffer[2]; |
| 3543 | VkCommandBufferAllocateInfo command_buffer_allocate_info{}; |
| 3544 | command_buffer_allocate_info.sType = |
| 3545 | VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO; |
| 3546 | command_buffer_allocate_info.commandPool = command_pool; |
| 3547 | command_buffer_allocate_info.commandBufferCount = 2; |
| 3548 | command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY; |
| 3549 | vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, |
| 3550 | command_buffer); |
| 3551 | |
| 3552 | VkQueue queue = VK_NULL_HANDLE; |
| 3553 | vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, |
| 3554 | 1, &queue); |
| 3555 | |
| 3556 | uint32_t qfi = 0; |
| 3557 | VkBufferCreateInfo buff_create_info = {}; |
| 3558 | buff_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO; |
| 3559 | buff_create_info.size = 1024; |
| 3560 | buff_create_info.usage = VK_BUFFER_USAGE_TRANSFER_DST_BIT; |
| 3561 | buff_create_info.queueFamilyIndexCount = 1; |
| 3562 | buff_create_info.pQueueFamilyIndices = &qfi; |
| 3563 | |
| 3564 | VkResult err; |
| 3565 | VkBuffer buffer; |
| 3566 | err = vkCreateBuffer(m_device->device(), &buff_create_info, NULL, &buffer); |
| 3567 | ASSERT_VK_SUCCESS(err); |
| 3568 | VkMemoryAllocateInfo mem_alloc = {}; |
| 3569 | mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO; |
| 3570 | mem_alloc.pNext = NULL; |
| 3571 | mem_alloc.allocationSize = 1024; |
| 3572 | mem_alloc.memoryTypeIndex = 0; |
| 3573 | |
| 3574 | VkMemoryRequirements memReqs; |
| 3575 | vkGetBufferMemoryRequirements(m_device->device(), buffer, &memReqs); |
| 3576 | bool pass = |
| 3577 | m_device->phy().set_memory_type(memReqs.memoryTypeBits, &mem_alloc, 0); |
| 3578 | if (!pass) { |
| 3579 | vkDestroyBuffer(m_device->device(), buffer, NULL); |
| 3580 | return; |
| 3581 | } |
| 3582 | |
| 3583 | VkDeviceMemory mem; |
| 3584 | err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem); |
| 3585 | ASSERT_VK_SUCCESS(err); |
| 3586 | err = vkBindBufferMemory(m_device->device(), buffer, mem, 0); |
| 3587 | ASSERT_VK_SUCCESS(err); |
| 3588 | |
| 3589 | { |
| 3590 | VkCommandBufferBeginInfo begin_info{}; |
| 3591 | begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO; |
| 3592 | vkBeginCommandBuffer(command_buffer[0], &begin_info); |
| 3593 | |
| 3594 | vkCmdResetQueryPool(command_buffer[0], query_pool, 0, 1); |
| 3595 | vkCmdWriteTimestamp(command_buffer[0], |
| 3596 | VK_PIPELINE_STAGE_ALL_GRAPHICS_BIT, query_pool, 0); |
| 3597 | |
| 3598 | vkEndCommandBuffer(command_buffer[0]); |
| 3599 | |
| 3600 | vkBeginCommandBuffer(command_buffer[1], &begin_info); |
| 3601 | |
| 3602 | vkCmdCopyQueryPoolResults(command_buffer[1], query_pool, 0, 1, buffer, |
| 3603 | 0, 0, 0); |
| 3604 | |
| 3605 | vkEndCommandBuffer(command_buffer[1]); |
| 3606 | } |
| 3607 | { |
| 3608 | VkSubmitInfo submit_info{}; |
| 3609 | submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO; |
| 3610 | submit_info.commandBufferCount = 2; |
| 3611 | submit_info.pCommandBuffers = command_buffer; |
| 3612 | submit_info.signalSemaphoreCount = 0; |
| 3613 | submit_info.pSignalSemaphores = nullptr; |
| 3614 | vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE); |
| 3615 | } |
| 3616 | |
| 3617 | vkQueueWaitIdle(queue); |
| 3618 | |
| 3619 | vkDestroyQueryPool(m_device->device(), query_pool, nullptr); |
| 3620 | vkFreeCommandBuffers(m_device->device(), command_pool, 2, command_buffer); |
| 3621 | vkDestroyCommandPool(m_device->device(), command_pool, NULL); |
Tony Barbour | df4c004 | 2016-06-01 15:55:43 -0600 | [diff] [blame] | 3622 | vkDestroyBuffer(m_device->device(), buffer, NULL); |
| 3623 | vkFreeMemory(m_device->device(), mem, NULL); |
Michael Lentine | 5627e69 | 2016-05-20 17:45:02 -0500 | [diff] [blame] | 3624 | |
| 3625 | m_errorMonitor->VerifyNotFound(); |
| 3626 | } |
Michael Lentine | 860b0fe | 2016-05-20 10:14:00 -0500 | [diff] [blame] | 3627 | |
| 3628 | TEST_F(VkLayerTest, ResetEventThenSet) { |
| 3629 | TEST_DESCRIPTION( |
| 3630 | "Reset an event then set it after the reset has been submitted."); |
| 3631 | |
Michael Lentine | 860b0fe | 2016-05-20 10:14:00 -0500 | [diff] [blame] | 3632 | m_errorMonitor->ExpectSuccess(); |
| 3633 | |
| 3634 | VkEvent event; |
| 3635 | VkEventCreateInfo event_create_info{}; |
| 3636 | event_create_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO; |
| 3637 | vkCreateEvent(m_device->device(), &event_create_info, nullptr, &event); |
| 3638 | |
| 3639 | VkCommandPool command_pool; |
| 3640 | VkCommandPoolCreateInfo pool_create_info{}; |
| 3641 | pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO; |
| 3642 | pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_; |
| 3643 | pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT; |
| 3644 | vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, |
| 3645 | &command_pool); |
| 3646 | |
| 3647 | VkCommandBuffer command_buffer; |
| 3648 | VkCommandBufferAllocateInfo command_buffer_allocate_info{}; |
| 3649 | command_buffer_allocate_info.sType = |
| 3650 | VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO; |
| 3651 | command_buffer_allocate_info.commandPool = command_pool; |
| 3652 | command_buffer_allocate_info.commandBufferCount = 1; |
| 3653 | command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY; |
| 3654 | vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, |
| 3655 | &command_buffer); |
| 3656 | |
| 3657 | VkQueue queue = VK_NULL_HANDLE; |
| 3658 | vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, |
Tony Barbour | fe302c0 | 2016-06-06 13:05:19 -0600 | [diff] [blame] | 3659 | 0, &queue); |
Michael Lentine | 860b0fe | 2016-05-20 10:14:00 -0500 | [diff] [blame] | 3660 | |
| 3661 | { |
| 3662 | VkCommandBufferBeginInfo begin_info{}; |
| 3663 | begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO; |
| 3664 | vkBeginCommandBuffer(command_buffer, &begin_info); |
| 3665 | |
| 3666 | vkCmdResetEvent(command_buffer, event, |
| 3667 | VK_PIPELINE_STAGE_ALL_COMMANDS_BIT); |
| 3668 | vkCmdWaitEvents(command_buffer, 1, &event, |
| 3669 | VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, |
| 3670 | VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, nullptr, 0, |
| 3671 | nullptr, 0, nullptr); |
| 3672 | vkEndCommandBuffer(command_buffer); |
| 3673 | } |
| 3674 | { |
| 3675 | VkSubmitInfo submit_info{}; |
| 3676 | submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO; |
| 3677 | submit_info.commandBufferCount = 1; |
| 3678 | submit_info.pCommandBuffers = &command_buffer; |
| 3679 | submit_info.signalSemaphoreCount = 0; |
| 3680 | submit_info.pSignalSemaphores = nullptr; |
| 3681 | vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE); |
| 3682 | } |
| 3683 | { |
| 3684 | m_errorMonitor->SetDesiredFailureMsg( |
| 3685 | VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot call vkSetEvent() on event " |
| 3686 | "0x1 that is already in use by a " |
| 3687 | "command buffer."); |
| 3688 | vkSetEvent(m_device->device(), event); |
| 3689 | m_errorMonitor->VerifyFound(); |
| 3690 | } |
| 3691 | |
| 3692 | vkQueueWaitIdle(queue); |
| 3693 | |
| 3694 | vkDestroyEvent(m_device->device(), event, nullptr); |
| 3695 | vkFreeCommandBuffers(m_device->device(), command_pool, 1, &command_buffer); |
| 3696 | vkDestroyCommandPool(m_device->device(), command_pool, NULL); |
| 3697 | } |
| 3698 | |
| 3699 | // This is a positive test. No errors should be generated. |
Tobin Ehlis | 0bb263b | 2016-05-10 12:13:02 -0600 | [diff] [blame] | 3700 | TEST_F(VkLayerTest, TwoFencesThreeFrames) { |
| 3701 | TEST_DESCRIPTION("Two command buffers with two separate fences are each " |
| 3702 | "run through a Submit & WaitForFences cycle 3 times. This " |
| 3703 | "previously revealed a bug so running this positive test " |
| 3704 | "to prevent a regression."); |
| 3705 | m_errorMonitor->ExpectSuccess(); |
| 3706 | |
| 3707 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 3708 | VkQueue queue = VK_NULL_HANDLE; |
| 3709 | vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, |
| 3710 | 0, &queue); |
| 3711 | |
| 3712 | static const uint32_t NUM_OBJECTS = 2; |
| 3713 | static const uint32_t NUM_FRAMES = 3; |
| 3714 | VkCommandBuffer cmd_buffers[NUM_OBJECTS] = {}; |
| 3715 | VkFence fences[NUM_OBJECTS] = {}; |
| 3716 | |
| 3717 | VkCommandPool cmd_pool; |
| 3718 | VkCommandPoolCreateInfo cmd_pool_ci = {}; |
| 3719 | cmd_pool_ci.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO; |
| 3720 | cmd_pool_ci.queueFamilyIndex = m_device->graphics_queue_node_index_; |
| 3721 | cmd_pool_ci.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT; |
| 3722 | VkResult err = vkCreateCommandPool(m_device->device(), &cmd_pool_ci, |
| 3723 | nullptr, &cmd_pool); |
| 3724 | ASSERT_VK_SUCCESS(err); |
| 3725 | |
| 3726 | VkCommandBufferAllocateInfo cmd_buf_info = {}; |
| 3727 | cmd_buf_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO; |
| 3728 | cmd_buf_info.commandPool = cmd_pool; |
| 3729 | cmd_buf_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY; |
| 3730 | cmd_buf_info.commandBufferCount = 1; |
| 3731 | |
| 3732 | VkFenceCreateInfo fence_ci = {}; |
| 3733 | fence_ci.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO; |
| 3734 | fence_ci.pNext = nullptr; |
| 3735 | fence_ci.flags = 0; |
| 3736 | |
| 3737 | for (uint32_t i = 0; i < NUM_OBJECTS; ++i) { |
| 3738 | err = vkAllocateCommandBuffers(m_device->device(), &cmd_buf_info, |
| 3739 | &cmd_buffers[i]); |
| 3740 | ASSERT_VK_SUCCESS(err); |
| 3741 | err = vkCreateFence(m_device->device(), &fence_ci, nullptr, &fences[i]); |
| 3742 | ASSERT_VK_SUCCESS(err); |
| 3743 | } |
| 3744 | |
| 3745 | for (uint32_t frame = 0; frame < NUM_FRAMES; ++frame) { |
Tobin Ehlis | f902516 | 2016-05-26 06:55:21 -0600 | [diff] [blame] | 3746 | for (uint32_t obj = 0; obj < NUM_OBJECTS; ++obj) { |
| 3747 | // Create empty cmd buffer |
| 3748 | VkCommandBufferBeginInfo cmdBufBeginDesc = {}; |
| 3749 | cmdBufBeginDesc.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO; |
Tobin Ehlis | 0bb263b | 2016-05-10 12:13:02 -0600 | [diff] [blame] | 3750 | |
Tobin Ehlis | f902516 | 2016-05-26 06:55:21 -0600 | [diff] [blame] | 3751 | err = vkBeginCommandBuffer(cmd_buffers[obj], &cmdBufBeginDesc); |
| 3752 | ASSERT_VK_SUCCESS(err); |
| 3753 | err = vkEndCommandBuffer(cmd_buffers[obj]); |
| 3754 | ASSERT_VK_SUCCESS(err); |
Tobin Ehlis | 0bb263b | 2016-05-10 12:13:02 -0600 | [diff] [blame] | 3755 | |
Tobin Ehlis | f902516 | 2016-05-26 06:55:21 -0600 | [diff] [blame] | 3756 | VkSubmitInfo submit_info = {}; |
| 3757 | submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO; |
| 3758 | submit_info.commandBufferCount = 1; |
| 3759 | submit_info.pCommandBuffers = &cmd_buffers[obj]; |
| 3760 | // Submit cmd buffer and wait for fence |
| 3761 | err = vkQueueSubmit(queue, 1, &submit_info, fences[obj]); |
| 3762 | ASSERT_VK_SUCCESS(err); |
| 3763 | err = vkWaitForFences(m_device->device(), 1, &fences[obj], VK_TRUE, |
| 3764 | UINT64_MAX); |
| 3765 | ASSERT_VK_SUCCESS(err); |
| 3766 | err = vkResetFences(m_device->device(), 1, &fences[obj]); |
| 3767 | ASSERT_VK_SUCCESS(err); |
| 3768 | } |
Tobin Ehlis | 0bb263b | 2016-05-10 12:13:02 -0600 | [diff] [blame] | 3769 | } |
| 3770 | m_errorMonitor->VerifyNotFound(); |
Tony Barbour | df4c004 | 2016-06-01 15:55:43 -0600 | [diff] [blame] | 3771 | vkDestroyCommandPool(m_device->device(), cmd_pool, NULL); |
| 3772 | for (uint32_t i = 0; i < NUM_OBJECTS; ++i) { |
| 3773 | vkDestroyFence(m_device->device(), fences[i], nullptr); |
| 3774 | } |
Tobin Ehlis | 0bb263b | 2016-05-10 12:13:02 -0600 | [diff] [blame] | 3775 | } |
| 3776 | // This is a positive test. No errors should be generated. |
Mark Lobodzinski | c808d44 | 2016-04-14 10:57:23 -0600 | [diff] [blame] | 3777 | TEST_F(VkLayerTest, TwoQueueSubmitsSeparateQueuesWithSemaphoreAndOneFenceQWI) { |
| 3778 | |
| 3779 | TEST_DESCRIPTION("Two command buffers, each in a separate QueueSubmit call " |
| 3780 | "submitted on separate queues followed by a QueueWaitIdle."); |
| 3781 | |
Dustin Graves | 4845814 | 2016-04-29 16:11:55 -0600 | [diff] [blame] | 3782 | if ((m_device->queue_props.empty()) || |
| 3783 | (m_device->queue_props[0].queueCount < 2)) |
Tony Barbour | dc18b26 | 2016-04-22 14:49:48 -0600 | [diff] [blame] | 3784 | return; |
| 3785 | |
Mark Lobodzinski | c808d44 | 2016-04-14 10:57:23 -0600 | [diff] [blame] | 3786 | m_errorMonitor->ExpectSuccess(); |
| 3787 | |
| 3788 | VkSemaphore semaphore; |
| 3789 | VkSemaphoreCreateInfo semaphore_create_info{}; |
| 3790 | semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO; |
| 3791 | vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, |
| 3792 | &semaphore); |
| 3793 | |
| 3794 | VkCommandPool command_pool; |
| 3795 | VkCommandPoolCreateInfo pool_create_info{}; |
| 3796 | pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO; |
| 3797 | pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_; |
| 3798 | pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT; |
| 3799 | vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, |
| 3800 | &command_pool); |
| 3801 | |
| 3802 | VkCommandBuffer command_buffer[2]; |
| 3803 | VkCommandBufferAllocateInfo command_buffer_allocate_info{}; |
| 3804 | command_buffer_allocate_info.sType = |
| 3805 | VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO; |
| 3806 | command_buffer_allocate_info.commandPool = command_pool; |
| 3807 | command_buffer_allocate_info.commandBufferCount = 2; |
| 3808 | command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY; |
| 3809 | vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, |
| 3810 | command_buffer); |
| 3811 | |
| 3812 | VkQueue queue = VK_NULL_HANDLE; |
| 3813 | vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, |
| 3814 | 1, &queue); |
| 3815 | |
| 3816 | { |
| 3817 | VkCommandBufferBeginInfo begin_info{}; |
| 3818 | begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO; |
| 3819 | vkBeginCommandBuffer(command_buffer[0], &begin_info); |
| 3820 | |
| 3821 | vkCmdPipelineBarrier(command_buffer[0], |
| 3822 | VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, |
| 3823 | VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, nullptr, |
| 3824 | 0, nullptr, 0, nullptr); |
| 3825 | |
| 3826 | VkViewport viewport{}; |
| 3827 | viewport.maxDepth = 1.0f; |
| 3828 | viewport.minDepth = 0.0f; |
| 3829 | viewport.width = 512; |
| 3830 | viewport.height = 512; |
| 3831 | viewport.x = 0; |
| 3832 | viewport.y = 0; |
| 3833 | vkCmdSetViewport(command_buffer[0], 0, 1, &viewport); |
| 3834 | vkEndCommandBuffer(command_buffer[0]); |
| 3835 | } |
| 3836 | { |
| 3837 | VkCommandBufferBeginInfo begin_info{}; |
| 3838 | begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO; |
| 3839 | vkBeginCommandBuffer(command_buffer[1], &begin_info); |
| 3840 | |
| 3841 | VkViewport viewport{}; |
| 3842 | viewport.maxDepth = 1.0f; |
| 3843 | viewport.minDepth = 0.0f; |
| 3844 | viewport.width = 512; |
| 3845 | viewport.height = 512; |
| 3846 | viewport.x = 0; |
| 3847 | viewport.y = 0; |
| 3848 | vkCmdSetViewport(command_buffer[1], 0, 1, &viewport); |
| 3849 | vkEndCommandBuffer(command_buffer[1]); |
| 3850 | } |
| 3851 | { |
| 3852 | VkSubmitInfo submit_info{}; |
| 3853 | submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO; |
| 3854 | submit_info.commandBufferCount = 1; |
| 3855 | submit_info.pCommandBuffers = &command_buffer[0]; |
| 3856 | submit_info.signalSemaphoreCount = 1; |
| 3857 | submit_info.pSignalSemaphores = &semaphore; |
| 3858 | vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE); |
| 3859 | } |
| 3860 | { |
| 3861 | VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT}; |
| 3862 | VkSubmitInfo submit_info{}; |
| 3863 | submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO; |
| 3864 | submit_info.commandBufferCount = 1; |
| 3865 | submit_info.pCommandBuffers = &command_buffer[1]; |
| 3866 | submit_info.waitSemaphoreCount = 1; |
| 3867 | submit_info.pWaitSemaphores = &semaphore; |
| 3868 | submit_info.pWaitDstStageMask = flags; |
| 3869 | vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE); |
| 3870 | } |
| 3871 | |
| 3872 | vkQueueWaitIdle(m_device->m_queue); |
| 3873 | |
| 3874 | vkDestroySemaphore(m_device->device(), semaphore, nullptr); |
| 3875 | vkFreeCommandBuffers(m_device->device(), command_pool, 2, |
| 3876 | &command_buffer[0]); |
| 3877 | vkDestroyCommandPool(m_device->device(), command_pool, NULL); |
| 3878 | |
| 3879 | m_errorMonitor->VerifyNotFound(); |
| 3880 | } |
| 3881 | |
| 3882 | // This is a positive test. No errors should be generated. |
| 3883 | TEST_F(VkLayerTest, TwoQueueSubmitsSeparateQueuesWithSemaphoreAndOneFenceQWIFence) { |
| 3884 | |
| 3885 | TEST_DESCRIPTION("Two command buffers, each in a separate QueueSubmit call " |
| 3886 | "submitted on separate queues, the second having a fence" |
| 3887 | "followed by a QueueWaitIdle."); |
| 3888 | |
Dustin Graves | 4845814 | 2016-04-29 16:11:55 -0600 | [diff] [blame] | 3889 | if ((m_device->queue_props.empty()) || |
| 3890 | (m_device->queue_props[0].queueCount < 2)) |
Tony Barbour | dc18b26 | 2016-04-22 14:49:48 -0600 | [diff] [blame] | 3891 | return; |
| 3892 | |
Mark Lobodzinski | c808d44 | 2016-04-14 10:57:23 -0600 | [diff] [blame] | 3893 | m_errorMonitor->ExpectSuccess(); |
| 3894 | |
| 3895 | VkFence fence; |
| 3896 | VkFenceCreateInfo fence_create_info{}; |
| 3897 | fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO; |
| 3898 | vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence); |
| 3899 | |
| 3900 | VkSemaphore semaphore; |
| 3901 | VkSemaphoreCreateInfo semaphore_create_info{}; |
| 3902 | semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO; |
| 3903 | vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, |
| 3904 | &semaphore); |
| 3905 | |
| 3906 | VkCommandPool command_pool; |
| 3907 | VkCommandPoolCreateInfo pool_create_info{}; |
| 3908 | pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO; |
| 3909 | pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_; |
| 3910 | pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT; |
| 3911 | vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, |
| 3912 | &command_pool); |
| 3913 | |
| 3914 | VkCommandBuffer command_buffer[2]; |
| 3915 | VkCommandBufferAllocateInfo command_buffer_allocate_info{}; |
| 3916 | command_buffer_allocate_info.sType = |
| 3917 | VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO; |
| 3918 | command_buffer_allocate_info.commandPool = command_pool; |
| 3919 | command_buffer_allocate_info.commandBufferCount = 2; |
| 3920 | command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY; |
| 3921 | vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, |
| 3922 | command_buffer); |
| 3923 | |
| 3924 | VkQueue queue = VK_NULL_HANDLE; |
| 3925 | vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, |
| 3926 | 1, &queue); |
| 3927 | |
| 3928 | { |
| 3929 | VkCommandBufferBeginInfo begin_info{}; |
| 3930 | begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO; |
| 3931 | vkBeginCommandBuffer(command_buffer[0], &begin_info); |
| 3932 | |
| 3933 | vkCmdPipelineBarrier(command_buffer[0], |
| 3934 | VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, |
| 3935 | VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, nullptr, |
| 3936 | 0, nullptr, 0, nullptr); |
| 3937 | |
| 3938 | VkViewport viewport{}; |
| 3939 | viewport.maxDepth = 1.0f; |
| 3940 | viewport.minDepth = 0.0f; |
| 3941 | viewport.width = 512; |
| 3942 | viewport.height = 512; |
| 3943 | viewport.x = 0; |
| 3944 | viewport.y = 0; |
| 3945 | vkCmdSetViewport(command_buffer[0], 0, 1, &viewport); |
| 3946 | vkEndCommandBuffer(command_buffer[0]); |
| 3947 | } |
| 3948 | { |
| 3949 | VkCommandBufferBeginInfo begin_info{}; |
| 3950 | begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO; |
| 3951 | vkBeginCommandBuffer(command_buffer[1], &begin_info); |
| 3952 | |
| 3953 | VkViewport viewport{}; |
| 3954 | viewport.maxDepth = 1.0f; |
| 3955 | viewport.minDepth = 0.0f; |
| 3956 | viewport.width = 512; |
| 3957 | viewport.height = 512; |
| 3958 | viewport.x = 0; |
| 3959 | viewport.y = 0; |
| 3960 | vkCmdSetViewport(command_buffer[1], 0, 1, &viewport); |
| 3961 | vkEndCommandBuffer(command_buffer[1]); |
| 3962 | } |
| 3963 | { |
| 3964 | VkSubmitInfo submit_info{}; |
| 3965 | submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO; |
| 3966 | submit_info.commandBufferCount = 1; |
| 3967 | submit_info.pCommandBuffers = &command_buffer[0]; |
| 3968 | submit_info.signalSemaphoreCount = 1; |
| 3969 | submit_info.pSignalSemaphores = &semaphore; |
| 3970 | vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE); |
| 3971 | } |
| 3972 | { |
| 3973 | VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT}; |
| 3974 | VkSubmitInfo submit_info{}; |
| 3975 | submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO; |
| 3976 | submit_info.commandBufferCount = 1; |
| 3977 | submit_info.pCommandBuffers = &command_buffer[1]; |
| 3978 | submit_info.waitSemaphoreCount = 1; |
| 3979 | submit_info.pWaitSemaphores = &semaphore; |
| 3980 | submit_info.pWaitDstStageMask = flags; |
| 3981 | vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence); |
| 3982 | } |
| 3983 | |
| 3984 | vkQueueWaitIdle(m_device->m_queue); |
| 3985 | |
| 3986 | vkDestroyFence(m_device->device(), fence, nullptr); |
| 3987 | vkDestroySemaphore(m_device->device(), semaphore, nullptr); |
| 3988 | vkFreeCommandBuffers(m_device->device(), command_pool, 2, |
| 3989 | &command_buffer[0]); |
| 3990 | vkDestroyCommandPool(m_device->device(), command_pool, NULL); |
| 3991 | |
| 3992 | m_errorMonitor->VerifyNotFound(); |
| 3993 | } |
| 3994 | |
| 3995 | // This is a positive test. No errors should be generated. |
| 3996 | TEST_F(VkLayerTest, |
| 3997 | TwoQueueSubmitsSeparateQueuesWithSemaphoreAndOneFenceTwoWFF) { |
| 3998 | |
| 3999 | TEST_DESCRIPTION( |
| 4000 | "Two command buffers, each in a separate QueueSubmit call " |
| 4001 | "submitted on separate queues, the second having a fence" |
| 4002 | "followed by two consecutive WaitForFences calls on the same fence."); |
| 4003 | |
Dustin Graves | 4845814 | 2016-04-29 16:11:55 -0600 | [diff] [blame] | 4004 | if ((m_device->queue_props.empty()) || |
| 4005 | (m_device->queue_props[0].queueCount < 2)) |
Tony Barbour | dc18b26 | 2016-04-22 14:49:48 -0600 | [diff] [blame] | 4006 | return; |
| 4007 | |
Mark Lobodzinski | c808d44 | 2016-04-14 10:57:23 -0600 | [diff] [blame] | 4008 | m_errorMonitor->ExpectSuccess(); |
| 4009 | |
| 4010 | VkFence fence; |
| 4011 | VkFenceCreateInfo fence_create_info{}; |
| 4012 | fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO; |
| 4013 | vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence); |
| 4014 | |
| 4015 | VkSemaphore semaphore; |
| 4016 | VkSemaphoreCreateInfo semaphore_create_info{}; |
| 4017 | semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO; |
| 4018 | vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, |
| 4019 | &semaphore); |
| 4020 | |
| 4021 | VkCommandPool command_pool; |
| 4022 | VkCommandPoolCreateInfo pool_create_info{}; |
| 4023 | pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO; |
| 4024 | pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_; |
| 4025 | pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT; |
| 4026 | vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, |
| 4027 | &command_pool); |
| 4028 | |
| 4029 | VkCommandBuffer command_buffer[2]; |
| 4030 | VkCommandBufferAllocateInfo command_buffer_allocate_info{}; |
| 4031 | command_buffer_allocate_info.sType = |
| 4032 | VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO; |
| 4033 | command_buffer_allocate_info.commandPool = command_pool; |
| 4034 | command_buffer_allocate_info.commandBufferCount = 2; |
| 4035 | command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY; |
| 4036 | vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, |
| 4037 | command_buffer); |
| 4038 | |
| 4039 | VkQueue queue = VK_NULL_HANDLE; |
| 4040 | vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, |
| 4041 | 1, &queue); |
| 4042 | |
| 4043 | { |
| 4044 | VkCommandBufferBeginInfo begin_info{}; |
| 4045 | begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO; |
| 4046 | vkBeginCommandBuffer(command_buffer[0], &begin_info); |
| 4047 | |
| 4048 | vkCmdPipelineBarrier(command_buffer[0], |
| 4049 | VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, |
| 4050 | VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, nullptr, |
| 4051 | 0, nullptr, 0, nullptr); |
| 4052 | |
| 4053 | VkViewport viewport{}; |
| 4054 | viewport.maxDepth = 1.0f; |
| 4055 | viewport.minDepth = 0.0f; |
| 4056 | viewport.width = 512; |
| 4057 | viewport.height = 512; |
| 4058 | viewport.x = 0; |
| 4059 | viewport.y = 0; |
| 4060 | vkCmdSetViewport(command_buffer[0], 0, 1, &viewport); |
| 4061 | vkEndCommandBuffer(command_buffer[0]); |
| 4062 | } |
| 4063 | { |
| 4064 | VkCommandBufferBeginInfo begin_info{}; |
| 4065 | begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO; |
| 4066 | vkBeginCommandBuffer(command_buffer[1], &begin_info); |
| 4067 | |
| 4068 | VkViewport viewport{}; |
| 4069 | viewport.maxDepth = 1.0f; |
| 4070 | viewport.minDepth = 0.0f; |
| 4071 | viewport.width = 512; |
| 4072 | viewport.height = 512; |
| 4073 | viewport.x = 0; |
| 4074 | viewport.y = 0; |
| 4075 | vkCmdSetViewport(command_buffer[1], 0, 1, &viewport); |
| 4076 | vkEndCommandBuffer(command_buffer[1]); |
| 4077 | } |
| 4078 | { |
| 4079 | VkSubmitInfo submit_info{}; |
| 4080 | submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO; |
| 4081 | submit_info.commandBufferCount = 1; |
| 4082 | submit_info.pCommandBuffers = &command_buffer[0]; |
| 4083 | submit_info.signalSemaphoreCount = 1; |
| 4084 | submit_info.pSignalSemaphores = &semaphore; |
| 4085 | vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE); |
| 4086 | } |
| 4087 | { |
| 4088 | VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT}; |
| 4089 | VkSubmitInfo submit_info{}; |
| 4090 | submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO; |
| 4091 | submit_info.commandBufferCount = 1; |
| 4092 | submit_info.pCommandBuffers = &command_buffer[1]; |
| 4093 | submit_info.waitSemaphoreCount = 1; |
| 4094 | submit_info.pWaitSemaphores = &semaphore; |
| 4095 | submit_info.pWaitDstStageMask = flags; |
| 4096 | vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence); |
| 4097 | } |
| 4098 | |
| 4099 | vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX); |
| 4100 | vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX); |
| 4101 | |
| 4102 | vkDestroyFence(m_device->device(), fence, nullptr); |
| 4103 | vkDestroySemaphore(m_device->device(), semaphore, nullptr); |
| 4104 | vkFreeCommandBuffers(m_device->device(), command_pool, 2, |
| 4105 | &command_buffer[0]); |
| 4106 | vkDestroyCommandPool(m_device->device(), command_pool, NULL); |
| 4107 | |
| 4108 | m_errorMonitor->VerifyNotFound(); |
| 4109 | } |
| 4110 | |
Chris Forbes | 0f8126b | 2016-06-20 17:48:22 +1200 | [diff] [blame] | 4111 | #if 0 |
| 4112 | TEST_F(VkLayerTest, TwoQueuesEnsureCorrectRetirementWithWorkStolen) { |
| 4113 | if ((m_device->queue_props.empty()) || |
| 4114 | (m_device->queue_props[0].queueCount < 2)) { |
| 4115 | printf("Test requires two queues, skipping\n"); |
| 4116 | return; |
| 4117 | } |
| 4118 | |
| 4119 | VkResult err; |
| 4120 | |
| 4121 | m_errorMonitor->ExpectSuccess(); |
| 4122 | |
| 4123 | VkQueue q0 = m_device->m_queue; |
| 4124 | VkQueue q1 = nullptr; |
| 4125 | vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &q1); |
| 4126 | ASSERT_NE(q1, nullptr); |
| 4127 | |
| 4128 | // An (empty) command buffer. We must have work in the first submission -- |
| 4129 | // the layer treats unfenced work differently from fenced work. |
| 4130 | VkCommandPoolCreateInfo cpci = { VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO, nullptr, 0, 0 }; |
| 4131 | VkCommandPool pool; |
| 4132 | err = vkCreateCommandPool(m_device->device(), &cpci, nullptr, &pool); |
| 4133 | ASSERT_VK_SUCCESS(err); |
| 4134 | VkCommandBufferAllocateInfo cbai = { VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO, nullptr, |
| 4135 | pool, VK_COMMAND_BUFFER_LEVEL_PRIMARY, 1 |
| 4136 | }; |
| 4137 | VkCommandBuffer cb; |
| 4138 | err = vkAllocateCommandBuffers(m_device->device(), &cbai, &cb); |
| 4139 | ASSERT_VK_SUCCESS(err); |
| 4140 | VkCommandBufferBeginInfo cbbi = { VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO, nullptr, |
| 4141 | 0, nullptr |
| 4142 | }; |
| 4143 | err = vkBeginCommandBuffer(cb, &cbbi); |
| 4144 | ASSERT_VK_SUCCESS(err); |
| 4145 | err = vkEndCommandBuffer(cb); |
| 4146 | ASSERT_VK_SUCCESS(err); |
| 4147 | |
| 4148 | // A semaphore |
| 4149 | VkSemaphoreCreateInfo sci = { VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO, nullptr, 0 }; |
| 4150 | VkSemaphore s; |
| 4151 | err = vkCreateSemaphore(m_device->device(), &sci, nullptr, &s); |
| 4152 | ASSERT_VK_SUCCESS(err); |
| 4153 | |
| 4154 | // First submission, to q0 |
| 4155 | VkSubmitInfo s0 = { |
| 4156 | VK_STRUCTURE_TYPE_SUBMIT_INFO, nullptr, |
| 4157 | 0, nullptr, nullptr, |
| 4158 | 1, &cb, |
| 4159 | 1, &s |
| 4160 | }; |
| 4161 | |
| 4162 | err = vkQueueSubmit(q0, 1, &s0, VK_NULL_HANDLE); |
| 4163 | ASSERT_VK_SUCCESS(err); |
| 4164 | |
| 4165 | // Second submission, to q1, waiting on s |
| 4166 | VkFlags waitmask = VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT; // doesn't really matter what this value is. |
| 4167 | VkSubmitInfo s1 = { |
| 4168 | VK_STRUCTURE_TYPE_SUBMIT_INFO, nullptr, |
| 4169 | 1, &s, &waitmask, |
| 4170 | 0, nullptr, |
| 4171 | 0, nullptr |
| 4172 | }; |
| 4173 | |
| 4174 | err = vkQueueSubmit(q1, 1, &s1, VK_NULL_HANDLE); |
| 4175 | ASSERT_VK_SUCCESS(err); |
| 4176 | |
| 4177 | // Wait for q0 idle |
| 4178 | err = vkQueueWaitIdle(q0); |
| 4179 | ASSERT_VK_SUCCESS(err); |
| 4180 | |
| 4181 | // Command buffer should have been completed (it was on q0); reset the pool. |
| 4182 | vkFreeCommandBuffers(m_device->device(), pool, 1, &cb); |
| 4183 | |
| 4184 | m_errorMonitor->VerifyNotFound(); |
| 4185 | |
| 4186 | // Force device completely idle and clean up resources |
| 4187 | vkDeviceWaitIdle(m_device->device()); |
| 4188 | vkDestroyCommandPool(m_device->device(), pool, nullptr); |
| 4189 | vkDestroySemaphore(m_device->device(), s, nullptr); |
| 4190 | } |
| 4191 | #endif |
| 4192 | |
Mark Lobodzinski | c808d44 | 2016-04-14 10:57:23 -0600 | [diff] [blame] | 4193 | // This is a positive test. No errors should be generated. |
| 4194 | TEST_F(VkLayerTest, TwoQueueSubmitsSeparateQueuesWithSemaphoreAndOneFence) { |
| 4195 | |
| 4196 | TEST_DESCRIPTION("Two command buffers, each in a separate QueueSubmit call " |
| 4197 | "submitted on separate queues, the second having a fence, " |
| 4198 | "followed by a WaitForFences call."); |
| 4199 | |
Dustin Graves | 4845814 | 2016-04-29 16:11:55 -0600 | [diff] [blame] | 4200 | if ((m_device->queue_props.empty()) || |
| 4201 | (m_device->queue_props[0].queueCount < 2)) |
Tony Barbour | dc18b26 | 2016-04-22 14:49:48 -0600 | [diff] [blame] | 4202 | return; |
| 4203 | |
Mark Lobodzinski | c808d44 | 2016-04-14 10:57:23 -0600 | [diff] [blame] | 4204 | m_errorMonitor->ExpectSuccess(); |
| 4205 | |
| 4206 | VkFence fence; |
| 4207 | VkFenceCreateInfo fence_create_info{}; |
| 4208 | fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO; |
| 4209 | vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence); |
| 4210 | |
| 4211 | VkSemaphore semaphore; |
| 4212 | VkSemaphoreCreateInfo semaphore_create_info{}; |
| 4213 | semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO; |
| 4214 | vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, |
| 4215 | &semaphore); |
| 4216 | |
| 4217 | VkCommandPool command_pool; |
| 4218 | VkCommandPoolCreateInfo pool_create_info{}; |
| 4219 | pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO; |
| 4220 | pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_; |
| 4221 | pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT; |
| 4222 | vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, |
| 4223 | &command_pool); |
| 4224 | |
| 4225 | VkCommandBuffer command_buffer[2]; |
| 4226 | VkCommandBufferAllocateInfo command_buffer_allocate_info{}; |
| 4227 | command_buffer_allocate_info.sType = |
| 4228 | VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO; |
| 4229 | command_buffer_allocate_info.commandPool = command_pool; |
| 4230 | command_buffer_allocate_info.commandBufferCount = 2; |
| 4231 | command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY; |
| 4232 | vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, |
| 4233 | command_buffer); |
| 4234 | |
| 4235 | VkQueue queue = VK_NULL_HANDLE; |
| 4236 | vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, |
| 4237 | 1, &queue); |
| 4238 | |
| 4239 | |
| 4240 | { |
| 4241 | VkCommandBufferBeginInfo begin_info{}; |
| 4242 | begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO; |
| 4243 | vkBeginCommandBuffer(command_buffer[0], &begin_info); |
| 4244 | |
| 4245 | vkCmdPipelineBarrier(command_buffer[0], |
| 4246 | VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, |
| 4247 | VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, nullptr, |
| 4248 | 0, nullptr, 0, nullptr); |
| 4249 | |
| 4250 | VkViewport viewport{}; |
| 4251 | viewport.maxDepth = 1.0f; |
| 4252 | viewport.minDepth = 0.0f; |
| 4253 | viewport.width = 512; |
| 4254 | viewport.height = 512; |
| 4255 | viewport.x = 0; |
| 4256 | viewport.y = 0; |
| 4257 | vkCmdSetViewport(command_buffer[0], 0, 1, &viewport); |
| 4258 | vkEndCommandBuffer(command_buffer[0]); |
| 4259 | } |
| 4260 | { |
| 4261 | VkCommandBufferBeginInfo begin_info{}; |
| 4262 | begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO; |
| 4263 | vkBeginCommandBuffer(command_buffer[1], &begin_info); |
| 4264 | |
| 4265 | VkViewport viewport{}; |
| 4266 | viewport.maxDepth = 1.0f; |
| 4267 | viewport.minDepth = 0.0f; |
| 4268 | viewport.width = 512; |
| 4269 | viewport.height = 512; |
| 4270 | viewport.x = 0; |
| 4271 | viewport.y = 0; |
| 4272 | vkCmdSetViewport(command_buffer[1], 0, 1, &viewport); |
| 4273 | vkEndCommandBuffer(command_buffer[1]); |
| 4274 | } |
| 4275 | { |
| 4276 | VkSubmitInfo submit_info{}; |
| 4277 | submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO; |
| 4278 | submit_info.commandBufferCount = 1; |
| 4279 | submit_info.pCommandBuffers = &command_buffer[0]; |
| 4280 | submit_info.signalSemaphoreCount = 1; |
| 4281 | submit_info.pSignalSemaphores = &semaphore; |
| 4282 | vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE); |
| 4283 | } |
| 4284 | { |
| 4285 | VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT}; |
| 4286 | VkSubmitInfo submit_info{}; |
| 4287 | submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO; |
| 4288 | submit_info.commandBufferCount = 1; |
| 4289 | submit_info.pCommandBuffers = &command_buffer[1]; |
| 4290 | submit_info.waitSemaphoreCount = 1; |
| 4291 | submit_info.pWaitSemaphores = &semaphore; |
| 4292 | submit_info.pWaitDstStageMask = flags; |
| 4293 | vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence); |
| 4294 | } |
| 4295 | |
| 4296 | vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX); |
| 4297 | |
| 4298 | vkDestroyFence(m_device->device(), fence, nullptr); |
| 4299 | vkDestroySemaphore(m_device->device(), semaphore, nullptr); |
| 4300 | vkFreeCommandBuffers(m_device->device(), command_pool, 2, |
| 4301 | &command_buffer[0]); |
| 4302 | vkDestroyCommandPool(m_device->device(), command_pool, NULL); |
| 4303 | |
| 4304 | m_errorMonitor->VerifyNotFound(); |
| 4305 | } |
| 4306 | |
| 4307 | // This is a positive test. No errors should be generated. |
| 4308 | TEST_F(VkLayerTest, TwoQueueSubmitsOneQueueWithSemaphoreAndOneFence) { |
| 4309 | |
| 4310 | TEST_DESCRIPTION("Two command buffers, each in a separate QueueSubmit call " |
| 4311 | "on the same queue, sharing a signal/wait semaphore, the " |
| 4312 | "second having a fence, " |
| 4313 | "followed by a WaitForFences call."); |
| 4314 | |
| 4315 | m_errorMonitor->ExpectSuccess(); |
| 4316 | |
| 4317 | VkFence fence; |
| 4318 | VkFenceCreateInfo fence_create_info{}; |
| 4319 | fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO; |
| 4320 | vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence); |
| 4321 | |
| 4322 | VkSemaphore semaphore; |
| 4323 | VkSemaphoreCreateInfo semaphore_create_info{}; |
| 4324 | semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO; |
| 4325 | vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, |
| 4326 | &semaphore); |
| 4327 | |
| 4328 | VkCommandPool command_pool; |
| 4329 | VkCommandPoolCreateInfo pool_create_info{}; |
| 4330 | pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO; |
| 4331 | pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_; |
| 4332 | pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT; |
| 4333 | vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, |
| 4334 | &command_pool); |
| 4335 | |
| 4336 | VkCommandBuffer command_buffer[2]; |
| 4337 | VkCommandBufferAllocateInfo command_buffer_allocate_info{}; |
| 4338 | command_buffer_allocate_info.sType = |
| 4339 | VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO; |
| 4340 | command_buffer_allocate_info.commandPool = command_pool; |
| 4341 | command_buffer_allocate_info.commandBufferCount = 2; |
| 4342 | command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY; |
| 4343 | vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, |
| 4344 | command_buffer); |
| 4345 | |
| 4346 | { |
| 4347 | VkCommandBufferBeginInfo begin_info{}; |
| 4348 | begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO; |
| 4349 | vkBeginCommandBuffer(command_buffer[0], &begin_info); |
| 4350 | |
| 4351 | vkCmdPipelineBarrier(command_buffer[0], |
| 4352 | VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, |
| 4353 | VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, nullptr, |
| 4354 | 0, nullptr, 0, nullptr); |
| 4355 | |
| 4356 | VkViewport viewport{}; |
| 4357 | viewport.maxDepth = 1.0f; |
| 4358 | viewport.minDepth = 0.0f; |
| 4359 | viewport.width = 512; |
| 4360 | viewport.height = 512; |
| 4361 | viewport.x = 0; |
| 4362 | viewport.y = 0; |
| 4363 | vkCmdSetViewport(command_buffer[0], 0, 1, &viewport); |
| 4364 | vkEndCommandBuffer(command_buffer[0]); |
| 4365 | } |
| 4366 | { |
| 4367 | VkCommandBufferBeginInfo begin_info{}; |
| 4368 | begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO; |
| 4369 | vkBeginCommandBuffer(command_buffer[1], &begin_info); |
| 4370 | |
| 4371 | VkViewport viewport{}; |
| 4372 | viewport.maxDepth = 1.0f; |
| 4373 | viewport.minDepth = 0.0f; |
| 4374 | viewport.width = 512; |
| 4375 | viewport.height = 512; |
| 4376 | viewport.x = 0; |
| 4377 | viewport.y = 0; |
| 4378 | vkCmdSetViewport(command_buffer[1], 0, 1, &viewport); |
| 4379 | vkEndCommandBuffer(command_buffer[1]); |
| 4380 | } |
| 4381 | { |
| 4382 | VkSubmitInfo submit_info{}; |
| 4383 | submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO; |
| 4384 | submit_info.commandBufferCount = 1; |
| 4385 | submit_info.pCommandBuffers = &command_buffer[0]; |
| 4386 | submit_info.signalSemaphoreCount = 1; |
| 4387 | submit_info.pSignalSemaphores = &semaphore; |
| 4388 | vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE); |
| 4389 | } |
| 4390 | { |
| 4391 | VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT}; |
| 4392 | VkSubmitInfo submit_info{}; |
| 4393 | submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO; |
| 4394 | submit_info.commandBufferCount = 1; |
| 4395 | submit_info.pCommandBuffers = &command_buffer[1]; |
| 4396 | submit_info.waitSemaphoreCount = 1; |
| 4397 | submit_info.pWaitSemaphores = &semaphore; |
| 4398 | submit_info.pWaitDstStageMask = flags; |
| 4399 | vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence); |
| 4400 | } |
| 4401 | |
| 4402 | vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX); |
| 4403 | |
| 4404 | vkDestroyFence(m_device->device(), fence, nullptr); |
| 4405 | vkDestroySemaphore(m_device->device(), semaphore, nullptr); |
| 4406 | vkFreeCommandBuffers(m_device->device(), command_pool, 2, |
| 4407 | &command_buffer[0]); |
| 4408 | vkDestroyCommandPool(m_device->device(), command_pool, NULL); |
| 4409 | |
| 4410 | m_errorMonitor->VerifyNotFound(); |
| 4411 | } |
| 4412 | |
| 4413 | // This is a positive test. No errors should be generated. |
| 4414 | TEST_F(VkLayerTest, TwoQueueSubmitsOneQueueNullQueueSubmitWithFence) { |
| 4415 | |
| 4416 | TEST_DESCRIPTION( |
| 4417 | "Two command buffers, each in a separate QueueSubmit call " |
| 4418 | "on the same queue, no fences, followed by a third QueueSubmit with NO " |
| 4419 | "SubmitInfos but with a fence, followed by a WaitForFences call."); |
| 4420 | |
| 4421 | m_errorMonitor->ExpectSuccess(); |
| 4422 | |
| 4423 | VkFence fence; |
| 4424 | VkFenceCreateInfo fence_create_info{}; |
| 4425 | fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO; |
| 4426 | vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence); |
| 4427 | |
| 4428 | VkCommandPool command_pool; |
| 4429 | VkCommandPoolCreateInfo pool_create_info{}; |
| 4430 | pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO; |
| 4431 | pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_; |
| 4432 | pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT; |
| 4433 | vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, |
| 4434 | &command_pool); |
| 4435 | |
| 4436 | VkCommandBuffer command_buffer[2]; |
| 4437 | VkCommandBufferAllocateInfo command_buffer_allocate_info{}; |
| 4438 | command_buffer_allocate_info.sType = |
| 4439 | VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO; |
| 4440 | command_buffer_allocate_info.commandPool = command_pool; |
| 4441 | command_buffer_allocate_info.commandBufferCount = 2; |
| 4442 | command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY; |
| 4443 | vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, |
| 4444 | command_buffer); |
| 4445 | |
| 4446 | { |
| 4447 | VkCommandBufferBeginInfo begin_info{}; |
| 4448 | begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO; |
| 4449 | vkBeginCommandBuffer(command_buffer[0], &begin_info); |
| 4450 | |
| 4451 | vkCmdPipelineBarrier(command_buffer[0], |
| 4452 | VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, |
| 4453 | VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, nullptr, |
| 4454 | 0, nullptr, 0, nullptr); |
| 4455 | |
| 4456 | VkViewport viewport{}; |
| 4457 | viewport.maxDepth = 1.0f; |
| 4458 | viewport.minDepth = 0.0f; |
| 4459 | viewport.width = 512; |
| 4460 | viewport.height = 512; |
| 4461 | viewport.x = 0; |
| 4462 | viewport.y = 0; |
| 4463 | vkCmdSetViewport(command_buffer[0], 0, 1, &viewport); |
| 4464 | vkEndCommandBuffer(command_buffer[0]); |
| 4465 | } |
| 4466 | { |
| 4467 | VkCommandBufferBeginInfo begin_info{}; |
| 4468 | begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO; |
| 4469 | vkBeginCommandBuffer(command_buffer[1], &begin_info); |
| 4470 | |
| 4471 | VkViewport viewport{}; |
| 4472 | viewport.maxDepth = 1.0f; |
| 4473 | viewport.minDepth = 0.0f; |
| 4474 | viewport.width = 512; |
| 4475 | viewport.height = 512; |
| 4476 | viewport.x = 0; |
| 4477 | viewport.y = 0; |
| 4478 | vkCmdSetViewport(command_buffer[1], 0, 1, &viewport); |
| 4479 | vkEndCommandBuffer(command_buffer[1]); |
| 4480 | } |
| 4481 | { |
| 4482 | VkSubmitInfo submit_info{}; |
| 4483 | submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO; |
| 4484 | submit_info.commandBufferCount = 1; |
| 4485 | submit_info.pCommandBuffers = &command_buffer[0]; |
| 4486 | submit_info.signalSemaphoreCount = 0; |
| 4487 | submit_info.pSignalSemaphores = VK_NULL_HANDLE; |
| 4488 | vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE); |
| 4489 | } |
| 4490 | { |
| 4491 | VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT}; |
| 4492 | VkSubmitInfo submit_info{}; |
| 4493 | submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO; |
| 4494 | submit_info.commandBufferCount = 1; |
| 4495 | submit_info.pCommandBuffers = &command_buffer[1]; |
| 4496 | submit_info.waitSemaphoreCount = 0; |
| 4497 | submit_info.pWaitSemaphores = VK_NULL_HANDLE; |
| 4498 | submit_info.pWaitDstStageMask = flags; |
| 4499 | vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE); |
| 4500 | } |
| 4501 | |
| 4502 | vkQueueSubmit(m_device->m_queue, 0, NULL, fence); |
| 4503 | |
Mike Stroyan | cd1c3e5 | 2016-06-21 09:20:01 -0600 | [diff] [blame^] | 4504 | VkResult err = |
| 4505 | vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX); |
| 4506 | ASSERT_VK_SUCCESS(err); |
Mark Lobodzinski | c808d44 | 2016-04-14 10:57:23 -0600 | [diff] [blame] | 4507 | |
| 4508 | vkDestroyFence(m_device->device(), fence, nullptr); |
| 4509 | vkFreeCommandBuffers(m_device->device(), command_pool, 2, |
| 4510 | &command_buffer[0]); |
| 4511 | vkDestroyCommandPool(m_device->device(), command_pool, NULL); |
| 4512 | |
| 4513 | m_errorMonitor->VerifyNotFound(); |
| 4514 | } |
| 4515 | |
| 4516 | // This is a positive test. No errors should be generated. |
| 4517 | TEST_F(VkLayerTest, TwoQueueSubmitsOneQueueOneFence) { |
| 4518 | |
| 4519 | TEST_DESCRIPTION("Two command buffers, each in a separate QueueSubmit call " |
| 4520 | "on the same queue, the second having a fence, followed " |
| 4521 | "by a WaitForFences call."); |
| 4522 | |
| 4523 | m_errorMonitor->ExpectSuccess(); |
| 4524 | |
| 4525 | VkFence fence; |
| 4526 | VkFenceCreateInfo fence_create_info{}; |
| 4527 | fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO; |
| 4528 | vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence); |
| 4529 | |
| 4530 | VkCommandPool command_pool; |
| 4531 | VkCommandPoolCreateInfo pool_create_info{}; |
| 4532 | pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO; |
| 4533 | pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_; |
| 4534 | pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT; |
| 4535 | vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, |
| 4536 | &command_pool); |
| 4537 | |
| 4538 | VkCommandBuffer command_buffer[2]; |
| 4539 | VkCommandBufferAllocateInfo command_buffer_allocate_info{}; |
| 4540 | command_buffer_allocate_info.sType = |
| 4541 | VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO; |
| 4542 | command_buffer_allocate_info.commandPool = command_pool; |
| 4543 | command_buffer_allocate_info.commandBufferCount = 2; |
| 4544 | command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY; |
| 4545 | vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, |
| 4546 | command_buffer); |
| 4547 | |
| 4548 | { |
| 4549 | VkCommandBufferBeginInfo begin_info{}; |
| 4550 | begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO; |
| 4551 | vkBeginCommandBuffer(command_buffer[0], &begin_info); |
| 4552 | |
| 4553 | vkCmdPipelineBarrier(command_buffer[0], |
| 4554 | VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, |
| 4555 | VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, nullptr, |
| 4556 | 0, nullptr, 0, nullptr); |
| 4557 | |
| 4558 | VkViewport viewport{}; |
| 4559 | viewport.maxDepth = 1.0f; |
| 4560 | viewport.minDepth = 0.0f; |
| 4561 | viewport.width = 512; |
| 4562 | viewport.height = 512; |
| 4563 | viewport.x = 0; |
| 4564 | viewport.y = 0; |
| 4565 | vkCmdSetViewport(command_buffer[0], 0, 1, &viewport); |
| 4566 | vkEndCommandBuffer(command_buffer[0]); |
| 4567 | } |
| 4568 | { |
| 4569 | VkCommandBufferBeginInfo begin_info{}; |
| 4570 | begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO; |
| 4571 | vkBeginCommandBuffer(command_buffer[1], &begin_info); |
| 4572 | |
| 4573 | VkViewport viewport{}; |
| 4574 | viewport.maxDepth = 1.0f; |
| 4575 | viewport.minDepth = 0.0f; |
| 4576 | viewport.width = 512; |
| 4577 | viewport.height = 512; |
| 4578 | viewport.x = 0; |
| 4579 | viewport.y = 0; |
| 4580 | vkCmdSetViewport(command_buffer[1], 0, 1, &viewport); |
| 4581 | vkEndCommandBuffer(command_buffer[1]); |
| 4582 | } |
| 4583 | { |
| 4584 | VkSubmitInfo submit_info{}; |
| 4585 | submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO; |
| 4586 | submit_info.commandBufferCount = 1; |
| 4587 | submit_info.pCommandBuffers = &command_buffer[0]; |
| 4588 | submit_info.signalSemaphoreCount = 0; |
| 4589 | submit_info.pSignalSemaphores = VK_NULL_HANDLE; |
| 4590 | vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE); |
| 4591 | } |
| 4592 | { |
| 4593 | VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT}; |
| 4594 | VkSubmitInfo submit_info{}; |
| 4595 | submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO; |
| 4596 | submit_info.commandBufferCount = 1; |
| 4597 | submit_info.pCommandBuffers = &command_buffer[1]; |
| 4598 | submit_info.waitSemaphoreCount = 0; |
| 4599 | submit_info.pWaitSemaphores = VK_NULL_HANDLE; |
| 4600 | submit_info.pWaitDstStageMask = flags; |
| 4601 | vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence); |
| 4602 | } |
| 4603 | |
| 4604 | vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX); |
| 4605 | |
| 4606 | vkDestroyFence(m_device->device(), fence, nullptr); |
| 4607 | vkFreeCommandBuffers(m_device->device(), command_pool, 2, |
| 4608 | &command_buffer[0]); |
| 4609 | vkDestroyCommandPool(m_device->device(), command_pool, NULL); |
| 4610 | |
| 4611 | m_errorMonitor->VerifyNotFound(); |
| 4612 | } |
| 4613 | |
| 4614 | // This is a positive test. No errors should be generated. |
| 4615 | TEST_F(VkLayerTest, TwoSubmitInfosWithSemaphoreOneQueueSubmitsOneFence) { |
| 4616 | |
| 4617 | TEST_DESCRIPTION( |
| 4618 | "Two command buffers each in a separate SubmitInfo sent in a single " |
| 4619 | "QueueSubmit call followed by a WaitForFences call."); |
| 4620 | |
| 4621 | m_errorMonitor->ExpectSuccess(); |
| 4622 | |
| 4623 | VkFence fence; |
| 4624 | VkFenceCreateInfo fence_create_info{}; |
| 4625 | fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO; |
| 4626 | vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence); |
| 4627 | |
| 4628 | VkSemaphore semaphore; |
| 4629 | VkSemaphoreCreateInfo semaphore_create_info{}; |
| 4630 | semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO; |
| 4631 | vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, |
| 4632 | &semaphore); |
| 4633 | |
| 4634 | VkCommandPool command_pool; |
| 4635 | VkCommandPoolCreateInfo pool_create_info{}; |
| 4636 | pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO; |
| 4637 | pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_; |
| 4638 | pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT; |
| 4639 | vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, |
| 4640 | &command_pool); |
| 4641 | |
| 4642 | VkCommandBuffer command_buffer[2]; |
| 4643 | VkCommandBufferAllocateInfo command_buffer_allocate_info{}; |
| 4644 | command_buffer_allocate_info.sType = |
| 4645 | VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO; |
| 4646 | command_buffer_allocate_info.commandPool = command_pool; |
| 4647 | command_buffer_allocate_info.commandBufferCount = 2; |
| 4648 | command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY; |
| 4649 | vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, |
| 4650 | command_buffer); |
| 4651 | |
| 4652 | { |
| 4653 | VkCommandBufferBeginInfo begin_info{}; |
| 4654 | begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO; |
| 4655 | vkBeginCommandBuffer(command_buffer[0], &begin_info); |
| 4656 | |
| 4657 | vkCmdPipelineBarrier(command_buffer[0], |
| 4658 | VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, |
| 4659 | VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, nullptr, |
| 4660 | 0, nullptr, 0, nullptr); |
| 4661 | |
| 4662 | VkViewport viewport{}; |
| 4663 | viewport.maxDepth = 1.0f; |
| 4664 | viewport.minDepth = 0.0f; |
| 4665 | viewport.width = 512; |
| 4666 | viewport.height = 512; |
| 4667 | viewport.x = 0; |
| 4668 | viewport.y = 0; |
| 4669 | vkCmdSetViewport(command_buffer[0], 0, 1, &viewport); |
| 4670 | vkEndCommandBuffer(command_buffer[0]); |
| 4671 | } |
| 4672 | { |
| 4673 | VkCommandBufferBeginInfo begin_info{}; |
| 4674 | begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO; |
| 4675 | vkBeginCommandBuffer(command_buffer[1], &begin_info); |
| 4676 | |
| 4677 | VkViewport viewport{}; |
| 4678 | viewport.maxDepth = 1.0f; |
| 4679 | viewport.minDepth = 0.0f; |
| 4680 | viewport.width = 512; |
| 4681 | viewport.height = 512; |
| 4682 | viewport.x = 0; |
| 4683 | viewport.y = 0; |
| 4684 | vkCmdSetViewport(command_buffer[1], 0, 1, &viewport); |
| 4685 | vkEndCommandBuffer(command_buffer[1]); |
| 4686 | } |
| 4687 | { |
| 4688 | VkSubmitInfo submit_info[2]; |
| 4689 | VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT}; |
| 4690 | |
| 4691 | submit_info[0].sType = VK_STRUCTURE_TYPE_SUBMIT_INFO; |
| 4692 | submit_info[0].pNext = NULL; |
| 4693 | submit_info[0].commandBufferCount = 1; |
| 4694 | submit_info[0].pCommandBuffers = &command_buffer[0]; |
| 4695 | submit_info[0].signalSemaphoreCount = 1; |
| 4696 | submit_info[0].pSignalSemaphores = &semaphore; |
| 4697 | submit_info[0].waitSemaphoreCount = 0; |
| 4698 | submit_info[0].pWaitSemaphores = NULL; |
| 4699 | submit_info[0].pWaitDstStageMask = 0; |
| 4700 | |
| 4701 | submit_info[1].sType = VK_STRUCTURE_TYPE_SUBMIT_INFO; |
| 4702 | submit_info[1].pNext = NULL; |
| 4703 | submit_info[1].commandBufferCount = 1; |
| 4704 | submit_info[1].pCommandBuffers = &command_buffer[1]; |
| 4705 | submit_info[1].waitSemaphoreCount = 1; |
| 4706 | submit_info[1].pWaitSemaphores = &semaphore; |
| 4707 | submit_info[1].pWaitDstStageMask = flags; |
| 4708 | submit_info[1].signalSemaphoreCount = 0; |
| 4709 | submit_info[1].pSignalSemaphores = NULL; |
| 4710 | vkQueueSubmit(m_device->m_queue, 2, &submit_info[0], fence); |
| 4711 | } |
| 4712 | |
| 4713 | vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX); |
| 4714 | |
| 4715 | vkDestroyFence(m_device->device(), fence, nullptr); |
| 4716 | vkFreeCommandBuffers(m_device->device(), command_pool, 2, |
| 4717 | &command_buffer[0]); |
| 4718 | vkDestroyCommandPool(m_device->device(), command_pool, NULL); |
Tony Barbour | df4c004 | 2016-06-01 15:55:43 -0600 | [diff] [blame] | 4719 | vkDestroySemaphore(m_device->device(), semaphore, nullptr); |
Mark Lobodzinski | c808d44 | 2016-04-14 10:57:23 -0600 | [diff] [blame] | 4720 | |
| 4721 | m_errorMonitor->VerifyNotFound(); |
| 4722 | } |
| 4723 | |
Tobin Ehlis | b1a8799 | 2016-05-25 16:42:47 -0600 | [diff] [blame] | 4724 | TEST_F(VkLayerTest, DynamicDepthBiasNotBound) { |
Tobin Ehlis | a5200ef | 2016-05-03 10:34:08 -0600 | [diff] [blame] | 4725 | TEST_DESCRIPTION( |
Tobin Ehlis | b1a8799 | 2016-05-25 16:42:47 -0600 | [diff] [blame] | 4726 | "Run a simple draw calls to validate failure when Depth Bias dynamic " |
| 4727 | "state is required but not correctly bound."); |
| 4728 | |
| 4729 | // Dynamic depth bias |
| 4730 | m_errorMonitor->SetDesiredFailureMsg( |
| 4731 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 4732 | "Dynamic depth bias state not set for this command buffer"); |
| 4733 | VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, |
| 4734 | BsoFailDepthBias); |
| 4735 | m_errorMonitor->VerifyFound(); |
| 4736 | } |
| 4737 | |
| 4738 | TEST_F(VkLayerTest, DynamicLineWidthNotBound) { |
| 4739 | TEST_DESCRIPTION( |
| 4740 | "Run a simple draw calls to validate failure when Line Width dynamic " |
| 4741 | "state is required but not correctly bound."); |
Tobin Ehlis | a5200ef | 2016-05-03 10:34:08 -0600 | [diff] [blame] | 4742 | |
| 4743 | // Dynamic line width |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 4744 | m_errorMonitor->SetDesiredFailureMsg( |
| 4745 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 4746 | "Dynamic line width state not set for this command buffer"); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 4747 | VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, |
| 4748 | BsoFailLineWidth); |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 4749 | m_errorMonitor->VerifyFound(); |
Tobin Ehlis | b1a8799 | 2016-05-25 16:42:47 -0600 | [diff] [blame] | 4750 | } |
| 4751 | |
| 4752 | TEST_F(VkLayerTest, DynamicViewportNotBound) { |
| 4753 | TEST_DESCRIPTION( |
| 4754 | "Run a simple draw calls to validate failure when Viewport dynamic " |
| 4755 | "state is required but not correctly bound."); |
| 4756 | |
Tobin Ehlis | a5200ef | 2016-05-03 10:34:08 -0600 | [diff] [blame] | 4757 | // Dynamic viewport state |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 4758 | m_errorMonitor->SetDesiredFailureMsg( |
| 4759 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 4760 | "Dynamic viewport state not set for this command buffer"); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 4761 | VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, |
| 4762 | BsoFailViewport); |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 4763 | m_errorMonitor->VerifyFound(); |
Tobin Ehlis | b1a8799 | 2016-05-25 16:42:47 -0600 | [diff] [blame] | 4764 | } |
| 4765 | |
| 4766 | TEST_F(VkLayerTest, DynamicScissorNotBound) { |
| 4767 | TEST_DESCRIPTION( |
| 4768 | "Run a simple draw calls to validate failure when Scissor dynamic " |
| 4769 | "state is required but not correctly bound."); |
| 4770 | |
Tobin Ehlis | a5200ef | 2016-05-03 10:34:08 -0600 | [diff] [blame] | 4771 | // Dynamic scissor state |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 4772 | m_errorMonitor->SetDesiredFailureMsg( |
| 4773 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 4774 | "Dynamic scissor state not set for this command buffer"); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 4775 | VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, |
| 4776 | BsoFailScissor); |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 4777 | m_errorMonitor->VerifyFound(); |
Tobin Ehlis | b1a8799 | 2016-05-25 16:42:47 -0600 | [diff] [blame] | 4778 | } |
| 4779 | |
Tobin Ehlis | 21c8835 | 2016-05-26 06:15:45 -0600 | [diff] [blame] | 4780 | TEST_F(VkLayerTest, DynamiBlendConstantsNotBound) { |
Tobin Ehlis | b1a8799 | 2016-05-25 16:42:47 -0600 | [diff] [blame] | 4781 | TEST_DESCRIPTION( |
Tobin Ehlis | 21c8835 | 2016-05-26 06:15:45 -0600 | [diff] [blame] | 4782 | "Run a simple draw calls to validate failure when Blend Constants " |
| 4783 | "dynamic state is required but not correctly bound."); |
| 4784 | // Dynamic blend constant state |
| 4785 | m_errorMonitor->SetDesiredFailureMsg( |
| 4786 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 4787 | "Dynamic blend constants state not set for this command buffer"); |
| 4788 | VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, |
| 4789 | BsoFailBlend); |
| 4790 | m_errorMonitor->VerifyFound(); |
| 4791 | } |
| 4792 | |
| 4793 | TEST_F(VkLayerTest, DynamicDepthBoundsNotBound) { |
| 4794 | TEST_DESCRIPTION( |
| 4795 | "Run a simple draw calls to validate failure when Depth Bounds dynamic " |
Tobin Ehlis | b1a8799 | 2016-05-25 16:42:47 -0600 | [diff] [blame] | 4796 | "state is required but not correctly bound."); |
Tobin Ehlis | 21c8835 | 2016-05-26 06:15:45 -0600 | [diff] [blame] | 4797 | if (!m_device->phy().features().depthBounds) { |
| 4798 | printf("Device does not support depthBounds test; skipped.\n"); |
| 4799 | return; |
| 4800 | } |
| 4801 | // Dynamic depth bounds |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 4802 | m_errorMonitor->SetDesiredFailureMsg( |
| 4803 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 4804 | "Dynamic depth bounds state not set for this command buffer"); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 4805 | VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, |
| 4806 | BsoFailDepthBounds); |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 4807 | m_errorMonitor->VerifyFound(); |
Tobin Ehlis | b1a8799 | 2016-05-25 16:42:47 -0600 | [diff] [blame] | 4808 | } |
| 4809 | |
| 4810 | TEST_F(VkLayerTest, DynamicStencilReadNotBound) { |
| 4811 | TEST_DESCRIPTION( |
| 4812 | "Run a simple draw calls to validate failure when Stencil Read dynamic " |
| 4813 | "state is required but not correctly bound."); |
Tobin Ehlis | a5200ef | 2016-05-03 10:34:08 -0600 | [diff] [blame] | 4814 | // Dynamic stencil read mask |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 4815 | m_errorMonitor->SetDesiredFailureMsg( |
| 4816 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 4817 | "Dynamic stencil read mask state not set for this command buffer"); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 4818 | VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, |
| 4819 | BsoFailStencilReadMask); |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 4820 | m_errorMonitor->VerifyFound(); |
Tobin Ehlis | b1a8799 | 2016-05-25 16:42:47 -0600 | [diff] [blame] | 4821 | } |
| 4822 | |
| 4823 | TEST_F(VkLayerTest, DynamicStencilWriteNotBound) { |
| 4824 | TEST_DESCRIPTION( |
| 4825 | "Run a simple draw calls to validate failure when Stencil Write dynamic" |
| 4826 | " state is required but not correctly bound."); |
Tobin Ehlis | a5200ef | 2016-05-03 10:34:08 -0600 | [diff] [blame] | 4827 | // Dynamic stencil write mask |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 4828 | m_errorMonitor->SetDesiredFailureMsg( |
| 4829 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 4830 | "Dynamic stencil write mask state not set for this command buffer"); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 4831 | VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, |
| 4832 | BsoFailStencilWriteMask); |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 4833 | m_errorMonitor->VerifyFound(); |
Tobin Ehlis | b1a8799 | 2016-05-25 16:42:47 -0600 | [diff] [blame] | 4834 | } |
| 4835 | |
| 4836 | TEST_F(VkLayerTest, DynamicStencilRefNotBound) { |
| 4837 | TEST_DESCRIPTION( |
| 4838 | "Run a simple draw calls to validate failure when Stencil Ref dynamic " |
| 4839 | "state is required but not correctly bound."); |
Tobin Ehlis | a5200ef | 2016-05-03 10:34:08 -0600 | [diff] [blame] | 4840 | // Dynamic stencil reference |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 4841 | m_errorMonitor->SetDesiredFailureMsg( |
| 4842 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 4843 | "Dynamic stencil reference state not set for this command buffer"); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 4844 | VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, |
| 4845 | BsoFailStencilReference); |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 4846 | m_errorMonitor->VerifyFound(); |
Tobin Ehlis | 963a404 | 2015-09-29 08:18:34 -0600 | [diff] [blame] | 4847 | } |
| 4848 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 4849 | TEST_F(VkLayerTest, CommandBufferTwoSubmits) { |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 4850 | m_errorMonitor->SetDesiredFailureMsg( |
| 4851 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 4852 | "was begun w/ VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT set, but has " |
| 4853 | "been submitted"); |
Tobin Ehlis | 59278bf | 2015-08-18 07:10:58 -0600 | [diff] [blame] | 4854 | |
Tobin Ehlis | 59278bf | 2015-08-18 07:10:58 -0600 | [diff] [blame] | 4855 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 4856 | ASSERT_NO_FATAL_FAILURE(InitViewport()); |
| 4857 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 4858 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 4859 | // We luck out b/c by default the framework creates CB w/ the |
| 4860 | // VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT set |
Tobin Ehlis | 59278bf | 2015-08-18 07:10:58 -0600 | [diff] [blame] | 4861 | BeginCommandBuffer(); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 4862 | m_commandBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color, |
| 4863 | m_stencil_clear_color, NULL); |
Tobin Ehlis | 59278bf | 2015-08-18 07:10:58 -0600 | [diff] [blame] | 4864 | EndCommandBuffer(); |
| 4865 | |
Tobin Ehlis | 59278bf | 2015-08-18 07:10:58 -0600 | [diff] [blame] | 4866 | // Bypass framework since it does the waits automatically |
| 4867 | VkResult err = VK_SUCCESS; |
Courtney Goeltzenleuchter | 806c700 | 2015-10-27 11:22:14 -0600 | [diff] [blame] | 4868 | VkSubmitInfo submit_info; |
Chia-I Wu | f9be13c | 2015-10-26 20:37:06 +0800 | [diff] [blame] | 4869 | submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO; |
| 4870 | submit_info.pNext = NULL; |
Chia-I Wu | d50a7d7 | 2015-10-26 20:48:51 +0800 | [diff] [blame] | 4871 | submit_info.waitSemaphoreCount = 0; |
Courtney Goeltzenleuchter | 806c700 | 2015-10-27 11:22:14 -0600 | [diff] [blame] | 4872 | submit_info.pWaitSemaphores = NULL; |
Jon Ashburn | 7f9716c | 2015-12-30 16:42:50 -0700 | [diff] [blame] | 4873 | submit_info.pWaitDstStageMask = NULL; |
Chia-I Wu | d50a7d7 | 2015-10-26 20:48:51 +0800 | [diff] [blame] | 4874 | submit_info.commandBufferCount = 1; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 4875 | submit_info.pCommandBuffers = &m_commandBuffer->handle(); |
Chia-I Wu | d50a7d7 | 2015-10-26 20:48:51 +0800 | [diff] [blame] | 4876 | submit_info.signalSemaphoreCount = 0; |
Courtney Goeltzenleuchter | 806c700 | 2015-10-27 11:22:14 -0600 | [diff] [blame] | 4877 | submit_info.pSignalSemaphores = NULL; |
| 4878 | |
Chris Forbes | 40028e2 | 2016-06-13 09:59:34 +1200 | [diff] [blame] | 4879 | err = vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 4880 | ASSERT_VK_SUCCESS(err); |
Tobin Ehlis | 59278bf | 2015-08-18 07:10:58 -0600 | [diff] [blame] | 4881 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 4882 | // Cause validation error by re-submitting cmd buffer that should only be |
| 4883 | // submitted once |
Chris Forbes | 40028e2 | 2016-06-13 09:59:34 +1200 | [diff] [blame] | 4884 | err = vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE); |
Tobin Ehlis | 59278bf | 2015-08-18 07:10:58 -0600 | [diff] [blame] | 4885 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 4886 | m_errorMonitor->VerifyFound(); |
Tobin Ehlis | 59278bf | 2015-08-18 07:10:58 -0600 | [diff] [blame] | 4887 | } |
| 4888 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 4889 | TEST_F(VkLayerTest, AllocDescriptorFromEmptyPool) { |
Tobin Ehlis | f93f1e3 | 2015-10-20 16:16:04 -0600 | [diff] [blame] | 4890 | // Initiate Draw w/o a PSO bound |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 4891 | VkResult err; |
Tobin Ehlis | f93f1e3 | 2015-10-20 16:16:04 -0600 | [diff] [blame] | 4892 | |
Courtney Goeltzenleuchter | 7415d5a | 2015-12-09 15:48:16 -0700 | [diff] [blame] | 4893 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 4894 | "Unable to allocate 1 descriptors of " |
| 4895 | "type " |
| 4896 | "VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER "); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 4897 | |
Tobin Ehlis | f93f1e3 | 2015-10-20 16:16:04 -0600 | [diff] [blame] | 4898 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 4899 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
Tobin Ehlis | f93f1e3 | 2015-10-20 16:16:04 -0600 | [diff] [blame] | 4900 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 4901 | // Create Pool w/ 1 Sampler descriptor, but try to alloc Uniform Buffer |
| 4902 | // descriptor from it |
Chia-I Wu | 1b99bb2 | 2015-10-27 19:25:11 +0800 | [diff] [blame] | 4903 | VkDescriptorPoolSize ds_type_count = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 4904 | ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLER; |
| 4905 | ds_type_count.descriptorCount = 1; |
Tobin Ehlis | f93f1e3 | 2015-10-20 16:16:04 -0600 | [diff] [blame] | 4906 | |
| 4907 | VkDescriptorPoolCreateInfo ds_pool_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 4908 | ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO; |
| 4909 | ds_pool_ci.pNext = NULL; |
| 4910 | ds_pool_ci.flags = 0; |
| 4911 | ds_pool_ci.maxSets = 1; |
| 4912 | ds_pool_ci.poolSizeCount = 1; |
| 4913 | ds_pool_ci.pPoolSizes = &ds_type_count; |
Tobin Ehlis | f93f1e3 | 2015-10-20 16:16:04 -0600 | [diff] [blame] | 4914 | |
| 4915 | VkDescriptorPool ds_pool; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 4916 | err = |
| 4917 | vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool); |
Tobin Ehlis | f93f1e3 | 2015-10-20 16:16:04 -0600 | [diff] [blame] | 4918 | ASSERT_VK_SUCCESS(err); |
| 4919 | |
| 4920 | VkDescriptorSetLayoutBinding dsl_binding = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 4921 | dsl_binding.binding = 0; |
| 4922 | dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 4923 | dsl_binding.descriptorCount = 1; |
| 4924 | dsl_binding.stageFlags = VK_SHADER_STAGE_ALL; |
| 4925 | dsl_binding.pImmutableSamplers = NULL; |
Tobin Ehlis | f93f1e3 | 2015-10-20 16:16:04 -0600 | [diff] [blame] | 4926 | |
| 4927 | VkDescriptorSetLayoutCreateInfo ds_layout_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 4928 | ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO; |
| 4929 | ds_layout_ci.pNext = NULL; |
| 4930 | ds_layout_ci.bindingCount = 1; |
| 4931 | ds_layout_ci.pBindings = &dsl_binding; |
Tobin Ehlis | f93f1e3 | 2015-10-20 16:16:04 -0600 | [diff] [blame] | 4932 | |
| 4933 | VkDescriptorSetLayout ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 4934 | err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, |
| 4935 | &ds_layout); |
Tobin Ehlis | f93f1e3 | 2015-10-20 16:16:04 -0600 | [diff] [blame] | 4936 | ASSERT_VK_SUCCESS(err); |
| 4937 | |
| 4938 | VkDescriptorSet descriptorSet; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 4939 | VkDescriptorSetAllocateInfo alloc_info = {}; |
Chia-I Wu | 00ce540 | 2015-11-10 16:21:09 +0800 | [diff] [blame] | 4940 | alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO; |
Jon Ashburn | f19916e | 2016-01-11 13:12:43 -0700 | [diff] [blame] | 4941 | alloc_info.descriptorSetCount = 1; |
Courtney Goeltzenleuchter | bee18a9 | 2015-10-23 14:21:05 -0600 | [diff] [blame] | 4942 | alloc_info.descriptorPool = ds_pool; |
| 4943 | alloc_info.pSetLayouts = &ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 4944 | err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, |
| 4945 | &descriptorSet); |
Tobin Ehlis | f93f1e3 | 2015-10-20 16:16:04 -0600 | [diff] [blame] | 4946 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 4947 | m_errorMonitor->VerifyFound(); |
Tobin Ehlis | f93f1e3 | 2015-10-20 16:16:04 -0600 | [diff] [blame] | 4948 | |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 4949 | vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL); |
| 4950 | vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL); |
Tobin Ehlis | f93f1e3 | 2015-10-20 16:16:04 -0600 | [diff] [blame] | 4951 | } |
| 4952 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 4953 | TEST_F(VkLayerTest, FreeDescriptorFromOneShotPool) { |
| 4954 | VkResult err; |
Tobin Ehlis | e735c69 | 2015-10-08 13:13:50 -0600 | [diff] [blame] | 4955 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 4956 | m_errorMonitor->SetDesiredFailureMsg( |
| 4957 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 4958 | "It is invalid to call vkFreeDescriptorSets() with a pool created " |
| 4959 | "without setting VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT."); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 4960 | |
Tobin Ehlis | e735c69 | 2015-10-08 13:13:50 -0600 | [diff] [blame] | 4961 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 4962 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
Tobin Ehlis | e735c69 | 2015-10-08 13:13:50 -0600 | [diff] [blame] | 4963 | |
Chia-I Wu | 1b99bb2 | 2015-10-27 19:25:11 +0800 | [diff] [blame] | 4964 | VkDescriptorPoolSize ds_type_count = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 4965 | ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 4966 | ds_type_count.descriptorCount = 1; |
Tobin Ehlis | e735c69 | 2015-10-08 13:13:50 -0600 | [diff] [blame] | 4967 | |
| 4968 | VkDescriptorPoolCreateInfo ds_pool_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 4969 | ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO; |
| 4970 | ds_pool_ci.pNext = NULL; |
| 4971 | ds_pool_ci.maxSets = 1; |
| 4972 | ds_pool_ci.poolSizeCount = 1; |
| 4973 | ds_pool_ci.flags = 0; |
| 4974 | // Not specifying VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT means |
| 4975 | // app can only call vkResetDescriptorPool on this pool.; |
| 4976 | ds_pool_ci.pPoolSizes = &ds_type_count; |
Tobin Ehlis | e735c69 | 2015-10-08 13:13:50 -0600 | [diff] [blame] | 4977 | |
| 4978 | VkDescriptorPool ds_pool; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 4979 | err = |
| 4980 | vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool); |
Tobin Ehlis | e735c69 | 2015-10-08 13:13:50 -0600 | [diff] [blame] | 4981 | ASSERT_VK_SUCCESS(err); |
| 4982 | |
| 4983 | VkDescriptorSetLayoutBinding dsl_binding = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 4984 | dsl_binding.binding = 0; |
| 4985 | dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 4986 | dsl_binding.descriptorCount = 1; |
| 4987 | dsl_binding.stageFlags = VK_SHADER_STAGE_ALL; |
| 4988 | dsl_binding.pImmutableSamplers = NULL; |
Tobin Ehlis | e735c69 | 2015-10-08 13:13:50 -0600 | [diff] [blame] | 4989 | |
| 4990 | VkDescriptorSetLayoutCreateInfo ds_layout_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 4991 | ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO; |
| 4992 | ds_layout_ci.pNext = NULL; |
| 4993 | ds_layout_ci.bindingCount = 1; |
| 4994 | ds_layout_ci.pBindings = &dsl_binding; |
Tobin Ehlis | e735c69 | 2015-10-08 13:13:50 -0600 | [diff] [blame] | 4995 | |
| 4996 | VkDescriptorSetLayout ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 4997 | err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, |
| 4998 | &ds_layout); |
Tobin Ehlis | e735c69 | 2015-10-08 13:13:50 -0600 | [diff] [blame] | 4999 | ASSERT_VK_SUCCESS(err); |
| 5000 | |
| 5001 | VkDescriptorSet descriptorSet; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 5002 | VkDescriptorSetAllocateInfo alloc_info = {}; |
Chia-I Wu | 00ce540 | 2015-11-10 16:21:09 +0800 | [diff] [blame] | 5003 | alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO; |
Jon Ashburn | f19916e | 2016-01-11 13:12:43 -0700 | [diff] [blame] | 5004 | alloc_info.descriptorSetCount = 1; |
Courtney Goeltzenleuchter | bee18a9 | 2015-10-23 14:21:05 -0600 | [diff] [blame] | 5005 | alloc_info.descriptorPool = ds_pool; |
| 5006 | alloc_info.pSetLayouts = &ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5007 | err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, |
| 5008 | &descriptorSet); |
Tobin Ehlis | e735c69 | 2015-10-08 13:13:50 -0600 | [diff] [blame] | 5009 | ASSERT_VK_SUCCESS(err); |
| 5010 | |
| 5011 | err = vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptorSet); |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 5012 | m_errorMonitor->VerifyFound(); |
Tobin Ehlis | e735c69 | 2015-10-08 13:13:50 -0600 | [diff] [blame] | 5013 | |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 5014 | vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL); |
| 5015 | vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL); |
Tobin Ehlis | e735c69 | 2015-10-08 13:13:50 -0600 | [diff] [blame] | 5016 | } |
| 5017 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5018 | TEST_F(VkLayerTest, InvalidDescriptorPool) { |
Karl Schultz | bdb7595 | 2016-04-19 11:36:49 -0600 | [diff] [blame] | 5019 | // Attempt to clear Descriptor Pool with bad object. |
| 5020 | // ObjectTracker should catch this. |
| 5021 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 5022 | "Invalid VkDescriptorPool Object 0xbaad6001"); |
Mark Lobodzinski | 02bf89d | 2016-05-10 14:45:13 -0600 | [diff] [blame] | 5023 | uint64_t fake_pool_handle = 0xbaad6001; |
| 5024 | VkDescriptorPool bad_pool = reinterpret_cast<VkDescriptorPool &>(fake_pool_handle); |
| 5025 | vkResetDescriptorPool(device(), bad_pool, 0); |
Karl Schultz | bdb7595 | 2016-04-19 11:36:49 -0600 | [diff] [blame] | 5026 | m_errorMonitor->VerifyFound(); |
Tobin Ehlis | 49eb23d | 2015-05-22 12:38:55 -0600 | [diff] [blame] | 5027 | } |
| 5028 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5029 | TEST_F(VkLayerTest, InvalidDescriptorSet) { |
Karl Schultz | bdb7595 | 2016-04-19 11:36:49 -0600 | [diff] [blame] | 5030 | // Attempt to bind an invalid Descriptor Set to a valid Command Buffer |
| 5031 | // ObjectTracker should catch this. |
Tobin Ehlis | 49eb23d | 2015-05-22 12:38:55 -0600 | [diff] [blame] | 5032 | // Create a valid cmd buffer |
Karl Schultz | bdb7595 | 2016-04-19 11:36:49 -0600 | [diff] [blame] | 5033 | // call vkCmdBindDescriptorSets w/ false Descriptor Set |
Mark Lobodzinski | 02bf89d | 2016-05-10 14:45:13 -0600 | [diff] [blame] | 5034 | |
| 5035 | uint64_t fake_set_handle = 0xbaad6001; |
| 5036 | VkDescriptorSet bad_set = reinterpret_cast<VkDescriptorSet &>(fake_set_handle); |
Karl Schultz | bdb7595 | 2016-04-19 11:36:49 -0600 | [diff] [blame] | 5037 | VkResult err; |
| 5038 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 5039 | "Invalid VkDescriptorSet Object 0xbaad6001"); |
| 5040 | |
| 5041 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 5042 | |
| 5043 | VkDescriptorSetLayoutBinding layout_bindings[1] = {}; |
| 5044 | layout_bindings[0].binding = 0; |
| 5045 | layout_bindings[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 5046 | layout_bindings[0].descriptorCount = 1; |
| 5047 | layout_bindings[0].stageFlags = VK_SHADER_STAGE_VERTEX_BIT; |
| 5048 | layout_bindings[0].pImmutableSamplers = NULL; |
| 5049 | |
| 5050 | VkDescriptorSetLayout descriptor_set_layout; |
| 5051 | VkDescriptorSetLayoutCreateInfo dslci = {}; |
| 5052 | dslci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO; |
| 5053 | dslci.pNext = NULL; |
| 5054 | dslci.bindingCount = 1; |
| 5055 | dslci.pBindings = layout_bindings; |
| 5056 | err = vkCreateDescriptorSetLayout(device(), &dslci, NULL, &descriptor_set_layout); |
Karl Schultz | 5cb2111 | 2016-04-21 17:17:40 -0600 | [diff] [blame] | 5057 | ASSERT_VK_SUCCESS(err); |
Karl Schultz | bdb7595 | 2016-04-19 11:36:49 -0600 | [diff] [blame] | 5058 | |
| 5059 | VkPipelineLayout pipeline_layout; |
| 5060 | VkPipelineLayoutCreateInfo plci = {}; |
| 5061 | plci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO; |
| 5062 | plci.pNext = NULL; |
| 5063 | plci.setLayoutCount = 1; |
| 5064 | plci.pSetLayouts = &descriptor_set_layout; |
| 5065 | err = vkCreatePipelineLayout(device(), &plci, NULL, &pipeline_layout); |
Karl Schultz | 5cb2111 | 2016-04-21 17:17:40 -0600 | [diff] [blame] | 5066 | ASSERT_VK_SUCCESS(err); |
Karl Schultz | bdb7595 | 2016-04-19 11:36:49 -0600 | [diff] [blame] | 5067 | |
| 5068 | BeginCommandBuffer(); |
| 5069 | vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, |
Mark Lobodzinski | 02bf89d | 2016-05-10 14:45:13 -0600 | [diff] [blame] | 5070 | pipeline_layout, 0, 1, &bad_set, 0, NULL); |
Karl Schultz | bdb7595 | 2016-04-19 11:36:49 -0600 | [diff] [blame] | 5071 | m_errorMonitor->VerifyFound(); |
| 5072 | EndCommandBuffer(); |
| 5073 | vkDestroyPipelineLayout(device(), pipeline_layout, NULL); |
| 5074 | vkDestroyDescriptorSetLayout(device(), descriptor_set_layout, NULL); |
Tobin Ehlis | 49eb23d | 2015-05-22 12:38:55 -0600 | [diff] [blame] | 5075 | } |
| 5076 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5077 | TEST_F(VkLayerTest, InvalidDescriptorSetLayout) { |
Karl Schultz | bdb7595 | 2016-04-19 11:36:49 -0600 | [diff] [blame] | 5078 | // Attempt to create a Pipeline Layout with an invalid Descriptor Set Layout. |
| 5079 | // ObjectTracker should catch this. |
Mark Lobodzinski | 02bf89d | 2016-05-10 14:45:13 -0600 | [diff] [blame] | 5080 | uint64_t fake_layout_handle = 0xbaad6001; |
| 5081 | VkDescriptorSetLayout bad_layout = reinterpret_cast<VkDescriptorSetLayout &>(fake_layout_handle); |
Karl Schultz | bdb7595 | 2016-04-19 11:36:49 -0600 | [diff] [blame] | 5082 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 5083 | "Invalid VkDescriptorSetLayout Object 0xbaad6001"); |
| 5084 | |
| 5085 | VkPipelineLayout pipeline_layout; |
| 5086 | VkPipelineLayoutCreateInfo plci = {}; |
| 5087 | plci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO; |
| 5088 | plci.pNext = NULL; |
| 5089 | plci.setLayoutCount = 1; |
| 5090 | plci.pSetLayouts = &bad_layout; |
| 5091 | vkCreatePipelineLayout(device(), &plci, NULL, &pipeline_layout); |
| 5092 | |
| 5093 | m_errorMonitor->VerifyFound(); |
Tobin Ehlis | 49eb23d | 2015-05-22 12:38:55 -0600 | [diff] [blame] | 5094 | } |
| 5095 | |
Mark Mueller | d491441 | 2016-06-13 17:52:06 -0600 | [diff] [blame] | 5096 | TEST_F(VkLayerTest, WriteDescriptorSetIntegrityCheck) { |
| 5097 | TEST_DESCRIPTION("This test verifies some requirements of chapter 13.2.3 of the Vulkan Spec " |
| 5098 | "1) A uniform buffer update must have a valid buffer index." |
| 5099 | "2) When using an array of descriptors in a single WriteDescriptor," |
| 5100 | " the descriptor types and stageflags must all be the same." |
| 5101 | "3) Immutable Sampler state must match across descriptors"); |
| 5102 | |
| 5103 | const char *invalid_BufferInfo_ErrorMessage = |
| 5104 | "vkUpdateDescriptorSets: if pDescriptorWrites[0].descriptorType is VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, " |
| 5105 | "VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC or " |
| 5106 | "VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC, pDescriptorWrites[0].pBufferInfo must not be NULL"; |
| 5107 | const char *stateFlag_ErrorMessage = |
Mark Mueller | 5c838ce | 2016-06-16 09:54:29 -0600 | [diff] [blame] | 5108 | "Attempting write update to descriptor set "; |
Mark Mueller | d491441 | 2016-06-13 17:52:06 -0600 | [diff] [blame] | 5109 | const char *immutable_ErrorMessage = |
Mark Mueller | 5c838ce | 2016-06-16 09:54:29 -0600 | [diff] [blame] | 5110 | "Attempting write update to descriptor set "; |
Mark Mueller | d491441 | 2016-06-13 17:52:06 -0600 | [diff] [blame] | 5111 | |
Mark Mueller | d491441 | 2016-06-13 17:52:06 -0600 | [diff] [blame] | 5112 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_BufferInfo_ErrorMessage); |
| 5113 | |
| 5114 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 5115 | VkDescriptorPoolSize ds_type_count[4] = {}; |
| 5116 | ds_type_count[0].type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 5117 | ds_type_count[0].descriptorCount = 1; |
| 5118 | ds_type_count[1].type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER; |
| 5119 | ds_type_count[1].descriptorCount = 1; |
| 5120 | ds_type_count[2].type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER; |
| 5121 | ds_type_count[2].descriptorCount = 1; |
| 5122 | ds_type_count[3].type = VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT; |
| 5123 | ds_type_count[3].descriptorCount = 1; |
| 5124 | |
| 5125 | VkDescriptorPoolCreateInfo ds_pool_ci = {}; |
| 5126 | ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO; |
| 5127 | ds_pool_ci.maxSets = 1; |
| 5128 | ds_pool_ci.poolSizeCount = sizeof(ds_type_count) / sizeof(VkDescriptorPoolSize); |
| 5129 | ds_pool_ci.pPoolSizes = ds_type_count; |
| 5130 | |
| 5131 | VkDescriptorPool ds_pool; |
| 5132 | VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool); |
| 5133 | ASSERT_VK_SUCCESS(err); |
| 5134 | |
Mark Mueller | b989672 | 2016-06-16 09:54:29 -0600 | [diff] [blame] | 5135 | VkDescriptorSetLayoutBinding layout_binding[3] = {}; |
Mark Mueller | d491441 | 2016-06-13 17:52:06 -0600 | [diff] [blame] | 5136 | layout_binding[0].binding = 0; |
| 5137 | layout_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 5138 | layout_binding[0].descriptorCount = 1; |
| 5139 | layout_binding[0].stageFlags = VK_SHADER_STAGE_ALL; |
| 5140 | layout_binding[0].pImmutableSamplers = NULL; |
| 5141 | |
| 5142 | layout_binding[1].binding = 1; |
| 5143 | layout_binding[1].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER; |
| 5144 | layout_binding[1].descriptorCount = 1; |
| 5145 | layout_binding[1].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT; |
| 5146 | layout_binding[1].pImmutableSamplers = NULL; |
| 5147 | |
| 5148 | VkSamplerCreateInfo sampler_ci = {}; |
| 5149 | sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO; |
| 5150 | sampler_ci.pNext = NULL; |
| 5151 | sampler_ci.magFilter = VK_FILTER_NEAREST; |
| 5152 | sampler_ci.minFilter = VK_FILTER_NEAREST; |
| 5153 | sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST; |
| 5154 | sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE; |
| 5155 | sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE; |
| 5156 | sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE; |
| 5157 | sampler_ci.mipLodBias = 1.0; |
| 5158 | sampler_ci.anisotropyEnable = VK_FALSE; |
| 5159 | sampler_ci.maxAnisotropy = 1; |
| 5160 | sampler_ci.compareEnable = VK_FALSE; |
| 5161 | sampler_ci.compareOp = VK_COMPARE_OP_NEVER; |
| 5162 | sampler_ci.minLod = 1.0; |
| 5163 | sampler_ci.maxLod = 1.0; |
| 5164 | sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE; |
| 5165 | sampler_ci.unnormalizedCoordinates = VK_FALSE; |
| 5166 | VkSampler sampler; |
| 5167 | |
| 5168 | err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler); |
| 5169 | ASSERT_VK_SUCCESS(err); |
| 5170 | |
| 5171 | layout_binding[2].binding = 2; |
| 5172 | layout_binding[2].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER; |
| 5173 | layout_binding[2].descriptorCount = 1; |
| 5174 | layout_binding[2].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT; |
| 5175 | layout_binding[2].pImmutableSamplers = static_cast<VkSampler *>(&sampler); |
| 5176 | |
Mark Mueller | d491441 | 2016-06-13 17:52:06 -0600 | [diff] [blame] | 5177 | VkDescriptorSetLayoutCreateInfo ds_layout_ci = {}; |
| 5178 | ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO; |
| 5179 | ds_layout_ci.bindingCount = sizeof(layout_binding) / sizeof(VkDescriptorSetLayoutBinding); |
| 5180 | ds_layout_ci.pBindings = layout_binding; |
| 5181 | VkDescriptorSetLayout ds_layout; |
| 5182 | err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout); |
| 5183 | ASSERT_VK_SUCCESS(err); |
| 5184 | |
| 5185 | VkDescriptorSetAllocateInfo alloc_info = {}; |
| 5186 | alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO; |
| 5187 | alloc_info.descriptorSetCount = 1; |
| 5188 | alloc_info.descriptorPool = ds_pool; |
| 5189 | alloc_info.pSetLayouts = &ds_layout; |
| 5190 | VkDescriptorSet descriptorSet; |
| 5191 | err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet); |
| 5192 | ASSERT_VK_SUCCESS(err); |
| 5193 | |
| 5194 | VkPipelineLayoutCreateInfo pipeline_layout_ci = {}; |
| 5195 | pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO; |
| 5196 | pipeline_layout_ci.pNext = NULL; |
| 5197 | pipeline_layout_ci.setLayoutCount = 1; |
| 5198 | pipeline_layout_ci.pSetLayouts = &ds_layout; |
| 5199 | |
| 5200 | VkPipelineLayout pipeline_layout; |
| 5201 | err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout); |
| 5202 | ASSERT_VK_SUCCESS(err); |
| 5203 | |
Mark Mueller | 5c838ce | 2016-06-16 09:54:29 -0600 | [diff] [blame] | 5204 | VkWriteDescriptorSet descriptor_write = {}; |
Mark Mueller | d491441 | 2016-06-13 17:52:06 -0600 | [diff] [blame] | 5205 | descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET; |
| 5206 | descriptor_write.dstSet = descriptorSet; |
| 5207 | descriptor_write.dstBinding = 0; |
| 5208 | descriptor_write.descriptorCount = 1; |
| 5209 | descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 5210 | |
Mark Mueller | 5c838ce | 2016-06-16 09:54:29 -0600 | [diff] [blame] | 5211 | // 1) The uniform buffer is intentionally invalid here |
Mark Mueller | d491441 | 2016-06-13 17:52:06 -0600 | [diff] [blame] | 5212 | vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL); |
| 5213 | m_errorMonitor->VerifyFound(); |
| 5214 | |
| 5215 | // Create a buffer to update the descriptor with |
| 5216 | uint32_t qfi = 0; |
| 5217 | VkBufferCreateInfo buffCI = {}; |
| 5218 | buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO; |
| 5219 | buffCI.size = 1024; |
| 5220 | buffCI.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT; |
| 5221 | buffCI.queueFamilyIndexCount = 1; |
| 5222 | buffCI.pQueueFamilyIndices = &qfi; |
| 5223 | |
| 5224 | VkBuffer dyub; |
| 5225 | err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &dyub); |
| 5226 | ASSERT_VK_SUCCESS(err); |
| 5227 | VkDescriptorBufferInfo buffInfo = {}; |
| 5228 | buffInfo.buffer = dyub; |
| 5229 | buffInfo.offset = 0; |
| 5230 | buffInfo.range = 1024; |
| 5231 | |
| 5232 | descriptor_write.pBufferInfo = &buffInfo; |
| 5233 | descriptor_write.descriptorCount = 2; |
| 5234 | |
Mark Mueller | 5c838ce | 2016-06-16 09:54:29 -0600 | [diff] [blame] | 5235 | // 2) The stateFlags don't match between the first and second descriptor |
Mark Mueller | d491441 | 2016-06-13 17:52:06 -0600 | [diff] [blame] | 5236 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, stateFlag_ErrorMessage); |
| 5237 | vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL); |
| 5238 | m_errorMonitor->VerifyFound(); |
| 5239 | |
Mark Mueller | 5c838ce | 2016-06-16 09:54:29 -0600 | [diff] [blame] | 5240 | // 3) The second descriptor has a null_ptr pImmutableSamplers and |
| 5241 | // the third descriptor contains an immutable sampler |
Mark Mueller | d491441 | 2016-06-13 17:52:06 -0600 | [diff] [blame] | 5242 | descriptor_write.dstBinding = 1; |
| 5243 | descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER; |
Mark Mueller | 5c838ce | 2016-06-16 09:54:29 -0600 | [diff] [blame] | 5244 | |
| 5245 | |
| 5246 | // Make pImageInfo index non-null to avoid complaints of it missing |
| 5247 | VkDescriptorImageInfo imageInfo = {}; |
| 5248 | imageInfo.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL; |
| 5249 | descriptor_write.pImageInfo = &imageInfo; |
Mark Mueller | d491441 | 2016-06-13 17:52:06 -0600 | [diff] [blame] | 5250 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, immutable_ErrorMessage); |
| 5251 | vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL); |
| 5252 | m_errorMonitor->VerifyFound(); |
| 5253 | |
Mark Mueller | d491441 | 2016-06-13 17:52:06 -0600 | [diff] [blame] | 5254 | vkDestroyBuffer(m_device->device(), dyub, NULL); |
| 5255 | vkDestroySampler(m_device->device(), sampler, NULL); |
| 5256 | vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL); |
| 5257 | vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL); |
| 5258 | vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL); |
| 5259 | } |
| 5260 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5261 | TEST_F(VkLayerTest, InvalidPipeline) { |
Karl Schultz | bdb7595 | 2016-04-19 11:36:49 -0600 | [diff] [blame] | 5262 | // Attempt to bind an invalid Pipeline to a valid Command Buffer |
| 5263 | // ObjectTracker should catch this. |
Tobin Ehlis | 49eb23d | 2015-05-22 12:38:55 -0600 | [diff] [blame] | 5264 | // Create a valid cmd buffer |
| 5265 | // call vkCmdBindPipeline w/ false Pipeline |
Mark Lobodzinski | 02bf89d | 2016-05-10 14:45:13 -0600 | [diff] [blame] | 5266 | uint64_t fake_pipeline_handle = 0xbaad6001; |
| 5267 | VkPipeline bad_pipeline = reinterpret_cast<VkPipeline &>(fake_pipeline_handle); |
Karl Schultz | bdb7595 | 2016-04-19 11:36:49 -0600 | [diff] [blame] | 5268 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 5269 | "Invalid VkPipeline Object 0xbaad6001"); |
| 5270 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 5271 | BeginCommandBuffer(); |
| 5272 | vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), |
| 5273 | VK_PIPELINE_BIND_POINT_GRAPHICS, bad_pipeline); |
| 5274 | m_errorMonitor->VerifyFound(); |
Tobin Ehlis | b8b6b27 | 2016-05-02 13:26:06 -0600 | [diff] [blame] | 5275 | // Now issue a draw call with no pipeline bound |
| 5276 | m_errorMonitor->SetDesiredFailureMsg( |
| 5277 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 5278 | "At Draw/Dispatch time no valid VkPipeline is bound!"); |
Tony Barbour | df4c004 | 2016-06-01 15:55:43 -0600 | [diff] [blame] | 5279 | |
Tobin Ehlis | b8b6b27 | 2016-05-02 13:26:06 -0600 | [diff] [blame] | 5280 | BeginCommandBuffer(); |
| 5281 | Draw(1, 0, 0, 0); |
| 5282 | m_errorMonitor->VerifyFound(); |
| 5283 | // Finally same check once more but with Dispatch/Compute |
| 5284 | m_errorMonitor->SetDesiredFailureMsg( |
| 5285 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 5286 | "At Draw/Dispatch time no valid VkPipeline is bound!"); |
Tobin Ehlis | b8b6b27 | 2016-05-02 13:26:06 -0600 | [diff] [blame] | 5287 | BeginCommandBuffer(); |
| 5288 | vkCmdDispatch(m_commandBuffer->GetBufferHandle(), 0, 0, 0); |
| 5289 | m_errorMonitor->VerifyFound(); |
Tobin Ehlis | 49eb23d | 2015-05-22 12:38:55 -0600 | [diff] [blame] | 5290 | } |
| 5291 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5292 | TEST_F(VkLayerTest, DescriptorSetNotUpdated) { |
| 5293 | // Create and update CommandBuffer then call QueueSubmit w/o calling End on |
| 5294 | // CommandBuffer |
| 5295 | VkResult err; |
Tobin Ehlis | 7d1a711 | 2015-05-27 14:32:28 -0600 | [diff] [blame] | 5296 | |
Mark Lobodzinski | 510e20d | 2016-02-11 09:26:16 -0700 | [diff] [blame] | 5297 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5298 | " bound but it was never updated. "); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 5299 | |
Tobin Ehlis | 7d1a711 | 2015-05-27 14:32:28 -0600 | [diff] [blame] | 5300 | ASSERT_NO_FATAL_FAILURE(InitState()); |
Mike Stroyan | 713b2d7 | 2015-08-04 10:49:29 -0600 | [diff] [blame] | 5301 | ASSERT_NO_FATAL_FAILURE(InitViewport()); |
| 5302 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
Chia-I Wu | 1b99bb2 | 2015-10-27 19:25:11 +0800 | [diff] [blame] | 5303 | VkDescriptorPoolSize ds_type_count = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5304 | ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 5305 | ds_type_count.descriptorCount = 1; |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 5306 | |
| 5307 | VkDescriptorPoolCreateInfo ds_pool_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5308 | ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO; |
| 5309 | ds_pool_ci.pNext = NULL; |
| 5310 | ds_pool_ci.maxSets = 1; |
| 5311 | ds_pool_ci.poolSizeCount = 1; |
| 5312 | ds_pool_ci.pPoolSizes = &ds_type_count; |
Mike Stroyan | 713b2d7 | 2015-08-04 10:49:29 -0600 | [diff] [blame] | 5313 | |
Tobin Ehlis | 7d1a711 | 2015-05-27 14:32:28 -0600 | [diff] [blame] | 5314 | VkDescriptorPool ds_pool; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5315 | err = |
| 5316 | vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool); |
Tobin Ehlis | 7d1a711 | 2015-05-27 14:32:28 -0600 | [diff] [blame] | 5317 | ASSERT_VK_SUCCESS(err); |
Tobin Ehlis | 7d1a711 | 2015-05-27 14:32:28 -0600 | [diff] [blame] | 5318 | |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 5319 | VkDescriptorSetLayoutBinding dsl_binding = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5320 | dsl_binding.binding = 0; |
| 5321 | dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 5322 | dsl_binding.descriptorCount = 1; |
| 5323 | dsl_binding.stageFlags = VK_SHADER_STAGE_ALL; |
| 5324 | dsl_binding.pImmutableSamplers = NULL; |
Tobin Ehlis | 7d1a711 | 2015-05-27 14:32:28 -0600 | [diff] [blame] | 5325 | |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 5326 | VkDescriptorSetLayoutCreateInfo ds_layout_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5327 | ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO; |
| 5328 | ds_layout_ci.pNext = NULL; |
| 5329 | ds_layout_ci.bindingCount = 1; |
| 5330 | ds_layout_ci.pBindings = &dsl_binding; |
Tobin Ehlis | 7d1a711 | 2015-05-27 14:32:28 -0600 | [diff] [blame] | 5331 | VkDescriptorSetLayout ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5332 | err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, |
| 5333 | &ds_layout); |
Tobin Ehlis | 7d1a711 | 2015-05-27 14:32:28 -0600 | [diff] [blame] | 5334 | ASSERT_VK_SUCCESS(err); |
| 5335 | |
| 5336 | VkDescriptorSet descriptorSet; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 5337 | VkDescriptorSetAllocateInfo alloc_info = {}; |
Chia-I Wu | 00ce540 | 2015-11-10 16:21:09 +0800 | [diff] [blame] | 5338 | alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO; |
Jon Ashburn | f19916e | 2016-01-11 13:12:43 -0700 | [diff] [blame] | 5339 | alloc_info.descriptorSetCount = 1; |
Courtney Goeltzenleuchter | bee18a9 | 2015-10-23 14:21:05 -0600 | [diff] [blame] | 5340 | alloc_info.descriptorPool = ds_pool; |
| 5341 | alloc_info.pSetLayouts = &ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5342 | err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, |
| 5343 | &descriptorSet); |
Tobin Ehlis | 7d1a711 | 2015-05-27 14:32:28 -0600 | [diff] [blame] | 5344 | ASSERT_VK_SUCCESS(err); |
| 5345 | |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 5346 | VkPipelineLayoutCreateInfo pipeline_layout_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5347 | pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO; |
| 5348 | pipeline_layout_ci.pNext = NULL; |
| 5349 | pipeline_layout_ci.setLayoutCount = 1; |
| 5350 | pipeline_layout_ci.pSetLayouts = &ds_layout; |
Tobin Ehlis | 7d1a711 | 2015-05-27 14:32:28 -0600 | [diff] [blame] | 5351 | |
| 5352 | VkPipelineLayout pipeline_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5353 | err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, |
| 5354 | &pipeline_layout); |
Tobin Ehlis | 7d1a711 | 2015-05-27 14:32:28 -0600 | [diff] [blame] | 5355 | ASSERT_VK_SUCCESS(err); |
| 5356 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5357 | VkShaderObj vs(m_device, bindStateVertShaderText, |
| 5358 | VK_SHADER_STAGE_VERTEX_BIT, this); |
Karl Schultz | bdb7595 | 2016-04-19 11:36:49 -0600 | [diff] [blame] | 5359 | // We shouldn't need a fragment shader but add it to be able to run |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5360 | // on more devices |
| 5361 | VkShaderObj fs(m_device, bindStateFragShaderText, |
| 5362 | VK_SHADER_STAGE_FRAGMENT_BIT, this); |
Tobin Ehlis | 7d1a711 | 2015-05-27 14:32:28 -0600 | [diff] [blame] | 5363 | |
Tony Barbour | c95e4ac | 2015-08-04 17:05:26 -0600 | [diff] [blame] | 5364 | VkPipelineObj pipe(m_device); |
| 5365 | pipe.AddShader(&vs); |
Tony Barbour | 1c94d37 | 2015-08-06 11:21:08 -0600 | [diff] [blame] | 5366 | pipe.AddShader(&fs); |
Mark Young | c89c631 | 2016-03-31 16:03:20 -0600 | [diff] [blame] | 5367 | pipe.AddColorAttachment(); |
Tony Barbour | c95e4ac | 2015-08-04 17:05:26 -0600 | [diff] [blame] | 5368 | pipe.CreateVKPipeline(pipeline_layout, renderPass()); |
Tony Barbour | fe3351b | 2015-07-28 10:17:20 -0600 | [diff] [blame] | 5369 | |
| 5370 | BeginCommandBuffer(); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5371 | vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), |
| 5372 | VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle()); |
| 5373 | vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), |
| 5374 | VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, |
| 5375 | 1, &descriptorSet, 0, NULL); |
Tobin Ehlis | 7d1a711 | 2015-05-27 14:32:28 -0600 | [diff] [blame] | 5376 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 5377 | m_errorMonitor->VerifyFound(); |
Mike Stroyan | d1c84a5 | 2015-08-18 14:40:24 -0600 | [diff] [blame] | 5378 | |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 5379 | vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL); |
| 5380 | vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL); |
| 5381 | vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL); |
Tobin Ehlis | af1f3a4 | 2015-06-25 15:46:59 -0600 | [diff] [blame] | 5382 | } |
| 5383 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5384 | TEST_F(VkLayerTest, InvalidBufferViewObject) { |
Tobin Ehlis | ba31cab | 2015-11-02 15:24:32 -0700 | [diff] [blame] | 5385 | // Create a single TEXEL_BUFFER descriptor and send it an invalid bufferView |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5386 | VkResult err; |
Tobin Ehlis | ba31cab | 2015-11-02 15:24:32 -0700 | [diff] [blame] | 5387 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5388 | m_errorMonitor->SetDesiredFailureMsg( |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 5389 | VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attempted write update to texel buffer " |
| 5390 | "descriptor with invalid buffer view"); |
Tobin Ehlis | ba31cab | 2015-11-02 15:24:32 -0700 | [diff] [blame] | 5391 | |
| 5392 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 5393 | VkDescriptorPoolSize ds_type_count = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5394 | ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER; |
| 5395 | ds_type_count.descriptorCount = 1; |
Tobin Ehlis | ba31cab | 2015-11-02 15:24:32 -0700 | [diff] [blame] | 5396 | |
| 5397 | VkDescriptorPoolCreateInfo ds_pool_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5398 | ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO; |
| 5399 | ds_pool_ci.pNext = NULL; |
| 5400 | ds_pool_ci.maxSets = 1; |
| 5401 | ds_pool_ci.poolSizeCount = 1; |
| 5402 | ds_pool_ci.pPoolSizes = &ds_type_count; |
Tobin Ehlis | ba31cab | 2015-11-02 15:24:32 -0700 | [diff] [blame] | 5403 | |
| 5404 | VkDescriptorPool ds_pool; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5405 | err = |
| 5406 | vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool); |
Tobin Ehlis | ba31cab | 2015-11-02 15:24:32 -0700 | [diff] [blame] | 5407 | ASSERT_VK_SUCCESS(err); |
| 5408 | |
| 5409 | VkDescriptorSetLayoutBinding dsl_binding = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5410 | dsl_binding.binding = 0; |
| 5411 | dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER; |
| 5412 | dsl_binding.descriptorCount = 1; |
| 5413 | dsl_binding.stageFlags = VK_SHADER_STAGE_ALL; |
| 5414 | dsl_binding.pImmutableSamplers = NULL; |
Tobin Ehlis | ba31cab | 2015-11-02 15:24:32 -0700 | [diff] [blame] | 5415 | |
| 5416 | VkDescriptorSetLayoutCreateInfo ds_layout_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5417 | ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO; |
| 5418 | ds_layout_ci.pNext = NULL; |
| 5419 | ds_layout_ci.bindingCount = 1; |
| 5420 | ds_layout_ci.pBindings = &dsl_binding; |
Tobin Ehlis | ba31cab | 2015-11-02 15:24:32 -0700 | [diff] [blame] | 5421 | VkDescriptorSetLayout ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5422 | err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, |
| 5423 | &ds_layout); |
Tobin Ehlis | ba31cab | 2015-11-02 15:24:32 -0700 | [diff] [blame] | 5424 | ASSERT_VK_SUCCESS(err); |
| 5425 | |
| 5426 | VkDescriptorSet descriptorSet; |
| 5427 | VkDescriptorSetAllocateInfo alloc_info = {}; |
Chia-I Wu | 00ce540 | 2015-11-10 16:21:09 +0800 | [diff] [blame] | 5428 | alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO; |
Jon Ashburn | f19916e | 2016-01-11 13:12:43 -0700 | [diff] [blame] | 5429 | alloc_info.descriptorSetCount = 1; |
Tobin Ehlis | ba31cab | 2015-11-02 15:24:32 -0700 | [diff] [blame] | 5430 | alloc_info.descriptorPool = ds_pool; |
| 5431 | alloc_info.pSetLayouts = &ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5432 | err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, |
| 5433 | &descriptorSet); |
Tobin Ehlis | ba31cab | 2015-11-02 15:24:32 -0700 | [diff] [blame] | 5434 | ASSERT_VK_SUCCESS(err); |
| 5435 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5436 | VkBufferView view = |
| 5437 | (VkBufferView)((size_t)0xbaadbeef); // invalid bufferView object |
Tobin Ehlis | ba31cab | 2015-11-02 15:24:32 -0700 | [diff] [blame] | 5438 | VkWriteDescriptorSet descriptor_write; |
| 5439 | memset(&descriptor_write, 0, sizeof(descriptor_write)); |
| 5440 | descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET; |
| 5441 | descriptor_write.dstSet = descriptorSet; |
| 5442 | descriptor_write.dstBinding = 0; |
| 5443 | descriptor_write.descriptorCount = 1; |
| 5444 | descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER; |
| 5445 | descriptor_write.pTexelBufferView = &view; |
| 5446 | |
| 5447 | vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL); |
| 5448 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 5449 | m_errorMonitor->VerifyFound(); |
Tobin Ehlis | ba31cab | 2015-11-02 15:24:32 -0700 | [diff] [blame] | 5450 | |
| 5451 | vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL); |
| 5452 | vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL); |
| 5453 | } |
| 5454 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5455 | TEST_F(VkLayerTest, InvalidDynamicOffsetCases) { |
| 5456 | // Create a descriptorSet w/ dynamic descriptor and then hit 3 offset error |
| 5457 | // cases: |
Tobin Ehlis | f658505 | 2015-12-17 11:48:42 -0700 | [diff] [blame] | 5458 | // 1. No dynamicOffset supplied |
| 5459 | // 2. Too many dynamicOffsets supplied |
| 5460 | // 3. Dynamic offset oversteps buffer being updated |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5461 | VkResult err; |
Courtney Goeltzenleuchter | 7415d5a | 2015-12-09 15:48:16 -0700 | [diff] [blame] | 5462 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5463 | " requires 1 dynamicOffsets, but only " |
| 5464 | "0 dynamicOffsets are left in " |
| 5465 | "pDynamicOffsets "); |
Tobin Ehlis | 49f903e | 2015-11-04 13:30:34 -0700 | [diff] [blame] | 5466 | |
| 5467 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 5468 | ASSERT_NO_FATAL_FAILURE(InitViewport()); |
| 5469 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 5470 | |
| 5471 | VkDescriptorPoolSize ds_type_count = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5472 | ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC; |
| 5473 | ds_type_count.descriptorCount = 1; |
Tobin Ehlis | 49f903e | 2015-11-04 13:30:34 -0700 | [diff] [blame] | 5474 | |
| 5475 | VkDescriptorPoolCreateInfo ds_pool_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5476 | ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO; |
| 5477 | ds_pool_ci.pNext = NULL; |
| 5478 | ds_pool_ci.maxSets = 1; |
| 5479 | ds_pool_ci.poolSizeCount = 1; |
| 5480 | ds_pool_ci.pPoolSizes = &ds_type_count; |
Tobin Ehlis | 49f903e | 2015-11-04 13:30:34 -0700 | [diff] [blame] | 5481 | |
| 5482 | VkDescriptorPool ds_pool; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5483 | err = |
| 5484 | vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool); |
Tobin Ehlis | 49f903e | 2015-11-04 13:30:34 -0700 | [diff] [blame] | 5485 | ASSERT_VK_SUCCESS(err); |
| 5486 | |
| 5487 | VkDescriptorSetLayoutBinding dsl_binding = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5488 | dsl_binding.binding = 0; |
| 5489 | dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC; |
| 5490 | dsl_binding.descriptorCount = 1; |
| 5491 | dsl_binding.stageFlags = VK_SHADER_STAGE_ALL; |
| 5492 | dsl_binding.pImmutableSamplers = NULL; |
Tobin Ehlis | 49f903e | 2015-11-04 13:30:34 -0700 | [diff] [blame] | 5493 | |
| 5494 | VkDescriptorSetLayoutCreateInfo ds_layout_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5495 | ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO; |
| 5496 | ds_layout_ci.pNext = NULL; |
| 5497 | ds_layout_ci.bindingCount = 1; |
| 5498 | ds_layout_ci.pBindings = &dsl_binding; |
Tobin Ehlis | 49f903e | 2015-11-04 13:30:34 -0700 | [diff] [blame] | 5499 | VkDescriptorSetLayout ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5500 | err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, |
| 5501 | &ds_layout); |
Tobin Ehlis | 49f903e | 2015-11-04 13:30:34 -0700 | [diff] [blame] | 5502 | ASSERT_VK_SUCCESS(err); |
| 5503 | |
| 5504 | VkDescriptorSet descriptorSet; |
| 5505 | VkDescriptorSetAllocateInfo alloc_info = {}; |
Chia-I Wu | 00ce540 | 2015-11-10 16:21:09 +0800 | [diff] [blame] | 5506 | alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO; |
Jon Ashburn | f19916e | 2016-01-11 13:12:43 -0700 | [diff] [blame] | 5507 | alloc_info.descriptorSetCount = 1; |
Tobin Ehlis | 49f903e | 2015-11-04 13:30:34 -0700 | [diff] [blame] | 5508 | alloc_info.descriptorPool = ds_pool; |
| 5509 | alloc_info.pSetLayouts = &ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5510 | err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, |
| 5511 | &descriptorSet); |
Tobin Ehlis | 49f903e | 2015-11-04 13:30:34 -0700 | [diff] [blame] | 5512 | ASSERT_VK_SUCCESS(err); |
| 5513 | |
| 5514 | VkPipelineLayoutCreateInfo pipeline_layout_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5515 | pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO; |
| 5516 | pipeline_layout_ci.pNext = NULL; |
| 5517 | pipeline_layout_ci.setLayoutCount = 1; |
| 5518 | pipeline_layout_ci.pSetLayouts = &ds_layout; |
Tobin Ehlis | 49f903e | 2015-11-04 13:30:34 -0700 | [diff] [blame] | 5519 | |
| 5520 | VkPipelineLayout pipeline_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5521 | err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, |
| 5522 | &pipeline_layout); |
Tobin Ehlis | 49f903e | 2015-11-04 13:30:34 -0700 | [diff] [blame] | 5523 | ASSERT_VK_SUCCESS(err); |
| 5524 | |
| 5525 | // Create a buffer to update the descriptor with |
| 5526 | uint32_t qfi = 0; |
| 5527 | VkBufferCreateInfo buffCI = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5528 | buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO; |
| 5529 | buffCI.size = 1024; |
| 5530 | buffCI.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT; |
| 5531 | buffCI.queueFamilyIndexCount = 1; |
| 5532 | buffCI.pQueueFamilyIndices = &qfi; |
Tobin Ehlis | 49f903e | 2015-11-04 13:30:34 -0700 | [diff] [blame] | 5533 | |
| 5534 | VkBuffer dyub; |
| 5535 | err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &dyub); |
| 5536 | ASSERT_VK_SUCCESS(err); |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 5537 | // Allocate memory and bind to buffer so we can make it to the appropriate |
| 5538 | // error |
| 5539 | VkMemoryAllocateInfo mem_alloc = {}; |
| 5540 | mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO; |
| 5541 | mem_alloc.pNext = NULL; |
| 5542 | mem_alloc.allocationSize = 1024; |
Chris Forbes | b6116cc | 2016-05-08 11:39:59 +1200 | [diff] [blame] | 5543 | mem_alloc.memoryTypeIndex = 0; |
| 5544 | |
| 5545 | VkMemoryRequirements memReqs; |
| 5546 | vkGetBufferMemoryRequirements(m_device->device(), dyub, &memReqs); |
| 5547 | bool pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &mem_alloc, |
| 5548 | 0); |
| 5549 | if (!pass) { |
| 5550 | vkDestroyBuffer(m_device->device(), dyub, NULL); |
| 5551 | return; |
| 5552 | } |
| 5553 | |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 5554 | VkDeviceMemory mem; |
| 5555 | err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem); |
| 5556 | ASSERT_VK_SUCCESS(err); |
| 5557 | err = vkBindBufferMemory(m_device->device(), dyub, mem, 0); |
| 5558 | ASSERT_VK_SUCCESS(err); |
Tobin Ehlis | 49f903e | 2015-11-04 13:30:34 -0700 | [diff] [blame] | 5559 | // Correctly update descriptor to avoid "NOT_UPDATED" error |
| 5560 | VkDescriptorBufferInfo buffInfo = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5561 | buffInfo.buffer = dyub; |
| 5562 | buffInfo.offset = 0; |
| 5563 | buffInfo.range = 1024; |
Tobin Ehlis | 49f903e | 2015-11-04 13:30:34 -0700 | [diff] [blame] | 5564 | |
| 5565 | VkWriteDescriptorSet descriptor_write; |
| 5566 | memset(&descriptor_write, 0, sizeof(descriptor_write)); |
| 5567 | descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET; |
| 5568 | descriptor_write.dstSet = descriptorSet; |
| 5569 | descriptor_write.dstBinding = 0; |
| 5570 | descriptor_write.descriptorCount = 1; |
| 5571 | descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC; |
| 5572 | descriptor_write.pBufferInfo = &buffInfo; |
| 5573 | |
| 5574 | vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL); |
| 5575 | |
| 5576 | BeginCommandBuffer(); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5577 | vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), |
| 5578 | VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, |
| 5579 | 1, &descriptorSet, 0, NULL); |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 5580 | m_errorMonitor->VerifyFound(); |
Tobin Ehlis | f658505 | 2015-12-17 11:48:42 -0700 | [diff] [blame] | 5581 | uint32_t pDynOff[2] = {512, 756}; |
| 5582 | // Now cause error b/c too many dynOffsets in array for # of dyn descriptors |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5583 | m_errorMonitor->SetDesiredFailureMsg( |
| 5584 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Tobin Ehlis | f658505 | 2015-12-17 11:48:42 -0700 | [diff] [blame] | 5585 | "Attempting to bind 1 descriptorSets with 1 dynamic descriptors, but "); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5586 | vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), |
| 5587 | VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, |
| 5588 | 1, &descriptorSet, 2, pDynOff); |
Chris Forbes | 7b34280 | 2016-04-07 13:20:10 +1200 | [diff] [blame] | 5589 | m_errorMonitor->VerifyFound(); |
Tobin Ehlis | f658505 | 2015-12-17 11:48:42 -0700 | [diff] [blame] | 5590 | // Finally cause error due to dynamicOffset being too big |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 5591 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 5592 | " dynamic offset 512 combined with " |
| 5593 | "offset 0 and range 1024 that " |
| 5594 | "oversteps the buffer size of 1024"); |
Tobin Ehlis | f658505 | 2015-12-17 11:48:42 -0700 | [diff] [blame] | 5595 | // Create PSO to be used for draw-time errors below |
| 5596 | char const *vsSource = |
Chris Forbes | 7b34280 | 2016-04-07 13:20:10 +1200 | [diff] [blame] | 5597 | "#version 450\n" |
Tobin Ehlis | f658505 | 2015-12-17 11:48:42 -0700 | [diff] [blame] | 5598 | "\n" |
Tony Barbour | e804d20 | 2016-01-05 13:37:45 -0700 | [diff] [blame] | 5599 | "out gl_PerVertex { \n" |
| 5600 | " vec4 gl_Position;\n" |
| 5601 | "};\n" |
Tobin Ehlis | f658505 | 2015-12-17 11:48:42 -0700 | [diff] [blame] | 5602 | "void main(){\n" |
| 5603 | " gl_Position = vec4(1);\n" |
| 5604 | "}\n"; |
| 5605 | char const *fsSource = |
Chris Forbes | 7b34280 | 2016-04-07 13:20:10 +1200 | [diff] [blame] | 5606 | "#version 450\n" |
Tobin Ehlis | f658505 | 2015-12-17 11:48:42 -0700 | [diff] [blame] | 5607 | "\n" |
| 5608 | "layout(location=0) out vec4 x;\n" |
| 5609 | "layout(set=0) layout(binding=0) uniform foo { int x; int y; } bar;\n" |
| 5610 | "void main(){\n" |
| 5611 | " x = vec4(bar.y);\n" |
| 5612 | "}\n"; |
| 5613 | VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this); |
| 5614 | VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this); |
| 5615 | VkPipelineObj pipe(m_device); |
| 5616 | pipe.AddShader(&vs); |
| 5617 | pipe.AddShader(&fs); |
| 5618 | pipe.AddColorAttachment(); |
| 5619 | pipe.CreateVKPipeline(pipeline_layout, renderPass()); |
| 5620 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5621 | vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), |
| 5622 | VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle()); |
| 5623 | // This update should succeed, but offset size of 512 will overstep buffer |
| 5624 | // /w range 1024 & size 1024 |
| 5625 | vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), |
| 5626 | VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, |
| 5627 | 1, &descriptorSet, 1, pDynOff); |
Tobin Ehlis | f658505 | 2015-12-17 11:48:42 -0700 | [diff] [blame] | 5628 | Draw(1, 0, 0, 0); |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 5629 | m_errorMonitor->VerifyFound(); |
Tobin Ehlis | 49f903e | 2015-11-04 13:30:34 -0700 | [diff] [blame] | 5630 | |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 5631 | vkDestroyBuffer(m_device->device(), dyub, NULL); |
Tobin Ehlis | 512098e | 2016-05-05 09:06:12 -0600 | [diff] [blame] | 5632 | vkFreeMemory(m_device->device(), mem, NULL); |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 5633 | |
Tobin Ehlis | 49f903e | 2015-11-04 13:30:34 -0700 | [diff] [blame] | 5634 | vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL); |
Tony Barbour | df4c004 | 2016-06-01 15:55:43 -0600 | [diff] [blame] | 5635 | vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL); |
Tobin Ehlis | 49f903e | 2015-11-04 13:30:34 -0700 | [diff] [blame] | 5636 | vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL); |
| 5637 | } |
| 5638 | |
Tobin Ehlis | 3a23b6a | 2016-02-17 10:35:18 -0700 | [diff] [blame] | 5639 | TEST_F(VkLayerTest, InvalidPushConstants) { |
Tobin Ehlis | 3a23b6a | 2016-02-17 10:35:18 -0700 | [diff] [blame] | 5640 | VkResult err; |
Tobin Ehlis | 3a23b6a | 2016-02-17 10:35:18 -0700 | [diff] [blame] | 5641 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 5642 | ASSERT_NO_FATAL_FAILURE(InitViewport()); |
| 5643 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 5644 | |
Karl Schultz | fc8eaf1 | 2016-05-06 13:56:42 -0600 | [diff] [blame] | 5645 | VkPipelineLayout pipeline_layout; |
Tobin Ehlis | 3a23b6a | 2016-02-17 10:35:18 -0700 | [diff] [blame] | 5646 | VkPushConstantRange pc_range = {}; |
Tobin Ehlis | 3a23b6a | 2016-02-17 10:35:18 -0700 | [diff] [blame] | 5647 | VkPipelineLayoutCreateInfo pipeline_layout_ci = {}; |
| 5648 | pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO; |
| 5649 | pipeline_layout_ci.pushConstantRangeCount = 1; |
| 5650 | pipeline_layout_ci.pPushConstantRanges = &pc_range; |
| 5651 | |
Karl Schultz | fc8eaf1 | 2016-05-06 13:56:42 -0600 | [diff] [blame] | 5652 | // |
| 5653 | // Check for invalid push constant ranges in pipeline layouts. |
| 5654 | // |
| 5655 | struct PipelineLayoutTestCase { |
Karl Schultz | c81037d | 2016-05-12 08:11:23 -0600 | [diff] [blame] | 5656 | VkPushConstantRange const range; |
Karl Schultz | fc8eaf1 | 2016-05-06 13:56:42 -0600 | [diff] [blame] | 5657 | char const *msg; |
| 5658 | }; |
Tobin Ehlis | 3a23b6a | 2016-02-17 10:35:18 -0700 | [diff] [blame] | 5659 | |
Karl Schultz | c81037d | 2016-05-12 08:11:23 -0600 | [diff] [blame] | 5660 | const uint32_t too_big = m_device->props.limits.maxPushConstantsSize + 0x4; |
| 5661 | const std::array<PipelineLayoutTestCase, 10> range_tests = {{ |
| 5662 | {{VK_SHADER_STAGE_VERTEX_BIT, 0, 0}, |
| 5663 | "vkCreatePipelineLayout() call has push constants index 0 with " |
| 5664 | "size 0."}, |
| 5665 | {{VK_SHADER_STAGE_VERTEX_BIT, 0, 1}, |
| 5666 | "vkCreatePipelineLayout() call has push constants index 0 with " |
| 5667 | "size 1."}, |
| 5668 | {{VK_SHADER_STAGE_VERTEX_BIT, 1, 1}, |
| 5669 | "vkCreatePipelineLayout() call has push constants index 0 with " |
| 5670 | "size 1."}, |
| 5671 | {{VK_SHADER_STAGE_VERTEX_BIT, 1, 0}, |
| 5672 | "vkCreatePipelineLayout() call has push constants index 0 with " |
| 5673 | "size 0."}, |
| 5674 | {{VK_SHADER_STAGE_VERTEX_BIT, 1, 4}, |
| 5675 | "vkCreatePipelineLayout() call has push constants index 0 with " |
| 5676 | "offset 1. Offset must"}, |
| 5677 | {{VK_SHADER_STAGE_VERTEX_BIT, 0, too_big}, |
| 5678 | "vkCreatePipelineLayout() call has push constants index 0 " |
| 5679 | "with offset "}, |
| 5680 | {{VK_SHADER_STAGE_VERTEX_BIT, too_big, too_big}, |
| 5681 | "vkCreatePipelineLayout() call has push constants " |
| 5682 | "index 0 with offset "}, |
| 5683 | {{VK_SHADER_STAGE_VERTEX_BIT, too_big, 0}, |
| 5684 | "vkCreatePipelineLayout() call has push constants index 0 " |
| 5685 | "with offset "}, |
| 5686 | {{VK_SHADER_STAGE_VERTEX_BIT, 0xFFFFFFF0, 0x00000020}, |
| 5687 | "vkCreatePipelineLayout() call has push " |
| 5688 | "constants index 0 with offset "}, |
| 5689 | {{VK_SHADER_STAGE_VERTEX_BIT, 0x00000020, 0xFFFFFFF0}, |
| 5690 | "vkCreatePipelineLayout() call has push " |
| 5691 | "constants index 0 with offset "}, |
Karl Schultz | fc8eaf1 | 2016-05-06 13:56:42 -0600 | [diff] [blame] | 5692 | }}; |
| 5693 | |
| 5694 | // Check for invalid offset and size |
Karl Schultz | c81037d | 2016-05-12 08:11:23 -0600 | [diff] [blame] | 5695 | for (const auto &iter : range_tests) { |
| 5696 | pc_range = iter.range; |
Karl Schultz | fc8eaf1 | 2016-05-06 13:56:42 -0600 | [diff] [blame] | 5697 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 5698 | iter.msg); |
| 5699 | err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, |
| 5700 | NULL, &pipeline_layout); |
| 5701 | m_errorMonitor->VerifyFound(); |
| 5702 | if (VK_SUCCESS == err) { |
| 5703 | vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL); |
| 5704 | } |
| 5705 | } |
| 5706 | |
| 5707 | // Check for invalid stage flag |
| 5708 | pc_range.offset = 0; |
| 5709 | pc_range.size = 16; |
| 5710 | pc_range.stageFlags = 0; |
Tobin Ehlis | 3a23b6a | 2016-02-17 10:35:18 -0700 | [diff] [blame] | 5711 | m_errorMonitor->SetDesiredFailureMsg( |
| 5712 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Karl Schultz | fc8eaf1 | 2016-05-06 13:56:42 -0600 | [diff] [blame] | 5713 | "vkCreatePipelineLayout() call has no stageFlags set."); |
Tobin Ehlis | 3a23b6a | 2016-02-17 10:35:18 -0700 | [diff] [blame] | 5714 | err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, |
| 5715 | &pipeline_layout); |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 5716 | m_errorMonitor->VerifyFound(); |
Karl Schultz | fc8eaf1 | 2016-05-06 13:56:42 -0600 | [diff] [blame] | 5717 | if (VK_SUCCESS == err) { |
| 5718 | vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL); |
| 5719 | } |
| 5720 | |
| 5721 | // Check for overlapping ranges |
Karl Schultz | c81037d | 2016-05-12 08:11:23 -0600 | [diff] [blame] | 5722 | const uint32_t ranges_per_test = 5; |
Karl Schultz | fc8eaf1 | 2016-05-06 13:56:42 -0600 | [diff] [blame] | 5723 | struct OverlappingRangeTestCase { |
Karl Schultz | c81037d | 2016-05-12 08:11:23 -0600 | [diff] [blame] | 5724 | VkPushConstantRange const ranges[ranges_per_test]; |
Karl Schultz | fc8eaf1 | 2016-05-06 13:56:42 -0600 | [diff] [blame] | 5725 | char const *msg; |
| 5726 | }; |
| 5727 | |
Karl Schultz | c81037d | 2016-05-12 08:11:23 -0600 | [diff] [blame] | 5728 | const std::array<OverlappingRangeTestCase, 5> overlapping_range_tests = { |
Karl Schultz | fc8eaf1 | 2016-05-06 13:56:42 -0600 | [diff] [blame] | 5729 | {{{{VK_SHADER_STAGE_VERTEX_BIT, 0, 4}, |
| 5730 | {VK_SHADER_STAGE_VERTEX_BIT, 0, 4}, |
| 5731 | {VK_SHADER_STAGE_VERTEX_BIT, 0, 4}, |
| 5732 | {VK_SHADER_STAGE_VERTEX_BIT, 0, 4}, |
| 5733 | {VK_SHADER_STAGE_VERTEX_BIT, 0, 4}}, |
| 5734 | "vkCreatePipelineLayout() call has push constants with overlapping " |
| 5735 | "ranges: 0:[0, 4), 1:[0, 4)"}, |
| 5736 | { |
| 5737 | {{VK_SHADER_STAGE_VERTEX_BIT, 0, 4}, |
| 5738 | {VK_SHADER_STAGE_VERTEX_BIT, 4, 4}, |
| 5739 | {VK_SHADER_STAGE_VERTEX_BIT, 8, 4}, |
| 5740 | {VK_SHADER_STAGE_VERTEX_BIT, 12, 8}, |
| 5741 | {VK_SHADER_STAGE_VERTEX_BIT, 16, 4}}, |
| 5742 | "vkCreatePipelineLayout() call has push constants with " |
| 5743 | "overlapping " |
| 5744 | "ranges: 3:[12, 20), 4:[16, 20)", |
| 5745 | }, |
| 5746 | { |
| 5747 | {{VK_SHADER_STAGE_VERTEX_BIT, 16, 4}, |
| 5748 | {VK_SHADER_STAGE_VERTEX_BIT, 12, 8}, |
| 5749 | {VK_SHADER_STAGE_VERTEX_BIT, 8, 4}, |
| 5750 | {VK_SHADER_STAGE_VERTEX_BIT, 4, 4}, |
| 5751 | {VK_SHADER_STAGE_VERTEX_BIT, 0, 4}}, |
| 5752 | "vkCreatePipelineLayout() call has push constants with " |
| 5753 | "overlapping " |
| 5754 | "ranges: 0:[16, 20), 1:[12, 20)", |
| 5755 | }, |
| 5756 | { |
| 5757 | {{VK_SHADER_STAGE_VERTEX_BIT, 16, 4}, |
| 5758 | {VK_SHADER_STAGE_VERTEX_BIT, 8, 4}, |
| 5759 | {VK_SHADER_STAGE_VERTEX_BIT, 4, 4}, |
| 5760 | {VK_SHADER_STAGE_VERTEX_BIT, 12, 8}, |
| 5761 | {VK_SHADER_STAGE_VERTEX_BIT, 0, 4}}, |
| 5762 | "vkCreatePipelineLayout() call has push constants with " |
| 5763 | "overlapping " |
| 5764 | "ranges: 0:[16, 20), 3:[12, 20)", |
| 5765 | }, |
| 5766 | { |
| 5767 | {{VK_SHADER_STAGE_VERTEX_BIT, 16, 4}, |
| 5768 | {VK_SHADER_STAGE_VERTEX_BIT, 32, 4}, |
| 5769 | {VK_SHADER_STAGE_VERTEX_BIT, 4, 96}, |
| 5770 | {VK_SHADER_STAGE_VERTEX_BIT, 40, 8}, |
| 5771 | {VK_SHADER_STAGE_VERTEX_BIT, 52, 4}}, |
| 5772 | "vkCreatePipelineLayout() call has push constants with " |
| 5773 | "overlapping " |
| 5774 | "ranges: 0:[16, 20), 2:[4, 100)", |
| 5775 | }}}; |
Karl Schultz | fc8eaf1 | 2016-05-06 13:56:42 -0600 | [diff] [blame] | 5776 | |
Karl Schultz | c81037d | 2016-05-12 08:11:23 -0600 | [diff] [blame] | 5777 | for (const auto &iter : overlapping_range_tests) { |
Karl Schultz | fc8eaf1 | 2016-05-06 13:56:42 -0600 | [diff] [blame] | 5778 | pipeline_layout_ci.pPushConstantRanges = iter.ranges; |
Karl Schultz | c81037d | 2016-05-12 08:11:23 -0600 | [diff] [blame] | 5779 | pipeline_layout_ci.pushConstantRangeCount = ranges_per_test; |
| 5780 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, |
Karl Schultz | fc8eaf1 | 2016-05-06 13:56:42 -0600 | [diff] [blame] | 5781 | iter.msg); |
| 5782 | err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, |
| 5783 | NULL, &pipeline_layout); |
| 5784 | m_errorMonitor->VerifyFound(); |
| 5785 | if (VK_SUCCESS == err) { |
| 5786 | vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL); |
| 5787 | } |
| 5788 | } |
| 5789 | |
| 5790 | // Run some positive tests to make sure overlap checking in the layer is OK |
Karl Schultz | c81037d | 2016-05-12 08:11:23 -0600 | [diff] [blame] | 5791 | const std::array<OverlappingRangeTestCase, 2> overlapping_range_tests_pos = |
| 5792 | {{{{{VK_SHADER_STAGE_VERTEX_BIT, 0, 4}, |
| 5793 | {VK_SHADER_STAGE_VERTEX_BIT, 4, 4}, |
| 5794 | {VK_SHADER_STAGE_VERTEX_BIT, 8, 4}, |
| 5795 | {VK_SHADER_STAGE_VERTEX_BIT, 12, 4}, |
| 5796 | {VK_SHADER_STAGE_VERTEX_BIT, 16, 4}}, |
| 5797 | ""}, |
| 5798 | {{{VK_SHADER_STAGE_VERTEX_BIT, 92, 24}, |
| 5799 | {VK_SHADER_STAGE_VERTEX_BIT, 80, 4}, |
| 5800 | {VK_SHADER_STAGE_VERTEX_BIT, 64, 8}, |
| 5801 | {VK_SHADER_STAGE_VERTEX_BIT, 4, 16}, |
| 5802 | {VK_SHADER_STAGE_VERTEX_BIT, 0, 4}}, |
| 5803 | ""}}}; |
| 5804 | for (const auto &iter : overlapping_range_tests_pos) { |
Karl Schultz | fc8eaf1 | 2016-05-06 13:56:42 -0600 | [diff] [blame] | 5805 | pipeline_layout_ci.pPushConstantRanges = iter.ranges; |
| 5806 | m_errorMonitor->ExpectSuccess(); |
| 5807 | err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, |
| 5808 | NULL, &pipeline_layout); |
| 5809 | m_errorMonitor->VerifyNotFound(); |
| 5810 | if (VK_SUCCESS == err) { |
| 5811 | vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL); |
| 5812 | } |
| 5813 | } |
| 5814 | |
| 5815 | // |
| 5816 | // CmdPushConstants tests |
| 5817 | // |
Karl Schultz | c81037d | 2016-05-12 08:11:23 -0600 | [diff] [blame] | 5818 | const uint8_t dummy_values[100] = {}; |
Karl Schultz | fc8eaf1 | 2016-05-06 13:56:42 -0600 | [diff] [blame] | 5819 | |
| 5820 | // Check for invalid offset and size and if range is within layout range(s) |
Karl Schultz | c81037d | 2016-05-12 08:11:23 -0600 | [diff] [blame] | 5821 | const std::array<PipelineLayoutTestCase, 16> cmd_range_tests = {{ |
| 5822 | {{VK_SHADER_STAGE_VERTEX_BIT, 0, 0}, |
| 5823 | "vkCmdPushConstants() call has push constants with size 0. Size " |
| 5824 | "must be greater than zero and a multiple of 4."}, |
| 5825 | {{VK_SHADER_STAGE_VERTEX_BIT, 0, 1}, |
| 5826 | "vkCmdPushConstants() call has push constants with size 1. Size " |
| 5827 | "must be greater than zero and a multiple of 4."}, |
| 5828 | {{VK_SHADER_STAGE_VERTEX_BIT, 1, 1}, |
| 5829 | "vkCmdPushConstants() call has push constants with size 1. Size " |
| 5830 | "must be greater than zero and a multiple of 4."}, |
| 5831 | {{VK_SHADER_STAGE_VERTEX_BIT, 1, 0}, |
| 5832 | "vkCmdPushConstants() call has push constants with offset 1. " |
| 5833 | "Offset must be a multiple of 4."}, |
| 5834 | {{VK_SHADER_STAGE_VERTEX_BIT, 1, 4}, |
| 5835 | "vkCmdPushConstants() call has push constants with offset 1. " |
| 5836 | "Offset must be a multiple of 4."}, |
| 5837 | {{VK_SHADER_STAGE_VERTEX_BIT, 0, 20}, |
| 5838 | "vkCmdPushConstants() Push constant range [0, 20) with stageFlags = " |
| 5839 | "0x1 not within flag-matching ranges in pipeline layout"}, |
| 5840 | {{VK_SHADER_STAGE_VERTEX_BIT, 60, 8}, |
| 5841 | "vkCmdPushConstants() Push constant range [60, 68) with stageFlags = " |
| 5842 | "0x1 not within flag-matching ranges in pipeline layout"}, |
| 5843 | {{VK_SHADER_STAGE_VERTEX_BIT, 76, 8}, |
| 5844 | "vkCmdPushConstants() Push constant range [76, 84) with stageFlags = " |
| 5845 | "0x1 not within flag-matching ranges in pipeline layout"}, |
| 5846 | {{VK_SHADER_STAGE_VERTEX_BIT, 0, 80}, |
| 5847 | "vkCmdPushConstants() Push constant range [0, 80) with stageFlags = " |
| 5848 | "0x1 not within flag-matching ranges in pipeline layout"}, |
| 5849 | {{VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT, 0, 4}, |
| 5850 | "vkCmdPushConstants() stageFlags = 0x2 do not match the stageFlags in " |
| 5851 | "any of the ranges in pipeline layout"}, |
| 5852 | {{VK_SHADER_STAGE_VERTEX_BIT | VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT, |
| 5853 | 0, 16}, |
| 5854 | "vkCmdPushConstants() stageFlags = 0x3 do not match the stageFlags in " |
| 5855 | "any of the ranges in pipeline layout"}, |
| 5856 | {{VK_SHADER_STAGE_VERTEX_BIT, 0, too_big}, |
Karl Schultz | fc8eaf1 | 2016-05-06 13:56:42 -0600 | [diff] [blame] | 5857 | "vkCmdPushConstants() call has push constants with offset "}, |
Karl Schultz | c81037d | 2016-05-12 08:11:23 -0600 | [diff] [blame] | 5858 | {{VK_SHADER_STAGE_VERTEX_BIT, too_big, too_big}, |
Karl Schultz | fc8eaf1 | 2016-05-06 13:56:42 -0600 | [diff] [blame] | 5859 | "vkCmdPushConstants() call has push constants with offset "}, |
Karl Schultz | c81037d | 2016-05-12 08:11:23 -0600 | [diff] [blame] | 5860 | {{VK_SHADER_STAGE_VERTEX_BIT, too_big, 0}, |
Karl Schultz | fc8eaf1 | 2016-05-06 13:56:42 -0600 | [diff] [blame] | 5861 | "vkCmdPushConstants() call has push constants with offset "}, |
Karl Schultz | c81037d | 2016-05-12 08:11:23 -0600 | [diff] [blame] | 5862 | {{VK_SHADER_STAGE_VERTEX_BIT, 0xFFFFFFF0, 0x00000020}, |
Karl Schultz | fc8eaf1 | 2016-05-06 13:56:42 -0600 | [diff] [blame] | 5863 | "vkCmdPushConstants() call has push constants with offset "}, |
Karl Schultz | c81037d | 2016-05-12 08:11:23 -0600 | [diff] [blame] | 5864 | {{VK_SHADER_STAGE_VERTEX_BIT, 0x00000020, 0xFFFFFFF0}, |
Karl Schultz | fc8eaf1 | 2016-05-06 13:56:42 -0600 | [diff] [blame] | 5865 | "vkCmdPushConstants() call has push constants with offset "}, |
| 5866 | }}; |
| 5867 | |
| 5868 | // Two ranges for testing robustness |
Karl Schultz | c81037d | 2016-05-12 08:11:23 -0600 | [diff] [blame] | 5869 | const VkPushConstantRange pc_range2[] = { |
Karl Schultz | fc8eaf1 | 2016-05-06 13:56:42 -0600 | [diff] [blame] | 5870 | {VK_SHADER_STAGE_VERTEX_BIT, 64, 16}, |
Karl Schultz | c81037d | 2016-05-12 08:11:23 -0600 | [diff] [blame] | 5871 | {VK_SHADER_STAGE_VERTEX_BIT, 0, 16}, |
Karl Schultz | fc8eaf1 | 2016-05-06 13:56:42 -0600 | [diff] [blame] | 5872 | }; |
Karl Schultz | c81037d | 2016-05-12 08:11:23 -0600 | [diff] [blame] | 5873 | pipeline_layout_ci.pushConstantRangeCount = |
| 5874 | sizeof(pc_range2) / sizeof(VkPushConstantRange); |
Karl Schultz | fc8eaf1 | 2016-05-06 13:56:42 -0600 | [diff] [blame] | 5875 | pipeline_layout_ci.pPushConstantRanges = pc_range2; |
Tobin Ehlis | 3a23b6a | 2016-02-17 10:35:18 -0700 | [diff] [blame] | 5876 | err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, |
| 5877 | &pipeline_layout); |
| 5878 | ASSERT_VK_SUCCESS(err); |
| 5879 | BeginCommandBuffer(); |
Karl Schultz | c81037d | 2016-05-12 08:11:23 -0600 | [diff] [blame] | 5880 | for (const auto &iter : cmd_range_tests) { |
Karl Schultz | fc8eaf1 | 2016-05-06 13:56:42 -0600 | [diff] [blame] | 5881 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 5882 | iter.msg); |
| 5883 | vkCmdPushConstants(m_commandBuffer->GetBufferHandle(), pipeline_layout, |
Karl Schultz | c81037d | 2016-05-12 08:11:23 -0600 | [diff] [blame] | 5884 | iter.range.stageFlags, iter.range.offset, |
| 5885 | iter.range.size, dummy_values); |
Karl Schultz | fc8eaf1 | 2016-05-06 13:56:42 -0600 | [diff] [blame] | 5886 | m_errorMonitor->VerifyFound(); |
| 5887 | } |
| 5888 | |
| 5889 | // Check for invalid stage flag |
| 5890 | m_errorMonitor->SetDesiredFailureMsg( |
| 5891 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 5892 | "vkCmdPushConstants() call has no stageFlags set."); |
| 5893 | vkCmdPushConstants(m_commandBuffer->GetBufferHandle(), pipeline_layout, 0, |
Karl Schultz | c81037d | 2016-05-12 08:11:23 -0600 | [diff] [blame] | 5894 | 0, 16, dummy_values); |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 5895 | m_errorMonitor->VerifyFound(); |
Karl Schultz | c81037d | 2016-05-12 08:11:23 -0600 | [diff] [blame] | 5896 | EndCommandBuffer(); |
| 5897 | vkResetCommandBuffer(m_commandBuffer->GetBufferHandle(), 0); |
| 5898 | vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL); |
Karl Schultz | fc8eaf1 | 2016-05-06 13:56:42 -0600 | [diff] [blame] | 5899 | |
Karl Schultz | c81037d | 2016-05-12 08:11:23 -0600 | [diff] [blame] | 5900 | // overlapping range tests with cmd |
| 5901 | const std::array<PipelineLayoutTestCase, 3> cmd_overlap_tests = {{ |
| 5902 | {{VK_SHADER_STAGE_VERTEX_BIT, 0, 20}, |
| 5903 | "vkCmdPushConstants() Push constant range [0, 20) with stageFlags = " |
| 5904 | "0x1 not within flag-matching ranges in pipeline layout"}, |
| 5905 | {{VK_SHADER_STAGE_VERTEX_BIT, 16, 4}, |
| 5906 | "vkCmdPushConstants() Push constant range [16, 20) with stageFlags = " |
| 5907 | "0x1 not within flag-matching ranges in pipeline layout"}, |
| 5908 | {{VK_SHADER_STAGE_VERTEX_BIT, 40, 16}, |
| 5909 | "vkCmdPushConstants() Push constant range [40, 56) with stageFlags = " |
| 5910 | "0x1 not within flag-matching ranges in pipeline layout"}, |
| 5911 | }}; |
| 5912 | const VkPushConstantRange pc_range3[] = { |
| 5913 | {VK_SHADER_STAGE_VERTEX_BIT, 20, 16}, |
| 5914 | {VK_SHADER_STAGE_VERTEX_BIT, 0, 16}, |
| 5915 | {VK_SHADER_STAGE_VERTEX_BIT, 0, 4}, |
| 5916 | {VK_SHADER_STAGE_VERTEX_BIT, 44, 8}, |
| 5917 | {VK_SHADER_STAGE_VERTEX_BIT, 80, 12}, |
| 5918 | {VK_SHADER_STAGE_VERTEX_BIT, 36, 8}, |
| 5919 | {VK_SHADER_STAGE_VERTEX_BIT, 56, 28}, |
| 5920 | }; |
| 5921 | pipeline_layout_ci.pushConstantRangeCount = |
| 5922 | sizeof(pc_range3) / sizeof(VkPushConstantRange); |
| 5923 | pipeline_layout_ci.pPushConstantRanges = pc_range3; |
| 5924 | err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, |
| 5925 | &pipeline_layout); |
| 5926 | ASSERT_VK_SUCCESS(err); |
| 5927 | BeginCommandBuffer(); |
| 5928 | for (const auto &iter : cmd_overlap_tests) { |
| 5929 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 5930 | iter.msg); |
| 5931 | vkCmdPushConstants(m_commandBuffer->GetBufferHandle(), pipeline_layout, |
| 5932 | iter.range.stageFlags, iter.range.offset, |
| 5933 | iter.range.size, dummy_values); |
| 5934 | m_errorMonitor->VerifyFound(); |
| 5935 | } |
| 5936 | EndCommandBuffer(); |
| 5937 | vkResetCommandBuffer(m_commandBuffer->GetBufferHandle(), 0); |
| 5938 | vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL); |
| 5939 | |
| 5940 | // positive overlapping range tests with cmd |
| 5941 | const std::array<PipelineLayoutTestCase, 4> cmd_overlap_tests_pos = {{ |
| 5942 | {{VK_SHADER_STAGE_VERTEX_BIT, 0, 16}, ""}, |
| 5943 | {{VK_SHADER_STAGE_VERTEX_BIT, 0, 4}, ""}, |
| 5944 | {{VK_SHADER_STAGE_VERTEX_BIT, 20, 12}, ""}, |
| 5945 | {{VK_SHADER_STAGE_VERTEX_BIT, 56, 36}, ""}, |
| 5946 | }}; |
| 5947 | const VkPushConstantRange pc_range4[] = { |
| 5948 | {VK_SHADER_STAGE_VERTEX_BIT, 0, 64}, |
| 5949 | {VK_SHADER_STAGE_VERTEX_BIT, 20, 16}, |
| 5950 | {VK_SHADER_STAGE_VERTEX_BIT, 0, 16}, |
| 5951 | {VK_SHADER_STAGE_VERTEX_BIT, 0, 4}, |
| 5952 | {VK_SHADER_STAGE_VERTEX_BIT, 44, 8}, |
| 5953 | {VK_SHADER_STAGE_VERTEX_BIT, 80, 12}, |
| 5954 | {VK_SHADER_STAGE_VERTEX_BIT, 36, 8}, |
| 5955 | {VK_SHADER_STAGE_VERTEX_BIT, 56, 28}, |
| 5956 | }; |
| 5957 | pipeline_layout_ci.pushConstantRangeCount = |
| 5958 | sizeof(pc_range4) / sizeof(VkPushConstantRange); |
| 5959 | pipeline_layout_ci.pPushConstantRanges = pc_range4; |
| 5960 | err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, |
| 5961 | &pipeline_layout); |
| 5962 | ASSERT_VK_SUCCESS(err); |
| 5963 | BeginCommandBuffer(); |
| 5964 | for (const auto &iter : cmd_overlap_tests_pos) { |
| 5965 | m_errorMonitor->ExpectSuccess(); |
| 5966 | vkCmdPushConstants(m_commandBuffer->GetBufferHandle(), pipeline_layout, |
| 5967 | iter.range.stageFlags, iter.range.offset, |
| 5968 | iter.range.size, dummy_values); |
| 5969 | m_errorMonitor->VerifyNotFound(); |
| 5970 | } |
| 5971 | EndCommandBuffer(); |
| 5972 | vkResetCommandBuffer(m_commandBuffer->GetBufferHandle(), 0); |
Tobin Ehlis | 3a23b6a | 2016-02-17 10:35:18 -0700 | [diff] [blame] | 5973 | vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL); |
| 5974 | } |
| 5975 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5976 | TEST_F(VkLayerTest, DescriptorSetCompatibility) { |
Tobin Ehlis | 559c638 | 2015-11-05 09:52:49 -0700 | [diff] [blame] | 5977 | // Test various desriptorSet errors with bad binding combinations |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5978 | VkResult err; |
Tobin Ehlis | 559c638 | 2015-11-05 09:52:49 -0700 | [diff] [blame] | 5979 | |
| 5980 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 5981 | ASSERT_NO_FATAL_FAILURE(InitViewport()); |
| 5982 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 5983 | |
Mike Stroyan | b8a6100 | 2016-06-20 16:00:28 -0600 | [diff] [blame] | 5984 | const VkFormat tex_format = VK_FORMAT_R8G8B8A8_UNORM; |
| 5985 | VkImageTiling tiling; |
| 5986 | VkFormatProperties format_properties; |
| 5987 | vkGetPhysicalDeviceFormatProperties(gpu(), tex_format, &format_properties); |
| 5988 | if (format_properties.linearTilingFeatures & |
| 5989 | VK_FORMAT_FEATURE_STORAGE_IMAGE_BIT) { |
| 5990 | tiling = VK_IMAGE_TILING_LINEAR; |
| 5991 | } else if (format_properties.optimalTilingFeatures & |
| 5992 | VK_FORMAT_FEATURE_STORAGE_IMAGE_BIT) { |
| 5993 | tiling = VK_IMAGE_TILING_OPTIMAL; |
| 5994 | } else { |
| 5995 | printf("Device does not support VK_FORMAT_FEATURE_STORAGE_IMAGE_BIT; " |
| 5996 | "skipped.\n"); |
| 5997 | return; |
| 5998 | } |
| 5999 | |
Tobin Ehlis | 559c638 | 2015-11-05 09:52:49 -0700 | [diff] [blame] | 6000 | static const uint32_t NUM_DESCRIPTOR_TYPES = 5; |
| 6001 | VkDescriptorPoolSize ds_type_count[NUM_DESCRIPTOR_TYPES] = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6002 | ds_type_count[0].type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 6003 | ds_type_count[0].descriptorCount = 10; |
| 6004 | ds_type_count[1].type = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE; |
| 6005 | ds_type_count[1].descriptorCount = 2; |
| 6006 | ds_type_count[2].type = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE; |
| 6007 | ds_type_count[2].descriptorCount = 2; |
| 6008 | ds_type_count[3].type = VK_DESCRIPTOR_TYPE_SAMPLER; |
| 6009 | ds_type_count[3].descriptorCount = 5; |
| 6010 | // TODO : LunarG ILO driver currently asserts in desc.c w/ INPUT_ATTACHMENT |
| 6011 | // type |
| 6012 | // ds_type_count[4].type = VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT; |
| 6013 | ds_type_count[4].type = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER; |
| 6014 | ds_type_count[4].descriptorCount = 2; |
Tobin Ehlis | 559c638 | 2015-11-05 09:52:49 -0700 | [diff] [blame] | 6015 | |
| 6016 | VkDescriptorPoolCreateInfo ds_pool_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6017 | ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO; |
| 6018 | ds_pool_ci.pNext = NULL; |
| 6019 | ds_pool_ci.maxSets = 5; |
| 6020 | ds_pool_ci.poolSizeCount = NUM_DESCRIPTOR_TYPES; |
| 6021 | ds_pool_ci.pPoolSizes = ds_type_count; |
Tobin Ehlis | 559c638 | 2015-11-05 09:52:49 -0700 | [diff] [blame] | 6022 | |
| 6023 | VkDescriptorPool ds_pool; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6024 | err = |
| 6025 | vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool); |
Tobin Ehlis | 559c638 | 2015-11-05 09:52:49 -0700 | [diff] [blame] | 6026 | ASSERT_VK_SUCCESS(err); |
| 6027 | |
| 6028 | static const uint32_t MAX_DS_TYPES_IN_LAYOUT = 2; |
| 6029 | VkDescriptorSetLayoutBinding dsl_binding[MAX_DS_TYPES_IN_LAYOUT] = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6030 | dsl_binding[0].binding = 0; |
| 6031 | dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 6032 | dsl_binding[0].descriptorCount = 5; |
| 6033 | dsl_binding[0].stageFlags = VK_SHADER_STAGE_ALL; |
| 6034 | dsl_binding[0].pImmutableSamplers = NULL; |
Tobin Ehlis | 559c638 | 2015-11-05 09:52:49 -0700 | [diff] [blame] | 6035 | |
Tobin Ehlis | 8fab656 | 2015-12-01 09:57:09 -0700 | [diff] [blame] | 6036 | // Create layout identical to set0 layout but w/ different stageFlags |
| 6037 | VkDescriptorSetLayoutBinding dsl_fs_stage_only = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6038 | dsl_fs_stage_only.binding = 0; |
| 6039 | dsl_fs_stage_only.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 6040 | dsl_fs_stage_only.descriptorCount = 5; |
| 6041 | dsl_fs_stage_only.stageFlags = |
| 6042 | VK_SHADER_STAGE_FRAGMENT_BIT; // Different stageFlags to cause error at |
| 6043 | // bind time |
| 6044 | dsl_fs_stage_only.pImmutableSamplers = NULL; |
Tobin Ehlis | 559c638 | 2015-11-05 09:52:49 -0700 | [diff] [blame] | 6045 | VkDescriptorSetLayoutCreateInfo ds_layout_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6046 | ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO; |
| 6047 | ds_layout_ci.pNext = NULL; |
| 6048 | ds_layout_ci.bindingCount = 1; |
| 6049 | ds_layout_ci.pBindings = dsl_binding; |
Tobin Ehlis | 559c638 | 2015-11-05 09:52:49 -0700 | [diff] [blame] | 6050 | static const uint32_t NUM_LAYOUTS = 4; |
| 6051 | VkDescriptorSetLayout ds_layout[NUM_LAYOUTS] = {}; |
Tobin Ehlis | 8fab656 | 2015-12-01 09:57:09 -0700 | [diff] [blame] | 6052 | VkDescriptorSetLayout ds_layout_fs_only = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6053 | // Create 4 unique layouts for full pipelineLayout, and 1 special fs-only |
| 6054 | // layout for error case |
| 6055 | err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, |
| 6056 | &ds_layout[0]); |
Tobin Ehlis | 559c638 | 2015-11-05 09:52:49 -0700 | [diff] [blame] | 6057 | ASSERT_VK_SUCCESS(err); |
Jon Ashburn | 6e23c1f | 2015-12-30 18:01:16 -0700 | [diff] [blame] | 6058 | ds_layout_ci.pBindings = &dsl_fs_stage_only; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6059 | err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, |
| 6060 | &ds_layout_fs_only); |
Tobin Ehlis | 8fab656 | 2015-12-01 09:57:09 -0700 | [diff] [blame] | 6061 | ASSERT_VK_SUCCESS(err); |
Tobin Ehlis | 559c638 | 2015-11-05 09:52:49 -0700 | [diff] [blame] | 6062 | dsl_binding[0].binding = 0; |
| 6063 | dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE; |
Tobin Ehlis | 8fab656 | 2015-12-01 09:57:09 -0700 | [diff] [blame] | 6064 | dsl_binding[0].descriptorCount = 2; |
Mike Stroyan | 9c70cdb | 2016-01-06 14:14:17 -0700 | [diff] [blame] | 6065 | dsl_binding[1].binding = 1; |
| 6066 | dsl_binding[1].descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE; |
| 6067 | dsl_binding[1].descriptorCount = 2; |
| 6068 | dsl_binding[1].stageFlags = VK_SHADER_STAGE_ALL; |
| 6069 | dsl_binding[1].pImmutableSamplers = NULL; |
Jon Ashburn | 6e23c1f | 2015-12-30 18:01:16 -0700 | [diff] [blame] | 6070 | ds_layout_ci.pBindings = dsl_binding; |
Tobin Ehlis | 559c638 | 2015-11-05 09:52:49 -0700 | [diff] [blame] | 6071 | ds_layout_ci.bindingCount = 2; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6072 | err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, |
| 6073 | &ds_layout[1]); |
Tobin Ehlis | 559c638 | 2015-11-05 09:52:49 -0700 | [diff] [blame] | 6074 | ASSERT_VK_SUCCESS(err); |
| 6075 | dsl_binding[0].binding = 0; |
| 6076 | dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER; |
Tobin Ehlis | 8fab656 | 2015-12-01 09:57:09 -0700 | [diff] [blame] | 6077 | dsl_binding[0].descriptorCount = 5; |
Tobin Ehlis | 559c638 | 2015-11-05 09:52:49 -0700 | [diff] [blame] | 6078 | ds_layout_ci.bindingCount = 1; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6079 | err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, |
| 6080 | &ds_layout[2]); |
Tobin Ehlis | 559c638 | 2015-11-05 09:52:49 -0700 | [diff] [blame] | 6081 | ASSERT_VK_SUCCESS(err); |
| 6082 | dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER; |
Tobin Ehlis | 8fab656 | 2015-12-01 09:57:09 -0700 | [diff] [blame] | 6083 | dsl_binding[0].descriptorCount = 2; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6084 | err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, |
| 6085 | &ds_layout[3]); |
Tobin Ehlis | 559c638 | 2015-11-05 09:52:49 -0700 | [diff] [blame] | 6086 | ASSERT_VK_SUCCESS(err); |
| 6087 | |
| 6088 | static const uint32_t NUM_SETS = 4; |
| 6089 | VkDescriptorSet descriptorSet[NUM_SETS] = {}; |
| 6090 | VkDescriptorSetAllocateInfo alloc_info = {}; |
Tobin Ehlis | 8fab656 | 2015-12-01 09:57:09 -0700 | [diff] [blame] | 6091 | alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO; |
Jon Ashburn | f19916e | 2016-01-11 13:12:43 -0700 | [diff] [blame] | 6092 | alloc_info.descriptorSetCount = NUM_LAYOUTS; |
Tobin Ehlis | 559c638 | 2015-11-05 09:52:49 -0700 | [diff] [blame] | 6093 | alloc_info.descriptorPool = ds_pool; |
| 6094 | alloc_info.pSetLayouts = ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6095 | err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, |
| 6096 | descriptorSet); |
Tobin Ehlis | 559c638 | 2015-11-05 09:52:49 -0700 | [diff] [blame] | 6097 | ASSERT_VK_SUCCESS(err); |
Tobin Ehlis | 8fab656 | 2015-12-01 09:57:09 -0700 | [diff] [blame] | 6098 | VkDescriptorSet ds0_fs_only = {}; |
Jon Ashburn | f19916e | 2016-01-11 13:12:43 -0700 | [diff] [blame] | 6099 | alloc_info.descriptorSetCount = 1; |
Tobin Ehlis | 8fab656 | 2015-12-01 09:57:09 -0700 | [diff] [blame] | 6100 | alloc_info.pSetLayouts = &ds_layout_fs_only; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6101 | err = |
| 6102 | vkAllocateDescriptorSets(m_device->device(), &alloc_info, &ds0_fs_only); |
Tobin Ehlis | 8fab656 | 2015-12-01 09:57:09 -0700 | [diff] [blame] | 6103 | ASSERT_VK_SUCCESS(err); |
Tobin Ehlis | 559c638 | 2015-11-05 09:52:49 -0700 | [diff] [blame] | 6104 | |
| 6105 | VkPipelineLayoutCreateInfo pipeline_layout_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6106 | pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO; |
| 6107 | pipeline_layout_ci.pNext = NULL; |
| 6108 | pipeline_layout_ci.setLayoutCount = NUM_LAYOUTS; |
| 6109 | pipeline_layout_ci.pSetLayouts = ds_layout; |
Tobin Ehlis | 559c638 | 2015-11-05 09:52:49 -0700 | [diff] [blame] | 6110 | |
| 6111 | VkPipelineLayout pipeline_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6112 | err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, |
| 6113 | &pipeline_layout); |
Tobin Ehlis | 559c638 | 2015-11-05 09:52:49 -0700 | [diff] [blame] | 6114 | ASSERT_VK_SUCCESS(err); |
Tobin Ehlis | 8fab656 | 2015-12-01 09:57:09 -0700 | [diff] [blame] | 6115 | // Create pipelineLayout with only one setLayout |
| 6116 | pipeline_layout_ci.setLayoutCount = 1; |
| 6117 | VkPipelineLayout single_pipe_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6118 | err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, |
| 6119 | &single_pipe_layout); |
Tobin Ehlis | 8fab656 | 2015-12-01 09:57:09 -0700 | [diff] [blame] | 6120 | ASSERT_VK_SUCCESS(err); |
| 6121 | // Create pipelineLayout with 2 descriptor setLayout at index 0 |
| 6122 | pipeline_layout_ci.pSetLayouts = &ds_layout[3]; |
| 6123 | VkPipelineLayout pipe_layout_one_desc; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6124 | err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, |
| 6125 | &pipe_layout_one_desc); |
Tobin Ehlis | 8fab656 | 2015-12-01 09:57:09 -0700 | [diff] [blame] | 6126 | ASSERT_VK_SUCCESS(err); |
| 6127 | // Create pipelineLayout with 5 SAMPLER descriptor setLayout at index 0 |
| 6128 | pipeline_layout_ci.pSetLayouts = &ds_layout[2]; |
| 6129 | VkPipelineLayout pipe_layout_five_samp; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6130 | err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, |
| 6131 | &pipe_layout_five_samp); |
Tobin Ehlis | 8fab656 | 2015-12-01 09:57:09 -0700 | [diff] [blame] | 6132 | ASSERT_VK_SUCCESS(err); |
| 6133 | // Create pipelineLayout with UB type, but stageFlags for FS only |
| 6134 | pipeline_layout_ci.pSetLayouts = &ds_layout_fs_only; |
| 6135 | VkPipelineLayout pipe_layout_fs_only; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6136 | err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, |
| 6137 | &pipe_layout_fs_only); |
Tobin Ehlis | 8fab656 | 2015-12-01 09:57:09 -0700 | [diff] [blame] | 6138 | ASSERT_VK_SUCCESS(err); |
| 6139 | // Create pipelineLayout w/ incompatible set0 layout, but set1 is fine |
| 6140 | VkDescriptorSetLayout pl_bad_s0[2] = {}; |
| 6141 | pl_bad_s0[0] = ds_layout_fs_only; |
| 6142 | pl_bad_s0[1] = ds_layout[1]; |
| 6143 | pipeline_layout_ci.setLayoutCount = 2; |
| 6144 | pipeline_layout_ci.pSetLayouts = pl_bad_s0; |
| 6145 | VkPipelineLayout pipe_layout_bad_set0; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6146 | err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, |
| 6147 | &pipe_layout_bad_set0); |
Tobin Ehlis | 8fab656 | 2015-12-01 09:57:09 -0700 | [diff] [blame] | 6148 | ASSERT_VK_SUCCESS(err); |
Tobin Ehlis | 559c638 | 2015-11-05 09:52:49 -0700 | [diff] [blame] | 6149 | |
| 6150 | // Create a buffer to update the descriptor with |
| 6151 | uint32_t qfi = 0; |
| 6152 | VkBufferCreateInfo buffCI = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6153 | buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO; |
| 6154 | buffCI.size = 1024; |
| 6155 | buffCI.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT; |
| 6156 | buffCI.queueFamilyIndexCount = 1; |
| 6157 | buffCI.pQueueFamilyIndices = &qfi; |
Tobin Ehlis | 559c638 | 2015-11-05 09:52:49 -0700 | [diff] [blame] | 6158 | |
| 6159 | VkBuffer dyub; |
| 6160 | err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &dyub); |
| 6161 | ASSERT_VK_SUCCESS(err); |
| 6162 | // Correctly update descriptor to avoid "NOT_UPDATED" error |
| 6163 | static const uint32_t NUM_BUFFS = 5; |
| 6164 | VkDescriptorBufferInfo buffInfo[NUM_BUFFS] = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6165 | for (uint32_t i = 0; i < NUM_BUFFS; ++i) { |
Tobin Ehlis | 559c638 | 2015-11-05 09:52:49 -0700 | [diff] [blame] | 6166 | buffInfo[i].buffer = dyub; |
| 6167 | buffInfo[i].offset = 0; |
| 6168 | buffInfo[i].range = 1024; |
| 6169 | } |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6170 | VkImage image; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6171 | const int32_t tex_width = 32; |
| 6172 | const int32_t tex_height = 32; |
Tobin Ehlis | 8fab656 | 2015-12-01 09:57:09 -0700 | [diff] [blame] | 6173 | VkImageCreateInfo image_create_info = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6174 | image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO; |
| 6175 | image_create_info.pNext = NULL; |
| 6176 | image_create_info.imageType = VK_IMAGE_TYPE_2D; |
| 6177 | image_create_info.format = tex_format; |
| 6178 | image_create_info.extent.width = tex_width; |
| 6179 | image_create_info.extent.height = tex_height; |
| 6180 | image_create_info.extent.depth = 1; |
| 6181 | image_create_info.mipLevels = 1; |
| 6182 | image_create_info.arrayLayers = 1; |
| 6183 | image_create_info.samples = VK_SAMPLE_COUNT_1_BIT; |
Mike Stroyan | b8a6100 | 2016-06-20 16:00:28 -0600 | [diff] [blame] | 6184 | image_create_info.tiling = tiling; |
| 6185 | image_create_info.usage = |
| 6186 | VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_STORAGE_BIT; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6187 | image_create_info.flags = 0; |
Tobin Ehlis | 8fab656 | 2015-12-01 09:57:09 -0700 | [diff] [blame] | 6188 | err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image); |
| 6189 | ASSERT_VK_SUCCESS(err); |
Tobin Ehlis | 559c638 | 2015-11-05 09:52:49 -0700 | [diff] [blame] | 6190 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6191 | VkMemoryRequirements memReqs; |
| 6192 | VkDeviceMemory imageMem; |
| 6193 | bool pass; |
Mike Stroyan | 9c70cdb | 2016-01-06 14:14:17 -0700 | [diff] [blame] | 6194 | VkMemoryAllocateInfo memAlloc = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6195 | memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO; |
| 6196 | memAlloc.pNext = NULL; |
| 6197 | memAlloc.allocationSize = 0; |
| 6198 | memAlloc.memoryTypeIndex = 0; |
Mike Stroyan | 9c70cdb | 2016-01-06 14:14:17 -0700 | [diff] [blame] | 6199 | vkGetImageMemoryRequirements(m_device->device(), image, &memReqs); |
| 6200 | memAlloc.allocationSize = memReqs.size; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6201 | pass = |
| 6202 | m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0); |
Mike Stroyan | 9c70cdb | 2016-01-06 14:14:17 -0700 | [diff] [blame] | 6203 | ASSERT_TRUE(pass); |
| 6204 | err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &imageMem); |
| 6205 | ASSERT_VK_SUCCESS(err); |
| 6206 | err = vkBindImageMemory(m_device->device(), image, imageMem, 0); |
| 6207 | ASSERT_VK_SUCCESS(err); |
| 6208 | |
Tobin Ehlis | 8fab656 | 2015-12-01 09:57:09 -0700 | [diff] [blame] | 6209 | VkImageViewCreateInfo image_view_create_info = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6210 | image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO; |
| 6211 | image_view_create_info.image = image; |
| 6212 | image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D; |
| 6213 | image_view_create_info.format = tex_format; |
| 6214 | image_view_create_info.subresourceRange.layerCount = 1; |
| 6215 | image_view_create_info.subresourceRange.baseMipLevel = 0; |
| 6216 | image_view_create_info.subresourceRange.levelCount = 1; |
| 6217 | image_view_create_info.subresourceRange.aspectMask = |
| 6218 | VK_IMAGE_ASPECT_COLOR_BIT; |
Tobin Ehlis | 559c638 | 2015-11-05 09:52:49 -0700 | [diff] [blame] | 6219 | |
Tobin Ehlis | 8fab656 | 2015-12-01 09:57:09 -0700 | [diff] [blame] | 6220 | VkImageView view; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6221 | err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, |
| 6222 | &view); |
Tobin Ehlis | 8fab656 | 2015-12-01 09:57:09 -0700 | [diff] [blame] | 6223 | ASSERT_VK_SUCCESS(err); |
Tobin Ehlis | 991d45a | 2016-01-06 08:48:41 -0700 | [diff] [blame] | 6224 | VkDescriptorImageInfo imageInfo[4] = {}; |
Tobin Ehlis | 8fab656 | 2015-12-01 09:57:09 -0700 | [diff] [blame] | 6225 | imageInfo[0].imageView = view; |
| 6226 | imageInfo[0].imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL; |
| 6227 | imageInfo[1].imageView = view; |
| 6228 | imageInfo[1].imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL; |
Tobin Ehlis | 991d45a | 2016-01-06 08:48:41 -0700 | [diff] [blame] | 6229 | imageInfo[2].imageView = view; |
| 6230 | imageInfo[2].imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL; |
| 6231 | imageInfo[3].imageView = view; |
| 6232 | imageInfo[3].imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL; |
Tobin Ehlis | 8fab656 | 2015-12-01 09:57:09 -0700 | [diff] [blame] | 6233 | |
| 6234 | static const uint32_t NUM_SET_UPDATES = 3; |
| 6235 | VkWriteDescriptorSet descriptor_write[NUM_SET_UPDATES] = {}; |
| 6236 | descriptor_write[0].sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET; |
| 6237 | descriptor_write[0].dstSet = descriptorSet[0]; |
| 6238 | descriptor_write[0].dstBinding = 0; |
| 6239 | descriptor_write[0].descriptorCount = 5; |
| 6240 | descriptor_write[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 6241 | descriptor_write[0].pBufferInfo = buffInfo; |
| 6242 | descriptor_write[1].sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET; |
| 6243 | descriptor_write[1].dstSet = descriptorSet[1]; |
| 6244 | descriptor_write[1].dstBinding = 0; |
| 6245 | descriptor_write[1].descriptorCount = 2; |
| 6246 | descriptor_write[1].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE; |
| 6247 | descriptor_write[1].pImageInfo = imageInfo; |
| 6248 | descriptor_write[2].sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET; |
| 6249 | descriptor_write[2].dstSet = descriptorSet[1]; |
| 6250 | descriptor_write[2].dstBinding = 1; |
| 6251 | descriptor_write[2].descriptorCount = 2; |
| 6252 | descriptor_write[2].descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE; |
Tobin Ehlis | 991d45a | 2016-01-06 08:48:41 -0700 | [diff] [blame] | 6253 | descriptor_write[2].pImageInfo = &imageInfo[2]; |
Tobin Ehlis | 8fab656 | 2015-12-01 09:57:09 -0700 | [diff] [blame] | 6254 | |
| 6255 | vkUpdateDescriptorSets(m_device->device(), 3, descriptor_write, 0, NULL); |
Tobin Ehlis | 559c638 | 2015-11-05 09:52:49 -0700 | [diff] [blame] | 6256 | |
Tobin Ehlis | 8845283 | 2015-12-03 09:40:56 -0700 | [diff] [blame] | 6257 | // Create PSO to be used for draw-time errors below |
| 6258 | char const *vsSource = |
Chris Forbes | 7b34280 | 2016-04-07 13:20:10 +1200 | [diff] [blame] | 6259 | "#version 450\n" |
Tobin Ehlis | 8845283 | 2015-12-03 09:40:56 -0700 | [diff] [blame] | 6260 | "\n" |
Tony Barbour | e804d20 | 2016-01-05 13:37:45 -0700 | [diff] [blame] | 6261 | "out gl_PerVertex {\n" |
| 6262 | " vec4 gl_Position;\n" |
| 6263 | "};\n" |
Tobin Ehlis | 8845283 | 2015-12-03 09:40:56 -0700 | [diff] [blame] | 6264 | "void main(){\n" |
| 6265 | " gl_Position = vec4(1);\n" |
| 6266 | "}\n"; |
| 6267 | char const *fsSource = |
Chris Forbes | 7b34280 | 2016-04-07 13:20:10 +1200 | [diff] [blame] | 6268 | "#version 450\n" |
Tobin Ehlis | 8845283 | 2015-12-03 09:40:56 -0700 | [diff] [blame] | 6269 | "\n" |
| 6270 | "layout(location=0) out vec4 x;\n" |
| 6271 | "layout(set=0) layout(binding=0) uniform foo { int x; int y; } bar;\n" |
| 6272 | "void main(){\n" |
| 6273 | " x = vec4(bar.y);\n" |
| 6274 | "}\n"; |
| 6275 | VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this); |
| 6276 | VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this); |
Tobin Ehlis | 559c638 | 2015-11-05 09:52:49 -0700 | [diff] [blame] | 6277 | VkPipelineObj pipe(m_device); |
| 6278 | pipe.AddShader(&vs); |
| 6279 | pipe.AddShader(&fs); |
Tobin Ehlis | 8845283 | 2015-12-03 09:40:56 -0700 | [diff] [blame] | 6280 | pipe.AddColorAttachment(); |
| 6281 | pipe.CreateVKPipeline(pipe_layout_fs_only, renderPass()); |
Tobin Ehlis | 559c638 | 2015-11-05 09:52:49 -0700 | [diff] [blame] | 6282 | |
| 6283 | BeginCommandBuffer(); |
Tobin Ehlis | 8845283 | 2015-12-03 09:40:56 -0700 | [diff] [blame] | 6284 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6285 | vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), |
| 6286 | VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle()); |
| 6287 | // NOTE : I believe LunarG ilo driver has bug (LX#189) that requires binding |
| 6288 | // of PSO |
| 6289 | // here before binding DSs. Otherwise we assert in cmd_copy_dset_data() of |
| 6290 | // cmd_pipeline.c |
| 6291 | // due to the fact that cmd_alloc_dset_data() has not been called in |
| 6292 | // cmd_bind_graphics_pipeline() |
| 6293 | // TODO : Want to cause various binding incompatibility issues here to test |
| 6294 | // DrawState |
Tobin Ehlis | 559c638 | 2015-11-05 09:52:49 -0700 | [diff] [blame] | 6295 | // First cause various verify_layout_compatibility() fails |
| 6296 | // Second disturb early and late sets and verify INFO msgs |
Tobin Ehlis | 8fab656 | 2015-12-01 09:57:09 -0700 | [diff] [blame] | 6297 | // verify_set_layout_compatibility fail cases: |
| 6298 | // 1. invalid VkPipelineLayout (layout) passed into vkCmdBindDescriptorSets |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6299 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 6300 | " due to: invalid VkPipelineLayout "); |
| 6301 | vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), |
| 6302 | VK_PIPELINE_BIND_POINT_GRAPHICS, |
| 6303 | (VkPipelineLayout)((size_t)0xbaadb1be), 0, 1, |
| 6304 | &descriptorSet[0], 0, NULL); |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 6305 | m_errorMonitor->VerifyFound(); |
| 6306 | |
Tobin Ehlis | 8fab656 | 2015-12-01 09:57:09 -0700 | [diff] [blame] | 6307 | // 2. layoutIndex exceeds # of layouts in layout |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6308 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 6309 | " attempting to bind set to index 1"); |
| 6310 | vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), |
| 6311 | VK_PIPELINE_BIND_POINT_GRAPHICS, single_pipe_layout, |
| 6312 | 0, 2, &descriptorSet[0], 0, NULL); |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 6313 | m_errorMonitor->VerifyFound(); |
| 6314 | |
Tobin Ehlis | 8fab656 | 2015-12-01 09:57:09 -0700 | [diff] [blame] | 6315 | vkDestroyPipelineLayout(m_device->device(), single_pipe_layout, NULL); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6316 | // 3. Pipeline setLayout[0] has 2 descriptors, but set being bound has 5 |
| 6317 | // descriptors |
| 6318 | m_errorMonitor->SetDesiredFailureMsg( |
| 6319 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Tobin Ehlis | 2d9deec | 2016-04-21 14:19:26 -0600 | [diff] [blame] | 6320 | " has 2 descriptors, but DescriptorSetLayout "); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6321 | vkCmdBindDescriptorSets( |
| 6322 | m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, |
| 6323 | pipe_layout_one_desc, 0, 1, &descriptorSet[0], 0, NULL); |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 6324 | m_errorMonitor->VerifyFound(); |
| 6325 | |
Tobin Ehlis | 8fab656 | 2015-12-01 09:57:09 -0700 | [diff] [blame] | 6326 | vkDestroyPipelineLayout(m_device->device(), pipe_layout_one_desc, NULL); |
| 6327 | // 4. same # of descriptors but mismatch in type |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6328 | m_errorMonitor->SetDesiredFailureMsg( |
| 6329 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Tobin Ehlis | 2d9deec | 2016-04-21 14:19:26 -0600 | [diff] [blame] | 6330 | " is type 'VK_DESCRIPTOR_TYPE_SAMPLER' but binding "); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6331 | vkCmdBindDescriptorSets( |
| 6332 | m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, |
| 6333 | pipe_layout_five_samp, 0, 1, &descriptorSet[0], 0, NULL); |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 6334 | m_errorMonitor->VerifyFound(); |
| 6335 | |
Tobin Ehlis | 8fab656 | 2015-12-01 09:57:09 -0700 | [diff] [blame] | 6336 | vkDestroyPipelineLayout(m_device->device(), pipe_layout_five_samp, NULL); |
| 6337 | // 5. same # of descriptors but mismatch in stageFlags |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6338 | m_errorMonitor->SetDesiredFailureMsg( |
| 6339 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Tobin Ehlis | 2d9deec | 2016-04-21 14:19:26 -0600 | [diff] [blame] | 6340 | " has stageFlags 16 but binding 0 for DescriptorSetLayout "); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6341 | vkCmdBindDescriptorSets( |
| 6342 | m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, |
| 6343 | pipe_layout_fs_only, 0, 1, &descriptorSet[0], 0, NULL); |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 6344 | m_errorMonitor->VerifyFound(); |
| 6345 | |
Tobin Ehlis | 8fab656 | 2015-12-01 09:57:09 -0700 | [diff] [blame] | 6346 | // Cause INFO messages due to disturbing previously bound Sets |
| 6347 | // First bind sets 0 & 1 |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6348 | vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), |
| 6349 | VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, |
| 6350 | 2, &descriptorSet[0], 0, NULL); |
Tobin Ehlis | 8fab656 | 2015-12-01 09:57:09 -0700 | [diff] [blame] | 6351 | // 1. Disturb bound set0 by re-binding set1 w/ updated pipelineLayout |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6352 | m_errorMonitor->SetDesiredFailureMsg( |
Mark Lobodzinski | 510e20d | 2016-02-11 09:26:16 -0700 | [diff] [blame] | 6353 | VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6354 | " previously bound as set #0 was disturbed "); |
| 6355 | vkCmdBindDescriptorSets( |
| 6356 | m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, |
| 6357 | pipe_layout_bad_set0, 1, 1, &descriptorSet[1], 0, NULL); |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 6358 | m_errorMonitor->VerifyFound(); |
| 6359 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6360 | vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), |
| 6361 | VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, |
| 6362 | 2, &descriptorSet[0], 0, NULL); |
Tobin Ehlis | 8fab656 | 2015-12-01 09:57:09 -0700 | [diff] [blame] | 6363 | // 2. Disturb set after last bound set |
Mark Lobodzinski | 510e20d | 2016-02-11 09:26:16 -0700 | [diff] [blame] | 6364 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6365 | " newly bound as set #0 so set #1 and " |
| 6366 | "any subsequent sets were disturbed "); |
| 6367 | vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), |
| 6368 | VK_PIPELINE_BIND_POINT_GRAPHICS, |
| 6369 | pipe_layout_fs_only, 0, 1, &ds0_fs_only, 0, NULL); |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 6370 | m_errorMonitor->VerifyFound(); |
| 6371 | |
Tobin Ehlis | 8845283 | 2015-12-03 09:40:56 -0700 | [diff] [blame] | 6372 | // Cause draw-time errors due to PSO incompatibilities |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6373 | // 1. Error due to not binding required set (we actually use same code as |
| 6374 | // above to disturb set0) |
| 6375 | vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), |
| 6376 | VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, |
| 6377 | 2, &descriptorSet[0], 0, NULL); |
| 6378 | vkCmdBindDescriptorSets( |
| 6379 | m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, |
| 6380 | pipe_layout_bad_set0, 1, 1, &descriptorSet[1], 0, NULL); |
| 6381 | m_errorMonitor->SetDesiredFailureMsg( |
| 6382 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 6383 | " uses set #0 but that set is not bound."); |
Tobin Ehlis | 8845283 | 2015-12-03 09:40:56 -0700 | [diff] [blame] | 6384 | Draw(1, 0, 0, 0); |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 6385 | m_errorMonitor->VerifyFound(); |
| 6386 | |
Tobin Ehlis | 991d45a | 2016-01-06 08:48:41 -0700 | [diff] [blame] | 6387 | vkDestroyPipelineLayout(m_device->device(), pipe_layout_bad_set0, NULL); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6388 | // 2. Error due to bound set not being compatible with PSO's |
| 6389 | // VkPipelineLayout (diff stageFlags in this case) |
| 6390 | vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), |
| 6391 | VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, |
| 6392 | 2, &descriptorSet[0], 0, NULL); |
| 6393 | m_errorMonitor->SetDesiredFailureMsg( |
| 6394 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 6395 | " bound as set #0 is not compatible with "); |
Tobin Ehlis | 8845283 | 2015-12-03 09:40:56 -0700 | [diff] [blame] | 6396 | Draw(1, 0, 0, 0); |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 6397 | m_errorMonitor->VerifyFound(); |
| 6398 | |
Tobin Ehlis | 8fab656 | 2015-12-01 09:57:09 -0700 | [diff] [blame] | 6399 | // Remaining clean-up |
| 6400 | vkDestroyPipelineLayout(m_device->device(), pipe_layout_fs_only, NULL); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6401 | for (uint32_t i = 0; i < NUM_LAYOUTS; ++i) { |
Tobin Ehlis | 8fab656 | 2015-12-01 09:57:09 -0700 | [diff] [blame] | 6402 | vkDestroyDescriptorSetLayout(m_device->device(), ds_layout[i], NULL); |
| 6403 | } |
| 6404 | vkDestroyDescriptorSetLayout(m_device->device(), ds_layout_fs_only, NULL); |
Tobin Ehlis | 9bfd449 | 2016-05-05 15:09:11 -0600 | [diff] [blame] | 6405 | vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &ds0_fs_only); |
| 6406 | vkFreeDescriptorSets(m_device->device(), ds_pool, NUM_SETS, descriptorSet); |
Tobin Ehlis | 8fab656 | 2015-12-01 09:57:09 -0700 | [diff] [blame] | 6407 | vkDestroyBuffer(m_device->device(), dyub, NULL); |
Tobin Ehlis | 559c638 | 2015-11-05 09:52:49 -0700 | [diff] [blame] | 6408 | vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL); |
| 6409 | vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL); |
Tony Barbour | df4c004 | 2016-06-01 15:55:43 -0600 | [diff] [blame] | 6410 | vkFreeMemory(m_device->device(), imageMem, NULL); |
| 6411 | vkDestroyImage(m_device->device(), image, NULL); |
| 6412 | vkDestroyImageView(m_device->device(), view, NULL); |
Tobin Ehlis | 559c638 | 2015-11-05 09:52:49 -0700 | [diff] [blame] | 6413 | } |
Tobin Ehlis | 559c638 | 2015-11-05 09:52:49 -0700 | [diff] [blame] | 6414 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6415 | TEST_F(VkLayerTest, NoBeginCommandBuffer) { |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 6416 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6417 | m_errorMonitor->SetDesiredFailureMsg( |
| 6418 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 6419 | "You must call vkBeginCommandBuffer() before this call to "); |
Tobin Ehlis | af1f3a4 | 2015-06-25 15:46:59 -0600 | [diff] [blame] | 6420 | |
| 6421 | ASSERT_NO_FATAL_FAILURE(InitState()); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 6422 | VkCommandBufferObj commandBuffer(m_device, m_commandPool); |
Tobin Ehlis | af1f3a4 | 2015-06-25 15:46:59 -0600 | [diff] [blame] | 6423 | // Call EndCommandBuffer() w/o calling BeginCommandBuffer() |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 6424 | vkEndCommandBuffer(commandBuffer.GetBufferHandle()); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 6425 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 6426 | m_errorMonitor->VerifyFound(); |
Tobin Ehlis | af1f3a4 | 2015-06-25 15:46:59 -0600 | [diff] [blame] | 6427 | } |
| 6428 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6429 | TEST_F(VkLayerTest, SecondaryCommandBufferNullRenderpass) { |
| 6430 | VkResult err; |
| 6431 | VkCommandBuffer draw_cmd; |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 6432 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6433 | m_errorMonitor->SetDesiredFailureMsg( |
| 6434 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Tobin Ehlis | 61b36f3 | 2015-12-16 08:19:42 -0700 | [diff] [blame] | 6435 | " must specify a valid renderpass parameter."); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 6436 | |
Mark Lobodzinski | d9139a6 | 2015-08-04 16:24:20 -0600 | [diff] [blame] | 6437 | ASSERT_NO_FATAL_FAILURE(InitState()); |
Mark Lobodzinski | d9139a6 | 2015-08-04 16:24:20 -0600 | [diff] [blame] | 6438 | |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 6439 | VkCommandBufferAllocateInfo cmd = {}; |
Chia-I Wu | 00ce540 | 2015-11-10 16:21:09 +0800 | [diff] [blame] | 6440 | cmd.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO; |
Cody Northrop | b456970 | 2015-08-04 17:35:57 -0600 | [diff] [blame] | 6441 | cmd.pNext = NULL; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 6442 | cmd.commandPool = m_commandPool; |
| 6443 | cmd.level = VK_COMMAND_BUFFER_LEVEL_SECONDARY; |
Jon Ashburn | f19916e | 2016-01-11 13:12:43 -0700 | [diff] [blame] | 6444 | cmd.commandBufferCount = 1; |
Cody Northrop | b456970 | 2015-08-04 17:35:57 -0600 | [diff] [blame] | 6445 | |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 6446 | err = vkAllocateCommandBuffers(m_device->device(), &cmd, &draw_cmd); |
Mike Stroyan | d1c84a5 | 2015-08-18 14:40:24 -0600 | [diff] [blame] | 6447 | ASSERT_VK_SUCCESS(err); |
Mark Lobodzinski | d9139a6 | 2015-08-04 16:24:20 -0600 | [diff] [blame] | 6448 | |
| 6449 | // Force the failure by not setting the Renderpass and Framebuffer fields |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 6450 | VkCommandBufferBeginInfo cmd_buf_info = {}; |
Jon Ashburn | f19916e | 2016-01-11 13:12:43 -0700 | [diff] [blame] | 6451 | VkCommandBufferInheritanceInfo cmd_buf_hinfo = {}; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 6452 | cmd_buf_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO; |
Cody Northrop | b456970 | 2015-08-04 17:35:57 -0600 | [diff] [blame] | 6453 | cmd_buf_info.pNext = NULL; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6454 | cmd_buf_info.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT | |
| 6455 | VK_COMMAND_BUFFER_USAGE_RENDER_PASS_CONTINUE_BIT; |
Jon Ashburn | f19916e | 2016-01-11 13:12:43 -0700 | [diff] [blame] | 6456 | cmd_buf_info.pInheritanceInfo = &cmd_buf_hinfo; |
Mark Lobodzinski | d9139a6 | 2015-08-04 16:24:20 -0600 | [diff] [blame] | 6457 | |
| 6458 | // The error should be caught by validation of the BeginCommandBuffer call |
| 6459 | vkBeginCommandBuffer(draw_cmd, &cmd_buf_info); |
| 6460 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 6461 | m_errorMonitor->VerifyFound(); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 6462 | vkFreeCommandBuffers(m_device->device(), m_commandPool, 1, &draw_cmd); |
Mark Lobodzinski | d9139a6 | 2015-08-04 16:24:20 -0600 | [diff] [blame] | 6463 | } |
| 6464 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6465 | TEST_F(VkLayerTest, CommandBufferResetErrors) { |
Tobin Ehlis | ac0ef84 | 2015-12-14 13:46:38 -0700 | [diff] [blame] | 6466 | // Cause error due to Begin while recording CB |
| 6467 | // Then cause 2 errors for attempting to reset CB w/o having |
| 6468 | // VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT set for the pool from |
| 6469 | // which CBs were allocated. Note that this bit is off by default. |
Courtney Goeltzenleuchter | 7415d5a | 2015-12-09 15:48:16 -0700 | [diff] [blame] | 6470 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6471 | "Cannot call Begin on CB"); |
Tobin Ehlis | ac0ef84 | 2015-12-14 13:46:38 -0700 | [diff] [blame] | 6472 | |
| 6473 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 6474 | |
| 6475 | // Calls AllocateCommandBuffers |
| 6476 | VkCommandBufferObj commandBuffer(m_device, m_commandPool); |
| 6477 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6478 | // Force the failure by setting the Renderpass and Framebuffer fields with |
| 6479 | // (fake) data |
Tobin Ehlis | ac0ef84 | 2015-12-14 13:46:38 -0700 | [diff] [blame] | 6480 | VkCommandBufferBeginInfo cmd_buf_info = {}; |
Jon Ashburn | f19916e | 2016-01-11 13:12:43 -0700 | [diff] [blame] | 6481 | VkCommandBufferInheritanceInfo cmd_buf_hinfo = {}; |
Tobin Ehlis | ac0ef84 | 2015-12-14 13:46:38 -0700 | [diff] [blame] | 6482 | cmd_buf_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO; |
| 6483 | cmd_buf_info.pNext = NULL; |
| 6484 | cmd_buf_info.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT; |
Jon Ashburn | f19916e | 2016-01-11 13:12:43 -0700 | [diff] [blame] | 6485 | cmd_buf_info.pInheritanceInfo = &cmd_buf_hinfo; |
Tobin Ehlis | ac0ef84 | 2015-12-14 13:46:38 -0700 | [diff] [blame] | 6486 | |
| 6487 | // Begin CB to transition to recording state |
| 6488 | vkBeginCommandBuffer(commandBuffer.GetBufferHandle(), &cmd_buf_info); |
| 6489 | // Can't re-begin. This should trigger error |
| 6490 | vkBeginCommandBuffer(commandBuffer.GetBufferHandle(), &cmd_buf_info); |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 6491 | m_errorMonitor->VerifyFound(); |
| 6492 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6493 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 6494 | "Attempt to reset command buffer "); |
Tobin Ehlis | ac0ef84 | 2015-12-14 13:46:38 -0700 | [diff] [blame] | 6495 | VkCommandBufferResetFlags flags = 0; // Don't care about flags for this test |
| 6496 | // Reset attempt will trigger error due to incorrect CommandPool state |
| 6497 | vkResetCommandBuffer(commandBuffer.GetBufferHandle(), flags); |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 6498 | m_errorMonitor->VerifyFound(); |
| 6499 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6500 | m_errorMonitor->SetDesiredFailureMsg( |
| 6501 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 6502 | " attempts to implicitly reset cmdBuffer created from "); |
Tobin Ehlis | ac0ef84 | 2015-12-14 13:46:38 -0700 | [diff] [blame] | 6503 | // Transition CB to RECORDED state |
| 6504 | vkEndCommandBuffer(commandBuffer.GetBufferHandle()); |
| 6505 | // Now attempting to Begin will implicitly reset, which triggers error |
| 6506 | vkBeginCommandBuffer(commandBuffer.GetBufferHandle(), &cmd_buf_info); |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 6507 | m_errorMonitor->VerifyFound(); |
Tobin Ehlis | ac0ef84 | 2015-12-14 13:46:38 -0700 | [diff] [blame] | 6508 | } |
| 6509 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6510 | TEST_F(VkLayerTest, InvalidPipelineCreateState) { |
Tobin Ehlis | af1f3a4 | 2015-06-25 15:46:59 -0600 | [diff] [blame] | 6511 | // Attempt to Create Gfx Pipeline w/o a VS |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6512 | VkResult err; |
Tobin Ehlis | af1f3a4 | 2015-06-25 15:46:59 -0600 | [diff] [blame] | 6513 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6514 | m_errorMonitor->SetDesiredFailureMsg( |
| 6515 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 6516 | "Invalid Pipeline CreateInfo State: Vtx Shader required"); |
| 6517 | |
Tobin Ehlis | af1f3a4 | 2015-06-25 15:46:59 -0600 | [diff] [blame] | 6518 | ASSERT_NO_FATAL_FAILURE(InitState()); |
Tobin Ehlis | c9ac2b6 | 2015-09-11 12:57:55 -0600 | [diff] [blame] | 6519 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
Mark Lobodzinski | 209b529 | 2015-09-17 09:44:05 -0600 | [diff] [blame] | 6520 | |
Chia-I Wu | 1b99bb2 | 2015-10-27 19:25:11 +0800 | [diff] [blame] | 6521 | VkDescriptorPoolSize ds_type_count = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6522 | ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 6523 | ds_type_count.descriptorCount = 1; |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 6524 | |
| 6525 | VkDescriptorPoolCreateInfo ds_pool_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6526 | ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO; |
| 6527 | ds_pool_ci.pNext = NULL; |
| 6528 | ds_pool_ci.maxSets = 1; |
| 6529 | ds_pool_ci.poolSizeCount = 1; |
| 6530 | ds_pool_ci.pPoolSizes = &ds_type_count; |
Mark Lobodzinski | 209b529 | 2015-09-17 09:44:05 -0600 | [diff] [blame] | 6531 | |
Tobin Ehlis | af1f3a4 | 2015-06-25 15:46:59 -0600 | [diff] [blame] | 6532 | VkDescriptorPool ds_pool; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6533 | err = |
| 6534 | vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool); |
Tobin Ehlis | af1f3a4 | 2015-06-25 15:46:59 -0600 | [diff] [blame] | 6535 | ASSERT_VK_SUCCESS(err); |
| 6536 | |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 6537 | VkDescriptorSetLayoutBinding dsl_binding = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6538 | dsl_binding.binding = 0; |
| 6539 | dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 6540 | dsl_binding.descriptorCount = 1; |
| 6541 | dsl_binding.stageFlags = VK_SHADER_STAGE_ALL; |
| 6542 | dsl_binding.pImmutableSamplers = NULL; |
Tobin Ehlis | af1f3a4 | 2015-06-25 15:46:59 -0600 | [diff] [blame] | 6543 | |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 6544 | VkDescriptorSetLayoutCreateInfo ds_layout_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6545 | ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO; |
| 6546 | ds_layout_ci.pNext = NULL; |
| 6547 | ds_layout_ci.bindingCount = 1; |
| 6548 | ds_layout_ci.pBindings = &dsl_binding; |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 6549 | |
Tobin Ehlis | af1f3a4 | 2015-06-25 15:46:59 -0600 | [diff] [blame] | 6550 | VkDescriptorSetLayout ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6551 | err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, |
| 6552 | &ds_layout); |
Tobin Ehlis | af1f3a4 | 2015-06-25 15:46:59 -0600 | [diff] [blame] | 6553 | ASSERT_VK_SUCCESS(err); |
| 6554 | |
| 6555 | VkDescriptorSet descriptorSet; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 6556 | VkDescriptorSetAllocateInfo alloc_info = {}; |
Chia-I Wu | 00ce540 | 2015-11-10 16:21:09 +0800 | [diff] [blame] | 6557 | alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO; |
Jon Ashburn | f19916e | 2016-01-11 13:12:43 -0700 | [diff] [blame] | 6558 | alloc_info.descriptorSetCount = 1; |
Courtney Goeltzenleuchter | bee18a9 | 2015-10-23 14:21:05 -0600 | [diff] [blame] | 6559 | alloc_info.descriptorPool = ds_pool; |
| 6560 | alloc_info.pSetLayouts = &ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6561 | err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, |
| 6562 | &descriptorSet); |
Tobin Ehlis | af1f3a4 | 2015-06-25 15:46:59 -0600 | [diff] [blame] | 6563 | ASSERT_VK_SUCCESS(err); |
| 6564 | |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 6565 | VkPipelineLayoutCreateInfo pipeline_layout_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6566 | pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO; |
| 6567 | pipeline_layout_ci.setLayoutCount = 1; |
| 6568 | pipeline_layout_ci.pSetLayouts = &ds_layout; |
Tobin Ehlis | af1f3a4 | 2015-06-25 15:46:59 -0600 | [diff] [blame] | 6569 | |
| 6570 | VkPipelineLayout pipeline_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6571 | err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, |
| 6572 | &pipeline_layout); |
Tobin Ehlis | af1f3a4 | 2015-06-25 15:46:59 -0600 | [diff] [blame] | 6573 | ASSERT_VK_SUCCESS(err); |
| 6574 | |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 6575 | VkViewport vp = {}; // Just need dummy vp to point to |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6576 | VkRect2D sc = {}; // dummy scissor to point to |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 6577 | |
| 6578 | VkPipelineViewportStateCreateInfo vp_state_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6579 | vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO; |
| 6580 | vp_state_ci.scissorCount = 1; |
| 6581 | vp_state_ci.pScissors = ≻ |
| 6582 | vp_state_ci.viewportCount = 1; |
| 6583 | vp_state_ci.pViewports = &vp; |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 6584 | |
Karl Schultz | dfdb8d4 | 2016-03-08 10:30:21 -0700 | [diff] [blame] | 6585 | VkPipelineRasterizationStateCreateInfo rs_state_ci = {}; |
| 6586 | rs_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO; |
| 6587 | rs_state_ci.polygonMode = VK_POLYGON_MODE_FILL; |
| 6588 | rs_state_ci.cullMode = VK_CULL_MODE_BACK_BIT; |
| 6589 | rs_state_ci.frontFace = VK_FRONT_FACE_COUNTER_CLOCKWISE; |
| 6590 | rs_state_ci.depthClampEnable = VK_FALSE; |
| 6591 | rs_state_ci.rasterizerDiscardEnable = VK_FALSE; |
| 6592 | rs_state_ci.depthBiasEnable = VK_FALSE; |
| 6593 | |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 6594 | VkGraphicsPipelineCreateInfo gp_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6595 | gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO; |
| 6596 | gp_ci.pViewportState = &vp_state_ci; |
Karl Schultz | dfdb8d4 | 2016-03-08 10:30:21 -0700 | [diff] [blame] | 6597 | gp_ci.pRasterizationState = &rs_state_ci; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6598 | gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT; |
| 6599 | gp_ci.layout = pipeline_layout; |
| 6600 | gp_ci.renderPass = renderPass(); |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 6601 | |
| 6602 | VkPipelineCacheCreateInfo pc_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6603 | pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO; |
| 6604 | pc_ci.initialDataSize = 0; |
| 6605 | pc_ci.pInitialData = 0; |
Tobin Ehlis | af1f3a4 | 2015-06-25 15:46:59 -0600 | [diff] [blame] | 6606 | |
| 6607 | VkPipeline pipeline; |
Jon Ashburn | c669cc6 | 2015-07-09 15:02:25 -0600 | [diff] [blame] | 6608 | VkPipelineCache pipelineCache; |
| 6609 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6610 | err = |
| 6611 | vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache); |
Jon Ashburn | c669cc6 | 2015-07-09 15:02:25 -0600 | [diff] [blame] | 6612 | ASSERT_VK_SUCCESS(err); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6613 | err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, |
| 6614 | &gp_ci, NULL, &pipeline); |
Tobin Ehlis | 7d1a711 | 2015-05-27 14:32:28 -0600 | [diff] [blame] | 6615 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 6616 | m_errorMonitor->VerifyFound(); |
Mike Stroyan | d1c84a5 | 2015-08-18 14:40:24 -0600 | [diff] [blame] | 6617 | |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 6618 | vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL); |
| 6619 | vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL); |
| 6620 | vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL); |
| 6621 | vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL); |
Tobin Ehlis | af1f3a4 | 2015-06-25 15:46:59 -0600 | [diff] [blame] | 6622 | } |
Tobin Ehlis | 912df02 | 2015-09-17 08:46:18 -0600 | [diff] [blame] | 6623 | /*// TODO : This test should be good, but needs Tess support in compiler to run |
| 6624 | TEST_F(VkLayerTest, InvalidPatchControlPoints) |
| 6625 | { |
| 6626 | // Attempt to Create Gfx Pipeline w/o a VS |
Tobin Ehlis | 912df02 | 2015-09-17 08:46:18 -0600 | [diff] [blame] | 6627 | VkResult err; |
Tobin Ehlis | af1f3a4 | 2015-06-25 15:46:59 -0600 | [diff] [blame] | 6628 | |
Courtney Goeltzenleuchter | 7415d5a | 2015-12-09 15:48:16 -0700 | [diff] [blame] | 6629 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6630 | "Invalid Pipeline CreateInfo State: VK_PRIMITIVE_TOPOLOGY_PATCH |
| 6631 | primitive "); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 6632 | |
Tobin Ehlis | 912df02 | 2015-09-17 08:46:18 -0600 | [diff] [blame] | 6633 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 6634 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
Tobin Ehlis | 912df02 | 2015-09-17 08:46:18 -0600 | [diff] [blame] | 6635 | |
Chia-I Wu | 1b99bb2 | 2015-10-27 19:25:11 +0800 | [diff] [blame] | 6636 | VkDescriptorPoolSize ds_type_count = {}; |
Tobin Ehlis | 912df02 | 2015-09-17 08:46:18 -0600 | [diff] [blame] | 6637 | ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
Chia-I Wu | d50a7d7 | 2015-10-26 20:48:51 +0800 | [diff] [blame] | 6638 | ds_type_count.descriptorCount = 1; |
Tobin Ehlis | 912df02 | 2015-09-17 08:46:18 -0600 | [diff] [blame] | 6639 | |
| 6640 | VkDescriptorPoolCreateInfo ds_pool_ci = {}; |
| 6641 | ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO; |
| 6642 | ds_pool_ci.pNext = NULL; |
Chia-I Wu | 1b99bb2 | 2015-10-27 19:25:11 +0800 | [diff] [blame] | 6643 | ds_pool_ci.poolSizeCount = 1; |
| 6644 | ds_pool_ci.pPoolSizes = &ds_type_count; |
Tobin Ehlis | 912df02 | 2015-09-17 08:46:18 -0600 | [diff] [blame] | 6645 | |
| 6646 | VkDescriptorPool ds_pool; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6647 | err = vkCreateDescriptorPool(m_device->device(), |
| 6648 | VK_DESCRIPTOR_POOL_USAGE_NON_FREE, 1, &ds_pool_ci, NULL, &ds_pool); |
Tobin Ehlis | 912df02 | 2015-09-17 08:46:18 -0600 | [diff] [blame] | 6649 | ASSERT_VK_SUCCESS(err); |
| 6650 | |
| 6651 | VkDescriptorSetLayoutBinding dsl_binding = {}; |
Chia-I Wu | d46e6ae | 2015-10-31 00:31:16 +0800 | [diff] [blame] | 6652 | dsl_binding.binding = 0; |
Tobin Ehlis | 912df02 | 2015-09-17 08:46:18 -0600 | [diff] [blame] | 6653 | dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
Chia-I Wu | 0212448 | 2015-11-06 06:42:02 +0800 | [diff] [blame] | 6654 | dsl_binding.descriptorCount = 1; |
Tobin Ehlis | 912df02 | 2015-09-17 08:46:18 -0600 | [diff] [blame] | 6655 | dsl_binding.stageFlags = VK_SHADER_STAGE_ALL; |
| 6656 | dsl_binding.pImmutableSamplers = NULL; |
| 6657 | |
| 6658 | VkDescriptorSetLayoutCreateInfo ds_layout_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6659 | ds_layout_ci.sType = |
| 6660 | VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO; |
Tobin Ehlis | 912df02 | 2015-09-17 08:46:18 -0600 | [diff] [blame] | 6661 | ds_layout_ci.pNext = NULL; |
Chia-I Wu | d50a7d7 | 2015-10-26 20:48:51 +0800 | [diff] [blame] | 6662 | ds_layout_ci.bindingCount = 1; |
Jon Ashburn | 6e23c1f | 2015-12-30 18:01:16 -0700 | [diff] [blame] | 6663 | ds_layout_ci.pBindings = &dsl_binding; |
Tobin Ehlis | 912df02 | 2015-09-17 08:46:18 -0600 | [diff] [blame] | 6664 | |
| 6665 | VkDescriptorSetLayout ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6666 | err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, |
| 6667 | &ds_layout); |
Tobin Ehlis | 912df02 | 2015-09-17 08:46:18 -0600 | [diff] [blame] | 6668 | ASSERT_VK_SUCCESS(err); |
| 6669 | |
| 6670 | VkDescriptorSet descriptorSet; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6671 | err = vkAllocateDescriptorSets(m_device->device(), ds_pool, |
| 6672 | VK_DESCRIPTOR_SET_USAGE_NON_FREE, 1, &ds_layout, &descriptorSet); |
Tobin Ehlis | 912df02 | 2015-09-17 08:46:18 -0600 | [diff] [blame] | 6673 | ASSERT_VK_SUCCESS(err); |
| 6674 | |
| 6675 | VkPipelineLayoutCreateInfo pipeline_layout_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6676 | pipeline_layout_ci.sType = |
| 6677 | VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO; |
Tobin Ehlis | 912df02 | 2015-09-17 08:46:18 -0600 | [diff] [blame] | 6678 | pipeline_layout_ci.pNext = NULL; |
Chia-I Wu | d50a7d7 | 2015-10-26 20:48:51 +0800 | [diff] [blame] | 6679 | pipeline_layout_ci.setLayoutCount = 1; |
Tobin Ehlis | 912df02 | 2015-09-17 08:46:18 -0600 | [diff] [blame] | 6680 | pipeline_layout_ci.pSetLayouts = &ds_layout; |
| 6681 | |
| 6682 | VkPipelineLayout pipeline_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6683 | err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, |
| 6684 | &pipeline_layout); |
Tobin Ehlis | 912df02 | 2015-09-17 08:46:18 -0600 | [diff] [blame] | 6685 | ASSERT_VK_SUCCESS(err); |
| 6686 | |
| 6687 | VkPipelineShaderStageCreateInfo shaderStages[3]; |
| 6688 | memset(&shaderStages, 0, 3 * sizeof(VkPipelineShaderStageCreateInfo)); |
| 6689 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6690 | VkShaderObj vs(m_device,bindStateVertShaderText,VK_SHADER_STAGE_VERTEX_BIT, |
| 6691 | this); |
Tobin Ehlis | 912df02 | 2015-09-17 08:46:18 -0600 | [diff] [blame] | 6692 | // Just using VS txt for Tess shaders as we don't care about functionality |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6693 | VkShaderObj |
| 6694 | tc(m_device,bindStateVertShaderText,VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT, |
| 6695 | this); |
| 6696 | VkShaderObj |
| 6697 | te(m_device,bindStateVertShaderText,VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT, |
| 6698 | this); |
Tobin Ehlis | 912df02 | 2015-09-17 08:46:18 -0600 | [diff] [blame] | 6699 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6700 | shaderStages[0].sType = |
| 6701 | VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO; |
Courtney Goeltzenleuchter | d263550 | 2015-10-21 17:08:06 -0600 | [diff] [blame] | 6702 | shaderStages[0].stage = VK_SHADER_STAGE_VERTEX_BIT; |
Tobin Ehlis | 912df02 | 2015-09-17 08:46:18 -0600 | [diff] [blame] | 6703 | shaderStages[0].shader = vs.handle(); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6704 | shaderStages[1].sType = |
| 6705 | VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO; |
Courtney Goeltzenleuchter | d263550 | 2015-10-21 17:08:06 -0600 | [diff] [blame] | 6706 | shaderStages[1].stage = VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT; |
Tobin Ehlis | 912df02 | 2015-09-17 08:46:18 -0600 | [diff] [blame] | 6707 | shaderStages[1].shader = tc.handle(); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6708 | shaderStages[2].sType = |
| 6709 | VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO; |
Courtney Goeltzenleuchter | d263550 | 2015-10-21 17:08:06 -0600 | [diff] [blame] | 6710 | shaderStages[2].stage = VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT; |
Tobin Ehlis | 912df02 | 2015-09-17 08:46:18 -0600 | [diff] [blame] | 6711 | shaderStages[2].shader = te.handle(); |
| 6712 | |
| 6713 | VkPipelineInputAssemblyStateCreateInfo iaCI = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6714 | iaCI.sType = |
| 6715 | VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO; |
Chia-I Wu | 515eb8f | 2015-10-31 00:31:16 +0800 | [diff] [blame] | 6716 | iaCI.topology = VK_PRIMITIVE_TOPOLOGY_PATCH_LIST; |
Tobin Ehlis | 912df02 | 2015-09-17 08:46:18 -0600 | [diff] [blame] | 6717 | |
| 6718 | VkPipelineTessellationStateCreateInfo tsCI = {}; |
| 6719 | tsCI.sType = VK_STRUCTURE_TYPE_PIPELINE_TESSELLATION_STATE_CREATE_INFO; |
| 6720 | tsCI.patchControlPoints = 0; // This will cause an error |
| 6721 | |
| 6722 | VkGraphicsPipelineCreateInfo gp_ci = {}; |
| 6723 | gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO; |
| 6724 | gp_ci.pNext = NULL; |
| 6725 | gp_ci.stageCount = 3; |
| 6726 | gp_ci.pStages = shaderStages; |
| 6727 | gp_ci.pVertexInputState = NULL; |
| 6728 | gp_ci.pInputAssemblyState = &iaCI; |
| 6729 | gp_ci.pTessellationState = &tsCI; |
| 6730 | gp_ci.pViewportState = NULL; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 6731 | gp_ci.pRasterizationState = NULL; |
Tobin Ehlis | 912df02 | 2015-09-17 08:46:18 -0600 | [diff] [blame] | 6732 | gp_ci.pMultisampleState = NULL; |
| 6733 | gp_ci.pDepthStencilState = NULL; |
| 6734 | gp_ci.pColorBlendState = NULL; |
| 6735 | gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT; |
| 6736 | gp_ci.layout = pipeline_layout; |
| 6737 | gp_ci.renderPass = renderPass(); |
| 6738 | |
| 6739 | VkPipelineCacheCreateInfo pc_ci = {}; |
| 6740 | pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO; |
| 6741 | pc_ci.pNext = NULL; |
| 6742 | pc_ci.initialSize = 0; |
| 6743 | pc_ci.initialData = 0; |
| 6744 | pc_ci.maxSize = 0; |
| 6745 | |
| 6746 | VkPipeline pipeline; |
| 6747 | VkPipelineCache pipelineCache; |
| 6748 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6749 | err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, |
| 6750 | &pipelineCache); |
Tobin Ehlis | 912df02 | 2015-09-17 08:46:18 -0600 | [diff] [blame] | 6751 | ASSERT_VK_SUCCESS(err); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6752 | err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, |
| 6753 | &gp_ci, NULL, &pipeline); |
Tobin Ehlis | 912df02 | 2015-09-17 08:46:18 -0600 | [diff] [blame] | 6754 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 6755 | m_errorMonitor->VerifyFound(); |
Mike Stroyan | d1c84a5 | 2015-08-18 14:40:24 -0600 | [diff] [blame] | 6756 | |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 6757 | vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL); |
| 6758 | vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL); |
| 6759 | vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL); |
| 6760 | vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL); |
Tobin Ehlis | 912df02 | 2015-09-17 08:46:18 -0600 | [diff] [blame] | 6761 | } |
| 6762 | */ |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 6763 | // Set scissor and viewport counts to different numbers |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6764 | TEST_F(VkLayerTest, PSOViewportScissorCountMismatch) { |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6765 | VkResult err; |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 6766 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6767 | m_errorMonitor->SetDesiredFailureMsg( |
| 6768 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 6769 | "Gfx Pipeline viewport count (1) must match scissor count (0)."); |
| 6770 | |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 6771 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 6772 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 6773 | |
Chia-I Wu | 1b99bb2 | 2015-10-27 19:25:11 +0800 | [diff] [blame] | 6774 | VkDescriptorPoolSize ds_type_count = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6775 | ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 6776 | ds_type_count.descriptorCount = 1; |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 6777 | |
| 6778 | VkDescriptorPoolCreateInfo ds_pool_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6779 | ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO; |
| 6780 | ds_pool_ci.maxSets = 1; |
| 6781 | ds_pool_ci.poolSizeCount = 1; |
| 6782 | ds_pool_ci.pPoolSizes = &ds_type_count; |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 6783 | |
| 6784 | VkDescriptorPool ds_pool; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6785 | err = |
| 6786 | vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool); |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 6787 | ASSERT_VK_SUCCESS(err); |
| 6788 | |
| 6789 | VkDescriptorSetLayoutBinding dsl_binding = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6790 | dsl_binding.binding = 0; |
| 6791 | dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 6792 | dsl_binding.descriptorCount = 1; |
| 6793 | dsl_binding.stageFlags = VK_SHADER_STAGE_ALL; |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 6794 | |
| 6795 | VkDescriptorSetLayoutCreateInfo ds_layout_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6796 | ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO; |
| 6797 | ds_layout_ci.bindingCount = 1; |
| 6798 | ds_layout_ci.pBindings = &dsl_binding; |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 6799 | |
| 6800 | VkDescriptorSetLayout ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6801 | err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, |
| 6802 | &ds_layout); |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 6803 | ASSERT_VK_SUCCESS(err); |
| 6804 | |
| 6805 | VkDescriptorSet descriptorSet; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 6806 | VkDescriptorSetAllocateInfo alloc_info = {}; |
Chia-I Wu | 00ce540 | 2015-11-10 16:21:09 +0800 | [diff] [blame] | 6807 | alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO; |
Jon Ashburn | f19916e | 2016-01-11 13:12:43 -0700 | [diff] [blame] | 6808 | alloc_info.descriptorSetCount = 1; |
Courtney Goeltzenleuchter | bee18a9 | 2015-10-23 14:21:05 -0600 | [diff] [blame] | 6809 | alloc_info.descriptorPool = ds_pool; |
| 6810 | alloc_info.pSetLayouts = &ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6811 | err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, |
| 6812 | &descriptorSet); |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 6813 | ASSERT_VK_SUCCESS(err); |
| 6814 | |
| 6815 | VkPipelineLayoutCreateInfo pipeline_layout_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6816 | pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO; |
| 6817 | pipeline_layout_ci.setLayoutCount = 1; |
| 6818 | pipeline_layout_ci.pSetLayouts = &ds_layout; |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 6819 | |
| 6820 | VkPipelineLayout pipeline_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6821 | err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, |
| 6822 | &pipeline_layout); |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 6823 | ASSERT_VK_SUCCESS(err); |
| 6824 | |
| 6825 | VkViewport vp = {}; // Just need dummy vp to point to |
| 6826 | |
| 6827 | VkPipelineViewportStateCreateInfo vp_state_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6828 | vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO; |
| 6829 | vp_state_ci.scissorCount = 0; |
| 6830 | vp_state_ci.viewportCount = 1; // Count mismatch should cause error |
| 6831 | vp_state_ci.pViewports = &vp; |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 6832 | |
Karl Schultz | dfdb8d4 | 2016-03-08 10:30:21 -0700 | [diff] [blame] | 6833 | VkPipelineRasterizationStateCreateInfo rs_state_ci = {}; |
| 6834 | rs_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO; |
| 6835 | rs_state_ci.polygonMode = VK_POLYGON_MODE_FILL; |
| 6836 | rs_state_ci.cullMode = VK_CULL_MODE_BACK_BIT; |
| 6837 | rs_state_ci.frontFace = VK_FRONT_FACE_COUNTER_CLOCKWISE; |
| 6838 | rs_state_ci.depthClampEnable = VK_FALSE; |
| 6839 | rs_state_ci.rasterizerDiscardEnable = VK_FALSE; |
| 6840 | rs_state_ci.depthBiasEnable = VK_FALSE; |
| 6841 | |
Cody Northrop | eb3a6c1 | 2015-10-05 14:44:45 -0600 | [diff] [blame] | 6842 | VkPipelineShaderStageCreateInfo shaderStages[2]; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6843 | memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo)); |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 6844 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6845 | VkShaderObj vs(m_device, bindStateVertShaderText, |
| 6846 | VK_SHADER_STAGE_VERTEX_BIT, this); |
| 6847 | VkShaderObj fs(m_device, bindStateFragShaderText, |
| 6848 | VK_SHADER_STAGE_FRAGMENT_BIT, |
Karl Schultz | bdb7595 | 2016-04-19 11:36:49 -0600 | [diff] [blame] | 6849 | this); // We shouldn't need a fragment shader |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6850 | // but add it to be able to run on more devices |
Chia-I Wu | 28e0691 | 2015-10-31 00:31:16 +0800 | [diff] [blame] | 6851 | shaderStages[0] = vs.GetStageCreateInfo(); |
| 6852 | shaderStages[1] = fs.GetStageCreateInfo(); |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 6853 | |
| 6854 | VkGraphicsPipelineCreateInfo gp_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6855 | gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO; |
| 6856 | gp_ci.stageCount = 2; |
| 6857 | gp_ci.pStages = shaderStages; |
| 6858 | gp_ci.pViewportState = &vp_state_ci; |
Karl Schultz | dfdb8d4 | 2016-03-08 10:30:21 -0700 | [diff] [blame] | 6859 | gp_ci.pRasterizationState = &rs_state_ci; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6860 | gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT; |
| 6861 | gp_ci.layout = pipeline_layout; |
| 6862 | gp_ci.renderPass = renderPass(); |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 6863 | |
| 6864 | VkPipelineCacheCreateInfo pc_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6865 | pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO; |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 6866 | |
| 6867 | VkPipeline pipeline; |
| 6868 | VkPipelineCache pipelineCache; |
| 6869 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6870 | err = |
| 6871 | vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache); |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 6872 | ASSERT_VK_SUCCESS(err); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6873 | err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, |
| 6874 | &gp_ci, NULL, &pipeline); |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 6875 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 6876 | m_errorMonitor->VerifyFound(); |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 6877 | |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 6878 | vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL); |
| 6879 | vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL); |
| 6880 | vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL); |
| 6881 | vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL); |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 6882 | } |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6883 | // Don't set viewport state in PSO. This is an error b/c we always need this |
| 6884 | // state |
Tobin Ehlis | d332f28 | 2015-10-02 11:00:56 -0600 | [diff] [blame] | 6885 | // for the counts even if the data is going to be set dynamically. |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6886 | TEST_F(VkLayerTest, PSOViewportStateNotSet) { |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 6887 | // Attempt to Create Gfx Pipeline w/o a VS |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6888 | VkResult err; |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 6889 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6890 | m_errorMonitor->SetDesiredFailureMsg( |
| 6891 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 6892 | "Gfx Pipeline pViewportState is null. Even if "); |
| 6893 | |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 6894 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 6895 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 6896 | |
Chia-I Wu | 1b99bb2 | 2015-10-27 19:25:11 +0800 | [diff] [blame] | 6897 | VkDescriptorPoolSize ds_type_count = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6898 | ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 6899 | ds_type_count.descriptorCount = 1; |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 6900 | |
| 6901 | VkDescriptorPoolCreateInfo ds_pool_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6902 | ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO; |
| 6903 | ds_pool_ci.maxSets = 1; |
| 6904 | ds_pool_ci.poolSizeCount = 1; |
| 6905 | ds_pool_ci.pPoolSizes = &ds_type_count; |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 6906 | |
| 6907 | VkDescriptorPool ds_pool; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6908 | err = |
| 6909 | vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool); |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 6910 | ASSERT_VK_SUCCESS(err); |
| 6911 | |
| 6912 | VkDescriptorSetLayoutBinding dsl_binding = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6913 | dsl_binding.binding = 0; |
| 6914 | dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 6915 | dsl_binding.descriptorCount = 1; |
| 6916 | dsl_binding.stageFlags = VK_SHADER_STAGE_ALL; |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 6917 | |
| 6918 | VkDescriptorSetLayoutCreateInfo ds_layout_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6919 | ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO; |
| 6920 | ds_layout_ci.bindingCount = 1; |
| 6921 | ds_layout_ci.pBindings = &dsl_binding; |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 6922 | |
| 6923 | VkDescriptorSetLayout ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6924 | err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, |
| 6925 | &ds_layout); |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 6926 | ASSERT_VK_SUCCESS(err); |
| 6927 | |
| 6928 | VkDescriptorSet descriptorSet; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 6929 | VkDescriptorSetAllocateInfo alloc_info = {}; |
Chia-I Wu | 00ce540 | 2015-11-10 16:21:09 +0800 | [diff] [blame] | 6930 | alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO; |
Jon Ashburn | f19916e | 2016-01-11 13:12:43 -0700 | [diff] [blame] | 6931 | alloc_info.descriptorSetCount = 1; |
Courtney Goeltzenleuchter | bee18a9 | 2015-10-23 14:21:05 -0600 | [diff] [blame] | 6932 | alloc_info.descriptorPool = ds_pool; |
| 6933 | alloc_info.pSetLayouts = &ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6934 | err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, |
| 6935 | &descriptorSet); |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 6936 | ASSERT_VK_SUCCESS(err); |
| 6937 | |
| 6938 | VkPipelineLayoutCreateInfo pipeline_layout_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6939 | pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO; |
| 6940 | pipeline_layout_ci.setLayoutCount = 1; |
| 6941 | pipeline_layout_ci.pSetLayouts = &ds_layout; |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 6942 | |
| 6943 | VkPipelineLayout pipeline_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6944 | err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, |
| 6945 | &pipeline_layout); |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 6946 | ASSERT_VK_SUCCESS(err); |
| 6947 | |
| 6948 | VkDynamicState sc_state = VK_DYNAMIC_STATE_SCISSOR; |
| 6949 | // Set scissor as dynamic to avoid second error |
| 6950 | VkPipelineDynamicStateCreateInfo dyn_state_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6951 | dyn_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO; |
| 6952 | dyn_state_ci.dynamicStateCount = 1; |
| 6953 | dyn_state_ci.pDynamicStates = &sc_state; |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 6954 | |
Cody Northrop | eb3a6c1 | 2015-10-05 14:44:45 -0600 | [diff] [blame] | 6955 | VkPipelineShaderStageCreateInfo shaderStages[2]; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6956 | memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo)); |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 6957 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6958 | VkShaderObj vs(m_device, bindStateVertShaderText, |
| 6959 | VK_SHADER_STAGE_VERTEX_BIT, this); |
| 6960 | VkShaderObj fs(m_device, bindStateFragShaderText, |
| 6961 | VK_SHADER_STAGE_FRAGMENT_BIT, |
Karl Schultz | bdb7595 | 2016-04-19 11:36:49 -0600 | [diff] [blame] | 6962 | this); // We shouldn't need a fragment shader |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6963 | // but add it to be able to run on more devices |
Chia-I Wu | 28e0691 | 2015-10-31 00:31:16 +0800 | [diff] [blame] | 6964 | shaderStages[0] = vs.GetStageCreateInfo(); |
| 6965 | shaderStages[1] = fs.GetStageCreateInfo(); |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 6966 | |
Karl Schultz | dfdb8d4 | 2016-03-08 10:30:21 -0700 | [diff] [blame] | 6967 | |
| 6968 | VkPipelineRasterizationStateCreateInfo rs_state_ci = {}; |
| 6969 | rs_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO; |
| 6970 | rs_state_ci.polygonMode = VK_POLYGON_MODE_FILL; |
| 6971 | rs_state_ci.cullMode = VK_CULL_MODE_BACK_BIT; |
| 6972 | rs_state_ci.frontFace = VK_FRONT_FACE_COUNTER_CLOCKWISE; |
| 6973 | rs_state_ci.depthClampEnable = VK_FALSE; |
| 6974 | rs_state_ci.rasterizerDiscardEnable = VK_FALSE; |
| 6975 | rs_state_ci.depthBiasEnable = VK_FALSE; |
| 6976 | |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 6977 | VkGraphicsPipelineCreateInfo gp_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6978 | gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO; |
| 6979 | gp_ci.stageCount = 2; |
| 6980 | gp_ci.pStages = shaderStages; |
Karl Schultz | dfdb8d4 | 2016-03-08 10:30:21 -0700 | [diff] [blame] | 6981 | gp_ci.pRasterizationState = &rs_state_ci; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6982 | gp_ci.pViewportState = NULL; // Not setting VP state w/o dynamic vp state |
| 6983 | // should cause validation error |
| 6984 | gp_ci.pDynamicState = &dyn_state_ci; |
| 6985 | gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT; |
| 6986 | gp_ci.layout = pipeline_layout; |
| 6987 | gp_ci.renderPass = renderPass(); |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 6988 | |
| 6989 | VkPipelineCacheCreateInfo pc_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6990 | pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO; |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 6991 | |
| 6992 | VkPipeline pipeline; |
| 6993 | VkPipelineCache pipelineCache; |
| 6994 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6995 | err = |
| 6996 | vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache); |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 6997 | ASSERT_VK_SUCCESS(err); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6998 | err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, |
| 6999 | &gp_ci, NULL, &pipeline); |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 7000 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 7001 | m_errorMonitor->VerifyFound(); |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 7002 | |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 7003 | vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL); |
| 7004 | vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL); |
| 7005 | vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL); |
| 7006 | vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL); |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 7007 | } |
| 7008 | // Create PSO w/o non-zero viewportCount but no viewport data |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7009 | // Then run second test where dynamic scissor count doesn't match PSO scissor |
| 7010 | // count |
| 7011 | TEST_F(VkLayerTest, PSOViewportCountWithoutDataAndDynScissorMismatch) { |
| 7012 | VkResult err; |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 7013 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7014 | m_errorMonitor->SetDesiredFailureMsg( |
| 7015 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 7016 | "Gfx Pipeline viewportCount is 1, but pViewports is NULL. "); |
| 7017 | |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 7018 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 7019 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 7020 | |
Chia-I Wu | 1b99bb2 | 2015-10-27 19:25:11 +0800 | [diff] [blame] | 7021 | VkDescriptorPoolSize ds_type_count = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7022 | ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 7023 | ds_type_count.descriptorCount = 1; |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 7024 | |
| 7025 | VkDescriptorPoolCreateInfo ds_pool_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7026 | ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO; |
| 7027 | ds_pool_ci.maxSets = 1; |
| 7028 | ds_pool_ci.poolSizeCount = 1; |
| 7029 | ds_pool_ci.pPoolSizes = &ds_type_count; |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 7030 | |
| 7031 | VkDescriptorPool ds_pool; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7032 | err = |
| 7033 | vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool); |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 7034 | ASSERT_VK_SUCCESS(err); |
| 7035 | |
| 7036 | VkDescriptorSetLayoutBinding dsl_binding = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7037 | dsl_binding.binding = 0; |
| 7038 | dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 7039 | dsl_binding.descriptorCount = 1; |
| 7040 | dsl_binding.stageFlags = VK_SHADER_STAGE_ALL; |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 7041 | |
| 7042 | VkDescriptorSetLayoutCreateInfo ds_layout_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7043 | ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO; |
| 7044 | ds_layout_ci.bindingCount = 1; |
| 7045 | ds_layout_ci.pBindings = &dsl_binding; |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 7046 | |
| 7047 | VkDescriptorSetLayout ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7048 | err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, |
| 7049 | &ds_layout); |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 7050 | ASSERT_VK_SUCCESS(err); |
| 7051 | |
| 7052 | VkDescriptorSet descriptorSet; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 7053 | VkDescriptorSetAllocateInfo alloc_info = {}; |
Chia-I Wu | 00ce540 | 2015-11-10 16:21:09 +0800 | [diff] [blame] | 7054 | alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO; |
Jon Ashburn | f19916e | 2016-01-11 13:12:43 -0700 | [diff] [blame] | 7055 | alloc_info.descriptorSetCount = 1; |
Courtney Goeltzenleuchter | bee18a9 | 2015-10-23 14:21:05 -0600 | [diff] [blame] | 7056 | alloc_info.descriptorPool = ds_pool; |
| 7057 | alloc_info.pSetLayouts = &ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7058 | err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, |
| 7059 | &descriptorSet); |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 7060 | ASSERT_VK_SUCCESS(err); |
| 7061 | |
| 7062 | VkPipelineLayoutCreateInfo pipeline_layout_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7063 | pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO; |
| 7064 | pipeline_layout_ci.setLayoutCount = 1; |
| 7065 | pipeline_layout_ci.pSetLayouts = &ds_layout; |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 7066 | |
| 7067 | VkPipelineLayout pipeline_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7068 | err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, |
| 7069 | &pipeline_layout); |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 7070 | ASSERT_VK_SUCCESS(err); |
| 7071 | |
| 7072 | VkPipelineViewportStateCreateInfo vp_state_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7073 | vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO; |
| 7074 | vp_state_ci.viewportCount = 1; |
| 7075 | vp_state_ci.pViewports = NULL; // Null vp w/ count of 1 should cause error |
| 7076 | vp_state_ci.scissorCount = 1; |
| 7077 | vp_state_ci.pScissors = |
| 7078 | NULL; // Scissor is dynamic (below) so this won't cause error |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 7079 | |
| 7080 | VkDynamicState sc_state = VK_DYNAMIC_STATE_SCISSOR; |
| 7081 | // Set scissor as dynamic to avoid that error |
| 7082 | VkPipelineDynamicStateCreateInfo dyn_state_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7083 | dyn_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO; |
| 7084 | dyn_state_ci.dynamicStateCount = 1; |
| 7085 | dyn_state_ci.pDynamicStates = &sc_state; |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 7086 | |
Cody Northrop | eb3a6c1 | 2015-10-05 14:44:45 -0600 | [diff] [blame] | 7087 | VkPipelineShaderStageCreateInfo shaderStages[2]; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7088 | memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo)); |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 7089 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7090 | VkShaderObj vs(m_device, bindStateVertShaderText, |
| 7091 | VK_SHADER_STAGE_VERTEX_BIT, this); |
| 7092 | VkShaderObj fs(m_device, bindStateFragShaderText, |
| 7093 | VK_SHADER_STAGE_FRAGMENT_BIT, |
Karl Schultz | bdb7595 | 2016-04-19 11:36:49 -0600 | [diff] [blame] | 7094 | this); // We shouldn't need a fragment shader |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7095 | // but add it to be able to run on more devices |
Chia-I Wu | 28e0691 | 2015-10-31 00:31:16 +0800 | [diff] [blame] | 7096 | shaderStages[0] = vs.GetStageCreateInfo(); |
| 7097 | shaderStages[1] = fs.GetStageCreateInfo(); |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 7098 | |
Cody Northrop | f6622dc | 2015-10-06 10:33:21 -0600 | [diff] [blame] | 7099 | VkPipelineVertexInputStateCreateInfo vi_ci = {}; |
| 7100 | vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO; |
| 7101 | vi_ci.pNext = nullptr; |
Chia-I Wu | d50a7d7 | 2015-10-26 20:48:51 +0800 | [diff] [blame] | 7102 | vi_ci.vertexBindingDescriptionCount = 0; |
Cody Northrop | f6622dc | 2015-10-06 10:33:21 -0600 | [diff] [blame] | 7103 | vi_ci.pVertexBindingDescriptions = nullptr; |
Chia-I Wu | d50a7d7 | 2015-10-26 20:48:51 +0800 | [diff] [blame] | 7104 | vi_ci.vertexAttributeDescriptionCount = 0; |
Cody Northrop | f6622dc | 2015-10-06 10:33:21 -0600 | [diff] [blame] | 7105 | vi_ci.pVertexAttributeDescriptions = nullptr; |
| 7106 | |
| 7107 | VkPipelineInputAssemblyStateCreateInfo ia_ci = {}; |
| 7108 | ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO; |
| 7109 | ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP; |
| 7110 | |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 7111 | VkPipelineRasterizationStateCreateInfo rs_ci = {}; |
Chia-I Wu | 1b99bb2 | 2015-10-27 19:25:11 +0800 | [diff] [blame] | 7112 | rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO; |
Cody Northrop | f6622dc | 2015-10-06 10:33:21 -0600 | [diff] [blame] | 7113 | rs_ci.pNext = nullptr; |
| 7114 | |
Mark Young | c89c631 | 2016-03-31 16:03:20 -0600 | [diff] [blame] | 7115 | VkPipelineColorBlendAttachmentState att = {}; |
| 7116 | att.blendEnable = VK_FALSE; |
| 7117 | att.colorWriteMask = 0xf; |
| 7118 | |
Cody Northrop | f6622dc | 2015-10-06 10:33:21 -0600 | [diff] [blame] | 7119 | VkPipelineColorBlendStateCreateInfo cb_ci = {}; |
| 7120 | cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO; |
| 7121 | cb_ci.pNext = nullptr; |
Mark Young | c89c631 | 2016-03-31 16:03:20 -0600 | [diff] [blame] | 7122 | cb_ci.attachmentCount = 1; |
| 7123 | cb_ci.pAttachments = &att; |
Cody Northrop | f6622dc | 2015-10-06 10:33:21 -0600 | [diff] [blame] | 7124 | |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 7125 | VkGraphicsPipelineCreateInfo gp_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7126 | gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO; |
| 7127 | gp_ci.stageCount = 2; |
| 7128 | gp_ci.pStages = shaderStages; |
| 7129 | gp_ci.pVertexInputState = &vi_ci; |
| 7130 | gp_ci.pInputAssemblyState = &ia_ci; |
| 7131 | gp_ci.pViewportState = &vp_state_ci; |
| 7132 | gp_ci.pRasterizationState = &rs_ci; |
| 7133 | gp_ci.pColorBlendState = &cb_ci; |
| 7134 | gp_ci.pDynamicState = &dyn_state_ci; |
| 7135 | gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT; |
| 7136 | gp_ci.layout = pipeline_layout; |
| 7137 | gp_ci.renderPass = renderPass(); |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 7138 | |
| 7139 | VkPipelineCacheCreateInfo pc_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7140 | pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO; |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 7141 | |
| 7142 | VkPipeline pipeline; |
| 7143 | VkPipelineCache pipelineCache; |
| 7144 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7145 | err = |
| 7146 | vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache); |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 7147 | ASSERT_VK_SUCCESS(err); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7148 | err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, |
| 7149 | &gp_ci, NULL, &pipeline); |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 7150 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 7151 | m_errorMonitor->VerifyFound(); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 7152 | |
Tobin Ehlis | d332f28 | 2015-10-02 11:00:56 -0600 | [diff] [blame] | 7153 | // Now hit second fail case where we set scissor w/ different count than PSO |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7154 | // First need to successfully create the PSO from above by setting |
| 7155 | // pViewports |
| 7156 | m_errorMonitor->SetDesiredFailureMsg( |
| 7157 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 7158 | "Dynamic scissorCount from vkCmdSetScissor() is 2, but PSO " |
| 7159 | "scissorCount is 1. These counts must match."); |
| 7160 | |
| 7161 | VkViewport vp = {}; // Just need dummy vp to point to |
| 7162 | vp_state_ci.pViewports = &vp; |
| 7163 | err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, |
| 7164 | &gp_ci, NULL, &pipeline); |
| 7165 | ASSERT_VK_SUCCESS(err); |
| 7166 | BeginCommandBuffer(); |
| 7167 | vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), |
| 7168 | VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline); |
| 7169 | VkRect2D scissors[2] = {}; // don't care about data |
| 7170 | // Count of 2 doesn't match PSO count of 1 |
| 7171 | vkCmdSetScissor(m_commandBuffer->GetBufferHandle(), 0, 2, scissors); |
| 7172 | Draw(1, 0, 0, 0); |
| 7173 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 7174 | m_errorMonitor->VerifyFound(); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7175 | |
| 7176 | vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL); |
| 7177 | vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL); |
| 7178 | vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL); |
| 7179 | vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL); |
Tony Barbour | df4c004 | 2016-06-01 15:55:43 -0600 | [diff] [blame] | 7180 | vkDestroyPipeline(m_device->device(), pipeline, NULL); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7181 | } |
| 7182 | // Create PSO w/o non-zero scissorCount but no scissor data |
| 7183 | // Then run second test where dynamic viewportCount doesn't match PSO |
| 7184 | // viewportCount |
| 7185 | TEST_F(VkLayerTest, PSOScissorCountWithoutDataAndDynViewportMismatch) { |
| 7186 | VkResult err; |
| 7187 | |
| 7188 | m_errorMonitor->SetDesiredFailureMsg( |
| 7189 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 7190 | "Gfx Pipeline scissorCount is 1, but pScissors is NULL. "); |
| 7191 | |
| 7192 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 7193 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 7194 | |
| 7195 | VkDescriptorPoolSize ds_type_count = {}; |
| 7196 | ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 7197 | ds_type_count.descriptorCount = 1; |
| 7198 | |
| 7199 | VkDescriptorPoolCreateInfo ds_pool_ci = {}; |
| 7200 | ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO; |
| 7201 | ds_pool_ci.maxSets = 1; |
| 7202 | ds_pool_ci.poolSizeCount = 1; |
| 7203 | ds_pool_ci.pPoolSizes = &ds_type_count; |
| 7204 | |
| 7205 | VkDescriptorPool ds_pool; |
| 7206 | err = |
| 7207 | vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool); |
| 7208 | ASSERT_VK_SUCCESS(err); |
| 7209 | |
| 7210 | VkDescriptorSetLayoutBinding dsl_binding = {}; |
| 7211 | dsl_binding.binding = 0; |
| 7212 | dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 7213 | dsl_binding.descriptorCount = 1; |
| 7214 | dsl_binding.stageFlags = VK_SHADER_STAGE_ALL; |
| 7215 | |
| 7216 | VkDescriptorSetLayoutCreateInfo ds_layout_ci = {}; |
| 7217 | ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO; |
| 7218 | ds_layout_ci.bindingCount = 1; |
| 7219 | ds_layout_ci.pBindings = &dsl_binding; |
| 7220 | |
| 7221 | VkDescriptorSetLayout ds_layout; |
| 7222 | err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, |
| 7223 | &ds_layout); |
| 7224 | ASSERT_VK_SUCCESS(err); |
| 7225 | |
| 7226 | VkDescriptorSet descriptorSet; |
| 7227 | VkDescriptorSetAllocateInfo alloc_info = {}; |
| 7228 | alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO; |
| 7229 | alloc_info.descriptorSetCount = 1; |
| 7230 | alloc_info.descriptorPool = ds_pool; |
| 7231 | alloc_info.pSetLayouts = &ds_layout; |
| 7232 | err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, |
| 7233 | &descriptorSet); |
| 7234 | ASSERT_VK_SUCCESS(err); |
| 7235 | |
| 7236 | VkPipelineLayoutCreateInfo pipeline_layout_ci = {}; |
| 7237 | pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO; |
| 7238 | pipeline_layout_ci.setLayoutCount = 1; |
| 7239 | pipeline_layout_ci.pSetLayouts = &ds_layout; |
| 7240 | |
| 7241 | VkPipelineLayout pipeline_layout; |
| 7242 | err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, |
| 7243 | &pipeline_layout); |
| 7244 | ASSERT_VK_SUCCESS(err); |
| 7245 | |
| 7246 | VkPipelineViewportStateCreateInfo vp_state_ci = {}; |
| 7247 | vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO; |
| 7248 | vp_state_ci.scissorCount = 1; |
| 7249 | vp_state_ci.pScissors = |
| 7250 | NULL; // Null scissor w/ count of 1 should cause error |
| 7251 | vp_state_ci.viewportCount = 1; |
| 7252 | vp_state_ci.pViewports = |
| 7253 | NULL; // vp is dynamic (below) so this won't cause error |
| 7254 | |
| 7255 | VkDynamicState vp_state = VK_DYNAMIC_STATE_VIEWPORT; |
| 7256 | // Set scissor as dynamic to avoid that error |
| 7257 | VkPipelineDynamicStateCreateInfo dyn_state_ci = {}; |
| 7258 | dyn_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO; |
| 7259 | dyn_state_ci.dynamicStateCount = 1; |
| 7260 | dyn_state_ci.pDynamicStates = &vp_state; |
| 7261 | |
| 7262 | VkPipelineShaderStageCreateInfo shaderStages[2]; |
| 7263 | memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo)); |
| 7264 | |
| 7265 | VkShaderObj vs(m_device, bindStateVertShaderText, |
| 7266 | VK_SHADER_STAGE_VERTEX_BIT, this); |
| 7267 | VkShaderObj fs(m_device, bindStateFragShaderText, |
| 7268 | VK_SHADER_STAGE_FRAGMENT_BIT, |
Karl Schultz | bdb7595 | 2016-04-19 11:36:49 -0600 | [diff] [blame] | 7269 | this); // We shouldn't need a fragment shader |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7270 | // but add it to be able to run on more devices |
| 7271 | shaderStages[0] = vs.GetStageCreateInfo(); |
| 7272 | shaderStages[1] = fs.GetStageCreateInfo(); |
| 7273 | |
| 7274 | VkPipelineVertexInputStateCreateInfo vi_ci = {}; |
| 7275 | vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO; |
| 7276 | vi_ci.pNext = nullptr; |
| 7277 | vi_ci.vertexBindingDescriptionCount = 0; |
| 7278 | vi_ci.pVertexBindingDescriptions = nullptr; |
| 7279 | vi_ci.vertexAttributeDescriptionCount = 0; |
| 7280 | vi_ci.pVertexAttributeDescriptions = nullptr; |
| 7281 | |
| 7282 | VkPipelineInputAssemblyStateCreateInfo ia_ci = {}; |
| 7283 | ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO; |
| 7284 | ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP; |
| 7285 | |
| 7286 | VkPipelineRasterizationStateCreateInfo rs_ci = {}; |
| 7287 | rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO; |
| 7288 | rs_ci.pNext = nullptr; |
| 7289 | |
Mark Young | c89c631 | 2016-03-31 16:03:20 -0600 | [diff] [blame] | 7290 | VkPipelineColorBlendAttachmentState att = {}; |
| 7291 | att.blendEnable = VK_FALSE; |
| 7292 | att.colorWriteMask = 0xf; |
| 7293 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7294 | VkPipelineColorBlendStateCreateInfo cb_ci = {}; |
| 7295 | cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO; |
| 7296 | cb_ci.pNext = nullptr; |
Mark Young | c89c631 | 2016-03-31 16:03:20 -0600 | [diff] [blame] | 7297 | cb_ci.attachmentCount = 1; |
| 7298 | cb_ci.pAttachments = &att; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7299 | |
| 7300 | VkGraphicsPipelineCreateInfo gp_ci = {}; |
| 7301 | gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO; |
| 7302 | gp_ci.stageCount = 2; |
| 7303 | gp_ci.pStages = shaderStages; |
| 7304 | gp_ci.pVertexInputState = &vi_ci; |
| 7305 | gp_ci.pInputAssemblyState = &ia_ci; |
| 7306 | gp_ci.pViewportState = &vp_state_ci; |
| 7307 | gp_ci.pRasterizationState = &rs_ci; |
| 7308 | gp_ci.pColorBlendState = &cb_ci; |
| 7309 | gp_ci.pDynamicState = &dyn_state_ci; |
| 7310 | gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT; |
| 7311 | gp_ci.layout = pipeline_layout; |
| 7312 | gp_ci.renderPass = renderPass(); |
| 7313 | |
| 7314 | VkPipelineCacheCreateInfo pc_ci = {}; |
| 7315 | pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO; |
| 7316 | |
| 7317 | VkPipeline pipeline; |
| 7318 | VkPipelineCache pipelineCache; |
| 7319 | |
| 7320 | err = |
| 7321 | vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache); |
| 7322 | ASSERT_VK_SUCCESS(err); |
| 7323 | err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, |
| 7324 | &gp_ci, NULL, &pipeline); |
| 7325 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 7326 | m_errorMonitor->VerifyFound(); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7327 | |
| 7328 | // Now hit second fail case where we set scissor w/ different count than PSO |
| 7329 | // First need to successfully create the PSO from above by setting |
| 7330 | // pViewports |
| 7331 | m_errorMonitor->SetDesiredFailureMsg( |
| 7332 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 7333 | "Dynamic viewportCount from vkCmdSetViewport() is 2, but PSO " |
| 7334 | "viewportCount is 1. These counts must match."); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 7335 | |
Tobin Ehlis | d332f28 | 2015-10-02 11:00:56 -0600 | [diff] [blame] | 7336 | VkRect2D sc = {}; // Just need dummy vp to point to |
| 7337 | vp_state_ci.pScissors = ≻ |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7338 | err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, |
| 7339 | &gp_ci, NULL, &pipeline); |
Tobin Ehlis | d332f28 | 2015-10-02 11:00:56 -0600 | [diff] [blame] | 7340 | ASSERT_VK_SUCCESS(err); |
| 7341 | BeginCommandBuffer(); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7342 | vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), |
| 7343 | VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline); |
Tobin Ehlis | d332f28 | 2015-10-02 11:00:56 -0600 | [diff] [blame] | 7344 | VkViewport viewports[2] = {}; // don't care about data |
| 7345 | // Count of 2 doesn't match PSO count of 1 |
Jon Ashburn | 19d3bf1 | 2015-12-30 14:06:55 -0700 | [diff] [blame] | 7346 | vkCmdSetViewport(m_commandBuffer->GetBufferHandle(), 0, 2, viewports); |
Tobin Ehlis | d332f28 | 2015-10-02 11:00:56 -0600 | [diff] [blame] | 7347 | Draw(1, 0, 0, 0); |
| 7348 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 7349 | m_errorMonitor->VerifyFound(); |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 7350 | |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 7351 | vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL); |
| 7352 | vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL); |
| 7353 | vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL); |
| 7354 | vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL); |
Tony Barbour | df4c004 | 2016-06-01 15:55:43 -0600 | [diff] [blame] | 7355 | vkDestroyPipeline(m_device->device(), pipeline, NULL); |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 7356 | } |
| 7357 | |
Mark Young | 7394fdd | 2016-03-31 14:56:43 -0600 | [diff] [blame] | 7358 | TEST_F(VkLayerTest, PSOLineWidthInvalid) { |
| 7359 | VkResult err; |
| 7360 | |
| 7361 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Mark Young | 4710795 | 2016-05-02 15:59:55 -0600 | [diff] [blame] | 7362 | "Attempt to set lineWidth to -1"); |
Mark Young | 7394fdd | 2016-03-31 14:56:43 -0600 | [diff] [blame] | 7363 | |
| 7364 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 7365 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 7366 | |
| 7367 | VkDescriptorPoolSize ds_type_count = {}; |
| 7368 | ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 7369 | ds_type_count.descriptorCount = 1; |
| 7370 | |
| 7371 | VkDescriptorPoolCreateInfo ds_pool_ci = {}; |
| 7372 | ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO; |
| 7373 | ds_pool_ci.maxSets = 1; |
| 7374 | ds_pool_ci.poolSizeCount = 1; |
| 7375 | ds_pool_ci.pPoolSizes = &ds_type_count; |
| 7376 | |
| 7377 | VkDescriptorPool ds_pool; |
| 7378 | err = |
| 7379 | vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool); |
| 7380 | ASSERT_VK_SUCCESS(err); |
| 7381 | |
| 7382 | VkDescriptorSetLayoutBinding dsl_binding = {}; |
| 7383 | dsl_binding.binding = 0; |
| 7384 | dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 7385 | dsl_binding.descriptorCount = 1; |
| 7386 | dsl_binding.stageFlags = VK_SHADER_STAGE_ALL; |
| 7387 | |
| 7388 | VkDescriptorSetLayoutCreateInfo ds_layout_ci = {}; |
| 7389 | ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO; |
| 7390 | ds_layout_ci.bindingCount = 1; |
| 7391 | ds_layout_ci.pBindings = &dsl_binding; |
| 7392 | |
| 7393 | VkDescriptorSetLayout ds_layout; |
| 7394 | err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, |
| 7395 | &ds_layout); |
| 7396 | ASSERT_VK_SUCCESS(err); |
| 7397 | |
| 7398 | VkDescriptorSet descriptorSet; |
| 7399 | VkDescriptorSetAllocateInfo alloc_info = {}; |
| 7400 | alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO; |
| 7401 | alloc_info.descriptorSetCount = 1; |
| 7402 | alloc_info.descriptorPool = ds_pool; |
| 7403 | alloc_info.pSetLayouts = &ds_layout; |
| 7404 | err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, |
| 7405 | &descriptorSet); |
| 7406 | ASSERT_VK_SUCCESS(err); |
| 7407 | |
| 7408 | VkPipelineLayoutCreateInfo pipeline_layout_ci = {}; |
| 7409 | pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO; |
| 7410 | pipeline_layout_ci.setLayoutCount = 1; |
| 7411 | pipeline_layout_ci.pSetLayouts = &ds_layout; |
| 7412 | |
| 7413 | VkPipelineLayout pipeline_layout; |
| 7414 | err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, |
| 7415 | &pipeline_layout); |
| 7416 | ASSERT_VK_SUCCESS(err); |
| 7417 | |
| 7418 | VkPipelineViewportStateCreateInfo vp_state_ci = {}; |
| 7419 | vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO; |
| 7420 | vp_state_ci.scissorCount = 1; |
| 7421 | vp_state_ci.pScissors = NULL; |
| 7422 | vp_state_ci.viewportCount = 1; |
| 7423 | vp_state_ci.pViewports = NULL; |
| 7424 | |
| 7425 | VkDynamicState dynamic_states[3] = {VK_DYNAMIC_STATE_VIEWPORT, |
| 7426 | VK_DYNAMIC_STATE_SCISSOR, |
| 7427 | VK_DYNAMIC_STATE_LINE_WIDTH}; |
| 7428 | // Set scissor as dynamic to avoid that error |
| 7429 | VkPipelineDynamicStateCreateInfo dyn_state_ci = {}; |
| 7430 | dyn_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO; |
| 7431 | dyn_state_ci.dynamicStateCount = 2; |
| 7432 | dyn_state_ci.pDynamicStates = dynamic_states; |
| 7433 | |
| 7434 | VkPipelineShaderStageCreateInfo shaderStages[2]; |
| 7435 | memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo)); |
| 7436 | |
| 7437 | VkShaderObj vs(m_device, bindStateVertShaderText, |
| 7438 | VK_SHADER_STAGE_VERTEX_BIT, this); |
| 7439 | VkShaderObj fs(m_device, bindStateFragShaderText, |
| 7440 | VK_SHADER_STAGE_FRAGMENT_BIT, |
| 7441 | this); // TODO - We shouldn't need a fragment shader |
| 7442 | // but add it to be able to run on more devices |
| 7443 | shaderStages[0] = vs.GetStageCreateInfo(); |
| 7444 | shaderStages[1] = fs.GetStageCreateInfo(); |
| 7445 | |
| 7446 | VkPipelineVertexInputStateCreateInfo vi_ci = {}; |
| 7447 | vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO; |
| 7448 | vi_ci.pNext = nullptr; |
| 7449 | vi_ci.vertexBindingDescriptionCount = 0; |
| 7450 | vi_ci.pVertexBindingDescriptions = nullptr; |
| 7451 | vi_ci.vertexAttributeDescriptionCount = 0; |
| 7452 | vi_ci.pVertexAttributeDescriptions = nullptr; |
| 7453 | |
| 7454 | VkPipelineInputAssemblyStateCreateInfo ia_ci = {}; |
| 7455 | ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO; |
| 7456 | ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP; |
| 7457 | |
| 7458 | VkPipelineRasterizationStateCreateInfo rs_ci = {}; |
| 7459 | rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO; |
| 7460 | rs_ci.pNext = nullptr; |
| 7461 | |
Mark Young | 4710795 | 2016-05-02 15:59:55 -0600 | [diff] [blame] | 7462 | // Check too low (line width of -1.0f). |
| 7463 | rs_ci.lineWidth = -1.0f; |
Mark Young | 7394fdd | 2016-03-31 14:56:43 -0600 | [diff] [blame] | 7464 | |
| 7465 | VkPipelineColorBlendAttachmentState att = {}; |
| 7466 | att.blendEnable = VK_FALSE; |
| 7467 | att.colorWriteMask = 0xf; |
| 7468 | |
| 7469 | VkPipelineColorBlendStateCreateInfo cb_ci = {}; |
| 7470 | cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO; |
| 7471 | cb_ci.pNext = nullptr; |
| 7472 | cb_ci.attachmentCount = 1; |
| 7473 | cb_ci.pAttachments = &att; |
| 7474 | |
| 7475 | VkGraphicsPipelineCreateInfo gp_ci = {}; |
| 7476 | gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO; |
| 7477 | gp_ci.stageCount = 2; |
| 7478 | gp_ci.pStages = shaderStages; |
| 7479 | gp_ci.pVertexInputState = &vi_ci; |
| 7480 | gp_ci.pInputAssemblyState = &ia_ci; |
| 7481 | gp_ci.pViewportState = &vp_state_ci; |
| 7482 | gp_ci.pRasterizationState = &rs_ci; |
| 7483 | gp_ci.pColorBlendState = &cb_ci; |
| 7484 | gp_ci.pDynamicState = &dyn_state_ci; |
| 7485 | gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT; |
| 7486 | gp_ci.layout = pipeline_layout; |
| 7487 | gp_ci.renderPass = renderPass(); |
| 7488 | |
| 7489 | VkPipelineCacheCreateInfo pc_ci = {}; |
| 7490 | pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO; |
| 7491 | |
| 7492 | VkPipeline pipeline; |
| 7493 | VkPipelineCache pipelineCache; |
| 7494 | |
| 7495 | err = |
| 7496 | vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache); |
| 7497 | ASSERT_VK_SUCCESS(err); |
| 7498 | err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, |
| 7499 | &gp_ci, NULL, &pipeline); |
| 7500 | |
| 7501 | m_errorMonitor->VerifyFound(); |
Tony Barbour | df4c004 | 2016-06-01 15:55:43 -0600 | [diff] [blame] | 7502 | vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL); |
Mark Young | 7394fdd | 2016-03-31 14:56:43 -0600 | [diff] [blame] | 7503 | |
| 7504 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 7505 | "Attempt to set lineWidth to 65536"); |
| 7506 | |
| 7507 | // Check too high (line width of 65536.0f). |
| 7508 | rs_ci.lineWidth = 65536.0f; |
| 7509 | |
| 7510 | err = |
| 7511 | vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache); |
| 7512 | ASSERT_VK_SUCCESS(err); |
| 7513 | err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, |
| 7514 | &gp_ci, NULL, &pipeline); |
| 7515 | |
| 7516 | m_errorMonitor->VerifyFound(); |
Tony Barbour | df4c004 | 2016-06-01 15:55:43 -0600 | [diff] [blame] | 7517 | vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL); |
Mark Young | 7394fdd | 2016-03-31 14:56:43 -0600 | [diff] [blame] | 7518 | |
| 7519 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Mark Young | 4710795 | 2016-05-02 15:59:55 -0600 | [diff] [blame] | 7520 | "Attempt to set lineWidth to -1"); |
Mark Young | 7394fdd | 2016-03-31 14:56:43 -0600 | [diff] [blame] | 7521 | |
| 7522 | dyn_state_ci.dynamicStateCount = 3; |
| 7523 | |
| 7524 | rs_ci.lineWidth = 1.0f; |
| 7525 | |
| 7526 | err = |
| 7527 | vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache); |
| 7528 | ASSERT_VK_SUCCESS(err); |
| 7529 | err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, |
| 7530 | &gp_ci, NULL, &pipeline); |
| 7531 | BeginCommandBuffer(); |
| 7532 | vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), |
| 7533 | VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline); |
| 7534 | |
| 7535 | // Check too low with dynamic setting. |
Mark Young | 4710795 | 2016-05-02 15:59:55 -0600 | [diff] [blame] | 7536 | vkCmdSetLineWidth(m_commandBuffer->GetBufferHandle(), -1.0f); |
Mark Young | 7394fdd | 2016-03-31 14:56:43 -0600 | [diff] [blame] | 7537 | m_errorMonitor->VerifyFound(); |
| 7538 | |
| 7539 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 7540 | "Attempt to set lineWidth to 65536"); |
| 7541 | |
| 7542 | // Check too high with dynamic setting. |
| 7543 | vkCmdSetLineWidth(m_commandBuffer->GetBufferHandle(), 65536.0f); |
| 7544 | m_errorMonitor->VerifyFound(); |
| 7545 | EndCommandBuffer(); |
| 7546 | |
| 7547 | vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL); |
| 7548 | vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL); |
| 7549 | vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL); |
| 7550 | vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL); |
Tony Barbour | df4c004 | 2016-06-01 15:55:43 -0600 | [diff] [blame] | 7551 | vkDestroyPipeline(m_device->device(), pipeline, NULL); |
Mark Young | 7394fdd | 2016-03-31 14:56:43 -0600 | [diff] [blame] | 7552 | } |
| 7553 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7554 | TEST_F(VkLayerTest, NullRenderPass) { |
Tobin Ehlis | 98aa0ed | 2015-06-25 16:27:19 -0600 | [diff] [blame] | 7555 | // Bind a NULL RenderPass |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7556 | m_errorMonitor->SetDesiredFailureMsg( |
| 7557 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 7558 | "You cannot use a NULL RenderPass object in vkCmdBeginRenderPass()"); |
Tobin Ehlis | 98aa0ed | 2015-06-25 16:27:19 -0600 | [diff] [blame] | 7559 | |
| 7560 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 7561 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
Tobin Ehlis | 98aa0ed | 2015-06-25 16:27:19 -0600 | [diff] [blame] | 7562 | |
Tony Barbour | fe3351b | 2015-07-28 10:17:20 -0600 | [diff] [blame] | 7563 | BeginCommandBuffer(); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7564 | // Don't care about RenderPass handle b/c error should be flagged before |
| 7565 | // that |
| 7566 | vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), NULL, |
| 7567 | VK_SUBPASS_CONTENTS_INLINE); |
Tobin Ehlis | 98aa0ed | 2015-06-25 16:27:19 -0600 | [diff] [blame] | 7568 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 7569 | m_errorMonitor->VerifyFound(); |
Tobin Ehlis | 98aa0ed | 2015-06-25 16:27:19 -0600 | [diff] [blame] | 7570 | } |
| 7571 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7572 | TEST_F(VkLayerTest, RenderPassWithinRenderPass) { |
Tobin Ehlis | af1f3a4 | 2015-06-25 15:46:59 -0600 | [diff] [blame] | 7573 | // Bind a BeginRenderPass within an active RenderPass |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7574 | m_errorMonitor->SetDesiredFailureMsg( |
| 7575 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 7576 | "It is invalid to issue this call inside an active render pass"); |
Tobin Ehlis | af1f3a4 | 2015-06-25 15:46:59 -0600 | [diff] [blame] | 7577 | |
| 7578 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 7579 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
Tobin Ehlis | af1f3a4 | 2015-06-25 15:46:59 -0600 | [diff] [blame] | 7580 | |
Tony Barbour | fe3351b | 2015-07-28 10:17:20 -0600 | [diff] [blame] | 7581 | BeginCommandBuffer(); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7582 | // Just create a dummy Renderpass that's non-NULL so we can get to the |
| 7583 | // proper error |
Chris Forbes | 38ae7c4 | 2016-06-21 20:51:44 +1200 | [diff] [blame] | 7584 | vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &m_renderPassBeginInfo, |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7585 | VK_SUBPASS_CONTENTS_INLINE); |
Tobin Ehlis | af1f3a4 | 2015-06-25 15:46:59 -0600 | [diff] [blame] | 7586 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 7587 | m_errorMonitor->VerifyFound(); |
Tobin Ehlis | 49eb23d | 2015-05-22 12:38:55 -0600 | [diff] [blame] | 7588 | } |
| 7589 | |
Chris Forbes | 2eeabe3 | 2016-06-21 20:52:34 +1200 | [diff] [blame] | 7590 | TEST_F(VkLayerTest, RenderPassSecondaryCommandBuffersMultipleTimes) { |
| 7591 | m_errorMonitor->ExpectSuccess(); |
| 7592 | |
| 7593 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 7594 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 7595 | |
| 7596 | BeginCommandBuffer(); // framework implicitly begins the renderpass. |
| 7597 | vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle()); // end implicit. |
| 7598 | |
| 7599 | vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &m_renderPassBeginInfo, |
| 7600 | VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS); |
| 7601 | vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle()); |
| 7602 | m_errorMonitor->VerifyNotFound(); |
| 7603 | vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &m_renderPassBeginInfo, |
| 7604 | VK_SUBPASS_CONTENTS_INLINE); |
| 7605 | m_errorMonitor->VerifyNotFound(); |
| 7606 | vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle()); |
| 7607 | m_errorMonitor->VerifyNotFound(); |
| 7608 | |
| 7609 | m_commandBuffer->EndCommandBuffer(); |
| 7610 | m_errorMonitor->VerifyNotFound(); |
| 7611 | } |
| 7612 | |
Tobin Ehlis | 5a1c033 | 2016-05-31 13:59:26 -0600 | [diff] [blame] | 7613 | TEST_F(VkLayerTest, RenderPassClearOpMismatch) { |
| 7614 | TEST_DESCRIPTION("Begin a renderPass where clearValueCount is less than" |
| 7615 | "the number of renderPass attachments that use loadOp" |
| 7616 | "VK_ATTACHMENT_LOAD_OP_CLEAR."); |
| 7617 | |
| 7618 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 7619 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 7620 | |
| 7621 | // Create a renderPass with a single attachment that uses loadOp CLEAR |
| 7622 | VkAttachmentReference attach = {}; |
| 7623 | attach.layout = VK_IMAGE_LAYOUT_GENERAL; |
| 7624 | VkSubpassDescription subpass = {}; |
| 7625 | subpass.inputAttachmentCount = 1; |
| 7626 | subpass.pInputAttachments = &attach; |
| 7627 | VkRenderPassCreateInfo rpci = {}; |
| 7628 | rpci.subpassCount = 1; |
| 7629 | rpci.pSubpasses = &subpass; |
| 7630 | rpci.attachmentCount = 1; |
| 7631 | VkAttachmentDescription attach_desc = {}; |
| 7632 | attach_desc.format = VK_FORMAT_UNDEFINED; |
| 7633 | // Set loadOp to CLEAR |
| 7634 | attach_desc.loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR; |
| 7635 | rpci.pAttachments = &attach_desc; |
| 7636 | rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO; |
| 7637 | VkRenderPass rp; |
| 7638 | vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp); |
| 7639 | |
| 7640 | VkCommandBufferInheritanceInfo hinfo = {}; |
| 7641 | hinfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO; |
| 7642 | hinfo.renderPass = VK_NULL_HANDLE; |
| 7643 | hinfo.subpass = 0; |
| 7644 | hinfo.framebuffer = VK_NULL_HANDLE; |
| 7645 | hinfo.occlusionQueryEnable = VK_FALSE; |
| 7646 | hinfo.queryFlags = 0; |
| 7647 | hinfo.pipelineStatistics = 0; |
| 7648 | VkCommandBufferBeginInfo info = {}; |
| 7649 | info.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT; |
| 7650 | info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO; |
| 7651 | info.pInheritanceInfo = &hinfo; |
| 7652 | |
| 7653 | vkBeginCommandBuffer(m_commandBuffer->handle(), &info); |
| 7654 | VkRenderPassBeginInfo rp_begin = {}; |
| 7655 | rp_begin.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO; |
| 7656 | rp_begin.pNext = NULL; |
| 7657 | rp_begin.renderPass = renderPass(); |
| 7658 | rp_begin.framebuffer = framebuffer(); |
| 7659 | rp_begin.clearValueCount = 0; // Should be 1 |
| 7660 | |
| 7661 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 7662 | " has a clearValueCount of 0 but the " |
| 7663 | "actual number of attachments in " |
| 7664 | "renderPass "); |
| 7665 | |
| 7666 | vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &rp_begin, |
| 7667 | VK_SUBPASS_CONTENTS_INLINE); |
| 7668 | |
| 7669 | m_errorMonitor->VerifyFound(); |
Mark Lobodzinski | 5c70ebd | 2016-06-09 13:45:00 -0600 | [diff] [blame] | 7670 | |
| 7671 | vkDestroyRenderPass(m_device->device(), rp, NULL); |
Tobin Ehlis | 5a1c033 | 2016-05-31 13:59:26 -0600 | [diff] [blame] | 7672 | } |
| 7673 | |
Cody Northrop | 3bb4d96 | 2016-05-09 16:15:57 -0600 | [diff] [blame] | 7674 | TEST_F(VkLayerTest, EndCommandBufferWithinRenderPass) { |
| 7675 | |
| 7676 | TEST_DESCRIPTION("End a command buffer with an active render pass"); |
| 7677 | |
| 7678 | m_errorMonitor->SetDesiredFailureMsg( |
| 7679 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 7680 | "It is invalid to issue this call inside an active render pass"); |
| 7681 | |
| 7682 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 7683 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 7684 | |
| 7685 | // The framework's BeginCommandBuffer calls CreateRenderPass |
| 7686 | BeginCommandBuffer(); |
| 7687 | |
| 7688 | // Call directly into vkEndCommandBuffer instead of the |
| 7689 | // the framework's EndCommandBuffer, which inserts a |
| 7690 | // vkEndRenderPass |
| 7691 | vkEndCommandBuffer(m_commandBuffer->GetBufferHandle()); |
| 7692 | |
| 7693 | m_errorMonitor->VerifyFound(); |
| 7694 | |
| 7695 | // TODO: Add test for VK_COMMAND_BUFFER_LEVEL_SECONDARY |
| 7696 | // TODO: Add test for VK_COMMAND_BUFFER_USAGE_RENDER_PASS_CONTINUE_BIT |
| 7697 | } |
| 7698 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7699 | TEST_F(VkLayerTest, FillBufferWithinRenderPass) { |
Mark Lobodzinski | d563950 | 2015-09-24 09:51:47 -0600 | [diff] [blame] | 7700 | // Call CmdFillBuffer within an active renderpass |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7701 | m_errorMonitor->SetDesiredFailureMsg( |
| 7702 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 7703 | "It is invalid to issue this call inside an active render pass"); |
Mark Lobodzinski | d563950 | 2015-09-24 09:51:47 -0600 | [diff] [blame] | 7704 | |
| 7705 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 7706 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
Mark Lobodzinski | d563950 | 2015-09-24 09:51:47 -0600 | [diff] [blame] | 7707 | |
| 7708 | // Renderpass is started here |
| 7709 | BeginCommandBuffer(); |
| 7710 | |
| 7711 | VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 7712 | vk_testing::Buffer dstBuffer; |
| 7713 | dstBuffer.init_as_dst(*m_device, (VkDeviceSize)1024, reqs); |
Mark Lobodzinski | d563950 | 2015-09-24 09:51:47 -0600 | [diff] [blame] | 7714 | |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 7715 | m_commandBuffer->FillBuffer(dstBuffer.handle(), 0, 4, 0x11111111); |
Mark Lobodzinski | d563950 | 2015-09-24 09:51:47 -0600 | [diff] [blame] | 7716 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 7717 | m_errorMonitor->VerifyFound(); |
Mark Lobodzinski | d563950 | 2015-09-24 09:51:47 -0600 | [diff] [blame] | 7718 | } |
| 7719 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7720 | TEST_F(VkLayerTest, UpdateBufferWithinRenderPass) { |
Mark Lobodzinski | d563950 | 2015-09-24 09:51:47 -0600 | [diff] [blame] | 7721 | // Call CmdUpdateBuffer within an active renderpass |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7722 | m_errorMonitor->SetDesiredFailureMsg( |
| 7723 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 7724 | "It is invalid to issue this call inside an active render pass"); |
Mark Lobodzinski | d563950 | 2015-09-24 09:51:47 -0600 | [diff] [blame] | 7725 | |
| 7726 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 7727 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
Mark Lobodzinski | d563950 | 2015-09-24 09:51:47 -0600 | [diff] [blame] | 7728 | |
| 7729 | // Renderpass is started here |
| 7730 | BeginCommandBuffer(); |
| 7731 | |
| 7732 | VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 7733 | vk_testing::Buffer dstBuffer; |
| 7734 | dstBuffer.init_as_dst(*m_device, (VkDeviceSize)1024, reqs); |
Mark Lobodzinski | d563950 | 2015-09-24 09:51:47 -0600 | [diff] [blame] | 7735 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7736 | VkDeviceSize dstOffset = 0; |
| 7737 | VkDeviceSize dataSize = 1024; |
| 7738 | const uint32_t *pData = NULL; |
Mark Lobodzinski | d563950 | 2015-09-24 09:51:47 -0600 | [diff] [blame] | 7739 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7740 | vkCmdUpdateBuffer(m_commandBuffer->GetBufferHandle(), dstBuffer.handle(), |
| 7741 | dstOffset, dataSize, pData); |
Mark Lobodzinski | d563950 | 2015-09-24 09:51:47 -0600 | [diff] [blame] | 7742 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 7743 | m_errorMonitor->VerifyFound(); |
Mark Lobodzinski | d563950 | 2015-09-24 09:51:47 -0600 | [diff] [blame] | 7744 | } |
| 7745 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7746 | TEST_F(VkLayerTest, ClearColorImageWithinRenderPass) { |
Mark Lobodzinski | d563950 | 2015-09-24 09:51:47 -0600 | [diff] [blame] | 7747 | // Call CmdClearColorImage within an active RenderPass |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7748 | m_errorMonitor->SetDesiredFailureMsg( |
| 7749 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 7750 | "It is invalid to issue this call inside an active render pass"); |
Mark Lobodzinski | d563950 | 2015-09-24 09:51:47 -0600 | [diff] [blame] | 7751 | |
| 7752 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 7753 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
Mark Lobodzinski | d563950 | 2015-09-24 09:51:47 -0600 | [diff] [blame] | 7754 | |
| 7755 | // Renderpass is started here |
| 7756 | BeginCommandBuffer(); |
| 7757 | |
Michael Lentine | 0a369f6 | 2016-02-03 16:51:46 -0600 | [diff] [blame] | 7758 | VkClearColorValue clear_color; |
| 7759 | memset(clear_color.uint32, 0, sizeof(uint32_t) * 4); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7760 | VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT; |
| 7761 | const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM; |
| 7762 | const int32_t tex_width = 32; |
| 7763 | const int32_t tex_height = 32; |
| 7764 | VkImageCreateInfo image_create_info = {}; |
| 7765 | image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO; |
| 7766 | image_create_info.pNext = NULL; |
| 7767 | image_create_info.imageType = VK_IMAGE_TYPE_2D; |
| 7768 | image_create_info.format = tex_format; |
| 7769 | image_create_info.extent.width = tex_width; |
| 7770 | image_create_info.extent.height = tex_height; |
| 7771 | image_create_info.extent.depth = 1; |
| 7772 | image_create_info.mipLevels = 1; |
| 7773 | image_create_info.arrayLayers = 1; |
| 7774 | image_create_info.samples = VK_SAMPLE_COUNT_1_BIT; |
| 7775 | image_create_info.tiling = VK_IMAGE_TILING_LINEAR; |
| 7776 | image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT; |
Mark Lobodzinski | d563950 | 2015-09-24 09:51:47 -0600 | [diff] [blame] | 7777 | |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 7778 | vk_testing::Image dstImage; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7779 | dstImage.init(*m_device, (const VkImageCreateInfo &)image_create_info, |
| 7780 | reqs); |
Mark Lobodzinski | d563950 | 2015-09-24 09:51:47 -0600 | [diff] [blame] | 7781 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7782 | const VkImageSubresourceRange range = vk_testing::Image::subresource_range( |
| 7783 | image_create_info, VK_IMAGE_ASPECT_COLOR_BIT); |
Mark Lobodzinski | d563950 | 2015-09-24 09:51:47 -0600 | [diff] [blame] | 7784 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7785 | vkCmdClearColorImage(m_commandBuffer->GetBufferHandle(), dstImage.handle(), |
| 7786 | VK_IMAGE_LAYOUT_GENERAL, &clear_color, 1, &range); |
Mark Lobodzinski | d563950 | 2015-09-24 09:51:47 -0600 | [diff] [blame] | 7787 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 7788 | m_errorMonitor->VerifyFound(); |
Mark Lobodzinski | d563950 | 2015-09-24 09:51:47 -0600 | [diff] [blame] | 7789 | } |
| 7790 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7791 | TEST_F(VkLayerTest, ClearDepthStencilImageWithinRenderPass) { |
Mark Lobodzinski | d563950 | 2015-09-24 09:51:47 -0600 | [diff] [blame] | 7792 | // Call CmdClearDepthStencilImage within an active RenderPass |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7793 | m_errorMonitor->SetDesiredFailureMsg( |
| 7794 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 7795 | "It is invalid to issue this call inside an active render pass"); |
Mark Lobodzinski | d563950 | 2015-09-24 09:51:47 -0600 | [diff] [blame] | 7796 | |
| 7797 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 7798 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
Mark Lobodzinski | d563950 | 2015-09-24 09:51:47 -0600 | [diff] [blame] | 7799 | |
| 7800 | // Renderpass is started here |
| 7801 | BeginCommandBuffer(); |
| 7802 | |
| 7803 | VkClearDepthStencilValue clear_value = {0}; |
Dustin Graves | a2e5c94 | 2016-02-11 18:28:06 -0700 | [diff] [blame] | 7804 | VkMemoryPropertyFlags reqs = 0; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7805 | VkImageCreateInfo image_create_info = vk_testing::Image::create_info(); |
| 7806 | image_create_info.imageType = VK_IMAGE_TYPE_2D; |
| 7807 | image_create_info.format = VK_FORMAT_D24_UNORM_S8_UINT; |
| 7808 | image_create_info.extent.width = 64; |
| 7809 | image_create_info.extent.height = 64; |
| 7810 | image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL; |
| 7811 | image_create_info.usage = VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT; |
Mark Lobodzinski | d563950 | 2015-09-24 09:51:47 -0600 | [diff] [blame] | 7812 | |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 7813 | vk_testing::Image dstImage; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7814 | dstImage.init(*m_device, (const VkImageCreateInfo &)image_create_info, |
| 7815 | reqs); |
Mark Lobodzinski | d563950 | 2015-09-24 09:51:47 -0600 | [diff] [blame] | 7816 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7817 | const VkImageSubresourceRange range = vk_testing::Image::subresource_range( |
| 7818 | image_create_info, VK_IMAGE_ASPECT_DEPTH_BIT); |
Mark Lobodzinski | d563950 | 2015-09-24 09:51:47 -0600 | [diff] [blame] | 7819 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7820 | vkCmdClearDepthStencilImage( |
| 7821 | m_commandBuffer->GetBufferHandle(), dstImage.handle(), |
| 7822 | VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL, &clear_value, 1, |
| 7823 | &range); |
Mark Lobodzinski | d563950 | 2015-09-24 09:51:47 -0600 | [diff] [blame] | 7824 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 7825 | m_errorMonitor->VerifyFound(); |
Mark Lobodzinski | d563950 | 2015-09-24 09:51:47 -0600 | [diff] [blame] | 7826 | } |
| 7827 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7828 | TEST_F(VkLayerTest, ClearColorAttachmentsOutsideRenderPass) { |
Courtney Goeltzenleuchter | c9323e0 | 2015-10-15 16:51:05 -0600 | [diff] [blame] | 7829 | // Call CmdClearAttachmentss outside of an active RenderPass |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7830 | VkResult err; |
Mark Lobodzinski | d563950 | 2015-09-24 09:51:47 -0600 | [diff] [blame] | 7831 | |
Courtney Goeltzenleuchter | 7415d5a | 2015-12-09 15:48:16 -0700 | [diff] [blame] | 7832 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7833 | "vkCmdClearAttachments: This call " |
| 7834 | "must be issued inside an active " |
| 7835 | "render pass"); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 7836 | |
Mark Lobodzinski | d563950 | 2015-09-24 09:51:47 -0600 | [diff] [blame] | 7837 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 7838 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
Mark Lobodzinski | d563950 | 2015-09-24 09:51:47 -0600 | [diff] [blame] | 7839 | |
| 7840 | // Start no RenderPass |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 7841 | err = m_commandBuffer->BeginCommandBuffer(); |
Mark Lobodzinski | d563950 | 2015-09-24 09:51:47 -0600 | [diff] [blame] | 7842 | ASSERT_VK_SUCCESS(err); |
| 7843 | |
Courtney Goeltzenleuchter | c9323e0 | 2015-10-15 16:51:05 -0600 | [diff] [blame] | 7844 | VkClearAttachment color_attachment; |
| 7845 | color_attachment.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; |
| 7846 | color_attachment.clearValue.color.float32[0] = 0; |
| 7847 | color_attachment.clearValue.color.float32[1] = 0; |
| 7848 | color_attachment.clearValue.color.float32[2] = 0; |
| 7849 | color_attachment.clearValue.color.float32[3] = 0; |
| 7850 | color_attachment.colorAttachment = 0; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7851 | VkClearRect clear_rect = {{{0, 0}, {32, 32}}}; |
| 7852 | vkCmdClearAttachments(m_commandBuffer->GetBufferHandle(), 1, |
| 7853 | &color_attachment, 1, &clear_rect); |
Mark Lobodzinski | d563950 | 2015-09-24 09:51:47 -0600 | [diff] [blame] | 7854 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 7855 | m_errorMonitor->VerifyFound(); |
Mark Lobodzinski | d563950 | 2015-09-24 09:51:47 -0600 | [diff] [blame] | 7856 | } |
| 7857 | |
Karl Schultz | 9e66a29 | 2016-04-21 15:57:51 -0600 | [diff] [blame] | 7858 | TEST_F(VkLayerTest, BufferMemoryBarrierNoBuffer) { |
| 7859 | // Try to add a buffer memory barrier with no buffer. |
| 7860 | m_errorMonitor->SetDesiredFailureMsg( |
| 7861 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 7862 | "required parameter pBufferMemoryBarriers[i].buffer specified as VK_NULL_HANDLE"); |
| 7863 | |
| 7864 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 7865 | BeginCommandBuffer(); |
| 7866 | |
| 7867 | VkBufferMemoryBarrier buf_barrier = {}; |
| 7868 | buf_barrier.sType = VK_STRUCTURE_TYPE_BUFFER_MEMORY_BARRIER; |
| 7869 | buf_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT; |
| 7870 | buf_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT; |
| 7871 | buf_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED; |
| 7872 | buf_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED; |
| 7873 | buf_barrier.buffer = VK_NULL_HANDLE; |
| 7874 | buf_barrier.offset = 0; |
| 7875 | buf_barrier.size = VK_WHOLE_SIZE; |
| 7876 | vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), |
| 7877 | VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, |
| 7878 | 0, 0, nullptr, 1, &buf_barrier, 0, nullptr); |
| 7879 | |
| 7880 | m_errorMonitor->VerifyFound(); |
| 7881 | } |
| 7882 | |
Tony Barbour | 7fd5c0f | 2016-05-03 16:11:53 -0600 | [diff] [blame] | 7883 | TEST_F(VkLayerTest, InvalidBarriers) { |
| 7884 | TEST_DESCRIPTION("A variety of ways to get VK_INVALID_BARRIER "); |
| 7885 | |
| 7886 | m_errorMonitor->SetDesiredFailureMsg( |
| 7887 | VK_DEBUG_REPORT_ERROR_BIT_EXT, "Barriers cannot be set during subpass"); |
| 7888 | |
| 7889 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 7890 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 7891 | |
| 7892 | VkMemoryBarrier mem_barrier = {}; |
| 7893 | mem_barrier.sType = VK_STRUCTURE_TYPE_MEMORY_BARRIER; |
| 7894 | mem_barrier.pNext = NULL; |
| 7895 | mem_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT; |
| 7896 | mem_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT; |
| 7897 | BeginCommandBuffer(); |
| 7898 | // BeginCommandBuffer() starts a render pass |
| 7899 | vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), |
| 7900 | VK_PIPELINE_STAGE_HOST_BIT, |
| 7901 | VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 1, |
| 7902 | &mem_barrier, 0, nullptr, 0, nullptr); |
| 7903 | m_errorMonitor->VerifyFound(); |
| 7904 | |
| 7905 | m_errorMonitor->SetDesiredFailureMsg( |
| 7906 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 7907 | "Image Layout cannot be transitioned to UNDEFINED"); |
| 7908 | VkImageObj image(m_device); |
| 7909 | image.init(128, 128, VK_FORMAT_B8G8R8A8_UNORM, |
| 7910 | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0); |
| 7911 | ASSERT_TRUE(image.initialized()); |
| 7912 | VkImageMemoryBarrier img_barrier = {}; |
| 7913 | img_barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER; |
| 7914 | img_barrier.pNext = NULL; |
| 7915 | img_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT; |
| 7916 | img_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT; |
| 7917 | img_barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL; |
| 7918 | // New layout can't be UNDEFINED |
| 7919 | img_barrier.newLayout = VK_IMAGE_LAYOUT_UNDEFINED; |
| 7920 | img_barrier.image = image.handle(); |
| 7921 | img_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED; |
| 7922 | img_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED; |
| 7923 | img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; |
| 7924 | img_barrier.subresourceRange.baseArrayLayer = 0; |
| 7925 | img_barrier.subresourceRange.baseMipLevel = 0; |
| 7926 | img_barrier.subresourceRange.layerCount = 1; |
| 7927 | img_barrier.subresourceRange.levelCount = 1; |
| 7928 | vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), |
| 7929 | VK_PIPELINE_STAGE_HOST_BIT, |
| 7930 | VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0, nullptr, 0, |
| 7931 | nullptr, 1, &img_barrier); |
| 7932 | m_errorMonitor->VerifyFound(); |
| 7933 | img_barrier.newLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL; |
| 7934 | |
| 7935 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 7936 | "Subresource must have the sum of the " |
| 7937 | "baseArrayLayer"); |
| 7938 | // baseArrayLayer + layerCount must be <= image's arrayLayers |
| 7939 | img_barrier.subresourceRange.baseArrayLayer = 1; |
| 7940 | vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), |
| 7941 | VK_PIPELINE_STAGE_HOST_BIT, |
| 7942 | VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0, nullptr, 0, |
| 7943 | nullptr, 1, &img_barrier); |
| 7944 | m_errorMonitor->VerifyFound(); |
| 7945 | img_barrier.subresourceRange.baseArrayLayer = 0; |
| 7946 | |
| 7947 | m_errorMonitor->SetDesiredFailureMsg( |
| 7948 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 7949 | "Subresource must have the sum of the baseMipLevel"); |
| 7950 | // baseMipLevel + levelCount must be <= image's mipLevels |
| 7951 | img_barrier.subresourceRange.baseMipLevel = 1; |
| 7952 | vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), |
| 7953 | VK_PIPELINE_STAGE_HOST_BIT, |
| 7954 | VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0, nullptr, 0, |
| 7955 | nullptr, 1, &img_barrier); |
| 7956 | m_errorMonitor->VerifyFound(); |
| 7957 | img_barrier.subresourceRange.baseMipLevel = 0; |
| 7958 | |
| 7959 | m_errorMonitor->SetDesiredFailureMsg( |
| 7960 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 7961 | "Buffer Barriers cannot be used during a render pass"); |
| 7962 | vk_testing::Buffer buffer; |
| 7963 | buffer.init(*m_device, 256); |
| 7964 | VkBufferMemoryBarrier buf_barrier = {}; |
| 7965 | buf_barrier.sType = VK_STRUCTURE_TYPE_BUFFER_MEMORY_BARRIER; |
| 7966 | buf_barrier.pNext = NULL; |
| 7967 | buf_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT; |
| 7968 | buf_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT; |
| 7969 | buf_barrier.buffer = buffer.handle(); |
| 7970 | buf_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED; |
| 7971 | buf_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED; |
| 7972 | buf_barrier.offset = 0; |
| 7973 | buf_barrier.size = VK_WHOLE_SIZE; |
| 7974 | // Can't send buffer barrier during a render pass |
| 7975 | vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), |
| 7976 | VK_PIPELINE_STAGE_HOST_BIT, |
| 7977 | VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0, nullptr, 1, |
| 7978 | &buf_barrier, 0, nullptr); |
| 7979 | m_errorMonitor->VerifyFound(); |
| 7980 | vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle()); |
| 7981 | |
| 7982 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 7983 | "which is not less than total size"); |
| 7984 | buf_barrier.offset = 257; |
| 7985 | // Offset greater than total size |
| 7986 | vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), |
| 7987 | VK_PIPELINE_STAGE_HOST_BIT, |
| 7988 | VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0, nullptr, 1, |
| 7989 | &buf_barrier, 0, nullptr); |
| 7990 | m_errorMonitor->VerifyFound(); |
| 7991 | buf_barrier.offset = 0; |
| 7992 | |
| 7993 | m_errorMonitor->SetDesiredFailureMsg( |
| 7994 | VK_DEBUG_REPORT_ERROR_BIT_EXT, "whose sum is greater than total size"); |
| 7995 | buf_barrier.size = 257; |
| 7996 | // Size greater than total size |
| 7997 | vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), |
| 7998 | VK_PIPELINE_STAGE_HOST_BIT, |
| 7999 | VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0, nullptr, 1, |
| 8000 | &buf_barrier, 0, nullptr); |
| 8001 | m_errorMonitor->VerifyFound(); |
| 8002 | buf_barrier.size = VK_WHOLE_SIZE; |
| 8003 | |
| 8004 | m_errorMonitor->SetDesiredFailureMsg( |
| 8005 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 8006 | "Image is a depth and stencil format and thus must " |
| 8007 | "have both VK_IMAGE_ASPECT_DEPTH_BIT and " |
| 8008 | "VK_IMAGE_ASPECT_STENCIL_BIT set."); |
| 8009 | VkDepthStencilObj ds_image(m_device); |
| 8010 | ds_image.Init(m_device, 128, 128, VK_FORMAT_D24_UNORM_S8_UINT); |
| 8011 | ASSERT_TRUE(ds_image.initialized()); |
| 8012 | img_barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL; |
| 8013 | img_barrier.newLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL; |
| 8014 | img_barrier.image = ds_image.handle(); |
| 8015 | // Leave aspectMask at COLOR on purpose |
| 8016 | vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), |
| 8017 | VK_PIPELINE_STAGE_HOST_BIT, |
| 8018 | VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0, nullptr, 0, |
| 8019 | nullptr, 1, &img_barrier); |
| 8020 | m_errorMonitor->VerifyFound(); |
| 8021 | } |
| 8022 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8023 | TEST_F(VkLayerTest, IdxBufferAlignmentError) { |
Tobin Ehlis | c4c2318 | 2015-09-17 12:24:13 -0600 | [diff] [blame] | 8024 | // Bind a BeginRenderPass within an active RenderPass |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8025 | VkResult err; |
Tobin Ehlis | c4c2318 | 2015-09-17 12:24:13 -0600 | [diff] [blame] | 8026 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8027 | m_errorMonitor->SetDesiredFailureMsg( |
| 8028 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 8029 | "vkCmdBindIndexBuffer() offset (0x7) does not fall on "); |
| 8030 | |
Tobin Ehlis | c4c2318 | 2015-09-17 12:24:13 -0600 | [diff] [blame] | 8031 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 8032 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
Tobin Ehlis | c4c2318 | 2015-09-17 12:24:13 -0600 | [diff] [blame] | 8033 | uint32_t qfi = 0; |
| 8034 | VkBufferCreateInfo buffCI = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8035 | buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO; |
| 8036 | buffCI.size = 1024; |
| 8037 | buffCI.usage = VK_BUFFER_USAGE_INDEX_BUFFER_BIT; |
| 8038 | buffCI.queueFamilyIndexCount = 1; |
| 8039 | buffCI.pQueueFamilyIndices = &qfi; |
Tobin Ehlis | c4c2318 | 2015-09-17 12:24:13 -0600 | [diff] [blame] | 8040 | |
| 8041 | VkBuffer ib; |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 8042 | err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &ib); |
Tobin Ehlis | c4c2318 | 2015-09-17 12:24:13 -0600 | [diff] [blame] | 8043 | ASSERT_VK_SUCCESS(err); |
| 8044 | |
| 8045 | BeginCommandBuffer(); |
| 8046 | ASSERT_VK_SUCCESS(err); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8047 | // vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), |
| 8048 | // VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle()); |
Tobin Ehlis | c4c2318 | 2015-09-17 12:24:13 -0600 | [diff] [blame] | 8049 | // Should error before calling to driver so don't care about actual data |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8050 | vkCmdBindIndexBuffer(m_commandBuffer->GetBufferHandle(), ib, 7, |
| 8051 | VK_INDEX_TYPE_UINT16); |
Tobin Ehlis | c4c2318 | 2015-09-17 12:24:13 -0600 | [diff] [blame] | 8052 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 8053 | m_errorMonitor->VerifyFound(); |
Mike Stroyan | d1c84a5 | 2015-08-18 14:40:24 -0600 | [diff] [blame] | 8054 | |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 8055 | vkDestroyBuffer(m_device->device(), ib, NULL); |
Tobin Ehlis | c4c2318 | 2015-09-17 12:24:13 -0600 | [diff] [blame] | 8056 | } |
| 8057 | |
Mark Lobodzinski | 52a6e7d | 2016-02-25 15:09:52 -0700 | [diff] [blame] | 8058 | TEST_F(VkLayerTest, InvalidQueueFamilyIndex) { |
| 8059 | // Create an out-of-range queueFamilyIndex |
| 8060 | m_errorMonitor->SetDesiredFailureMsg( |
| 8061 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Dustin Graves | de62853 | 2016-04-21 16:30:17 -0600 | [diff] [blame] | 8062 | "vkCreateBuffer: pCreateInfo->pQueueFamilyIndices[0] (777) must be one " |
| 8063 | "of the indices specified when the device was created, via the " |
| 8064 | "VkDeviceQueueCreateInfo structure."); |
Mark Lobodzinski | 52a6e7d | 2016-02-25 15:09:52 -0700 | [diff] [blame] | 8065 | |
| 8066 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 8067 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 8068 | VkBufferCreateInfo buffCI = {}; |
| 8069 | buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO; |
| 8070 | buffCI.size = 1024; |
| 8071 | buffCI.usage = VK_BUFFER_USAGE_INDEX_BUFFER_BIT; |
| 8072 | buffCI.queueFamilyIndexCount = 1; |
| 8073 | // Introduce failure by specifying invalid queue_family_index |
| 8074 | uint32_t qfi = 777; |
| 8075 | buffCI.pQueueFamilyIndices = &qfi; |
Tobin Ehlis | 24aab04 | 2016-03-24 10:54:18 -0600 | [diff] [blame] | 8076 | buffCI.sharingMode = VK_SHARING_MODE_CONCURRENT; // qfi only matters in CONCURRENT mode |
Mark Lobodzinski | 52a6e7d | 2016-02-25 15:09:52 -0700 | [diff] [blame] | 8077 | |
| 8078 | VkBuffer ib; |
| 8079 | vkCreateBuffer(m_device->device(), &buffCI, NULL, &ib); |
| 8080 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 8081 | m_errorMonitor->VerifyFound(); |
Tony Barbour | df4c004 | 2016-06-01 15:55:43 -0600 | [diff] [blame] | 8082 | vkDestroyBuffer(m_device->device(), ib, NULL); |
Mark Lobodzinski | 52a6e7d | 2016-02-25 15:09:52 -0700 | [diff] [blame] | 8083 | } |
| 8084 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8085 | TEST_F(VkLayerTest, ExecuteCommandsPrimaryCB) { |
| 8086 | // Attempt vkCmdExecuteCommands w/ a primary cmd buffer (should only be |
| 8087 | // secondary) |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 8088 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8089 | m_errorMonitor->SetDesiredFailureMsg( |
| 8090 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 8091 | "vkCmdExecuteCommands() called w/ Primary Cmd Buffer "); |
Tobin Ehlis | 4b34ddc | 2015-09-17 14:18:16 -0600 | [diff] [blame] | 8092 | |
| 8093 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 8094 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
Tobin Ehlis | 4b34ddc | 2015-09-17 14:18:16 -0600 | [diff] [blame] | 8095 | |
| 8096 | BeginCommandBuffer(); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8097 | // ASSERT_VK_SUCCESS(err); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 8098 | VkCommandBuffer primCB = m_commandBuffer->GetBufferHandle(); |
| 8099 | vkCmdExecuteCommands(m_commandBuffer->GetBufferHandle(), 1, &primCB); |
Tobin Ehlis | 4b34ddc | 2015-09-17 14:18:16 -0600 | [diff] [blame] | 8100 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 8101 | m_errorMonitor->VerifyFound(); |
Tobin Ehlis | 4b34ddc | 2015-09-17 14:18:16 -0600 | [diff] [blame] | 8102 | } |
| 8103 | |
Tobin Ehlis | 17826bd | 2016-05-25 11:12:50 -0600 | [diff] [blame] | 8104 | TEST_F(VkLayerTest, DSUsageBitsErrors) { |
| 8105 | TEST_DESCRIPTION("Attempt to update descriptor sets for images and buffers " |
| 8106 | "that do not have correct usage bits sets."); |
| 8107 | VkResult err; |
| 8108 | |
| 8109 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 8110 | VkDescriptorPoolSize ds_type_count[VK_DESCRIPTOR_TYPE_RANGE_SIZE] = {}; |
| 8111 | for (uint32_t i = 0; i < VK_DESCRIPTOR_TYPE_RANGE_SIZE; ++i) { |
| 8112 | ds_type_count[i].type = VkDescriptorType(i); |
| 8113 | ds_type_count[i].descriptorCount = 1; |
| 8114 | } |
| 8115 | VkDescriptorPoolCreateInfo ds_pool_ci = {}; |
| 8116 | ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO; |
| 8117 | ds_pool_ci.pNext = NULL; |
| 8118 | ds_pool_ci.maxSets = VK_DESCRIPTOR_TYPE_RANGE_SIZE; |
| 8119 | ds_pool_ci.poolSizeCount = VK_DESCRIPTOR_TYPE_RANGE_SIZE; |
| 8120 | ds_pool_ci.pPoolSizes = ds_type_count; |
| 8121 | |
| 8122 | VkDescriptorPool ds_pool; |
| 8123 | err = |
| 8124 | vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool); |
| 8125 | ASSERT_VK_SUCCESS(err); |
| 8126 | |
| 8127 | // Create 10 layouts where each has a single descriptor of different type |
| 8128 | VkDescriptorSetLayoutBinding dsl_binding[VK_DESCRIPTOR_TYPE_RANGE_SIZE] = |
| 8129 | {}; |
| 8130 | for (uint32_t i = 0; i < VK_DESCRIPTOR_TYPE_RANGE_SIZE; ++i) { |
| 8131 | dsl_binding[i].binding = 0; |
| 8132 | dsl_binding[i].descriptorType = VkDescriptorType(i); |
| 8133 | dsl_binding[i].descriptorCount = 1; |
| 8134 | dsl_binding[i].stageFlags = VK_SHADER_STAGE_ALL; |
| 8135 | dsl_binding[i].pImmutableSamplers = NULL; |
| 8136 | } |
| 8137 | |
| 8138 | VkDescriptorSetLayoutCreateInfo ds_layout_ci = {}; |
| 8139 | ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO; |
| 8140 | ds_layout_ci.pNext = NULL; |
| 8141 | ds_layout_ci.bindingCount = 1; |
| 8142 | VkDescriptorSetLayout ds_layouts[VK_DESCRIPTOR_TYPE_RANGE_SIZE]; |
| 8143 | for (uint32_t i = 0; i < VK_DESCRIPTOR_TYPE_RANGE_SIZE; ++i) { |
| 8144 | ds_layout_ci.pBindings = dsl_binding + i; |
| 8145 | err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, |
| 8146 | NULL, ds_layouts + i); |
| 8147 | ASSERT_VK_SUCCESS(err); |
| 8148 | } |
| 8149 | VkDescriptorSet descriptor_sets[VK_DESCRIPTOR_TYPE_RANGE_SIZE] = {}; |
| 8150 | VkDescriptorSetAllocateInfo alloc_info = {}; |
| 8151 | alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO; |
| 8152 | alloc_info.descriptorSetCount = VK_DESCRIPTOR_TYPE_RANGE_SIZE; |
| 8153 | alloc_info.descriptorPool = ds_pool; |
| 8154 | alloc_info.pSetLayouts = ds_layouts; |
| 8155 | err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, |
| 8156 | descriptor_sets); |
| 8157 | ASSERT_VK_SUCCESS(err); |
| 8158 | |
| 8159 | // Create a buffer & bufferView to be used for invalid updates |
| 8160 | VkBufferCreateInfo buff_ci = {}; |
| 8161 | buff_ci.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO; |
| 8162 | // This usage is not valid for any descriptor type |
| 8163 | buff_ci.usage = VK_BUFFER_USAGE_TRANSFER_SRC_BIT; |
| 8164 | buff_ci.size = 256; |
| 8165 | buff_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE; |
| 8166 | VkBuffer buffer; |
| 8167 | err = vkCreateBuffer(m_device->device(), &buff_ci, NULL, &buffer); |
| 8168 | ASSERT_VK_SUCCESS(err); |
| 8169 | |
| 8170 | VkBufferViewCreateInfo buff_view_ci = {}; |
| 8171 | buff_view_ci.sType = VK_STRUCTURE_TYPE_BUFFER_VIEW_CREATE_INFO; |
| 8172 | buff_view_ci.buffer = buffer; |
| 8173 | buff_view_ci.format = VK_FORMAT_R8_UNORM; |
| 8174 | buff_view_ci.range = VK_WHOLE_SIZE; |
| 8175 | VkBufferView buff_view; |
| 8176 | err = |
| 8177 | vkCreateBufferView(m_device->device(), &buff_view_ci, NULL, &buff_view); |
| 8178 | ASSERT_VK_SUCCESS(err); |
| 8179 | |
| 8180 | // Create an image to be used for invalid updates |
| 8181 | VkImageCreateInfo image_ci = {}; |
| 8182 | image_ci.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO; |
| 8183 | image_ci.imageType = VK_IMAGE_TYPE_2D; |
| 8184 | image_ci.format = VK_FORMAT_R8G8B8A8_UNORM; |
| 8185 | image_ci.extent.width = 64; |
| 8186 | image_ci.extent.height = 64; |
| 8187 | image_ci.extent.depth = 1; |
| 8188 | image_ci.mipLevels = 1; |
| 8189 | image_ci.arrayLayers = 1; |
| 8190 | image_ci.samples = VK_SAMPLE_COUNT_1_BIT; |
| 8191 | image_ci.tiling = VK_IMAGE_TILING_LINEAR; |
| 8192 | image_ci.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED; |
| 8193 | // This usage is not valid for any descriptor type |
| 8194 | image_ci.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT; |
| 8195 | image_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE; |
| 8196 | VkImage image; |
| 8197 | err = vkCreateImage(m_device->device(), &image_ci, NULL, &image); |
| 8198 | ASSERT_VK_SUCCESS(err); |
| 8199 | // Bind memory to image |
| 8200 | VkMemoryRequirements mem_reqs; |
| 8201 | VkDeviceMemory image_mem; |
| 8202 | bool pass; |
| 8203 | VkMemoryAllocateInfo mem_alloc = {}; |
| 8204 | mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO; |
| 8205 | mem_alloc.pNext = NULL; |
| 8206 | mem_alloc.allocationSize = 0; |
| 8207 | mem_alloc.memoryTypeIndex = 0; |
| 8208 | vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs); |
| 8209 | mem_alloc.allocationSize = mem_reqs.size; |
| 8210 | pass = |
| 8211 | m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0); |
| 8212 | ASSERT_TRUE(pass); |
| 8213 | err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &image_mem); |
| 8214 | ASSERT_VK_SUCCESS(err); |
| 8215 | err = vkBindImageMemory(m_device->device(), image, image_mem, 0); |
| 8216 | ASSERT_VK_SUCCESS(err); |
| 8217 | // Now create view for image |
| 8218 | VkImageViewCreateInfo image_view_ci = {}; |
| 8219 | image_view_ci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO; |
| 8220 | image_view_ci.image = image; |
| 8221 | image_view_ci.format = VK_FORMAT_R8G8B8A8_UNORM; |
| 8222 | image_view_ci.viewType = VK_IMAGE_VIEW_TYPE_2D; |
| 8223 | image_view_ci.subresourceRange.layerCount = 1; |
| 8224 | image_view_ci.subresourceRange.baseArrayLayer = 0; |
| 8225 | image_view_ci.subresourceRange.levelCount = 1; |
| 8226 | image_view_ci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; |
| 8227 | VkImageView image_view; |
| 8228 | err = vkCreateImageView(m_device->device(), &image_view_ci, NULL, |
| 8229 | &image_view); |
| 8230 | ASSERT_VK_SUCCESS(err); |
| 8231 | |
| 8232 | VkDescriptorBufferInfo buff_info = {}; |
| 8233 | buff_info.buffer = buffer; |
| 8234 | VkDescriptorImageInfo img_info = {}; |
| 8235 | img_info.imageView = image_view; |
| 8236 | VkWriteDescriptorSet descriptor_write = {}; |
| 8237 | descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET; |
| 8238 | descriptor_write.dstBinding = 0; |
| 8239 | descriptor_write.descriptorCount = 1; |
| 8240 | descriptor_write.pTexelBufferView = &buff_view; |
| 8241 | descriptor_write.pBufferInfo = &buff_info; |
| 8242 | descriptor_write.pImageInfo = &img_info; |
| 8243 | |
| 8244 | // These error messages align with VkDescriptorType struct |
| 8245 | const char *error_msgs[] = { |
| 8246 | "", // placeholder, no error for SAMPLER descriptor |
| 8247 | " does not have VK_IMAGE_USAGE_SAMPLED_BIT set.", |
| 8248 | " does not have VK_IMAGE_USAGE_SAMPLED_BIT set.", |
| 8249 | " does not have VK_IMAGE_USAGE_STORAGE_BIT set.", |
| 8250 | " does not have VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT set.", |
| 8251 | " does not have VK_BUFFER_USAGE_STORAGE_TEXEL_BUFFER_BIT set.", |
| 8252 | " does not have VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT set.", |
| 8253 | " does not have VK_BUFFER_USAGE_STORAGE_BUFFER_BIT set.", |
| 8254 | " does not have VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT set.", |
| 8255 | " does not have VK_BUFFER_USAGE_STORAGE_BUFFER_BIT set.", |
| 8256 | " does not have VK_IMAGE_USAGE_INPUT_ATTACHMENT_BIT set."}; |
| 8257 | // Start loop at 1 as SAMPLER desc type has no usage bit error |
| 8258 | for (uint32_t i = 1; i < VK_DESCRIPTOR_TYPE_RANGE_SIZE; ++i) { |
| 8259 | descriptor_write.descriptorType = VkDescriptorType(i); |
| 8260 | descriptor_write.dstSet = descriptor_sets[i]; |
| 8261 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 8262 | error_msgs[i]); |
| 8263 | |
| 8264 | vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, |
| 8265 | NULL); |
| 8266 | |
| 8267 | m_errorMonitor->VerifyFound(); |
| 8268 | vkDestroyDescriptorSetLayout(m_device->device(), ds_layouts[i], NULL); |
| 8269 | } |
| 8270 | vkDestroyDescriptorSetLayout(m_device->device(), ds_layouts[0], NULL); |
| 8271 | vkDestroyImage(m_device->device(), image, NULL); |
Tony Barbour | df4c004 | 2016-06-01 15:55:43 -0600 | [diff] [blame] | 8272 | vkFreeMemory(m_device->device(), image_mem, NULL); |
Tobin Ehlis | 17826bd | 2016-05-25 11:12:50 -0600 | [diff] [blame] | 8273 | vkDestroyImageView(m_device->device(), image_view, NULL); |
| 8274 | vkDestroyBuffer(m_device->device(), buffer, NULL); |
| 8275 | vkDestroyBufferView(m_device->device(), buff_view, NULL); |
| 8276 | vkFreeDescriptorSets(m_device->device(), ds_pool, |
| 8277 | VK_DESCRIPTOR_TYPE_RANGE_SIZE, descriptor_sets); |
| 8278 | vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL); |
| 8279 | } |
| 8280 | |
Tobin Ehlis | 2fc296b | 2016-06-15 14:05:27 -0600 | [diff] [blame] | 8281 | TEST_F(VkLayerTest, DSAspectBitsErrors) { |
| 8282 | // TODO : Initially only catching case where DEPTH & STENCIL aspect bits |
| 8283 | // are set, but could expand this test to hit more cases. |
| 8284 | TEST_DESCRIPTION("Attempt to update descriptor sets for images " |
| 8285 | "that do not have correct aspect bits sets."); |
| 8286 | VkResult err; |
| 8287 | |
| 8288 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 8289 | VkDescriptorPoolSize ds_type_count = {}; |
| 8290 | ds_type_count.type = VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT; |
| 8291 | ds_type_count.descriptorCount = 1; |
| 8292 | |
| 8293 | VkDescriptorPoolCreateInfo ds_pool_ci = {}; |
| 8294 | ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO; |
| 8295 | ds_pool_ci.pNext = NULL; |
| 8296 | ds_pool_ci.maxSets = 5; |
| 8297 | ds_pool_ci.poolSizeCount = 1; |
| 8298 | ds_pool_ci.pPoolSizes = &ds_type_count; |
| 8299 | |
| 8300 | VkDescriptorPool ds_pool; |
| 8301 | err = |
| 8302 | vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool); |
| 8303 | ASSERT_VK_SUCCESS(err); |
| 8304 | |
| 8305 | VkDescriptorSetLayoutBinding dsl_binding = {}; |
| 8306 | dsl_binding.binding = 0; |
| 8307 | dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT; |
| 8308 | dsl_binding.descriptorCount = 1; |
| 8309 | dsl_binding.stageFlags = VK_SHADER_STAGE_ALL; |
| 8310 | dsl_binding.pImmutableSamplers = NULL; |
| 8311 | |
| 8312 | VkDescriptorSetLayoutCreateInfo ds_layout_ci = {}; |
| 8313 | ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO; |
| 8314 | ds_layout_ci.pNext = NULL; |
| 8315 | ds_layout_ci.bindingCount = 1; |
| 8316 | ds_layout_ci.pBindings = &dsl_binding; |
| 8317 | VkDescriptorSetLayout ds_layout; |
| 8318 | err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, |
| 8319 | &ds_layout); |
| 8320 | ASSERT_VK_SUCCESS(err); |
| 8321 | |
| 8322 | VkDescriptorSet descriptor_set = {}; |
| 8323 | VkDescriptorSetAllocateInfo alloc_info = {}; |
| 8324 | alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO; |
| 8325 | alloc_info.descriptorSetCount = 1; |
| 8326 | alloc_info.descriptorPool = ds_pool; |
| 8327 | alloc_info.pSetLayouts = &ds_layout; |
| 8328 | err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, |
| 8329 | &descriptor_set); |
| 8330 | ASSERT_VK_SUCCESS(err); |
| 8331 | |
| 8332 | // Create an image to be used for invalid updates |
| 8333 | VkImageCreateInfo image_ci = {}; |
| 8334 | image_ci.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO; |
| 8335 | image_ci.imageType = VK_IMAGE_TYPE_2D; |
| 8336 | image_ci.format = VK_FORMAT_D24_UNORM_S8_UINT; |
| 8337 | image_ci.extent.width = 64; |
| 8338 | image_ci.extent.height = 64; |
| 8339 | image_ci.extent.depth = 1; |
| 8340 | image_ci.mipLevels = 1; |
| 8341 | image_ci.arrayLayers = 1; |
| 8342 | image_ci.samples = VK_SAMPLE_COUNT_1_BIT; |
| 8343 | image_ci.tiling = VK_IMAGE_TILING_LINEAR; |
| 8344 | image_ci.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED; |
| 8345 | image_ci.usage = VK_IMAGE_USAGE_SAMPLED_BIT; |
| 8346 | image_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE; |
| 8347 | VkImage image; |
| 8348 | err = vkCreateImage(m_device->device(), &image_ci, NULL, &image); |
| 8349 | ASSERT_VK_SUCCESS(err); |
| 8350 | // Bind memory to image |
| 8351 | VkMemoryRequirements mem_reqs; |
| 8352 | VkDeviceMemory image_mem; |
| 8353 | bool pass; |
| 8354 | VkMemoryAllocateInfo mem_alloc = {}; |
| 8355 | mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO; |
| 8356 | mem_alloc.pNext = NULL; |
| 8357 | mem_alloc.allocationSize = 0; |
| 8358 | mem_alloc.memoryTypeIndex = 0; |
| 8359 | vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs); |
| 8360 | mem_alloc.allocationSize = mem_reqs.size; |
| 8361 | pass = |
| 8362 | m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0); |
| 8363 | ASSERT_TRUE(pass); |
| 8364 | err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &image_mem); |
| 8365 | ASSERT_VK_SUCCESS(err); |
| 8366 | err = vkBindImageMemory(m_device->device(), image, image_mem, 0); |
| 8367 | ASSERT_VK_SUCCESS(err); |
| 8368 | // Now create view for image |
| 8369 | VkImageViewCreateInfo image_view_ci = {}; |
| 8370 | image_view_ci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO; |
| 8371 | image_view_ci.image = image; |
| 8372 | image_view_ci.format = VK_FORMAT_D24_UNORM_S8_UINT; |
| 8373 | image_view_ci.viewType = VK_IMAGE_VIEW_TYPE_2D; |
| 8374 | image_view_ci.subresourceRange.layerCount = 1; |
| 8375 | image_view_ci.subresourceRange.baseArrayLayer = 0; |
| 8376 | image_view_ci.subresourceRange.levelCount = 1; |
| 8377 | // Setting both depth & stencil aspect bits is illegal for descriptor |
| 8378 | image_view_ci.subresourceRange.aspectMask = |
| 8379 | VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT; |
| 8380 | |
| 8381 | VkImageView image_view; |
| 8382 | err = vkCreateImageView(m_device->device(), &image_view_ci, NULL, |
| 8383 | &image_view); |
| 8384 | ASSERT_VK_SUCCESS(err); |
| 8385 | |
| 8386 | VkDescriptorImageInfo img_info = {}; |
| 8387 | img_info.imageView = image_view; |
| 8388 | VkWriteDescriptorSet descriptor_write = {}; |
| 8389 | descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET; |
| 8390 | descriptor_write.dstBinding = 0; |
| 8391 | descriptor_write.descriptorCount = 1; |
| 8392 | descriptor_write.pTexelBufferView = NULL; |
| 8393 | descriptor_write.pBufferInfo = NULL; |
| 8394 | descriptor_write.pImageInfo = &img_info; |
| 8395 | descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT; |
| 8396 | descriptor_write.dstSet = descriptor_set; |
| 8397 | const char *error_msg = " please only set either VK_IMAGE_ASPECT_DEPTH_BIT " |
| 8398 | "or VK_IMAGE_ASPECT_STENCIL_BIT "; |
| 8399 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 8400 | error_msg); |
| 8401 | |
| 8402 | vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL); |
| 8403 | |
| 8404 | m_errorMonitor->VerifyFound(); |
| 8405 | vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL); |
| 8406 | vkDestroyImage(m_device->device(), image, NULL); |
| 8407 | vkFreeMemory(m_device->device(), image_mem, NULL); |
| 8408 | vkDestroyImageView(m_device->device(), image_view, NULL); |
| 8409 | vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptor_set); |
| 8410 | vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL); |
| 8411 | } |
| 8412 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8413 | TEST_F(VkLayerTest, DSTypeMismatch) { |
Tobin Ehlis | 49eb23d | 2015-05-22 12:38:55 -0600 | [diff] [blame] | 8414 | // Create DS w/ layout of one type and attempt Update w/ mis-matched type |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8415 | VkResult err; |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 8416 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8417 | m_errorMonitor->SetDesiredFailureMsg( |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 8418 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 8419 | " binding #0 with type VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER but update " |
| 8420 | "type is VK_DESCRIPTOR_TYPE_SAMPLER"); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 8421 | |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 8422 | ASSERT_NO_FATAL_FAILURE(InitState()); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8423 | // VkDescriptorSetObj descriptorSet(m_device); |
Chia-I Wu | 1b99bb2 | 2015-10-27 19:25:11 +0800 | [diff] [blame] | 8424 | VkDescriptorPoolSize ds_type_count = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8425 | ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 8426 | ds_type_count.descriptorCount = 1; |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 8427 | |
| 8428 | VkDescriptorPoolCreateInfo ds_pool_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8429 | ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO; |
| 8430 | ds_pool_ci.pNext = NULL; |
| 8431 | ds_pool_ci.maxSets = 1; |
| 8432 | ds_pool_ci.poolSizeCount = 1; |
| 8433 | ds_pool_ci.pPoolSizes = &ds_type_count; |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 8434 | |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 8435 | VkDescriptorPool ds_pool; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8436 | err = |
| 8437 | vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool); |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 8438 | ASSERT_VK_SUCCESS(err); |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 8439 | VkDescriptorSetLayoutBinding dsl_binding = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8440 | dsl_binding.binding = 0; |
| 8441 | dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 8442 | dsl_binding.descriptorCount = 1; |
| 8443 | dsl_binding.stageFlags = VK_SHADER_STAGE_ALL; |
| 8444 | dsl_binding.pImmutableSamplers = NULL; |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 8445 | |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 8446 | VkDescriptorSetLayoutCreateInfo ds_layout_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8447 | ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO; |
| 8448 | ds_layout_ci.pNext = NULL; |
| 8449 | ds_layout_ci.bindingCount = 1; |
| 8450 | ds_layout_ci.pBindings = &dsl_binding; |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 8451 | |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 8452 | VkDescriptorSetLayout ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8453 | err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, |
| 8454 | &ds_layout); |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 8455 | ASSERT_VK_SUCCESS(err); |
| 8456 | |
| 8457 | VkDescriptorSet descriptorSet; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 8458 | VkDescriptorSetAllocateInfo alloc_info = {}; |
Chia-I Wu | 00ce540 | 2015-11-10 16:21:09 +0800 | [diff] [blame] | 8459 | alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO; |
Jon Ashburn | f19916e | 2016-01-11 13:12:43 -0700 | [diff] [blame] | 8460 | alloc_info.descriptorSetCount = 1; |
Courtney Goeltzenleuchter | bee18a9 | 2015-10-23 14:21:05 -0600 | [diff] [blame] | 8461 | alloc_info.descriptorPool = ds_pool; |
| 8462 | alloc_info.pSetLayouts = &ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8463 | err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, |
| 8464 | &descriptorSet); |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 8465 | ASSERT_VK_SUCCESS(err); |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 8466 | |
Tobin Ehlis | 30db8f8 | 2016-05-05 08:19:48 -0600 | [diff] [blame] | 8467 | VkSamplerCreateInfo sampler_ci = {}; |
| 8468 | sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO; |
| 8469 | sampler_ci.pNext = NULL; |
| 8470 | sampler_ci.magFilter = VK_FILTER_NEAREST; |
| 8471 | sampler_ci.minFilter = VK_FILTER_NEAREST; |
| 8472 | sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST; |
| 8473 | sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE; |
| 8474 | sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE; |
| 8475 | sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE; |
| 8476 | sampler_ci.mipLodBias = 1.0; |
| 8477 | sampler_ci.anisotropyEnable = VK_FALSE; |
| 8478 | sampler_ci.maxAnisotropy = 1; |
| 8479 | sampler_ci.compareEnable = VK_FALSE; |
| 8480 | sampler_ci.compareOp = VK_COMPARE_OP_NEVER; |
| 8481 | sampler_ci.minLod = 1.0; |
| 8482 | sampler_ci.maxLod = 1.0; |
| 8483 | sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE; |
| 8484 | sampler_ci.unnormalizedCoordinates = VK_FALSE; |
| 8485 | VkSampler sampler; |
| 8486 | err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler); |
| 8487 | ASSERT_VK_SUCCESS(err); |
| 8488 | |
| 8489 | VkDescriptorImageInfo info = {}; |
| 8490 | info.sampler = sampler; |
Chia-I Wu | 9d00ed7 | 2015-05-25 16:27:55 +0800 | [diff] [blame] | 8491 | |
| 8492 | VkWriteDescriptorSet descriptor_write; |
| 8493 | memset(&descriptor_write, 0, sizeof(descriptor_write)); |
| 8494 | descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 8495 | descriptor_write.dstSet = descriptorSet; |
Chia-I Wu | d50a7d7 | 2015-10-26 20:48:51 +0800 | [diff] [blame] | 8496 | descriptor_write.descriptorCount = 1; |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 8497 | // This is a mismatched type for the layout which expects BUFFER |
Chia-I Wu | 9d00ed7 | 2015-05-25 16:27:55 +0800 | [diff] [blame] | 8498 | descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER; |
Courtney Goeltzenleuchter | 4cb6d92 | 2015-10-23 13:38:14 -0600 | [diff] [blame] | 8499 | descriptor_write.pImageInfo = &info; |
Chia-I Wu | 9d00ed7 | 2015-05-25 16:27:55 +0800 | [diff] [blame] | 8500 | |
| 8501 | vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL); |
| 8502 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 8503 | m_errorMonitor->VerifyFound(); |
Mike Stroyan | d1c84a5 | 2015-08-18 14:40:24 -0600 | [diff] [blame] | 8504 | |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 8505 | vkDestroySampler(m_device->device(), sampler, NULL); |
| 8506 | vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL); |
| 8507 | vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL); |
Tobin Ehlis | 49eb23d | 2015-05-22 12:38:55 -0600 | [diff] [blame] | 8508 | } |
| 8509 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8510 | TEST_F(VkLayerTest, DSUpdateOutOfBounds) { |
Tobin Ehlis | 49eb23d | 2015-05-22 12:38:55 -0600 | [diff] [blame] | 8511 | // For overlapping Update, have arrayIndex exceed that of layout |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8512 | VkResult err; |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 8513 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8514 | m_errorMonitor->SetDesiredFailureMsg( |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 8515 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 8516 | " binding #0 with 1 total descriptors but update of 1 descriptors " |
| 8517 | "starting at binding offset of 0 combined with update array element " |
| 8518 | "offset of 1 oversteps the size of this descriptor set."); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 8519 | |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 8520 | ASSERT_NO_FATAL_FAILURE(InitState()); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8521 | // VkDescriptorSetObj descriptorSet(m_device); |
Chia-I Wu | 1b99bb2 | 2015-10-27 19:25:11 +0800 | [diff] [blame] | 8522 | VkDescriptorPoolSize ds_type_count = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8523 | ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 8524 | ds_type_count.descriptorCount = 1; |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 8525 | |
| 8526 | VkDescriptorPoolCreateInfo ds_pool_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8527 | ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO; |
| 8528 | ds_pool_ci.pNext = NULL; |
| 8529 | ds_pool_ci.maxSets = 1; |
| 8530 | ds_pool_ci.poolSizeCount = 1; |
| 8531 | ds_pool_ci.pPoolSizes = &ds_type_count; |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 8532 | |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 8533 | VkDescriptorPool ds_pool; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8534 | err = |
| 8535 | vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool); |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 8536 | ASSERT_VK_SUCCESS(err); |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 8537 | |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 8538 | VkDescriptorSetLayoutBinding dsl_binding = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8539 | dsl_binding.binding = 0; |
| 8540 | dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 8541 | dsl_binding.descriptorCount = 1; |
| 8542 | dsl_binding.stageFlags = VK_SHADER_STAGE_ALL; |
| 8543 | dsl_binding.pImmutableSamplers = NULL; |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 8544 | |
| 8545 | VkDescriptorSetLayoutCreateInfo ds_layout_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8546 | ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO; |
| 8547 | ds_layout_ci.pNext = NULL; |
| 8548 | ds_layout_ci.bindingCount = 1; |
| 8549 | ds_layout_ci.pBindings = &dsl_binding; |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 8550 | |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 8551 | VkDescriptorSetLayout ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8552 | err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, |
| 8553 | &ds_layout); |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 8554 | ASSERT_VK_SUCCESS(err); |
| 8555 | |
| 8556 | VkDescriptorSet descriptorSet; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 8557 | VkDescriptorSetAllocateInfo alloc_info = {}; |
Chia-I Wu | 00ce540 | 2015-11-10 16:21:09 +0800 | [diff] [blame] | 8558 | alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO; |
Jon Ashburn | f19916e | 2016-01-11 13:12:43 -0700 | [diff] [blame] | 8559 | alloc_info.descriptorSetCount = 1; |
Courtney Goeltzenleuchter | bee18a9 | 2015-10-23 14:21:05 -0600 | [diff] [blame] | 8560 | alloc_info.descriptorPool = ds_pool; |
| 8561 | alloc_info.pSetLayouts = &ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8562 | err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, |
| 8563 | &descriptorSet); |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 8564 | ASSERT_VK_SUCCESS(err); |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 8565 | |
Tobin Ehlis | 30db8f8 | 2016-05-05 08:19:48 -0600 | [diff] [blame] | 8566 | // Correctly update descriptor to avoid "NOT_UPDATED" error |
| 8567 | VkDescriptorBufferInfo buff_info = {}; |
| 8568 | buff_info.buffer = |
| 8569 | VkBuffer(0); // Don't care about buffer handle for this test |
| 8570 | buff_info.offset = 0; |
| 8571 | buff_info.range = 1024; |
Chia-I Wu | 9d00ed7 | 2015-05-25 16:27:55 +0800 | [diff] [blame] | 8572 | |
| 8573 | VkWriteDescriptorSet descriptor_write; |
| 8574 | memset(&descriptor_write, 0, sizeof(descriptor_write)); |
| 8575 | descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 8576 | descriptor_write.dstSet = descriptorSet; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8577 | descriptor_write.dstArrayElement = |
| 8578 | 1; /* This index out of bounds for the update */ |
Chia-I Wu | d50a7d7 | 2015-10-26 20:48:51 +0800 | [diff] [blame] | 8579 | descriptor_write.descriptorCount = 1; |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 8580 | descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 8581 | descriptor_write.pBufferInfo = &buff_info; |
Chia-I Wu | 9d00ed7 | 2015-05-25 16:27:55 +0800 | [diff] [blame] | 8582 | |
| 8583 | vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL); |
| 8584 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 8585 | m_errorMonitor->VerifyFound(); |
Mike Stroyan | d1c84a5 | 2015-08-18 14:40:24 -0600 | [diff] [blame] | 8586 | |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 8587 | vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL); |
| 8588 | vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL); |
Tobin Ehlis | 49eb23d | 2015-05-22 12:38:55 -0600 | [diff] [blame] | 8589 | } |
| 8590 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8591 | TEST_F(VkLayerTest, InvalidDSUpdateIndex) { |
| 8592 | // Create layout w/ count of 1 and attempt update to that layout w/ binding |
| 8593 | // index 2 |
| 8594 | VkResult err; |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 8595 | |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 8596 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 8597 | " does not have binding 2."); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 8598 | |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 8599 | ASSERT_NO_FATAL_FAILURE(InitState()); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8600 | // VkDescriptorSetObj descriptorSet(m_device); |
Chia-I Wu | 1b99bb2 | 2015-10-27 19:25:11 +0800 | [diff] [blame] | 8601 | VkDescriptorPoolSize ds_type_count = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8602 | ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 8603 | ds_type_count.descriptorCount = 1; |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 8604 | |
| 8605 | VkDescriptorPoolCreateInfo ds_pool_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8606 | ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO; |
| 8607 | ds_pool_ci.pNext = NULL; |
| 8608 | ds_pool_ci.maxSets = 1; |
| 8609 | ds_pool_ci.poolSizeCount = 1; |
| 8610 | ds_pool_ci.pPoolSizes = &ds_type_count; |
Courtney Goeltzenleuchter | fe908d3 | 2015-09-16 16:12:45 -0600 | [diff] [blame] | 8611 | |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 8612 | VkDescriptorPool ds_pool; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8613 | err = |
| 8614 | vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool); |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 8615 | ASSERT_VK_SUCCESS(err); |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 8616 | |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 8617 | VkDescriptorSetLayoutBinding dsl_binding = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8618 | dsl_binding.binding = 0; |
| 8619 | dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 8620 | dsl_binding.descriptorCount = 1; |
| 8621 | dsl_binding.stageFlags = VK_SHADER_STAGE_ALL; |
| 8622 | dsl_binding.pImmutableSamplers = NULL; |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 8623 | |
| 8624 | VkDescriptorSetLayoutCreateInfo ds_layout_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8625 | ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO; |
| 8626 | ds_layout_ci.pNext = NULL; |
| 8627 | ds_layout_ci.bindingCount = 1; |
| 8628 | ds_layout_ci.pBindings = &dsl_binding; |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 8629 | VkDescriptorSetLayout ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8630 | err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, |
| 8631 | &ds_layout); |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 8632 | ASSERT_VK_SUCCESS(err); |
| 8633 | |
| 8634 | VkDescriptorSet descriptorSet; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 8635 | VkDescriptorSetAllocateInfo alloc_info = {}; |
Chia-I Wu | 00ce540 | 2015-11-10 16:21:09 +0800 | [diff] [blame] | 8636 | alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO; |
Jon Ashburn | f19916e | 2016-01-11 13:12:43 -0700 | [diff] [blame] | 8637 | alloc_info.descriptorSetCount = 1; |
Courtney Goeltzenleuchter | bee18a9 | 2015-10-23 14:21:05 -0600 | [diff] [blame] | 8638 | alloc_info.descriptorPool = ds_pool; |
| 8639 | alloc_info.pSetLayouts = &ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8640 | err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, |
| 8641 | &descriptorSet); |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 8642 | ASSERT_VK_SUCCESS(err); |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 8643 | |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 8644 | VkSamplerCreateInfo sampler_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8645 | sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO; |
| 8646 | sampler_ci.pNext = NULL; |
| 8647 | sampler_ci.magFilter = VK_FILTER_NEAREST; |
| 8648 | sampler_ci.minFilter = VK_FILTER_NEAREST; |
| 8649 | sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST; |
| 8650 | sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE; |
| 8651 | sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE; |
| 8652 | sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE; |
| 8653 | sampler_ci.mipLodBias = 1.0; |
| 8654 | sampler_ci.anisotropyEnable = VK_FALSE; |
| 8655 | sampler_ci.maxAnisotropy = 1; |
| 8656 | sampler_ci.compareEnable = VK_FALSE; |
| 8657 | sampler_ci.compareOp = VK_COMPARE_OP_NEVER; |
| 8658 | sampler_ci.minLod = 1.0; |
| 8659 | sampler_ci.maxLod = 1.0; |
| 8660 | sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE; |
| 8661 | sampler_ci.unnormalizedCoordinates = VK_FALSE; |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 8662 | |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 8663 | VkSampler sampler; |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 8664 | err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler); |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 8665 | ASSERT_VK_SUCCESS(err); |
Chia-I Wu | 9d00ed7 | 2015-05-25 16:27:55 +0800 | [diff] [blame] | 8666 | |
Courtney Goeltzenleuchter | 4cb6d92 | 2015-10-23 13:38:14 -0600 | [diff] [blame] | 8667 | VkDescriptorImageInfo info = {}; |
| 8668 | info.sampler = sampler; |
Chia-I Wu | 9d00ed7 | 2015-05-25 16:27:55 +0800 | [diff] [blame] | 8669 | |
| 8670 | VkWriteDescriptorSet descriptor_write; |
| 8671 | memset(&descriptor_write, 0, sizeof(descriptor_write)); |
| 8672 | descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 8673 | descriptor_write.dstSet = descriptorSet; |
| 8674 | descriptor_write.dstBinding = 2; |
Chia-I Wu | d50a7d7 | 2015-10-26 20:48:51 +0800 | [diff] [blame] | 8675 | descriptor_write.descriptorCount = 1; |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 8676 | // This is the wrong type, but out of bounds will be flagged first |
Chia-I Wu | 9d00ed7 | 2015-05-25 16:27:55 +0800 | [diff] [blame] | 8677 | descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER; |
Courtney Goeltzenleuchter | 4cb6d92 | 2015-10-23 13:38:14 -0600 | [diff] [blame] | 8678 | descriptor_write.pImageInfo = &info; |
Chia-I Wu | 9d00ed7 | 2015-05-25 16:27:55 +0800 | [diff] [blame] | 8679 | |
| 8680 | vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL); |
| 8681 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 8682 | m_errorMonitor->VerifyFound(); |
Mike Stroyan | d1c84a5 | 2015-08-18 14:40:24 -0600 | [diff] [blame] | 8683 | |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 8684 | vkDestroySampler(m_device->device(), sampler, NULL); |
| 8685 | vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL); |
| 8686 | vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL); |
Tobin Ehlis | 49eb23d | 2015-05-22 12:38:55 -0600 | [diff] [blame] | 8687 | } |
| 8688 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8689 | TEST_F(VkLayerTest, InvalidDSUpdateStruct) { |
| 8690 | // Call UpdateDS w/ struct type other than valid VK_STRUCTUR_TYPE_UPDATE_* |
| 8691 | // types |
| 8692 | VkResult err; |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 8693 | |
Courtney Goeltzenleuchter | 7415d5a | 2015-12-09 15:48:16 -0700 | [diff] [blame] | 8694 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Tobin Ehlis | 660bcdc | 2016-05-17 10:39:46 -0600 | [diff] [blame] | 8695 | ".sType must be VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET"); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 8696 | |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 8697 | ASSERT_NO_FATAL_FAILURE(InitState()); |
Mark Lobodzinski | 209b529 | 2015-09-17 09:44:05 -0600 | [diff] [blame] | 8698 | |
Chia-I Wu | 1b99bb2 | 2015-10-27 19:25:11 +0800 | [diff] [blame] | 8699 | VkDescriptorPoolSize ds_type_count = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8700 | ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 8701 | ds_type_count.descriptorCount = 1; |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 8702 | |
| 8703 | VkDescriptorPoolCreateInfo ds_pool_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8704 | ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO; |
| 8705 | ds_pool_ci.pNext = NULL; |
| 8706 | ds_pool_ci.maxSets = 1; |
| 8707 | ds_pool_ci.poolSizeCount = 1; |
| 8708 | ds_pool_ci.pPoolSizes = &ds_type_count; |
Courtney Goeltzenleuchter | fe908d3 | 2015-09-16 16:12:45 -0600 | [diff] [blame] | 8709 | |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 8710 | VkDescriptorPool ds_pool; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8711 | err = |
| 8712 | vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool); |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 8713 | ASSERT_VK_SUCCESS(err); |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 8714 | VkDescriptorSetLayoutBinding dsl_binding = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8715 | dsl_binding.binding = 0; |
| 8716 | dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 8717 | dsl_binding.descriptorCount = 1; |
| 8718 | dsl_binding.stageFlags = VK_SHADER_STAGE_ALL; |
| 8719 | dsl_binding.pImmutableSamplers = NULL; |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 8720 | |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 8721 | VkDescriptorSetLayoutCreateInfo ds_layout_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8722 | ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO; |
| 8723 | ds_layout_ci.pNext = NULL; |
| 8724 | ds_layout_ci.bindingCount = 1; |
| 8725 | ds_layout_ci.pBindings = &dsl_binding; |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 8726 | |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 8727 | VkDescriptorSetLayout ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8728 | err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, |
| 8729 | &ds_layout); |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 8730 | ASSERT_VK_SUCCESS(err); |
| 8731 | |
| 8732 | VkDescriptorSet descriptorSet; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 8733 | VkDescriptorSetAllocateInfo alloc_info = {}; |
Chia-I Wu | 00ce540 | 2015-11-10 16:21:09 +0800 | [diff] [blame] | 8734 | alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO; |
Jon Ashburn | f19916e | 2016-01-11 13:12:43 -0700 | [diff] [blame] | 8735 | alloc_info.descriptorSetCount = 1; |
Courtney Goeltzenleuchter | bee18a9 | 2015-10-23 14:21:05 -0600 | [diff] [blame] | 8736 | alloc_info.descriptorPool = ds_pool; |
| 8737 | alloc_info.pSetLayouts = &ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8738 | err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, |
| 8739 | &descriptorSet); |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 8740 | ASSERT_VK_SUCCESS(err); |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 8741 | |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 8742 | VkSamplerCreateInfo sampler_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8743 | sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO; |
| 8744 | sampler_ci.pNext = NULL; |
| 8745 | sampler_ci.magFilter = VK_FILTER_NEAREST; |
| 8746 | sampler_ci.minFilter = VK_FILTER_NEAREST; |
| 8747 | sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST; |
| 8748 | sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE; |
| 8749 | sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE; |
| 8750 | sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE; |
| 8751 | sampler_ci.mipLodBias = 1.0; |
| 8752 | sampler_ci.anisotropyEnable = VK_FALSE; |
| 8753 | sampler_ci.maxAnisotropy = 1; |
| 8754 | sampler_ci.compareEnable = VK_FALSE; |
| 8755 | sampler_ci.compareOp = VK_COMPARE_OP_NEVER; |
| 8756 | sampler_ci.minLod = 1.0; |
| 8757 | sampler_ci.maxLod = 1.0; |
| 8758 | sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE; |
| 8759 | sampler_ci.unnormalizedCoordinates = VK_FALSE; |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 8760 | VkSampler sampler; |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 8761 | err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler); |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 8762 | ASSERT_VK_SUCCESS(err); |
Chia-I Wu | 9d00ed7 | 2015-05-25 16:27:55 +0800 | [diff] [blame] | 8763 | |
Courtney Goeltzenleuchter | 4cb6d92 | 2015-10-23 13:38:14 -0600 | [diff] [blame] | 8764 | VkDescriptorImageInfo info = {}; |
| 8765 | info.sampler = sampler; |
Chia-I Wu | 9d00ed7 | 2015-05-25 16:27:55 +0800 | [diff] [blame] | 8766 | |
| 8767 | VkWriteDescriptorSet descriptor_write; |
| 8768 | memset(&descriptor_write, 0, sizeof(descriptor_write)); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8769 | descriptor_write.sType = |
| 8770 | (VkStructureType)0x99999999; /* Intentionally broken struct type */ |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 8771 | descriptor_write.dstSet = descriptorSet; |
Chia-I Wu | d50a7d7 | 2015-10-26 20:48:51 +0800 | [diff] [blame] | 8772 | descriptor_write.descriptorCount = 1; |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 8773 | // This is the wrong type, but out of bounds will be flagged first |
Chia-I Wu | 9d00ed7 | 2015-05-25 16:27:55 +0800 | [diff] [blame] | 8774 | descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER; |
Courtney Goeltzenleuchter | 4cb6d92 | 2015-10-23 13:38:14 -0600 | [diff] [blame] | 8775 | descriptor_write.pImageInfo = &info; |
Chia-I Wu | 9d00ed7 | 2015-05-25 16:27:55 +0800 | [diff] [blame] | 8776 | |
| 8777 | vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL); |
| 8778 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 8779 | m_errorMonitor->VerifyFound(); |
Mike Stroyan | d1c84a5 | 2015-08-18 14:40:24 -0600 | [diff] [blame] | 8780 | |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 8781 | vkDestroySampler(m_device->device(), sampler, NULL); |
| 8782 | vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL); |
| 8783 | vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL); |
Tobin Ehlis | 49eb23d | 2015-05-22 12:38:55 -0600 | [diff] [blame] | 8784 | } |
| 8785 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8786 | TEST_F(VkLayerTest, SampleDescriptorUpdateError) { |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 8787 | // Create a single Sampler descriptor and send it an invalid Sampler |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8788 | VkResult err; |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 8789 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8790 | m_errorMonitor->SetDesiredFailureMsg( |
| 8791 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 8792 | "Attempted write update to sampler descriptor with invalid sampler"); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 8793 | |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 8794 | ASSERT_NO_FATAL_FAILURE(InitState()); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8795 | // TODO : Farm Descriptor setup code to helper function(s) to reduce copied |
| 8796 | // code |
Chia-I Wu | 1b99bb2 | 2015-10-27 19:25:11 +0800 | [diff] [blame] | 8797 | VkDescriptorPoolSize ds_type_count = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8798 | ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLER; |
| 8799 | ds_type_count.descriptorCount = 1; |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 8800 | |
| 8801 | VkDescriptorPoolCreateInfo ds_pool_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8802 | ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO; |
| 8803 | ds_pool_ci.pNext = NULL; |
| 8804 | ds_pool_ci.maxSets = 1; |
| 8805 | ds_pool_ci.poolSizeCount = 1; |
| 8806 | ds_pool_ci.pPoolSizes = &ds_type_count; |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 8807 | |
| 8808 | VkDescriptorPool ds_pool; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8809 | err = |
| 8810 | vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool); |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 8811 | ASSERT_VK_SUCCESS(err); |
| 8812 | |
| 8813 | VkDescriptorSetLayoutBinding dsl_binding = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8814 | dsl_binding.binding = 0; |
| 8815 | dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER; |
| 8816 | dsl_binding.descriptorCount = 1; |
| 8817 | dsl_binding.stageFlags = VK_SHADER_STAGE_ALL; |
| 8818 | dsl_binding.pImmutableSamplers = NULL; |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 8819 | |
| 8820 | VkDescriptorSetLayoutCreateInfo ds_layout_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8821 | ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO; |
| 8822 | ds_layout_ci.pNext = NULL; |
| 8823 | ds_layout_ci.bindingCount = 1; |
| 8824 | ds_layout_ci.pBindings = &dsl_binding; |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 8825 | VkDescriptorSetLayout ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8826 | err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, |
| 8827 | &ds_layout); |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 8828 | ASSERT_VK_SUCCESS(err); |
| 8829 | |
| 8830 | VkDescriptorSet descriptorSet; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 8831 | VkDescriptorSetAllocateInfo alloc_info = {}; |
Chia-I Wu | 00ce540 | 2015-11-10 16:21:09 +0800 | [diff] [blame] | 8832 | alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO; |
Jon Ashburn | f19916e | 2016-01-11 13:12:43 -0700 | [diff] [blame] | 8833 | alloc_info.descriptorSetCount = 1; |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 8834 | alloc_info.descriptorPool = ds_pool; |
| 8835 | alloc_info.pSetLayouts = &ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8836 | err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, |
| 8837 | &descriptorSet); |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 8838 | ASSERT_VK_SUCCESS(err); |
| 8839 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8840 | VkSampler sampler = |
| 8841 | (VkSampler)((size_t)0xbaadbeef); // Sampler with invalid handle |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 8842 | |
| 8843 | VkDescriptorImageInfo descriptor_info; |
| 8844 | memset(&descriptor_info, 0, sizeof(VkDescriptorImageInfo)); |
| 8845 | descriptor_info.sampler = sampler; |
| 8846 | |
| 8847 | VkWriteDescriptorSet descriptor_write; |
| 8848 | memset(&descriptor_write, 0, sizeof(descriptor_write)); |
| 8849 | descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 8850 | descriptor_write.dstSet = descriptorSet; |
| 8851 | descriptor_write.dstBinding = 0; |
Chia-I Wu | d50a7d7 | 2015-10-26 20:48:51 +0800 | [diff] [blame] | 8852 | descriptor_write.descriptorCount = 1; |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 8853 | descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER; |
| 8854 | descriptor_write.pImageInfo = &descriptor_info; |
| 8855 | |
| 8856 | vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL); |
| 8857 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 8858 | m_errorMonitor->VerifyFound(); |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 8859 | |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 8860 | vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL); |
| 8861 | vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL); |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 8862 | } |
| 8863 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8864 | TEST_F(VkLayerTest, ImageViewDescriptorUpdateError) { |
| 8865 | // Create a single combined Image/Sampler descriptor and send it an invalid |
| 8866 | // imageView |
| 8867 | VkResult err; |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 8868 | |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 8869 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 8870 | "Attempted write update to combined " |
| 8871 | "image sampler descriptor failed due " |
Tobin Ehlis | 63c4b8a | 2016-05-09 10:29:34 -0600 | [diff] [blame] | 8872 | "to: Invalid VkImageView:"); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 8873 | |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 8874 | ASSERT_NO_FATAL_FAILURE(InitState()); |
Chia-I Wu | 1b99bb2 | 2015-10-27 19:25:11 +0800 | [diff] [blame] | 8875 | VkDescriptorPoolSize ds_type_count = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8876 | ds_type_count.type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER; |
| 8877 | ds_type_count.descriptorCount = 1; |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 8878 | |
| 8879 | VkDescriptorPoolCreateInfo ds_pool_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8880 | ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO; |
| 8881 | ds_pool_ci.pNext = NULL; |
| 8882 | ds_pool_ci.maxSets = 1; |
| 8883 | ds_pool_ci.poolSizeCount = 1; |
| 8884 | ds_pool_ci.pPoolSizes = &ds_type_count; |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 8885 | |
| 8886 | VkDescriptorPool ds_pool; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8887 | err = |
| 8888 | vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool); |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 8889 | ASSERT_VK_SUCCESS(err); |
| 8890 | |
| 8891 | VkDescriptorSetLayoutBinding dsl_binding = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8892 | dsl_binding.binding = 0; |
| 8893 | dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER; |
| 8894 | dsl_binding.descriptorCount = 1; |
| 8895 | dsl_binding.stageFlags = VK_SHADER_STAGE_ALL; |
| 8896 | dsl_binding.pImmutableSamplers = NULL; |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 8897 | |
| 8898 | VkDescriptorSetLayoutCreateInfo ds_layout_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8899 | ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO; |
| 8900 | ds_layout_ci.pNext = NULL; |
| 8901 | ds_layout_ci.bindingCount = 1; |
| 8902 | ds_layout_ci.pBindings = &dsl_binding; |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 8903 | VkDescriptorSetLayout ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8904 | err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, |
| 8905 | &ds_layout); |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 8906 | ASSERT_VK_SUCCESS(err); |
| 8907 | |
| 8908 | VkDescriptorSet descriptorSet; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 8909 | VkDescriptorSetAllocateInfo alloc_info = {}; |
Chia-I Wu | 00ce540 | 2015-11-10 16:21:09 +0800 | [diff] [blame] | 8910 | alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO; |
Jon Ashburn | f19916e | 2016-01-11 13:12:43 -0700 | [diff] [blame] | 8911 | alloc_info.descriptorSetCount = 1; |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 8912 | alloc_info.descriptorPool = ds_pool; |
| 8913 | alloc_info.pSetLayouts = &ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8914 | err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, |
| 8915 | &descriptorSet); |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 8916 | ASSERT_VK_SUCCESS(err); |
| 8917 | |
| 8918 | VkSamplerCreateInfo sampler_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8919 | sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO; |
| 8920 | sampler_ci.pNext = NULL; |
| 8921 | sampler_ci.magFilter = VK_FILTER_NEAREST; |
| 8922 | sampler_ci.minFilter = VK_FILTER_NEAREST; |
| 8923 | sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST; |
| 8924 | sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE; |
| 8925 | sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE; |
| 8926 | sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE; |
| 8927 | sampler_ci.mipLodBias = 1.0; |
| 8928 | sampler_ci.anisotropyEnable = VK_FALSE; |
| 8929 | sampler_ci.maxAnisotropy = 1; |
| 8930 | sampler_ci.compareEnable = VK_FALSE; |
| 8931 | sampler_ci.compareOp = VK_COMPARE_OP_NEVER; |
| 8932 | sampler_ci.minLod = 1.0; |
| 8933 | sampler_ci.maxLod = 1.0; |
| 8934 | sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE; |
| 8935 | sampler_ci.unnormalizedCoordinates = VK_FALSE; |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 8936 | |
| 8937 | VkSampler sampler; |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 8938 | err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler); |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 8939 | ASSERT_VK_SUCCESS(err); |
| 8940 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8941 | VkImageView view = |
| 8942 | (VkImageView)((size_t)0xbaadbeef); // invalid imageView object |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 8943 | |
| 8944 | VkDescriptorImageInfo descriptor_info; |
| 8945 | memset(&descriptor_info, 0, sizeof(VkDescriptorImageInfo)); |
| 8946 | descriptor_info.sampler = sampler; |
| 8947 | descriptor_info.imageView = view; |
| 8948 | |
| 8949 | VkWriteDescriptorSet descriptor_write; |
| 8950 | memset(&descriptor_write, 0, sizeof(descriptor_write)); |
| 8951 | descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 8952 | descriptor_write.dstSet = descriptorSet; |
| 8953 | descriptor_write.dstBinding = 0; |
Chia-I Wu | d50a7d7 | 2015-10-26 20:48:51 +0800 | [diff] [blame] | 8954 | descriptor_write.descriptorCount = 1; |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 8955 | descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER; |
| 8956 | descriptor_write.pImageInfo = &descriptor_info; |
| 8957 | |
| 8958 | vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL); |
| 8959 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 8960 | m_errorMonitor->VerifyFound(); |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 8961 | |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 8962 | vkDestroySampler(m_device->device(), sampler, NULL); |
| 8963 | vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL); |
| 8964 | vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL); |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 8965 | } |
| 8966 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8967 | TEST_F(VkLayerTest, CopyDescriptorUpdateErrors) { |
| 8968 | // Create DS w/ layout of 2 types, write update 1 and attempt to copy-update |
| 8969 | // into the other |
| 8970 | VkResult err; |
Tobin Ehlis | 04356f9 | 2015-10-27 16:35:27 -0600 | [diff] [blame] | 8971 | |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 8972 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 8973 | " binding #1 with type " |
| 8974 | "VK_DESCRIPTOR_TYPE_SAMPLER. Types do " |
| 8975 | "not match."); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 8976 | |
Tobin Ehlis | 04356f9 | 2015-10-27 16:35:27 -0600 | [diff] [blame] | 8977 | ASSERT_NO_FATAL_FAILURE(InitState()); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8978 | // VkDescriptorSetObj descriptorSet(m_device); |
Chia-I Wu | 1b99bb2 | 2015-10-27 19:25:11 +0800 | [diff] [blame] | 8979 | VkDescriptorPoolSize ds_type_count[2] = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8980 | ds_type_count[0].type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 8981 | ds_type_count[0].descriptorCount = 1; |
| 8982 | ds_type_count[1].type = VK_DESCRIPTOR_TYPE_SAMPLER; |
| 8983 | ds_type_count[1].descriptorCount = 1; |
Tobin Ehlis | 04356f9 | 2015-10-27 16:35:27 -0600 | [diff] [blame] | 8984 | |
| 8985 | VkDescriptorPoolCreateInfo ds_pool_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8986 | ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO; |
| 8987 | ds_pool_ci.pNext = NULL; |
| 8988 | ds_pool_ci.maxSets = 1; |
| 8989 | ds_pool_ci.poolSizeCount = 2; |
| 8990 | ds_pool_ci.pPoolSizes = ds_type_count; |
Tobin Ehlis | 04356f9 | 2015-10-27 16:35:27 -0600 | [diff] [blame] | 8991 | |
| 8992 | VkDescriptorPool ds_pool; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8993 | err = |
| 8994 | vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool); |
Tobin Ehlis | 04356f9 | 2015-10-27 16:35:27 -0600 | [diff] [blame] | 8995 | ASSERT_VK_SUCCESS(err); |
| 8996 | VkDescriptorSetLayoutBinding dsl_binding[2] = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8997 | dsl_binding[0].binding = 0; |
| 8998 | dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 8999 | dsl_binding[0].descriptorCount = 1; |
| 9000 | dsl_binding[0].stageFlags = VK_SHADER_STAGE_ALL; |
| 9001 | dsl_binding[0].pImmutableSamplers = NULL; |
| 9002 | dsl_binding[1].binding = 1; |
| 9003 | dsl_binding[1].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER; |
| 9004 | dsl_binding[1].descriptorCount = 1; |
| 9005 | dsl_binding[1].stageFlags = VK_SHADER_STAGE_ALL; |
| 9006 | dsl_binding[1].pImmutableSamplers = NULL; |
Tobin Ehlis | 04356f9 | 2015-10-27 16:35:27 -0600 | [diff] [blame] | 9007 | |
| 9008 | VkDescriptorSetLayoutCreateInfo ds_layout_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9009 | ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO; |
| 9010 | ds_layout_ci.pNext = NULL; |
| 9011 | ds_layout_ci.bindingCount = 2; |
| 9012 | ds_layout_ci.pBindings = dsl_binding; |
Tobin Ehlis | 04356f9 | 2015-10-27 16:35:27 -0600 | [diff] [blame] | 9013 | |
| 9014 | VkDescriptorSetLayout ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9015 | err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, |
| 9016 | &ds_layout); |
Tobin Ehlis | 04356f9 | 2015-10-27 16:35:27 -0600 | [diff] [blame] | 9017 | ASSERT_VK_SUCCESS(err); |
| 9018 | |
| 9019 | VkDescriptorSet descriptorSet; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 9020 | VkDescriptorSetAllocateInfo alloc_info = {}; |
Chia-I Wu | 00ce540 | 2015-11-10 16:21:09 +0800 | [diff] [blame] | 9021 | alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO; |
Jon Ashburn | f19916e | 2016-01-11 13:12:43 -0700 | [diff] [blame] | 9022 | alloc_info.descriptorSetCount = 1; |
Tobin Ehlis | 04356f9 | 2015-10-27 16:35:27 -0600 | [diff] [blame] | 9023 | alloc_info.descriptorPool = ds_pool; |
| 9024 | alloc_info.pSetLayouts = &ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9025 | err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, |
| 9026 | &descriptorSet); |
Tobin Ehlis | 04356f9 | 2015-10-27 16:35:27 -0600 | [diff] [blame] | 9027 | ASSERT_VK_SUCCESS(err); |
| 9028 | |
| 9029 | VkSamplerCreateInfo sampler_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9030 | sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO; |
| 9031 | sampler_ci.pNext = NULL; |
| 9032 | sampler_ci.magFilter = VK_FILTER_NEAREST; |
| 9033 | sampler_ci.minFilter = VK_FILTER_NEAREST; |
| 9034 | sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST; |
| 9035 | sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE; |
| 9036 | sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE; |
| 9037 | sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE; |
| 9038 | sampler_ci.mipLodBias = 1.0; |
| 9039 | sampler_ci.anisotropyEnable = VK_FALSE; |
| 9040 | sampler_ci.maxAnisotropy = 1; |
| 9041 | sampler_ci.compareEnable = VK_FALSE; |
| 9042 | sampler_ci.compareOp = VK_COMPARE_OP_NEVER; |
| 9043 | sampler_ci.minLod = 1.0; |
| 9044 | sampler_ci.maxLod = 1.0; |
| 9045 | sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE; |
| 9046 | sampler_ci.unnormalizedCoordinates = VK_FALSE; |
Tobin Ehlis | 04356f9 | 2015-10-27 16:35:27 -0600 | [diff] [blame] | 9047 | |
| 9048 | VkSampler sampler; |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 9049 | err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler); |
Tobin Ehlis | 04356f9 | 2015-10-27 16:35:27 -0600 | [diff] [blame] | 9050 | ASSERT_VK_SUCCESS(err); |
| 9051 | |
| 9052 | VkDescriptorImageInfo info = {}; |
| 9053 | info.sampler = sampler; |
| 9054 | |
| 9055 | VkWriteDescriptorSet descriptor_write; |
| 9056 | memset(&descriptor_write, 0, sizeof(VkWriteDescriptorSet)); |
| 9057 | descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 9058 | descriptor_write.dstSet = descriptorSet; |
| 9059 | descriptor_write.dstBinding = 1; // SAMPLER binding from layout above |
Chia-I Wu | d50a7d7 | 2015-10-26 20:48:51 +0800 | [diff] [blame] | 9060 | descriptor_write.descriptorCount = 1; |
Tobin Ehlis | 04356f9 | 2015-10-27 16:35:27 -0600 | [diff] [blame] | 9061 | descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER; |
| 9062 | descriptor_write.pImageInfo = &info; |
| 9063 | // This write update should succeed |
| 9064 | vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL); |
| 9065 | // Now perform a copy update that fails due to type mismatch |
| 9066 | VkCopyDescriptorSet copy_ds_update; |
| 9067 | memset(©_ds_update, 0, sizeof(VkCopyDescriptorSet)); |
| 9068 | copy_ds_update.sType = VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET; |
| 9069 | copy_ds_update.srcSet = descriptorSet; |
Mark Young | 2992748 | 2016-05-04 14:38:51 -0600 | [diff] [blame] | 9070 | copy_ds_update.srcBinding = 1; // Copy from SAMPLER binding |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 9071 | copy_ds_update.dstSet = descriptorSet; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9072 | copy_ds_update.dstBinding = 0; // ERROR : copy to UNIFORM binding |
Chia-I Wu | d50a7d7 | 2015-10-26 20:48:51 +0800 | [diff] [blame] | 9073 | copy_ds_update.descriptorCount = 1; // copy 1 descriptor |
Tobin Ehlis | 04356f9 | 2015-10-27 16:35:27 -0600 | [diff] [blame] | 9074 | vkUpdateDescriptorSets(m_device->device(), 0, NULL, 1, ©_ds_update); |
| 9075 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 9076 | m_errorMonitor->VerifyFound(); |
Tobin Ehlis | 04356f9 | 2015-10-27 16:35:27 -0600 | [diff] [blame] | 9077 | // Now perform a copy update that fails due to binding out of bounds |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9078 | m_errorMonitor->SetDesiredFailureMsg( |
| 9079 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 9080 | " does not have copy update src binding of 3."); |
Tobin Ehlis | 04356f9 | 2015-10-27 16:35:27 -0600 | [diff] [blame] | 9081 | memset(©_ds_update, 0, sizeof(VkCopyDescriptorSet)); |
| 9082 | copy_ds_update.sType = VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET; |
| 9083 | copy_ds_update.srcSet = descriptorSet; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9084 | copy_ds_update.srcBinding = |
| 9085 | 3; // ERROR : Invalid binding for matching layout |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 9086 | copy_ds_update.dstSet = descriptorSet; |
| 9087 | copy_ds_update.dstBinding = 0; |
Mark Young | 2992748 | 2016-05-04 14:38:51 -0600 | [diff] [blame] | 9088 | copy_ds_update.descriptorCount = 1; // Copy 1 descriptor |
Tobin Ehlis | 04356f9 | 2015-10-27 16:35:27 -0600 | [diff] [blame] | 9089 | vkUpdateDescriptorSets(m_device->device(), 0, NULL, 1, ©_ds_update); |
| 9090 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 9091 | m_errorMonitor->VerifyFound(); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 9092 | |
Tobin Ehlis | 04356f9 | 2015-10-27 16:35:27 -0600 | [diff] [blame] | 9093 | // Now perform a copy update that fails due to binding out of bounds |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9094 | m_errorMonitor->SetDesiredFailureMsg( |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 9095 | VK_DEBUG_REPORT_ERROR_BIT_EXT, " binding#1 with offset index of 1 plus " |
| 9096 | "update array offset of 0 and update of " |
| 9097 | "5 descriptors oversteps total number " |
| 9098 | "of descriptors in set: 2."); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 9099 | |
Tobin Ehlis | 04356f9 | 2015-10-27 16:35:27 -0600 | [diff] [blame] | 9100 | memset(©_ds_update, 0, sizeof(VkCopyDescriptorSet)); |
| 9101 | copy_ds_update.sType = VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET; |
| 9102 | copy_ds_update.srcSet = descriptorSet; |
| 9103 | copy_ds_update.srcBinding = 1; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 9104 | copy_ds_update.dstSet = descriptorSet; |
| 9105 | copy_ds_update.dstBinding = 0; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9106 | copy_ds_update.descriptorCount = |
| 9107 | 5; // ERROR copy 5 descriptors (out of bounds for layout) |
Tobin Ehlis | 04356f9 | 2015-10-27 16:35:27 -0600 | [diff] [blame] | 9108 | vkUpdateDescriptorSets(m_device->device(), 0, NULL, 1, ©_ds_update); |
| 9109 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 9110 | m_errorMonitor->VerifyFound(); |
Tobin Ehlis | 04356f9 | 2015-10-27 16:35:27 -0600 | [diff] [blame] | 9111 | |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 9112 | vkDestroySampler(m_device->device(), sampler, NULL); |
| 9113 | vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL); |
| 9114 | vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL); |
Tobin Ehlis | 04356f9 | 2015-10-27 16:35:27 -0600 | [diff] [blame] | 9115 | } |
| 9116 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9117 | TEST_F(VkLayerTest, NumSamplesMismatch) { |
| 9118 | // Create CommandBuffer where MSAA samples doesn't match RenderPass |
| 9119 | // sampleCount |
| 9120 | VkResult err; |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 9121 | |
Courtney Goeltzenleuchter | 7415d5a | 2015-12-09 15:48:16 -0700 | [diff] [blame] | 9122 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9123 | "Num samples mismatch! "); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 9124 | |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 9125 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 9126 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
Chia-I Wu | 1b99bb2 | 2015-10-27 19:25:11 +0800 | [diff] [blame] | 9127 | VkDescriptorPoolSize ds_type_count = {}; |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 9128 | ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
Chia-I Wu | d50a7d7 | 2015-10-26 20:48:51 +0800 | [diff] [blame] | 9129 | ds_type_count.descriptorCount = 1; |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 9130 | |
| 9131 | VkDescriptorPoolCreateInfo ds_pool_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9132 | ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO; |
| 9133 | ds_pool_ci.pNext = NULL; |
| 9134 | ds_pool_ci.maxSets = 1; |
| 9135 | ds_pool_ci.poolSizeCount = 1; |
| 9136 | ds_pool_ci.pPoolSizes = &ds_type_count; |
Courtney Goeltzenleuchter | fe908d3 | 2015-09-16 16:12:45 -0600 | [diff] [blame] | 9137 | |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 9138 | VkDescriptorPool ds_pool; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9139 | err = |
| 9140 | vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool); |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 9141 | ASSERT_VK_SUCCESS(err); |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 9142 | |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 9143 | VkDescriptorSetLayoutBinding dsl_binding = {}; |
Chia-I Wu | d46e6ae | 2015-10-31 00:31:16 +0800 | [diff] [blame] | 9144 | dsl_binding.binding = 0; |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 9145 | dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
Chia-I Wu | 0212448 | 2015-11-06 06:42:02 +0800 | [diff] [blame] | 9146 | dsl_binding.descriptorCount = 1; |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 9147 | dsl_binding.stageFlags = VK_SHADER_STAGE_ALL; |
| 9148 | dsl_binding.pImmutableSamplers = NULL; |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 9149 | |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 9150 | VkDescriptorSetLayoutCreateInfo ds_layout_ci = {}; |
| 9151 | ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO; |
| 9152 | ds_layout_ci.pNext = NULL; |
Chia-I Wu | d50a7d7 | 2015-10-26 20:48:51 +0800 | [diff] [blame] | 9153 | ds_layout_ci.bindingCount = 1; |
Jon Ashburn | 6e23c1f | 2015-12-30 18:01:16 -0700 | [diff] [blame] | 9154 | ds_layout_ci.pBindings = &dsl_binding; |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 9155 | |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 9156 | VkDescriptorSetLayout ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9157 | err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, |
| 9158 | &ds_layout); |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 9159 | ASSERT_VK_SUCCESS(err); |
| 9160 | |
| 9161 | VkDescriptorSet descriptorSet; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 9162 | VkDescriptorSetAllocateInfo alloc_info = {}; |
Chia-I Wu | 00ce540 | 2015-11-10 16:21:09 +0800 | [diff] [blame] | 9163 | alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO; |
Jon Ashburn | f19916e | 2016-01-11 13:12:43 -0700 | [diff] [blame] | 9164 | alloc_info.descriptorSetCount = 1; |
Courtney Goeltzenleuchter | bee18a9 | 2015-10-23 14:21:05 -0600 | [diff] [blame] | 9165 | alloc_info.descriptorPool = ds_pool; |
| 9166 | alloc_info.pSetLayouts = &ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9167 | err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, |
| 9168 | &descriptorSet); |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 9169 | ASSERT_VK_SUCCESS(err); |
| 9170 | |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 9171 | VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9172 | pipe_ms_state_ci.sType = |
| 9173 | VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO; |
| 9174 | pipe_ms_state_ci.pNext = NULL; |
| 9175 | pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_4_BIT; |
| 9176 | pipe_ms_state_ci.sampleShadingEnable = 0; |
| 9177 | pipe_ms_state_ci.minSampleShading = 1.0; |
| 9178 | pipe_ms_state_ci.pSampleMask = NULL; |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 9179 | |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 9180 | VkPipelineLayoutCreateInfo pipeline_layout_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9181 | pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO; |
| 9182 | pipeline_layout_ci.pNext = NULL; |
| 9183 | pipeline_layout_ci.setLayoutCount = 1; |
| 9184 | pipeline_layout_ci.pSetLayouts = &ds_layout; |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 9185 | |
| 9186 | VkPipelineLayout pipeline_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9187 | err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, |
| 9188 | &pipeline_layout); |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 9189 | ASSERT_VK_SUCCESS(err); |
| 9190 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9191 | VkShaderObj vs(m_device, bindStateVertShaderText, |
| 9192 | VK_SHADER_STAGE_VERTEX_BIT, this); |
| 9193 | VkShaderObj fs(m_device, bindStateFragShaderText, |
| 9194 | VK_SHADER_STAGE_FRAGMENT_BIT, |
Karl Schultz | bdb7595 | 2016-04-19 11:36:49 -0600 | [diff] [blame] | 9195 | this); // We shouldn't need a fragment shader |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9196 | // but add it to be able to run on more devices |
Tony Barbour | 62e1a5b | 2015-08-06 10:16:07 -0600 | [diff] [blame] | 9197 | VkPipelineObj pipe(m_device); |
| 9198 | pipe.AddShader(&vs); |
Tony Barbour | 1c94d37 | 2015-08-06 11:21:08 -0600 | [diff] [blame] | 9199 | pipe.AddShader(&fs); |
Mark Young | c89c631 | 2016-03-31 16:03:20 -0600 | [diff] [blame] | 9200 | pipe.AddColorAttachment(); |
Tony Barbour | 62e1a5b | 2015-08-06 10:16:07 -0600 | [diff] [blame] | 9201 | pipe.SetMSAA(&pipe_ms_state_ci); |
| 9202 | pipe.CreateVKPipeline(pipeline_layout, renderPass()); |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 9203 | |
Tony Barbour | fe3351b | 2015-07-28 10:17:20 -0600 | [diff] [blame] | 9204 | BeginCommandBuffer(); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9205 | vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), |
| 9206 | VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle()); |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 9207 | |
Mark Young | 2992748 | 2016-05-04 14:38:51 -0600 | [diff] [blame] | 9208 | // Render triangle (the error should trigger on the attempt to draw). |
| 9209 | Draw(3, 1, 0, 0); |
| 9210 | |
| 9211 | // Finalize recording of the command buffer |
| 9212 | EndCommandBuffer(); |
| 9213 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 9214 | m_errorMonitor->VerifyFound(); |
Mike Stroyan | d1c84a5 | 2015-08-18 14:40:24 -0600 | [diff] [blame] | 9215 | |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 9216 | vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL); |
| 9217 | vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL); |
| 9218 | vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL); |
Tobin Ehlis | 49eb23d | 2015-05-22 12:38:55 -0600 | [diff] [blame] | 9219 | } |
Mark Young | 2992748 | 2016-05-04 14:38:51 -0600 | [diff] [blame] | 9220 | |
Tobin Ehlis | 85aa15a | 2016-06-15 10:52:37 -0600 | [diff] [blame] | 9221 | TEST_F(VkLayerTest, RenderPassIncompatible) { |
| 9222 | TEST_DESCRIPTION("Hit RenderPass incompatible cases. " |
| 9223 | "Initial case is drawing with an active renderpass that's " |
| 9224 | "not compatible with the bound PSO's creation renderpass"); |
| 9225 | VkResult err; |
| 9226 | |
| 9227 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 9228 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 9229 | |
| 9230 | VkDescriptorSetLayoutBinding dsl_binding = {}; |
| 9231 | dsl_binding.binding = 0; |
| 9232 | dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 9233 | dsl_binding.descriptorCount = 1; |
| 9234 | dsl_binding.stageFlags = VK_SHADER_STAGE_ALL; |
| 9235 | dsl_binding.pImmutableSamplers = NULL; |
| 9236 | |
| 9237 | VkDescriptorSetLayoutCreateInfo ds_layout_ci = {}; |
| 9238 | ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO; |
| 9239 | ds_layout_ci.pNext = NULL; |
| 9240 | ds_layout_ci.bindingCount = 1; |
| 9241 | ds_layout_ci.pBindings = &dsl_binding; |
| 9242 | |
| 9243 | VkDescriptorSetLayout ds_layout; |
| 9244 | err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, |
| 9245 | &ds_layout); |
| 9246 | ASSERT_VK_SUCCESS(err); |
| 9247 | |
| 9248 | VkPipelineLayoutCreateInfo pipeline_layout_ci = {}; |
| 9249 | pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO; |
| 9250 | pipeline_layout_ci.pNext = NULL; |
| 9251 | pipeline_layout_ci.setLayoutCount = 1; |
| 9252 | pipeline_layout_ci.pSetLayouts = &ds_layout; |
| 9253 | |
| 9254 | VkPipelineLayout pipeline_layout; |
| 9255 | err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, |
| 9256 | &pipeline_layout); |
| 9257 | ASSERT_VK_SUCCESS(err); |
| 9258 | |
| 9259 | VkShaderObj vs(m_device, bindStateVertShaderText, |
| 9260 | VK_SHADER_STAGE_VERTEX_BIT, this); |
| 9261 | VkShaderObj fs(m_device, bindStateFragShaderText, |
| 9262 | VK_SHADER_STAGE_FRAGMENT_BIT, |
| 9263 | this); // We shouldn't need a fragment shader |
| 9264 | // but add it to be able to run on more devices |
| 9265 | // Create a renderpass that will be incompatible with default renderpass |
| 9266 | VkAttachmentReference attach = {}; |
| 9267 | attach.layout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL; |
| 9268 | VkAttachmentReference color_att = {}; |
| 9269 | color_att.layout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL; |
| 9270 | VkSubpassDescription subpass = {}; |
| 9271 | subpass.inputAttachmentCount = 1; |
| 9272 | subpass.pInputAttachments = &attach; |
| 9273 | subpass.colorAttachmentCount = 1; |
| 9274 | subpass.pColorAttachments = &color_att; |
| 9275 | VkRenderPassCreateInfo rpci = {}; |
| 9276 | rpci.subpassCount = 1; |
| 9277 | rpci.pSubpasses = &subpass; |
| 9278 | rpci.attachmentCount = 1; |
| 9279 | VkAttachmentDescription attach_desc = {}; |
| 9280 | attach_desc.samples = VK_SAMPLE_COUNT_1_BIT; |
Cody Northrop | bd16af1 | 2016-06-21 09:25:48 -0600 | [diff] [blame] | 9281 | // Format incompatible with PSO RP color attach format B8G8R8A8_UNORM |
| 9282 | attach_desc.format = VK_FORMAT_R8G8B8A8_UNORM; |
Tobin Ehlis | 85aa15a | 2016-06-15 10:52:37 -0600 | [diff] [blame] | 9283 | rpci.pAttachments = &attach_desc; |
| 9284 | rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO; |
| 9285 | VkRenderPass rp; |
| 9286 | vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp); |
| 9287 | VkPipelineObj pipe(m_device); |
| 9288 | pipe.AddShader(&vs); |
| 9289 | pipe.AddShader(&fs); |
| 9290 | pipe.AddColorAttachment(); |
| 9291 | VkViewport view_port = {}; |
| 9292 | m_viewports.push_back(view_port); |
| 9293 | pipe.SetViewport(m_viewports); |
| 9294 | VkRect2D rect = {}; |
| 9295 | m_scissors.push_back(rect); |
| 9296 | pipe.SetScissor(m_scissors); |
| 9297 | pipe.CreateVKPipeline(pipeline_layout, renderPass()); |
| 9298 | |
| 9299 | VkCommandBufferInheritanceInfo cbii = {}; |
| 9300 | cbii.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO; |
| 9301 | cbii.renderPass = rp; |
| 9302 | cbii.subpass = 0; |
| 9303 | VkCommandBufferBeginInfo cbbi = {}; |
| 9304 | cbbi.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO; |
| 9305 | cbbi.pInheritanceInfo = &cbii; |
| 9306 | vkBeginCommandBuffer(m_commandBuffer->handle(), &cbbi); |
| 9307 | VkRenderPassBeginInfo rpbi = {}; |
| 9308 | rpbi.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO; |
| 9309 | rpbi.framebuffer = m_framebuffer; |
| 9310 | rpbi.renderPass = rp; |
| 9311 | vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &rpbi, |
| 9312 | VK_SUBPASS_CONTENTS_INLINE); |
| 9313 | vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), |
| 9314 | VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle()); |
| 9315 | |
| 9316 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 9317 | " is incompatible w/ gfx pipeline "); |
| 9318 | // Render triangle (the error should trigger on the attempt to draw). |
| 9319 | Draw(3, 1, 0, 0); |
| 9320 | |
| 9321 | // Finalize recording of the command buffer |
| 9322 | EndCommandBuffer(); |
| 9323 | |
| 9324 | m_errorMonitor->VerifyFound(); |
| 9325 | |
| 9326 | vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL); |
| 9327 | vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL); |
| 9328 | vkDestroyRenderPass(m_device->device(), rp, NULL); |
| 9329 | } |
| 9330 | |
Mark Young | c89c631 | 2016-03-31 16:03:20 -0600 | [diff] [blame] | 9331 | TEST_F(VkLayerTest, NumBlendAttachMismatch) { |
| 9332 | // Create Pipeline where the number of blend attachments doesn't match the |
| 9333 | // number of color attachments. In this case, we don't add any color |
| 9334 | // blend attachments even though we have a color attachment. |
| 9335 | VkResult err; |
| 9336 | |
| 9337 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Mark Young | 2992748 | 2016-05-04 14:38:51 -0600 | [diff] [blame] | 9338 | "Render pass subpass 0 mismatch with blending state defined and blend state attachment"); |
Mark Young | c89c631 | 2016-03-31 16:03:20 -0600 | [diff] [blame] | 9339 | |
| 9340 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 9341 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 9342 | VkDescriptorPoolSize ds_type_count = {}; |
| 9343 | ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 9344 | ds_type_count.descriptorCount = 1; |
| 9345 | |
| 9346 | VkDescriptorPoolCreateInfo ds_pool_ci = {}; |
| 9347 | ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO; |
| 9348 | ds_pool_ci.pNext = NULL; |
| 9349 | ds_pool_ci.maxSets = 1; |
| 9350 | ds_pool_ci.poolSizeCount = 1; |
| 9351 | ds_pool_ci.pPoolSizes = &ds_type_count; |
| 9352 | |
| 9353 | VkDescriptorPool ds_pool; |
| 9354 | err = |
| 9355 | vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool); |
| 9356 | ASSERT_VK_SUCCESS(err); |
| 9357 | |
| 9358 | VkDescriptorSetLayoutBinding dsl_binding = {}; |
| 9359 | dsl_binding.binding = 0; |
| 9360 | dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 9361 | dsl_binding.descriptorCount = 1; |
| 9362 | dsl_binding.stageFlags = VK_SHADER_STAGE_ALL; |
| 9363 | dsl_binding.pImmutableSamplers = NULL; |
| 9364 | |
| 9365 | VkDescriptorSetLayoutCreateInfo ds_layout_ci = {}; |
| 9366 | ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO; |
| 9367 | ds_layout_ci.pNext = NULL; |
| 9368 | ds_layout_ci.bindingCount = 1; |
| 9369 | ds_layout_ci.pBindings = &dsl_binding; |
| 9370 | |
| 9371 | VkDescriptorSetLayout ds_layout; |
| 9372 | err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, |
| 9373 | &ds_layout); |
| 9374 | ASSERT_VK_SUCCESS(err); |
| 9375 | |
| 9376 | VkDescriptorSet descriptorSet; |
| 9377 | VkDescriptorSetAllocateInfo alloc_info = {}; |
| 9378 | alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO; |
| 9379 | alloc_info.descriptorSetCount = 1; |
| 9380 | alloc_info.descriptorPool = ds_pool; |
| 9381 | alloc_info.pSetLayouts = &ds_layout; |
| 9382 | err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, |
| 9383 | &descriptorSet); |
| 9384 | ASSERT_VK_SUCCESS(err); |
| 9385 | |
| 9386 | VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {}; |
| 9387 | pipe_ms_state_ci.sType = |
| 9388 | VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO; |
| 9389 | pipe_ms_state_ci.pNext = NULL; |
| 9390 | pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT; |
| 9391 | pipe_ms_state_ci.sampleShadingEnable = 0; |
| 9392 | pipe_ms_state_ci.minSampleShading = 1.0; |
| 9393 | pipe_ms_state_ci.pSampleMask = NULL; |
| 9394 | |
| 9395 | VkPipelineLayoutCreateInfo pipeline_layout_ci = {}; |
| 9396 | pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO; |
| 9397 | pipeline_layout_ci.pNext = NULL; |
| 9398 | pipeline_layout_ci.setLayoutCount = 1; |
| 9399 | pipeline_layout_ci.pSetLayouts = &ds_layout; |
| 9400 | |
| 9401 | VkPipelineLayout pipeline_layout; |
| 9402 | err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, |
| 9403 | &pipeline_layout); |
| 9404 | ASSERT_VK_SUCCESS(err); |
| 9405 | |
| 9406 | VkShaderObj vs(m_device, bindStateVertShaderText, |
| 9407 | VK_SHADER_STAGE_VERTEX_BIT, this); |
| 9408 | VkShaderObj fs(m_device, bindStateFragShaderText, |
| 9409 | VK_SHADER_STAGE_FRAGMENT_BIT, |
Karl Schultz | bdb7595 | 2016-04-19 11:36:49 -0600 | [diff] [blame] | 9410 | this); // We shouldn't need a fragment shader |
Mark Young | c89c631 | 2016-03-31 16:03:20 -0600 | [diff] [blame] | 9411 | // but add it to be able to run on more devices |
| 9412 | VkPipelineObj pipe(m_device); |
| 9413 | pipe.AddShader(&vs); |
| 9414 | pipe.AddShader(&fs); |
| 9415 | pipe.SetMSAA(&pipe_ms_state_ci); |
| 9416 | pipe.CreateVKPipeline(pipeline_layout, renderPass()); |
| 9417 | |
| 9418 | BeginCommandBuffer(); |
| 9419 | vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), |
| 9420 | VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle()); |
| 9421 | |
Mark Young | 2992748 | 2016-05-04 14:38:51 -0600 | [diff] [blame] | 9422 | // Render triangle (the error should trigger on the attempt to draw). |
| 9423 | Draw(3, 1, 0, 0); |
| 9424 | |
| 9425 | // Finalize recording of the command buffer |
| 9426 | EndCommandBuffer(); |
| 9427 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 9428 | m_errorMonitor->VerifyFound(); |
Mark Young | c89c631 | 2016-03-31 16:03:20 -0600 | [diff] [blame] | 9429 | |
| 9430 | vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL); |
| 9431 | vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL); |
| 9432 | vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL); |
| 9433 | } |
Mark Young | 2992748 | 2016-05-04 14:38:51 -0600 | [diff] [blame] | 9434 | |
Mark Mueller | d491441 | 2016-06-13 17:52:06 -0600 | [diff] [blame] | 9435 | TEST_F(VkLayerTest, MissingClearAttachment) { |
| 9436 | TEST_DESCRIPTION("Points to a wrong colorAttachment index in a VkClearAttachment " |
| 9437 | "structure passed to vkCmdClearAttachments"); |
| 9438 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 9439 | "vkCmdClearAttachments() attachment index 1 not found in attachment " |
| 9440 | "reference array of active subpass 0"); |
| 9441 | |
| 9442 | VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailCmdClearAttachments); |
| 9443 | m_errorMonitor->VerifyFound(); |
| 9444 | } |
| 9445 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9446 | TEST_F(VkLayerTest, ClearCmdNoDraw) { |
| 9447 | // Create CommandBuffer where we add ClearCmd for FB Color attachment prior |
| 9448 | // to issuing a Draw |
| 9449 | VkResult err; |
Tobin Ehlis | 53eddda | 2015-07-01 16:46:13 -0600 | [diff] [blame] | 9450 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9451 | m_errorMonitor->SetDesiredFailureMsg( |
Tony Barbour | 7e56d30 | 2016-03-02 15:12:01 -0700 | [diff] [blame] | 9452 | VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 9453 | "vkCmdClearAttachments() issued on CB object "); |
| 9454 | |
Tobin Ehlis | 53eddda | 2015-07-01 16:46:13 -0600 | [diff] [blame] | 9455 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 9456 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 9457 | |
Chia-I Wu | 1b99bb2 | 2015-10-27 19:25:11 +0800 | [diff] [blame] | 9458 | VkDescriptorPoolSize ds_type_count = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9459 | ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 9460 | ds_type_count.descriptorCount = 1; |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 9461 | |
| 9462 | VkDescriptorPoolCreateInfo ds_pool_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9463 | ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO; |
| 9464 | ds_pool_ci.pNext = NULL; |
| 9465 | ds_pool_ci.maxSets = 1; |
| 9466 | ds_pool_ci.poolSizeCount = 1; |
| 9467 | ds_pool_ci.pPoolSizes = &ds_type_count; |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 9468 | |
Tobin Ehlis | 53eddda | 2015-07-01 16:46:13 -0600 | [diff] [blame] | 9469 | VkDescriptorPool ds_pool; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9470 | err = |
| 9471 | vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool); |
Tobin Ehlis | 53eddda | 2015-07-01 16:46:13 -0600 | [diff] [blame] | 9472 | ASSERT_VK_SUCCESS(err); |
| 9473 | |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 9474 | VkDescriptorSetLayoutBinding dsl_binding = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9475 | dsl_binding.binding = 0; |
| 9476 | dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 9477 | dsl_binding.descriptorCount = 1; |
| 9478 | dsl_binding.stageFlags = VK_SHADER_STAGE_ALL; |
| 9479 | dsl_binding.pImmutableSamplers = NULL; |
Tobin Ehlis | 53eddda | 2015-07-01 16:46:13 -0600 | [diff] [blame] | 9480 | |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 9481 | VkDescriptorSetLayoutCreateInfo ds_layout_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9482 | ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO; |
| 9483 | ds_layout_ci.pNext = NULL; |
| 9484 | ds_layout_ci.bindingCount = 1; |
| 9485 | ds_layout_ci.pBindings = &dsl_binding; |
Mark Lobodzinski | 209b529 | 2015-09-17 09:44:05 -0600 | [diff] [blame] | 9486 | |
Tobin Ehlis | 53eddda | 2015-07-01 16:46:13 -0600 | [diff] [blame] | 9487 | VkDescriptorSetLayout ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9488 | err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, |
| 9489 | &ds_layout); |
Tobin Ehlis | 53eddda | 2015-07-01 16:46:13 -0600 | [diff] [blame] | 9490 | ASSERT_VK_SUCCESS(err); |
| 9491 | |
| 9492 | VkDescriptorSet descriptorSet; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 9493 | VkDescriptorSetAllocateInfo alloc_info = {}; |
Chia-I Wu | 00ce540 | 2015-11-10 16:21:09 +0800 | [diff] [blame] | 9494 | alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO; |
Jon Ashburn | f19916e | 2016-01-11 13:12:43 -0700 | [diff] [blame] | 9495 | alloc_info.descriptorSetCount = 1; |
Courtney Goeltzenleuchter | bee18a9 | 2015-10-23 14:21:05 -0600 | [diff] [blame] | 9496 | alloc_info.descriptorPool = ds_pool; |
| 9497 | alloc_info.pSetLayouts = &ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9498 | err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, |
| 9499 | &descriptorSet); |
Tobin Ehlis | 53eddda | 2015-07-01 16:46:13 -0600 | [diff] [blame] | 9500 | ASSERT_VK_SUCCESS(err); |
| 9501 | |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 9502 | VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9503 | pipe_ms_state_ci.sType = |
| 9504 | VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO; |
| 9505 | pipe_ms_state_ci.pNext = NULL; |
| 9506 | pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_4_BIT; |
| 9507 | pipe_ms_state_ci.sampleShadingEnable = 0; |
| 9508 | pipe_ms_state_ci.minSampleShading = 1.0; |
| 9509 | pipe_ms_state_ci.pSampleMask = NULL; |
Tobin Ehlis | 53eddda | 2015-07-01 16:46:13 -0600 | [diff] [blame] | 9510 | |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 9511 | VkPipelineLayoutCreateInfo pipeline_layout_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9512 | pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO; |
| 9513 | pipeline_layout_ci.pNext = NULL; |
| 9514 | pipeline_layout_ci.setLayoutCount = 1; |
| 9515 | pipeline_layout_ci.pSetLayouts = &ds_layout; |
Tobin Ehlis | 53eddda | 2015-07-01 16:46:13 -0600 | [diff] [blame] | 9516 | |
| 9517 | VkPipelineLayout pipeline_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9518 | err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, |
| 9519 | &pipeline_layout); |
Tobin Ehlis | 53eddda | 2015-07-01 16:46:13 -0600 | [diff] [blame] | 9520 | ASSERT_VK_SUCCESS(err); |
Mark Lobodzinski | 209b529 | 2015-09-17 09:44:05 -0600 | [diff] [blame] | 9521 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9522 | VkShaderObj vs(m_device, bindStateVertShaderText, |
| 9523 | VK_SHADER_STAGE_VERTEX_BIT, this); |
Karl Schultz | bdb7595 | 2016-04-19 11:36:49 -0600 | [diff] [blame] | 9524 | // We shouldn't need a fragment shader but add it to be able to run |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9525 | // on more devices |
| 9526 | VkShaderObj fs(m_device, bindStateFragShaderText, |
| 9527 | VK_SHADER_STAGE_FRAGMENT_BIT, this); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 9528 | |
Tony Barbour | 62e1a5b | 2015-08-06 10:16:07 -0600 | [diff] [blame] | 9529 | VkPipelineObj pipe(m_device); |
| 9530 | pipe.AddShader(&vs); |
Tony Barbour | 1c94d37 | 2015-08-06 11:21:08 -0600 | [diff] [blame] | 9531 | pipe.AddShader(&fs); |
Tony Barbour | 62e1a5b | 2015-08-06 10:16:07 -0600 | [diff] [blame] | 9532 | pipe.SetMSAA(&pipe_ms_state_ci); |
| 9533 | pipe.CreateVKPipeline(pipeline_layout, renderPass()); |
Tony Barbour | fe3351b | 2015-07-28 10:17:20 -0600 | [diff] [blame] | 9534 | |
| 9535 | BeginCommandBuffer(); |
Tobin Ehlis | 53eddda | 2015-07-01 16:46:13 -0600 | [diff] [blame] | 9536 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9537 | // Main thing we care about for this test is that the VkImage obj we're |
| 9538 | // clearing matches Color Attachment of FB |
Tobin Ehlis | 53eddda | 2015-07-01 16:46:13 -0600 | [diff] [blame] | 9539 | // Also pass down other dummy params to keep driver and paramchecker happy |
Courtney Goeltzenleuchter | c9323e0 | 2015-10-15 16:51:05 -0600 | [diff] [blame] | 9540 | VkClearAttachment color_attachment; |
| 9541 | color_attachment.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; |
| 9542 | color_attachment.clearValue.color.float32[0] = 1.0; |
| 9543 | color_attachment.clearValue.color.float32[1] = 1.0; |
| 9544 | color_attachment.clearValue.color.float32[2] = 1.0; |
| 9545 | color_attachment.clearValue.color.float32[3] = 1.0; |
| 9546 | color_attachment.colorAttachment = 0; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9547 | VkClearRect clear_rect = { |
| 9548 | {{0, 0}, {(uint32_t)m_width, (uint32_t)m_height}}}; |
Tobin Ehlis | 53eddda | 2015-07-01 16:46:13 -0600 | [diff] [blame] | 9549 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9550 | vkCmdClearAttachments(m_commandBuffer->GetBufferHandle(), 1, |
| 9551 | &color_attachment, 1, &clear_rect); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 9552 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 9553 | m_errorMonitor->VerifyFound(); |
Mike Stroyan | d1c84a5 | 2015-08-18 14:40:24 -0600 | [diff] [blame] | 9554 | |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 9555 | vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL); |
| 9556 | vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL); |
| 9557 | vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL); |
Tobin Ehlis | 53eddda | 2015-07-01 16:46:13 -0600 | [diff] [blame] | 9558 | } |
| 9559 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9560 | TEST_F(VkLayerTest, VtxBufferBadIndex) { |
| 9561 | VkResult err; |
Tobin Ehlis | 502480b | 2015-06-24 15:53:07 -0600 | [diff] [blame] | 9562 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9563 | m_errorMonitor->SetDesiredFailureMsg( |
Mark Lobodzinski | 510e20d | 2016-02-11 09:26:16 -0700 | [diff] [blame] | 9564 | VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, |
Mark Lobodzinski | dfcd9b6 | 2015-12-14 15:14:10 -0700 | [diff] [blame] | 9565 | "but no vertex buffers are attached to this Pipeline State Object"); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 9566 | |
Tobin Ehlis | 502480b | 2015-06-24 15:53:07 -0600 | [diff] [blame] | 9567 | ASSERT_NO_FATAL_FAILURE(InitState()); |
Tobin Ehlis | d332f28 | 2015-10-02 11:00:56 -0600 | [diff] [blame] | 9568 | ASSERT_NO_FATAL_FAILURE(InitViewport()); |
Tobin Ehlis | 502480b | 2015-06-24 15:53:07 -0600 | [diff] [blame] | 9569 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 9570 | |
Chia-I Wu | 1b99bb2 | 2015-10-27 19:25:11 +0800 | [diff] [blame] | 9571 | VkDescriptorPoolSize ds_type_count = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9572 | ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 9573 | ds_type_count.descriptorCount = 1; |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 9574 | |
| 9575 | VkDescriptorPoolCreateInfo ds_pool_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9576 | ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO; |
| 9577 | ds_pool_ci.pNext = NULL; |
| 9578 | ds_pool_ci.maxSets = 1; |
| 9579 | ds_pool_ci.poolSizeCount = 1; |
| 9580 | ds_pool_ci.pPoolSizes = &ds_type_count; |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 9581 | |
Courtney Goeltzenleuchter | fe908d3 | 2015-09-16 16:12:45 -0600 | [diff] [blame] | 9582 | VkDescriptorPool ds_pool; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9583 | err = |
| 9584 | vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool); |
Tobin Ehlis | 502480b | 2015-06-24 15:53:07 -0600 | [diff] [blame] | 9585 | ASSERT_VK_SUCCESS(err); |
| 9586 | |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 9587 | VkDescriptorSetLayoutBinding dsl_binding = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9588 | dsl_binding.binding = 0; |
| 9589 | dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 9590 | dsl_binding.descriptorCount = 1; |
| 9591 | dsl_binding.stageFlags = VK_SHADER_STAGE_ALL; |
| 9592 | dsl_binding.pImmutableSamplers = NULL; |
Tobin Ehlis | 502480b | 2015-06-24 15:53:07 -0600 | [diff] [blame] | 9593 | |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 9594 | VkDescriptorSetLayoutCreateInfo ds_layout_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9595 | ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO; |
| 9596 | ds_layout_ci.pNext = NULL; |
| 9597 | ds_layout_ci.bindingCount = 1; |
| 9598 | ds_layout_ci.pBindings = &dsl_binding; |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 9599 | |
Tobin Ehlis | 502480b | 2015-06-24 15:53:07 -0600 | [diff] [blame] | 9600 | VkDescriptorSetLayout ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9601 | err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, |
| 9602 | &ds_layout); |
Tobin Ehlis | 502480b | 2015-06-24 15:53:07 -0600 | [diff] [blame] | 9603 | ASSERT_VK_SUCCESS(err); |
| 9604 | |
| 9605 | VkDescriptorSet descriptorSet; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 9606 | VkDescriptorSetAllocateInfo alloc_info = {}; |
Chia-I Wu | 00ce540 | 2015-11-10 16:21:09 +0800 | [diff] [blame] | 9607 | alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO; |
Jon Ashburn | f19916e | 2016-01-11 13:12:43 -0700 | [diff] [blame] | 9608 | alloc_info.descriptorSetCount = 1; |
Courtney Goeltzenleuchter | bee18a9 | 2015-10-23 14:21:05 -0600 | [diff] [blame] | 9609 | alloc_info.descriptorPool = ds_pool; |
| 9610 | alloc_info.pSetLayouts = &ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9611 | err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, |
| 9612 | &descriptorSet); |
Tobin Ehlis | 502480b | 2015-06-24 15:53:07 -0600 | [diff] [blame] | 9613 | ASSERT_VK_SUCCESS(err); |
| 9614 | |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 9615 | VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9616 | pipe_ms_state_ci.sType = |
| 9617 | VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO; |
| 9618 | pipe_ms_state_ci.pNext = NULL; |
| 9619 | pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT; |
| 9620 | pipe_ms_state_ci.sampleShadingEnable = 0; |
| 9621 | pipe_ms_state_ci.minSampleShading = 1.0; |
| 9622 | pipe_ms_state_ci.pSampleMask = NULL; |
Tobin Ehlis | 502480b | 2015-06-24 15:53:07 -0600 | [diff] [blame] | 9623 | |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 9624 | VkPipelineLayoutCreateInfo pipeline_layout_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9625 | pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO; |
| 9626 | pipeline_layout_ci.pNext = NULL; |
| 9627 | pipeline_layout_ci.setLayoutCount = 1; |
| 9628 | pipeline_layout_ci.pSetLayouts = &ds_layout; |
| 9629 | VkPipelineLayout pipeline_layout; |
Tobin Ehlis | 502480b | 2015-06-24 15:53:07 -0600 | [diff] [blame] | 9630 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9631 | err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, |
| 9632 | &pipeline_layout); |
Tobin Ehlis | 502480b | 2015-06-24 15:53:07 -0600 | [diff] [blame] | 9633 | ASSERT_VK_SUCCESS(err); |
| 9634 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9635 | VkShaderObj vs(m_device, bindStateVertShaderText, |
| 9636 | VK_SHADER_STAGE_VERTEX_BIT, this); |
| 9637 | VkShaderObj fs(m_device, bindStateFragShaderText, |
| 9638 | VK_SHADER_STAGE_FRAGMENT_BIT, |
Karl Schultz | bdb7595 | 2016-04-19 11:36:49 -0600 | [diff] [blame] | 9639 | this); // We shouldn't need a fragment shader |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9640 | // but add it to be able to run on more devices |
Tony Barbour | 62e1a5b | 2015-08-06 10:16:07 -0600 | [diff] [blame] | 9641 | VkPipelineObj pipe(m_device); |
| 9642 | pipe.AddShader(&vs); |
Tony Barbour | 1c94d37 | 2015-08-06 11:21:08 -0600 | [diff] [blame] | 9643 | pipe.AddShader(&fs); |
Mark Young | c89c631 | 2016-03-31 16:03:20 -0600 | [diff] [blame] | 9644 | pipe.AddColorAttachment(); |
Tony Barbour | 62e1a5b | 2015-08-06 10:16:07 -0600 | [diff] [blame] | 9645 | pipe.SetMSAA(&pipe_ms_state_ci); |
Tobin Ehlis | d332f28 | 2015-10-02 11:00:56 -0600 | [diff] [blame] | 9646 | pipe.SetViewport(m_viewports); |
| 9647 | pipe.SetScissor(m_scissors); |
Tony Barbour | 62e1a5b | 2015-08-06 10:16:07 -0600 | [diff] [blame] | 9648 | pipe.CreateVKPipeline(pipeline_layout, renderPass()); |
Tony Barbour | fe3351b | 2015-07-28 10:17:20 -0600 | [diff] [blame] | 9649 | |
| 9650 | BeginCommandBuffer(); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9651 | vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), |
| 9652 | VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle()); |
Tobin Ehlis | f7bf450 | 2015-09-09 15:12:35 -0600 | [diff] [blame] | 9653 | // Don't care about actual data, just need to get to draw to flag error |
| 9654 | static const float vbo_data[3] = {1.f, 0.f, 1.f}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9655 | VkConstantBufferObj vbo(m_device, sizeof(vbo_data), sizeof(float), |
| 9656 | (const void *)&vbo_data); |
Tobin Ehlis | f7bf450 | 2015-09-09 15:12:35 -0600 | [diff] [blame] | 9657 | BindVertexBuffer(&vbo, (VkDeviceSize)0, 1); // VBO idx 1, but no VBO in PSO |
Courtney Goeltzenleuchter | 08c2637 | 2015-09-23 12:31:50 -0600 | [diff] [blame] | 9658 | Draw(1, 0, 0, 0); |
Tobin Ehlis | 502480b | 2015-06-24 15:53:07 -0600 | [diff] [blame] | 9659 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 9660 | m_errorMonitor->VerifyFound(); |
Mike Stroyan | d1c84a5 | 2015-08-18 14:40:24 -0600 | [diff] [blame] | 9661 | |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 9662 | vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL); |
| 9663 | vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL); |
| 9664 | vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL); |
Tobin Ehlis | 502480b | 2015-06-24 15:53:07 -0600 | [diff] [blame] | 9665 | } |
Tobin Ehlis | c555a3c | 2016-05-04 14:08:34 -0600 | [diff] [blame] | 9666 | // INVALID_IMAGE_LAYOUT tests (one other case is hit by MapMemWithoutHostVisibleBit and not here) |
| 9667 | TEST_F(VkLayerTest, InvalidImageLayout) { |
| 9668 | TEST_DESCRIPTION("Hit all possible validation checks associated with the " |
| 9669 | "DRAWSTATE_INVALID_IMAGE_LAYOUT enum. Generally these involve having" |
| 9670 | "images in the wrong layout when they're copied or transitioned."); |
| 9671 | // 3 in ValidateCmdBufImageLayouts |
| 9672 | // * -1 Attempt to submit cmd buf w/ deleted image |
| 9673 | // * -2 Cmd buf submit of image w/ layout not matching first use w/ subresource |
| 9674 | // * -3 Cmd buf submit of image w/ layout not matching first use w/o subresource |
| 9675 | m_errorMonitor->SetDesiredFailureMsg( |
| 9676 | VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, |
| 9677 | "Layout for input image should be TRANSFER_SRC_OPTIMAL instead of GENERAL."); |
| 9678 | |
| 9679 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 9680 | // Create src & dst images to use for copy operations |
| 9681 | VkImage src_image; |
| 9682 | VkImage dst_image; |
| 9683 | |
| 9684 | const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM; |
| 9685 | const int32_t tex_width = 32; |
| 9686 | const int32_t tex_height = 32; |
| 9687 | |
| 9688 | VkImageCreateInfo image_create_info = {}; |
| 9689 | image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO; |
| 9690 | image_create_info.pNext = NULL; |
| 9691 | image_create_info.imageType = VK_IMAGE_TYPE_2D; |
| 9692 | image_create_info.format = tex_format; |
| 9693 | image_create_info.extent.width = tex_width; |
| 9694 | image_create_info.extent.height = tex_height; |
| 9695 | image_create_info.extent.depth = 1; |
| 9696 | image_create_info.mipLevels = 1; |
| 9697 | image_create_info.arrayLayers = 4; |
| 9698 | image_create_info.samples = VK_SAMPLE_COUNT_1_BIT; |
| 9699 | image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL; |
| 9700 | image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT; |
| 9701 | image_create_info.flags = 0; |
| 9702 | |
| 9703 | VkResult err = vkCreateImage(m_device->device(), &image_create_info, NULL, &src_image); |
| 9704 | ASSERT_VK_SUCCESS(err); |
| 9705 | err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dst_image); |
| 9706 | ASSERT_VK_SUCCESS(err); |
| 9707 | |
| 9708 | BeginCommandBuffer(); |
| 9709 | VkImageCopy copyRegion; |
| 9710 | copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; |
| 9711 | copyRegion.srcSubresource.mipLevel = 0; |
| 9712 | copyRegion.srcSubresource.baseArrayLayer = 0; |
| 9713 | copyRegion.srcSubresource.layerCount = 1; |
| 9714 | copyRegion.srcOffset.x = 0; |
| 9715 | copyRegion.srcOffset.y = 0; |
| 9716 | copyRegion.srcOffset.z = 0; |
| 9717 | copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; |
| 9718 | copyRegion.dstSubresource.mipLevel = 0; |
| 9719 | copyRegion.dstSubresource.baseArrayLayer = 0; |
| 9720 | copyRegion.dstSubresource.layerCount = 1; |
| 9721 | copyRegion.dstOffset.x = 0; |
| 9722 | copyRegion.dstOffset.y = 0; |
| 9723 | copyRegion.dstOffset.z = 0; |
| 9724 | copyRegion.extent.width = 1; |
| 9725 | copyRegion.extent.height = 1; |
| 9726 | copyRegion.extent.depth = 1; |
| 9727 | m_commandBuffer->CopyImage(src_image, VK_IMAGE_LAYOUT_GENERAL, dst_image, VK_IMAGE_LAYOUT_GENERAL, 1, ©Region); |
| 9728 | m_errorMonitor->VerifyFound(); |
| 9729 | // Now cause error due to src image layout changing |
| 9730 | m_errorMonitor->SetDesiredFailureMsg( |
| 9731 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 9732 | "Cannot copy from an image whose source layout is VK_IMAGE_LAYOUT_UNDEFINED and doesn't match the current layout VK_IMAGE_LAYOUT_GENERAL."); |
| 9733 | m_commandBuffer->CopyImage(src_image, VK_IMAGE_LAYOUT_UNDEFINED, dst_image, VK_IMAGE_LAYOUT_GENERAL, 1, ©Region); |
| 9734 | m_errorMonitor->VerifyFound(); |
| 9735 | // Final src error is due to bad layout type |
| 9736 | m_errorMonitor->SetDesiredFailureMsg( |
| 9737 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 9738 | "Layout for input image is VK_IMAGE_LAYOUT_UNDEFINED but can only be TRANSFER_SRC_OPTIMAL or GENERAL."); |
| 9739 | m_commandBuffer->CopyImage(src_image, VK_IMAGE_LAYOUT_UNDEFINED, dst_image, VK_IMAGE_LAYOUT_GENERAL, 1, ©Region); |
| 9740 | m_errorMonitor->VerifyFound(); |
| 9741 | // Now verify same checks for dst |
| 9742 | m_errorMonitor->SetDesiredFailureMsg( |
| 9743 | VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, |
| 9744 | "Layout for output image should be TRANSFER_DST_OPTIMAL instead of GENERAL."); |
| 9745 | m_commandBuffer->CopyImage(src_image, VK_IMAGE_LAYOUT_GENERAL, dst_image, VK_IMAGE_LAYOUT_GENERAL, 1, ©Region); |
| 9746 | m_errorMonitor->VerifyFound(); |
| 9747 | // Now cause error due to src image layout changing |
| 9748 | m_errorMonitor->SetDesiredFailureMsg( |
| 9749 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 9750 | "Cannot copy from an image whose dest layout is VK_IMAGE_LAYOUT_UNDEFINED and doesn't match the current layout VK_IMAGE_LAYOUT_GENERAL."); |
| 9751 | m_commandBuffer->CopyImage(src_image, VK_IMAGE_LAYOUT_GENERAL, dst_image, VK_IMAGE_LAYOUT_UNDEFINED, 1, ©Region); |
| 9752 | m_errorMonitor->VerifyFound(); |
| 9753 | m_errorMonitor->SetDesiredFailureMsg( |
| 9754 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 9755 | "Layout for output image is VK_IMAGE_LAYOUT_UNDEFINED but can only be TRANSFER_DST_OPTIMAL or GENERAL."); |
| 9756 | m_commandBuffer->CopyImage(src_image, VK_IMAGE_LAYOUT_GENERAL, dst_image, VK_IMAGE_LAYOUT_UNDEFINED, 1, ©Region); |
| 9757 | m_errorMonitor->VerifyFound(); |
| 9758 | // Now cause error due to bad image layout transition in PipelineBarrier |
| 9759 | VkImageMemoryBarrier image_barrier[1] = {}; |
| 9760 | image_barrier[0].oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL; |
| 9761 | image_barrier[0].image = src_image; |
| 9762 | image_barrier[0].subresourceRange.layerCount = 2; |
| 9763 | image_barrier[0].subresourceRange.levelCount = 2; |
| 9764 | image_barrier[0].subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; |
| 9765 | m_errorMonitor->SetDesiredFailureMsg( |
| 9766 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 9767 | "You cannot transition the layout from VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL when current layout is VK_IMAGE_LAYOUT_GENERAL."); |
| 9768 | vkCmdPipelineBarrier(m_commandBuffer->handle(), VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, NULL, 0, NULL, 1, image_barrier); |
| 9769 | m_errorMonitor->VerifyFound(); |
| 9770 | |
| 9771 | // Finally some layout errors at RenderPass create time |
| 9772 | // Just hacking in specific state to get to the errors we want so don't copy this unless you know what you're doing. |
| 9773 | VkAttachmentReference attach = {}; |
| 9774 | // perf warning for GENERAL layout w/ non-DS input attachment |
| 9775 | attach.layout = VK_IMAGE_LAYOUT_GENERAL; |
| 9776 | VkSubpassDescription subpass = {}; |
| 9777 | subpass.inputAttachmentCount = 1; |
| 9778 | subpass.pInputAttachments = &attach; |
| 9779 | VkRenderPassCreateInfo rpci = {}; |
| 9780 | rpci.subpassCount = 1; |
| 9781 | rpci.pSubpasses = &subpass; |
| 9782 | rpci.attachmentCount = 1; |
| 9783 | VkAttachmentDescription attach_desc = {}; |
| 9784 | attach_desc.format = VK_FORMAT_UNDEFINED; |
| 9785 | rpci.pAttachments = &attach_desc; |
Tobin Ehlis | 1efce02 | 2016-05-11 10:40:34 -0600 | [diff] [blame] | 9786 | rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO; |
Tobin Ehlis | c555a3c | 2016-05-04 14:08:34 -0600 | [diff] [blame] | 9787 | VkRenderPass rp; |
| 9788 | m_errorMonitor->SetDesiredFailureMsg( |
| 9789 | VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, |
| 9790 | "Layout for input attachment is GENERAL but should be READ_ONLY_OPTIMAL."); |
| 9791 | vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp); |
| 9792 | m_errorMonitor->VerifyFound(); |
| 9793 | // error w/ non-general layout |
| 9794 | attach.layout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL; |
| 9795 | |
| 9796 | m_errorMonitor->SetDesiredFailureMsg( |
| 9797 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 9798 | "Layout for input attachment is VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL but can only be READ_ONLY_OPTIMAL or GENERAL."); |
| 9799 | vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp); |
| 9800 | m_errorMonitor->VerifyFound(); |
| 9801 | subpass.inputAttachmentCount = 0; |
| 9802 | subpass.colorAttachmentCount = 1; |
| 9803 | subpass.pColorAttachments = &attach; |
| 9804 | attach.layout = VK_IMAGE_LAYOUT_GENERAL; |
| 9805 | // perf warning for GENERAL layout on color attachment |
| 9806 | m_errorMonitor->SetDesiredFailureMsg( |
| 9807 | VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, |
| 9808 | "Layout for color attachment is GENERAL but should be COLOR_ATTACHMENT_OPTIMAL."); |
| 9809 | vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp); |
| 9810 | m_errorMonitor->VerifyFound(); |
| 9811 | // error w/ non-color opt or GENERAL layout for color attachment |
| 9812 | attach.layout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL; |
| 9813 | m_errorMonitor->SetDesiredFailureMsg( |
| 9814 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 9815 | "Layout for color attachment is VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL but can only be COLOR_ATTACHMENT_OPTIMAL or GENERAL."); |
| 9816 | vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp); |
| 9817 | m_errorMonitor->VerifyFound(); |
| 9818 | subpass.colorAttachmentCount = 0; |
| 9819 | subpass.pDepthStencilAttachment = &attach; |
| 9820 | attach.layout = VK_IMAGE_LAYOUT_GENERAL; |
| 9821 | // perf warning for GENERAL layout on DS attachment |
| 9822 | m_errorMonitor->SetDesiredFailureMsg( |
| 9823 | VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, |
| 9824 | "Layout for depth attachment is GENERAL but should be DEPTH_STENCIL_ATTACHMENT_OPTIMAL."); |
| 9825 | vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp); |
| 9826 | m_errorMonitor->VerifyFound(); |
| 9827 | // error w/ non-ds opt or GENERAL layout for color attachment |
| 9828 | attach.layout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL; |
| 9829 | m_errorMonitor->SetDesiredFailureMsg( |
| 9830 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 9831 | "Layout for depth attachment is VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL but can only be DEPTH_STENCIL_ATTACHMENT_OPTIMAL or GENERAL."); |
| 9832 | vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp); |
| 9833 | m_errorMonitor->VerifyFound(); |
Tobin Ehlis | 1efce02 | 2016-05-11 10:40:34 -0600 | [diff] [blame] | 9834 | // For this error we need a valid renderpass so create default one |
| 9835 | attach.layout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL; |
| 9836 | attach.attachment = 0; |
| 9837 | attach_desc.format = VK_FORMAT_D24_UNORM_S8_UINT; |
| 9838 | attach_desc.samples = VK_SAMPLE_COUNT_1_BIT; |
| 9839 | attach_desc.storeOp = VK_ATTACHMENT_STORE_OP_STORE; |
| 9840 | attach_desc.stencilLoadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE; |
| 9841 | attach_desc.stencilStoreOp = VK_ATTACHMENT_STORE_OP_DONT_CARE; |
| 9842 | // Can't do a CLEAR load on READ_ONLY initialLayout |
| 9843 | attach_desc.loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR; |
| 9844 | attach_desc.initialLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL; |
| 9845 | attach_desc.finalLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL; |
| 9846 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 9847 | " with invalid first layout " |
| 9848 | "VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_" |
| 9849 | "ONLY_OPTIMAL"); |
| 9850 | vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp); |
| 9851 | m_errorMonitor->VerifyFound(); |
Tobin Ehlis | c555a3c | 2016-05-04 14:08:34 -0600 | [diff] [blame] | 9852 | |
| 9853 | vkDestroyImage(m_device->device(), src_image, NULL); |
| 9854 | vkDestroyImage(m_device->device(), dst_image, NULL); |
| 9855 | } |
Mark Lobodzinski | 209b529 | 2015-09-17 09:44:05 -0600 | [diff] [blame] | 9856 | #endif // DRAW_STATE_TESTS |
| 9857 | |
Tobin Ehlis | 0788f52 | 2015-05-26 16:11:58 -0600 | [diff] [blame] | 9858 | #if THREADING_TESTS |
Mike Stroyan | accf769 | 2015-05-12 16:00:45 -0600 | [diff] [blame] | 9859 | #if GTEST_IS_THREADSAFE |
| 9860 | struct thread_data_struct { |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 9861 | VkCommandBuffer commandBuffer; |
Mike Stroyan | accf769 | 2015-05-12 16:00:45 -0600 | [diff] [blame] | 9862 | VkEvent event; |
| 9863 | bool bailout; |
| 9864 | }; |
| 9865 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9866 | extern "C" void *AddToCommandBuffer(void *arg) { |
| 9867 | struct thread_data_struct *data = (struct thread_data_struct *)arg; |
Mike Stroyan | accf769 | 2015-05-12 16:00:45 -0600 | [diff] [blame] | 9868 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9869 | for (int i = 0; i < 10000; i++) { |
| 9870 | vkCmdSetEvent(data->commandBuffer, data->event, |
| 9871 | VK_PIPELINE_STAGE_ALL_COMMANDS_BIT); |
Mike Stroyan | accf769 | 2015-05-12 16:00:45 -0600 | [diff] [blame] | 9872 | if (data->bailout) { |
| 9873 | break; |
| 9874 | } |
| 9875 | } |
| 9876 | return NULL; |
| 9877 | } |
| 9878 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9879 | TEST_F(VkLayerTest, ThreadCommandBufferCollision) { |
Mike Stroyan | 4268d1f | 2015-07-13 14:45:35 -0600 | [diff] [blame] | 9880 | test_platform_thread thread; |
Mike Stroyan | accf769 | 2015-05-12 16:00:45 -0600 | [diff] [blame] | 9881 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9882 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 9883 | "THREADING ERROR"); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 9884 | |
Mike Stroyan | accf769 | 2015-05-12 16:00:45 -0600 | [diff] [blame] | 9885 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 9886 | ASSERT_NO_FATAL_FAILURE(InitViewport()); |
| 9887 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 9888 | |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 9889 | // Calls AllocateCommandBuffers |
| 9890 | VkCommandBufferObj commandBuffer(m_device, m_commandPool); |
Mark Lobodzinski | 5495d13 | 2015-09-30 16:19:16 -0600 | [diff] [blame] | 9891 | |
| 9892 | // Avoid creating RenderPass |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 9893 | commandBuffer.BeginCommandBuffer(); |
Mike Stroyan | accf769 | 2015-05-12 16:00:45 -0600 | [diff] [blame] | 9894 | |
| 9895 | VkEventCreateInfo event_info; |
| 9896 | VkEvent event; |
Mike Stroyan | accf769 | 2015-05-12 16:00:45 -0600 | [diff] [blame] | 9897 | VkResult err; |
| 9898 | |
| 9899 | memset(&event_info, 0, sizeof(event_info)); |
| 9900 | event_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO; |
| 9901 | |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 9902 | err = vkCreateEvent(device(), &event_info, NULL, &event); |
Mike Stroyan | accf769 | 2015-05-12 16:00:45 -0600 | [diff] [blame] | 9903 | ASSERT_VK_SUCCESS(err); |
| 9904 | |
Mike Stroyan | accf769 | 2015-05-12 16:00:45 -0600 | [diff] [blame] | 9905 | err = vkResetEvent(device(), event); |
| 9906 | ASSERT_VK_SUCCESS(err); |
| 9907 | |
| 9908 | struct thread_data_struct data; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 9909 | data.commandBuffer = commandBuffer.GetBufferHandle(); |
Mike Stroyan | accf769 | 2015-05-12 16:00:45 -0600 | [diff] [blame] | 9910 | data.event = event; |
| 9911 | data.bailout = false; |
| 9912 | m_errorMonitor->SetBailout(&data.bailout); |
| 9913 | // Add many entries to command buffer from another thread. |
Mike Stroyan | 4268d1f | 2015-07-13 14:45:35 -0600 | [diff] [blame] | 9914 | test_platform_thread_create(&thread, AddToCommandBuffer, (void *)&data); |
Mike Stroyan | accf769 | 2015-05-12 16:00:45 -0600 | [diff] [blame] | 9915 | // Add many entries to command buffer from this thread at the same time. |
| 9916 | AddToCommandBuffer(&data); |
Mark Lobodzinski | 5495d13 | 2015-09-30 16:19:16 -0600 | [diff] [blame] | 9917 | |
Mike Stroyan | 4268d1f | 2015-07-13 14:45:35 -0600 | [diff] [blame] | 9918 | test_platform_thread_join(thread, NULL); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 9919 | commandBuffer.EndCommandBuffer(); |
Mike Stroyan | accf769 | 2015-05-12 16:00:45 -0600 | [diff] [blame] | 9920 | |
Mike Stroyan | 10b8cb7 | 2016-01-22 15:22:03 -0700 | [diff] [blame] | 9921 | m_errorMonitor->SetBailout(NULL); |
| 9922 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 9923 | m_errorMonitor->VerifyFound(); |
Mike Stroyan | accf769 | 2015-05-12 16:00:45 -0600 | [diff] [blame] | 9924 | |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 9925 | vkDestroyEvent(device(), event, NULL); |
Mike Stroyan | accf769 | 2015-05-12 16:00:45 -0600 | [diff] [blame] | 9926 | } |
Mark Lobodzinski | 209b529 | 2015-09-17 09:44:05 -0600 | [diff] [blame] | 9927 | #endif // GTEST_IS_THREADSAFE |
| 9928 | #endif // THREADING_TESTS |
| 9929 | |
Chris Forbes | 9f7ff63 | 2015-05-25 11:13:08 +1200 | [diff] [blame] | 9930 | #if SHADER_CHECKER_TESTS |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9931 | TEST_F(VkLayerTest, InvalidSPIRVCodeSize) { |
Courtney Goeltzenleuchter | 7415d5a | 2015-12-09 15:48:16 -0700 | [diff] [blame] | 9932 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Chris Forbes | b4afd0f | 2016-04-04 10:48:35 +1200 | [diff] [blame] | 9933 | "Invalid SPIR-V header"); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 9934 | |
Courtney Goeltzenleuchter | 00c52b2 | 2015-09-16 12:58:29 -0600 | [diff] [blame] | 9935 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 9936 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 9937 | |
Courtney Goeltzenleuchter | 00c52b2 | 2015-09-16 12:58:29 -0600 | [diff] [blame] | 9938 | VkShaderModule module; |
| 9939 | VkShaderModuleCreateInfo moduleCreateInfo; |
| 9940 | struct icd_spv_header spv; |
| 9941 | |
| 9942 | spv.magic = ICD_SPV_MAGIC; |
| 9943 | spv.version = ICD_SPV_VERSION; |
| 9944 | spv.gen_magic = 0; |
| 9945 | |
| 9946 | moduleCreateInfo.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO; |
| 9947 | moduleCreateInfo.pNext = NULL; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9948 | moduleCreateInfo.pCode = (const uint32_t *)&spv; |
Courtney Goeltzenleuchter | 00c52b2 | 2015-09-16 12:58:29 -0600 | [diff] [blame] | 9949 | moduleCreateInfo.codeSize = 4; |
| 9950 | moduleCreateInfo.flags = 0; |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 9951 | vkCreateShaderModule(m_device->device(), &moduleCreateInfo, NULL, &module); |
Courtney Goeltzenleuchter | 00c52b2 | 2015-09-16 12:58:29 -0600 | [diff] [blame] | 9952 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 9953 | m_errorMonitor->VerifyFound(); |
Courtney Goeltzenleuchter | 00c52b2 | 2015-09-16 12:58:29 -0600 | [diff] [blame] | 9954 | } |
| 9955 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9956 | TEST_F(VkLayerTest, InvalidSPIRVMagic) { |
Courtney Goeltzenleuchter | 7415d5a | 2015-12-09 15:48:16 -0700 | [diff] [blame] | 9957 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Chris Forbes | b4afd0f | 2016-04-04 10:48:35 +1200 | [diff] [blame] | 9958 | "Invalid SPIR-V magic number"); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 9959 | |
Courtney Goeltzenleuchter | 00c52b2 | 2015-09-16 12:58:29 -0600 | [diff] [blame] | 9960 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 9961 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 9962 | |
Courtney Goeltzenleuchter | 00c52b2 | 2015-09-16 12:58:29 -0600 | [diff] [blame] | 9963 | VkShaderModule module; |
| 9964 | VkShaderModuleCreateInfo moduleCreateInfo; |
| 9965 | struct icd_spv_header spv; |
| 9966 | |
| 9967 | spv.magic = ~ICD_SPV_MAGIC; |
| 9968 | spv.version = ICD_SPV_VERSION; |
| 9969 | spv.gen_magic = 0; |
| 9970 | |
| 9971 | moduleCreateInfo.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO; |
| 9972 | moduleCreateInfo.pNext = NULL; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9973 | moduleCreateInfo.pCode = (const uint32_t *)&spv; |
Courtney Goeltzenleuchter | 00c52b2 | 2015-09-16 12:58:29 -0600 | [diff] [blame] | 9974 | moduleCreateInfo.codeSize = sizeof(spv) + 10; |
| 9975 | moduleCreateInfo.flags = 0; |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 9976 | vkCreateShaderModule(m_device->device(), &moduleCreateInfo, NULL, &module); |
Courtney Goeltzenleuchter | 00c52b2 | 2015-09-16 12:58:29 -0600 | [diff] [blame] | 9977 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 9978 | m_errorMonitor->VerifyFound(); |
Courtney Goeltzenleuchter | 00c52b2 | 2015-09-16 12:58:29 -0600 | [diff] [blame] | 9979 | } |
| 9980 | |
Chris Forbes | b4afd0f | 2016-04-04 10:48:35 +1200 | [diff] [blame] | 9981 | #if 0 |
| 9982 | // Not currently covered by SPIRV-Tools validator |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9983 | TEST_F(VkLayerTest, InvalidSPIRVVersion) { |
Courtney Goeltzenleuchter | 7415d5a | 2015-12-09 15:48:16 -0700 | [diff] [blame] | 9984 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Chris Forbes | b4afd0f | 2016-04-04 10:48:35 +1200 | [diff] [blame] | 9985 | "Invalid SPIR-V header"); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 9986 | |
Courtney Goeltzenleuchter | 00c52b2 | 2015-09-16 12:58:29 -0600 | [diff] [blame] | 9987 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 9988 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 9989 | |
Courtney Goeltzenleuchter | 00c52b2 | 2015-09-16 12:58:29 -0600 | [diff] [blame] | 9990 | VkShaderModule module; |
| 9991 | VkShaderModuleCreateInfo moduleCreateInfo; |
| 9992 | struct icd_spv_header spv; |
| 9993 | |
| 9994 | spv.magic = ICD_SPV_MAGIC; |
| 9995 | spv.version = ~ICD_SPV_VERSION; |
| 9996 | spv.gen_magic = 0; |
| 9997 | |
| 9998 | moduleCreateInfo.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO; |
| 9999 | moduleCreateInfo.pNext = NULL; |
| 10000 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 10001 | moduleCreateInfo.pCode = (const uint32_t *)&spv; |
Courtney Goeltzenleuchter | 00c52b2 | 2015-09-16 12:58:29 -0600 | [diff] [blame] | 10002 | moduleCreateInfo.codeSize = sizeof(spv) + 10; |
| 10003 | moduleCreateInfo.flags = 0; |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 10004 | vkCreateShaderModule(m_device->device(), &moduleCreateInfo, NULL, &module); |
Courtney Goeltzenleuchter | 00c52b2 | 2015-09-16 12:58:29 -0600 | [diff] [blame] | 10005 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 10006 | m_errorMonitor->VerifyFound(); |
Courtney Goeltzenleuchter | 00c52b2 | 2015-09-16 12:58:29 -0600 | [diff] [blame] | 10007 | } |
Chris Forbes | b4afd0f | 2016-04-04 10:48:35 +1200 | [diff] [blame] | 10008 | #endif |
Courtney Goeltzenleuchter | 00c52b2 | 2015-09-16 12:58:29 -0600 | [diff] [blame] | 10009 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 10010 | TEST_F(VkLayerTest, CreatePipelineVertexOutputNotConsumed) { |
Mark Lobodzinski | 510e20d | 2016-02-11 09:26:16 -0700 | [diff] [blame] | 10011 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 10012 | "not consumed by fragment shader"); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 10013 | |
Chris Forbes | 9f7ff63 | 2015-05-25 11:13:08 +1200 | [diff] [blame] | 10014 | ASSERT_NO_FATAL_FAILURE(InitState()); |
Tobin Ehlis | c9ac2b6 | 2015-09-11 12:57:55 -0600 | [diff] [blame] | 10015 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
Chris Forbes | 9f7ff63 | 2015-05-25 11:13:08 +1200 | [diff] [blame] | 10016 | |
| 10017 | char const *vsSource = |
Chris Forbes | 3846771 | 2016-04-04 17:28:05 +1200 | [diff] [blame] | 10018 | "#version 450\n" |
Chris Forbes | 9f7ff63 | 2015-05-25 11:13:08 +1200 | [diff] [blame] | 10019 | "\n" |
| 10020 | "layout(location=0) out float x;\n" |
Tony Barbour | e804d20 | 2016-01-05 13:37:45 -0700 | [diff] [blame] | 10021 | "out gl_PerVertex {\n" |
| 10022 | " vec4 gl_Position;\n" |
| 10023 | "};\n" |
Chris Forbes | 9f7ff63 | 2015-05-25 11:13:08 +1200 | [diff] [blame] | 10024 | "void main(){\n" |
| 10025 | " gl_Position = vec4(1);\n" |
| 10026 | " x = 0;\n" |
| 10027 | "}\n"; |
| 10028 | char const *fsSource = |
Chris Forbes | 3846771 | 2016-04-04 17:28:05 +1200 | [diff] [blame] | 10029 | "#version 450\n" |
Chris Forbes | 9f7ff63 | 2015-05-25 11:13:08 +1200 | [diff] [blame] | 10030 | "\n" |
| 10031 | "layout(location=0) out vec4 color;\n" |
| 10032 | "void main(){\n" |
| 10033 | " color = vec4(1);\n" |
| 10034 | "}\n"; |
| 10035 | |
Courtney Goeltzenleuchter | d263550 | 2015-10-21 17:08:06 -0600 | [diff] [blame] | 10036 | VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this); |
| 10037 | VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this); |
Chris Forbes | 9f7ff63 | 2015-05-25 11:13:08 +1200 | [diff] [blame] | 10038 | |
| 10039 | VkPipelineObj pipe(m_device); |
Chia-I Wu | 08accc6 | 2015-07-07 11:50:03 +0800 | [diff] [blame] | 10040 | pipe.AddColorAttachment(); |
Chris Forbes | 9f7ff63 | 2015-05-25 11:13:08 +1200 | [diff] [blame] | 10041 | pipe.AddShader(&vs); |
| 10042 | pipe.AddShader(&fs); |
| 10043 | |
Chris Forbes | 9f7ff63 | 2015-05-25 11:13:08 +1200 | [diff] [blame] | 10044 | VkDescriptorSetObj descriptorSet(m_device); |
| 10045 | descriptorSet.AppendDummy(); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 10046 | descriptorSet.CreateVKDescriptorSet(m_commandBuffer); |
Chris Forbes | 9f7ff63 | 2015-05-25 11:13:08 +1200 | [diff] [blame] | 10047 | |
Tony Barbour | 5781e8f | 2015-08-04 16:23:11 -0600 | [diff] [blame] | 10048 | pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass()); |
Chris Forbes | 9f7ff63 | 2015-05-25 11:13:08 +1200 | [diff] [blame] | 10049 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 10050 | m_errorMonitor->VerifyFound(); |
Chris Forbes | 9f7ff63 | 2015-05-25 11:13:08 +1200 | [diff] [blame] | 10051 | } |
Chris Forbes | 9f7ff63 | 2015-05-25 11:13:08 +1200 | [diff] [blame] | 10052 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 10053 | TEST_F(VkLayerTest, CreatePipelineFragmentInputNotProvided) { |
Courtney Goeltzenleuchter | 7415d5a | 2015-12-09 15:48:16 -0700 | [diff] [blame] | 10054 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 10055 | "not written by vertex shader"); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 10056 | |
Chris Forbes | 59cb88d | 2015-05-25 11:13:13 +1200 | [diff] [blame] | 10057 | ASSERT_NO_FATAL_FAILURE(InitState()); |
Tobin Ehlis | c9ac2b6 | 2015-09-11 12:57:55 -0600 | [diff] [blame] | 10058 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
Chris Forbes | 59cb88d | 2015-05-25 11:13:13 +1200 | [diff] [blame] | 10059 | |
| 10060 | char const *vsSource = |
Chris Forbes | 3846771 | 2016-04-04 17:28:05 +1200 | [diff] [blame] | 10061 | "#version 450\n" |
Chris Forbes | 59cb88d | 2015-05-25 11:13:13 +1200 | [diff] [blame] | 10062 | "\n" |
Tony Barbour | e804d20 | 2016-01-05 13:37:45 -0700 | [diff] [blame] | 10063 | "out gl_PerVertex {\n" |
| 10064 | " vec4 gl_Position;\n" |
| 10065 | "};\n" |
Chris Forbes | 59cb88d | 2015-05-25 11:13:13 +1200 | [diff] [blame] | 10066 | "void main(){\n" |
| 10067 | " gl_Position = vec4(1);\n" |
| 10068 | "}\n"; |
| 10069 | char const *fsSource = |
Chris Forbes | 3846771 | 2016-04-04 17:28:05 +1200 | [diff] [blame] | 10070 | "#version 450\n" |
Chris Forbes | 59cb88d | 2015-05-25 11:13:13 +1200 | [diff] [blame] | 10071 | "\n" |
| 10072 | "layout(location=0) in float x;\n" |
| 10073 | "layout(location=0) out vec4 color;\n" |
| 10074 | "void main(){\n" |
| 10075 | " color = vec4(x);\n" |
| 10076 | "}\n"; |
| 10077 | |
Courtney Goeltzenleuchter | d263550 | 2015-10-21 17:08:06 -0600 | [diff] [blame] | 10078 | VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this); |
| 10079 | VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this); |
Chris Forbes | 59cb88d | 2015-05-25 11:13:13 +1200 | [diff] [blame] | 10080 | |
| 10081 | VkPipelineObj pipe(m_device); |
Chia-I Wu | 08accc6 | 2015-07-07 11:50:03 +0800 | [diff] [blame] | 10082 | pipe.AddColorAttachment(); |
Chris Forbes | 59cb88d | 2015-05-25 11:13:13 +1200 | [diff] [blame] | 10083 | pipe.AddShader(&vs); |
| 10084 | pipe.AddShader(&fs); |
| 10085 | |
Chris Forbes | 59cb88d | 2015-05-25 11:13:13 +1200 | [diff] [blame] | 10086 | VkDescriptorSetObj descriptorSet(m_device); |
| 10087 | descriptorSet.AppendDummy(); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 10088 | descriptorSet.CreateVKDescriptorSet(m_commandBuffer); |
Chris Forbes | 59cb88d | 2015-05-25 11:13:13 +1200 | [diff] [blame] | 10089 | |
Tony Barbour | 5781e8f | 2015-08-04 16:23:11 -0600 | [diff] [blame] | 10090 | pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass()); |
Chris Forbes | 59cb88d | 2015-05-25 11:13:13 +1200 | [diff] [blame] | 10091 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 10092 | m_errorMonitor->VerifyFound(); |
Chris Forbes | 59cb88d | 2015-05-25 11:13:13 +1200 | [diff] [blame] | 10093 | } |
| 10094 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 10095 | TEST_F(VkLayerTest, CreatePipelineFragmentInputNotProvidedInBlock) { |
Chris Forbes | a3e85f6 | 2016-01-15 14:53:11 +1300 | [diff] [blame] | 10096 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 10097 | "not written by vertex shader"); |
Chris Forbes | a3e85f6 | 2016-01-15 14:53:11 +1300 | [diff] [blame] | 10098 | |
| 10099 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 10100 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 10101 | |
| 10102 | char const *vsSource = |
Chris Forbes | 3846771 | 2016-04-04 17:28:05 +1200 | [diff] [blame] | 10103 | "#version 450\n" |
Chris Forbes | a3e85f6 | 2016-01-15 14:53:11 +1300 | [diff] [blame] | 10104 | "\n" |
| 10105 | "out gl_PerVertex {\n" |
| 10106 | " vec4 gl_Position;\n" |
| 10107 | "};\n" |
| 10108 | "void main(){\n" |
| 10109 | " gl_Position = vec4(1);\n" |
| 10110 | "}\n"; |
| 10111 | char const *fsSource = |
| 10112 | "#version 450\n" |
Chris Forbes | a3e85f6 | 2016-01-15 14:53:11 +1300 | [diff] [blame] | 10113 | "\n" |
| 10114 | "in block { layout(location=0) float x; } ins;\n" |
| 10115 | "layout(location=0) out vec4 color;\n" |
| 10116 | "void main(){\n" |
| 10117 | " color = vec4(ins.x);\n" |
| 10118 | "}\n"; |
| 10119 | |
| 10120 | VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this); |
| 10121 | VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this); |
| 10122 | |
| 10123 | VkPipelineObj pipe(m_device); |
| 10124 | pipe.AddColorAttachment(); |
| 10125 | pipe.AddShader(&vs); |
| 10126 | pipe.AddShader(&fs); |
| 10127 | |
| 10128 | VkDescriptorSetObj descriptorSet(m_device); |
| 10129 | descriptorSet.AppendDummy(); |
| 10130 | descriptorSet.CreateVKDescriptorSet(m_commandBuffer); |
| 10131 | |
| 10132 | pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass()); |
| 10133 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 10134 | m_errorMonitor->VerifyFound(); |
Chris Forbes | a3e85f6 | 2016-01-15 14:53:11 +1300 | [diff] [blame] | 10135 | } |
| 10136 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 10137 | TEST_F(VkLayerTest, CreatePipelineVsFsTypeMismatchArraySize) { |
Chris Forbes | 0036fd1 | 2016-01-26 14:19:49 +1300 | [diff] [blame] | 10138 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Chris Forbes | e992882 | 2016-02-17 14:44:52 +1300 | [diff] [blame] | 10139 | "Type mismatch on location 0.0: 'ptr to " |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 10140 | "output arr[2] of float32' vs 'ptr to " |
| 10141 | "input arr[3] of float32'"); |
Chris Forbes | 0036fd1 | 2016-01-26 14:19:49 +1300 | [diff] [blame] | 10142 | |
| 10143 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 10144 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 10145 | |
| 10146 | char const *vsSource = |
Chris Forbes | 3846771 | 2016-04-04 17:28:05 +1200 | [diff] [blame] | 10147 | "#version 450\n" |
Chris Forbes | 0036fd1 | 2016-01-26 14:19:49 +1300 | [diff] [blame] | 10148 | "\n" |
| 10149 | "layout(location=0) out float x[2];\n" |
| 10150 | "out gl_PerVertex {\n" |
| 10151 | " vec4 gl_Position;\n" |
| 10152 | "};\n" |
| 10153 | "void main(){\n" |
| 10154 | " x[0] = 0; x[1] = 0;\n" |
| 10155 | " gl_Position = vec4(1);\n" |
| 10156 | "}\n"; |
| 10157 | char const *fsSource = |
Chris Forbes | 3846771 | 2016-04-04 17:28:05 +1200 | [diff] [blame] | 10158 | "#version 450\n" |
Chris Forbes | 0036fd1 | 2016-01-26 14:19:49 +1300 | [diff] [blame] | 10159 | "\n" |
| 10160 | "layout(location=0) in float x[3];\n" |
| 10161 | "layout(location=0) out vec4 color;\n" |
| 10162 | "void main(){\n" |
| 10163 | " color = vec4(x[0] + x[1] + x[2]);\n" |
| 10164 | "}\n"; |
| 10165 | |
| 10166 | VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this); |
| 10167 | VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this); |
| 10168 | |
| 10169 | VkPipelineObj pipe(m_device); |
| 10170 | pipe.AddColorAttachment(); |
| 10171 | pipe.AddShader(&vs); |
| 10172 | pipe.AddShader(&fs); |
| 10173 | |
| 10174 | VkDescriptorSetObj descriptorSet(m_device); |
| 10175 | descriptorSet.AppendDummy(); |
| 10176 | descriptorSet.CreateVKDescriptorSet(m_commandBuffer); |
| 10177 | |
| 10178 | pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass()); |
| 10179 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 10180 | m_errorMonitor->VerifyFound(); |
Chris Forbes | 0036fd1 | 2016-01-26 14:19:49 +1300 | [diff] [blame] | 10181 | } |
| 10182 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 10183 | TEST_F(VkLayerTest, CreatePipelineVsFsTypeMismatch) { |
Courtney Goeltzenleuchter | 7415d5a | 2015-12-09 15:48:16 -0700 | [diff] [blame] | 10184 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 10185 | "Type mismatch on location 0"); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 10186 | |
Chris Forbes | b56af56 | 2015-05-25 11:13:17 +1200 | [diff] [blame] | 10187 | ASSERT_NO_FATAL_FAILURE(InitState()); |
Tobin Ehlis | c9ac2b6 | 2015-09-11 12:57:55 -0600 | [diff] [blame] | 10188 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
Chris Forbes | b56af56 | 2015-05-25 11:13:17 +1200 | [diff] [blame] | 10189 | |
| 10190 | char const *vsSource = |
Chris Forbes | 3846771 | 2016-04-04 17:28:05 +1200 | [diff] [blame] | 10191 | "#version 450\n" |
Chris Forbes | b56af56 | 2015-05-25 11:13:17 +1200 | [diff] [blame] | 10192 | "\n" |
| 10193 | "layout(location=0) out int x;\n" |
Tony Barbour | e804d20 | 2016-01-05 13:37:45 -0700 | [diff] [blame] | 10194 | "out gl_PerVertex {\n" |
| 10195 | " vec4 gl_Position;\n" |
| 10196 | "};\n" |
Chris Forbes | b56af56 | 2015-05-25 11:13:17 +1200 | [diff] [blame] | 10197 | "void main(){\n" |
| 10198 | " x = 0;\n" |
| 10199 | " gl_Position = vec4(1);\n" |
| 10200 | "}\n"; |
| 10201 | char const *fsSource = |
Chris Forbes | 3846771 | 2016-04-04 17:28:05 +1200 | [diff] [blame] | 10202 | "#version 450\n" |
Chris Forbes | b56af56 | 2015-05-25 11:13:17 +1200 | [diff] [blame] | 10203 | "\n" |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 10204 | "layout(location=0) in float x;\n" /* VS writes int */ |
Chris Forbes | b56af56 | 2015-05-25 11:13:17 +1200 | [diff] [blame] | 10205 | "layout(location=0) out vec4 color;\n" |
| 10206 | "void main(){\n" |
| 10207 | " color = vec4(x);\n" |
| 10208 | "}\n"; |
| 10209 | |
Courtney Goeltzenleuchter | d263550 | 2015-10-21 17:08:06 -0600 | [diff] [blame] | 10210 | VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this); |
| 10211 | VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this); |
Chris Forbes | b56af56 | 2015-05-25 11:13:17 +1200 | [diff] [blame] | 10212 | |
| 10213 | VkPipelineObj pipe(m_device); |
Chia-I Wu | 08accc6 | 2015-07-07 11:50:03 +0800 | [diff] [blame] | 10214 | pipe.AddColorAttachment(); |
Chris Forbes | b56af56 | 2015-05-25 11:13:17 +1200 | [diff] [blame] | 10215 | pipe.AddShader(&vs); |
| 10216 | pipe.AddShader(&fs); |
| 10217 | |
Chris Forbes | b56af56 | 2015-05-25 11:13:17 +1200 | [diff] [blame] | 10218 | VkDescriptorSetObj descriptorSet(m_device); |
| 10219 | descriptorSet.AppendDummy(); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 10220 | descriptorSet.CreateVKDescriptorSet(m_commandBuffer); |
Chris Forbes | b56af56 | 2015-05-25 11:13:17 +1200 | [diff] [blame] | 10221 | |
Tony Barbour | 5781e8f | 2015-08-04 16:23:11 -0600 | [diff] [blame] | 10222 | pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass()); |
Chris Forbes | b56af56 | 2015-05-25 11:13:17 +1200 | [diff] [blame] | 10223 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 10224 | m_errorMonitor->VerifyFound(); |
Chris Forbes | b56af56 | 2015-05-25 11:13:17 +1200 | [diff] [blame] | 10225 | } |
| 10226 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 10227 | TEST_F(VkLayerTest, CreatePipelineVsFsTypeMismatchInBlock) { |
Chris Forbes | a3e85f6 | 2016-01-15 14:53:11 +1300 | [diff] [blame] | 10228 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 10229 | "Type mismatch on location 0"); |
Chris Forbes | a3e85f6 | 2016-01-15 14:53:11 +1300 | [diff] [blame] | 10230 | |
| 10231 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 10232 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 10233 | |
| 10234 | char const *vsSource = |
| 10235 | "#version 450\n" |
Chris Forbes | a3e85f6 | 2016-01-15 14:53:11 +1300 | [diff] [blame] | 10236 | "\n" |
| 10237 | "out block { layout(location=0) int x; } outs;\n" |
| 10238 | "out gl_PerVertex {\n" |
| 10239 | " vec4 gl_Position;\n" |
| 10240 | "};\n" |
| 10241 | "void main(){\n" |
| 10242 | " outs.x = 0;\n" |
| 10243 | " gl_Position = vec4(1);\n" |
| 10244 | "}\n"; |
| 10245 | char const *fsSource = |
| 10246 | "#version 450\n" |
Chris Forbes | a3e85f6 | 2016-01-15 14:53:11 +1300 | [diff] [blame] | 10247 | "\n" |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 10248 | "in block { layout(location=0) float x; } ins;\n" /* VS writes int */ |
Chris Forbes | a3e85f6 | 2016-01-15 14:53:11 +1300 | [diff] [blame] | 10249 | "layout(location=0) out vec4 color;\n" |
| 10250 | "void main(){\n" |
| 10251 | " color = vec4(ins.x);\n" |
| 10252 | "}\n"; |
| 10253 | |
| 10254 | VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this); |
| 10255 | VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this); |
| 10256 | |
| 10257 | VkPipelineObj pipe(m_device); |
| 10258 | pipe.AddColorAttachment(); |
| 10259 | pipe.AddShader(&vs); |
| 10260 | pipe.AddShader(&fs); |
| 10261 | |
| 10262 | VkDescriptorSetObj descriptorSet(m_device); |
| 10263 | descriptorSet.AppendDummy(); |
| 10264 | descriptorSet.CreateVKDescriptorSet(m_commandBuffer); |
| 10265 | |
| 10266 | pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass()); |
| 10267 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 10268 | m_errorMonitor->VerifyFound(); |
Chris Forbes | e992882 | 2016-02-17 14:44:52 +1300 | [diff] [blame] | 10269 | } |
| 10270 | |
| 10271 | TEST_F(VkLayerTest, CreatePipelineVsFsMismatchByLocation) { |
| 10272 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 10273 | "location 0.0 which is not written by vertex shader"); |
| 10274 | |
| 10275 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 10276 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 10277 | |
| 10278 | char const *vsSource = |
| 10279 | "#version 450\n" |
Chris Forbes | e992882 | 2016-02-17 14:44:52 +1300 | [diff] [blame] | 10280 | "\n" |
| 10281 | "out block { layout(location=1) float x; } outs;\n" |
| 10282 | "out gl_PerVertex {\n" |
| 10283 | " vec4 gl_Position;\n" |
| 10284 | "};\n" |
| 10285 | "void main(){\n" |
| 10286 | " outs.x = 0;\n" |
| 10287 | " gl_Position = vec4(1);\n" |
| 10288 | "}\n"; |
| 10289 | char const *fsSource = |
| 10290 | "#version 450\n" |
Chris Forbes | e992882 | 2016-02-17 14:44:52 +1300 | [diff] [blame] | 10291 | "\n" |
| 10292 | "in block { layout(location=0) float x; } ins;\n" |
| 10293 | "layout(location=0) out vec4 color;\n" |
| 10294 | "void main(){\n" |
| 10295 | " color = vec4(ins.x);\n" |
| 10296 | "}\n"; |
| 10297 | |
| 10298 | VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this); |
| 10299 | VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this); |
| 10300 | |
| 10301 | VkPipelineObj pipe(m_device); |
| 10302 | pipe.AddColorAttachment(); |
| 10303 | pipe.AddShader(&vs); |
| 10304 | pipe.AddShader(&fs); |
| 10305 | |
| 10306 | VkDescriptorSetObj descriptorSet(m_device); |
| 10307 | descriptorSet.AppendDummy(); |
| 10308 | descriptorSet.CreateVKDescriptorSet(m_commandBuffer); |
| 10309 | |
| 10310 | pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass()); |
| 10311 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 10312 | m_errorMonitor->VerifyFound(); |
Chris Forbes | e992882 | 2016-02-17 14:44:52 +1300 | [diff] [blame] | 10313 | } |
| 10314 | |
| 10315 | TEST_F(VkLayerTest, CreatePipelineVsFsMismatchByComponent) { |
| 10316 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 10317 | "location 0.1 which is not written by vertex shader"); |
| 10318 | |
| 10319 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 10320 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 10321 | |
| 10322 | char const *vsSource = |
| 10323 | "#version 450\n" |
Chris Forbes | e992882 | 2016-02-17 14:44:52 +1300 | [diff] [blame] | 10324 | "\n" |
| 10325 | "out block { layout(location=0, component=0) float x; } outs;\n" |
| 10326 | "out gl_PerVertex {\n" |
| 10327 | " vec4 gl_Position;\n" |
| 10328 | "};\n" |
| 10329 | "void main(){\n" |
| 10330 | " outs.x = 0;\n" |
| 10331 | " gl_Position = vec4(1);\n" |
| 10332 | "}\n"; |
| 10333 | char const *fsSource = |
| 10334 | "#version 450\n" |
Chris Forbes | e992882 | 2016-02-17 14:44:52 +1300 | [diff] [blame] | 10335 | "\n" |
| 10336 | "in block { layout(location=0, component=1) float x; } ins;\n" |
| 10337 | "layout(location=0) out vec4 color;\n" |
| 10338 | "void main(){\n" |
| 10339 | " color = vec4(ins.x);\n" |
| 10340 | "}\n"; |
| 10341 | |
| 10342 | VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this); |
| 10343 | VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this); |
| 10344 | |
| 10345 | VkPipelineObj pipe(m_device); |
| 10346 | pipe.AddColorAttachment(); |
| 10347 | pipe.AddShader(&vs); |
| 10348 | pipe.AddShader(&fs); |
| 10349 | |
| 10350 | VkDescriptorSetObj descriptorSet(m_device); |
| 10351 | descriptorSet.AppendDummy(); |
| 10352 | descriptorSet.CreateVKDescriptorSet(m_commandBuffer); |
| 10353 | |
| 10354 | pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass()); |
| 10355 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 10356 | m_errorMonitor->VerifyFound(); |
Chris Forbes | a3e85f6 | 2016-01-15 14:53:11 +1300 | [diff] [blame] | 10357 | } |
| 10358 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 10359 | TEST_F(VkLayerTest, CreatePipelineAttribNotConsumed) { |
Mark Lobodzinski | 510e20d | 2016-02-11 09:26:16 -0700 | [diff] [blame] | 10360 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 10361 | "location 0 not consumed by VS"); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 10362 | |
Chris Forbes | de136e0 | 2015-05-25 11:13:28 +1200 | [diff] [blame] | 10363 | ASSERT_NO_FATAL_FAILURE(InitState()); |
Tobin Ehlis | c9ac2b6 | 2015-09-11 12:57:55 -0600 | [diff] [blame] | 10364 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
Chris Forbes | de136e0 | 2015-05-25 11:13:28 +1200 | [diff] [blame] | 10365 | |
| 10366 | VkVertexInputBindingDescription input_binding; |
| 10367 | memset(&input_binding, 0, sizeof(input_binding)); |
| 10368 | |
| 10369 | VkVertexInputAttributeDescription input_attrib; |
| 10370 | memset(&input_attrib, 0, sizeof(input_attrib)); |
| 10371 | input_attrib.format = VK_FORMAT_R32_SFLOAT; |
| 10372 | |
| 10373 | char const *vsSource = |
Chris Forbes | 3846771 | 2016-04-04 17:28:05 +1200 | [diff] [blame] | 10374 | "#version 450\n" |
Chris Forbes | de136e0 | 2015-05-25 11:13:28 +1200 | [diff] [blame] | 10375 | "\n" |
Tony Barbour | e804d20 | 2016-01-05 13:37:45 -0700 | [diff] [blame] | 10376 | "out gl_PerVertex {\n" |
| 10377 | " vec4 gl_Position;\n" |
| 10378 | "};\n" |
Chris Forbes | de136e0 | 2015-05-25 11:13:28 +1200 | [diff] [blame] | 10379 | "void main(){\n" |
| 10380 | " gl_Position = vec4(1);\n" |
| 10381 | "}\n"; |
| 10382 | char const *fsSource = |
Chris Forbes | 3846771 | 2016-04-04 17:28:05 +1200 | [diff] [blame] | 10383 | "#version 450\n" |
Chris Forbes | de136e0 | 2015-05-25 11:13:28 +1200 | [diff] [blame] | 10384 | "\n" |
| 10385 | "layout(location=0) out vec4 color;\n" |
| 10386 | "void main(){\n" |
| 10387 | " color = vec4(1);\n" |
| 10388 | "}\n"; |
| 10389 | |
Courtney Goeltzenleuchter | d263550 | 2015-10-21 17:08:06 -0600 | [diff] [blame] | 10390 | VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this); |
| 10391 | VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this); |
Chris Forbes | de136e0 | 2015-05-25 11:13:28 +1200 | [diff] [blame] | 10392 | |
| 10393 | VkPipelineObj pipe(m_device); |
Chia-I Wu | 08accc6 | 2015-07-07 11:50:03 +0800 | [diff] [blame] | 10394 | pipe.AddColorAttachment(); |
Chris Forbes | de136e0 | 2015-05-25 11:13:28 +1200 | [diff] [blame] | 10395 | pipe.AddShader(&vs); |
| 10396 | pipe.AddShader(&fs); |
| 10397 | |
| 10398 | pipe.AddVertexInputBindings(&input_binding, 1); |
| 10399 | pipe.AddVertexInputAttribs(&input_attrib, 1); |
| 10400 | |
Chris Forbes | de136e0 | 2015-05-25 11:13:28 +1200 | [diff] [blame] | 10401 | VkDescriptorSetObj descriptorSet(m_device); |
| 10402 | descriptorSet.AppendDummy(); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 10403 | descriptorSet.CreateVKDescriptorSet(m_commandBuffer); |
Chris Forbes | de136e0 | 2015-05-25 11:13:28 +1200 | [diff] [blame] | 10404 | |
Tony Barbour | 5781e8f | 2015-08-04 16:23:11 -0600 | [diff] [blame] | 10405 | pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass()); |
Chris Forbes | de136e0 | 2015-05-25 11:13:28 +1200 | [diff] [blame] | 10406 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 10407 | m_errorMonitor->VerifyFound(); |
Chris Forbes | de136e0 | 2015-05-25 11:13:28 +1200 | [diff] [blame] | 10408 | } |
| 10409 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 10410 | TEST_F(VkLayerTest, CreatePipelineAttribLocationMismatch) { |
Mark Lobodzinski | 510e20d | 2016-02-11 09:26:16 -0700 | [diff] [blame] | 10411 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 10412 | "location 0 not consumed by VS"); |
Chris Forbes | 7d83cd5 | 2016-01-15 11:32:03 +1300 | [diff] [blame] | 10413 | |
| 10414 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 10415 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 10416 | |
| 10417 | VkVertexInputBindingDescription input_binding; |
| 10418 | memset(&input_binding, 0, sizeof(input_binding)); |
| 10419 | |
| 10420 | VkVertexInputAttributeDescription input_attrib; |
| 10421 | memset(&input_attrib, 0, sizeof(input_attrib)); |
| 10422 | input_attrib.format = VK_FORMAT_R32_SFLOAT; |
| 10423 | |
| 10424 | char const *vsSource = |
Chris Forbes | 3846771 | 2016-04-04 17:28:05 +1200 | [diff] [blame] | 10425 | "#version 450\n" |
Chris Forbes | 7d83cd5 | 2016-01-15 11:32:03 +1300 | [diff] [blame] | 10426 | "\n" |
| 10427 | "layout(location=1) in float x;\n" |
| 10428 | "out gl_PerVertex {\n" |
| 10429 | " vec4 gl_Position;\n" |
| 10430 | "};\n" |
| 10431 | "void main(){\n" |
| 10432 | " gl_Position = vec4(x);\n" |
| 10433 | "}\n"; |
| 10434 | char const *fsSource = |
Chris Forbes | 3846771 | 2016-04-04 17:28:05 +1200 | [diff] [blame] | 10435 | "#version 450\n" |
Chris Forbes | 7d83cd5 | 2016-01-15 11:32:03 +1300 | [diff] [blame] | 10436 | "\n" |
| 10437 | "layout(location=0) out vec4 color;\n" |
| 10438 | "void main(){\n" |
| 10439 | " color = vec4(1);\n" |
| 10440 | "}\n"; |
| 10441 | |
| 10442 | VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this); |
| 10443 | VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this); |
| 10444 | |
| 10445 | VkPipelineObj pipe(m_device); |
| 10446 | pipe.AddColorAttachment(); |
| 10447 | pipe.AddShader(&vs); |
| 10448 | pipe.AddShader(&fs); |
| 10449 | |
| 10450 | pipe.AddVertexInputBindings(&input_binding, 1); |
| 10451 | pipe.AddVertexInputAttribs(&input_attrib, 1); |
| 10452 | |
| 10453 | VkDescriptorSetObj descriptorSet(m_device); |
| 10454 | descriptorSet.AppendDummy(); |
| 10455 | descriptorSet.CreateVKDescriptorSet(m_commandBuffer); |
| 10456 | |
| 10457 | pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass()); |
| 10458 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 10459 | m_errorMonitor->VerifyFound(); |
Chris Forbes | 7d83cd5 | 2016-01-15 11:32:03 +1300 | [diff] [blame] | 10460 | } |
| 10461 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 10462 | TEST_F(VkLayerTest, CreatePipelineAttribNotProvided) { |
| 10463 | m_errorMonitor->SetDesiredFailureMsg( |
| 10464 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 10465 | "VS consumes input at location 0 but not provided"); |
| 10466 | |
Chris Forbes | 62e8e50 | 2015-05-25 11:13:29 +1200 | [diff] [blame] | 10467 | ASSERT_NO_FATAL_FAILURE(InitState()); |
Tobin Ehlis | c9ac2b6 | 2015-09-11 12:57:55 -0600 | [diff] [blame] | 10468 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
Chris Forbes | 62e8e50 | 2015-05-25 11:13:29 +1200 | [diff] [blame] | 10469 | |
| 10470 | char const *vsSource = |
Chris Forbes | 3846771 | 2016-04-04 17:28:05 +1200 | [diff] [blame] | 10471 | "#version 450\n" |
Chris Forbes | 62e8e50 | 2015-05-25 11:13:29 +1200 | [diff] [blame] | 10472 | "\n" |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 10473 | "layout(location=0) in vec4 x;\n" /* not provided */ |
Tony Barbour | e804d20 | 2016-01-05 13:37:45 -0700 | [diff] [blame] | 10474 | "out gl_PerVertex {\n" |
| 10475 | " vec4 gl_Position;\n" |
| 10476 | "};\n" |
Chris Forbes | 62e8e50 | 2015-05-25 11:13:29 +1200 | [diff] [blame] | 10477 | "void main(){\n" |
| 10478 | " gl_Position = x;\n" |
| 10479 | "}\n"; |
| 10480 | char const *fsSource = |
Chris Forbes | 3846771 | 2016-04-04 17:28:05 +1200 | [diff] [blame] | 10481 | "#version 450\n" |
Chris Forbes | 62e8e50 | 2015-05-25 11:13:29 +1200 | [diff] [blame] | 10482 | "\n" |
| 10483 | "layout(location=0) out vec4 color;\n" |
| 10484 | "void main(){\n" |
| 10485 | " color = vec4(1);\n" |
| 10486 | "}\n"; |
| 10487 | |
Courtney Goeltzenleuchter | d263550 | 2015-10-21 17:08:06 -0600 | [diff] [blame] | 10488 | VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this); |
| 10489 | VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this); |
Chris Forbes | 62e8e50 | 2015-05-25 11:13:29 +1200 | [diff] [blame] | 10490 | |
| 10491 | VkPipelineObj pipe(m_device); |
Chia-I Wu | 08accc6 | 2015-07-07 11:50:03 +0800 | [diff] [blame] | 10492 | pipe.AddColorAttachment(); |
Chris Forbes | 62e8e50 | 2015-05-25 11:13:29 +1200 | [diff] [blame] | 10493 | pipe.AddShader(&vs); |
| 10494 | pipe.AddShader(&fs); |
| 10495 | |
Chris Forbes | 62e8e50 | 2015-05-25 11:13:29 +1200 | [diff] [blame] | 10496 | VkDescriptorSetObj descriptorSet(m_device); |
| 10497 | descriptorSet.AppendDummy(); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 10498 | descriptorSet.CreateVKDescriptorSet(m_commandBuffer); |
Chris Forbes | 62e8e50 | 2015-05-25 11:13:29 +1200 | [diff] [blame] | 10499 | |
Tony Barbour | 5781e8f | 2015-08-04 16:23:11 -0600 | [diff] [blame] | 10500 | pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass()); |
Chris Forbes | 62e8e50 | 2015-05-25 11:13:29 +1200 | [diff] [blame] | 10501 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 10502 | m_errorMonitor->VerifyFound(); |
Chris Forbes | 62e8e50 | 2015-05-25 11:13:29 +1200 | [diff] [blame] | 10503 | } |
| 10504 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 10505 | TEST_F(VkLayerTest, CreatePipelineAttribTypeMismatch) { |
| 10506 | m_errorMonitor->SetDesiredFailureMsg( |
| 10507 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 10508 | "location 0 does not match VS input type"); |
| 10509 | |
Chris Forbes | c97d98e | 2015-05-25 11:13:31 +1200 | [diff] [blame] | 10510 | ASSERT_NO_FATAL_FAILURE(InitState()); |
Tobin Ehlis | c9ac2b6 | 2015-09-11 12:57:55 -0600 | [diff] [blame] | 10511 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
Chris Forbes | c97d98e | 2015-05-25 11:13:31 +1200 | [diff] [blame] | 10512 | |
| 10513 | VkVertexInputBindingDescription input_binding; |
| 10514 | memset(&input_binding, 0, sizeof(input_binding)); |
| 10515 | |
| 10516 | VkVertexInputAttributeDescription input_attrib; |
| 10517 | memset(&input_attrib, 0, sizeof(input_attrib)); |
| 10518 | input_attrib.format = VK_FORMAT_R32_SFLOAT; |
| 10519 | |
| 10520 | char const *vsSource = |
Chris Forbes | 3846771 | 2016-04-04 17:28:05 +1200 | [diff] [blame] | 10521 | "#version 450\n" |
Chris Forbes | c97d98e | 2015-05-25 11:13:31 +1200 | [diff] [blame] | 10522 | "\n" |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 10523 | "layout(location=0) in int x;\n" /* attrib provided float */ |
Tony Barbour | e804d20 | 2016-01-05 13:37:45 -0700 | [diff] [blame] | 10524 | "out gl_PerVertex {\n" |
| 10525 | " vec4 gl_Position;\n" |
| 10526 | "};\n" |
Chris Forbes | c97d98e | 2015-05-25 11:13:31 +1200 | [diff] [blame] | 10527 | "void main(){\n" |
| 10528 | " gl_Position = vec4(x);\n" |
| 10529 | "}\n"; |
| 10530 | char const *fsSource = |
Chris Forbes | 3846771 | 2016-04-04 17:28:05 +1200 | [diff] [blame] | 10531 | "#version 450\n" |
Chris Forbes | c97d98e | 2015-05-25 11:13:31 +1200 | [diff] [blame] | 10532 | "\n" |
| 10533 | "layout(location=0) out vec4 color;\n" |
| 10534 | "void main(){\n" |
| 10535 | " color = vec4(1);\n" |
| 10536 | "}\n"; |
| 10537 | |
Courtney Goeltzenleuchter | d263550 | 2015-10-21 17:08:06 -0600 | [diff] [blame] | 10538 | VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this); |
| 10539 | VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this); |
Chris Forbes | c97d98e | 2015-05-25 11:13:31 +1200 | [diff] [blame] | 10540 | |
| 10541 | VkPipelineObj pipe(m_device); |
Chia-I Wu | 08accc6 | 2015-07-07 11:50:03 +0800 | [diff] [blame] | 10542 | pipe.AddColorAttachment(); |
Chris Forbes | c97d98e | 2015-05-25 11:13:31 +1200 | [diff] [blame] | 10543 | pipe.AddShader(&vs); |
| 10544 | pipe.AddShader(&fs); |
| 10545 | |
| 10546 | pipe.AddVertexInputBindings(&input_binding, 1); |
| 10547 | pipe.AddVertexInputAttribs(&input_attrib, 1); |
| 10548 | |
Chris Forbes | c97d98e | 2015-05-25 11:13:31 +1200 | [diff] [blame] | 10549 | VkDescriptorSetObj descriptorSet(m_device); |
| 10550 | descriptorSet.AppendDummy(); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 10551 | descriptorSet.CreateVKDescriptorSet(m_commandBuffer); |
Chris Forbes | c97d98e | 2015-05-25 11:13:31 +1200 | [diff] [blame] | 10552 | |
Tony Barbour | 5781e8f | 2015-08-04 16:23:11 -0600 | [diff] [blame] | 10553 | pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass()); |
Chris Forbes | c97d98e | 2015-05-25 11:13:31 +1200 | [diff] [blame] | 10554 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 10555 | m_errorMonitor->VerifyFound(); |
Chris Forbes | c97d98e | 2015-05-25 11:13:31 +1200 | [diff] [blame] | 10556 | } |
| 10557 | |
Chris Forbes | c68b43c | 2016-04-06 11:18:47 +1200 | [diff] [blame] | 10558 | TEST_F(VkLayerTest, CreatePipelineDuplicateStage) { |
| 10559 | m_errorMonitor->SetDesiredFailureMsg( |
| 10560 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 10561 | "Multiple shaders provided for stage VK_SHADER_STAGE_VERTEX_BIT"); |
| 10562 | |
| 10563 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 10564 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 10565 | |
| 10566 | char const *vsSource = |
| 10567 | "#version 450\n" |
| 10568 | "\n" |
| 10569 | "out gl_PerVertex {\n" |
| 10570 | " vec4 gl_Position;\n" |
| 10571 | "};\n" |
| 10572 | "void main(){\n" |
| 10573 | " gl_Position = vec4(1);\n" |
| 10574 | "}\n"; |
| 10575 | char const *fsSource = |
| 10576 | "#version 450\n" |
| 10577 | "\n" |
| 10578 | "layout(location=0) out vec4 color;\n" |
| 10579 | "void main(){\n" |
| 10580 | " color = vec4(1);\n" |
| 10581 | "}\n"; |
| 10582 | |
| 10583 | VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this); |
| 10584 | VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this); |
| 10585 | |
| 10586 | VkPipelineObj pipe(m_device); |
| 10587 | pipe.AddColorAttachment(); |
| 10588 | pipe.AddShader(&vs); |
| 10589 | pipe.AddShader(&vs); |
| 10590 | pipe.AddShader(&fs); |
| 10591 | |
| 10592 | VkDescriptorSetObj descriptorSet(m_device); |
| 10593 | descriptorSet.AppendDummy(); |
| 10594 | descriptorSet.CreateVKDescriptorSet(m_commandBuffer); |
| 10595 | |
| 10596 | pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass()); |
| 10597 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 10598 | m_errorMonitor->VerifyFound(); |
Chris Forbes | c68b43c | 2016-04-06 11:18:47 +1200 | [diff] [blame] | 10599 | } |
| 10600 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 10601 | TEST_F(VkLayerTest, CreatePipelineAttribMatrixType) { |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 10602 | m_errorMonitor->ExpectSuccess(); |
Chris Forbes | 2682b24 | 2015-11-24 11:13:14 +1300 | [diff] [blame] | 10603 | |
| 10604 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 10605 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 10606 | |
| 10607 | VkVertexInputBindingDescription input_binding; |
| 10608 | memset(&input_binding, 0, sizeof(input_binding)); |
| 10609 | |
| 10610 | VkVertexInputAttributeDescription input_attribs[2]; |
| 10611 | memset(input_attribs, 0, sizeof(input_attribs)); |
| 10612 | |
| 10613 | for (int i = 0; i < 2; i++) { |
| 10614 | input_attribs[i].format = VK_FORMAT_R32G32B32A32_SFLOAT; |
| 10615 | input_attribs[i].location = i; |
| 10616 | } |
| 10617 | |
| 10618 | char const *vsSource = |
Chris Forbes | 3846771 | 2016-04-04 17:28:05 +1200 | [diff] [blame] | 10619 | "#version 450\n" |
Chris Forbes | 2682b24 | 2015-11-24 11:13:14 +1300 | [diff] [blame] | 10620 | "\n" |
| 10621 | "layout(location=0) in mat2x4 x;\n" |
Tony Barbour | e804d20 | 2016-01-05 13:37:45 -0700 | [diff] [blame] | 10622 | "out gl_PerVertex {\n" |
| 10623 | " vec4 gl_Position;\n" |
| 10624 | "};\n" |
Chris Forbes | 2682b24 | 2015-11-24 11:13:14 +1300 | [diff] [blame] | 10625 | "void main(){\n" |
| 10626 | " gl_Position = x[0] + x[1];\n" |
| 10627 | "}\n"; |
| 10628 | char const *fsSource = |
Chris Forbes | 3846771 | 2016-04-04 17:28:05 +1200 | [diff] [blame] | 10629 | "#version 450\n" |
Chris Forbes | 2682b24 | 2015-11-24 11:13:14 +1300 | [diff] [blame] | 10630 | "\n" |
| 10631 | "layout(location=0) out vec4 color;\n" |
| 10632 | "void main(){\n" |
| 10633 | " color = vec4(1);\n" |
| 10634 | "}\n"; |
| 10635 | |
| 10636 | VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this); |
| 10637 | VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this); |
| 10638 | |
| 10639 | VkPipelineObj pipe(m_device); |
| 10640 | pipe.AddColorAttachment(); |
| 10641 | pipe.AddShader(&vs); |
| 10642 | pipe.AddShader(&fs); |
| 10643 | |
| 10644 | pipe.AddVertexInputBindings(&input_binding, 1); |
| 10645 | pipe.AddVertexInputAttribs(input_attribs, 2); |
| 10646 | |
| 10647 | VkDescriptorSetObj descriptorSet(m_device); |
| 10648 | descriptorSet.AppendDummy(); |
| 10649 | descriptorSet.CreateVKDescriptorSet(m_commandBuffer); |
| 10650 | |
| 10651 | pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass()); |
| 10652 | |
| 10653 | /* expect success */ |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 10654 | m_errorMonitor->VerifyNotFound(); |
Chris Forbes | 2682b24 | 2015-11-24 11:13:14 +1300 | [diff] [blame] | 10655 | } |
| 10656 | |
Chris Forbes | 2682b24 | 2015-11-24 11:13:14 +1300 | [diff] [blame] | 10657 | TEST_F(VkLayerTest, CreatePipelineAttribArrayType) |
| 10658 | { |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 10659 | m_errorMonitor->ExpectSuccess(); |
Chris Forbes | 2682b24 | 2015-11-24 11:13:14 +1300 | [diff] [blame] | 10660 | |
| 10661 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 10662 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 10663 | |
| 10664 | VkVertexInputBindingDescription input_binding; |
| 10665 | memset(&input_binding, 0, sizeof(input_binding)); |
| 10666 | |
| 10667 | VkVertexInputAttributeDescription input_attribs[2]; |
| 10668 | memset(input_attribs, 0, sizeof(input_attribs)); |
| 10669 | |
| 10670 | for (int i = 0; i < 2; i++) { |
| 10671 | input_attribs[i].format = VK_FORMAT_R32G32B32A32_SFLOAT; |
| 10672 | input_attribs[i].location = i; |
| 10673 | } |
| 10674 | |
| 10675 | char const *vsSource = |
Chris Forbes | 3846771 | 2016-04-04 17:28:05 +1200 | [diff] [blame] | 10676 | "#version 450\n" |
Chris Forbes | 2682b24 | 2015-11-24 11:13:14 +1300 | [diff] [blame] | 10677 | "\n" |
| 10678 | "layout(location=0) in vec4 x[2];\n" |
Tony Barbour | e804d20 | 2016-01-05 13:37:45 -0700 | [diff] [blame] | 10679 | "out gl_PerVertex {\n" |
| 10680 | " vec4 gl_Position;\n" |
| 10681 | "};\n" |
Chris Forbes | 2682b24 | 2015-11-24 11:13:14 +1300 | [diff] [blame] | 10682 | "void main(){\n" |
| 10683 | " gl_Position = x[0] + x[1];\n" |
| 10684 | "}\n"; |
| 10685 | char const *fsSource = |
Chris Forbes | 3846771 | 2016-04-04 17:28:05 +1200 | [diff] [blame] | 10686 | "#version 450\n" |
Chris Forbes | 2682b24 | 2015-11-24 11:13:14 +1300 | [diff] [blame] | 10687 | "\n" |
| 10688 | "layout(location=0) out vec4 color;\n" |
| 10689 | "void main(){\n" |
| 10690 | " color = vec4(1);\n" |
| 10691 | "}\n"; |
| 10692 | |
| 10693 | VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this); |
| 10694 | VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this); |
| 10695 | |
| 10696 | VkPipelineObj pipe(m_device); |
| 10697 | pipe.AddColorAttachment(); |
| 10698 | pipe.AddShader(&vs); |
| 10699 | pipe.AddShader(&fs); |
| 10700 | |
| 10701 | pipe.AddVertexInputBindings(&input_binding, 1); |
| 10702 | pipe.AddVertexInputAttribs(input_attribs, 2); |
| 10703 | |
| 10704 | VkDescriptorSetObj descriptorSet(m_device); |
| 10705 | descriptorSet.AppendDummy(); |
| 10706 | descriptorSet.CreateVKDescriptorSet(m_commandBuffer); |
| 10707 | |
| 10708 | pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass()); |
| 10709 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 10710 | m_errorMonitor->VerifyNotFound(); |
Chris Forbes | 2682b24 | 2015-11-24 11:13:14 +1300 | [diff] [blame] | 10711 | } |
Chris Forbes | 2682b24 | 2015-11-24 11:13:14 +1300 | [diff] [blame] | 10712 | |
Chris Forbes | 4ea14fc | 2016-04-04 18:52:54 +1200 | [diff] [blame] | 10713 | TEST_F(VkLayerTest, CreatePipelineSimplePositive) |
| 10714 | { |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 10715 | m_errorMonitor->ExpectSuccess(); |
Chris Forbes | 4ea14fc | 2016-04-04 18:52:54 +1200 | [diff] [blame] | 10716 | |
| 10717 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 10718 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 10719 | |
| 10720 | char const *vsSource = |
| 10721 | "#version 450\n" |
| 10722 | "out gl_PerVertex {\n" |
| 10723 | " vec4 gl_Position;\n" |
| 10724 | "};\n" |
| 10725 | "void main(){\n" |
| 10726 | " gl_Position = vec4(0);\n" |
| 10727 | "}\n"; |
| 10728 | char const *fsSource = |
| 10729 | "#version 450\n" |
| 10730 | "\n" |
| 10731 | "layout(location=0) out vec4 color;\n" |
| 10732 | "void main(){\n" |
| 10733 | " color = vec4(1);\n" |
| 10734 | "}\n"; |
| 10735 | |
| 10736 | VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this); |
| 10737 | VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this); |
| 10738 | |
| 10739 | VkPipelineObj pipe(m_device); |
| 10740 | pipe.AddColorAttachment(); |
| 10741 | pipe.AddShader(&vs); |
| 10742 | pipe.AddShader(&fs); |
| 10743 | |
| 10744 | VkDescriptorSetObj descriptorSet(m_device); |
| 10745 | descriptorSet.AppendDummy(); |
| 10746 | descriptorSet.CreateVKDescriptorSet(m_commandBuffer); |
| 10747 | |
| 10748 | pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass()); |
| 10749 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 10750 | m_errorMonitor->VerifyNotFound(); |
Chris Forbes | 4ea14fc | 2016-04-04 18:52:54 +1200 | [diff] [blame] | 10751 | } |
| 10752 | |
Chris Forbes | 912c919 | 2016-04-05 17:50:35 +1200 | [diff] [blame] | 10753 | TEST_F(VkLayerTest, CreatePipelineRelaxedTypeMatch) |
| 10754 | { |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 10755 | m_errorMonitor->ExpectSuccess(); |
Chris Forbes | 912c919 | 2016-04-05 17:50:35 +1200 | [diff] [blame] | 10756 | |
| 10757 | // VK 1.0.8 Specification, 14.1.3 "Additionally,..." block |
| 10758 | |
| 10759 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 10760 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 10761 | |
| 10762 | char const *vsSource = |
| 10763 | "#version 450\n" |
| 10764 | "out gl_PerVertex {\n" |
| 10765 | " vec4 gl_Position;\n" |
| 10766 | "};\n" |
| 10767 | "layout(location=0) out vec3 x;\n" |
| 10768 | "layout(location=1) out ivec3 y;\n" |
| 10769 | "layout(location=2) out vec3 z;\n" |
| 10770 | "void main(){\n" |
| 10771 | " gl_Position = vec4(0);\n" |
| 10772 | " x = vec3(0); y = ivec3(0); z = vec3(0);\n" |
| 10773 | "}\n"; |
| 10774 | char const *fsSource = |
| 10775 | "#version 450\n" |
| 10776 | "\n" |
| 10777 | "layout(location=0) out vec4 color;\n" |
| 10778 | "layout(location=0) in float x;\n" |
| 10779 | "layout(location=1) flat in int y;\n" |
| 10780 | "layout(location=2) in vec2 z;\n" |
| 10781 | "void main(){\n" |
| 10782 | " color = vec4(1 + x + y + z.x);\n" |
| 10783 | "}\n"; |
| 10784 | |
| 10785 | VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this); |
| 10786 | VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this); |
| 10787 | |
| 10788 | VkPipelineObj pipe(m_device); |
| 10789 | pipe.AddColorAttachment(); |
| 10790 | pipe.AddShader(&vs); |
| 10791 | pipe.AddShader(&fs); |
| 10792 | |
| 10793 | VkDescriptorSetObj descriptorSet(m_device); |
| 10794 | descriptorSet.AppendDummy(); |
| 10795 | descriptorSet.CreateVKDescriptorSet(m_commandBuffer); |
| 10796 | |
| 10797 | pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass()); |
| 10798 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 10799 | m_errorMonitor->VerifyNotFound(); |
Chris Forbes | 912c919 | 2016-04-05 17:50:35 +1200 | [diff] [blame] | 10800 | } |
| 10801 | |
Chris Forbes | 4ea14fc | 2016-04-04 18:52:54 +1200 | [diff] [blame] | 10802 | TEST_F(VkLayerTest, CreatePipelineTessPerVertex) |
| 10803 | { |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 10804 | m_errorMonitor->ExpectSuccess(); |
Chris Forbes | 4ea14fc | 2016-04-04 18:52:54 +1200 | [diff] [blame] | 10805 | |
| 10806 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 10807 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 10808 | |
Chris Forbes | c1e852d | 2016-04-04 19:26:42 +1200 | [diff] [blame] | 10809 | if (!m_device->phy().features().tessellationShader) { |
| 10810 | printf("Device does not support tessellation shaders; skipped.\n"); |
| 10811 | return; |
| 10812 | } |
| 10813 | |
Chris Forbes | 4ea14fc | 2016-04-04 18:52:54 +1200 | [diff] [blame] | 10814 | char const *vsSource = |
| 10815 | "#version 450\n" |
| 10816 | "void main(){}\n"; |
| 10817 | char const *tcsSource = |
| 10818 | "#version 450\n" |
| 10819 | "layout(location=0) out int x[];\n" |
| 10820 | "layout(vertices=3) out;\n" |
| 10821 | "void main(){\n" |
| 10822 | " gl_TessLevelOuter[0] = gl_TessLevelOuter[1] = gl_TessLevelOuter[2] = 1;\n" |
| 10823 | " gl_TessLevelInner[0] = 1;\n" |
| 10824 | " x[gl_InvocationID] = gl_InvocationID;\n" |
| 10825 | "}\n"; |
| 10826 | char const *tesSource = |
| 10827 | "#version 450\n" |
| 10828 | "layout(triangles, equal_spacing, cw) in;\n" |
| 10829 | "layout(location=0) in int x[];\n" |
| 10830 | "out gl_PerVertex { vec4 gl_Position; };\n" |
| 10831 | "void main(){\n" |
| 10832 | " gl_Position.xyz = gl_TessCoord;\n" |
| 10833 | " gl_Position.w = x[0] + x[1] + x[2];\n" |
| 10834 | "}\n"; |
| 10835 | char const *fsSource = |
| 10836 | "#version 450\n" |
| 10837 | "layout(location=0) out vec4 color;\n" |
| 10838 | "void main(){\n" |
| 10839 | " color = vec4(1);\n" |
| 10840 | "}\n"; |
| 10841 | |
| 10842 | VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this); |
| 10843 | VkShaderObj tcs(m_device, tcsSource, VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT, this); |
| 10844 | VkShaderObj tes(m_device, tesSource, VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT, this); |
| 10845 | VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this); |
| 10846 | |
| 10847 | VkPipelineInputAssemblyStateCreateInfo iasci{ |
| 10848 | VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO, |
| 10849 | nullptr, |
| 10850 | 0, |
| 10851 | VK_PRIMITIVE_TOPOLOGY_PATCH_LIST, |
| 10852 | VK_FALSE}; |
| 10853 | |
Chris Forbes | b4cacb6 | 2016-04-04 19:15:00 +1200 | [diff] [blame] | 10854 | VkPipelineTessellationStateCreateInfo tsci{ |
| 10855 | VK_STRUCTURE_TYPE_PIPELINE_TESSELLATION_STATE_CREATE_INFO, |
| 10856 | nullptr, |
| 10857 | 0, |
| 10858 | 3}; |
| 10859 | |
Chris Forbes | 4ea14fc | 2016-04-04 18:52:54 +1200 | [diff] [blame] | 10860 | VkPipelineObj pipe(m_device); |
| 10861 | pipe.SetInputAssembly(&iasci); |
Chris Forbes | b4cacb6 | 2016-04-04 19:15:00 +1200 | [diff] [blame] | 10862 | pipe.SetTessellation(&tsci); |
Chris Forbes | 4ea14fc | 2016-04-04 18:52:54 +1200 | [diff] [blame] | 10863 | pipe.AddColorAttachment(); |
| 10864 | pipe.AddShader(&vs); |
| 10865 | pipe.AddShader(&tcs); |
| 10866 | pipe.AddShader(&tes); |
| 10867 | pipe.AddShader(&fs); |
| 10868 | |
| 10869 | VkDescriptorSetObj descriptorSet(m_device); |
| 10870 | descriptorSet.AppendDummy(); |
| 10871 | descriptorSet.CreateVKDescriptorSet(m_commandBuffer); |
| 10872 | |
| 10873 | pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass()); |
| 10874 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 10875 | m_errorMonitor->VerifyNotFound(); |
Chris Forbes | 4ea14fc | 2016-04-04 18:52:54 +1200 | [diff] [blame] | 10876 | } |
| 10877 | |
Chris Forbes | a0ab815 | 2016-04-20 13:34:27 +1200 | [diff] [blame] | 10878 | TEST_F(VkLayerTest, CreatePipelineGeometryInputBlockPositive) |
| 10879 | { |
| 10880 | m_errorMonitor->ExpectSuccess(); |
| 10881 | |
| 10882 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 10883 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 10884 | |
| 10885 | if (!m_device->phy().features().geometryShader) { |
| 10886 | printf("Device does not support geometry shaders; skipped.\n"); |
| 10887 | return; |
| 10888 | } |
| 10889 | |
| 10890 | char const *vsSource = |
| 10891 | "#version 450\n" |
| 10892 | "layout(location=0) out VertexData { vec4 x; } vs_out;\n" |
| 10893 | "void main(){\n" |
| 10894 | " vs_out.x = vec4(1);\n" |
| 10895 | "}\n"; |
| 10896 | char const *gsSource = |
| 10897 | "#version 450\n" |
| 10898 | "layout(triangles) in;\n" |
| 10899 | "layout(triangle_strip, max_vertices=3) out;\n" |
| 10900 | "layout(location=0) in VertexData { vec4 x; } gs_in[];\n" |
| 10901 | "out gl_PerVertex { vec4 gl_Position; };\n" |
| 10902 | "void main() {\n" |
| 10903 | " gl_Position = gs_in[0].x;\n" |
| 10904 | " EmitVertex();\n" |
| 10905 | "}\n"; |
| 10906 | char const *fsSource = |
| 10907 | "#version 450\n" |
| 10908 | "layout(location=0) out vec4 color;\n" |
| 10909 | "void main(){\n" |
| 10910 | " color = vec4(1);\n" |
| 10911 | "}\n"; |
| 10912 | |
| 10913 | VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this); |
| 10914 | VkShaderObj gs(m_device, gsSource, VK_SHADER_STAGE_GEOMETRY_BIT, this); |
| 10915 | VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this); |
| 10916 | |
| 10917 | VkPipelineObj pipe(m_device); |
| 10918 | pipe.AddColorAttachment(); |
| 10919 | pipe.AddShader(&vs); |
| 10920 | pipe.AddShader(&gs); |
| 10921 | pipe.AddShader(&fs); |
| 10922 | |
| 10923 | VkDescriptorSetObj descriptorSet(m_device); |
| 10924 | descriptorSet.AppendDummy(); |
| 10925 | descriptorSet.CreateVKDescriptorSet(m_commandBuffer); |
| 10926 | |
| 10927 | pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass()); |
| 10928 | |
| 10929 | m_errorMonitor->VerifyNotFound(); |
| 10930 | } |
| 10931 | |
Chris Forbes | a0193bc | 2016-04-04 19:19:47 +1200 | [diff] [blame] | 10932 | TEST_F(VkLayerTest, CreatePipelineTessPatchDecorationMismatch) |
| 10933 | { |
| 10934 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 10935 | "is per-vertex in tessellation control shader stage " |
| 10936 | "but per-patch in tessellation evaluation shader stage"); |
| 10937 | |
| 10938 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 10939 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 10940 | |
Chris Forbes | c1e852d | 2016-04-04 19:26:42 +1200 | [diff] [blame] | 10941 | if (!m_device->phy().features().tessellationShader) { |
| 10942 | printf("Device does not support tessellation shaders; skipped.\n"); |
| 10943 | return; |
| 10944 | } |
| 10945 | |
Chris Forbes | a0193bc | 2016-04-04 19:19:47 +1200 | [diff] [blame] | 10946 | char const *vsSource = |
| 10947 | "#version 450\n" |
| 10948 | "void main(){}\n"; |
| 10949 | char const *tcsSource = |
| 10950 | "#version 450\n" |
| 10951 | "layout(location=0) out int x[];\n" |
| 10952 | "layout(vertices=3) out;\n" |
| 10953 | "void main(){\n" |
| 10954 | " gl_TessLevelOuter[0] = gl_TessLevelOuter[1] = gl_TessLevelOuter[2] = 1;\n" |
| 10955 | " gl_TessLevelInner[0] = 1;\n" |
| 10956 | " x[gl_InvocationID] = gl_InvocationID;\n" |
| 10957 | "}\n"; |
| 10958 | char const *tesSource = |
| 10959 | "#version 450\n" |
| 10960 | "layout(triangles, equal_spacing, cw) in;\n" |
| 10961 | "layout(location=0) patch in int x;\n" |
| 10962 | "out gl_PerVertex { vec4 gl_Position; };\n" |
| 10963 | "void main(){\n" |
| 10964 | " gl_Position.xyz = gl_TessCoord;\n" |
| 10965 | " gl_Position.w = x;\n" |
| 10966 | "}\n"; |
| 10967 | char const *fsSource = |
| 10968 | "#version 450\n" |
| 10969 | "layout(location=0) out vec4 color;\n" |
| 10970 | "void main(){\n" |
| 10971 | " color = vec4(1);\n" |
| 10972 | "}\n"; |
| 10973 | |
| 10974 | VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this); |
| 10975 | VkShaderObj tcs(m_device, tcsSource, VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT, this); |
| 10976 | VkShaderObj tes(m_device, tesSource, VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT, this); |
| 10977 | VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this); |
| 10978 | |
| 10979 | VkPipelineInputAssemblyStateCreateInfo iasci{ |
| 10980 | VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO, |
| 10981 | nullptr, |
| 10982 | 0, |
| 10983 | VK_PRIMITIVE_TOPOLOGY_PATCH_LIST, |
| 10984 | VK_FALSE}; |
| 10985 | |
| 10986 | VkPipelineTessellationStateCreateInfo tsci{ |
| 10987 | VK_STRUCTURE_TYPE_PIPELINE_TESSELLATION_STATE_CREATE_INFO, |
| 10988 | nullptr, |
| 10989 | 0, |
| 10990 | 3}; |
| 10991 | |
| 10992 | VkPipelineObj pipe(m_device); |
| 10993 | pipe.SetInputAssembly(&iasci); |
| 10994 | pipe.SetTessellation(&tsci); |
| 10995 | pipe.AddColorAttachment(); |
| 10996 | pipe.AddShader(&vs); |
| 10997 | pipe.AddShader(&tcs); |
| 10998 | pipe.AddShader(&tes); |
| 10999 | pipe.AddShader(&fs); |
| 11000 | |
| 11001 | VkDescriptorSetObj descriptorSet(m_device); |
| 11002 | descriptorSet.AppendDummy(); |
| 11003 | descriptorSet.CreateVKDescriptorSet(m_commandBuffer); |
| 11004 | |
| 11005 | pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass()); |
| 11006 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 11007 | m_errorMonitor->VerifyFound(); |
Chris Forbes | a0193bc | 2016-04-04 19:19:47 +1200 | [diff] [blame] | 11008 | } |
| 11009 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 11010 | TEST_F(VkLayerTest, CreatePipelineAttribBindingConflict) { |
| 11011 | m_errorMonitor->SetDesiredFailureMsg( |
| 11012 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 11013 | "Duplicate vertex input binding descriptions for binding 0"); |
| 11014 | |
Chris Forbes | 280ba2c | 2015-06-12 11:16:41 +1200 | [diff] [blame] | 11015 | ASSERT_NO_FATAL_FAILURE(InitState()); |
Tobin Ehlis | c9ac2b6 | 2015-09-11 12:57:55 -0600 | [diff] [blame] | 11016 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
Chris Forbes | 280ba2c | 2015-06-12 11:16:41 +1200 | [diff] [blame] | 11017 | |
| 11018 | /* Two binding descriptions for binding 0 */ |
| 11019 | VkVertexInputBindingDescription input_bindings[2]; |
| 11020 | memset(input_bindings, 0, sizeof(input_bindings)); |
| 11021 | |
| 11022 | VkVertexInputAttributeDescription input_attrib; |
| 11023 | memset(&input_attrib, 0, sizeof(input_attrib)); |
| 11024 | input_attrib.format = VK_FORMAT_R32_SFLOAT; |
| 11025 | |
| 11026 | char const *vsSource = |
Chris Forbes | 3846771 | 2016-04-04 17:28:05 +1200 | [diff] [blame] | 11027 | "#version 450\n" |
Chris Forbes | 280ba2c | 2015-06-12 11:16:41 +1200 | [diff] [blame] | 11028 | "\n" |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 11029 | "layout(location=0) in float x;\n" /* attrib provided float */ |
Tony Barbour | e804d20 | 2016-01-05 13:37:45 -0700 | [diff] [blame] | 11030 | "out gl_PerVertex {\n" |
| 11031 | " vec4 gl_Position;\n" |
| 11032 | "};\n" |
Chris Forbes | 280ba2c | 2015-06-12 11:16:41 +1200 | [diff] [blame] | 11033 | "void main(){\n" |
| 11034 | " gl_Position = vec4(x);\n" |
| 11035 | "}\n"; |
| 11036 | char const *fsSource = |
Chris Forbes | 3846771 | 2016-04-04 17:28:05 +1200 | [diff] [blame] | 11037 | "#version 450\n" |
Chris Forbes | 280ba2c | 2015-06-12 11:16:41 +1200 | [diff] [blame] | 11038 | "\n" |
| 11039 | "layout(location=0) out vec4 color;\n" |
| 11040 | "void main(){\n" |
| 11041 | " color = vec4(1);\n" |
| 11042 | "}\n"; |
| 11043 | |
Courtney Goeltzenleuchter | d263550 | 2015-10-21 17:08:06 -0600 | [diff] [blame] | 11044 | VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this); |
| 11045 | VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this); |
Chris Forbes | 280ba2c | 2015-06-12 11:16:41 +1200 | [diff] [blame] | 11046 | |
| 11047 | VkPipelineObj pipe(m_device); |
Chia-I Wu | 08accc6 | 2015-07-07 11:50:03 +0800 | [diff] [blame] | 11048 | pipe.AddColorAttachment(); |
Chris Forbes | 280ba2c | 2015-06-12 11:16:41 +1200 | [diff] [blame] | 11049 | pipe.AddShader(&vs); |
| 11050 | pipe.AddShader(&fs); |
| 11051 | |
| 11052 | pipe.AddVertexInputBindings(input_bindings, 2); |
| 11053 | pipe.AddVertexInputAttribs(&input_attrib, 1); |
| 11054 | |
Chris Forbes | 280ba2c | 2015-06-12 11:16:41 +1200 | [diff] [blame] | 11055 | VkDescriptorSetObj descriptorSet(m_device); |
| 11056 | descriptorSet.AppendDummy(); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 11057 | descriptorSet.CreateVKDescriptorSet(m_commandBuffer); |
Chris Forbes | 280ba2c | 2015-06-12 11:16:41 +1200 | [diff] [blame] | 11058 | |
Tony Barbour | 5781e8f | 2015-08-04 16:23:11 -0600 | [diff] [blame] | 11059 | pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass()); |
Chris Forbes | 280ba2c | 2015-06-12 11:16:41 +1200 | [diff] [blame] | 11060 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 11061 | m_errorMonitor->VerifyFound(); |
Chris Forbes | 280ba2c | 2015-06-12 11:16:41 +1200 | [diff] [blame] | 11062 | } |
Chris Forbes | 8f68b56 | 2015-05-25 11:13:32 +1200 | [diff] [blame] | 11063 | |
Chris Forbes | 35efec7 | 2016-04-21 14:32:08 +1200 | [diff] [blame] | 11064 | TEST_F(VkLayerTest, CreatePipeline64BitAttributesPositive) { |
| 11065 | m_errorMonitor->ExpectSuccess(); |
| 11066 | |
| 11067 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 11068 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 11069 | |
| 11070 | if (!m_device->phy().features().tessellationShader) { |
| 11071 | printf("Device does not support 64bit vertex attributes; skipped.\n"); |
| 11072 | return; |
| 11073 | } |
| 11074 | |
| 11075 | VkVertexInputBindingDescription input_bindings[1]; |
| 11076 | memset(input_bindings, 0, sizeof(input_bindings)); |
| 11077 | |
| 11078 | VkVertexInputAttributeDescription input_attribs[4]; |
| 11079 | memset(input_attribs, 0, sizeof(input_attribs)); |
| 11080 | input_attribs[0].location = 0; |
| 11081 | input_attribs[0].offset = 0; |
| 11082 | input_attribs[0].format = VK_FORMAT_R64G64B64A64_SFLOAT; |
| 11083 | input_attribs[1].location = 2; |
| 11084 | input_attribs[1].offset = 32; |
| 11085 | input_attribs[1].format = VK_FORMAT_R64G64B64A64_SFLOAT; |
| 11086 | input_attribs[2].location = 4; |
| 11087 | input_attribs[2].offset = 64; |
| 11088 | input_attribs[2].format = VK_FORMAT_R64G64B64A64_SFLOAT; |
| 11089 | input_attribs[3].location = 6; |
| 11090 | input_attribs[3].offset = 96; |
| 11091 | input_attribs[3].format = VK_FORMAT_R64G64B64A64_SFLOAT; |
| 11092 | |
| 11093 | char const *vsSource = |
| 11094 | "#version 450\n" |
| 11095 | "\n" |
| 11096 | "layout(location=0) in dmat4 x;\n" |
| 11097 | "out gl_PerVertex {\n" |
| 11098 | " vec4 gl_Position;\n" |
| 11099 | "};\n" |
| 11100 | "void main(){\n" |
| 11101 | " gl_Position = vec4(x[0][0]);\n" |
| 11102 | "}\n"; |
| 11103 | char const *fsSource = |
| 11104 | "#version 450\n" |
| 11105 | "\n" |
| 11106 | "layout(location=0) out vec4 color;\n" |
| 11107 | "void main(){\n" |
| 11108 | " color = vec4(1);\n" |
| 11109 | "}\n"; |
| 11110 | |
| 11111 | VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this); |
| 11112 | VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this); |
| 11113 | |
| 11114 | VkPipelineObj pipe(m_device); |
| 11115 | pipe.AddColorAttachment(); |
| 11116 | pipe.AddShader(&vs); |
| 11117 | pipe.AddShader(&fs); |
| 11118 | |
| 11119 | pipe.AddVertexInputBindings(input_bindings, 1); |
| 11120 | pipe.AddVertexInputAttribs(input_attribs, 4); |
| 11121 | |
| 11122 | VkDescriptorSetObj descriptorSet(m_device); |
| 11123 | descriptorSet.AppendDummy(); |
| 11124 | descriptorSet.CreateVKDescriptorSet(m_commandBuffer); |
| 11125 | |
| 11126 | pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass()); |
| 11127 | |
| 11128 | m_errorMonitor->VerifyNotFound(); |
| 11129 | } |
| 11130 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 11131 | TEST_F(VkLayerTest, CreatePipelineFragmentOutputNotWritten) { |
Courtney Goeltzenleuchter | 7415d5a | 2015-12-09 15:48:16 -0700 | [diff] [blame] | 11132 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 11133 | "Attachment 0 not written by FS"); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 11134 | |
Chris Forbes | 4d6d1e5 | 2015-05-25 11:13:40 +1200 | [diff] [blame] | 11135 | ASSERT_NO_FATAL_FAILURE(InitState()); |
Chris Forbes | 4d6d1e5 | 2015-05-25 11:13:40 +1200 | [diff] [blame] | 11136 | |
| 11137 | char const *vsSource = |
Chris Forbes | 3846771 | 2016-04-04 17:28:05 +1200 | [diff] [blame] | 11138 | "#version 450\n" |
Chris Forbes | 4d6d1e5 | 2015-05-25 11:13:40 +1200 | [diff] [blame] | 11139 | "\n" |
Tony Barbour | e804d20 | 2016-01-05 13:37:45 -0700 | [diff] [blame] | 11140 | "out gl_PerVertex {\n" |
| 11141 | " vec4 gl_Position;\n" |
| 11142 | "};\n" |
Chris Forbes | 4d6d1e5 | 2015-05-25 11:13:40 +1200 | [diff] [blame] | 11143 | "void main(){\n" |
| 11144 | " gl_Position = vec4(1);\n" |
| 11145 | "}\n"; |
| 11146 | char const *fsSource = |
Chris Forbes | 3846771 | 2016-04-04 17:28:05 +1200 | [diff] [blame] | 11147 | "#version 450\n" |
Chris Forbes | 4d6d1e5 | 2015-05-25 11:13:40 +1200 | [diff] [blame] | 11148 | "\n" |
| 11149 | "void main(){\n" |
| 11150 | "}\n"; |
| 11151 | |
Courtney Goeltzenleuchter | d263550 | 2015-10-21 17:08:06 -0600 | [diff] [blame] | 11152 | VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this); |
| 11153 | VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this); |
Chris Forbes | 4d6d1e5 | 2015-05-25 11:13:40 +1200 | [diff] [blame] | 11154 | |
| 11155 | VkPipelineObj pipe(m_device); |
| 11156 | pipe.AddShader(&vs); |
| 11157 | pipe.AddShader(&fs); |
| 11158 | |
Chia-I Wu | 08accc6 | 2015-07-07 11:50:03 +0800 | [diff] [blame] | 11159 | /* set up CB 0, not written */ |
| 11160 | pipe.AddColorAttachment(); |
| 11161 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
Chris Forbes | 4d6d1e5 | 2015-05-25 11:13:40 +1200 | [diff] [blame] | 11162 | |
Chris Forbes | 4d6d1e5 | 2015-05-25 11:13:40 +1200 | [diff] [blame] | 11163 | VkDescriptorSetObj descriptorSet(m_device); |
| 11164 | descriptorSet.AppendDummy(); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 11165 | descriptorSet.CreateVKDescriptorSet(m_commandBuffer); |
Chris Forbes | 4d6d1e5 | 2015-05-25 11:13:40 +1200 | [diff] [blame] | 11166 | |
Tony Barbour | 5781e8f | 2015-08-04 16:23:11 -0600 | [diff] [blame] | 11167 | pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass()); |
Chris Forbes | 4d6d1e5 | 2015-05-25 11:13:40 +1200 | [diff] [blame] | 11168 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 11169 | m_errorMonitor->VerifyFound(); |
Chris Forbes | 4d6d1e5 | 2015-05-25 11:13:40 +1200 | [diff] [blame] | 11170 | } |
| 11171 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 11172 | TEST_F(VkLayerTest, CreatePipelineFragmentOutputNotConsumed) { |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 11173 | m_errorMonitor->SetDesiredFailureMsg( |
Mark Lobodzinski | 510e20d | 2016-02-11 09:26:16 -0700 | [diff] [blame] | 11174 | VK_DEBUG_REPORT_WARNING_BIT_EXT, |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 11175 | "FS writes to output location 1 with no matching attachment"); |
| 11176 | |
Chris Forbes | f3fffaa | 2015-05-25 11:13:43 +1200 | [diff] [blame] | 11177 | ASSERT_NO_FATAL_FAILURE(InitState()); |
Chris Forbes | f3fffaa | 2015-05-25 11:13:43 +1200 | [diff] [blame] | 11178 | |
| 11179 | char const *vsSource = |
Chris Forbes | 3846771 | 2016-04-04 17:28:05 +1200 | [diff] [blame] | 11180 | "#version 450\n" |
Chris Forbes | f3fffaa | 2015-05-25 11:13:43 +1200 | [diff] [blame] | 11181 | "\n" |
Tony Barbour | e804d20 | 2016-01-05 13:37:45 -0700 | [diff] [blame] | 11182 | "out gl_PerVertex {\n" |
| 11183 | " vec4 gl_Position;\n" |
| 11184 | "};\n" |
Chris Forbes | f3fffaa | 2015-05-25 11:13:43 +1200 | [diff] [blame] | 11185 | "void main(){\n" |
| 11186 | " gl_Position = vec4(1);\n" |
| 11187 | "}\n"; |
| 11188 | char const *fsSource = |
Chris Forbes | 3846771 | 2016-04-04 17:28:05 +1200 | [diff] [blame] | 11189 | "#version 450\n" |
Chris Forbes | f3fffaa | 2015-05-25 11:13:43 +1200 | [diff] [blame] | 11190 | "\n" |
| 11191 | "layout(location=0) out vec4 x;\n" |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 11192 | "layout(location=1) out vec4 y;\n" /* no matching attachment for this */ |
Chris Forbes | f3fffaa | 2015-05-25 11:13:43 +1200 | [diff] [blame] | 11193 | "void main(){\n" |
| 11194 | " x = vec4(1);\n" |
| 11195 | " y = vec4(1);\n" |
| 11196 | "}\n"; |
| 11197 | |
Courtney Goeltzenleuchter | d263550 | 2015-10-21 17:08:06 -0600 | [diff] [blame] | 11198 | VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this); |
| 11199 | VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this); |
Chris Forbes | f3fffaa | 2015-05-25 11:13:43 +1200 | [diff] [blame] | 11200 | |
| 11201 | VkPipelineObj pipe(m_device); |
| 11202 | pipe.AddShader(&vs); |
| 11203 | pipe.AddShader(&fs); |
| 11204 | |
Chia-I Wu | 08accc6 | 2015-07-07 11:50:03 +0800 | [diff] [blame] | 11205 | /* set up CB 0, not written */ |
| 11206 | pipe.AddColorAttachment(); |
| 11207 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
Chris Forbes | f3fffaa | 2015-05-25 11:13:43 +1200 | [diff] [blame] | 11208 | /* FS writes CB 1, but we don't configure it */ |
| 11209 | |
Chris Forbes | f3fffaa | 2015-05-25 11:13:43 +1200 | [diff] [blame] | 11210 | VkDescriptorSetObj descriptorSet(m_device); |
| 11211 | descriptorSet.AppendDummy(); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 11212 | descriptorSet.CreateVKDescriptorSet(m_commandBuffer); |
Chris Forbes | f3fffaa | 2015-05-25 11:13:43 +1200 | [diff] [blame] | 11213 | |
Tony Barbour | 5781e8f | 2015-08-04 16:23:11 -0600 | [diff] [blame] | 11214 | pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass()); |
Chris Forbes | f3fffaa | 2015-05-25 11:13:43 +1200 | [diff] [blame] | 11215 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 11216 | m_errorMonitor->VerifyFound(); |
Chris Forbes | f3fffaa | 2015-05-25 11:13:43 +1200 | [diff] [blame] | 11217 | } |
| 11218 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 11219 | TEST_F(VkLayerTest, CreatePipelineFragmentOutputTypeMismatch) { |
Courtney Goeltzenleuchter | 7415d5a | 2015-12-09 15:48:16 -0700 | [diff] [blame] | 11220 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 11221 | "does not match FS output type"); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 11222 | |
Chris Forbes | a36d69e | 2015-05-25 11:13:44 +1200 | [diff] [blame] | 11223 | ASSERT_NO_FATAL_FAILURE(InitState()); |
Chris Forbes | a36d69e | 2015-05-25 11:13:44 +1200 | [diff] [blame] | 11224 | |
| 11225 | char const *vsSource = |
Chris Forbes | 3846771 | 2016-04-04 17:28:05 +1200 | [diff] [blame] | 11226 | "#version 450\n" |
Chris Forbes | a36d69e | 2015-05-25 11:13:44 +1200 | [diff] [blame] | 11227 | "\n" |
Tony Barbour | e804d20 | 2016-01-05 13:37:45 -0700 | [diff] [blame] | 11228 | "out gl_PerVertex {\n" |
| 11229 | " vec4 gl_Position;\n" |
| 11230 | "};\n" |
Chris Forbes | a36d69e | 2015-05-25 11:13:44 +1200 | [diff] [blame] | 11231 | "void main(){\n" |
| 11232 | " gl_Position = vec4(1);\n" |
| 11233 | "}\n"; |
| 11234 | char const *fsSource = |
Chris Forbes | 3846771 | 2016-04-04 17:28:05 +1200 | [diff] [blame] | 11235 | "#version 450\n" |
Chris Forbes | a36d69e | 2015-05-25 11:13:44 +1200 | [diff] [blame] | 11236 | "\n" |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 11237 | "layout(location=0) out ivec4 x;\n" /* not UNORM */ |
Chris Forbes | a36d69e | 2015-05-25 11:13:44 +1200 | [diff] [blame] | 11238 | "void main(){\n" |
| 11239 | " x = ivec4(1);\n" |
| 11240 | "}\n"; |
| 11241 | |
Courtney Goeltzenleuchter | d263550 | 2015-10-21 17:08:06 -0600 | [diff] [blame] | 11242 | VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this); |
| 11243 | VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this); |
Chris Forbes | a36d69e | 2015-05-25 11:13:44 +1200 | [diff] [blame] | 11244 | |
| 11245 | VkPipelineObj pipe(m_device); |
| 11246 | pipe.AddShader(&vs); |
| 11247 | pipe.AddShader(&fs); |
| 11248 | |
Chia-I Wu | 08accc6 | 2015-07-07 11:50:03 +0800 | [diff] [blame] | 11249 | /* set up CB 0; type is UNORM by default */ |
| 11250 | pipe.AddColorAttachment(); |
| 11251 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
Chris Forbes | a36d69e | 2015-05-25 11:13:44 +1200 | [diff] [blame] | 11252 | |
Chris Forbes | a36d69e | 2015-05-25 11:13:44 +1200 | [diff] [blame] | 11253 | VkDescriptorSetObj descriptorSet(m_device); |
| 11254 | descriptorSet.AppendDummy(); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 11255 | descriptorSet.CreateVKDescriptorSet(m_commandBuffer); |
Chris Forbes | a36d69e | 2015-05-25 11:13:44 +1200 | [diff] [blame] | 11256 | |
Tony Barbour | 5781e8f | 2015-08-04 16:23:11 -0600 | [diff] [blame] | 11257 | pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass()); |
Chris Forbes | a36d69e | 2015-05-25 11:13:44 +1200 | [diff] [blame] | 11258 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 11259 | m_errorMonitor->VerifyFound(); |
Chris Forbes | a36d69e | 2015-05-25 11:13:44 +1200 | [diff] [blame] | 11260 | } |
Chris Forbes | 7b1b893 | 2015-06-05 14:43:36 +1200 | [diff] [blame] | 11261 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 11262 | TEST_F(VkLayerTest, CreatePipelineUniformBlockNotProvided) { |
Courtney Goeltzenleuchter | 7415d5a | 2015-12-09 15:48:16 -0700 | [diff] [blame] | 11263 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 11264 | "not declared in pipeline layout"); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 11265 | |
Chris Forbes | 556c76c | 2015-08-14 12:04:59 +1200 | [diff] [blame] | 11266 | ASSERT_NO_FATAL_FAILURE(InitState()); |
Chris Forbes | 556c76c | 2015-08-14 12:04:59 +1200 | [diff] [blame] | 11267 | |
| 11268 | char const *vsSource = |
Chris Forbes | 3846771 | 2016-04-04 17:28:05 +1200 | [diff] [blame] | 11269 | "#version 450\n" |
Chris Forbes | 556c76c | 2015-08-14 12:04:59 +1200 | [diff] [blame] | 11270 | "\n" |
Tony Barbour | e804d20 | 2016-01-05 13:37:45 -0700 | [diff] [blame] | 11271 | "out gl_PerVertex {\n" |
| 11272 | " vec4 gl_Position;\n" |
| 11273 | "};\n" |
Chris Forbes | 556c76c | 2015-08-14 12:04:59 +1200 | [diff] [blame] | 11274 | "void main(){\n" |
| 11275 | " gl_Position = vec4(1);\n" |
| 11276 | "}\n"; |
| 11277 | char const *fsSource = |
Chris Forbes | 3846771 | 2016-04-04 17:28:05 +1200 | [diff] [blame] | 11278 | "#version 450\n" |
Chris Forbes | 556c76c | 2015-08-14 12:04:59 +1200 | [diff] [blame] | 11279 | "\n" |
| 11280 | "layout(location=0) out vec4 x;\n" |
| 11281 | "layout(set=0) layout(binding=0) uniform foo { int x; int y; } bar;\n" |
| 11282 | "void main(){\n" |
| 11283 | " x = vec4(bar.y);\n" |
| 11284 | "}\n"; |
| 11285 | |
Courtney Goeltzenleuchter | d263550 | 2015-10-21 17:08:06 -0600 | [diff] [blame] | 11286 | VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this); |
| 11287 | VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this); |
Chris Forbes | 556c76c | 2015-08-14 12:04:59 +1200 | [diff] [blame] | 11288 | |
Chris Forbes | 556c76c | 2015-08-14 12:04:59 +1200 | [diff] [blame] | 11289 | VkPipelineObj pipe(m_device); |
| 11290 | pipe.AddShader(&vs); |
| 11291 | pipe.AddShader(&fs); |
| 11292 | |
| 11293 | /* set up CB 0; type is UNORM by default */ |
| 11294 | pipe.AddColorAttachment(); |
| 11295 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 11296 | |
| 11297 | VkDescriptorSetObj descriptorSet(m_device); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 11298 | descriptorSet.CreateVKDescriptorSet(m_commandBuffer); |
Chris Forbes | 556c76c | 2015-08-14 12:04:59 +1200 | [diff] [blame] | 11299 | |
| 11300 | pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass()); |
| 11301 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 11302 | m_errorMonitor->VerifyFound(); |
Chris Forbes | 556c76c | 2015-08-14 12:04:59 +1200 | [diff] [blame] | 11303 | } |
| 11304 | |
Chris Forbes | 5c59e90 | 2016-02-26 16:56:09 +1300 | [diff] [blame] | 11305 | TEST_F(VkLayerTest, CreatePipelinePushConstantsNotInLayout) { |
| 11306 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 11307 | "not declared in layout"); |
| 11308 | |
| 11309 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 11310 | |
| 11311 | char const *vsSource = |
| 11312 | "#version 450\n" |
Chris Forbes | 5c59e90 | 2016-02-26 16:56:09 +1300 | [diff] [blame] | 11313 | "\n" |
| 11314 | "layout(push_constant, std430) uniform foo { float x; } consts;\n" |
| 11315 | "out gl_PerVertex {\n" |
| 11316 | " vec4 gl_Position;\n" |
| 11317 | "};\n" |
| 11318 | "void main(){\n" |
| 11319 | " gl_Position = vec4(consts.x);\n" |
| 11320 | "}\n"; |
| 11321 | char const *fsSource = |
| 11322 | "#version 450\n" |
Chris Forbes | 5c59e90 | 2016-02-26 16:56:09 +1300 | [diff] [blame] | 11323 | "\n" |
| 11324 | "layout(location=0) out vec4 x;\n" |
| 11325 | "void main(){\n" |
| 11326 | " x = vec4(1);\n" |
| 11327 | "}\n"; |
| 11328 | |
| 11329 | VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this); |
| 11330 | VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this); |
| 11331 | |
| 11332 | VkPipelineObj pipe(m_device); |
| 11333 | pipe.AddShader(&vs); |
| 11334 | pipe.AddShader(&fs); |
| 11335 | |
| 11336 | /* set up CB 0; type is UNORM by default */ |
| 11337 | pipe.AddColorAttachment(); |
| 11338 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 11339 | |
| 11340 | VkDescriptorSetObj descriptorSet(m_device); |
| 11341 | descriptorSet.CreateVKDescriptorSet(m_commandBuffer); |
| 11342 | |
| 11343 | pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass()); |
| 11344 | |
| 11345 | /* should have generated an error -- no push constant ranges provided! */ |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 11346 | m_errorMonitor->VerifyFound(); |
Chris Forbes | 5c59e90 | 2016-02-26 16:56:09 +1300 | [diff] [blame] | 11347 | } |
| 11348 | |
Chris Forbes | 10eb9ae | 2016-05-31 16:09:42 +1200 | [diff] [blame] | 11349 | TEST_F(VkLayerTest, CreateComputePipelineMissingDescriptor) { |
| 11350 | m_errorMonitor->SetDesiredFailureMsg( |
| 11351 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 11352 | "Shader uses descriptor slot 0.0"); |
| 11353 | |
| 11354 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 11355 | |
| 11356 | char const *csSource = |
| 11357 | "#version 450\n" |
| 11358 | "\n" |
| 11359 | "layout(local_size_x=1) in;\n" |
| 11360 | "layout(set=0, binding=0) buffer block { vec4 x; };\n" |
| 11361 | "void main(){\n" |
| 11362 | " x = vec4(1);\n" |
| 11363 | "}\n"; |
| 11364 | |
| 11365 | VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this); |
| 11366 | |
| 11367 | VkDescriptorSetObj descriptorSet(m_device); |
| 11368 | descriptorSet.CreateVKDescriptorSet(m_commandBuffer); |
| 11369 | |
| 11370 | VkComputePipelineCreateInfo cpci = { |
| 11371 | VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO, |
| 11372 | nullptr, 0, { |
| 11373 | VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, |
| 11374 | nullptr, 0, VK_SHADER_STAGE_COMPUTE_BIT, |
| 11375 | cs.handle(), "main", nullptr |
| 11376 | }, |
| 11377 | descriptorSet.GetPipelineLayout(), |
| 11378 | VK_NULL_HANDLE, -1 |
| 11379 | }; |
| 11380 | |
| 11381 | VkPipeline pipe; |
| 11382 | VkResult err = vkCreateComputePipelines( |
| 11383 | m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe); |
| 11384 | |
| 11385 | m_errorMonitor->VerifyFound(); |
| 11386 | |
| 11387 | if (err == VK_SUCCESS) { |
| 11388 | vkDestroyPipeline(m_device->device(), pipe, nullptr); |
| 11389 | } |
| 11390 | } |
| 11391 | |
| 11392 | TEST_F(VkLayerTest, CreateComputePipelineMissingDescriptorUnusedPositive) { |
| 11393 | m_errorMonitor->ExpectSuccess(); |
| 11394 | |
| 11395 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 11396 | |
| 11397 | char const *csSource = |
| 11398 | "#version 450\n" |
| 11399 | "\n" |
| 11400 | "layout(local_size_x=1) in;\n" |
| 11401 | "layout(set=0, binding=0) buffer block { vec4 x; };\n" |
| 11402 | "void main(){\n" |
| 11403 | " // x is not used.\n" |
| 11404 | "}\n"; |
| 11405 | |
| 11406 | VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this); |
| 11407 | |
| 11408 | VkDescriptorSetObj descriptorSet(m_device); |
| 11409 | descriptorSet.CreateVKDescriptorSet(m_commandBuffer); |
| 11410 | |
| 11411 | VkComputePipelineCreateInfo cpci = { |
| 11412 | VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO, |
| 11413 | nullptr, 0, { |
| 11414 | VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, |
| 11415 | nullptr, 0, VK_SHADER_STAGE_COMPUTE_BIT, |
| 11416 | cs.handle(), "main", nullptr |
| 11417 | }, |
| 11418 | descriptorSet.GetPipelineLayout(), |
| 11419 | VK_NULL_HANDLE, -1 |
| 11420 | }; |
| 11421 | |
| 11422 | VkPipeline pipe; |
| 11423 | VkResult err = vkCreateComputePipelines( |
| 11424 | m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe); |
| 11425 | |
| 11426 | m_errorMonitor->VerifyNotFound(); |
| 11427 | |
| 11428 | if (err == VK_SUCCESS) { |
| 11429 | vkDestroyPipeline(m_device->device(), pipe, nullptr); |
| 11430 | } |
| 11431 | } |
| 11432 | |
Mark Lobodzinski | 209b529 | 2015-09-17 09:44:05 -0600 | [diff] [blame] | 11433 | #endif // SHADER_CHECKER_TESTS |
| 11434 | |
| 11435 | #if DEVICE_LIMITS_TESTS |
Mark Young | c48c4c1 | 2016-04-11 14:26:49 -0600 | [diff] [blame] | 11436 | TEST_F(VkLayerTest, CreateImageLimitsViolationMaxWidth) { |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 11437 | m_errorMonitor->SetDesiredFailureMsg( |
| 11438 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 11439 | "CreateImage extents exceed allowable limits for format"); |
Mark Lobodzinski | 6f2274e | 2015-09-22 09:33:21 -0600 | [diff] [blame] | 11440 | |
| 11441 | ASSERT_NO_FATAL_FAILURE(InitState()); |
Mark Lobodzinski | 6f2274e | 2015-09-22 09:33:21 -0600 | [diff] [blame] | 11442 | |
| 11443 | // Create an image |
| 11444 | VkImage image; |
| 11445 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 11446 | const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM; |
| 11447 | const int32_t tex_width = 32; |
| 11448 | const int32_t tex_height = 32; |
Mark Lobodzinski | 6f2274e | 2015-09-22 09:33:21 -0600 | [diff] [blame] | 11449 | |
| 11450 | VkImageCreateInfo image_create_info = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 11451 | image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO; |
| 11452 | image_create_info.pNext = NULL; |
| 11453 | image_create_info.imageType = VK_IMAGE_TYPE_2D; |
| 11454 | image_create_info.format = tex_format; |
| 11455 | image_create_info.extent.width = tex_width; |
Mark Lobodzinski | 6f2274e | 2015-09-22 09:33:21 -0600 | [diff] [blame] | 11456 | image_create_info.extent.height = tex_height; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 11457 | image_create_info.extent.depth = 1; |
| 11458 | image_create_info.mipLevels = 1; |
| 11459 | image_create_info.arrayLayers = 1; |
| 11460 | image_create_info.samples = VK_SAMPLE_COUNT_1_BIT; |
| 11461 | image_create_info.tiling = VK_IMAGE_TILING_LINEAR; |
| 11462 | image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT; |
| 11463 | image_create_info.flags = 0; |
Mark Lobodzinski | 6f2274e | 2015-09-22 09:33:21 -0600 | [diff] [blame] | 11464 | |
| 11465 | // Introduce error by sending down a bogus width extent |
| 11466 | image_create_info.extent.width = 65536; |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 11467 | vkCreateImage(m_device->device(), &image_create_info, NULL, &image); |
Mark Lobodzinski | 6f2274e | 2015-09-22 09:33:21 -0600 | [diff] [blame] | 11468 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 11469 | m_errorMonitor->VerifyFound(); |
Mark Lobodzinski | 6f2274e | 2015-09-22 09:33:21 -0600 | [diff] [blame] | 11470 | } |
| 11471 | |
Mark Young | c48c4c1 | 2016-04-11 14:26:49 -0600 | [diff] [blame] | 11472 | TEST_F(VkLayerTest, CreateImageLimitsViolationMinWidth) { |
| 11473 | m_errorMonitor->SetDesiredFailureMsg( |
| 11474 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 11475 | "CreateImage extents is 0 for at least one required dimension"); |
| 11476 | |
| 11477 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 11478 | |
| 11479 | // Create an image |
| 11480 | VkImage image; |
| 11481 | |
| 11482 | const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM; |
| 11483 | const int32_t tex_width = 32; |
| 11484 | const int32_t tex_height = 32; |
| 11485 | |
| 11486 | VkImageCreateInfo image_create_info = {}; |
| 11487 | image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO; |
| 11488 | image_create_info.pNext = NULL; |
| 11489 | image_create_info.imageType = VK_IMAGE_TYPE_2D; |
| 11490 | image_create_info.format = tex_format; |
| 11491 | image_create_info.extent.width = tex_width; |
| 11492 | image_create_info.extent.height = tex_height; |
| 11493 | image_create_info.extent.depth = 1; |
| 11494 | image_create_info.mipLevels = 1; |
| 11495 | image_create_info.arrayLayers = 1; |
| 11496 | image_create_info.samples = VK_SAMPLE_COUNT_1_BIT; |
| 11497 | image_create_info.tiling = VK_IMAGE_TILING_LINEAR; |
| 11498 | image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT; |
| 11499 | image_create_info.flags = 0; |
| 11500 | |
| 11501 | // Introduce error by sending down a bogus width extent |
| 11502 | image_create_info.extent.width = 0; |
| 11503 | vkCreateImage(m_device->device(), &image_create_info, NULL, &image); |
| 11504 | |
| 11505 | m_errorMonitor->VerifyFound(); |
| 11506 | } |
Mark Lobodzinski | 209b529 | 2015-09-17 09:44:05 -0600 | [diff] [blame] | 11507 | #endif // DEVICE_LIMITS_TESTS |
Chris Forbes | a36d69e | 2015-05-25 11:13:44 +1200 | [diff] [blame] | 11508 | |
Tobin Ehlis | cde0889 | 2015-09-22 10:11:37 -0600 | [diff] [blame] | 11509 | #if IMAGE_TESTS |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 11510 | TEST_F(VkLayerTest, InvalidImageView) { |
| 11511 | VkResult err; |
Tobin Ehlis | cde0889 | 2015-09-22 10:11:37 -0600 | [diff] [blame] | 11512 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 11513 | m_errorMonitor->SetDesiredFailureMsg( |
| 11514 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 11515 | "vkCreateImageView called with baseMipLevel 10 "); |
| 11516 | |
Tobin Ehlis | cde0889 | 2015-09-22 10:11:37 -0600 | [diff] [blame] | 11517 | ASSERT_NO_FATAL_FAILURE(InitState()); |
Tobin Ehlis | cde0889 | 2015-09-22 10:11:37 -0600 | [diff] [blame] | 11518 | |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 11519 | // Create an image and try to create a view with bad baseMipLevel |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 11520 | VkImage image; |
Tobin Ehlis | cde0889 | 2015-09-22 10:11:37 -0600 | [diff] [blame] | 11521 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 11522 | const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM; |
| 11523 | const int32_t tex_width = 32; |
| 11524 | const int32_t tex_height = 32; |
Tobin Ehlis | cde0889 | 2015-09-22 10:11:37 -0600 | [diff] [blame] | 11525 | |
| 11526 | VkImageCreateInfo image_create_info = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 11527 | image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO; |
| 11528 | image_create_info.pNext = NULL; |
| 11529 | image_create_info.imageType = VK_IMAGE_TYPE_2D; |
| 11530 | image_create_info.format = tex_format; |
| 11531 | image_create_info.extent.width = tex_width; |
| 11532 | image_create_info.extent.height = tex_height; |
| 11533 | image_create_info.extent.depth = 1; |
| 11534 | image_create_info.mipLevels = 1; |
| 11535 | image_create_info.arrayLayers = 1; |
| 11536 | image_create_info.samples = VK_SAMPLE_COUNT_1_BIT; |
| 11537 | image_create_info.tiling = VK_IMAGE_TILING_LINEAR; |
| 11538 | image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT; |
| 11539 | image_create_info.flags = 0; |
Tobin Ehlis | cde0889 | 2015-09-22 10:11:37 -0600 | [diff] [blame] | 11540 | |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 11541 | err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image); |
Tobin Ehlis | cde0889 | 2015-09-22 10:11:37 -0600 | [diff] [blame] | 11542 | ASSERT_VK_SUCCESS(err); |
| 11543 | |
| 11544 | VkImageViewCreateInfo image_view_create_info = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 11545 | image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO; |
| 11546 | image_view_create_info.image = image; |
| 11547 | image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D; |
| 11548 | image_view_create_info.format = tex_format; |
| 11549 | image_view_create_info.subresourceRange.layerCount = 1; |
| 11550 | image_view_create_info.subresourceRange.baseMipLevel = 10; // cause an error |
| 11551 | image_view_create_info.subresourceRange.levelCount = 1; |
| 11552 | image_view_create_info.subresourceRange.aspectMask = |
| 11553 | VK_IMAGE_ASPECT_COLOR_BIT; |
Tobin Ehlis | cde0889 | 2015-09-22 10:11:37 -0600 | [diff] [blame] | 11554 | |
| 11555 | VkImageView view; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 11556 | err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, |
| 11557 | &view); |
Tobin Ehlis | cde0889 | 2015-09-22 10:11:37 -0600 | [diff] [blame] | 11558 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 11559 | m_errorMonitor->VerifyFound(); |
Tony Barbour | df4c004 | 2016-06-01 15:55:43 -0600 | [diff] [blame] | 11560 | vkDestroyImage(m_device->device(), image, NULL); |
Tobin Ehlis | cde0889 | 2015-09-22 10:11:37 -0600 | [diff] [blame] | 11561 | } |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 11562 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 11563 | TEST_F(VkLayerTest, InvalidImageViewAspect) { |
Tobin Ehlis | 1f567a2 | 2016-05-25 16:15:18 -0600 | [diff] [blame] | 11564 | TEST_DESCRIPTION( |
| 11565 | "Create an image and try to create a view with an invalid aspectMask"); |
Courtney Goeltzenleuchter | 7415d5a | 2015-12-09 15:48:16 -0700 | [diff] [blame] | 11566 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 11567 | "vkCreateImageView: Color image " |
| 11568 | "formats must have ONLY the " |
| 11569 | "VK_IMAGE_ASPECT_COLOR_BIT set"); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 11570 | |
Mark Lobodzinski | dc86b85 | 2015-10-23 14:20:31 -0600 | [diff] [blame] | 11571 | ASSERT_NO_FATAL_FAILURE(InitState()); |
Mark Lobodzinski | dc86b85 | 2015-10-23 14:20:31 -0600 | [diff] [blame] | 11572 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 11573 | const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM; |
Tobin Ehlis | 1f567a2 | 2016-05-25 16:15:18 -0600 | [diff] [blame] | 11574 | VkImageObj image(m_device); |
| 11575 | image.init(32, 32, tex_format, VK_IMAGE_USAGE_SAMPLED_BIT, |
| 11576 | VK_IMAGE_TILING_LINEAR, 0); |
| 11577 | ASSERT_TRUE(image.initialized()); |
Mark Lobodzinski | dc86b85 | 2015-10-23 14:20:31 -0600 | [diff] [blame] | 11578 | |
| 11579 | VkImageViewCreateInfo image_view_create_info = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 11580 | image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO; |
Tobin Ehlis | 1f567a2 | 2016-05-25 16:15:18 -0600 | [diff] [blame] | 11581 | image_view_create_info.image = image.handle(); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 11582 | image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D; |
| 11583 | image_view_create_info.format = tex_format; |
| 11584 | image_view_create_info.subresourceRange.baseMipLevel = 0; |
| 11585 | image_view_create_info.subresourceRange.levelCount = 1; |
| 11586 | // Cause an error by setting an invalid image aspect |
| 11587 | image_view_create_info.subresourceRange.aspectMask = |
| 11588 | VK_IMAGE_ASPECT_METADATA_BIT; |
Mark Lobodzinski | dc86b85 | 2015-10-23 14:20:31 -0600 | [diff] [blame] | 11589 | |
| 11590 | VkImageView view; |
Tobin Ehlis | 1f567a2 | 2016-05-25 16:15:18 -0600 | [diff] [blame] | 11591 | vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view); |
Mark Lobodzinski | dc86b85 | 2015-10-23 14:20:31 -0600 | [diff] [blame] | 11592 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 11593 | m_errorMonitor->VerifyFound(); |
Mark Lobodzinski | dc86b85 | 2015-10-23 14:20:31 -0600 | [diff] [blame] | 11594 | } |
| 11595 | |
Mark Lobodzinski | db11763 | 2016-03-31 10:45:56 -0600 | [diff] [blame] | 11596 | TEST_F(VkLayerTest, CopyImageLayerCountMismatch) { |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 11597 | VkResult err; |
| 11598 | bool pass; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 11599 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 11600 | m_errorMonitor->SetDesiredFailureMsg( |
| 11601 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Mark Lobodzinski | db11763 | 2016-03-31 10:45:56 -0600 | [diff] [blame] | 11602 | "vkCmdCopyImage: number of layers in source and destination subresources for pRegions"); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 11603 | |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 11604 | ASSERT_NO_FATAL_FAILURE(InitState()); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 11605 | |
| 11606 | // Create two images of different types and try to copy between them |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 11607 | VkImage srcImage; |
| 11608 | VkImage dstImage; |
| 11609 | VkDeviceMemory srcMem; |
| 11610 | VkDeviceMemory destMem; |
| 11611 | VkMemoryRequirements memReqs; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 11612 | |
| 11613 | VkImageCreateInfo image_create_info = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 11614 | image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO; |
| 11615 | image_create_info.pNext = NULL; |
| 11616 | image_create_info.imageType = VK_IMAGE_TYPE_2D; |
| 11617 | image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM; |
| 11618 | image_create_info.extent.width = 32; |
| 11619 | image_create_info.extent.height = 32; |
| 11620 | image_create_info.extent.depth = 1; |
| 11621 | image_create_info.mipLevels = 1; |
Mark Lobodzinski | db11763 | 2016-03-31 10:45:56 -0600 | [diff] [blame] | 11622 | image_create_info.arrayLayers = 4; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 11623 | image_create_info.samples = VK_SAMPLE_COUNT_1_BIT; |
| 11624 | image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL; |
| 11625 | image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT; |
| 11626 | image_create_info.flags = 0; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 11627 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 11628 | err = |
| 11629 | vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 11630 | ASSERT_VK_SUCCESS(err); |
| 11631 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 11632 | err = |
| 11633 | vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 11634 | ASSERT_VK_SUCCESS(err); |
| 11635 | |
| 11636 | // Allocate memory |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 11637 | VkMemoryAllocateInfo memAlloc = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 11638 | memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO; |
| 11639 | memAlloc.pNext = NULL; |
| 11640 | memAlloc.allocationSize = 0; |
| 11641 | memAlloc.memoryTypeIndex = 0; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 11642 | |
Courtney Goeltzenleuchter | 06d8947 | 2015-10-20 16:40:38 -0600 | [diff] [blame] | 11643 | vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 11644 | memAlloc.allocationSize = memReqs.size; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 11645 | pass = |
| 11646 | m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0); |
Courtney Goeltzenleuchter | 1d2f0dd | 2015-10-22 11:03:31 -0600 | [diff] [blame] | 11647 | ASSERT_TRUE(pass); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 11648 | err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 11649 | ASSERT_VK_SUCCESS(err); |
| 11650 | |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 11651 | vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 11652 | memAlloc.allocationSize = memReqs.size; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 11653 | pass = |
| 11654 | m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 11655 | ASSERT_VK_SUCCESS(err); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 11656 | err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 11657 | ASSERT_VK_SUCCESS(err); |
| 11658 | |
| 11659 | err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0); |
| 11660 | ASSERT_VK_SUCCESS(err); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 11661 | err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 11662 | ASSERT_VK_SUCCESS(err); |
| 11663 | |
| 11664 | BeginCommandBuffer(); |
| 11665 | VkImageCopy copyRegion; |
Chia-I Wu | ab83a0e | 2015-10-27 19:00:15 +0800 | [diff] [blame] | 11666 | copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 11667 | copyRegion.srcSubresource.mipLevel = 0; |
Courtney Goeltzenleuchter | 8367ce0 | 2015-10-16 09:46:00 -0600 | [diff] [blame] | 11668 | copyRegion.srcSubresource.baseArrayLayer = 0; |
Mark Lobodzinski | db11763 | 2016-03-31 10:45:56 -0600 | [diff] [blame] | 11669 | copyRegion.srcSubresource.layerCount = 1; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 11670 | copyRegion.srcOffset.x = 0; |
| 11671 | copyRegion.srcOffset.y = 0; |
| 11672 | copyRegion.srcOffset.z = 0; |
Chia-I Wu | ab83a0e | 2015-10-27 19:00:15 +0800 | [diff] [blame] | 11673 | copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 11674 | copyRegion.dstSubresource.mipLevel = 0; |
| 11675 | copyRegion.dstSubresource.baseArrayLayer = 0; |
Mark Lobodzinski | db11763 | 2016-03-31 10:45:56 -0600 | [diff] [blame] | 11676 | // Introduce failure by forcing the dst layerCount to differ from src |
| 11677 | copyRegion.dstSubresource.layerCount = 3; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 11678 | copyRegion.dstOffset.x = 0; |
| 11679 | copyRegion.dstOffset.y = 0; |
| 11680 | copyRegion.dstOffset.z = 0; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 11681 | copyRegion.extent.width = 1; |
| 11682 | copyRegion.extent.height = 1; |
| 11683 | copyRegion.extent.depth = 1; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 11684 | m_commandBuffer->CopyImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, |
| 11685 | VK_IMAGE_LAYOUT_GENERAL, 1, ©Region); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 11686 | EndCommandBuffer(); |
| 11687 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 11688 | m_errorMonitor->VerifyFound(); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 11689 | |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 11690 | vkDestroyImage(m_device->device(), srcImage, NULL); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 11691 | vkDestroyImage(m_device->device(), dstImage, NULL); |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 11692 | vkFreeMemory(m_device->device(), srcMem, NULL); |
| 11693 | vkFreeMemory(m_device->device(), destMem, NULL); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 11694 | } |
| 11695 | |
Tony Barbour | d667364 | 2016-05-05 14:46:39 -0600 | [diff] [blame] | 11696 | TEST_F(VkLayerTest, ImageLayerUnsupportedFormat) { |
| 11697 | |
| 11698 | TEST_DESCRIPTION("Creating images with unsuported formats "); |
| 11699 | |
| 11700 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 11701 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 11702 | VkImageObj image(m_device); |
| 11703 | image.init(128, 128, VK_FORMAT_B8G8R8A8_UNORM, |
| 11704 | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | |
| 11705 | VK_IMAGE_USAGE_TRANSFER_DST_BIT, |
| 11706 | VK_IMAGE_TILING_OPTIMAL, 0); |
| 11707 | ASSERT_TRUE(image.initialized()); |
| 11708 | |
Mark Lobodzinski | ba5c686 | 2016-05-17 08:14:00 -0600 | [diff] [blame] | 11709 | // Create image with unsupported format - Expect FORMAT_UNSUPPORTED |
| 11710 | VkImageCreateInfo image_create_info; |
| 11711 | image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO; |
| 11712 | image_create_info.pNext = NULL; |
| 11713 | image_create_info.imageType = VK_IMAGE_TYPE_2D; |
| 11714 | image_create_info.format = VK_FORMAT_UNDEFINED; |
| 11715 | image_create_info.extent.width = 32; |
| 11716 | image_create_info.extent.height = 32; |
| 11717 | image_create_info.extent.depth = 1; |
| 11718 | image_create_info.mipLevels = 1; |
| 11719 | image_create_info.arrayLayers = 1; |
| 11720 | image_create_info.samples = VK_SAMPLE_COUNT_1_BIT; |
| 11721 | image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL; |
| 11722 | image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT; |
| 11723 | image_create_info.flags = 0; |
| 11724 | |
| 11725 | m_errorMonitor->SetDesiredFailureMsg( |
| 11726 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 11727 | "vkCreateImage: VkFormat for image must not be VK_FORMAT_UNDEFINED"); |
| 11728 | |
| 11729 | VkImage localImage; |
| 11730 | vkCreateImage(m_device->handle(), &image_create_info, NULL, &localImage); |
| 11731 | m_errorMonitor->VerifyFound(); |
| 11732 | |
Tony Barbour | d667364 | 2016-05-05 14:46:39 -0600 | [diff] [blame] | 11733 | VkFormat unsupported = VK_FORMAT_UNDEFINED; |
Mark Lobodzinski | ba5c686 | 2016-05-17 08:14:00 -0600 | [diff] [blame] | 11734 | // Look for a format that is COMPLETELY unsupported with this hardware |
Tony Barbour | d667364 | 2016-05-05 14:46:39 -0600 | [diff] [blame] | 11735 | for (int f = VK_FORMAT_BEGIN_RANGE; f <= VK_FORMAT_END_RANGE; f++) { |
| 11736 | VkFormat format = static_cast<VkFormat>(f); |
| 11737 | VkFormatProperties fProps = m_device->format_properties(format); |
| 11738 | if (format != VK_FORMAT_UNDEFINED && fProps.linearTilingFeatures == 0 && |
| 11739 | fProps.optimalTilingFeatures == 0) { |
| 11740 | unsupported = format; |
| 11741 | break; |
| 11742 | } |
| 11743 | } |
Mark Lobodzinski | ba5c686 | 2016-05-17 08:14:00 -0600 | [diff] [blame] | 11744 | |
Tony Barbour | d667364 | 2016-05-05 14:46:39 -0600 | [diff] [blame] | 11745 | if (unsupported != VK_FORMAT_UNDEFINED) { |
Tony Barbour | d667364 | 2016-05-05 14:46:39 -0600 | [diff] [blame] | 11746 | image_create_info.format = unsupported; |
Tony Barbour | d667364 | 2016-05-05 14:46:39 -0600 | [diff] [blame] | 11747 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Mark Lobodzinski | ba5c686 | 2016-05-17 08:14:00 -0600 | [diff] [blame] | 11748 | "is an unsupported format"); |
Tony Barbour | d667364 | 2016-05-05 14:46:39 -0600 | [diff] [blame] | 11749 | |
Mark Lobodzinski | ba5c686 | 2016-05-17 08:14:00 -0600 | [diff] [blame] | 11750 | vkCreateImage(m_device->handle(), &image_create_info, NULL, &localImage); |
Tony Barbour | d667364 | 2016-05-05 14:46:39 -0600 | [diff] [blame] | 11751 | m_errorMonitor->VerifyFound(); |
| 11752 | } |
| 11753 | } |
| 11754 | |
| 11755 | TEST_F(VkLayerTest, ImageLayerViewTests) { |
| 11756 | VkResult ret; |
| 11757 | TEST_DESCRIPTION("Passing bad parameters to CreateImageView"); |
| 11758 | |
| 11759 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 11760 | |
| 11761 | VkImageObj image(m_device); |
| 11762 | image.init(128, 128, VK_FORMAT_B8G8R8A8_UNORM, |
| 11763 | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | |
| 11764 | VK_IMAGE_USAGE_TRANSFER_DST_BIT, |
| 11765 | VK_IMAGE_TILING_OPTIMAL, 0); |
| 11766 | ASSERT_TRUE(image.initialized()); |
| 11767 | |
| 11768 | VkImageView imgView; |
| 11769 | VkImageViewCreateInfo imgViewInfo = {}; |
| 11770 | imgViewInfo.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO; |
| 11771 | imgViewInfo.image = image.handle(); |
| 11772 | imgViewInfo.viewType = VK_IMAGE_VIEW_TYPE_2D; |
| 11773 | imgViewInfo.format = VK_FORMAT_B8G8R8A8_UNORM; |
| 11774 | imgViewInfo.subresourceRange.layerCount = 1; |
| 11775 | imgViewInfo.subresourceRange.baseMipLevel = 0; |
| 11776 | imgViewInfo.subresourceRange.levelCount = 1; |
| 11777 | imgViewInfo.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; |
| 11778 | |
| 11779 | m_errorMonitor->SetDesiredFailureMsg( |
| 11780 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 11781 | "vkCreateImageView called with baseMipLevel"); |
| 11782 | // View can't have baseMipLevel >= image's mipLevels - Expect |
| 11783 | // VIEW_CREATE_ERROR |
| 11784 | imgViewInfo.subresourceRange.baseMipLevel = 1; |
| 11785 | vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView); |
| 11786 | m_errorMonitor->VerifyFound(); |
| 11787 | imgViewInfo.subresourceRange.baseMipLevel = 0; |
| 11788 | |
| 11789 | m_errorMonitor->SetDesiredFailureMsg( |
| 11790 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 11791 | "vkCreateImageView called with baseArrayLayer"); |
| 11792 | // View can't have baseArrayLayer >= image's arraySize - Expect |
| 11793 | // VIEW_CREATE_ERROR |
| 11794 | imgViewInfo.subresourceRange.baseArrayLayer = 1; |
| 11795 | vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView); |
| 11796 | m_errorMonitor->VerifyFound(); |
| 11797 | imgViewInfo.subresourceRange.baseArrayLayer = 0; |
| 11798 | |
| 11799 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 11800 | "vkCreateImageView called with 0 in " |
| 11801 | "pCreateInfo->subresourceRange." |
| 11802 | "levelCount"); |
| 11803 | // View's levelCount can't be 0 - Expect VIEW_CREATE_ERROR |
| 11804 | imgViewInfo.subresourceRange.levelCount = 0; |
| 11805 | vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView); |
| 11806 | m_errorMonitor->VerifyFound(); |
| 11807 | imgViewInfo.subresourceRange.levelCount = 1; |
| 11808 | |
| 11809 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 11810 | "vkCreateImageView called with 0 in " |
| 11811 | "pCreateInfo->subresourceRange." |
| 11812 | "layerCount"); |
| 11813 | // View's layerCount can't be 0 - Expect VIEW_CREATE_ERROR |
| 11814 | imgViewInfo.subresourceRange.layerCount = 0; |
| 11815 | vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView); |
| 11816 | m_errorMonitor->VerifyFound(); |
| 11817 | imgViewInfo.subresourceRange.layerCount = 1; |
| 11818 | |
| 11819 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 11820 | "but both must be color formats"); |
| 11821 | // Can't use depth format for view into color image - Expect INVALID_FORMAT |
| 11822 | imgViewInfo.format = VK_FORMAT_D24_UNORM_S8_UINT; |
| 11823 | vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView); |
| 11824 | m_errorMonitor->VerifyFound(); |
| 11825 | imgViewInfo.format = VK_FORMAT_B8G8R8A8_UNORM; |
| 11826 | |
| 11827 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 11828 | "Formats MUST be IDENTICAL unless " |
| 11829 | "VK_IMAGE_CREATE_MUTABLE_FORMAT BIT " |
| 11830 | "was set on image creation."); |
| 11831 | // Same compatibility class but no MUTABLE_FORMAT bit - Expect |
| 11832 | // VIEW_CREATE_ERROR |
| 11833 | imgViewInfo.format = VK_FORMAT_B8G8R8A8_UINT; |
| 11834 | vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView); |
| 11835 | m_errorMonitor->VerifyFound(); |
| 11836 | imgViewInfo.format = VK_FORMAT_B8G8R8A8_UNORM; |
| 11837 | |
| 11838 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 11839 | "can support ImageViews with " |
| 11840 | "differing formats but they must be " |
| 11841 | "in the same compatibility class."); |
| 11842 | // Have MUTABLE_FORMAT bit but not in same compatibility class - Expect |
| 11843 | // VIEW_CREATE_ERROR |
| 11844 | VkImageCreateInfo mutImgInfo = image.create_info(); |
| 11845 | VkImage mutImage; |
| 11846 | mutImgInfo.format = VK_FORMAT_R8_UINT; |
| 11847 | assert( |
| 11848 | m_device->format_properties(VK_FORMAT_R8_UINT).optimalTilingFeatures & |
| 11849 | VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT); |
| 11850 | mutImgInfo.flags = VK_IMAGE_CREATE_MUTABLE_FORMAT_BIT; |
| 11851 | mutImgInfo.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT; |
| 11852 | ret = vkCreateImage(m_device->handle(), &mutImgInfo, NULL, &mutImage); |
| 11853 | ASSERT_VK_SUCCESS(ret); |
| 11854 | imgViewInfo.image = mutImage; |
| 11855 | vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView); |
| 11856 | m_errorMonitor->VerifyFound(); |
| 11857 | imgViewInfo.image = image.handle(); |
| 11858 | vkDestroyImage(m_device->handle(), mutImage, NULL); |
| 11859 | } |
| 11860 | |
| 11861 | TEST_F(VkLayerTest, MiscImageLayerTests) { |
| 11862 | |
| 11863 | TEST_DESCRIPTION("Image layer tests that don't belong elsewhare"); |
| 11864 | |
| 11865 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 11866 | |
| 11867 | VkImageObj image(m_device); |
| 11868 | image.init(128, 128, VK_FORMAT_B8G8R8A8_UNORM, |
| 11869 | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | |
| 11870 | VK_IMAGE_USAGE_TRANSFER_DST_BIT, |
| 11871 | VK_IMAGE_TILING_OPTIMAL, 0); |
| 11872 | ASSERT_TRUE(image.initialized()); |
| 11873 | |
| 11874 | m_errorMonitor->SetDesiredFailureMsg( |
| 11875 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 11876 | "number of layers in image subresource is zero"); |
| 11877 | vk_testing::Buffer buffer; |
| 11878 | VkMemoryPropertyFlags reqs = 0; |
| 11879 | buffer.init_as_src(*m_device, 128 * 128 * 4, reqs); |
| 11880 | VkBufferImageCopy region = {}; |
| 11881 | region.bufferRowLength = 128; |
| 11882 | region.bufferImageHeight = 128; |
| 11883 | region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; |
| 11884 | // layerCount can't be 0 - Expect MISMATCHED_IMAGE_ASPECT |
| 11885 | region.imageSubresource.layerCount = 0; |
| 11886 | region.imageExtent.height = 4; |
| 11887 | region.imageExtent.width = 4; |
| 11888 | region.imageExtent.depth = 1; |
| 11889 | m_commandBuffer->BeginCommandBuffer(); |
| 11890 | vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), |
| 11891 | image.handle(), VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, |
| 11892 | 1, ®ion); |
| 11893 | m_errorMonitor->VerifyFound(); |
| 11894 | region.imageSubresource.layerCount = 1; |
| 11895 | |
| 11896 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 11897 | "aspectMasks for each region must " |
| 11898 | "specify only COLOR or DEPTH or " |
| 11899 | "STENCIL"); |
| 11900 | // Expect MISMATCHED_IMAGE_ASPECT |
| 11901 | region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_METADATA_BIT; |
| 11902 | vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), |
| 11903 | image.handle(), VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, |
| 11904 | 1, ®ion); |
| 11905 | m_errorMonitor->VerifyFound(); |
| 11906 | region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; |
| 11907 | |
| 11908 | m_errorMonitor->SetDesiredFailureMsg( |
| 11909 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 11910 | "If the format of srcImage is a depth, stencil, depth stencil or " |
| 11911 | "integer-based format then filter must be VK_FILTER_NEAREST"); |
| 11912 | // Expect INVALID_FILTER |
| 11913 | VkImageObj intImage1(m_device); |
| 11914 | intImage1.init(128, 128, VK_FORMAT_R8_UINT, |
| 11915 | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, |
| 11916 | 0); |
| 11917 | VkImageObj intImage2(m_device); |
| 11918 | intImage2.init(128, 128, VK_FORMAT_R8_UINT, |
| 11919 | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, |
| 11920 | 0); |
| 11921 | VkImageBlit blitRegion = {}; |
| 11922 | blitRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; |
| 11923 | blitRegion.srcSubresource.baseArrayLayer = 0; |
| 11924 | blitRegion.srcSubresource.layerCount = 1; |
| 11925 | blitRegion.srcSubresource.mipLevel = 0; |
| 11926 | blitRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; |
| 11927 | blitRegion.dstSubresource.baseArrayLayer = 0; |
| 11928 | blitRegion.dstSubresource.layerCount = 1; |
| 11929 | blitRegion.dstSubresource.mipLevel = 0; |
| 11930 | |
| 11931 | vkCmdBlitImage(m_commandBuffer->GetBufferHandle(), intImage1.handle(), |
| 11932 | intImage1.layout(), intImage2.handle(), intImage2.layout(), |
| 11933 | 16, &blitRegion, VK_FILTER_LINEAR); |
| 11934 | m_errorMonitor->VerifyFound(); |
| 11935 | |
| 11936 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 11937 | "called with 0 in ppMemoryBarriers"); |
| 11938 | VkImageMemoryBarrier img_barrier; |
| 11939 | img_barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER; |
| 11940 | img_barrier.pNext = NULL; |
| 11941 | img_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT; |
| 11942 | img_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT; |
| 11943 | img_barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL; |
| 11944 | img_barrier.newLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL; |
| 11945 | img_barrier.image = image.handle(); |
| 11946 | img_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED; |
| 11947 | img_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED; |
| 11948 | img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; |
| 11949 | img_barrier.subresourceRange.baseArrayLayer = 0; |
| 11950 | img_barrier.subresourceRange.baseMipLevel = 0; |
| 11951 | // layerCount should not be 0 - Expect INVALID_IMAGE_RESOURCE |
| 11952 | img_barrier.subresourceRange.layerCount = 0; |
| 11953 | img_barrier.subresourceRange.levelCount = 1; |
| 11954 | vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), |
| 11955 | VK_PIPELINE_STAGE_HOST_BIT, |
| 11956 | VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0, nullptr, 0, |
| 11957 | nullptr, 1, &img_barrier); |
| 11958 | m_errorMonitor->VerifyFound(); |
| 11959 | img_barrier.subresourceRange.layerCount = 1; |
| 11960 | } |
| 11961 | |
| 11962 | TEST_F(VkLayerTest, ImageFormatLimits) { |
| 11963 | |
| 11964 | TEST_DESCRIPTION("Exceed the limits of image format "); |
| 11965 | |
| 11966 | m_errorMonitor->SetDesiredFailureMsg( |
| 11967 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 11968 | "CreateImage extents exceed allowable limits for format"); |
| 11969 | VkImageCreateInfo image_create_info = {}; |
| 11970 | image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO; |
| 11971 | image_create_info.pNext = NULL; |
| 11972 | image_create_info.imageType = VK_IMAGE_TYPE_2D; |
| 11973 | image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM; |
| 11974 | image_create_info.extent.width = 32; |
| 11975 | image_create_info.extent.height = 32; |
| 11976 | image_create_info.extent.depth = 1; |
| 11977 | image_create_info.mipLevels = 1; |
| 11978 | image_create_info.arrayLayers = 1; |
| 11979 | image_create_info.samples = VK_SAMPLE_COUNT_1_BIT; |
| 11980 | image_create_info.tiling = VK_IMAGE_TILING_LINEAR; |
| 11981 | image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT; |
| 11982 | image_create_info.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED; |
| 11983 | image_create_info.flags = 0; |
| 11984 | |
| 11985 | VkImage nullImg; |
| 11986 | VkImageFormatProperties imgFmtProps; |
| 11987 | vkGetPhysicalDeviceImageFormatProperties( |
| 11988 | gpu(), image_create_info.format, image_create_info.imageType, |
| 11989 | image_create_info.tiling, image_create_info.usage, |
| 11990 | image_create_info.flags, &imgFmtProps); |
| 11991 | image_create_info.extent.depth = imgFmtProps.maxExtent.depth + 1; |
| 11992 | // Expect INVALID_FORMAT_LIMITS_VIOLATION |
| 11993 | vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg); |
| 11994 | m_errorMonitor->VerifyFound(); |
| 11995 | image_create_info.extent.depth = 1; |
| 11996 | |
| 11997 | m_errorMonitor->SetDesiredFailureMsg( |
| 11998 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 11999 | "exceeds allowable maximum supported by format of"); |
| 12000 | image_create_info.mipLevels = imgFmtProps.maxMipLevels + 1; |
| 12001 | // Expect INVALID_FORMAT_LIMITS_VIOLATION |
| 12002 | vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg); |
| 12003 | m_errorMonitor->VerifyFound(); |
| 12004 | image_create_info.mipLevels = 1; |
| 12005 | |
| 12006 | m_errorMonitor->SetDesiredFailureMsg( |
| 12007 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 12008 | "exceeds allowable maximum supported by format of"); |
| 12009 | image_create_info.arrayLayers = imgFmtProps.maxArrayLayers + 1; |
| 12010 | // Expect INVALID_FORMAT_LIMITS_VIOLATION |
| 12011 | vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg); |
| 12012 | m_errorMonitor->VerifyFound(); |
| 12013 | image_create_info.arrayLayers = 1; |
| 12014 | |
| 12015 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 12016 | "is not supported by format"); |
| 12017 | int samples = imgFmtProps.sampleCounts >> 1; |
| 12018 | image_create_info.samples = (VkSampleCountFlagBits)samples; |
| 12019 | // Expect INVALID_FORMAT_LIMITS_VIOLATION |
| 12020 | vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg); |
| 12021 | m_errorMonitor->VerifyFound(); |
| 12022 | image_create_info.samples = VK_SAMPLE_COUNT_1_BIT; |
| 12023 | |
| 12024 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 12025 | "pCreateInfo->initialLayout, must be " |
| 12026 | "VK_IMAGE_LAYOUT_UNDEFINED or " |
| 12027 | "VK_IMAGE_LAYOUT_PREINITIALIZED"); |
| 12028 | image_create_info.initialLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL; |
| 12029 | // Expect INVALID_LAYOUT |
| 12030 | vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg); |
| 12031 | m_errorMonitor->VerifyFound(); |
| 12032 | image_create_info.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED; |
| 12033 | } |
| 12034 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12035 | TEST_F(VkLayerTest, CopyImageFormatSizeMismatch) { |
Karl Schultz | bdb7595 | 2016-04-19 11:36:49 -0600 | [diff] [blame] | 12036 | VkResult err; |
| 12037 | bool pass; |
| 12038 | |
| 12039 | // Create color images with different format sizes and try to copy between them |
| 12040 | m_errorMonitor->SetDesiredFailureMsg( |
| 12041 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 12042 | "vkCmdCopyImage called with unmatched source and dest image format sizes"); |
| 12043 | |
| 12044 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 12045 | |
| 12046 | // Create two images of different types and try to copy between them |
| 12047 | VkImage srcImage; |
| 12048 | VkImage dstImage; |
| 12049 | VkDeviceMemory srcMem; |
| 12050 | VkDeviceMemory destMem; |
| 12051 | VkMemoryRequirements memReqs; |
| 12052 | |
| 12053 | VkImageCreateInfo image_create_info = {}; |
| 12054 | image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO; |
| 12055 | image_create_info.pNext = NULL; |
| 12056 | image_create_info.imageType = VK_IMAGE_TYPE_2D; |
| 12057 | image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM; |
| 12058 | image_create_info.extent.width = 32; |
| 12059 | image_create_info.extent.height = 32; |
| 12060 | image_create_info.extent.depth = 1; |
| 12061 | image_create_info.mipLevels = 1; |
| 12062 | image_create_info.arrayLayers = 1; |
| 12063 | image_create_info.samples = VK_SAMPLE_COUNT_1_BIT; |
| 12064 | image_create_info.tiling = VK_IMAGE_TILING_LINEAR; |
| 12065 | image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT; |
| 12066 | image_create_info.flags = 0; |
| 12067 | |
| 12068 | err = |
| 12069 | vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage); |
| 12070 | ASSERT_VK_SUCCESS(err); |
| 12071 | |
| 12072 | image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT; |
| 12073 | // Introduce failure by creating second image with a different-sized format. |
| 12074 | image_create_info.format = VK_FORMAT_R5G5B5A1_UNORM_PACK16; |
| 12075 | |
| 12076 | err = |
| 12077 | vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage); |
| 12078 | ASSERT_VK_SUCCESS(err); |
| 12079 | |
| 12080 | // Allocate memory |
| 12081 | VkMemoryAllocateInfo memAlloc = {}; |
| 12082 | memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO; |
| 12083 | memAlloc.pNext = NULL; |
| 12084 | memAlloc.allocationSize = 0; |
| 12085 | memAlloc.memoryTypeIndex = 0; |
| 12086 | |
| 12087 | vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs); |
| 12088 | memAlloc.allocationSize = memReqs.size; |
| 12089 | pass = |
| 12090 | m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0); |
| 12091 | ASSERT_TRUE(pass); |
| 12092 | err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem); |
| 12093 | ASSERT_VK_SUCCESS(err); |
| 12094 | |
| 12095 | vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs); |
| 12096 | memAlloc.allocationSize = memReqs.size; |
| 12097 | pass = |
| 12098 | m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0); |
| 12099 | ASSERT_TRUE(pass); |
| 12100 | err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem); |
| 12101 | ASSERT_VK_SUCCESS(err); |
| 12102 | |
| 12103 | err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0); |
| 12104 | ASSERT_VK_SUCCESS(err); |
| 12105 | err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0); |
| 12106 | ASSERT_VK_SUCCESS(err); |
| 12107 | |
| 12108 | BeginCommandBuffer(); |
| 12109 | VkImageCopy copyRegion; |
| 12110 | copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; |
| 12111 | copyRegion.srcSubresource.mipLevel = 0; |
| 12112 | copyRegion.srcSubresource.baseArrayLayer = 0; |
| 12113 | copyRegion.srcSubresource.layerCount = 0; |
| 12114 | copyRegion.srcOffset.x = 0; |
| 12115 | copyRegion.srcOffset.y = 0; |
| 12116 | copyRegion.srcOffset.z = 0; |
| 12117 | copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; |
| 12118 | copyRegion.dstSubresource.mipLevel = 0; |
| 12119 | copyRegion.dstSubresource.baseArrayLayer = 0; |
| 12120 | copyRegion.dstSubresource.layerCount = 0; |
| 12121 | copyRegion.dstOffset.x = 0; |
| 12122 | copyRegion.dstOffset.y = 0; |
| 12123 | copyRegion.dstOffset.z = 0; |
| 12124 | copyRegion.extent.width = 1; |
| 12125 | copyRegion.extent.height = 1; |
| 12126 | copyRegion.extent.depth = 1; |
| 12127 | m_commandBuffer->CopyImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, |
| 12128 | VK_IMAGE_LAYOUT_GENERAL, 1, ©Region); |
| 12129 | EndCommandBuffer(); |
| 12130 | |
| 12131 | m_errorMonitor->VerifyFound(); |
| 12132 | |
| 12133 | vkDestroyImage(m_device->device(), srcImage, NULL); |
| 12134 | vkDestroyImage(m_device->device(), dstImage, NULL); |
| 12135 | vkFreeMemory(m_device->device(), srcMem, NULL); |
| 12136 | vkFreeMemory(m_device->device(), destMem, NULL); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12137 | } |
| 12138 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12139 | TEST_F(VkLayerTest, CopyImageDepthStencilFormatMismatch) { |
| 12140 | VkResult err; |
| 12141 | bool pass; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12142 | |
Mark Lobodzinski | db11763 | 2016-03-31 10:45:56 -0600 | [diff] [blame] | 12143 | // Create a color image and a depth/stencil image and try to copy between them |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12144 | m_errorMonitor->SetDesiredFailureMsg( |
| 12145 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Mark Lobodzinski | db11763 | 2016-03-31 10:45:56 -0600 | [diff] [blame] | 12146 | "vkCmdCopyImage called with unmatched source and dest image depth"); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 12147 | |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12148 | ASSERT_NO_FATAL_FAILURE(InitState()); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12149 | |
| 12150 | // Create two images of different types and try to copy between them |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12151 | VkImage srcImage; |
| 12152 | VkImage dstImage; |
| 12153 | VkDeviceMemory srcMem; |
| 12154 | VkDeviceMemory destMem; |
| 12155 | VkMemoryRequirements memReqs; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12156 | |
| 12157 | VkImageCreateInfo image_create_info = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12158 | image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO; |
| 12159 | image_create_info.pNext = NULL; |
| 12160 | image_create_info.imageType = VK_IMAGE_TYPE_2D; |
| 12161 | image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM; |
| 12162 | image_create_info.extent.width = 32; |
| 12163 | image_create_info.extent.height = 32; |
| 12164 | image_create_info.extent.depth = 1; |
| 12165 | image_create_info.mipLevels = 1; |
| 12166 | image_create_info.arrayLayers = 1; |
| 12167 | image_create_info.samples = VK_SAMPLE_COUNT_1_BIT; |
| 12168 | image_create_info.tiling = VK_IMAGE_TILING_LINEAR; |
| 12169 | image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT; |
| 12170 | image_create_info.flags = 0; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12171 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12172 | err = |
| 12173 | vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12174 | ASSERT_VK_SUCCESS(err); |
| 12175 | |
Karl Schultz | bdb7595 | 2016-04-19 11:36:49 -0600 | [diff] [blame] | 12176 | image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT; |
| 12177 | |
Mark Lobodzinski | db11763 | 2016-03-31 10:45:56 -0600 | [diff] [blame] | 12178 | // Introduce failure by creating second image with a depth/stencil format |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12179 | image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL; |
Mark Lobodzinski | db11763 | 2016-03-31 10:45:56 -0600 | [diff] [blame] | 12180 | image_create_info.format = VK_FORMAT_D24_UNORM_S8_UINT; |
| 12181 | image_create_info.usage = VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12182 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12183 | err = |
| 12184 | vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12185 | ASSERT_VK_SUCCESS(err); |
| 12186 | |
| 12187 | // Allocate memory |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 12188 | VkMemoryAllocateInfo memAlloc = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12189 | memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO; |
| 12190 | memAlloc.pNext = NULL; |
| 12191 | memAlloc.allocationSize = 0; |
| 12192 | memAlloc.memoryTypeIndex = 0; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12193 | |
Courtney Goeltzenleuchter | 06d8947 | 2015-10-20 16:40:38 -0600 | [diff] [blame] | 12194 | vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12195 | memAlloc.allocationSize = memReqs.size; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12196 | pass = |
| 12197 | m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0); |
Courtney Goeltzenleuchter | 1d2f0dd | 2015-10-22 11:03:31 -0600 | [diff] [blame] | 12198 | ASSERT_TRUE(pass); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 12199 | err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12200 | ASSERT_VK_SUCCESS(err); |
| 12201 | |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 12202 | vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12203 | memAlloc.allocationSize = memReqs.size; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12204 | pass = |
| 12205 | m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0); |
Courtney Goeltzenleuchter | 1d2f0dd | 2015-10-22 11:03:31 -0600 | [diff] [blame] | 12206 | ASSERT_TRUE(pass); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 12207 | err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12208 | ASSERT_VK_SUCCESS(err); |
| 12209 | |
| 12210 | err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0); |
| 12211 | ASSERT_VK_SUCCESS(err); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 12212 | err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12213 | ASSERT_VK_SUCCESS(err); |
| 12214 | |
| 12215 | BeginCommandBuffer(); |
| 12216 | VkImageCopy copyRegion; |
Chia-I Wu | ab83a0e | 2015-10-27 19:00:15 +0800 | [diff] [blame] | 12217 | copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12218 | copyRegion.srcSubresource.mipLevel = 0; |
Courtney Goeltzenleuchter | 8367ce0 | 2015-10-16 09:46:00 -0600 | [diff] [blame] | 12219 | copyRegion.srcSubresource.baseArrayLayer = 0; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 12220 | copyRegion.srcSubresource.layerCount = 0; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12221 | copyRegion.srcOffset.x = 0; |
| 12222 | copyRegion.srcOffset.y = 0; |
| 12223 | copyRegion.srcOffset.z = 0; |
Chia-I Wu | ab83a0e | 2015-10-27 19:00:15 +0800 | [diff] [blame] | 12224 | copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 12225 | copyRegion.dstSubresource.mipLevel = 0; |
| 12226 | copyRegion.dstSubresource.baseArrayLayer = 0; |
| 12227 | copyRegion.dstSubresource.layerCount = 0; |
| 12228 | copyRegion.dstOffset.x = 0; |
| 12229 | copyRegion.dstOffset.y = 0; |
| 12230 | copyRegion.dstOffset.z = 0; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12231 | copyRegion.extent.width = 1; |
| 12232 | copyRegion.extent.height = 1; |
| 12233 | copyRegion.extent.depth = 1; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12234 | m_commandBuffer->CopyImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, |
| 12235 | VK_IMAGE_LAYOUT_GENERAL, 1, ©Region); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12236 | EndCommandBuffer(); |
| 12237 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 12238 | m_errorMonitor->VerifyFound(); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12239 | |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 12240 | vkDestroyImage(m_device->device(), srcImage, NULL); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 12241 | vkDestroyImage(m_device->device(), dstImage, NULL); |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 12242 | vkFreeMemory(m_device->device(), srcMem, NULL); |
| 12243 | vkFreeMemory(m_device->device(), destMem, NULL); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12244 | } |
| 12245 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12246 | TEST_F(VkLayerTest, ResolveImageLowSampleCount) { |
| 12247 | VkResult err; |
| 12248 | bool pass; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12249 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12250 | m_errorMonitor->SetDesiredFailureMsg( |
| 12251 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 12252 | "vkCmdResolveImage called with source sample count less than 2."); |
| 12253 | |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12254 | ASSERT_NO_FATAL_FAILURE(InitState()); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12255 | |
| 12256 | // Create two images of sample count 1 and try to Resolve between them |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12257 | VkImage srcImage; |
| 12258 | VkImage dstImage; |
| 12259 | VkDeviceMemory srcMem; |
| 12260 | VkDeviceMemory destMem; |
| 12261 | VkMemoryRequirements memReqs; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12262 | |
| 12263 | VkImageCreateInfo image_create_info = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12264 | image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO; |
| 12265 | image_create_info.pNext = NULL; |
| 12266 | image_create_info.imageType = VK_IMAGE_TYPE_2D; |
| 12267 | image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM; |
| 12268 | image_create_info.extent.width = 32; |
| 12269 | image_create_info.extent.height = 1; |
| 12270 | image_create_info.extent.depth = 1; |
| 12271 | image_create_info.mipLevels = 1; |
| 12272 | image_create_info.arrayLayers = 1; |
| 12273 | image_create_info.samples = VK_SAMPLE_COUNT_1_BIT; |
| 12274 | image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL; |
| 12275 | image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT; |
| 12276 | image_create_info.flags = 0; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12277 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12278 | err = |
| 12279 | vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12280 | ASSERT_VK_SUCCESS(err); |
| 12281 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12282 | image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12283 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12284 | err = |
| 12285 | vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12286 | ASSERT_VK_SUCCESS(err); |
| 12287 | |
| 12288 | // Allocate memory |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 12289 | VkMemoryAllocateInfo memAlloc = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12290 | memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO; |
| 12291 | memAlloc.pNext = NULL; |
| 12292 | memAlloc.allocationSize = 0; |
| 12293 | memAlloc.memoryTypeIndex = 0; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12294 | |
Courtney Goeltzenleuchter | 06d8947 | 2015-10-20 16:40:38 -0600 | [diff] [blame] | 12295 | vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12296 | memAlloc.allocationSize = memReqs.size; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12297 | pass = |
| 12298 | m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0); |
Courtney Goeltzenleuchter | 1d2f0dd | 2015-10-22 11:03:31 -0600 | [diff] [blame] | 12299 | ASSERT_TRUE(pass); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 12300 | err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12301 | ASSERT_VK_SUCCESS(err); |
| 12302 | |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 12303 | vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12304 | memAlloc.allocationSize = memReqs.size; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12305 | pass = |
| 12306 | m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0); |
Courtney Goeltzenleuchter | 1d2f0dd | 2015-10-22 11:03:31 -0600 | [diff] [blame] | 12307 | ASSERT_TRUE(pass); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 12308 | err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12309 | ASSERT_VK_SUCCESS(err); |
| 12310 | |
| 12311 | err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0); |
| 12312 | ASSERT_VK_SUCCESS(err); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 12313 | err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12314 | ASSERT_VK_SUCCESS(err); |
| 12315 | |
| 12316 | BeginCommandBuffer(); |
| 12317 | // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest? |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12318 | // VK_IMAGE_LAYOUT_UNDEFINED = 0, |
| 12319 | // VK_IMAGE_LAYOUT_GENERAL = 1, |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12320 | VkImageResolve resolveRegion; |
Chia-I Wu | ab83a0e | 2015-10-27 19:00:15 +0800 | [diff] [blame] | 12321 | resolveRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12322 | resolveRegion.srcSubresource.mipLevel = 0; |
Courtney Goeltzenleuchter | 8367ce0 | 2015-10-16 09:46:00 -0600 | [diff] [blame] | 12323 | resolveRegion.srcSubresource.baseArrayLayer = 0; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 12324 | resolveRegion.srcSubresource.layerCount = 0; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12325 | resolveRegion.srcOffset.x = 0; |
| 12326 | resolveRegion.srcOffset.y = 0; |
| 12327 | resolveRegion.srcOffset.z = 0; |
Chia-I Wu | ab83a0e | 2015-10-27 19:00:15 +0800 | [diff] [blame] | 12328 | resolveRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 12329 | resolveRegion.dstSubresource.mipLevel = 0; |
| 12330 | resolveRegion.dstSubresource.baseArrayLayer = 0; |
| 12331 | resolveRegion.dstSubresource.layerCount = 0; |
| 12332 | resolveRegion.dstOffset.x = 0; |
| 12333 | resolveRegion.dstOffset.y = 0; |
| 12334 | resolveRegion.dstOffset.z = 0; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12335 | resolveRegion.extent.width = 1; |
| 12336 | resolveRegion.extent.height = 1; |
| 12337 | resolveRegion.extent.depth = 1; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12338 | m_commandBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, |
| 12339 | VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12340 | EndCommandBuffer(); |
| 12341 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 12342 | m_errorMonitor->VerifyFound(); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12343 | |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 12344 | vkDestroyImage(m_device->device(), srcImage, NULL); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 12345 | vkDestroyImage(m_device->device(), dstImage, NULL); |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 12346 | vkFreeMemory(m_device->device(), srcMem, NULL); |
| 12347 | vkFreeMemory(m_device->device(), destMem, NULL); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12348 | } |
| 12349 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12350 | TEST_F(VkLayerTest, ResolveImageHighSampleCount) { |
| 12351 | VkResult err; |
| 12352 | bool pass; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12353 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12354 | m_errorMonitor->SetDesiredFailureMsg( |
| 12355 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 12356 | "vkCmdResolveImage called with dest sample count greater than 1."); |
| 12357 | |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12358 | ASSERT_NO_FATAL_FAILURE(InitState()); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12359 | |
Chris Forbes | a753069 | 2016-05-08 12:35:39 +1200 | [diff] [blame] | 12360 | // Create two images of sample count 4 and try to Resolve between them |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12361 | VkImage srcImage; |
| 12362 | VkImage dstImage; |
| 12363 | VkDeviceMemory srcMem; |
| 12364 | VkDeviceMemory destMem; |
| 12365 | VkMemoryRequirements memReqs; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12366 | |
| 12367 | VkImageCreateInfo image_create_info = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12368 | image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO; |
| 12369 | image_create_info.pNext = NULL; |
| 12370 | image_create_info.imageType = VK_IMAGE_TYPE_2D; |
| 12371 | image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM; |
| 12372 | image_create_info.extent.width = 32; |
| 12373 | image_create_info.extent.height = 1; |
| 12374 | image_create_info.extent.depth = 1; |
| 12375 | image_create_info.mipLevels = 1; |
| 12376 | image_create_info.arrayLayers = 1; |
Chris Forbes | a753069 | 2016-05-08 12:35:39 +1200 | [diff] [blame] | 12377 | image_create_info.samples = VK_SAMPLE_COUNT_4_BIT; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12378 | image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL; |
| 12379 | // Note: Some implementations expect color attachment usage for any |
| 12380 | // multisample surface |
| 12381 | image_create_info.usage = |
| 12382 | VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT; |
| 12383 | image_create_info.flags = 0; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12384 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12385 | err = |
| 12386 | vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12387 | ASSERT_VK_SUCCESS(err); |
| 12388 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12389 | // Note: Some implementations expect color attachment usage for any |
| 12390 | // multisample surface |
| 12391 | image_create_info.usage = |
| 12392 | VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12393 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12394 | err = |
| 12395 | vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12396 | ASSERT_VK_SUCCESS(err); |
| 12397 | |
| 12398 | // Allocate memory |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 12399 | VkMemoryAllocateInfo memAlloc = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12400 | memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO; |
| 12401 | memAlloc.pNext = NULL; |
| 12402 | memAlloc.allocationSize = 0; |
| 12403 | memAlloc.memoryTypeIndex = 0; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12404 | |
Courtney Goeltzenleuchter | 06d8947 | 2015-10-20 16:40:38 -0600 | [diff] [blame] | 12405 | vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12406 | memAlloc.allocationSize = memReqs.size; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12407 | pass = |
| 12408 | m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0); |
Courtney Goeltzenleuchter | 1d2f0dd | 2015-10-22 11:03:31 -0600 | [diff] [blame] | 12409 | ASSERT_TRUE(pass); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 12410 | err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12411 | ASSERT_VK_SUCCESS(err); |
| 12412 | |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 12413 | vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12414 | memAlloc.allocationSize = memReqs.size; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12415 | pass = |
| 12416 | m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0); |
Courtney Goeltzenleuchter | 1d2f0dd | 2015-10-22 11:03:31 -0600 | [diff] [blame] | 12417 | ASSERT_TRUE(pass); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 12418 | err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12419 | ASSERT_VK_SUCCESS(err); |
| 12420 | |
| 12421 | err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0); |
| 12422 | ASSERT_VK_SUCCESS(err); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 12423 | err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12424 | ASSERT_VK_SUCCESS(err); |
| 12425 | |
| 12426 | BeginCommandBuffer(); |
| 12427 | // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest? |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12428 | // VK_IMAGE_LAYOUT_UNDEFINED = 0, |
| 12429 | // VK_IMAGE_LAYOUT_GENERAL = 1, |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12430 | VkImageResolve resolveRegion; |
Chia-I Wu | ab83a0e | 2015-10-27 19:00:15 +0800 | [diff] [blame] | 12431 | resolveRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12432 | resolveRegion.srcSubresource.mipLevel = 0; |
Courtney Goeltzenleuchter | 8367ce0 | 2015-10-16 09:46:00 -0600 | [diff] [blame] | 12433 | resolveRegion.srcSubresource.baseArrayLayer = 0; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 12434 | resolveRegion.srcSubresource.layerCount = 0; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12435 | resolveRegion.srcOffset.x = 0; |
| 12436 | resolveRegion.srcOffset.y = 0; |
| 12437 | resolveRegion.srcOffset.z = 0; |
Chia-I Wu | ab83a0e | 2015-10-27 19:00:15 +0800 | [diff] [blame] | 12438 | resolveRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 12439 | resolveRegion.dstSubresource.mipLevel = 0; |
| 12440 | resolveRegion.dstSubresource.baseArrayLayer = 0; |
| 12441 | resolveRegion.dstSubresource.layerCount = 0; |
| 12442 | resolveRegion.dstOffset.x = 0; |
| 12443 | resolveRegion.dstOffset.y = 0; |
| 12444 | resolveRegion.dstOffset.z = 0; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12445 | resolveRegion.extent.width = 1; |
| 12446 | resolveRegion.extent.height = 1; |
| 12447 | resolveRegion.extent.depth = 1; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12448 | m_commandBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, |
| 12449 | VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12450 | EndCommandBuffer(); |
| 12451 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 12452 | m_errorMonitor->VerifyFound(); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12453 | |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 12454 | vkDestroyImage(m_device->device(), srcImage, NULL); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 12455 | vkDestroyImage(m_device->device(), dstImage, NULL); |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 12456 | vkFreeMemory(m_device->device(), srcMem, NULL); |
| 12457 | vkFreeMemory(m_device->device(), destMem, NULL); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12458 | } |
| 12459 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12460 | TEST_F(VkLayerTest, ResolveImageFormatMismatch) { |
| 12461 | VkResult err; |
| 12462 | bool pass; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12463 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12464 | m_errorMonitor->SetDesiredFailureMsg( |
| 12465 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 12466 | "vkCmdResolveImage called with unmatched source and dest formats."); |
| 12467 | |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12468 | ASSERT_NO_FATAL_FAILURE(InitState()); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12469 | |
| 12470 | // Create two images of different types and try to copy between them |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12471 | VkImage srcImage; |
| 12472 | VkImage dstImage; |
| 12473 | VkDeviceMemory srcMem; |
| 12474 | VkDeviceMemory destMem; |
| 12475 | VkMemoryRequirements memReqs; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12476 | |
| 12477 | VkImageCreateInfo image_create_info = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12478 | image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO; |
| 12479 | image_create_info.pNext = NULL; |
| 12480 | image_create_info.imageType = VK_IMAGE_TYPE_2D; |
| 12481 | image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM; |
| 12482 | image_create_info.extent.width = 32; |
| 12483 | image_create_info.extent.height = 1; |
| 12484 | image_create_info.extent.depth = 1; |
| 12485 | image_create_info.mipLevels = 1; |
| 12486 | image_create_info.arrayLayers = 1; |
| 12487 | image_create_info.samples = VK_SAMPLE_COUNT_2_BIT; |
| 12488 | image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL; |
| 12489 | // Note: Some implementations expect color attachment usage for any |
| 12490 | // multisample surface |
| 12491 | image_create_info.usage = |
| 12492 | VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT; |
| 12493 | image_create_info.flags = 0; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12494 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12495 | err = |
| 12496 | vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12497 | ASSERT_VK_SUCCESS(err); |
| 12498 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12499 | // Set format to something other than source image |
| 12500 | image_create_info.format = VK_FORMAT_R32_SFLOAT; |
| 12501 | // Note: Some implementations expect color attachment usage for any |
| 12502 | // multisample surface |
| 12503 | image_create_info.usage = |
| 12504 | VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT; |
| 12505 | image_create_info.samples = VK_SAMPLE_COUNT_1_BIT; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12506 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12507 | err = |
| 12508 | vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12509 | ASSERT_VK_SUCCESS(err); |
| 12510 | |
| 12511 | // Allocate memory |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 12512 | VkMemoryAllocateInfo memAlloc = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12513 | memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO; |
| 12514 | memAlloc.pNext = NULL; |
| 12515 | memAlloc.allocationSize = 0; |
| 12516 | memAlloc.memoryTypeIndex = 0; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12517 | |
Courtney Goeltzenleuchter | 06d8947 | 2015-10-20 16:40:38 -0600 | [diff] [blame] | 12518 | vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12519 | memAlloc.allocationSize = memReqs.size; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12520 | pass = |
| 12521 | m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0); |
Courtney Goeltzenleuchter | 1d2f0dd | 2015-10-22 11:03:31 -0600 | [diff] [blame] | 12522 | ASSERT_TRUE(pass); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 12523 | err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12524 | ASSERT_VK_SUCCESS(err); |
| 12525 | |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 12526 | vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12527 | memAlloc.allocationSize = memReqs.size; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12528 | pass = |
| 12529 | m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0); |
Courtney Goeltzenleuchter | 1d2f0dd | 2015-10-22 11:03:31 -0600 | [diff] [blame] | 12530 | ASSERT_TRUE(pass); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 12531 | err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12532 | ASSERT_VK_SUCCESS(err); |
| 12533 | |
| 12534 | err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0); |
| 12535 | ASSERT_VK_SUCCESS(err); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 12536 | err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12537 | ASSERT_VK_SUCCESS(err); |
| 12538 | |
| 12539 | BeginCommandBuffer(); |
| 12540 | // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest? |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12541 | // VK_IMAGE_LAYOUT_UNDEFINED = 0, |
| 12542 | // VK_IMAGE_LAYOUT_GENERAL = 1, |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12543 | VkImageResolve resolveRegion; |
Chia-I Wu | ab83a0e | 2015-10-27 19:00:15 +0800 | [diff] [blame] | 12544 | resolveRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12545 | resolveRegion.srcSubresource.mipLevel = 0; |
Courtney Goeltzenleuchter | 8367ce0 | 2015-10-16 09:46:00 -0600 | [diff] [blame] | 12546 | resolveRegion.srcSubresource.baseArrayLayer = 0; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 12547 | resolveRegion.srcSubresource.layerCount = 0; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12548 | resolveRegion.srcOffset.x = 0; |
| 12549 | resolveRegion.srcOffset.y = 0; |
| 12550 | resolveRegion.srcOffset.z = 0; |
Chia-I Wu | ab83a0e | 2015-10-27 19:00:15 +0800 | [diff] [blame] | 12551 | resolveRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 12552 | resolveRegion.dstSubresource.mipLevel = 0; |
| 12553 | resolveRegion.dstSubresource.baseArrayLayer = 0; |
| 12554 | resolveRegion.dstSubresource.layerCount = 0; |
| 12555 | resolveRegion.dstOffset.x = 0; |
| 12556 | resolveRegion.dstOffset.y = 0; |
| 12557 | resolveRegion.dstOffset.z = 0; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12558 | resolveRegion.extent.width = 1; |
| 12559 | resolveRegion.extent.height = 1; |
| 12560 | resolveRegion.extent.depth = 1; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12561 | m_commandBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, |
| 12562 | VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12563 | EndCommandBuffer(); |
| 12564 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 12565 | m_errorMonitor->VerifyFound(); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12566 | |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 12567 | vkDestroyImage(m_device->device(), srcImage, NULL); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 12568 | vkDestroyImage(m_device->device(), dstImage, NULL); |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 12569 | vkFreeMemory(m_device->device(), srcMem, NULL); |
| 12570 | vkFreeMemory(m_device->device(), destMem, NULL); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12571 | } |
| 12572 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12573 | TEST_F(VkLayerTest, ResolveImageTypeMismatch) { |
| 12574 | VkResult err; |
| 12575 | bool pass; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12576 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12577 | m_errorMonitor->SetDesiredFailureMsg( |
| 12578 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 12579 | "vkCmdResolveImage called with unmatched source and dest image types."); |
| 12580 | |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12581 | ASSERT_NO_FATAL_FAILURE(InitState()); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12582 | |
| 12583 | // Create two images of different types and try to copy between them |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12584 | VkImage srcImage; |
| 12585 | VkImage dstImage; |
| 12586 | VkDeviceMemory srcMem; |
| 12587 | VkDeviceMemory destMem; |
| 12588 | VkMemoryRequirements memReqs; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12589 | |
| 12590 | VkImageCreateInfo image_create_info = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12591 | image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO; |
| 12592 | image_create_info.pNext = NULL; |
| 12593 | image_create_info.imageType = VK_IMAGE_TYPE_2D; |
| 12594 | image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM; |
| 12595 | image_create_info.extent.width = 32; |
| 12596 | image_create_info.extent.height = 1; |
| 12597 | image_create_info.extent.depth = 1; |
| 12598 | image_create_info.mipLevels = 1; |
| 12599 | image_create_info.arrayLayers = 1; |
| 12600 | image_create_info.samples = VK_SAMPLE_COUNT_2_BIT; |
| 12601 | image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL; |
| 12602 | // Note: Some implementations expect color attachment usage for any |
| 12603 | // multisample surface |
| 12604 | image_create_info.usage = |
| 12605 | VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT; |
| 12606 | image_create_info.flags = 0; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12607 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12608 | err = |
| 12609 | vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12610 | ASSERT_VK_SUCCESS(err); |
| 12611 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12612 | image_create_info.imageType = VK_IMAGE_TYPE_1D; |
| 12613 | // Note: Some implementations expect color attachment usage for any |
| 12614 | // multisample surface |
| 12615 | image_create_info.usage = |
| 12616 | VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT; |
| 12617 | image_create_info.samples = VK_SAMPLE_COUNT_1_BIT; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12618 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12619 | err = |
| 12620 | vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12621 | ASSERT_VK_SUCCESS(err); |
| 12622 | |
| 12623 | // Allocate memory |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 12624 | VkMemoryAllocateInfo memAlloc = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12625 | memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO; |
| 12626 | memAlloc.pNext = NULL; |
| 12627 | memAlloc.allocationSize = 0; |
| 12628 | memAlloc.memoryTypeIndex = 0; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12629 | |
Courtney Goeltzenleuchter | 06d8947 | 2015-10-20 16:40:38 -0600 | [diff] [blame] | 12630 | vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12631 | memAlloc.allocationSize = memReqs.size; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12632 | pass = |
| 12633 | m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0); |
Courtney Goeltzenleuchter | 1d2f0dd | 2015-10-22 11:03:31 -0600 | [diff] [blame] | 12634 | ASSERT_TRUE(pass); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 12635 | err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12636 | ASSERT_VK_SUCCESS(err); |
| 12637 | |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 12638 | vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12639 | memAlloc.allocationSize = memReqs.size; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12640 | pass = |
| 12641 | m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0); |
Courtney Goeltzenleuchter | 1d2f0dd | 2015-10-22 11:03:31 -0600 | [diff] [blame] | 12642 | ASSERT_TRUE(pass); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 12643 | err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12644 | ASSERT_VK_SUCCESS(err); |
| 12645 | |
| 12646 | err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0); |
| 12647 | ASSERT_VK_SUCCESS(err); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 12648 | err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12649 | ASSERT_VK_SUCCESS(err); |
| 12650 | |
| 12651 | BeginCommandBuffer(); |
| 12652 | // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest? |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12653 | // VK_IMAGE_LAYOUT_UNDEFINED = 0, |
| 12654 | // VK_IMAGE_LAYOUT_GENERAL = 1, |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12655 | VkImageResolve resolveRegion; |
Chia-I Wu | ab83a0e | 2015-10-27 19:00:15 +0800 | [diff] [blame] | 12656 | resolveRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12657 | resolveRegion.srcSubresource.mipLevel = 0; |
Courtney Goeltzenleuchter | 8367ce0 | 2015-10-16 09:46:00 -0600 | [diff] [blame] | 12658 | resolveRegion.srcSubresource.baseArrayLayer = 0; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 12659 | resolveRegion.srcSubresource.layerCount = 0; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12660 | resolveRegion.srcOffset.x = 0; |
| 12661 | resolveRegion.srcOffset.y = 0; |
| 12662 | resolveRegion.srcOffset.z = 0; |
Chia-I Wu | ab83a0e | 2015-10-27 19:00:15 +0800 | [diff] [blame] | 12663 | resolveRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 12664 | resolveRegion.dstSubresource.mipLevel = 0; |
| 12665 | resolveRegion.dstSubresource.baseArrayLayer = 0; |
| 12666 | resolveRegion.dstSubresource.layerCount = 0; |
| 12667 | resolveRegion.dstOffset.x = 0; |
| 12668 | resolveRegion.dstOffset.y = 0; |
| 12669 | resolveRegion.dstOffset.z = 0; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12670 | resolveRegion.extent.width = 1; |
| 12671 | resolveRegion.extent.height = 1; |
| 12672 | resolveRegion.extent.depth = 1; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12673 | m_commandBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, |
| 12674 | VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12675 | EndCommandBuffer(); |
| 12676 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 12677 | m_errorMonitor->VerifyFound(); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12678 | |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 12679 | vkDestroyImage(m_device->device(), srcImage, NULL); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 12680 | vkDestroyImage(m_device->device(), dstImage, NULL); |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 12681 | vkFreeMemory(m_device->device(), srcMem, NULL); |
| 12682 | vkFreeMemory(m_device->device(), destMem, NULL); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12683 | } |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 12684 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12685 | TEST_F(VkLayerTest, DepthStencilImageViewWithColorAspectBitError) { |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 12686 | // Create a single Image descriptor and cause it to first hit an error due |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12687 | // to using a DS format, then cause it to hit error due to COLOR_BIT not |
| 12688 | // set in aspect |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 12689 | // The image format check comes 2nd in validation so we trigger it first, |
| 12690 | // then when we cause aspect fail next, bad format check will be preempted |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12691 | VkResult err; |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 12692 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12693 | m_errorMonitor->SetDesiredFailureMsg( |
| 12694 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 12695 | "Combination depth/stencil image formats can have only the "); |
| 12696 | |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 12697 | ASSERT_NO_FATAL_FAILURE(InitState()); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 12698 | |
Chia-I Wu | 1b99bb2 | 2015-10-27 19:25:11 +0800 | [diff] [blame] | 12699 | VkDescriptorPoolSize ds_type_count = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12700 | ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE; |
| 12701 | ds_type_count.descriptorCount = 1; |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 12702 | |
| 12703 | VkDescriptorPoolCreateInfo ds_pool_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12704 | ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO; |
| 12705 | ds_pool_ci.pNext = NULL; |
| 12706 | ds_pool_ci.maxSets = 1; |
| 12707 | ds_pool_ci.poolSizeCount = 1; |
| 12708 | ds_pool_ci.pPoolSizes = &ds_type_count; |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 12709 | |
| 12710 | VkDescriptorPool ds_pool; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12711 | err = |
| 12712 | vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool); |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 12713 | ASSERT_VK_SUCCESS(err); |
| 12714 | |
| 12715 | VkDescriptorSetLayoutBinding dsl_binding = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12716 | dsl_binding.binding = 0; |
| 12717 | dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE; |
| 12718 | dsl_binding.descriptorCount = 1; |
| 12719 | dsl_binding.stageFlags = VK_SHADER_STAGE_ALL; |
| 12720 | dsl_binding.pImmutableSamplers = NULL; |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 12721 | |
| 12722 | VkDescriptorSetLayoutCreateInfo ds_layout_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12723 | ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO; |
| 12724 | ds_layout_ci.pNext = NULL; |
| 12725 | ds_layout_ci.bindingCount = 1; |
| 12726 | ds_layout_ci.pBindings = &dsl_binding; |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 12727 | VkDescriptorSetLayout ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12728 | err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, |
| 12729 | &ds_layout); |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 12730 | ASSERT_VK_SUCCESS(err); |
| 12731 | |
| 12732 | VkDescriptorSet descriptorSet; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 12733 | VkDescriptorSetAllocateInfo alloc_info = {}; |
Chia-I Wu | 00ce540 | 2015-11-10 16:21:09 +0800 | [diff] [blame] | 12734 | alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO; |
Jon Ashburn | f19916e | 2016-01-11 13:12:43 -0700 | [diff] [blame] | 12735 | alloc_info.descriptorSetCount = 1; |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 12736 | alloc_info.descriptorPool = ds_pool; |
| 12737 | alloc_info.pSetLayouts = &ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12738 | err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, |
| 12739 | &descriptorSet); |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 12740 | ASSERT_VK_SUCCESS(err); |
| 12741 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12742 | VkImage image_bad; |
| 12743 | VkImage image_good; |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 12744 | // One bad format and one good format for Color attachment |
Tobin Ehlis | 269f032 | 2016-05-25 16:24:21 -0600 | [diff] [blame] | 12745 | const VkFormat tex_format_bad = VK_FORMAT_D24_UNORM_S8_UINT; |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 12746 | const VkFormat tex_format_good = VK_FORMAT_B8G8R8A8_UNORM; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12747 | const int32_t tex_width = 32; |
| 12748 | const int32_t tex_height = 32; |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 12749 | |
| 12750 | VkImageCreateInfo image_create_info = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12751 | image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO; |
| 12752 | image_create_info.pNext = NULL; |
| 12753 | image_create_info.imageType = VK_IMAGE_TYPE_2D; |
| 12754 | image_create_info.format = tex_format_bad; |
| 12755 | image_create_info.extent.width = tex_width; |
| 12756 | image_create_info.extent.height = tex_height; |
| 12757 | image_create_info.extent.depth = 1; |
| 12758 | image_create_info.mipLevels = 1; |
| 12759 | image_create_info.arrayLayers = 1; |
| 12760 | image_create_info.samples = VK_SAMPLE_COUNT_1_BIT; |
| 12761 | image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL; |
| 12762 | image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT | |
| 12763 | VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT; |
| 12764 | image_create_info.flags = 0; |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 12765 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12766 | err = |
| 12767 | vkCreateImage(m_device->device(), &image_create_info, NULL, &image_bad); |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 12768 | ASSERT_VK_SUCCESS(err); |
| 12769 | image_create_info.format = tex_format_good; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12770 | image_create_info.usage = |
| 12771 | VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT; |
| 12772 | err = vkCreateImage(m_device->device(), &image_create_info, NULL, |
| 12773 | &image_good); |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 12774 | ASSERT_VK_SUCCESS(err); |
| 12775 | |
| 12776 | VkImageViewCreateInfo image_view_create_info = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12777 | image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO; |
| 12778 | image_view_create_info.image = image_bad; |
| 12779 | image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D; |
| 12780 | image_view_create_info.format = tex_format_bad; |
| 12781 | image_view_create_info.subresourceRange.baseArrayLayer = 0; |
| 12782 | image_view_create_info.subresourceRange.baseMipLevel = 0; |
| 12783 | image_view_create_info.subresourceRange.layerCount = 1; |
| 12784 | image_view_create_info.subresourceRange.levelCount = 1; |
| 12785 | image_view_create_info.subresourceRange.aspectMask = |
| 12786 | VK_IMAGE_ASPECT_COLOR_BIT; |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 12787 | |
| 12788 | VkImageView view; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12789 | err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, |
| 12790 | &view); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 12791 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 12792 | m_errorMonitor->VerifyFound(); |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 12793 | |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 12794 | vkDestroyImage(m_device->device(), image_bad, NULL); |
| 12795 | vkDestroyImage(m_device->device(), image_good, NULL); |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 12796 | vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL); |
| 12797 | vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL); |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 12798 | } |
Tobin Ehlis | 6e23d77 | 2016-05-19 11:08:34 -0600 | [diff] [blame] | 12799 | |
| 12800 | TEST_F(VkLayerTest, ClearImageErrors) { |
| 12801 | TEST_DESCRIPTION("Call ClearColorImage w/ a depth|stencil image and " |
| 12802 | "ClearDepthStencilImage with a color image."); |
| 12803 | |
| 12804 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 12805 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 12806 | |
| 12807 | // Renderpass is started here so end it as Clear cmds can't be in renderpass |
| 12808 | BeginCommandBuffer(); |
| 12809 | m_commandBuffer->EndRenderPass(); |
| 12810 | |
| 12811 | // Color image |
| 12812 | VkClearColorValue clear_color; |
| 12813 | memset(clear_color.uint32, 0, sizeof(uint32_t) * 4); |
| 12814 | VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT; |
| 12815 | const VkFormat color_format = VK_FORMAT_B8G8R8A8_UNORM; |
| 12816 | const int32_t img_width = 32; |
| 12817 | const int32_t img_height = 32; |
| 12818 | VkImageCreateInfo image_create_info = {}; |
| 12819 | image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO; |
| 12820 | image_create_info.pNext = NULL; |
| 12821 | image_create_info.imageType = VK_IMAGE_TYPE_2D; |
| 12822 | image_create_info.format = color_format; |
| 12823 | image_create_info.extent.width = img_width; |
| 12824 | image_create_info.extent.height = img_height; |
| 12825 | image_create_info.extent.depth = 1; |
| 12826 | image_create_info.mipLevels = 1; |
| 12827 | image_create_info.arrayLayers = 1; |
| 12828 | image_create_info.samples = VK_SAMPLE_COUNT_1_BIT; |
| 12829 | image_create_info.tiling = VK_IMAGE_TILING_LINEAR; |
| 12830 | image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT; |
| 12831 | |
| 12832 | vk_testing::Image color_image; |
| 12833 | color_image.init(*m_device, (const VkImageCreateInfo &)image_create_info, |
| 12834 | reqs); |
| 12835 | |
| 12836 | const VkImageSubresourceRange color_range = |
| 12837 | vk_testing::Image::subresource_range(image_create_info, |
| 12838 | VK_IMAGE_ASPECT_COLOR_BIT); |
| 12839 | |
| 12840 | // Depth/Stencil image |
| 12841 | VkClearDepthStencilValue clear_value = {0}; |
| 12842 | reqs = 0; // don't need HOST_VISIBLE DS image |
| 12843 | VkImageCreateInfo ds_image_create_info = vk_testing::Image::create_info(); |
| 12844 | ds_image_create_info.imageType = VK_IMAGE_TYPE_2D; |
| 12845 | ds_image_create_info.format = VK_FORMAT_D24_UNORM_S8_UINT; |
| 12846 | ds_image_create_info.extent.width = 64; |
| 12847 | ds_image_create_info.extent.height = 64; |
| 12848 | ds_image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL; |
| 12849 | ds_image_create_info.usage = VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT; |
| 12850 | |
| 12851 | vk_testing::Image ds_image; |
| 12852 | ds_image.init(*m_device, (const VkImageCreateInfo &)ds_image_create_info, |
| 12853 | reqs); |
| 12854 | |
| 12855 | const VkImageSubresourceRange ds_range = |
| 12856 | vk_testing::Image::subresource_range(ds_image_create_info, |
| 12857 | VK_IMAGE_ASPECT_DEPTH_BIT); |
| 12858 | |
| 12859 | m_errorMonitor->SetDesiredFailureMsg( |
| 12860 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 12861 | "vkCmdClearColorImage called with depth/stencil image."); |
| 12862 | |
| 12863 | vkCmdClearColorImage(m_commandBuffer->GetBufferHandle(), ds_image.handle(), |
| 12864 | VK_IMAGE_LAYOUT_GENERAL, &clear_color, 1, |
| 12865 | &color_range); |
| 12866 | |
| 12867 | m_errorMonitor->VerifyFound(); |
| 12868 | |
Tony Barbour | 26434b9 | 2016-06-02 09:43:50 -0600 | [diff] [blame] | 12869 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 12870 | "vkCmdClearColorImage called with " |
| 12871 | "image created without " |
| 12872 | "VK_IMAGE_USAGE_TRANSFER_DST_BIT"); |
| 12873 | |
| 12874 | vkCmdClearColorImage(m_commandBuffer->GetBufferHandle(), ds_image.handle(), |
| 12875 | VK_IMAGE_LAYOUT_GENERAL, &clear_color, 1, |
| 12876 | &color_range); |
| 12877 | |
| 12878 | m_errorMonitor->VerifyFound(); |
| 12879 | |
Tobin Ehlis | 6e23d77 | 2016-05-19 11:08:34 -0600 | [diff] [blame] | 12880 | // Call CmdClearDepthStencilImage with color image |
| 12881 | m_errorMonitor->SetDesiredFailureMsg( |
| 12882 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 12883 | "vkCmdClearDepthStencilImage called without a depth/stencil image."); |
| 12884 | |
| 12885 | vkCmdClearDepthStencilImage( |
| 12886 | m_commandBuffer->GetBufferHandle(), color_image.handle(), |
| 12887 | VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL, &clear_value, 1, |
| 12888 | &ds_range); |
| 12889 | |
| 12890 | m_errorMonitor->VerifyFound(); |
| 12891 | } |
Tobin Ehlis | cde0889 | 2015-09-22 10:11:37 -0600 | [diff] [blame] | 12892 | #endif // IMAGE_TESTS |
| 12893 | |
Tony Barbour | 300a608 | 2015-04-07 13:44:53 -0600 | [diff] [blame] | 12894 | int main(int argc, char **argv) { |
| 12895 | int result; |
| 12896 | |
Cody Northrop | 8e54a40 | 2016-03-08 22:25:52 -0700 | [diff] [blame] | 12897 | #ifdef ANDROID |
| 12898 | int vulkanSupport = InitVulkan(); |
| 12899 | if (vulkanSupport == 0) |
| 12900 | return 1; |
| 12901 | #endif |
| 12902 | |
Tony Barbour | 300a608 | 2015-04-07 13:44:53 -0600 | [diff] [blame] | 12903 | ::testing::InitGoogleTest(&argc, argv); |
Tony Barbour | 6918cd5 | 2015-04-09 12:58:51 -0600 | [diff] [blame] | 12904 | VkTestFramework::InitArgs(&argc, argv); |
Tony Barbour | 300a608 | 2015-04-07 13:44:53 -0600 | [diff] [blame] | 12905 | |
| 12906 | ::testing::AddGlobalTestEnvironment(new TestEnvironment); |
| 12907 | |
| 12908 | result = RUN_ALL_TESTS(); |
| 12909 | |
Tony Barbour | 6918cd5 | 2015-04-09 12:58:51 -0600 | [diff] [blame] | 12910 | VkTestFramework::Finish(); |
Tony Barbour | 300a608 | 2015-04-07 13:44:53 -0600 | [diff] [blame] | 12911 | return result; |
| 12912 | } |