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 | } |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [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 | |
| 3224 | TEST_F(VkLayerTest, AttachmentUsageMismatch) { |
| 3225 | TEST_DESCRIPTION("Create a framebuffer where a subpass uses a color image " |
| 3226 | "in the depthStencil attachment point"); |
| 3227 | |
| 3228 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 3229 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 3230 | |
| 3231 | m_errorMonitor->SetDesiredFailureMsg( |
| 3232 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 3233 | "conflicts with the image's IMAGE_USAGE flags"); |
| 3234 | |
| 3235 | // Create a renderPass with a depth-stencil attachment created with |
| 3236 | // IMAGE_USAGE_COLOR_ATTACHMENT |
| 3237 | VkAttachmentReference attach = {}; |
| 3238 | attach.layout = VK_IMAGE_LAYOUT_GENERAL; |
| 3239 | VkSubpassDescription subpass = {}; |
| 3240 | // Add our color attachment to pDepthStencilAttachment |
| 3241 | subpass.pDepthStencilAttachment = &attach; |
| 3242 | VkRenderPassCreateInfo rpci = {}; |
| 3243 | rpci.subpassCount = 1; |
| 3244 | rpci.pSubpasses = &subpass; |
| 3245 | rpci.attachmentCount = 1; |
| 3246 | VkAttachmentDescription attach_desc = {}; |
| 3247 | attach_desc.format = VK_FORMAT_UNDEFINED; |
| 3248 | rpci.pAttachments = &attach_desc; |
| 3249 | rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO; |
| 3250 | VkRenderPass rp; |
| 3251 | VkResult err = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp); |
| 3252 | ASSERT_VK_SUCCESS(err); |
| 3253 | |
| 3254 | VkImageView imageView = |
| 3255 | m_renderTargets[0]->targetView(VK_FORMAT_B8G8R8A8_UNORM); |
| 3256 | VkFramebufferCreateInfo fb_info = {}; |
| 3257 | fb_info.sType = VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO; |
| 3258 | fb_info.pNext = NULL; |
| 3259 | fb_info.renderPass = rp; |
| 3260 | fb_info.attachmentCount = 1; |
| 3261 | fb_info.pAttachments = &imageView; |
| 3262 | fb_info.width = 100; |
| 3263 | fb_info.height = 100; |
| 3264 | fb_info.layers = 1; |
| 3265 | |
| 3266 | VkFramebuffer fb; |
| 3267 | err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb); |
| 3268 | |
| 3269 | m_errorMonitor->VerifyFound(); |
| 3270 | |
| 3271 | if (err == VK_SUCCESS) { |
| 3272 | vkDestroyFramebuffer(m_device->device(), fb, NULL); |
| 3273 | } |
| 3274 | vkDestroyRenderPass(m_device->device(), rp, NULL); |
| 3275 | } |
| 3276 | |
Mark Lobodzinski | c808d44 | 2016-04-14 10:57:23 -0600 | [diff] [blame] | 3277 | // This is a positive test. No errors should be generated. |
Michael Lentine | 860b0fe | 2016-05-20 10:14:00 -0500 | [diff] [blame] | 3278 | TEST_F(VkLayerTest, WaitEventThenSet) { |
| 3279 | TEST_DESCRIPTION( |
| 3280 | "Wait on a event then set it after the wait has been submitted."); |
| 3281 | |
Michael Lentine | 860b0fe | 2016-05-20 10:14:00 -0500 | [diff] [blame] | 3282 | m_errorMonitor->ExpectSuccess(); |
| 3283 | |
| 3284 | VkEvent event; |
| 3285 | VkEventCreateInfo event_create_info{}; |
| 3286 | event_create_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO; |
| 3287 | vkCreateEvent(m_device->device(), &event_create_info, nullptr, &event); |
| 3288 | |
| 3289 | VkCommandPool command_pool; |
| 3290 | VkCommandPoolCreateInfo pool_create_info{}; |
| 3291 | pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO; |
| 3292 | pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_; |
| 3293 | pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT; |
| 3294 | vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, |
| 3295 | &command_pool); |
| 3296 | |
| 3297 | VkCommandBuffer command_buffer; |
| 3298 | VkCommandBufferAllocateInfo command_buffer_allocate_info{}; |
| 3299 | command_buffer_allocate_info.sType = |
| 3300 | VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO; |
| 3301 | command_buffer_allocate_info.commandPool = command_pool; |
| 3302 | command_buffer_allocate_info.commandBufferCount = 1; |
| 3303 | command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY; |
| 3304 | vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, |
| 3305 | &command_buffer); |
| 3306 | |
| 3307 | VkQueue queue = VK_NULL_HANDLE; |
| 3308 | vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, |
Tony Barbour | fe302c0 | 2016-06-06 13:05:19 -0600 | [diff] [blame] | 3309 | 0, &queue); |
Michael Lentine | 860b0fe | 2016-05-20 10:14:00 -0500 | [diff] [blame] | 3310 | |
| 3311 | { |
| 3312 | VkCommandBufferBeginInfo begin_info{}; |
| 3313 | begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO; |
| 3314 | vkBeginCommandBuffer(command_buffer, &begin_info); |
| 3315 | |
| 3316 | vkCmdWaitEvents(command_buffer, 1, &event, VK_PIPELINE_STAGE_HOST_BIT, |
| 3317 | VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, nullptr, 0, |
| 3318 | nullptr, 0, nullptr); |
| 3319 | vkCmdResetEvent(command_buffer, event, |
| 3320 | VK_PIPELINE_STAGE_ALL_COMMANDS_BIT); |
| 3321 | vkEndCommandBuffer(command_buffer); |
| 3322 | } |
| 3323 | { |
| 3324 | VkSubmitInfo submit_info{}; |
| 3325 | submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO; |
| 3326 | submit_info.commandBufferCount = 1; |
| 3327 | submit_info.pCommandBuffers = &command_buffer; |
| 3328 | submit_info.signalSemaphoreCount = 0; |
| 3329 | submit_info.pSignalSemaphores = nullptr; |
| 3330 | vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE); |
| 3331 | } |
| 3332 | { vkSetEvent(m_device->device(), event); } |
| 3333 | |
| 3334 | vkQueueWaitIdle(queue); |
| 3335 | |
| 3336 | vkDestroyEvent(m_device->device(), event, nullptr); |
| 3337 | vkFreeCommandBuffers(m_device->device(), command_pool, 1, &command_buffer); |
| 3338 | vkDestroyCommandPool(m_device->device(), command_pool, NULL); |
| 3339 | |
| 3340 | m_errorMonitor->VerifyNotFound(); |
| 3341 | } |
Michael Lentine | 5627e69 | 2016-05-20 17:45:02 -0500 | [diff] [blame] | 3342 | // This is a positive test. No errors should be generated. |
| 3343 | TEST_F(VkLayerTest, QueryAndCopyMultipleCommandBuffers) { |
| 3344 | TEST_DESCRIPTION( |
| 3345 | "Issue a query and copy from it on a second command buffer."); |
| 3346 | |
| 3347 | if ((m_device->queue_props.empty()) || |
| 3348 | (m_device->queue_props[0].queueCount < 2)) |
| 3349 | return; |
| 3350 | |
| 3351 | m_errorMonitor->ExpectSuccess(); |
| 3352 | |
| 3353 | VkQueryPool query_pool; |
| 3354 | VkQueryPoolCreateInfo query_pool_create_info{}; |
| 3355 | query_pool_create_info.sType = VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO; |
| 3356 | query_pool_create_info.queryType = VK_QUERY_TYPE_TIMESTAMP; |
| 3357 | query_pool_create_info.queryCount = 1; |
| 3358 | vkCreateQueryPool(m_device->device(), &query_pool_create_info, nullptr, |
| 3359 | &query_pool); |
| 3360 | |
| 3361 | VkCommandPool command_pool; |
| 3362 | VkCommandPoolCreateInfo pool_create_info{}; |
| 3363 | pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO; |
| 3364 | pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_; |
| 3365 | pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT; |
| 3366 | vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, |
| 3367 | &command_pool); |
| 3368 | |
| 3369 | VkCommandBuffer command_buffer[2]; |
| 3370 | VkCommandBufferAllocateInfo command_buffer_allocate_info{}; |
| 3371 | command_buffer_allocate_info.sType = |
| 3372 | VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO; |
| 3373 | command_buffer_allocate_info.commandPool = command_pool; |
| 3374 | command_buffer_allocate_info.commandBufferCount = 2; |
| 3375 | command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY; |
| 3376 | vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, |
| 3377 | command_buffer); |
| 3378 | |
| 3379 | VkQueue queue = VK_NULL_HANDLE; |
| 3380 | vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, |
| 3381 | 1, &queue); |
| 3382 | |
| 3383 | uint32_t qfi = 0; |
| 3384 | VkBufferCreateInfo buff_create_info = {}; |
| 3385 | buff_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO; |
| 3386 | buff_create_info.size = 1024; |
| 3387 | buff_create_info.usage = VK_BUFFER_USAGE_TRANSFER_DST_BIT; |
| 3388 | buff_create_info.queueFamilyIndexCount = 1; |
| 3389 | buff_create_info.pQueueFamilyIndices = &qfi; |
| 3390 | |
| 3391 | VkResult err; |
| 3392 | VkBuffer buffer; |
| 3393 | err = vkCreateBuffer(m_device->device(), &buff_create_info, NULL, &buffer); |
| 3394 | ASSERT_VK_SUCCESS(err); |
| 3395 | VkMemoryAllocateInfo mem_alloc = {}; |
| 3396 | mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO; |
| 3397 | mem_alloc.pNext = NULL; |
| 3398 | mem_alloc.allocationSize = 1024; |
| 3399 | mem_alloc.memoryTypeIndex = 0; |
| 3400 | |
| 3401 | VkMemoryRequirements memReqs; |
| 3402 | vkGetBufferMemoryRequirements(m_device->device(), buffer, &memReqs); |
| 3403 | bool pass = |
| 3404 | m_device->phy().set_memory_type(memReqs.memoryTypeBits, &mem_alloc, 0); |
| 3405 | if (!pass) { |
| 3406 | vkDestroyBuffer(m_device->device(), buffer, NULL); |
| 3407 | return; |
| 3408 | } |
| 3409 | |
| 3410 | VkDeviceMemory mem; |
| 3411 | err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem); |
| 3412 | ASSERT_VK_SUCCESS(err); |
| 3413 | err = vkBindBufferMemory(m_device->device(), buffer, mem, 0); |
| 3414 | ASSERT_VK_SUCCESS(err); |
| 3415 | |
| 3416 | { |
| 3417 | VkCommandBufferBeginInfo begin_info{}; |
| 3418 | begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO; |
| 3419 | vkBeginCommandBuffer(command_buffer[0], &begin_info); |
| 3420 | |
| 3421 | vkCmdResetQueryPool(command_buffer[0], query_pool, 0, 1); |
| 3422 | vkCmdWriteTimestamp(command_buffer[0], |
| 3423 | VK_PIPELINE_STAGE_ALL_GRAPHICS_BIT, query_pool, 0); |
| 3424 | |
| 3425 | vkEndCommandBuffer(command_buffer[0]); |
| 3426 | |
| 3427 | vkBeginCommandBuffer(command_buffer[1], &begin_info); |
| 3428 | |
| 3429 | vkCmdCopyQueryPoolResults(command_buffer[1], query_pool, 0, 1, buffer, |
| 3430 | 0, 0, 0); |
| 3431 | |
| 3432 | vkEndCommandBuffer(command_buffer[1]); |
| 3433 | } |
| 3434 | { |
| 3435 | VkSubmitInfo submit_info{}; |
| 3436 | submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO; |
| 3437 | submit_info.commandBufferCount = 2; |
| 3438 | submit_info.pCommandBuffers = command_buffer; |
| 3439 | submit_info.signalSemaphoreCount = 0; |
| 3440 | submit_info.pSignalSemaphores = nullptr; |
| 3441 | vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE); |
| 3442 | } |
| 3443 | |
| 3444 | vkQueueWaitIdle(queue); |
| 3445 | |
| 3446 | vkDestroyQueryPool(m_device->device(), query_pool, nullptr); |
| 3447 | vkFreeCommandBuffers(m_device->device(), command_pool, 2, command_buffer); |
| 3448 | vkDestroyCommandPool(m_device->device(), command_pool, NULL); |
Tony Barbour | df4c004 | 2016-06-01 15:55:43 -0600 | [diff] [blame] | 3449 | vkDestroyBuffer(m_device->device(), buffer, NULL); |
| 3450 | vkFreeMemory(m_device->device(), mem, NULL); |
Michael Lentine | 5627e69 | 2016-05-20 17:45:02 -0500 | [diff] [blame] | 3451 | |
| 3452 | m_errorMonitor->VerifyNotFound(); |
| 3453 | } |
Michael Lentine | 860b0fe | 2016-05-20 10:14:00 -0500 | [diff] [blame] | 3454 | |
| 3455 | TEST_F(VkLayerTest, ResetEventThenSet) { |
| 3456 | TEST_DESCRIPTION( |
| 3457 | "Reset an event then set it after the reset has been submitted."); |
| 3458 | |
Michael Lentine | 860b0fe | 2016-05-20 10:14:00 -0500 | [diff] [blame] | 3459 | m_errorMonitor->ExpectSuccess(); |
| 3460 | |
| 3461 | VkEvent event; |
| 3462 | VkEventCreateInfo event_create_info{}; |
| 3463 | event_create_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO; |
| 3464 | vkCreateEvent(m_device->device(), &event_create_info, nullptr, &event); |
| 3465 | |
| 3466 | VkCommandPool command_pool; |
| 3467 | VkCommandPoolCreateInfo pool_create_info{}; |
| 3468 | pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO; |
| 3469 | pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_; |
| 3470 | pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT; |
| 3471 | vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, |
| 3472 | &command_pool); |
| 3473 | |
| 3474 | VkCommandBuffer command_buffer; |
| 3475 | VkCommandBufferAllocateInfo command_buffer_allocate_info{}; |
| 3476 | command_buffer_allocate_info.sType = |
| 3477 | VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO; |
| 3478 | command_buffer_allocate_info.commandPool = command_pool; |
| 3479 | command_buffer_allocate_info.commandBufferCount = 1; |
| 3480 | command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY; |
| 3481 | vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, |
| 3482 | &command_buffer); |
| 3483 | |
| 3484 | VkQueue queue = VK_NULL_HANDLE; |
| 3485 | vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, |
Tony Barbour | fe302c0 | 2016-06-06 13:05:19 -0600 | [diff] [blame] | 3486 | 0, &queue); |
Michael Lentine | 860b0fe | 2016-05-20 10:14:00 -0500 | [diff] [blame] | 3487 | |
| 3488 | { |
| 3489 | VkCommandBufferBeginInfo begin_info{}; |
| 3490 | begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO; |
| 3491 | vkBeginCommandBuffer(command_buffer, &begin_info); |
| 3492 | |
| 3493 | vkCmdResetEvent(command_buffer, event, |
| 3494 | VK_PIPELINE_STAGE_ALL_COMMANDS_BIT); |
| 3495 | vkCmdWaitEvents(command_buffer, 1, &event, |
| 3496 | VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, |
| 3497 | VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, nullptr, 0, |
| 3498 | nullptr, 0, nullptr); |
| 3499 | vkEndCommandBuffer(command_buffer); |
| 3500 | } |
| 3501 | { |
| 3502 | VkSubmitInfo submit_info{}; |
| 3503 | submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO; |
| 3504 | submit_info.commandBufferCount = 1; |
| 3505 | submit_info.pCommandBuffers = &command_buffer; |
| 3506 | submit_info.signalSemaphoreCount = 0; |
| 3507 | submit_info.pSignalSemaphores = nullptr; |
| 3508 | vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE); |
| 3509 | } |
| 3510 | { |
| 3511 | m_errorMonitor->SetDesiredFailureMsg( |
| 3512 | VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot call vkSetEvent() on event " |
| 3513 | "0x1 that is already in use by a " |
| 3514 | "command buffer."); |
| 3515 | vkSetEvent(m_device->device(), event); |
| 3516 | m_errorMonitor->VerifyFound(); |
| 3517 | } |
| 3518 | |
| 3519 | vkQueueWaitIdle(queue); |
| 3520 | |
| 3521 | vkDestroyEvent(m_device->device(), event, nullptr); |
| 3522 | vkFreeCommandBuffers(m_device->device(), command_pool, 1, &command_buffer); |
| 3523 | vkDestroyCommandPool(m_device->device(), command_pool, NULL); |
| 3524 | } |
| 3525 | |
| 3526 | // This is a positive test. No errors should be generated. |
Tobin Ehlis | 0bb263b | 2016-05-10 12:13:02 -0600 | [diff] [blame] | 3527 | TEST_F(VkLayerTest, TwoFencesThreeFrames) { |
| 3528 | TEST_DESCRIPTION("Two command buffers with two separate fences are each " |
| 3529 | "run through a Submit & WaitForFences cycle 3 times. This " |
| 3530 | "previously revealed a bug so running this positive test " |
| 3531 | "to prevent a regression."); |
| 3532 | m_errorMonitor->ExpectSuccess(); |
| 3533 | |
| 3534 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 3535 | VkQueue queue = VK_NULL_HANDLE; |
| 3536 | vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, |
| 3537 | 0, &queue); |
| 3538 | |
| 3539 | static const uint32_t NUM_OBJECTS = 2; |
| 3540 | static const uint32_t NUM_FRAMES = 3; |
| 3541 | VkCommandBuffer cmd_buffers[NUM_OBJECTS] = {}; |
| 3542 | VkFence fences[NUM_OBJECTS] = {}; |
| 3543 | |
| 3544 | VkCommandPool cmd_pool; |
| 3545 | VkCommandPoolCreateInfo cmd_pool_ci = {}; |
| 3546 | cmd_pool_ci.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO; |
| 3547 | cmd_pool_ci.queueFamilyIndex = m_device->graphics_queue_node_index_; |
| 3548 | cmd_pool_ci.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT; |
| 3549 | VkResult err = vkCreateCommandPool(m_device->device(), &cmd_pool_ci, |
| 3550 | nullptr, &cmd_pool); |
| 3551 | ASSERT_VK_SUCCESS(err); |
| 3552 | |
| 3553 | VkCommandBufferAllocateInfo cmd_buf_info = {}; |
| 3554 | cmd_buf_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO; |
| 3555 | cmd_buf_info.commandPool = cmd_pool; |
| 3556 | cmd_buf_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY; |
| 3557 | cmd_buf_info.commandBufferCount = 1; |
| 3558 | |
| 3559 | VkFenceCreateInfo fence_ci = {}; |
| 3560 | fence_ci.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO; |
| 3561 | fence_ci.pNext = nullptr; |
| 3562 | fence_ci.flags = 0; |
| 3563 | |
| 3564 | for (uint32_t i = 0; i < NUM_OBJECTS; ++i) { |
| 3565 | err = vkAllocateCommandBuffers(m_device->device(), &cmd_buf_info, |
| 3566 | &cmd_buffers[i]); |
| 3567 | ASSERT_VK_SUCCESS(err); |
| 3568 | err = vkCreateFence(m_device->device(), &fence_ci, nullptr, &fences[i]); |
| 3569 | ASSERT_VK_SUCCESS(err); |
| 3570 | } |
| 3571 | |
| 3572 | for (uint32_t frame = 0; frame < NUM_FRAMES; ++frame) { |
Tobin Ehlis | f902516 | 2016-05-26 06:55:21 -0600 | [diff] [blame] | 3573 | for (uint32_t obj = 0; obj < NUM_OBJECTS; ++obj) { |
| 3574 | // Create empty cmd buffer |
| 3575 | VkCommandBufferBeginInfo cmdBufBeginDesc = {}; |
| 3576 | cmdBufBeginDesc.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO; |
Tobin Ehlis | 0bb263b | 2016-05-10 12:13:02 -0600 | [diff] [blame] | 3577 | |
Tobin Ehlis | f902516 | 2016-05-26 06:55:21 -0600 | [diff] [blame] | 3578 | err = vkBeginCommandBuffer(cmd_buffers[obj], &cmdBufBeginDesc); |
| 3579 | ASSERT_VK_SUCCESS(err); |
| 3580 | err = vkEndCommandBuffer(cmd_buffers[obj]); |
| 3581 | ASSERT_VK_SUCCESS(err); |
Tobin Ehlis | 0bb263b | 2016-05-10 12:13:02 -0600 | [diff] [blame] | 3582 | |
Tobin Ehlis | f902516 | 2016-05-26 06:55:21 -0600 | [diff] [blame] | 3583 | VkSubmitInfo submit_info = {}; |
| 3584 | submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO; |
| 3585 | submit_info.commandBufferCount = 1; |
| 3586 | submit_info.pCommandBuffers = &cmd_buffers[obj]; |
| 3587 | // Submit cmd buffer and wait for fence |
| 3588 | err = vkQueueSubmit(queue, 1, &submit_info, fences[obj]); |
| 3589 | ASSERT_VK_SUCCESS(err); |
| 3590 | err = vkWaitForFences(m_device->device(), 1, &fences[obj], VK_TRUE, |
| 3591 | UINT64_MAX); |
| 3592 | ASSERT_VK_SUCCESS(err); |
| 3593 | err = vkResetFences(m_device->device(), 1, &fences[obj]); |
| 3594 | ASSERT_VK_SUCCESS(err); |
| 3595 | } |
Tobin Ehlis | 0bb263b | 2016-05-10 12:13:02 -0600 | [diff] [blame] | 3596 | } |
| 3597 | m_errorMonitor->VerifyNotFound(); |
Tony Barbour | df4c004 | 2016-06-01 15:55:43 -0600 | [diff] [blame] | 3598 | vkDestroyCommandPool(m_device->device(), cmd_pool, NULL); |
| 3599 | for (uint32_t i = 0; i < NUM_OBJECTS; ++i) { |
| 3600 | vkDestroyFence(m_device->device(), fences[i], nullptr); |
| 3601 | } |
Tobin Ehlis | 0bb263b | 2016-05-10 12:13:02 -0600 | [diff] [blame] | 3602 | } |
| 3603 | // This is a positive test. No errors should be generated. |
Mark Lobodzinski | c808d44 | 2016-04-14 10:57:23 -0600 | [diff] [blame] | 3604 | TEST_F(VkLayerTest, TwoQueueSubmitsSeparateQueuesWithSemaphoreAndOneFenceQWI) { |
| 3605 | |
| 3606 | TEST_DESCRIPTION("Two command buffers, each in a separate QueueSubmit call " |
| 3607 | "submitted on separate queues followed by a QueueWaitIdle."); |
| 3608 | |
Dustin Graves | 4845814 | 2016-04-29 16:11:55 -0600 | [diff] [blame] | 3609 | if ((m_device->queue_props.empty()) || |
| 3610 | (m_device->queue_props[0].queueCount < 2)) |
Tony Barbour | dc18b26 | 2016-04-22 14:49:48 -0600 | [diff] [blame] | 3611 | return; |
| 3612 | |
Mark Lobodzinski | c808d44 | 2016-04-14 10:57:23 -0600 | [diff] [blame] | 3613 | m_errorMonitor->ExpectSuccess(); |
| 3614 | |
| 3615 | VkSemaphore semaphore; |
| 3616 | VkSemaphoreCreateInfo semaphore_create_info{}; |
| 3617 | semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO; |
| 3618 | vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, |
| 3619 | &semaphore); |
| 3620 | |
| 3621 | VkCommandPool command_pool; |
| 3622 | VkCommandPoolCreateInfo pool_create_info{}; |
| 3623 | pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO; |
| 3624 | pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_; |
| 3625 | pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT; |
| 3626 | vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, |
| 3627 | &command_pool); |
| 3628 | |
| 3629 | VkCommandBuffer command_buffer[2]; |
| 3630 | VkCommandBufferAllocateInfo command_buffer_allocate_info{}; |
| 3631 | command_buffer_allocate_info.sType = |
| 3632 | VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO; |
| 3633 | command_buffer_allocate_info.commandPool = command_pool; |
| 3634 | command_buffer_allocate_info.commandBufferCount = 2; |
| 3635 | command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY; |
| 3636 | vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, |
| 3637 | command_buffer); |
| 3638 | |
| 3639 | VkQueue queue = VK_NULL_HANDLE; |
| 3640 | vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, |
| 3641 | 1, &queue); |
| 3642 | |
| 3643 | { |
| 3644 | VkCommandBufferBeginInfo begin_info{}; |
| 3645 | begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO; |
| 3646 | vkBeginCommandBuffer(command_buffer[0], &begin_info); |
| 3647 | |
| 3648 | vkCmdPipelineBarrier(command_buffer[0], |
| 3649 | VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, |
| 3650 | VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, nullptr, |
| 3651 | 0, nullptr, 0, nullptr); |
| 3652 | |
| 3653 | VkViewport viewport{}; |
| 3654 | viewport.maxDepth = 1.0f; |
| 3655 | viewport.minDepth = 0.0f; |
| 3656 | viewport.width = 512; |
| 3657 | viewport.height = 512; |
| 3658 | viewport.x = 0; |
| 3659 | viewport.y = 0; |
| 3660 | vkCmdSetViewport(command_buffer[0], 0, 1, &viewport); |
| 3661 | vkEndCommandBuffer(command_buffer[0]); |
| 3662 | } |
| 3663 | { |
| 3664 | VkCommandBufferBeginInfo begin_info{}; |
| 3665 | begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO; |
| 3666 | vkBeginCommandBuffer(command_buffer[1], &begin_info); |
| 3667 | |
| 3668 | VkViewport viewport{}; |
| 3669 | viewport.maxDepth = 1.0f; |
| 3670 | viewport.minDepth = 0.0f; |
| 3671 | viewport.width = 512; |
| 3672 | viewport.height = 512; |
| 3673 | viewport.x = 0; |
| 3674 | viewport.y = 0; |
| 3675 | vkCmdSetViewport(command_buffer[1], 0, 1, &viewport); |
| 3676 | vkEndCommandBuffer(command_buffer[1]); |
| 3677 | } |
| 3678 | { |
| 3679 | VkSubmitInfo submit_info{}; |
| 3680 | submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO; |
| 3681 | submit_info.commandBufferCount = 1; |
| 3682 | submit_info.pCommandBuffers = &command_buffer[0]; |
| 3683 | submit_info.signalSemaphoreCount = 1; |
| 3684 | submit_info.pSignalSemaphores = &semaphore; |
| 3685 | vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE); |
| 3686 | } |
| 3687 | { |
| 3688 | VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT}; |
| 3689 | VkSubmitInfo submit_info{}; |
| 3690 | submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO; |
| 3691 | submit_info.commandBufferCount = 1; |
| 3692 | submit_info.pCommandBuffers = &command_buffer[1]; |
| 3693 | submit_info.waitSemaphoreCount = 1; |
| 3694 | submit_info.pWaitSemaphores = &semaphore; |
| 3695 | submit_info.pWaitDstStageMask = flags; |
| 3696 | vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE); |
| 3697 | } |
| 3698 | |
| 3699 | vkQueueWaitIdle(m_device->m_queue); |
| 3700 | |
| 3701 | vkDestroySemaphore(m_device->device(), semaphore, nullptr); |
| 3702 | vkFreeCommandBuffers(m_device->device(), command_pool, 2, |
| 3703 | &command_buffer[0]); |
| 3704 | vkDestroyCommandPool(m_device->device(), command_pool, NULL); |
| 3705 | |
| 3706 | m_errorMonitor->VerifyNotFound(); |
| 3707 | } |
| 3708 | |
| 3709 | // This is a positive test. No errors should be generated. |
| 3710 | TEST_F(VkLayerTest, TwoQueueSubmitsSeparateQueuesWithSemaphoreAndOneFenceQWIFence) { |
| 3711 | |
| 3712 | TEST_DESCRIPTION("Two command buffers, each in a separate QueueSubmit call " |
| 3713 | "submitted on separate queues, the second having a fence" |
| 3714 | "followed by a QueueWaitIdle."); |
| 3715 | |
Dustin Graves | 4845814 | 2016-04-29 16:11:55 -0600 | [diff] [blame] | 3716 | if ((m_device->queue_props.empty()) || |
| 3717 | (m_device->queue_props[0].queueCount < 2)) |
Tony Barbour | dc18b26 | 2016-04-22 14:49:48 -0600 | [diff] [blame] | 3718 | return; |
| 3719 | |
Mark Lobodzinski | c808d44 | 2016-04-14 10:57:23 -0600 | [diff] [blame] | 3720 | m_errorMonitor->ExpectSuccess(); |
| 3721 | |
| 3722 | VkFence fence; |
| 3723 | VkFenceCreateInfo fence_create_info{}; |
| 3724 | fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO; |
| 3725 | vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence); |
| 3726 | |
| 3727 | VkSemaphore semaphore; |
| 3728 | VkSemaphoreCreateInfo semaphore_create_info{}; |
| 3729 | semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO; |
| 3730 | vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, |
| 3731 | &semaphore); |
| 3732 | |
| 3733 | VkCommandPool command_pool; |
| 3734 | VkCommandPoolCreateInfo pool_create_info{}; |
| 3735 | pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO; |
| 3736 | pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_; |
| 3737 | pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT; |
| 3738 | vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, |
| 3739 | &command_pool); |
| 3740 | |
| 3741 | VkCommandBuffer command_buffer[2]; |
| 3742 | VkCommandBufferAllocateInfo command_buffer_allocate_info{}; |
| 3743 | command_buffer_allocate_info.sType = |
| 3744 | VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO; |
| 3745 | command_buffer_allocate_info.commandPool = command_pool; |
| 3746 | command_buffer_allocate_info.commandBufferCount = 2; |
| 3747 | command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY; |
| 3748 | vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, |
| 3749 | command_buffer); |
| 3750 | |
| 3751 | VkQueue queue = VK_NULL_HANDLE; |
| 3752 | vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, |
| 3753 | 1, &queue); |
| 3754 | |
| 3755 | { |
| 3756 | VkCommandBufferBeginInfo begin_info{}; |
| 3757 | begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO; |
| 3758 | vkBeginCommandBuffer(command_buffer[0], &begin_info); |
| 3759 | |
| 3760 | vkCmdPipelineBarrier(command_buffer[0], |
| 3761 | VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, |
| 3762 | VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, nullptr, |
| 3763 | 0, nullptr, 0, nullptr); |
| 3764 | |
| 3765 | VkViewport viewport{}; |
| 3766 | viewport.maxDepth = 1.0f; |
| 3767 | viewport.minDepth = 0.0f; |
| 3768 | viewport.width = 512; |
| 3769 | viewport.height = 512; |
| 3770 | viewport.x = 0; |
| 3771 | viewport.y = 0; |
| 3772 | vkCmdSetViewport(command_buffer[0], 0, 1, &viewport); |
| 3773 | vkEndCommandBuffer(command_buffer[0]); |
| 3774 | } |
| 3775 | { |
| 3776 | VkCommandBufferBeginInfo begin_info{}; |
| 3777 | begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO; |
| 3778 | vkBeginCommandBuffer(command_buffer[1], &begin_info); |
| 3779 | |
| 3780 | VkViewport viewport{}; |
| 3781 | viewport.maxDepth = 1.0f; |
| 3782 | viewport.minDepth = 0.0f; |
| 3783 | viewport.width = 512; |
| 3784 | viewport.height = 512; |
| 3785 | viewport.x = 0; |
| 3786 | viewport.y = 0; |
| 3787 | vkCmdSetViewport(command_buffer[1], 0, 1, &viewport); |
| 3788 | vkEndCommandBuffer(command_buffer[1]); |
| 3789 | } |
| 3790 | { |
| 3791 | VkSubmitInfo submit_info{}; |
| 3792 | submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO; |
| 3793 | submit_info.commandBufferCount = 1; |
| 3794 | submit_info.pCommandBuffers = &command_buffer[0]; |
| 3795 | submit_info.signalSemaphoreCount = 1; |
| 3796 | submit_info.pSignalSemaphores = &semaphore; |
| 3797 | vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE); |
| 3798 | } |
| 3799 | { |
| 3800 | VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT}; |
| 3801 | VkSubmitInfo submit_info{}; |
| 3802 | submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO; |
| 3803 | submit_info.commandBufferCount = 1; |
| 3804 | submit_info.pCommandBuffers = &command_buffer[1]; |
| 3805 | submit_info.waitSemaphoreCount = 1; |
| 3806 | submit_info.pWaitSemaphores = &semaphore; |
| 3807 | submit_info.pWaitDstStageMask = flags; |
| 3808 | vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence); |
| 3809 | } |
| 3810 | |
| 3811 | vkQueueWaitIdle(m_device->m_queue); |
| 3812 | |
| 3813 | vkDestroyFence(m_device->device(), fence, nullptr); |
| 3814 | vkDestroySemaphore(m_device->device(), semaphore, nullptr); |
| 3815 | vkFreeCommandBuffers(m_device->device(), command_pool, 2, |
| 3816 | &command_buffer[0]); |
| 3817 | vkDestroyCommandPool(m_device->device(), command_pool, NULL); |
| 3818 | |
| 3819 | m_errorMonitor->VerifyNotFound(); |
| 3820 | } |
| 3821 | |
| 3822 | // This is a positive test. No errors should be generated. |
| 3823 | TEST_F(VkLayerTest, |
| 3824 | TwoQueueSubmitsSeparateQueuesWithSemaphoreAndOneFenceTwoWFF) { |
| 3825 | |
| 3826 | TEST_DESCRIPTION( |
| 3827 | "Two command buffers, each in a separate QueueSubmit call " |
| 3828 | "submitted on separate queues, the second having a fence" |
| 3829 | "followed by two consecutive WaitForFences calls on the same fence."); |
| 3830 | |
Dustin Graves | 4845814 | 2016-04-29 16:11:55 -0600 | [diff] [blame] | 3831 | if ((m_device->queue_props.empty()) || |
| 3832 | (m_device->queue_props[0].queueCount < 2)) |
Tony Barbour | dc18b26 | 2016-04-22 14:49:48 -0600 | [diff] [blame] | 3833 | return; |
| 3834 | |
Mark Lobodzinski | c808d44 | 2016-04-14 10:57:23 -0600 | [diff] [blame] | 3835 | m_errorMonitor->ExpectSuccess(); |
| 3836 | |
| 3837 | VkFence fence; |
| 3838 | VkFenceCreateInfo fence_create_info{}; |
| 3839 | fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO; |
| 3840 | vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence); |
| 3841 | |
| 3842 | VkSemaphore semaphore; |
| 3843 | VkSemaphoreCreateInfo semaphore_create_info{}; |
| 3844 | semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO; |
| 3845 | vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, |
| 3846 | &semaphore); |
| 3847 | |
| 3848 | VkCommandPool command_pool; |
| 3849 | VkCommandPoolCreateInfo pool_create_info{}; |
| 3850 | pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO; |
| 3851 | pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_; |
| 3852 | pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT; |
| 3853 | vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, |
| 3854 | &command_pool); |
| 3855 | |
| 3856 | VkCommandBuffer command_buffer[2]; |
| 3857 | VkCommandBufferAllocateInfo command_buffer_allocate_info{}; |
| 3858 | command_buffer_allocate_info.sType = |
| 3859 | VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO; |
| 3860 | command_buffer_allocate_info.commandPool = command_pool; |
| 3861 | command_buffer_allocate_info.commandBufferCount = 2; |
| 3862 | command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY; |
| 3863 | vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, |
| 3864 | command_buffer); |
| 3865 | |
| 3866 | VkQueue queue = VK_NULL_HANDLE; |
| 3867 | vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, |
| 3868 | 1, &queue); |
| 3869 | |
| 3870 | { |
| 3871 | VkCommandBufferBeginInfo begin_info{}; |
| 3872 | begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO; |
| 3873 | vkBeginCommandBuffer(command_buffer[0], &begin_info); |
| 3874 | |
| 3875 | vkCmdPipelineBarrier(command_buffer[0], |
| 3876 | VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, |
| 3877 | VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, nullptr, |
| 3878 | 0, nullptr, 0, nullptr); |
| 3879 | |
| 3880 | VkViewport viewport{}; |
| 3881 | viewport.maxDepth = 1.0f; |
| 3882 | viewport.minDepth = 0.0f; |
| 3883 | viewport.width = 512; |
| 3884 | viewport.height = 512; |
| 3885 | viewport.x = 0; |
| 3886 | viewport.y = 0; |
| 3887 | vkCmdSetViewport(command_buffer[0], 0, 1, &viewport); |
| 3888 | vkEndCommandBuffer(command_buffer[0]); |
| 3889 | } |
| 3890 | { |
| 3891 | VkCommandBufferBeginInfo begin_info{}; |
| 3892 | begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO; |
| 3893 | vkBeginCommandBuffer(command_buffer[1], &begin_info); |
| 3894 | |
| 3895 | VkViewport viewport{}; |
| 3896 | viewport.maxDepth = 1.0f; |
| 3897 | viewport.minDepth = 0.0f; |
| 3898 | viewport.width = 512; |
| 3899 | viewport.height = 512; |
| 3900 | viewport.x = 0; |
| 3901 | viewport.y = 0; |
| 3902 | vkCmdSetViewport(command_buffer[1], 0, 1, &viewport); |
| 3903 | vkEndCommandBuffer(command_buffer[1]); |
| 3904 | } |
| 3905 | { |
| 3906 | VkSubmitInfo submit_info{}; |
| 3907 | submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO; |
| 3908 | submit_info.commandBufferCount = 1; |
| 3909 | submit_info.pCommandBuffers = &command_buffer[0]; |
| 3910 | submit_info.signalSemaphoreCount = 1; |
| 3911 | submit_info.pSignalSemaphores = &semaphore; |
| 3912 | vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE); |
| 3913 | } |
| 3914 | { |
| 3915 | VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT}; |
| 3916 | VkSubmitInfo submit_info{}; |
| 3917 | submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO; |
| 3918 | submit_info.commandBufferCount = 1; |
| 3919 | submit_info.pCommandBuffers = &command_buffer[1]; |
| 3920 | submit_info.waitSemaphoreCount = 1; |
| 3921 | submit_info.pWaitSemaphores = &semaphore; |
| 3922 | submit_info.pWaitDstStageMask = flags; |
| 3923 | vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence); |
| 3924 | } |
| 3925 | |
| 3926 | vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX); |
| 3927 | vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX); |
| 3928 | |
| 3929 | vkDestroyFence(m_device->device(), fence, nullptr); |
| 3930 | vkDestroySemaphore(m_device->device(), semaphore, nullptr); |
| 3931 | vkFreeCommandBuffers(m_device->device(), command_pool, 2, |
| 3932 | &command_buffer[0]); |
| 3933 | vkDestroyCommandPool(m_device->device(), command_pool, NULL); |
| 3934 | |
| 3935 | m_errorMonitor->VerifyNotFound(); |
| 3936 | } |
| 3937 | |
| 3938 | // This is a positive test. No errors should be generated. |
| 3939 | TEST_F(VkLayerTest, TwoQueueSubmitsSeparateQueuesWithSemaphoreAndOneFence) { |
| 3940 | |
| 3941 | TEST_DESCRIPTION("Two command buffers, each in a separate QueueSubmit call " |
| 3942 | "submitted on separate queues, the second having a fence, " |
| 3943 | "followed by a WaitForFences call."); |
| 3944 | |
Dustin Graves | 4845814 | 2016-04-29 16:11:55 -0600 | [diff] [blame] | 3945 | if ((m_device->queue_props.empty()) || |
| 3946 | (m_device->queue_props[0].queueCount < 2)) |
Tony Barbour | dc18b26 | 2016-04-22 14:49:48 -0600 | [diff] [blame] | 3947 | return; |
| 3948 | |
Mark Lobodzinski | c808d44 | 2016-04-14 10:57:23 -0600 | [diff] [blame] | 3949 | m_errorMonitor->ExpectSuccess(); |
| 3950 | |
| 3951 | VkFence fence; |
| 3952 | VkFenceCreateInfo fence_create_info{}; |
| 3953 | fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO; |
| 3954 | vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence); |
| 3955 | |
| 3956 | VkSemaphore semaphore; |
| 3957 | VkSemaphoreCreateInfo semaphore_create_info{}; |
| 3958 | semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO; |
| 3959 | vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, |
| 3960 | &semaphore); |
| 3961 | |
| 3962 | VkCommandPool command_pool; |
| 3963 | VkCommandPoolCreateInfo pool_create_info{}; |
| 3964 | pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO; |
| 3965 | pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_; |
| 3966 | pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT; |
| 3967 | vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, |
| 3968 | &command_pool); |
| 3969 | |
| 3970 | VkCommandBuffer command_buffer[2]; |
| 3971 | VkCommandBufferAllocateInfo command_buffer_allocate_info{}; |
| 3972 | command_buffer_allocate_info.sType = |
| 3973 | VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO; |
| 3974 | command_buffer_allocate_info.commandPool = command_pool; |
| 3975 | command_buffer_allocate_info.commandBufferCount = 2; |
| 3976 | command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY; |
| 3977 | vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, |
| 3978 | command_buffer); |
| 3979 | |
| 3980 | VkQueue queue = VK_NULL_HANDLE; |
| 3981 | vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, |
| 3982 | 1, &queue); |
| 3983 | |
| 3984 | |
| 3985 | { |
| 3986 | VkCommandBufferBeginInfo begin_info{}; |
| 3987 | begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO; |
| 3988 | vkBeginCommandBuffer(command_buffer[0], &begin_info); |
| 3989 | |
| 3990 | vkCmdPipelineBarrier(command_buffer[0], |
| 3991 | VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, |
| 3992 | VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, nullptr, |
| 3993 | 0, nullptr, 0, nullptr); |
| 3994 | |
| 3995 | VkViewport viewport{}; |
| 3996 | viewport.maxDepth = 1.0f; |
| 3997 | viewport.minDepth = 0.0f; |
| 3998 | viewport.width = 512; |
| 3999 | viewport.height = 512; |
| 4000 | viewport.x = 0; |
| 4001 | viewport.y = 0; |
| 4002 | vkCmdSetViewport(command_buffer[0], 0, 1, &viewport); |
| 4003 | vkEndCommandBuffer(command_buffer[0]); |
| 4004 | } |
| 4005 | { |
| 4006 | VkCommandBufferBeginInfo begin_info{}; |
| 4007 | begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO; |
| 4008 | vkBeginCommandBuffer(command_buffer[1], &begin_info); |
| 4009 | |
| 4010 | VkViewport viewport{}; |
| 4011 | viewport.maxDepth = 1.0f; |
| 4012 | viewport.minDepth = 0.0f; |
| 4013 | viewport.width = 512; |
| 4014 | viewport.height = 512; |
| 4015 | viewport.x = 0; |
| 4016 | viewport.y = 0; |
| 4017 | vkCmdSetViewport(command_buffer[1], 0, 1, &viewport); |
| 4018 | vkEndCommandBuffer(command_buffer[1]); |
| 4019 | } |
| 4020 | { |
| 4021 | VkSubmitInfo submit_info{}; |
| 4022 | submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO; |
| 4023 | submit_info.commandBufferCount = 1; |
| 4024 | submit_info.pCommandBuffers = &command_buffer[0]; |
| 4025 | submit_info.signalSemaphoreCount = 1; |
| 4026 | submit_info.pSignalSemaphores = &semaphore; |
| 4027 | vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE); |
| 4028 | } |
| 4029 | { |
| 4030 | VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT}; |
| 4031 | VkSubmitInfo submit_info{}; |
| 4032 | submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO; |
| 4033 | submit_info.commandBufferCount = 1; |
| 4034 | submit_info.pCommandBuffers = &command_buffer[1]; |
| 4035 | submit_info.waitSemaphoreCount = 1; |
| 4036 | submit_info.pWaitSemaphores = &semaphore; |
| 4037 | submit_info.pWaitDstStageMask = flags; |
| 4038 | vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence); |
| 4039 | } |
| 4040 | |
| 4041 | vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX); |
| 4042 | |
| 4043 | vkDestroyFence(m_device->device(), fence, nullptr); |
| 4044 | vkDestroySemaphore(m_device->device(), semaphore, nullptr); |
| 4045 | vkFreeCommandBuffers(m_device->device(), command_pool, 2, |
| 4046 | &command_buffer[0]); |
| 4047 | vkDestroyCommandPool(m_device->device(), command_pool, NULL); |
| 4048 | |
| 4049 | m_errorMonitor->VerifyNotFound(); |
| 4050 | } |
| 4051 | |
| 4052 | // This is a positive test. No errors should be generated. |
| 4053 | TEST_F(VkLayerTest, TwoQueueSubmitsOneQueueWithSemaphoreAndOneFence) { |
| 4054 | |
| 4055 | TEST_DESCRIPTION("Two command buffers, each in a separate QueueSubmit call " |
| 4056 | "on the same queue, sharing a signal/wait semaphore, the " |
| 4057 | "second having a fence, " |
| 4058 | "followed by a WaitForFences call."); |
| 4059 | |
| 4060 | m_errorMonitor->ExpectSuccess(); |
| 4061 | |
| 4062 | VkFence fence; |
| 4063 | VkFenceCreateInfo fence_create_info{}; |
| 4064 | fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO; |
| 4065 | vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence); |
| 4066 | |
| 4067 | VkSemaphore semaphore; |
| 4068 | VkSemaphoreCreateInfo semaphore_create_info{}; |
| 4069 | semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO; |
| 4070 | vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, |
| 4071 | &semaphore); |
| 4072 | |
| 4073 | VkCommandPool command_pool; |
| 4074 | VkCommandPoolCreateInfo pool_create_info{}; |
| 4075 | pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO; |
| 4076 | pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_; |
| 4077 | pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT; |
| 4078 | vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, |
| 4079 | &command_pool); |
| 4080 | |
| 4081 | VkCommandBuffer command_buffer[2]; |
| 4082 | VkCommandBufferAllocateInfo command_buffer_allocate_info{}; |
| 4083 | command_buffer_allocate_info.sType = |
| 4084 | VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO; |
| 4085 | command_buffer_allocate_info.commandPool = command_pool; |
| 4086 | command_buffer_allocate_info.commandBufferCount = 2; |
| 4087 | command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY; |
| 4088 | vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, |
| 4089 | command_buffer); |
| 4090 | |
| 4091 | { |
| 4092 | VkCommandBufferBeginInfo begin_info{}; |
| 4093 | begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO; |
| 4094 | vkBeginCommandBuffer(command_buffer[0], &begin_info); |
| 4095 | |
| 4096 | vkCmdPipelineBarrier(command_buffer[0], |
| 4097 | VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, |
| 4098 | VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, nullptr, |
| 4099 | 0, nullptr, 0, nullptr); |
| 4100 | |
| 4101 | VkViewport viewport{}; |
| 4102 | viewport.maxDepth = 1.0f; |
| 4103 | viewport.minDepth = 0.0f; |
| 4104 | viewport.width = 512; |
| 4105 | viewport.height = 512; |
| 4106 | viewport.x = 0; |
| 4107 | viewport.y = 0; |
| 4108 | vkCmdSetViewport(command_buffer[0], 0, 1, &viewport); |
| 4109 | vkEndCommandBuffer(command_buffer[0]); |
| 4110 | } |
| 4111 | { |
| 4112 | VkCommandBufferBeginInfo begin_info{}; |
| 4113 | begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO; |
| 4114 | vkBeginCommandBuffer(command_buffer[1], &begin_info); |
| 4115 | |
| 4116 | VkViewport viewport{}; |
| 4117 | viewport.maxDepth = 1.0f; |
| 4118 | viewport.minDepth = 0.0f; |
| 4119 | viewport.width = 512; |
| 4120 | viewport.height = 512; |
| 4121 | viewport.x = 0; |
| 4122 | viewport.y = 0; |
| 4123 | vkCmdSetViewport(command_buffer[1], 0, 1, &viewport); |
| 4124 | vkEndCommandBuffer(command_buffer[1]); |
| 4125 | } |
| 4126 | { |
| 4127 | VkSubmitInfo submit_info{}; |
| 4128 | submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO; |
| 4129 | submit_info.commandBufferCount = 1; |
| 4130 | submit_info.pCommandBuffers = &command_buffer[0]; |
| 4131 | submit_info.signalSemaphoreCount = 1; |
| 4132 | submit_info.pSignalSemaphores = &semaphore; |
| 4133 | vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE); |
| 4134 | } |
| 4135 | { |
| 4136 | VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT}; |
| 4137 | VkSubmitInfo submit_info{}; |
| 4138 | submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO; |
| 4139 | submit_info.commandBufferCount = 1; |
| 4140 | submit_info.pCommandBuffers = &command_buffer[1]; |
| 4141 | submit_info.waitSemaphoreCount = 1; |
| 4142 | submit_info.pWaitSemaphores = &semaphore; |
| 4143 | submit_info.pWaitDstStageMask = flags; |
| 4144 | vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence); |
| 4145 | } |
| 4146 | |
| 4147 | vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX); |
| 4148 | |
| 4149 | vkDestroyFence(m_device->device(), fence, nullptr); |
| 4150 | vkDestroySemaphore(m_device->device(), semaphore, nullptr); |
| 4151 | vkFreeCommandBuffers(m_device->device(), command_pool, 2, |
| 4152 | &command_buffer[0]); |
| 4153 | vkDestroyCommandPool(m_device->device(), command_pool, NULL); |
| 4154 | |
| 4155 | m_errorMonitor->VerifyNotFound(); |
| 4156 | } |
| 4157 | |
| 4158 | // This is a positive test. No errors should be generated. |
| 4159 | TEST_F(VkLayerTest, TwoQueueSubmitsOneQueueNullQueueSubmitWithFence) { |
| 4160 | |
| 4161 | TEST_DESCRIPTION( |
| 4162 | "Two command buffers, each in a separate QueueSubmit call " |
| 4163 | "on the same queue, no fences, followed by a third QueueSubmit with NO " |
| 4164 | "SubmitInfos but with a fence, followed by a WaitForFences call."); |
| 4165 | |
| 4166 | m_errorMonitor->ExpectSuccess(); |
| 4167 | |
| 4168 | VkFence fence; |
| 4169 | VkFenceCreateInfo fence_create_info{}; |
| 4170 | fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO; |
| 4171 | vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence); |
| 4172 | |
| 4173 | VkCommandPool command_pool; |
| 4174 | VkCommandPoolCreateInfo pool_create_info{}; |
| 4175 | pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO; |
| 4176 | pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_; |
| 4177 | pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT; |
| 4178 | vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, |
| 4179 | &command_pool); |
| 4180 | |
| 4181 | VkCommandBuffer command_buffer[2]; |
| 4182 | VkCommandBufferAllocateInfo command_buffer_allocate_info{}; |
| 4183 | command_buffer_allocate_info.sType = |
| 4184 | VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO; |
| 4185 | command_buffer_allocate_info.commandPool = command_pool; |
| 4186 | command_buffer_allocate_info.commandBufferCount = 2; |
| 4187 | command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY; |
| 4188 | vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, |
| 4189 | command_buffer); |
| 4190 | |
| 4191 | { |
| 4192 | VkCommandBufferBeginInfo begin_info{}; |
| 4193 | begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO; |
| 4194 | vkBeginCommandBuffer(command_buffer[0], &begin_info); |
| 4195 | |
| 4196 | vkCmdPipelineBarrier(command_buffer[0], |
| 4197 | VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, |
| 4198 | VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, nullptr, |
| 4199 | 0, nullptr, 0, nullptr); |
| 4200 | |
| 4201 | VkViewport viewport{}; |
| 4202 | viewport.maxDepth = 1.0f; |
| 4203 | viewport.minDepth = 0.0f; |
| 4204 | viewport.width = 512; |
| 4205 | viewport.height = 512; |
| 4206 | viewport.x = 0; |
| 4207 | viewport.y = 0; |
| 4208 | vkCmdSetViewport(command_buffer[0], 0, 1, &viewport); |
| 4209 | vkEndCommandBuffer(command_buffer[0]); |
| 4210 | } |
| 4211 | { |
| 4212 | VkCommandBufferBeginInfo begin_info{}; |
| 4213 | begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO; |
| 4214 | vkBeginCommandBuffer(command_buffer[1], &begin_info); |
| 4215 | |
| 4216 | VkViewport viewport{}; |
| 4217 | viewport.maxDepth = 1.0f; |
| 4218 | viewport.minDepth = 0.0f; |
| 4219 | viewport.width = 512; |
| 4220 | viewport.height = 512; |
| 4221 | viewport.x = 0; |
| 4222 | viewport.y = 0; |
| 4223 | vkCmdSetViewport(command_buffer[1], 0, 1, &viewport); |
| 4224 | vkEndCommandBuffer(command_buffer[1]); |
| 4225 | } |
| 4226 | { |
| 4227 | VkSubmitInfo submit_info{}; |
| 4228 | submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO; |
| 4229 | submit_info.commandBufferCount = 1; |
| 4230 | submit_info.pCommandBuffers = &command_buffer[0]; |
| 4231 | submit_info.signalSemaphoreCount = 0; |
| 4232 | submit_info.pSignalSemaphores = VK_NULL_HANDLE; |
| 4233 | vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE); |
| 4234 | } |
| 4235 | { |
| 4236 | VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT}; |
| 4237 | VkSubmitInfo submit_info{}; |
| 4238 | submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO; |
| 4239 | submit_info.commandBufferCount = 1; |
| 4240 | submit_info.pCommandBuffers = &command_buffer[1]; |
| 4241 | submit_info.waitSemaphoreCount = 0; |
| 4242 | submit_info.pWaitSemaphores = VK_NULL_HANDLE; |
| 4243 | submit_info.pWaitDstStageMask = flags; |
| 4244 | vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE); |
| 4245 | } |
| 4246 | |
| 4247 | vkQueueSubmit(m_device->m_queue, 0, NULL, fence); |
| 4248 | |
| 4249 | vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX); |
| 4250 | |
| 4251 | vkDestroyFence(m_device->device(), fence, nullptr); |
| 4252 | vkFreeCommandBuffers(m_device->device(), command_pool, 2, |
| 4253 | &command_buffer[0]); |
| 4254 | vkDestroyCommandPool(m_device->device(), command_pool, NULL); |
| 4255 | |
| 4256 | m_errorMonitor->VerifyNotFound(); |
| 4257 | } |
| 4258 | |
| 4259 | // This is a positive test. No errors should be generated. |
| 4260 | TEST_F(VkLayerTest, TwoQueueSubmitsOneQueueOneFence) { |
| 4261 | |
| 4262 | TEST_DESCRIPTION("Two command buffers, each in a separate QueueSubmit call " |
| 4263 | "on the same queue, the second having a fence, followed " |
| 4264 | "by a WaitForFences call."); |
| 4265 | |
| 4266 | m_errorMonitor->ExpectSuccess(); |
| 4267 | |
| 4268 | VkFence fence; |
| 4269 | VkFenceCreateInfo fence_create_info{}; |
| 4270 | fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO; |
| 4271 | vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence); |
| 4272 | |
| 4273 | VkCommandPool command_pool; |
| 4274 | VkCommandPoolCreateInfo pool_create_info{}; |
| 4275 | pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO; |
| 4276 | pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_; |
| 4277 | pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT; |
| 4278 | vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, |
| 4279 | &command_pool); |
| 4280 | |
| 4281 | VkCommandBuffer command_buffer[2]; |
| 4282 | VkCommandBufferAllocateInfo command_buffer_allocate_info{}; |
| 4283 | command_buffer_allocate_info.sType = |
| 4284 | VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO; |
| 4285 | command_buffer_allocate_info.commandPool = command_pool; |
| 4286 | command_buffer_allocate_info.commandBufferCount = 2; |
| 4287 | command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY; |
| 4288 | vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, |
| 4289 | command_buffer); |
| 4290 | |
| 4291 | { |
| 4292 | VkCommandBufferBeginInfo begin_info{}; |
| 4293 | begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO; |
| 4294 | vkBeginCommandBuffer(command_buffer[0], &begin_info); |
| 4295 | |
| 4296 | vkCmdPipelineBarrier(command_buffer[0], |
| 4297 | VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, |
| 4298 | VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, nullptr, |
| 4299 | 0, nullptr, 0, nullptr); |
| 4300 | |
| 4301 | VkViewport viewport{}; |
| 4302 | viewport.maxDepth = 1.0f; |
| 4303 | viewport.minDepth = 0.0f; |
| 4304 | viewport.width = 512; |
| 4305 | viewport.height = 512; |
| 4306 | viewport.x = 0; |
| 4307 | viewport.y = 0; |
| 4308 | vkCmdSetViewport(command_buffer[0], 0, 1, &viewport); |
| 4309 | vkEndCommandBuffer(command_buffer[0]); |
| 4310 | } |
| 4311 | { |
| 4312 | VkCommandBufferBeginInfo begin_info{}; |
| 4313 | begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO; |
| 4314 | vkBeginCommandBuffer(command_buffer[1], &begin_info); |
| 4315 | |
| 4316 | VkViewport viewport{}; |
| 4317 | viewport.maxDepth = 1.0f; |
| 4318 | viewport.minDepth = 0.0f; |
| 4319 | viewport.width = 512; |
| 4320 | viewport.height = 512; |
| 4321 | viewport.x = 0; |
| 4322 | viewport.y = 0; |
| 4323 | vkCmdSetViewport(command_buffer[1], 0, 1, &viewport); |
| 4324 | vkEndCommandBuffer(command_buffer[1]); |
| 4325 | } |
| 4326 | { |
| 4327 | VkSubmitInfo submit_info{}; |
| 4328 | submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO; |
| 4329 | submit_info.commandBufferCount = 1; |
| 4330 | submit_info.pCommandBuffers = &command_buffer[0]; |
| 4331 | submit_info.signalSemaphoreCount = 0; |
| 4332 | submit_info.pSignalSemaphores = VK_NULL_HANDLE; |
| 4333 | vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE); |
| 4334 | } |
| 4335 | { |
| 4336 | VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT}; |
| 4337 | VkSubmitInfo submit_info{}; |
| 4338 | submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO; |
| 4339 | submit_info.commandBufferCount = 1; |
| 4340 | submit_info.pCommandBuffers = &command_buffer[1]; |
| 4341 | submit_info.waitSemaphoreCount = 0; |
| 4342 | submit_info.pWaitSemaphores = VK_NULL_HANDLE; |
| 4343 | submit_info.pWaitDstStageMask = flags; |
| 4344 | vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence); |
| 4345 | } |
| 4346 | |
| 4347 | vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX); |
| 4348 | |
| 4349 | vkDestroyFence(m_device->device(), fence, nullptr); |
| 4350 | vkFreeCommandBuffers(m_device->device(), command_pool, 2, |
| 4351 | &command_buffer[0]); |
| 4352 | vkDestroyCommandPool(m_device->device(), command_pool, NULL); |
| 4353 | |
| 4354 | m_errorMonitor->VerifyNotFound(); |
| 4355 | } |
| 4356 | |
| 4357 | // This is a positive test. No errors should be generated. |
| 4358 | TEST_F(VkLayerTest, TwoSubmitInfosWithSemaphoreOneQueueSubmitsOneFence) { |
| 4359 | |
| 4360 | TEST_DESCRIPTION( |
| 4361 | "Two command buffers each in a separate SubmitInfo sent in a single " |
| 4362 | "QueueSubmit call followed by a WaitForFences call."); |
| 4363 | |
| 4364 | m_errorMonitor->ExpectSuccess(); |
| 4365 | |
| 4366 | VkFence fence; |
| 4367 | VkFenceCreateInfo fence_create_info{}; |
| 4368 | fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO; |
| 4369 | vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence); |
| 4370 | |
| 4371 | VkSemaphore semaphore; |
| 4372 | VkSemaphoreCreateInfo semaphore_create_info{}; |
| 4373 | semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO; |
| 4374 | vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, |
| 4375 | &semaphore); |
| 4376 | |
| 4377 | VkCommandPool command_pool; |
| 4378 | VkCommandPoolCreateInfo pool_create_info{}; |
| 4379 | pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO; |
| 4380 | pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_; |
| 4381 | pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT; |
| 4382 | vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, |
| 4383 | &command_pool); |
| 4384 | |
| 4385 | VkCommandBuffer command_buffer[2]; |
| 4386 | VkCommandBufferAllocateInfo command_buffer_allocate_info{}; |
| 4387 | command_buffer_allocate_info.sType = |
| 4388 | VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO; |
| 4389 | command_buffer_allocate_info.commandPool = command_pool; |
| 4390 | command_buffer_allocate_info.commandBufferCount = 2; |
| 4391 | command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY; |
| 4392 | vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, |
| 4393 | command_buffer); |
| 4394 | |
| 4395 | { |
| 4396 | VkCommandBufferBeginInfo begin_info{}; |
| 4397 | begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO; |
| 4398 | vkBeginCommandBuffer(command_buffer[0], &begin_info); |
| 4399 | |
| 4400 | vkCmdPipelineBarrier(command_buffer[0], |
| 4401 | VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, |
| 4402 | VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, nullptr, |
| 4403 | 0, nullptr, 0, nullptr); |
| 4404 | |
| 4405 | VkViewport viewport{}; |
| 4406 | viewport.maxDepth = 1.0f; |
| 4407 | viewport.minDepth = 0.0f; |
| 4408 | viewport.width = 512; |
| 4409 | viewport.height = 512; |
| 4410 | viewport.x = 0; |
| 4411 | viewport.y = 0; |
| 4412 | vkCmdSetViewport(command_buffer[0], 0, 1, &viewport); |
| 4413 | vkEndCommandBuffer(command_buffer[0]); |
| 4414 | } |
| 4415 | { |
| 4416 | VkCommandBufferBeginInfo begin_info{}; |
| 4417 | begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO; |
| 4418 | vkBeginCommandBuffer(command_buffer[1], &begin_info); |
| 4419 | |
| 4420 | VkViewport viewport{}; |
| 4421 | viewport.maxDepth = 1.0f; |
| 4422 | viewport.minDepth = 0.0f; |
| 4423 | viewport.width = 512; |
| 4424 | viewport.height = 512; |
| 4425 | viewport.x = 0; |
| 4426 | viewport.y = 0; |
| 4427 | vkCmdSetViewport(command_buffer[1], 0, 1, &viewport); |
| 4428 | vkEndCommandBuffer(command_buffer[1]); |
| 4429 | } |
| 4430 | { |
| 4431 | VkSubmitInfo submit_info[2]; |
| 4432 | VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT}; |
| 4433 | |
| 4434 | submit_info[0].sType = VK_STRUCTURE_TYPE_SUBMIT_INFO; |
| 4435 | submit_info[0].pNext = NULL; |
| 4436 | submit_info[0].commandBufferCount = 1; |
| 4437 | submit_info[0].pCommandBuffers = &command_buffer[0]; |
| 4438 | submit_info[0].signalSemaphoreCount = 1; |
| 4439 | submit_info[0].pSignalSemaphores = &semaphore; |
| 4440 | submit_info[0].waitSemaphoreCount = 0; |
| 4441 | submit_info[0].pWaitSemaphores = NULL; |
| 4442 | submit_info[0].pWaitDstStageMask = 0; |
| 4443 | |
| 4444 | submit_info[1].sType = VK_STRUCTURE_TYPE_SUBMIT_INFO; |
| 4445 | submit_info[1].pNext = NULL; |
| 4446 | submit_info[1].commandBufferCount = 1; |
| 4447 | submit_info[1].pCommandBuffers = &command_buffer[1]; |
| 4448 | submit_info[1].waitSemaphoreCount = 1; |
| 4449 | submit_info[1].pWaitSemaphores = &semaphore; |
| 4450 | submit_info[1].pWaitDstStageMask = flags; |
| 4451 | submit_info[1].signalSemaphoreCount = 0; |
| 4452 | submit_info[1].pSignalSemaphores = NULL; |
| 4453 | vkQueueSubmit(m_device->m_queue, 2, &submit_info[0], fence); |
| 4454 | } |
| 4455 | |
| 4456 | vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX); |
| 4457 | |
| 4458 | vkDestroyFence(m_device->device(), fence, nullptr); |
| 4459 | vkFreeCommandBuffers(m_device->device(), command_pool, 2, |
| 4460 | &command_buffer[0]); |
| 4461 | vkDestroyCommandPool(m_device->device(), command_pool, NULL); |
Tony Barbour | df4c004 | 2016-06-01 15:55:43 -0600 | [diff] [blame] | 4462 | vkDestroySemaphore(m_device->device(), semaphore, nullptr); |
Mark Lobodzinski | c808d44 | 2016-04-14 10:57:23 -0600 | [diff] [blame] | 4463 | |
| 4464 | m_errorMonitor->VerifyNotFound(); |
| 4465 | } |
| 4466 | |
Tobin Ehlis | b1a8799 | 2016-05-25 16:42:47 -0600 | [diff] [blame] | 4467 | TEST_F(VkLayerTest, DynamicDepthBiasNotBound) { |
Tobin Ehlis | a5200ef | 2016-05-03 10:34:08 -0600 | [diff] [blame] | 4468 | TEST_DESCRIPTION( |
Tobin Ehlis | b1a8799 | 2016-05-25 16:42:47 -0600 | [diff] [blame] | 4469 | "Run a simple draw calls to validate failure when Depth Bias dynamic " |
| 4470 | "state is required but not correctly bound."); |
| 4471 | |
| 4472 | // Dynamic depth bias |
| 4473 | m_errorMonitor->SetDesiredFailureMsg( |
| 4474 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 4475 | "Dynamic depth bias state not set for this command buffer"); |
| 4476 | VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, |
| 4477 | BsoFailDepthBias); |
| 4478 | m_errorMonitor->VerifyFound(); |
| 4479 | } |
| 4480 | |
| 4481 | TEST_F(VkLayerTest, DynamicLineWidthNotBound) { |
| 4482 | TEST_DESCRIPTION( |
| 4483 | "Run a simple draw calls to validate failure when Line Width dynamic " |
| 4484 | "state is required but not correctly bound."); |
Tobin Ehlis | a5200ef | 2016-05-03 10:34:08 -0600 | [diff] [blame] | 4485 | |
| 4486 | // Dynamic line width |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 4487 | m_errorMonitor->SetDesiredFailureMsg( |
| 4488 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 4489 | "Dynamic line width state not set for this command buffer"); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 4490 | VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, |
| 4491 | BsoFailLineWidth); |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 4492 | m_errorMonitor->VerifyFound(); |
Tobin Ehlis | b1a8799 | 2016-05-25 16:42:47 -0600 | [diff] [blame] | 4493 | } |
| 4494 | |
| 4495 | TEST_F(VkLayerTest, DynamicViewportNotBound) { |
| 4496 | TEST_DESCRIPTION( |
| 4497 | "Run a simple draw calls to validate failure when Viewport dynamic " |
| 4498 | "state is required but not correctly bound."); |
| 4499 | |
Tobin Ehlis | a5200ef | 2016-05-03 10:34:08 -0600 | [diff] [blame] | 4500 | // Dynamic viewport state |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 4501 | m_errorMonitor->SetDesiredFailureMsg( |
| 4502 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 4503 | "Dynamic viewport state not set for this command buffer"); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 4504 | VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, |
| 4505 | BsoFailViewport); |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 4506 | m_errorMonitor->VerifyFound(); |
Tobin Ehlis | b1a8799 | 2016-05-25 16:42:47 -0600 | [diff] [blame] | 4507 | } |
| 4508 | |
| 4509 | TEST_F(VkLayerTest, DynamicScissorNotBound) { |
| 4510 | TEST_DESCRIPTION( |
| 4511 | "Run a simple draw calls to validate failure when Scissor dynamic " |
| 4512 | "state is required but not correctly bound."); |
| 4513 | |
Tobin Ehlis | a5200ef | 2016-05-03 10:34:08 -0600 | [diff] [blame] | 4514 | // Dynamic scissor state |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 4515 | m_errorMonitor->SetDesiredFailureMsg( |
| 4516 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 4517 | "Dynamic scissor state not set for this command buffer"); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 4518 | VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, |
| 4519 | BsoFailScissor); |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 4520 | m_errorMonitor->VerifyFound(); |
Tobin Ehlis | b1a8799 | 2016-05-25 16:42:47 -0600 | [diff] [blame] | 4521 | } |
| 4522 | |
Tobin Ehlis | 21c8835 | 2016-05-26 06:15:45 -0600 | [diff] [blame] | 4523 | TEST_F(VkLayerTest, DynamiBlendConstantsNotBound) { |
Tobin Ehlis | b1a8799 | 2016-05-25 16:42:47 -0600 | [diff] [blame] | 4524 | TEST_DESCRIPTION( |
Tobin Ehlis | 21c8835 | 2016-05-26 06:15:45 -0600 | [diff] [blame] | 4525 | "Run a simple draw calls to validate failure when Blend Constants " |
| 4526 | "dynamic state is required but not correctly bound."); |
| 4527 | // Dynamic blend constant state |
| 4528 | m_errorMonitor->SetDesiredFailureMsg( |
| 4529 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 4530 | "Dynamic blend constants state not set for this command buffer"); |
| 4531 | VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, |
| 4532 | BsoFailBlend); |
| 4533 | m_errorMonitor->VerifyFound(); |
| 4534 | } |
| 4535 | |
| 4536 | TEST_F(VkLayerTest, DynamicDepthBoundsNotBound) { |
| 4537 | TEST_DESCRIPTION( |
| 4538 | "Run a simple draw calls to validate failure when Depth Bounds dynamic " |
Tobin Ehlis | b1a8799 | 2016-05-25 16:42:47 -0600 | [diff] [blame] | 4539 | "state is required but not correctly bound."); |
Tobin Ehlis | 21c8835 | 2016-05-26 06:15:45 -0600 | [diff] [blame] | 4540 | if (!m_device->phy().features().depthBounds) { |
| 4541 | printf("Device does not support depthBounds test; skipped.\n"); |
| 4542 | return; |
| 4543 | } |
| 4544 | // Dynamic depth bounds |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 4545 | m_errorMonitor->SetDesiredFailureMsg( |
| 4546 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 4547 | "Dynamic depth bounds state not set for this command buffer"); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 4548 | VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, |
| 4549 | BsoFailDepthBounds); |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 4550 | m_errorMonitor->VerifyFound(); |
Tobin Ehlis | b1a8799 | 2016-05-25 16:42:47 -0600 | [diff] [blame] | 4551 | } |
| 4552 | |
| 4553 | TEST_F(VkLayerTest, DynamicStencilReadNotBound) { |
| 4554 | TEST_DESCRIPTION( |
| 4555 | "Run a simple draw calls to validate failure when Stencil Read dynamic " |
| 4556 | "state is required but not correctly bound."); |
Tobin Ehlis | a5200ef | 2016-05-03 10:34:08 -0600 | [diff] [blame] | 4557 | // Dynamic stencil read mask |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 4558 | m_errorMonitor->SetDesiredFailureMsg( |
| 4559 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 4560 | "Dynamic stencil read mask state not set for this command buffer"); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 4561 | VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, |
| 4562 | BsoFailStencilReadMask); |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 4563 | m_errorMonitor->VerifyFound(); |
Tobin Ehlis | b1a8799 | 2016-05-25 16:42:47 -0600 | [diff] [blame] | 4564 | } |
| 4565 | |
| 4566 | TEST_F(VkLayerTest, DynamicStencilWriteNotBound) { |
| 4567 | TEST_DESCRIPTION( |
| 4568 | "Run a simple draw calls to validate failure when Stencil Write dynamic" |
| 4569 | " state is required but not correctly bound."); |
Tobin Ehlis | a5200ef | 2016-05-03 10:34:08 -0600 | [diff] [blame] | 4570 | // Dynamic stencil write mask |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 4571 | m_errorMonitor->SetDesiredFailureMsg( |
| 4572 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 4573 | "Dynamic stencil write mask state not set for this command buffer"); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 4574 | VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, |
| 4575 | BsoFailStencilWriteMask); |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 4576 | m_errorMonitor->VerifyFound(); |
Tobin Ehlis | b1a8799 | 2016-05-25 16:42:47 -0600 | [diff] [blame] | 4577 | } |
| 4578 | |
| 4579 | TEST_F(VkLayerTest, DynamicStencilRefNotBound) { |
| 4580 | TEST_DESCRIPTION( |
| 4581 | "Run a simple draw calls to validate failure when Stencil Ref dynamic " |
| 4582 | "state is required but not correctly bound."); |
Tobin Ehlis | a5200ef | 2016-05-03 10:34:08 -0600 | [diff] [blame] | 4583 | // Dynamic stencil reference |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 4584 | m_errorMonitor->SetDesiredFailureMsg( |
| 4585 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 4586 | "Dynamic stencil reference state not set for this command buffer"); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 4587 | VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, |
| 4588 | BsoFailStencilReference); |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 4589 | m_errorMonitor->VerifyFound(); |
Tobin Ehlis | 963a404 | 2015-09-29 08:18:34 -0600 | [diff] [blame] | 4590 | } |
| 4591 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 4592 | TEST_F(VkLayerTest, CommandBufferTwoSubmits) { |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 4593 | m_errorMonitor->SetDesiredFailureMsg( |
| 4594 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 4595 | "was begun w/ VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT set, but has " |
| 4596 | "been submitted"); |
Tobin Ehlis | 59278bf | 2015-08-18 07:10:58 -0600 | [diff] [blame] | 4597 | |
Tobin Ehlis | 59278bf | 2015-08-18 07:10:58 -0600 | [diff] [blame] | 4598 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 4599 | ASSERT_NO_FATAL_FAILURE(InitViewport()); |
| 4600 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 4601 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 4602 | // We luck out b/c by default the framework creates CB w/ the |
| 4603 | // VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT set |
Tobin Ehlis | 59278bf | 2015-08-18 07:10:58 -0600 | [diff] [blame] | 4604 | BeginCommandBuffer(); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 4605 | m_commandBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color, |
| 4606 | m_stencil_clear_color, NULL); |
Tobin Ehlis | 59278bf | 2015-08-18 07:10:58 -0600 | [diff] [blame] | 4607 | EndCommandBuffer(); |
| 4608 | |
Tobin Ehlis | 59278bf | 2015-08-18 07:10:58 -0600 | [diff] [blame] | 4609 | // Bypass framework since it does the waits automatically |
| 4610 | VkResult err = VK_SUCCESS; |
Courtney Goeltzenleuchter | 806c700 | 2015-10-27 11:22:14 -0600 | [diff] [blame] | 4611 | VkSubmitInfo submit_info; |
Chia-I Wu | f9be13c | 2015-10-26 20:37:06 +0800 | [diff] [blame] | 4612 | submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO; |
| 4613 | submit_info.pNext = NULL; |
Chia-I Wu | d50a7d7 | 2015-10-26 20:48:51 +0800 | [diff] [blame] | 4614 | submit_info.waitSemaphoreCount = 0; |
Courtney Goeltzenleuchter | 806c700 | 2015-10-27 11:22:14 -0600 | [diff] [blame] | 4615 | submit_info.pWaitSemaphores = NULL; |
Jon Ashburn | 7f9716c | 2015-12-30 16:42:50 -0700 | [diff] [blame] | 4616 | submit_info.pWaitDstStageMask = NULL; |
Chia-I Wu | d50a7d7 | 2015-10-26 20:48:51 +0800 | [diff] [blame] | 4617 | submit_info.commandBufferCount = 1; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 4618 | submit_info.pCommandBuffers = &m_commandBuffer->handle(); |
Chia-I Wu | d50a7d7 | 2015-10-26 20:48:51 +0800 | [diff] [blame] | 4619 | submit_info.signalSemaphoreCount = 0; |
Courtney Goeltzenleuchter | 806c700 | 2015-10-27 11:22:14 -0600 | [diff] [blame] | 4620 | submit_info.pSignalSemaphores = NULL; |
| 4621 | |
Chris Forbes | 40028e2 | 2016-06-13 09:59:34 +1200 | [diff] [blame] | 4622 | err = vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 4623 | ASSERT_VK_SUCCESS(err); |
Tobin Ehlis | 59278bf | 2015-08-18 07:10:58 -0600 | [diff] [blame] | 4624 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 4625 | // Cause validation error by re-submitting cmd buffer that should only be |
| 4626 | // submitted once |
Chris Forbes | 40028e2 | 2016-06-13 09:59:34 +1200 | [diff] [blame] | 4627 | err = vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE); |
Tobin Ehlis | 59278bf | 2015-08-18 07:10:58 -0600 | [diff] [blame] | 4628 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 4629 | m_errorMonitor->VerifyFound(); |
Tobin Ehlis | 59278bf | 2015-08-18 07:10:58 -0600 | [diff] [blame] | 4630 | } |
| 4631 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 4632 | TEST_F(VkLayerTest, AllocDescriptorFromEmptyPool) { |
Tobin Ehlis | f93f1e3 | 2015-10-20 16:16:04 -0600 | [diff] [blame] | 4633 | // Initiate Draw w/o a PSO bound |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 4634 | VkResult err; |
Tobin Ehlis | f93f1e3 | 2015-10-20 16:16:04 -0600 | [diff] [blame] | 4635 | |
Courtney Goeltzenleuchter | 7415d5a | 2015-12-09 15:48:16 -0700 | [diff] [blame] | 4636 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 4637 | "Unable to allocate 1 descriptors of " |
| 4638 | "type " |
| 4639 | "VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER "); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 4640 | |
Tobin Ehlis | f93f1e3 | 2015-10-20 16:16:04 -0600 | [diff] [blame] | 4641 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 4642 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
Tobin Ehlis | f93f1e3 | 2015-10-20 16:16:04 -0600 | [diff] [blame] | 4643 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 4644 | // Create Pool w/ 1 Sampler descriptor, but try to alloc Uniform Buffer |
| 4645 | // descriptor from it |
Chia-I Wu | 1b99bb2 | 2015-10-27 19:25:11 +0800 | [diff] [blame] | 4646 | VkDescriptorPoolSize ds_type_count = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 4647 | ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLER; |
| 4648 | ds_type_count.descriptorCount = 1; |
Tobin Ehlis | f93f1e3 | 2015-10-20 16:16:04 -0600 | [diff] [blame] | 4649 | |
| 4650 | VkDescriptorPoolCreateInfo ds_pool_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 4651 | ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO; |
| 4652 | ds_pool_ci.pNext = NULL; |
| 4653 | ds_pool_ci.flags = 0; |
| 4654 | ds_pool_ci.maxSets = 1; |
| 4655 | ds_pool_ci.poolSizeCount = 1; |
| 4656 | ds_pool_ci.pPoolSizes = &ds_type_count; |
Tobin Ehlis | f93f1e3 | 2015-10-20 16:16:04 -0600 | [diff] [blame] | 4657 | |
| 4658 | VkDescriptorPool ds_pool; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 4659 | err = |
| 4660 | vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool); |
Tobin Ehlis | f93f1e3 | 2015-10-20 16:16:04 -0600 | [diff] [blame] | 4661 | ASSERT_VK_SUCCESS(err); |
| 4662 | |
| 4663 | VkDescriptorSetLayoutBinding dsl_binding = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 4664 | dsl_binding.binding = 0; |
| 4665 | dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 4666 | dsl_binding.descriptorCount = 1; |
| 4667 | dsl_binding.stageFlags = VK_SHADER_STAGE_ALL; |
| 4668 | dsl_binding.pImmutableSamplers = NULL; |
Tobin Ehlis | f93f1e3 | 2015-10-20 16:16:04 -0600 | [diff] [blame] | 4669 | |
| 4670 | VkDescriptorSetLayoutCreateInfo ds_layout_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 4671 | ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO; |
| 4672 | ds_layout_ci.pNext = NULL; |
| 4673 | ds_layout_ci.bindingCount = 1; |
| 4674 | ds_layout_ci.pBindings = &dsl_binding; |
Tobin Ehlis | f93f1e3 | 2015-10-20 16:16:04 -0600 | [diff] [blame] | 4675 | |
| 4676 | VkDescriptorSetLayout ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 4677 | err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, |
| 4678 | &ds_layout); |
Tobin Ehlis | f93f1e3 | 2015-10-20 16:16:04 -0600 | [diff] [blame] | 4679 | ASSERT_VK_SUCCESS(err); |
| 4680 | |
| 4681 | VkDescriptorSet descriptorSet; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 4682 | VkDescriptorSetAllocateInfo alloc_info = {}; |
Chia-I Wu | 00ce540 | 2015-11-10 16:21:09 +0800 | [diff] [blame] | 4683 | alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO; |
Jon Ashburn | f19916e | 2016-01-11 13:12:43 -0700 | [diff] [blame] | 4684 | alloc_info.descriptorSetCount = 1; |
Courtney Goeltzenleuchter | bee18a9 | 2015-10-23 14:21:05 -0600 | [diff] [blame] | 4685 | alloc_info.descriptorPool = ds_pool; |
| 4686 | alloc_info.pSetLayouts = &ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 4687 | err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, |
| 4688 | &descriptorSet); |
Tobin Ehlis | f93f1e3 | 2015-10-20 16:16:04 -0600 | [diff] [blame] | 4689 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 4690 | m_errorMonitor->VerifyFound(); |
Tobin Ehlis | f93f1e3 | 2015-10-20 16:16:04 -0600 | [diff] [blame] | 4691 | |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 4692 | vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL); |
| 4693 | vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL); |
Tobin Ehlis | f93f1e3 | 2015-10-20 16:16:04 -0600 | [diff] [blame] | 4694 | } |
| 4695 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 4696 | TEST_F(VkLayerTest, FreeDescriptorFromOneShotPool) { |
| 4697 | VkResult err; |
Tobin Ehlis | e735c69 | 2015-10-08 13:13:50 -0600 | [diff] [blame] | 4698 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 4699 | m_errorMonitor->SetDesiredFailureMsg( |
| 4700 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 4701 | "It is invalid to call vkFreeDescriptorSets() with a pool created " |
| 4702 | "without setting VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT."); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 4703 | |
Tobin Ehlis | e735c69 | 2015-10-08 13:13:50 -0600 | [diff] [blame] | 4704 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 4705 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
Tobin Ehlis | e735c69 | 2015-10-08 13:13:50 -0600 | [diff] [blame] | 4706 | |
Chia-I Wu | 1b99bb2 | 2015-10-27 19:25:11 +0800 | [diff] [blame] | 4707 | VkDescriptorPoolSize ds_type_count = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 4708 | ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 4709 | ds_type_count.descriptorCount = 1; |
Tobin Ehlis | e735c69 | 2015-10-08 13:13:50 -0600 | [diff] [blame] | 4710 | |
| 4711 | VkDescriptorPoolCreateInfo ds_pool_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 4712 | ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO; |
| 4713 | ds_pool_ci.pNext = NULL; |
| 4714 | ds_pool_ci.maxSets = 1; |
| 4715 | ds_pool_ci.poolSizeCount = 1; |
| 4716 | ds_pool_ci.flags = 0; |
| 4717 | // Not specifying VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT means |
| 4718 | // app can only call vkResetDescriptorPool on this pool.; |
| 4719 | ds_pool_ci.pPoolSizes = &ds_type_count; |
Tobin Ehlis | e735c69 | 2015-10-08 13:13:50 -0600 | [diff] [blame] | 4720 | |
| 4721 | VkDescriptorPool ds_pool; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 4722 | err = |
| 4723 | vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool); |
Tobin Ehlis | e735c69 | 2015-10-08 13:13:50 -0600 | [diff] [blame] | 4724 | ASSERT_VK_SUCCESS(err); |
| 4725 | |
| 4726 | VkDescriptorSetLayoutBinding dsl_binding = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 4727 | dsl_binding.binding = 0; |
| 4728 | dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 4729 | dsl_binding.descriptorCount = 1; |
| 4730 | dsl_binding.stageFlags = VK_SHADER_STAGE_ALL; |
| 4731 | dsl_binding.pImmutableSamplers = NULL; |
Tobin Ehlis | e735c69 | 2015-10-08 13:13:50 -0600 | [diff] [blame] | 4732 | |
| 4733 | VkDescriptorSetLayoutCreateInfo ds_layout_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 4734 | ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO; |
| 4735 | ds_layout_ci.pNext = NULL; |
| 4736 | ds_layout_ci.bindingCount = 1; |
| 4737 | ds_layout_ci.pBindings = &dsl_binding; |
Tobin Ehlis | e735c69 | 2015-10-08 13:13:50 -0600 | [diff] [blame] | 4738 | |
| 4739 | VkDescriptorSetLayout ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 4740 | err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, |
| 4741 | &ds_layout); |
Tobin Ehlis | e735c69 | 2015-10-08 13:13:50 -0600 | [diff] [blame] | 4742 | ASSERT_VK_SUCCESS(err); |
| 4743 | |
| 4744 | VkDescriptorSet descriptorSet; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 4745 | VkDescriptorSetAllocateInfo alloc_info = {}; |
Chia-I Wu | 00ce540 | 2015-11-10 16:21:09 +0800 | [diff] [blame] | 4746 | alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO; |
Jon Ashburn | f19916e | 2016-01-11 13:12:43 -0700 | [diff] [blame] | 4747 | alloc_info.descriptorSetCount = 1; |
Courtney Goeltzenleuchter | bee18a9 | 2015-10-23 14:21:05 -0600 | [diff] [blame] | 4748 | alloc_info.descriptorPool = ds_pool; |
| 4749 | alloc_info.pSetLayouts = &ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 4750 | err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, |
| 4751 | &descriptorSet); |
Tobin Ehlis | e735c69 | 2015-10-08 13:13:50 -0600 | [diff] [blame] | 4752 | ASSERT_VK_SUCCESS(err); |
| 4753 | |
| 4754 | err = vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptorSet); |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 4755 | m_errorMonitor->VerifyFound(); |
Tobin Ehlis | e735c69 | 2015-10-08 13:13:50 -0600 | [diff] [blame] | 4756 | |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 4757 | vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL); |
| 4758 | vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL); |
Tobin Ehlis | e735c69 | 2015-10-08 13:13:50 -0600 | [diff] [blame] | 4759 | } |
| 4760 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 4761 | TEST_F(VkLayerTest, InvalidDescriptorPool) { |
Karl Schultz | bdb7595 | 2016-04-19 11:36:49 -0600 | [diff] [blame] | 4762 | // Attempt to clear Descriptor Pool with bad object. |
| 4763 | // ObjectTracker should catch this. |
| 4764 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 4765 | "Invalid VkDescriptorPool Object 0xbaad6001"); |
Mark Lobodzinski | 02bf89d | 2016-05-10 14:45:13 -0600 | [diff] [blame] | 4766 | uint64_t fake_pool_handle = 0xbaad6001; |
| 4767 | VkDescriptorPool bad_pool = reinterpret_cast<VkDescriptorPool &>(fake_pool_handle); |
| 4768 | vkResetDescriptorPool(device(), bad_pool, 0); |
Karl Schultz | bdb7595 | 2016-04-19 11:36:49 -0600 | [diff] [blame] | 4769 | m_errorMonitor->VerifyFound(); |
Tobin Ehlis | 49eb23d | 2015-05-22 12:38:55 -0600 | [diff] [blame] | 4770 | } |
| 4771 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 4772 | TEST_F(VkLayerTest, InvalidDescriptorSet) { |
Karl Schultz | bdb7595 | 2016-04-19 11:36:49 -0600 | [diff] [blame] | 4773 | // Attempt to bind an invalid Descriptor Set to a valid Command Buffer |
| 4774 | // ObjectTracker should catch this. |
Tobin Ehlis | 49eb23d | 2015-05-22 12:38:55 -0600 | [diff] [blame] | 4775 | // Create a valid cmd buffer |
Karl Schultz | bdb7595 | 2016-04-19 11:36:49 -0600 | [diff] [blame] | 4776 | // call vkCmdBindDescriptorSets w/ false Descriptor Set |
Mark Lobodzinski | 02bf89d | 2016-05-10 14:45:13 -0600 | [diff] [blame] | 4777 | |
| 4778 | uint64_t fake_set_handle = 0xbaad6001; |
| 4779 | VkDescriptorSet bad_set = reinterpret_cast<VkDescriptorSet &>(fake_set_handle); |
Karl Schultz | bdb7595 | 2016-04-19 11:36:49 -0600 | [diff] [blame] | 4780 | VkResult err; |
| 4781 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 4782 | "Invalid VkDescriptorSet Object 0xbaad6001"); |
| 4783 | |
| 4784 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 4785 | |
| 4786 | VkDescriptorSetLayoutBinding layout_bindings[1] = {}; |
| 4787 | layout_bindings[0].binding = 0; |
| 4788 | layout_bindings[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 4789 | layout_bindings[0].descriptorCount = 1; |
| 4790 | layout_bindings[0].stageFlags = VK_SHADER_STAGE_VERTEX_BIT; |
| 4791 | layout_bindings[0].pImmutableSamplers = NULL; |
| 4792 | |
| 4793 | VkDescriptorSetLayout descriptor_set_layout; |
| 4794 | VkDescriptorSetLayoutCreateInfo dslci = {}; |
| 4795 | dslci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO; |
| 4796 | dslci.pNext = NULL; |
| 4797 | dslci.bindingCount = 1; |
| 4798 | dslci.pBindings = layout_bindings; |
| 4799 | err = vkCreateDescriptorSetLayout(device(), &dslci, NULL, &descriptor_set_layout); |
Karl Schultz | 5cb2111 | 2016-04-21 17:17:40 -0600 | [diff] [blame] | 4800 | ASSERT_VK_SUCCESS(err); |
Karl Schultz | bdb7595 | 2016-04-19 11:36:49 -0600 | [diff] [blame] | 4801 | |
| 4802 | VkPipelineLayout pipeline_layout; |
| 4803 | VkPipelineLayoutCreateInfo plci = {}; |
| 4804 | plci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO; |
| 4805 | plci.pNext = NULL; |
| 4806 | plci.setLayoutCount = 1; |
| 4807 | plci.pSetLayouts = &descriptor_set_layout; |
| 4808 | err = vkCreatePipelineLayout(device(), &plci, NULL, &pipeline_layout); |
Karl Schultz | 5cb2111 | 2016-04-21 17:17:40 -0600 | [diff] [blame] | 4809 | ASSERT_VK_SUCCESS(err); |
Karl Schultz | bdb7595 | 2016-04-19 11:36:49 -0600 | [diff] [blame] | 4810 | |
| 4811 | BeginCommandBuffer(); |
| 4812 | vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, |
Mark Lobodzinski | 02bf89d | 2016-05-10 14:45:13 -0600 | [diff] [blame] | 4813 | pipeline_layout, 0, 1, &bad_set, 0, NULL); |
Karl Schultz | bdb7595 | 2016-04-19 11:36:49 -0600 | [diff] [blame] | 4814 | m_errorMonitor->VerifyFound(); |
| 4815 | EndCommandBuffer(); |
| 4816 | vkDestroyPipelineLayout(device(), pipeline_layout, NULL); |
| 4817 | vkDestroyDescriptorSetLayout(device(), descriptor_set_layout, NULL); |
Tobin Ehlis | 49eb23d | 2015-05-22 12:38:55 -0600 | [diff] [blame] | 4818 | } |
| 4819 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 4820 | TEST_F(VkLayerTest, InvalidDescriptorSetLayout) { |
Karl Schultz | bdb7595 | 2016-04-19 11:36:49 -0600 | [diff] [blame] | 4821 | // Attempt to create a Pipeline Layout with an invalid Descriptor Set Layout. |
| 4822 | // ObjectTracker should catch this. |
Mark Lobodzinski | 02bf89d | 2016-05-10 14:45:13 -0600 | [diff] [blame] | 4823 | uint64_t fake_layout_handle = 0xbaad6001; |
| 4824 | VkDescriptorSetLayout bad_layout = reinterpret_cast<VkDescriptorSetLayout &>(fake_layout_handle); |
Karl Schultz | bdb7595 | 2016-04-19 11:36:49 -0600 | [diff] [blame] | 4825 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 4826 | "Invalid VkDescriptorSetLayout Object 0xbaad6001"); |
| 4827 | |
| 4828 | VkPipelineLayout pipeline_layout; |
| 4829 | VkPipelineLayoutCreateInfo plci = {}; |
| 4830 | plci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO; |
| 4831 | plci.pNext = NULL; |
| 4832 | plci.setLayoutCount = 1; |
| 4833 | plci.pSetLayouts = &bad_layout; |
| 4834 | vkCreatePipelineLayout(device(), &plci, NULL, &pipeline_layout); |
| 4835 | |
| 4836 | m_errorMonitor->VerifyFound(); |
Tobin Ehlis | 49eb23d | 2015-05-22 12:38:55 -0600 | [diff] [blame] | 4837 | } |
| 4838 | |
Mark Mueller | d491441 | 2016-06-13 17:52:06 -0600 | [diff] [blame] | 4839 | TEST_F(VkLayerTest, WriteDescriptorSetIntegrityCheck) { |
| 4840 | TEST_DESCRIPTION("This test verifies some requirements of chapter 13.2.3 of the Vulkan Spec " |
| 4841 | "1) A uniform buffer update must have a valid buffer index." |
| 4842 | "2) When using an array of descriptors in a single WriteDescriptor," |
| 4843 | " the descriptor types and stageflags must all be the same." |
| 4844 | "3) Immutable Sampler state must match across descriptors"); |
| 4845 | |
| 4846 | const char *invalid_BufferInfo_ErrorMessage = |
| 4847 | "vkUpdateDescriptorSets: if pDescriptorWrites[0].descriptorType is VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, " |
| 4848 | "VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC or " |
| 4849 | "VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC, pDescriptorWrites[0].pBufferInfo must not be NULL"; |
| 4850 | const char *stateFlag_ErrorMessage = |
Mark Mueller | 5c838ce | 2016-06-16 09:54:29 -0600 | [diff] [blame] | 4851 | "Attempting write update to descriptor set "; |
Mark Mueller | d491441 | 2016-06-13 17:52:06 -0600 | [diff] [blame] | 4852 | const char *immutable_ErrorMessage = |
Mark Mueller | 5c838ce | 2016-06-16 09:54:29 -0600 | [diff] [blame] | 4853 | "Attempting write update to descriptor set "; |
Mark Mueller | d491441 | 2016-06-13 17:52:06 -0600 | [diff] [blame] | 4854 | |
Mark Mueller | d491441 | 2016-06-13 17:52:06 -0600 | [diff] [blame] | 4855 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_BufferInfo_ErrorMessage); |
| 4856 | |
| 4857 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 4858 | VkDescriptorPoolSize ds_type_count[4] = {}; |
| 4859 | ds_type_count[0].type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 4860 | ds_type_count[0].descriptorCount = 1; |
| 4861 | ds_type_count[1].type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER; |
| 4862 | ds_type_count[1].descriptorCount = 1; |
| 4863 | ds_type_count[2].type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER; |
| 4864 | ds_type_count[2].descriptorCount = 1; |
| 4865 | ds_type_count[3].type = VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT; |
| 4866 | ds_type_count[3].descriptorCount = 1; |
| 4867 | |
| 4868 | VkDescriptorPoolCreateInfo ds_pool_ci = {}; |
| 4869 | ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO; |
| 4870 | ds_pool_ci.maxSets = 1; |
| 4871 | ds_pool_ci.poolSizeCount = sizeof(ds_type_count) / sizeof(VkDescriptorPoolSize); |
| 4872 | ds_pool_ci.pPoolSizes = ds_type_count; |
| 4873 | |
| 4874 | VkDescriptorPool ds_pool; |
| 4875 | VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool); |
| 4876 | ASSERT_VK_SUCCESS(err); |
| 4877 | |
Mark Mueller | b989672 | 2016-06-16 09:54:29 -0600 | [diff] [blame] | 4878 | VkDescriptorSetLayoutBinding layout_binding[3] = {}; |
Mark Mueller | d491441 | 2016-06-13 17:52:06 -0600 | [diff] [blame] | 4879 | layout_binding[0].binding = 0; |
| 4880 | layout_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 4881 | layout_binding[0].descriptorCount = 1; |
| 4882 | layout_binding[0].stageFlags = VK_SHADER_STAGE_ALL; |
| 4883 | layout_binding[0].pImmutableSamplers = NULL; |
| 4884 | |
| 4885 | layout_binding[1].binding = 1; |
| 4886 | layout_binding[1].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER; |
| 4887 | layout_binding[1].descriptorCount = 1; |
| 4888 | layout_binding[1].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT; |
| 4889 | layout_binding[1].pImmutableSamplers = NULL; |
| 4890 | |
| 4891 | VkSamplerCreateInfo sampler_ci = {}; |
| 4892 | sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO; |
| 4893 | sampler_ci.pNext = NULL; |
| 4894 | sampler_ci.magFilter = VK_FILTER_NEAREST; |
| 4895 | sampler_ci.minFilter = VK_FILTER_NEAREST; |
| 4896 | sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST; |
| 4897 | sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE; |
| 4898 | sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE; |
| 4899 | sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE; |
| 4900 | sampler_ci.mipLodBias = 1.0; |
| 4901 | sampler_ci.anisotropyEnable = VK_FALSE; |
| 4902 | sampler_ci.maxAnisotropy = 1; |
| 4903 | sampler_ci.compareEnable = VK_FALSE; |
| 4904 | sampler_ci.compareOp = VK_COMPARE_OP_NEVER; |
| 4905 | sampler_ci.minLod = 1.0; |
| 4906 | sampler_ci.maxLod = 1.0; |
| 4907 | sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE; |
| 4908 | sampler_ci.unnormalizedCoordinates = VK_FALSE; |
| 4909 | VkSampler sampler; |
| 4910 | |
| 4911 | err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler); |
| 4912 | ASSERT_VK_SUCCESS(err); |
| 4913 | |
| 4914 | layout_binding[2].binding = 2; |
| 4915 | layout_binding[2].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER; |
| 4916 | layout_binding[2].descriptorCount = 1; |
| 4917 | layout_binding[2].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT; |
| 4918 | layout_binding[2].pImmutableSamplers = static_cast<VkSampler *>(&sampler); |
| 4919 | |
Mark Mueller | d491441 | 2016-06-13 17:52:06 -0600 | [diff] [blame] | 4920 | VkDescriptorSetLayoutCreateInfo ds_layout_ci = {}; |
| 4921 | ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO; |
| 4922 | ds_layout_ci.bindingCount = sizeof(layout_binding) / sizeof(VkDescriptorSetLayoutBinding); |
| 4923 | ds_layout_ci.pBindings = layout_binding; |
| 4924 | VkDescriptorSetLayout ds_layout; |
| 4925 | err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout); |
| 4926 | ASSERT_VK_SUCCESS(err); |
| 4927 | |
| 4928 | VkDescriptorSetAllocateInfo alloc_info = {}; |
| 4929 | alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO; |
| 4930 | alloc_info.descriptorSetCount = 1; |
| 4931 | alloc_info.descriptorPool = ds_pool; |
| 4932 | alloc_info.pSetLayouts = &ds_layout; |
| 4933 | VkDescriptorSet descriptorSet; |
| 4934 | err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet); |
| 4935 | ASSERT_VK_SUCCESS(err); |
| 4936 | |
| 4937 | VkPipelineLayoutCreateInfo pipeline_layout_ci = {}; |
| 4938 | pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO; |
| 4939 | pipeline_layout_ci.pNext = NULL; |
| 4940 | pipeline_layout_ci.setLayoutCount = 1; |
| 4941 | pipeline_layout_ci.pSetLayouts = &ds_layout; |
| 4942 | |
| 4943 | VkPipelineLayout pipeline_layout; |
| 4944 | err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout); |
| 4945 | ASSERT_VK_SUCCESS(err); |
| 4946 | |
Mark Mueller | 5c838ce | 2016-06-16 09:54:29 -0600 | [diff] [blame] | 4947 | VkWriteDescriptorSet descriptor_write = {}; |
Mark Mueller | d491441 | 2016-06-13 17:52:06 -0600 | [diff] [blame] | 4948 | descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET; |
| 4949 | descriptor_write.dstSet = descriptorSet; |
| 4950 | descriptor_write.dstBinding = 0; |
| 4951 | descriptor_write.descriptorCount = 1; |
| 4952 | descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 4953 | |
Mark Mueller | 5c838ce | 2016-06-16 09:54:29 -0600 | [diff] [blame] | 4954 | // 1) The uniform buffer is intentionally invalid here |
Mark Mueller | d491441 | 2016-06-13 17:52:06 -0600 | [diff] [blame] | 4955 | vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL); |
| 4956 | m_errorMonitor->VerifyFound(); |
| 4957 | |
| 4958 | // Create a buffer to update the descriptor with |
| 4959 | uint32_t qfi = 0; |
| 4960 | VkBufferCreateInfo buffCI = {}; |
| 4961 | buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO; |
| 4962 | buffCI.size = 1024; |
| 4963 | buffCI.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT; |
| 4964 | buffCI.queueFamilyIndexCount = 1; |
| 4965 | buffCI.pQueueFamilyIndices = &qfi; |
| 4966 | |
| 4967 | VkBuffer dyub; |
| 4968 | err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &dyub); |
| 4969 | ASSERT_VK_SUCCESS(err); |
| 4970 | VkDescriptorBufferInfo buffInfo = {}; |
| 4971 | buffInfo.buffer = dyub; |
| 4972 | buffInfo.offset = 0; |
| 4973 | buffInfo.range = 1024; |
| 4974 | |
| 4975 | descriptor_write.pBufferInfo = &buffInfo; |
| 4976 | descriptor_write.descriptorCount = 2; |
| 4977 | |
Mark Mueller | 5c838ce | 2016-06-16 09:54:29 -0600 | [diff] [blame] | 4978 | // 2) The stateFlags don't match between the first and second descriptor |
Mark Mueller | d491441 | 2016-06-13 17:52:06 -0600 | [diff] [blame] | 4979 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, stateFlag_ErrorMessage); |
| 4980 | vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL); |
| 4981 | m_errorMonitor->VerifyFound(); |
| 4982 | |
Mark Mueller | 5c838ce | 2016-06-16 09:54:29 -0600 | [diff] [blame] | 4983 | // 3) The second descriptor has a null_ptr pImmutableSamplers and |
| 4984 | // the third descriptor contains an immutable sampler |
Mark Mueller | d491441 | 2016-06-13 17:52:06 -0600 | [diff] [blame] | 4985 | descriptor_write.dstBinding = 1; |
| 4986 | descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER; |
Mark Mueller | 5c838ce | 2016-06-16 09:54:29 -0600 | [diff] [blame] | 4987 | |
| 4988 | |
| 4989 | // Make pImageInfo index non-null to avoid complaints of it missing |
| 4990 | VkDescriptorImageInfo imageInfo = {}; |
| 4991 | imageInfo.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL; |
| 4992 | descriptor_write.pImageInfo = &imageInfo; |
Mark Mueller | d491441 | 2016-06-13 17:52:06 -0600 | [diff] [blame] | 4993 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, immutable_ErrorMessage); |
| 4994 | vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL); |
| 4995 | m_errorMonitor->VerifyFound(); |
| 4996 | |
Mark Mueller | d491441 | 2016-06-13 17:52:06 -0600 | [diff] [blame] | 4997 | vkDestroyBuffer(m_device->device(), dyub, NULL); |
| 4998 | vkDestroySampler(m_device->device(), sampler, NULL); |
| 4999 | vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL); |
| 5000 | vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL); |
| 5001 | vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL); |
| 5002 | } |
| 5003 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5004 | TEST_F(VkLayerTest, InvalidPipeline) { |
Karl Schultz | bdb7595 | 2016-04-19 11:36:49 -0600 | [diff] [blame] | 5005 | // Attempt to bind an invalid Pipeline to a valid Command Buffer |
| 5006 | // ObjectTracker should catch this. |
Tobin Ehlis | 49eb23d | 2015-05-22 12:38:55 -0600 | [diff] [blame] | 5007 | // Create a valid cmd buffer |
| 5008 | // call vkCmdBindPipeline w/ false Pipeline |
Mark Lobodzinski | 02bf89d | 2016-05-10 14:45:13 -0600 | [diff] [blame] | 5009 | uint64_t fake_pipeline_handle = 0xbaad6001; |
| 5010 | VkPipeline bad_pipeline = reinterpret_cast<VkPipeline &>(fake_pipeline_handle); |
Karl Schultz | bdb7595 | 2016-04-19 11:36:49 -0600 | [diff] [blame] | 5011 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 5012 | "Invalid VkPipeline Object 0xbaad6001"); |
| 5013 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 5014 | BeginCommandBuffer(); |
| 5015 | vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), |
| 5016 | VK_PIPELINE_BIND_POINT_GRAPHICS, bad_pipeline); |
| 5017 | m_errorMonitor->VerifyFound(); |
Tobin Ehlis | b8b6b27 | 2016-05-02 13:26:06 -0600 | [diff] [blame] | 5018 | // Now issue a draw call with no pipeline bound |
| 5019 | m_errorMonitor->SetDesiredFailureMsg( |
| 5020 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 5021 | "At Draw/Dispatch time no valid VkPipeline is bound!"); |
Tony Barbour | df4c004 | 2016-06-01 15:55:43 -0600 | [diff] [blame] | 5022 | |
Tobin Ehlis | b8b6b27 | 2016-05-02 13:26:06 -0600 | [diff] [blame] | 5023 | BeginCommandBuffer(); |
| 5024 | Draw(1, 0, 0, 0); |
| 5025 | m_errorMonitor->VerifyFound(); |
| 5026 | // Finally same check once more but with Dispatch/Compute |
| 5027 | m_errorMonitor->SetDesiredFailureMsg( |
| 5028 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 5029 | "At Draw/Dispatch time no valid VkPipeline is bound!"); |
Tobin Ehlis | b8b6b27 | 2016-05-02 13:26:06 -0600 | [diff] [blame] | 5030 | BeginCommandBuffer(); |
| 5031 | vkCmdDispatch(m_commandBuffer->GetBufferHandle(), 0, 0, 0); |
| 5032 | m_errorMonitor->VerifyFound(); |
Tobin Ehlis | 49eb23d | 2015-05-22 12:38:55 -0600 | [diff] [blame] | 5033 | } |
| 5034 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5035 | TEST_F(VkLayerTest, DescriptorSetNotUpdated) { |
| 5036 | // Create and update CommandBuffer then call QueueSubmit w/o calling End on |
| 5037 | // CommandBuffer |
| 5038 | VkResult err; |
Tobin Ehlis | 7d1a711 | 2015-05-27 14:32:28 -0600 | [diff] [blame] | 5039 | |
Mark Lobodzinski | 510e20d | 2016-02-11 09:26:16 -0700 | [diff] [blame] | 5040 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5041 | " bound but it was never updated. "); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 5042 | |
Tobin Ehlis | 7d1a711 | 2015-05-27 14:32:28 -0600 | [diff] [blame] | 5043 | ASSERT_NO_FATAL_FAILURE(InitState()); |
Mike Stroyan | 713b2d7 | 2015-08-04 10:49:29 -0600 | [diff] [blame] | 5044 | ASSERT_NO_FATAL_FAILURE(InitViewport()); |
| 5045 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
Chia-I Wu | 1b99bb2 | 2015-10-27 19:25:11 +0800 | [diff] [blame] | 5046 | VkDescriptorPoolSize ds_type_count = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5047 | ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 5048 | ds_type_count.descriptorCount = 1; |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 5049 | |
| 5050 | VkDescriptorPoolCreateInfo ds_pool_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5051 | ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO; |
| 5052 | ds_pool_ci.pNext = NULL; |
| 5053 | ds_pool_ci.maxSets = 1; |
| 5054 | ds_pool_ci.poolSizeCount = 1; |
| 5055 | ds_pool_ci.pPoolSizes = &ds_type_count; |
Mike Stroyan | 713b2d7 | 2015-08-04 10:49:29 -0600 | [diff] [blame] | 5056 | |
Tobin Ehlis | 7d1a711 | 2015-05-27 14:32:28 -0600 | [diff] [blame] | 5057 | VkDescriptorPool ds_pool; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5058 | err = |
| 5059 | vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool); |
Tobin Ehlis | 7d1a711 | 2015-05-27 14:32:28 -0600 | [diff] [blame] | 5060 | ASSERT_VK_SUCCESS(err); |
Tobin Ehlis | 7d1a711 | 2015-05-27 14:32:28 -0600 | [diff] [blame] | 5061 | |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 5062 | VkDescriptorSetLayoutBinding dsl_binding = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5063 | dsl_binding.binding = 0; |
| 5064 | dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 5065 | dsl_binding.descriptorCount = 1; |
| 5066 | dsl_binding.stageFlags = VK_SHADER_STAGE_ALL; |
| 5067 | dsl_binding.pImmutableSamplers = NULL; |
Tobin Ehlis | 7d1a711 | 2015-05-27 14:32:28 -0600 | [diff] [blame] | 5068 | |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 5069 | VkDescriptorSetLayoutCreateInfo ds_layout_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5070 | ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO; |
| 5071 | ds_layout_ci.pNext = NULL; |
| 5072 | ds_layout_ci.bindingCount = 1; |
| 5073 | ds_layout_ci.pBindings = &dsl_binding; |
Tobin Ehlis | 7d1a711 | 2015-05-27 14:32:28 -0600 | [diff] [blame] | 5074 | VkDescriptorSetLayout ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5075 | err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, |
| 5076 | &ds_layout); |
Tobin Ehlis | 7d1a711 | 2015-05-27 14:32:28 -0600 | [diff] [blame] | 5077 | ASSERT_VK_SUCCESS(err); |
| 5078 | |
| 5079 | VkDescriptorSet descriptorSet; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 5080 | VkDescriptorSetAllocateInfo alloc_info = {}; |
Chia-I Wu | 00ce540 | 2015-11-10 16:21:09 +0800 | [diff] [blame] | 5081 | alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO; |
Jon Ashburn | f19916e | 2016-01-11 13:12:43 -0700 | [diff] [blame] | 5082 | alloc_info.descriptorSetCount = 1; |
Courtney Goeltzenleuchter | bee18a9 | 2015-10-23 14:21:05 -0600 | [diff] [blame] | 5083 | alloc_info.descriptorPool = ds_pool; |
| 5084 | alloc_info.pSetLayouts = &ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5085 | err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, |
| 5086 | &descriptorSet); |
Tobin Ehlis | 7d1a711 | 2015-05-27 14:32:28 -0600 | [diff] [blame] | 5087 | ASSERT_VK_SUCCESS(err); |
| 5088 | |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 5089 | VkPipelineLayoutCreateInfo pipeline_layout_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5090 | pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO; |
| 5091 | pipeline_layout_ci.pNext = NULL; |
| 5092 | pipeline_layout_ci.setLayoutCount = 1; |
| 5093 | pipeline_layout_ci.pSetLayouts = &ds_layout; |
Tobin Ehlis | 7d1a711 | 2015-05-27 14:32:28 -0600 | [diff] [blame] | 5094 | |
| 5095 | VkPipelineLayout pipeline_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5096 | err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, |
| 5097 | &pipeline_layout); |
Tobin Ehlis | 7d1a711 | 2015-05-27 14:32:28 -0600 | [diff] [blame] | 5098 | ASSERT_VK_SUCCESS(err); |
| 5099 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5100 | VkShaderObj vs(m_device, bindStateVertShaderText, |
| 5101 | VK_SHADER_STAGE_VERTEX_BIT, this); |
Karl Schultz | bdb7595 | 2016-04-19 11:36:49 -0600 | [diff] [blame] | 5102 | // 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] | 5103 | // on more devices |
| 5104 | VkShaderObj fs(m_device, bindStateFragShaderText, |
| 5105 | VK_SHADER_STAGE_FRAGMENT_BIT, this); |
Tobin Ehlis | 7d1a711 | 2015-05-27 14:32:28 -0600 | [diff] [blame] | 5106 | |
Tony Barbour | c95e4ac | 2015-08-04 17:05:26 -0600 | [diff] [blame] | 5107 | VkPipelineObj pipe(m_device); |
| 5108 | pipe.AddShader(&vs); |
Tony Barbour | 1c94d37 | 2015-08-06 11:21:08 -0600 | [diff] [blame] | 5109 | pipe.AddShader(&fs); |
Mark Young | c89c631 | 2016-03-31 16:03:20 -0600 | [diff] [blame] | 5110 | pipe.AddColorAttachment(); |
Tony Barbour | c95e4ac | 2015-08-04 17:05:26 -0600 | [diff] [blame] | 5111 | pipe.CreateVKPipeline(pipeline_layout, renderPass()); |
Tony Barbour | fe3351b | 2015-07-28 10:17:20 -0600 | [diff] [blame] | 5112 | |
| 5113 | BeginCommandBuffer(); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5114 | vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), |
| 5115 | VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle()); |
| 5116 | vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), |
| 5117 | VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, |
| 5118 | 1, &descriptorSet, 0, NULL); |
Tobin Ehlis | 7d1a711 | 2015-05-27 14:32:28 -0600 | [diff] [blame] | 5119 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 5120 | m_errorMonitor->VerifyFound(); |
Mike Stroyan | d1c84a5 | 2015-08-18 14:40:24 -0600 | [diff] [blame] | 5121 | |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 5122 | vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL); |
| 5123 | vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL); |
| 5124 | vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL); |
Tobin Ehlis | af1f3a4 | 2015-06-25 15:46:59 -0600 | [diff] [blame] | 5125 | } |
| 5126 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5127 | TEST_F(VkLayerTest, InvalidBufferViewObject) { |
Tobin Ehlis | ba31cab | 2015-11-02 15:24:32 -0700 | [diff] [blame] | 5128 | // Create a single TEXEL_BUFFER descriptor and send it an invalid bufferView |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5129 | VkResult err; |
Tobin Ehlis | ba31cab | 2015-11-02 15:24:32 -0700 | [diff] [blame] | 5130 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5131 | m_errorMonitor->SetDesiredFailureMsg( |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 5132 | VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attempted write update to texel buffer " |
| 5133 | "descriptor with invalid buffer view"); |
Tobin Ehlis | ba31cab | 2015-11-02 15:24:32 -0700 | [diff] [blame] | 5134 | |
| 5135 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 5136 | VkDescriptorPoolSize ds_type_count = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5137 | ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER; |
| 5138 | ds_type_count.descriptorCount = 1; |
Tobin Ehlis | ba31cab | 2015-11-02 15:24:32 -0700 | [diff] [blame] | 5139 | |
| 5140 | VkDescriptorPoolCreateInfo ds_pool_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5141 | ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO; |
| 5142 | ds_pool_ci.pNext = NULL; |
| 5143 | ds_pool_ci.maxSets = 1; |
| 5144 | ds_pool_ci.poolSizeCount = 1; |
| 5145 | ds_pool_ci.pPoolSizes = &ds_type_count; |
Tobin Ehlis | ba31cab | 2015-11-02 15:24:32 -0700 | [diff] [blame] | 5146 | |
| 5147 | VkDescriptorPool ds_pool; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5148 | err = |
| 5149 | vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool); |
Tobin Ehlis | ba31cab | 2015-11-02 15:24:32 -0700 | [diff] [blame] | 5150 | ASSERT_VK_SUCCESS(err); |
| 5151 | |
| 5152 | VkDescriptorSetLayoutBinding dsl_binding = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5153 | dsl_binding.binding = 0; |
| 5154 | dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER; |
| 5155 | dsl_binding.descriptorCount = 1; |
| 5156 | dsl_binding.stageFlags = VK_SHADER_STAGE_ALL; |
| 5157 | dsl_binding.pImmutableSamplers = NULL; |
Tobin Ehlis | ba31cab | 2015-11-02 15:24:32 -0700 | [diff] [blame] | 5158 | |
| 5159 | VkDescriptorSetLayoutCreateInfo ds_layout_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5160 | ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO; |
| 5161 | ds_layout_ci.pNext = NULL; |
| 5162 | ds_layout_ci.bindingCount = 1; |
| 5163 | ds_layout_ci.pBindings = &dsl_binding; |
Tobin Ehlis | ba31cab | 2015-11-02 15:24:32 -0700 | [diff] [blame] | 5164 | VkDescriptorSetLayout ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5165 | err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, |
| 5166 | &ds_layout); |
Tobin Ehlis | ba31cab | 2015-11-02 15:24:32 -0700 | [diff] [blame] | 5167 | ASSERT_VK_SUCCESS(err); |
| 5168 | |
| 5169 | VkDescriptorSet descriptorSet; |
| 5170 | VkDescriptorSetAllocateInfo alloc_info = {}; |
Chia-I Wu | 00ce540 | 2015-11-10 16:21:09 +0800 | [diff] [blame] | 5171 | alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO; |
Jon Ashburn | f19916e | 2016-01-11 13:12:43 -0700 | [diff] [blame] | 5172 | alloc_info.descriptorSetCount = 1; |
Tobin Ehlis | ba31cab | 2015-11-02 15:24:32 -0700 | [diff] [blame] | 5173 | alloc_info.descriptorPool = ds_pool; |
| 5174 | alloc_info.pSetLayouts = &ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5175 | err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, |
| 5176 | &descriptorSet); |
Tobin Ehlis | ba31cab | 2015-11-02 15:24:32 -0700 | [diff] [blame] | 5177 | ASSERT_VK_SUCCESS(err); |
| 5178 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5179 | VkBufferView view = |
| 5180 | (VkBufferView)((size_t)0xbaadbeef); // invalid bufferView object |
Tobin Ehlis | ba31cab | 2015-11-02 15:24:32 -0700 | [diff] [blame] | 5181 | VkWriteDescriptorSet descriptor_write; |
| 5182 | memset(&descriptor_write, 0, sizeof(descriptor_write)); |
| 5183 | descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET; |
| 5184 | descriptor_write.dstSet = descriptorSet; |
| 5185 | descriptor_write.dstBinding = 0; |
| 5186 | descriptor_write.descriptorCount = 1; |
| 5187 | descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER; |
| 5188 | descriptor_write.pTexelBufferView = &view; |
| 5189 | |
| 5190 | vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL); |
| 5191 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 5192 | m_errorMonitor->VerifyFound(); |
Tobin Ehlis | ba31cab | 2015-11-02 15:24:32 -0700 | [diff] [blame] | 5193 | |
| 5194 | vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL); |
| 5195 | vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL); |
| 5196 | } |
| 5197 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5198 | TEST_F(VkLayerTest, InvalidDynamicOffsetCases) { |
| 5199 | // Create a descriptorSet w/ dynamic descriptor and then hit 3 offset error |
| 5200 | // cases: |
Tobin Ehlis | f658505 | 2015-12-17 11:48:42 -0700 | [diff] [blame] | 5201 | // 1. No dynamicOffset supplied |
| 5202 | // 2. Too many dynamicOffsets supplied |
| 5203 | // 3. Dynamic offset oversteps buffer being updated |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5204 | VkResult err; |
Courtney Goeltzenleuchter | 7415d5a | 2015-12-09 15:48:16 -0700 | [diff] [blame] | 5205 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5206 | " requires 1 dynamicOffsets, but only " |
| 5207 | "0 dynamicOffsets are left in " |
| 5208 | "pDynamicOffsets "); |
Tobin Ehlis | 49f903e | 2015-11-04 13:30:34 -0700 | [diff] [blame] | 5209 | |
| 5210 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 5211 | ASSERT_NO_FATAL_FAILURE(InitViewport()); |
| 5212 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 5213 | |
| 5214 | VkDescriptorPoolSize ds_type_count = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5215 | ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC; |
| 5216 | ds_type_count.descriptorCount = 1; |
Tobin Ehlis | 49f903e | 2015-11-04 13:30:34 -0700 | [diff] [blame] | 5217 | |
| 5218 | VkDescriptorPoolCreateInfo ds_pool_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5219 | ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO; |
| 5220 | ds_pool_ci.pNext = NULL; |
| 5221 | ds_pool_ci.maxSets = 1; |
| 5222 | ds_pool_ci.poolSizeCount = 1; |
| 5223 | ds_pool_ci.pPoolSizes = &ds_type_count; |
Tobin Ehlis | 49f903e | 2015-11-04 13:30:34 -0700 | [diff] [blame] | 5224 | |
| 5225 | VkDescriptorPool ds_pool; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5226 | err = |
| 5227 | vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool); |
Tobin Ehlis | 49f903e | 2015-11-04 13:30:34 -0700 | [diff] [blame] | 5228 | ASSERT_VK_SUCCESS(err); |
| 5229 | |
| 5230 | VkDescriptorSetLayoutBinding dsl_binding = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5231 | dsl_binding.binding = 0; |
| 5232 | dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC; |
| 5233 | dsl_binding.descriptorCount = 1; |
| 5234 | dsl_binding.stageFlags = VK_SHADER_STAGE_ALL; |
| 5235 | dsl_binding.pImmutableSamplers = NULL; |
Tobin Ehlis | 49f903e | 2015-11-04 13:30:34 -0700 | [diff] [blame] | 5236 | |
| 5237 | VkDescriptorSetLayoutCreateInfo ds_layout_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5238 | ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO; |
| 5239 | ds_layout_ci.pNext = NULL; |
| 5240 | ds_layout_ci.bindingCount = 1; |
| 5241 | ds_layout_ci.pBindings = &dsl_binding; |
Tobin Ehlis | 49f903e | 2015-11-04 13:30:34 -0700 | [diff] [blame] | 5242 | VkDescriptorSetLayout ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5243 | err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, |
| 5244 | &ds_layout); |
Tobin Ehlis | 49f903e | 2015-11-04 13:30:34 -0700 | [diff] [blame] | 5245 | ASSERT_VK_SUCCESS(err); |
| 5246 | |
| 5247 | VkDescriptorSet descriptorSet; |
| 5248 | VkDescriptorSetAllocateInfo alloc_info = {}; |
Chia-I Wu | 00ce540 | 2015-11-10 16:21:09 +0800 | [diff] [blame] | 5249 | alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO; |
Jon Ashburn | f19916e | 2016-01-11 13:12:43 -0700 | [diff] [blame] | 5250 | alloc_info.descriptorSetCount = 1; |
Tobin Ehlis | 49f903e | 2015-11-04 13:30:34 -0700 | [diff] [blame] | 5251 | alloc_info.descriptorPool = ds_pool; |
| 5252 | alloc_info.pSetLayouts = &ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5253 | err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, |
| 5254 | &descriptorSet); |
Tobin Ehlis | 49f903e | 2015-11-04 13:30:34 -0700 | [diff] [blame] | 5255 | ASSERT_VK_SUCCESS(err); |
| 5256 | |
| 5257 | VkPipelineLayoutCreateInfo pipeline_layout_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5258 | pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO; |
| 5259 | pipeline_layout_ci.pNext = NULL; |
| 5260 | pipeline_layout_ci.setLayoutCount = 1; |
| 5261 | pipeline_layout_ci.pSetLayouts = &ds_layout; |
Tobin Ehlis | 49f903e | 2015-11-04 13:30:34 -0700 | [diff] [blame] | 5262 | |
| 5263 | VkPipelineLayout pipeline_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5264 | err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, |
| 5265 | &pipeline_layout); |
Tobin Ehlis | 49f903e | 2015-11-04 13:30:34 -0700 | [diff] [blame] | 5266 | ASSERT_VK_SUCCESS(err); |
| 5267 | |
| 5268 | // Create a buffer to update the descriptor with |
| 5269 | uint32_t qfi = 0; |
| 5270 | VkBufferCreateInfo buffCI = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5271 | buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO; |
| 5272 | buffCI.size = 1024; |
| 5273 | buffCI.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT; |
| 5274 | buffCI.queueFamilyIndexCount = 1; |
| 5275 | buffCI.pQueueFamilyIndices = &qfi; |
Tobin Ehlis | 49f903e | 2015-11-04 13:30:34 -0700 | [diff] [blame] | 5276 | |
| 5277 | VkBuffer dyub; |
| 5278 | err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &dyub); |
| 5279 | ASSERT_VK_SUCCESS(err); |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 5280 | // Allocate memory and bind to buffer so we can make it to the appropriate |
| 5281 | // error |
| 5282 | VkMemoryAllocateInfo mem_alloc = {}; |
| 5283 | mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO; |
| 5284 | mem_alloc.pNext = NULL; |
| 5285 | mem_alloc.allocationSize = 1024; |
Chris Forbes | b6116cc | 2016-05-08 11:39:59 +1200 | [diff] [blame] | 5286 | mem_alloc.memoryTypeIndex = 0; |
| 5287 | |
| 5288 | VkMemoryRequirements memReqs; |
| 5289 | vkGetBufferMemoryRequirements(m_device->device(), dyub, &memReqs); |
| 5290 | bool pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &mem_alloc, |
| 5291 | 0); |
| 5292 | if (!pass) { |
| 5293 | vkDestroyBuffer(m_device->device(), dyub, NULL); |
| 5294 | return; |
| 5295 | } |
| 5296 | |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 5297 | VkDeviceMemory mem; |
| 5298 | err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem); |
| 5299 | ASSERT_VK_SUCCESS(err); |
| 5300 | err = vkBindBufferMemory(m_device->device(), dyub, mem, 0); |
| 5301 | ASSERT_VK_SUCCESS(err); |
Tobin Ehlis | 49f903e | 2015-11-04 13:30:34 -0700 | [diff] [blame] | 5302 | // Correctly update descriptor to avoid "NOT_UPDATED" error |
| 5303 | VkDescriptorBufferInfo buffInfo = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5304 | buffInfo.buffer = dyub; |
| 5305 | buffInfo.offset = 0; |
| 5306 | buffInfo.range = 1024; |
Tobin Ehlis | 49f903e | 2015-11-04 13:30:34 -0700 | [diff] [blame] | 5307 | |
| 5308 | VkWriteDescriptorSet descriptor_write; |
| 5309 | memset(&descriptor_write, 0, sizeof(descriptor_write)); |
| 5310 | descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET; |
| 5311 | descriptor_write.dstSet = descriptorSet; |
| 5312 | descriptor_write.dstBinding = 0; |
| 5313 | descriptor_write.descriptorCount = 1; |
| 5314 | descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC; |
| 5315 | descriptor_write.pBufferInfo = &buffInfo; |
| 5316 | |
| 5317 | vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL); |
| 5318 | |
| 5319 | BeginCommandBuffer(); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5320 | vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), |
| 5321 | VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, |
| 5322 | 1, &descriptorSet, 0, NULL); |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 5323 | m_errorMonitor->VerifyFound(); |
Tobin Ehlis | f658505 | 2015-12-17 11:48:42 -0700 | [diff] [blame] | 5324 | uint32_t pDynOff[2] = {512, 756}; |
| 5325 | // 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] | 5326 | m_errorMonitor->SetDesiredFailureMsg( |
| 5327 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Tobin Ehlis | f658505 | 2015-12-17 11:48:42 -0700 | [diff] [blame] | 5328 | "Attempting to bind 1 descriptorSets with 1 dynamic descriptors, but "); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5329 | vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), |
| 5330 | VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, |
| 5331 | 1, &descriptorSet, 2, pDynOff); |
Chris Forbes | 7b34280 | 2016-04-07 13:20:10 +1200 | [diff] [blame] | 5332 | m_errorMonitor->VerifyFound(); |
Tobin Ehlis | f658505 | 2015-12-17 11:48:42 -0700 | [diff] [blame] | 5333 | // Finally cause error due to dynamicOffset being too big |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 5334 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 5335 | " dynamic offset 512 combined with " |
| 5336 | "offset 0 and range 1024 that " |
| 5337 | "oversteps the buffer size of 1024"); |
Tobin Ehlis | f658505 | 2015-12-17 11:48:42 -0700 | [diff] [blame] | 5338 | // Create PSO to be used for draw-time errors below |
| 5339 | char const *vsSource = |
Chris Forbes | 7b34280 | 2016-04-07 13:20:10 +1200 | [diff] [blame] | 5340 | "#version 450\n" |
Tobin Ehlis | f658505 | 2015-12-17 11:48:42 -0700 | [diff] [blame] | 5341 | "\n" |
Tony Barbour | e804d20 | 2016-01-05 13:37:45 -0700 | [diff] [blame] | 5342 | "out gl_PerVertex { \n" |
| 5343 | " vec4 gl_Position;\n" |
| 5344 | "};\n" |
Tobin Ehlis | f658505 | 2015-12-17 11:48:42 -0700 | [diff] [blame] | 5345 | "void main(){\n" |
| 5346 | " gl_Position = vec4(1);\n" |
| 5347 | "}\n"; |
| 5348 | char const *fsSource = |
Chris Forbes | 7b34280 | 2016-04-07 13:20:10 +1200 | [diff] [blame] | 5349 | "#version 450\n" |
Tobin Ehlis | f658505 | 2015-12-17 11:48:42 -0700 | [diff] [blame] | 5350 | "\n" |
| 5351 | "layout(location=0) out vec4 x;\n" |
| 5352 | "layout(set=0) layout(binding=0) uniform foo { int x; int y; } bar;\n" |
| 5353 | "void main(){\n" |
| 5354 | " x = vec4(bar.y);\n" |
| 5355 | "}\n"; |
| 5356 | VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this); |
| 5357 | VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this); |
| 5358 | VkPipelineObj pipe(m_device); |
| 5359 | pipe.AddShader(&vs); |
| 5360 | pipe.AddShader(&fs); |
| 5361 | pipe.AddColorAttachment(); |
| 5362 | pipe.CreateVKPipeline(pipeline_layout, renderPass()); |
| 5363 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5364 | vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), |
| 5365 | VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle()); |
| 5366 | // This update should succeed, but offset size of 512 will overstep buffer |
| 5367 | // /w range 1024 & size 1024 |
| 5368 | vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), |
| 5369 | VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, |
| 5370 | 1, &descriptorSet, 1, pDynOff); |
Tobin Ehlis | f658505 | 2015-12-17 11:48:42 -0700 | [diff] [blame] | 5371 | Draw(1, 0, 0, 0); |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 5372 | m_errorMonitor->VerifyFound(); |
Tobin Ehlis | 49f903e | 2015-11-04 13:30:34 -0700 | [diff] [blame] | 5373 | |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 5374 | vkDestroyBuffer(m_device->device(), dyub, NULL); |
Tobin Ehlis | 512098e | 2016-05-05 09:06:12 -0600 | [diff] [blame] | 5375 | vkFreeMemory(m_device->device(), mem, NULL); |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 5376 | |
Tobin Ehlis | 49f903e | 2015-11-04 13:30:34 -0700 | [diff] [blame] | 5377 | vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL); |
Tony Barbour | df4c004 | 2016-06-01 15:55:43 -0600 | [diff] [blame] | 5378 | vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL); |
Tobin Ehlis | 49f903e | 2015-11-04 13:30:34 -0700 | [diff] [blame] | 5379 | vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL); |
| 5380 | } |
| 5381 | |
Tobin Ehlis | 3a23b6a | 2016-02-17 10:35:18 -0700 | [diff] [blame] | 5382 | TEST_F(VkLayerTest, InvalidPushConstants) { |
Tobin Ehlis | 3a23b6a | 2016-02-17 10:35:18 -0700 | [diff] [blame] | 5383 | VkResult err; |
Tobin Ehlis | 3a23b6a | 2016-02-17 10:35:18 -0700 | [diff] [blame] | 5384 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 5385 | ASSERT_NO_FATAL_FAILURE(InitViewport()); |
| 5386 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 5387 | |
Karl Schultz | fc8eaf1 | 2016-05-06 13:56:42 -0600 | [diff] [blame] | 5388 | VkPipelineLayout pipeline_layout; |
Tobin Ehlis | 3a23b6a | 2016-02-17 10:35:18 -0700 | [diff] [blame] | 5389 | VkPushConstantRange pc_range = {}; |
Tobin Ehlis | 3a23b6a | 2016-02-17 10:35:18 -0700 | [diff] [blame] | 5390 | VkPipelineLayoutCreateInfo pipeline_layout_ci = {}; |
| 5391 | pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO; |
| 5392 | pipeline_layout_ci.pushConstantRangeCount = 1; |
| 5393 | pipeline_layout_ci.pPushConstantRanges = &pc_range; |
| 5394 | |
Karl Schultz | fc8eaf1 | 2016-05-06 13:56:42 -0600 | [diff] [blame] | 5395 | // |
| 5396 | // Check for invalid push constant ranges in pipeline layouts. |
| 5397 | // |
| 5398 | struct PipelineLayoutTestCase { |
Karl Schultz | c81037d | 2016-05-12 08:11:23 -0600 | [diff] [blame] | 5399 | VkPushConstantRange const range; |
Karl Schultz | fc8eaf1 | 2016-05-06 13:56:42 -0600 | [diff] [blame] | 5400 | char const *msg; |
| 5401 | }; |
Tobin Ehlis | 3a23b6a | 2016-02-17 10:35:18 -0700 | [diff] [blame] | 5402 | |
Karl Schultz | c81037d | 2016-05-12 08:11:23 -0600 | [diff] [blame] | 5403 | const uint32_t too_big = m_device->props.limits.maxPushConstantsSize + 0x4; |
| 5404 | const std::array<PipelineLayoutTestCase, 10> range_tests = {{ |
| 5405 | {{VK_SHADER_STAGE_VERTEX_BIT, 0, 0}, |
| 5406 | "vkCreatePipelineLayout() call has push constants index 0 with " |
| 5407 | "size 0."}, |
| 5408 | {{VK_SHADER_STAGE_VERTEX_BIT, 0, 1}, |
| 5409 | "vkCreatePipelineLayout() call has push constants index 0 with " |
| 5410 | "size 1."}, |
| 5411 | {{VK_SHADER_STAGE_VERTEX_BIT, 1, 1}, |
| 5412 | "vkCreatePipelineLayout() call has push constants index 0 with " |
| 5413 | "size 1."}, |
| 5414 | {{VK_SHADER_STAGE_VERTEX_BIT, 1, 0}, |
| 5415 | "vkCreatePipelineLayout() call has push constants index 0 with " |
| 5416 | "size 0."}, |
| 5417 | {{VK_SHADER_STAGE_VERTEX_BIT, 1, 4}, |
| 5418 | "vkCreatePipelineLayout() call has push constants index 0 with " |
| 5419 | "offset 1. Offset must"}, |
| 5420 | {{VK_SHADER_STAGE_VERTEX_BIT, 0, too_big}, |
| 5421 | "vkCreatePipelineLayout() call has push constants index 0 " |
| 5422 | "with offset "}, |
| 5423 | {{VK_SHADER_STAGE_VERTEX_BIT, too_big, too_big}, |
| 5424 | "vkCreatePipelineLayout() call has push constants " |
| 5425 | "index 0 with offset "}, |
| 5426 | {{VK_SHADER_STAGE_VERTEX_BIT, too_big, 0}, |
| 5427 | "vkCreatePipelineLayout() call has push constants index 0 " |
| 5428 | "with offset "}, |
| 5429 | {{VK_SHADER_STAGE_VERTEX_BIT, 0xFFFFFFF0, 0x00000020}, |
| 5430 | "vkCreatePipelineLayout() call has push " |
| 5431 | "constants index 0 with offset "}, |
| 5432 | {{VK_SHADER_STAGE_VERTEX_BIT, 0x00000020, 0xFFFFFFF0}, |
| 5433 | "vkCreatePipelineLayout() call has push " |
| 5434 | "constants index 0 with offset "}, |
Karl Schultz | fc8eaf1 | 2016-05-06 13:56:42 -0600 | [diff] [blame] | 5435 | }}; |
| 5436 | |
| 5437 | // Check for invalid offset and size |
Karl Schultz | c81037d | 2016-05-12 08:11:23 -0600 | [diff] [blame] | 5438 | for (const auto &iter : range_tests) { |
| 5439 | pc_range = iter.range; |
Karl Schultz | fc8eaf1 | 2016-05-06 13:56:42 -0600 | [diff] [blame] | 5440 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 5441 | iter.msg); |
| 5442 | err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, |
| 5443 | NULL, &pipeline_layout); |
| 5444 | m_errorMonitor->VerifyFound(); |
| 5445 | if (VK_SUCCESS == err) { |
| 5446 | vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL); |
| 5447 | } |
| 5448 | } |
| 5449 | |
| 5450 | // Check for invalid stage flag |
| 5451 | pc_range.offset = 0; |
| 5452 | pc_range.size = 16; |
| 5453 | pc_range.stageFlags = 0; |
Tobin Ehlis | 3a23b6a | 2016-02-17 10:35:18 -0700 | [diff] [blame] | 5454 | m_errorMonitor->SetDesiredFailureMsg( |
| 5455 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Karl Schultz | fc8eaf1 | 2016-05-06 13:56:42 -0600 | [diff] [blame] | 5456 | "vkCreatePipelineLayout() call has no stageFlags set."); |
Tobin Ehlis | 3a23b6a | 2016-02-17 10:35:18 -0700 | [diff] [blame] | 5457 | err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, |
| 5458 | &pipeline_layout); |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 5459 | m_errorMonitor->VerifyFound(); |
Karl Schultz | fc8eaf1 | 2016-05-06 13:56:42 -0600 | [diff] [blame] | 5460 | if (VK_SUCCESS == err) { |
| 5461 | vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL); |
| 5462 | } |
| 5463 | |
| 5464 | // Check for overlapping ranges |
Karl Schultz | c81037d | 2016-05-12 08:11:23 -0600 | [diff] [blame] | 5465 | const uint32_t ranges_per_test = 5; |
Karl Schultz | fc8eaf1 | 2016-05-06 13:56:42 -0600 | [diff] [blame] | 5466 | struct OverlappingRangeTestCase { |
Karl Schultz | c81037d | 2016-05-12 08:11:23 -0600 | [diff] [blame] | 5467 | VkPushConstantRange const ranges[ranges_per_test]; |
Karl Schultz | fc8eaf1 | 2016-05-06 13:56:42 -0600 | [diff] [blame] | 5468 | char const *msg; |
| 5469 | }; |
| 5470 | |
Karl Schultz | c81037d | 2016-05-12 08:11:23 -0600 | [diff] [blame] | 5471 | const std::array<OverlappingRangeTestCase, 5> overlapping_range_tests = { |
Karl Schultz | fc8eaf1 | 2016-05-06 13:56:42 -0600 | [diff] [blame] | 5472 | {{{{VK_SHADER_STAGE_VERTEX_BIT, 0, 4}, |
| 5473 | {VK_SHADER_STAGE_VERTEX_BIT, 0, 4}, |
| 5474 | {VK_SHADER_STAGE_VERTEX_BIT, 0, 4}, |
| 5475 | {VK_SHADER_STAGE_VERTEX_BIT, 0, 4}, |
| 5476 | {VK_SHADER_STAGE_VERTEX_BIT, 0, 4}}, |
| 5477 | "vkCreatePipelineLayout() call has push constants with overlapping " |
| 5478 | "ranges: 0:[0, 4), 1:[0, 4)"}, |
| 5479 | { |
| 5480 | {{VK_SHADER_STAGE_VERTEX_BIT, 0, 4}, |
| 5481 | {VK_SHADER_STAGE_VERTEX_BIT, 4, 4}, |
| 5482 | {VK_SHADER_STAGE_VERTEX_BIT, 8, 4}, |
| 5483 | {VK_SHADER_STAGE_VERTEX_BIT, 12, 8}, |
| 5484 | {VK_SHADER_STAGE_VERTEX_BIT, 16, 4}}, |
| 5485 | "vkCreatePipelineLayout() call has push constants with " |
| 5486 | "overlapping " |
| 5487 | "ranges: 3:[12, 20), 4:[16, 20)", |
| 5488 | }, |
| 5489 | { |
| 5490 | {{VK_SHADER_STAGE_VERTEX_BIT, 16, 4}, |
| 5491 | {VK_SHADER_STAGE_VERTEX_BIT, 12, 8}, |
| 5492 | {VK_SHADER_STAGE_VERTEX_BIT, 8, 4}, |
| 5493 | {VK_SHADER_STAGE_VERTEX_BIT, 4, 4}, |
| 5494 | {VK_SHADER_STAGE_VERTEX_BIT, 0, 4}}, |
| 5495 | "vkCreatePipelineLayout() call has push constants with " |
| 5496 | "overlapping " |
| 5497 | "ranges: 0:[16, 20), 1:[12, 20)", |
| 5498 | }, |
| 5499 | { |
| 5500 | {{VK_SHADER_STAGE_VERTEX_BIT, 16, 4}, |
| 5501 | {VK_SHADER_STAGE_VERTEX_BIT, 8, 4}, |
| 5502 | {VK_SHADER_STAGE_VERTEX_BIT, 4, 4}, |
| 5503 | {VK_SHADER_STAGE_VERTEX_BIT, 12, 8}, |
| 5504 | {VK_SHADER_STAGE_VERTEX_BIT, 0, 4}}, |
| 5505 | "vkCreatePipelineLayout() call has push constants with " |
| 5506 | "overlapping " |
| 5507 | "ranges: 0:[16, 20), 3:[12, 20)", |
| 5508 | }, |
| 5509 | { |
| 5510 | {{VK_SHADER_STAGE_VERTEX_BIT, 16, 4}, |
| 5511 | {VK_SHADER_STAGE_VERTEX_BIT, 32, 4}, |
| 5512 | {VK_SHADER_STAGE_VERTEX_BIT, 4, 96}, |
| 5513 | {VK_SHADER_STAGE_VERTEX_BIT, 40, 8}, |
| 5514 | {VK_SHADER_STAGE_VERTEX_BIT, 52, 4}}, |
| 5515 | "vkCreatePipelineLayout() call has push constants with " |
| 5516 | "overlapping " |
| 5517 | "ranges: 0:[16, 20), 2:[4, 100)", |
| 5518 | }}}; |
Karl Schultz | fc8eaf1 | 2016-05-06 13:56:42 -0600 | [diff] [blame] | 5519 | |
Karl Schultz | c81037d | 2016-05-12 08:11:23 -0600 | [diff] [blame] | 5520 | for (const auto &iter : overlapping_range_tests) { |
Karl Schultz | fc8eaf1 | 2016-05-06 13:56:42 -0600 | [diff] [blame] | 5521 | pipeline_layout_ci.pPushConstantRanges = iter.ranges; |
Karl Schultz | c81037d | 2016-05-12 08:11:23 -0600 | [diff] [blame] | 5522 | pipeline_layout_ci.pushConstantRangeCount = ranges_per_test; |
| 5523 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, |
Karl Schultz | fc8eaf1 | 2016-05-06 13:56:42 -0600 | [diff] [blame] | 5524 | iter.msg); |
| 5525 | err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, |
| 5526 | NULL, &pipeline_layout); |
| 5527 | m_errorMonitor->VerifyFound(); |
| 5528 | if (VK_SUCCESS == err) { |
| 5529 | vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL); |
| 5530 | } |
| 5531 | } |
| 5532 | |
| 5533 | // 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] | 5534 | const std::array<OverlappingRangeTestCase, 2> overlapping_range_tests_pos = |
| 5535 | {{{{{VK_SHADER_STAGE_VERTEX_BIT, 0, 4}, |
| 5536 | {VK_SHADER_STAGE_VERTEX_BIT, 4, 4}, |
| 5537 | {VK_SHADER_STAGE_VERTEX_BIT, 8, 4}, |
| 5538 | {VK_SHADER_STAGE_VERTEX_BIT, 12, 4}, |
| 5539 | {VK_SHADER_STAGE_VERTEX_BIT, 16, 4}}, |
| 5540 | ""}, |
| 5541 | {{{VK_SHADER_STAGE_VERTEX_BIT, 92, 24}, |
| 5542 | {VK_SHADER_STAGE_VERTEX_BIT, 80, 4}, |
| 5543 | {VK_SHADER_STAGE_VERTEX_BIT, 64, 8}, |
| 5544 | {VK_SHADER_STAGE_VERTEX_BIT, 4, 16}, |
| 5545 | {VK_SHADER_STAGE_VERTEX_BIT, 0, 4}}, |
| 5546 | ""}}}; |
| 5547 | for (const auto &iter : overlapping_range_tests_pos) { |
Karl Schultz | fc8eaf1 | 2016-05-06 13:56:42 -0600 | [diff] [blame] | 5548 | pipeline_layout_ci.pPushConstantRanges = iter.ranges; |
| 5549 | m_errorMonitor->ExpectSuccess(); |
| 5550 | err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, |
| 5551 | NULL, &pipeline_layout); |
| 5552 | m_errorMonitor->VerifyNotFound(); |
| 5553 | if (VK_SUCCESS == err) { |
| 5554 | vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL); |
| 5555 | } |
| 5556 | } |
| 5557 | |
| 5558 | // |
| 5559 | // CmdPushConstants tests |
| 5560 | // |
Karl Schultz | c81037d | 2016-05-12 08:11:23 -0600 | [diff] [blame] | 5561 | const uint8_t dummy_values[100] = {}; |
Karl Schultz | fc8eaf1 | 2016-05-06 13:56:42 -0600 | [diff] [blame] | 5562 | |
| 5563 | // 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] | 5564 | const std::array<PipelineLayoutTestCase, 16> cmd_range_tests = {{ |
| 5565 | {{VK_SHADER_STAGE_VERTEX_BIT, 0, 0}, |
| 5566 | "vkCmdPushConstants() call has push constants with size 0. Size " |
| 5567 | "must be greater than zero and a multiple of 4."}, |
| 5568 | {{VK_SHADER_STAGE_VERTEX_BIT, 0, 1}, |
| 5569 | "vkCmdPushConstants() call has push constants with size 1. Size " |
| 5570 | "must be greater than zero and a multiple of 4."}, |
| 5571 | {{VK_SHADER_STAGE_VERTEX_BIT, 1, 1}, |
| 5572 | "vkCmdPushConstants() call has push constants with size 1. Size " |
| 5573 | "must be greater than zero and a multiple of 4."}, |
| 5574 | {{VK_SHADER_STAGE_VERTEX_BIT, 1, 0}, |
| 5575 | "vkCmdPushConstants() call has push constants with offset 1. " |
| 5576 | "Offset must be a multiple of 4."}, |
| 5577 | {{VK_SHADER_STAGE_VERTEX_BIT, 1, 4}, |
| 5578 | "vkCmdPushConstants() call has push constants with offset 1. " |
| 5579 | "Offset must be a multiple of 4."}, |
| 5580 | {{VK_SHADER_STAGE_VERTEX_BIT, 0, 20}, |
| 5581 | "vkCmdPushConstants() Push constant range [0, 20) with stageFlags = " |
| 5582 | "0x1 not within flag-matching ranges in pipeline layout"}, |
| 5583 | {{VK_SHADER_STAGE_VERTEX_BIT, 60, 8}, |
| 5584 | "vkCmdPushConstants() Push constant range [60, 68) with stageFlags = " |
| 5585 | "0x1 not within flag-matching ranges in pipeline layout"}, |
| 5586 | {{VK_SHADER_STAGE_VERTEX_BIT, 76, 8}, |
| 5587 | "vkCmdPushConstants() Push constant range [76, 84) with stageFlags = " |
| 5588 | "0x1 not within flag-matching ranges in pipeline layout"}, |
| 5589 | {{VK_SHADER_STAGE_VERTEX_BIT, 0, 80}, |
| 5590 | "vkCmdPushConstants() Push constant range [0, 80) with stageFlags = " |
| 5591 | "0x1 not within flag-matching ranges in pipeline layout"}, |
| 5592 | {{VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT, 0, 4}, |
| 5593 | "vkCmdPushConstants() stageFlags = 0x2 do not match the stageFlags in " |
| 5594 | "any of the ranges in pipeline layout"}, |
| 5595 | {{VK_SHADER_STAGE_VERTEX_BIT | VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT, |
| 5596 | 0, 16}, |
| 5597 | "vkCmdPushConstants() stageFlags = 0x3 do not match the stageFlags in " |
| 5598 | "any of the ranges in pipeline layout"}, |
| 5599 | {{VK_SHADER_STAGE_VERTEX_BIT, 0, too_big}, |
Karl Schultz | fc8eaf1 | 2016-05-06 13:56:42 -0600 | [diff] [blame] | 5600 | "vkCmdPushConstants() call has push constants with offset "}, |
Karl Schultz | c81037d | 2016-05-12 08:11:23 -0600 | [diff] [blame] | 5601 | {{VK_SHADER_STAGE_VERTEX_BIT, too_big, too_big}, |
Karl Schultz | fc8eaf1 | 2016-05-06 13:56:42 -0600 | [diff] [blame] | 5602 | "vkCmdPushConstants() call has push constants with offset "}, |
Karl Schultz | c81037d | 2016-05-12 08:11:23 -0600 | [diff] [blame] | 5603 | {{VK_SHADER_STAGE_VERTEX_BIT, too_big, 0}, |
Karl Schultz | fc8eaf1 | 2016-05-06 13:56:42 -0600 | [diff] [blame] | 5604 | "vkCmdPushConstants() call has push constants with offset "}, |
Karl Schultz | c81037d | 2016-05-12 08:11:23 -0600 | [diff] [blame] | 5605 | {{VK_SHADER_STAGE_VERTEX_BIT, 0xFFFFFFF0, 0x00000020}, |
Karl Schultz | fc8eaf1 | 2016-05-06 13:56:42 -0600 | [diff] [blame] | 5606 | "vkCmdPushConstants() call has push constants with offset "}, |
Karl Schultz | c81037d | 2016-05-12 08:11:23 -0600 | [diff] [blame] | 5607 | {{VK_SHADER_STAGE_VERTEX_BIT, 0x00000020, 0xFFFFFFF0}, |
Karl Schultz | fc8eaf1 | 2016-05-06 13:56:42 -0600 | [diff] [blame] | 5608 | "vkCmdPushConstants() call has push constants with offset "}, |
| 5609 | }}; |
| 5610 | |
| 5611 | // Two ranges for testing robustness |
Karl Schultz | c81037d | 2016-05-12 08:11:23 -0600 | [diff] [blame] | 5612 | const VkPushConstantRange pc_range2[] = { |
Karl Schultz | fc8eaf1 | 2016-05-06 13:56:42 -0600 | [diff] [blame] | 5613 | {VK_SHADER_STAGE_VERTEX_BIT, 64, 16}, |
Karl Schultz | c81037d | 2016-05-12 08:11:23 -0600 | [diff] [blame] | 5614 | {VK_SHADER_STAGE_VERTEX_BIT, 0, 16}, |
Karl Schultz | fc8eaf1 | 2016-05-06 13:56:42 -0600 | [diff] [blame] | 5615 | }; |
Karl Schultz | c81037d | 2016-05-12 08:11:23 -0600 | [diff] [blame] | 5616 | pipeline_layout_ci.pushConstantRangeCount = |
| 5617 | sizeof(pc_range2) / sizeof(VkPushConstantRange); |
Karl Schultz | fc8eaf1 | 2016-05-06 13:56:42 -0600 | [diff] [blame] | 5618 | pipeline_layout_ci.pPushConstantRanges = pc_range2; |
Tobin Ehlis | 3a23b6a | 2016-02-17 10:35:18 -0700 | [diff] [blame] | 5619 | err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, |
| 5620 | &pipeline_layout); |
| 5621 | ASSERT_VK_SUCCESS(err); |
| 5622 | BeginCommandBuffer(); |
Karl Schultz | c81037d | 2016-05-12 08:11:23 -0600 | [diff] [blame] | 5623 | for (const auto &iter : cmd_range_tests) { |
Karl Schultz | fc8eaf1 | 2016-05-06 13:56:42 -0600 | [diff] [blame] | 5624 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 5625 | iter.msg); |
| 5626 | vkCmdPushConstants(m_commandBuffer->GetBufferHandle(), pipeline_layout, |
Karl Schultz | c81037d | 2016-05-12 08:11:23 -0600 | [diff] [blame] | 5627 | iter.range.stageFlags, iter.range.offset, |
| 5628 | iter.range.size, dummy_values); |
Karl Schultz | fc8eaf1 | 2016-05-06 13:56:42 -0600 | [diff] [blame] | 5629 | m_errorMonitor->VerifyFound(); |
| 5630 | } |
| 5631 | |
| 5632 | // Check for invalid stage flag |
| 5633 | m_errorMonitor->SetDesiredFailureMsg( |
| 5634 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 5635 | "vkCmdPushConstants() call has no stageFlags set."); |
| 5636 | vkCmdPushConstants(m_commandBuffer->GetBufferHandle(), pipeline_layout, 0, |
Karl Schultz | c81037d | 2016-05-12 08:11:23 -0600 | [diff] [blame] | 5637 | 0, 16, dummy_values); |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 5638 | m_errorMonitor->VerifyFound(); |
Karl Schultz | c81037d | 2016-05-12 08:11:23 -0600 | [diff] [blame] | 5639 | EndCommandBuffer(); |
| 5640 | vkResetCommandBuffer(m_commandBuffer->GetBufferHandle(), 0); |
| 5641 | vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL); |
Karl Schultz | fc8eaf1 | 2016-05-06 13:56:42 -0600 | [diff] [blame] | 5642 | |
Karl Schultz | c81037d | 2016-05-12 08:11:23 -0600 | [diff] [blame] | 5643 | // overlapping range tests with cmd |
| 5644 | const std::array<PipelineLayoutTestCase, 3> cmd_overlap_tests = {{ |
| 5645 | {{VK_SHADER_STAGE_VERTEX_BIT, 0, 20}, |
| 5646 | "vkCmdPushConstants() Push constant range [0, 20) with stageFlags = " |
| 5647 | "0x1 not within flag-matching ranges in pipeline layout"}, |
| 5648 | {{VK_SHADER_STAGE_VERTEX_BIT, 16, 4}, |
| 5649 | "vkCmdPushConstants() Push constant range [16, 20) with stageFlags = " |
| 5650 | "0x1 not within flag-matching ranges in pipeline layout"}, |
| 5651 | {{VK_SHADER_STAGE_VERTEX_BIT, 40, 16}, |
| 5652 | "vkCmdPushConstants() Push constant range [40, 56) with stageFlags = " |
| 5653 | "0x1 not within flag-matching ranges in pipeline layout"}, |
| 5654 | }}; |
| 5655 | const VkPushConstantRange pc_range3[] = { |
| 5656 | {VK_SHADER_STAGE_VERTEX_BIT, 20, 16}, |
| 5657 | {VK_SHADER_STAGE_VERTEX_BIT, 0, 16}, |
| 5658 | {VK_SHADER_STAGE_VERTEX_BIT, 0, 4}, |
| 5659 | {VK_SHADER_STAGE_VERTEX_BIT, 44, 8}, |
| 5660 | {VK_SHADER_STAGE_VERTEX_BIT, 80, 12}, |
| 5661 | {VK_SHADER_STAGE_VERTEX_BIT, 36, 8}, |
| 5662 | {VK_SHADER_STAGE_VERTEX_BIT, 56, 28}, |
| 5663 | }; |
| 5664 | pipeline_layout_ci.pushConstantRangeCount = |
| 5665 | sizeof(pc_range3) / sizeof(VkPushConstantRange); |
| 5666 | pipeline_layout_ci.pPushConstantRanges = pc_range3; |
| 5667 | err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, |
| 5668 | &pipeline_layout); |
| 5669 | ASSERT_VK_SUCCESS(err); |
| 5670 | BeginCommandBuffer(); |
| 5671 | for (const auto &iter : cmd_overlap_tests) { |
| 5672 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 5673 | iter.msg); |
| 5674 | vkCmdPushConstants(m_commandBuffer->GetBufferHandle(), pipeline_layout, |
| 5675 | iter.range.stageFlags, iter.range.offset, |
| 5676 | iter.range.size, dummy_values); |
| 5677 | m_errorMonitor->VerifyFound(); |
| 5678 | } |
| 5679 | EndCommandBuffer(); |
| 5680 | vkResetCommandBuffer(m_commandBuffer->GetBufferHandle(), 0); |
| 5681 | vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL); |
| 5682 | |
| 5683 | // positive overlapping range tests with cmd |
| 5684 | const std::array<PipelineLayoutTestCase, 4> cmd_overlap_tests_pos = {{ |
| 5685 | {{VK_SHADER_STAGE_VERTEX_BIT, 0, 16}, ""}, |
| 5686 | {{VK_SHADER_STAGE_VERTEX_BIT, 0, 4}, ""}, |
| 5687 | {{VK_SHADER_STAGE_VERTEX_BIT, 20, 12}, ""}, |
| 5688 | {{VK_SHADER_STAGE_VERTEX_BIT, 56, 36}, ""}, |
| 5689 | }}; |
| 5690 | const VkPushConstantRange pc_range4[] = { |
| 5691 | {VK_SHADER_STAGE_VERTEX_BIT, 0, 64}, |
| 5692 | {VK_SHADER_STAGE_VERTEX_BIT, 20, 16}, |
| 5693 | {VK_SHADER_STAGE_VERTEX_BIT, 0, 16}, |
| 5694 | {VK_SHADER_STAGE_VERTEX_BIT, 0, 4}, |
| 5695 | {VK_SHADER_STAGE_VERTEX_BIT, 44, 8}, |
| 5696 | {VK_SHADER_STAGE_VERTEX_BIT, 80, 12}, |
| 5697 | {VK_SHADER_STAGE_VERTEX_BIT, 36, 8}, |
| 5698 | {VK_SHADER_STAGE_VERTEX_BIT, 56, 28}, |
| 5699 | }; |
| 5700 | pipeline_layout_ci.pushConstantRangeCount = |
| 5701 | sizeof(pc_range4) / sizeof(VkPushConstantRange); |
| 5702 | pipeline_layout_ci.pPushConstantRanges = pc_range4; |
| 5703 | err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, |
| 5704 | &pipeline_layout); |
| 5705 | ASSERT_VK_SUCCESS(err); |
| 5706 | BeginCommandBuffer(); |
| 5707 | for (const auto &iter : cmd_overlap_tests_pos) { |
| 5708 | m_errorMonitor->ExpectSuccess(); |
| 5709 | vkCmdPushConstants(m_commandBuffer->GetBufferHandle(), pipeline_layout, |
| 5710 | iter.range.stageFlags, iter.range.offset, |
| 5711 | iter.range.size, dummy_values); |
| 5712 | m_errorMonitor->VerifyNotFound(); |
| 5713 | } |
| 5714 | EndCommandBuffer(); |
| 5715 | vkResetCommandBuffer(m_commandBuffer->GetBufferHandle(), 0); |
Tobin Ehlis | 3a23b6a | 2016-02-17 10:35:18 -0700 | [diff] [blame] | 5716 | vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL); |
| 5717 | } |
| 5718 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5719 | TEST_F(VkLayerTest, DescriptorSetCompatibility) { |
Tobin Ehlis | 559c638 | 2015-11-05 09:52:49 -0700 | [diff] [blame] | 5720 | // Test various desriptorSet errors with bad binding combinations |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5721 | VkResult err; |
Tobin Ehlis | 559c638 | 2015-11-05 09:52:49 -0700 | [diff] [blame] | 5722 | |
| 5723 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 5724 | ASSERT_NO_FATAL_FAILURE(InitViewport()); |
| 5725 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 5726 | |
| 5727 | static const uint32_t NUM_DESCRIPTOR_TYPES = 5; |
| 5728 | VkDescriptorPoolSize ds_type_count[NUM_DESCRIPTOR_TYPES] = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5729 | ds_type_count[0].type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 5730 | ds_type_count[0].descriptorCount = 10; |
| 5731 | ds_type_count[1].type = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE; |
| 5732 | ds_type_count[1].descriptorCount = 2; |
| 5733 | ds_type_count[2].type = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE; |
| 5734 | ds_type_count[2].descriptorCount = 2; |
| 5735 | ds_type_count[3].type = VK_DESCRIPTOR_TYPE_SAMPLER; |
| 5736 | ds_type_count[3].descriptorCount = 5; |
| 5737 | // TODO : LunarG ILO driver currently asserts in desc.c w/ INPUT_ATTACHMENT |
| 5738 | // type |
| 5739 | // ds_type_count[4].type = VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT; |
| 5740 | ds_type_count[4].type = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER; |
| 5741 | ds_type_count[4].descriptorCount = 2; |
Tobin Ehlis | 559c638 | 2015-11-05 09:52:49 -0700 | [diff] [blame] | 5742 | |
| 5743 | VkDescriptorPoolCreateInfo ds_pool_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5744 | ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO; |
| 5745 | ds_pool_ci.pNext = NULL; |
| 5746 | ds_pool_ci.maxSets = 5; |
| 5747 | ds_pool_ci.poolSizeCount = NUM_DESCRIPTOR_TYPES; |
| 5748 | ds_pool_ci.pPoolSizes = ds_type_count; |
Tobin Ehlis | 559c638 | 2015-11-05 09:52:49 -0700 | [diff] [blame] | 5749 | |
| 5750 | VkDescriptorPool ds_pool; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5751 | err = |
| 5752 | vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool); |
Tobin Ehlis | 559c638 | 2015-11-05 09:52:49 -0700 | [diff] [blame] | 5753 | ASSERT_VK_SUCCESS(err); |
| 5754 | |
| 5755 | static const uint32_t MAX_DS_TYPES_IN_LAYOUT = 2; |
| 5756 | VkDescriptorSetLayoutBinding dsl_binding[MAX_DS_TYPES_IN_LAYOUT] = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5757 | dsl_binding[0].binding = 0; |
| 5758 | dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 5759 | dsl_binding[0].descriptorCount = 5; |
| 5760 | dsl_binding[0].stageFlags = VK_SHADER_STAGE_ALL; |
| 5761 | dsl_binding[0].pImmutableSamplers = NULL; |
Tobin Ehlis | 559c638 | 2015-11-05 09:52:49 -0700 | [diff] [blame] | 5762 | |
Tobin Ehlis | 8fab656 | 2015-12-01 09:57:09 -0700 | [diff] [blame] | 5763 | // Create layout identical to set0 layout but w/ different stageFlags |
| 5764 | VkDescriptorSetLayoutBinding dsl_fs_stage_only = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5765 | dsl_fs_stage_only.binding = 0; |
| 5766 | dsl_fs_stage_only.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 5767 | dsl_fs_stage_only.descriptorCount = 5; |
| 5768 | dsl_fs_stage_only.stageFlags = |
| 5769 | VK_SHADER_STAGE_FRAGMENT_BIT; // Different stageFlags to cause error at |
| 5770 | // bind time |
| 5771 | dsl_fs_stage_only.pImmutableSamplers = NULL; |
Tobin Ehlis | 559c638 | 2015-11-05 09:52:49 -0700 | [diff] [blame] | 5772 | VkDescriptorSetLayoutCreateInfo ds_layout_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5773 | ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO; |
| 5774 | ds_layout_ci.pNext = NULL; |
| 5775 | ds_layout_ci.bindingCount = 1; |
| 5776 | ds_layout_ci.pBindings = dsl_binding; |
Tobin Ehlis | 559c638 | 2015-11-05 09:52:49 -0700 | [diff] [blame] | 5777 | static const uint32_t NUM_LAYOUTS = 4; |
| 5778 | VkDescriptorSetLayout ds_layout[NUM_LAYOUTS] = {}; |
Tobin Ehlis | 8fab656 | 2015-12-01 09:57:09 -0700 | [diff] [blame] | 5779 | VkDescriptorSetLayout ds_layout_fs_only = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5780 | // Create 4 unique layouts for full pipelineLayout, and 1 special fs-only |
| 5781 | // layout for error case |
| 5782 | err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, |
| 5783 | &ds_layout[0]); |
Tobin Ehlis | 559c638 | 2015-11-05 09:52:49 -0700 | [diff] [blame] | 5784 | ASSERT_VK_SUCCESS(err); |
Jon Ashburn | 6e23c1f | 2015-12-30 18:01:16 -0700 | [diff] [blame] | 5785 | ds_layout_ci.pBindings = &dsl_fs_stage_only; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5786 | err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, |
| 5787 | &ds_layout_fs_only); |
Tobin Ehlis | 8fab656 | 2015-12-01 09:57:09 -0700 | [diff] [blame] | 5788 | ASSERT_VK_SUCCESS(err); |
Tobin Ehlis | 559c638 | 2015-11-05 09:52:49 -0700 | [diff] [blame] | 5789 | dsl_binding[0].binding = 0; |
| 5790 | dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE; |
Tobin Ehlis | 8fab656 | 2015-12-01 09:57:09 -0700 | [diff] [blame] | 5791 | dsl_binding[0].descriptorCount = 2; |
Mike Stroyan | 9c70cdb | 2016-01-06 14:14:17 -0700 | [diff] [blame] | 5792 | dsl_binding[1].binding = 1; |
| 5793 | dsl_binding[1].descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE; |
| 5794 | dsl_binding[1].descriptorCount = 2; |
| 5795 | dsl_binding[1].stageFlags = VK_SHADER_STAGE_ALL; |
| 5796 | dsl_binding[1].pImmutableSamplers = NULL; |
Jon Ashburn | 6e23c1f | 2015-12-30 18:01:16 -0700 | [diff] [blame] | 5797 | ds_layout_ci.pBindings = dsl_binding; |
Tobin Ehlis | 559c638 | 2015-11-05 09:52:49 -0700 | [diff] [blame] | 5798 | ds_layout_ci.bindingCount = 2; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5799 | err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, |
| 5800 | &ds_layout[1]); |
Tobin Ehlis | 559c638 | 2015-11-05 09:52:49 -0700 | [diff] [blame] | 5801 | ASSERT_VK_SUCCESS(err); |
| 5802 | dsl_binding[0].binding = 0; |
| 5803 | dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER; |
Tobin Ehlis | 8fab656 | 2015-12-01 09:57:09 -0700 | [diff] [blame] | 5804 | dsl_binding[0].descriptorCount = 5; |
Tobin Ehlis | 559c638 | 2015-11-05 09:52:49 -0700 | [diff] [blame] | 5805 | ds_layout_ci.bindingCount = 1; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5806 | err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, |
| 5807 | &ds_layout[2]); |
Tobin Ehlis | 559c638 | 2015-11-05 09:52:49 -0700 | [diff] [blame] | 5808 | ASSERT_VK_SUCCESS(err); |
| 5809 | dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER; |
Tobin Ehlis | 8fab656 | 2015-12-01 09:57:09 -0700 | [diff] [blame] | 5810 | dsl_binding[0].descriptorCount = 2; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5811 | err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, |
| 5812 | &ds_layout[3]); |
Tobin Ehlis | 559c638 | 2015-11-05 09:52:49 -0700 | [diff] [blame] | 5813 | ASSERT_VK_SUCCESS(err); |
| 5814 | |
| 5815 | static const uint32_t NUM_SETS = 4; |
| 5816 | VkDescriptorSet descriptorSet[NUM_SETS] = {}; |
| 5817 | VkDescriptorSetAllocateInfo alloc_info = {}; |
Tobin Ehlis | 8fab656 | 2015-12-01 09:57:09 -0700 | [diff] [blame] | 5818 | alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO; |
Jon Ashburn | f19916e | 2016-01-11 13:12:43 -0700 | [diff] [blame] | 5819 | alloc_info.descriptorSetCount = NUM_LAYOUTS; |
Tobin Ehlis | 559c638 | 2015-11-05 09:52:49 -0700 | [diff] [blame] | 5820 | alloc_info.descriptorPool = ds_pool; |
| 5821 | alloc_info.pSetLayouts = ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5822 | err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, |
| 5823 | descriptorSet); |
Tobin Ehlis | 559c638 | 2015-11-05 09:52:49 -0700 | [diff] [blame] | 5824 | ASSERT_VK_SUCCESS(err); |
Tobin Ehlis | 8fab656 | 2015-12-01 09:57:09 -0700 | [diff] [blame] | 5825 | VkDescriptorSet ds0_fs_only = {}; |
Jon Ashburn | f19916e | 2016-01-11 13:12:43 -0700 | [diff] [blame] | 5826 | alloc_info.descriptorSetCount = 1; |
Tobin Ehlis | 8fab656 | 2015-12-01 09:57:09 -0700 | [diff] [blame] | 5827 | alloc_info.pSetLayouts = &ds_layout_fs_only; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5828 | err = |
| 5829 | vkAllocateDescriptorSets(m_device->device(), &alloc_info, &ds0_fs_only); |
Tobin Ehlis | 8fab656 | 2015-12-01 09:57:09 -0700 | [diff] [blame] | 5830 | ASSERT_VK_SUCCESS(err); |
Tobin Ehlis | 559c638 | 2015-11-05 09:52:49 -0700 | [diff] [blame] | 5831 | |
| 5832 | VkPipelineLayoutCreateInfo pipeline_layout_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5833 | pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO; |
| 5834 | pipeline_layout_ci.pNext = NULL; |
| 5835 | pipeline_layout_ci.setLayoutCount = NUM_LAYOUTS; |
| 5836 | pipeline_layout_ci.pSetLayouts = ds_layout; |
Tobin Ehlis | 559c638 | 2015-11-05 09:52:49 -0700 | [diff] [blame] | 5837 | |
| 5838 | VkPipelineLayout pipeline_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5839 | err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, |
| 5840 | &pipeline_layout); |
Tobin Ehlis | 559c638 | 2015-11-05 09:52:49 -0700 | [diff] [blame] | 5841 | ASSERT_VK_SUCCESS(err); |
Tobin Ehlis | 8fab656 | 2015-12-01 09:57:09 -0700 | [diff] [blame] | 5842 | // Create pipelineLayout with only one setLayout |
| 5843 | pipeline_layout_ci.setLayoutCount = 1; |
| 5844 | VkPipelineLayout single_pipe_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5845 | err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, |
| 5846 | &single_pipe_layout); |
Tobin Ehlis | 8fab656 | 2015-12-01 09:57:09 -0700 | [diff] [blame] | 5847 | ASSERT_VK_SUCCESS(err); |
| 5848 | // Create pipelineLayout with 2 descriptor setLayout at index 0 |
| 5849 | pipeline_layout_ci.pSetLayouts = &ds_layout[3]; |
| 5850 | VkPipelineLayout pipe_layout_one_desc; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5851 | err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, |
| 5852 | &pipe_layout_one_desc); |
Tobin Ehlis | 8fab656 | 2015-12-01 09:57:09 -0700 | [diff] [blame] | 5853 | ASSERT_VK_SUCCESS(err); |
| 5854 | // Create pipelineLayout with 5 SAMPLER descriptor setLayout at index 0 |
| 5855 | pipeline_layout_ci.pSetLayouts = &ds_layout[2]; |
| 5856 | VkPipelineLayout pipe_layout_five_samp; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5857 | err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, |
| 5858 | &pipe_layout_five_samp); |
Tobin Ehlis | 8fab656 | 2015-12-01 09:57:09 -0700 | [diff] [blame] | 5859 | ASSERT_VK_SUCCESS(err); |
| 5860 | // Create pipelineLayout with UB type, but stageFlags for FS only |
| 5861 | pipeline_layout_ci.pSetLayouts = &ds_layout_fs_only; |
| 5862 | VkPipelineLayout pipe_layout_fs_only; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5863 | err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, |
| 5864 | &pipe_layout_fs_only); |
Tobin Ehlis | 8fab656 | 2015-12-01 09:57:09 -0700 | [diff] [blame] | 5865 | ASSERT_VK_SUCCESS(err); |
| 5866 | // Create pipelineLayout w/ incompatible set0 layout, but set1 is fine |
| 5867 | VkDescriptorSetLayout pl_bad_s0[2] = {}; |
| 5868 | pl_bad_s0[0] = ds_layout_fs_only; |
| 5869 | pl_bad_s0[1] = ds_layout[1]; |
| 5870 | pipeline_layout_ci.setLayoutCount = 2; |
| 5871 | pipeline_layout_ci.pSetLayouts = pl_bad_s0; |
| 5872 | VkPipelineLayout pipe_layout_bad_set0; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5873 | err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, |
| 5874 | &pipe_layout_bad_set0); |
Tobin Ehlis | 8fab656 | 2015-12-01 09:57:09 -0700 | [diff] [blame] | 5875 | ASSERT_VK_SUCCESS(err); |
Tobin Ehlis | 559c638 | 2015-11-05 09:52:49 -0700 | [diff] [blame] | 5876 | |
| 5877 | // Create a buffer to update the descriptor with |
| 5878 | uint32_t qfi = 0; |
| 5879 | VkBufferCreateInfo buffCI = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5880 | buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO; |
| 5881 | buffCI.size = 1024; |
| 5882 | buffCI.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT; |
| 5883 | buffCI.queueFamilyIndexCount = 1; |
| 5884 | buffCI.pQueueFamilyIndices = &qfi; |
Tobin Ehlis | 559c638 | 2015-11-05 09:52:49 -0700 | [diff] [blame] | 5885 | |
| 5886 | VkBuffer dyub; |
| 5887 | err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &dyub); |
| 5888 | ASSERT_VK_SUCCESS(err); |
| 5889 | // Correctly update descriptor to avoid "NOT_UPDATED" error |
| 5890 | static const uint32_t NUM_BUFFS = 5; |
| 5891 | VkDescriptorBufferInfo buffInfo[NUM_BUFFS] = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5892 | for (uint32_t i = 0; i < NUM_BUFFS; ++i) { |
Tobin Ehlis | 559c638 | 2015-11-05 09:52:49 -0700 | [diff] [blame] | 5893 | buffInfo[i].buffer = dyub; |
| 5894 | buffInfo[i].offset = 0; |
| 5895 | buffInfo[i].range = 1024; |
| 5896 | } |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5897 | VkImage image; |
| 5898 | const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM; |
| 5899 | const int32_t tex_width = 32; |
| 5900 | const int32_t tex_height = 32; |
Tobin Ehlis | 8fab656 | 2015-12-01 09:57:09 -0700 | [diff] [blame] | 5901 | VkImageCreateInfo image_create_info = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5902 | image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO; |
| 5903 | image_create_info.pNext = NULL; |
| 5904 | image_create_info.imageType = VK_IMAGE_TYPE_2D; |
| 5905 | image_create_info.format = tex_format; |
| 5906 | image_create_info.extent.width = tex_width; |
| 5907 | image_create_info.extent.height = tex_height; |
| 5908 | image_create_info.extent.depth = 1; |
| 5909 | image_create_info.mipLevels = 1; |
| 5910 | image_create_info.arrayLayers = 1; |
| 5911 | image_create_info.samples = VK_SAMPLE_COUNT_1_BIT; |
| 5912 | image_create_info.tiling = VK_IMAGE_TILING_LINEAR; |
| 5913 | image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT; |
| 5914 | image_create_info.flags = 0; |
Tobin Ehlis | 8fab656 | 2015-12-01 09:57:09 -0700 | [diff] [blame] | 5915 | err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image); |
| 5916 | ASSERT_VK_SUCCESS(err); |
Tobin Ehlis | 559c638 | 2015-11-05 09:52:49 -0700 | [diff] [blame] | 5917 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5918 | VkMemoryRequirements memReqs; |
| 5919 | VkDeviceMemory imageMem; |
| 5920 | bool pass; |
Mike Stroyan | 9c70cdb | 2016-01-06 14:14:17 -0700 | [diff] [blame] | 5921 | VkMemoryAllocateInfo memAlloc = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5922 | memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO; |
| 5923 | memAlloc.pNext = NULL; |
| 5924 | memAlloc.allocationSize = 0; |
| 5925 | memAlloc.memoryTypeIndex = 0; |
Mike Stroyan | 9c70cdb | 2016-01-06 14:14:17 -0700 | [diff] [blame] | 5926 | vkGetImageMemoryRequirements(m_device->device(), image, &memReqs); |
| 5927 | memAlloc.allocationSize = memReqs.size; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5928 | pass = |
| 5929 | m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0); |
Mike Stroyan | 9c70cdb | 2016-01-06 14:14:17 -0700 | [diff] [blame] | 5930 | ASSERT_TRUE(pass); |
| 5931 | err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &imageMem); |
| 5932 | ASSERT_VK_SUCCESS(err); |
| 5933 | err = vkBindImageMemory(m_device->device(), image, imageMem, 0); |
| 5934 | ASSERT_VK_SUCCESS(err); |
| 5935 | |
Tobin Ehlis | 8fab656 | 2015-12-01 09:57:09 -0700 | [diff] [blame] | 5936 | VkImageViewCreateInfo image_view_create_info = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5937 | image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO; |
| 5938 | image_view_create_info.image = image; |
| 5939 | image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D; |
| 5940 | image_view_create_info.format = tex_format; |
| 5941 | image_view_create_info.subresourceRange.layerCount = 1; |
| 5942 | image_view_create_info.subresourceRange.baseMipLevel = 0; |
| 5943 | image_view_create_info.subresourceRange.levelCount = 1; |
| 5944 | image_view_create_info.subresourceRange.aspectMask = |
| 5945 | VK_IMAGE_ASPECT_COLOR_BIT; |
Tobin Ehlis | 559c638 | 2015-11-05 09:52:49 -0700 | [diff] [blame] | 5946 | |
Tobin Ehlis | 8fab656 | 2015-12-01 09:57:09 -0700 | [diff] [blame] | 5947 | VkImageView view; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5948 | err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, |
| 5949 | &view); |
Tobin Ehlis | 8fab656 | 2015-12-01 09:57:09 -0700 | [diff] [blame] | 5950 | ASSERT_VK_SUCCESS(err); |
Tobin Ehlis | 991d45a | 2016-01-06 08:48:41 -0700 | [diff] [blame] | 5951 | VkDescriptorImageInfo imageInfo[4] = {}; |
Tobin Ehlis | 8fab656 | 2015-12-01 09:57:09 -0700 | [diff] [blame] | 5952 | imageInfo[0].imageView = view; |
| 5953 | imageInfo[0].imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL; |
| 5954 | imageInfo[1].imageView = view; |
| 5955 | imageInfo[1].imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL; |
Tobin Ehlis | 991d45a | 2016-01-06 08:48:41 -0700 | [diff] [blame] | 5956 | imageInfo[2].imageView = view; |
| 5957 | imageInfo[2].imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL; |
| 5958 | imageInfo[3].imageView = view; |
| 5959 | imageInfo[3].imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL; |
Tobin Ehlis | 8fab656 | 2015-12-01 09:57:09 -0700 | [diff] [blame] | 5960 | |
| 5961 | static const uint32_t NUM_SET_UPDATES = 3; |
| 5962 | VkWriteDescriptorSet descriptor_write[NUM_SET_UPDATES] = {}; |
| 5963 | descriptor_write[0].sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET; |
| 5964 | descriptor_write[0].dstSet = descriptorSet[0]; |
| 5965 | descriptor_write[0].dstBinding = 0; |
| 5966 | descriptor_write[0].descriptorCount = 5; |
| 5967 | descriptor_write[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 5968 | descriptor_write[0].pBufferInfo = buffInfo; |
| 5969 | descriptor_write[1].sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET; |
| 5970 | descriptor_write[1].dstSet = descriptorSet[1]; |
| 5971 | descriptor_write[1].dstBinding = 0; |
| 5972 | descriptor_write[1].descriptorCount = 2; |
| 5973 | descriptor_write[1].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE; |
| 5974 | descriptor_write[1].pImageInfo = imageInfo; |
| 5975 | descriptor_write[2].sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET; |
| 5976 | descriptor_write[2].dstSet = descriptorSet[1]; |
| 5977 | descriptor_write[2].dstBinding = 1; |
| 5978 | descriptor_write[2].descriptorCount = 2; |
| 5979 | descriptor_write[2].descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE; |
Tobin Ehlis | 991d45a | 2016-01-06 08:48:41 -0700 | [diff] [blame] | 5980 | descriptor_write[2].pImageInfo = &imageInfo[2]; |
Tobin Ehlis | 8fab656 | 2015-12-01 09:57:09 -0700 | [diff] [blame] | 5981 | |
| 5982 | vkUpdateDescriptorSets(m_device->device(), 3, descriptor_write, 0, NULL); |
Tobin Ehlis | 559c638 | 2015-11-05 09:52:49 -0700 | [diff] [blame] | 5983 | |
Tobin Ehlis | 8845283 | 2015-12-03 09:40:56 -0700 | [diff] [blame] | 5984 | // Create PSO to be used for draw-time errors below |
| 5985 | char const *vsSource = |
Chris Forbes | 7b34280 | 2016-04-07 13:20:10 +1200 | [diff] [blame] | 5986 | "#version 450\n" |
Tobin Ehlis | 8845283 | 2015-12-03 09:40:56 -0700 | [diff] [blame] | 5987 | "\n" |
Tony Barbour | e804d20 | 2016-01-05 13:37:45 -0700 | [diff] [blame] | 5988 | "out gl_PerVertex {\n" |
| 5989 | " vec4 gl_Position;\n" |
| 5990 | "};\n" |
Tobin Ehlis | 8845283 | 2015-12-03 09:40:56 -0700 | [diff] [blame] | 5991 | "void main(){\n" |
| 5992 | " gl_Position = vec4(1);\n" |
| 5993 | "}\n"; |
| 5994 | char const *fsSource = |
Chris Forbes | 7b34280 | 2016-04-07 13:20:10 +1200 | [diff] [blame] | 5995 | "#version 450\n" |
Tobin Ehlis | 8845283 | 2015-12-03 09:40:56 -0700 | [diff] [blame] | 5996 | "\n" |
| 5997 | "layout(location=0) out vec4 x;\n" |
| 5998 | "layout(set=0) layout(binding=0) uniform foo { int x; int y; } bar;\n" |
| 5999 | "void main(){\n" |
| 6000 | " x = vec4(bar.y);\n" |
| 6001 | "}\n"; |
| 6002 | VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this); |
| 6003 | VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this); |
Tobin Ehlis | 559c638 | 2015-11-05 09:52:49 -0700 | [diff] [blame] | 6004 | VkPipelineObj pipe(m_device); |
| 6005 | pipe.AddShader(&vs); |
| 6006 | pipe.AddShader(&fs); |
Tobin Ehlis | 8845283 | 2015-12-03 09:40:56 -0700 | [diff] [blame] | 6007 | pipe.AddColorAttachment(); |
| 6008 | pipe.CreateVKPipeline(pipe_layout_fs_only, renderPass()); |
Tobin Ehlis | 559c638 | 2015-11-05 09:52:49 -0700 | [diff] [blame] | 6009 | |
| 6010 | BeginCommandBuffer(); |
Tobin Ehlis | 8845283 | 2015-12-03 09:40:56 -0700 | [diff] [blame] | 6011 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6012 | vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), |
| 6013 | VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle()); |
| 6014 | // NOTE : I believe LunarG ilo driver has bug (LX#189) that requires binding |
| 6015 | // of PSO |
| 6016 | // here before binding DSs. Otherwise we assert in cmd_copy_dset_data() of |
| 6017 | // cmd_pipeline.c |
| 6018 | // due to the fact that cmd_alloc_dset_data() has not been called in |
| 6019 | // cmd_bind_graphics_pipeline() |
| 6020 | // TODO : Want to cause various binding incompatibility issues here to test |
| 6021 | // DrawState |
Tobin Ehlis | 559c638 | 2015-11-05 09:52:49 -0700 | [diff] [blame] | 6022 | // First cause various verify_layout_compatibility() fails |
| 6023 | // Second disturb early and late sets and verify INFO msgs |
Tobin Ehlis | 8fab656 | 2015-12-01 09:57:09 -0700 | [diff] [blame] | 6024 | // verify_set_layout_compatibility fail cases: |
| 6025 | // 1. invalid VkPipelineLayout (layout) passed into vkCmdBindDescriptorSets |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6026 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 6027 | " due to: invalid VkPipelineLayout "); |
| 6028 | vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), |
| 6029 | VK_PIPELINE_BIND_POINT_GRAPHICS, |
| 6030 | (VkPipelineLayout)((size_t)0xbaadb1be), 0, 1, |
| 6031 | &descriptorSet[0], 0, NULL); |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 6032 | m_errorMonitor->VerifyFound(); |
| 6033 | |
Tobin Ehlis | 8fab656 | 2015-12-01 09:57:09 -0700 | [diff] [blame] | 6034 | // 2. layoutIndex exceeds # of layouts in layout |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6035 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 6036 | " attempting to bind set to index 1"); |
| 6037 | vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), |
| 6038 | VK_PIPELINE_BIND_POINT_GRAPHICS, single_pipe_layout, |
| 6039 | 0, 2, &descriptorSet[0], 0, NULL); |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 6040 | m_errorMonitor->VerifyFound(); |
| 6041 | |
Tobin Ehlis | 8fab656 | 2015-12-01 09:57:09 -0700 | [diff] [blame] | 6042 | vkDestroyPipelineLayout(m_device->device(), single_pipe_layout, NULL); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6043 | // 3. Pipeline setLayout[0] has 2 descriptors, but set being bound has 5 |
| 6044 | // descriptors |
| 6045 | m_errorMonitor->SetDesiredFailureMsg( |
| 6046 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Tobin Ehlis | 2d9deec | 2016-04-21 14:19:26 -0600 | [diff] [blame] | 6047 | " has 2 descriptors, but DescriptorSetLayout "); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6048 | vkCmdBindDescriptorSets( |
| 6049 | m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, |
| 6050 | pipe_layout_one_desc, 0, 1, &descriptorSet[0], 0, NULL); |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 6051 | m_errorMonitor->VerifyFound(); |
| 6052 | |
Tobin Ehlis | 8fab656 | 2015-12-01 09:57:09 -0700 | [diff] [blame] | 6053 | vkDestroyPipelineLayout(m_device->device(), pipe_layout_one_desc, NULL); |
| 6054 | // 4. same # of descriptors but mismatch in type |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6055 | m_errorMonitor->SetDesiredFailureMsg( |
| 6056 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Tobin Ehlis | 2d9deec | 2016-04-21 14:19:26 -0600 | [diff] [blame] | 6057 | " is type 'VK_DESCRIPTOR_TYPE_SAMPLER' but binding "); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6058 | vkCmdBindDescriptorSets( |
| 6059 | m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, |
| 6060 | pipe_layout_five_samp, 0, 1, &descriptorSet[0], 0, NULL); |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 6061 | m_errorMonitor->VerifyFound(); |
| 6062 | |
Tobin Ehlis | 8fab656 | 2015-12-01 09:57:09 -0700 | [diff] [blame] | 6063 | vkDestroyPipelineLayout(m_device->device(), pipe_layout_five_samp, NULL); |
| 6064 | // 5. same # of descriptors but mismatch in stageFlags |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6065 | m_errorMonitor->SetDesiredFailureMsg( |
| 6066 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Tobin Ehlis | 2d9deec | 2016-04-21 14:19:26 -0600 | [diff] [blame] | 6067 | " has stageFlags 16 but binding 0 for DescriptorSetLayout "); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6068 | vkCmdBindDescriptorSets( |
| 6069 | m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, |
| 6070 | pipe_layout_fs_only, 0, 1, &descriptorSet[0], 0, NULL); |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 6071 | m_errorMonitor->VerifyFound(); |
| 6072 | |
Tobin Ehlis | 8fab656 | 2015-12-01 09:57:09 -0700 | [diff] [blame] | 6073 | // Cause INFO messages due to disturbing previously bound Sets |
| 6074 | // First bind sets 0 & 1 |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6075 | vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), |
| 6076 | VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, |
| 6077 | 2, &descriptorSet[0], 0, NULL); |
Tobin Ehlis | 8fab656 | 2015-12-01 09:57:09 -0700 | [diff] [blame] | 6078 | // 1. Disturb bound set0 by re-binding set1 w/ updated pipelineLayout |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6079 | m_errorMonitor->SetDesiredFailureMsg( |
Mark Lobodzinski | 510e20d | 2016-02-11 09:26:16 -0700 | [diff] [blame] | 6080 | VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6081 | " previously bound as set #0 was disturbed "); |
| 6082 | vkCmdBindDescriptorSets( |
| 6083 | m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, |
| 6084 | pipe_layout_bad_set0, 1, 1, &descriptorSet[1], 0, NULL); |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 6085 | m_errorMonitor->VerifyFound(); |
| 6086 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6087 | vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), |
| 6088 | VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, |
| 6089 | 2, &descriptorSet[0], 0, NULL); |
Tobin Ehlis | 8fab656 | 2015-12-01 09:57:09 -0700 | [diff] [blame] | 6090 | // 2. Disturb set after last bound set |
Mark Lobodzinski | 510e20d | 2016-02-11 09:26:16 -0700 | [diff] [blame] | 6091 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6092 | " newly bound as set #0 so set #1 and " |
| 6093 | "any subsequent sets were disturbed "); |
| 6094 | vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), |
| 6095 | VK_PIPELINE_BIND_POINT_GRAPHICS, |
| 6096 | pipe_layout_fs_only, 0, 1, &ds0_fs_only, 0, NULL); |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 6097 | m_errorMonitor->VerifyFound(); |
| 6098 | |
Tobin Ehlis | 8845283 | 2015-12-03 09:40:56 -0700 | [diff] [blame] | 6099 | // Cause draw-time errors due to PSO incompatibilities |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6100 | // 1. Error due to not binding required set (we actually use same code as |
| 6101 | // above to disturb set0) |
| 6102 | vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), |
| 6103 | VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, |
| 6104 | 2, &descriptorSet[0], 0, NULL); |
| 6105 | vkCmdBindDescriptorSets( |
| 6106 | m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, |
| 6107 | pipe_layout_bad_set0, 1, 1, &descriptorSet[1], 0, NULL); |
| 6108 | m_errorMonitor->SetDesiredFailureMsg( |
| 6109 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 6110 | " uses set #0 but that set is not bound."); |
Tobin Ehlis | 8845283 | 2015-12-03 09:40:56 -0700 | [diff] [blame] | 6111 | Draw(1, 0, 0, 0); |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 6112 | m_errorMonitor->VerifyFound(); |
| 6113 | |
Tobin Ehlis | 991d45a | 2016-01-06 08:48:41 -0700 | [diff] [blame] | 6114 | vkDestroyPipelineLayout(m_device->device(), pipe_layout_bad_set0, NULL); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6115 | // 2. Error due to bound set not being compatible with PSO's |
| 6116 | // VkPipelineLayout (diff stageFlags in this case) |
| 6117 | vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), |
| 6118 | VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, |
| 6119 | 2, &descriptorSet[0], 0, NULL); |
| 6120 | m_errorMonitor->SetDesiredFailureMsg( |
| 6121 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 6122 | " bound as set #0 is not compatible with "); |
Tobin Ehlis | 8845283 | 2015-12-03 09:40:56 -0700 | [diff] [blame] | 6123 | Draw(1, 0, 0, 0); |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 6124 | m_errorMonitor->VerifyFound(); |
| 6125 | |
Tobin Ehlis | 8fab656 | 2015-12-01 09:57:09 -0700 | [diff] [blame] | 6126 | // Remaining clean-up |
| 6127 | vkDestroyPipelineLayout(m_device->device(), pipe_layout_fs_only, NULL); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6128 | for (uint32_t i = 0; i < NUM_LAYOUTS; ++i) { |
Tobin Ehlis | 8fab656 | 2015-12-01 09:57:09 -0700 | [diff] [blame] | 6129 | vkDestroyDescriptorSetLayout(m_device->device(), ds_layout[i], NULL); |
| 6130 | } |
| 6131 | vkDestroyDescriptorSetLayout(m_device->device(), ds_layout_fs_only, NULL); |
Tobin Ehlis | 9bfd449 | 2016-05-05 15:09:11 -0600 | [diff] [blame] | 6132 | vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &ds0_fs_only); |
| 6133 | vkFreeDescriptorSets(m_device->device(), ds_pool, NUM_SETS, descriptorSet); |
Tobin Ehlis | 8fab656 | 2015-12-01 09:57:09 -0700 | [diff] [blame] | 6134 | vkDestroyBuffer(m_device->device(), dyub, NULL); |
Tobin Ehlis | 559c638 | 2015-11-05 09:52:49 -0700 | [diff] [blame] | 6135 | vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL); |
| 6136 | vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL); |
Tony Barbour | df4c004 | 2016-06-01 15:55:43 -0600 | [diff] [blame] | 6137 | vkFreeMemory(m_device->device(), imageMem, NULL); |
| 6138 | vkDestroyImage(m_device->device(), image, NULL); |
| 6139 | vkDestroyImageView(m_device->device(), view, NULL); |
Tobin Ehlis | 559c638 | 2015-11-05 09:52:49 -0700 | [diff] [blame] | 6140 | } |
Tobin Ehlis | 559c638 | 2015-11-05 09:52:49 -0700 | [diff] [blame] | 6141 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6142 | TEST_F(VkLayerTest, NoBeginCommandBuffer) { |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 6143 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6144 | m_errorMonitor->SetDesiredFailureMsg( |
| 6145 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 6146 | "You must call vkBeginCommandBuffer() before this call to "); |
Tobin Ehlis | af1f3a4 | 2015-06-25 15:46:59 -0600 | [diff] [blame] | 6147 | |
| 6148 | ASSERT_NO_FATAL_FAILURE(InitState()); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 6149 | VkCommandBufferObj commandBuffer(m_device, m_commandPool); |
Tobin Ehlis | af1f3a4 | 2015-06-25 15:46:59 -0600 | [diff] [blame] | 6150 | // Call EndCommandBuffer() w/o calling BeginCommandBuffer() |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 6151 | vkEndCommandBuffer(commandBuffer.GetBufferHandle()); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 6152 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 6153 | m_errorMonitor->VerifyFound(); |
Tobin Ehlis | af1f3a4 | 2015-06-25 15:46:59 -0600 | [diff] [blame] | 6154 | } |
| 6155 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6156 | TEST_F(VkLayerTest, SecondaryCommandBufferNullRenderpass) { |
| 6157 | VkResult err; |
| 6158 | VkCommandBuffer draw_cmd; |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 6159 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6160 | m_errorMonitor->SetDesiredFailureMsg( |
| 6161 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Tobin Ehlis | 61b36f3 | 2015-12-16 08:19:42 -0700 | [diff] [blame] | 6162 | " must specify a valid renderpass parameter."); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 6163 | |
Mark Lobodzinski | d9139a6 | 2015-08-04 16:24:20 -0600 | [diff] [blame] | 6164 | ASSERT_NO_FATAL_FAILURE(InitState()); |
Mark Lobodzinski | d9139a6 | 2015-08-04 16:24:20 -0600 | [diff] [blame] | 6165 | |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 6166 | VkCommandBufferAllocateInfo cmd = {}; |
Chia-I Wu | 00ce540 | 2015-11-10 16:21:09 +0800 | [diff] [blame] | 6167 | cmd.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO; |
Cody Northrop | b456970 | 2015-08-04 17:35:57 -0600 | [diff] [blame] | 6168 | cmd.pNext = NULL; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 6169 | cmd.commandPool = m_commandPool; |
| 6170 | cmd.level = VK_COMMAND_BUFFER_LEVEL_SECONDARY; |
Jon Ashburn | f19916e | 2016-01-11 13:12:43 -0700 | [diff] [blame] | 6171 | cmd.commandBufferCount = 1; |
Cody Northrop | b456970 | 2015-08-04 17:35:57 -0600 | [diff] [blame] | 6172 | |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 6173 | err = vkAllocateCommandBuffers(m_device->device(), &cmd, &draw_cmd); |
Mike Stroyan | d1c84a5 | 2015-08-18 14:40:24 -0600 | [diff] [blame] | 6174 | ASSERT_VK_SUCCESS(err); |
Mark Lobodzinski | d9139a6 | 2015-08-04 16:24:20 -0600 | [diff] [blame] | 6175 | |
| 6176 | // Force the failure by not setting the Renderpass and Framebuffer fields |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 6177 | VkCommandBufferBeginInfo cmd_buf_info = {}; |
Jon Ashburn | f19916e | 2016-01-11 13:12:43 -0700 | [diff] [blame] | 6178 | VkCommandBufferInheritanceInfo cmd_buf_hinfo = {}; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 6179 | cmd_buf_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO; |
Cody Northrop | b456970 | 2015-08-04 17:35:57 -0600 | [diff] [blame] | 6180 | cmd_buf_info.pNext = NULL; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6181 | cmd_buf_info.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT | |
| 6182 | VK_COMMAND_BUFFER_USAGE_RENDER_PASS_CONTINUE_BIT; |
Jon Ashburn | f19916e | 2016-01-11 13:12:43 -0700 | [diff] [blame] | 6183 | cmd_buf_info.pInheritanceInfo = &cmd_buf_hinfo; |
Mark Lobodzinski | d9139a6 | 2015-08-04 16:24:20 -0600 | [diff] [blame] | 6184 | |
| 6185 | // The error should be caught by validation of the BeginCommandBuffer call |
| 6186 | vkBeginCommandBuffer(draw_cmd, &cmd_buf_info); |
| 6187 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 6188 | m_errorMonitor->VerifyFound(); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 6189 | vkFreeCommandBuffers(m_device->device(), m_commandPool, 1, &draw_cmd); |
Mark Lobodzinski | d9139a6 | 2015-08-04 16:24:20 -0600 | [diff] [blame] | 6190 | } |
| 6191 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6192 | TEST_F(VkLayerTest, CommandBufferResetErrors) { |
Tobin Ehlis | ac0ef84 | 2015-12-14 13:46:38 -0700 | [diff] [blame] | 6193 | // Cause error due to Begin while recording CB |
| 6194 | // Then cause 2 errors for attempting to reset CB w/o having |
| 6195 | // VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT set for the pool from |
| 6196 | // which CBs were allocated. Note that this bit is off by default. |
Courtney Goeltzenleuchter | 7415d5a | 2015-12-09 15:48:16 -0700 | [diff] [blame] | 6197 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6198 | "Cannot call Begin on CB"); |
Tobin Ehlis | ac0ef84 | 2015-12-14 13:46:38 -0700 | [diff] [blame] | 6199 | |
| 6200 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 6201 | |
| 6202 | // Calls AllocateCommandBuffers |
| 6203 | VkCommandBufferObj commandBuffer(m_device, m_commandPool); |
| 6204 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6205 | // Force the failure by setting the Renderpass and Framebuffer fields with |
| 6206 | // (fake) data |
Tobin Ehlis | ac0ef84 | 2015-12-14 13:46:38 -0700 | [diff] [blame] | 6207 | VkCommandBufferBeginInfo cmd_buf_info = {}; |
Jon Ashburn | f19916e | 2016-01-11 13:12:43 -0700 | [diff] [blame] | 6208 | VkCommandBufferInheritanceInfo cmd_buf_hinfo = {}; |
Tobin Ehlis | ac0ef84 | 2015-12-14 13:46:38 -0700 | [diff] [blame] | 6209 | cmd_buf_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO; |
| 6210 | cmd_buf_info.pNext = NULL; |
| 6211 | cmd_buf_info.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT; |
Jon Ashburn | f19916e | 2016-01-11 13:12:43 -0700 | [diff] [blame] | 6212 | cmd_buf_info.pInheritanceInfo = &cmd_buf_hinfo; |
Tobin Ehlis | ac0ef84 | 2015-12-14 13:46:38 -0700 | [diff] [blame] | 6213 | |
| 6214 | // Begin CB to transition to recording state |
| 6215 | vkBeginCommandBuffer(commandBuffer.GetBufferHandle(), &cmd_buf_info); |
| 6216 | // Can't re-begin. This should trigger error |
| 6217 | vkBeginCommandBuffer(commandBuffer.GetBufferHandle(), &cmd_buf_info); |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 6218 | m_errorMonitor->VerifyFound(); |
| 6219 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6220 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 6221 | "Attempt to reset command buffer "); |
Tobin Ehlis | ac0ef84 | 2015-12-14 13:46:38 -0700 | [diff] [blame] | 6222 | VkCommandBufferResetFlags flags = 0; // Don't care about flags for this test |
| 6223 | // Reset attempt will trigger error due to incorrect CommandPool state |
| 6224 | vkResetCommandBuffer(commandBuffer.GetBufferHandle(), flags); |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 6225 | m_errorMonitor->VerifyFound(); |
| 6226 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6227 | m_errorMonitor->SetDesiredFailureMsg( |
| 6228 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 6229 | " attempts to implicitly reset cmdBuffer created from "); |
Tobin Ehlis | ac0ef84 | 2015-12-14 13:46:38 -0700 | [diff] [blame] | 6230 | // Transition CB to RECORDED state |
| 6231 | vkEndCommandBuffer(commandBuffer.GetBufferHandle()); |
| 6232 | // Now attempting to Begin will implicitly reset, which triggers error |
| 6233 | vkBeginCommandBuffer(commandBuffer.GetBufferHandle(), &cmd_buf_info); |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 6234 | m_errorMonitor->VerifyFound(); |
Tobin Ehlis | ac0ef84 | 2015-12-14 13:46:38 -0700 | [diff] [blame] | 6235 | } |
| 6236 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6237 | TEST_F(VkLayerTest, InvalidPipelineCreateState) { |
Tobin Ehlis | af1f3a4 | 2015-06-25 15:46:59 -0600 | [diff] [blame] | 6238 | // Attempt to Create Gfx Pipeline w/o a VS |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6239 | VkResult err; |
Tobin Ehlis | af1f3a4 | 2015-06-25 15:46:59 -0600 | [diff] [blame] | 6240 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6241 | m_errorMonitor->SetDesiredFailureMsg( |
| 6242 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 6243 | "Invalid Pipeline CreateInfo State: Vtx Shader required"); |
| 6244 | |
Tobin Ehlis | af1f3a4 | 2015-06-25 15:46:59 -0600 | [diff] [blame] | 6245 | ASSERT_NO_FATAL_FAILURE(InitState()); |
Tobin Ehlis | c9ac2b6 | 2015-09-11 12:57:55 -0600 | [diff] [blame] | 6246 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
Mark Lobodzinski | 209b529 | 2015-09-17 09:44:05 -0600 | [diff] [blame] | 6247 | |
Chia-I Wu | 1b99bb2 | 2015-10-27 19:25:11 +0800 | [diff] [blame] | 6248 | VkDescriptorPoolSize ds_type_count = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6249 | ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 6250 | ds_type_count.descriptorCount = 1; |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 6251 | |
| 6252 | VkDescriptorPoolCreateInfo ds_pool_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6253 | ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO; |
| 6254 | ds_pool_ci.pNext = NULL; |
| 6255 | ds_pool_ci.maxSets = 1; |
| 6256 | ds_pool_ci.poolSizeCount = 1; |
| 6257 | ds_pool_ci.pPoolSizes = &ds_type_count; |
Mark Lobodzinski | 209b529 | 2015-09-17 09:44:05 -0600 | [diff] [blame] | 6258 | |
Tobin Ehlis | af1f3a4 | 2015-06-25 15:46:59 -0600 | [diff] [blame] | 6259 | VkDescriptorPool ds_pool; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6260 | err = |
| 6261 | vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool); |
Tobin Ehlis | af1f3a4 | 2015-06-25 15:46:59 -0600 | [diff] [blame] | 6262 | ASSERT_VK_SUCCESS(err); |
| 6263 | |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 6264 | VkDescriptorSetLayoutBinding dsl_binding = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6265 | dsl_binding.binding = 0; |
| 6266 | dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 6267 | dsl_binding.descriptorCount = 1; |
| 6268 | dsl_binding.stageFlags = VK_SHADER_STAGE_ALL; |
| 6269 | dsl_binding.pImmutableSamplers = NULL; |
Tobin Ehlis | af1f3a4 | 2015-06-25 15:46:59 -0600 | [diff] [blame] | 6270 | |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 6271 | VkDescriptorSetLayoutCreateInfo ds_layout_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6272 | ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO; |
| 6273 | ds_layout_ci.pNext = NULL; |
| 6274 | ds_layout_ci.bindingCount = 1; |
| 6275 | ds_layout_ci.pBindings = &dsl_binding; |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 6276 | |
Tobin Ehlis | af1f3a4 | 2015-06-25 15:46:59 -0600 | [diff] [blame] | 6277 | VkDescriptorSetLayout ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6278 | err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, |
| 6279 | &ds_layout); |
Tobin Ehlis | af1f3a4 | 2015-06-25 15:46:59 -0600 | [diff] [blame] | 6280 | ASSERT_VK_SUCCESS(err); |
| 6281 | |
| 6282 | VkDescriptorSet descriptorSet; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 6283 | VkDescriptorSetAllocateInfo alloc_info = {}; |
Chia-I Wu | 00ce540 | 2015-11-10 16:21:09 +0800 | [diff] [blame] | 6284 | alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO; |
Jon Ashburn | f19916e | 2016-01-11 13:12:43 -0700 | [diff] [blame] | 6285 | alloc_info.descriptorSetCount = 1; |
Courtney Goeltzenleuchter | bee18a9 | 2015-10-23 14:21:05 -0600 | [diff] [blame] | 6286 | alloc_info.descriptorPool = ds_pool; |
| 6287 | alloc_info.pSetLayouts = &ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6288 | err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, |
| 6289 | &descriptorSet); |
Tobin Ehlis | af1f3a4 | 2015-06-25 15:46:59 -0600 | [diff] [blame] | 6290 | ASSERT_VK_SUCCESS(err); |
| 6291 | |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 6292 | VkPipelineLayoutCreateInfo pipeline_layout_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6293 | pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO; |
| 6294 | pipeline_layout_ci.setLayoutCount = 1; |
| 6295 | pipeline_layout_ci.pSetLayouts = &ds_layout; |
Tobin Ehlis | af1f3a4 | 2015-06-25 15:46:59 -0600 | [diff] [blame] | 6296 | |
| 6297 | VkPipelineLayout pipeline_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6298 | err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, |
| 6299 | &pipeline_layout); |
Tobin Ehlis | af1f3a4 | 2015-06-25 15:46:59 -0600 | [diff] [blame] | 6300 | ASSERT_VK_SUCCESS(err); |
| 6301 | |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 6302 | VkViewport vp = {}; // Just need dummy vp to point to |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6303 | VkRect2D sc = {}; // dummy scissor to point to |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 6304 | |
| 6305 | VkPipelineViewportStateCreateInfo vp_state_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6306 | vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO; |
| 6307 | vp_state_ci.scissorCount = 1; |
| 6308 | vp_state_ci.pScissors = ≻ |
| 6309 | vp_state_ci.viewportCount = 1; |
| 6310 | vp_state_ci.pViewports = &vp; |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 6311 | |
Karl Schultz | dfdb8d4 | 2016-03-08 10:30:21 -0700 | [diff] [blame] | 6312 | VkPipelineRasterizationStateCreateInfo rs_state_ci = {}; |
| 6313 | rs_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO; |
| 6314 | rs_state_ci.polygonMode = VK_POLYGON_MODE_FILL; |
| 6315 | rs_state_ci.cullMode = VK_CULL_MODE_BACK_BIT; |
| 6316 | rs_state_ci.frontFace = VK_FRONT_FACE_COUNTER_CLOCKWISE; |
| 6317 | rs_state_ci.depthClampEnable = VK_FALSE; |
| 6318 | rs_state_ci.rasterizerDiscardEnable = VK_FALSE; |
| 6319 | rs_state_ci.depthBiasEnable = VK_FALSE; |
| 6320 | |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 6321 | VkGraphicsPipelineCreateInfo gp_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6322 | gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO; |
| 6323 | gp_ci.pViewportState = &vp_state_ci; |
Karl Schultz | dfdb8d4 | 2016-03-08 10:30:21 -0700 | [diff] [blame] | 6324 | gp_ci.pRasterizationState = &rs_state_ci; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6325 | gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT; |
| 6326 | gp_ci.layout = pipeline_layout; |
| 6327 | gp_ci.renderPass = renderPass(); |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 6328 | |
| 6329 | VkPipelineCacheCreateInfo pc_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6330 | pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO; |
| 6331 | pc_ci.initialDataSize = 0; |
| 6332 | pc_ci.pInitialData = 0; |
Tobin Ehlis | af1f3a4 | 2015-06-25 15:46:59 -0600 | [diff] [blame] | 6333 | |
| 6334 | VkPipeline pipeline; |
Jon Ashburn | c669cc6 | 2015-07-09 15:02:25 -0600 | [diff] [blame] | 6335 | VkPipelineCache pipelineCache; |
| 6336 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6337 | err = |
| 6338 | vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache); |
Jon Ashburn | c669cc6 | 2015-07-09 15:02:25 -0600 | [diff] [blame] | 6339 | ASSERT_VK_SUCCESS(err); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6340 | err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, |
| 6341 | &gp_ci, NULL, &pipeline); |
Tobin Ehlis | 7d1a711 | 2015-05-27 14:32:28 -0600 | [diff] [blame] | 6342 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 6343 | m_errorMonitor->VerifyFound(); |
Mike Stroyan | d1c84a5 | 2015-08-18 14:40:24 -0600 | [diff] [blame] | 6344 | |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 6345 | vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL); |
| 6346 | vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL); |
| 6347 | vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL); |
| 6348 | vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL); |
Tobin Ehlis | af1f3a4 | 2015-06-25 15:46:59 -0600 | [diff] [blame] | 6349 | } |
Tobin Ehlis | 912df02 | 2015-09-17 08:46:18 -0600 | [diff] [blame] | 6350 | /*// TODO : This test should be good, but needs Tess support in compiler to run |
| 6351 | TEST_F(VkLayerTest, InvalidPatchControlPoints) |
| 6352 | { |
| 6353 | // Attempt to Create Gfx Pipeline w/o a VS |
Tobin Ehlis | 912df02 | 2015-09-17 08:46:18 -0600 | [diff] [blame] | 6354 | VkResult err; |
Tobin Ehlis | af1f3a4 | 2015-06-25 15:46:59 -0600 | [diff] [blame] | 6355 | |
Courtney Goeltzenleuchter | 7415d5a | 2015-12-09 15:48:16 -0700 | [diff] [blame] | 6356 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6357 | "Invalid Pipeline CreateInfo State: VK_PRIMITIVE_TOPOLOGY_PATCH |
| 6358 | primitive "); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 6359 | |
Tobin Ehlis | 912df02 | 2015-09-17 08:46:18 -0600 | [diff] [blame] | 6360 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 6361 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
Tobin Ehlis | 912df02 | 2015-09-17 08:46:18 -0600 | [diff] [blame] | 6362 | |
Chia-I Wu | 1b99bb2 | 2015-10-27 19:25:11 +0800 | [diff] [blame] | 6363 | VkDescriptorPoolSize ds_type_count = {}; |
Tobin Ehlis | 912df02 | 2015-09-17 08:46:18 -0600 | [diff] [blame] | 6364 | ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
Chia-I Wu | d50a7d7 | 2015-10-26 20:48:51 +0800 | [diff] [blame] | 6365 | ds_type_count.descriptorCount = 1; |
Tobin Ehlis | 912df02 | 2015-09-17 08:46:18 -0600 | [diff] [blame] | 6366 | |
| 6367 | VkDescriptorPoolCreateInfo ds_pool_ci = {}; |
| 6368 | ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO; |
| 6369 | ds_pool_ci.pNext = NULL; |
Chia-I Wu | 1b99bb2 | 2015-10-27 19:25:11 +0800 | [diff] [blame] | 6370 | ds_pool_ci.poolSizeCount = 1; |
| 6371 | ds_pool_ci.pPoolSizes = &ds_type_count; |
Tobin Ehlis | 912df02 | 2015-09-17 08:46:18 -0600 | [diff] [blame] | 6372 | |
| 6373 | VkDescriptorPool ds_pool; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6374 | err = vkCreateDescriptorPool(m_device->device(), |
| 6375 | 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] | 6376 | ASSERT_VK_SUCCESS(err); |
| 6377 | |
| 6378 | VkDescriptorSetLayoutBinding dsl_binding = {}; |
Chia-I Wu | d46e6ae | 2015-10-31 00:31:16 +0800 | [diff] [blame] | 6379 | dsl_binding.binding = 0; |
Tobin Ehlis | 912df02 | 2015-09-17 08:46:18 -0600 | [diff] [blame] | 6380 | dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
Chia-I Wu | 0212448 | 2015-11-06 06:42:02 +0800 | [diff] [blame] | 6381 | dsl_binding.descriptorCount = 1; |
Tobin Ehlis | 912df02 | 2015-09-17 08:46:18 -0600 | [diff] [blame] | 6382 | dsl_binding.stageFlags = VK_SHADER_STAGE_ALL; |
| 6383 | dsl_binding.pImmutableSamplers = NULL; |
| 6384 | |
| 6385 | VkDescriptorSetLayoutCreateInfo ds_layout_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6386 | ds_layout_ci.sType = |
| 6387 | VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO; |
Tobin Ehlis | 912df02 | 2015-09-17 08:46:18 -0600 | [diff] [blame] | 6388 | ds_layout_ci.pNext = NULL; |
Chia-I Wu | d50a7d7 | 2015-10-26 20:48:51 +0800 | [diff] [blame] | 6389 | ds_layout_ci.bindingCount = 1; |
Jon Ashburn | 6e23c1f | 2015-12-30 18:01:16 -0700 | [diff] [blame] | 6390 | ds_layout_ci.pBindings = &dsl_binding; |
Tobin Ehlis | 912df02 | 2015-09-17 08:46:18 -0600 | [diff] [blame] | 6391 | |
| 6392 | VkDescriptorSetLayout ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6393 | err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, |
| 6394 | &ds_layout); |
Tobin Ehlis | 912df02 | 2015-09-17 08:46:18 -0600 | [diff] [blame] | 6395 | ASSERT_VK_SUCCESS(err); |
| 6396 | |
| 6397 | VkDescriptorSet descriptorSet; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6398 | err = vkAllocateDescriptorSets(m_device->device(), ds_pool, |
| 6399 | VK_DESCRIPTOR_SET_USAGE_NON_FREE, 1, &ds_layout, &descriptorSet); |
Tobin Ehlis | 912df02 | 2015-09-17 08:46:18 -0600 | [diff] [blame] | 6400 | ASSERT_VK_SUCCESS(err); |
| 6401 | |
| 6402 | VkPipelineLayoutCreateInfo pipeline_layout_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6403 | pipeline_layout_ci.sType = |
| 6404 | VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO; |
Tobin Ehlis | 912df02 | 2015-09-17 08:46:18 -0600 | [diff] [blame] | 6405 | pipeline_layout_ci.pNext = NULL; |
Chia-I Wu | d50a7d7 | 2015-10-26 20:48:51 +0800 | [diff] [blame] | 6406 | pipeline_layout_ci.setLayoutCount = 1; |
Tobin Ehlis | 912df02 | 2015-09-17 08:46:18 -0600 | [diff] [blame] | 6407 | pipeline_layout_ci.pSetLayouts = &ds_layout; |
| 6408 | |
| 6409 | VkPipelineLayout pipeline_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6410 | err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, |
| 6411 | &pipeline_layout); |
Tobin Ehlis | 912df02 | 2015-09-17 08:46:18 -0600 | [diff] [blame] | 6412 | ASSERT_VK_SUCCESS(err); |
| 6413 | |
| 6414 | VkPipelineShaderStageCreateInfo shaderStages[3]; |
| 6415 | memset(&shaderStages, 0, 3 * sizeof(VkPipelineShaderStageCreateInfo)); |
| 6416 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6417 | VkShaderObj vs(m_device,bindStateVertShaderText,VK_SHADER_STAGE_VERTEX_BIT, |
| 6418 | this); |
Tobin Ehlis | 912df02 | 2015-09-17 08:46:18 -0600 | [diff] [blame] | 6419 | // 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] | 6420 | VkShaderObj |
| 6421 | tc(m_device,bindStateVertShaderText,VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT, |
| 6422 | this); |
| 6423 | VkShaderObj |
| 6424 | te(m_device,bindStateVertShaderText,VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT, |
| 6425 | this); |
Tobin Ehlis | 912df02 | 2015-09-17 08:46:18 -0600 | [diff] [blame] | 6426 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6427 | shaderStages[0].sType = |
| 6428 | VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO; |
Courtney Goeltzenleuchter | d263550 | 2015-10-21 17:08:06 -0600 | [diff] [blame] | 6429 | shaderStages[0].stage = VK_SHADER_STAGE_VERTEX_BIT; |
Tobin Ehlis | 912df02 | 2015-09-17 08:46:18 -0600 | [diff] [blame] | 6430 | shaderStages[0].shader = vs.handle(); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6431 | shaderStages[1].sType = |
| 6432 | VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO; |
Courtney Goeltzenleuchter | d263550 | 2015-10-21 17:08:06 -0600 | [diff] [blame] | 6433 | shaderStages[1].stage = VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT; |
Tobin Ehlis | 912df02 | 2015-09-17 08:46:18 -0600 | [diff] [blame] | 6434 | shaderStages[1].shader = tc.handle(); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6435 | shaderStages[2].sType = |
| 6436 | VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO; |
Courtney Goeltzenleuchter | d263550 | 2015-10-21 17:08:06 -0600 | [diff] [blame] | 6437 | shaderStages[2].stage = VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT; |
Tobin Ehlis | 912df02 | 2015-09-17 08:46:18 -0600 | [diff] [blame] | 6438 | shaderStages[2].shader = te.handle(); |
| 6439 | |
| 6440 | VkPipelineInputAssemblyStateCreateInfo iaCI = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6441 | iaCI.sType = |
| 6442 | VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO; |
Chia-I Wu | 515eb8f | 2015-10-31 00:31:16 +0800 | [diff] [blame] | 6443 | iaCI.topology = VK_PRIMITIVE_TOPOLOGY_PATCH_LIST; |
Tobin Ehlis | 912df02 | 2015-09-17 08:46:18 -0600 | [diff] [blame] | 6444 | |
| 6445 | VkPipelineTessellationStateCreateInfo tsCI = {}; |
| 6446 | tsCI.sType = VK_STRUCTURE_TYPE_PIPELINE_TESSELLATION_STATE_CREATE_INFO; |
| 6447 | tsCI.patchControlPoints = 0; // This will cause an error |
| 6448 | |
| 6449 | VkGraphicsPipelineCreateInfo gp_ci = {}; |
| 6450 | gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO; |
| 6451 | gp_ci.pNext = NULL; |
| 6452 | gp_ci.stageCount = 3; |
| 6453 | gp_ci.pStages = shaderStages; |
| 6454 | gp_ci.pVertexInputState = NULL; |
| 6455 | gp_ci.pInputAssemblyState = &iaCI; |
| 6456 | gp_ci.pTessellationState = &tsCI; |
| 6457 | gp_ci.pViewportState = NULL; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 6458 | gp_ci.pRasterizationState = NULL; |
Tobin Ehlis | 912df02 | 2015-09-17 08:46:18 -0600 | [diff] [blame] | 6459 | gp_ci.pMultisampleState = NULL; |
| 6460 | gp_ci.pDepthStencilState = NULL; |
| 6461 | gp_ci.pColorBlendState = NULL; |
| 6462 | gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT; |
| 6463 | gp_ci.layout = pipeline_layout; |
| 6464 | gp_ci.renderPass = renderPass(); |
| 6465 | |
| 6466 | VkPipelineCacheCreateInfo pc_ci = {}; |
| 6467 | pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO; |
| 6468 | pc_ci.pNext = NULL; |
| 6469 | pc_ci.initialSize = 0; |
| 6470 | pc_ci.initialData = 0; |
| 6471 | pc_ci.maxSize = 0; |
| 6472 | |
| 6473 | VkPipeline pipeline; |
| 6474 | VkPipelineCache pipelineCache; |
| 6475 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6476 | err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, |
| 6477 | &pipelineCache); |
Tobin Ehlis | 912df02 | 2015-09-17 08:46:18 -0600 | [diff] [blame] | 6478 | ASSERT_VK_SUCCESS(err); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6479 | err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, |
| 6480 | &gp_ci, NULL, &pipeline); |
Tobin Ehlis | 912df02 | 2015-09-17 08:46:18 -0600 | [diff] [blame] | 6481 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 6482 | m_errorMonitor->VerifyFound(); |
Mike Stroyan | d1c84a5 | 2015-08-18 14:40:24 -0600 | [diff] [blame] | 6483 | |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 6484 | vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL); |
| 6485 | vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL); |
| 6486 | vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL); |
| 6487 | vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL); |
Tobin Ehlis | 912df02 | 2015-09-17 08:46:18 -0600 | [diff] [blame] | 6488 | } |
| 6489 | */ |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 6490 | // Set scissor and viewport counts to different numbers |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6491 | TEST_F(VkLayerTest, PSOViewportScissorCountMismatch) { |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6492 | VkResult err; |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 6493 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6494 | m_errorMonitor->SetDesiredFailureMsg( |
| 6495 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 6496 | "Gfx Pipeline viewport count (1) must match scissor count (0)."); |
| 6497 | |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 6498 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 6499 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 6500 | |
Chia-I Wu | 1b99bb2 | 2015-10-27 19:25:11 +0800 | [diff] [blame] | 6501 | VkDescriptorPoolSize ds_type_count = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6502 | ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 6503 | ds_type_count.descriptorCount = 1; |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 6504 | |
| 6505 | VkDescriptorPoolCreateInfo ds_pool_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6506 | ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO; |
| 6507 | ds_pool_ci.maxSets = 1; |
| 6508 | ds_pool_ci.poolSizeCount = 1; |
| 6509 | ds_pool_ci.pPoolSizes = &ds_type_count; |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 6510 | |
| 6511 | VkDescriptorPool ds_pool; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6512 | err = |
| 6513 | vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool); |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 6514 | ASSERT_VK_SUCCESS(err); |
| 6515 | |
| 6516 | VkDescriptorSetLayoutBinding dsl_binding = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6517 | dsl_binding.binding = 0; |
| 6518 | dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 6519 | dsl_binding.descriptorCount = 1; |
| 6520 | dsl_binding.stageFlags = VK_SHADER_STAGE_ALL; |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 6521 | |
| 6522 | VkDescriptorSetLayoutCreateInfo ds_layout_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6523 | ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO; |
| 6524 | ds_layout_ci.bindingCount = 1; |
| 6525 | ds_layout_ci.pBindings = &dsl_binding; |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 6526 | |
| 6527 | VkDescriptorSetLayout ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6528 | err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, |
| 6529 | &ds_layout); |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 6530 | ASSERT_VK_SUCCESS(err); |
| 6531 | |
| 6532 | VkDescriptorSet descriptorSet; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 6533 | VkDescriptorSetAllocateInfo alloc_info = {}; |
Chia-I Wu | 00ce540 | 2015-11-10 16:21:09 +0800 | [diff] [blame] | 6534 | alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO; |
Jon Ashburn | f19916e | 2016-01-11 13:12:43 -0700 | [diff] [blame] | 6535 | alloc_info.descriptorSetCount = 1; |
Courtney Goeltzenleuchter | bee18a9 | 2015-10-23 14:21:05 -0600 | [diff] [blame] | 6536 | alloc_info.descriptorPool = ds_pool; |
| 6537 | alloc_info.pSetLayouts = &ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6538 | err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, |
| 6539 | &descriptorSet); |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 6540 | ASSERT_VK_SUCCESS(err); |
| 6541 | |
| 6542 | VkPipelineLayoutCreateInfo pipeline_layout_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6543 | pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO; |
| 6544 | pipeline_layout_ci.setLayoutCount = 1; |
| 6545 | pipeline_layout_ci.pSetLayouts = &ds_layout; |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 6546 | |
| 6547 | VkPipelineLayout pipeline_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6548 | err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, |
| 6549 | &pipeline_layout); |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 6550 | ASSERT_VK_SUCCESS(err); |
| 6551 | |
| 6552 | VkViewport vp = {}; // Just need dummy vp to point to |
| 6553 | |
| 6554 | VkPipelineViewportStateCreateInfo vp_state_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6555 | vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO; |
| 6556 | vp_state_ci.scissorCount = 0; |
| 6557 | vp_state_ci.viewportCount = 1; // Count mismatch should cause error |
| 6558 | vp_state_ci.pViewports = &vp; |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 6559 | |
Karl Schultz | dfdb8d4 | 2016-03-08 10:30:21 -0700 | [diff] [blame] | 6560 | VkPipelineRasterizationStateCreateInfo rs_state_ci = {}; |
| 6561 | rs_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO; |
| 6562 | rs_state_ci.polygonMode = VK_POLYGON_MODE_FILL; |
| 6563 | rs_state_ci.cullMode = VK_CULL_MODE_BACK_BIT; |
| 6564 | rs_state_ci.frontFace = VK_FRONT_FACE_COUNTER_CLOCKWISE; |
| 6565 | rs_state_ci.depthClampEnable = VK_FALSE; |
| 6566 | rs_state_ci.rasterizerDiscardEnable = VK_FALSE; |
| 6567 | rs_state_ci.depthBiasEnable = VK_FALSE; |
| 6568 | |
Cody Northrop | eb3a6c1 | 2015-10-05 14:44:45 -0600 | [diff] [blame] | 6569 | VkPipelineShaderStageCreateInfo shaderStages[2]; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6570 | memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo)); |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 6571 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6572 | VkShaderObj vs(m_device, bindStateVertShaderText, |
| 6573 | VK_SHADER_STAGE_VERTEX_BIT, this); |
| 6574 | VkShaderObj fs(m_device, bindStateFragShaderText, |
| 6575 | VK_SHADER_STAGE_FRAGMENT_BIT, |
Karl Schultz | bdb7595 | 2016-04-19 11:36:49 -0600 | [diff] [blame] | 6576 | this); // We shouldn't need a fragment shader |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6577 | // but add it to be able to run on more devices |
Chia-I Wu | 28e0691 | 2015-10-31 00:31:16 +0800 | [diff] [blame] | 6578 | shaderStages[0] = vs.GetStageCreateInfo(); |
| 6579 | shaderStages[1] = fs.GetStageCreateInfo(); |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 6580 | |
| 6581 | VkGraphicsPipelineCreateInfo gp_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6582 | gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO; |
| 6583 | gp_ci.stageCount = 2; |
| 6584 | gp_ci.pStages = shaderStages; |
| 6585 | gp_ci.pViewportState = &vp_state_ci; |
Karl Schultz | dfdb8d4 | 2016-03-08 10:30:21 -0700 | [diff] [blame] | 6586 | gp_ci.pRasterizationState = &rs_state_ci; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6587 | gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT; |
| 6588 | gp_ci.layout = pipeline_layout; |
| 6589 | gp_ci.renderPass = renderPass(); |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 6590 | |
| 6591 | VkPipelineCacheCreateInfo pc_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6592 | pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO; |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 6593 | |
| 6594 | VkPipeline pipeline; |
| 6595 | VkPipelineCache pipelineCache; |
| 6596 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6597 | err = |
| 6598 | vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache); |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 6599 | ASSERT_VK_SUCCESS(err); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6600 | err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, |
| 6601 | &gp_ci, NULL, &pipeline); |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 6602 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 6603 | m_errorMonitor->VerifyFound(); |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 6604 | |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 6605 | vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL); |
| 6606 | vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL); |
| 6607 | vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL); |
| 6608 | vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL); |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 6609 | } |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6610 | // Don't set viewport state in PSO. This is an error b/c we always need this |
| 6611 | // state |
Tobin Ehlis | d332f28 | 2015-10-02 11:00:56 -0600 | [diff] [blame] | 6612 | // 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] | 6613 | TEST_F(VkLayerTest, PSOViewportStateNotSet) { |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 6614 | // Attempt to Create Gfx Pipeline w/o a VS |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6615 | VkResult err; |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 6616 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6617 | m_errorMonitor->SetDesiredFailureMsg( |
| 6618 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 6619 | "Gfx Pipeline pViewportState is null. Even if "); |
| 6620 | |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 6621 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 6622 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 6623 | |
Chia-I Wu | 1b99bb2 | 2015-10-27 19:25:11 +0800 | [diff] [blame] | 6624 | VkDescriptorPoolSize ds_type_count = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6625 | ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 6626 | ds_type_count.descriptorCount = 1; |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 6627 | |
| 6628 | VkDescriptorPoolCreateInfo ds_pool_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6629 | ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO; |
| 6630 | ds_pool_ci.maxSets = 1; |
| 6631 | ds_pool_ci.poolSizeCount = 1; |
| 6632 | ds_pool_ci.pPoolSizes = &ds_type_count; |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 6633 | |
| 6634 | VkDescriptorPool ds_pool; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6635 | err = |
| 6636 | vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool); |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 6637 | ASSERT_VK_SUCCESS(err); |
| 6638 | |
| 6639 | VkDescriptorSetLayoutBinding dsl_binding = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6640 | dsl_binding.binding = 0; |
| 6641 | dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 6642 | dsl_binding.descriptorCount = 1; |
| 6643 | dsl_binding.stageFlags = VK_SHADER_STAGE_ALL; |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 6644 | |
| 6645 | VkDescriptorSetLayoutCreateInfo ds_layout_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6646 | ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO; |
| 6647 | ds_layout_ci.bindingCount = 1; |
| 6648 | ds_layout_ci.pBindings = &dsl_binding; |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 6649 | |
| 6650 | VkDescriptorSetLayout ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6651 | err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, |
| 6652 | &ds_layout); |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 6653 | ASSERT_VK_SUCCESS(err); |
| 6654 | |
| 6655 | VkDescriptorSet descriptorSet; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 6656 | VkDescriptorSetAllocateInfo alloc_info = {}; |
Chia-I Wu | 00ce540 | 2015-11-10 16:21:09 +0800 | [diff] [blame] | 6657 | alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO; |
Jon Ashburn | f19916e | 2016-01-11 13:12:43 -0700 | [diff] [blame] | 6658 | alloc_info.descriptorSetCount = 1; |
Courtney Goeltzenleuchter | bee18a9 | 2015-10-23 14:21:05 -0600 | [diff] [blame] | 6659 | alloc_info.descriptorPool = ds_pool; |
| 6660 | alloc_info.pSetLayouts = &ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6661 | err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, |
| 6662 | &descriptorSet); |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 6663 | ASSERT_VK_SUCCESS(err); |
| 6664 | |
| 6665 | VkPipelineLayoutCreateInfo pipeline_layout_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6666 | pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO; |
| 6667 | pipeline_layout_ci.setLayoutCount = 1; |
| 6668 | pipeline_layout_ci.pSetLayouts = &ds_layout; |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 6669 | |
| 6670 | VkPipelineLayout pipeline_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6671 | err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, |
| 6672 | &pipeline_layout); |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 6673 | ASSERT_VK_SUCCESS(err); |
| 6674 | |
| 6675 | VkDynamicState sc_state = VK_DYNAMIC_STATE_SCISSOR; |
| 6676 | // Set scissor as dynamic to avoid second error |
| 6677 | VkPipelineDynamicStateCreateInfo dyn_state_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6678 | dyn_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO; |
| 6679 | dyn_state_ci.dynamicStateCount = 1; |
| 6680 | dyn_state_ci.pDynamicStates = &sc_state; |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 6681 | |
Cody Northrop | eb3a6c1 | 2015-10-05 14:44:45 -0600 | [diff] [blame] | 6682 | VkPipelineShaderStageCreateInfo shaderStages[2]; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6683 | memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo)); |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 6684 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6685 | VkShaderObj vs(m_device, bindStateVertShaderText, |
| 6686 | VK_SHADER_STAGE_VERTEX_BIT, this); |
| 6687 | VkShaderObj fs(m_device, bindStateFragShaderText, |
| 6688 | VK_SHADER_STAGE_FRAGMENT_BIT, |
Karl Schultz | bdb7595 | 2016-04-19 11:36:49 -0600 | [diff] [blame] | 6689 | this); // We shouldn't need a fragment shader |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6690 | // but add it to be able to run on more devices |
Chia-I Wu | 28e0691 | 2015-10-31 00:31:16 +0800 | [diff] [blame] | 6691 | shaderStages[0] = vs.GetStageCreateInfo(); |
| 6692 | shaderStages[1] = fs.GetStageCreateInfo(); |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 6693 | |
Karl Schultz | dfdb8d4 | 2016-03-08 10:30:21 -0700 | [diff] [blame] | 6694 | |
| 6695 | VkPipelineRasterizationStateCreateInfo rs_state_ci = {}; |
| 6696 | rs_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO; |
| 6697 | rs_state_ci.polygonMode = VK_POLYGON_MODE_FILL; |
| 6698 | rs_state_ci.cullMode = VK_CULL_MODE_BACK_BIT; |
| 6699 | rs_state_ci.frontFace = VK_FRONT_FACE_COUNTER_CLOCKWISE; |
| 6700 | rs_state_ci.depthClampEnable = VK_FALSE; |
| 6701 | rs_state_ci.rasterizerDiscardEnable = VK_FALSE; |
| 6702 | rs_state_ci.depthBiasEnable = VK_FALSE; |
| 6703 | |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 6704 | VkGraphicsPipelineCreateInfo gp_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6705 | gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO; |
| 6706 | gp_ci.stageCount = 2; |
| 6707 | gp_ci.pStages = shaderStages; |
Karl Schultz | dfdb8d4 | 2016-03-08 10:30:21 -0700 | [diff] [blame] | 6708 | gp_ci.pRasterizationState = &rs_state_ci; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6709 | gp_ci.pViewportState = NULL; // Not setting VP state w/o dynamic vp state |
| 6710 | // should cause validation error |
| 6711 | gp_ci.pDynamicState = &dyn_state_ci; |
| 6712 | gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT; |
| 6713 | gp_ci.layout = pipeline_layout; |
| 6714 | gp_ci.renderPass = renderPass(); |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 6715 | |
| 6716 | VkPipelineCacheCreateInfo pc_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6717 | pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO; |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 6718 | |
| 6719 | VkPipeline pipeline; |
| 6720 | VkPipelineCache pipelineCache; |
| 6721 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6722 | err = |
| 6723 | vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache); |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 6724 | ASSERT_VK_SUCCESS(err); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6725 | err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, |
| 6726 | &gp_ci, NULL, &pipeline); |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 6727 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 6728 | m_errorMonitor->VerifyFound(); |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 6729 | |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 6730 | vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL); |
| 6731 | vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL); |
| 6732 | vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL); |
| 6733 | vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL); |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 6734 | } |
| 6735 | // Create PSO w/o non-zero viewportCount but no viewport data |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6736 | // Then run second test where dynamic scissor count doesn't match PSO scissor |
| 6737 | // count |
| 6738 | TEST_F(VkLayerTest, PSOViewportCountWithoutDataAndDynScissorMismatch) { |
| 6739 | VkResult err; |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 6740 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6741 | m_errorMonitor->SetDesiredFailureMsg( |
| 6742 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 6743 | "Gfx Pipeline viewportCount is 1, but pViewports is NULL. "); |
| 6744 | |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 6745 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 6746 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 6747 | |
Chia-I Wu | 1b99bb2 | 2015-10-27 19:25:11 +0800 | [diff] [blame] | 6748 | VkDescriptorPoolSize ds_type_count = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6749 | ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 6750 | ds_type_count.descriptorCount = 1; |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 6751 | |
| 6752 | VkDescriptorPoolCreateInfo ds_pool_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6753 | ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO; |
| 6754 | ds_pool_ci.maxSets = 1; |
| 6755 | ds_pool_ci.poolSizeCount = 1; |
| 6756 | ds_pool_ci.pPoolSizes = &ds_type_count; |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 6757 | |
| 6758 | VkDescriptorPool ds_pool; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6759 | err = |
| 6760 | vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool); |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 6761 | ASSERT_VK_SUCCESS(err); |
| 6762 | |
| 6763 | VkDescriptorSetLayoutBinding dsl_binding = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6764 | dsl_binding.binding = 0; |
| 6765 | dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 6766 | dsl_binding.descriptorCount = 1; |
| 6767 | dsl_binding.stageFlags = VK_SHADER_STAGE_ALL; |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 6768 | |
| 6769 | VkDescriptorSetLayoutCreateInfo ds_layout_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6770 | ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO; |
| 6771 | ds_layout_ci.bindingCount = 1; |
| 6772 | ds_layout_ci.pBindings = &dsl_binding; |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 6773 | |
| 6774 | VkDescriptorSetLayout ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6775 | err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, |
| 6776 | &ds_layout); |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 6777 | ASSERT_VK_SUCCESS(err); |
| 6778 | |
| 6779 | VkDescriptorSet descriptorSet; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 6780 | VkDescriptorSetAllocateInfo alloc_info = {}; |
Chia-I Wu | 00ce540 | 2015-11-10 16:21:09 +0800 | [diff] [blame] | 6781 | alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO; |
Jon Ashburn | f19916e | 2016-01-11 13:12:43 -0700 | [diff] [blame] | 6782 | alloc_info.descriptorSetCount = 1; |
Courtney Goeltzenleuchter | bee18a9 | 2015-10-23 14:21:05 -0600 | [diff] [blame] | 6783 | alloc_info.descriptorPool = ds_pool; |
| 6784 | alloc_info.pSetLayouts = &ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6785 | err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, |
| 6786 | &descriptorSet); |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 6787 | ASSERT_VK_SUCCESS(err); |
| 6788 | |
| 6789 | VkPipelineLayoutCreateInfo pipeline_layout_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6790 | pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO; |
| 6791 | pipeline_layout_ci.setLayoutCount = 1; |
| 6792 | pipeline_layout_ci.pSetLayouts = &ds_layout; |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 6793 | |
| 6794 | VkPipelineLayout pipeline_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6795 | err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, |
| 6796 | &pipeline_layout); |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 6797 | ASSERT_VK_SUCCESS(err); |
| 6798 | |
| 6799 | VkPipelineViewportStateCreateInfo vp_state_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6800 | vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO; |
| 6801 | vp_state_ci.viewportCount = 1; |
| 6802 | vp_state_ci.pViewports = NULL; // Null vp w/ count of 1 should cause error |
| 6803 | vp_state_ci.scissorCount = 1; |
| 6804 | vp_state_ci.pScissors = |
| 6805 | NULL; // Scissor is dynamic (below) so this won't cause error |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 6806 | |
| 6807 | VkDynamicState sc_state = VK_DYNAMIC_STATE_SCISSOR; |
| 6808 | // Set scissor as dynamic to avoid that error |
| 6809 | VkPipelineDynamicStateCreateInfo dyn_state_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6810 | dyn_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO; |
| 6811 | dyn_state_ci.dynamicStateCount = 1; |
| 6812 | dyn_state_ci.pDynamicStates = &sc_state; |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 6813 | |
Cody Northrop | eb3a6c1 | 2015-10-05 14:44:45 -0600 | [diff] [blame] | 6814 | VkPipelineShaderStageCreateInfo shaderStages[2]; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6815 | memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo)); |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 6816 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6817 | VkShaderObj vs(m_device, bindStateVertShaderText, |
| 6818 | VK_SHADER_STAGE_VERTEX_BIT, this); |
| 6819 | VkShaderObj fs(m_device, bindStateFragShaderText, |
| 6820 | VK_SHADER_STAGE_FRAGMENT_BIT, |
Karl Schultz | bdb7595 | 2016-04-19 11:36:49 -0600 | [diff] [blame] | 6821 | this); // We shouldn't need a fragment shader |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6822 | // but add it to be able to run on more devices |
Chia-I Wu | 28e0691 | 2015-10-31 00:31:16 +0800 | [diff] [blame] | 6823 | shaderStages[0] = vs.GetStageCreateInfo(); |
| 6824 | shaderStages[1] = fs.GetStageCreateInfo(); |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 6825 | |
Cody Northrop | f6622dc | 2015-10-06 10:33:21 -0600 | [diff] [blame] | 6826 | VkPipelineVertexInputStateCreateInfo vi_ci = {}; |
| 6827 | vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO; |
| 6828 | vi_ci.pNext = nullptr; |
Chia-I Wu | d50a7d7 | 2015-10-26 20:48:51 +0800 | [diff] [blame] | 6829 | vi_ci.vertexBindingDescriptionCount = 0; |
Cody Northrop | f6622dc | 2015-10-06 10:33:21 -0600 | [diff] [blame] | 6830 | vi_ci.pVertexBindingDescriptions = nullptr; |
Chia-I Wu | d50a7d7 | 2015-10-26 20:48:51 +0800 | [diff] [blame] | 6831 | vi_ci.vertexAttributeDescriptionCount = 0; |
Cody Northrop | f6622dc | 2015-10-06 10:33:21 -0600 | [diff] [blame] | 6832 | vi_ci.pVertexAttributeDescriptions = nullptr; |
| 6833 | |
| 6834 | VkPipelineInputAssemblyStateCreateInfo ia_ci = {}; |
| 6835 | ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO; |
| 6836 | ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP; |
| 6837 | |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 6838 | VkPipelineRasterizationStateCreateInfo rs_ci = {}; |
Chia-I Wu | 1b99bb2 | 2015-10-27 19:25:11 +0800 | [diff] [blame] | 6839 | rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO; |
Cody Northrop | f6622dc | 2015-10-06 10:33:21 -0600 | [diff] [blame] | 6840 | rs_ci.pNext = nullptr; |
| 6841 | |
Mark Young | c89c631 | 2016-03-31 16:03:20 -0600 | [diff] [blame] | 6842 | VkPipelineColorBlendAttachmentState att = {}; |
| 6843 | att.blendEnable = VK_FALSE; |
| 6844 | att.colorWriteMask = 0xf; |
| 6845 | |
Cody Northrop | f6622dc | 2015-10-06 10:33:21 -0600 | [diff] [blame] | 6846 | VkPipelineColorBlendStateCreateInfo cb_ci = {}; |
| 6847 | cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO; |
| 6848 | cb_ci.pNext = nullptr; |
Mark Young | c89c631 | 2016-03-31 16:03:20 -0600 | [diff] [blame] | 6849 | cb_ci.attachmentCount = 1; |
| 6850 | cb_ci.pAttachments = &att; |
Cody Northrop | f6622dc | 2015-10-06 10:33:21 -0600 | [diff] [blame] | 6851 | |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 6852 | VkGraphicsPipelineCreateInfo gp_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6853 | gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO; |
| 6854 | gp_ci.stageCount = 2; |
| 6855 | gp_ci.pStages = shaderStages; |
| 6856 | gp_ci.pVertexInputState = &vi_ci; |
| 6857 | gp_ci.pInputAssemblyState = &ia_ci; |
| 6858 | gp_ci.pViewportState = &vp_state_ci; |
| 6859 | gp_ci.pRasterizationState = &rs_ci; |
| 6860 | gp_ci.pColorBlendState = &cb_ci; |
| 6861 | gp_ci.pDynamicState = &dyn_state_ci; |
| 6862 | gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT; |
| 6863 | gp_ci.layout = pipeline_layout; |
| 6864 | gp_ci.renderPass = renderPass(); |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 6865 | |
| 6866 | VkPipelineCacheCreateInfo pc_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6867 | pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO; |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 6868 | |
| 6869 | VkPipeline pipeline; |
| 6870 | VkPipelineCache pipelineCache; |
| 6871 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6872 | err = |
| 6873 | vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache); |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 6874 | ASSERT_VK_SUCCESS(err); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6875 | err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, |
| 6876 | &gp_ci, NULL, &pipeline); |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 6877 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 6878 | m_errorMonitor->VerifyFound(); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 6879 | |
Tobin Ehlis | d332f28 | 2015-10-02 11:00:56 -0600 | [diff] [blame] | 6880 | // 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] | 6881 | // First need to successfully create the PSO from above by setting |
| 6882 | // pViewports |
| 6883 | m_errorMonitor->SetDesiredFailureMsg( |
| 6884 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 6885 | "Dynamic scissorCount from vkCmdSetScissor() is 2, but PSO " |
| 6886 | "scissorCount is 1. These counts must match."); |
| 6887 | |
| 6888 | VkViewport vp = {}; // Just need dummy vp to point to |
| 6889 | vp_state_ci.pViewports = &vp; |
| 6890 | err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, |
| 6891 | &gp_ci, NULL, &pipeline); |
| 6892 | ASSERT_VK_SUCCESS(err); |
| 6893 | BeginCommandBuffer(); |
| 6894 | vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), |
| 6895 | VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline); |
| 6896 | VkRect2D scissors[2] = {}; // don't care about data |
| 6897 | // Count of 2 doesn't match PSO count of 1 |
| 6898 | vkCmdSetScissor(m_commandBuffer->GetBufferHandle(), 0, 2, scissors); |
| 6899 | Draw(1, 0, 0, 0); |
| 6900 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 6901 | m_errorMonitor->VerifyFound(); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6902 | |
| 6903 | vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL); |
| 6904 | vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL); |
| 6905 | vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL); |
| 6906 | vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL); |
Tony Barbour | df4c004 | 2016-06-01 15:55:43 -0600 | [diff] [blame] | 6907 | vkDestroyPipeline(m_device->device(), pipeline, NULL); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6908 | } |
| 6909 | // Create PSO w/o non-zero scissorCount but no scissor data |
| 6910 | // Then run second test where dynamic viewportCount doesn't match PSO |
| 6911 | // viewportCount |
| 6912 | TEST_F(VkLayerTest, PSOScissorCountWithoutDataAndDynViewportMismatch) { |
| 6913 | VkResult err; |
| 6914 | |
| 6915 | m_errorMonitor->SetDesiredFailureMsg( |
| 6916 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 6917 | "Gfx Pipeline scissorCount is 1, but pScissors is NULL. "); |
| 6918 | |
| 6919 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 6920 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 6921 | |
| 6922 | VkDescriptorPoolSize ds_type_count = {}; |
| 6923 | ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 6924 | ds_type_count.descriptorCount = 1; |
| 6925 | |
| 6926 | VkDescriptorPoolCreateInfo ds_pool_ci = {}; |
| 6927 | ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO; |
| 6928 | ds_pool_ci.maxSets = 1; |
| 6929 | ds_pool_ci.poolSizeCount = 1; |
| 6930 | ds_pool_ci.pPoolSizes = &ds_type_count; |
| 6931 | |
| 6932 | VkDescriptorPool ds_pool; |
| 6933 | err = |
| 6934 | vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool); |
| 6935 | ASSERT_VK_SUCCESS(err); |
| 6936 | |
| 6937 | VkDescriptorSetLayoutBinding dsl_binding = {}; |
| 6938 | dsl_binding.binding = 0; |
| 6939 | dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 6940 | dsl_binding.descriptorCount = 1; |
| 6941 | dsl_binding.stageFlags = VK_SHADER_STAGE_ALL; |
| 6942 | |
| 6943 | VkDescriptorSetLayoutCreateInfo ds_layout_ci = {}; |
| 6944 | ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO; |
| 6945 | ds_layout_ci.bindingCount = 1; |
| 6946 | ds_layout_ci.pBindings = &dsl_binding; |
| 6947 | |
| 6948 | VkDescriptorSetLayout ds_layout; |
| 6949 | err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, |
| 6950 | &ds_layout); |
| 6951 | ASSERT_VK_SUCCESS(err); |
| 6952 | |
| 6953 | VkDescriptorSet descriptorSet; |
| 6954 | VkDescriptorSetAllocateInfo alloc_info = {}; |
| 6955 | alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO; |
| 6956 | alloc_info.descriptorSetCount = 1; |
| 6957 | alloc_info.descriptorPool = ds_pool; |
| 6958 | alloc_info.pSetLayouts = &ds_layout; |
| 6959 | err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, |
| 6960 | &descriptorSet); |
| 6961 | ASSERT_VK_SUCCESS(err); |
| 6962 | |
| 6963 | VkPipelineLayoutCreateInfo pipeline_layout_ci = {}; |
| 6964 | pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO; |
| 6965 | pipeline_layout_ci.setLayoutCount = 1; |
| 6966 | pipeline_layout_ci.pSetLayouts = &ds_layout; |
| 6967 | |
| 6968 | VkPipelineLayout pipeline_layout; |
| 6969 | err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, |
| 6970 | &pipeline_layout); |
| 6971 | ASSERT_VK_SUCCESS(err); |
| 6972 | |
| 6973 | VkPipelineViewportStateCreateInfo vp_state_ci = {}; |
| 6974 | vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO; |
| 6975 | vp_state_ci.scissorCount = 1; |
| 6976 | vp_state_ci.pScissors = |
| 6977 | NULL; // Null scissor w/ count of 1 should cause error |
| 6978 | vp_state_ci.viewportCount = 1; |
| 6979 | vp_state_ci.pViewports = |
| 6980 | NULL; // vp is dynamic (below) so this won't cause error |
| 6981 | |
| 6982 | VkDynamicState vp_state = VK_DYNAMIC_STATE_VIEWPORT; |
| 6983 | // Set scissor as dynamic to avoid that error |
| 6984 | VkPipelineDynamicStateCreateInfo dyn_state_ci = {}; |
| 6985 | dyn_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO; |
| 6986 | dyn_state_ci.dynamicStateCount = 1; |
| 6987 | dyn_state_ci.pDynamicStates = &vp_state; |
| 6988 | |
| 6989 | VkPipelineShaderStageCreateInfo shaderStages[2]; |
| 6990 | memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo)); |
| 6991 | |
| 6992 | VkShaderObj vs(m_device, bindStateVertShaderText, |
| 6993 | VK_SHADER_STAGE_VERTEX_BIT, this); |
| 6994 | VkShaderObj fs(m_device, bindStateFragShaderText, |
| 6995 | VK_SHADER_STAGE_FRAGMENT_BIT, |
Karl Schultz | bdb7595 | 2016-04-19 11:36:49 -0600 | [diff] [blame] | 6996 | this); // We shouldn't need a fragment shader |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6997 | // but add it to be able to run on more devices |
| 6998 | shaderStages[0] = vs.GetStageCreateInfo(); |
| 6999 | shaderStages[1] = fs.GetStageCreateInfo(); |
| 7000 | |
| 7001 | VkPipelineVertexInputStateCreateInfo vi_ci = {}; |
| 7002 | vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO; |
| 7003 | vi_ci.pNext = nullptr; |
| 7004 | vi_ci.vertexBindingDescriptionCount = 0; |
| 7005 | vi_ci.pVertexBindingDescriptions = nullptr; |
| 7006 | vi_ci.vertexAttributeDescriptionCount = 0; |
| 7007 | vi_ci.pVertexAttributeDescriptions = nullptr; |
| 7008 | |
| 7009 | VkPipelineInputAssemblyStateCreateInfo ia_ci = {}; |
| 7010 | ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO; |
| 7011 | ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP; |
| 7012 | |
| 7013 | VkPipelineRasterizationStateCreateInfo rs_ci = {}; |
| 7014 | rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO; |
| 7015 | rs_ci.pNext = nullptr; |
| 7016 | |
Mark Young | c89c631 | 2016-03-31 16:03:20 -0600 | [diff] [blame] | 7017 | VkPipelineColorBlendAttachmentState att = {}; |
| 7018 | att.blendEnable = VK_FALSE; |
| 7019 | att.colorWriteMask = 0xf; |
| 7020 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7021 | VkPipelineColorBlendStateCreateInfo cb_ci = {}; |
| 7022 | cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO; |
| 7023 | cb_ci.pNext = nullptr; |
Mark Young | c89c631 | 2016-03-31 16:03:20 -0600 | [diff] [blame] | 7024 | cb_ci.attachmentCount = 1; |
| 7025 | cb_ci.pAttachments = &att; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7026 | |
| 7027 | VkGraphicsPipelineCreateInfo gp_ci = {}; |
| 7028 | gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO; |
| 7029 | gp_ci.stageCount = 2; |
| 7030 | gp_ci.pStages = shaderStages; |
| 7031 | gp_ci.pVertexInputState = &vi_ci; |
| 7032 | gp_ci.pInputAssemblyState = &ia_ci; |
| 7033 | gp_ci.pViewportState = &vp_state_ci; |
| 7034 | gp_ci.pRasterizationState = &rs_ci; |
| 7035 | gp_ci.pColorBlendState = &cb_ci; |
| 7036 | gp_ci.pDynamicState = &dyn_state_ci; |
| 7037 | gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT; |
| 7038 | gp_ci.layout = pipeline_layout; |
| 7039 | gp_ci.renderPass = renderPass(); |
| 7040 | |
| 7041 | VkPipelineCacheCreateInfo pc_ci = {}; |
| 7042 | pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO; |
| 7043 | |
| 7044 | VkPipeline pipeline; |
| 7045 | VkPipelineCache pipelineCache; |
| 7046 | |
| 7047 | err = |
| 7048 | vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache); |
| 7049 | ASSERT_VK_SUCCESS(err); |
| 7050 | err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, |
| 7051 | &gp_ci, NULL, &pipeline); |
| 7052 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 7053 | m_errorMonitor->VerifyFound(); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7054 | |
| 7055 | // Now hit second fail case where we set scissor w/ different count than PSO |
| 7056 | // First need to successfully create the PSO from above by setting |
| 7057 | // pViewports |
| 7058 | m_errorMonitor->SetDesiredFailureMsg( |
| 7059 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 7060 | "Dynamic viewportCount from vkCmdSetViewport() is 2, but PSO " |
| 7061 | "viewportCount is 1. These counts must match."); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 7062 | |
Tobin Ehlis | d332f28 | 2015-10-02 11:00:56 -0600 | [diff] [blame] | 7063 | VkRect2D sc = {}; // Just need dummy vp to point to |
| 7064 | vp_state_ci.pScissors = ≻ |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7065 | err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, |
| 7066 | &gp_ci, NULL, &pipeline); |
Tobin Ehlis | d332f28 | 2015-10-02 11:00:56 -0600 | [diff] [blame] | 7067 | ASSERT_VK_SUCCESS(err); |
| 7068 | BeginCommandBuffer(); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7069 | vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), |
| 7070 | VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline); |
Tobin Ehlis | d332f28 | 2015-10-02 11:00:56 -0600 | [diff] [blame] | 7071 | VkViewport viewports[2] = {}; // don't care about data |
| 7072 | // Count of 2 doesn't match PSO count of 1 |
Jon Ashburn | 19d3bf1 | 2015-12-30 14:06:55 -0700 | [diff] [blame] | 7073 | vkCmdSetViewport(m_commandBuffer->GetBufferHandle(), 0, 2, viewports); |
Tobin Ehlis | d332f28 | 2015-10-02 11:00:56 -0600 | [diff] [blame] | 7074 | Draw(1, 0, 0, 0); |
| 7075 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 7076 | m_errorMonitor->VerifyFound(); |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 7077 | |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 7078 | vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL); |
| 7079 | vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL); |
| 7080 | vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL); |
| 7081 | vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL); |
Tony Barbour | df4c004 | 2016-06-01 15:55:43 -0600 | [diff] [blame] | 7082 | vkDestroyPipeline(m_device->device(), pipeline, NULL); |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 7083 | } |
| 7084 | |
Mark Young | 7394fdd | 2016-03-31 14:56:43 -0600 | [diff] [blame] | 7085 | TEST_F(VkLayerTest, PSOLineWidthInvalid) { |
| 7086 | VkResult err; |
| 7087 | |
| 7088 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Mark Young | 4710795 | 2016-05-02 15:59:55 -0600 | [diff] [blame] | 7089 | "Attempt to set lineWidth to -1"); |
Mark Young | 7394fdd | 2016-03-31 14:56:43 -0600 | [diff] [blame] | 7090 | |
| 7091 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 7092 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 7093 | |
| 7094 | VkDescriptorPoolSize ds_type_count = {}; |
| 7095 | ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 7096 | ds_type_count.descriptorCount = 1; |
| 7097 | |
| 7098 | VkDescriptorPoolCreateInfo ds_pool_ci = {}; |
| 7099 | ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO; |
| 7100 | ds_pool_ci.maxSets = 1; |
| 7101 | ds_pool_ci.poolSizeCount = 1; |
| 7102 | ds_pool_ci.pPoolSizes = &ds_type_count; |
| 7103 | |
| 7104 | VkDescriptorPool ds_pool; |
| 7105 | err = |
| 7106 | vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool); |
| 7107 | ASSERT_VK_SUCCESS(err); |
| 7108 | |
| 7109 | VkDescriptorSetLayoutBinding dsl_binding = {}; |
| 7110 | dsl_binding.binding = 0; |
| 7111 | dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 7112 | dsl_binding.descriptorCount = 1; |
| 7113 | dsl_binding.stageFlags = VK_SHADER_STAGE_ALL; |
| 7114 | |
| 7115 | VkDescriptorSetLayoutCreateInfo ds_layout_ci = {}; |
| 7116 | ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO; |
| 7117 | ds_layout_ci.bindingCount = 1; |
| 7118 | ds_layout_ci.pBindings = &dsl_binding; |
| 7119 | |
| 7120 | VkDescriptorSetLayout ds_layout; |
| 7121 | err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, |
| 7122 | &ds_layout); |
| 7123 | ASSERT_VK_SUCCESS(err); |
| 7124 | |
| 7125 | VkDescriptorSet descriptorSet; |
| 7126 | VkDescriptorSetAllocateInfo alloc_info = {}; |
| 7127 | alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO; |
| 7128 | alloc_info.descriptorSetCount = 1; |
| 7129 | alloc_info.descriptorPool = ds_pool; |
| 7130 | alloc_info.pSetLayouts = &ds_layout; |
| 7131 | err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, |
| 7132 | &descriptorSet); |
| 7133 | ASSERT_VK_SUCCESS(err); |
| 7134 | |
| 7135 | VkPipelineLayoutCreateInfo pipeline_layout_ci = {}; |
| 7136 | pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO; |
| 7137 | pipeline_layout_ci.setLayoutCount = 1; |
| 7138 | pipeline_layout_ci.pSetLayouts = &ds_layout; |
| 7139 | |
| 7140 | VkPipelineLayout pipeline_layout; |
| 7141 | err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, |
| 7142 | &pipeline_layout); |
| 7143 | ASSERT_VK_SUCCESS(err); |
| 7144 | |
| 7145 | VkPipelineViewportStateCreateInfo vp_state_ci = {}; |
| 7146 | vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO; |
| 7147 | vp_state_ci.scissorCount = 1; |
| 7148 | vp_state_ci.pScissors = NULL; |
| 7149 | vp_state_ci.viewportCount = 1; |
| 7150 | vp_state_ci.pViewports = NULL; |
| 7151 | |
| 7152 | VkDynamicState dynamic_states[3] = {VK_DYNAMIC_STATE_VIEWPORT, |
| 7153 | VK_DYNAMIC_STATE_SCISSOR, |
| 7154 | VK_DYNAMIC_STATE_LINE_WIDTH}; |
| 7155 | // Set scissor as dynamic to avoid that error |
| 7156 | VkPipelineDynamicStateCreateInfo dyn_state_ci = {}; |
| 7157 | dyn_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO; |
| 7158 | dyn_state_ci.dynamicStateCount = 2; |
| 7159 | dyn_state_ci.pDynamicStates = dynamic_states; |
| 7160 | |
| 7161 | VkPipelineShaderStageCreateInfo shaderStages[2]; |
| 7162 | memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo)); |
| 7163 | |
| 7164 | VkShaderObj vs(m_device, bindStateVertShaderText, |
| 7165 | VK_SHADER_STAGE_VERTEX_BIT, this); |
| 7166 | VkShaderObj fs(m_device, bindStateFragShaderText, |
| 7167 | VK_SHADER_STAGE_FRAGMENT_BIT, |
| 7168 | this); // TODO - We shouldn't need a fragment shader |
| 7169 | // but add it to be able to run on more devices |
| 7170 | shaderStages[0] = vs.GetStageCreateInfo(); |
| 7171 | shaderStages[1] = fs.GetStageCreateInfo(); |
| 7172 | |
| 7173 | VkPipelineVertexInputStateCreateInfo vi_ci = {}; |
| 7174 | vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO; |
| 7175 | vi_ci.pNext = nullptr; |
| 7176 | vi_ci.vertexBindingDescriptionCount = 0; |
| 7177 | vi_ci.pVertexBindingDescriptions = nullptr; |
| 7178 | vi_ci.vertexAttributeDescriptionCount = 0; |
| 7179 | vi_ci.pVertexAttributeDescriptions = nullptr; |
| 7180 | |
| 7181 | VkPipelineInputAssemblyStateCreateInfo ia_ci = {}; |
| 7182 | ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO; |
| 7183 | ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP; |
| 7184 | |
| 7185 | VkPipelineRasterizationStateCreateInfo rs_ci = {}; |
| 7186 | rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO; |
| 7187 | rs_ci.pNext = nullptr; |
| 7188 | |
Mark Young | 4710795 | 2016-05-02 15:59:55 -0600 | [diff] [blame] | 7189 | // Check too low (line width of -1.0f). |
| 7190 | rs_ci.lineWidth = -1.0f; |
Mark Young | 7394fdd | 2016-03-31 14:56:43 -0600 | [diff] [blame] | 7191 | |
| 7192 | VkPipelineColorBlendAttachmentState att = {}; |
| 7193 | att.blendEnable = VK_FALSE; |
| 7194 | att.colorWriteMask = 0xf; |
| 7195 | |
| 7196 | VkPipelineColorBlendStateCreateInfo cb_ci = {}; |
| 7197 | cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO; |
| 7198 | cb_ci.pNext = nullptr; |
| 7199 | cb_ci.attachmentCount = 1; |
| 7200 | cb_ci.pAttachments = &att; |
| 7201 | |
| 7202 | VkGraphicsPipelineCreateInfo gp_ci = {}; |
| 7203 | gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO; |
| 7204 | gp_ci.stageCount = 2; |
| 7205 | gp_ci.pStages = shaderStages; |
| 7206 | gp_ci.pVertexInputState = &vi_ci; |
| 7207 | gp_ci.pInputAssemblyState = &ia_ci; |
| 7208 | gp_ci.pViewportState = &vp_state_ci; |
| 7209 | gp_ci.pRasterizationState = &rs_ci; |
| 7210 | gp_ci.pColorBlendState = &cb_ci; |
| 7211 | gp_ci.pDynamicState = &dyn_state_ci; |
| 7212 | gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT; |
| 7213 | gp_ci.layout = pipeline_layout; |
| 7214 | gp_ci.renderPass = renderPass(); |
| 7215 | |
| 7216 | VkPipelineCacheCreateInfo pc_ci = {}; |
| 7217 | pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO; |
| 7218 | |
| 7219 | VkPipeline pipeline; |
| 7220 | VkPipelineCache pipelineCache; |
| 7221 | |
| 7222 | err = |
| 7223 | vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache); |
| 7224 | ASSERT_VK_SUCCESS(err); |
| 7225 | err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, |
| 7226 | &gp_ci, NULL, &pipeline); |
| 7227 | |
| 7228 | m_errorMonitor->VerifyFound(); |
Tony Barbour | df4c004 | 2016-06-01 15:55:43 -0600 | [diff] [blame] | 7229 | vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL); |
Mark Young | 7394fdd | 2016-03-31 14:56:43 -0600 | [diff] [blame] | 7230 | |
| 7231 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 7232 | "Attempt to set lineWidth to 65536"); |
| 7233 | |
| 7234 | // Check too high (line width of 65536.0f). |
| 7235 | rs_ci.lineWidth = 65536.0f; |
| 7236 | |
| 7237 | err = |
| 7238 | vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache); |
| 7239 | ASSERT_VK_SUCCESS(err); |
| 7240 | err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, |
| 7241 | &gp_ci, NULL, &pipeline); |
| 7242 | |
| 7243 | m_errorMonitor->VerifyFound(); |
Tony Barbour | df4c004 | 2016-06-01 15:55:43 -0600 | [diff] [blame] | 7244 | vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL); |
Mark Young | 7394fdd | 2016-03-31 14:56:43 -0600 | [diff] [blame] | 7245 | |
| 7246 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Mark Young | 4710795 | 2016-05-02 15:59:55 -0600 | [diff] [blame] | 7247 | "Attempt to set lineWidth to -1"); |
Mark Young | 7394fdd | 2016-03-31 14:56:43 -0600 | [diff] [blame] | 7248 | |
| 7249 | dyn_state_ci.dynamicStateCount = 3; |
| 7250 | |
| 7251 | rs_ci.lineWidth = 1.0f; |
| 7252 | |
| 7253 | err = |
| 7254 | vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache); |
| 7255 | ASSERT_VK_SUCCESS(err); |
| 7256 | err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, |
| 7257 | &gp_ci, NULL, &pipeline); |
| 7258 | BeginCommandBuffer(); |
| 7259 | vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), |
| 7260 | VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline); |
| 7261 | |
| 7262 | // Check too low with dynamic setting. |
Mark Young | 4710795 | 2016-05-02 15:59:55 -0600 | [diff] [blame] | 7263 | vkCmdSetLineWidth(m_commandBuffer->GetBufferHandle(), -1.0f); |
Mark Young | 7394fdd | 2016-03-31 14:56:43 -0600 | [diff] [blame] | 7264 | m_errorMonitor->VerifyFound(); |
| 7265 | |
| 7266 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 7267 | "Attempt to set lineWidth to 65536"); |
| 7268 | |
| 7269 | // Check too high with dynamic setting. |
| 7270 | vkCmdSetLineWidth(m_commandBuffer->GetBufferHandle(), 65536.0f); |
| 7271 | m_errorMonitor->VerifyFound(); |
| 7272 | EndCommandBuffer(); |
| 7273 | |
| 7274 | vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL); |
| 7275 | vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL); |
| 7276 | vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL); |
| 7277 | vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL); |
Tony Barbour | df4c004 | 2016-06-01 15:55:43 -0600 | [diff] [blame] | 7278 | vkDestroyPipeline(m_device->device(), pipeline, NULL); |
Mark Young | 7394fdd | 2016-03-31 14:56:43 -0600 | [diff] [blame] | 7279 | } |
| 7280 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7281 | TEST_F(VkLayerTest, NullRenderPass) { |
Tobin Ehlis | 98aa0ed | 2015-06-25 16:27:19 -0600 | [diff] [blame] | 7282 | // Bind a NULL RenderPass |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7283 | m_errorMonitor->SetDesiredFailureMsg( |
| 7284 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 7285 | "You cannot use a NULL RenderPass object in vkCmdBeginRenderPass()"); |
Tobin Ehlis | 98aa0ed | 2015-06-25 16:27:19 -0600 | [diff] [blame] | 7286 | |
| 7287 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 7288 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
Tobin Ehlis | 98aa0ed | 2015-06-25 16:27:19 -0600 | [diff] [blame] | 7289 | |
Tony Barbour | fe3351b | 2015-07-28 10:17:20 -0600 | [diff] [blame] | 7290 | BeginCommandBuffer(); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7291 | // Don't care about RenderPass handle b/c error should be flagged before |
| 7292 | // that |
| 7293 | vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), NULL, |
| 7294 | VK_SUBPASS_CONTENTS_INLINE); |
Tobin Ehlis | 98aa0ed | 2015-06-25 16:27:19 -0600 | [diff] [blame] | 7295 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 7296 | m_errorMonitor->VerifyFound(); |
Tobin Ehlis | 98aa0ed | 2015-06-25 16:27:19 -0600 | [diff] [blame] | 7297 | } |
| 7298 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7299 | TEST_F(VkLayerTest, RenderPassWithinRenderPass) { |
Tobin Ehlis | af1f3a4 | 2015-06-25 15:46:59 -0600 | [diff] [blame] | 7300 | // Bind a BeginRenderPass within an active RenderPass |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7301 | m_errorMonitor->SetDesiredFailureMsg( |
| 7302 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 7303 | "It is invalid to issue this call inside an active render pass"); |
Tobin Ehlis | af1f3a4 | 2015-06-25 15:46:59 -0600 | [diff] [blame] | 7304 | |
| 7305 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 7306 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
Tobin Ehlis | af1f3a4 | 2015-06-25 15:46:59 -0600 | [diff] [blame] | 7307 | |
Tony Barbour | fe3351b | 2015-07-28 10:17:20 -0600 | [diff] [blame] | 7308 | BeginCommandBuffer(); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7309 | // Just create a dummy Renderpass that's non-NULL so we can get to the |
| 7310 | // proper error |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 7311 | VkRenderPassBeginInfo rp_begin = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7312 | rp_begin.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO; |
| 7313 | rp_begin.pNext = NULL; |
| 7314 | rp_begin.renderPass = renderPass(); |
| 7315 | rp_begin.framebuffer = framebuffer(); |
Mark Lobodzinski | 209b529 | 2015-09-17 09:44:05 -0600 | [diff] [blame] | 7316 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7317 | vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &rp_begin, |
| 7318 | VK_SUBPASS_CONTENTS_INLINE); |
Tobin Ehlis | af1f3a4 | 2015-06-25 15:46:59 -0600 | [diff] [blame] | 7319 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 7320 | m_errorMonitor->VerifyFound(); |
Tobin Ehlis | 49eb23d | 2015-05-22 12:38:55 -0600 | [diff] [blame] | 7321 | } |
| 7322 | |
Tobin Ehlis | 5a1c033 | 2016-05-31 13:59:26 -0600 | [diff] [blame] | 7323 | TEST_F(VkLayerTest, RenderPassClearOpMismatch) { |
| 7324 | TEST_DESCRIPTION("Begin a renderPass where clearValueCount is less than" |
| 7325 | "the number of renderPass attachments that use loadOp" |
| 7326 | "VK_ATTACHMENT_LOAD_OP_CLEAR."); |
| 7327 | |
| 7328 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 7329 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 7330 | |
| 7331 | // Create a renderPass with a single attachment that uses loadOp CLEAR |
| 7332 | VkAttachmentReference attach = {}; |
| 7333 | attach.layout = VK_IMAGE_LAYOUT_GENERAL; |
| 7334 | VkSubpassDescription subpass = {}; |
| 7335 | subpass.inputAttachmentCount = 1; |
| 7336 | subpass.pInputAttachments = &attach; |
| 7337 | VkRenderPassCreateInfo rpci = {}; |
| 7338 | rpci.subpassCount = 1; |
| 7339 | rpci.pSubpasses = &subpass; |
| 7340 | rpci.attachmentCount = 1; |
| 7341 | VkAttachmentDescription attach_desc = {}; |
| 7342 | attach_desc.format = VK_FORMAT_UNDEFINED; |
| 7343 | // Set loadOp to CLEAR |
| 7344 | attach_desc.loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR; |
| 7345 | rpci.pAttachments = &attach_desc; |
| 7346 | rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO; |
| 7347 | VkRenderPass rp; |
| 7348 | vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp); |
| 7349 | |
| 7350 | VkCommandBufferInheritanceInfo hinfo = {}; |
| 7351 | hinfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO; |
| 7352 | hinfo.renderPass = VK_NULL_HANDLE; |
| 7353 | hinfo.subpass = 0; |
| 7354 | hinfo.framebuffer = VK_NULL_HANDLE; |
| 7355 | hinfo.occlusionQueryEnable = VK_FALSE; |
| 7356 | hinfo.queryFlags = 0; |
| 7357 | hinfo.pipelineStatistics = 0; |
| 7358 | VkCommandBufferBeginInfo info = {}; |
| 7359 | info.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT; |
| 7360 | info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO; |
| 7361 | info.pInheritanceInfo = &hinfo; |
| 7362 | |
| 7363 | vkBeginCommandBuffer(m_commandBuffer->handle(), &info); |
| 7364 | VkRenderPassBeginInfo rp_begin = {}; |
| 7365 | rp_begin.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO; |
| 7366 | rp_begin.pNext = NULL; |
| 7367 | rp_begin.renderPass = renderPass(); |
| 7368 | rp_begin.framebuffer = framebuffer(); |
| 7369 | rp_begin.clearValueCount = 0; // Should be 1 |
| 7370 | |
| 7371 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 7372 | " has a clearValueCount of 0 but the " |
| 7373 | "actual number of attachments in " |
| 7374 | "renderPass "); |
| 7375 | |
| 7376 | vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &rp_begin, |
| 7377 | VK_SUBPASS_CONTENTS_INLINE); |
| 7378 | |
| 7379 | m_errorMonitor->VerifyFound(); |
Mark Lobodzinski | 5c70ebd | 2016-06-09 13:45:00 -0600 | [diff] [blame] | 7380 | |
| 7381 | vkDestroyRenderPass(m_device->device(), rp, NULL); |
Tobin Ehlis | 5a1c033 | 2016-05-31 13:59:26 -0600 | [diff] [blame] | 7382 | } |
| 7383 | |
Cody Northrop | 3bb4d96 | 2016-05-09 16:15:57 -0600 | [diff] [blame] | 7384 | TEST_F(VkLayerTest, EndCommandBufferWithinRenderPass) { |
| 7385 | |
| 7386 | TEST_DESCRIPTION("End a command buffer with an active render pass"); |
| 7387 | |
| 7388 | m_errorMonitor->SetDesiredFailureMsg( |
| 7389 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 7390 | "It is invalid to issue this call inside an active render pass"); |
| 7391 | |
| 7392 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 7393 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 7394 | |
| 7395 | // The framework's BeginCommandBuffer calls CreateRenderPass |
| 7396 | BeginCommandBuffer(); |
| 7397 | |
| 7398 | // Call directly into vkEndCommandBuffer instead of the |
| 7399 | // the framework's EndCommandBuffer, which inserts a |
| 7400 | // vkEndRenderPass |
| 7401 | vkEndCommandBuffer(m_commandBuffer->GetBufferHandle()); |
| 7402 | |
| 7403 | m_errorMonitor->VerifyFound(); |
| 7404 | |
| 7405 | // TODO: Add test for VK_COMMAND_BUFFER_LEVEL_SECONDARY |
| 7406 | // TODO: Add test for VK_COMMAND_BUFFER_USAGE_RENDER_PASS_CONTINUE_BIT |
| 7407 | } |
| 7408 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7409 | TEST_F(VkLayerTest, FillBufferWithinRenderPass) { |
Mark Lobodzinski | d563950 | 2015-09-24 09:51:47 -0600 | [diff] [blame] | 7410 | // Call CmdFillBuffer within an active renderpass |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7411 | m_errorMonitor->SetDesiredFailureMsg( |
| 7412 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 7413 | "It is invalid to issue this call inside an active render pass"); |
Mark Lobodzinski | d563950 | 2015-09-24 09:51:47 -0600 | [diff] [blame] | 7414 | |
| 7415 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 7416 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
Mark Lobodzinski | d563950 | 2015-09-24 09:51:47 -0600 | [diff] [blame] | 7417 | |
| 7418 | // Renderpass is started here |
| 7419 | BeginCommandBuffer(); |
| 7420 | |
| 7421 | VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 7422 | vk_testing::Buffer dstBuffer; |
| 7423 | dstBuffer.init_as_dst(*m_device, (VkDeviceSize)1024, reqs); |
Mark Lobodzinski | d563950 | 2015-09-24 09:51:47 -0600 | [diff] [blame] | 7424 | |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 7425 | m_commandBuffer->FillBuffer(dstBuffer.handle(), 0, 4, 0x11111111); |
Mark Lobodzinski | d563950 | 2015-09-24 09:51:47 -0600 | [diff] [blame] | 7426 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 7427 | m_errorMonitor->VerifyFound(); |
Mark Lobodzinski | d563950 | 2015-09-24 09:51:47 -0600 | [diff] [blame] | 7428 | } |
| 7429 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7430 | TEST_F(VkLayerTest, UpdateBufferWithinRenderPass) { |
Mark Lobodzinski | d563950 | 2015-09-24 09:51:47 -0600 | [diff] [blame] | 7431 | // Call CmdUpdateBuffer within an active renderpass |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7432 | m_errorMonitor->SetDesiredFailureMsg( |
| 7433 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 7434 | "It is invalid to issue this call inside an active render pass"); |
Mark Lobodzinski | d563950 | 2015-09-24 09:51:47 -0600 | [diff] [blame] | 7435 | |
| 7436 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 7437 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
Mark Lobodzinski | d563950 | 2015-09-24 09:51:47 -0600 | [diff] [blame] | 7438 | |
| 7439 | // Renderpass is started here |
| 7440 | BeginCommandBuffer(); |
| 7441 | |
| 7442 | VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 7443 | vk_testing::Buffer dstBuffer; |
| 7444 | dstBuffer.init_as_dst(*m_device, (VkDeviceSize)1024, reqs); |
Mark Lobodzinski | d563950 | 2015-09-24 09:51:47 -0600 | [diff] [blame] | 7445 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7446 | VkDeviceSize dstOffset = 0; |
| 7447 | VkDeviceSize dataSize = 1024; |
| 7448 | const uint32_t *pData = NULL; |
Mark Lobodzinski | d563950 | 2015-09-24 09:51:47 -0600 | [diff] [blame] | 7449 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7450 | vkCmdUpdateBuffer(m_commandBuffer->GetBufferHandle(), dstBuffer.handle(), |
| 7451 | dstOffset, dataSize, pData); |
Mark Lobodzinski | d563950 | 2015-09-24 09:51:47 -0600 | [diff] [blame] | 7452 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 7453 | m_errorMonitor->VerifyFound(); |
Mark Lobodzinski | d563950 | 2015-09-24 09:51:47 -0600 | [diff] [blame] | 7454 | } |
| 7455 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7456 | TEST_F(VkLayerTest, ClearColorImageWithinRenderPass) { |
Mark Lobodzinski | d563950 | 2015-09-24 09:51:47 -0600 | [diff] [blame] | 7457 | // Call CmdClearColorImage within an active RenderPass |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7458 | m_errorMonitor->SetDesiredFailureMsg( |
| 7459 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 7460 | "It is invalid to issue this call inside an active render pass"); |
Mark Lobodzinski | d563950 | 2015-09-24 09:51:47 -0600 | [diff] [blame] | 7461 | |
| 7462 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 7463 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
Mark Lobodzinski | d563950 | 2015-09-24 09:51:47 -0600 | [diff] [blame] | 7464 | |
| 7465 | // Renderpass is started here |
| 7466 | BeginCommandBuffer(); |
| 7467 | |
Michael Lentine | 0a369f6 | 2016-02-03 16:51:46 -0600 | [diff] [blame] | 7468 | VkClearColorValue clear_color; |
| 7469 | memset(clear_color.uint32, 0, sizeof(uint32_t) * 4); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7470 | VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT; |
| 7471 | const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM; |
| 7472 | const int32_t tex_width = 32; |
| 7473 | const int32_t tex_height = 32; |
| 7474 | VkImageCreateInfo image_create_info = {}; |
| 7475 | image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO; |
| 7476 | image_create_info.pNext = NULL; |
| 7477 | image_create_info.imageType = VK_IMAGE_TYPE_2D; |
| 7478 | image_create_info.format = tex_format; |
| 7479 | image_create_info.extent.width = tex_width; |
| 7480 | image_create_info.extent.height = tex_height; |
| 7481 | image_create_info.extent.depth = 1; |
| 7482 | image_create_info.mipLevels = 1; |
| 7483 | image_create_info.arrayLayers = 1; |
| 7484 | image_create_info.samples = VK_SAMPLE_COUNT_1_BIT; |
| 7485 | image_create_info.tiling = VK_IMAGE_TILING_LINEAR; |
| 7486 | image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT; |
Mark Lobodzinski | d563950 | 2015-09-24 09:51:47 -0600 | [diff] [blame] | 7487 | |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 7488 | vk_testing::Image dstImage; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7489 | dstImage.init(*m_device, (const VkImageCreateInfo &)image_create_info, |
| 7490 | reqs); |
Mark Lobodzinski | d563950 | 2015-09-24 09:51:47 -0600 | [diff] [blame] | 7491 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7492 | const VkImageSubresourceRange range = vk_testing::Image::subresource_range( |
| 7493 | image_create_info, VK_IMAGE_ASPECT_COLOR_BIT); |
Mark Lobodzinski | d563950 | 2015-09-24 09:51:47 -0600 | [diff] [blame] | 7494 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7495 | vkCmdClearColorImage(m_commandBuffer->GetBufferHandle(), dstImage.handle(), |
| 7496 | VK_IMAGE_LAYOUT_GENERAL, &clear_color, 1, &range); |
Mark Lobodzinski | d563950 | 2015-09-24 09:51:47 -0600 | [diff] [blame] | 7497 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 7498 | m_errorMonitor->VerifyFound(); |
Mark Lobodzinski | d563950 | 2015-09-24 09:51:47 -0600 | [diff] [blame] | 7499 | } |
| 7500 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7501 | TEST_F(VkLayerTest, ClearDepthStencilImageWithinRenderPass) { |
Mark Lobodzinski | d563950 | 2015-09-24 09:51:47 -0600 | [diff] [blame] | 7502 | // Call CmdClearDepthStencilImage within an active RenderPass |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7503 | m_errorMonitor->SetDesiredFailureMsg( |
| 7504 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 7505 | "It is invalid to issue this call inside an active render pass"); |
Mark Lobodzinski | d563950 | 2015-09-24 09:51:47 -0600 | [diff] [blame] | 7506 | |
| 7507 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 7508 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
Mark Lobodzinski | d563950 | 2015-09-24 09:51:47 -0600 | [diff] [blame] | 7509 | |
| 7510 | // Renderpass is started here |
| 7511 | BeginCommandBuffer(); |
| 7512 | |
| 7513 | VkClearDepthStencilValue clear_value = {0}; |
Dustin Graves | a2e5c94 | 2016-02-11 18:28:06 -0700 | [diff] [blame] | 7514 | VkMemoryPropertyFlags reqs = 0; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7515 | VkImageCreateInfo image_create_info = vk_testing::Image::create_info(); |
| 7516 | image_create_info.imageType = VK_IMAGE_TYPE_2D; |
| 7517 | image_create_info.format = VK_FORMAT_D24_UNORM_S8_UINT; |
| 7518 | image_create_info.extent.width = 64; |
| 7519 | image_create_info.extent.height = 64; |
| 7520 | image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL; |
| 7521 | image_create_info.usage = VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT; |
Mark Lobodzinski | d563950 | 2015-09-24 09:51:47 -0600 | [diff] [blame] | 7522 | |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 7523 | vk_testing::Image dstImage; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7524 | dstImage.init(*m_device, (const VkImageCreateInfo &)image_create_info, |
| 7525 | reqs); |
Mark Lobodzinski | d563950 | 2015-09-24 09:51:47 -0600 | [diff] [blame] | 7526 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7527 | const VkImageSubresourceRange range = vk_testing::Image::subresource_range( |
| 7528 | image_create_info, VK_IMAGE_ASPECT_DEPTH_BIT); |
Mark Lobodzinski | d563950 | 2015-09-24 09:51:47 -0600 | [diff] [blame] | 7529 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7530 | vkCmdClearDepthStencilImage( |
| 7531 | m_commandBuffer->GetBufferHandle(), dstImage.handle(), |
| 7532 | VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL, &clear_value, 1, |
| 7533 | &range); |
Mark Lobodzinski | d563950 | 2015-09-24 09:51:47 -0600 | [diff] [blame] | 7534 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 7535 | m_errorMonitor->VerifyFound(); |
Mark Lobodzinski | d563950 | 2015-09-24 09:51:47 -0600 | [diff] [blame] | 7536 | } |
| 7537 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7538 | TEST_F(VkLayerTest, ClearColorAttachmentsOutsideRenderPass) { |
Courtney Goeltzenleuchter | c9323e0 | 2015-10-15 16:51:05 -0600 | [diff] [blame] | 7539 | // Call CmdClearAttachmentss outside of an active RenderPass |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7540 | VkResult err; |
Mark Lobodzinski | d563950 | 2015-09-24 09:51:47 -0600 | [diff] [blame] | 7541 | |
Courtney Goeltzenleuchter | 7415d5a | 2015-12-09 15:48:16 -0700 | [diff] [blame] | 7542 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7543 | "vkCmdClearAttachments: This call " |
| 7544 | "must be issued inside an active " |
| 7545 | "render pass"); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 7546 | |
Mark Lobodzinski | d563950 | 2015-09-24 09:51:47 -0600 | [diff] [blame] | 7547 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 7548 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
Mark Lobodzinski | d563950 | 2015-09-24 09:51:47 -0600 | [diff] [blame] | 7549 | |
| 7550 | // Start no RenderPass |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 7551 | err = m_commandBuffer->BeginCommandBuffer(); |
Mark Lobodzinski | d563950 | 2015-09-24 09:51:47 -0600 | [diff] [blame] | 7552 | ASSERT_VK_SUCCESS(err); |
| 7553 | |
Courtney Goeltzenleuchter | c9323e0 | 2015-10-15 16:51:05 -0600 | [diff] [blame] | 7554 | VkClearAttachment color_attachment; |
| 7555 | color_attachment.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; |
| 7556 | color_attachment.clearValue.color.float32[0] = 0; |
| 7557 | color_attachment.clearValue.color.float32[1] = 0; |
| 7558 | color_attachment.clearValue.color.float32[2] = 0; |
| 7559 | color_attachment.clearValue.color.float32[3] = 0; |
| 7560 | color_attachment.colorAttachment = 0; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7561 | VkClearRect clear_rect = {{{0, 0}, {32, 32}}}; |
| 7562 | vkCmdClearAttachments(m_commandBuffer->GetBufferHandle(), 1, |
| 7563 | &color_attachment, 1, &clear_rect); |
Mark Lobodzinski | d563950 | 2015-09-24 09:51:47 -0600 | [diff] [blame] | 7564 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 7565 | m_errorMonitor->VerifyFound(); |
Mark Lobodzinski | d563950 | 2015-09-24 09:51:47 -0600 | [diff] [blame] | 7566 | } |
| 7567 | |
Karl Schultz | 9e66a29 | 2016-04-21 15:57:51 -0600 | [diff] [blame] | 7568 | TEST_F(VkLayerTest, BufferMemoryBarrierNoBuffer) { |
| 7569 | // Try to add a buffer memory barrier with no buffer. |
| 7570 | m_errorMonitor->SetDesiredFailureMsg( |
| 7571 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 7572 | "required parameter pBufferMemoryBarriers[i].buffer specified as VK_NULL_HANDLE"); |
| 7573 | |
| 7574 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 7575 | BeginCommandBuffer(); |
| 7576 | |
| 7577 | VkBufferMemoryBarrier buf_barrier = {}; |
| 7578 | buf_barrier.sType = VK_STRUCTURE_TYPE_BUFFER_MEMORY_BARRIER; |
| 7579 | buf_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT; |
| 7580 | buf_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT; |
| 7581 | buf_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED; |
| 7582 | buf_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED; |
| 7583 | buf_barrier.buffer = VK_NULL_HANDLE; |
| 7584 | buf_barrier.offset = 0; |
| 7585 | buf_barrier.size = VK_WHOLE_SIZE; |
| 7586 | vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), |
| 7587 | VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, |
| 7588 | 0, 0, nullptr, 1, &buf_barrier, 0, nullptr); |
| 7589 | |
| 7590 | m_errorMonitor->VerifyFound(); |
| 7591 | } |
| 7592 | |
Tony Barbour | 7fd5c0f | 2016-05-03 16:11:53 -0600 | [diff] [blame] | 7593 | TEST_F(VkLayerTest, InvalidBarriers) { |
| 7594 | TEST_DESCRIPTION("A variety of ways to get VK_INVALID_BARRIER "); |
| 7595 | |
| 7596 | m_errorMonitor->SetDesiredFailureMsg( |
| 7597 | VK_DEBUG_REPORT_ERROR_BIT_EXT, "Barriers cannot be set during subpass"); |
| 7598 | |
| 7599 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 7600 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 7601 | |
| 7602 | VkMemoryBarrier mem_barrier = {}; |
| 7603 | mem_barrier.sType = VK_STRUCTURE_TYPE_MEMORY_BARRIER; |
| 7604 | mem_barrier.pNext = NULL; |
| 7605 | mem_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT; |
| 7606 | mem_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT; |
| 7607 | BeginCommandBuffer(); |
| 7608 | // BeginCommandBuffer() starts a render pass |
| 7609 | vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), |
| 7610 | VK_PIPELINE_STAGE_HOST_BIT, |
| 7611 | VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 1, |
| 7612 | &mem_barrier, 0, nullptr, 0, nullptr); |
| 7613 | m_errorMonitor->VerifyFound(); |
| 7614 | |
| 7615 | m_errorMonitor->SetDesiredFailureMsg( |
| 7616 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 7617 | "Image Layout cannot be transitioned to UNDEFINED"); |
| 7618 | VkImageObj image(m_device); |
| 7619 | image.init(128, 128, VK_FORMAT_B8G8R8A8_UNORM, |
| 7620 | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0); |
| 7621 | ASSERT_TRUE(image.initialized()); |
| 7622 | VkImageMemoryBarrier img_barrier = {}; |
| 7623 | img_barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER; |
| 7624 | img_barrier.pNext = NULL; |
| 7625 | img_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT; |
| 7626 | img_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT; |
| 7627 | img_barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL; |
| 7628 | // New layout can't be UNDEFINED |
| 7629 | img_barrier.newLayout = VK_IMAGE_LAYOUT_UNDEFINED; |
| 7630 | img_barrier.image = image.handle(); |
| 7631 | img_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED; |
| 7632 | img_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED; |
| 7633 | img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; |
| 7634 | img_barrier.subresourceRange.baseArrayLayer = 0; |
| 7635 | img_barrier.subresourceRange.baseMipLevel = 0; |
| 7636 | img_barrier.subresourceRange.layerCount = 1; |
| 7637 | img_barrier.subresourceRange.levelCount = 1; |
| 7638 | vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), |
| 7639 | VK_PIPELINE_STAGE_HOST_BIT, |
| 7640 | VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0, nullptr, 0, |
| 7641 | nullptr, 1, &img_barrier); |
| 7642 | m_errorMonitor->VerifyFound(); |
| 7643 | img_barrier.newLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL; |
| 7644 | |
| 7645 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 7646 | "Subresource must have the sum of the " |
| 7647 | "baseArrayLayer"); |
| 7648 | // baseArrayLayer + layerCount must be <= image's arrayLayers |
| 7649 | img_barrier.subresourceRange.baseArrayLayer = 1; |
| 7650 | vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), |
| 7651 | VK_PIPELINE_STAGE_HOST_BIT, |
| 7652 | VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0, nullptr, 0, |
| 7653 | nullptr, 1, &img_barrier); |
| 7654 | m_errorMonitor->VerifyFound(); |
| 7655 | img_barrier.subresourceRange.baseArrayLayer = 0; |
| 7656 | |
| 7657 | m_errorMonitor->SetDesiredFailureMsg( |
| 7658 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 7659 | "Subresource must have the sum of the baseMipLevel"); |
| 7660 | // baseMipLevel + levelCount must be <= image's mipLevels |
| 7661 | img_barrier.subresourceRange.baseMipLevel = 1; |
| 7662 | vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), |
| 7663 | VK_PIPELINE_STAGE_HOST_BIT, |
| 7664 | VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0, nullptr, 0, |
| 7665 | nullptr, 1, &img_barrier); |
| 7666 | m_errorMonitor->VerifyFound(); |
| 7667 | img_barrier.subresourceRange.baseMipLevel = 0; |
| 7668 | |
| 7669 | m_errorMonitor->SetDesiredFailureMsg( |
| 7670 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 7671 | "Buffer Barriers cannot be used during a render pass"); |
| 7672 | vk_testing::Buffer buffer; |
| 7673 | buffer.init(*m_device, 256); |
| 7674 | VkBufferMemoryBarrier buf_barrier = {}; |
| 7675 | buf_barrier.sType = VK_STRUCTURE_TYPE_BUFFER_MEMORY_BARRIER; |
| 7676 | buf_barrier.pNext = NULL; |
| 7677 | buf_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT; |
| 7678 | buf_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT; |
| 7679 | buf_barrier.buffer = buffer.handle(); |
| 7680 | buf_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED; |
| 7681 | buf_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED; |
| 7682 | buf_barrier.offset = 0; |
| 7683 | buf_barrier.size = VK_WHOLE_SIZE; |
| 7684 | // Can't send buffer barrier during a render pass |
| 7685 | vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), |
| 7686 | VK_PIPELINE_STAGE_HOST_BIT, |
| 7687 | VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0, nullptr, 1, |
| 7688 | &buf_barrier, 0, nullptr); |
| 7689 | m_errorMonitor->VerifyFound(); |
| 7690 | vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle()); |
| 7691 | |
| 7692 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 7693 | "which is not less than total size"); |
| 7694 | buf_barrier.offset = 257; |
| 7695 | // Offset greater than total size |
| 7696 | vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), |
| 7697 | VK_PIPELINE_STAGE_HOST_BIT, |
| 7698 | VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0, nullptr, 1, |
| 7699 | &buf_barrier, 0, nullptr); |
| 7700 | m_errorMonitor->VerifyFound(); |
| 7701 | buf_barrier.offset = 0; |
| 7702 | |
| 7703 | m_errorMonitor->SetDesiredFailureMsg( |
| 7704 | VK_DEBUG_REPORT_ERROR_BIT_EXT, "whose sum is greater than total size"); |
| 7705 | buf_barrier.size = 257; |
| 7706 | // Size greater than total size |
| 7707 | vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), |
| 7708 | VK_PIPELINE_STAGE_HOST_BIT, |
| 7709 | VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0, nullptr, 1, |
| 7710 | &buf_barrier, 0, nullptr); |
| 7711 | m_errorMonitor->VerifyFound(); |
| 7712 | buf_barrier.size = VK_WHOLE_SIZE; |
| 7713 | |
| 7714 | m_errorMonitor->SetDesiredFailureMsg( |
| 7715 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 7716 | "Image is a depth and stencil format and thus must " |
| 7717 | "have both VK_IMAGE_ASPECT_DEPTH_BIT and " |
| 7718 | "VK_IMAGE_ASPECT_STENCIL_BIT set."); |
| 7719 | VkDepthStencilObj ds_image(m_device); |
| 7720 | ds_image.Init(m_device, 128, 128, VK_FORMAT_D24_UNORM_S8_UINT); |
| 7721 | ASSERT_TRUE(ds_image.initialized()); |
| 7722 | img_barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL; |
| 7723 | img_barrier.newLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL; |
| 7724 | img_barrier.image = ds_image.handle(); |
| 7725 | // Leave aspectMask at COLOR on purpose |
| 7726 | vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), |
| 7727 | VK_PIPELINE_STAGE_HOST_BIT, |
| 7728 | VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0, nullptr, 0, |
| 7729 | nullptr, 1, &img_barrier); |
| 7730 | m_errorMonitor->VerifyFound(); |
| 7731 | } |
| 7732 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7733 | TEST_F(VkLayerTest, IdxBufferAlignmentError) { |
Tobin Ehlis | c4c2318 | 2015-09-17 12:24:13 -0600 | [diff] [blame] | 7734 | // Bind a BeginRenderPass within an active RenderPass |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7735 | VkResult err; |
Tobin Ehlis | c4c2318 | 2015-09-17 12:24:13 -0600 | [diff] [blame] | 7736 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7737 | m_errorMonitor->SetDesiredFailureMsg( |
| 7738 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 7739 | "vkCmdBindIndexBuffer() offset (0x7) does not fall on "); |
| 7740 | |
Tobin Ehlis | c4c2318 | 2015-09-17 12:24:13 -0600 | [diff] [blame] | 7741 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 7742 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
Tobin Ehlis | c4c2318 | 2015-09-17 12:24:13 -0600 | [diff] [blame] | 7743 | uint32_t qfi = 0; |
| 7744 | VkBufferCreateInfo buffCI = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7745 | buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO; |
| 7746 | buffCI.size = 1024; |
| 7747 | buffCI.usage = VK_BUFFER_USAGE_INDEX_BUFFER_BIT; |
| 7748 | buffCI.queueFamilyIndexCount = 1; |
| 7749 | buffCI.pQueueFamilyIndices = &qfi; |
Tobin Ehlis | c4c2318 | 2015-09-17 12:24:13 -0600 | [diff] [blame] | 7750 | |
| 7751 | VkBuffer ib; |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 7752 | err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &ib); |
Tobin Ehlis | c4c2318 | 2015-09-17 12:24:13 -0600 | [diff] [blame] | 7753 | ASSERT_VK_SUCCESS(err); |
| 7754 | |
| 7755 | BeginCommandBuffer(); |
| 7756 | ASSERT_VK_SUCCESS(err); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7757 | // vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), |
| 7758 | // VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle()); |
Tobin Ehlis | c4c2318 | 2015-09-17 12:24:13 -0600 | [diff] [blame] | 7759 | // 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] | 7760 | vkCmdBindIndexBuffer(m_commandBuffer->GetBufferHandle(), ib, 7, |
| 7761 | VK_INDEX_TYPE_UINT16); |
Tobin Ehlis | c4c2318 | 2015-09-17 12:24:13 -0600 | [diff] [blame] | 7762 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 7763 | m_errorMonitor->VerifyFound(); |
Mike Stroyan | d1c84a5 | 2015-08-18 14:40:24 -0600 | [diff] [blame] | 7764 | |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 7765 | vkDestroyBuffer(m_device->device(), ib, NULL); |
Tobin Ehlis | c4c2318 | 2015-09-17 12:24:13 -0600 | [diff] [blame] | 7766 | } |
| 7767 | |
Mark Lobodzinski | 52a6e7d | 2016-02-25 15:09:52 -0700 | [diff] [blame] | 7768 | TEST_F(VkLayerTest, InvalidQueueFamilyIndex) { |
| 7769 | // Create an out-of-range queueFamilyIndex |
| 7770 | m_errorMonitor->SetDesiredFailureMsg( |
| 7771 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Dustin Graves | de62853 | 2016-04-21 16:30:17 -0600 | [diff] [blame] | 7772 | "vkCreateBuffer: pCreateInfo->pQueueFamilyIndices[0] (777) must be one " |
| 7773 | "of the indices specified when the device was created, via the " |
| 7774 | "VkDeviceQueueCreateInfo structure."); |
Mark Lobodzinski | 52a6e7d | 2016-02-25 15:09:52 -0700 | [diff] [blame] | 7775 | |
| 7776 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 7777 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 7778 | VkBufferCreateInfo buffCI = {}; |
| 7779 | buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO; |
| 7780 | buffCI.size = 1024; |
| 7781 | buffCI.usage = VK_BUFFER_USAGE_INDEX_BUFFER_BIT; |
| 7782 | buffCI.queueFamilyIndexCount = 1; |
| 7783 | // Introduce failure by specifying invalid queue_family_index |
| 7784 | uint32_t qfi = 777; |
| 7785 | buffCI.pQueueFamilyIndices = &qfi; |
Tobin Ehlis | 24aab04 | 2016-03-24 10:54:18 -0600 | [diff] [blame] | 7786 | buffCI.sharingMode = VK_SHARING_MODE_CONCURRENT; // qfi only matters in CONCURRENT mode |
Mark Lobodzinski | 52a6e7d | 2016-02-25 15:09:52 -0700 | [diff] [blame] | 7787 | |
| 7788 | VkBuffer ib; |
| 7789 | vkCreateBuffer(m_device->device(), &buffCI, NULL, &ib); |
| 7790 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 7791 | m_errorMonitor->VerifyFound(); |
Tony Barbour | df4c004 | 2016-06-01 15:55:43 -0600 | [diff] [blame] | 7792 | vkDestroyBuffer(m_device->device(), ib, NULL); |
Mark Lobodzinski | 52a6e7d | 2016-02-25 15:09:52 -0700 | [diff] [blame] | 7793 | } |
| 7794 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7795 | TEST_F(VkLayerTest, ExecuteCommandsPrimaryCB) { |
| 7796 | // Attempt vkCmdExecuteCommands w/ a primary cmd buffer (should only be |
| 7797 | // secondary) |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 7798 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7799 | m_errorMonitor->SetDesiredFailureMsg( |
| 7800 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 7801 | "vkCmdExecuteCommands() called w/ Primary Cmd Buffer "); |
Tobin Ehlis | 4b34ddc | 2015-09-17 14:18:16 -0600 | [diff] [blame] | 7802 | |
| 7803 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 7804 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
Tobin Ehlis | 4b34ddc | 2015-09-17 14:18:16 -0600 | [diff] [blame] | 7805 | |
| 7806 | BeginCommandBuffer(); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7807 | // ASSERT_VK_SUCCESS(err); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 7808 | VkCommandBuffer primCB = m_commandBuffer->GetBufferHandle(); |
| 7809 | vkCmdExecuteCommands(m_commandBuffer->GetBufferHandle(), 1, &primCB); |
Tobin Ehlis | 4b34ddc | 2015-09-17 14:18:16 -0600 | [diff] [blame] | 7810 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 7811 | m_errorMonitor->VerifyFound(); |
Tobin Ehlis | 4b34ddc | 2015-09-17 14:18:16 -0600 | [diff] [blame] | 7812 | } |
| 7813 | |
Tobin Ehlis | 17826bd | 2016-05-25 11:12:50 -0600 | [diff] [blame] | 7814 | TEST_F(VkLayerTest, DSUsageBitsErrors) { |
| 7815 | TEST_DESCRIPTION("Attempt to update descriptor sets for images and buffers " |
| 7816 | "that do not have correct usage bits sets."); |
| 7817 | VkResult err; |
| 7818 | |
| 7819 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 7820 | VkDescriptorPoolSize ds_type_count[VK_DESCRIPTOR_TYPE_RANGE_SIZE] = {}; |
| 7821 | for (uint32_t i = 0; i < VK_DESCRIPTOR_TYPE_RANGE_SIZE; ++i) { |
| 7822 | ds_type_count[i].type = VkDescriptorType(i); |
| 7823 | ds_type_count[i].descriptorCount = 1; |
| 7824 | } |
| 7825 | VkDescriptorPoolCreateInfo ds_pool_ci = {}; |
| 7826 | ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO; |
| 7827 | ds_pool_ci.pNext = NULL; |
| 7828 | ds_pool_ci.maxSets = VK_DESCRIPTOR_TYPE_RANGE_SIZE; |
| 7829 | ds_pool_ci.poolSizeCount = VK_DESCRIPTOR_TYPE_RANGE_SIZE; |
| 7830 | ds_pool_ci.pPoolSizes = ds_type_count; |
| 7831 | |
| 7832 | VkDescriptorPool ds_pool; |
| 7833 | err = |
| 7834 | vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool); |
| 7835 | ASSERT_VK_SUCCESS(err); |
| 7836 | |
| 7837 | // Create 10 layouts where each has a single descriptor of different type |
| 7838 | VkDescriptorSetLayoutBinding dsl_binding[VK_DESCRIPTOR_TYPE_RANGE_SIZE] = |
| 7839 | {}; |
| 7840 | for (uint32_t i = 0; i < VK_DESCRIPTOR_TYPE_RANGE_SIZE; ++i) { |
| 7841 | dsl_binding[i].binding = 0; |
| 7842 | dsl_binding[i].descriptorType = VkDescriptorType(i); |
| 7843 | dsl_binding[i].descriptorCount = 1; |
| 7844 | dsl_binding[i].stageFlags = VK_SHADER_STAGE_ALL; |
| 7845 | dsl_binding[i].pImmutableSamplers = NULL; |
| 7846 | } |
| 7847 | |
| 7848 | VkDescriptorSetLayoutCreateInfo ds_layout_ci = {}; |
| 7849 | ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO; |
| 7850 | ds_layout_ci.pNext = NULL; |
| 7851 | ds_layout_ci.bindingCount = 1; |
| 7852 | VkDescriptorSetLayout ds_layouts[VK_DESCRIPTOR_TYPE_RANGE_SIZE]; |
| 7853 | for (uint32_t i = 0; i < VK_DESCRIPTOR_TYPE_RANGE_SIZE; ++i) { |
| 7854 | ds_layout_ci.pBindings = dsl_binding + i; |
| 7855 | err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, |
| 7856 | NULL, ds_layouts + i); |
| 7857 | ASSERT_VK_SUCCESS(err); |
| 7858 | } |
| 7859 | VkDescriptorSet descriptor_sets[VK_DESCRIPTOR_TYPE_RANGE_SIZE] = {}; |
| 7860 | VkDescriptorSetAllocateInfo alloc_info = {}; |
| 7861 | alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO; |
| 7862 | alloc_info.descriptorSetCount = VK_DESCRIPTOR_TYPE_RANGE_SIZE; |
| 7863 | alloc_info.descriptorPool = ds_pool; |
| 7864 | alloc_info.pSetLayouts = ds_layouts; |
| 7865 | err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, |
| 7866 | descriptor_sets); |
| 7867 | ASSERT_VK_SUCCESS(err); |
| 7868 | |
| 7869 | // Create a buffer & bufferView to be used for invalid updates |
| 7870 | VkBufferCreateInfo buff_ci = {}; |
| 7871 | buff_ci.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO; |
| 7872 | // This usage is not valid for any descriptor type |
| 7873 | buff_ci.usage = VK_BUFFER_USAGE_TRANSFER_SRC_BIT; |
| 7874 | buff_ci.size = 256; |
| 7875 | buff_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE; |
| 7876 | VkBuffer buffer; |
| 7877 | err = vkCreateBuffer(m_device->device(), &buff_ci, NULL, &buffer); |
| 7878 | ASSERT_VK_SUCCESS(err); |
| 7879 | |
| 7880 | VkBufferViewCreateInfo buff_view_ci = {}; |
| 7881 | buff_view_ci.sType = VK_STRUCTURE_TYPE_BUFFER_VIEW_CREATE_INFO; |
| 7882 | buff_view_ci.buffer = buffer; |
| 7883 | buff_view_ci.format = VK_FORMAT_R8_UNORM; |
| 7884 | buff_view_ci.range = VK_WHOLE_SIZE; |
| 7885 | VkBufferView buff_view; |
| 7886 | err = |
| 7887 | vkCreateBufferView(m_device->device(), &buff_view_ci, NULL, &buff_view); |
| 7888 | ASSERT_VK_SUCCESS(err); |
| 7889 | |
| 7890 | // Create an image to be used for invalid updates |
| 7891 | VkImageCreateInfo image_ci = {}; |
| 7892 | image_ci.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO; |
| 7893 | image_ci.imageType = VK_IMAGE_TYPE_2D; |
| 7894 | image_ci.format = VK_FORMAT_R8G8B8A8_UNORM; |
| 7895 | image_ci.extent.width = 64; |
| 7896 | image_ci.extent.height = 64; |
| 7897 | image_ci.extent.depth = 1; |
| 7898 | image_ci.mipLevels = 1; |
| 7899 | image_ci.arrayLayers = 1; |
| 7900 | image_ci.samples = VK_SAMPLE_COUNT_1_BIT; |
| 7901 | image_ci.tiling = VK_IMAGE_TILING_LINEAR; |
| 7902 | image_ci.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED; |
| 7903 | // This usage is not valid for any descriptor type |
| 7904 | image_ci.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT; |
| 7905 | image_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE; |
| 7906 | VkImage image; |
| 7907 | err = vkCreateImage(m_device->device(), &image_ci, NULL, &image); |
| 7908 | ASSERT_VK_SUCCESS(err); |
| 7909 | // Bind memory to image |
| 7910 | VkMemoryRequirements mem_reqs; |
| 7911 | VkDeviceMemory image_mem; |
| 7912 | bool pass; |
| 7913 | VkMemoryAllocateInfo mem_alloc = {}; |
| 7914 | mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO; |
| 7915 | mem_alloc.pNext = NULL; |
| 7916 | mem_alloc.allocationSize = 0; |
| 7917 | mem_alloc.memoryTypeIndex = 0; |
| 7918 | vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs); |
| 7919 | mem_alloc.allocationSize = mem_reqs.size; |
| 7920 | pass = |
| 7921 | m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0); |
| 7922 | ASSERT_TRUE(pass); |
| 7923 | err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &image_mem); |
| 7924 | ASSERT_VK_SUCCESS(err); |
| 7925 | err = vkBindImageMemory(m_device->device(), image, image_mem, 0); |
| 7926 | ASSERT_VK_SUCCESS(err); |
| 7927 | // Now create view for image |
| 7928 | VkImageViewCreateInfo image_view_ci = {}; |
| 7929 | image_view_ci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO; |
| 7930 | image_view_ci.image = image; |
| 7931 | image_view_ci.format = VK_FORMAT_R8G8B8A8_UNORM; |
| 7932 | image_view_ci.viewType = VK_IMAGE_VIEW_TYPE_2D; |
| 7933 | image_view_ci.subresourceRange.layerCount = 1; |
| 7934 | image_view_ci.subresourceRange.baseArrayLayer = 0; |
| 7935 | image_view_ci.subresourceRange.levelCount = 1; |
| 7936 | image_view_ci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; |
| 7937 | VkImageView image_view; |
| 7938 | err = vkCreateImageView(m_device->device(), &image_view_ci, NULL, |
| 7939 | &image_view); |
| 7940 | ASSERT_VK_SUCCESS(err); |
| 7941 | |
| 7942 | VkDescriptorBufferInfo buff_info = {}; |
| 7943 | buff_info.buffer = buffer; |
| 7944 | VkDescriptorImageInfo img_info = {}; |
| 7945 | img_info.imageView = image_view; |
| 7946 | VkWriteDescriptorSet descriptor_write = {}; |
| 7947 | descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET; |
| 7948 | descriptor_write.dstBinding = 0; |
| 7949 | descriptor_write.descriptorCount = 1; |
| 7950 | descriptor_write.pTexelBufferView = &buff_view; |
| 7951 | descriptor_write.pBufferInfo = &buff_info; |
| 7952 | descriptor_write.pImageInfo = &img_info; |
| 7953 | |
| 7954 | // These error messages align with VkDescriptorType struct |
| 7955 | const char *error_msgs[] = { |
| 7956 | "", // placeholder, no error for SAMPLER descriptor |
| 7957 | " does not have VK_IMAGE_USAGE_SAMPLED_BIT set.", |
| 7958 | " does not have VK_IMAGE_USAGE_SAMPLED_BIT set.", |
| 7959 | " does not have VK_IMAGE_USAGE_STORAGE_BIT set.", |
| 7960 | " does not have VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT set.", |
| 7961 | " does not have VK_BUFFER_USAGE_STORAGE_TEXEL_BUFFER_BIT set.", |
| 7962 | " does not have VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT set.", |
| 7963 | " does not have VK_BUFFER_USAGE_STORAGE_BUFFER_BIT set.", |
| 7964 | " does not have VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT set.", |
| 7965 | " does not have VK_BUFFER_USAGE_STORAGE_BUFFER_BIT set.", |
| 7966 | " does not have VK_IMAGE_USAGE_INPUT_ATTACHMENT_BIT set."}; |
| 7967 | // Start loop at 1 as SAMPLER desc type has no usage bit error |
| 7968 | for (uint32_t i = 1; i < VK_DESCRIPTOR_TYPE_RANGE_SIZE; ++i) { |
| 7969 | descriptor_write.descriptorType = VkDescriptorType(i); |
| 7970 | descriptor_write.dstSet = descriptor_sets[i]; |
| 7971 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 7972 | error_msgs[i]); |
| 7973 | |
| 7974 | vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, |
| 7975 | NULL); |
| 7976 | |
| 7977 | m_errorMonitor->VerifyFound(); |
| 7978 | vkDestroyDescriptorSetLayout(m_device->device(), ds_layouts[i], NULL); |
| 7979 | } |
| 7980 | vkDestroyDescriptorSetLayout(m_device->device(), ds_layouts[0], NULL); |
| 7981 | vkDestroyImage(m_device->device(), image, NULL); |
Tony Barbour | df4c004 | 2016-06-01 15:55:43 -0600 | [diff] [blame] | 7982 | vkFreeMemory(m_device->device(), image_mem, NULL); |
Tobin Ehlis | 17826bd | 2016-05-25 11:12:50 -0600 | [diff] [blame] | 7983 | vkDestroyImageView(m_device->device(), image_view, NULL); |
| 7984 | vkDestroyBuffer(m_device->device(), buffer, NULL); |
| 7985 | vkDestroyBufferView(m_device->device(), buff_view, NULL); |
| 7986 | vkFreeDescriptorSets(m_device->device(), ds_pool, |
| 7987 | VK_DESCRIPTOR_TYPE_RANGE_SIZE, descriptor_sets); |
| 7988 | vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL); |
| 7989 | } |
| 7990 | |
Tobin Ehlis | 2fc296b | 2016-06-15 14:05:27 -0600 | [diff] [blame] | 7991 | TEST_F(VkLayerTest, DSAspectBitsErrors) { |
| 7992 | // TODO : Initially only catching case where DEPTH & STENCIL aspect bits |
| 7993 | // are set, but could expand this test to hit more cases. |
| 7994 | TEST_DESCRIPTION("Attempt to update descriptor sets for images " |
| 7995 | "that do not have correct aspect bits sets."); |
| 7996 | VkResult err; |
| 7997 | |
| 7998 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 7999 | VkDescriptorPoolSize ds_type_count = {}; |
| 8000 | ds_type_count.type = VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT; |
| 8001 | ds_type_count.descriptorCount = 1; |
| 8002 | |
| 8003 | VkDescriptorPoolCreateInfo ds_pool_ci = {}; |
| 8004 | ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO; |
| 8005 | ds_pool_ci.pNext = NULL; |
| 8006 | ds_pool_ci.maxSets = 5; |
| 8007 | ds_pool_ci.poolSizeCount = 1; |
| 8008 | ds_pool_ci.pPoolSizes = &ds_type_count; |
| 8009 | |
| 8010 | VkDescriptorPool ds_pool; |
| 8011 | err = |
| 8012 | vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool); |
| 8013 | ASSERT_VK_SUCCESS(err); |
| 8014 | |
| 8015 | VkDescriptorSetLayoutBinding dsl_binding = {}; |
| 8016 | dsl_binding.binding = 0; |
| 8017 | dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT; |
| 8018 | dsl_binding.descriptorCount = 1; |
| 8019 | dsl_binding.stageFlags = VK_SHADER_STAGE_ALL; |
| 8020 | dsl_binding.pImmutableSamplers = NULL; |
| 8021 | |
| 8022 | VkDescriptorSetLayoutCreateInfo ds_layout_ci = {}; |
| 8023 | ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO; |
| 8024 | ds_layout_ci.pNext = NULL; |
| 8025 | ds_layout_ci.bindingCount = 1; |
| 8026 | ds_layout_ci.pBindings = &dsl_binding; |
| 8027 | VkDescriptorSetLayout ds_layout; |
| 8028 | err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, |
| 8029 | &ds_layout); |
| 8030 | ASSERT_VK_SUCCESS(err); |
| 8031 | |
| 8032 | VkDescriptorSet descriptor_set = {}; |
| 8033 | VkDescriptorSetAllocateInfo alloc_info = {}; |
| 8034 | alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO; |
| 8035 | alloc_info.descriptorSetCount = 1; |
| 8036 | alloc_info.descriptorPool = ds_pool; |
| 8037 | alloc_info.pSetLayouts = &ds_layout; |
| 8038 | err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, |
| 8039 | &descriptor_set); |
| 8040 | ASSERT_VK_SUCCESS(err); |
| 8041 | |
| 8042 | // Create an image to be used for invalid updates |
| 8043 | VkImageCreateInfo image_ci = {}; |
| 8044 | image_ci.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO; |
| 8045 | image_ci.imageType = VK_IMAGE_TYPE_2D; |
| 8046 | image_ci.format = VK_FORMAT_D24_UNORM_S8_UINT; |
| 8047 | image_ci.extent.width = 64; |
| 8048 | image_ci.extent.height = 64; |
| 8049 | image_ci.extent.depth = 1; |
| 8050 | image_ci.mipLevels = 1; |
| 8051 | image_ci.arrayLayers = 1; |
| 8052 | image_ci.samples = VK_SAMPLE_COUNT_1_BIT; |
| 8053 | image_ci.tiling = VK_IMAGE_TILING_LINEAR; |
| 8054 | image_ci.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED; |
| 8055 | image_ci.usage = VK_IMAGE_USAGE_SAMPLED_BIT; |
| 8056 | image_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE; |
| 8057 | VkImage image; |
| 8058 | err = vkCreateImage(m_device->device(), &image_ci, NULL, &image); |
| 8059 | ASSERT_VK_SUCCESS(err); |
| 8060 | // Bind memory to image |
| 8061 | VkMemoryRequirements mem_reqs; |
| 8062 | VkDeviceMemory image_mem; |
| 8063 | bool pass; |
| 8064 | VkMemoryAllocateInfo mem_alloc = {}; |
| 8065 | mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO; |
| 8066 | mem_alloc.pNext = NULL; |
| 8067 | mem_alloc.allocationSize = 0; |
| 8068 | mem_alloc.memoryTypeIndex = 0; |
| 8069 | vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs); |
| 8070 | mem_alloc.allocationSize = mem_reqs.size; |
| 8071 | pass = |
| 8072 | m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0); |
| 8073 | ASSERT_TRUE(pass); |
| 8074 | err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &image_mem); |
| 8075 | ASSERT_VK_SUCCESS(err); |
| 8076 | err = vkBindImageMemory(m_device->device(), image, image_mem, 0); |
| 8077 | ASSERT_VK_SUCCESS(err); |
| 8078 | // Now create view for image |
| 8079 | VkImageViewCreateInfo image_view_ci = {}; |
| 8080 | image_view_ci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO; |
| 8081 | image_view_ci.image = image; |
| 8082 | image_view_ci.format = VK_FORMAT_D24_UNORM_S8_UINT; |
| 8083 | image_view_ci.viewType = VK_IMAGE_VIEW_TYPE_2D; |
| 8084 | image_view_ci.subresourceRange.layerCount = 1; |
| 8085 | image_view_ci.subresourceRange.baseArrayLayer = 0; |
| 8086 | image_view_ci.subresourceRange.levelCount = 1; |
| 8087 | // Setting both depth & stencil aspect bits is illegal for descriptor |
| 8088 | image_view_ci.subresourceRange.aspectMask = |
| 8089 | VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT; |
| 8090 | |
| 8091 | VkImageView image_view; |
| 8092 | err = vkCreateImageView(m_device->device(), &image_view_ci, NULL, |
| 8093 | &image_view); |
| 8094 | ASSERT_VK_SUCCESS(err); |
| 8095 | |
| 8096 | VkDescriptorImageInfo img_info = {}; |
| 8097 | img_info.imageView = image_view; |
| 8098 | VkWriteDescriptorSet descriptor_write = {}; |
| 8099 | descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET; |
| 8100 | descriptor_write.dstBinding = 0; |
| 8101 | descriptor_write.descriptorCount = 1; |
| 8102 | descriptor_write.pTexelBufferView = NULL; |
| 8103 | descriptor_write.pBufferInfo = NULL; |
| 8104 | descriptor_write.pImageInfo = &img_info; |
| 8105 | descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT; |
| 8106 | descriptor_write.dstSet = descriptor_set; |
| 8107 | const char *error_msg = " please only set either VK_IMAGE_ASPECT_DEPTH_BIT " |
| 8108 | "or VK_IMAGE_ASPECT_STENCIL_BIT "; |
| 8109 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 8110 | error_msg); |
| 8111 | |
| 8112 | vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL); |
| 8113 | |
| 8114 | m_errorMonitor->VerifyFound(); |
| 8115 | vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL); |
| 8116 | vkDestroyImage(m_device->device(), image, NULL); |
| 8117 | vkFreeMemory(m_device->device(), image_mem, NULL); |
| 8118 | vkDestroyImageView(m_device->device(), image_view, NULL); |
| 8119 | vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptor_set); |
| 8120 | vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL); |
| 8121 | } |
| 8122 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8123 | TEST_F(VkLayerTest, DSTypeMismatch) { |
Tobin Ehlis | 49eb23d | 2015-05-22 12:38:55 -0600 | [diff] [blame] | 8124 | // 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] | 8125 | VkResult err; |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 8126 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8127 | m_errorMonitor->SetDesiredFailureMsg( |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 8128 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 8129 | " binding #0 with type VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER but update " |
| 8130 | "type is VK_DESCRIPTOR_TYPE_SAMPLER"); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 8131 | |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 8132 | ASSERT_NO_FATAL_FAILURE(InitState()); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8133 | // VkDescriptorSetObj descriptorSet(m_device); |
Chia-I Wu | 1b99bb2 | 2015-10-27 19:25:11 +0800 | [diff] [blame] | 8134 | VkDescriptorPoolSize ds_type_count = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8135 | ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 8136 | ds_type_count.descriptorCount = 1; |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 8137 | |
| 8138 | VkDescriptorPoolCreateInfo ds_pool_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8139 | ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO; |
| 8140 | ds_pool_ci.pNext = NULL; |
| 8141 | ds_pool_ci.maxSets = 1; |
| 8142 | ds_pool_ci.poolSizeCount = 1; |
| 8143 | ds_pool_ci.pPoolSizes = &ds_type_count; |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 8144 | |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 8145 | VkDescriptorPool ds_pool; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8146 | err = |
| 8147 | vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool); |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 8148 | ASSERT_VK_SUCCESS(err); |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 8149 | VkDescriptorSetLayoutBinding dsl_binding = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8150 | dsl_binding.binding = 0; |
| 8151 | dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 8152 | dsl_binding.descriptorCount = 1; |
| 8153 | dsl_binding.stageFlags = VK_SHADER_STAGE_ALL; |
| 8154 | dsl_binding.pImmutableSamplers = NULL; |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 8155 | |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 8156 | VkDescriptorSetLayoutCreateInfo ds_layout_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8157 | ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO; |
| 8158 | ds_layout_ci.pNext = NULL; |
| 8159 | ds_layout_ci.bindingCount = 1; |
| 8160 | ds_layout_ci.pBindings = &dsl_binding; |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 8161 | |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 8162 | VkDescriptorSetLayout ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8163 | err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, |
| 8164 | &ds_layout); |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 8165 | ASSERT_VK_SUCCESS(err); |
| 8166 | |
| 8167 | VkDescriptorSet descriptorSet; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 8168 | VkDescriptorSetAllocateInfo alloc_info = {}; |
Chia-I Wu | 00ce540 | 2015-11-10 16:21:09 +0800 | [diff] [blame] | 8169 | alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO; |
Jon Ashburn | f19916e | 2016-01-11 13:12:43 -0700 | [diff] [blame] | 8170 | alloc_info.descriptorSetCount = 1; |
Courtney Goeltzenleuchter | bee18a9 | 2015-10-23 14:21:05 -0600 | [diff] [blame] | 8171 | alloc_info.descriptorPool = ds_pool; |
| 8172 | alloc_info.pSetLayouts = &ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8173 | err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, |
| 8174 | &descriptorSet); |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 8175 | ASSERT_VK_SUCCESS(err); |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 8176 | |
Tobin Ehlis | 30db8f8 | 2016-05-05 08:19:48 -0600 | [diff] [blame] | 8177 | VkSamplerCreateInfo sampler_ci = {}; |
| 8178 | sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO; |
| 8179 | sampler_ci.pNext = NULL; |
| 8180 | sampler_ci.magFilter = VK_FILTER_NEAREST; |
| 8181 | sampler_ci.minFilter = VK_FILTER_NEAREST; |
| 8182 | sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST; |
| 8183 | sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE; |
| 8184 | sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE; |
| 8185 | sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE; |
| 8186 | sampler_ci.mipLodBias = 1.0; |
| 8187 | sampler_ci.anisotropyEnable = VK_FALSE; |
| 8188 | sampler_ci.maxAnisotropy = 1; |
| 8189 | sampler_ci.compareEnable = VK_FALSE; |
| 8190 | sampler_ci.compareOp = VK_COMPARE_OP_NEVER; |
| 8191 | sampler_ci.minLod = 1.0; |
| 8192 | sampler_ci.maxLod = 1.0; |
| 8193 | sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE; |
| 8194 | sampler_ci.unnormalizedCoordinates = VK_FALSE; |
| 8195 | VkSampler sampler; |
| 8196 | err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler); |
| 8197 | ASSERT_VK_SUCCESS(err); |
| 8198 | |
| 8199 | VkDescriptorImageInfo info = {}; |
| 8200 | info.sampler = sampler; |
Chia-I Wu | 9d00ed7 | 2015-05-25 16:27:55 +0800 | [diff] [blame] | 8201 | |
| 8202 | VkWriteDescriptorSet descriptor_write; |
| 8203 | memset(&descriptor_write, 0, sizeof(descriptor_write)); |
| 8204 | descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 8205 | descriptor_write.dstSet = descriptorSet; |
Chia-I Wu | d50a7d7 | 2015-10-26 20:48:51 +0800 | [diff] [blame] | 8206 | descriptor_write.descriptorCount = 1; |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 8207 | // This is a mismatched type for the layout which expects BUFFER |
Chia-I Wu | 9d00ed7 | 2015-05-25 16:27:55 +0800 | [diff] [blame] | 8208 | descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER; |
Courtney Goeltzenleuchter | 4cb6d92 | 2015-10-23 13:38:14 -0600 | [diff] [blame] | 8209 | descriptor_write.pImageInfo = &info; |
Chia-I Wu | 9d00ed7 | 2015-05-25 16:27:55 +0800 | [diff] [blame] | 8210 | |
| 8211 | vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL); |
| 8212 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 8213 | m_errorMonitor->VerifyFound(); |
Mike Stroyan | d1c84a5 | 2015-08-18 14:40:24 -0600 | [diff] [blame] | 8214 | |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 8215 | vkDestroySampler(m_device->device(), sampler, NULL); |
| 8216 | vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL); |
| 8217 | vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL); |
Tobin Ehlis | 49eb23d | 2015-05-22 12:38:55 -0600 | [diff] [blame] | 8218 | } |
| 8219 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8220 | TEST_F(VkLayerTest, DSUpdateOutOfBounds) { |
Tobin Ehlis | 49eb23d | 2015-05-22 12:38:55 -0600 | [diff] [blame] | 8221 | // For overlapping Update, have arrayIndex exceed that of layout |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8222 | VkResult err; |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 8223 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8224 | m_errorMonitor->SetDesiredFailureMsg( |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 8225 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 8226 | " binding #0 with 1 total descriptors but update of 1 descriptors " |
| 8227 | "starting at binding offset of 0 combined with update array element " |
| 8228 | "offset of 1 oversteps the size of this descriptor set."); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 8229 | |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 8230 | ASSERT_NO_FATAL_FAILURE(InitState()); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8231 | // VkDescriptorSetObj descriptorSet(m_device); |
Chia-I Wu | 1b99bb2 | 2015-10-27 19:25:11 +0800 | [diff] [blame] | 8232 | VkDescriptorPoolSize ds_type_count = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8233 | ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 8234 | ds_type_count.descriptorCount = 1; |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 8235 | |
| 8236 | VkDescriptorPoolCreateInfo ds_pool_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8237 | ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO; |
| 8238 | ds_pool_ci.pNext = NULL; |
| 8239 | ds_pool_ci.maxSets = 1; |
| 8240 | ds_pool_ci.poolSizeCount = 1; |
| 8241 | ds_pool_ci.pPoolSizes = &ds_type_count; |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 8242 | |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 8243 | VkDescriptorPool ds_pool; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8244 | err = |
| 8245 | vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool); |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 8246 | ASSERT_VK_SUCCESS(err); |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 8247 | |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 8248 | VkDescriptorSetLayoutBinding dsl_binding = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8249 | dsl_binding.binding = 0; |
| 8250 | dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 8251 | dsl_binding.descriptorCount = 1; |
| 8252 | dsl_binding.stageFlags = VK_SHADER_STAGE_ALL; |
| 8253 | dsl_binding.pImmutableSamplers = NULL; |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 8254 | |
| 8255 | VkDescriptorSetLayoutCreateInfo ds_layout_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8256 | ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO; |
| 8257 | ds_layout_ci.pNext = NULL; |
| 8258 | ds_layout_ci.bindingCount = 1; |
| 8259 | ds_layout_ci.pBindings = &dsl_binding; |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 8260 | |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 8261 | VkDescriptorSetLayout ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8262 | err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, |
| 8263 | &ds_layout); |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 8264 | ASSERT_VK_SUCCESS(err); |
| 8265 | |
| 8266 | VkDescriptorSet descriptorSet; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 8267 | VkDescriptorSetAllocateInfo alloc_info = {}; |
Chia-I Wu | 00ce540 | 2015-11-10 16:21:09 +0800 | [diff] [blame] | 8268 | alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO; |
Jon Ashburn | f19916e | 2016-01-11 13:12:43 -0700 | [diff] [blame] | 8269 | alloc_info.descriptorSetCount = 1; |
Courtney Goeltzenleuchter | bee18a9 | 2015-10-23 14:21:05 -0600 | [diff] [blame] | 8270 | alloc_info.descriptorPool = ds_pool; |
| 8271 | alloc_info.pSetLayouts = &ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8272 | err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, |
| 8273 | &descriptorSet); |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 8274 | ASSERT_VK_SUCCESS(err); |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 8275 | |
Tobin Ehlis | 30db8f8 | 2016-05-05 08:19:48 -0600 | [diff] [blame] | 8276 | // Correctly update descriptor to avoid "NOT_UPDATED" error |
| 8277 | VkDescriptorBufferInfo buff_info = {}; |
| 8278 | buff_info.buffer = |
| 8279 | VkBuffer(0); // Don't care about buffer handle for this test |
| 8280 | buff_info.offset = 0; |
| 8281 | buff_info.range = 1024; |
Chia-I Wu | 9d00ed7 | 2015-05-25 16:27:55 +0800 | [diff] [blame] | 8282 | |
| 8283 | VkWriteDescriptorSet descriptor_write; |
| 8284 | memset(&descriptor_write, 0, sizeof(descriptor_write)); |
| 8285 | descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 8286 | descriptor_write.dstSet = descriptorSet; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8287 | descriptor_write.dstArrayElement = |
| 8288 | 1; /* This index out of bounds for the update */ |
Chia-I Wu | d50a7d7 | 2015-10-26 20:48:51 +0800 | [diff] [blame] | 8289 | descriptor_write.descriptorCount = 1; |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 8290 | descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 8291 | descriptor_write.pBufferInfo = &buff_info; |
Chia-I Wu | 9d00ed7 | 2015-05-25 16:27:55 +0800 | [diff] [blame] | 8292 | |
| 8293 | vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL); |
| 8294 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 8295 | m_errorMonitor->VerifyFound(); |
Mike Stroyan | d1c84a5 | 2015-08-18 14:40:24 -0600 | [diff] [blame] | 8296 | |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 8297 | vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL); |
| 8298 | vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL); |
Tobin Ehlis | 49eb23d | 2015-05-22 12:38:55 -0600 | [diff] [blame] | 8299 | } |
| 8300 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8301 | TEST_F(VkLayerTest, InvalidDSUpdateIndex) { |
| 8302 | // Create layout w/ count of 1 and attempt update to that layout w/ binding |
| 8303 | // index 2 |
| 8304 | VkResult err; |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 8305 | |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 8306 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 8307 | " does not have binding 2."); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 8308 | |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 8309 | ASSERT_NO_FATAL_FAILURE(InitState()); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8310 | // VkDescriptorSetObj descriptorSet(m_device); |
Chia-I Wu | 1b99bb2 | 2015-10-27 19:25:11 +0800 | [diff] [blame] | 8311 | VkDescriptorPoolSize ds_type_count = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8312 | ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 8313 | ds_type_count.descriptorCount = 1; |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 8314 | |
| 8315 | VkDescriptorPoolCreateInfo ds_pool_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8316 | ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO; |
| 8317 | ds_pool_ci.pNext = NULL; |
| 8318 | ds_pool_ci.maxSets = 1; |
| 8319 | ds_pool_ci.poolSizeCount = 1; |
| 8320 | ds_pool_ci.pPoolSizes = &ds_type_count; |
Courtney Goeltzenleuchter | fe908d3 | 2015-09-16 16:12:45 -0600 | [diff] [blame] | 8321 | |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 8322 | VkDescriptorPool ds_pool; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8323 | err = |
| 8324 | vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool); |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 8325 | ASSERT_VK_SUCCESS(err); |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 8326 | |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 8327 | VkDescriptorSetLayoutBinding dsl_binding = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8328 | dsl_binding.binding = 0; |
| 8329 | dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 8330 | dsl_binding.descriptorCount = 1; |
| 8331 | dsl_binding.stageFlags = VK_SHADER_STAGE_ALL; |
| 8332 | dsl_binding.pImmutableSamplers = NULL; |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 8333 | |
| 8334 | VkDescriptorSetLayoutCreateInfo ds_layout_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8335 | ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO; |
| 8336 | ds_layout_ci.pNext = NULL; |
| 8337 | ds_layout_ci.bindingCount = 1; |
| 8338 | ds_layout_ci.pBindings = &dsl_binding; |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 8339 | VkDescriptorSetLayout ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8340 | err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, |
| 8341 | &ds_layout); |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 8342 | ASSERT_VK_SUCCESS(err); |
| 8343 | |
| 8344 | VkDescriptorSet descriptorSet; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 8345 | VkDescriptorSetAllocateInfo alloc_info = {}; |
Chia-I Wu | 00ce540 | 2015-11-10 16:21:09 +0800 | [diff] [blame] | 8346 | alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO; |
Jon Ashburn | f19916e | 2016-01-11 13:12:43 -0700 | [diff] [blame] | 8347 | alloc_info.descriptorSetCount = 1; |
Courtney Goeltzenleuchter | bee18a9 | 2015-10-23 14:21:05 -0600 | [diff] [blame] | 8348 | alloc_info.descriptorPool = ds_pool; |
| 8349 | alloc_info.pSetLayouts = &ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8350 | err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, |
| 8351 | &descriptorSet); |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 8352 | ASSERT_VK_SUCCESS(err); |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 8353 | |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 8354 | VkSamplerCreateInfo sampler_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8355 | sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO; |
| 8356 | sampler_ci.pNext = NULL; |
| 8357 | sampler_ci.magFilter = VK_FILTER_NEAREST; |
| 8358 | sampler_ci.minFilter = VK_FILTER_NEAREST; |
| 8359 | sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST; |
| 8360 | sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE; |
| 8361 | sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE; |
| 8362 | sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE; |
| 8363 | sampler_ci.mipLodBias = 1.0; |
| 8364 | sampler_ci.anisotropyEnable = VK_FALSE; |
| 8365 | sampler_ci.maxAnisotropy = 1; |
| 8366 | sampler_ci.compareEnable = VK_FALSE; |
| 8367 | sampler_ci.compareOp = VK_COMPARE_OP_NEVER; |
| 8368 | sampler_ci.minLod = 1.0; |
| 8369 | sampler_ci.maxLod = 1.0; |
| 8370 | sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE; |
| 8371 | sampler_ci.unnormalizedCoordinates = VK_FALSE; |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 8372 | |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 8373 | VkSampler sampler; |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 8374 | err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler); |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 8375 | ASSERT_VK_SUCCESS(err); |
Chia-I Wu | 9d00ed7 | 2015-05-25 16:27:55 +0800 | [diff] [blame] | 8376 | |
Courtney Goeltzenleuchter | 4cb6d92 | 2015-10-23 13:38:14 -0600 | [diff] [blame] | 8377 | VkDescriptorImageInfo info = {}; |
| 8378 | info.sampler = sampler; |
Chia-I Wu | 9d00ed7 | 2015-05-25 16:27:55 +0800 | [diff] [blame] | 8379 | |
| 8380 | VkWriteDescriptorSet descriptor_write; |
| 8381 | memset(&descriptor_write, 0, sizeof(descriptor_write)); |
| 8382 | descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 8383 | descriptor_write.dstSet = descriptorSet; |
| 8384 | descriptor_write.dstBinding = 2; |
Chia-I Wu | d50a7d7 | 2015-10-26 20:48:51 +0800 | [diff] [blame] | 8385 | descriptor_write.descriptorCount = 1; |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 8386 | // 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] | 8387 | descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER; |
Courtney Goeltzenleuchter | 4cb6d92 | 2015-10-23 13:38:14 -0600 | [diff] [blame] | 8388 | descriptor_write.pImageInfo = &info; |
Chia-I Wu | 9d00ed7 | 2015-05-25 16:27:55 +0800 | [diff] [blame] | 8389 | |
| 8390 | vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL); |
| 8391 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 8392 | m_errorMonitor->VerifyFound(); |
Mike Stroyan | d1c84a5 | 2015-08-18 14:40:24 -0600 | [diff] [blame] | 8393 | |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 8394 | vkDestroySampler(m_device->device(), sampler, NULL); |
| 8395 | vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL); |
| 8396 | vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL); |
Tobin Ehlis | 49eb23d | 2015-05-22 12:38:55 -0600 | [diff] [blame] | 8397 | } |
| 8398 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8399 | TEST_F(VkLayerTest, InvalidDSUpdateStruct) { |
| 8400 | // Call UpdateDS w/ struct type other than valid VK_STRUCTUR_TYPE_UPDATE_* |
| 8401 | // types |
| 8402 | VkResult err; |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 8403 | |
Courtney Goeltzenleuchter | 7415d5a | 2015-12-09 15:48:16 -0700 | [diff] [blame] | 8404 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Tobin Ehlis | 660bcdc | 2016-05-17 10:39:46 -0600 | [diff] [blame] | 8405 | ".sType must be VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET"); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 8406 | |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 8407 | ASSERT_NO_FATAL_FAILURE(InitState()); |
Mark Lobodzinski | 209b529 | 2015-09-17 09:44:05 -0600 | [diff] [blame] | 8408 | |
Chia-I Wu | 1b99bb2 | 2015-10-27 19:25:11 +0800 | [diff] [blame] | 8409 | VkDescriptorPoolSize ds_type_count = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8410 | ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 8411 | ds_type_count.descriptorCount = 1; |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 8412 | |
| 8413 | VkDescriptorPoolCreateInfo ds_pool_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8414 | ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO; |
| 8415 | ds_pool_ci.pNext = NULL; |
| 8416 | ds_pool_ci.maxSets = 1; |
| 8417 | ds_pool_ci.poolSizeCount = 1; |
| 8418 | ds_pool_ci.pPoolSizes = &ds_type_count; |
Courtney Goeltzenleuchter | fe908d3 | 2015-09-16 16:12:45 -0600 | [diff] [blame] | 8419 | |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 8420 | VkDescriptorPool ds_pool; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8421 | err = |
| 8422 | vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool); |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 8423 | ASSERT_VK_SUCCESS(err); |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 8424 | VkDescriptorSetLayoutBinding dsl_binding = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8425 | dsl_binding.binding = 0; |
| 8426 | dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 8427 | dsl_binding.descriptorCount = 1; |
| 8428 | dsl_binding.stageFlags = VK_SHADER_STAGE_ALL; |
| 8429 | dsl_binding.pImmutableSamplers = NULL; |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 8430 | |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 8431 | VkDescriptorSetLayoutCreateInfo ds_layout_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8432 | ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO; |
| 8433 | ds_layout_ci.pNext = NULL; |
| 8434 | ds_layout_ci.bindingCount = 1; |
| 8435 | ds_layout_ci.pBindings = &dsl_binding; |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 8436 | |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 8437 | VkDescriptorSetLayout ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8438 | err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, |
| 8439 | &ds_layout); |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 8440 | ASSERT_VK_SUCCESS(err); |
| 8441 | |
| 8442 | VkDescriptorSet descriptorSet; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 8443 | VkDescriptorSetAllocateInfo alloc_info = {}; |
Chia-I Wu | 00ce540 | 2015-11-10 16:21:09 +0800 | [diff] [blame] | 8444 | alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO; |
Jon Ashburn | f19916e | 2016-01-11 13:12:43 -0700 | [diff] [blame] | 8445 | alloc_info.descriptorSetCount = 1; |
Courtney Goeltzenleuchter | bee18a9 | 2015-10-23 14:21:05 -0600 | [diff] [blame] | 8446 | alloc_info.descriptorPool = ds_pool; |
| 8447 | alloc_info.pSetLayouts = &ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8448 | err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, |
| 8449 | &descriptorSet); |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 8450 | ASSERT_VK_SUCCESS(err); |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 8451 | |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 8452 | VkSamplerCreateInfo sampler_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8453 | sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO; |
| 8454 | sampler_ci.pNext = NULL; |
| 8455 | sampler_ci.magFilter = VK_FILTER_NEAREST; |
| 8456 | sampler_ci.minFilter = VK_FILTER_NEAREST; |
| 8457 | sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST; |
| 8458 | sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE; |
| 8459 | sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE; |
| 8460 | sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE; |
| 8461 | sampler_ci.mipLodBias = 1.0; |
| 8462 | sampler_ci.anisotropyEnable = VK_FALSE; |
| 8463 | sampler_ci.maxAnisotropy = 1; |
| 8464 | sampler_ci.compareEnable = VK_FALSE; |
| 8465 | sampler_ci.compareOp = VK_COMPARE_OP_NEVER; |
| 8466 | sampler_ci.minLod = 1.0; |
| 8467 | sampler_ci.maxLod = 1.0; |
| 8468 | sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE; |
| 8469 | sampler_ci.unnormalizedCoordinates = VK_FALSE; |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 8470 | VkSampler sampler; |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 8471 | err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler); |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 8472 | ASSERT_VK_SUCCESS(err); |
Chia-I Wu | 9d00ed7 | 2015-05-25 16:27:55 +0800 | [diff] [blame] | 8473 | |
Courtney Goeltzenleuchter | 4cb6d92 | 2015-10-23 13:38:14 -0600 | [diff] [blame] | 8474 | VkDescriptorImageInfo info = {}; |
| 8475 | info.sampler = sampler; |
Chia-I Wu | 9d00ed7 | 2015-05-25 16:27:55 +0800 | [diff] [blame] | 8476 | |
| 8477 | VkWriteDescriptorSet descriptor_write; |
| 8478 | memset(&descriptor_write, 0, sizeof(descriptor_write)); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8479 | descriptor_write.sType = |
| 8480 | (VkStructureType)0x99999999; /* Intentionally broken struct type */ |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 8481 | descriptor_write.dstSet = descriptorSet; |
Chia-I Wu | d50a7d7 | 2015-10-26 20:48:51 +0800 | [diff] [blame] | 8482 | descriptor_write.descriptorCount = 1; |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 8483 | // 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] | 8484 | descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER; |
Courtney Goeltzenleuchter | 4cb6d92 | 2015-10-23 13:38:14 -0600 | [diff] [blame] | 8485 | descriptor_write.pImageInfo = &info; |
Chia-I Wu | 9d00ed7 | 2015-05-25 16:27:55 +0800 | [diff] [blame] | 8486 | |
| 8487 | vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL); |
| 8488 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 8489 | m_errorMonitor->VerifyFound(); |
Mike Stroyan | d1c84a5 | 2015-08-18 14:40:24 -0600 | [diff] [blame] | 8490 | |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 8491 | vkDestroySampler(m_device->device(), sampler, NULL); |
| 8492 | vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL); |
| 8493 | vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL); |
Tobin Ehlis | 49eb23d | 2015-05-22 12:38:55 -0600 | [diff] [blame] | 8494 | } |
| 8495 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8496 | TEST_F(VkLayerTest, SampleDescriptorUpdateError) { |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 8497 | // Create a single Sampler descriptor and send it an invalid Sampler |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8498 | VkResult err; |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 8499 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8500 | m_errorMonitor->SetDesiredFailureMsg( |
| 8501 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 8502 | "Attempted write update to sampler descriptor with invalid sampler"); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 8503 | |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 8504 | ASSERT_NO_FATAL_FAILURE(InitState()); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8505 | // TODO : Farm Descriptor setup code to helper function(s) to reduce copied |
| 8506 | // code |
Chia-I Wu | 1b99bb2 | 2015-10-27 19:25:11 +0800 | [diff] [blame] | 8507 | VkDescriptorPoolSize ds_type_count = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8508 | ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLER; |
| 8509 | ds_type_count.descriptorCount = 1; |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 8510 | |
| 8511 | VkDescriptorPoolCreateInfo ds_pool_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8512 | ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO; |
| 8513 | ds_pool_ci.pNext = NULL; |
| 8514 | ds_pool_ci.maxSets = 1; |
| 8515 | ds_pool_ci.poolSizeCount = 1; |
| 8516 | ds_pool_ci.pPoolSizes = &ds_type_count; |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 8517 | |
| 8518 | VkDescriptorPool ds_pool; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8519 | err = |
| 8520 | vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool); |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 8521 | ASSERT_VK_SUCCESS(err); |
| 8522 | |
| 8523 | VkDescriptorSetLayoutBinding dsl_binding = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8524 | dsl_binding.binding = 0; |
| 8525 | dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER; |
| 8526 | dsl_binding.descriptorCount = 1; |
| 8527 | dsl_binding.stageFlags = VK_SHADER_STAGE_ALL; |
| 8528 | dsl_binding.pImmutableSamplers = NULL; |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 8529 | |
| 8530 | VkDescriptorSetLayoutCreateInfo ds_layout_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8531 | ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO; |
| 8532 | ds_layout_ci.pNext = NULL; |
| 8533 | ds_layout_ci.bindingCount = 1; |
| 8534 | ds_layout_ci.pBindings = &dsl_binding; |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 8535 | VkDescriptorSetLayout ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8536 | err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, |
| 8537 | &ds_layout); |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 8538 | ASSERT_VK_SUCCESS(err); |
| 8539 | |
| 8540 | VkDescriptorSet descriptorSet; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 8541 | VkDescriptorSetAllocateInfo alloc_info = {}; |
Chia-I Wu | 00ce540 | 2015-11-10 16:21:09 +0800 | [diff] [blame] | 8542 | alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO; |
Jon Ashburn | f19916e | 2016-01-11 13:12:43 -0700 | [diff] [blame] | 8543 | alloc_info.descriptorSetCount = 1; |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 8544 | alloc_info.descriptorPool = ds_pool; |
| 8545 | alloc_info.pSetLayouts = &ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8546 | err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, |
| 8547 | &descriptorSet); |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 8548 | ASSERT_VK_SUCCESS(err); |
| 8549 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8550 | VkSampler sampler = |
| 8551 | (VkSampler)((size_t)0xbaadbeef); // Sampler with invalid handle |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 8552 | |
| 8553 | VkDescriptorImageInfo descriptor_info; |
| 8554 | memset(&descriptor_info, 0, sizeof(VkDescriptorImageInfo)); |
| 8555 | descriptor_info.sampler = sampler; |
| 8556 | |
| 8557 | VkWriteDescriptorSet descriptor_write; |
| 8558 | memset(&descriptor_write, 0, sizeof(descriptor_write)); |
| 8559 | descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 8560 | descriptor_write.dstSet = descriptorSet; |
| 8561 | descriptor_write.dstBinding = 0; |
Chia-I Wu | d50a7d7 | 2015-10-26 20:48:51 +0800 | [diff] [blame] | 8562 | descriptor_write.descriptorCount = 1; |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 8563 | descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER; |
| 8564 | descriptor_write.pImageInfo = &descriptor_info; |
| 8565 | |
| 8566 | vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL); |
| 8567 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 8568 | m_errorMonitor->VerifyFound(); |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 8569 | |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 8570 | vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL); |
| 8571 | vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL); |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 8572 | } |
| 8573 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8574 | TEST_F(VkLayerTest, ImageViewDescriptorUpdateError) { |
| 8575 | // Create a single combined Image/Sampler descriptor and send it an invalid |
| 8576 | // imageView |
| 8577 | VkResult err; |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 8578 | |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 8579 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 8580 | "Attempted write update to combined " |
| 8581 | "image sampler descriptor failed due " |
Tobin Ehlis | 63c4b8a | 2016-05-09 10:29:34 -0600 | [diff] [blame] | 8582 | "to: Invalid VkImageView:"); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 8583 | |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 8584 | ASSERT_NO_FATAL_FAILURE(InitState()); |
Chia-I Wu | 1b99bb2 | 2015-10-27 19:25:11 +0800 | [diff] [blame] | 8585 | VkDescriptorPoolSize ds_type_count = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8586 | ds_type_count.type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER; |
| 8587 | ds_type_count.descriptorCount = 1; |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 8588 | |
| 8589 | VkDescriptorPoolCreateInfo ds_pool_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8590 | ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO; |
| 8591 | ds_pool_ci.pNext = NULL; |
| 8592 | ds_pool_ci.maxSets = 1; |
| 8593 | ds_pool_ci.poolSizeCount = 1; |
| 8594 | ds_pool_ci.pPoolSizes = &ds_type_count; |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 8595 | |
| 8596 | VkDescriptorPool ds_pool; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8597 | err = |
| 8598 | vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool); |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 8599 | ASSERT_VK_SUCCESS(err); |
| 8600 | |
| 8601 | VkDescriptorSetLayoutBinding dsl_binding = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8602 | dsl_binding.binding = 0; |
| 8603 | dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER; |
| 8604 | dsl_binding.descriptorCount = 1; |
| 8605 | dsl_binding.stageFlags = VK_SHADER_STAGE_ALL; |
| 8606 | dsl_binding.pImmutableSamplers = NULL; |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 8607 | |
| 8608 | VkDescriptorSetLayoutCreateInfo ds_layout_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8609 | ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO; |
| 8610 | ds_layout_ci.pNext = NULL; |
| 8611 | ds_layout_ci.bindingCount = 1; |
| 8612 | ds_layout_ci.pBindings = &dsl_binding; |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 8613 | VkDescriptorSetLayout ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8614 | err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, |
| 8615 | &ds_layout); |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 8616 | ASSERT_VK_SUCCESS(err); |
| 8617 | |
| 8618 | VkDescriptorSet descriptorSet; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 8619 | VkDescriptorSetAllocateInfo alloc_info = {}; |
Chia-I Wu | 00ce540 | 2015-11-10 16:21:09 +0800 | [diff] [blame] | 8620 | alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO; |
Jon Ashburn | f19916e | 2016-01-11 13:12:43 -0700 | [diff] [blame] | 8621 | alloc_info.descriptorSetCount = 1; |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 8622 | alloc_info.descriptorPool = ds_pool; |
| 8623 | alloc_info.pSetLayouts = &ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8624 | err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, |
| 8625 | &descriptorSet); |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 8626 | ASSERT_VK_SUCCESS(err); |
| 8627 | |
| 8628 | VkSamplerCreateInfo sampler_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8629 | sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO; |
| 8630 | sampler_ci.pNext = NULL; |
| 8631 | sampler_ci.magFilter = VK_FILTER_NEAREST; |
| 8632 | sampler_ci.minFilter = VK_FILTER_NEAREST; |
| 8633 | sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST; |
| 8634 | sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE; |
| 8635 | sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE; |
| 8636 | sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE; |
| 8637 | sampler_ci.mipLodBias = 1.0; |
| 8638 | sampler_ci.anisotropyEnable = VK_FALSE; |
| 8639 | sampler_ci.maxAnisotropy = 1; |
| 8640 | sampler_ci.compareEnable = VK_FALSE; |
| 8641 | sampler_ci.compareOp = VK_COMPARE_OP_NEVER; |
| 8642 | sampler_ci.minLod = 1.0; |
| 8643 | sampler_ci.maxLod = 1.0; |
| 8644 | sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE; |
| 8645 | sampler_ci.unnormalizedCoordinates = VK_FALSE; |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 8646 | |
| 8647 | VkSampler sampler; |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 8648 | err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler); |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 8649 | ASSERT_VK_SUCCESS(err); |
| 8650 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8651 | VkImageView view = |
| 8652 | (VkImageView)((size_t)0xbaadbeef); // invalid imageView object |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 8653 | |
| 8654 | VkDescriptorImageInfo descriptor_info; |
| 8655 | memset(&descriptor_info, 0, sizeof(VkDescriptorImageInfo)); |
| 8656 | descriptor_info.sampler = sampler; |
| 8657 | descriptor_info.imageView = view; |
| 8658 | |
| 8659 | VkWriteDescriptorSet descriptor_write; |
| 8660 | memset(&descriptor_write, 0, sizeof(descriptor_write)); |
| 8661 | descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 8662 | descriptor_write.dstSet = descriptorSet; |
| 8663 | descriptor_write.dstBinding = 0; |
Chia-I Wu | d50a7d7 | 2015-10-26 20:48:51 +0800 | [diff] [blame] | 8664 | descriptor_write.descriptorCount = 1; |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 8665 | descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER; |
| 8666 | descriptor_write.pImageInfo = &descriptor_info; |
| 8667 | |
| 8668 | vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL); |
| 8669 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 8670 | m_errorMonitor->VerifyFound(); |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 8671 | |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 8672 | vkDestroySampler(m_device->device(), sampler, NULL); |
| 8673 | vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL); |
| 8674 | vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL); |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 8675 | } |
| 8676 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8677 | TEST_F(VkLayerTest, CopyDescriptorUpdateErrors) { |
| 8678 | // Create DS w/ layout of 2 types, write update 1 and attempt to copy-update |
| 8679 | // into the other |
| 8680 | VkResult err; |
Tobin Ehlis | 04356f9 | 2015-10-27 16:35:27 -0600 | [diff] [blame] | 8681 | |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 8682 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 8683 | " binding #1 with type " |
| 8684 | "VK_DESCRIPTOR_TYPE_SAMPLER. Types do " |
| 8685 | "not match."); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 8686 | |
Tobin Ehlis | 04356f9 | 2015-10-27 16:35:27 -0600 | [diff] [blame] | 8687 | ASSERT_NO_FATAL_FAILURE(InitState()); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8688 | // VkDescriptorSetObj descriptorSet(m_device); |
Chia-I Wu | 1b99bb2 | 2015-10-27 19:25:11 +0800 | [diff] [blame] | 8689 | VkDescriptorPoolSize ds_type_count[2] = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8690 | ds_type_count[0].type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 8691 | ds_type_count[0].descriptorCount = 1; |
| 8692 | ds_type_count[1].type = VK_DESCRIPTOR_TYPE_SAMPLER; |
| 8693 | ds_type_count[1].descriptorCount = 1; |
Tobin Ehlis | 04356f9 | 2015-10-27 16:35:27 -0600 | [diff] [blame] | 8694 | |
| 8695 | VkDescriptorPoolCreateInfo ds_pool_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8696 | ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO; |
| 8697 | ds_pool_ci.pNext = NULL; |
| 8698 | ds_pool_ci.maxSets = 1; |
| 8699 | ds_pool_ci.poolSizeCount = 2; |
| 8700 | ds_pool_ci.pPoolSizes = ds_type_count; |
Tobin Ehlis | 04356f9 | 2015-10-27 16:35:27 -0600 | [diff] [blame] | 8701 | |
| 8702 | VkDescriptorPool ds_pool; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8703 | err = |
| 8704 | vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool); |
Tobin Ehlis | 04356f9 | 2015-10-27 16:35:27 -0600 | [diff] [blame] | 8705 | ASSERT_VK_SUCCESS(err); |
| 8706 | VkDescriptorSetLayoutBinding dsl_binding[2] = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8707 | dsl_binding[0].binding = 0; |
| 8708 | dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 8709 | dsl_binding[0].descriptorCount = 1; |
| 8710 | dsl_binding[0].stageFlags = VK_SHADER_STAGE_ALL; |
| 8711 | dsl_binding[0].pImmutableSamplers = NULL; |
| 8712 | dsl_binding[1].binding = 1; |
| 8713 | dsl_binding[1].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER; |
| 8714 | dsl_binding[1].descriptorCount = 1; |
| 8715 | dsl_binding[1].stageFlags = VK_SHADER_STAGE_ALL; |
| 8716 | dsl_binding[1].pImmutableSamplers = NULL; |
Tobin Ehlis | 04356f9 | 2015-10-27 16:35:27 -0600 | [diff] [blame] | 8717 | |
| 8718 | VkDescriptorSetLayoutCreateInfo ds_layout_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8719 | ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO; |
| 8720 | ds_layout_ci.pNext = NULL; |
| 8721 | ds_layout_ci.bindingCount = 2; |
| 8722 | ds_layout_ci.pBindings = dsl_binding; |
Tobin Ehlis | 04356f9 | 2015-10-27 16:35:27 -0600 | [diff] [blame] | 8723 | |
| 8724 | VkDescriptorSetLayout ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8725 | err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, |
| 8726 | &ds_layout); |
Tobin Ehlis | 04356f9 | 2015-10-27 16:35:27 -0600 | [diff] [blame] | 8727 | ASSERT_VK_SUCCESS(err); |
| 8728 | |
| 8729 | VkDescriptorSet descriptorSet; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 8730 | VkDescriptorSetAllocateInfo alloc_info = {}; |
Chia-I Wu | 00ce540 | 2015-11-10 16:21:09 +0800 | [diff] [blame] | 8731 | alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO; |
Jon Ashburn | f19916e | 2016-01-11 13:12:43 -0700 | [diff] [blame] | 8732 | alloc_info.descriptorSetCount = 1; |
Tobin Ehlis | 04356f9 | 2015-10-27 16:35:27 -0600 | [diff] [blame] | 8733 | alloc_info.descriptorPool = ds_pool; |
| 8734 | alloc_info.pSetLayouts = &ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8735 | err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, |
| 8736 | &descriptorSet); |
Tobin Ehlis | 04356f9 | 2015-10-27 16:35:27 -0600 | [diff] [blame] | 8737 | ASSERT_VK_SUCCESS(err); |
| 8738 | |
| 8739 | VkSamplerCreateInfo sampler_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8740 | sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO; |
| 8741 | sampler_ci.pNext = NULL; |
| 8742 | sampler_ci.magFilter = VK_FILTER_NEAREST; |
| 8743 | sampler_ci.minFilter = VK_FILTER_NEAREST; |
| 8744 | sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST; |
| 8745 | sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE; |
| 8746 | sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE; |
| 8747 | sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE; |
| 8748 | sampler_ci.mipLodBias = 1.0; |
| 8749 | sampler_ci.anisotropyEnable = VK_FALSE; |
| 8750 | sampler_ci.maxAnisotropy = 1; |
| 8751 | sampler_ci.compareEnable = VK_FALSE; |
| 8752 | sampler_ci.compareOp = VK_COMPARE_OP_NEVER; |
| 8753 | sampler_ci.minLod = 1.0; |
| 8754 | sampler_ci.maxLod = 1.0; |
| 8755 | sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE; |
| 8756 | sampler_ci.unnormalizedCoordinates = VK_FALSE; |
Tobin Ehlis | 04356f9 | 2015-10-27 16:35:27 -0600 | [diff] [blame] | 8757 | |
| 8758 | VkSampler sampler; |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 8759 | err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler); |
Tobin Ehlis | 04356f9 | 2015-10-27 16:35:27 -0600 | [diff] [blame] | 8760 | ASSERT_VK_SUCCESS(err); |
| 8761 | |
| 8762 | VkDescriptorImageInfo info = {}; |
| 8763 | info.sampler = sampler; |
| 8764 | |
| 8765 | VkWriteDescriptorSet descriptor_write; |
| 8766 | memset(&descriptor_write, 0, sizeof(VkWriteDescriptorSet)); |
| 8767 | descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 8768 | descriptor_write.dstSet = descriptorSet; |
| 8769 | descriptor_write.dstBinding = 1; // SAMPLER binding from layout above |
Chia-I Wu | d50a7d7 | 2015-10-26 20:48:51 +0800 | [diff] [blame] | 8770 | descriptor_write.descriptorCount = 1; |
Tobin Ehlis | 04356f9 | 2015-10-27 16:35:27 -0600 | [diff] [blame] | 8771 | descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER; |
| 8772 | descriptor_write.pImageInfo = &info; |
| 8773 | // This write update should succeed |
| 8774 | vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL); |
| 8775 | // Now perform a copy update that fails due to type mismatch |
| 8776 | VkCopyDescriptorSet copy_ds_update; |
| 8777 | memset(©_ds_update, 0, sizeof(VkCopyDescriptorSet)); |
| 8778 | copy_ds_update.sType = VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET; |
| 8779 | copy_ds_update.srcSet = descriptorSet; |
Mark Young | 2992748 | 2016-05-04 14:38:51 -0600 | [diff] [blame] | 8780 | copy_ds_update.srcBinding = 1; // Copy from SAMPLER binding |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 8781 | copy_ds_update.dstSet = descriptorSet; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8782 | copy_ds_update.dstBinding = 0; // ERROR : copy to UNIFORM binding |
Chia-I Wu | d50a7d7 | 2015-10-26 20:48:51 +0800 | [diff] [blame] | 8783 | copy_ds_update.descriptorCount = 1; // copy 1 descriptor |
Tobin Ehlis | 04356f9 | 2015-10-27 16:35:27 -0600 | [diff] [blame] | 8784 | vkUpdateDescriptorSets(m_device->device(), 0, NULL, 1, ©_ds_update); |
| 8785 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 8786 | m_errorMonitor->VerifyFound(); |
Tobin Ehlis | 04356f9 | 2015-10-27 16:35:27 -0600 | [diff] [blame] | 8787 | // 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] | 8788 | m_errorMonitor->SetDesiredFailureMsg( |
| 8789 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 8790 | " does not have copy update src binding of 3."); |
Tobin Ehlis | 04356f9 | 2015-10-27 16:35:27 -0600 | [diff] [blame] | 8791 | memset(©_ds_update, 0, sizeof(VkCopyDescriptorSet)); |
| 8792 | copy_ds_update.sType = VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET; |
| 8793 | copy_ds_update.srcSet = descriptorSet; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8794 | copy_ds_update.srcBinding = |
| 8795 | 3; // ERROR : Invalid binding for matching layout |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 8796 | copy_ds_update.dstSet = descriptorSet; |
| 8797 | copy_ds_update.dstBinding = 0; |
Mark Young | 2992748 | 2016-05-04 14:38:51 -0600 | [diff] [blame] | 8798 | copy_ds_update.descriptorCount = 1; // Copy 1 descriptor |
Tobin Ehlis | 04356f9 | 2015-10-27 16:35:27 -0600 | [diff] [blame] | 8799 | vkUpdateDescriptorSets(m_device->device(), 0, NULL, 1, ©_ds_update); |
| 8800 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 8801 | m_errorMonitor->VerifyFound(); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 8802 | |
Tobin Ehlis | 04356f9 | 2015-10-27 16:35:27 -0600 | [diff] [blame] | 8803 | // 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] | 8804 | m_errorMonitor->SetDesiredFailureMsg( |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 8805 | VK_DEBUG_REPORT_ERROR_BIT_EXT, " binding#1 with offset index of 1 plus " |
| 8806 | "update array offset of 0 and update of " |
| 8807 | "5 descriptors oversteps total number " |
| 8808 | "of descriptors in set: 2."); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 8809 | |
Tobin Ehlis | 04356f9 | 2015-10-27 16:35:27 -0600 | [diff] [blame] | 8810 | memset(©_ds_update, 0, sizeof(VkCopyDescriptorSet)); |
| 8811 | copy_ds_update.sType = VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET; |
| 8812 | copy_ds_update.srcSet = descriptorSet; |
| 8813 | copy_ds_update.srcBinding = 1; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 8814 | copy_ds_update.dstSet = descriptorSet; |
| 8815 | copy_ds_update.dstBinding = 0; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8816 | copy_ds_update.descriptorCount = |
| 8817 | 5; // ERROR copy 5 descriptors (out of bounds for layout) |
Tobin Ehlis | 04356f9 | 2015-10-27 16:35:27 -0600 | [diff] [blame] | 8818 | vkUpdateDescriptorSets(m_device->device(), 0, NULL, 1, ©_ds_update); |
| 8819 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 8820 | m_errorMonitor->VerifyFound(); |
Tobin Ehlis | 04356f9 | 2015-10-27 16:35:27 -0600 | [diff] [blame] | 8821 | |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 8822 | vkDestroySampler(m_device->device(), sampler, NULL); |
| 8823 | vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL); |
| 8824 | vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL); |
Tobin Ehlis | 04356f9 | 2015-10-27 16:35:27 -0600 | [diff] [blame] | 8825 | } |
| 8826 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8827 | TEST_F(VkLayerTest, NumSamplesMismatch) { |
| 8828 | // Create CommandBuffer where MSAA samples doesn't match RenderPass |
| 8829 | // sampleCount |
| 8830 | VkResult err; |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 8831 | |
Courtney Goeltzenleuchter | 7415d5a | 2015-12-09 15:48:16 -0700 | [diff] [blame] | 8832 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8833 | "Num samples mismatch! "); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 8834 | |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 8835 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 8836 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
Chia-I Wu | 1b99bb2 | 2015-10-27 19:25:11 +0800 | [diff] [blame] | 8837 | VkDescriptorPoolSize ds_type_count = {}; |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 8838 | ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
Chia-I Wu | d50a7d7 | 2015-10-26 20:48:51 +0800 | [diff] [blame] | 8839 | ds_type_count.descriptorCount = 1; |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 8840 | |
| 8841 | VkDescriptorPoolCreateInfo ds_pool_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8842 | ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO; |
| 8843 | ds_pool_ci.pNext = NULL; |
| 8844 | ds_pool_ci.maxSets = 1; |
| 8845 | ds_pool_ci.poolSizeCount = 1; |
| 8846 | ds_pool_ci.pPoolSizes = &ds_type_count; |
Courtney Goeltzenleuchter | fe908d3 | 2015-09-16 16:12:45 -0600 | [diff] [blame] | 8847 | |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 8848 | VkDescriptorPool ds_pool; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8849 | err = |
| 8850 | vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool); |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 8851 | ASSERT_VK_SUCCESS(err); |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 8852 | |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 8853 | VkDescriptorSetLayoutBinding dsl_binding = {}; |
Chia-I Wu | d46e6ae | 2015-10-31 00:31:16 +0800 | [diff] [blame] | 8854 | dsl_binding.binding = 0; |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 8855 | dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
Chia-I Wu | 0212448 | 2015-11-06 06:42:02 +0800 | [diff] [blame] | 8856 | dsl_binding.descriptorCount = 1; |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 8857 | dsl_binding.stageFlags = VK_SHADER_STAGE_ALL; |
| 8858 | dsl_binding.pImmutableSamplers = NULL; |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 8859 | |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 8860 | VkDescriptorSetLayoutCreateInfo ds_layout_ci = {}; |
| 8861 | ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO; |
| 8862 | ds_layout_ci.pNext = NULL; |
Chia-I Wu | d50a7d7 | 2015-10-26 20:48:51 +0800 | [diff] [blame] | 8863 | ds_layout_ci.bindingCount = 1; |
Jon Ashburn | 6e23c1f | 2015-12-30 18:01:16 -0700 | [diff] [blame] | 8864 | ds_layout_ci.pBindings = &dsl_binding; |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 8865 | |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 8866 | VkDescriptorSetLayout ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8867 | err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, |
| 8868 | &ds_layout); |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 8869 | ASSERT_VK_SUCCESS(err); |
| 8870 | |
| 8871 | VkDescriptorSet descriptorSet; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 8872 | VkDescriptorSetAllocateInfo alloc_info = {}; |
Chia-I Wu | 00ce540 | 2015-11-10 16:21:09 +0800 | [diff] [blame] | 8873 | alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO; |
Jon Ashburn | f19916e | 2016-01-11 13:12:43 -0700 | [diff] [blame] | 8874 | alloc_info.descriptorSetCount = 1; |
Courtney Goeltzenleuchter | bee18a9 | 2015-10-23 14:21:05 -0600 | [diff] [blame] | 8875 | alloc_info.descriptorPool = ds_pool; |
| 8876 | alloc_info.pSetLayouts = &ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8877 | err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, |
| 8878 | &descriptorSet); |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 8879 | ASSERT_VK_SUCCESS(err); |
| 8880 | |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 8881 | VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8882 | pipe_ms_state_ci.sType = |
| 8883 | VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO; |
| 8884 | pipe_ms_state_ci.pNext = NULL; |
| 8885 | pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_4_BIT; |
| 8886 | pipe_ms_state_ci.sampleShadingEnable = 0; |
| 8887 | pipe_ms_state_ci.minSampleShading = 1.0; |
| 8888 | pipe_ms_state_ci.pSampleMask = NULL; |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 8889 | |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 8890 | VkPipelineLayoutCreateInfo pipeline_layout_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8891 | pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO; |
| 8892 | pipeline_layout_ci.pNext = NULL; |
| 8893 | pipeline_layout_ci.setLayoutCount = 1; |
| 8894 | pipeline_layout_ci.pSetLayouts = &ds_layout; |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 8895 | |
| 8896 | VkPipelineLayout pipeline_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8897 | err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, |
| 8898 | &pipeline_layout); |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 8899 | ASSERT_VK_SUCCESS(err); |
| 8900 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8901 | VkShaderObj vs(m_device, bindStateVertShaderText, |
| 8902 | VK_SHADER_STAGE_VERTEX_BIT, this); |
| 8903 | VkShaderObj fs(m_device, bindStateFragShaderText, |
| 8904 | VK_SHADER_STAGE_FRAGMENT_BIT, |
Karl Schultz | bdb7595 | 2016-04-19 11:36:49 -0600 | [diff] [blame] | 8905 | this); // We shouldn't need a fragment shader |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8906 | // but add it to be able to run on more devices |
Tony Barbour | 62e1a5b | 2015-08-06 10:16:07 -0600 | [diff] [blame] | 8907 | VkPipelineObj pipe(m_device); |
| 8908 | pipe.AddShader(&vs); |
Tony Barbour | 1c94d37 | 2015-08-06 11:21:08 -0600 | [diff] [blame] | 8909 | pipe.AddShader(&fs); |
Mark Young | c89c631 | 2016-03-31 16:03:20 -0600 | [diff] [blame] | 8910 | pipe.AddColorAttachment(); |
Tony Barbour | 62e1a5b | 2015-08-06 10:16:07 -0600 | [diff] [blame] | 8911 | pipe.SetMSAA(&pipe_ms_state_ci); |
| 8912 | pipe.CreateVKPipeline(pipeline_layout, renderPass()); |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 8913 | |
Tony Barbour | fe3351b | 2015-07-28 10:17:20 -0600 | [diff] [blame] | 8914 | BeginCommandBuffer(); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8915 | vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), |
| 8916 | VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle()); |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 8917 | |
Mark Young | 2992748 | 2016-05-04 14:38:51 -0600 | [diff] [blame] | 8918 | // Render triangle (the error should trigger on the attempt to draw). |
| 8919 | Draw(3, 1, 0, 0); |
| 8920 | |
| 8921 | // Finalize recording of the command buffer |
| 8922 | EndCommandBuffer(); |
| 8923 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 8924 | m_errorMonitor->VerifyFound(); |
Mike Stroyan | d1c84a5 | 2015-08-18 14:40:24 -0600 | [diff] [blame] | 8925 | |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 8926 | vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL); |
| 8927 | vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL); |
| 8928 | vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL); |
Tobin Ehlis | 49eb23d | 2015-05-22 12:38:55 -0600 | [diff] [blame] | 8929 | } |
Mark Young | 2992748 | 2016-05-04 14:38:51 -0600 | [diff] [blame] | 8930 | |
Tobin Ehlis | 85aa15a | 2016-06-15 10:52:37 -0600 | [diff] [blame] | 8931 | TEST_F(VkLayerTest, RenderPassIncompatible) { |
| 8932 | TEST_DESCRIPTION("Hit RenderPass incompatible cases. " |
| 8933 | "Initial case is drawing with an active renderpass that's " |
| 8934 | "not compatible with the bound PSO's creation renderpass"); |
| 8935 | VkResult err; |
| 8936 | |
| 8937 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 8938 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 8939 | |
| 8940 | VkDescriptorSetLayoutBinding dsl_binding = {}; |
| 8941 | dsl_binding.binding = 0; |
| 8942 | dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 8943 | dsl_binding.descriptorCount = 1; |
| 8944 | dsl_binding.stageFlags = VK_SHADER_STAGE_ALL; |
| 8945 | dsl_binding.pImmutableSamplers = NULL; |
| 8946 | |
| 8947 | VkDescriptorSetLayoutCreateInfo ds_layout_ci = {}; |
| 8948 | ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO; |
| 8949 | ds_layout_ci.pNext = NULL; |
| 8950 | ds_layout_ci.bindingCount = 1; |
| 8951 | ds_layout_ci.pBindings = &dsl_binding; |
| 8952 | |
| 8953 | VkDescriptorSetLayout ds_layout; |
| 8954 | err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, |
| 8955 | &ds_layout); |
| 8956 | ASSERT_VK_SUCCESS(err); |
| 8957 | |
| 8958 | VkPipelineLayoutCreateInfo pipeline_layout_ci = {}; |
| 8959 | pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO; |
| 8960 | pipeline_layout_ci.pNext = NULL; |
| 8961 | pipeline_layout_ci.setLayoutCount = 1; |
| 8962 | pipeline_layout_ci.pSetLayouts = &ds_layout; |
| 8963 | |
| 8964 | VkPipelineLayout pipeline_layout; |
| 8965 | err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, |
| 8966 | &pipeline_layout); |
| 8967 | ASSERT_VK_SUCCESS(err); |
| 8968 | |
| 8969 | VkShaderObj vs(m_device, bindStateVertShaderText, |
| 8970 | VK_SHADER_STAGE_VERTEX_BIT, this); |
| 8971 | VkShaderObj fs(m_device, bindStateFragShaderText, |
| 8972 | VK_SHADER_STAGE_FRAGMENT_BIT, |
| 8973 | this); // We shouldn't need a fragment shader |
| 8974 | // but add it to be able to run on more devices |
| 8975 | // Create a renderpass that will be incompatible with default renderpass |
| 8976 | VkAttachmentReference attach = {}; |
| 8977 | attach.layout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL; |
| 8978 | VkAttachmentReference color_att = {}; |
| 8979 | color_att.layout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL; |
| 8980 | VkSubpassDescription subpass = {}; |
| 8981 | subpass.inputAttachmentCount = 1; |
| 8982 | subpass.pInputAttachments = &attach; |
| 8983 | subpass.colorAttachmentCount = 1; |
| 8984 | subpass.pColorAttachments = &color_att; |
| 8985 | VkRenderPassCreateInfo rpci = {}; |
| 8986 | rpci.subpassCount = 1; |
| 8987 | rpci.pSubpasses = &subpass; |
| 8988 | rpci.attachmentCount = 1; |
| 8989 | VkAttachmentDescription attach_desc = {}; |
| 8990 | attach_desc.samples = VK_SAMPLE_COUNT_1_BIT; |
| 8991 | // Format incompatible with PSO RP color attach format RGBA8_UNORM |
| 8992 | attach_desc.format = VK_FORMAT_UNDEFINED; |
| 8993 | rpci.pAttachments = &attach_desc; |
| 8994 | rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO; |
| 8995 | VkRenderPass rp; |
| 8996 | vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp); |
| 8997 | VkPipelineObj pipe(m_device); |
| 8998 | pipe.AddShader(&vs); |
| 8999 | pipe.AddShader(&fs); |
| 9000 | pipe.AddColorAttachment(); |
| 9001 | VkViewport view_port = {}; |
| 9002 | m_viewports.push_back(view_port); |
| 9003 | pipe.SetViewport(m_viewports); |
| 9004 | VkRect2D rect = {}; |
| 9005 | m_scissors.push_back(rect); |
| 9006 | pipe.SetScissor(m_scissors); |
| 9007 | pipe.CreateVKPipeline(pipeline_layout, renderPass()); |
| 9008 | |
| 9009 | VkCommandBufferInheritanceInfo cbii = {}; |
| 9010 | cbii.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO; |
| 9011 | cbii.renderPass = rp; |
| 9012 | cbii.subpass = 0; |
| 9013 | VkCommandBufferBeginInfo cbbi = {}; |
| 9014 | cbbi.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO; |
| 9015 | cbbi.pInheritanceInfo = &cbii; |
| 9016 | vkBeginCommandBuffer(m_commandBuffer->handle(), &cbbi); |
| 9017 | VkRenderPassBeginInfo rpbi = {}; |
| 9018 | rpbi.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO; |
| 9019 | rpbi.framebuffer = m_framebuffer; |
| 9020 | rpbi.renderPass = rp; |
| 9021 | vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &rpbi, |
| 9022 | VK_SUBPASS_CONTENTS_INLINE); |
| 9023 | vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), |
| 9024 | VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle()); |
| 9025 | |
| 9026 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 9027 | " is incompatible w/ gfx pipeline "); |
| 9028 | // Render triangle (the error should trigger on the attempt to draw). |
| 9029 | Draw(3, 1, 0, 0); |
| 9030 | |
| 9031 | // Finalize recording of the command buffer |
| 9032 | EndCommandBuffer(); |
| 9033 | |
| 9034 | m_errorMonitor->VerifyFound(); |
| 9035 | |
| 9036 | vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL); |
| 9037 | vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL); |
| 9038 | vkDestroyRenderPass(m_device->device(), rp, NULL); |
| 9039 | } |
| 9040 | |
Mark Young | c89c631 | 2016-03-31 16:03:20 -0600 | [diff] [blame] | 9041 | TEST_F(VkLayerTest, NumBlendAttachMismatch) { |
| 9042 | // Create Pipeline where the number of blend attachments doesn't match the |
| 9043 | // number of color attachments. In this case, we don't add any color |
| 9044 | // blend attachments even though we have a color attachment. |
| 9045 | VkResult err; |
| 9046 | |
| 9047 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Mark Young | 2992748 | 2016-05-04 14:38:51 -0600 | [diff] [blame] | 9048 | "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] | 9049 | |
| 9050 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 9051 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 9052 | VkDescriptorPoolSize ds_type_count = {}; |
| 9053 | ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 9054 | ds_type_count.descriptorCount = 1; |
| 9055 | |
| 9056 | VkDescriptorPoolCreateInfo ds_pool_ci = {}; |
| 9057 | ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO; |
| 9058 | ds_pool_ci.pNext = NULL; |
| 9059 | ds_pool_ci.maxSets = 1; |
| 9060 | ds_pool_ci.poolSizeCount = 1; |
| 9061 | ds_pool_ci.pPoolSizes = &ds_type_count; |
| 9062 | |
| 9063 | VkDescriptorPool ds_pool; |
| 9064 | err = |
| 9065 | vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool); |
| 9066 | ASSERT_VK_SUCCESS(err); |
| 9067 | |
| 9068 | VkDescriptorSetLayoutBinding dsl_binding = {}; |
| 9069 | dsl_binding.binding = 0; |
| 9070 | dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 9071 | dsl_binding.descriptorCount = 1; |
| 9072 | dsl_binding.stageFlags = VK_SHADER_STAGE_ALL; |
| 9073 | dsl_binding.pImmutableSamplers = NULL; |
| 9074 | |
| 9075 | VkDescriptorSetLayoutCreateInfo ds_layout_ci = {}; |
| 9076 | ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO; |
| 9077 | ds_layout_ci.pNext = NULL; |
| 9078 | ds_layout_ci.bindingCount = 1; |
| 9079 | ds_layout_ci.pBindings = &dsl_binding; |
| 9080 | |
| 9081 | VkDescriptorSetLayout ds_layout; |
| 9082 | err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, |
| 9083 | &ds_layout); |
| 9084 | ASSERT_VK_SUCCESS(err); |
| 9085 | |
| 9086 | VkDescriptorSet descriptorSet; |
| 9087 | VkDescriptorSetAllocateInfo alloc_info = {}; |
| 9088 | alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO; |
| 9089 | alloc_info.descriptorSetCount = 1; |
| 9090 | alloc_info.descriptorPool = ds_pool; |
| 9091 | alloc_info.pSetLayouts = &ds_layout; |
| 9092 | err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, |
| 9093 | &descriptorSet); |
| 9094 | ASSERT_VK_SUCCESS(err); |
| 9095 | |
| 9096 | VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {}; |
| 9097 | pipe_ms_state_ci.sType = |
| 9098 | VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO; |
| 9099 | pipe_ms_state_ci.pNext = NULL; |
| 9100 | pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT; |
| 9101 | pipe_ms_state_ci.sampleShadingEnable = 0; |
| 9102 | pipe_ms_state_ci.minSampleShading = 1.0; |
| 9103 | pipe_ms_state_ci.pSampleMask = NULL; |
| 9104 | |
| 9105 | VkPipelineLayoutCreateInfo pipeline_layout_ci = {}; |
| 9106 | pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO; |
| 9107 | pipeline_layout_ci.pNext = NULL; |
| 9108 | pipeline_layout_ci.setLayoutCount = 1; |
| 9109 | pipeline_layout_ci.pSetLayouts = &ds_layout; |
| 9110 | |
| 9111 | VkPipelineLayout pipeline_layout; |
| 9112 | err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, |
| 9113 | &pipeline_layout); |
| 9114 | ASSERT_VK_SUCCESS(err); |
| 9115 | |
| 9116 | VkShaderObj vs(m_device, bindStateVertShaderText, |
| 9117 | VK_SHADER_STAGE_VERTEX_BIT, this); |
| 9118 | VkShaderObj fs(m_device, bindStateFragShaderText, |
| 9119 | VK_SHADER_STAGE_FRAGMENT_BIT, |
Karl Schultz | bdb7595 | 2016-04-19 11:36:49 -0600 | [diff] [blame] | 9120 | this); // We shouldn't need a fragment shader |
Mark Young | c89c631 | 2016-03-31 16:03:20 -0600 | [diff] [blame] | 9121 | // but add it to be able to run on more devices |
| 9122 | VkPipelineObj pipe(m_device); |
| 9123 | pipe.AddShader(&vs); |
| 9124 | pipe.AddShader(&fs); |
| 9125 | pipe.SetMSAA(&pipe_ms_state_ci); |
| 9126 | pipe.CreateVKPipeline(pipeline_layout, renderPass()); |
| 9127 | |
| 9128 | BeginCommandBuffer(); |
| 9129 | vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), |
| 9130 | VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle()); |
| 9131 | |
Mark Young | 2992748 | 2016-05-04 14:38:51 -0600 | [diff] [blame] | 9132 | // Render triangle (the error should trigger on the attempt to draw). |
| 9133 | Draw(3, 1, 0, 0); |
| 9134 | |
| 9135 | // Finalize recording of the command buffer |
| 9136 | EndCommandBuffer(); |
| 9137 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 9138 | m_errorMonitor->VerifyFound(); |
Mark Young | c89c631 | 2016-03-31 16:03:20 -0600 | [diff] [blame] | 9139 | |
| 9140 | vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL); |
| 9141 | vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL); |
| 9142 | vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL); |
| 9143 | } |
Mark Young | 2992748 | 2016-05-04 14:38:51 -0600 | [diff] [blame] | 9144 | |
Mark Mueller | d491441 | 2016-06-13 17:52:06 -0600 | [diff] [blame] | 9145 | TEST_F(VkLayerTest, MissingClearAttachment) { |
| 9146 | TEST_DESCRIPTION("Points to a wrong colorAttachment index in a VkClearAttachment " |
| 9147 | "structure passed to vkCmdClearAttachments"); |
| 9148 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 9149 | "vkCmdClearAttachments() attachment index 1 not found in attachment " |
| 9150 | "reference array of active subpass 0"); |
| 9151 | |
| 9152 | VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailCmdClearAttachments); |
| 9153 | m_errorMonitor->VerifyFound(); |
| 9154 | } |
| 9155 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9156 | TEST_F(VkLayerTest, ClearCmdNoDraw) { |
| 9157 | // Create CommandBuffer where we add ClearCmd for FB Color attachment prior |
| 9158 | // to issuing a Draw |
| 9159 | VkResult err; |
Tobin Ehlis | 53eddda | 2015-07-01 16:46:13 -0600 | [diff] [blame] | 9160 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9161 | m_errorMonitor->SetDesiredFailureMsg( |
Tony Barbour | 7e56d30 | 2016-03-02 15:12:01 -0700 | [diff] [blame] | 9162 | VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 9163 | "vkCmdClearAttachments() issued on CB object "); |
| 9164 | |
Tobin Ehlis | 53eddda | 2015-07-01 16:46:13 -0600 | [diff] [blame] | 9165 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 9166 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 9167 | |
Chia-I Wu | 1b99bb2 | 2015-10-27 19:25:11 +0800 | [diff] [blame] | 9168 | VkDescriptorPoolSize ds_type_count = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9169 | ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 9170 | ds_type_count.descriptorCount = 1; |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 9171 | |
| 9172 | VkDescriptorPoolCreateInfo ds_pool_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9173 | ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO; |
| 9174 | ds_pool_ci.pNext = NULL; |
| 9175 | ds_pool_ci.maxSets = 1; |
| 9176 | ds_pool_ci.poolSizeCount = 1; |
| 9177 | ds_pool_ci.pPoolSizes = &ds_type_count; |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 9178 | |
Tobin Ehlis | 53eddda | 2015-07-01 16:46:13 -0600 | [diff] [blame] | 9179 | VkDescriptorPool ds_pool; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9180 | err = |
| 9181 | vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool); |
Tobin Ehlis | 53eddda | 2015-07-01 16:46:13 -0600 | [diff] [blame] | 9182 | ASSERT_VK_SUCCESS(err); |
| 9183 | |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 9184 | VkDescriptorSetLayoutBinding dsl_binding = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9185 | dsl_binding.binding = 0; |
| 9186 | dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 9187 | dsl_binding.descriptorCount = 1; |
| 9188 | dsl_binding.stageFlags = VK_SHADER_STAGE_ALL; |
| 9189 | dsl_binding.pImmutableSamplers = NULL; |
Tobin Ehlis | 53eddda | 2015-07-01 16:46:13 -0600 | [diff] [blame] | 9190 | |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 9191 | VkDescriptorSetLayoutCreateInfo ds_layout_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9192 | ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO; |
| 9193 | ds_layout_ci.pNext = NULL; |
| 9194 | ds_layout_ci.bindingCount = 1; |
| 9195 | ds_layout_ci.pBindings = &dsl_binding; |
Mark Lobodzinski | 209b529 | 2015-09-17 09:44:05 -0600 | [diff] [blame] | 9196 | |
Tobin Ehlis | 53eddda | 2015-07-01 16:46:13 -0600 | [diff] [blame] | 9197 | VkDescriptorSetLayout ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9198 | err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, |
| 9199 | &ds_layout); |
Tobin Ehlis | 53eddda | 2015-07-01 16:46:13 -0600 | [diff] [blame] | 9200 | ASSERT_VK_SUCCESS(err); |
| 9201 | |
| 9202 | VkDescriptorSet descriptorSet; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 9203 | VkDescriptorSetAllocateInfo alloc_info = {}; |
Chia-I Wu | 00ce540 | 2015-11-10 16:21:09 +0800 | [diff] [blame] | 9204 | alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO; |
Jon Ashburn | f19916e | 2016-01-11 13:12:43 -0700 | [diff] [blame] | 9205 | alloc_info.descriptorSetCount = 1; |
Courtney Goeltzenleuchter | bee18a9 | 2015-10-23 14:21:05 -0600 | [diff] [blame] | 9206 | alloc_info.descriptorPool = ds_pool; |
| 9207 | alloc_info.pSetLayouts = &ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9208 | err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, |
| 9209 | &descriptorSet); |
Tobin Ehlis | 53eddda | 2015-07-01 16:46:13 -0600 | [diff] [blame] | 9210 | ASSERT_VK_SUCCESS(err); |
| 9211 | |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 9212 | VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9213 | pipe_ms_state_ci.sType = |
| 9214 | VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO; |
| 9215 | pipe_ms_state_ci.pNext = NULL; |
| 9216 | pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_4_BIT; |
| 9217 | pipe_ms_state_ci.sampleShadingEnable = 0; |
| 9218 | pipe_ms_state_ci.minSampleShading = 1.0; |
| 9219 | pipe_ms_state_ci.pSampleMask = NULL; |
Tobin Ehlis | 53eddda | 2015-07-01 16:46:13 -0600 | [diff] [blame] | 9220 | |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 9221 | VkPipelineLayoutCreateInfo pipeline_layout_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9222 | pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO; |
| 9223 | pipeline_layout_ci.pNext = NULL; |
| 9224 | pipeline_layout_ci.setLayoutCount = 1; |
| 9225 | pipeline_layout_ci.pSetLayouts = &ds_layout; |
Tobin Ehlis | 53eddda | 2015-07-01 16:46:13 -0600 | [diff] [blame] | 9226 | |
| 9227 | VkPipelineLayout pipeline_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9228 | err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, |
| 9229 | &pipeline_layout); |
Tobin Ehlis | 53eddda | 2015-07-01 16:46:13 -0600 | [diff] [blame] | 9230 | ASSERT_VK_SUCCESS(err); |
Mark Lobodzinski | 209b529 | 2015-09-17 09:44:05 -0600 | [diff] [blame] | 9231 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9232 | VkShaderObj vs(m_device, bindStateVertShaderText, |
| 9233 | VK_SHADER_STAGE_VERTEX_BIT, this); |
Karl Schultz | bdb7595 | 2016-04-19 11:36:49 -0600 | [diff] [blame] | 9234 | // 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] | 9235 | // on more devices |
| 9236 | VkShaderObj fs(m_device, bindStateFragShaderText, |
| 9237 | VK_SHADER_STAGE_FRAGMENT_BIT, this); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 9238 | |
Tony Barbour | 62e1a5b | 2015-08-06 10:16:07 -0600 | [diff] [blame] | 9239 | VkPipelineObj pipe(m_device); |
| 9240 | pipe.AddShader(&vs); |
Tony Barbour | 1c94d37 | 2015-08-06 11:21:08 -0600 | [diff] [blame] | 9241 | pipe.AddShader(&fs); |
Tony Barbour | 62e1a5b | 2015-08-06 10:16:07 -0600 | [diff] [blame] | 9242 | pipe.SetMSAA(&pipe_ms_state_ci); |
| 9243 | pipe.CreateVKPipeline(pipeline_layout, renderPass()); |
Tony Barbour | fe3351b | 2015-07-28 10:17:20 -0600 | [diff] [blame] | 9244 | |
| 9245 | BeginCommandBuffer(); |
Tobin Ehlis | 53eddda | 2015-07-01 16:46:13 -0600 | [diff] [blame] | 9246 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9247 | // Main thing we care about for this test is that the VkImage obj we're |
| 9248 | // clearing matches Color Attachment of FB |
Tobin Ehlis | 53eddda | 2015-07-01 16:46:13 -0600 | [diff] [blame] | 9249 | // Also pass down other dummy params to keep driver and paramchecker happy |
Courtney Goeltzenleuchter | c9323e0 | 2015-10-15 16:51:05 -0600 | [diff] [blame] | 9250 | VkClearAttachment color_attachment; |
| 9251 | color_attachment.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; |
| 9252 | color_attachment.clearValue.color.float32[0] = 1.0; |
| 9253 | color_attachment.clearValue.color.float32[1] = 1.0; |
| 9254 | color_attachment.clearValue.color.float32[2] = 1.0; |
| 9255 | color_attachment.clearValue.color.float32[3] = 1.0; |
| 9256 | color_attachment.colorAttachment = 0; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9257 | VkClearRect clear_rect = { |
| 9258 | {{0, 0}, {(uint32_t)m_width, (uint32_t)m_height}}}; |
Tobin Ehlis | 53eddda | 2015-07-01 16:46:13 -0600 | [diff] [blame] | 9259 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9260 | vkCmdClearAttachments(m_commandBuffer->GetBufferHandle(), 1, |
| 9261 | &color_attachment, 1, &clear_rect); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 9262 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 9263 | m_errorMonitor->VerifyFound(); |
Mike Stroyan | d1c84a5 | 2015-08-18 14:40:24 -0600 | [diff] [blame] | 9264 | |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 9265 | vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL); |
| 9266 | vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL); |
| 9267 | vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL); |
Tobin Ehlis | 53eddda | 2015-07-01 16:46:13 -0600 | [diff] [blame] | 9268 | } |
| 9269 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9270 | TEST_F(VkLayerTest, VtxBufferBadIndex) { |
| 9271 | VkResult err; |
Tobin Ehlis | 502480b | 2015-06-24 15:53:07 -0600 | [diff] [blame] | 9272 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9273 | m_errorMonitor->SetDesiredFailureMsg( |
Mark Lobodzinski | 510e20d | 2016-02-11 09:26:16 -0700 | [diff] [blame] | 9274 | VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, |
Mark Lobodzinski | dfcd9b6 | 2015-12-14 15:14:10 -0700 | [diff] [blame] | 9275 | "but no vertex buffers are attached to this Pipeline State Object"); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 9276 | |
Tobin Ehlis | 502480b | 2015-06-24 15:53:07 -0600 | [diff] [blame] | 9277 | ASSERT_NO_FATAL_FAILURE(InitState()); |
Tobin Ehlis | d332f28 | 2015-10-02 11:00:56 -0600 | [diff] [blame] | 9278 | ASSERT_NO_FATAL_FAILURE(InitViewport()); |
Tobin Ehlis | 502480b | 2015-06-24 15:53:07 -0600 | [diff] [blame] | 9279 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 9280 | |
Chia-I Wu | 1b99bb2 | 2015-10-27 19:25:11 +0800 | [diff] [blame] | 9281 | VkDescriptorPoolSize ds_type_count = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9282 | ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 9283 | ds_type_count.descriptorCount = 1; |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 9284 | |
| 9285 | VkDescriptorPoolCreateInfo ds_pool_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9286 | ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO; |
| 9287 | ds_pool_ci.pNext = NULL; |
| 9288 | ds_pool_ci.maxSets = 1; |
| 9289 | ds_pool_ci.poolSizeCount = 1; |
| 9290 | ds_pool_ci.pPoolSizes = &ds_type_count; |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 9291 | |
Courtney Goeltzenleuchter | fe908d3 | 2015-09-16 16:12:45 -0600 | [diff] [blame] | 9292 | VkDescriptorPool ds_pool; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9293 | err = |
| 9294 | vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool); |
Tobin Ehlis | 502480b | 2015-06-24 15:53:07 -0600 | [diff] [blame] | 9295 | ASSERT_VK_SUCCESS(err); |
| 9296 | |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 9297 | VkDescriptorSetLayoutBinding dsl_binding = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9298 | dsl_binding.binding = 0; |
| 9299 | dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 9300 | dsl_binding.descriptorCount = 1; |
| 9301 | dsl_binding.stageFlags = VK_SHADER_STAGE_ALL; |
| 9302 | dsl_binding.pImmutableSamplers = NULL; |
Tobin Ehlis | 502480b | 2015-06-24 15:53:07 -0600 | [diff] [blame] | 9303 | |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 9304 | VkDescriptorSetLayoutCreateInfo ds_layout_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9305 | ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO; |
| 9306 | ds_layout_ci.pNext = NULL; |
| 9307 | ds_layout_ci.bindingCount = 1; |
| 9308 | ds_layout_ci.pBindings = &dsl_binding; |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 9309 | |
Tobin Ehlis | 502480b | 2015-06-24 15:53:07 -0600 | [diff] [blame] | 9310 | VkDescriptorSetLayout ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9311 | err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, |
| 9312 | &ds_layout); |
Tobin Ehlis | 502480b | 2015-06-24 15:53:07 -0600 | [diff] [blame] | 9313 | ASSERT_VK_SUCCESS(err); |
| 9314 | |
| 9315 | VkDescriptorSet descriptorSet; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 9316 | VkDescriptorSetAllocateInfo alloc_info = {}; |
Chia-I Wu | 00ce540 | 2015-11-10 16:21:09 +0800 | [diff] [blame] | 9317 | alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO; |
Jon Ashburn | f19916e | 2016-01-11 13:12:43 -0700 | [diff] [blame] | 9318 | alloc_info.descriptorSetCount = 1; |
Courtney Goeltzenleuchter | bee18a9 | 2015-10-23 14:21:05 -0600 | [diff] [blame] | 9319 | alloc_info.descriptorPool = ds_pool; |
| 9320 | alloc_info.pSetLayouts = &ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9321 | err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, |
| 9322 | &descriptorSet); |
Tobin Ehlis | 502480b | 2015-06-24 15:53:07 -0600 | [diff] [blame] | 9323 | ASSERT_VK_SUCCESS(err); |
| 9324 | |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 9325 | VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9326 | pipe_ms_state_ci.sType = |
| 9327 | VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO; |
| 9328 | pipe_ms_state_ci.pNext = NULL; |
| 9329 | pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT; |
| 9330 | pipe_ms_state_ci.sampleShadingEnable = 0; |
| 9331 | pipe_ms_state_ci.minSampleShading = 1.0; |
| 9332 | pipe_ms_state_ci.pSampleMask = NULL; |
Tobin Ehlis | 502480b | 2015-06-24 15:53:07 -0600 | [diff] [blame] | 9333 | |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 9334 | VkPipelineLayoutCreateInfo pipeline_layout_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9335 | pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO; |
| 9336 | pipeline_layout_ci.pNext = NULL; |
| 9337 | pipeline_layout_ci.setLayoutCount = 1; |
| 9338 | pipeline_layout_ci.pSetLayouts = &ds_layout; |
| 9339 | VkPipelineLayout pipeline_layout; |
Tobin Ehlis | 502480b | 2015-06-24 15:53:07 -0600 | [diff] [blame] | 9340 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9341 | err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, |
| 9342 | &pipeline_layout); |
Tobin Ehlis | 502480b | 2015-06-24 15:53:07 -0600 | [diff] [blame] | 9343 | ASSERT_VK_SUCCESS(err); |
| 9344 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9345 | VkShaderObj vs(m_device, bindStateVertShaderText, |
| 9346 | VK_SHADER_STAGE_VERTEX_BIT, this); |
| 9347 | VkShaderObj fs(m_device, bindStateFragShaderText, |
| 9348 | VK_SHADER_STAGE_FRAGMENT_BIT, |
Karl Schultz | bdb7595 | 2016-04-19 11:36:49 -0600 | [diff] [blame] | 9349 | this); // We shouldn't need a fragment shader |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9350 | // but add it to be able to run on more devices |
Tony Barbour | 62e1a5b | 2015-08-06 10:16:07 -0600 | [diff] [blame] | 9351 | VkPipelineObj pipe(m_device); |
| 9352 | pipe.AddShader(&vs); |
Tony Barbour | 1c94d37 | 2015-08-06 11:21:08 -0600 | [diff] [blame] | 9353 | pipe.AddShader(&fs); |
Mark Young | c89c631 | 2016-03-31 16:03:20 -0600 | [diff] [blame] | 9354 | pipe.AddColorAttachment(); |
Tony Barbour | 62e1a5b | 2015-08-06 10:16:07 -0600 | [diff] [blame] | 9355 | pipe.SetMSAA(&pipe_ms_state_ci); |
Tobin Ehlis | d332f28 | 2015-10-02 11:00:56 -0600 | [diff] [blame] | 9356 | pipe.SetViewport(m_viewports); |
| 9357 | pipe.SetScissor(m_scissors); |
Tony Barbour | 62e1a5b | 2015-08-06 10:16:07 -0600 | [diff] [blame] | 9358 | pipe.CreateVKPipeline(pipeline_layout, renderPass()); |
Tony Barbour | fe3351b | 2015-07-28 10:17:20 -0600 | [diff] [blame] | 9359 | |
| 9360 | BeginCommandBuffer(); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9361 | vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), |
| 9362 | VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle()); |
Tobin Ehlis | f7bf450 | 2015-09-09 15:12:35 -0600 | [diff] [blame] | 9363 | // Don't care about actual data, just need to get to draw to flag error |
| 9364 | static const float vbo_data[3] = {1.f, 0.f, 1.f}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9365 | VkConstantBufferObj vbo(m_device, sizeof(vbo_data), sizeof(float), |
| 9366 | (const void *)&vbo_data); |
Tobin Ehlis | f7bf450 | 2015-09-09 15:12:35 -0600 | [diff] [blame] | 9367 | 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] | 9368 | Draw(1, 0, 0, 0); |
Tobin Ehlis | 502480b | 2015-06-24 15:53:07 -0600 | [diff] [blame] | 9369 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 9370 | m_errorMonitor->VerifyFound(); |
Mike Stroyan | d1c84a5 | 2015-08-18 14:40:24 -0600 | [diff] [blame] | 9371 | |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 9372 | vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL); |
| 9373 | vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL); |
| 9374 | vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL); |
Tobin Ehlis | 502480b | 2015-06-24 15:53:07 -0600 | [diff] [blame] | 9375 | } |
Tobin Ehlis | c555a3c | 2016-05-04 14:08:34 -0600 | [diff] [blame] | 9376 | // INVALID_IMAGE_LAYOUT tests (one other case is hit by MapMemWithoutHostVisibleBit and not here) |
| 9377 | TEST_F(VkLayerTest, InvalidImageLayout) { |
| 9378 | TEST_DESCRIPTION("Hit all possible validation checks associated with the " |
| 9379 | "DRAWSTATE_INVALID_IMAGE_LAYOUT enum. Generally these involve having" |
| 9380 | "images in the wrong layout when they're copied or transitioned."); |
| 9381 | // 3 in ValidateCmdBufImageLayouts |
| 9382 | // * -1 Attempt to submit cmd buf w/ deleted image |
| 9383 | // * -2 Cmd buf submit of image w/ layout not matching first use w/ subresource |
| 9384 | // * -3 Cmd buf submit of image w/ layout not matching first use w/o subresource |
| 9385 | m_errorMonitor->SetDesiredFailureMsg( |
| 9386 | VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, |
| 9387 | "Layout for input image should be TRANSFER_SRC_OPTIMAL instead of GENERAL."); |
| 9388 | |
| 9389 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 9390 | // Create src & dst images to use for copy operations |
| 9391 | VkImage src_image; |
| 9392 | VkImage dst_image; |
| 9393 | |
| 9394 | const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM; |
| 9395 | const int32_t tex_width = 32; |
| 9396 | const int32_t tex_height = 32; |
| 9397 | |
| 9398 | VkImageCreateInfo image_create_info = {}; |
| 9399 | image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO; |
| 9400 | image_create_info.pNext = NULL; |
| 9401 | image_create_info.imageType = VK_IMAGE_TYPE_2D; |
| 9402 | image_create_info.format = tex_format; |
| 9403 | image_create_info.extent.width = tex_width; |
| 9404 | image_create_info.extent.height = tex_height; |
| 9405 | image_create_info.extent.depth = 1; |
| 9406 | image_create_info.mipLevels = 1; |
| 9407 | image_create_info.arrayLayers = 4; |
| 9408 | image_create_info.samples = VK_SAMPLE_COUNT_1_BIT; |
| 9409 | image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL; |
| 9410 | image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT; |
| 9411 | image_create_info.flags = 0; |
| 9412 | |
| 9413 | VkResult err = vkCreateImage(m_device->device(), &image_create_info, NULL, &src_image); |
| 9414 | ASSERT_VK_SUCCESS(err); |
| 9415 | err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dst_image); |
| 9416 | ASSERT_VK_SUCCESS(err); |
| 9417 | |
| 9418 | BeginCommandBuffer(); |
| 9419 | VkImageCopy copyRegion; |
| 9420 | copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; |
| 9421 | copyRegion.srcSubresource.mipLevel = 0; |
| 9422 | copyRegion.srcSubresource.baseArrayLayer = 0; |
| 9423 | copyRegion.srcSubresource.layerCount = 1; |
| 9424 | copyRegion.srcOffset.x = 0; |
| 9425 | copyRegion.srcOffset.y = 0; |
| 9426 | copyRegion.srcOffset.z = 0; |
| 9427 | copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; |
| 9428 | copyRegion.dstSubresource.mipLevel = 0; |
| 9429 | copyRegion.dstSubresource.baseArrayLayer = 0; |
| 9430 | copyRegion.dstSubresource.layerCount = 1; |
| 9431 | copyRegion.dstOffset.x = 0; |
| 9432 | copyRegion.dstOffset.y = 0; |
| 9433 | copyRegion.dstOffset.z = 0; |
| 9434 | copyRegion.extent.width = 1; |
| 9435 | copyRegion.extent.height = 1; |
| 9436 | copyRegion.extent.depth = 1; |
| 9437 | m_commandBuffer->CopyImage(src_image, VK_IMAGE_LAYOUT_GENERAL, dst_image, VK_IMAGE_LAYOUT_GENERAL, 1, ©Region); |
| 9438 | m_errorMonitor->VerifyFound(); |
| 9439 | // Now cause error due to src image layout changing |
| 9440 | m_errorMonitor->SetDesiredFailureMsg( |
| 9441 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 9442 | "Cannot copy from an image whose source layout is VK_IMAGE_LAYOUT_UNDEFINED and doesn't match the current layout VK_IMAGE_LAYOUT_GENERAL."); |
| 9443 | m_commandBuffer->CopyImage(src_image, VK_IMAGE_LAYOUT_UNDEFINED, dst_image, VK_IMAGE_LAYOUT_GENERAL, 1, ©Region); |
| 9444 | m_errorMonitor->VerifyFound(); |
| 9445 | // Final src error is due to bad layout type |
| 9446 | m_errorMonitor->SetDesiredFailureMsg( |
| 9447 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 9448 | "Layout for input image is VK_IMAGE_LAYOUT_UNDEFINED but can only be TRANSFER_SRC_OPTIMAL or GENERAL."); |
| 9449 | m_commandBuffer->CopyImage(src_image, VK_IMAGE_LAYOUT_UNDEFINED, dst_image, VK_IMAGE_LAYOUT_GENERAL, 1, ©Region); |
| 9450 | m_errorMonitor->VerifyFound(); |
| 9451 | // Now verify same checks for dst |
| 9452 | m_errorMonitor->SetDesiredFailureMsg( |
| 9453 | VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, |
| 9454 | "Layout for output image should be TRANSFER_DST_OPTIMAL instead of GENERAL."); |
| 9455 | m_commandBuffer->CopyImage(src_image, VK_IMAGE_LAYOUT_GENERAL, dst_image, VK_IMAGE_LAYOUT_GENERAL, 1, ©Region); |
| 9456 | m_errorMonitor->VerifyFound(); |
| 9457 | // Now cause error due to src image layout changing |
| 9458 | m_errorMonitor->SetDesiredFailureMsg( |
| 9459 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 9460 | "Cannot copy from an image whose dest layout is VK_IMAGE_LAYOUT_UNDEFINED and doesn't match the current layout VK_IMAGE_LAYOUT_GENERAL."); |
| 9461 | m_commandBuffer->CopyImage(src_image, VK_IMAGE_LAYOUT_GENERAL, dst_image, VK_IMAGE_LAYOUT_UNDEFINED, 1, ©Region); |
| 9462 | m_errorMonitor->VerifyFound(); |
| 9463 | m_errorMonitor->SetDesiredFailureMsg( |
| 9464 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 9465 | "Layout for output image is VK_IMAGE_LAYOUT_UNDEFINED but can only be TRANSFER_DST_OPTIMAL or GENERAL."); |
| 9466 | m_commandBuffer->CopyImage(src_image, VK_IMAGE_LAYOUT_GENERAL, dst_image, VK_IMAGE_LAYOUT_UNDEFINED, 1, ©Region); |
| 9467 | m_errorMonitor->VerifyFound(); |
| 9468 | // Now cause error due to bad image layout transition in PipelineBarrier |
| 9469 | VkImageMemoryBarrier image_barrier[1] = {}; |
| 9470 | image_barrier[0].oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL; |
| 9471 | image_barrier[0].image = src_image; |
| 9472 | image_barrier[0].subresourceRange.layerCount = 2; |
| 9473 | image_barrier[0].subresourceRange.levelCount = 2; |
| 9474 | image_barrier[0].subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; |
| 9475 | m_errorMonitor->SetDesiredFailureMsg( |
| 9476 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 9477 | "You cannot transition the layout from VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL when current layout is VK_IMAGE_LAYOUT_GENERAL."); |
| 9478 | vkCmdPipelineBarrier(m_commandBuffer->handle(), VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, NULL, 0, NULL, 1, image_barrier); |
| 9479 | m_errorMonitor->VerifyFound(); |
| 9480 | |
| 9481 | // Finally some layout errors at RenderPass create time |
| 9482 | // Just hacking in specific state to get to the errors we want so don't copy this unless you know what you're doing. |
| 9483 | VkAttachmentReference attach = {}; |
| 9484 | // perf warning for GENERAL layout w/ non-DS input attachment |
| 9485 | attach.layout = VK_IMAGE_LAYOUT_GENERAL; |
| 9486 | VkSubpassDescription subpass = {}; |
| 9487 | subpass.inputAttachmentCount = 1; |
| 9488 | subpass.pInputAttachments = &attach; |
| 9489 | VkRenderPassCreateInfo rpci = {}; |
| 9490 | rpci.subpassCount = 1; |
| 9491 | rpci.pSubpasses = &subpass; |
| 9492 | rpci.attachmentCount = 1; |
| 9493 | VkAttachmentDescription attach_desc = {}; |
| 9494 | attach_desc.format = VK_FORMAT_UNDEFINED; |
| 9495 | rpci.pAttachments = &attach_desc; |
Tobin Ehlis | 1efce02 | 2016-05-11 10:40:34 -0600 | [diff] [blame] | 9496 | rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO; |
Tobin Ehlis | c555a3c | 2016-05-04 14:08:34 -0600 | [diff] [blame] | 9497 | VkRenderPass rp; |
| 9498 | m_errorMonitor->SetDesiredFailureMsg( |
| 9499 | VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, |
| 9500 | "Layout for input attachment is GENERAL but should be READ_ONLY_OPTIMAL."); |
| 9501 | vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp); |
| 9502 | m_errorMonitor->VerifyFound(); |
| 9503 | // error w/ non-general layout |
| 9504 | attach.layout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL; |
| 9505 | |
| 9506 | m_errorMonitor->SetDesiredFailureMsg( |
| 9507 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 9508 | "Layout for input attachment is VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL but can only be READ_ONLY_OPTIMAL or GENERAL."); |
| 9509 | vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp); |
| 9510 | m_errorMonitor->VerifyFound(); |
| 9511 | subpass.inputAttachmentCount = 0; |
| 9512 | subpass.colorAttachmentCount = 1; |
| 9513 | subpass.pColorAttachments = &attach; |
| 9514 | attach.layout = VK_IMAGE_LAYOUT_GENERAL; |
| 9515 | // perf warning for GENERAL layout on color attachment |
| 9516 | m_errorMonitor->SetDesiredFailureMsg( |
| 9517 | VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, |
| 9518 | "Layout for color attachment is GENERAL but should be COLOR_ATTACHMENT_OPTIMAL."); |
| 9519 | vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp); |
| 9520 | m_errorMonitor->VerifyFound(); |
| 9521 | // error w/ non-color opt or GENERAL layout for color attachment |
| 9522 | attach.layout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL; |
| 9523 | m_errorMonitor->SetDesiredFailureMsg( |
| 9524 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 9525 | "Layout for color attachment is VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL but can only be COLOR_ATTACHMENT_OPTIMAL or GENERAL."); |
| 9526 | vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp); |
| 9527 | m_errorMonitor->VerifyFound(); |
| 9528 | subpass.colorAttachmentCount = 0; |
| 9529 | subpass.pDepthStencilAttachment = &attach; |
| 9530 | attach.layout = VK_IMAGE_LAYOUT_GENERAL; |
| 9531 | // perf warning for GENERAL layout on DS attachment |
| 9532 | m_errorMonitor->SetDesiredFailureMsg( |
| 9533 | VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, |
| 9534 | "Layout for depth attachment is GENERAL but should be DEPTH_STENCIL_ATTACHMENT_OPTIMAL."); |
| 9535 | vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp); |
| 9536 | m_errorMonitor->VerifyFound(); |
| 9537 | // error w/ non-ds opt or GENERAL layout for color attachment |
| 9538 | attach.layout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL; |
| 9539 | m_errorMonitor->SetDesiredFailureMsg( |
| 9540 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 9541 | "Layout for depth attachment is VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL but can only be DEPTH_STENCIL_ATTACHMENT_OPTIMAL or GENERAL."); |
| 9542 | vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp); |
| 9543 | m_errorMonitor->VerifyFound(); |
Tobin Ehlis | 1efce02 | 2016-05-11 10:40:34 -0600 | [diff] [blame] | 9544 | // For this error we need a valid renderpass so create default one |
| 9545 | attach.layout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL; |
| 9546 | attach.attachment = 0; |
| 9547 | attach_desc.format = VK_FORMAT_D24_UNORM_S8_UINT; |
| 9548 | attach_desc.samples = VK_SAMPLE_COUNT_1_BIT; |
| 9549 | attach_desc.storeOp = VK_ATTACHMENT_STORE_OP_STORE; |
| 9550 | attach_desc.stencilLoadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE; |
| 9551 | attach_desc.stencilStoreOp = VK_ATTACHMENT_STORE_OP_DONT_CARE; |
| 9552 | // Can't do a CLEAR load on READ_ONLY initialLayout |
| 9553 | attach_desc.loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR; |
| 9554 | attach_desc.initialLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL; |
| 9555 | attach_desc.finalLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL; |
| 9556 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 9557 | " with invalid first layout " |
| 9558 | "VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_" |
| 9559 | "ONLY_OPTIMAL"); |
| 9560 | vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp); |
| 9561 | m_errorMonitor->VerifyFound(); |
Tobin Ehlis | c555a3c | 2016-05-04 14:08:34 -0600 | [diff] [blame] | 9562 | |
| 9563 | vkDestroyImage(m_device->device(), src_image, NULL); |
| 9564 | vkDestroyImage(m_device->device(), dst_image, NULL); |
| 9565 | } |
Mark Lobodzinski | 209b529 | 2015-09-17 09:44:05 -0600 | [diff] [blame] | 9566 | #endif // DRAW_STATE_TESTS |
| 9567 | |
Tobin Ehlis | 0788f52 | 2015-05-26 16:11:58 -0600 | [diff] [blame] | 9568 | #if THREADING_TESTS |
Mike Stroyan | accf769 | 2015-05-12 16:00:45 -0600 | [diff] [blame] | 9569 | #if GTEST_IS_THREADSAFE |
| 9570 | struct thread_data_struct { |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 9571 | VkCommandBuffer commandBuffer; |
Mike Stroyan | accf769 | 2015-05-12 16:00:45 -0600 | [diff] [blame] | 9572 | VkEvent event; |
| 9573 | bool bailout; |
| 9574 | }; |
| 9575 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9576 | extern "C" void *AddToCommandBuffer(void *arg) { |
| 9577 | struct thread_data_struct *data = (struct thread_data_struct *)arg; |
Mike Stroyan | accf769 | 2015-05-12 16:00:45 -0600 | [diff] [blame] | 9578 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9579 | for (int i = 0; i < 10000; i++) { |
| 9580 | vkCmdSetEvent(data->commandBuffer, data->event, |
| 9581 | VK_PIPELINE_STAGE_ALL_COMMANDS_BIT); |
Mike Stroyan | accf769 | 2015-05-12 16:00:45 -0600 | [diff] [blame] | 9582 | if (data->bailout) { |
| 9583 | break; |
| 9584 | } |
| 9585 | } |
| 9586 | return NULL; |
| 9587 | } |
| 9588 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9589 | TEST_F(VkLayerTest, ThreadCommandBufferCollision) { |
Mike Stroyan | 4268d1f | 2015-07-13 14:45:35 -0600 | [diff] [blame] | 9590 | test_platform_thread thread; |
Mike Stroyan | accf769 | 2015-05-12 16:00:45 -0600 | [diff] [blame] | 9591 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9592 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 9593 | "THREADING ERROR"); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 9594 | |
Mike Stroyan | accf769 | 2015-05-12 16:00:45 -0600 | [diff] [blame] | 9595 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 9596 | ASSERT_NO_FATAL_FAILURE(InitViewport()); |
| 9597 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 9598 | |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 9599 | // Calls AllocateCommandBuffers |
| 9600 | VkCommandBufferObj commandBuffer(m_device, m_commandPool); |
Mark Lobodzinski | 5495d13 | 2015-09-30 16:19:16 -0600 | [diff] [blame] | 9601 | |
| 9602 | // Avoid creating RenderPass |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 9603 | commandBuffer.BeginCommandBuffer(); |
Mike Stroyan | accf769 | 2015-05-12 16:00:45 -0600 | [diff] [blame] | 9604 | |
| 9605 | VkEventCreateInfo event_info; |
| 9606 | VkEvent event; |
Mike Stroyan | accf769 | 2015-05-12 16:00:45 -0600 | [diff] [blame] | 9607 | VkResult err; |
| 9608 | |
| 9609 | memset(&event_info, 0, sizeof(event_info)); |
| 9610 | event_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO; |
| 9611 | |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 9612 | err = vkCreateEvent(device(), &event_info, NULL, &event); |
Mike Stroyan | accf769 | 2015-05-12 16:00:45 -0600 | [diff] [blame] | 9613 | ASSERT_VK_SUCCESS(err); |
| 9614 | |
Mike Stroyan | accf769 | 2015-05-12 16:00:45 -0600 | [diff] [blame] | 9615 | err = vkResetEvent(device(), event); |
| 9616 | ASSERT_VK_SUCCESS(err); |
| 9617 | |
| 9618 | struct thread_data_struct data; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 9619 | data.commandBuffer = commandBuffer.GetBufferHandle(); |
Mike Stroyan | accf769 | 2015-05-12 16:00:45 -0600 | [diff] [blame] | 9620 | data.event = event; |
| 9621 | data.bailout = false; |
| 9622 | m_errorMonitor->SetBailout(&data.bailout); |
| 9623 | // Add many entries to command buffer from another thread. |
Mike Stroyan | 4268d1f | 2015-07-13 14:45:35 -0600 | [diff] [blame] | 9624 | test_platform_thread_create(&thread, AddToCommandBuffer, (void *)&data); |
Mike Stroyan | accf769 | 2015-05-12 16:00:45 -0600 | [diff] [blame] | 9625 | // Add many entries to command buffer from this thread at the same time. |
| 9626 | AddToCommandBuffer(&data); |
Mark Lobodzinski | 5495d13 | 2015-09-30 16:19:16 -0600 | [diff] [blame] | 9627 | |
Mike Stroyan | 4268d1f | 2015-07-13 14:45:35 -0600 | [diff] [blame] | 9628 | test_platform_thread_join(thread, NULL); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 9629 | commandBuffer.EndCommandBuffer(); |
Mike Stroyan | accf769 | 2015-05-12 16:00:45 -0600 | [diff] [blame] | 9630 | |
Mike Stroyan | 10b8cb7 | 2016-01-22 15:22:03 -0700 | [diff] [blame] | 9631 | m_errorMonitor->SetBailout(NULL); |
| 9632 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 9633 | m_errorMonitor->VerifyFound(); |
Mike Stroyan | accf769 | 2015-05-12 16:00:45 -0600 | [diff] [blame] | 9634 | |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 9635 | vkDestroyEvent(device(), event, NULL); |
Mike Stroyan | accf769 | 2015-05-12 16:00:45 -0600 | [diff] [blame] | 9636 | } |
Mark Lobodzinski | 209b529 | 2015-09-17 09:44:05 -0600 | [diff] [blame] | 9637 | #endif // GTEST_IS_THREADSAFE |
| 9638 | #endif // THREADING_TESTS |
| 9639 | |
Chris Forbes | 9f7ff63 | 2015-05-25 11:13:08 +1200 | [diff] [blame] | 9640 | #if SHADER_CHECKER_TESTS |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9641 | TEST_F(VkLayerTest, InvalidSPIRVCodeSize) { |
Courtney Goeltzenleuchter | 7415d5a | 2015-12-09 15:48:16 -0700 | [diff] [blame] | 9642 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Chris Forbes | b4afd0f | 2016-04-04 10:48:35 +1200 | [diff] [blame] | 9643 | "Invalid SPIR-V header"); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 9644 | |
Courtney Goeltzenleuchter | 00c52b2 | 2015-09-16 12:58:29 -0600 | [diff] [blame] | 9645 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 9646 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 9647 | |
Courtney Goeltzenleuchter | 00c52b2 | 2015-09-16 12:58:29 -0600 | [diff] [blame] | 9648 | VkShaderModule module; |
| 9649 | VkShaderModuleCreateInfo moduleCreateInfo; |
| 9650 | struct icd_spv_header spv; |
| 9651 | |
| 9652 | spv.magic = ICD_SPV_MAGIC; |
| 9653 | spv.version = ICD_SPV_VERSION; |
| 9654 | spv.gen_magic = 0; |
| 9655 | |
| 9656 | moduleCreateInfo.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO; |
| 9657 | moduleCreateInfo.pNext = NULL; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9658 | moduleCreateInfo.pCode = (const uint32_t *)&spv; |
Courtney Goeltzenleuchter | 00c52b2 | 2015-09-16 12:58:29 -0600 | [diff] [blame] | 9659 | moduleCreateInfo.codeSize = 4; |
| 9660 | moduleCreateInfo.flags = 0; |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 9661 | vkCreateShaderModule(m_device->device(), &moduleCreateInfo, NULL, &module); |
Courtney Goeltzenleuchter | 00c52b2 | 2015-09-16 12:58:29 -0600 | [diff] [blame] | 9662 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 9663 | m_errorMonitor->VerifyFound(); |
Courtney Goeltzenleuchter | 00c52b2 | 2015-09-16 12:58:29 -0600 | [diff] [blame] | 9664 | } |
| 9665 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9666 | TEST_F(VkLayerTest, InvalidSPIRVMagic) { |
Courtney Goeltzenleuchter | 7415d5a | 2015-12-09 15:48:16 -0700 | [diff] [blame] | 9667 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Chris Forbes | b4afd0f | 2016-04-04 10:48:35 +1200 | [diff] [blame] | 9668 | "Invalid SPIR-V magic number"); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 9669 | |
Courtney Goeltzenleuchter | 00c52b2 | 2015-09-16 12:58:29 -0600 | [diff] [blame] | 9670 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 9671 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 9672 | |
Courtney Goeltzenleuchter | 00c52b2 | 2015-09-16 12:58:29 -0600 | [diff] [blame] | 9673 | VkShaderModule module; |
| 9674 | VkShaderModuleCreateInfo moduleCreateInfo; |
| 9675 | struct icd_spv_header spv; |
| 9676 | |
| 9677 | spv.magic = ~ICD_SPV_MAGIC; |
| 9678 | spv.version = ICD_SPV_VERSION; |
| 9679 | spv.gen_magic = 0; |
| 9680 | |
| 9681 | moduleCreateInfo.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO; |
| 9682 | moduleCreateInfo.pNext = NULL; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9683 | moduleCreateInfo.pCode = (const uint32_t *)&spv; |
Courtney Goeltzenleuchter | 00c52b2 | 2015-09-16 12:58:29 -0600 | [diff] [blame] | 9684 | moduleCreateInfo.codeSize = sizeof(spv) + 10; |
| 9685 | moduleCreateInfo.flags = 0; |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 9686 | vkCreateShaderModule(m_device->device(), &moduleCreateInfo, NULL, &module); |
Courtney Goeltzenleuchter | 00c52b2 | 2015-09-16 12:58:29 -0600 | [diff] [blame] | 9687 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 9688 | m_errorMonitor->VerifyFound(); |
Courtney Goeltzenleuchter | 00c52b2 | 2015-09-16 12:58:29 -0600 | [diff] [blame] | 9689 | } |
| 9690 | |
Chris Forbes | b4afd0f | 2016-04-04 10:48:35 +1200 | [diff] [blame] | 9691 | #if 0 |
| 9692 | // Not currently covered by SPIRV-Tools validator |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9693 | TEST_F(VkLayerTest, InvalidSPIRVVersion) { |
Courtney Goeltzenleuchter | 7415d5a | 2015-12-09 15:48:16 -0700 | [diff] [blame] | 9694 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Chris Forbes | b4afd0f | 2016-04-04 10:48:35 +1200 | [diff] [blame] | 9695 | "Invalid SPIR-V header"); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 9696 | |
Courtney Goeltzenleuchter | 00c52b2 | 2015-09-16 12:58:29 -0600 | [diff] [blame] | 9697 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 9698 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 9699 | |
Courtney Goeltzenleuchter | 00c52b2 | 2015-09-16 12:58:29 -0600 | [diff] [blame] | 9700 | VkShaderModule module; |
| 9701 | VkShaderModuleCreateInfo moduleCreateInfo; |
| 9702 | struct icd_spv_header spv; |
| 9703 | |
| 9704 | spv.magic = ICD_SPV_MAGIC; |
| 9705 | spv.version = ~ICD_SPV_VERSION; |
| 9706 | spv.gen_magic = 0; |
| 9707 | |
| 9708 | moduleCreateInfo.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO; |
| 9709 | moduleCreateInfo.pNext = NULL; |
| 9710 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9711 | moduleCreateInfo.pCode = (const uint32_t *)&spv; |
Courtney Goeltzenleuchter | 00c52b2 | 2015-09-16 12:58:29 -0600 | [diff] [blame] | 9712 | moduleCreateInfo.codeSize = sizeof(spv) + 10; |
| 9713 | moduleCreateInfo.flags = 0; |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 9714 | vkCreateShaderModule(m_device->device(), &moduleCreateInfo, NULL, &module); |
Courtney Goeltzenleuchter | 00c52b2 | 2015-09-16 12:58:29 -0600 | [diff] [blame] | 9715 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 9716 | m_errorMonitor->VerifyFound(); |
Courtney Goeltzenleuchter | 00c52b2 | 2015-09-16 12:58:29 -0600 | [diff] [blame] | 9717 | } |
Chris Forbes | b4afd0f | 2016-04-04 10:48:35 +1200 | [diff] [blame] | 9718 | #endif |
Courtney Goeltzenleuchter | 00c52b2 | 2015-09-16 12:58:29 -0600 | [diff] [blame] | 9719 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9720 | TEST_F(VkLayerTest, CreatePipelineVertexOutputNotConsumed) { |
Mark Lobodzinski | 510e20d | 2016-02-11 09:26:16 -0700 | [diff] [blame] | 9721 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9722 | "not consumed by fragment shader"); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 9723 | |
Chris Forbes | 9f7ff63 | 2015-05-25 11:13:08 +1200 | [diff] [blame] | 9724 | ASSERT_NO_FATAL_FAILURE(InitState()); |
Tobin Ehlis | c9ac2b6 | 2015-09-11 12:57:55 -0600 | [diff] [blame] | 9725 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
Chris Forbes | 9f7ff63 | 2015-05-25 11:13:08 +1200 | [diff] [blame] | 9726 | |
| 9727 | char const *vsSource = |
Chris Forbes | 3846771 | 2016-04-04 17:28:05 +1200 | [diff] [blame] | 9728 | "#version 450\n" |
Chris Forbes | 9f7ff63 | 2015-05-25 11:13:08 +1200 | [diff] [blame] | 9729 | "\n" |
| 9730 | "layout(location=0) out float x;\n" |
Tony Barbour | e804d20 | 2016-01-05 13:37:45 -0700 | [diff] [blame] | 9731 | "out gl_PerVertex {\n" |
| 9732 | " vec4 gl_Position;\n" |
| 9733 | "};\n" |
Chris Forbes | 9f7ff63 | 2015-05-25 11:13:08 +1200 | [diff] [blame] | 9734 | "void main(){\n" |
| 9735 | " gl_Position = vec4(1);\n" |
| 9736 | " x = 0;\n" |
| 9737 | "}\n"; |
| 9738 | char const *fsSource = |
Chris Forbes | 3846771 | 2016-04-04 17:28:05 +1200 | [diff] [blame] | 9739 | "#version 450\n" |
Chris Forbes | 9f7ff63 | 2015-05-25 11:13:08 +1200 | [diff] [blame] | 9740 | "\n" |
| 9741 | "layout(location=0) out vec4 color;\n" |
| 9742 | "void main(){\n" |
| 9743 | " color = vec4(1);\n" |
| 9744 | "}\n"; |
| 9745 | |
Courtney Goeltzenleuchter | d263550 | 2015-10-21 17:08:06 -0600 | [diff] [blame] | 9746 | VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this); |
| 9747 | VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this); |
Chris Forbes | 9f7ff63 | 2015-05-25 11:13:08 +1200 | [diff] [blame] | 9748 | |
| 9749 | VkPipelineObj pipe(m_device); |
Chia-I Wu | 08accc6 | 2015-07-07 11:50:03 +0800 | [diff] [blame] | 9750 | pipe.AddColorAttachment(); |
Chris Forbes | 9f7ff63 | 2015-05-25 11:13:08 +1200 | [diff] [blame] | 9751 | pipe.AddShader(&vs); |
| 9752 | pipe.AddShader(&fs); |
| 9753 | |
Chris Forbes | 9f7ff63 | 2015-05-25 11:13:08 +1200 | [diff] [blame] | 9754 | VkDescriptorSetObj descriptorSet(m_device); |
| 9755 | descriptorSet.AppendDummy(); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 9756 | descriptorSet.CreateVKDescriptorSet(m_commandBuffer); |
Chris Forbes | 9f7ff63 | 2015-05-25 11:13:08 +1200 | [diff] [blame] | 9757 | |
Tony Barbour | 5781e8f | 2015-08-04 16:23:11 -0600 | [diff] [blame] | 9758 | pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass()); |
Chris Forbes | 9f7ff63 | 2015-05-25 11:13:08 +1200 | [diff] [blame] | 9759 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 9760 | m_errorMonitor->VerifyFound(); |
Chris Forbes | 9f7ff63 | 2015-05-25 11:13:08 +1200 | [diff] [blame] | 9761 | } |
Chris Forbes | 9f7ff63 | 2015-05-25 11:13:08 +1200 | [diff] [blame] | 9762 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9763 | TEST_F(VkLayerTest, CreatePipelineFragmentInputNotProvided) { |
Courtney Goeltzenleuchter | 7415d5a | 2015-12-09 15:48:16 -0700 | [diff] [blame] | 9764 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9765 | "not written by vertex shader"); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 9766 | |
Chris Forbes | 59cb88d | 2015-05-25 11:13:13 +1200 | [diff] [blame] | 9767 | ASSERT_NO_FATAL_FAILURE(InitState()); |
Tobin Ehlis | c9ac2b6 | 2015-09-11 12:57:55 -0600 | [diff] [blame] | 9768 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
Chris Forbes | 59cb88d | 2015-05-25 11:13:13 +1200 | [diff] [blame] | 9769 | |
| 9770 | char const *vsSource = |
Chris Forbes | 3846771 | 2016-04-04 17:28:05 +1200 | [diff] [blame] | 9771 | "#version 450\n" |
Chris Forbes | 59cb88d | 2015-05-25 11:13:13 +1200 | [diff] [blame] | 9772 | "\n" |
Tony Barbour | e804d20 | 2016-01-05 13:37:45 -0700 | [diff] [blame] | 9773 | "out gl_PerVertex {\n" |
| 9774 | " vec4 gl_Position;\n" |
| 9775 | "};\n" |
Chris Forbes | 59cb88d | 2015-05-25 11:13:13 +1200 | [diff] [blame] | 9776 | "void main(){\n" |
| 9777 | " gl_Position = vec4(1);\n" |
| 9778 | "}\n"; |
| 9779 | char const *fsSource = |
Chris Forbes | 3846771 | 2016-04-04 17:28:05 +1200 | [diff] [blame] | 9780 | "#version 450\n" |
Chris Forbes | 59cb88d | 2015-05-25 11:13:13 +1200 | [diff] [blame] | 9781 | "\n" |
| 9782 | "layout(location=0) in float x;\n" |
| 9783 | "layout(location=0) out vec4 color;\n" |
| 9784 | "void main(){\n" |
| 9785 | " color = vec4(x);\n" |
| 9786 | "}\n"; |
| 9787 | |
Courtney Goeltzenleuchter | d263550 | 2015-10-21 17:08:06 -0600 | [diff] [blame] | 9788 | VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this); |
| 9789 | VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this); |
Chris Forbes | 59cb88d | 2015-05-25 11:13:13 +1200 | [diff] [blame] | 9790 | |
| 9791 | VkPipelineObj pipe(m_device); |
Chia-I Wu | 08accc6 | 2015-07-07 11:50:03 +0800 | [diff] [blame] | 9792 | pipe.AddColorAttachment(); |
Chris Forbes | 59cb88d | 2015-05-25 11:13:13 +1200 | [diff] [blame] | 9793 | pipe.AddShader(&vs); |
| 9794 | pipe.AddShader(&fs); |
| 9795 | |
Chris Forbes | 59cb88d | 2015-05-25 11:13:13 +1200 | [diff] [blame] | 9796 | VkDescriptorSetObj descriptorSet(m_device); |
| 9797 | descriptorSet.AppendDummy(); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 9798 | descriptorSet.CreateVKDescriptorSet(m_commandBuffer); |
Chris Forbes | 59cb88d | 2015-05-25 11:13:13 +1200 | [diff] [blame] | 9799 | |
Tony Barbour | 5781e8f | 2015-08-04 16:23:11 -0600 | [diff] [blame] | 9800 | pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass()); |
Chris Forbes | 59cb88d | 2015-05-25 11:13:13 +1200 | [diff] [blame] | 9801 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 9802 | m_errorMonitor->VerifyFound(); |
Chris Forbes | 59cb88d | 2015-05-25 11:13:13 +1200 | [diff] [blame] | 9803 | } |
| 9804 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9805 | TEST_F(VkLayerTest, CreatePipelineFragmentInputNotProvidedInBlock) { |
Chris Forbes | a3e85f6 | 2016-01-15 14:53:11 +1300 | [diff] [blame] | 9806 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9807 | "not written by vertex shader"); |
Chris Forbes | a3e85f6 | 2016-01-15 14:53:11 +1300 | [diff] [blame] | 9808 | |
| 9809 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 9810 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 9811 | |
| 9812 | char const *vsSource = |
Chris Forbes | 3846771 | 2016-04-04 17:28:05 +1200 | [diff] [blame] | 9813 | "#version 450\n" |
Chris Forbes | a3e85f6 | 2016-01-15 14:53:11 +1300 | [diff] [blame] | 9814 | "\n" |
| 9815 | "out gl_PerVertex {\n" |
| 9816 | " vec4 gl_Position;\n" |
| 9817 | "};\n" |
| 9818 | "void main(){\n" |
| 9819 | " gl_Position = vec4(1);\n" |
| 9820 | "}\n"; |
| 9821 | char const *fsSource = |
| 9822 | "#version 450\n" |
Chris Forbes | a3e85f6 | 2016-01-15 14:53:11 +1300 | [diff] [blame] | 9823 | "\n" |
| 9824 | "in block { layout(location=0) float x; } ins;\n" |
| 9825 | "layout(location=0) out vec4 color;\n" |
| 9826 | "void main(){\n" |
| 9827 | " color = vec4(ins.x);\n" |
| 9828 | "}\n"; |
| 9829 | |
| 9830 | VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this); |
| 9831 | VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this); |
| 9832 | |
| 9833 | VkPipelineObj pipe(m_device); |
| 9834 | pipe.AddColorAttachment(); |
| 9835 | pipe.AddShader(&vs); |
| 9836 | pipe.AddShader(&fs); |
| 9837 | |
| 9838 | VkDescriptorSetObj descriptorSet(m_device); |
| 9839 | descriptorSet.AppendDummy(); |
| 9840 | descriptorSet.CreateVKDescriptorSet(m_commandBuffer); |
| 9841 | |
| 9842 | pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass()); |
| 9843 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 9844 | m_errorMonitor->VerifyFound(); |
Chris Forbes | a3e85f6 | 2016-01-15 14:53:11 +1300 | [diff] [blame] | 9845 | } |
| 9846 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9847 | TEST_F(VkLayerTest, CreatePipelineVsFsTypeMismatchArraySize) { |
Chris Forbes | 0036fd1 | 2016-01-26 14:19:49 +1300 | [diff] [blame] | 9848 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Chris Forbes | e992882 | 2016-02-17 14:44:52 +1300 | [diff] [blame] | 9849 | "Type mismatch on location 0.0: 'ptr to " |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9850 | "output arr[2] of float32' vs 'ptr to " |
| 9851 | "input arr[3] of float32'"); |
Chris Forbes | 0036fd1 | 2016-01-26 14:19:49 +1300 | [diff] [blame] | 9852 | |
| 9853 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 9854 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 9855 | |
| 9856 | char const *vsSource = |
Chris Forbes | 3846771 | 2016-04-04 17:28:05 +1200 | [diff] [blame] | 9857 | "#version 450\n" |
Chris Forbes | 0036fd1 | 2016-01-26 14:19:49 +1300 | [diff] [blame] | 9858 | "\n" |
| 9859 | "layout(location=0) out float x[2];\n" |
| 9860 | "out gl_PerVertex {\n" |
| 9861 | " vec4 gl_Position;\n" |
| 9862 | "};\n" |
| 9863 | "void main(){\n" |
| 9864 | " x[0] = 0; x[1] = 0;\n" |
| 9865 | " gl_Position = vec4(1);\n" |
| 9866 | "}\n"; |
| 9867 | char const *fsSource = |
Chris Forbes | 3846771 | 2016-04-04 17:28:05 +1200 | [diff] [blame] | 9868 | "#version 450\n" |
Chris Forbes | 0036fd1 | 2016-01-26 14:19:49 +1300 | [diff] [blame] | 9869 | "\n" |
| 9870 | "layout(location=0) in float x[3];\n" |
| 9871 | "layout(location=0) out vec4 color;\n" |
| 9872 | "void main(){\n" |
| 9873 | " color = vec4(x[0] + x[1] + x[2]);\n" |
| 9874 | "}\n"; |
| 9875 | |
| 9876 | VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this); |
| 9877 | VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this); |
| 9878 | |
| 9879 | VkPipelineObj pipe(m_device); |
| 9880 | pipe.AddColorAttachment(); |
| 9881 | pipe.AddShader(&vs); |
| 9882 | pipe.AddShader(&fs); |
| 9883 | |
| 9884 | VkDescriptorSetObj descriptorSet(m_device); |
| 9885 | descriptorSet.AppendDummy(); |
| 9886 | descriptorSet.CreateVKDescriptorSet(m_commandBuffer); |
| 9887 | |
| 9888 | pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass()); |
| 9889 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 9890 | m_errorMonitor->VerifyFound(); |
Chris Forbes | 0036fd1 | 2016-01-26 14:19:49 +1300 | [diff] [blame] | 9891 | } |
| 9892 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9893 | TEST_F(VkLayerTest, CreatePipelineVsFsTypeMismatch) { |
Courtney Goeltzenleuchter | 7415d5a | 2015-12-09 15:48:16 -0700 | [diff] [blame] | 9894 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9895 | "Type mismatch on location 0"); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 9896 | |
Chris Forbes | b56af56 | 2015-05-25 11:13:17 +1200 | [diff] [blame] | 9897 | ASSERT_NO_FATAL_FAILURE(InitState()); |
Tobin Ehlis | c9ac2b6 | 2015-09-11 12:57:55 -0600 | [diff] [blame] | 9898 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
Chris Forbes | b56af56 | 2015-05-25 11:13:17 +1200 | [diff] [blame] | 9899 | |
| 9900 | char const *vsSource = |
Chris Forbes | 3846771 | 2016-04-04 17:28:05 +1200 | [diff] [blame] | 9901 | "#version 450\n" |
Chris Forbes | b56af56 | 2015-05-25 11:13:17 +1200 | [diff] [blame] | 9902 | "\n" |
| 9903 | "layout(location=0) out int x;\n" |
Tony Barbour | e804d20 | 2016-01-05 13:37:45 -0700 | [diff] [blame] | 9904 | "out gl_PerVertex {\n" |
| 9905 | " vec4 gl_Position;\n" |
| 9906 | "};\n" |
Chris Forbes | b56af56 | 2015-05-25 11:13:17 +1200 | [diff] [blame] | 9907 | "void main(){\n" |
| 9908 | " x = 0;\n" |
| 9909 | " gl_Position = vec4(1);\n" |
| 9910 | "}\n"; |
| 9911 | char const *fsSource = |
Chris Forbes | 3846771 | 2016-04-04 17:28:05 +1200 | [diff] [blame] | 9912 | "#version 450\n" |
Chris Forbes | b56af56 | 2015-05-25 11:13:17 +1200 | [diff] [blame] | 9913 | "\n" |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9914 | "layout(location=0) in float x;\n" /* VS writes int */ |
Chris Forbes | b56af56 | 2015-05-25 11:13:17 +1200 | [diff] [blame] | 9915 | "layout(location=0) out vec4 color;\n" |
| 9916 | "void main(){\n" |
| 9917 | " color = vec4(x);\n" |
| 9918 | "}\n"; |
| 9919 | |
Courtney Goeltzenleuchter | d263550 | 2015-10-21 17:08:06 -0600 | [diff] [blame] | 9920 | VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this); |
| 9921 | VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this); |
Chris Forbes | b56af56 | 2015-05-25 11:13:17 +1200 | [diff] [blame] | 9922 | |
| 9923 | VkPipelineObj pipe(m_device); |
Chia-I Wu | 08accc6 | 2015-07-07 11:50:03 +0800 | [diff] [blame] | 9924 | pipe.AddColorAttachment(); |
Chris Forbes | b56af56 | 2015-05-25 11:13:17 +1200 | [diff] [blame] | 9925 | pipe.AddShader(&vs); |
| 9926 | pipe.AddShader(&fs); |
| 9927 | |
Chris Forbes | b56af56 | 2015-05-25 11:13:17 +1200 | [diff] [blame] | 9928 | VkDescriptorSetObj descriptorSet(m_device); |
| 9929 | descriptorSet.AppendDummy(); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 9930 | descriptorSet.CreateVKDescriptorSet(m_commandBuffer); |
Chris Forbes | b56af56 | 2015-05-25 11:13:17 +1200 | [diff] [blame] | 9931 | |
Tony Barbour | 5781e8f | 2015-08-04 16:23:11 -0600 | [diff] [blame] | 9932 | pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass()); |
Chris Forbes | b56af56 | 2015-05-25 11:13:17 +1200 | [diff] [blame] | 9933 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 9934 | m_errorMonitor->VerifyFound(); |
Chris Forbes | b56af56 | 2015-05-25 11:13:17 +1200 | [diff] [blame] | 9935 | } |
| 9936 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9937 | TEST_F(VkLayerTest, CreatePipelineVsFsTypeMismatchInBlock) { |
Chris Forbes | a3e85f6 | 2016-01-15 14:53:11 +1300 | [diff] [blame] | 9938 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9939 | "Type mismatch on location 0"); |
Chris Forbes | a3e85f6 | 2016-01-15 14:53:11 +1300 | [diff] [blame] | 9940 | |
| 9941 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 9942 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 9943 | |
| 9944 | char const *vsSource = |
| 9945 | "#version 450\n" |
Chris Forbes | a3e85f6 | 2016-01-15 14:53:11 +1300 | [diff] [blame] | 9946 | "\n" |
| 9947 | "out block { layout(location=0) int x; } outs;\n" |
| 9948 | "out gl_PerVertex {\n" |
| 9949 | " vec4 gl_Position;\n" |
| 9950 | "};\n" |
| 9951 | "void main(){\n" |
| 9952 | " outs.x = 0;\n" |
| 9953 | " gl_Position = vec4(1);\n" |
| 9954 | "}\n"; |
| 9955 | char const *fsSource = |
| 9956 | "#version 450\n" |
Chris Forbes | a3e85f6 | 2016-01-15 14:53:11 +1300 | [diff] [blame] | 9957 | "\n" |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9958 | "in block { layout(location=0) float x; } ins;\n" /* VS writes int */ |
Chris Forbes | a3e85f6 | 2016-01-15 14:53:11 +1300 | [diff] [blame] | 9959 | "layout(location=0) out vec4 color;\n" |
| 9960 | "void main(){\n" |
| 9961 | " color = vec4(ins.x);\n" |
| 9962 | "}\n"; |
| 9963 | |
| 9964 | VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this); |
| 9965 | VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this); |
| 9966 | |
| 9967 | VkPipelineObj pipe(m_device); |
| 9968 | pipe.AddColorAttachment(); |
| 9969 | pipe.AddShader(&vs); |
| 9970 | pipe.AddShader(&fs); |
| 9971 | |
| 9972 | VkDescriptorSetObj descriptorSet(m_device); |
| 9973 | descriptorSet.AppendDummy(); |
| 9974 | descriptorSet.CreateVKDescriptorSet(m_commandBuffer); |
| 9975 | |
| 9976 | pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass()); |
| 9977 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 9978 | m_errorMonitor->VerifyFound(); |
Chris Forbes | e992882 | 2016-02-17 14:44:52 +1300 | [diff] [blame] | 9979 | } |
| 9980 | |
| 9981 | TEST_F(VkLayerTest, CreatePipelineVsFsMismatchByLocation) { |
| 9982 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 9983 | "location 0.0 which is not written by vertex shader"); |
| 9984 | |
| 9985 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 9986 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 9987 | |
| 9988 | char const *vsSource = |
| 9989 | "#version 450\n" |
Chris Forbes | e992882 | 2016-02-17 14:44:52 +1300 | [diff] [blame] | 9990 | "\n" |
| 9991 | "out block { layout(location=1) float x; } outs;\n" |
| 9992 | "out gl_PerVertex {\n" |
| 9993 | " vec4 gl_Position;\n" |
| 9994 | "};\n" |
| 9995 | "void main(){\n" |
| 9996 | " outs.x = 0;\n" |
| 9997 | " gl_Position = vec4(1);\n" |
| 9998 | "}\n"; |
| 9999 | char const *fsSource = |
| 10000 | "#version 450\n" |
Chris Forbes | e992882 | 2016-02-17 14:44:52 +1300 | [diff] [blame] | 10001 | "\n" |
| 10002 | "in block { layout(location=0) float x; } ins;\n" |
| 10003 | "layout(location=0) out vec4 color;\n" |
| 10004 | "void main(){\n" |
| 10005 | " color = vec4(ins.x);\n" |
| 10006 | "}\n"; |
| 10007 | |
| 10008 | VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this); |
| 10009 | VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this); |
| 10010 | |
| 10011 | VkPipelineObj pipe(m_device); |
| 10012 | pipe.AddColorAttachment(); |
| 10013 | pipe.AddShader(&vs); |
| 10014 | pipe.AddShader(&fs); |
| 10015 | |
| 10016 | VkDescriptorSetObj descriptorSet(m_device); |
| 10017 | descriptorSet.AppendDummy(); |
| 10018 | descriptorSet.CreateVKDescriptorSet(m_commandBuffer); |
| 10019 | |
| 10020 | pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass()); |
| 10021 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 10022 | m_errorMonitor->VerifyFound(); |
Chris Forbes | e992882 | 2016-02-17 14:44:52 +1300 | [diff] [blame] | 10023 | } |
| 10024 | |
| 10025 | TEST_F(VkLayerTest, CreatePipelineVsFsMismatchByComponent) { |
| 10026 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 10027 | "location 0.1 which is not written by vertex shader"); |
| 10028 | |
| 10029 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 10030 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 10031 | |
| 10032 | char const *vsSource = |
| 10033 | "#version 450\n" |
Chris Forbes | e992882 | 2016-02-17 14:44:52 +1300 | [diff] [blame] | 10034 | "\n" |
| 10035 | "out block { layout(location=0, component=0) float x; } outs;\n" |
| 10036 | "out gl_PerVertex {\n" |
| 10037 | " vec4 gl_Position;\n" |
| 10038 | "};\n" |
| 10039 | "void main(){\n" |
| 10040 | " outs.x = 0;\n" |
| 10041 | " gl_Position = vec4(1);\n" |
| 10042 | "}\n"; |
| 10043 | char const *fsSource = |
| 10044 | "#version 450\n" |
Chris Forbes | e992882 | 2016-02-17 14:44:52 +1300 | [diff] [blame] | 10045 | "\n" |
| 10046 | "in block { layout(location=0, component=1) float x; } ins;\n" |
| 10047 | "layout(location=0) out vec4 color;\n" |
| 10048 | "void main(){\n" |
| 10049 | " color = vec4(ins.x);\n" |
| 10050 | "}\n"; |
| 10051 | |
| 10052 | VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this); |
| 10053 | VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this); |
| 10054 | |
| 10055 | VkPipelineObj pipe(m_device); |
| 10056 | pipe.AddColorAttachment(); |
| 10057 | pipe.AddShader(&vs); |
| 10058 | pipe.AddShader(&fs); |
| 10059 | |
| 10060 | VkDescriptorSetObj descriptorSet(m_device); |
| 10061 | descriptorSet.AppendDummy(); |
| 10062 | descriptorSet.CreateVKDescriptorSet(m_commandBuffer); |
| 10063 | |
| 10064 | pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass()); |
| 10065 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 10066 | m_errorMonitor->VerifyFound(); |
Chris Forbes | a3e85f6 | 2016-01-15 14:53:11 +1300 | [diff] [blame] | 10067 | } |
| 10068 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 10069 | TEST_F(VkLayerTest, CreatePipelineAttribNotConsumed) { |
Mark Lobodzinski | 510e20d | 2016-02-11 09:26:16 -0700 | [diff] [blame] | 10070 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 10071 | "location 0 not consumed by VS"); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 10072 | |
Chris Forbes | de136e0 | 2015-05-25 11:13:28 +1200 | [diff] [blame] | 10073 | ASSERT_NO_FATAL_FAILURE(InitState()); |
Tobin Ehlis | c9ac2b6 | 2015-09-11 12:57:55 -0600 | [diff] [blame] | 10074 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
Chris Forbes | de136e0 | 2015-05-25 11:13:28 +1200 | [diff] [blame] | 10075 | |
| 10076 | VkVertexInputBindingDescription input_binding; |
| 10077 | memset(&input_binding, 0, sizeof(input_binding)); |
| 10078 | |
| 10079 | VkVertexInputAttributeDescription input_attrib; |
| 10080 | memset(&input_attrib, 0, sizeof(input_attrib)); |
| 10081 | input_attrib.format = VK_FORMAT_R32_SFLOAT; |
| 10082 | |
| 10083 | char const *vsSource = |
Chris Forbes | 3846771 | 2016-04-04 17:28:05 +1200 | [diff] [blame] | 10084 | "#version 450\n" |
Chris Forbes | de136e0 | 2015-05-25 11:13:28 +1200 | [diff] [blame] | 10085 | "\n" |
Tony Barbour | e804d20 | 2016-01-05 13:37:45 -0700 | [diff] [blame] | 10086 | "out gl_PerVertex {\n" |
| 10087 | " vec4 gl_Position;\n" |
| 10088 | "};\n" |
Chris Forbes | de136e0 | 2015-05-25 11:13:28 +1200 | [diff] [blame] | 10089 | "void main(){\n" |
| 10090 | " gl_Position = vec4(1);\n" |
| 10091 | "}\n"; |
| 10092 | char const *fsSource = |
Chris Forbes | 3846771 | 2016-04-04 17:28:05 +1200 | [diff] [blame] | 10093 | "#version 450\n" |
Chris Forbes | de136e0 | 2015-05-25 11:13:28 +1200 | [diff] [blame] | 10094 | "\n" |
| 10095 | "layout(location=0) out vec4 color;\n" |
| 10096 | "void main(){\n" |
| 10097 | " color = vec4(1);\n" |
| 10098 | "}\n"; |
| 10099 | |
Courtney Goeltzenleuchter | d263550 | 2015-10-21 17:08:06 -0600 | [diff] [blame] | 10100 | VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this); |
| 10101 | VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this); |
Chris Forbes | de136e0 | 2015-05-25 11:13:28 +1200 | [diff] [blame] | 10102 | |
| 10103 | VkPipelineObj pipe(m_device); |
Chia-I Wu | 08accc6 | 2015-07-07 11:50:03 +0800 | [diff] [blame] | 10104 | pipe.AddColorAttachment(); |
Chris Forbes | de136e0 | 2015-05-25 11:13:28 +1200 | [diff] [blame] | 10105 | pipe.AddShader(&vs); |
| 10106 | pipe.AddShader(&fs); |
| 10107 | |
| 10108 | pipe.AddVertexInputBindings(&input_binding, 1); |
| 10109 | pipe.AddVertexInputAttribs(&input_attrib, 1); |
| 10110 | |
Chris Forbes | de136e0 | 2015-05-25 11:13:28 +1200 | [diff] [blame] | 10111 | VkDescriptorSetObj descriptorSet(m_device); |
| 10112 | descriptorSet.AppendDummy(); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 10113 | descriptorSet.CreateVKDescriptorSet(m_commandBuffer); |
Chris Forbes | de136e0 | 2015-05-25 11:13:28 +1200 | [diff] [blame] | 10114 | |
Tony Barbour | 5781e8f | 2015-08-04 16:23:11 -0600 | [diff] [blame] | 10115 | pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass()); |
Chris Forbes | de136e0 | 2015-05-25 11:13:28 +1200 | [diff] [blame] | 10116 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 10117 | m_errorMonitor->VerifyFound(); |
Chris Forbes | de136e0 | 2015-05-25 11:13:28 +1200 | [diff] [blame] | 10118 | } |
| 10119 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 10120 | TEST_F(VkLayerTest, CreatePipelineAttribLocationMismatch) { |
Mark Lobodzinski | 510e20d | 2016-02-11 09:26:16 -0700 | [diff] [blame] | 10121 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 10122 | "location 0 not consumed by VS"); |
Chris Forbes | 7d83cd5 | 2016-01-15 11:32:03 +1300 | [diff] [blame] | 10123 | |
| 10124 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 10125 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 10126 | |
| 10127 | VkVertexInputBindingDescription input_binding; |
| 10128 | memset(&input_binding, 0, sizeof(input_binding)); |
| 10129 | |
| 10130 | VkVertexInputAttributeDescription input_attrib; |
| 10131 | memset(&input_attrib, 0, sizeof(input_attrib)); |
| 10132 | input_attrib.format = VK_FORMAT_R32_SFLOAT; |
| 10133 | |
| 10134 | char const *vsSource = |
Chris Forbes | 3846771 | 2016-04-04 17:28:05 +1200 | [diff] [blame] | 10135 | "#version 450\n" |
Chris Forbes | 7d83cd5 | 2016-01-15 11:32:03 +1300 | [diff] [blame] | 10136 | "\n" |
| 10137 | "layout(location=1) in float x;\n" |
| 10138 | "out gl_PerVertex {\n" |
| 10139 | " vec4 gl_Position;\n" |
| 10140 | "};\n" |
| 10141 | "void main(){\n" |
| 10142 | " gl_Position = vec4(x);\n" |
| 10143 | "}\n"; |
| 10144 | char const *fsSource = |
Chris Forbes | 3846771 | 2016-04-04 17:28:05 +1200 | [diff] [blame] | 10145 | "#version 450\n" |
Chris Forbes | 7d83cd5 | 2016-01-15 11:32:03 +1300 | [diff] [blame] | 10146 | "\n" |
| 10147 | "layout(location=0) out vec4 color;\n" |
| 10148 | "void main(){\n" |
| 10149 | " color = vec4(1);\n" |
| 10150 | "}\n"; |
| 10151 | |
| 10152 | VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this); |
| 10153 | VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this); |
| 10154 | |
| 10155 | VkPipelineObj pipe(m_device); |
| 10156 | pipe.AddColorAttachment(); |
| 10157 | pipe.AddShader(&vs); |
| 10158 | pipe.AddShader(&fs); |
| 10159 | |
| 10160 | pipe.AddVertexInputBindings(&input_binding, 1); |
| 10161 | pipe.AddVertexInputAttribs(&input_attrib, 1); |
| 10162 | |
| 10163 | VkDescriptorSetObj descriptorSet(m_device); |
| 10164 | descriptorSet.AppendDummy(); |
| 10165 | descriptorSet.CreateVKDescriptorSet(m_commandBuffer); |
| 10166 | |
| 10167 | pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass()); |
| 10168 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 10169 | m_errorMonitor->VerifyFound(); |
Chris Forbes | 7d83cd5 | 2016-01-15 11:32:03 +1300 | [diff] [blame] | 10170 | } |
| 10171 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 10172 | TEST_F(VkLayerTest, CreatePipelineAttribNotProvided) { |
| 10173 | m_errorMonitor->SetDesiredFailureMsg( |
| 10174 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 10175 | "VS consumes input at location 0 but not provided"); |
| 10176 | |
Chris Forbes | 62e8e50 | 2015-05-25 11:13:29 +1200 | [diff] [blame] | 10177 | ASSERT_NO_FATAL_FAILURE(InitState()); |
Tobin Ehlis | c9ac2b6 | 2015-09-11 12:57:55 -0600 | [diff] [blame] | 10178 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
Chris Forbes | 62e8e50 | 2015-05-25 11:13:29 +1200 | [diff] [blame] | 10179 | |
| 10180 | char const *vsSource = |
Chris Forbes | 3846771 | 2016-04-04 17:28:05 +1200 | [diff] [blame] | 10181 | "#version 450\n" |
Chris Forbes | 62e8e50 | 2015-05-25 11:13:29 +1200 | [diff] [blame] | 10182 | "\n" |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 10183 | "layout(location=0) in vec4 x;\n" /* not provided */ |
Tony Barbour | e804d20 | 2016-01-05 13:37:45 -0700 | [diff] [blame] | 10184 | "out gl_PerVertex {\n" |
| 10185 | " vec4 gl_Position;\n" |
| 10186 | "};\n" |
Chris Forbes | 62e8e50 | 2015-05-25 11:13:29 +1200 | [diff] [blame] | 10187 | "void main(){\n" |
| 10188 | " gl_Position = x;\n" |
| 10189 | "}\n"; |
| 10190 | char const *fsSource = |
Chris Forbes | 3846771 | 2016-04-04 17:28:05 +1200 | [diff] [blame] | 10191 | "#version 450\n" |
Chris Forbes | 62e8e50 | 2015-05-25 11:13:29 +1200 | [diff] [blame] | 10192 | "\n" |
| 10193 | "layout(location=0) out vec4 color;\n" |
| 10194 | "void main(){\n" |
| 10195 | " color = vec4(1);\n" |
| 10196 | "}\n"; |
| 10197 | |
Courtney Goeltzenleuchter | d263550 | 2015-10-21 17:08:06 -0600 | [diff] [blame] | 10198 | VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this); |
| 10199 | VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this); |
Chris Forbes | 62e8e50 | 2015-05-25 11:13:29 +1200 | [diff] [blame] | 10200 | |
| 10201 | VkPipelineObj pipe(m_device); |
Chia-I Wu | 08accc6 | 2015-07-07 11:50:03 +0800 | [diff] [blame] | 10202 | pipe.AddColorAttachment(); |
Chris Forbes | 62e8e50 | 2015-05-25 11:13:29 +1200 | [diff] [blame] | 10203 | pipe.AddShader(&vs); |
| 10204 | pipe.AddShader(&fs); |
| 10205 | |
Chris Forbes | 62e8e50 | 2015-05-25 11:13:29 +1200 | [diff] [blame] | 10206 | VkDescriptorSetObj descriptorSet(m_device); |
| 10207 | descriptorSet.AppendDummy(); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 10208 | descriptorSet.CreateVKDescriptorSet(m_commandBuffer); |
Chris Forbes | 62e8e50 | 2015-05-25 11:13:29 +1200 | [diff] [blame] | 10209 | |
Tony Barbour | 5781e8f | 2015-08-04 16:23:11 -0600 | [diff] [blame] | 10210 | pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass()); |
Chris Forbes | 62e8e50 | 2015-05-25 11:13:29 +1200 | [diff] [blame] | 10211 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 10212 | m_errorMonitor->VerifyFound(); |
Chris Forbes | 62e8e50 | 2015-05-25 11:13:29 +1200 | [diff] [blame] | 10213 | } |
| 10214 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 10215 | TEST_F(VkLayerTest, CreatePipelineAttribTypeMismatch) { |
| 10216 | m_errorMonitor->SetDesiredFailureMsg( |
| 10217 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 10218 | "location 0 does not match VS input type"); |
| 10219 | |
Chris Forbes | c97d98e | 2015-05-25 11:13:31 +1200 | [diff] [blame] | 10220 | ASSERT_NO_FATAL_FAILURE(InitState()); |
Tobin Ehlis | c9ac2b6 | 2015-09-11 12:57:55 -0600 | [diff] [blame] | 10221 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
Chris Forbes | c97d98e | 2015-05-25 11:13:31 +1200 | [diff] [blame] | 10222 | |
| 10223 | VkVertexInputBindingDescription input_binding; |
| 10224 | memset(&input_binding, 0, sizeof(input_binding)); |
| 10225 | |
| 10226 | VkVertexInputAttributeDescription input_attrib; |
| 10227 | memset(&input_attrib, 0, sizeof(input_attrib)); |
| 10228 | input_attrib.format = VK_FORMAT_R32_SFLOAT; |
| 10229 | |
| 10230 | char const *vsSource = |
Chris Forbes | 3846771 | 2016-04-04 17:28:05 +1200 | [diff] [blame] | 10231 | "#version 450\n" |
Chris Forbes | c97d98e | 2015-05-25 11:13:31 +1200 | [diff] [blame] | 10232 | "\n" |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 10233 | "layout(location=0) in int x;\n" /* attrib provided float */ |
Tony Barbour | e804d20 | 2016-01-05 13:37:45 -0700 | [diff] [blame] | 10234 | "out gl_PerVertex {\n" |
| 10235 | " vec4 gl_Position;\n" |
| 10236 | "};\n" |
Chris Forbes | c97d98e | 2015-05-25 11:13:31 +1200 | [diff] [blame] | 10237 | "void main(){\n" |
| 10238 | " gl_Position = vec4(x);\n" |
| 10239 | "}\n"; |
| 10240 | char const *fsSource = |
Chris Forbes | 3846771 | 2016-04-04 17:28:05 +1200 | [diff] [blame] | 10241 | "#version 450\n" |
Chris Forbes | c97d98e | 2015-05-25 11:13:31 +1200 | [diff] [blame] | 10242 | "\n" |
| 10243 | "layout(location=0) out vec4 color;\n" |
| 10244 | "void main(){\n" |
| 10245 | " color = vec4(1);\n" |
| 10246 | "}\n"; |
| 10247 | |
Courtney Goeltzenleuchter | d263550 | 2015-10-21 17:08:06 -0600 | [diff] [blame] | 10248 | VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this); |
| 10249 | VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this); |
Chris Forbes | c97d98e | 2015-05-25 11:13:31 +1200 | [diff] [blame] | 10250 | |
| 10251 | VkPipelineObj pipe(m_device); |
Chia-I Wu | 08accc6 | 2015-07-07 11:50:03 +0800 | [diff] [blame] | 10252 | pipe.AddColorAttachment(); |
Chris Forbes | c97d98e | 2015-05-25 11:13:31 +1200 | [diff] [blame] | 10253 | pipe.AddShader(&vs); |
| 10254 | pipe.AddShader(&fs); |
| 10255 | |
| 10256 | pipe.AddVertexInputBindings(&input_binding, 1); |
| 10257 | pipe.AddVertexInputAttribs(&input_attrib, 1); |
| 10258 | |
Chris Forbes | c97d98e | 2015-05-25 11:13:31 +1200 | [diff] [blame] | 10259 | VkDescriptorSetObj descriptorSet(m_device); |
| 10260 | descriptorSet.AppendDummy(); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 10261 | descriptorSet.CreateVKDescriptorSet(m_commandBuffer); |
Chris Forbes | c97d98e | 2015-05-25 11:13:31 +1200 | [diff] [blame] | 10262 | |
Tony Barbour | 5781e8f | 2015-08-04 16:23:11 -0600 | [diff] [blame] | 10263 | pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass()); |
Chris Forbes | c97d98e | 2015-05-25 11:13:31 +1200 | [diff] [blame] | 10264 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 10265 | m_errorMonitor->VerifyFound(); |
Chris Forbes | c97d98e | 2015-05-25 11:13:31 +1200 | [diff] [blame] | 10266 | } |
| 10267 | |
Chris Forbes | c68b43c | 2016-04-06 11:18:47 +1200 | [diff] [blame] | 10268 | TEST_F(VkLayerTest, CreatePipelineDuplicateStage) { |
| 10269 | m_errorMonitor->SetDesiredFailureMsg( |
| 10270 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 10271 | "Multiple shaders provided for stage VK_SHADER_STAGE_VERTEX_BIT"); |
| 10272 | |
| 10273 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 10274 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 10275 | |
| 10276 | char const *vsSource = |
| 10277 | "#version 450\n" |
| 10278 | "\n" |
| 10279 | "out gl_PerVertex {\n" |
| 10280 | " vec4 gl_Position;\n" |
| 10281 | "};\n" |
| 10282 | "void main(){\n" |
| 10283 | " gl_Position = vec4(1);\n" |
| 10284 | "}\n"; |
| 10285 | char const *fsSource = |
| 10286 | "#version 450\n" |
| 10287 | "\n" |
| 10288 | "layout(location=0) out vec4 color;\n" |
| 10289 | "void main(){\n" |
| 10290 | " color = vec4(1);\n" |
| 10291 | "}\n"; |
| 10292 | |
| 10293 | VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this); |
| 10294 | VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this); |
| 10295 | |
| 10296 | VkPipelineObj pipe(m_device); |
| 10297 | pipe.AddColorAttachment(); |
| 10298 | pipe.AddShader(&vs); |
| 10299 | pipe.AddShader(&vs); |
| 10300 | pipe.AddShader(&fs); |
| 10301 | |
| 10302 | VkDescriptorSetObj descriptorSet(m_device); |
| 10303 | descriptorSet.AppendDummy(); |
| 10304 | descriptorSet.CreateVKDescriptorSet(m_commandBuffer); |
| 10305 | |
| 10306 | pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass()); |
| 10307 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 10308 | m_errorMonitor->VerifyFound(); |
Chris Forbes | c68b43c | 2016-04-06 11:18:47 +1200 | [diff] [blame] | 10309 | } |
| 10310 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 10311 | TEST_F(VkLayerTest, CreatePipelineAttribMatrixType) { |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 10312 | m_errorMonitor->ExpectSuccess(); |
Chris Forbes | 2682b24 | 2015-11-24 11:13:14 +1300 | [diff] [blame] | 10313 | |
| 10314 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 10315 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 10316 | |
| 10317 | VkVertexInputBindingDescription input_binding; |
| 10318 | memset(&input_binding, 0, sizeof(input_binding)); |
| 10319 | |
| 10320 | VkVertexInputAttributeDescription input_attribs[2]; |
| 10321 | memset(input_attribs, 0, sizeof(input_attribs)); |
| 10322 | |
| 10323 | for (int i = 0; i < 2; i++) { |
| 10324 | input_attribs[i].format = VK_FORMAT_R32G32B32A32_SFLOAT; |
| 10325 | input_attribs[i].location = i; |
| 10326 | } |
| 10327 | |
| 10328 | char const *vsSource = |
Chris Forbes | 3846771 | 2016-04-04 17:28:05 +1200 | [diff] [blame] | 10329 | "#version 450\n" |
Chris Forbes | 2682b24 | 2015-11-24 11:13:14 +1300 | [diff] [blame] | 10330 | "\n" |
| 10331 | "layout(location=0) in mat2x4 x;\n" |
Tony Barbour | e804d20 | 2016-01-05 13:37:45 -0700 | [diff] [blame] | 10332 | "out gl_PerVertex {\n" |
| 10333 | " vec4 gl_Position;\n" |
| 10334 | "};\n" |
Chris Forbes | 2682b24 | 2015-11-24 11:13:14 +1300 | [diff] [blame] | 10335 | "void main(){\n" |
| 10336 | " gl_Position = x[0] + x[1];\n" |
| 10337 | "}\n"; |
| 10338 | char const *fsSource = |
Chris Forbes | 3846771 | 2016-04-04 17:28:05 +1200 | [diff] [blame] | 10339 | "#version 450\n" |
Chris Forbes | 2682b24 | 2015-11-24 11:13:14 +1300 | [diff] [blame] | 10340 | "\n" |
| 10341 | "layout(location=0) out vec4 color;\n" |
| 10342 | "void main(){\n" |
| 10343 | " color = vec4(1);\n" |
| 10344 | "}\n"; |
| 10345 | |
| 10346 | VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this); |
| 10347 | VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this); |
| 10348 | |
| 10349 | VkPipelineObj pipe(m_device); |
| 10350 | pipe.AddColorAttachment(); |
| 10351 | pipe.AddShader(&vs); |
| 10352 | pipe.AddShader(&fs); |
| 10353 | |
| 10354 | pipe.AddVertexInputBindings(&input_binding, 1); |
| 10355 | pipe.AddVertexInputAttribs(input_attribs, 2); |
| 10356 | |
| 10357 | VkDescriptorSetObj descriptorSet(m_device); |
| 10358 | descriptorSet.AppendDummy(); |
| 10359 | descriptorSet.CreateVKDescriptorSet(m_commandBuffer); |
| 10360 | |
| 10361 | pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass()); |
| 10362 | |
| 10363 | /* expect success */ |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 10364 | m_errorMonitor->VerifyNotFound(); |
Chris Forbes | 2682b24 | 2015-11-24 11:13:14 +1300 | [diff] [blame] | 10365 | } |
| 10366 | |
Chris Forbes | 2682b24 | 2015-11-24 11:13:14 +1300 | [diff] [blame] | 10367 | TEST_F(VkLayerTest, CreatePipelineAttribArrayType) |
| 10368 | { |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 10369 | m_errorMonitor->ExpectSuccess(); |
Chris Forbes | 2682b24 | 2015-11-24 11:13:14 +1300 | [diff] [blame] | 10370 | |
| 10371 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 10372 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 10373 | |
| 10374 | VkVertexInputBindingDescription input_binding; |
| 10375 | memset(&input_binding, 0, sizeof(input_binding)); |
| 10376 | |
| 10377 | VkVertexInputAttributeDescription input_attribs[2]; |
| 10378 | memset(input_attribs, 0, sizeof(input_attribs)); |
| 10379 | |
| 10380 | for (int i = 0; i < 2; i++) { |
| 10381 | input_attribs[i].format = VK_FORMAT_R32G32B32A32_SFLOAT; |
| 10382 | input_attribs[i].location = i; |
| 10383 | } |
| 10384 | |
| 10385 | char const *vsSource = |
Chris Forbes | 3846771 | 2016-04-04 17:28:05 +1200 | [diff] [blame] | 10386 | "#version 450\n" |
Chris Forbes | 2682b24 | 2015-11-24 11:13:14 +1300 | [diff] [blame] | 10387 | "\n" |
| 10388 | "layout(location=0) in vec4 x[2];\n" |
Tony Barbour | e804d20 | 2016-01-05 13:37:45 -0700 | [diff] [blame] | 10389 | "out gl_PerVertex {\n" |
| 10390 | " vec4 gl_Position;\n" |
| 10391 | "};\n" |
Chris Forbes | 2682b24 | 2015-11-24 11:13:14 +1300 | [diff] [blame] | 10392 | "void main(){\n" |
| 10393 | " gl_Position = x[0] + x[1];\n" |
| 10394 | "}\n"; |
| 10395 | char const *fsSource = |
Chris Forbes | 3846771 | 2016-04-04 17:28:05 +1200 | [diff] [blame] | 10396 | "#version 450\n" |
Chris Forbes | 2682b24 | 2015-11-24 11:13:14 +1300 | [diff] [blame] | 10397 | "\n" |
| 10398 | "layout(location=0) out vec4 color;\n" |
| 10399 | "void main(){\n" |
| 10400 | " color = vec4(1);\n" |
| 10401 | "}\n"; |
| 10402 | |
| 10403 | VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this); |
| 10404 | VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this); |
| 10405 | |
| 10406 | VkPipelineObj pipe(m_device); |
| 10407 | pipe.AddColorAttachment(); |
| 10408 | pipe.AddShader(&vs); |
| 10409 | pipe.AddShader(&fs); |
| 10410 | |
| 10411 | pipe.AddVertexInputBindings(&input_binding, 1); |
| 10412 | pipe.AddVertexInputAttribs(input_attribs, 2); |
| 10413 | |
| 10414 | VkDescriptorSetObj descriptorSet(m_device); |
| 10415 | descriptorSet.AppendDummy(); |
| 10416 | descriptorSet.CreateVKDescriptorSet(m_commandBuffer); |
| 10417 | |
| 10418 | pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass()); |
| 10419 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 10420 | m_errorMonitor->VerifyNotFound(); |
Chris Forbes | 2682b24 | 2015-11-24 11:13:14 +1300 | [diff] [blame] | 10421 | } |
Chris Forbes | 2682b24 | 2015-11-24 11:13:14 +1300 | [diff] [blame] | 10422 | |
Chris Forbes | 4ea14fc | 2016-04-04 18:52:54 +1200 | [diff] [blame] | 10423 | TEST_F(VkLayerTest, CreatePipelineSimplePositive) |
| 10424 | { |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 10425 | m_errorMonitor->ExpectSuccess(); |
Chris Forbes | 4ea14fc | 2016-04-04 18:52:54 +1200 | [diff] [blame] | 10426 | |
| 10427 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 10428 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 10429 | |
| 10430 | char const *vsSource = |
| 10431 | "#version 450\n" |
| 10432 | "out gl_PerVertex {\n" |
| 10433 | " vec4 gl_Position;\n" |
| 10434 | "};\n" |
| 10435 | "void main(){\n" |
| 10436 | " gl_Position = vec4(0);\n" |
| 10437 | "}\n"; |
| 10438 | char const *fsSource = |
| 10439 | "#version 450\n" |
| 10440 | "\n" |
| 10441 | "layout(location=0) out vec4 color;\n" |
| 10442 | "void main(){\n" |
| 10443 | " color = vec4(1);\n" |
| 10444 | "}\n"; |
| 10445 | |
| 10446 | VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this); |
| 10447 | VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this); |
| 10448 | |
| 10449 | VkPipelineObj pipe(m_device); |
| 10450 | pipe.AddColorAttachment(); |
| 10451 | pipe.AddShader(&vs); |
| 10452 | pipe.AddShader(&fs); |
| 10453 | |
| 10454 | VkDescriptorSetObj descriptorSet(m_device); |
| 10455 | descriptorSet.AppendDummy(); |
| 10456 | descriptorSet.CreateVKDescriptorSet(m_commandBuffer); |
| 10457 | |
| 10458 | pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass()); |
| 10459 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 10460 | m_errorMonitor->VerifyNotFound(); |
Chris Forbes | 4ea14fc | 2016-04-04 18:52:54 +1200 | [diff] [blame] | 10461 | } |
| 10462 | |
Chris Forbes | 912c919 | 2016-04-05 17:50:35 +1200 | [diff] [blame] | 10463 | TEST_F(VkLayerTest, CreatePipelineRelaxedTypeMatch) |
| 10464 | { |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 10465 | m_errorMonitor->ExpectSuccess(); |
Chris Forbes | 912c919 | 2016-04-05 17:50:35 +1200 | [diff] [blame] | 10466 | |
| 10467 | // VK 1.0.8 Specification, 14.1.3 "Additionally,..." block |
| 10468 | |
| 10469 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 10470 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 10471 | |
| 10472 | char const *vsSource = |
| 10473 | "#version 450\n" |
| 10474 | "out gl_PerVertex {\n" |
| 10475 | " vec4 gl_Position;\n" |
| 10476 | "};\n" |
| 10477 | "layout(location=0) out vec3 x;\n" |
| 10478 | "layout(location=1) out ivec3 y;\n" |
| 10479 | "layout(location=2) out vec3 z;\n" |
| 10480 | "void main(){\n" |
| 10481 | " gl_Position = vec4(0);\n" |
| 10482 | " x = vec3(0); y = ivec3(0); z = vec3(0);\n" |
| 10483 | "}\n"; |
| 10484 | char const *fsSource = |
| 10485 | "#version 450\n" |
| 10486 | "\n" |
| 10487 | "layout(location=0) out vec4 color;\n" |
| 10488 | "layout(location=0) in float x;\n" |
| 10489 | "layout(location=1) flat in int y;\n" |
| 10490 | "layout(location=2) in vec2 z;\n" |
| 10491 | "void main(){\n" |
| 10492 | " color = vec4(1 + x + y + z.x);\n" |
| 10493 | "}\n"; |
| 10494 | |
| 10495 | VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this); |
| 10496 | VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this); |
| 10497 | |
| 10498 | VkPipelineObj pipe(m_device); |
| 10499 | pipe.AddColorAttachment(); |
| 10500 | pipe.AddShader(&vs); |
| 10501 | pipe.AddShader(&fs); |
| 10502 | |
| 10503 | VkDescriptorSetObj descriptorSet(m_device); |
| 10504 | descriptorSet.AppendDummy(); |
| 10505 | descriptorSet.CreateVKDescriptorSet(m_commandBuffer); |
| 10506 | |
| 10507 | pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass()); |
| 10508 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 10509 | m_errorMonitor->VerifyNotFound(); |
Chris Forbes | 912c919 | 2016-04-05 17:50:35 +1200 | [diff] [blame] | 10510 | } |
| 10511 | |
Chris Forbes | 4ea14fc | 2016-04-04 18:52:54 +1200 | [diff] [blame] | 10512 | TEST_F(VkLayerTest, CreatePipelineTessPerVertex) |
| 10513 | { |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 10514 | m_errorMonitor->ExpectSuccess(); |
Chris Forbes | 4ea14fc | 2016-04-04 18:52:54 +1200 | [diff] [blame] | 10515 | |
| 10516 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 10517 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 10518 | |
Chris Forbes | c1e852d | 2016-04-04 19:26:42 +1200 | [diff] [blame] | 10519 | if (!m_device->phy().features().tessellationShader) { |
| 10520 | printf("Device does not support tessellation shaders; skipped.\n"); |
| 10521 | return; |
| 10522 | } |
| 10523 | |
Chris Forbes | 4ea14fc | 2016-04-04 18:52:54 +1200 | [diff] [blame] | 10524 | char const *vsSource = |
| 10525 | "#version 450\n" |
| 10526 | "void main(){}\n"; |
| 10527 | char const *tcsSource = |
| 10528 | "#version 450\n" |
| 10529 | "layout(location=0) out int x[];\n" |
| 10530 | "layout(vertices=3) out;\n" |
| 10531 | "void main(){\n" |
| 10532 | " gl_TessLevelOuter[0] = gl_TessLevelOuter[1] = gl_TessLevelOuter[2] = 1;\n" |
| 10533 | " gl_TessLevelInner[0] = 1;\n" |
| 10534 | " x[gl_InvocationID] = gl_InvocationID;\n" |
| 10535 | "}\n"; |
| 10536 | char const *tesSource = |
| 10537 | "#version 450\n" |
| 10538 | "layout(triangles, equal_spacing, cw) in;\n" |
| 10539 | "layout(location=0) in int x[];\n" |
| 10540 | "out gl_PerVertex { vec4 gl_Position; };\n" |
| 10541 | "void main(){\n" |
| 10542 | " gl_Position.xyz = gl_TessCoord;\n" |
| 10543 | " gl_Position.w = x[0] + x[1] + x[2];\n" |
| 10544 | "}\n"; |
| 10545 | char const *fsSource = |
| 10546 | "#version 450\n" |
| 10547 | "layout(location=0) out vec4 color;\n" |
| 10548 | "void main(){\n" |
| 10549 | " color = vec4(1);\n" |
| 10550 | "}\n"; |
| 10551 | |
| 10552 | VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this); |
| 10553 | VkShaderObj tcs(m_device, tcsSource, VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT, this); |
| 10554 | VkShaderObj tes(m_device, tesSource, VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT, this); |
| 10555 | VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this); |
| 10556 | |
| 10557 | VkPipelineInputAssemblyStateCreateInfo iasci{ |
| 10558 | VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO, |
| 10559 | nullptr, |
| 10560 | 0, |
| 10561 | VK_PRIMITIVE_TOPOLOGY_PATCH_LIST, |
| 10562 | VK_FALSE}; |
| 10563 | |
Chris Forbes | b4cacb6 | 2016-04-04 19:15:00 +1200 | [diff] [blame] | 10564 | VkPipelineTessellationStateCreateInfo tsci{ |
| 10565 | VK_STRUCTURE_TYPE_PIPELINE_TESSELLATION_STATE_CREATE_INFO, |
| 10566 | nullptr, |
| 10567 | 0, |
| 10568 | 3}; |
| 10569 | |
Chris Forbes | 4ea14fc | 2016-04-04 18:52:54 +1200 | [diff] [blame] | 10570 | VkPipelineObj pipe(m_device); |
| 10571 | pipe.SetInputAssembly(&iasci); |
Chris Forbes | b4cacb6 | 2016-04-04 19:15:00 +1200 | [diff] [blame] | 10572 | pipe.SetTessellation(&tsci); |
Chris Forbes | 4ea14fc | 2016-04-04 18:52:54 +1200 | [diff] [blame] | 10573 | pipe.AddColorAttachment(); |
| 10574 | pipe.AddShader(&vs); |
| 10575 | pipe.AddShader(&tcs); |
| 10576 | pipe.AddShader(&tes); |
| 10577 | pipe.AddShader(&fs); |
| 10578 | |
| 10579 | VkDescriptorSetObj descriptorSet(m_device); |
| 10580 | descriptorSet.AppendDummy(); |
| 10581 | descriptorSet.CreateVKDescriptorSet(m_commandBuffer); |
| 10582 | |
| 10583 | pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass()); |
| 10584 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 10585 | m_errorMonitor->VerifyNotFound(); |
Chris Forbes | 4ea14fc | 2016-04-04 18:52:54 +1200 | [diff] [blame] | 10586 | } |
| 10587 | |
Chris Forbes | a0ab815 | 2016-04-20 13:34:27 +1200 | [diff] [blame] | 10588 | TEST_F(VkLayerTest, CreatePipelineGeometryInputBlockPositive) |
| 10589 | { |
| 10590 | m_errorMonitor->ExpectSuccess(); |
| 10591 | |
| 10592 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 10593 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 10594 | |
| 10595 | if (!m_device->phy().features().geometryShader) { |
| 10596 | printf("Device does not support geometry shaders; skipped.\n"); |
| 10597 | return; |
| 10598 | } |
| 10599 | |
| 10600 | char const *vsSource = |
| 10601 | "#version 450\n" |
| 10602 | "layout(location=0) out VertexData { vec4 x; } vs_out;\n" |
| 10603 | "void main(){\n" |
| 10604 | " vs_out.x = vec4(1);\n" |
| 10605 | "}\n"; |
| 10606 | char const *gsSource = |
| 10607 | "#version 450\n" |
| 10608 | "layout(triangles) in;\n" |
| 10609 | "layout(triangle_strip, max_vertices=3) out;\n" |
| 10610 | "layout(location=0) in VertexData { vec4 x; } gs_in[];\n" |
| 10611 | "out gl_PerVertex { vec4 gl_Position; };\n" |
| 10612 | "void main() {\n" |
| 10613 | " gl_Position = gs_in[0].x;\n" |
| 10614 | " EmitVertex();\n" |
| 10615 | "}\n"; |
| 10616 | char const *fsSource = |
| 10617 | "#version 450\n" |
| 10618 | "layout(location=0) out vec4 color;\n" |
| 10619 | "void main(){\n" |
| 10620 | " color = vec4(1);\n" |
| 10621 | "}\n"; |
| 10622 | |
| 10623 | VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this); |
| 10624 | VkShaderObj gs(m_device, gsSource, VK_SHADER_STAGE_GEOMETRY_BIT, this); |
| 10625 | VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this); |
| 10626 | |
| 10627 | VkPipelineObj pipe(m_device); |
| 10628 | pipe.AddColorAttachment(); |
| 10629 | pipe.AddShader(&vs); |
| 10630 | pipe.AddShader(&gs); |
| 10631 | pipe.AddShader(&fs); |
| 10632 | |
| 10633 | VkDescriptorSetObj descriptorSet(m_device); |
| 10634 | descriptorSet.AppendDummy(); |
| 10635 | descriptorSet.CreateVKDescriptorSet(m_commandBuffer); |
| 10636 | |
| 10637 | pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass()); |
| 10638 | |
| 10639 | m_errorMonitor->VerifyNotFound(); |
| 10640 | } |
| 10641 | |
Chris Forbes | a0193bc | 2016-04-04 19:19:47 +1200 | [diff] [blame] | 10642 | TEST_F(VkLayerTest, CreatePipelineTessPatchDecorationMismatch) |
| 10643 | { |
| 10644 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 10645 | "is per-vertex in tessellation control shader stage " |
| 10646 | "but per-patch in tessellation evaluation shader stage"); |
| 10647 | |
| 10648 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 10649 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 10650 | |
Chris Forbes | c1e852d | 2016-04-04 19:26:42 +1200 | [diff] [blame] | 10651 | if (!m_device->phy().features().tessellationShader) { |
| 10652 | printf("Device does not support tessellation shaders; skipped.\n"); |
| 10653 | return; |
| 10654 | } |
| 10655 | |
Chris Forbes | a0193bc | 2016-04-04 19:19:47 +1200 | [diff] [blame] | 10656 | char const *vsSource = |
| 10657 | "#version 450\n" |
| 10658 | "void main(){}\n"; |
| 10659 | char const *tcsSource = |
| 10660 | "#version 450\n" |
| 10661 | "layout(location=0) out int x[];\n" |
| 10662 | "layout(vertices=3) out;\n" |
| 10663 | "void main(){\n" |
| 10664 | " gl_TessLevelOuter[0] = gl_TessLevelOuter[1] = gl_TessLevelOuter[2] = 1;\n" |
| 10665 | " gl_TessLevelInner[0] = 1;\n" |
| 10666 | " x[gl_InvocationID] = gl_InvocationID;\n" |
| 10667 | "}\n"; |
| 10668 | char const *tesSource = |
| 10669 | "#version 450\n" |
| 10670 | "layout(triangles, equal_spacing, cw) in;\n" |
| 10671 | "layout(location=0) patch in int x;\n" |
| 10672 | "out gl_PerVertex { vec4 gl_Position; };\n" |
| 10673 | "void main(){\n" |
| 10674 | " gl_Position.xyz = gl_TessCoord;\n" |
| 10675 | " gl_Position.w = x;\n" |
| 10676 | "}\n"; |
| 10677 | char const *fsSource = |
| 10678 | "#version 450\n" |
| 10679 | "layout(location=0) out vec4 color;\n" |
| 10680 | "void main(){\n" |
| 10681 | " color = vec4(1);\n" |
| 10682 | "}\n"; |
| 10683 | |
| 10684 | VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this); |
| 10685 | VkShaderObj tcs(m_device, tcsSource, VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT, this); |
| 10686 | VkShaderObj tes(m_device, tesSource, VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT, this); |
| 10687 | VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this); |
| 10688 | |
| 10689 | VkPipelineInputAssemblyStateCreateInfo iasci{ |
| 10690 | VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO, |
| 10691 | nullptr, |
| 10692 | 0, |
| 10693 | VK_PRIMITIVE_TOPOLOGY_PATCH_LIST, |
| 10694 | VK_FALSE}; |
| 10695 | |
| 10696 | VkPipelineTessellationStateCreateInfo tsci{ |
| 10697 | VK_STRUCTURE_TYPE_PIPELINE_TESSELLATION_STATE_CREATE_INFO, |
| 10698 | nullptr, |
| 10699 | 0, |
| 10700 | 3}; |
| 10701 | |
| 10702 | VkPipelineObj pipe(m_device); |
| 10703 | pipe.SetInputAssembly(&iasci); |
| 10704 | pipe.SetTessellation(&tsci); |
| 10705 | pipe.AddColorAttachment(); |
| 10706 | pipe.AddShader(&vs); |
| 10707 | pipe.AddShader(&tcs); |
| 10708 | pipe.AddShader(&tes); |
| 10709 | pipe.AddShader(&fs); |
| 10710 | |
| 10711 | VkDescriptorSetObj descriptorSet(m_device); |
| 10712 | descriptorSet.AppendDummy(); |
| 10713 | descriptorSet.CreateVKDescriptorSet(m_commandBuffer); |
| 10714 | |
| 10715 | pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass()); |
| 10716 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 10717 | m_errorMonitor->VerifyFound(); |
Chris Forbes | a0193bc | 2016-04-04 19:19:47 +1200 | [diff] [blame] | 10718 | } |
| 10719 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 10720 | TEST_F(VkLayerTest, CreatePipelineAttribBindingConflict) { |
| 10721 | m_errorMonitor->SetDesiredFailureMsg( |
| 10722 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 10723 | "Duplicate vertex input binding descriptions for binding 0"); |
| 10724 | |
Chris Forbes | 280ba2c | 2015-06-12 11:16:41 +1200 | [diff] [blame] | 10725 | ASSERT_NO_FATAL_FAILURE(InitState()); |
Tobin Ehlis | c9ac2b6 | 2015-09-11 12:57:55 -0600 | [diff] [blame] | 10726 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
Chris Forbes | 280ba2c | 2015-06-12 11:16:41 +1200 | [diff] [blame] | 10727 | |
| 10728 | /* Two binding descriptions for binding 0 */ |
| 10729 | VkVertexInputBindingDescription input_bindings[2]; |
| 10730 | memset(input_bindings, 0, sizeof(input_bindings)); |
| 10731 | |
| 10732 | VkVertexInputAttributeDescription input_attrib; |
| 10733 | memset(&input_attrib, 0, sizeof(input_attrib)); |
| 10734 | input_attrib.format = VK_FORMAT_R32_SFLOAT; |
| 10735 | |
| 10736 | char const *vsSource = |
Chris Forbes | 3846771 | 2016-04-04 17:28:05 +1200 | [diff] [blame] | 10737 | "#version 450\n" |
Chris Forbes | 280ba2c | 2015-06-12 11:16:41 +1200 | [diff] [blame] | 10738 | "\n" |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 10739 | "layout(location=0) in float x;\n" /* attrib provided float */ |
Tony Barbour | e804d20 | 2016-01-05 13:37:45 -0700 | [diff] [blame] | 10740 | "out gl_PerVertex {\n" |
| 10741 | " vec4 gl_Position;\n" |
| 10742 | "};\n" |
Chris Forbes | 280ba2c | 2015-06-12 11:16:41 +1200 | [diff] [blame] | 10743 | "void main(){\n" |
| 10744 | " gl_Position = vec4(x);\n" |
| 10745 | "}\n"; |
| 10746 | char const *fsSource = |
Chris Forbes | 3846771 | 2016-04-04 17:28:05 +1200 | [diff] [blame] | 10747 | "#version 450\n" |
Chris Forbes | 280ba2c | 2015-06-12 11:16:41 +1200 | [diff] [blame] | 10748 | "\n" |
| 10749 | "layout(location=0) out vec4 color;\n" |
| 10750 | "void main(){\n" |
| 10751 | " color = vec4(1);\n" |
| 10752 | "}\n"; |
| 10753 | |
Courtney Goeltzenleuchter | d263550 | 2015-10-21 17:08:06 -0600 | [diff] [blame] | 10754 | VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this); |
| 10755 | VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this); |
Chris Forbes | 280ba2c | 2015-06-12 11:16:41 +1200 | [diff] [blame] | 10756 | |
| 10757 | VkPipelineObj pipe(m_device); |
Chia-I Wu | 08accc6 | 2015-07-07 11:50:03 +0800 | [diff] [blame] | 10758 | pipe.AddColorAttachment(); |
Chris Forbes | 280ba2c | 2015-06-12 11:16:41 +1200 | [diff] [blame] | 10759 | pipe.AddShader(&vs); |
| 10760 | pipe.AddShader(&fs); |
| 10761 | |
| 10762 | pipe.AddVertexInputBindings(input_bindings, 2); |
| 10763 | pipe.AddVertexInputAttribs(&input_attrib, 1); |
| 10764 | |
Chris Forbes | 280ba2c | 2015-06-12 11:16:41 +1200 | [diff] [blame] | 10765 | VkDescriptorSetObj descriptorSet(m_device); |
| 10766 | descriptorSet.AppendDummy(); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 10767 | descriptorSet.CreateVKDescriptorSet(m_commandBuffer); |
Chris Forbes | 280ba2c | 2015-06-12 11:16:41 +1200 | [diff] [blame] | 10768 | |
Tony Barbour | 5781e8f | 2015-08-04 16:23:11 -0600 | [diff] [blame] | 10769 | pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass()); |
Chris Forbes | 280ba2c | 2015-06-12 11:16:41 +1200 | [diff] [blame] | 10770 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 10771 | m_errorMonitor->VerifyFound(); |
Chris Forbes | 280ba2c | 2015-06-12 11:16:41 +1200 | [diff] [blame] | 10772 | } |
Chris Forbes | 8f68b56 | 2015-05-25 11:13:32 +1200 | [diff] [blame] | 10773 | |
Chris Forbes | 35efec7 | 2016-04-21 14:32:08 +1200 | [diff] [blame] | 10774 | TEST_F(VkLayerTest, CreatePipeline64BitAttributesPositive) { |
| 10775 | m_errorMonitor->ExpectSuccess(); |
| 10776 | |
| 10777 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 10778 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 10779 | |
| 10780 | if (!m_device->phy().features().tessellationShader) { |
| 10781 | printf("Device does not support 64bit vertex attributes; skipped.\n"); |
| 10782 | return; |
| 10783 | } |
| 10784 | |
| 10785 | VkVertexInputBindingDescription input_bindings[1]; |
| 10786 | memset(input_bindings, 0, sizeof(input_bindings)); |
| 10787 | |
| 10788 | VkVertexInputAttributeDescription input_attribs[4]; |
| 10789 | memset(input_attribs, 0, sizeof(input_attribs)); |
| 10790 | input_attribs[0].location = 0; |
| 10791 | input_attribs[0].offset = 0; |
| 10792 | input_attribs[0].format = VK_FORMAT_R64G64B64A64_SFLOAT; |
| 10793 | input_attribs[1].location = 2; |
| 10794 | input_attribs[1].offset = 32; |
| 10795 | input_attribs[1].format = VK_FORMAT_R64G64B64A64_SFLOAT; |
| 10796 | input_attribs[2].location = 4; |
| 10797 | input_attribs[2].offset = 64; |
| 10798 | input_attribs[2].format = VK_FORMAT_R64G64B64A64_SFLOAT; |
| 10799 | input_attribs[3].location = 6; |
| 10800 | input_attribs[3].offset = 96; |
| 10801 | input_attribs[3].format = VK_FORMAT_R64G64B64A64_SFLOAT; |
| 10802 | |
| 10803 | char const *vsSource = |
| 10804 | "#version 450\n" |
| 10805 | "\n" |
| 10806 | "layout(location=0) in dmat4 x;\n" |
| 10807 | "out gl_PerVertex {\n" |
| 10808 | " vec4 gl_Position;\n" |
| 10809 | "};\n" |
| 10810 | "void main(){\n" |
| 10811 | " gl_Position = vec4(x[0][0]);\n" |
| 10812 | "}\n"; |
| 10813 | char const *fsSource = |
| 10814 | "#version 450\n" |
| 10815 | "\n" |
| 10816 | "layout(location=0) out vec4 color;\n" |
| 10817 | "void main(){\n" |
| 10818 | " color = vec4(1);\n" |
| 10819 | "}\n"; |
| 10820 | |
| 10821 | VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this); |
| 10822 | VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this); |
| 10823 | |
| 10824 | VkPipelineObj pipe(m_device); |
| 10825 | pipe.AddColorAttachment(); |
| 10826 | pipe.AddShader(&vs); |
| 10827 | pipe.AddShader(&fs); |
| 10828 | |
| 10829 | pipe.AddVertexInputBindings(input_bindings, 1); |
| 10830 | pipe.AddVertexInputAttribs(input_attribs, 4); |
| 10831 | |
| 10832 | VkDescriptorSetObj descriptorSet(m_device); |
| 10833 | descriptorSet.AppendDummy(); |
| 10834 | descriptorSet.CreateVKDescriptorSet(m_commandBuffer); |
| 10835 | |
| 10836 | pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass()); |
| 10837 | |
| 10838 | m_errorMonitor->VerifyNotFound(); |
| 10839 | } |
| 10840 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 10841 | TEST_F(VkLayerTest, CreatePipelineFragmentOutputNotWritten) { |
Courtney Goeltzenleuchter | 7415d5a | 2015-12-09 15:48:16 -0700 | [diff] [blame] | 10842 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 10843 | "Attachment 0 not written by FS"); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 10844 | |
Chris Forbes | 4d6d1e5 | 2015-05-25 11:13:40 +1200 | [diff] [blame] | 10845 | ASSERT_NO_FATAL_FAILURE(InitState()); |
Chris Forbes | 4d6d1e5 | 2015-05-25 11:13:40 +1200 | [diff] [blame] | 10846 | |
| 10847 | char const *vsSource = |
Chris Forbes | 3846771 | 2016-04-04 17:28:05 +1200 | [diff] [blame] | 10848 | "#version 450\n" |
Chris Forbes | 4d6d1e5 | 2015-05-25 11:13:40 +1200 | [diff] [blame] | 10849 | "\n" |
Tony Barbour | e804d20 | 2016-01-05 13:37:45 -0700 | [diff] [blame] | 10850 | "out gl_PerVertex {\n" |
| 10851 | " vec4 gl_Position;\n" |
| 10852 | "};\n" |
Chris Forbes | 4d6d1e5 | 2015-05-25 11:13:40 +1200 | [diff] [blame] | 10853 | "void main(){\n" |
| 10854 | " gl_Position = vec4(1);\n" |
| 10855 | "}\n"; |
| 10856 | char const *fsSource = |
Chris Forbes | 3846771 | 2016-04-04 17:28:05 +1200 | [diff] [blame] | 10857 | "#version 450\n" |
Chris Forbes | 4d6d1e5 | 2015-05-25 11:13:40 +1200 | [diff] [blame] | 10858 | "\n" |
| 10859 | "void main(){\n" |
| 10860 | "}\n"; |
| 10861 | |
Courtney Goeltzenleuchter | d263550 | 2015-10-21 17:08:06 -0600 | [diff] [blame] | 10862 | VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this); |
| 10863 | VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this); |
Chris Forbes | 4d6d1e5 | 2015-05-25 11:13:40 +1200 | [diff] [blame] | 10864 | |
| 10865 | VkPipelineObj pipe(m_device); |
| 10866 | pipe.AddShader(&vs); |
| 10867 | pipe.AddShader(&fs); |
| 10868 | |
Chia-I Wu | 08accc6 | 2015-07-07 11:50:03 +0800 | [diff] [blame] | 10869 | /* set up CB 0, not written */ |
| 10870 | pipe.AddColorAttachment(); |
| 10871 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
Chris Forbes | 4d6d1e5 | 2015-05-25 11:13:40 +1200 | [diff] [blame] | 10872 | |
Chris Forbes | 4d6d1e5 | 2015-05-25 11:13:40 +1200 | [diff] [blame] | 10873 | VkDescriptorSetObj descriptorSet(m_device); |
| 10874 | descriptorSet.AppendDummy(); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 10875 | descriptorSet.CreateVKDescriptorSet(m_commandBuffer); |
Chris Forbes | 4d6d1e5 | 2015-05-25 11:13:40 +1200 | [diff] [blame] | 10876 | |
Tony Barbour | 5781e8f | 2015-08-04 16:23:11 -0600 | [diff] [blame] | 10877 | pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass()); |
Chris Forbes | 4d6d1e5 | 2015-05-25 11:13:40 +1200 | [diff] [blame] | 10878 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 10879 | m_errorMonitor->VerifyFound(); |
Chris Forbes | 4d6d1e5 | 2015-05-25 11:13:40 +1200 | [diff] [blame] | 10880 | } |
| 10881 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 10882 | TEST_F(VkLayerTest, CreatePipelineFragmentOutputNotConsumed) { |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 10883 | m_errorMonitor->SetDesiredFailureMsg( |
Mark Lobodzinski | 510e20d | 2016-02-11 09:26:16 -0700 | [diff] [blame] | 10884 | VK_DEBUG_REPORT_WARNING_BIT_EXT, |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 10885 | "FS writes to output location 1 with no matching attachment"); |
| 10886 | |
Chris Forbes | f3fffaa | 2015-05-25 11:13:43 +1200 | [diff] [blame] | 10887 | ASSERT_NO_FATAL_FAILURE(InitState()); |
Chris Forbes | f3fffaa | 2015-05-25 11:13:43 +1200 | [diff] [blame] | 10888 | |
| 10889 | char const *vsSource = |
Chris Forbes | 3846771 | 2016-04-04 17:28:05 +1200 | [diff] [blame] | 10890 | "#version 450\n" |
Chris Forbes | f3fffaa | 2015-05-25 11:13:43 +1200 | [diff] [blame] | 10891 | "\n" |
Tony Barbour | e804d20 | 2016-01-05 13:37:45 -0700 | [diff] [blame] | 10892 | "out gl_PerVertex {\n" |
| 10893 | " vec4 gl_Position;\n" |
| 10894 | "};\n" |
Chris Forbes | f3fffaa | 2015-05-25 11:13:43 +1200 | [diff] [blame] | 10895 | "void main(){\n" |
| 10896 | " gl_Position = vec4(1);\n" |
| 10897 | "}\n"; |
| 10898 | char const *fsSource = |
Chris Forbes | 3846771 | 2016-04-04 17:28:05 +1200 | [diff] [blame] | 10899 | "#version 450\n" |
Chris Forbes | f3fffaa | 2015-05-25 11:13:43 +1200 | [diff] [blame] | 10900 | "\n" |
| 10901 | "layout(location=0) out vec4 x;\n" |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 10902 | "layout(location=1) out vec4 y;\n" /* no matching attachment for this */ |
Chris Forbes | f3fffaa | 2015-05-25 11:13:43 +1200 | [diff] [blame] | 10903 | "void main(){\n" |
| 10904 | " x = vec4(1);\n" |
| 10905 | " y = vec4(1);\n" |
| 10906 | "}\n"; |
| 10907 | |
Courtney Goeltzenleuchter | d263550 | 2015-10-21 17:08:06 -0600 | [diff] [blame] | 10908 | VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this); |
| 10909 | VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this); |
Chris Forbes | f3fffaa | 2015-05-25 11:13:43 +1200 | [diff] [blame] | 10910 | |
| 10911 | VkPipelineObj pipe(m_device); |
| 10912 | pipe.AddShader(&vs); |
| 10913 | pipe.AddShader(&fs); |
| 10914 | |
Chia-I Wu | 08accc6 | 2015-07-07 11:50:03 +0800 | [diff] [blame] | 10915 | /* set up CB 0, not written */ |
| 10916 | pipe.AddColorAttachment(); |
| 10917 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
Chris Forbes | f3fffaa | 2015-05-25 11:13:43 +1200 | [diff] [blame] | 10918 | /* FS writes CB 1, but we don't configure it */ |
| 10919 | |
Chris Forbes | f3fffaa | 2015-05-25 11:13:43 +1200 | [diff] [blame] | 10920 | VkDescriptorSetObj descriptorSet(m_device); |
| 10921 | descriptorSet.AppendDummy(); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 10922 | descriptorSet.CreateVKDescriptorSet(m_commandBuffer); |
Chris Forbes | f3fffaa | 2015-05-25 11:13:43 +1200 | [diff] [blame] | 10923 | |
Tony Barbour | 5781e8f | 2015-08-04 16:23:11 -0600 | [diff] [blame] | 10924 | pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass()); |
Chris Forbes | f3fffaa | 2015-05-25 11:13:43 +1200 | [diff] [blame] | 10925 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 10926 | m_errorMonitor->VerifyFound(); |
Chris Forbes | f3fffaa | 2015-05-25 11:13:43 +1200 | [diff] [blame] | 10927 | } |
| 10928 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 10929 | TEST_F(VkLayerTest, CreatePipelineFragmentOutputTypeMismatch) { |
Courtney Goeltzenleuchter | 7415d5a | 2015-12-09 15:48:16 -0700 | [diff] [blame] | 10930 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 10931 | "does not match FS output type"); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 10932 | |
Chris Forbes | a36d69e | 2015-05-25 11:13:44 +1200 | [diff] [blame] | 10933 | ASSERT_NO_FATAL_FAILURE(InitState()); |
Chris Forbes | a36d69e | 2015-05-25 11:13:44 +1200 | [diff] [blame] | 10934 | |
| 10935 | char const *vsSource = |
Chris Forbes | 3846771 | 2016-04-04 17:28:05 +1200 | [diff] [blame] | 10936 | "#version 450\n" |
Chris Forbes | a36d69e | 2015-05-25 11:13:44 +1200 | [diff] [blame] | 10937 | "\n" |
Tony Barbour | e804d20 | 2016-01-05 13:37:45 -0700 | [diff] [blame] | 10938 | "out gl_PerVertex {\n" |
| 10939 | " vec4 gl_Position;\n" |
| 10940 | "};\n" |
Chris Forbes | a36d69e | 2015-05-25 11:13:44 +1200 | [diff] [blame] | 10941 | "void main(){\n" |
| 10942 | " gl_Position = vec4(1);\n" |
| 10943 | "}\n"; |
| 10944 | char const *fsSource = |
Chris Forbes | 3846771 | 2016-04-04 17:28:05 +1200 | [diff] [blame] | 10945 | "#version 450\n" |
Chris Forbes | a36d69e | 2015-05-25 11:13:44 +1200 | [diff] [blame] | 10946 | "\n" |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 10947 | "layout(location=0) out ivec4 x;\n" /* not UNORM */ |
Chris Forbes | a36d69e | 2015-05-25 11:13:44 +1200 | [diff] [blame] | 10948 | "void main(){\n" |
| 10949 | " x = ivec4(1);\n" |
| 10950 | "}\n"; |
| 10951 | |
Courtney Goeltzenleuchter | d263550 | 2015-10-21 17:08:06 -0600 | [diff] [blame] | 10952 | VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this); |
| 10953 | VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this); |
Chris Forbes | a36d69e | 2015-05-25 11:13:44 +1200 | [diff] [blame] | 10954 | |
| 10955 | VkPipelineObj pipe(m_device); |
| 10956 | pipe.AddShader(&vs); |
| 10957 | pipe.AddShader(&fs); |
| 10958 | |
Chia-I Wu | 08accc6 | 2015-07-07 11:50:03 +0800 | [diff] [blame] | 10959 | /* set up CB 0; type is UNORM by default */ |
| 10960 | pipe.AddColorAttachment(); |
| 10961 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
Chris Forbes | a36d69e | 2015-05-25 11:13:44 +1200 | [diff] [blame] | 10962 | |
Chris Forbes | a36d69e | 2015-05-25 11:13:44 +1200 | [diff] [blame] | 10963 | VkDescriptorSetObj descriptorSet(m_device); |
| 10964 | descriptorSet.AppendDummy(); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 10965 | descriptorSet.CreateVKDescriptorSet(m_commandBuffer); |
Chris Forbes | a36d69e | 2015-05-25 11:13:44 +1200 | [diff] [blame] | 10966 | |
Tony Barbour | 5781e8f | 2015-08-04 16:23:11 -0600 | [diff] [blame] | 10967 | pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass()); |
Chris Forbes | a36d69e | 2015-05-25 11:13:44 +1200 | [diff] [blame] | 10968 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 10969 | m_errorMonitor->VerifyFound(); |
Chris Forbes | a36d69e | 2015-05-25 11:13:44 +1200 | [diff] [blame] | 10970 | } |
Chris Forbes | 7b1b893 | 2015-06-05 14:43:36 +1200 | [diff] [blame] | 10971 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 10972 | TEST_F(VkLayerTest, CreatePipelineUniformBlockNotProvided) { |
Courtney Goeltzenleuchter | 7415d5a | 2015-12-09 15:48:16 -0700 | [diff] [blame] | 10973 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 10974 | "not declared in pipeline layout"); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 10975 | |
Chris Forbes | 556c76c | 2015-08-14 12:04:59 +1200 | [diff] [blame] | 10976 | ASSERT_NO_FATAL_FAILURE(InitState()); |
Chris Forbes | 556c76c | 2015-08-14 12:04:59 +1200 | [diff] [blame] | 10977 | |
| 10978 | char const *vsSource = |
Chris Forbes | 3846771 | 2016-04-04 17:28:05 +1200 | [diff] [blame] | 10979 | "#version 450\n" |
Chris Forbes | 556c76c | 2015-08-14 12:04:59 +1200 | [diff] [blame] | 10980 | "\n" |
Tony Barbour | e804d20 | 2016-01-05 13:37:45 -0700 | [diff] [blame] | 10981 | "out gl_PerVertex {\n" |
| 10982 | " vec4 gl_Position;\n" |
| 10983 | "};\n" |
Chris Forbes | 556c76c | 2015-08-14 12:04:59 +1200 | [diff] [blame] | 10984 | "void main(){\n" |
| 10985 | " gl_Position = vec4(1);\n" |
| 10986 | "}\n"; |
| 10987 | char const *fsSource = |
Chris Forbes | 3846771 | 2016-04-04 17:28:05 +1200 | [diff] [blame] | 10988 | "#version 450\n" |
Chris Forbes | 556c76c | 2015-08-14 12:04:59 +1200 | [diff] [blame] | 10989 | "\n" |
| 10990 | "layout(location=0) out vec4 x;\n" |
| 10991 | "layout(set=0) layout(binding=0) uniform foo { int x; int y; } bar;\n" |
| 10992 | "void main(){\n" |
| 10993 | " x = vec4(bar.y);\n" |
| 10994 | "}\n"; |
| 10995 | |
Courtney Goeltzenleuchter | d263550 | 2015-10-21 17:08:06 -0600 | [diff] [blame] | 10996 | VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this); |
| 10997 | VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this); |
Chris Forbes | 556c76c | 2015-08-14 12:04:59 +1200 | [diff] [blame] | 10998 | |
Chris Forbes | 556c76c | 2015-08-14 12:04:59 +1200 | [diff] [blame] | 10999 | VkPipelineObj pipe(m_device); |
| 11000 | pipe.AddShader(&vs); |
| 11001 | pipe.AddShader(&fs); |
| 11002 | |
| 11003 | /* set up CB 0; type is UNORM by default */ |
| 11004 | pipe.AddColorAttachment(); |
| 11005 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 11006 | |
| 11007 | VkDescriptorSetObj descriptorSet(m_device); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 11008 | descriptorSet.CreateVKDescriptorSet(m_commandBuffer); |
Chris Forbes | 556c76c | 2015-08-14 12:04:59 +1200 | [diff] [blame] | 11009 | |
| 11010 | pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass()); |
| 11011 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 11012 | m_errorMonitor->VerifyFound(); |
Chris Forbes | 556c76c | 2015-08-14 12:04:59 +1200 | [diff] [blame] | 11013 | } |
| 11014 | |
Chris Forbes | 5c59e90 | 2016-02-26 16:56:09 +1300 | [diff] [blame] | 11015 | TEST_F(VkLayerTest, CreatePipelinePushConstantsNotInLayout) { |
| 11016 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 11017 | "not declared in layout"); |
| 11018 | |
| 11019 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 11020 | |
| 11021 | char const *vsSource = |
| 11022 | "#version 450\n" |
Chris Forbes | 5c59e90 | 2016-02-26 16:56:09 +1300 | [diff] [blame] | 11023 | "\n" |
| 11024 | "layout(push_constant, std430) uniform foo { float x; } consts;\n" |
| 11025 | "out gl_PerVertex {\n" |
| 11026 | " vec4 gl_Position;\n" |
| 11027 | "};\n" |
| 11028 | "void main(){\n" |
| 11029 | " gl_Position = vec4(consts.x);\n" |
| 11030 | "}\n"; |
| 11031 | char const *fsSource = |
| 11032 | "#version 450\n" |
Chris Forbes | 5c59e90 | 2016-02-26 16:56:09 +1300 | [diff] [blame] | 11033 | "\n" |
| 11034 | "layout(location=0) out vec4 x;\n" |
| 11035 | "void main(){\n" |
| 11036 | " x = vec4(1);\n" |
| 11037 | "}\n"; |
| 11038 | |
| 11039 | VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this); |
| 11040 | VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this); |
| 11041 | |
| 11042 | VkPipelineObj pipe(m_device); |
| 11043 | pipe.AddShader(&vs); |
| 11044 | pipe.AddShader(&fs); |
| 11045 | |
| 11046 | /* set up CB 0; type is UNORM by default */ |
| 11047 | pipe.AddColorAttachment(); |
| 11048 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 11049 | |
| 11050 | VkDescriptorSetObj descriptorSet(m_device); |
| 11051 | descriptorSet.CreateVKDescriptorSet(m_commandBuffer); |
| 11052 | |
| 11053 | pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass()); |
| 11054 | |
| 11055 | /* should have generated an error -- no push constant ranges provided! */ |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 11056 | m_errorMonitor->VerifyFound(); |
Chris Forbes | 5c59e90 | 2016-02-26 16:56:09 +1300 | [diff] [blame] | 11057 | } |
| 11058 | |
Chris Forbes | 10eb9ae | 2016-05-31 16:09:42 +1200 | [diff] [blame] | 11059 | TEST_F(VkLayerTest, CreateComputePipelineMissingDescriptor) { |
| 11060 | m_errorMonitor->SetDesiredFailureMsg( |
| 11061 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 11062 | "Shader uses descriptor slot 0.0"); |
| 11063 | |
| 11064 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 11065 | |
| 11066 | char const *csSource = |
| 11067 | "#version 450\n" |
| 11068 | "\n" |
| 11069 | "layout(local_size_x=1) in;\n" |
| 11070 | "layout(set=0, binding=0) buffer block { vec4 x; };\n" |
| 11071 | "void main(){\n" |
| 11072 | " x = vec4(1);\n" |
| 11073 | "}\n"; |
| 11074 | |
| 11075 | VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this); |
| 11076 | |
| 11077 | VkDescriptorSetObj descriptorSet(m_device); |
| 11078 | descriptorSet.CreateVKDescriptorSet(m_commandBuffer); |
| 11079 | |
| 11080 | VkComputePipelineCreateInfo cpci = { |
| 11081 | VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO, |
| 11082 | nullptr, 0, { |
| 11083 | VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, |
| 11084 | nullptr, 0, VK_SHADER_STAGE_COMPUTE_BIT, |
| 11085 | cs.handle(), "main", nullptr |
| 11086 | }, |
| 11087 | descriptorSet.GetPipelineLayout(), |
| 11088 | VK_NULL_HANDLE, -1 |
| 11089 | }; |
| 11090 | |
| 11091 | VkPipeline pipe; |
| 11092 | VkResult err = vkCreateComputePipelines( |
| 11093 | m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe); |
| 11094 | |
| 11095 | m_errorMonitor->VerifyFound(); |
| 11096 | |
| 11097 | if (err == VK_SUCCESS) { |
| 11098 | vkDestroyPipeline(m_device->device(), pipe, nullptr); |
| 11099 | } |
| 11100 | } |
| 11101 | |
| 11102 | TEST_F(VkLayerTest, CreateComputePipelineMissingDescriptorUnusedPositive) { |
| 11103 | m_errorMonitor->ExpectSuccess(); |
| 11104 | |
| 11105 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 11106 | |
| 11107 | char const *csSource = |
| 11108 | "#version 450\n" |
| 11109 | "\n" |
| 11110 | "layout(local_size_x=1) in;\n" |
| 11111 | "layout(set=0, binding=0) buffer block { vec4 x; };\n" |
| 11112 | "void main(){\n" |
| 11113 | " // x is not used.\n" |
| 11114 | "}\n"; |
| 11115 | |
| 11116 | VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this); |
| 11117 | |
| 11118 | VkDescriptorSetObj descriptorSet(m_device); |
| 11119 | descriptorSet.CreateVKDescriptorSet(m_commandBuffer); |
| 11120 | |
| 11121 | VkComputePipelineCreateInfo cpci = { |
| 11122 | VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO, |
| 11123 | nullptr, 0, { |
| 11124 | VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, |
| 11125 | nullptr, 0, VK_SHADER_STAGE_COMPUTE_BIT, |
| 11126 | cs.handle(), "main", nullptr |
| 11127 | }, |
| 11128 | descriptorSet.GetPipelineLayout(), |
| 11129 | VK_NULL_HANDLE, -1 |
| 11130 | }; |
| 11131 | |
| 11132 | VkPipeline pipe; |
| 11133 | VkResult err = vkCreateComputePipelines( |
| 11134 | m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe); |
| 11135 | |
| 11136 | m_errorMonitor->VerifyNotFound(); |
| 11137 | |
| 11138 | if (err == VK_SUCCESS) { |
| 11139 | vkDestroyPipeline(m_device->device(), pipe, nullptr); |
| 11140 | } |
| 11141 | } |
| 11142 | |
Mark Lobodzinski | 209b529 | 2015-09-17 09:44:05 -0600 | [diff] [blame] | 11143 | #endif // SHADER_CHECKER_TESTS |
| 11144 | |
| 11145 | #if DEVICE_LIMITS_TESTS |
Mark Young | c48c4c1 | 2016-04-11 14:26:49 -0600 | [diff] [blame] | 11146 | TEST_F(VkLayerTest, CreateImageLimitsViolationMaxWidth) { |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 11147 | m_errorMonitor->SetDesiredFailureMsg( |
| 11148 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 11149 | "CreateImage extents exceed allowable limits for format"); |
Mark Lobodzinski | 6f2274e | 2015-09-22 09:33:21 -0600 | [diff] [blame] | 11150 | |
| 11151 | ASSERT_NO_FATAL_FAILURE(InitState()); |
Mark Lobodzinski | 6f2274e | 2015-09-22 09:33:21 -0600 | [diff] [blame] | 11152 | |
| 11153 | // Create an image |
| 11154 | VkImage image; |
| 11155 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 11156 | const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM; |
| 11157 | const int32_t tex_width = 32; |
| 11158 | const int32_t tex_height = 32; |
Mark Lobodzinski | 6f2274e | 2015-09-22 09:33:21 -0600 | [diff] [blame] | 11159 | |
| 11160 | VkImageCreateInfo image_create_info = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 11161 | image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO; |
| 11162 | image_create_info.pNext = NULL; |
| 11163 | image_create_info.imageType = VK_IMAGE_TYPE_2D; |
| 11164 | image_create_info.format = tex_format; |
| 11165 | image_create_info.extent.width = tex_width; |
Mark Lobodzinski | 6f2274e | 2015-09-22 09:33:21 -0600 | [diff] [blame] | 11166 | image_create_info.extent.height = tex_height; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 11167 | image_create_info.extent.depth = 1; |
| 11168 | image_create_info.mipLevels = 1; |
| 11169 | image_create_info.arrayLayers = 1; |
| 11170 | image_create_info.samples = VK_SAMPLE_COUNT_1_BIT; |
| 11171 | image_create_info.tiling = VK_IMAGE_TILING_LINEAR; |
| 11172 | image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT; |
| 11173 | image_create_info.flags = 0; |
Mark Lobodzinski | 6f2274e | 2015-09-22 09:33:21 -0600 | [diff] [blame] | 11174 | |
| 11175 | // Introduce error by sending down a bogus width extent |
| 11176 | image_create_info.extent.width = 65536; |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 11177 | vkCreateImage(m_device->device(), &image_create_info, NULL, &image); |
Mark Lobodzinski | 6f2274e | 2015-09-22 09:33:21 -0600 | [diff] [blame] | 11178 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 11179 | m_errorMonitor->VerifyFound(); |
Mark Lobodzinski | 6f2274e | 2015-09-22 09:33:21 -0600 | [diff] [blame] | 11180 | } |
| 11181 | |
Mark Young | c48c4c1 | 2016-04-11 14:26:49 -0600 | [diff] [blame] | 11182 | TEST_F(VkLayerTest, CreateImageLimitsViolationMinWidth) { |
| 11183 | m_errorMonitor->SetDesiredFailureMsg( |
| 11184 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 11185 | "CreateImage extents is 0 for at least one required dimension"); |
| 11186 | |
| 11187 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 11188 | |
| 11189 | // Create an image |
| 11190 | VkImage image; |
| 11191 | |
| 11192 | const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM; |
| 11193 | const int32_t tex_width = 32; |
| 11194 | const int32_t tex_height = 32; |
| 11195 | |
| 11196 | VkImageCreateInfo image_create_info = {}; |
| 11197 | image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO; |
| 11198 | image_create_info.pNext = NULL; |
| 11199 | image_create_info.imageType = VK_IMAGE_TYPE_2D; |
| 11200 | image_create_info.format = tex_format; |
| 11201 | image_create_info.extent.width = tex_width; |
| 11202 | image_create_info.extent.height = tex_height; |
| 11203 | image_create_info.extent.depth = 1; |
| 11204 | image_create_info.mipLevels = 1; |
| 11205 | image_create_info.arrayLayers = 1; |
| 11206 | image_create_info.samples = VK_SAMPLE_COUNT_1_BIT; |
| 11207 | image_create_info.tiling = VK_IMAGE_TILING_LINEAR; |
| 11208 | image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT; |
| 11209 | image_create_info.flags = 0; |
| 11210 | |
| 11211 | // Introduce error by sending down a bogus width extent |
| 11212 | image_create_info.extent.width = 0; |
| 11213 | vkCreateImage(m_device->device(), &image_create_info, NULL, &image); |
| 11214 | |
| 11215 | m_errorMonitor->VerifyFound(); |
| 11216 | } |
Mark Lobodzinski | 209b529 | 2015-09-17 09:44:05 -0600 | [diff] [blame] | 11217 | #endif // DEVICE_LIMITS_TESTS |
Chris Forbes | a36d69e | 2015-05-25 11:13:44 +1200 | [diff] [blame] | 11218 | |
Tobin Ehlis | cde0889 | 2015-09-22 10:11:37 -0600 | [diff] [blame] | 11219 | #if IMAGE_TESTS |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 11220 | TEST_F(VkLayerTest, InvalidImageView) { |
| 11221 | VkResult err; |
Tobin Ehlis | cde0889 | 2015-09-22 10:11:37 -0600 | [diff] [blame] | 11222 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 11223 | m_errorMonitor->SetDesiredFailureMsg( |
| 11224 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 11225 | "vkCreateImageView called with baseMipLevel 10 "); |
| 11226 | |
Tobin Ehlis | cde0889 | 2015-09-22 10:11:37 -0600 | [diff] [blame] | 11227 | ASSERT_NO_FATAL_FAILURE(InitState()); |
Tobin Ehlis | cde0889 | 2015-09-22 10:11:37 -0600 | [diff] [blame] | 11228 | |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 11229 | // Create an image and try to create a view with bad baseMipLevel |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 11230 | VkImage image; |
Tobin Ehlis | cde0889 | 2015-09-22 10:11:37 -0600 | [diff] [blame] | 11231 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 11232 | const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM; |
| 11233 | const int32_t tex_width = 32; |
| 11234 | const int32_t tex_height = 32; |
Tobin Ehlis | cde0889 | 2015-09-22 10:11:37 -0600 | [diff] [blame] | 11235 | |
| 11236 | VkImageCreateInfo image_create_info = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 11237 | image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO; |
| 11238 | image_create_info.pNext = NULL; |
| 11239 | image_create_info.imageType = VK_IMAGE_TYPE_2D; |
| 11240 | image_create_info.format = tex_format; |
| 11241 | image_create_info.extent.width = tex_width; |
| 11242 | image_create_info.extent.height = tex_height; |
| 11243 | image_create_info.extent.depth = 1; |
| 11244 | image_create_info.mipLevels = 1; |
| 11245 | image_create_info.arrayLayers = 1; |
| 11246 | image_create_info.samples = VK_SAMPLE_COUNT_1_BIT; |
| 11247 | image_create_info.tiling = VK_IMAGE_TILING_LINEAR; |
| 11248 | image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT; |
| 11249 | image_create_info.flags = 0; |
Tobin Ehlis | cde0889 | 2015-09-22 10:11:37 -0600 | [diff] [blame] | 11250 | |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 11251 | err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image); |
Tobin Ehlis | cde0889 | 2015-09-22 10:11:37 -0600 | [diff] [blame] | 11252 | ASSERT_VK_SUCCESS(err); |
| 11253 | |
| 11254 | VkImageViewCreateInfo image_view_create_info = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 11255 | image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO; |
| 11256 | image_view_create_info.image = image; |
| 11257 | image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D; |
| 11258 | image_view_create_info.format = tex_format; |
| 11259 | image_view_create_info.subresourceRange.layerCount = 1; |
| 11260 | image_view_create_info.subresourceRange.baseMipLevel = 10; // cause an error |
| 11261 | image_view_create_info.subresourceRange.levelCount = 1; |
| 11262 | image_view_create_info.subresourceRange.aspectMask = |
| 11263 | VK_IMAGE_ASPECT_COLOR_BIT; |
Tobin Ehlis | cde0889 | 2015-09-22 10:11:37 -0600 | [diff] [blame] | 11264 | |
| 11265 | VkImageView view; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 11266 | err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, |
| 11267 | &view); |
Tobin Ehlis | cde0889 | 2015-09-22 10:11:37 -0600 | [diff] [blame] | 11268 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 11269 | m_errorMonitor->VerifyFound(); |
Tony Barbour | df4c004 | 2016-06-01 15:55:43 -0600 | [diff] [blame] | 11270 | vkDestroyImage(m_device->device(), image, NULL); |
Tobin Ehlis | cde0889 | 2015-09-22 10:11:37 -0600 | [diff] [blame] | 11271 | } |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 11272 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 11273 | TEST_F(VkLayerTest, InvalidImageViewAspect) { |
Tobin Ehlis | 1f567a2 | 2016-05-25 16:15:18 -0600 | [diff] [blame] | 11274 | TEST_DESCRIPTION( |
| 11275 | "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] | 11276 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 11277 | "vkCreateImageView: Color image " |
| 11278 | "formats must have ONLY the " |
| 11279 | "VK_IMAGE_ASPECT_COLOR_BIT set"); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 11280 | |
Mark Lobodzinski | dc86b85 | 2015-10-23 14:20:31 -0600 | [diff] [blame] | 11281 | ASSERT_NO_FATAL_FAILURE(InitState()); |
Mark Lobodzinski | dc86b85 | 2015-10-23 14:20:31 -0600 | [diff] [blame] | 11282 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 11283 | const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM; |
Tobin Ehlis | 1f567a2 | 2016-05-25 16:15:18 -0600 | [diff] [blame] | 11284 | VkImageObj image(m_device); |
| 11285 | image.init(32, 32, tex_format, VK_IMAGE_USAGE_SAMPLED_BIT, |
| 11286 | VK_IMAGE_TILING_LINEAR, 0); |
| 11287 | ASSERT_TRUE(image.initialized()); |
Mark Lobodzinski | dc86b85 | 2015-10-23 14:20:31 -0600 | [diff] [blame] | 11288 | |
| 11289 | VkImageViewCreateInfo image_view_create_info = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 11290 | image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO; |
Tobin Ehlis | 1f567a2 | 2016-05-25 16:15:18 -0600 | [diff] [blame] | 11291 | image_view_create_info.image = image.handle(); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 11292 | image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D; |
| 11293 | image_view_create_info.format = tex_format; |
| 11294 | image_view_create_info.subresourceRange.baseMipLevel = 0; |
| 11295 | image_view_create_info.subresourceRange.levelCount = 1; |
| 11296 | // Cause an error by setting an invalid image aspect |
| 11297 | image_view_create_info.subresourceRange.aspectMask = |
| 11298 | VK_IMAGE_ASPECT_METADATA_BIT; |
Mark Lobodzinski | dc86b85 | 2015-10-23 14:20:31 -0600 | [diff] [blame] | 11299 | |
| 11300 | VkImageView view; |
Tobin Ehlis | 1f567a2 | 2016-05-25 16:15:18 -0600 | [diff] [blame] | 11301 | vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view); |
Mark Lobodzinski | dc86b85 | 2015-10-23 14:20:31 -0600 | [diff] [blame] | 11302 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 11303 | m_errorMonitor->VerifyFound(); |
Mark Lobodzinski | dc86b85 | 2015-10-23 14:20:31 -0600 | [diff] [blame] | 11304 | } |
| 11305 | |
Mark Lobodzinski | db11763 | 2016-03-31 10:45:56 -0600 | [diff] [blame] | 11306 | TEST_F(VkLayerTest, CopyImageLayerCountMismatch) { |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 11307 | VkResult err; |
| 11308 | bool pass; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 11309 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 11310 | m_errorMonitor->SetDesiredFailureMsg( |
| 11311 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Mark Lobodzinski | db11763 | 2016-03-31 10:45:56 -0600 | [diff] [blame] | 11312 | "vkCmdCopyImage: number of layers in source and destination subresources for pRegions"); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 11313 | |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 11314 | ASSERT_NO_FATAL_FAILURE(InitState()); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 11315 | |
| 11316 | // Create two images of different types and try to copy between them |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 11317 | VkImage srcImage; |
| 11318 | VkImage dstImage; |
| 11319 | VkDeviceMemory srcMem; |
| 11320 | VkDeviceMemory destMem; |
| 11321 | VkMemoryRequirements memReqs; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 11322 | |
| 11323 | VkImageCreateInfo image_create_info = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 11324 | image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO; |
| 11325 | image_create_info.pNext = NULL; |
| 11326 | image_create_info.imageType = VK_IMAGE_TYPE_2D; |
| 11327 | image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM; |
| 11328 | image_create_info.extent.width = 32; |
| 11329 | image_create_info.extent.height = 32; |
| 11330 | image_create_info.extent.depth = 1; |
| 11331 | image_create_info.mipLevels = 1; |
Mark Lobodzinski | db11763 | 2016-03-31 10:45:56 -0600 | [diff] [blame] | 11332 | image_create_info.arrayLayers = 4; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 11333 | image_create_info.samples = VK_SAMPLE_COUNT_1_BIT; |
| 11334 | image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL; |
| 11335 | image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT; |
| 11336 | image_create_info.flags = 0; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 11337 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 11338 | err = |
| 11339 | vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 11340 | ASSERT_VK_SUCCESS(err); |
| 11341 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 11342 | err = |
| 11343 | vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 11344 | ASSERT_VK_SUCCESS(err); |
| 11345 | |
| 11346 | // Allocate memory |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 11347 | VkMemoryAllocateInfo memAlloc = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 11348 | memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO; |
| 11349 | memAlloc.pNext = NULL; |
| 11350 | memAlloc.allocationSize = 0; |
| 11351 | memAlloc.memoryTypeIndex = 0; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 11352 | |
Courtney Goeltzenleuchter | 06d8947 | 2015-10-20 16:40:38 -0600 | [diff] [blame] | 11353 | vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 11354 | memAlloc.allocationSize = memReqs.size; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 11355 | pass = |
| 11356 | m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0); |
Courtney Goeltzenleuchter | 1d2f0dd | 2015-10-22 11:03:31 -0600 | [diff] [blame] | 11357 | ASSERT_TRUE(pass); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 11358 | err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 11359 | ASSERT_VK_SUCCESS(err); |
| 11360 | |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 11361 | vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 11362 | memAlloc.allocationSize = memReqs.size; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 11363 | pass = |
| 11364 | m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 11365 | ASSERT_VK_SUCCESS(err); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 11366 | err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 11367 | ASSERT_VK_SUCCESS(err); |
| 11368 | |
| 11369 | err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0); |
| 11370 | ASSERT_VK_SUCCESS(err); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 11371 | err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 11372 | ASSERT_VK_SUCCESS(err); |
| 11373 | |
| 11374 | BeginCommandBuffer(); |
| 11375 | VkImageCopy copyRegion; |
Chia-I Wu | ab83a0e | 2015-10-27 19:00:15 +0800 | [diff] [blame] | 11376 | copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 11377 | copyRegion.srcSubresource.mipLevel = 0; |
Courtney Goeltzenleuchter | 8367ce0 | 2015-10-16 09:46:00 -0600 | [diff] [blame] | 11378 | copyRegion.srcSubresource.baseArrayLayer = 0; |
Mark Lobodzinski | db11763 | 2016-03-31 10:45:56 -0600 | [diff] [blame] | 11379 | copyRegion.srcSubresource.layerCount = 1; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 11380 | copyRegion.srcOffset.x = 0; |
| 11381 | copyRegion.srcOffset.y = 0; |
| 11382 | copyRegion.srcOffset.z = 0; |
Chia-I Wu | ab83a0e | 2015-10-27 19:00:15 +0800 | [diff] [blame] | 11383 | copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 11384 | copyRegion.dstSubresource.mipLevel = 0; |
| 11385 | copyRegion.dstSubresource.baseArrayLayer = 0; |
Mark Lobodzinski | db11763 | 2016-03-31 10:45:56 -0600 | [diff] [blame] | 11386 | // Introduce failure by forcing the dst layerCount to differ from src |
| 11387 | copyRegion.dstSubresource.layerCount = 3; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 11388 | copyRegion.dstOffset.x = 0; |
| 11389 | copyRegion.dstOffset.y = 0; |
| 11390 | copyRegion.dstOffset.z = 0; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 11391 | copyRegion.extent.width = 1; |
| 11392 | copyRegion.extent.height = 1; |
| 11393 | copyRegion.extent.depth = 1; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 11394 | m_commandBuffer->CopyImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, |
| 11395 | VK_IMAGE_LAYOUT_GENERAL, 1, ©Region); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 11396 | EndCommandBuffer(); |
| 11397 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 11398 | m_errorMonitor->VerifyFound(); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 11399 | |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 11400 | vkDestroyImage(m_device->device(), srcImage, NULL); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 11401 | vkDestroyImage(m_device->device(), dstImage, NULL); |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 11402 | vkFreeMemory(m_device->device(), srcMem, NULL); |
| 11403 | vkFreeMemory(m_device->device(), destMem, NULL); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 11404 | } |
| 11405 | |
Tony Barbour | d667364 | 2016-05-05 14:46:39 -0600 | [diff] [blame] | 11406 | TEST_F(VkLayerTest, ImageLayerUnsupportedFormat) { |
| 11407 | |
| 11408 | TEST_DESCRIPTION("Creating images with unsuported formats "); |
| 11409 | |
| 11410 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 11411 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 11412 | VkImageObj image(m_device); |
| 11413 | image.init(128, 128, VK_FORMAT_B8G8R8A8_UNORM, |
| 11414 | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | |
| 11415 | VK_IMAGE_USAGE_TRANSFER_DST_BIT, |
| 11416 | VK_IMAGE_TILING_OPTIMAL, 0); |
| 11417 | ASSERT_TRUE(image.initialized()); |
| 11418 | |
Mark Lobodzinski | ba5c686 | 2016-05-17 08:14:00 -0600 | [diff] [blame] | 11419 | // Create image with unsupported format - Expect FORMAT_UNSUPPORTED |
| 11420 | VkImageCreateInfo image_create_info; |
| 11421 | image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO; |
| 11422 | image_create_info.pNext = NULL; |
| 11423 | image_create_info.imageType = VK_IMAGE_TYPE_2D; |
| 11424 | image_create_info.format = VK_FORMAT_UNDEFINED; |
| 11425 | image_create_info.extent.width = 32; |
| 11426 | image_create_info.extent.height = 32; |
| 11427 | image_create_info.extent.depth = 1; |
| 11428 | image_create_info.mipLevels = 1; |
| 11429 | image_create_info.arrayLayers = 1; |
| 11430 | image_create_info.samples = VK_SAMPLE_COUNT_1_BIT; |
| 11431 | image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL; |
| 11432 | image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT; |
| 11433 | image_create_info.flags = 0; |
| 11434 | |
| 11435 | m_errorMonitor->SetDesiredFailureMsg( |
| 11436 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 11437 | "vkCreateImage: VkFormat for image must not be VK_FORMAT_UNDEFINED"); |
| 11438 | |
| 11439 | VkImage localImage; |
| 11440 | vkCreateImage(m_device->handle(), &image_create_info, NULL, &localImage); |
| 11441 | m_errorMonitor->VerifyFound(); |
| 11442 | |
Tony Barbour | d667364 | 2016-05-05 14:46:39 -0600 | [diff] [blame] | 11443 | VkFormat unsupported = VK_FORMAT_UNDEFINED; |
Mark Lobodzinski | ba5c686 | 2016-05-17 08:14:00 -0600 | [diff] [blame] | 11444 | // Look for a format that is COMPLETELY unsupported with this hardware |
Tony Barbour | d667364 | 2016-05-05 14:46:39 -0600 | [diff] [blame] | 11445 | for (int f = VK_FORMAT_BEGIN_RANGE; f <= VK_FORMAT_END_RANGE; f++) { |
| 11446 | VkFormat format = static_cast<VkFormat>(f); |
| 11447 | VkFormatProperties fProps = m_device->format_properties(format); |
| 11448 | if (format != VK_FORMAT_UNDEFINED && fProps.linearTilingFeatures == 0 && |
| 11449 | fProps.optimalTilingFeatures == 0) { |
| 11450 | unsupported = format; |
| 11451 | break; |
| 11452 | } |
| 11453 | } |
Mark Lobodzinski | ba5c686 | 2016-05-17 08:14:00 -0600 | [diff] [blame] | 11454 | |
Tony Barbour | d667364 | 2016-05-05 14:46:39 -0600 | [diff] [blame] | 11455 | if (unsupported != VK_FORMAT_UNDEFINED) { |
Tony Barbour | d667364 | 2016-05-05 14:46:39 -0600 | [diff] [blame] | 11456 | image_create_info.format = unsupported; |
Tony Barbour | d667364 | 2016-05-05 14:46:39 -0600 | [diff] [blame] | 11457 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Mark Lobodzinski | ba5c686 | 2016-05-17 08:14:00 -0600 | [diff] [blame] | 11458 | "is an unsupported format"); |
Tony Barbour | d667364 | 2016-05-05 14:46:39 -0600 | [diff] [blame] | 11459 | |
Mark Lobodzinski | ba5c686 | 2016-05-17 08:14:00 -0600 | [diff] [blame] | 11460 | vkCreateImage(m_device->handle(), &image_create_info, NULL, &localImage); |
Tony Barbour | d667364 | 2016-05-05 14:46:39 -0600 | [diff] [blame] | 11461 | m_errorMonitor->VerifyFound(); |
| 11462 | } |
| 11463 | } |
| 11464 | |
| 11465 | TEST_F(VkLayerTest, ImageLayerViewTests) { |
| 11466 | VkResult ret; |
| 11467 | TEST_DESCRIPTION("Passing bad parameters to CreateImageView"); |
| 11468 | |
| 11469 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 11470 | |
| 11471 | VkImageObj image(m_device); |
| 11472 | image.init(128, 128, VK_FORMAT_B8G8R8A8_UNORM, |
| 11473 | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | |
| 11474 | VK_IMAGE_USAGE_TRANSFER_DST_BIT, |
| 11475 | VK_IMAGE_TILING_OPTIMAL, 0); |
| 11476 | ASSERT_TRUE(image.initialized()); |
| 11477 | |
| 11478 | VkImageView imgView; |
| 11479 | VkImageViewCreateInfo imgViewInfo = {}; |
| 11480 | imgViewInfo.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO; |
| 11481 | imgViewInfo.image = image.handle(); |
| 11482 | imgViewInfo.viewType = VK_IMAGE_VIEW_TYPE_2D; |
| 11483 | imgViewInfo.format = VK_FORMAT_B8G8R8A8_UNORM; |
| 11484 | imgViewInfo.subresourceRange.layerCount = 1; |
| 11485 | imgViewInfo.subresourceRange.baseMipLevel = 0; |
| 11486 | imgViewInfo.subresourceRange.levelCount = 1; |
| 11487 | imgViewInfo.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; |
| 11488 | |
| 11489 | m_errorMonitor->SetDesiredFailureMsg( |
| 11490 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 11491 | "vkCreateImageView called with baseMipLevel"); |
| 11492 | // View can't have baseMipLevel >= image's mipLevels - Expect |
| 11493 | // VIEW_CREATE_ERROR |
| 11494 | imgViewInfo.subresourceRange.baseMipLevel = 1; |
| 11495 | vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView); |
| 11496 | m_errorMonitor->VerifyFound(); |
| 11497 | imgViewInfo.subresourceRange.baseMipLevel = 0; |
| 11498 | |
| 11499 | m_errorMonitor->SetDesiredFailureMsg( |
| 11500 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 11501 | "vkCreateImageView called with baseArrayLayer"); |
| 11502 | // View can't have baseArrayLayer >= image's arraySize - Expect |
| 11503 | // VIEW_CREATE_ERROR |
| 11504 | imgViewInfo.subresourceRange.baseArrayLayer = 1; |
| 11505 | vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView); |
| 11506 | m_errorMonitor->VerifyFound(); |
| 11507 | imgViewInfo.subresourceRange.baseArrayLayer = 0; |
| 11508 | |
| 11509 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 11510 | "vkCreateImageView called with 0 in " |
| 11511 | "pCreateInfo->subresourceRange." |
| 11512 | "levelCount"); |
| 11513 | // View's levelCount can't be 0 - Expect VIEW_CREATE_ERROR |
| 11514 | imgViewInfo.subresourceRange.levelCount = 0; |
| 11515 | vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView); |
| 11516 | m_errorMonitor->VerifyFound(); |
| 11517 | imgViewInfo.subresourceRange.levelCount = 1; |
| 11518 | |
| 11519 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 11520 | "vkCreateImageView called with 0 in " |
| 11521 | "pCreateInfo->subresourceRange." |
| 11522 | "layerCount"); |
| 11523 | // View's layerCount can't be 0 - Expect VIEW_CREATE_ERROR |
| 11524 | imgViewInfo.subresourceRange.layerCount = 0; |
| 11525 | vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView); |
| 11526 | m_errorMonitor->VerifyFound(); |
| 11527 | imgViewInfo.subresourceRange.layerCount = 1; |
| 11528 | |
| 11529 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 11530 | "but both must be color formats"); |
| 11531 | // Can't use depth format for view into color image - Expect INVALID_FORMAT |
| 11532 | imgViewInfo.format = VK_FORMAT_D24_UNORM_S8_UINT; |
| 11533 | vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView); |
| 11534 | m_errorMonitor->VerifyFound(); |
| 11535 | imgViewInfo.format = VK_FORMAT_B8G8R8A8_UNORM; |
| 11536 | |
| 11537 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 11538 | "Formats MUST be IDENTICAL unless " |
| 11539 | "VK_IMAGE_CREATE_MUTABLE_FORMAT BIT " |
| 11540 | "was set on image creation."); |
| 11541 | // Same compatibility class but no MUTABLE_FORMAT bit - Expect |
| 11542 | // VIEW_CREATE_ERROR |
| 11543 | imgViewInfo.format = VK_FORMAT_B8G8R8A8_UINT; |
| 11544 | vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView); |
| 11545 | m_errorMonitor->VerifyFound(); |
| 11546 | imgViewInfo.format = VK_FORMAT_B8G8R8A8_UNORM; |
| 11547 | |
| 11548 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 11549 | "can support ImageViews with " |
| 11550 | "differing formats but they must be " |
| 11551 | "in the same compatibility class."); |
| 11552 | // Have MUTABLE_FORMAT bit but not in same compatibility class - Expect |
| 11553 | // VIEW_CREATE_ERROR |
| 11554 | VkImageCreateInfo mutImgInfo = image.create_info(); |
| 11555 | VkImage mutImage; |
| 11556 | mutImgInfo.format = VK_FORMAT_R8_UINT; |
| 11557 | assert( |
| 11558 | m_device->format_properties(VK_FORMAT_R8_UINT).optimalTilingFeatures & |
| 11559 | VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT); |
| 11560 | mutImgInfo.flags = VK_IMAGE_CREATE_MUTABLE_FORMAT_BIT; |
| 11561 | mutImgInfo.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT; |
| 11562 | ret = vkCreateImage(m_device->handle(), &mutImgInfo, NULL, &mutImage); |
| 11563 | ASSERT_VK_SUCCESS(ret); |
| 11564 | imgViewInfo.image = mutImage; |
| 11565 | vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView); |
| 11566 | m_errorMonitor->VerifyFound(); |
| 11567 | imgViewInfo.image = image.handle(); |
| 11568 | vkDestroyImage(m_device->handle(), mutImage, NULL); |
| 11569 | } |
| 11570 | |
| 11571 | TEST_F(VkLayerTest, MiscImageLayerTests) { |
| 11572 | |
| 11573 | TEST_DESCRIPTION("Image layer tests that don't belong elsewhare"); |
| 11574 | |
| 11575 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 11576 | |
| 11577 | VkImageObj image(m_device); |
| 11578 | image.init(128, 128, VK_FORMAT_B8G8R8A8_UNORM, |
| 11579 | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | |
| 11580 | VK_IMAGE_USAGE_TRANSFER_DST_BIT, |
| 11581 | VK_IMAGE_TILING_OPTIMAL, 0); |
| 11582 | ASSERT_TRUE(image.initialized()); |
| 11583 | |
| 11584 | m_errorMonitor->SetDesiredFailureMsg( |
| 11585 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 11586 | "number of layers in image subresource is zero"); |
| 11587 | vk_testing::Buffer buffer; |
| 11588 | VkMemoryPropertyFlags reqs = 0; |
| 11589 | buffer.init_as_src(*m_device, 128 * 128 * 4, reqs); |
| 11590 | VkBufferImageCopy region = {}; |
| 11591 | region.bufferRowLength = 128; |
| 11592 | region.bufferImageHeight = 128; |
| 11593 | region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; |
| 11594 | // layerCount can't be 0 - Expect MISMATCHED_IMAGE_ASPECT |
| 11595 | region.imageSubresource.layerCount = 0; |
| 11596 | region.imageExtent.height = 4; |
| 11597 | region.imageExtent.width = 4; |
| 11598 | region.imageExtent.depth = 1; |
| 11599 | m_commandBuffer->BeginCommandBuffer(); |
| 11600 | vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), |
| 11601 | image.handle(), VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, |
| 11602 | 1, ®ion); |
| 11603 | m_errorMonitor->VerifyFound(); |
| 11604 | region.imageSubresource.layerCount = 1; |
| 11605 | |
| 11606 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 11607 | "aspectMasks for each region must " |
| 11608 | "specify only COLOR or DEPTH or " |
| 11609 | "STENCIL"); |
| 11610 | // Expect MISMATCHED_IMAGE_ASPECT |
| 11611 | region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_METADATA_BIT; |
| 11612 | vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), |
| 11613 | image.handle(), VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, |
| 11614 | 1, ®ion); |
| 11615 | m_errorMonitor->VerifyFound(); |
| 11616 | region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; |
| 11617 | |
| 11618 | m_errorMonitor->SetDesiredFailureMsg( |
| 11619 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 11620 | "If the format of srcImage is a depth, stencil, depth stencil or " |
| 11621 | "integer-based format then filter must be VK_FILTER_NEAREST"); |
| 11622 | // Expect INVALID_FILTER |
| 11623 | VkImageObj intImage1(m_device); |
| 11624 | intImage1.init(128, 128, VK_FORMAT_R8_UINT, |
| 11625 | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, |
| 11626 | 0); |
| 11627 | VkImageObj intImage2(m_device); |
| 11628 | intImage2.init(128, 128, VK_FORMAT_R8_UINT, |
| 11629 | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, |
| 11630 | 0); |
| 11631 | VkImageBlit blitRegion = {}; |
| 11632 | blitRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; |
| 11633 | blitRegion.srcSubresource.baseArrayLayer = 0; |
| 11634 | blitRegion.srcSubresource.layerCount = 1; |
| 11635 | blitRegion.srcSubresource.mipLevel = 0; |
| 11636 | blitRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; |
| 11637 | blitRegion.dstSubresource.baseArrayLayer = 0; |
| 11638 | blitRegion.dstSubresource.layerCount = 1; |
| 11639 | blitRegion.dstSubresource.mipLevel = 0; |
| 11640 | |
| 11641 | vkCmdBlitImage(m_commandBuffer->GetBufferHandle(), intImage1.handle(), |
| 11642 | intImage1.layout(), intImage2.handle(), intImage2.layout(), |
| 11643 | 16, &blitRegion, VK_FILTER_LINEAR); |
| 11644 | m_errorMonitor->VerifyFound(); |
| 11645 | |
| 11646 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 11647 | "called with 0 in ppMemoryBarriers"); |
| 11648 | VkImageMemoryBarrier img_barrier; |
| 11649 | img_barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER; |
| 11650 | img_barrier.pNext = NULL; |
| 11651 | img_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT; |
| 11652 | img_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT; |
| 11653 | img_barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL; |
| 11654 | img_barrier.newLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL; |
| 11655 | img_barrier.image = image.handle(); |
| 11656 | img_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED; |
| 11657 | img_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED; |
| 11658 | img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; |
| 11659 | img_barrier.subresourceRange.baseArrayLayer = 0; |
| 11660 | img_barrier.subresourceRange.baseMipLevel = 0; |
| 11661 | // layerCount should not be 0 - Expect INVALID_IMAGE_RESOURCE |
| 11662 | img_barrier.subresourceRange.layerCount = 0; |
| 11663 | img_barrier.subresourceRange.levelCount = 1; |
| 11664 | vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), |
| 11665 | VK_PIPELINE_STAGE_HOST_BIT, |
| 11666 | VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0, nullptr, 0, |
| 11667 | nullptr, 1, &img_barrier); |
| 11668 | m_errorMonitor->VerifyFound(); |
| 11669 | img_barrier.subresourceRange.layerCount = 1; |
| 11670 | } |
| 11671 | |
| 11672 | TEST_F(VkLayerTest, ImageFormatLimits) { |
| 11673 | |
| 11674 | TEST_DESCRIPTION("Exceed the limits of image format "); |
| 11675 | |
| 11676 | m_errorMonitor->SetDesiredFailureMsg( |
| 11677 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 11678 | "CreateImage extents exceed allowable limits for format"); |
| 11679 | VkImageCreateInfo image_create_info = {}; |
| 11680 | image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO; |
| 11681 | image_create_info.pNext = NULL; |
| 11682 | image_create_info.imageType = VK_IMAGE_TYPE_2D; |
| 11683 | image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM; |
| 11684 | image_create_info.extent.width = 32; |
| 11685 | image_create_info.extent.height = 32; |
| 11686 | image_create_info.extent.depth = 1; |
| 11687 | image_create_info.mipLevels = 1; |
| 11688 | image_create_info.arrayLayers = 1; |
| 11689 | image_create_info.samples = VK_SAMPLE_COUNT_1_BIT; |
| 11690 | image_create_info.tiling = VK_IMAGE_TILING_LINEAR; |
| 11691 | image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT; |
| 11692 | image_create_info.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED; |
| 11693 | image_create_info.flags = 0; |
| 11694 | |
| 11695 | VkImage nullImg; |
| 11696 | VkImageFormatProperties imgFmtProps; |
| 11697 | vkGetPhysicalDeviceImageFormatProperties( |
| 11698 | gpu(), image_create_info.format, image_create_info.imageType, |
| 11699 | image_create_info.tiling, image_create_info.usage, |
| 11700 | image_create_info.flags, &imgFmtProps); |
| 11701 | image_create_info.extent.depth = imgFmtProps.maxExtent.depth + 1; |
| 11702 | // Expect INVALID_FORMAT_LIMITS_VIOLATION |
| 11703 | vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg); |
| 11704 | m_errorMonitor->VerifyFound(); |
| 11705 | image_create_info.extent.depth = 1; |
| 11706 | |
| 11707 | m_errorMonitor->SetDesiredFailureMsg( |
| 11708 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 11709 | "exceeds allowable maximum supported by format of"); |
| 11710 | image_create_info.mipLevels = imgFmtProps.maxMipLevels + 1; |
| 11711 | // Expect INVALID_FORMAT_LIMITS_VIOLATION |
| 11712 | vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg); |
| 11713 | m_errorMonitor->VerifyFound(); |
| 11714 | image_create_info.mipLevels = 1; |
| 11715 | |
| 11716 | m_errorMonitor->SetDesiredFailureMsg( |
| 11717 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 11718 | "exceeds allowable maximum supported by format of"); |
| 11719 | image_create_info.arrayLayers = imgFmtProps.maxArrayLayers + 1; |
| 11720 | // Expect INVALID_FORMAT_LIMITS_VIOLATION |
| 11721 | vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg); |
| 11722 | m_errorMonitor->VerifyFound(); |
| 11723 | image_create_info.arrayLayers = 1; |
| 11724 | |
| 11725 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 11726 | "is not supported by format"); |
| 11727 | int samples = imgFmtProps.sampleCounts >> 1; |
| 11728 | image_create_info.samples = (VkSampleCountFlagBits)samples; |
| 11729 | // Expect INVALID_FORMAT_LIMITS_VIOLATION |
| 11730 | vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg); |
| 11731 | m_errorMonitor->VerifyFound(); |
| 11732 | image_create_info.samples = VK_SAMPLE_COUNT_1_BIT; |
| 11733 | |
| 11734 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 11735 | "pCreateInfo->initialLayout, must be " |
| 11736 | "VK_IMAGE_LAYOUT_UNDEFINED or " |
| 11737 | "VK_IMAGE_LAYOUT_PREINITIALIZED"); |
| 11738 | image_create_info.initialLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL; |
| 11739 | // Expect INVALID_LAYOUT |
| 11740 | vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg); |
| 11741 | m_errorMonitor->VerifyFound(); |
| 11742 | image_create_info.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED; |
| 11743 | } |
| 11744 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 11745 | TEST_F(VkLayerTest, CopyImageFormatSizeMismatch) { |
Karl Schultz | bdb7595 | 2016-04-19 11:36:49 -0600 | [diff] [blame] | 11746 | VkResult err; |
| 11747 | bool pass; |
| 11748 | |
| 11749 | // Create color images with different format sizes and try to copy between them |
| 11750 | m_errorMonitor->SetDesiredFailureMsg( |
| 11751 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 11752 | "vkCmdCopyImage called with unmatched source and dest image format sizes"); |
| 11753 | |
| 11754 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 11755 | |
| 11756 | // Create two images of different types and try to copy between them |
| 11757 | VkImage srcImage; |
| 11758 | VkImage dstImage; |
| 11759 | VkDeviceMemory srcMem; |
| 11760 | VkDeviceMemory destMem; |
| 11761 | VkMemoryRequirements memReqs; |
| 11762 | |
| 11763 | VkImageCreateInfo image_create_info = {}; |
| 11764 | image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO; |
| 11765 | image_create_info.pNext = NULL; |
| 11766 | image_create_info.imageType = VK_IMAGE_TYPE_2D; |
| 11767 | image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM; |
| 11768 | image_create_info.extent.width = 32; |
| 11769 | image_create_info.extent.height = 32; |
| 11770 | image_create_info.extent.depth = 1; |
| 11771 | image_create_info.mipLevels = 1; |
| 11772 | image_create_info.arrayLayers = 1; |
| 11773 | image_create_info.samples = VK_SAMPLE_COUNT_1_BIT; |
| 11774 | image_create_info.tiling = VK_IMAGE_TILING_LINEAR; |
| 11775 | image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT; |
| 11776 | image_create_info.flags = 0; |
| 11777 | |
| 11778 | err = |
| 11779 | vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage); |
| 11780 | ASSERT_VK_SUCCESS(err); |
| 11781 | |
| 11782 | image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT; |
| 11783 | // Introduce failure by creating second image with a different-sized format. |
| 11784 | image_create_info.format = VK_FORMAT_R5G5B5A1_UNORM_PACK16; |
| 11785 | |
| 11786 | err = |
| 11787 | vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage); |
| 11788 | ASSERT_VK_SUCCESS(err); |
| 11789 | |
| 11790 | // Allocate memory |
| 11791 | VkMemoryAllocateInfo memAlloc = {}; |
| 11792 | memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO; |
| 11793 | memAlloc.pNext = NULL; |
| 11794 | memAlloc.allocationSize = 0; |
| 11795 | memAlloc.memoryTypeIndex = 0; |
| 11796 | |
| 11797 | vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs); |
| 11798 | memAlloc.allocationSize = memReqs.size; |
| 11799 | pass = |
| 11800 | m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0); |
| 11801 | ASSERT_TRUE(pass); |
| 11802 | err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem); |
| 11803 | ASSERT_VK_SUCCESS(err); |
| 11804 | |
| 11805 | vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs); |
| 11806 | memAlloc.allocationSize = memReqs.size; |
| 11807 | pass = |
| 11808 | m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0); |
| 11809 | ASSERT_TRUE(pass); |
| 11810 | err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem); |
| 11811 | ASSERT_VK_SUCCESS(err); |
| 11812 | |
| 11813 | err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0); |
| 11814 | ASSERT_VK_SUCCESS(err); |
| 11815 | err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0); |
| 11816 | ASSERT_VK_SUCCESS(err); |
| 11817 | |
| 11818 | BeginCommandBuffer(); |
| 11819 | VkImageCopy copyRegion; |
| 11820 | copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; |
| 11821 | copyRegion.srcSubresource.mipLevel = 0; |
| 11822 | copyRegion.srcSubresource.baseArrayLayer = 0; |
| 11823 | copyRegion.srcSubresource.layerCount = 0; |
| 11824 | copyRegion.srcOffset.x = 0; |
| 11825 | copyRegion.srcOffset.y = 0; |
| 11826 | copyRegion.srcOffset.z = 0; |
| 11827 | copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; |
| 11828 | copyRegion.dstSubresource.mipLevel = 0; |
| 11829 | copyRegion.dstSubresource.baseArrayLayer = 0; |
| 11830 | copyRegion.dstSubresource.layerCount = 0; |
| 11831 | copyRegion.dstOffset.x = 0; |
| 11832 | copyRegion.dstOffset.y = 0; |
| 11833 | copyRegion.dstOffset.z = 0; |
| 11834 | copyRegion.extent.width = 1; |
| 11835 | copyRegion.extent.height = 1; |
| 11836 | copyRegion.extent.depth = 1; |
| 11837 | m_commandBuffer->CopyImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, |
| 11838 | VK_IMAGE_LAYOUT_GENERAL, 1, ©Region); |
| 11839 | EndCommandBuffer(); |
| 11840 | |
| 11841 | m_errorMonitor->VerifyFound(); |
| 11842 | |
| 11843 | vkDestroyImage(m_device->device(), srcImage, NULL); |
| 11844 | vkDestroyImage(m_device->device(), dstImage, NULL); |
| 11845 | vkFreeMemory(m_device->device(), srcMem, NULL); |
| 11846 | vkFreeMemory(m_device->device(), destMem, NULL); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 11847 | } |
| 11848 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 11849 | TEST_F(VkLayerTest, CopyImageDepthStencilFormatMismatch) { |
| 11850 | VkResult err; |
| 11851 | bool pass; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 11852 | |
Mark Lobodzinski | db11763 | 2016-03-31 10:45:56 -0600 | [diff] [blame] | 11853 | // 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] | 11854 | m_errorMonitor->SetDesiredFailureMsg( |
| 11855 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Mark Lobodzinski | db11763 | 2016-03-31 10:45:56 -0600 | [diff] [blame] | 11856 | "vkCmdCopyImage called with unmatched source and dest image depth"); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 11857 | |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 11858 | ASSERT_NO_FATAL_FAILURE(InitState()); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 11859 | |
| 11860 | // Create two images of different types and try to copy between them |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 11861 | VkImage srcImage; |
| 11862 | VkImage dstImage; |
| 11863 | VkDeviceMemory srcMem; |
| 11864 | VkDeviceMemory destMem; |
| 11865 | VkMemoryRequirements memReqs; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 11866 | |
| 11867 | VkImageCreateInfo image_create_info = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 11868 | image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO; |
| 11869 | image_create_info.pNext = NULL; |
| 11870 | image_create_info.imageType = VK_IMAGE_TYPE_2D; |
| 11871 | image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM; |
| 11872 | image_create_info.extent.width = 32; |
| 11873 | image_create_info.extent.height = 32; |
| 11874 | image_create_info.extent.depth = 1; |
| 11875 | image_create_info.mipLevels = 1; |
| 11876 | image_create_info.arrayLayers = 1; |
| 11877 | image_create_info.samples = VK_SAMPLE_COUNT_1_BIT; |
| 11878 | image_create_info.tiling = VK_IMAGE_TILING_LINEAR; |
| 11879 | image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT; |
| 11880 | image_create_info.flags = 0; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 11881 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 11882 | err = |
| 11883 | vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 11884 | ASSERT_VK_SUCCESS(err); |
| 11885 | |
Karl Schultz | bdb7595 | 2016-04-19 11:36:49 -0600 | [diff] [blame] | 11886 | image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT; |
| 11887 | |
Mark Lobodzinski | db11763 | 2016-03-31 10:45:56 -0600 | [diff] [blame] | 11888 | // Introduce failure by creating second image with a depth/stencil format |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 11889 | image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL; |
Mark Lobodzinski | db11763 | 2016-03-31 10:45:56 -0600 | [diff] [blame] | 11890 | image_create_info.format = VK_FORMAT_D24_UNORM_S8_UINT; |
| 11891 | image_create_info.usage = VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 11892 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 11893 | err = |
| 11894 | vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 11895 | ASSERT_VK_SUCCESS(err); |
| 11896 | |
| 11897 | // Allocate memory |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 11898 | VkMemoryAllocateInfo memAlloc = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 11899 | memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO; |
| 11900 | memAlloc.pNext = NULL; |
| 11901 | memAlloc.allocationSize = 0; |
| 11902 | memAlloc.memoryTypeIndex = 0; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 11903 | |
Courtney Goeltzenleuchter | 06d8947 | 2015-10-20 16:40:38 -0600 | [diff] [blame] | 11904 | vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 11905 | memAlloc.allocationSize = memReqs.size; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 11906 | pass = |
| 11907 | m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0); |
Courtney Goeltzenleuchter | 1d2f0dd | 2015-10-22 11:03:31 -0600 | [diff] [blame] | 11908 | ASSERT_TRUE(pass); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 11909 | err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 11910 | ASSERT_VK_SUCCESS(err); |
| 11911 | |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 11912 | vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 11913 | memAlloc.allocationSize = memReqs.size; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 11914 | pass = |
| 11915 | m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0); |
Courtney Goeltzenleuchter | 1d2f0dd | 2015-10-22 11:03:31 -0600 | [diff] [blame] | 11916 | ASSERT_TRUE(pass); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 11917 | err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 11918 | ASSERT_VK_SUCCESS(err); |
| 11919 | |
| 11920 | err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0); |
| 11921 | ASSERT_VK_SUCCESS(err); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 11922 | err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 11923 | ASSERT_VK_SUCCESS(err); |
| 11924 | |
| 11925 | BeginCommandBuffer(); |
| 11926 | VkImageCopy copyRegion; |
Chia-I Wu | ab83a0e | 2015-10-27 19:00:15 +0800 | [diff] [blame] | 11927 | copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 11928 | copyRegion.srcSubresource.mipLevel = 0; |
Courtney Goeltzenleuchter | 8367ce0 | 2015-10-16 09:46:00 -0600 | [diff] [blame] | 11929 | copyRegion.srcSubresource.baseArrayLayer = 0; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 11930 | copyRegion.srcSubresource.layerCount = 0; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 11931 | copyRegion.srcOffset.x = 0; |
| 11932 | copyRegion.srcOffset.y = 0; |
| 11933 | copyRegion.srcOffset.z = 0; |
Chia-I Wu | ab83a0e | 2015-10-27 19:00:15 +0800 | [diff] [blame] | 11934 | copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 11935 | copyRegion.dstSubresource.mipLevel = 0; |
| 11936 | copyRegion.dstSubresource.baseArrayLayer = 0; |
| 11937 | copyRegion.dstSubresource.layerCount = 0; |
| 11938 | copyRegion.dstOffset.x = 0; |
| 11939 | copyRegion.dstOffset.y = 0; |
| 11940 | copyRegion.dstOffset.z = 0; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 11941 | copyRegion.extent.width = 1; |
| 11942 | copyRegion.extent.height = 1; |
| 11943 | copyRegion.extent.depth = 1; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 11944 | m_commandBuffer->CopyImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, |
| 11945 | VK_IMAGE_LAYOUT_GENERAL, 1, ©Region); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 11946 | EndCommandBuffer(); |
| 11947 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 11948 | m_errorMonitor->VerifyFound(); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 11949 | |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 11950 | vkDestroyImage(m_device->device(), srcImage, NULL); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 11951 | vkDestroyImage(m_device->device(), dstImage, NULL); |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 11952 | vkFreeMemory(m_device->device(), srcMem, NULL); |
| 11953 | vkFreeMemory(m_device->device(), destMem, NULL); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 11954 | } |
| 11955 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 11956 | TEST_F(VkLayerTest, ResolveImageLowSampleCount) { |
| 11957 | VkResult err; |
| 11958 | bool pass; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 11959 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 11960 | m_errorMonitor->SetDesiredFailureMsg( |
| 11961 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 11962 | "vkCmdResolveImage called with source sample count less than 2."); |
| 11963 | |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 11964 | ASSERT_NO_FATAL_FAILURE(InitState()); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 11965 | |
| 11966 | // 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] | 11967 | VkImage srcImage; |
| 11968 | VkImage dstImage; |
| 11969 | VkDeviceMemory srcMem; |
| 11970 | VkDeviceMemory destMem; |
| 11971 | VkMemoryRequirements memReqs; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 11972 | |
| 11973 | VkImageCreateInfo image_create_info = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 11974 | image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO; |
| 11975 | image_create_info.pNext = NULL; |
| 11976 | image_create_info.imageType = VK_IMAGE_TYPE_2D; |
| 11977 | image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM; |
| 11978 | image_create_info.extent.width = 32; |
| 11979 | image_create_info.extent.height = 1; |
| 11980 | image_create_info.extent.depth = 1; |
| 11981 | image_create_info.mipLevels = 1; |
| 11982 | image_create_info.arrayLayers = 1; |
| 11983 | image_create_info.samples = VK_SAMPLE_COUNT_1_BIT; |
| 11984 | image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL; |
| 11985 | image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT; |
| 11986 | image_create_info.flags = 0; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 11987 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 11988 | err = |
| 11989 | vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 11990 | ASSERT_VK_SUCCESS(err); |
| 11991 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 11992 | image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 11993 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 11994 | err = |
| 11995 | vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 11996 | ASSERT_VK_SUCCESS(err); |
| 11997 | |
| 11998 | // Allocate memory |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 11999 | VkMemoryAllocateInfo memAlloc = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12000 | memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO; |
| 12001 | memAlloc.pNext = NULL; |
| 12002 | memAlloc.allocationSize = 0; |
| 12003 | memAlloc.memoryTypeIndex = 0; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12004 | |
Courtney Goeltzenleuchter | 06d8947 | 2015-10-20 16:40:38 -0600 | [diff] [blame] | 12005 | vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12006 | memAlloc.allocationSize = memReqs.size; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12007 | pass = |
| 12008 | m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0); |
Courtney Goeltzenleuchter | 1d2f0dd | 2015-10-22 11:03:31 -0600 | [diff] [blame] | 12009 | ASSERT_TRUE(pass); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 12010 | err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12011 | ASSERT_VK_SUCCESS(err); |
| 12012 | |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 12013 | vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12014 | memAlloc.allocationSize = memReqs.size; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12015 | pass = |
| 12016 | m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0); |
Courtney Goeltzenleuchter | 1d2f0dd | 2015-10-22 11:03:31 -0600 | [diff] [blame] | 12017 | ASSERT_TRUE(pass); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 12018 | err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12019 | ASSERT_VK_SUCCESS(err); |
| 12020 | |
| 12021 | err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0); |
| 12022 | ASSERT_VK_SUCCESS(err); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 12023 | err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12024 | ASSERT_VK_SUCCESS(err); |
| 12025 | |
| 12026 | BeginCommandBuffer(); |
| 12027 | // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest? |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12028 | // VK_IMAGE_LAYOUT_UNDEFINED = 0, |
| 12029 | // VK_IMAGE_LAYOUT_GENERAL = 1, |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12030 | VkImageResolve resolveRegion; |
Chia-I Wu | ab83a0e | 2015-10-27 19:00:15 +0800 | [diff] [blame] | 12031 | resolveRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12032 | resolveRegion.srcSubresource.mipLevel = 0; |
Courtney Goeltzenleuchter | 8367ce0 | 2015-10-16 09:46:00 -0600 | [diff] [blame] | 12033 | resolveRegion.srcSubresource.baseArrayLayer = 0; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 12034 | resolveRegion.srcSubresource.layerCount = 0; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12035 | resolveRegion.srcOffset.x = 0; |
| 12036 | resolveRegion.srcOffset.y = 0; |
| 12037 | resolveRegion.srcOffset.z = 0; |
Chia-I Wu | ab83a0e | 2015-10-27 19:00:15 +0800 | [diff] [blame] | 12038 | resolveRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 12039 | resolveRegion.dstSubresource.mipLevel = 0; |
| 12040 | resolveRegion.dstSubresource.baseArrayLayer = 0; |
| 12041 | resolveRegion.dstSubresource.layerCount = 0; |
| 12042 | resolveRegion.dstOffset.x = 0; |
| 12043 | resolveRegion.dstOffset.y = 0; |
| 12044 | resolveRegion.dstOffset.z = 0; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12045 | resolveRegion.extent.width = 1; |
| 12046 | resolveRegion.extent.height = 1; |
| 12047 | resolveRegion.extent.depth = 1; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12048 | m_commandBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, |
| 12049 | VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12050 | EndCommandBuffer(); |
| 12051 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 12052 | m_errorMonitor->VerifyFound(); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12053 | |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 12054 | vkDestroyImage(m_device->device(), srcImage, NULL); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 12055 | vkDestroyImage(m_device->device(), dstImage, NULL); |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 12056 | vkFreeMemory(m_device->device(), srcMem, NULL); |
| 12057 | vkFreeMemory(m_device->device(), destMem, NULL); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12058 | } |
| 12059 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12060 | TEST_F(VkLayerTest, ResolveImageHighSampleCount) { |
| 12061 | VkResult err; |
| 12062 | bool pass; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12063 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12064 | m_errorMonitor->SetDesiredFailureMsg( |
| 12065 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 12066 | "vkCmdResolveImage called with dest sample count greater than 1."); |
| 12067 | |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12068 | ASSERT_NO_FATAL_FAILURE(InitState()); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12069 | |
Chris Forbes | a753069 | 2016-05-08 12:35:39 +1200 | [diff] [blame] | 12070 | // 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] | 12071 | VkImage srcImage; |
| 12072 | VkImage dstImage; |
| 12073 | VkDeviceMemory srcMem; |
| 12074 | VkDeviceMemory destMem; |
| 12075 | VkMemoryRequirements memReqs; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12076 | |
| 12077 | VkImageCreateInfo image_create_info = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12078 | image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO; |
| 12079 | image_create_info.pNext = NULL; |
| 12080 | image_create_info.imageType = VK_IMAGE_TYPE_2D; |
| 12081 | image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM; |
| 12082 | image_create_info.extent.width = 32; |
| 12083 | image_create_info.extent.height = 1; |
| 12084 | image_create_info.extent.depth = 1; |
| 12085 | image_create_info.mipLevels = 1; |
| 12086 | image_create_info.arrayLayers = 1; |
Chris Forbes | a753069 | 2016-05-08 12:35:39 +1200 | [diff] [blame] | 12087 | image_create_info.samples = VK_SAMPLE_COUNT_4_BIT; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12088 | image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL; |
| 12089 | // Note: Some implementations expect color attachment usage for any |
| 12090 | // multisample surface |
| 12091 | image_create_info.usage = |
| 12092 | VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT; |
| 12093 | image_create_info.flags = 0; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12094 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12095 | err = |
| 12096 | vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12097 | ASSERT_VK_SUCCESS(err); |
| 12098 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12099 | // Note: Some implementations expect color attachment usage for any |
| 12100 | // multisample surface |
| 12101 | image_create_info.usage = |
| 12102 | VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12103 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12104 | err = |
| 12105 | vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12106 | ASSERT_VK_SUCCESS(err); |
| 12107 | |
| 12108 | // Allocate memory |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 12109 | VkMemoryAllocateInfo memAlloc = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12110 | memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO; |
| 12111 | memAlloc.pNext = NULL; |
| 12112 | memAlloc.allocationSize = 0; |
| 12113 | memAlloc.memoryTypeIndex = 0; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12114 | |
Courtney Goeltzenleuchter | 06d8947 | 2015-10-20 16:40:38 -0600 | [diff] [blame] | 12115 | vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12116 | memAlloc.allocationSize = memReqs.size; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12117 | pass = |
| 12118 | m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0); |
Courtney Goeltzenleuchter | 1d2f0dd | 2015-10-22 11:03:31 -0600 | [diff] [blame] | 12119 | ASSERT_TRUE(pass); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 12120 | err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12121 | ASSERT_VK_SUCCESS(err); |
| 12122 | |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 12123 | vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12124 | memAlloc.allocationSize = memReqs.size; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12125 | pass = |
| 12126 | m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0); |
Courtney Goeltzenleuchter | 1d2f0dd | 2015-10-22 11:03:31 -0600 | [diff] [blame] | 12127 | ASSERT_TRUE(pass); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 12128 | err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12129 | ASSERT_VK_SUCCESS(err); |
| 12130 | |
| 12131 | err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0); |
| 12132 | ASSERT_VK_SUCCESS(err); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 12133 | err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12134 | ASSERT_VK_SUCCESS(err); |
| 12135 | |
| 12136 | BeginCommandBuffer(); |
| 12137 | // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest? |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12138 | // VK_IMAGE_LAYOUT_UNDEFINED = 0, |
| 12139 | // VK_IMAGE_LAYOUT_GENERAL = 1, |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12140 | VkImageResolve resolveRegion; |
Chia-I Wu | ab83a0e | 2015-10-27 19:00:15 +0800 | [diff] [blame] | 12141 | resolveRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12142 | resolveRegion.srcSubresource.mipLevel = 0; |
Courtney Goeltzenleuchter | 8367ce0 | 2015-10-16 09:46:00 -0600 | [diff] [blame] | 12143 | resolveRegion.srcSubresource.baseArrayLayer = 0; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 12144 | resolveRegion.srcSubresource.layerCount = 0; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12145 | resolveRegion.srcOffset.x = 0; |
| 12146 | resolveRegion.srcOffset.y = 0; |
| 12147 | resolveRegion.srcOffset.z = 0; |
Chia-I Wu | ab83a0e | 2015-10-27 19:00:15 +0800 | [diff] [blame] | 12148 | resolveRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 12149 | resolveRegion.dstSubresource.mipLevel = 0; |
| 12150 | resolveRegion.dstSubresource.baseArrayLayer = 0; |
| 12151 | resolveRegion.dstSubresource.layerCount = 0; |
| 12152 | resolveRegion.dstOffset.x = 0; |
| 12153 | resolveRegion.dstOffset.y = 0; |
| 12154 | resolveRegion.dstOffset.z = 0; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12155 | resolveRegion.extent.width = 1; |
| 12156 | resolveRegion.extent.height = 1; |
| 12157 | resolveRegion.extent.depth = 1; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12158 | m_commandBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, |
| 12159 | VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12160 | EndCommandBuffer(); |
| 12161 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 12162 | m_errorMonitor->VerifyFound(); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12163 | |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 12164 | vkDestroyImage(m_device->device(), srcImage, NULL); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 12165 | vkDestroyImage(m_device->device(), dstImage, NULL); |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 12166 | vkFreeMemory(m_device->device(), srcMem, NULL); |
| 12167 | vkFreeMemory(m_device->device(), destMem, NULL); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12168 | } |
| 12169 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12170 | TEST_F(VkLayerTest, ResolveImageFormatMismatch) { |
| 12171 | VkResult err; |
| 12172 | bool pass; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12173 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12174 | m_errorMonitor->SetDesiredFailureMsg( |
| 12175 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 12176 | "vkCmdResolveImage called with unmatched source and dest formats."); |
| 12177 | |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12178 | ASSERT_NO_FATAL_FAILURE(InitState()); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12179 | |
| 12180 | // Create two images of different types and try to copy between them |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12181 | VkImage srcImage; |
| 12182 | VkImage dstImage; |
| 12183 | VkDeviceMemory srcMem; |
| 12184 | VkDeviceMemory destMem; |
| 12185 | VkMemoryRequirements memReqs; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12186 | |
| 12187 | VkImageCreateInfo image_create_info = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12188 | image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO; |
| 12189 | image_create_info.pNext = NULL; |
| 12190 | image_create_info.imageType = VK_IMAGE_TYPE_2D; |
| 12191 | image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM; |
| 12192 | image_create_info.extent.width = 32; |
| 12193 | image_create_info.extent.height = 1; |
| 12194 | image_create_info.extent.depth = 1; |
| 12195 | image_create_info.mipLevels = 1; |
| 12196 | image_create_info.arrayLayers = 1; |
| 12197 | image_create_info.samples = VK_SAMPLE_COUNT_2_BIT; |
| 12198 | image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL; |
| 12199 | // Note: Some implementations expect color attachment usage for any |
| 12200 | // multisample surface |
| 12201 | image_create_info.usage = |
| 12202 | VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT; |
| 12203 | image_create_info.flags = 0; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12204 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12205 | err = |
| 12206 | vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12207 | ASSERT_VK_SUCCESS(err); |
| 12208 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12209 | // Set format to something other than source image |
| 12210 | image_create_info.format = VK_FORMAT_R32_SFLOAT; |
| 12211 | // Note: Some implementations expect color attachment usage for any |
| 12212 | // multisample surface |
| 12213 | image_create_info.usage = |
| 12214 | VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT; |
| 12215 | image_create_info.samples = VK_SAMPLE_COUNT_1_BIT; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12216 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12217 | err = |
| 12218 | vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12219 | ASSERT_VK_SUCCESS(err); |
| 12220 | |
| 12221 | // Allocate memory |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 12222 | VkMemoryAllocateInfo memAlloc = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12223 | memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO; |
| 12224 | memAlloc.pNext = NULL; |
| 12225 | memAlloc.allocationSize = 0; |
| 12226 | memAlloc.memoryTypeIndex = 0; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12227 | |
Courtney Goeltzenleuchter | 06d8947 | 2015-10-20 16:40:38 -0600 | [diff] [blame] | 12228 | vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12229 | memAlloc.allocationSize = memReqs.size; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12230 | pass = |
| 12231 | m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0); |
Courtney Goeltzenleuchter | 1d2f0dd | 2015-10-22 11:03:31 -0600 | [diff] [blame] | 12232 | ASSERT_TRUE(pass); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 12233 | err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12234 | ASSERT_VK_SUCCESS(err); |
| 12235 | |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 12236 | vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12237 | memAlloc.allocationSize = memReqs.size; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12238 | pass = |
| 12239 | m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0); |
Courtney Goeltzenleuchter | 1d2f0dd | 2015-10-22 11:03:31 -0600 | [diff] [blame] | 12240 | ASSERT_TRUE(pass); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 12241 | err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12242 | ASSERT_VK_SUCCESS(err); |
| 12243 | |
| 12244 | err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0); |
| 12245 | ASSERT_VK_SUCCESS(err); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 12246 | err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12247 | ASSERT_VK_SUCCESS(err); |
| 12248 | |
| 12249 | BeginCommandBuffer(); |
| 12250 | // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest? |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12251 | // VK_IMAGE_LAYOUT_UNDEFINED = 0, |
| 12252 | // VK_IMAGE_LAYOUT_GENERAL = 1, |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12253 | VkImageResolve resolveRegion; |
Chia-I Wu | ab83a0e | 2015-10-27 19:00:15 +0800 | [diff] [blame] | 12254 | resolveRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12255 | resolveRegion.srcSubresource.mipLevel = 0; |
Courtney Goeltzenleuchter | 8367ce0 | 2015-10-16 09:46:00 -0600 | [diff] [blame] | 12256 | resolveRegion.srcSubresource.baseArrayLayer = 0; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 12257 | resolveRegion.srcSubresource.layerCount = 0; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12258 | resolveRegion.srcOffset.x = 0; |
| 12259 | resolveRegion.srcOffset.y = 0; |
| 12260 | resolveRegion.srcOffset.z = 0; |
Chia-I Wu | ab83a0e | 2015-10-27 19:00:15 +0800 | [diff] [blame] | 12261 | resolveRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 12262 | resolveRegion.dstSubresource.mipLevel = 0; |
| 12263 | resolveRegion.dstSubresource.baseArrayLayer = 0; |
| 12264 | resolveRegion.dstSubresource.layerCount = 0; |
| 12265 | resolveRegion.dstOffset.x = 0; |
| 12266 | resolveRegion.dstOffset.y = 0; |
| 12267 | resolveRegion.dstOffset.z = 0; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12268 | resolveRegion.extent.width = 1; |
| 12269 | resolveRegion.extent.height = 1; |
| 12270 | resolveRegion.extent.depth = 1; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12271 | m_commandBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, |
| 12272 | VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12273 | EndCommandBuffer(); |
| 12274 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 12275 | m_errorMonitor->VerifyFound(); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12276 | |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 12277 | vkDestroyImage(m_device->device(), srcImage, NULL); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 12278 | vkDestroyImage(m_device->device(), dstImage, NULL); |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 12279 | vkFreeMemory(m_device->device(), srcMem, NULL); |
| 12280 | vkFreeMemory(m_device->device(), destMem, NULL); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12281 | } |
| 12282 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12283 | TEST_F(VkLayerTest, ResolveImageTypeMismatch) { |
| 12284 | VkResult err; |
| 12285 | bool pass; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12286 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12287 | m_errorMonitor->SetDesiredFailureMsg( |
| 12288 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 12289 | "vkCmdResolveImage called with unmatched source and dest image types."); |
| 12290 | |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12291 | ASSERT_NO_FATAL_FAILURE(InitState()); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12292 | |
| 12293 | // Create two images of different types and try to copy between them |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12294 | VkImage srcImage; |
| 12295 | VkImage dstImage; |
| 12296 | VkDeviceMemory srcMem; |
| 12297 | VkDeviceMemory destMem; |
| 12298 | VkMemoryRequirements memReqs; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12299 | |
| 12300 | VkImageCreateInfo image_create_info = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12301 | image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO; |
| 12302 | image_create_info.pNext = NULL; |
| 12303 | image_create_info.imageType = VK_IMAGE_TYPE_2D; |
| 12304 | image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM; |
| 12305 | image_create_info.extent.width = 32; |
| 12306 | image_create_info.extent.height = 1; |
| 12307 | image_create_info.extent.depth = 1; |
| 12308 | image_create_info.mipLevels = 1; |
| 12309 | image_create_info.arrayLayers = 1; |
| 12310 | image_create_info.samples = VK_SAMPLE_COUNT_2_BIT; |
| 12311 | image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL; |
| 12312 | // Note: Some implementations expect color attachment usage for any |
| 12313 | // multisample surface |
| 12314 | image_create_info.usage = |
| 12315 | VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT; |
| 12316 | image_create_info.flags = 0; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12317 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12318 | err = |
| 12319 | vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12320 | ASSERT_VK_SUCCESS(err); |
| 12321 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12322 | image_create_info.imageType = VK_IMAGE_TYPE_1D; |
| 12323 | // Note: Some implementations expect color attachment usage for any |
| 12324 | // multisample surface |
| 12325 | image_create_info.usage = |
| 12326 | VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT; |
| 12327 | image_create_info.samples = VK_SAMPLE_COUNT_1_BIT; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12328 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12329 | err = |
| 12330 | vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12331 | ASSERT_VK_SUCCESS(err); |
| 12332 | |
| 12333 | // Allocate memory |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 12334 | VkMemoryAllocateInfo memAlloc = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12335 | memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO; |
| 12336 | memAlloc.pNext = NULL; |
| 12337 | memAlloc.allocationSize = 0; |
| 12338 | memAlloc.memoryTypeIndex = 0; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12339 | |
Courtney Goeltzenleuchter | 06d8947 | 2015-10-20 16:40:38 -0600 | [diff] [blame] | 12340 | vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12341 | memAlloc.allocationSize = memReqs.size; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12342 | pass = |
| 12343 | m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0); |
Courtney Goeltzenleuchter | 1d2f0dd | 2015-10-22 11:03:31 -0600 | [diff] [blame] | 12344 | ASSERT_TRUE(pass); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 12345 | err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12346 | ASSERT_VK_SUCCESS(err); |
| 12347 | |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 12348 | vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12349 | memAlloc.allocationSize = memReqs.size; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12350 | pass = |
| 12351 | m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0); |
Courtney Goeltzenleuchter | 1d2f0dd | 2015-10-22 11:03:31 -0600 | [diff] [blame] | 12352 | ASSERT_TRUE(pass); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 12353 | err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12354 | ASSERT_VK_SUCCESS(err); |
| 12355 | |
| 12356 | err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0); |
| 12357 | ASSERT_VK_SUCCESS(err); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 12358 | err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12359 | ASSERT_VK_SUCCESS(err); |
| 12360 | |
| 12361 | BeginCommandBuffer(); |
| 12362 | // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest? |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12363 | // VK_IMAGE_LAYOUT_UNDEFINED = 0, |
| 12364 | // VK_IMAGE_LAYOUT_GENERAL = 1, |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12365 | VkImageResolve resolveRegion; |
Chia-I Wu | ab83a0e | 2015-10-27 19:00:15 +0800 | [diff] [blame] | 12366 | resolveRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12367 | resolveRegion.srcSubresource.mipLevel = 0; |
Courtney Goeltzenleuchter | 8367ce0 | 2015-10-16 09:46:00 -0600 | [diff] [blame] | 12368 | resolveRegion.srcSubresource.baseArrayLayer = 0; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 12369 | resolveRegion.srcSubresource.layerCount = 0; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12370 | resolveRegion.srcOffset.x = 0; |
| 12371 | resolveRegion.srcOffset.y = 0; |
| 12372 | resolveRegion.srcOffset.z = 0; |
Chia-I Wu | ab83a0e | 2015-10-27 19:00:15 +0800 | [diff] [blame] | 12373 | resolveRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 12374 | resolveRegion.dstSubresource.mipLevel = 0; |
| 12375 | resolveRegion.dstSubresource.baseArrayLayer = 0; |
| 12376 | resolveRegion.dstSubresource.layerCount = 0; |
| 12377 | resolveRegion.dstOffset.x = 0; |
| 12378 | resolveRegion.dstOffset.y = 0; |
| 12379 | resolveRegion.dstOffset.z = 0; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12380 | resolveRegion.extent.width = 1; |
| 12381 | resolveRegion.extent.height = 1; |
| 12382 | resolveRegion.extent.depth = 1; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12383 | m_commandBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, |
| 12384 | VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12385 | EndCommandBuffer(); |
| 12386 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 12387 | m_errorMonitor->VerifyFound(); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12388 | |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 12389 | vkDestroyImage(m_device->device(), srcImage, NULL); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 12390 | vkDestroyImage(m_device->device(), dstImage, NULL); |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 12391 | vkFreeMemory(m_device->device(), srcMem, NULL); |
| 12392 | vkFreeMemory(m_device->device(), destMem, NULL); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12393 | } |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 12394 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12395 | TEST_F(VkLayerTest, DepthStencilImageViewWithColorAspectBitError) { |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 12396 | // 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] | 12397 | // to using a DS format, then cause it to hit error due to COLOR_BIT not |
| 12398 | // set in aspect |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 12399 | // The image format check comes 2nd in validation so we trigger it first, |
| 12400 | // 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] | 12401 | VkResult err; |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 12402 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12403 | m_errorMonitor->SetDesiredFailureMsg( |
| 12404 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 12405 | "Combination depth/stencil image formats can have only the "); |
| 12406 | |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 12407 | ASSERT_NO_FATAL_FAILURE(InitState()); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 12408 | |
Chia-I Wu | 1b99bb2 | 2015-10-27 19:25:11 +0800 | [diff] [blame] | 12409 | VkDescriptorPoolSize ds_type_count = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12410 | ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE; |
| 12411 | ds_type_count.descriptorCount = 1; |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 12412 | |
| 12413 | VkDescriptorPoolCreateInfo ds_pool_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12414 | ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO; |
| 12415 | ds_pool_ci.pNext = NULL; |
| 12416 | ds_pool_ci.maxSets = 1; |
| 12417 | ds_pool_ci.poolSizeCount = 1; |
| 12418 | ds_pool_ci.pPoolSizes = &ds_type_count; |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 12419 | |
| 12420 | VkDescriptorPool ds_pool; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12421 | err = |
| 12422 | vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool); |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 12423 | ASSERT_VK_SUCCESS(err); |
| 12424 | |
| 12425 | VkDescriptorSetLayoutBinding dsl_binding = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12426 | dsl_binding.binding = 0; |
| 12427 | dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE; |
| 12428 | dsl_binding.descriptorCount = 1; |
| 12429 | dsl_binding.stageFlags = VK_SHADER_STAGE_ALL; |
| 12430 | dsl_binding.pImmutableSamplers = NULL; |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 12431 | |
| 12432 | VkDescriptorSetLayoutCreateInfo ds_layout_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12433 | ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO; |
| 12434 | ds_layout_ci.pNext = NULL; |
| 12435 | ds_layout_ci.bindingCount = 1; |
| 12436 | ds_layout_ci.pBindings = &dsl_binding; |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 12437 | VkDescriptorSetLayout ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12438 | err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, |
| 12439 | &ds_layout); |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 12440 | ASSERT_VK_SUCCESS(err); |
| 12441 | |
| 12442 | VkDescriptorSet descriptorSet; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 12443 | VkDescriptorSetAllocateInfo alloc_info = {}; |
Chia-I Wu | 00ce540 | 2015-11-10 16:21:09 +0800 | [diff] [blame] | 12444 | alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO; |
Jon Ashburn | f19916e | 2016-01-11 13:12:43 -0700 | [diff] [blame] | 12445 | alloc_info.descriptorSetCount = 1; |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 12446 | alloc_info.descriptorPool = ds_pool; |
| 12447 | alloc_info.pSetLayouts = &ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12448 | err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, |
| 12449 | &descriptorSet); |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 12450 | ASSERT_VK_SUCCESS(err); |
| 12451 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12452 | VkImage image_bad; |
| 12453 | VkImage image_good; |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 12454 | // One bad format and one good format for Color attachment |
Tobin Ehlis | 269f032 | 2016-05-25 16:24:21 -0600 | [diff] [blame] | 12455 | const VkFormat tex_format_bad = VK_FORMAT_D24_UNORM_S8_UINT; |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 12456 | const VkFormat tex_format_good = VK_FORMAT_B8G8R8A8_UNORM; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12457 | const int32_t tex_width = 32; |
| 12458 | const int32_t tex_height = 32; |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 12459 | |
| 12460 | VkImageCreateInfo image_create_info = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12461 | image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO; |
| 12462 | image_create_info.pNext = NULL; |
| 12463 | image_create_info.imageType = VK_IMAGE_TYPE_2D; |
| 12464 | image_create_info.format = tex_format_bad; |
| 12465 | image_create_info.extent.width = tex_width; |
| 12466 | image_create_info.extent.height = tex_height; |
| 12467 | image_create_info.extent.depth = 1; |
| 12468 | image_create_info.mipLevels = 1; |
| 12469 | image_create_info.arrayLayers = 1; |
| 12470 | image_create_info.samples = VK_SAMPLE_COUNT_1_BIT; |
| 12471 | image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL; |
| 12472 | image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT | |
| 12473 | VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT; |
| 12474 | image_create_info.flags = 0; |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 12475 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12476 | err = |
| 12477 | vkCreateImage(m_device->device(), &image_create_info, NULL, &image_bad); |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 12478 | ASSERT_VK_SUCCESS(err); |
| 12479 | image_create_info.format = tex_format_good; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12480 | image_create_info.usage = |
| 12481 | VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT; |
| 12482 | err = vkCreateImage(m_device->device(), &image_create_info, NULL, |
| 12483 | &image_good); |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 12484 | ASSERT_VK_SUCCESS(err); |
| 12485 | |
| 12486 | VkImageViewCreateInfo image_view_create_info = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12487 | image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO; |
| 12488 | image_view_create_info.image = image_bad; |
| 12489 | image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D; |
| 12490 | image_view_create_info.format = tex_format_bad; |
| 12491 | image_view_create_info.subresourceRange.baseArrayLayer = 0; |
| 12492 | image_view_create_info.subresourceRange.baseMipLevel = 0; |
| 12493 | image_view_create_info.subresourceRange.layerCount = 1; |
| 12494 | image_view_create_info.subresourceRange.levelCount = 1; |
| 12495 | image_view_create_info.subresourceRange.aspectMask = |
| 12496 | VK_IMAGE_ASPECT_COLOR_BIT; |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 12497 | |
| 12498 | VkImageView view; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12499 | err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, |
| 12500 | &view); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 12501 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 12502 | m_errorMonitor->VerifyFound(); |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 12503 | |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 12504 | vkDestroyImage(m_device->device(), image_bad, NULL); |
| 12505 | vkDestroyImage(m_device->device(), image_good, NULL); |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 12506 | vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL); |
| 12507 | vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL); |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 12508 | } |
Tobin Ehlis | 6e23d77 | 2016-05-19 11:08:34 -0600 | [diff] [blame] | 12509 | |
| 12510 | TEST_F(VkLayerTest, ClearImageErrors) { |
| 12511 | TEST_DESCRIPTION("Call ClearColorImage w/ a depth|stencil image and " |
| 12512 | "ClearDepthStencilImage with a color image."); |
| 12513 | |
| 12514 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 12515 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 12516 | |
| 12517 | // Renderpass is started here so end it as Clear cmds can't be in renderpass |
| 12518 | BeginCommandBuffer(); |
| 12519 | m_commandBuffer->EndRenderPass(); |
| 12520 | |
| 12521 | // Color image |
| 12522 | VkClearColorValue clear_color; |
| 12523 | memset(clear_color.uint32, 0, sizeof(uint32_t) * 4); |
| 12524 | VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT; |
| 12525 | const VkFormat color_format = VK_FORMAT_B8G8R8A8_UNORM; |
| 12526 | const int32_t img_width = 32; |
| 12527 | const int32_t img_height = 32; |
| 12528 | VkImageCreateInfo image_create_info = {}; |
| 12529 | image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO; |
| 12530 | image_create_info.pNext = NULL; |
| 12531 | image_create_info.imageType = VK_IMAGE_TYPE_2D; |
| 12532 | image_create_info.format = color_format; |
| 12533 | image_create_info.extent.width = img_width; |
| 12534 | image_create_info.extent.height = img_height; |
| 12535 | image_create_info.extent.depth = 1; |
| 12536 | image_create_info.mipLevels = 1; |
| 12537 | image_create_info.arrayLayers = 1; |
| 12538 | image_create_info.samples = VK_SAMPLE_COUNT_1_BIT; |
| 12539 | image_create_info.tiling = VK_IMAGE_TILING_LINEAR; |
| 12540 | image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT; |
| 12541 | |
| 12542 | vk_testing::Image color_image; |
| 12543 | color_image.init(*m_device, (const VkImageCreateInfo &)image_create_info, |
| 12544 | reqs); |
| 12545 | |
| 12546 | const VkImageSubresourceRange color_range = |
| 12547 | vk_testing::Image::subresource_range(image_create_info, |
| 12548 | VK_IMAGE_ASPECT_COLOR_BIT); |
| 12549 | |
| 12550 | // Depth/Stencil image |
| 12551 | VkClearDepthStencilValue clear_value = {0}; |
| 12552 | reqs = 0; // don't need HOST_VISIBLE DS image |
| 12553 | VkImageCreateInfo ds_image_create_info = vk_testing::Image::create_info(); |
| 12554 | ds_image_create_info.imageType = VK_IMAGE_TYPE_2D; |
| 12555 | ds_image_create_info.format = VK_FORMAT_D24_UNORM_S8_UINT; |
| 12556 | ds_image_create_info.extent.width = 64; |
| 12557 | ds_image_create_info.extent.height = 64; |
| 12558 | ds_image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL; |
| 12559 | ds_image_create_info.usage = VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT; |
| 12560 | |
| 12561 | vk_testing::Image ds_image; |
| 12562 | ds_image.init(*m_device, (const VkImageCreateInfo &)ds_image_create_info, |
| 12563 | reqs); |
| 12564 | |
| 12565 | const VkImageSubresourceRange ds_range = |
| 12566 | vk_testing::Image::subresource_range(ds_image_create_info, |
| 12567 | VK_IMAGE_ASPECT_DEPTH_BIT); |
| 12568 | |
| 12569 | m_errorMonitor->SetDesiredFailureMsg( |
| 12570 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 12571 | "vkCmdClearColorImage called with depth/stencil image."); |
| 12572 | |
| 12573 | vkCmdClearColorImage(m_commandBuffer->GetBufferHandle(), ds_image.handle(), |
| 12574 | VK_IMAGE_LAYOUT_GENERAL, &clear_color, 1, |
| 12575 | &color_range); |
| 12576 | |
| 12577 | m_errorMonitor->VerifyFound(); |
| 12578 | |
Tony Barbour | 26434b9 | 2016-06-02 09:43:50 -0600 | [diff] [blame] | 12579 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 12580 | "vkCmdClearColorImage called with " |
| 12581 | "image created without " |
| 12582 | "VK_IMAGE_USAGE_TRANSFER_DST_BIT"); |
| 12583 | |
| 12584 | vkCmdClearColorImage(m_commandBuffer->GetBufferHandle(), ds_image.handle(), |
| 12585 | VK_IMAGE_LAYOUT_GENERAL, &clear_color, 1, |
| 12586 | &color_range); |
| 12587 | |
| 12588 | m_errorMonitor->VerifyFound(); |
| 12589 | |
Tobin Ehlis | 6e23d77 | 2016-05-19 11:08:34 -0600 | [diff] [blame] | 12590 | // Call CmdClearDepthStencilImage with color image |
| 12591 | m_errorMonitor->SetDesiredFailureMsg( |
| 12592 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 12593 | "vkCmdClearDepthStencilImage called without a depth/stencil image."); |
| 12594 | |
| 12595 | vkCmdClearDepthStencilImage( |
| 12596 | m_commandBuffer->GetBufferHandle(), color_image.handle(), |
| 12597 | VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL, &clear_value, 1, |
| 12598 | &ds_range); |
| 12599 | |
| 12600 | m_errorMonitor->VerifyFound(); |
| 12601 | } |
Tobin Ehlis | cde0889 | 2015-09-22 10:11:37 -0600 | [diff] [blame] | 12602 | #endif // IMAGE_TESTS |
| 12603 | |
Tony Barbour | 300a608 | 2015-04-07 13:44:53 -0600 | [diff] [blame] | 12604 | int main(int argc, char **argv) { |
| 12605 | int result; |
| 12606 | |
Cody Northrop | 8e54a40 | 2016-03-08 22:25:52 -0700 | [diff] [blame] | 12607 | #ifdef ANDROID |
| 12608 | int vulkanSupport = InitVulkan(); |
| 12609 | if (vulkanSupport == 0) |
| 12610 | return 1; |
| 12611 | #endif |
| 12612 | |
Tony Barbour | 300a608 | 2015-04-07 13:44:53 -0600 | [diff] [blame] | 12613 | ::testing::InitGoogleTest(&argc, argv); |
Tony Barbour | 6918cd5 | 2015-04-09 12:58:51 -0600 | [diff] [blame] | 12614 | VkTestFramework::InitArgs(&argc, argv); |
Tony Barbour | 300a608 | 2015-04-07 13:44:53 -0600 | [diff] [blame] | 12615 | |
| 12616 | ::testing::AddGlobalTestEnvironment(new TestEnvironment); |
| 12617 | |
| 12618 | result = RUN_ALL_TESTS(); |
| 12619 | |
Tony Barbour | 6918cd5 | 2015-04-09 12:58:51 -0600 | [diff] [blame] | 12620 | VkTestFramework::Finish(); |
Tony Barbour | 300a608 | 2015-04-07 13:44:53 -0600 | [diff] [blame] | 12621 | return result; |
| 12622 | } |