Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2015-2016 The Khronos Group Inc. |
| 3 | * Copyright (c) 2015-2016 Valve Corporation |
| 4 | * Copyright (c) 2015-2016 LunarG, Inc. |
Michael Lentine | 0a369f6 | 2016-02-03 16:51:46 -0600 | [diff] [blame] | 5 | * Copyright (c) 2015-2016 Google, Inc. |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6 | * |
Jon Ashburn | 3ebf125 | 2016-04-19 11:30:31 -0600 | [diff] [blame] | 7 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 8 | * you may not use this file except in compliance with the License. |
| 9 | * You may obtain a copy of the License at |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 10 | * |
Jon Ashburn | 3ebf125 | 2016-04-19 11:30:31 -0600 | [diff] [blame] | 11 | * http://www.apache.org/licenses/LICENSE-2.0 |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12 | * |
| 13 | * Author: Chia-I Wu <olvaffe@gmail.com> |
| 14 | * Author: Chris Forbes <chrisf@ijw.co.nz> |
| 15 | * Author: Courtney Goeltzenleuchter <courtney@LunarG.com> |
| 16 | * Author: Mark Lobodzinski <mark@lunarg.com> |
| 17 | * Author: Mike Stroyan <mike@LunarG.com> |
| 18 | * Author: Tobin Ehlis <tobine@google.com> |
| 19 | * Author: Tony Barbour <tony@LunarG.com> |
| 20 | */ |
Tony Barbour | 65c48b3 | 2015-11-17 10:02:56 -0700 | [diff] [blame] | 21 | |
Cody Northrop | 8e54a40 | 2016-03-08 22:25:52 -0700 | [diff] [blame] | 22 | #ifdef ANDROID |
| 23 | #include "vulkan_wrapper.h" |
| 24 | #else |
David Pinedo | 9316d3b | 2015-11-06 12:54:48 -0700 | [diff] [blame] | 25 | #include <vulkan/vulkan.h> |
Cody Northrop | 8e54a40 | 2016-03-08 22:25:52 -0700 | [diff] [blame] | 26 | #endif |
Courtney Goeltzenleuchter | 58f3eff | 2015-10-07 13:28:58 -0600 | [diff] [blame] | 27 | #include "test_common.h" |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 28 | #include "vkrenderframework.h" |
Tobin Ehlis | a0cb02e | 2015-07-03 10:15:26 -0600 | [diff] [blame] | 29 | #include "vk_layer_config.h" |
Jon Ashburn | 7fa7e22 | 2016-02-02 12:08:10 -0700 | [diff] [blame] | 30 | #include "icd-spv.h" |
Tony Barbour | 300a608 | 2015-04-07 13:44:53 -0600 | [diff] [blame] | 31 | |
Mark Lobodzinski | 3780e14 | 2015-05-14 15:08:13 -0500 | [diff] [blame] | 32 | #define GLM_FORCE_RADIANS |
| 33 | #include "glm/glm.hpp" |
| 34 | #include <glm/gtc/matrix_transform.hpp> |
| 35 | |
Dustin Graves | ffa90fa | 2016-05-06 11:20:38 -0600 | [diff] [blame] | 36 | #define PARAMETER_VALIDATION_TESTS 1 |
Tobin Ehlis | 0788f52 | 2015-05-26 16:11:58 -0600 | [diff] [blame] | 37 | #define MEM_TRACKER_TESTS 1 |
| 38 | #define OBJ_TRACKER_TESTS 1 |
| 39 | #define DRAW_STATE_TESTS 1 |
| 40 | #define THREADING_TESTS 1 |
Chris Forbes | 9f7ff63 | 2015-05-25 11:13:08 +1200 | [diff] [blame] | 41 | #define SHADER_CHECKER_TESTS 1 |
Mark Lobodzinski | 209b529 | 2015-09-17 09:44:05 -0600 | [diff] [blame] | 42 | #define DEVICE_LIMITS_TESTS 1 |
Tobin Ehlis | cde0889 | 2015-09-22 10:11:37 -0600 | [diff] [blame] | 43 | #define IMAGE_TESTS 1 |
Tobin Ehlis | 0788f52 | 2015-05-26 16:11:58 -0600 | [diff] [blame] | 44 | |
Mark Lobodzinski | 3780e14 | 2015-05-14 15:08:13 -0500 | [diff] [blame] | 45 | //-------------------------------------------------------------------------------------- |
| 46 | // Mesh and VertexFormat Data |
| 47 | //-------------------------------------------------------------------------------------- |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 48 | struct Vertex { |
| 49 | float posX, posY, posZ, posW; // Position data |
| 50 | float r, g, b, a; // Color |
Mark Lobodzinski | 3780e14 | 2015-05-14 15:08:13 -0500 | [diff] [blame] | 51 | }; |
| 52 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 53 | #define XYZ1(_x_, _y_, _z_) (_x_), (_y_), (_z_), 1.f |
Mark Lobodzinski | 3780e14 | 2015-05-14 15:08:13 -0500 | [diff] [blame] | 54 | |
| 55 | typedef enum _BsoFailSelect { |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 56 | BsoFailNone = 0x00000000, |
| 57 | BsoFailLineWidth = 0x00000001, |
| 58 | BsoFailDepthBias = 0x00000002, |
| 59 | BsoFailViewport = 0x00000004, |
| 60 | BsoFailScissor = 0x00000008, |
| 61 | BsoFailBlend = 0x00000010, |
| 62 | BsoFailDepthBounds = 0x00000020, |
| 63 | BsoFailStencilReadMask = 0x00000040, |
| 64 | BsoFailStencilWriteMask = 0x00000080, |
| 65 | BsoFailStencilReference = 0x00000100, |
Mark Mueller | d491441 | 2016-06-13 17:52:06 -0600 | [diff] [blame] | 66 | BsoFailCmdClearAttachments = 0x00000200, |
Mark Lobodzinski | 3780e14 | 2015-05-14 15:08:13 -0500 | [diff] [blame] | 67 | } BsoFailSelect; |
| 68 | |
| 69 | struct vktriangle_vs_uniform { |
| 70 | // Must start with MVP |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 71 | float mvp[4][4]; |
| 72 | float position[3][4]; |
| 73 | float color[3][4]; |
Mark Lobodzinski | 3780e14 | 2015-05-14 15:08:13 -0500 | [diff] [blame] | 74 | }; |
| 75 | |
Mark Lobodzinski | 75a97e6 | 2015-06-02 09:41:30 -0500 | [diff] [blame] | 76 | static const char bindStateVertShaderText[] = |
Chris Forbes | 7b34280 | 2016-04-07 13:20:10 +1200 | [diff] [blame] | 77 | "#version 450\n" |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 78 | "vec2 vertices[3];\n" |
| 79 | "out gl_PerVertex {\n" |
| 80 | " vec4 gl_Position;\n" |
| 81 | "};\n" |
| 82 | "void main() {\n" |
| 83 | " vertices[0] = vec2(-1.0, -1.0);\n" |
| 84 | " vertices[1] = vec2( 1.0, -1.0);\n" |
| 85 | " vertices[2] = vec2( 0.0, 1.0);\n" |
| 86 | " gl_Position = vec4(vertices[gl_VertexIndex % 3], 0.0, 1.0);\n" |
| 87 | "}\n"; |
Mark Lobodzinski | 3780e14 | 2015-05-14 15:08:13 -0500 | [diff] [blame] | 88 | |
Mark Lobodzinski | 75a97e6 | 2015-06-02 09:41:30 -0500 | [diff] [blame] | 89 | static const char bindStateFragShaderText[] = |
Chris Forbes | 7b34280 | 2016-04-07 13:20:10 +1200 | [diff] [blame] | 90 | "#version 450\n" |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 91 | "\n" |
| 92 | "layout(location = 0) out vec4 uFragColor;\n" |
| 93 | "void main(){\n" |
| 94 | " uFragColor = vec4(0,1,0,1);\n" |
| 95 | "}\n"; |
Mark Lobodzinski | 3780e14 | 2015-05-14 15:08:13 -0500 | [diff] [blame] | 96 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 97 | static VKAPI_ATTR VkBool32 VKAPI_CALL |
| 98 | myDbgFunc(VkFlags msgFlags, VkDebugReportObjectTypeEXT objType, |
| 99 | uint64_t srcObject, size_t location, int32_t msgCode, |
| 100 | const char *pLayerPrefix, const char *pMsg, void *pUserData); |
Tony Barbour | 300a608 | 2015-04-07 13:44:53 -0600 | [diff] [blame] | 101 | |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 102 | // ******************************************************** |
| 103 | // ErrorMonitor Usage: |
| 104 | // |
| 105 | // Call SetDesiredFailureMsg with a string to be compared against all |
| 106 | // encountered log messages. Passing NULL will match all log messages. |
| 107 | // logMsg will return true for skipCall only if msg is matched or NULL. |
| 108 | // |
| 109 | // Call DesiredMsgFound to determine if the desired failure message |
| 110 | // was encountered. |
| 111 | |
Tony Barbour | 300a608 | 2015-04-07 13:44:53 -0600 | [diff] [blame] | 112 | class ErrorMonitor { |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 113 | public: |
| 114 | ErrorMonitor() { |
Mike Stroyan | 4268d1f | 2015-07-13 14:45:35 -0600 | [diff] [blame] | 115 | test_platform_thread_create_mutex(&m_mutex); |
| 116 | test_platform_thread_lock_mutex(&m_mutex); |
Mark Lobodzinski | 510e20d | 2016-02-11 09:26:16 -0700 | [diff] [blame] | 117 | m_msgFlags = VK_DEBUG_REPORT_INFORMATION_BIT_EXT; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 118 | m_bailout = NULL; |
Mike Stroyan | 4268d1f | 2015-07-13 14:45:35 -0600 | [diff] [blame] | 119 | test_platform_thread_unlock_mutex(&m_mutex); |
Tony Barbour | 300a608 | 2015-04-07 13:44:53 -0600 | [diff] [blame] | 120 | } |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 121 | |
Dustin Graves | 4845814 | 2016-04-29 16:11:55 -0600 | [diff] [blame] | 122 | ~ErrorMonitor() { test_platform_thread_delete_mutex(&m_mutex); } |
| 123 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 124 | void SetDesiredFailureMsg(VkFlags msgFlags, const char *msgString) { |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 125 | // also discard all collected messages to this point |
Mike Stroyan | 4268d1f | 2015-07-13 14:45:35 -0600 | [diff] [blame] | 126 | test_platform_thread_lock_mutex(&m_mutex); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 127 | m_failureMsg.clear(); |
| 128 | m_otherMsgs.clear(); |
| 129 | m_desiredMsg = msgString; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 130 | m_msgFound = VK_FALSE; |
| 131 | m_msgFlags = msgFlags; |
Mike Stroyan | 4268d1f | 2015-07-13 14:45:35 -0600 | [diff] [blame] | 132 | test_platform_thread_unlock_mutex(&m_mutex); |
Tony Barbour | 300a608 | 2015-04-07 13:44:53 -0600 | [diff] [blame] | 133 | } |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 134 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 135 | VkBool32 CheckForDesiredMsg(VkFlags msgFlags, const char *msgString) { |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 136 | VkBool32 result = VK_FALSE; |
Mike Stroyan | 4268d1f | 2015-07-13 14:45:35 -0600 | [diff] [blame] | 137 | test_platform_thread_lock_mutex(&m_mutex); |
Mike Stroyan | accf769 | 2015-05-12 16:00:45 -0600 | [diff] [blame] | 138 | if (m_bailout != NULL) { |
| 139 | *m_bailout = true; |
| 140 | } |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 141 | string errorString(msgString); |
| 142 | if (msgFlags & m_msgFlags) { |
| 143 | if (errorString.find(m_desiredMsg) != string::npos) { |
Chris Forbes | c7b8ad7 | 2016-04-04 18:50:38 +1200 | [diff] [blame] | 144 | if (m_msgFound) { /* if multiple matches, don't lose all but the last! */ |
| 145 | m_otherMsgs.push_back(m_failureMsg); |
| 146 | } |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 147 | m_failureMsg = errorString; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 148 | m_msgFound = VK_TRUE; |
| 149 | result = VK_TRUE; |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 150 | } else { |
| 151 | m_otherMsgs.push_back(errorString); |
| 152 | } |
| 153 | } |
Mike Stroyan | 4268d1f | 2015-07-13 14:45:35 -0600 | [diff] [blame] | 154 | test_platform_thread_unlock_mutex(&m_mutex); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 155 | return result; |
Mike Stroyan | accf769 | 2015-05-12 16:00:45 -0600 | [diff] [blame] | 156 | } |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 157 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 158 | vector<string> GetOtherFailureMsgs(void) { return m_otherMsgs; } |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 159 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 160 | string GetFailureMsg(void) { return m_failureMsg; } |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 161 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 162 | VkBool32 DesiredMsgFound(void) { return m_msgFound; } |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 163 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 164 | void SetBailout(bool *bailout) { m_bailout = bailout; } |
Tony Barbour | 300a608 | 2015-04-07 13:44:53 -0600 | [diff] [blame] | 165 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 166 | void DumpFailureMsgs(void) { |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 167 | vector<string> otherMsgs = GetOtherFailureMsgs(); |
| 168 | cout << "Other error messages logged for this test were:" << endl; |
| 169 | for (auto iter = otherMsgs.begin(); iter != otherMsgs.end(); iter++) { |
| 170 | cout << " " << *iter << endl; |
| 171 | } |
| 172 | } |
| 173 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 174 | /* helpers */ |
| 175 | |
| 176 | void ExpectSuccess() { |
| 177 | // match anything |
| 178 | SetDesiredFailureMsg(~0u, ""); |
| 179 | } |
| 180 | |
| 181 | void VerifyFound() { |
| 182 | // Not seeing the desired message is a failure. /Before/ throwing, dump |
| 183 | // any other messages. |
| 184 | if (!DesiredMsgFound()) { |
| 185 | DumpFailureMsgs(); |
| 186 | FAIL() << "Did not receive expected error '" << m_desiredMsg << "'"; |
| 187 | } |
| 188 | } |
| 189 | |
| 190 | void VerifyNotFound() { |
| 191 | // ExpectSuccess() configured us to match anything. Any error is a |
| 192 | // failure. |
| 193 | if (DesiredMsgFound()) { |
| 194 | DumpFailureMsgs(); |
| 195 | FAIL() << "Expected to succeed but got error: " << GetFailureMsg(); |
| 196 | } |
| 197 | } |
| 198 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 199 | private: |
| 200 | VkFlags m_msgFlags; |
| 201 | string m_desiredMsg; |
| 202 | string m_failureMsg; |
| 203 | vector<string> m_otherMsgs; |
Mike Stroyan | 4268d1f | 2015-07-13 14:45:35 -0600 | [diff] [blame] | 204 | test_platform_thread_mutex m_mutex; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 205 | bool *m_bailout; |
| 206 | VkBool32 m_msgFound; |
Tony Barbour | 300a608 | 2015-04-07 13:44:53 -0600 | [diff] [blame] | 207 | }; |
Mark Lobodzinski | 3780e14 | 2015-05-14 15:08:13 -0500 | [diff] [blame] | 208 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 209 | static VKAPI_ATTR VkBool32 VKAPI_CALL |
| 210 | myDbgFunc(VkFlags msgFlags, VkDebugReportObjectTypeEXT objType, |
| 211 | uint64_t srcObject, size_t location, int32_t msgCode, |
| 212 | const char *pLayerPrefix, const char *pMsg, void *pUserData) { |
| 213 | if (msgFlags & |
Mark Lobodzinski | 510e20d | 2016-02-11 09:26:16 -0700 | [diff] [blame] | 214 | (VK_DEBUG_REPORT_WARNING_BIT_EXT | VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 215 | VK_DEBUG_REPORT_ERROR_BIT_EXT)) { |
Tony Barbour | 0b4d956 | 2015-04-09 10:48:04 -0600 | [diff] [blame] | 216 | ErrorMonitor *errMonitor = (ErrorMonitor *)pUserData; |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 217 | return errMonitor->CheckForDesiredMsg(msgFlags, pMsg); |
Tony Barbour | 0b4d956 | 2015-04-09 10:48:04 -0600 | [diff] [blame] | 218 | } |
Courtney Goeltzenleuchter | 0664083 | 2015-09-04 13:52:24 -0600 | [diff] [blame] | 219 | return false; |
Tony Barbour | 300a608 | 2015-04-07 13:44:53 -0600 | [diff] [blame] | 220 | } |
Mark Lobodzinski | 3780e14 | 2015-05-14 15:08:13 -0500 | [diff] [blame] | 221 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 222 | class VkLayerTest : public VkRenderFramework { |
| 223 | public: |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 224 | VkResult BeginCommandBuffer(VkCommandBufferObj &commandBuffer); |
| 225 | VkResult EndCommandBuffer(VkCommandBufferObj &commandBuffer); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 226 | void VKTriangleTest(const char *vertShaderText, const char *fragShaderText, |
| 227 | BsoFailSelect failMask); |
| 228 | void GenericDrawPreparation(VkCommandBufferObj *commandBuffer, |
| 229 | VkPipelineObj &pipelineobj, |
| 230 | VkDescriptorSetObj &descriptorSet, |
| 231 | BsoFailSelect failMask); |
| 232 | void GenericDrawPreparation(VkPipelineObj &pipelineobj, |
| 233 | VkDescriptorSetObj &descriptorSet, |
| 234 | BsoFailSelect failMask) { |
| 235 | GenericDrawPreparation(m_commandBuffer, pipelineobj, descriptorSet, |
| 236 | failMask); |
| 237 | } |
Tony Barbour | 300a608 | 2015-04-07 13:44:53 -0600 | [diff] [blame] | 238 | |
Tony Barbour | fe3351b | 2015-07-28 10:17:20 -0600 | [diff] [blame] | 239 | /* Convenience functions that use built-in command buffer */ |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 240 | VkResult BeginCommandBuffer() { |
| 241 | return BeginCommandBuffer(*m_commandBuffer); |
| 242 | } |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 243 | VkResult EndCommandBuffer() { return EndCommandBuffer(*m_commandBuffer); } |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 244 | void Draw(uint32_t vertexCount, uint32_t instanceCount, |
| 245 | uint32_t firstVertex, uint32_t firstInstance) { |
| 246 | m_commandBuffer->Draw(vertexCount, instanceCount, firstVertex, |
| 247 | firstInstance); |
| 248 | } |
| 249 | void DrawIndexed(uint32_t indexCount, uint32_t instanceCount, |
| 250 | uint32_t firstIndex, int32_t vertexOffset, |
| 251 | uint32_t firstInstance) { |
| 252 | m_commandBuffer->DrawIndexed(indexCount, instanceCount, firstIndex, |
| 253 | vertexOffset, firstInstance); |
| 254 | } |
Mark Lobodzinski | cf0ae75 | 2016-06-23 10:02:24 -0600 | [diff] [blame] | 255 | void QueueCommandBuffer() { m_commandBuffer->QueueCommandBuffer(); } |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 256 | void QueueCommandBuffer(const VkFence &fence) { |
| 257 | m_commandBuffer->QueueCommandBuffer(fence); |
| 258 | } |
| 259 | void BindVertexBuffer(VkConstantBufferObj *vertexBuffer, |
| 260 | VkDeviceSize offset, uint32_t binding) { |
| 261 | m_commandBuffer->BindVertexBuffer(vertexBuffer, offset, binding); |
| 262 | } |
| 263 | void BindIndexBuffer(VkIndexBufferObj *indexBuffer, VkDeviceSize offset) { |
| 264 | m_commandBuffer->BindIndexBuffer(indexBuffer, offset); |
| 265 | } |
| 266 | |
| 267 | protected: |
| 268 | ErrorMonitor *m_errorMonitor; |
Ian Elliott | 2c1daf5 | 2016-05-12 09:41:46 -0600 | [diff] [blame] | 269 | bool m_enableWSI; |
Tony Barbour | 300a608 | 2015-04-07 13:44:53 -0600 | [diff] [blame] | 270 | |
| 271 | virtual void SetUp() { |
Courtney Goeltzenleuchter | cd69eee | 2015-07-06 09:10:47 -0600 | [diff] [blame] | 272 | std::vector<const char *> instance_layer_names; |
| 273 | std::vector<const char *> device_layer_names; |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 274 | std::vector<const char *> instance_extension_names; |
| 275 | std::vector<const char *> device_extension_names; |
Tony Barbour | 3fdff9e | 2015-04-23 12:55:36 -0600 | [diff] [blame] | 276 | |
Courtney Goeltzenleuchter | 7415d5a | 2015-12-09 15:48:16 -0700 | [diff] [blame] | 277 | instance_extension_names.push_back(VK_EXT_DEBUG_REPORT_EXTENSION_NAME); |
Courtney Goeltzenleuchter | c2b06fe | 2015-06-16 15:59:11 -0600 | [diff] [blame] | 278 | /* |
| 279 | * Since CreateDbgMsgCallback is an instance level extension call |
| 280 | * any extension / layer that utilizes that feature also needs |
| 281 | * to be enabled at create instance time. |
| 282 | */ |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 283 | // Use Threading layer first to protect others from |
| 284 | // ThreadCommandBufferCollision test |
Courtney Goeltzenleuchter | 7688532 | 2016-02-06 17:11:22 -0700 | [diff] [blame] | 285 | instance_layer_names.push_back("VK_LAYER_GOOGLE_threading"); |
Tobin Ehlis | 24aab04 | 2016-03-24 10:54:18 -0600 | [diff] [blame] | 286 | instance_layer_names.push_back("VK_LAYER_LUNARG_parameter_validation"); |
Michael Lentine | 03107b4 | 2015-12-11 10:49:51 -0800 | [diff] [blame] | 287 | instance_layer_names.push_back("VK_LAYER_LUNARG_object_tracker"); |
Tobin Ehlis | c96f806 | 2016-03-09 16:12:48 -0700 | [diff] [blame] | 288 | instance_layer_names.push_back("VK_LAYER_LUNARG_core_validation"); |
Michael Lentine | 03107b4 | 2015-12-11 10:49:51 -0800 | [diff] [blame] | 289 | instance_layer_names.push_back("VK_LAYER_LUNARG_image"); |
Ian Elliott | e48a138 | 2016-04-28 14:22:58 -0600 | [diff] [blame] | 290 | instance_layer_names.push_back("VK_LAYER_LUNARG_swapchain"); |
Dustin Graves | eaa78cd | 2016-01-26 16:30:22 -0700 | [diff] [blame] | 291 | instance_layer_names.push_back("VK_LAYER_GOOGLE_unique_objects"); |
Courtney Goeltzenleuchter | d971b61 | 2015-06-17 20:51:59 -0600 | [diff] [blame] | 292 | |
Courtney Goeltzenleuchter | 7688532 | 2016-02-06 17:11:22 -0700 | [diff] [blame] | 293 | device_layer_names.push_back("VK_LAYER_GOOGLE_threading"); |
Tobin Ehlis | 24aab04 | 2016-03-24 10:54:18 -0600 | [diff] [blame] | 294 | device_layer_names.push_back("VK_LAYER_LUNARG_parameter_validation"); |
Michael Lentine | 03107b4 | 2015-12-11 10:49:51 -0800 | [diff] [blame] | 295 | device_layer_names.push_back("VK_LAYER_LUNARG_object_tracker"); |
Tobin Ehlis | c96f806 | 2016-03-09 16:12:48 -0700 | [diff] [blame] | 296 | device_layer_names.push_back("VK_LAYER_LUNARG_core_validation"); |
Michael Lentine | 03107b4 | 2015-12-11 10:49:51 -0800 | [diff] [blame] | 297 | device_layer_names.push_back("VK_LAYER_LUNARG_image"); |
Ian Elliott | e48a138 | 2016-04-28 14:22:58 -0600 | [diff] [blame] | 298 | device_layer_names.push_back("VK_LAYER_LUNARG_swapchain"); |
Dustin Graves | eaa78cd | 2016-01-26 16:30:22 -0700 | [diff] [blame] | 299 | device_layer_names.push_back("VK_LAYER_GOOGLE_unique_objects"); |
Tony Barbour | 300a608 | 2015-04-07 13:44:53 -0600 | [diff] [blame] | 300 | |
Ian Elliott | 2c1daf5 | 2016-05-12 09:41:46 -0600 | [diff] [blame] | 301 | if (m_enableWSI) { |
| 302 | instance_extension_names.push_back(VK_KHR_SURFACE_EXTENSION_NAME); |
| 303 | device_extension_names.push_back(VK_KHR_SWAPCHAIN_EXTENSION_NAME); |
| 304 | #ifdef NEED_TO_TEST_THIS_ON_PLATFORM |
| 305 | #if defined(VK_USE_PLATFORM_ANDROID_KHR) |
| 306 | instance_extension_names.push_back(VK_KHR_ANDROID_SURFACE_EXTENSION_NAME); |
| 307 | #endif // VK_USE_PLATFORM_ANDROID_KHR |
| 308 | #if defined(VK_USE_PLATFORM_MIR_KHR) |
| 309 | instance_extension_names.push_back(VK_KHR_MIR_SURFACE_EXTENSION_NAME); |
| 310 | #endif // VK_USE_PLATFORM_MIR_KHR |
| 311 | #if defined(VK_USE_PLATFORM_WAYLAND_KHR) |
| 312 | instance_extension_names.push_back(VK_KHR_WAYLAND_SURFACE_EXTENSION_NAME); |
| 313 | #endif // VK_USE_PLATFORM_WAYLAND_KHR |
| 314 | #if defined(VK_USE_PLATFORM_WIN32_KHR) |
| 315 | instance_extension_names.push_back(VK_KHR_WIN32_SURFACE_EXTENSION_NAME); |
| 316 | #endif // VK_USE_PLATFORM_WIN32_KHR |
| 317 | #endif // NEED_TO_TEST_THIS_ON_PLATFORM |
| 318 | #if defined(VK_USE_PLATFORM_XCB_KHR) |
| 319 | instance_extension_names.push_back(VK_KHR_XCB_SURFACE_EXTENSION_NAME); |
| 320 | #elif defined(VK_USE_PLATFORM_XLIB_KHR) |
| 321 | instance_extension_names.push_back(VK_KHR_XLIB_SURFACE_EXTENSION_NAME); |
| 322 | #endif // VK_USE_PLATFORM_XLIB_KHR |
| 323 | } |
| 324 | |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 325 | this->app_info.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO; |
Tony Barbour | 300a608 | 2015-04-07 13:44:53 -0600 | [diff] [blame] | 326 | this->app_info.pNext = NULL; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 327 | this->app_info.pApplicationName = "layer_tests"; |
| 328 | this->app_info.applicationVersion = 1; |
Tony Barbour | 300a608 | 2015-04-07 13:44:53 -0600 | [diff] [blame] | 329 | this->app_info.pEngineName = "unittest"; |
| 330 | this->app_info.engineVersion = 1; |
Jon Ashburn | c5012ff | 2016-03-22 13:57:46 -0600 | [diff] [blame] | 331 | this->app_info.apiVersion = VK_API_VERSION_1_0; |
Tony Barbour | 300a608 | 2015-04-07 13:44:53 -0600 | [diff] [blame] | 332 | |
Tony Barbour | 15524c3 | 2015-04-29 17:34:29 -0600 | [diff] [blame] | 333 | m_errorMonitor = new ErrorMonitor; |
Courtney Goeltzenleuchter | cd69eee | 2015-07-06 09:10:47 -0600 | [diff] [blame] | 334 | InitFramework(instance_layer_names, device_layer_names, |
| 335 | instance_extension_names, device_extension_names, |
| 336 | myDbgFunc, m_errorMonitor); |
Tony Barbour | 300a608 | 2015-04-07 13:44:53 -0600 | [diff] [blame] | 337 | } |
| 338 | |
| 339 | virtual void TearDown() { |
| 340 | // Clean up resources before we reset |
Tony Barbour | 300a608 | 2015-04-07 13:44:53 -0600 | [diff] [blame] | 341 | ShutdownFramework(); |
Tony Barbour | 0b4d956 | 2015-04-09 10:48:04 -0600 | [diff] [blame] | 342 | delete m_errorMonitor; |
Tony Barbour | 300a608 | 2015-04-07 13:44:53 -0600 | [diff] [blame] | 343 | } |
Ian Elliott | 2c1daf5 | 2016-05-12 09:41:46 -0600 | [diff] [blame] | 344 | |
| 345 | VkLayerTest() { |
| 346 | m_enableWSI = false; |
| 347 | } |
Tony Barbour | 300a608 | 2015-04-07 13:44:53 -0600 | [diff] [blame] | 348 | }; |
Mark Lobodzinski | 3780e14 | 2015-05-14 15:08:13 -0500 | [diff] [blame] | 349 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 350 | VkResult VkLayerTest::BeginCommandBuffer(VkCommandBufferObj &commandBuffer) { |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 351 | VkResult result; |
Tony Barbour | 300a608 | 2015-04-07 13:44:53 -0600 | [diff] [blame] | 352 | |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 353 | result = commandBuffer.BeginCommandBuffer(); |
Tony Barbour | 300a608 | 2015-04-07 13:44:53 -0600 | [diff] [blame] | 354 | |
| 355 | /* |
| 356 | * For render test all drawing happens in a single render pass |
| 357 | * on a single command buffer. |
| 358 | */ |
Chris Forbes | 76a5eeb | 2015-06-16 14:05:59 +1200 | [diff] [blame] | 359 | if (VK_SUCCESS == result && renderPass()) { |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 360 | commandBuffer.BeginRenderPass(renderPassBeginInfo()); |
Tony Barbour | 300a608 | 2015-04-07 13:44:53 -0600 | [diff] [blame] | 361 | } |
| 362 | |
| 363 | return result; |
| 364 | } |
| 365 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 366 | VkResult VkLayerTest::EndCommandBuffer(VkCommandBufferObj &commandBuffer) { |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 367 | VkResult result; |
Tony Barbour | 300a608 | 2015-04-07 13:44:53 -0600 | [diff] [blame] | 368 | |
Chris Forbes | 76a5eeb | 2015-06-16 14:05:59 +1200 | [diff] [blame] | 369 | if (renderPass()) { |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 370 | commandBuffer.EndRenderPass(); |
Chris Forbes | 76a5eeb | 2015-06-16 14:05:59 +1200 | [diff] [blame] | 371 | } |
Tony Barbour | 300a608 | 2015-04-07 13:44:53 -0600 | [diff] [blame] | 372 | |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 373 | result = commandBuffer.EndCommandBuffer(); |
Tony Barbour | 300a608 | 2015-04-07 13:44:53 -0600 | [diff] [blame] | 374 | |
| 375 | return result; |
| 376 | } |
| 377 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 378 | void VkLayerTest::VKTriangleTest(const char *vertShaderText, |
| 379 | const char *fragShaderText, |
| 380 | BsoFailSelect failMask) { |
Mark Lobodzinski | 3780e14 | 2015-05-14 15:08:13 -0500 | [diff] [blame] | 381 | // Create identity matrix |
| 382 | int i; |
| 383 | struct vktriangle_vs_uniform data; |
| 384 | |
| 385 | glm::mat4 Projection = glm::mat4(1.0f); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 386 | glm::mat4 View = glm::mat4(1.0f); |
| 387 | glm::mat4 Model = glm::mat4(1.0f); |
| 388 | glm::mat4 MVP = Projection * View * Model; |
Mark Lobodzinski | 3780e14 | 2015-05-14 15:08:13 -0500 | [diff] [blame] | 389 | const int matrixSize = sizeof(MVP); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 390 | const int bufSize = sizeof(vktriangle_vs_uniform) / sizeof(float); |
Mark Lobodzinski | 3780e14 | 2015-05-14 15:08:13 -0500 | [diff] [blame] | 391 | |
| 392 | memcpy(&data.mvp, &MVP[0][0], matrixSize); |
| 393 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 394 | static const Vertex tri_data[] = { |
| 395 | {XYZ1(-1, -1, 0), XYZ1(1.f, 0.f, 0.f)}, |
| 396 | {XYZ1(1, -1, 0), XYZ1(0.f, 1.f, 0.f)}, |
| 397 | {XYZ1(0, 1, 0), XYZ1(0.f, 0.f, 1.f)}, |
Mark Lobodzinski | 3780e14 | 2015-05-14 15:08:13 -0500 | [diff] [blame] | 398 | }; |
| 399 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 400 | for (i = 0; i < 3; i++) { |
Mark Lobodzinski | 3780e14 | 2015-05-14 15:08:13 -0500 | [diff] [blame] | 401 | data.position[i][0] = tri_data[i].posX; |
| 402 | data.position[i][1] = tri_data[i].posY; |
| 403 | data.position[i][2] = tri_data[i].posZ; |
| 404 | data.position[i][3] = tri_data[i].posW; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 405 | data.color[i][0] = tri_data[i].r; |
| 406 | data.color[i][1] = tri_data[i].g; |
| 407 | data.color[i][2] = tri_data[i].b; |
| 408 | data.color[i][3] = tri_data[i].a; |
Mark Lobodzinski | 3780e14 | 2015-05-14 15:08:13 -0500 | [diff] [blame] | 409 | } |
| 410 | |
| 411 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 412 | ASSERT_NO_FATAL_FAILURE(InitViewport()); |
| 413 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 414 | VkConstantBufferObj constantBuffer(m_device, bufSize * 2, sizeof(float), |
| 415 | (const void *)&data); |
Mark Lobodzinski | 3780e14 | 2015-05-14 15:08:13 -0500 | [diff] [blame] | 416 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 417 | VkShaderObj vs(m_device, vertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this); |
| 418 | VkShaderObj ps(m_device, fragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, |
| 419 | this); |
Mark Lobodzinski | 3780e14 | 2015-05-14 15:08:13 -0500 | [diff] [blame] | 420 | |
| 421 | VkPipelineObj pipelineobj(m_device); |
Chia-I Wu | 08accc6 | 2015-07-07 11:50:03 +0800 | [diff] [blame] | 422 | pipelineobj.AddColorAttachment(); |
Mark Lobodzinski | 3780e14 | 2015-05-14 15:08:13 -0500 | [diff] [blame] | 423 | pipelineobj.AddShader(&vs); |
| 424 | pipelineobj.AddShader(&ps); |
Courtney Goeltzenleuchter | 507ba97 | 2015-09-30 16:16:57 -0600 | [diff] [blame] | 425 | if (failMask & BsoFailLineWidth) { |
| 426 | pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_LINE_WIDTH); |
Tobin Ehlis | 7a1d235 | 2016-03-28 11:18:19 -0600 | [diff] [blame] | 427 | VkPipelineInputAssemblyStateCreateInfo ia_state = {}; |
| 428 | ia_state.sType = |
| 429 | VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO; |
| 430 | ia_state.topology = VK_PRIMITIVE_TOPOLOGY_LINE_LIST; |
| 431 | pipelineobj.SetInputAssembly(&ia_state); |
Courtney Goeltzenleuchter | 507ba97 | 2015-09-30 16:16:57 -0600 | [diff] [blame] | 432 | } |
| 433 | if (failMask & BsoFailDepthBias) { |
| 434 | pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_DEPTH_BIAS); |
Tobin Ehlis | 7a1d235 | 2016-03-28 11:18:19 -0600 | [diff] [blame] | 435 | VkPipelineRasterizationStateCreateInfo rs_state = {}; |
| 436 | rs_state.sType = |
| 437 | VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO; |
| 438 | rs_state.depthBiasEnable = VK_TRUE; |
Mark Young | 7394fdd | 2016-03-31 14:56:43 -0600 | [diff] [blame] | 439 | rs_state.lineWidth = 1.0f; |
Tobin Ehlis | 7a1d235 | 2016-03-28 11:18:19 -0600 | [diff] [blame] | 440 | pipelineobj.SetRasterization(&rs_state); |
Courtney Goeltzenleuchter | 507ba97 | 2015-09-30 16:16:57 -0600 | [diff] [blame] | 441 | } |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 442 | // Viewport and scissors must stay in synch or other errors will occur than |
| 443 | // the ones we want |
Courtney Goeltzenleuchter | 507ba97 | 2015-09-30 16:16:57 -0600 | [diff] [blame] | 444 | if (failMask & BsoFailViewport) { |
| 445 | pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_VIEWPORT); |
Tobin Ehlis | d332f28 | 2015-10-02 11:00:56 -0600 | [diff] [blame] | 446 | m_viewports.clear(); |
| 447 | m_scissors.clear(); |
Courtney Goeltzenleuchter | 507ba97 | 2015-09-30 16:16:57 -0600 | [diff] [blame] | 448 | } |
| 449 | if (failMask & BsoFailScissor) { |
| 450 | pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_SCISSOR); |
Tobin Ehlis | d332f28 | 2015-10-02 11:00:56 -0600 | [diff] [blame] | 451 | m_scissors.clear(); |
| 452 | m_viewports.clear(); |
Courtney Goeltzenleuchter | 507ba97 | 2015-09-30 16:16:57 -0600 | [diff] [blame] | 453 | } |
| 454 | if (failMask & BsoFailBlend) { |
| 455 | pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_BLEND_CONSTANTS); |
Tobin Ehlis | 7a1d235 | 2016-03-28 11:18:19 -0600 | [diff] [blame] | 456 | VkPipelineColorBlendAttachmentState att_state = {}; |
| 457 | att_state.dstAlphaBlendFactor = VK_BLEND_FACTOR_CONSTANT_COLOR; |
| 458 | att_state.blendEnable = VK_TRUE; |
| 459 | pipelineobj.AddColorAttachment(0, &att_state); |
Courtney Goeltzenleuchter | 507ba97 | 2015-09-30 16:16:57 -0600 | [diff] [blame] | 460 | } |
| 461 | if (failMask & BsoFailDepthBounds) { |
| 462 | pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_DEPTH_BOUNDS); |
| 463 | } |
| 464 | if (failMask & BsoFailStencilReadMask) { |
| 465 | pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_STENCIL_COMPARE_MASK); |
| 466 | } |
| 467 | if (failMask & BsoFailStencilWriteMask) { |
| 468 | pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_STENCIL_WRITE_MASK); |
| 469 | } |
| 470 | if (failMask & BsoFailStencilReference) { |
| 471 | pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_STENCIL_REFERENCE); |
| 472 | } |
Mark Lobodzinski | 3780e14 | 2015-05-14 15:08:13 -0500 | [diff] [blame] | 473 | |
| 474 | VkDescriptorSetObj descriptorSet(m_device); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 475 | descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, |
| 476 | constantBuffer); |
Mark Lobodzinski | 3780e14 | 2015-05-14 15:08:13 -0500 | [diff] [blame] | 477 | |
| 478 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
Tony Barbour | fe3351b | 2015-07-28 10:17:20 -0600 | [diff] [blame] | 479 | ASSERT_VK_SUCCESS(BeginCommandBuffer()); |
Mark Lobodzinski | 3780e14 | 2015-05-14 15:08:13 -0500 | [diff] [blame] | 480 | |
Tony Barbour | fe3351b | 2015-07-28 10:17:20 -0600 | [diff] [blame] | 481 | GenericDrawPreparation(pipelineobj, descriptorSet, failMask); |
Mark Lobodzinski | 3780e14 | 2015-05-14 15:08:13 -0500 | [diff] [blame] | 482 | |
| 483 | // render triangle |
Courtney Goeltzenleuchter | 08c2637 | 2015-09-23 12:31:50 -0600 | [diff] [blame] | 484 | Draw(3, 1, 0, 0); |
Mark Lobodzinski | 3780e14 | 2015-05-14 15:08:13 -0500 | [diff] [blame] | 485 | |
Mark Mueller | d491441 | 2016-06-13 17:52:06 -0600 | [diff] [blame] | 486 | if (failMask & BsoFailCmdClearAttachments) { |
| 487 | VkClearAttachment color_attachment = {}; |
| 488 | color_attachment.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; |
| 489 | color_attachment.colorAttachment = 1; // Someone who knew what they were doing would use 0 for the index; |
| 490 | VkClearRect clear_rect = {{{0, 0}, {static_cast<uint32_t>(m_width), static_cast<uint32_t>(m_height)}}, 0, 0}; |
| 491 | |
| 492 | vkCmdClearAttachments(m_commandBuffer->GetBufferHandle(), 1, |
| 493 | &color_attachment, 1, &clear_rect); |
| 494 | } |
| 495 | |
Mark Lobodzinski | 3780e14 | 2015-05-14 15:08:13 -0500 | [diff] [blame] | 496 | // finalize recording of the command buffer |
Tony Barbour | fe3351b | 2015-07-28 10:17:20 -0600 | [diff] [blame] | 497 | EndCommandBuffer(); |
Mark Lobodzinski | 3780e14 | 2015-05-14 15:08:13 -0500 | [diff] [blame] | 498 | |
Tony Barbour | fe3351b | 2015-07-28 10:17:20 -0600 | [diff] [blame] | 499 | QueueCommandBuffer(); |
Mark Lobodzinski | 3780e14 | 2015-05-14 15:08:13 -0500 | [diff] [blame] | 500 | } |
| 501 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 502 | void VkLayerTest::GenericDrawPreparation(VkCommandBufferObj *commandBuffer, |
| 503 | VkPipelineObj &pipelineobj, |
| 504 | VkDescriptorSetObj &descriptorSet, |
| 505 | BsoFailSelect failMask) { |
Mark Lobodzinski | 3780e14 | 2015-05-14 15:08:13 -0500 | [diff] [blame] | 506 | if (m_depthStencil->Initialized()) { |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 507 | commandBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color, |
| 508 | m_stencil_clear_color, m_depthStencil); |
Mark Lobodzinski | 3780e14 | 2015-05-14 15:08:13 -0500 | [diff] [blame] | 509 | } else { |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 510 | commandBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color, |
| 511 | m_stencil_clear_color, NULL); |
Mark Lobodzinski | 3780e14 | 2015-05-14 15:08:13 -0500 | [diff] [blame] | 512 | } |
| 513 | |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 514 | commandBuffer->PrepareAttachments(); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 515 | // Make sure depthWriteEnable is set so that Depth fail test will work |
| 516 | // correctly |
| 517 | // Make sure stencilTestEnable is set so that Stencil fail test will work |
| 518 | // correctly |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 519 | VkStencilOpState stencil = {}; |
Chia-I Wu | 1b99bb2 | 2015-10-27 19:25:11 +0800 | [diff] [blame] | 520 | stencil.failOp = VK_STENCIL_OP_KEEP; |
| 521 | stencil.passOp = VK_STENCIL_OP_KEEP; |
| 522 | stencil.depthFailOp = VK_STENCIL_OP_KEEP; |
| 523 | stencil.compareOp = VK_COMPARE_OP_NEVER; |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 524 | |
| 525 | VkPipelineDepthStencilStateCreateInfo ds_ci = {}; |
| 526 | ds_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DEPTH_STENCIL_STATE_CREATE_INFO; |
Courtney Goeltzenleuchter | 507ba97 | 2015-09-30 16:16:57 -0600 | [diff] [blame] | 527 | ds_ci.pNext = NULL; |
| 528 | ds_ci.depthTestEnable = VK_FALSE; |
| 529 | ds_ci.depthWriteEnable = VK_TRUE; |
| 530 | ds_ci.depthCompareOp = VK_COMPARE_OP_NEVER; |
| 531 | ds_ci.depthBoundsTestEnable = VK_FALSE; |
Tobin Ehlis | 7a1d235 | 2016-03-28 11:18:19 -0600 | [diff] [blame] | 532 | if (failMask & BsoFailDepthBounds) { |
| 533 | ds_ci.depthBoundsTestEnable = VK_TRUE; |
Tobin Ehlis | 21c8835 | 2016-05-26 06:15:45 -0600 | [diff] [blame] | 534 | ds_ci.maxDepthBounds = 0.0f; |
| 535 | ds_ci.minDepthBounds = 0.0f; |
Tobin Ehlis | 7a1d235 | 2016-03-28 11:18:19 -0600 | [diff] [blame] | 536 | } |
Courtney Goeltzenleuchter | 507ba97 | 2015-09-30 16:16:57 -0600 | [diff] [blame] | 537 | ds_ci.stencilTestEnable = VK_TRUE; |
| 538 | ds_ci.front = stencil; |
| 539 | ds_ci.back = stencil; |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 540 | |
Tobin Ehlis | 4bf96d1 | 2015-06-25 11:58:41 -0600 | [diff] [blame] | 541 | pipelineobj.SetDepthStencil(&ds_ci); |
Tobin Ehlis | d332f28 | 2015-10-02 11:00:56 -0600 | [diff] [blame] | 542 | pipelineobj.SetViewport(m_viewports); |
| 543 | pipelineobj.SetScissor(m_scissors); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 544 | descriptorSet.CreateVKDescriptorSet(commandBuffer); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 545 | VkResult err = pipelineobj.CreateVKPipeline( |
| 546 | descriptorSet.GetPipelineLayout(), renderPass()); |
Cody Northrop | 29a08f2 | 2015-08-27 10:20:35 -0600 | [diff] [blame] | 547 | ASSERT_VK_SUCCESS(err); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 548 | commandBuffer->BindPipeline(pipelineobj); |
| 549 | commandBuffer->BindDescriptorSet(descriptorSet); |
Mark Lobodzinski | 3780e14 | 2015-05-14 15:08:13 -0500 | [diff] [blame] | 550 | } |
| 551 | |
Ian Elliott | 2c1daf5 | 2016-05-12 09:41:46 -0600 | [diff] [blame] | 552 | class VkWsiEnabledLayerTest : public VkLayerTest { |
| 553 | public: |
| 554 | protected: |
| 555 | VkWsiEnabledLayerTest() { |
| 556 | m_enableWSI = true; |
| 557 | } |
| 558 | }; |
| 559 | |
Mark Lobodzinski | 3780e14 | 2015-05-14 15:08:13 -0500 | [diff] [blame] | 560 | // ******************************************************************************************************************** |
| 561 | // ******************************************************************************************************************** |
| 562 | // ******************************************************************************************************************** |
| 563 | // ******************************************************************************************************************** |
Dustin Graves | ffa90fa | 2016-05-06 11:20:38 -0600 | [diff] [blame] | 564 | #if PARAMETER_VALIDATION_TESTS |
| 565 | TEST_F(VkLayerTest, RequiredParameter) { |
| 566 | TEST_DESCRIPTION("Specify VK_NULL_HANDLE, NULL, and 0 for required handle, " |
| 567 | "pointer, array, and array count parameters"); |
| 568 | |
| 569 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 570 | |
| 571 | m_errorMonitor->SetDesiredFailureMsg( |
| 572 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 573 | "required parameter pFeatures specified as NULL"); |
| 574 | // Specify NULL for a pointer to a handle |
| 575 | // Expected to trigger an error with |
| 576 | // parameter_validation::validate_required_pointer |
| 577 | vkGetPhysicalDeviceFeatures(gpu(), NULL); |
| 578 | m_errorMonitor->VerifyFound(); |
| 579 | |
| 580 | m_errorMonitor->SetDesiredFailureMsg( |
| 581 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Dustin Graves | a4bb8c1 | 2016-05-16 17:22:51 -0600 | [diff] [blame] | 582 | "required parameter pQueueFamilyPropertyCount specified as NULL"); |
Dustin Graves | ffa90fa | 2016-05-06 11:20:38 -0600 | [diff] [blame] | 583 | // Specify NULL for pointer to array count |
| 584 | // Expected to trigger an error with parameter_validation::validate_array |
Dustin Graves | a4bb8c1 | 2016-05-16 17:22:51 -0600 | [diff] [blame] | 585 | vkGetPhysicalDeviceQueueFamilyProperties(gpu(), NULL, NULL); |
Dustin Graves | ffa90fa | 2016-05-06 11:20:38 -0600 | [diff] [blame] | 586 | m_errorMonitor->VerifyFound(); |
| 587 | |
| 588 | m_errorMonitor->SetDesiredFailureMsg( |
| 589 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 590 | "parameter viewportCount must be greater than 0"); |
| 591 | // Specify 0 for a required array count |
| 592 | // Expected to trigger an error with parameter_validation::validate_array |
| 593 | VkViewport view_port = {}; |
| 594 | m_commandBuffer->SetViewport(0, 0, &view_port); |
| 595 | m_errorMonitor->VerifyFound(); |
| 596 | |
| 597 | m_errorMonitor->SetDesiredFailureMsg( |
| 598 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 599 | "required parameter pViewports specified as NULL"); |
| 600 | // Specify NULL for a required array |
| 601 | // Expected to trigger an error with parameter_validation::validate_array |
| 602 | m_commandBuffer->SetViewport(0, 1, NULL); |
| 603 | m_errorMonitor->VerifyFound(); |
| 604 | |
| 605 | m_errorMonitor->SetDesiredFailureMsg( |
| 606 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 607 | "required parameter memory specified as VK_NULL_HANDLE"); |
| 608 | // Specify VK_NULL_HANDLE for a required handle |
| 609 | // Expected to trigger an error with |
| 610 | // parameter_validation::validate_required_handle |
| 611 | vkUnmapMemory(device(), VK_NULL_HANDLE); |
| 612 | m_errorMonitor->VerifyFound(); |
| 613 | |
| 614 | m_errorMonitor->SetDesiredFailureMsg( |
| 615 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 616 | "required parameter pFences[0] specified as VK_NULL_HANDLE"); |
| 617 | // Specify VK_NULL_HANDLE for a required handle array entry |
| 618 | // Expected to trigger an error with |
| 619 | // parameter_validation::validate_required_handle_array |
| 620 | VkFence fence = VK_NULL_HANDLE; |
| 621 | vkResetFences(device(), 1, &fence); |
| 622 | m_errorMonitor->VerifyFound(); |
| 623 | |
| 624 | m_errorMonitor->SetDesiredFailureMsg( |
| 625 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 626 | "required parameter pAllocateInfo specified as NULL"); |
| 627 | // Specify NULL for a required struct pointer |
| 628 | // Expected to trigger an error with |
| 629 | // parameter_validation::validate_struct_type |
| 630 | VkDeviceMemory memory = VK_NULL_HANDLE; |
| 631 | vkAllocateMemory(device(), NULL, NULL, &memory); |
| 632 | m_errorMonitor->VerifyFound(); |
| 633 | |
| 634 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 635 | "value of faceMask must not be 0"); |
| 636 | // Specify 0 for a required VkFlags parameter |
| 637 | // Expected to trigger an error with parameter_validation::validate_flags |
| 638 | m_commandBuffer->SetStencilReference(0, 0); |
| 639 | m_errorMonitor->VerifyFound(); |
| 640 | |
| 641 | m_errorMonitor->SetDesiredFailureMsg( |
| 642 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 643 | "value of pSubmits[i].pWaitDstStageMask[0] must not be 0"); |
| 644 | // Specify 0 for a required VkFlags array entry |
| 645 | // Expected to trigger an error with |
| 646 | // parameter_validation::validate_flags_array |
| 647 | VkSemaphore semaphore = VK_NULL_HANDLE; |
| 648 | VkPipelineStageFlags stageFlags = 0; |
| 649 | VkSubmitInfo submitInfo = {}; |
| 650 | submitInfo.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO; |
| 651 | submitInfo.waitSemaphoreCount = 1; |
| 652 | submitInfo.pWaitSemaphores = &semaphore; |
| 653 | submitInfo.pWaitDstStageMask = &stageFlags; |
| 654 | vkQueueSubmit(m_device->m_queue, 1, &submitInfo, VK_NULL_HANDLE); |
| 655 | m_errorMonitor->VerifyFound(); |
| 656 | } |
Dustin Graves | c99cf5a | 2016-05-09 14:40:29 -0600 | [diff] [blame] | 657 | |
Dustin Graves | fce74c0 | 2016-05-10 11:42:58 -0600 | [diff] [blame] | 658 | TEST_F(VkLayerTest, ReservedParameter) { |
| 659 | TEST_DESCRIPTION("Specify a non-zero value for a reserved parameter"); |
| 660 | |
| 661 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 662 | |
| 663 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 664 | " must be 0"); |
| 665 | // Specify 0 for a reserved VkFlags parameter |
| 666 | // Expected to trigger an error with |
| 667 | // parameter_validation::validate_reserved_flags |
| 668 | VkEvent event_handle = VK_NULL_HANDLE; |
| 669 | VkEventCreateInfo event_info = {}; |
| 670 | event_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO; |
| 671 | event_info.flags = 1; |
| 672 | vkCreateEvent(device(), &event_info, NULL, &event_handle); |
| 673 | m_errorMonitor->VerifyFound(); |
| 674 | } |
| 675 | |
Dustin Graves | c99cf5a | 2016-05-09 14:40:29 -0600 | [diff] [blame] | 676 | TEST_F(VkLayerTest, InvalidStructSType) { |
| 677 | TEST_DESCRIPTION("Specify an invalid VkStructureType for a Vulkan " |
| 678 | "structure's sType field"); |
| 679 | |
| 680 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 681 | |
| 682 | m_errorMonitor->SetDesiredFailureMsg( |
| 683 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 684 | "parameter pAllocateInfo->sType must be"); |
| 685 | // Zero struct memory, effectively setting sType to |
| 686 | // VK_STRUCTURE_TYPE_APPLICATION_INFO |
| 687 | // Expected to trigger an error with |
| 688 | // parameter_validation::validate_struct_type |
| 689 | VkMemoryAllocateInfo alloc_info = {}; |
| 690 | VkDeviceMemory memory = VK_NULL_HANDLE; |
| 691 | vkAllocateMemory(device(), &alloc_info, NULL, &memory); |
| 692 | m_errorMonitor->VerifyFound(); |
| 693 | |
| 694 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 695 | "parameter pSubmits[0].sType must be"); |
| 696 | // Zero struct memory, effectively setting sType to |
| 697 | // VK_STRUCTURE_TYPE_APPLICATION_INFO |
| 698 | // Expected to trigger an error with |
| 699 | // parameter_validation::validate_struct_type_array |
| 700 | VkSubmitInfo submit_info = {}; |
| 701 | vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE); |
| 702 | m_errorMonitor->VerifyFound(); |
| 703 | } |
| 704 | |
| 705 | TEST_F(VkLayerTest, InvalidStructPNext) { |
| 706 | TEST_DESCRIPTION( |
| 707 | "Specify an invalid value for a Vulkan structure's pNext field"); |
| 708 | |
| 709 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 710 | |
| 711 | m_errorMonitor->SetDesiredFailureMsg( |
| 712 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Karl Schultz | 38b5099 | 2016-07-11 16:09:09 -0600 | [diff] [blame^] | 713 | "value of pCreateInfo->pNext must be NULL"); |
Dustin Graves | c99cf5a | 2016-05-09 14:40:29 -0600 | [diff] [blame] | 714 | // Set VkMemoryAllocateInfo::pNext to a non-NULL value, when pNext must be |
Karl Schultz | 38b5099 | 2016-07-11 16:09:09 -0600 | [diff] [blame^] | 715 | // NULL. |
| 716 | // Need to pick a function that has no allowed pNext structure types. |
| 717 | // Expected to trigger an error with |
| 718 | // parameter_validation::validate_struct_pnext |
| 719 | VkEvent event = VK_NULL_HANDLE; |
| 720 | VkEventCreateInfo event_alloc_info; |
| 721 | // Zero-initialization will provide the correct sType |
| 722 | VkApplicationInfo app_info = {}; |
| 723 | event_alloc_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO; |
| 724 | event_alloc_info.pNext = &app_info; |
| 725 | vkCreateEvent(device(), &event_alloc_info, NULL, &event); |
| 726 | m_errorMonitor->VerifyFound(); |
| 727 | |
| 728 | m_errorMonitor->SetDesiredFailureMsg( |
| 729 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 730 | " chain includes a structure with unexpected VkStructureType "); |
| 731 | // Set VkMemoryAllocateInfo::pNext to a non-NULL value, but use |
| 732 | // a function that has allowed pNext structure types and specify |
| 733 | // a structure type that is not allowed. |
Dustin Graves | c99cf5a | 2016-05-09 14:40:29 -0600 | [diff] [blame] | 734 | // Expected to trigger an error with |
| 735 | // parameter_validation::validate_struct_pnext |
| 736 | VkDeviceMemory memory = VK_NULL_HANDLE; |
Dustin Graves | 47b6cba | 2016-05-10 17:34:38 -0600 | [diff] [blame] | 737 | VkMemoryAllocateInfo memory_alloc_info = {}; |
| 738 | memory_alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO; |
| 739 | memory_alloc_info.pNext = &app_info; |
| 740 | vkAllocateMemory(device(), &memory_alloc_info, NULL, &memory); |
Dustin Graves | c99cf5a | 2016-05-09 14:40:29 -0600 | [diff] [blame] | 741 | m_errorMonitor->VerifyFound(); |
| 742 | |
Dustin Graves | 47b6cba | 2016-05-10 17:34:38 -0600 | [diff] [blame] | 743 | m_errorMonitor->SetDesiredFailureMsg( |
| 744 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 745 | " chain includes a structure with unexpected VkStructureType "); |
| 746 | // Set VkGraphicsPipelineCreateInfo::VkPipelineRasterizationStateCreateInfo::pNext to an invalid structure, when pNext is allowed to be a non-NULL value |
| 747 | // Expected to trigger an error with |
| 748 | // parameter_validation::validate_struct_pnext |
| 749 | VkDescriptorPoolSize ds_type_count = {}; |
| 750 | ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 751 | ds_type_count.descriptorCount = 1; |
| 752 | |
| 753 | VkDescriptorPoolCreateInfo ds_pool_ci = {}; |
| 754 | ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO; |
| 755 | ds_pool_ci.pNext = NULL; |
| 756 | ds_pool_ci.maxSets = 1; |
| 757 | ds_pool_ci.poolSizeCount = 1; |
| 758 | ds_pool_ci.pPoolSizes = &ds_type_count; |
| 759 | |
| 760 | VkDescriptorPool ds_pool; |
| 761 | VkResult err = |
| 762 | vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool); |
| 763 | ASSERT_VK_SUCCESS(err); |
| 764 | |
| 765 | VkDescriptorSetLayoutBinding dsl_binding = {}; |
| 766 | dsl_binding.binding = 0; |
| 767 | dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 768 | dsl_binding.descriptorCount = 1; |
| 769 | dsl_binding.stageFlags = VK_SHADER_STAGE_ALL; |
| 770 | dsl_binding.pImmutableSamplers = NULL; |
| 771 | |
| 772 | VkDescriptorSetLayoutCreateInfo ds_layout_ci = {}; |
| 773 | ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO; |
| 774 | ds_layout_ci.pNext = NULL; |
| 775 | ds_layout_ci.bindingCount = 1; |
| 776 | ds_layout_ci.pBindings = &dsl_binding; |
| 777 | |
| 778 | VkDescriptorSetLayout ds_layout; |
| 779 | err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, |
| 780 | &ds_layout); |
| 781 | ASSERT_VK_SUCCESS(err); |
| 782 | |
| 783 | VkDescriptorSet descriptorSet; |
| 784 | VkDescriptorSetAllocateInfo ds_alloc_info = {}; |
| 785 | ds_alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO; |
| 786 | ds_alloc_info.descriptorSetCount = 1; |
| 787 | ds_alloc_info.descriptorPool = ds_pool; |
| 788 | ds_alloc_info.pSetLayouts = &ds_layout; |
| 789 | err = vkAllocateDescriptorSets(m_device->device(), &ds_alloc_info, |
| 790 | &descriptorSet); |
| 791 | ASSERT_VK_SUCCESS(err); |
| 792 | |
| 793 | VkPipelineLayoutCreateInfo pipeline_layout_ci = {}; |
| 794 | pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO; |
| 795 | pipeline_layout_ci.setLayoutCount = 1; |
| 796 | pipeline_layout_ci.pSetLayouts = &ds_layout; |
| 797 | |
| 798 | VkPipelineLayout pipeline_layout; |
| 799 | err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, |
| 800 | &pipeline_layout); |
| 801 | ASSERT_VK_SUCCESS(err); |
| 802 | |
| 803 | VkViewport vp = {}; // Just need dummy vp to point to |
| 804 | VkRect2D sc = {}; // dummy scissor to point to |
| 805 | |
| 806 | VkPipelineViewportStateCreateInfo vp_state_ci = {}; |
| 807 | vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO; |
| 808 | vp_state_ci.scissorCount = 1; |
| 809 | vp_state_ci.pScissors = ≻ |
| 810 | vp_state_ci.viewportCount = 1; |
| 811 | vp_state_ci.pViewports = &vp; |
| 812 | |
| 813 | VkPipelineRasterizationStateCreateInfo rs_state_ci = {}; |
| 814 | rs_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO; |
| 815 | rs_state_ci.polygonMode = VK_POLYGON_MODE_FILL; |
| 816 | rs_state_ci.cullMode = VK_CULL_MODE_BACK_BIT; |
| 817 | rs_state_ci.frontFace = VK_FRONT_FACE_COUNTER_CLOCKWISE; |
| 818 | rs_state_ci.depthClampEnable = VK_FALSE; |
| 819 | rs_state_ci.rasterizerDiscardEnable = VK_FALSE; |
| 820 | rs_state_ci.depthBiasEnable = VK_FALSE; |
| 821 | |
| 822 | VkGraphicsPipelineCreateInfo gp_ci = {}; |
| 823 | gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO; |
| 824 | gp_ci.pViewportState = &vp_state_ci; |
| 825 | gp_ci.pRasterizationState = &rs_state_ci; |
| 826 | gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT; |
| 827 | gp_ci.layout = pipeline_layout; |
| 828 | gp_ci.renderPass = renderPass(); |
| 829 | |
| 830 | VkPipelineCacheCreateInfo pc_ci = {}; |
| 831 | pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO; |
| 832 | pc_ci.initialDataSize = 0; |
| 833 | pc_ci.pInitialData = 0; |
| 834 | |
| 835 | VkPipeline pipeline; |
| 836 | VkPipelineCache pipelineCache; |
| 837 | |
| 838 | err = |
| 839 | vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache); |
| 840 | ASSERT_VK_SUCCESS(err); |
| 841 | |
| 842 | // Set VkPipelineRasterizationStateCreateInfo::pNext to an invalid value |
| 843 | VkApplicationInfo invalid_pnext_struct = {}; |
| 844 | rs_state_ci.pNext = &invalid_pnext_struct; |
| 845 | |
| 846 | vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, |
| 847 | &gp_ci, NULL, &pipeline); |
| 848 | m_errorMonitor->VerifyFound(); |
Tony Barbour | df4c004 | 2016-06-01 15:55:43 -0600 | [diff] [blame] | 849 | vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL); |
| 850 | vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL); |
| 851 | vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL); |
| 852 | vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL); |
| 853 | |
Dustin Graves | c99cf5a | 2016-05-09 14:40:29 -0600 | [diff] [blame] | 854 | } |
Dustin Graves | 5d33d53 | 2016-05-09 16:21:12 -0600 | [diff] [blame] | 855 | |
| 856 | TEST_F(VkLayerTest, UnrecognizedValue) { |
| 857 | TEST_DESCRIPTION( |
| 858 | "Specify unrecognized Vulkan enumeration, flags, and VkBool32 values"); |
| 859 | |
| 860 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 861 | |
| 862 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 863 | "does not fall within the begin..end " |
| 864 | "range of the core VkFormat " |
| 865 | "enumeration tokens"); |
| 866 | // Specify an invalid VkFormat value |
| 867 | // Expected to trigger an error with |
| 868 | // parameter_validation::validate_ranged_enum |
| 869 | VkFormatProperties format_properties; |
| 870 | vkGetPhysicalDeviceFormatProperties(gpu(), static_cast<VkFormat>(8000), |
| 871 | &format_properties); |
| 872 | m_errorMonitor->VerifyFound(); |
| 873 | |
| 874 | m_errorMonitor->SetDesiredFailureMsg( |
| 875 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 876 | "contains flag bits that are not recognized members of"); |
| 877 | // Specify an invalid VkFlags bitmask value |
| 878 | // Expected to trigger an error with parameter_validation::validate_flags |
| 879 | VkImageFormatProperties image_format_properties; |
| 880 | vkGetPhysicalDeviceImageFormatProperties( |
| 881 | gpu(), VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_TYPE_2D, |
| 882 | VK_IMAGE_TILING_OPTIMAL, static_cast<VkImageUsageFlags>(1 << 25), 0, |
| 883 | &image_format_properties); |
| 884 | m_errorMonitor->VerifyFound(); |
| 885 | |
| 886 | m_errorMonitor->SetDesiredFailureMsg( |
| 887 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 888 | "contains flag bits that are not recognized members of"); |
| 889 | // Specify an invalid VkFlags array entry |
| 890 | // Expected to trigger an error with |
| 891 | // parameter_validation::validate_flags_array |
| 892 | VkSemaphore semaphore = VK_NULL_HANDLE; |
| 893 | VkPipelineStageFlags stage_flags = |
| 894 | static_cast<VkPipelineStageFlags>(1 << 25); |
| 895 | VkSubmitInfo submit_info = {}; |
| 896 | submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO; |
| 897 | submit_info.waitSemaphoreCount = 1; |
| 898 | submit_info.pWaitSemaphores = &semaphore; |
| 899 | submit_info.pWaitDstStageMask = &stage_flags; |
| 900 | vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE); |
| 901 | m_errorMonitor->VerifyFound(); |
| 902 | |
| 903 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, |
| 904 | "is neither VK_TRUE nor VK_FALSE"); |
| 905 | // Specify an invalid VkBool32 value |
| 906 | // Expected to trigger a warning with |
| 907 | // parameter_validation::validate_bool32 |
| 908 | VkSampler sampler = VK_NULL_HANDLE; |
| 909 | VkSamplerCreateInfo sampler_info = {}; |
| 910 | sampler_info.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO; |
| 911 | sampler_info.pNext = NULL; |
| 912 | sampler_info.magFilter = VK_FILTER_NEAREST; |
| 913 | sampler_info.minFilter = VK_FILTER_NEAREST; |
| 914 | sampler_info.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST; |
| 915 | sampler_info.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE; |
| 916 | sampler_info.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE; |
| 917 | sampler_info.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE; |
| 918 | sampler_info.mipLodBias = 1.0; |
| 919 | sampler_info.maxAnisotropy = 1; |
| 920 | sampler_info.compareEnable = VK_FALSE; |
| 921 | sampler_info.compareOp = VK_COMPARE_OP_NEVER; |
| 922 | sampler_info.minLod = 1.0; |
| 923 | sampler_info.maxLod = 1.0; |
| 924 | sampler_info.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE; |
| 925 | sampler_info.unnormalizedCoordinates = VK_FALSE; |
| 926 | // Not VK_TRUE or VK_FALSE |
| 927 | sampler_info.anisotropyEnable = 3; |
| 928 | vkCreateSampler(m_device->device(), &sampler_info, NULL, &sampler); |
| 929 | m_errorMonitor->VerifyFound(); |
| 930 | } |
Dustin Graves | fce74c0 | 2016-05-10 11:42:58 -0600 | [diff] [blame] | 931 | |
| 932 | TEST_F(VkLayerTest, FailedReturnValue) { |
| 933 | TEST_DESCRIPTION("Check for a message describing a VkResult failure code"); |
| 934 | |
| 935 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 936 | |
Dustin Graves | 13c1e2b | 2016-05-16 15:31:02 -0600 | [diff] [blame] | 937 | // Find an unsupported image format |
| 938 | VkFormat unsupported = VK_FORMAT_UNDEFINED; |
| 939 | for (int f = VK_FORMAT_BEGIN_RANGE; f <= VK_FORMAT_END_RANGE; f++) { |
| 940 | VkFormat format = static_cast<VkFormat>(f); |
| 941 | VkFormatProperties fProps = m_device->format_properties(format); |
| 942 | if (format != VK_FORMAT_UNDEFINED && fProps.linearTilingFeatures == 0 && |
| 943 | fProps.optimalTilingFeatures == 0) { |
| 944 | unsupported = format; |
| 945 | break; |
| 946 | } |
| 947 | } |
| 948 | |
| 949 | if (unsupported != VK_FORMAT_UNDEFINED) { |
| 950 | m_errorMonitor->SetDesiredFailureMsg( |
| 951 | VK_DEBUG_REPORT_WARNING_BIT_EXT, |
| 952 | "the requested format is not supported on this device"); |
| 953 | // Specify an unsupported VkFormat value to generate a |
| 954 | // VK_ERROR_FORMAT_NOT_SUPPORTED return code |
| 955 | // Expected to trigger a warning from |
| 956 | // parameter_validation::validate_result |
| 957 | VkImageFormatProperties image_format_properties; |
| 958 | VkResult err = vkGetPhysicalDeviceImageFormatProperties( |
| 959 | gpu(), unsupported, VK_IMAGE_TYPE_2D, VK_IMAGE_TILING_OPTIMAL, |
| 960 | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, 0, &image_format_properties); |
| 961 | ASSERT_TRUE(err == VK_ERROR_FORMAT_NOT_SUPPORTED); |
| 962 | m_errorMonitor->VerifyFound(); |
| 963 | } |
Dustin Graves | fce74c0 | 2016-05-10 11:42:58 -0600 | [diff] [blame] | 964 | } |
Mark Lobodzinski | e090fef | 2016-06-09 17:04:56 -0600 | [diff] [blame] | 965 | |
| 966 | TEST_F(VkLayerTest, UpdateBufferAlignment) { |
| 967 | TEST_DESCRIPTION("Check alignment parameters for vkCmdUpdateBuffer"); |
| 968 | uint32_t updateData[] = { 1, 2, 3, 4, 5, 6, 7, 8 }; |
| 969 | |
| 970 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 971 | |
| 972 | VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT; |
| 973 | vk_testing::Buffer buffer; |
| 974 | buffer.init_as_dst(*m_device, (VkDeviceSize)20, reqs); |
| 975 | |
| 976 | BeginCommandBuffer(); |
| 977 | // Introduce failure by using dstOffset that is not multiple of 4 |
| 978 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 979 | " is not a multiple of 4"); |
| 980 | m_commandBuffer->UpdateBuffer(buffer.handle(), 1, 4, updateData); |
| 981 | m_errorMonitor->VerifyFound(); |
| 982 | |
| 983 | // Introduce failure by using dataSize that is not multiple of 4 |
| 984 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 985 | " is not a multiple of 4"); |
| 986 | m_commandBuffer->UpdateBuffer(buffer.handle(), 0, 6, updateData); |
| 987 | m_errorMonitor->VerifyFound(); |
| 988 | |
| 989 | // Introduce failure by using dataSize that is < 0 |
| 990 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 991 | "must be greater than zero and less than or equal to 65536"); |
| 992 | m_commandBuffer->UpdateBuffer(buffer.handle(), 0, -44, updateData); |
| 993 | m_errorMonitor->VerifyFound(); |
| 994 | |
| 995 | // Introduce failure by using dataSize that is > 65536 |
| 996 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 997 | "must be greater than zero and less than or equal to 65536"); |
| 998 | m_commandBuffer->UpdateBuffer(buffer.handle(), 0, 80000, updateData); |
| 999 | m_errorMonitor->VerifyFound(); |
| 1000 | |
| 1001 | EndCommandBuffer(); |
| 1002 | } |
| 1003 | |
| 1004 | TEST_F(VkLayerTest, FillBufferAlignment) { |
| 1005 | TEST_DESCRIPTION("Check alignment parameters for vkCmdFillBuffer"); |
| 1006 | |
| 1007 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 1008 | |
| 1009 | VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT; |
| 1010 | vk_testing::Buffer buffer; |
| 1011 | buffer.init_as_dst(*m_device, (VkDeviceSize)20, reqs); |
| 1012 | |
| 1013 | BeginCommandBuffer(); |
| 1014 | |
| 1015 | // Introduce failure by using dstOffset that is not multiple of 4 |
| 1016 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 1017 | " is not a multiple of 4"); |
| 1018 | m_commandBuffer->FillBuffer(buffer.handle(), 1, 4, 0x11111111); |
| 1019 | m_errorMonitor->VerifyFound(); |
| 1020 | |
| 1021 | // Introduce failure by using size that is not multiple of 4 |
| 1022 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 1023 | " is not a multiple of 4"); |
| 1024 | m_commandBuffer->FillBuffer(buffer.handle(), 0, 6, 0x11111111); |
| 1025 | m_errorMonitor->VerifyFound(); |
| 1026 | |
| 1027 | // Introduce failure by using size that is zero |
| 1028 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 1029 | "must be greater than zero"); |
| 1030 | m_commandBuffer->FillBuffer(buffer.handle(), 0, 0, 0x11111111); |
| 1031 | m_errorMonitor->VerifyFound(); |
| 1032 | |
| 1033 | EndCommandBuffer(); |
| 1034 | } |
Dustin Graves | 40f3582 | 2016-06-23 11:12:53 -0600 | [diff] [blame] | 1035 | |
| 1036 | // This is a positive test. No failures are expected. |
| 1037 | TEST_F(VkLayerTest, IgnoreUnrelatedDescriptor) { |
| 1038 | TEST_DESCRIPTION("Ensure that the vkUpdateDescriptorSet validation code " |
| 1039 | "is ignoring VkWriteDescriptorSet members that are not " |
| 1040 | "related to the descriptor type specified by " |
| 1041 | "VkWriteDescriptorSet::descriptorType. Correct " |
| 1042 | "validation behavior will result in the test running to " |
| 1043 | "completion without validation errors."); |
| 1044 | |
Dustin Graves | 5e2d8fc | 2016-07-07 16:18:49 -0600 | [diff] [blame] | 1045 | const uintptr_t invalid_ptr = 0xcdcdcdcd; |
| 1046 | |
Dustin Graves | 40f3582 | 2016-06-23 11:12:53 -0600 | [diff] [blame] | 1047 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 1048 | |
| 1049 | // Image Case |
| 1050 | { |
| 1051 | m_errorMonitor->ExpectSuccess(); |
| 1052 | |
| 1053 | VkImage image; |
| 1054 | const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM; |
| 1055 | const int32_t tex_width = 32; |
| 1056 | const int32_t tex_height = 32; |
| 1057 | VkImageCreateInfo image_create_info = {}; |
| 1058 | image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO; |
| 1059 | image_create_info.pNext = NULL; |
| 1060 | image_create_info.imageType = VK_IMAGE_TYPE_2D; |
| 1061 | image_create_info.format = tex_format; |
| 1062 | image_create_info.extent.width = tex_width; |
| 1063 | image_create_info.extent.height = tex_height; |
| 1064 | image_create_info.extent.depth = 1; |
| 1065 | image_create_info.mipLevels = 1; |
| 1066 | image_create_info.arrayLayers = 1; |
| 1067 | image_create_info.samples = VK_SAMPLE_COUNT_1_BIT; |
| 1068 | image_create_info.tiling = VK_IMAGE_TILING_LINEAR; |
| 1069 | image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT; |
| 1070 | image_create_info.flags = 0; |
| 1071 | VkResult err = |
| 1072 | vkCreateImage(m_device->device(), &image_create_info, NULL, &image); |
| 1073 | ASSERT_VK_SUCCESS(err); |
| 1074 | |
| 1075 | VkMemoryRequirements memory_reqs; |
| 1076 | VkDeviceMemory image_memory; |
| 1077 | bool pass; |
| 1078 | VkMemoryAllocateInfo memory_info = {}; |
| 1079 | memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO; |
| 1080 | memory_info.pNext = NULL; |
| 1081 | memory_info.allocationSize = 0; |
| 1082 | memory_info.memoryTypeIndex = 0; |
| 1083 | vkGetImageMemoryRequirements(m_device->device(), image, &memory_reqs); |
| 1084 | memory_info.allocationSize = memory_reqs.size; |
| 1085 | pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, |
| 1086 | &memory_info, 0); |
| 1087 | ASSERT_TRUE(pass); |
| 1088 | err = vkAllocateMemory(m_device->device(), &memory_info, NULL, |
| 1089 | &image_memory); |
| 1090 | ASSERT_VK_SUCCESS(err); |
| 1091 | err = vkBindImageMemory(m_device->device(), image, image_memory, 0); |
| 1092 | ASSERT_VK_SUCCESS(err); |
| 1093 | |
| 1094 | VkImageViewCreateInfo image_view_create_info = {}; |
| 1095 | image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO; |
| 1096 | image_view_create_info.image = image; |
| 1097 | image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D; |
| 1098 | image_view_create_info.format = tex_format; |
| 1099 | image_view_create_info.subresourceRange.layerCount = 1; |
| 1100 | image_view_create_info.subresourceRange.baseMipLevel = 0; |
| 1101 | image_view_create_info.subresourceRange.levelCount = 1; |
| 1102 | image_view_create_info.subresourceRange.aspectMask = |
| 1103 | VK_IMAGE_ASPECT_COLOR_BIT; |
| 1104 | |
| 1105 | VkImageView view; |
| 1106 | err = vkCreateImageView(m_device->device(), &image_view_create_info, |
| 1107 | NULL, &view); |
| 1108 | ASSERT_VK_SUCCESS(err); |
| 1109 | |
| 1110 | VkDescriptorPoolSize ds_type_count = {}; |
| 1111 | ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE; |
| 1112 | ds_type_count.descriptorCount = 1; |
| 1113 | |
| 1114 | VkDescriptorPoolCreateInfo ds_pool_ci = {}; |
| 1115 | ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO; |
| 1116 | ds_pool_ci.pNext = NULL; |
| 1117 | ds_pool_ci.maxSets = 1; |
| 1118 | ds_pool_ci.poolSizeCount = 1; |
| 1119 | ds_pool_ci.pPoolSizes = &ds_type_count; |
| 1120 | |
| 1121 | VkDescriptorPool ds_pool; |
| 1122 | err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, |
| 1123 | &ds_pool); |
| 1124 | ASSERT_VK_SUCCESS(err); |
| 1125 | |
| 1126 | VkDescriptorSetLayoutBinding dsl_binding = {}; |
| 1127 | dsl_binding.binding = 0; |
| 1128 | dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE; |
| 1129 | dsl_binding.descriptorCount = 1; |
| 1130 | dsl_binding.stageFlags = VK_SHADER_STAGE_ALL; |
| 1131 | dsl_binding.pImmutableSamplers = NULL; |
| 1132 | |
| 1133 | VkDescriptorSetLayoutCreateInfo ds_layout_ci = {}; |
| 1134 | ds_layout_ci.sType = |
| 1135 | VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO; |
| 1136 | ds_layout_ci.pNext = NULL; |
| 1137 | ds_layout_ci.bindingCount = 1; |
| 1138 | ds_layout_ci.pBindings = &dsl_binding; |
| 1139 | VkDescriptorSetLayout ds_layout; |
| 1140 | err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, |
| 1141 | NULL, &ds_layout); |
| 1142 | ASSERT_VK_SUCCESS(err); |
| 1143 | |
| 1144 | VkDescriptorSet descriptor_set; |
| 1145 | VkDescriptorSetAllocateInfo alloc_info = {}; |
| 1146 | alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO; |
| 1147 | alloc_info.descriptorSetCount = 1; |
| 1148 | alloc_info.descriptorPool = ds_pool; |
| 1149 | alloc_info.pSetLayouts = &ds_layout; |
| 1150 | err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, |
| 1151 | &descriptor_set); |
| 1152 | ASSERT_VK_SUCCESS(err); |
| 1153 | |
| 1154 | VkDescriptorImageInfo image_info = {}; |
| 1155 | image_info.imageView = view; |
| 1156 | image_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL; |
| 1157 | |
| 1158 | VkWriteDescriptorSet descriptor_write; |
| 1159 | memset(&descriptor_write, 0, sizeof(descriptor_write)); |
| 1160 | descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET; |
| 1161 | descriptor_write.dstSet = descriptor_set; |
| 1162 | descriptor_write.dstBinding = 0; |
| 1163 | descriptor_write.descriptorCount = 1; |
| 1164 | descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE; |
| 1165 | descriptor_write.pImageInfo = &image_info; |
| 1166 | |
| 1167 | // Set pBufferInfo and pTexelBufferView to invalid values, which should |
| 1168 | // be |
| 1169 | // ignored for descriptorType == VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE. |
| 1170 | // This will most likely produce a crash if the parameter_validation |
| 1171 | // layer |
| 1172 | // does not correctly ignore pBufferInfo. |
| 1173 | descriptor_write.pBufferInfo = |
Dustin Graves | 5e2d8fc | 2016-07-07 16:18:49 -0600 | [diff] [blame] | 1174 | reinterpret_cast<const VkDescriptorBufferInfo *>(invalid_ptr); |
Dustin Graves | 40f3582 | 2016-06-23 11:12:53 -0600 | [diff] [blame] | 1175 | descriptor_write.pTexelBufferView = |
Dustin Graves | 5e2d8fc | 2016-07-07 16:18:49 -0600 | [diff] [blame] | 1176 | reinterpret_cast<const VkBufferView *>(invalid_ptr); |
Dustin Graves | 40f3582 | 2016-06-23 11:12:53 -0600 | [diff] [blame] | 1177 | |
| 1178 | vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, |
| 1179 | NULL); |
| 1180 | |
| 1181 | m_errorMonitor->VerifyNotFound(); |
| 1182 | |
| 1183 | vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptor_set); |
| 1184 | vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL); |
| 1185 | vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL); |
| 1186 | vkDestroyImageView(m_device->device(), view, NULL); |
| 1187 | vkDestroyImage(m_device->device(), image, NULL); |
| 1188 | vkFreeMemory(m_device->device(), image_memory, NULL); |
| 1189 | } |
| 1190 | |
| 1191 | // Buffer Case |
| 1192 | { |
| 1193 | m_errorMonitor->ExpectSuccess(); |
| 1194 | |
| 1195 | VkBuffer buffer; |
| 1196 | uint32_t queue_family_index = 0; |
| 1197 | VkBufferCreateInfo buffer_create_info = {}; |
| 1198 | buffer_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO; |
| 1199 | buffer_create_info.size = 1024; |
| 1200 | buffer_create_info.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT; |
| 1201 | buffer_create_info.queueFamilyIndexCount = 1; |
| 1202 | buffer_create_info.pQueueFamilyIndices = &queue_family_index; |
| 1203 | |
| 1204 | VkResult err = vkCreateBuffer(m_device->device(), &buffer_create_info, |
| 1205 | NULL, &buffer); |
| 1206 | ASSERT_VK_SUCCESS(err); |
| 1207 | |
| 1208 | VkMemoryRequirements memory_reqs; |
| 1209 | VkDeviceMemory buffer_memory; |
| 1210 | bool pass; |
| 1211 | VkMemoryAllocateInfo memory_info = {}; |
| 1212 | memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO; |
| 1213 | memory_info.pNext = NULL; |
| 1214 | memory_info.allocationSize = 0; |
| 1215 | memory_info.memoryTypeIndex = 0; |
| 1216 | |
| 1217 | vkGetBufferMemoryRequirements(m_device->device(), buffer, &memory_reqs); |
| 1218 | memory_info.allocationSize = memory_reqs.size; |
| 1219 | pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, |
| 1220 | &memory_info, 0); |
| 1221 | ASSERT_TRUE(pass); |
| 1222 | |
| 1223 | err = vkAllocateMemory(m_device->device(), &memory_info, NULL, |
| 1224 | &buffer_memory); |
| 1225 | ASSERT_VK_SUCCESS(err); |
| 1226 | err = vkBindBufferMemory(m_device->device(), buffer, buffer_memory, 0); |
| 1227 | ASSERT_VK_SUCCESS(err); |
| 1228 | |
| 1229 | VkDescriptorPoolSize ds_type_count = {}; |
| 1230 | ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 1231 | ds_type_count.descriptorCount = 1; |
| 1232 | |
| 1233 | VkDescriptorPoolCreateInfo ds_pool_ci = {}; |
| 1234 | ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO; |
| 1235 | ds_pool_ci.pNext = NULL; |
| 1236 | ds_pool_ci.maxSets = 1; |
| 1237 | ds_pool_ci.poolSizeCount = 1; |
| 1238 | ds_pool_ci.pPoolSizes = &ds_type_count; |
| 1239 | |
| 1240 | VkDescriptorPool ds_pool; |
| 1241 | err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, |
| 1242 | &ds_pool); |
| 1243 | ASSERT_VK_SUCCESS(err); |
| 1244 | |
| 1245 | VkDescriptorSetLayoutBinding dsl_binding = {}; |
| 1246 | dsl_binding.binding = 0; |
| 1247 | dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 1248 | dsl_binding.descriptorCount = 1; |
| 1249 | dsl_binding.stageFlags = VK_SHADER_STAGE_ALL; |
| 1250 | dsl_binding.pImmutableSamplers = NULL; |
| 1251 | |
| 1252 | VkDescriptorSetLayoutCreateInfo ds_layout_ci = {}; |
| 1253 | ds_layout_ci.sType = |
| 1254 | VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO; |
| 1255 | ds_layout_ci.pNext = NULL; |
| 1256 | ds_layout_ci.bindingCount = 1; |
| 1257 | ds_layout_ci.pBindings = &dsl_binding; |
| 1258 | VkDescriptorSetLayout ds_layout; |
| 1259 | err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, |
| 1260 | NULL, &ds_layout); |
| 1261 | ASSERT_VK_SUCCESS(err); |
| 1262 | |
| 1263 | VkDescriptorSet descriptor_set; |
| 1264 | VkDescriptorSetAllocateInfo alloc_info = {}; |
| 1265 | alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO; |
| 1266 | alloc_info.descriptorSetCount = 1; |
| 1267 | alloc_info.descriptorPool = ds_pool; |
| 1268 | alloc_info.pSetLayouts = &ds_layout; |
| 1269 | err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, |
| 1270 | &descriptor_set); |
| 1271 | ASSERT_VK_SUCCESS(err); |
| 1272 | |
| 1273 | VkDescriptorBufferInfo buffer_info = {}; |
| 1274 | buffer_info.buffer = buffer; |
| 1275 | buffer_info.offset = 0; |
| 1276 | buffer_info.range = 1024; |
| 1277 | |
| 1278 | VkWriteDescriptorSet descriptor_write; |
| 1279 | memset(&descriptor_write, 0, sizeof(descriptor_write)); |
| 1280 | descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET; |
| 1281 | descriptor_write.dstSet = descriptor_set; |
| 1282 | descriptor_write.dstBinding = 0; |
| 1283 | descriptor_write.descriptorCount = 1; |
| 1284 | descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 1285 | descriptor_write.pBufferInfo = &buffer_info; |
| 1286 | |
| 1287 | // Set pImageInfo and pTexelBufferView to invalid values, which should |
| 1288 | // be |
| 1289 | // ignored for descriptorType == VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER. |
| 1290 | // This will most likely produce a crash if the parameter_validation |
| 1291 | // layer |
| 1292 | // does not correctly ignore pImageInfo. |
| 1293 | descriptor_write.pImageInfo = |
Dustin Graves | 5e2d8fc | 2016-07-07 16:18:49 -0600 | [diff] [blame] | 1294 | reinterpret_cast<const VkDescriptorImageInfo *>(invalid_ptr); |
Dustin Graves | 40f3582 | 2016-06-23 11:12:53 -0600 | [diff] [blame] | 1295 | descriptor_write.pTexelBufferView = |
Dustin Graves | 5e2d8fc | 2016-07-07 16:18:49 -0600 | [diff] [blame] | 1296 | reinterpret_cast<const VkBufferView *>(invalid_ptr); |
Dustin Graves | 40f3582 | 2016-06-23 11:12:53 -0600 | [diff] [blame] | 1297 | |
| 1298 | vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, |
| 1299 | NULL); |
| 1300 | |
| 1301 | m_errorMonitor->VerifyNotFound(); |
| 1302 | |
| 1303 | vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptor_set); |
| 1304 | vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL); |
| 1305 | vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL); |
| 1306 | vkDestroyBuffer(m_device->device(), buffer, NULL); |
| 1307 | vkFreeMemory(m_device->device(), buffer_memory, NULL); |
| 1308 | } |
| 1309 | |
| 1310 | // Texel Buffer Case |
| 1311 | { |
| 1312 | m_errorMonitor->ExpectSuccess(); |
| 1313 | |
| 1314 | VkBuffer buffer; |
| 1315 | uint32_t queue_family_index = 0; |
| 1316 | VkBufferCreateInfo buffer_create_info = {}; |
| 1317 | buffer_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO; |
| 1318 | buffer_create_info.size = 1024; |
| 1319 | buffer_create_info.usage = VK_BUFFER_USAGE_STORAGE_TEXEL_BUFFER_BIT; |
| 1320 | buffer_create_info.queueFamilyIndexCount = 1; |
| 1321 | buffer_create_info.pQueueFamilyIndices = &queue_family_index; |
| 1322 | |
| 1323 | VkResult err = vkCreateBuffer(m_device->device(), &buffer_create_info, |
| 1324 | NULL, &buffer); |
| 1325 | ASSERT_VK_SUCCESS(err); |
| 1326 | |
| 1327 | VkMemoryRequirements memory_reqs; |
| 1328 | VkDeviceMemory buffer_memory; |
| 1329 | bool pass; |
| 1330 | VkMemoryAllocateInfo memory_info = {}; |
| 1331 | memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO; |
| 1332 | memory_info.pNext = NULL; |
| 1333 | memory_info.allocationSize = 0; |
| 1334 | memory_info.memoryTypeIndex = 0; |
| 1335 | |
| 1336 | vkGetBufferMemoryRequirements(m_device->device(), buffer, &memory_reqs); |
| 1337 | memory_info.allocationSize = memory_reqs.size; |
| 1338 | pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, |
| 1339 | &memory_info, 0); |
| 1340 | ASSERT_TRUE(pass); |
| 1341 | |
| 1342 | err = vkAllocateMemory(m_device->device(), &memory_info, NULL, |
| 1343 | &buffer_memory); |
| 1344 | ASSERT_VK_SUCCESS(err); |
| 1345 | err = vkBindBufferMemory(m_device->device(), buffer, buffer_memory, 0); |
| 1346 | ASSERT_VK_SUCCESS(err); |
| 1347 | |
| 1348 | VkBufferViewCreateInfo buff_view_ci = {}; |
| 1349 | buff_view_ci.sType = VK_STRUCTURE_TYPE_BUFFER_VIEW_CREATE_INFO; |
| 1350 | buff_view_ci.buffer = buffer; |
| 1351 | buff_view_ci.format = VK_FORMAT_R8_UNORM; |
| 1352 | buff_view_ci.range = VK_WHOLE_SIZE; |
| 1353 | VkBufferView buffer_view; |
| 1354 | err = vkCreateBufferView(m_device->device(), &buff_view_ci, NULL, |
| 1355 | &buffer_view); |
| 1356 | |
| 1357 | VkDescriptorPoolSize ds_type_count = {}; |
| 1358 | ds_type_count.type = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER; |
| 1359 | ds_type_count.descriptorCount = 1; |
| 1360 | |
| 1361 | VkDescriptorPoolCreateInfo ds_pool_ci = {}; |
| 1362 | ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO; |
| 1363 | ds_pool_ci.pNext = NULL; |
| 1364 | ds_pool_ci.maxSets = 1; |
| 1365 | ds_pool_ci.poolSizeCount = 1; |
| 1366 | ds_pool_ci.pPoolSizes = &ds_type_count; |
| 1367 | |
| 1368 | VkDescriptorPool ds_pool; |
| 1369 | err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, |
| 1370 | &ds_pool); |
| 1371 | ASSERT_VK_SUCCESS(err); |
| 1372 | |
| 1373 | VkDescriptorSetLayoutBinding dsl_binding = {}; |
| 1374 | dsl_binding.binding = 0; |
| 1375 | dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER; |
| 1376 | dsl_binding.descriptorCount = 1; |
| 1377 | dsl_binding.stageFlags = VK_SHADER_STAGE_ALL; |
| 1378 | dsl_binding.pImmutableSamplers = NULL; |
| 1379 | |
| 1380 | VkDescriptorSetLayoutCreateInfo ds_layout_ci = {}; |
| 1381 | ds_layout_ci.sType = |
| 1382 | VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO; |
| 1383 | ds_layout_ci.pNext = NULL; |
| 1384 | ds_layout_ci.bindingCount = 1; |
| 1385 | ds_layout_ci.pBindings = &dsl_binding; |
| 1386 | VkDescriptorSetLayout ds_layout; |
| 1387 | err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, |
| 1388 | NULL, &ds_layout); |
| 1389 | ASSERT_VK_SUCCESS(err); |
| 1390 | |
| 1391 | VkDescriptorSet descriptor_set; |
| 1392 | VkDescriptorSetAllocateInfo alloc_info = {}; |
| 1393 | alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO; |
| 1394 | alloc_info.descriptorSetCount = 1; |
| 1395 | alloc_info.descriptorPool = ds_pool; |
| 1396 | alloc_info.pSetLayouts = &ds_layout; |
| 1397 | err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, |
| 1398 | &descriptor_set); |
| 1399 | ASSERT_VK_SUCCESS(err); |
| 1400 | |
| 1401 | VkWriteDescriptorSet descriptor_write; |
| 1402 | memset(&descriptor_write, 0, sizeof(descriptor_write)); |
| 1403 | descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET; |
| 1404 | descriptor_write.dstSet = descriptor_set; |
| 1405 | descriptor_write.dstBinding = 0; |
| 1406 | descriptor_write.descriptorCount = 1; |
| 1407 | descriptor_write.descriptorType = |
| 1408 | VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER; |
| 1409 | descriptor_write.pTexelBufferView = &buffer_view; |
| 1410 | |
| 1411 | // Set pImageInfo and pBufferInfo to invalid values, which should be |
| 1412 | // ignored for descriptorType == |
| 1413 | // VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER. |
| 1414 | // This will most likely produce a crash if the parameter_validation |
| 1415 | // layer |
| 1416 | // does not correctly ignore pImageInfo and pBufferInfo. |
| 1417 | descriptor_write.pImageInfo = |
Dustin Graves | 5e2d8fc | 2016-07-07 16:18:49 -0600 | [diff] [blame] | 1418 | reinterpret_cast<const VkDescriptorImageInfo *>(invalid_ptr); |
Dustin Graves | 40f3582 | 2016-06-23 11:12:53 -0600 | [diff] [blame] | 1419 | descriptor_write.pBufferInfo = |
Dustin Graves | 5e2d8fc | 2016-07-07 16:18:49 -0600 | [diff] [blame] | 1420 | reinterpret_cast<const VkDescriptorBufferInfo *>(invalid_ptr); |
Dustin Graves | 40f3582 | 2016-06-23 11:12:53 -0600 | [diff] [blame] | 1421 | |
| 1422 | vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, |
| 1423 | NULL); |
| 1424 | |
| 1425 | m_errorMonitor->VerifyNotFound(); |
| 1426 | |
| 1427 | vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptor_set); |
| 1428 | vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL); |
| 1429 | vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL); |
| 1430 | vkDestroyBufferView(m_device->device(), buffer_view, NULL); |
| 1431 | vkDestroyBuffer(m_device->device(), buffer, NULL); |
| 1432 | vkFreeMemory(m_device->device(), buffer_memory, NULL); |
| 1433 | } |
| 1434 | } |
Dustin Graves | ffa90fa | 2016-05-06 11:20:38 -0600 | [diff] [blame] | 1435 | #endif // PARAMETER_VALIDATION_TESTS |
| 1436 | |
Tobin Ehlis | 0788f52 | 2015-05-26 16:11:58 -0600 | [diff] [blame] | 1437 | #if MEM_TRACKER_TESTS |
Tobin Ehlis | 8fab656 | 2015-12-01 09:57:09 -0700 | [diff] [blame] | 1438 | #if 0 |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 1439 | TEST_F(VkLayerTest, CallResetCommandBufferBeforeCompletion) |
Mark Lobodzinski | ccb2b04 | 2015-05-19 10:28:29 -0500 | [diff] [blame] | 1440 | { |
| 1441 | vk_testing::Fence testFence; |
Mark Lobodzinski | ccb2b04 | 2015-05-19 10:28:29 -0500 | [diff] [blame] | 1442 | VkFenceCreateInfo fenceInfo = {}; |
| 1443 | fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO; |
| 1444 | fenceInfo.pNext = NULL; |
| 1445 | fenceInfo.flags = 0; |
| 1446 | |
Courtney Goeltzenleuchter | 7415d5a | 2015-12-09 15:48:16 -0700 | [diff] [blame] | 1447 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Resetting CB"); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 1448 | |
Mark Lobodzinski | ccb2b04 | 2015-05-19 10:28:29 -0500 | [diff] [blame] | 1449 | ASSERT_NO_FATAL_FAILURE(InitState()); |
Tony Barbour | c1eb1a5 | 2015-07-20 13:00:10 -0600 | [diff] [blame] | 1450 | |
| 1451 | VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT; |
| 1452 | vk_testing::Buffer buffer; |
| 1453 | buffer.init_as_dst(*m_device, (VkDeviceSize)20, reqs); |
Mark Lobodzinski | ccb2b04 | 2015-05-19 10:28:29 -0500 | [diff] [blame] | 1454 | |
Tony Barbour | fe3351b | 2015-07-28 10:17:20 -0600 | [diff] [blame] | 1455 | BeginCommandBuffer(); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 1456 | m_commandBuffer->FillBuffer(buffer.handle(), 0, 4, 0x11111111); |
Tony Barbour | fe3351b | 2015-07-28 10:17:20 -0600 | [diff] [blame] | 1457 | EndCommandBuffer(); |
Mark Lobodzinski | ccb2b04 | 2015-05-19 10:28:29 -0500 | [diff] [blame] | 1458 | |
| 1459 | testFence.init(*m_device, fenceInfo); |
| 1460 | |
| 1461 | // Bypass framework since it does the waits automatically |
| 1462 | VkResult err = VK_SUCCESS; |
Courtney Goeltzenleuchter | 806c700 | 2015-10-27 11:22:14 -0600 | [diff] [blame] | 1463 | VkSubmitInfo submit_info; |
Chia-I Wu | f9be13c | 2015-10-26 20:37:06 +0800 | [diff] [blame] | 1464 | submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO; |
| 1465 | submit_info.pNext = NULL; |
Chia-I Wu | d50a7d7 | 2015-10-26 20:48:51 +0800 | [diff] [blame] | 1466 | submit_info.waitSemaphoreCount = 0; |
Courtney Goeltzenleuchter | 806c700 | 2015-10-27 11:22:14 -0600 | [diff] [blame] | 1467 | submit_info.pWaitSemaphores = NULL; |
Jon Ashburn | 7f9716c | 2015-12-30 16:42:50 -0700 | [diff] [blame] | 1468 | submit_info.pWaitDstStageMask = NULL; |
Chia-I Wu | d50a7d7 | 2015-10-26 20:48:51 +0800 | [diff] [blame] | 1469 | submit_info.commandBufferCount = 1; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 1470 | submit_info.pCommandBuffers = &m_commandBuffer->handle(); |
Chia-I Wu | d50a7d7 | 2015-10-26 20:48:51 +0800 | [diff] [blame] | 1471 | submit_info.signalSemaphoreCount = 0; |
Courtney Goeltzenleuchter | 806c700 | 2015-10-27 11:22:14 -0600 | [diff] [blame] | 1472 | submit_info.pSignalSemaphores = NULL; |
Courtney Goeltzenleuchter | 646b907 | 2015-10-20 18:04:07 -0600 | [diff] [blame] | 1473 | |
| 1474 | err = vkQueueSubmit( m_device->m_queue, 1, &submit_info, testFence.handle()); |
Mark Lobodzinski | ccb2b04 | 2015-05-19 10:28:29 -0500 | [diff] [blame] | 1475 | ASSERT_VK_SUCCESS( err ); |
| 1476 | |
Mark Lobodzinski | ccb2b04 | 2015-05-19 10:28:29 -0500 | [diff] [blame] | 1477 | // Introduce failure by calling begin again before checking fence |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 1478 | vkResetCommandBuffer(m_commandBuffer->handle(), 0); |
Mark Lobodzinski | ccb2b04 | 2015-05-19 10:28:29 -0500 | [diff] [blame] | 1479 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 1480 | m_errorMonitor->VerifyFound(); |
Mark Lobodzinski | ccb2b04 | 2015-05-19 10:28:29 -0500 | [diff] [blame] | 1481 | } |
| 1482 | |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 1483 | TEST_F(VkLayerTest, CallBeginCommandBufferBeforeCompletion) |
Mark Lobodzinski | ccb2b04 | 2015-05-19 10:28:29 -0500 | [diff] [blame] | 1484 | { |
| 1485 | vk_testing::Fence testFence; |
Mark Lobodzinski | ccb2b04 | 2015-05-19 10:28:29 -0500 | [diff] [blame] | 1486 | VkFenceCreateInfo fenceInfo = {}; |
| 1487 | fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO; |
| 1488 | fenceInfo.pNext = NULL; |
| 1489 | fenceInfo.flags = 0; |
| 1490 | |
Courtney Goeltzenleuchter | 7415d5a | 2015-12-09 15:48:16 -0700 | [diff] [blame] | 1491 | 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] | 1492 | |
Mark Lobodzinski | ccb2b04 | 2015-05-19 10:28:29 -0500 | [diff] [blame] | 1493 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 1494 | ASSERT_NO_FATAL_FAILURE(InitViewport()); |
| 1495 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 1496 | |
Tony Barbour | fe3351b | 2015-07-28 10:17:20 -0600 | [diff] [blame] | 1497 | BeginCommandBuffer(); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 1498 | 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] | 1499 | EndCommandBuffer(); |
Mark Lobodzinski | ccb2b04 | 2015-05-19 10:28:29 -0500 | [diff] [blame] | 1500 | |
| 1501 | testFence.init(*m_device, fenceInfo); |
| 1502 | |
| 1503 | // Bypass framework since it does the waits automatically |
| 1504 | VkResult err = VK_SUCCESS; |
Courtney Goeltzenleuchter | 806c700 | 2015-10-27 11:22:14 -0600 | [diff] [blame] | 1505 | VkSubmitInfo submit_info; |
Chia-I Wu | f9be13c | 2015-10-26 20:37:06 +0800 | [diff] [blame] | 1506 | submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO; |
| 1507 | submit_info.pNext = NULL; |
Chia-I Wu | d50a7d7 | 2015-10-26 20:48:51 +0800 | [diff] [blame] | 1508 | submit_info.waitSemaphoreCount = 0; |
Courtney Goeltzenleuchter | 806c700 | 2015-10-27 11:22:14 -0600 | [diff] [blame] | 1509 | submit_info.pWaitSemaphores = NULL; |
Jon Ashburn | 7f9716c | 2015-12-30 16:42:50 -0700 | [diff] [blame] | 1510 | submit_info.pWaitDstStageMask = NULL; |
Chia-I Wu | d50a7d7 | 2015-10-26 20:48:51 +0800 | [diff] [blame] | 1511 | submit_info.commandBufferCount = 1; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 1512 | submit_info.pCommandBuffers = &m_commandBuffer->handle(); |
Chia-I Wu | d50a7d7 | 2015-10-26 20:48:51 +0800 | [diff] [blame] | 1513 | submit_info.signalSemaphoreCount = 0; |
Courtney Goeltzenleuchter | 806c700 | 2015-10-27 11:22:14 -0600 | [diff] [blame] | 1514 | submit_info.pSignalSemaphores = NULL; |
Courtney Goeltzenleuchter | 646b907 | 2015-10-20 18:04:07 -0600 | [diff] [blame] | 1515 | |
| 1516 | err = vkQueueSubmit( m_device->m_queue, 1, &submit_info, testFence.handle()); |
Mark Lobodzinski | ccb2b04 | 2015-05-19 10:28:29 -0500 | [diff] [blame] | 1517 | ASSERT_VK_SUCCESS( err ); |
| 1518 | |
Jon Ashburn | f19916e | 2016-01-11 13:12:43 -0700 | [diff] [blame] | 1519 | VkCommandBufferInheritanceInfo hinfo = {}; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 1520 | VkCommandBufferBeginInfo info = {}; |
| 1521 | info.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT; |
| 1522 | info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO; |
Mark Lobodzinski | 5fcc421 | 2015-09-14 17:43:42 -0600 | [diff] [blame] | 1523 | info.renderPass = VK_NULL_HANDLE; |
| 1524 | info.subpass = 0; |
| 1525 | info.framebuffer = VK_NULL_HANDLE; |
Chia-I Wu | b8d47ae | 2015-11-11 10:18:12 +0800 | [diff] [blame] | 1526 | info.occlusionQueryEnable = VK_FALSE; |
| 1527 | info.queryFlags = 0; |
| 1528 | info.pipelineStatistics = 0; |
Mark Lobodzinski | 5fcc421 | 2015-09-14 17:43:42 -0600 | [diff] [blame] | 1529 | |
| 1530 | // Introduce failure by calling BCB again before checking fence |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 1531 | vkBeginCommandBuffer(m_commandBuffer->handle(), &info); |
Mark Lobodzinski | ccb2b04 | 2015-05-19 10:28:29 -0500 | [diff] [blame] | 1532 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 1533 | m_errorMonitor->VerifyFound(); |
Mark Lobodzinski | ccb2b04 | 2015-05-19 10:28:29 -0500 | [diff] [blame] | 1534 | } |
Tobin Ehlis | 8fab656 | 2015-12-01 09:57:09 -0700 | [diff] [blame] | 1535 | #endif |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 1536 | |
Mark Lobodzinski | 152fe25 | 2016-05-03 16:49:15 -0600 | [diff] [blame] | 1537 | // This is a positive test. No failures are expected. |
| 1538 | TEST_F(VkLayerTest, TestAliasedMemoryTracking) { |
| 1539 | VkResult err; |
| 1540 | bool pass; |
| 1541 | |
| 1542 | TEST_DESCRIPTION("Create a buffer, allocate memory, bind memory, destroy " |
| 1543 | "the buffer, create an image, and bind the same memory to " |
| 1544 | "it"); |
| 1545 | |
| 1546 | m_errorMonitor->ExpectSuccess(); |
| 1547 | |
| 1548 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 1549 | |
| 1550 | VkBuffer buffer; |
| 1551 | VkImage image; |
| 1552 | VkDeviceMemory mem; |
| 1553 | VkMemoryRequirements mem_reqs; |
| 1554 | |
| 1555 | VkBufferCreateInfo buf_info = {}; |
| 1556 | buf_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO; |
| 1557 | buf_info.pNext = NULL; |
| 1558 | buf_info.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT; |
| 1559 | buf_info.size = 256; |
| 1560 | buf_info.queueFamilyIndexCount = 0; |
| 1561 | buf_info.pQueueFamilyIndices = NULL; |
| 1562 | buf_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE; |
| 1563 | buf_info.flags = 0; |
| 1564 | err = vkCreateBuffer(m_device->device(), &buf_info, NULL, &buffer); |
| 1565 | ASSERT_VK_SUCCESS(err); |
| 1566 | |
| 1567 | vkGetBufferMemoryRequirements(m_device->device(), buffer, &mem_reqs); |
| 1568 | |
| 1569 | VkMemoryAllocateInfo alloc_info = {}; |
| 1570 | alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO; |
| 1571 | alloc_info.pNext = NULL; |
| 1572 | alloc_info.memoryTypeIndex = 0; |
| 1573 | |
| 1574 | // Ensure memory is big enough for both bindings |
| 1575 | alloc_info.allocationSize = 0x10000; |
| 1576 | |
| 1577 | pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &alloc_info, |
| 1578 | VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT); |
| 1579 | if (!pass) { |
| 1580 | vkDestroyBuffer(m_device->device(), buffer, NULL); |
| 1581 | return; |
| 1582 | } |
| 1583 | |
| 1584 | err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem); |
| 1585 | ASSERT_VK_SUCCESS(err); |
| 1586 | |
| 1587 | uint8_t *pData; |
| 1588 | err = vkMapMemory(m_device->device(), mem, 0, mem_reqs.size, 0, |
| 1589 | (void **)&pData); |
| 1590 | ASSERT_VK_SUCCESS(err); |
| 1591 | |
Mark Lobodzinski | 2abefa9 | 2016-05-05 11:45:57 -0600 | [diff] [blame] | 1592 | memset(pData, 0xCADECADE, static_cast<size_t>(mem_reqs.size)); |
Mark Lobodzinski | 152fe25 | 2016-05-03 16:49:15 -0600 | [diff] [blame] | 1593 | |
| 1594 | vkUnmapMemory(m_device->device(), mem); |
| 1595 | |
| 1596 | err = vkBindBufferMemory(m_device->device(), buffer, mem, 0); |
| 1597 | ASSERT_VK_SUCCESS(err); |
| 1598 | |
| 1599 | // NOW, destroy the buffer. Obviously, the resource no longer occupies this |
| 1600 | // memory. In fact, it was never used by the GPU. |
| 1601 | // Just be be sure, wait for idle. |
| 1602 | vkDestroyBuffer(m_device->device(), buffer, NULL); |
| 1603 | vkDeviceWaitIdle(m_device->device()); |
| 1604 | |
| 1605 | VkImageCreateInfo image_create_info = {}; |
| 1606 | image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO; |
| 1607 | image_create_info.pNext = NULL; |
| 1608 | image_create_info.imageType = VK_IMAGE_TYPE_2D; |
| 1609 | image_create_info.format = VK_FORMAT_R8G8B8A8_UNORM; |
| 1610 | image_create_info.extent.width = 64; |
| 1611 | image_create_info.extent.height = 64; |
| 1612 | image_create_info.extent.depth = 1; |
| 1613 | image_create_info.mipLevels = 1; |
| 1614 | image_create_info.arrayLayers = 1; |
| 1615 | image_create_info.samples = VK_SAMPLE_COUNT_1_BIT; |
| 1616 | image_create_info.tiling = VK_IMAGE_TILING_LINEAR; |
| 1617 | image_create_info.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED; |
| 1618 | image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT; |
| 1619 | image_create_info.queueFamilyIndexCount = 0; |
| 1620 | image_create_info.pQueueFamilyIndices = NULL; |
| 1621 | image_create_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE; |
| 1622 | image_create_info.flags = 0; |
| 1623 | |
| 1624 | VkMemoryAllocateInfo mem_alloc = {}; |
| 1625 | mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO; |
| 1626 | mem_alloc.pNext = NULL; |
| 1627 | mem_alloc.allocationSize = 0; |
| 1628 | mem_alloc.memoryTypeIndex = 0; |
| 1629 | |
| 1630 | /* Create a mappable image. It will be the texture if linear images are ok |
| 1631 | * to be textures or it will be the staging image if they are not. |
| 1632 | */ |
| 1633 | err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image); |
| 1634 | ASSERT_VK_SUCCESS(err); |
| 1635 | |
| 1636 | vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs); |
| 1637 | |
| 1638 | mem_alloc.allocationSize = mem_reqs.size; |
| 1639 | |
| 1640 | pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, |
| 1641 | VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT); |
| 1642 | if (!pass) { |
| 1643 | vkDestroyImage(m_device->device(), image, NULL); |
| 1644 | return; |
| 1645 | } |
| 1646 | |
Tobin Ehlis | 077ded3 | 2016-05-12 17:39:13 -0600 | [diff] [blame] | 1647 | // VALIDATION FAILURE: |
Mark Lobodzinski | 152fe25 | 2016-05-03 16:49:15 -0600 | [diff] [blame] | 1648 | err = vkBindImageMemory(m_device->device(), image, mem, 0); |
| 1649 | ASSERT_VK_SUCCESS(err); |
| 1650 | |
| 1651 | m_errorMonitor->VerifyNotFound(); |
| 1652 | |
Tony Barbour | df4c004 | 2016-06-01 15:55:43 -0600 | [diff] [blame] | 1653 | vkFreeMemory(m_device->device(), mem, NULL); |
Mark Lobodzinski | 152fe25 | 2016-05-03 16:49:15 -0600 | [diff] [blame] | 1654 | vkDestroyBuffer(m_device->device(), buffer, NULL); |
| 1655 | vkDestroyImage(m_device->device(), image, NULL); |
| 1656 | } |
| 1657 | |
Tobin Ehlis | f11be98 | 2016-05-11 13:52:53 -0600 | [diff] [blame] | 1658 | TEST_F(VkLayerTest, InvalidMemoryAliasing) { |
| 1659 | TEST_DESCRIPTION("Create a buffer and image, allocate memory, and bind the " |
| 1660 | "buffer and image to memory such that they will alias."); |
| 1661 | VkResult err; |
| 1662 | bool pass; |
| 1663 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 1664 | |
Tobin Ehlis | 077ded3 | 2016-05-12 17:39:13 -0600 | [diff] [blame] | 1665 | VkBuffer buffer, buffer2; |
Tobin Ehlis | f11be98 | 2016-05-11 13:52:53 -0600 | [diff] [blame] | 1666 | VkImage image; |
| 1667 | VkDeviceMemory mem; // buffer will be bound first |
| 1668 | VkDeviceMemory mem_img; // image bound first |
Tobin Ehlis | 077ded3 | 2016-05-12 17:39:13 -0600 | [diff] [blame] | 1669 | VkMemoryRequirements buff_mem_reqs, img_mem_reqs; |
Tobin Ehlis | f11be98 | 2016-05-11 13:52:53 -0600 | [diff] [blame] | 1670 | |
| 1671 | VkBufferCreateInfo buf_info = {}; |
| 1672 | buf_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO; |
| 1673 | buf_info.pNext = NULL; |
| 1674 | buf_info.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT; |
| 1675 | buf_info.size = 256; |
| 1676 | buf_info.queueFamilyIndexCount = 0; |
| 1677 | buf_info.pQueueFamilyIndices = NULL; |
| 1678 | buf_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE; |
| 1679 | buf_info.flags = 0; |
| 1680 | err = vkCreateBuffer(m_device->device(), &buf_info, NULL, &buffer); |
| 1681 | ASSERT_VK_SUCCESS(err); |
| 1682 | |
Tobin Ehlis | 077ded3 | 2016-05-12 17:39:13 -0600 | [diff] [blame] | 1683 | vkGetBufferMemoryRequirements(m_device->device(), buffer, &buff_mem_reqs); |
Tobin Ehlis | f11be98 | 2016-05-11 13:52:53 -0600 | [diff] [blame] | 1684 | |
| 1685 | VkImageCreateInfo image_create_info = {}; |
| 1686 | image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO; |
| 1687 | image_create_info.pNext = NULL; |
| 1688 | image_create_info.imageType = VK_IMAGE_TYPE_2D; |
| 1689 | image_create_info.format = VK_FORMAT_R8G8B8A8_UNORM; |
| 1690 | image_create_info.extent.width = 64; |
| 1691 | image_create_info.extent.height = 64; |
| 1692 | image_create_info.extent.depth = 1; |
| 1693 | image_create_info.mipLevels = 1; |
| 1694 | image_create_info.arrayLayers = 1; |
| 1695 | image_create_info.samples = VK_SAMPLE_COUNT_1_BIT; |
| 1696 | image_create_info.tiling = VK_IMAGE_TILING_LINEAR; |
| 1697 | image_create_info.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED; |
| 1698 | image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT; |
| 1699 | image_create_info.queueFamilyIndexCount = 0; |
| 1700 | image_create_info.pQueueFamilyIndices = NULL; |
| 1701 | image_create_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE; |
| 1702 | image_create_info.flags = 0; |
| 1703 | |
Tobin Ehlis | f11be98 | 2016-05-11 13:52:53 -0600 | [diff] [blame] | 1704 | err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image); |
| 1705 | ASSERT_VK_SUCCESS(err); |
| 1706 | |
Tobin Ehlis | 077ded3 | 2016-05-12 17:39:13 -0600 | [diff] [blame] | 1707 | vkGetImageMemoryRequirements(m_device->device(), image, &img_mem_reqs); |
| 1708 | |
| 1709 | VkMemoryAllocateInfo alloc_info = {}; |
| 1710 | alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO; |
| 1711 | alloc_info.pNext = NULL; |
| 1712 | alloc_info.memoryTypeIndex = 0; |
| 1713 | // Ensure memory is big enough for both bindings |
| 1714 | alloc_info.allocationSize = buff_mem_reqs.size + img_mem_reqs.size; |
| 1715 | pass = m_device->phy().set_memory_type( |
| 1716 | buff_mem_reqs.memoryTypeBits | img_mem_reqs.memoryTypeBits, &alloc_info, |
| 1717 | VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT); |
Tobin Ehlis | f11be98 | 2016-05-11 13:52:53 -0600 | [diff] [blame] | 1718 | if (!pass) { |
Tobin Ehlis | 077ded3 | 2016-05-12 17:39:13 -0600 | [diff] [blame] | 1719 | vkDestroyBuffer(m_device->device(), buffer, NULL); |
Tobin Ehlis | f11be98 | 2016-05-11 13:52:53 -0600 | [diff] [blame] | 1720 | vkDestroyImage(m_device->device(), image, NULL); |
| 1721 | return; |
| 1722 | } |
Tobin Ehlis | 077ded3 | 2016-05-12 17:39:13 -0600 | [diff] [blame] | 1723 | err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem); |
| 1724 | ASSERT_VK_SUCCESS(err); |
| 1725 | err = vkBindBufferMemory(m_device->device(), buffer, mem, 0); |
| 1726 | ASSERT_VK_SUCCESS(err); |
| 1727 | |
Tobin Ehlis | f11be98 | 2016-05-11 13:52:53 -0600 | [diff] [blame] | 1728 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 1729 | " is aliased with buffer 0x"); |
Tobin Ehlis | 077ded3 | 2016-05-12 17:39:13 -0600 | [diff] [blame] | 1730 | // VALIDATION FAILURE due to image mapping overlapping buffer mapping |
Tobin Ehlis | f11be98 | 2016-05-11 13:52:53 -0600 | [diff] [blame] | 1731 | err = vkBindImageMemory(m_device->device(), image, mem, 0); |
| 1732 | m_errorMonitor->VerifyFound(); |
| 1733 | |
| 1734 | // Now correctly bind image to second mem allocation before incorrectly |
Tobin Ehlis | 077ded3 | 2016-05-12 17:39:13 -0600 | [diff] [blame] | 1735 | // aliasing buffer2 |
| 1736 | err = vkCreateBuffer(m_device->device(), &buf_info, NULL, &buffer2); |
| 1737 | ASSERT_VK_SUCCESS(err); |
Tobin Ehlis | f11be98 | 2016-05-11 13:52:53 -0600 | [diff] [blame] | 1738 | err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem_img); |
| 1739 | ASSERT_VK_SUCCESS(err); |
| 1740 | err = vkBindImageMemory(m_device->device(), image, mem_img, 0); |
| 1741 | ASSERT_VK_SUCCESS(err); |
| 1742 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 1743 | " is aliased with image 0x"); |
Tobin Ehlis | 077ded3 | 2016-05-12 17:39:13 -0600 | [diff] [blame] | 1744 | err = vkBindBufferMemory(m_device->device(), buffer2, mem_img, 0); |
Tobin Ehlis | f11be98 | 2016-05-11 13:52:53 -0600 | [diff] [blame] | 1745 | m_errorMonitor->VerifyFound(); |
| 1746 | |
| 1747 | vkDestroyBuffer(m_device->device(), buffer, NULL); |
Tobin Ehlis | 077ded3 | 2016-05-12 17:39:13 -0600 | [diff] [blame] | 1748 | vkDestroyBuffer(m_device->device(), buffer2, NULL); |
Tobin Ehlis | f11be98 | 2016-05-11 13:52:53 -0600 | [diff] [blame] | 1749 | vkDestroyImage(m_device->device(), image, NULL); |
| 1750 | vkFreeMemory(m_device->device(), mem, NULL); |
| 1751 | vkFreeMemory(m_device->device(), mem_img, NULL); |
| 1752 | } |
| 1753 | |
Tobin Ehlis | 3537252 | 2016-05-12 08:32:31 -0600 | [diff] [blame] | 1754 | TEST_F(VkLayerTest, InvalidMemoryMapping) { |
| 1755 | TEST_DESCRIPTION("Attempt to map memory in a number of incorrect ways"); |
| 1756 | VkResult err; |
| 1757 | bool pass; |
| 1758 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 1759 | |
| 1760 | VkBuffer buffer; |
| 1761 | VkDeviceMemory mem; |
| 1762 | VkMemoryRequirements mem_reqs; |
| 1763 | |
| 1764 | VkBufferCreateInfo buf_info = {}; |
| 1765 | buf_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO; |
| 1766 | buf_info.pNext = NULL; |
| 1767 | buf_info.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT; |
| 1768 | buf_info.size = 256; |
| 1769 | buf_info.queueFamilyIndexCount = 0; |
| 1770 | buf_info.pQueueFamilyIndices = NULL; |
| 1771 | buf_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE; |
| 1772 | buf_info.flags = 0; |
| 1773 | err = vkCreateBuffer(m_device->device(), &buf_info, NULL, &buffer); |
| 1774 | ASSERT_VK_SUCCESS(err); |
| 1775 | |
| 1776 | vkGetBufferMemoryRequirements(m_device->device(), buffer, &mem_reqs); |
| 1777 | VkMemoryAllocateInfo alloc_info = {}; |
| 1778 | alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO; |
| 1779 | alloc_info.pNext = NULL; |
| 1780 | alloc_info.memoryTypeIndex = 0; |
| 1781 | |
| 1782 | // Ensure memory is big enough for both bindings |
| 1783 | static const VkDeviceSize allocation_size = 0x10000; |
| 1784 | alloc_info.allocationSize = allocation_size; |
| 1785 | pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &alloc_info, |
| 1786 | VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT); |
| 1787 | if (!pass) { |
| 1788 | vkDestroyBuffer(m_device->device(), buffer, NULL); |
| 1789 | return; |
| 1790 | } |
| 1791 | err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem); |
| 1792 | ASSERT_VK_SUCCESS(err); |
| 1793 | |
| 1794 | uint8_t *pData; |
| 1795 | // Attempt to map memory size 0 is invalid |
| 1796 | m_errorMonitor->SetDesiredFailureMsg( |
| 1797 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 1798 | "VkMapMemory: Attempting to map memory range of size zero"); |
| 1799 | err = vkMapMemory(m_device->device(), mem, 0, 0, 0, (void **)&pData); |
| 1800 | m_errorMonitor->VerifyFound(); |
| 1801 | // Map memory twice |
| 1802 | err = vkMapMemory(m_device->device(), mem, 0, mem_reqs.size, 0, |
| 1803 | (void **)&pData); |
| 1804 | ASSERT_VK_SUCCESS(err); |
| 1805 | m_errorMonitor->SetDesiredFailureMsg( |
| 1806 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 1807 | "VkMapMemory: Attempting to map memory on an already-mapped object "); |
| 1808 | err = vkMapMemory(m_device->device(), mem, 0, mem_reqs.size, 0, |
| 1809 | (void **)&pData); |
| 1810 | m_errorMonitor->VerifyFound(); |
| 1811 | |
| 1812 | // Unmap the memory to avoid re-map error |
| 1813 | vkUnmapMemory(m_device->device(), mem); |
| 1814 | // overstep allocation with VK_WHOLE_SIZE |
| 1815 | m_errorMonitor->SetDesiredFailureMsg( |
| 1816 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 1817 | " with size of VK_WHOLE_SIZE oversteps total array size 0x"); |
| 1818 | err = vkMapMemory(m_device->device(), mem, allocation_size + 1, |
| 1819 | VK_WHOLE_SIZE, 0, (void **)&pData); |
| 1820 | m_errorMonitor->VerifyFound(); |
| 1821 | // overstep allocation w/o VK_WHOLE_SIZE |
| 1822 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 1823 | " oversteps total array size 0x"); |
| 1824 | err = vkMapMemory(m_device->device(), mem, 1, allocation_size, 0, |
| 1825 | (void **)&pData); |
| 1826 | m_errorMonitor->VerifyFound(); |
| 1827 | // Now error due to unmapping memory that's not mapped |
| 1828 | m_errorMonitor->SetDesiredFailureMsg( |
| 1829 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 1830 | "Unmapping Memory without memory being mapped: "); |
| 1831 | vkUnmapMemory(m_device->device(), mem); |
| 1832 | m_errorMonitor->VerifyFound(); |
| 1833 | // Now map memory and cause errors due to flushing invalid ranges |
| 1834 | err = vkMapMemory(m_device->device(), mem, 16, VK_WHOLE_SIZE, 0, |
| 1835 | (void **)&pData); |
| 1836 | ASSERT_VK_SUCCESS(err); |
| 1837 | VkMappedMemoryRange mmr = {}; |
Chris Forbes | 3aec089 | 2016-06-13 10:29:26 +1200 | [diff] [blame] | 1838 | mmr.sType = VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE; |
Tobin Ehlis | 3537252 | 2016-05-12 08:32:31 -0600 | [diff] [blame] | 1839 | mmr.memory = mem; |
| 1840 | mmr.offset = 15; // Error b/c offset less than offset of mapped mem |
| 1841 | m_errorMonitor->SetDesiredFailureMsg( |
| 1842 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 1843 | ") is less than Memory Object's offset ("); |
| 1844 | vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr); |
| 1845 | m_errorMonitor->VerifyFound(); |
| 1846 | // Now flush range that oversteps mapped range |
| 1847 | vkUnmapMemory(m_device->device(), mem); |
| 1848 | err = vkMapMemory(m_device->device(), mem, 0, 256, 0, (void **)&pData); |
| 1849 | ASSERT_VK_SUCCESS(err); |
| 1850 | mmr.offset = 16; |
| 1851 | mmr.size = 256; // flushing bounds (272) exceed mapped bounds (256) |
| 1852 | m_errorMonitor->SetDesiredFailureMsg( |
| 1853 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 1854 | ") exceeds the Memory Object's upper-bound ("); |
| 1855 | vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr); |
| 1856 | m_errorMonitor->VerifyFound(); |
| 1857 | |
| 1858 | pass = |
| 1859 | m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &alloc_info, |
| 1860 | VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT, |
| 1861 | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT); |
| 1862 | if (!pass) { |
| 1863 | vkFreeMemory(m_device->device(), mem, NULL); |
| 1864 | vkDestroyBuffer(m_device->device(), buffer, NULL); |
| 1865 | return; |
| 1866 | } |
| 1867 | // TODO : If we can get HOST_VISIBLE w/o HOST_COHERENT we can test cases of |
| 1868 | // MEMTRACK_INVALID_MAP in validateAndCopyNoncoherentMemoryToDriver() |
| 1869 | |
| 1870 | vkDestroyBuffer(m_device->device(), buffer, NULL); |
| 1871 | vkFreeMemory(m_device->device(), mem, NULL); |
| 1872 | } |
| 1873 | |
Ian Elliott | 1c32c77 | 2016-04-28 14:47:13 -0600 | [diff] [blame] | 1874 | TEST_F(VkLayerTest, EnableWsiBeforeUse) { |
| 1875 | VkResult err; |
| 1876 | bool pass; |
| 1877 | |
Ian Elliott | 489eec0 | 2016-05-05 14:12:44 -0600 | [diff] [blame] | 1878 | // FIXME: After we turn on this code for non-Linux platforms, uncomment the |
| 1879 | // following declaration (which is temporarily being moved below): |
| 1880 | // VkSurfaceKHR surface = VK_NULL_HANDLE; |
Ian Elliott | 1c32c77 | 2016-04-28 14:47:13 -0600 | [diff] [blame] | 1881 | VkSwapchainKHR swapchain = VK_NULL_HANDLE; |
| 1882 | VkSwapchainCreateInfoKHR swapchain_create_info = {}; |
| 1883 | uint32_t swapchain_image_count = 0; |
| 1884 | // VkImage swapchain_images[1] = {VK_NULL_HANDLE}; |
| 1885 | uint32_t image_index = 0; |
| 1886 | // VkPresentInfoKHR present_info = {}; |
| 1887 | |
| 1888 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 1889 | |
Ian Elliott | 3f06ce5 | 2016-04-29 14:46:21 -0600 | [diff] [blame] | 1890 | #ifdef NEED_TO_TEST_THIS_ON_PLATFORM |
| 1891 | #if defined(VK_USE_PLATFORM_ANDROID_KHR) |
| 1892 | // Use the functions from the VK_KHR_android_surface extension without |
| 1893 | // enabling that extension: |
| 1894 | |
| 1895 | // Create a surface: |
| 1896 | VkAndroidSurfaceCreateInfoKHR android_create_info = {}; |
Ian Elliott | 3f06ce5 | 2016-04-29 14:46:21 -0600 | [diff] [blame] | 1897 | m_errorMonitor->SetDesiredFailureMsg( |
| 1898 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 1899 | "extension was not enabled for this"); |
| 1900 | err = vkCreateAndroidSurfaceKHR(instance(), &android_create_info, NULL, |
| 1901 | &surface); |
| 1902 | pass = (err != VK_SUCCESS); |
| 1903 | ASSERT_TRUE(pass); |
| 1904 | m_errorMonitor->VerifyFound(); |
| 1905 | #endif // VK_USE_PLATFORM_ANDROID_KHR |
| 1906 | |
| 1907 | |
| 1908 | #if defined(VK_USE_PLATFORM_MIR_KHR) |
| 1909 | // Use the functions from the VK_KHR_mir_surface extension without enabling |
| 1910 | // that extension: |
| 1911 | |
| 1912 | // Create a surface: |
| 1913 | VkMirSurfaceCreateInfoKHR mir_create_info = {}; |
Ian Elliott | 3f06ce5 | 2016-04-29 14:46:21 -0600 | [diff] [blame] | 1914 | m_errorMonitor->SetDesiredFailureMsg( |
| 1915 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 1916 | "extension was not enabled for this"); |
| 1917 | err = vkCreateMirSurfaceKHR(instance(), &mir_create_info, NULL, &surface); |
| 1918 | pass = (err != VK_SUCCESS); |
| 1919 | ASSERT_TRUE(pass); |
| 1920 | m_errorMonitor->VerifyFound(); |
| 1921 | |
| 1922 | // Tell whether an mir_connection supports presentation: |
| 1923 | MirConnection *mir_connection = NULL; |
| 1924 | m_errorMonitor->SetDesiredFailureMsg( |
| 1925 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 1926 | "extension was not enabled for this"); |
| 1927 | vkGetPhysicalDeviceMirPresentationSupportKHR(gpu(), 0, mir_connection, |
| 1928 | visual_id); |
| 1929 | m_errorMonitor->VerifyFound(); |
| 1930 | #endif // VK_USE_PLATFORM_MIR_KHR |
| 1931 | |
| 1932 | |
| 1933 | #if defined(VK_USE_PLATFORM_WAYLAND_KHR) |
| 1934 | // Use the functions from the VK_KHR_wayland_surface extension without |
| 1935 | // enabling that extension: |
| 1936 | |
| 1937 | // Create a surface: |
| 1938 | VkWaylandSurfaceCreateInfoKHR wayland_create_info = {}; |
Ian Elliott | 3f06ce5 | 2016-04-29 14:46:21 -0600 | [diff] [blame] | 1939 | m_errorMonitor->SetDesiredFailureMsg( |
| 1940 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 1941 | "extension was not enabled for this"); |
| 1942 | err = vkCreateWaylandSurfaceKHR(instance(), &wayland_create_info, NULL, |
| 1943 | &surface); |
| 1944 | pass = (err != VK_SUCCESS); |
| 1945 | ASSERT_TRUE(pass); |
| 1946 | m_errorMonitor->VerifyFound(); |
| 1947 | |
| 1948 | // Tell whether an wayland_display supports presentation: |
| 1949 | struct wl_display wayland_display = {}; |
| 1950 | m_errorMonitor->SetDesiredFailureMsg( |
| 1951 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 1952 | "extension was not enabled for this"); |
| 1953 | vkGetPhysicalDeviceWaylandPresentationSupportKHR(gpu(), 0, |
| 1954 | &wayland_display); |
| 1955 | m_errorMonitor->VerifyFound(); |
| 1956 | #endif // VK_USE_PLATFORM_WAYLAND_KHR |
Ian Elliott | 489eec0 | 2016-05-05 14:12:44 -0600 | [diff] [blame] | 1957 | #endif // NEED_TO_TEST_THIS_ON_PLATFORM |
Ian Elliott | 3f06ce5 | 2016-04-29 14:46:21 -0600 | [diff] [blame] | 1958 | |
| 1959 | |
| 1960 | #if defined(VK_USE_PLATFORM_WIN32_KHR) |
Ian Elliott | 489eec0 | 2016-05-05 14:12:44 -0600 | [diff] [blame] | 1961 | // FIXME: REMOVE THIS HERE, AND UNCOMMENT ABOVE, WHEN THIS TEST HAS BEEN PORTED |
| 1962 | // TO NON-LINUX PLATFORMS: |
| 1963 | VkSurfaceKHR surface = VK_NULL_HANDLE; |
Ian Elliott | 3f06ce5 | 2016-04-29 14:46:21 -0600 | [diff] [blame] | 1964 | // Use the functions from the VK_KHR_win32_surface extension without |
| 1965 | // enabling that extension: |
| 1966 | |
| 1967 | // Create a surface: |
| 1968 | VkWin32SurfaceCreateInfoKHR win32_create_info = {}; |
Ian Elliott | 3f06ce5 | 2016-04-29 14:46:21 -0600 | [diff] [blame] | 1969 | m_errorMonitor->SetDesiredFailureMsg( |
| 1970 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 1971 | "extension was not enabled for this"); |
| 1972 | err = vkCreateWin32SurfaceKHR(instance(), &win32_create_info, NULL, |
| 1973 | &surface); |
| 1974 | pass = (err != VK_SUCCESS); |
| 1975 | ASSERT_TRUE(pass); |
| 1976 | m_errorMonitor->VerifyFound(); |
| 1977 | |
| 1978 | // Tell whether win32 supports presentation: |
Ian Elliott | 3f06ce5 | 2016-04-29 14:46:21 -0600 | [diff] [blame] | 1979 | m_errorMonitor->SetDesiredFailureMsg( |
| 1980 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 1981 | "extension was not enabled for this"); |
Ian Elliott | 489eec0 | 2016-05-05 14:12:44 -0600 | [diff] [blame] | 1982 | vkGetPhysicalDeviceWin32PresentationSupportKHR(gpu(), 0); |
Ian Elliott | 3f06ce5 | 2016-04-29 14:46:21 -0600 | [diff] [blame] | 1983 | m_errorMonitor->VerifyFound(); |
Ian Elliott | 489eec0 | 2016-05-05 14:12:44 -0600 | [diff] [blame] | 1984 | // Set this (for now, until all platforms are supported and tested): |
| 1985 | #define NEED_TO_TEST_THIS_ON_PLATFORM |
| 1986 | #endif // VK_USE_PLATFORM_WIN32_KHR |
Ian Elliott | 3f06ce5 | 2016-04-29 14:46:21 -0600 | [diff] [blame] | 1987 | |
| 1988 | |
Ian Elliott | 1c32c77 | 2016-04-28 14:47:13 -0600 | [diff] [blame] | 1989 | #if defined(VK_USE_PLATFORM_XCB_KHR) |
Ian Elliott | 489eec0 | 2016-05-05 14:12:44 -0600 | [diff] [blame] | 1990 | // FIXME: REMOVE THIS HERE, AND UNCOMMENT ABOVE, WHEN THIS TEST HAS BEEN PORTED |
| 1991 | // TO NON-LINUX PLATFORMS: |
| 1992 | VkSurfaceKHR surface = VK_NULL_HANDLE; |
Ian Elliott | 1c32c77 | 2016-04-28 14:47:13 -0600 | [diff] [blame] | 1993 | // Use the functions from the VK_KHR_xcb_surface extension without enabling |
| 1994 | // that extension: |
| 1995 | |
| 1996 | // Create a surface: |
| 1997 | VkXcbSurfaceCreateInfoKHR xcb_create_info = {}; |
Ian Elliott | 1c32c77 | 2016-04-28 14:47:13 -0600 | [diff] [blame] | 1998 | m_errorMonitor->SetDesiredFailureMsg( |
| 1999 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 2000 | "extension was not enabled for this"); |
| 2001 | err = vkCreateXcbSurfaceKHR(instance(), &xcb_create_info, NULL, &surface); |
| 2002 | pass = (err != VK_SUCCESS); |
| 2003 | ASSERT_TRUE(pass); |
| 2004 | m_errorMonitor->VerifyFound(); |
| 2005 | |
| 2006 | // Tell whether an xcb_visualid_t supports presentation: |
Ian Elliott | 3f06ce5 | 2016-04-29 14:46:21 -0600 | [diff] [blame] | 2007 | xcb_connection_t *xcb_connection = NULL; |
Ian Elliott | 1c32c77 | 2016-04-28 14:47:13 -0600 | [diff] [blame] | 2008 | xcb_visualid_t visual_id = 0; |
| 2009 | m_errorMonitor->SetDesiredFailureMsg( |
| 2010 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 2011 | "extension was not enabled for this"); |
Ian Elliott | 3f06ce5 | 2016-04-29 14:46:21 -0600 | [diff] [blame] | 2012 | vkGetPhysicalDeviceXcbPresentationSupportKHR(gpu(), 0, xcb_connection, |
Ian Elliott | 1c32c77 | 2016-04-28 14:47:13 -0600 | [diff] [blame] | 2013 | visual_id); |
| 2014 | m_errorMonitor->VerifyFound(); |
Ian Elliott | 489eec0 | 2016-05-05 14:12:44 -0600 | [diff] [blame] | 2015 | // Set this (for now, until all platforms are supported and tested): |
| 2016 | #define NEED_TO_TEST_THIS_ON_PLATFORM |
Ian Elliott | 1c32c77 | 2016-04-28 14:47:13 -0600 | [diff] [blame] | 2017 | #endif // VK_USE_PLATFORM_XCB_KHR |
| 2018 | |
| 2019 | |
Ian Elliott | 1263081 | 2016-04-29 14:35:43 -0600 | [diff] [blame] | 2020 | #if defined(VK_USE_PLATFORM_XLIB_KHR) |
| 2021 | // Use the functions from the VK_KHR_xlib_surface extension without enabling |
| 2022 | // that extension: |
| 2023 | |
| 2024 | // Create a surface: |
| 2025 | VkXlibSurfaceCreateInfoKHR xlib_create_info = {}; |
Ian Elliott | 1263081 | 2016-04-29 14:35:43 -0600 | [diff] [blame] | 2026 | m_errorMonitor->SetDesiredFailureMsg( |
| 2027 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 2028 | "extension was not enabled for this"); |
| 2029 | err = vkCreateXlibSurfaceKHR(instance(), &xlib_create_info, NULL, &surface); |
| 2030 | pass = (err != VK_SUCCESS); |
| 2031 | ASSERT_TRUE(pass); |
| 2032 | m_errorMonitor->VerifyFound(); |
| 2033 | |
| 2034 | // Tell whether an Xlib VisualID supports presentation: |
| 2035 | Display *dpy = NULL; |
| 2036 | VisualID visual = 0; |
| 2037 | m_errorMonitor->SetDesiredFailureMsg( |
| 2038 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 2039 | "extension was not enabled for this"); |
| 2040 | vkGetPhysicalDeviceXlibPresentationSupportKHR(gpu(), 0, dpy, visual); |
| 2041 | m_errorMonitor->VerifyFound(); |
Ian Elliott | 489eec0 | 2016-05-05 14:12:44 -0600 | [diff] [blame] | 2042 | // Set this (for now, until all platforms are supported and tested): |
| 2043 | #define NEED_TO_TEST_THIS_ON_PLATFORM |
Ian Elliott | 1263081 | 2016-04-29 14:35:43 -0600 | [diff] [blame] | 2044 | #endif // VK_USE_PLATFORM_XLIB_KHR |
| 2045 | |
| 2046 | |
Ian Elliott | 1c32c77 | 2016-04-28 14:47:13 -0600 | [diff] [blame] | 2047 | // Use the functions from the VK_KHR_surface extension without enabling |
| 2048 | // that extension: |
| 2049 | |
Ian Elliott | 489eec0 | 2016-05-05 14:12:44 -0600 | [diff] [blame] | 2050 | #ifdef NEED_TO_TEST_THIS_ON_PLATFORM |
Ian Elliott | 1c32c77 | 2016-04-28 14:47:13 -0600 | [diff] [blame] | 2051 | // Destroy a surface: |
| 2052 | m_errorMonitor->SetDesiredFailureMsg( |
| 2053 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 2054 | "extension was not enabled for this"); |
| 2055 | vkDestroySurfaceKHR(instance(), surface, NULL); |
| 2056 | m_errorMonitor->VerifyFound(); |
| 2057 | |
| 2058 | // Check if surface supports presentation: |
| 2059 | VkBool32 supported = false; |
| 2060 | m_errorMonitor->SetDesiredFailureMsg( |
| 2061 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 2062 | "extension was not enabled for this"); |
| 2063 | err = vkGetPhysicalDeviceSurfaceSupportKHR(gpu(), 0, surface, &supported); |
| 2064 | pass = (err != VK_SUCCESS); |
| 2065 | ASSERT_TRUE(pass); |
| 2066 | m_errorMonitor->VerifyFound(); |
| 2067 | |
| 2068 | // Check surface capabilities: |
| 2069 | VkSurfaceCapabilitiesKHR capabilities = {}; |
| 2070 | m_errorMonitor->SetDesiredFailureMsg( |
| 2071 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 2072 | "extension was not enabled for this"); |
| 2073 | err = vkGetPhysicalDeviceSurfaceCapabilitiesKHR(gpu(), surface, |
| 2074 | &capabilities); |
| 2075 | pass = (err != VK_SUCCESS); |
| 2076 | ASSERT_TRUE(pass); |
| 2077 | m_errorMonitor->VerifyFound(); |
| 2078 | |
| 2079 | // Check surface formats: |
| 2080 | uint32_t format_count = 0; |
| 2081 | VkSurfaceFormatKHR *formats = NULL; |
| 2082 | m_errorMonitor->SetDesiredFailureMsg( |
| 2083 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 2084 | "extension was not enabled for this"); |
| 2085 | err = vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, |
| 2086 | &format_count, formats); |
| 2087 | pass = (err != VK_SUCCESS); |
| 2088 | ASSERT_TRUE(pass); |
| 2089 | m_errorMonitor->VerifyFound(); |
| 2090 | |
| 2091 | // Check surface present modes: |
| 2092 | uint32_t present_mode_count = 0; |
| 2093 | VkSurfaceFormatKHR *present_modes = NULL; |
| 2094 | m_errorMonitor->SetDesiredFailureMsg( |
| 2095 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 2096 | "extension was not enabled for this"); |
| 2097 | err = vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, |
| 2098 | &present_mode_count, present_modes); |
| 2099 | pass = (err != VK_SUCCESS); |
| 2100 | ASSERT_TRUE(pass); |
| 2101 | m_errorMonitor->VerifyFound(); |
Ian Elliott | 489eec0 | 2016-05-05 14:12:44 -0600 | [diff] [blame] | 2102 | #endif // NEED_TO_TEST_THIS_ON_PLATFORM |
Ian Elliott | 1c32c77 | 2016-04-28 14:47:13 -0600 | [diff] [blame] | 2103 | |
| 2104 | |
| 2105 | // Use the functions from the VK_KHR_swapchain extension without enabling |
| 2106 | // that extension: |
| 2107 | |
| 2108 | // Create a swapchain: |
| 2109 | m_errorMonitor->SetDesiredFailureMsg( |
| 2110 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 2111 | "extension was not enabled for this"); |
| 2112 | swapchain_create_info.sType = VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR; |
| 2113 | swapchain_create_info.pNext = NULL; |
Ian Elliott | 1c32c77 | 2016-04-28 14:47:13 -0600 | [diff] [blame] | 2114 | err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, |
| 2115 | NULL, &swapchain); |
| 2116 | pass = (err != VK_SUCCESS); |
| 2117 | ASSERT_TRUE(pass); |
| 2118 | m_errorMonitor->VerifyFound(); |
| 2119 | |
| 2120 | // Get the images from the swapchain: |
| 2121 | m_errorMonitor->SetDesiredFailureMsg( |
| 2122 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 2123 | "extension was not enabled for this"); |
| 2124 | err = vkGetSwapchainImagesKHR(m_device->device(), swapchain, |
| 2125 | &swapchain_image_count, NULL); |
| 2126 | pass = (err != VK_SUCCESS); |
| 2127 | ASSERT_TRUE(pass); |
| 2128 | m_errorMonitor->VerifyFound(); |
| 2129 | |
| 2130 | // Try to acquire an image: |
| 2131 | m_errorMonitor->SetDesiredFailureMsg( |
| 2132 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 2133 | "extension was not enabled for this"); |
| 2134 | err = vkAcquireNextImageKHR(m_device->device(), swapchain, 0, |
| 2135 | VK_NULL_HANDLE, VK_NULL_HANDLE, &image_index); |
| 2136 | pass = (err != VK_SUCCESS); |
| 2137 | ASSERT_TRUE(pass); |
| 2138 | m_errorMonitor->VerifyFound(); |
| 2139 | |
| 2140 | // Try to present an image: |
Ian Elliott | 2c1daf5 | 2016-05-12 09:41:46 -0600 | [diff] [blame] | 2141 | // |
| 2142 | // NOTE: Currently can't test this because a real swapchain is needed (as |
| 2143 | // opposed to the fake one we created) in order for the layer to lookup the |
| 2144 | // VkDevice used to enable the extension: |
Ian Elliott | 1c32c77 | 2016-04-28 14:47:13 -0600 | [diff] [blame] | 2145 | |
| 2146 | // Destroy the swapchain: |
| 2147 | m_errorMonitor->SetDesiredFailureMsg( |
| 2148 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 2149 | "extension was not enabled for this"); |
| 2150 | vkDestroySwapchainKHR(m_device->device(), swapchain, NULL); |
| 2151 | m_errorMonitor->VerifyFound(); |
| 2152 | } |
| 2153 | |
Ian Elliott | 2c1daf5 | 2016-05-12 09:41:46 -0600 | [diff] [blame] | 2154 | TEST_F(VkWsiEnabledLayerTest, TestEnabledWsi) { |
Ian Elliott | 2c1daf5 | 2016-05-12 09:41:46 -0600 | [diff] [blame] | 2155 | |
Dustin Graves | 6c6d898 | 2016-05-17 10:09:21 -0600 | [diff] [blame] | 2156 | #if defined(VK_USE_PLATFORM_XCB_KHR) |
Ian Elliott | 2c1daf5 | 2016-05-12 09:41:46 -0600 | [diff] [blame] | 2157 | VkSurfaceKHR surface = VK_NULL_HANDLE; |
Mark Lobodzinski | 085d27a | 2016-05-17 09:34:26 -0600 | [diff] [blame] | 2158 | |
Mark Lobodzinski | 085d27a | 2016-05-17 09:34:26 -0600 | [diff] [blame] | 2159 | VkResult err; |
| 2160 | bool pass; |
Ian Elliott | 2c1daf5 | 2016-05-12 09:41:46 -0600 | [diff] [blame] | 2161 | VkSwapchainKHR swapchain = VK_NULL_HANDLE; |
| 2162 | VkSwapchainCreateInfoKHR swapchain_create_info = {}; |
Mark Lobodzinski | 085d27a | 2016-05-17 09:34:26 -0600 | [diff] [blame] | 2163 | // uint32_t swapchain_image_count = 0; |
| 2164 | // VkImage swapchain_images[1] = {VK_NULL_HANDLE}; |
| 2165 | // uint32_t image_index = 0; |
| 2166 | // VkPresentInfoKHR present_info = {}; |
Ian Elliott | 2c1daf5 | 2016-05-12 09:41:46 -0600 | [diff] [blame] | 2167 | |
| 2168 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 2169 | |
| 2170 | // Use the create function from one of the VK_KHR_*_surface extension in |
| 2171 | // order to create a surface, testing all known errors in the process, |
| 2172 | // before successfully creating a surface: |
| 2173 | // First, try to create a surface without a VkXcbSurfaceCreateInfoKHR: |
Mark Lobodzinski | 085d27a | 2016-05-17 09:34:26 -0600 | [diff] [blame] | 2174 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 2175 | "called with NULL pointer"); |
Ian Elliott | 2c1daf5 | 2016-05-12 09:41:46 -0600 | [diff] [blame] | 2176 | err = vkCreateXcbSurfaceKHR(instance(), NULL, NULL, &surface); |
| 2177 | pass = (err != VK_SUCCESS); |
| 2178 | ASSERT_TRUE(pass); |
| 2179 | m_errorMonitor->VerifyFound(); |
| 2180 | |
| 2181 | // Next, try to create a surface with the wrong |
| 2182 | // VkXcbSurfaceCreateInfoKHR::sType: |
| 2183 | VkXcbSurfaceCreateInfoKHR xcb_create_info = {}; |
| 2184 | xcb_create_info.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO; |
Mark Lobodzinski | 085d27a | 2016-05-17 09:34:26 -0600 | [diff] [blame] | 2185 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 2186 | "called with the wrong value for"); |
Ian Elliott | 2c1daf5 | 2016-05-12 09:41:46 -0600 | [diff] [blame] | 2187 | err = vkCreateXcbSurfaceKHR(instance(), &xcb_create_info, NULL, &surface); |
| 2188 | pass = (err != VK_SUCCESS); |
| 2189 | ASSERT_TRUE(pass); |
| 2190 | m_errorMonitor->VerifyFound(); |
| 2191 | |
Ian Elliott | 2c1daf5 | 2016-05-12 09:41:46 -0600 | [diff] [blame] | 2192 | // Create a native window, and then correctly create a surface: |
| 2193 | xcb_connection_t *connection; |
| 2194 | xcb_screen_t *screen; |
| 2195 | xcb_window_t xcb_window; |
| 2196 | xcb_intern_atom_reply_t *atom_wm_delete_window; |
| 2197 | |
| 2198 | const xcb_setup_t *setup; |
| 2199 | xcb_screen_iterator_t iter; |
| 2200 | int scr; |
| 2201 | uint32_t value_mask, value_list[32]; |
| 2202 | int width = 1; |
| 2203 | int height = 1; |
| 2204 | |
| 2205 | connection = xcb_connect(NULL, &scr); |
| 2206 | ASSERT_TRUE(connection != NULL); |
| 2207 | setup = xcb_get_setup(connection); |
| 2208 | iter = xcb_setup_roots_iterator(setup); |
| 2209 | while (scr-- > 0) |
| 2210 | xcb_screen_next(&iter); |
| 2211 | screen = iter.data; |
| 2212 | |
| 2213 | xcb_window = xcb_generate_id(connection); |
| 2214 | |
| 2215 | value_mask = XCB_CW_BACK_PIXEL | XCB_CW_EVENT_MASK; |
| 2216 | value_list[0] = screen->black_pixel; |
| 2217 | value_list[1] = XCB_EVENT_MASK_KEY_RELEASE | XCB_EVENT_MASK_EXPOSURE | |
| 2218 | XCB_EVENT_MASK_STRUCTURE_NOTIFY; |
| 2219 | |
| 2220 | xcb_create_window(connection, XCB_COPY_FROM_PARENT, xcb_window, |
| 2221 | screen->root, 0, 0, width, height, 0, |
| 2222 | XCB_WINDOW_CLASS_INPUT_OUTPUT, screen->root_visual, |
| 2223 | value_mask, value_list); |
| 2224 | |
| 2225 | /* Magic code that will send notification when window is destroyed */ |
| 2226 | xcb_intern_atom_cookie_t cookie = |
| 2227 | xcb_intern_atom(connection, 1, 12, "WM_PROTOCOLS"); |
| 2228 | xcb_intern_atom_reply_t *reply = |
| 2229 | xcb_intern_atom_reply(connection, cookie, 0); |
| 2230 | |
| 2231 | xcb_intern_atom_cookie_t cookie2 = |
| 2232 | xcb_intern_atom(connection, 0, 16, "WM_DELETE_WINDOW"); |
Mark Lobodzinski | 085d27a | 2016-05-17 09:34:26 -0600 | [diff] [blame] | 2233 | atom_wm_delete_window = xcb_intern_atom_reply(connection, cookie2, 0); |
Ian Elliott | 2c1daf5 | 2016-05-12 09:41:46 -0600 | [diff] [blame] | 2234 | xcb_change_property(connection, XCB_PROP_MODE_REPLACE, xcb_window, |
| 2235 | (*reply).atom, 4, 32, 1, |
| 2236 | &(*atom_wm_delete_window).atom); |
| 2237 | free(reply); |
| 2238 | |
| 2239 | xcb_map_window(connection, xcb_window); |
| 2240 | |
| 2241 | // Force the x/y coordinates to 100,100 results are identical in consecutive |
| 2242 | // runs |
| 2243 | const uint32_t coords[] = {100, 100}; |
| 2244 | xcb_configure_window(connection, xcb_window, |
| 2245 | XCB_CONFIG_WINDOW_X | XCB_CONFIG_WINDOW_Y, coords); |
| 2246 | |
Ian Elliott | 2c1daf5 | 2016-05-12 09:41:46 -0600 | [diff] [blame] | 2247 | // Finally, try to correctly create a surface: |
| 2248 | xcb_create_info.sType = VK_STRUCTURE_TYPE_XCB_SURFACE_CREATE_INFO_KHR; |
| 2249 | xcb_create_info.pNext = NULL; |
| 2250 | xcb_create_info.flags = 0; |
| 2251 | xcb_create_info.connection = connection; |
| 2252 | xcb_create_info.window = xcb_window; |
| 2253 | err = vkCreateXcbSurfaceKHR(instance(), &xcb_create_info, NULL, &surface); |
| 2254 | pass = (err == VK_SUCCESS); |
| 2255 | ASSERT_TRUE(pass); |
| 2256 | |
Ian Elliott | 2c1daf5 | 2016-05-12 09:41:46 -0600 | [diff] [blame] | 2257 | // Check if surface supports presentation: |
| 2258 | |
| 2259 | // 1st, do so without having queried the queue families: |
| 2260 | VkBool32 supported = false; |
| 2261 | // TODO: Get the following error to come out: |
| 2262 | m_errorMonitor->SetDesiredFailureMsg( |
| 2263 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 2264 | "called before calling the vkGetPhysicalDeviceQueueFamilyProperties " |
| 2265 | "function"); |
| 2266 | err = vkGetPhysicalDeviceSurfaceSupportKHR(gpu(), 0, surface, &supported); |
| 2267 | pass = (err != VK_SUCCESS); |
Mark Lobodzinski | 085d27a | 2016-05-17 09:34:26 -0600 | [diff] [blame] | 2268 | // ASSERT_TRUE(pass); |
| 2269 | // m_errorMonitor->VerifyFound(); |
Ian Elliott | 2c1daf5 | 2016-05-12 09:41:46 -0600 | [diff] [blame] | 2270 | |
| 2271 | // Next, query a queue family index that's too large: |
| 2272 | m_errorMonitor->SetDesiredFailureMsg( |
| 2273 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 2274 | "called with a queueFamilyIndex that is too large"); |
Mark Lobodzinski | 085d27a | 2016-05-17 09:34:26 -0600 | [diff] [blame] | 2275 | err = vkGetPhysicalDeviceSurfaceSupportKHR(gpu(), 100000, surface, |
| 2276 | &supported); |
Ian Elliott | 2c1daf5 | 2016-05-12 09:41:46 -0600 | [diff] [blame] | 2277 | pass = (err != VK_SUCCESS); |
| 2278 | ASSERT_TRUE(pass); |
| 2279 | m_errorMonitor->VerifyFound(); |
| 2280 | |
| 2281 | // Finally, do so correctly: |
Mark Lobodzinski | 085d27a | 2016-05-17 09:34:26 -0600 | [diff] [blame] | 2282 | // FIXME: THIS ISN'T CORRECT--MUST QUERY UNTIL WE FIND A QUEUE FAMILY THAT'S |
| 2283 | // SUPPORTED |
Ian Elliott | 2c1daf5 | 2016-05-12 09:41:46 -0600 | [diff] [blame] | 2284 | err = vkGetPhysicalDeviceSurfaceSupportKHR(gpu(), 0, surface, &supported); |
| 2285 | pass = (err == VK_SUCCESS); |
| 2286 | ASSERT_TRUE(pass); |
| 2287 | |
Ian Elliott | 2c1daf5 | 2016-05-12 09:41:46 -0600 | [diff] [blame] | 2288 | // Before proceeding, try to create a swapchain without having called |
| 2289 | // vkGetPhysicalDeviceSurfaceCapabilitiesKHR(): |
| 2290 | swapchain_create_info.sType = VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR; |
| 2291 | swapchain_create_info.pNext = NULL; |
| 2292 | swapchain_create_info.flags = 0; |
| 2293 | m_errorMonitor->SetDesiredFailureMsg( |
| 2294 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 2295 | "called before calling vkGetPhysicalDeviceSurfaceCapabilitiesKHR()."); |
Mark Lobodzinski | 085d27a | 2016-05-17 09:34:26 -0600 | [diff] [blame] | 2296 | err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, |
| 2297 | &swapchain); |
Ian Elliott | 2c1daf5 | 2016-05-12 09:41:46 -0600 | [diff] [blame] | 2298 | pass = (err != VK_SUCCESS); |
| 2299 | ASSERT_TRUE(pass); |
| 2300 | m_errorMonitor->VerifyFound(); |
| 2301 | |
Ian Elliott | 2c1daf5 | 2016-05-12 09:41:46 -0600 | [diff] [blame] | 2302 | // Get the surface capabilities: |
| 2303 | VkSurfaceCapabilitiesKHR surface_capabilities; |
| 2304 | |
| 2305 | // Do so correctly (only error logged by this entrypoint is if the |
| 2306 | // extension isn't enabled): |
| 2307 | err = vkGetPhysicalDeviceSurfaceCapabilitiesKHR(gpu(), surface, |
| 2308 | &surface_capabilities); |
| 2309 | pass = (err == VK_SUCCESS); |
| 2310 | ASSERT_TRUE(pass); |
| 2311 | |
Ian Elliott | 2c1daf5 | 2016-05-12 09:41:46 -0600 | [diff] [blame] | 2312 | // Get the surface formats: |
| 2313 | uint32_t surface_format_count; |
| 2314 | |
| 2315 | // First, try without a pointer to surface_format_count: |
Mark Lobodzinski | 085d27a | 2016-05-17 09:34:26 -0600 | [diff] [blame] | 2316 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 2317 | "called with NULL pointer"); |
Ian Elliott | 2c1daf5 | 2016-05-12 09:41:46 -0600 | [diff] [blame] | 2318 | vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, NULL, NULL); |
| 2319 | pass = (err == VK_SUCCESS); |
| 2320 | ASSERT_TRUE(pass); |
| 2321 | m_errorMonitor->VerifyFound(); |
| 2322 | |
| 2323 | // Next, call with a non-NULL pSurfaceFormats, even though we haven't |
| 2324 | // correctly done a 1st try (to get the count): |
| 2325 | m_errorMonitor->SetDesiredFailureMsg( |
| 2326 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 2327 | "but no prior positive value has been seen for"); |
| 2328 | surface_format_count = 0; |
| 2329 | vkGetPhysicalDeviceSurfaceFormatsKHR( |
Mark Lobodzinski | 085d27a | 2016-05-17 09:34:26 -0600 | [diff] [blame] | 2330 | gpu(), surface, &surface_format_count, |
| 2331 | (VkSurfaceFormatKHR *)&surface_format_count); |
Ian Elliott | 2c1daf5 | 2016-05-12 09:41:46 -0600 | [diff] [blame] | 2332 | pass = (err == VK_SUCCESS); |
| 2333 | ASSERT_TRUE(pass); |
| 2334 | m_errorMonitor->VerifyFound(); |
| 2335 | |
| 2336 | // 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] | 2337 | vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &surface_format_count, |
| 2338 | NULL); |
Ian Elliott | 2c1daf5 | 2016-05-12 09:41:46 -0600 | [diff] [blame] | 2339 | pass = (err == VK_SUCCESS); |
| 2340 | ASSERT_TRUE(pass); |
| 2341 | |
| 2342 | // Allocate memory for the correct number of VkSurfaceFormatKHR's: |
Mark Lobodzinski | 085d27a | 2016-05-17 09:34:26 -0600 | [diff] [blame] | 2343 | VkSurfaceFormatKHR *surface_formats = (VkSurfaceFormatKHR *)malloc( |
| 2344 | surface_format_count * sizeof(VkSurfaceFormatKHR)); |
Ian Elliott | 2c1daf5 | 2016-05-12 09:41:46 -0600 | [diff] [blame] | 2345 | |
| 2346 | // Next, do a 2nd try with surface_format_count being set too high: |
| 2347 | surface_format_count += 5; |
Mark Lobodzinski | 085d27a | 2016-05-17 09:34:26 -0600 | [diff] [blame] | 2348 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 2349 | "that is greater than the value"); |
| 2350 | vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &surface_format_count, |
Ian Elliott | 2c1daf5 | 2016-05-12 09:41:46 -0600 | [diff] [blame] | 2351 | surface_formats); |
| 2352 | pass = (err == VK_SUCCESS); |
| 2353 | ASSERT_TRUE(pass); |
| 2354 | m_errorMonitor->VerifyFound(); |
| 2355 | |
| 2356 | // Finally, do a correct 1st and 2nd try: |
Mark Lobodzinski | 085d27a | 2016-05-17 09:34:26 -0600 | [diff] [blame] | 2357 | vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &surface_format_count, |
| 2358 | NULL); |
Ian Elliott | 2c1daf5 | 2016-05-12 09:41:46 -0600 | [diff] [blame] | 2359 | pass = (err == VK_SUCCESS); |
| 2360 | ASSERT_TRUE(pass); |
Mark Lobodzinski | 085d27a | 2016-05-17 09:34:26 -0600 | [diff] [blame] | 2361 | vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &surface_format_count, |
Ian Elliott | 2c1daf5 | 2016-05-12 09:41:46 -0600 | [diff] [blame] | 2362 | surface_formats); |
| 2363 | pass = (err == VK_SUCCESS); |
| 2364 | ASSERT_TRUE(pass); |
| 2365 | |
Ian Elliott | 2c1daf5 | 2016-05-12 09:41:46 -0600 | [diff] [blame] | 2366 | // Get the surface present modes: |
| 2367 | uint32_t surface_present_mode_count; |
| 2368 | |
| 2369 | // First, try without a pointer to surface_format_count: |
Mark Lobodzinski | 085d27a | 2016-05-17 09:34:26 -0600 | [diff] [blame] | 2370 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 2371 | "called with NULL pointer"); |
Ian Elliott | 2c1daf5 | 2016-05-12 09:41:46 -0600 | [diff] [blame] | 2372 | vkGetPhysicalDeviceSurfacePresentModesKHR(gpu(), surface, NULL, NULL); |
| 2373 | pass = (err == VK_SUCCESS); |
| 2374 | ASSERT_TRUE(pass); |
| 2375 | m_errorMonitor->VerifyFound(); |
| 2376 | |
| 2377 | // Next, call with a non-NULL VkPresentModeKHR, even though we haven't |
| 2378 | // correctly done a 1st try (to get the count): |
| 2379 | m_errorMonitor->SetDesiredFailureMsg( |
| 2380 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 2381 | "but no prior positive value has been seen for"); |
| 2382 | surface_present_mode_count = 0; |
| 2383 | vkGetPhysicalDeviceSurfacePresentModesKHR( |
Mark Lobodzinski | 085d27a | 2016-05-17 09:34:26 -0600 | [diff] [blame] | 2384 | gpu(), surface, &surface_present_mode_count, |
| 2385 | (VkPresentModeKHR *)&surface_present_mode_count); |
Ian Elliott | 2c1daf5 | 2016-05-12 09:41:46 -0600 | [diff] [blame] | 2386 | pass = (err == VK_SUCCESS); |
| 2387 | ASSERT_TRUE(pass); |
| 2388 | m_errorMonitor->VerifyFound(); |
| 2389 | |
| 2390 | // 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] | 2391 | vkGetPhysicalDeviceSurfacePresentModesKHR( |
| 2392 | gpu(), surface, &surface_present_mode_count, NULL); |
Ian Elliott | 2c1daf5 | 2016-05-12 09:41:46 -0600 | [diff] [blame] | 2393 | pass = (err == VK_SUCCESS); |
| 2394 | ASSERT_TRUE(pass); |
| 2395 | |
| 2396 | // Allocate memory for the correct number of VkSurfaceFormatKHR's: |
Mark Lobodzinski | 085d27a | 2016-05-17 09:34:26 -0600 | [diff] [blame] | 2397 | VkPresentModeKHR *surface_present_modes = (VkPresentModeKHR *)malloc( |
| 2398 | surface_present_mode_count * sizeof(VkPresentModeKHR)); |
Ian Elliott | 2c1daf5 | 2016-05-12 09:41:46 -0600 | [diff] [blame] | 2399 | |
| 2400 | // Next, do a 2nd try with surface_format_count being set too high: |
| 2401 | surface_present_mode_count += 5; |
Mark Lobodzinski | 085d27a | 2016-05-17 09:34:26 -0600 | [diff] [blame] | 2402 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 2403 | "that is greater than the value"); |
| 2404 | vkGetPhysicalDeviceSurfacePresentModesKHR( |
| 2405 | gpu(), surface, &surface_present_mode_count, surface_present_modes); |
Ian Elliott | 2c1daf5 | 2016-05-12 09:41:46 -0600 | [diff] [blame] | 2406 | pass = (err == VK_SUCCESS); |
| 2407 | ASSERT_TRUE(pass); |
| 2408 | m_errorMonitor->VerifyFound(); |
| 2409 | |
| 2410 | // Finally, do a correct 1st and 2nd try: |
Mark Lobodzinski | 085d27a | 2016-05-17 09:34:26 -0600 | [diff] [blame] | 2411 | vkGetPhysicalDeviceSurfacePresentModesKHR( |
| 2412 | gpu(), surface, &surface_present_mode_count, NULL); |
Ian Elliott | 2c1daf5 | 2016-05-12 09:41:46 -0600 | [diff] [blame] | 2413 | pass = (err == VK_SUCCESS); |
| 2414 | ASSERT_TRUE(pass); |
Mark Lobodzinski | 085d27a | 2016-05-17 09:34:26 -0600 | [diff] [blame] | 2415 | vkGetPhysicalDeviceSurfacePresentModesKHR( |
| 2416 | gpu(), surface, &surface_present_mode_count, surface_present_modes); |
Ian Elliott | 2c1daf5 | 2016-05-12 09:41:46 -0600 | [diff] [blame] | 2417 | pass = (err == VK_SUCCESS); |
| 2418 | ASSERT_TRUE(pass); |
| 2419 | |
Ian Elliott | 2c1daf5 | 2016-05-12 09:41:46 -0600 | [diff] [blame] | 2420 | // Create a swapchain: |
| 2421 | |
| 2422 | // First, try without a pointer to swapchain_create_info: |
Mark Lobodzinski | 085d27a | 2016-05-17 09:34:26 -0600 | [diff] [blame] | 2423 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 2424 | "called with NULL pointer"); |
Ian Elliott | 2c1daf5 | 2016-05-12 09:41:46 -0600 | [diff] [blame] | 2425 | err = vkCreateSwapchainKHR(m_device->device(), NULL, NULL, &swapchain); |
| 2426 | pass = (err != VK_SUCCESS); |
| 2427 | ASSERT_TRUE(pass); |
| 2428 | m_errorMonitor->VerifyFound(); |
| 2429 | |
| 2430 | // Next, call with a non-NULL swapchain_create_info, that has the wrong |
| 2431 | // sType: |
| 2432 | swapchain_create_info.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO; |
Mark Lobodzinski | 085d27a | 2016-05-17 09:34:26 -0600 | [diff] [blame] | 2433 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 2434 | "called with the wrong value for"); |
| 2435 | err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, |
| 2436 | &swapchain); |
Ian Elliott | 2c1daf5 | 2016-05-12 09:41:46 -0600 | [diff] [blame] | 2437 | pass = (err != VK_SUCCESS); |
| 2438 | ASSERT_TRUE(pass); |
| 2439 | m_errorMonitor->VerifyFound(); |
| 2440 | |
| 2441 | // Next, call with a NULL swapchain pointer: |
| 2442 | swapchain_create_info.sType = VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR; |
| 2443 | swapchain_create_info.pNext = NULL; |
| 2444 | swapchain_create_info.flags = 0; |
Mark Lobodzinski | 085d27a | 2016-05-17 09:34:26 -0600 | [diff] [blame] | 2445 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 2446 | "called with NULL pointer"); |
| 2447 | err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, |
| 2448 | NULL); |
Ian Elliott | 2c1daf5 | 2016-05-12 09:41:46 -0600 | [diff] [blame] | 2449 | pass = (err != VK_SUCCESS); |
| 2450 | ASSERT_TRUE(pass); |
| 2451 | m_errorMonitor->VerifyFound(); |
| 2452 | |
Mark Lobodzinski | 085d27a | 2016-05-17 09:34:26 -0600 | [diff] [blame] | 2453 | // TODO: Enhance swapchain layer so that |
| 2454 | // swapchain_create_info.queueFamilyIndexCount is checked against something? |
Ian Elliott | 2c1daf5 | 2016-05-12 09:41:46 -0600 | [diff] [blame] | 2455 | |
| 2456 | // Next, call with a queue family index that's too large: |
| 2457 | uint32_t queueFamilyIndex[2] = {100000, 0}; |
| 2458 | swapchain_create_info.imageSharingMode = VK_SHARING_MODE_CONCURRENT; |
| 2459 | swapchain_create_info.queueFamilyIndexCount = 2; |
| 2460 | swapchain_create_info.pQueueFamilyIndices = queueFamilyIndex; |
| 2461 | m_errorMonitor->SetDesiredFailureMsg( |
| 2462 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 2463 | "called with a queueFamilyIndex that is too large"); |
Mark Lobodzinski | 085d27a | 2016-05-17 09:34:26 -0600 | [diff] [blame] | 2464 | err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, |
| 2465 | &swapchain); |
Ian Elliott | 2c1daf5 | 2016-05-12 09:41:46 -0600 | [diff] [blame] | 2466 | pass = (err != VK_SUCCESS); |
| 2467 | ASSERT_TRUE(pass); |
| 2468 | m_errorMonitor->VerifyFound(); |
| 2469 | |
| 2470 | // Next, call a queueFamilyIndexCount that's too small for CONCURRENT: |
| 2471 | swapchain_create_info.imageSharingMode = VK_SHARING_MODE_CONCURRENT; |
| 2472 | swapchain_create_info.queueFamilyIndexCount = 1; |
| 2473 | m_errorMonitor->SetDesiredFailureMsg( |
| 2474 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 2475 | "but with a bad value(s) for pCreateInfo->queueFamilyIndexCount or " |
| 2476 | "pCreateInfo->pQueueFamilyIndices)."); |
Mark Lobodzinski | 085d27a | 2016-05-17 09:34:26 -0600 | [diff] [blame] | 2477 | err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, |
| 2478 | &swapchain); |
Ian Elliott | 2c1daf5 | 2016-05-12 09:41:46 -0600 | [diff] [blame] | 2479 | pass = (err != VK_SUCCESS); |
| 2480 | ASSERT_TRUE(pass); |
| 2481 | m_errorMonitor->VerifyFound(); |
| 2482 | |
| 2483 | // Next, call with an invalid imageSharingMode: |
| 2484 | swapchain_create_info.imageSharingMode = VK_SHARING_MODE_MAX_ENUM; |
| 2485 | swapchain_create_info.queueFamilyIndexCount = 1; |
| 2486 | m_errorMonitor->SetDesiredFailureMsg( |
| 2487 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 2488 | "called with a non-supported pCreateInfo->imageSharingMode (i.e."); |
Mark Lobodzinski | 085d27a | 2016-05-17 09:34:26 -0600 | [diff] [blame] | 2489 | err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, |
| 2490 | &swapchain); |
Ian Elliott | 2c1daf5 | 2016-05-12 09:41:46 -0600 | [diff] [blame] | 2491 | pass = (err != VK_SUCCESS); |
| 2492 | ASSERT_TRUE(pass); |
| 2493 | m_errorMonitor->VerifyFound(); |
| 2494 | // Fix for the future: |
Mark Lobodzinski | 085d27a | 2016-05-17 09:34:26 -0600 | [diff] [blame] | 2495 | // FIXME: THIS ISN'T CORRECT--MUST QUERY UNTIL WE FIND A QUEUE FAMILY THAT'S |
| 2496 | // SUPPORTED |
Ian Elliott | 2c1daf5 | 2016-05-12 09:41:46 -0600 | [diff] [blame] | 2497 | swapchain_create_info.queueFamilyIndexCount = 0; |
| 2498 | queueFamilyIndex[0] = 0; |
| 2499 | swapchain_create_info.imageSharingMode = VK_SHARING_MODE_EXCLUSIVE; |
| 2500 | |
Mark Lobodzinski | 085d27a | 2016-05-17 09:34:26 -0600 | [diff] [blame] | 2501 | // TODO: CONTINUE TESTING VALIDATION OF vkCreateSwapchainKHR() ... |
Ian Elliott | 2c1daf5 | 2016-05-12 09:41:46 -0600 | [diff] [blame] | 2502 | // Get the images from a swapchain: |
Ian Elliott | 2c1daf5 | 2016-05-12 09:41:46 -0600 | [diff] [blame] | 2503 | // Acquire an image from a swapchain: |
Ian Elliott | 2c1daf5 | 2016-05-12 09:41:46 -0600 | [diff] [blame] | 2504 | // Present an image to a swapchain: |
Ian Elliott | 2c1daf5 | 2016-05-12 09:41:46 -0600 | [diff] [blame] | 2505 | // Destroy the swapchain: |
| 2506 | |
Mark Lobodzinski | 085d27a | 2016-05-17 09:34:26 -0600 | [diff] [blame] | 2507 | // TODOs: |
| 2508 | // |
| 2509 | // - Try destroying the device without first destroying the swapchain |
| 2510 | // |
| 2511 | // - Try destroying the device without first destroying the surface |
| 2512 | // |
| 2513 | // - Try destroying the surface without first destroying the swapchain |
Ian Elliott | 2c1daf5 | 2016-05-12 09:41:46 -0600 | [diff] [blame] | 2514 | |
| 2515 | // Destroy the surface: |
| 2516 | vkDestroySurfaceKHR(instance(), surface, NULL); |
| 2517 | |
Ian Elliott | 2c1daf5 | 2016-05-12 09:41:46 -0600 | [diff] [blame] | 2518 | // Tear down the window: |
| 2519 | xcb_destroy_window(connection, xcb_window); |
| 2520 | xcb_disconnect(connection); |
| 2521 | |
| 2522 | #else // VK_USE_PLATFORM_XCB_KHR |
Mark Lobodzinski | 085d27a | 2016-05-17 09:34:26 -0600 | [diff] [blame] | 2523 | return; |
Ian Elliott | 2c1daf5 | 2016-05-12 09:41:46 -0600 | [diff] [blame] | 2524 | #endif // VK_USE_PLATFORM_XCB_KHR |
| 2525 | } |
| 2526 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 2527 | TEST_F(VkLayerTest, MapMemWithoutHostVisibleBit) { |
| 2528 | VkResult err; |
| 2529 | bool pass; |
Mark Lobodzinski | 3780e14 | 2015-05-14 15:08:13 -0500 | [diff] [blame] | 2530 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 2531 | m_errorMonitor->SetDesiredFailureMsg( |
| 2532 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 2533 | "Mapping Memory without VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT"); |
| 2534 | |
Mark Lobodzinski | 3780e14 | 2015-05-14 15:08:13 -0500 | [diff] [blame] | 2535 | ASSERT_NO_FATAL_FAILURE(InitState()); |
Mark Lobodzinski | 3780e14 | 2015-05-14 15:08:13 -0500 | [diff] [blame] | 2536 | |
| 2537 | // 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] | 2538 | VkImage image; |
| 2539 | VkDeviceMemory mem; |
| 2540 | VkMemoryRequirements mem_reqs; |
Mark Lobodzinski | 3780e14 | 2015-05-14 15:08:13 -0500 | [diff] [blame] | 2541 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 2542 | const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM; |
| 2543 | const int32_t tex_width = 32; |
| 2544 | const int32_t tex_height = 32; |
Mark Lobodzinski | 3780e14 | 2015-05-14 15:08:13 -0500 | [diff] [blame] | 2545 | |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 2546 | VkImageCreateInfo image_create_info = {}; |
| 2547 | image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 2548 | image_create_info.pNext = NULL; |
| 2549 | image_create_info.imageType = VK_IMAGE_TYPE_2D; |
| 2550 | image_create_info.format = tex_format; |
| 2551 | image_create_info.extent.width = tex_width; |
| 2552 | image_create_info.extent.height = tex_height; |
| 2553 | image_create_info.extent.depth = 1; |
| 2554 | image_create_info.mipLevels = 1; |
| 2555 | image_create_info.arrayLayers = 1; |
| 2556 | image_create_info.samples = VK_SAMPLE_COUNT_1_BIT; |
| 2557 | image_create_info.tiling = VK_IMAGE_TILING_LINEAR; |
| 2558 | image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT; |
| 2559 | image_create_info.flags = 0; |
Mark Lobodzinski | 5fcc421 | 2015-09-14 17:43:42 -0600 | [diff] [blame] | 2560 | |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 2561 | VkMemoryAllocateInfo mem_alloc = {}; |
Chia-I Wu | 00ce540 | 2015-11-10 16:21:09 +0800 | [diff] [blame] | 2562 | mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 2563 | mem_alloc.pNext = NULL; |
| 2564 | mem_alloc.allocationSize = 0; |
| 2565 | // Introduce failure, do NOT set memProps to |
| 2566 | // VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT |
| 2567 | mem_alloc.memoryTypeIndex = 1; |
Mark Lobodzinski | 3780e14 | 2015-05-14 15:08:13 -0500 | [diff] [blame] | 2568 | |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 2569 | err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image); |
Mark Lobodzinski | 3780e14 | 2015-05-14 15:08:13 -0500 | [diff] [blame] | 2570 | ASSERT_VK_SUCCESS(err); |
| 2571 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 2572 | vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs); |
Mark Lobodzinski | 3780e14 | 2015-05-14 15:08:13 -0500 | [diff] [blame] | 2573 | |
Mark Lobodzinski | 2306535 | 2015-05-29 09:32:35 -0500 | [diff] [blame] | 2574 | mem_alloc.allocationSize = mem_reqs.size; |
Mark Lobodzinski | 3780e14 | 2015-05-14 15:08:13 -0500 | [diff] [blame] | 2575 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 2576 | pass = |
| 2577 | m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0, |
| 2578 | VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT); |
| 2579 | if (!pass) { // If we can't find any unmappable memory this test doesn't |
| 2580 | // make sense |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 2581 | vkDestroyImage(m_device->device(), image, NULL); |
Tony Barbour | 02fdc7d | 2015-08-04 16:13:01 -0600 | [diff] [blame] | 2582 | return; |
Mike Stroyan | d1c84a5 | 2015-08-18 14:40:24 -0600 | [diff] [blame] | 2583 | } |
Mike Stroyan | 713b2d7 | 2015-08-04 10:49:29 -0600 | [diff] [blame] | 2584 | |
Mark Lobodzinski | 3780e14 | 2015-05-14 15:08:13 -0500 | [diff] [blame] | 2585 | // allocate memory |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 2586 | err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem); |
Mark Lobodzinski | 3780e14 | 2015-05-14 15:08:13 -0500 | [diff] [blame] | 2587 | ASSERT_VK_SUCCESS(err); |
| 2588 | |
| 2589 | // Try to bind free memory that has been freed |
Tony Barbour | 67e9915 | 2015-07-10 14:10:27 -0600 | [diff] [blame] | 2590 | err = vkBindImageMemory(m_device->device(), image, mem, 0); |
Mark Lobodzinski | 3780e14 | 2015-05-14 15:08:13 -0500 | [diff] [blame] | 2591 | ASSERT_VK_SUCCESS(err); |
| 2592 | |
| 2593 | // Map memory as if to initialize the image |
| 2594 | void *mappedAddress = NULL; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 2595 | err = vkMapMemory(m_device->device(), mem, 0, VK_WHOLE_SIZE, 0, |
| 2596 | &mappedAddress); |
Mark Lobodzinski | 3780e14 | 2015-05-14 15:08:13 -0500 | [diff] [blame] | 2597 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 2598 | m_errorMonitor->VerifyFound(); |
Mike Stroyan | d1c84a5 | 2015-08-18 14:40:24 -0600 | [diff] [blame] | 2599 | |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 2600 | vkDestroyImage(m_device->device(), image, NULL); |
Tony Barbour | df4c004 | 2016-06-01 15:55:43 -0600 | [diff] [blame] | 2601 | vkFreeMemory(m_device->device(), mem, NULL); |
Mark Lobodzinski | 3780e14 | 2015-05-14 15:08:13 -0500 | [diff] [blame] | 2602 | } |
| 2603 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 2604 | TEST_F(VkLayerTest, RebindMemory) { |
| 2605 | VkResult err; |
| 2606 | bool pass; |
Mark Lobodzinski | 944aab1 | 2015-06-05 13:59:04 -0500 | [diff] [blame] | 2607 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 2608 | m_errorMonitor->SetDesiredFailureMsg( |
| 2609 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 2610 | "which has already been bound to mem object"); |
| 2611 | |
Mark Lobodzinski | 944aab1 | 2015-06-05 13:59:04 -0500 | [diff] [blame] | 2612 | ASSERT_NO_FATAL_FAILURE(InitState()); |
Mark Lobodzinski | 944aab1 | 2015-06-05 13:59:04 -0500 | [diff] [blame] | 2613 | |
| 2614 | // 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] | 2615 | VkImage image; |
| 2616 | VkDeviceMemory mem1; |
| 2617 | VkDeviceMemory mem2; |
| 2618 | VkMemoryRequirements mem_reqs; |
Mark Lobodzinski | 944aab1 | 2015-06-05 13:59:04 -0500 | [diff] [blame] | 2619 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 2620 | const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM; |
| 2621 | const int32_t tex_width = 32; |
| 2622 | const int32_t tex_height = 32; |
Mark Lobodzinski | 944aab1 | 2015-06-05 13:59:04 -0500 | [diff] [blame] | 2623 | |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 2624 | VkImageCreateInfo image_create_info = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 2625 | image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO; |
| 2626 | image_create_info.pNext = NULL; |
| 2627 | image_create_info.imageType = VK_IMAGE_TYPE_2D; |
| 2628 | image_create_info.format = tex_format; |
| 2629 | image_create_info.extent.width = tex_width; |
| 2630 | image_create_info.extent.height = tex_height; |
| 2631 | image_create_info.extent.depth = 1; |
| 2632 | image_create_info.mipLevels = 1; |
| 2633 | image_create_info.arrayLayers = 1; |
| 2634 | image_create_info.samples = VK_SAMPLE_COUNT_1_BIT; |
| 2635 | image_create_info.tiling = VK_IMAGE_TILING_LINEAR; |
| 2636 | image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT; |
| 2637 | image_create_info.flags = 0; |
Mark Lobodzinski | 944aab1 | 2015-06-05 13:59:04 -0500 | [diff] [blame] | 2638 | |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 2639 | VkMemoryAllocateInfo mem_alloc = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 2640 | mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO; |
| 2641 | mem_alloc.pNext = NULL; |
| 2642 | mem_alloc.allocationSize = 0; |
| 2643 | mem_alloc.memoryTypeIndex = 0; |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 2644 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 2645 | // Introduce failure, do NOT set memProps to |
| 2646 | // VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 2647 | mem_alloc.memoryTypeIndex = 1; |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 2648 | err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image); |
Mark Lobodzinski | 944aab1 | 2015-06-05 13:59:04 -0500 | [diff] [blame] | 2649 | ASSERT_VK_SUCCESS(err); |
| 2650 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 2651 | vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs); |
Mark Lobodzinski | 944aab1 | 2015-06-05 13:59:04 -0500 | [diff] [blame] | 2652 | |
| 2653 | mem_alloc.allocationSize = mem_reqs.size; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 2654 | pass = |
| 2655 | m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0); |
Courtney Goeltzenleuchter | 1d2f0dd | 2015-10-22 11:03:31 -0600 | [diff] [blame] | 2656 | ASSERT_TRUE(pass); |
Mark Lobodzinski | 944aab1 | 2015-06-05 13:59:04 -0500 | [diff] [blame] | 2657 | |
| 2658 | // allocate 2 memory objects |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 2659 | err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem1); |
Mark Lobodzinski | 944aab1 | 2015-06-05 13:59:04 -0500 | [diff] [blame] | 2660 | ASSERT_VK_SUCCESS(err); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 2661 | err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem2); |
Mark Lobodzinski | 944aab1 | 2015-06-05 13:59:04 -0500 | [diff] [blame] | 2662 | ASSERT_VK_SUCCESS(err); |
| 2663 | |
| 2664 | // Bind first memory object to Image object |
Tony Barbour | 67e9915 | 2015-07-10 14:10:27 -0600 | [diff] [blame] | 2665 | err = vkBindImageMemory(m_device->device(), image, mem1, 0); |
Mark Lobodzinski | 944aab1 | 2015-06-05 13:59:04 -0500 | [diff] [blame] | 2666 | ASSERT_VK_SUCCESS(err); |
| 2667 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 2668 | // Introduce validation failure, try to bind a different memory object to |
| 2669 | // the same image object |
Tony Barbour | 67e9915 | 2015-07-10 14:10:27 -0600 | [diff] [blame] | 2670 | err = vkBindImageMemory(m_device->device(), image, mem2, 0); |
Mark Lobodzinski | 944aab1 | 2015-06-05 13:59:04 -0500 | [diff] [blame] | 2671 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 2672 | m_errorMonitor->VerifyFound(); |
Mike Stroyan | d1c84a5 | 2015-08-18 14:40:24 -0600 | [diff] [blame] | 2673 | |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 2674 | vkDestroyImage(m_device->device(), image, NULL); |
| 2675 | vkFreeMemory(m_device->device(), mem1, NULL); |
| 2676 | vkFreeMemory(m_device->device(), mem2, NULL); |
Mark Lobodzinski | 944aab1 | 2015-06-05 13:59:04 -0500 | [diff] [blame] | 2677 | } |
Mark Lobodzinski | 3780e14 | 2015-05-14 15:08:13 -0500 | [diff] [blame] | 2678 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 2679 | TEST_F(VkLayerTest, SubmitSignaledFence) { |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 2680 | vk_testing::Fence testFence; |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 2681 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 2682 | m_errorMonitor->SetDesiredFailureMsg( |
| 2683 | VK_DEBUG_REPORT_ERROR_BIT_EXT, "submitted in SIGNALED state. Fences " |
| 2684 | "must be reset before being submitted"); |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 2685 | |
| 2686 | VkFenceCreateInfo fenceInfo = {}; |
Tony Barbour | 0b4d956 | 2015-04-09 10:48:04 -0600 | [diff] [blame] | 2687 | fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO; |
| 2688 | fenceInfo.pNext = NULL; |
| 2689 | fenceInfo.flags = VK_FENCE_CREATE_SIGNALED_BIT; |
Tony Barbour | 300a608 | 2015-04-07 13:44:53 -0600 | [diff] [blame] | 2690 | |
Tony Barbour | 300a608 | 2015-04-07 13:44:53 -0600 | [diff] [blame] | 2691 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 2692 | ASSERT_NO_FATAL_FAILURE(InitViewport()); |
| 2693 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 2694 | |
Tony Barbour | fe3351b | 2015-07-28 10:17:20 -0600 | [diff] [blame] | 2695 | BeginCommandBuffer(); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 2696 | m_commandBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color, |
| 2697 | m_stencil_clear_color, NULL); |
Tony Barbour | fe3351b | 2015-07-28 10:17:20 -0600 | [diff] [blame] | 2698 | EndCommandBuffer(); |
Tony Barbour | 300a608 | 2015-04-07 13:44:53 -0600 | [diff] [blame] | 2699 | |
| 2700 | testFence.init(*m_device, fenceInfo); |
Mark Lobodzinski | 5fcc421 | 2015-09-14 17:43:42 -0600 | [diff] [blame] | 2701 | |
Courtney Goeltzenleuchter | 806c700 | 2015-10-27 11:22:14 -0600 | [diff] [blame] | 2702 | VkSubmitInfo submit_info; |
Chia-I Wu | f9be13c | 2015-10-26 20:37:06 +0800 | [diff] [blame] | 2703 | submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO; |
| 2704 | submit_info.pNext = NULL; |
Chia-I Wu | d50a7d7 | 2015-10-26 20:48:51 +0800 | [diff] [blame] | 2705 | submit_info.waitSemaphoreCount = 0; |
Courtney Goeltzenleuchter | 806c700 | 2015-10-27 11:22:14 -0600 | [diff] [blame] | 2706 | submit_info.pWaitSemaphores = NULL; |
Jon Ashburn | 7f9716c | 2015-12-30 16:42:50 -0700 | [diff] [blame] | 2707 | submit_info.pWaitDstStageMask = NULL; |
Chia-I Wu | d50a7d7 | 2015-10-26 20:48:51 +0800 | [diff] [blame] | 2708 | submit_info.commandBufferCount = 1; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 2709 | submit_info.pCommandBuffers = &m_commandBuffer->handle(); |
Chia-I Wu | d50a7d7 | 2015-10-26 20:48:51 +0800 | [diff] [blame] | 2710 | submit_info.signalSemaphoreCount = 0; |
Courtney Goeltzenleuchter | 806c700 | 2015-10-27 11:22:14 -0600 | [diff] [blame] | 2711 | submit_info.pSignalSemaphores = NULL; |
Courtney Goeltzenleuchter | 646b907 | 2015-10-20 18:04:07 -0600 | [diff] [blame] | 2712 | |
| 2713 | vkQueueSubmit(m_device->m_queue, 1, &submit_info, testFence.handle()); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 2714 | vkQueueWaitIdle(m_device->m_queue); |
Mark Lobodzinski | 5fcc421 | 2015-09-14 17:43:42 -0600 | [diff] [blame] | 2715 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 2716 | m_errorMonitor->VerifyFound(); |
Tony Barbour | 0b4d956 | 2015-04-09 10:48:04 -0600 | [diff] [blame] | 2717 | } |
Tobin Ehlis | aff7ae9 | 2016-04-18 15:45:20 -0600 | [diff] [blame] | 2718 | // This is a positive test. We used to expect error in this case but spec now |
| 2719 | // allows it |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 2720 | TEST_F(VkLayerTest, ResetUnsignaledFence) { |
Tobin Ehlis | aff7ae9 | 2016-04-18 15:45:20 -0600 | [diff] [blame] | 2721 | m_errorMonitor->ExpectSuccess(); |
Tony Barbour | 0b4d956 | 2015-04-09 10:48:04 -0600 | [diff] [blame] | 2722 | vk_testing::Fence testFence; |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 2723 | VkFenceCreateInfo fenceInfo = {}; |
Tony Barbour | 0b4d956 | 2015-04-09 10:48:04 -0600 | [diff] [blame] | 2724 | fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO; |
| 2725 | fenceInfo.pNext = NULL; |
| 2726 | |
Tony Barbour | 0b4d956 | 2015-04-09 10:48:04 -0600 | [diff] [blame] | 2727 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 2728 | testFence.init(*m_device, fenceInfo); |
Chia-I Wu | d9e8e82 | 2015-07-03 11:45:55 +0800 | [diff] [blame] | 2729 | VkFence fences[1] = {testFence.handle()}; |
Tobin Ehlis | aff7ae9 | 2016-04-18 15:45:20 -0600 | [diff] [blame] | 2730 | VkResult result = vkResetFences(m_device->device(), 1, fences); |
| 2731 | ASSERT_VK_SUCCESS(result); |
Tony Barbour | 300a608 | 2015-04-07 13:44:53 -0600 | [diff] [blame] | 2732 | |
Tobin Ehlis | aff7ae9 | 2016-04-18 15:45:20 -0600 | [diff] [blame] | 2733 | m_errorMonitor->VerifyNotFound(); |
Tony Barbour | 300a608 | 2015-04-07 13:44:53 -0600 | [diff] [blame] | 2734 | } |
Tobin Ehlis | 41376e1 | 2015-07-03 08:45:14 -0600 | [diff] [blame] | 2735 | |
Chris Forbes | e70b7d3 | 2016-06-15 15:49:12 +1200 | [diff] [blame] | 2736 | #if 0 |
| 2737 | TEST_F(VkLayerTest, LongFenceChain) |
| 2738 | { |
| 2739 | m_errorMonitor->ExpectSuccess(); |
| 2740 | |
| 2741 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 2742 | VkResult err; |
| 2743 | |
| 2744 | std::vector<VkFence> fences; |
| 2745 | |
| 2746 | const int chainLength = 32768; |
| 2747 | |
| 2748 | for (int i = 0; i < chainLength; i++) { |
| 2749 | VkFenceCreateInfo fci = { VK_STRUCTURE_TYPE_FENCE_CREATE_INFO, nullptr, 0 }; |
| 2750 | VkFence fence; |
| 2751 | err = vkCreateFence(m_device->device(), &fci, nullptr, &fence); |
| 2752 | ASSERT_VK_SUCCESS(err); |
| 2753 | |
| 2754 | fences.push_back(fence); |
| 2755 | |
| 2756 | VkSubmitInfo si = { VK_STRUCTURE_TYPE_SUBMIT_INFO, nullptr, 0, nullptr, nullptr, |
| 2757 | 0, nullptr, 0, nullptr }; |
| 2758 | err = vkQueueSubmit(m_device->m_queue, 1, &si, fence); |
| 2759 | ASSERT_VK_SUCCESS(err); |
| 2760 | |
| 2761 | } |
| 2762 | |
| 2763 | // BOOM, stack overflow. |
| 2764 | vkWaitForFences(m_device->device(), 1, &fences.back(), VK_TRUE, UINT64_MAX); |
| 2765 | |
| 2766 | for (auto fence : fences) |
| 2767 | vkDestroyFence(m_device->device(), fence, nullptr); |
| 2768 | |
| 2769 | m_errorMonitor->VerifyNotFound(); |
| 2770 | } |
| 2771 | #endif |
| 2772 | |
Chris Forbes | 18127d1 | 2016-06-08 16:52:28 +1200 | [diff] [blame] | 2773 | TEST_F(VkLayerTest, CommandBufferSimultaneousUseSync) |
| 2774 | { |
| 2775 | m_errorMonitor->ExpectSuccess(); |
| 2776 | |
| 2777 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 2778 | VkResult err; |
| 2779 | |
| 2780 | // Record (empty!) command buffer that can be submitted multiple times |
| 2781 | // simultaneously. |
| 2782 | VkCommandBufferBeginInfo cbbi = { |
| 2783 | VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO, nullptr, |
| 2784 | VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT, nullptr |
| 2785 | }; |
| 2786 | m_commandBuffer->BeginCommandBuffer(&cbbi); |
| 2787 | m_commandBuffer->EndCommandBuffer(); |
| 2788 | |
| 2789 | VkFenceCreateInfo fci = { VK_STRUCTURE_TYPE_FENCE_CREATE_INFO, nullptr, 0 }; |
| 2790 | VkFence fence; |
| 2791 | err = vkCreateFence(m_device->device(), &fci, nullptr, &fence); |
| 2792 | ASSERT_VK_SUCCESS(err); |
| 2793 | |
| 2794 | VkSemaphoreCreateInfo sci = { VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO, nullptr, 0 }; |
| 2795 | VkSemaphore s1, s2; |
| 2796 | err = vkCreateSemaphore(m_device->device(), &sci, nullptr, &s1); |
| 2797 | ASSERT_VK_SUCCESS(err); |
| 2798 | err = vkCreateSemaphore(m_device->device(), &sci, nullptr, &s2); |
| 2799 | ASSERT_VK_SUCCESS(err); |
| 2800 | |
| 2801 | // Submit CB once signaling s1, with fence so we can roll forward to its retirement. |
| 2802 | VkSubmitInfo si = { VK_STRUCTURE_TYPE_SUBMIT_INFO, nullptr, 0, nullptr, nullptr, |
| 2803 | 1, &m_commandBuffer->handle(), 1, &s1 }; |
| 2804 | err = vkQueueSubmit(m_device->m_queue, 1, &si, fence); |
| 2805 | ASSERT_VK_SUCCESS(err); |
| 2806 | |
| 2807 | // Submit CB again, signaling s2. |
| 2808 | si.pSignalSemaphores = &s2; |
| 2809 | err = vkQueueSubmit(m_device->m_queue, 1, &si, VK_NULL_HANDLE); |
| 2810 | ASSERT_VK_SUCCESS(err); |
| 2811 | |
| 2812 | // Wait for fence. |
| 2813 | err = vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX); |
| 2814 | ASSERT_VK_SUCCESS(err); |
| 2815 | |
| 2816 | // CB is still in flight from second submission, but semaphore s1 is no |
| 2817 | // longer in flight. delete it. |
| 2818 | vkDestroySemaphore(m_device->device(), s1, nullptr); |
| 2819 | |
| 2820 | m_errorMonitor->VerifyNotFound(); |
| 2821 | |
| 2822 | // Force device idle and clean up remaining objects |
| 2823 | vkDeviceWaitIdle(m_device->device()); |
| 2824 | vkDestroySemaphore(m_device->device(), s2, nullptr); |
| 2825 | vkDestroyFence(m_device->device(), fence, nullptr); |
| 2826 | } |
| 2827 | |
Chris Forbes | 4e44c91 | 2016-06-16 10:20:00 +1200 | [diff] [blame] | 2828 | TEST_F(VkLayerTest, FenceCreateSignaledWaitHandling) |
| 2829 | { |
| 2830 | m_errorMonitor->ExpectSuccess(); |
| 2831 | |
| 2832 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 2833 | VkResult err; |
| 2834 | |
| 2835 | // A fence created signaled |
| 2836 | VkFenceCreateInfo fci1 = { VK_STRUCTURE_TYPE_FENCE_CREATE_INFO, nullptr, VK_FENCE_CREATE_SIGNALED_BIT }; |
| 2837 | VkFence f1; |
| 2838 | err = vkCreateFence(m_device->device(), &fci1, nullptr, &f1); |
| 2839 | ASSERT_VK_SUCCESS(err); |
| 2840 | |
| 2841 | // A fence created not |
| 2842 | VkFenceCreateInfo fci2 = { VK_STRUCTURE_TYPE_FENCE_CREATE_INFO, nullptr, 0 }; |
| 2843 | VkFence f2; |
| 2844 | err = vkCreateFence(m_device->device(), &fci2, nullptr, &f2); |
| 2845 | ASSERT_VK_SUCCESS(err); |
| 2846 | |
| 2847 | // Submit the unsignaled fence |
| 2848 | VkSubmitInfo si = { VK_STRUCTURE_TYPE_SUBMIT_INFO, nullptr, 0, nullptr, nullptr, |
| 2849 | 0, nullptr, 0, nullptr }; |
| 2850 | err = vkQueueSubmit(m_device->m_queue, 1, &si, f2); |
| 2851 | |
| 2852 | // Wait on both fences, with signaled first. |
| 2853 | VkFence fences[] = { f1, f2 }; |
| 2854 | vkWaitForFences(m_device->device(), 2, fences, VK_TRUE, UINT64_MAX); |
| 2855 | |
| 2856 | // Should have both retired! |
| 2857 | vkDestroyFence(m_device->device(), f1, nullptr); |
| 2858 | vkDestroyFence(m_device->device(), f2, nullptr); |
| 2859 | |
| 2860 | m_errorMonitor->VerifyNotFound(); |
| 2861 | } |
| 2862 | |
Tobin Ehlis | 41376e1 | 2015-07-03 08:45:14 -0600 | [diff] [blame] | 2863 | TEST_F(VkLayerTest, InvalidUsageBits) |
| 2864 | { |
Tony Barbour | f92621a | 2016-05-02 14:28:12 -0600 | [diff] [blame] | 2865 | TEST_DESCRIPTION( |
Karl Schultz | b5bc11e | 2016-05-04 08:36:08 -0600 | [diff] [blame] | 2866 | "Specify wrong usage for image then create conflicting view of image " |
Tony Barbour | f92621a | 2016-05-02 14:28:12 -0600 | [diff] [blame] | 2867 | "Initialize buffer with wrong usage then perform copy expecting errors " |
| 2868 | "from both the image and the buffer (2 calls)"); |
Courtney Goeltzenleuchter | 7415d5a | 2015-12-09 15:48:16 -0700 | [diff] [blame] | 2869 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 2870 | "Invalid usage flag for image "); |
Tobin Ehlis | 41376e1 | 2015-07-03 08:45:14 -0600 | [diff] [blame] | 2871 | |
| 2872 | ASSERT_NO_FATAL_FAILURE(InitState()); |
Tony Barbour | f92621a | 2016-05-02 14:28:12 -0600 | [diff] [blame] | 2873 | VkImageObj image(m_device); |
| 2874 | // Initialize image with USAGE_INPUT_ATTACHMENT |
Tobin Ehlis | 8b313c0 | 2016-05-25 15:01:52 -0600 | [diff] [blame] | 2875 | image.init(128, 128, VK_FORMAT_D24_UNORM_S8_UINT, |
Karl Schultz | b5bc11e | 2016-05-04 08:36:08 -0600 | [diff] [blame] | 2876 | VK_IMAGE_USAGE_INPUT_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0); |
| 2877 | ASSERT_TRUE(image.initialized()); |
Tobin Ehlis | 41376e1 | 2015-07-03 08:45:14 -0600 | [diff] [blame] | 2878 | |
Tony Barbour | f92621a | 2016-05-02 14:28:12 -0600 | [diff] [blame] | 2879 | VkImageView dsv; |
| 2880 | VkImageViewCreateInfo dsvci = {}; |
| 2881 | dsvci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO; |
| 2882 | dsvci.image = image.handle(); |
| 2883 | dsvci.viewType = VK_IMAGE_VIEW_TYPE_2D; |
| 2884 | dsvci.format = VK_FORMAT_D32_SFLOAT_S8_UINT; |
| 2885 | dsvci.subresourceRange.layerCount = 1; |
| 2886 | dsvci.subresourceRange.baseMipLevel = 0; |
| 2887 | dsvci.subresourceRange.levelCount = 1; |
| 2888 | dsvci.subresourceRange.aspectMask = |
| 2889 | VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT; |
Tobin Ehlis | 41376e1 | 2015-07-03 08:45:14 -0600 | [diff] [blame] | 2890 | |
Tony Barbour | f92621a | 2016-05-02 14:28:12 -0600 | [diff] [blame] | 2891 | // Create a view with depth / stencil aspect for image with different usage |
| 2892 | vkCreateImageView(m_device->device(), &dsvci, NULL, &dsv); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 2893 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 2894 | m_errorMonitor->VerifyFound(); |
Tony Barbour | f92621a | 2016-05-02 14:28:12 -0600 | [diff] [blame] | 2895 | |
| 2896 | // Initialize buffer with TRANSFER_DST usage |
| 2897 | vk_testing::Buffer buffer; |
| 2898 | VkMemoryPropertyFlags reqs = 0; |
| 2899 | buffer.init_as_dst(*m_device, 128 * 128, reqs); |
| 2900 | VkBufferImageCopy region = {}; |
| 2901 | region.bufferRowLength = 128; |
| 2902 | region.bufferImageHeight = 128; |
| 2903 | region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; |
| 2904 | region.imageSubresource.layerCount = 1; |
| 2905 | region.imageExtent.height = 16; |
| 2906 | region.imageExtent.width = 16; |
| 2907 | region.imageExtent.depth = 1; |
| 2908 | |
| 2909 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 2910 | "Invalid usage flag for buffer "); |
| 2911 | // Buffer usage not set to TRANSFER_SRC and image usage not set to |
| 2912 | // TRANSFER_DST |
| 2913 | BeginCommandBuffer(); |
| 2914 | vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), |
| 2915 | image.handle(), VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, |
| 2916 | 1, ®ion); |
| 2917 | m_errorMonitor->VerifyFound(); |
| 2918 | |
| 2919 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 2920 | "Invalid usage flag for image "); |
| 2921 | vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), |
| 2922 | image.handle(), VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, |
| 2923 | 1, ®ion); |
| 2924 | m_errorMonitor->VerifyFound(); |
Tobin Ehlis | 41376e1 | 2015-07-03 08:45:14 -0600 | [diff] [blame] | 2925 | } |
Mark Lobodzinski | 209b529 | 2015-09-17 09:44:05 -0600 | [diff] [blame] | 2926 | #endif // MEM_TRACKER_TESTS |
| 2927 | |
Tobin Ehlis | 4bf96d1 | 2015-06-25 11:58:41 -0600 | [diff] [blame] | 2928 | #if OBJ_TRACKER_TESTS |
Mark Lobodzinski | fc5cc66 | 2016-05-02 17:17:41 -0600 | [diff] [blame] | 2929 | |
| 2930 | TEST_F(VkLayerTest, LeakAnObject) { |
| 2931 | VkResult err; |
| 2932 | |
| 2933 | TEST_DESCRIPTION( |
| 2934 | "Create a fence and destroy its device without first destroying the fence."); |
| 2935 | |
| 2936 | // Note that we have to create a new device since destroying the |
| 2937 | // framework's device causes Teardown() to fail and just calling Teardown |
| 2938 | // will destroy the errorMonitor. |
| 2939 | |
| 2940 | m_errorMonitor->SetDesiredFailureMsg( |
| 2941 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 2942 | "OBJ ERROR : VK_DEBUG_REPORT_OBJECT_TYPE_FENCE_EXT object"); |
| 2943 | |
| 2944 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 2945 | |
| 2946 | const std::vector<VkQueueFamilyProperties> queue_props = |
| 2947 | m_device->queue_props; |
| 2948 | std::vector<VkDeviceQueueCreateInfo> queue_info; |
| 2949 | queue_info.reserve(queue_props.size()); |
| 2950 | std::vector<std::vector<float>> queue_priorities; |
| 2951 | for (uint32_t i = 0; i < (uint32_t)queue_props.size(); i++) { |
| 2952 | VkDeviceQueueCreateInfo qi = {}; |
| 2953 | qi.sType = VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO; |
| 2954 | qi.pNext = NULL; |
| 2955 | qi.queueFamilyIndex = i; |
| 2956 | qi.queueCount = queue_props[i].queueCount; |
| 2957 | queue_priorities.emplace_back(qi.queueCount, 0.0f); |
| 2958 | qi.pQueuePriorities = queue_priorities[i].data(); |
| 2959 | queue_info.push_back(qi); |
| 2960 | } |
| 2961 | |
| 2962 | std::vector<const char *> device_layer_names; |
| 2963 | std::vector<const char *> device_extension_names; |
| 2964 | device_layer_names.push_back("VK_LAYER_GOOGLE_threading"); |
| 2965 | device_layer_names.push_back("VK_LAYER_LUNARG_parameter_validation"); |
| 2966 | device_layer_names.push_back("VK_LAYER_LUNARG_object_tracker"); |
| 2967 | device_layer_names.push_back("VK_LAYER_LUNARG_core_validation"); |
Mark Lobodzinski | fc5cc66 | 2016-05-02 17:17:41 -0600 | [diff] [blame] | 2968 | device_layer_names.push_back("VK_LAYER_LUNARG_image"); |
| 2969 | device_layer_names.push_back("VK_LAYER_GOOGLE_unique_objects"); |
| 2970 | |
| 2971 | // The sacrificial device object |
| 2972 | VkDevice testDevice; |
| 2973 | VkDeviceCreateInfo device_create_info = {}; |
| 2974 | auto features = m_device->phy().features(); |
| 2975 | device_create_info.sType = VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO; |
| 2976 | device_create_info.pNext = NULL; |
| 2977 | device_create_info.queueCreateInfoCount = queue_info.size(); |
| 2978 | device_create_info.pQueueCreateInfos = queue_info.data(); |
| 2979 | device_create_info.enabledLayerCount = device_layer_names.size(); |
| 2980 | device_create_info.ppEnabledLayerNames = device_layer_names.data(); |
| 2981 | device_create_info.pEnabledFeatures = &features; |
| 2982 | err = vkCreateDevice(gpu(), &device_create_info, NULL, &testDevice); |
| 2983 | ASSERT_VK_SUCCESS(err); |
| 2984 | |
| 2985 | VkFence fence; |
| 2986 | VkFenceCreateInfo fence_create_info = {}; |
| 2987 | fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO; |
| 2988 | fence_create_info.pNext = NULL; |
| 2989 | fence_create_info.flags = 0; |
| 2990 | err = vkCreateFence(testDevice, &fence_create_info, NULL, &fence); |
| 2991 | ASSERT_VK_SUCCESS(err); |
| 2992 | |
| 2993 | // Induce failure by not calling vkDestroyFence |
| 2994 | vkDestroyDevice(testDevice, NULL); |
| 2995 | m_errorMonitor->VerifyFound(); |
| 2996 | } |
| 2997 | |
| 2998 | TEST_F(VkLayerTest, InvalidCommandPoolConsistency) { |
| 2999 | |
| 3000 | TEST_DESCRIPTION("Allocate command buffers from one command pool and " |
| 3001 | "attempt to delete them from another."); |
| 3002 | |
| 3003 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 3004 | "FreeCommandBuffers is attempting to free Command Buffer"); |
| 3005 | |
| 3006 | VkCommandPool command_pool_one; |
| 3007 | VkCommandPool command_pool_two; |
| 3008 | |
| 3009 | VkCommandPoolCreateInfo pool_create_info{}; |
| 3010 | pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO; |
| 3011 | pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_; |
| 3012 | pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT; |
| 3013 | |
| 3014 | vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, |
| 3015 | &command_pool_one); |
| 3016 | |
| 3017 | vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, |
| 3018 | &command_pool_two); |
| 3019 | |
| 3020 | VkCommandBuffer command_buffer[9]; |
| 3021 | VkCommandBufferAllocateInfo command_buffer_allocate_info{}; |
| 3022 | command_buffer_allocate_info.sType = |
| 3023 | VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO; |
| 3024 | command_buffer_allocate_info.commandPool = command_pool_one; |
| 3025 | command_buffer_allocate_info.commandBufferCount = 9; |
| 3026 | command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY; |
| 3027 | vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, |
| 3028 | command_buffer); |
| 3029 | |
| 3030 | vkFreeCommandBuffers(m_device->device(), command_pool_two, 4, |
| 3031 | &command_buffer[3]); |
| 3032 | |
| 3033 | m_errorMonitor->VerifyFound(); |
| 3034 | |
| 3035 | vkDestroyCommandPool(m_device->device(), command_pool_one, NULL); |
| 3036 | vkDestroyCommandPool(m_device->device(), command_pool_two, NULL); |
| 3037 | } |
| 3038 | |
| 3039 | TEST_F(VkLayerTest, InvalidDescriptorPoolConsistency) { |
| 3040 | VkResult err; |
| 3041 | |
| 3042 | TEST_DESCRIPTION("Allocate descriptor sets from one DS pool and " |
| 3043 | "attempt to delete them from another."); |
| 3044 | |
| 3045 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 3046 | "FreeDescriptorSets is attempting to free descriptorSet"); |
| 3047 | |
| 3048 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 3049 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 3050 | |
| 3051 | VkDescriptorPoolSize ds_type_count = {}; |
| 3052 | ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLER; |
| 3053 | ds_type_count.descriptorCount = 1; |
| 3054 | |
| 3055 | VkDescriptorPoolCreateInfo ds_pool_ci = {}; |
| 3056 | ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO; |
| 3057 | ds_pool_ci.pNext = NULL; |
| 3058 | ds_pool_ci.flags = 0; |
| 3059 | ds_pool_ci.maxSets = 1; |
| 3060 | ds_pool_ci.poolSizeCount = 1; |
| 3061 | ds_pool_ci.pPoolSizes = &ds_type_count; |
| 3062 | |
| 3063 | VkDescriptorPool ds_pool_one; |
| 3064 | err = |
| 3065 | vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool_one); |
| 3066 | ASSERT_VK_SUCCESS(err); |
| 3067 | |
| 3068 | // Create a second descriptor pool |
| 3069 | VkDescriptorPool ds_pool_two; |
| 3070 | err = |
| 3071 | vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool_two); |
| 3072 | ASSERT_VK_SUCCESS(err); |
| 3073 | |
| 3074 | VkDescriptorSetLayoutBinding dsl_binding = {}; |
| 3075 | dsl_binding.binding = 0; |
| 3076 | dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER; |
| 3077 | dsl_binding.descriptorCount = 1; |
| 3078 | dsl_binding.stageFlags = VK_SHADER_STAGE_ALL; |
| 3079 | dsl_binding.pImmutableSamplers = NULL; |
| 3080 | |
| 3081 | VkDescriptorSetLayoutCreateInfo ds_layout_ci = {}; |
| 3082 | ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO; |
| 3083 | ds_layout_ci.pNext = NULL; |
| 3084 | ds_layout_ci.bindingCount = 1; |
| 3085 | ds_layout_ci.pBindings = &dsl_binding; |
| 3086 | |
| 3087 | VkDescriptorSetLayout ds_layout; |
| 3088 | err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, |
| 3089 | &ds_layout); |
| 3090 | ASSERT_VK_SUCCESS(err); |
| 3091 | |
| 3092 | VkDescriptorSet descriptorSet; |
| 3093 | VkDescriptorSetAllocateInfo alloc_info = {}; |
| 3094 | alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO; |
| 3095 | alloc_info.descriptorSetCount = 1; |
| 3096 | alloc_info.descriptorPool = ds_pool_one; |
| 3097 | alloc_info.pSetLayouts = &ds_layout; |
| 3098 | err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, |
| 3099 | &descriptorSet); |
| 3100 | ASSERT_VK_SUCCESS(err); |
| 3101 | |
| 3102 | err = vkFreeDescriptorSets(m_device->device(), ds_pool_two, 1, &descriptorSet); |
| 3103 | |
| 3104 | m_errorMonitor->VerifyFound(); |
| 3105 | |
| 3106 | vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL); |
| 3107 | vkDestroyDescriptorPool(m_device->device(), ds_pool_one, NULL); |
| 3108 | vkDestroyDescriptorPool(m_device->device(), ds_pool_two, NULL); |
| 3109 | } |
| 3110 | |
| 3111 | TEST_F(VkLayerTest, CreateUnknownObject) { |
| 3112 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 3113 | "Invalid VkImage Object "); |
| 3114 | |
| 3115 | TEST_DESCRIPTION( |
| 3116 | "Pass an invalid image object handle into a Vulkan API call."); |
| 3117 | |
| 3118 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 3119 | |
| 3120 | // Pass bogus handle into GetImageMemoryRequirements |
| 3121 | VkMemoryRequirements mem_reqs; |
| 3122 | uint64_t fakeImageHandle = 0xCADECADE; |
| 3123 | VkImage fauxImage = reinterpret_cast<VkImage &>(fakeImageHandle); |
| 3124 | |
| 3125 | vkGetImageMemoryRequirements(m_device->device(), fauxImage, &mem_reqs); |
| 3126 | |
| 3127 | m_errorMonitor->VerifyFound(); |
| 3128 | } |
| 3129 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 3130 | TEST_F(VkLayerTest, PipelineNotBound) { |
| 3131 | VkResult err; |
Tobin Ehlis | c9ac2b6 | 2015-09-11 12:57:55 -0600 | [diff] [blame] | 3132 | |
Mark Lobodzinski | fc5cc66 | 2016-05-02 17:17:41 -0600 | [diff] [blame] | 3133 | TEST_DESCRIPTION( |
| 3134 | "Pass in an invalid pipeline object handle into a Vulkan API call."); |
| 3135 | |
Courtney Goeltzenleuchter | 7415d5a | 2015-12-09 15:48:16 -0700 | [diff] [blame] | 3136 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 3137 | "Invalid VkPipeline Object "); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 3138 | |
Tobin Ehlis | c9ac2b6 | 2015-09-11 12:57:55 -0600 | [diff] [blame] | 3139 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 3140 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
Tobin Ehlis | c9ac2b6 | 2015-09-11 12:57:55 -0600 | [diff] [blame] | 3141 | |
Chia-I Wu | 1b99bb2 | 2015-10-27 19:25:11 +0800 | [diff] [blame] | 3142 | VkDescriptorPoolSize ds_type_count = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 3143 | ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 3144 | ds_type_count.descriptorCount = 1; |
Tobin Ehlis | c9ac2b6 | 2015-09-11 12:57:55 -0600 | [diff] [blame] | 3145 | |
| 3146 | VkDescriptorPoolCreateInfo ds_pool_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 3147 | ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO; |
| 3148 | ds_pool_ci.pNext = NULL; |
| 3149 | ds_pool_ci.maxSets = 1; |
| 3150 | ds_pool_ci.poolSizeCount = 1; |
| 3151 | ds_pool_ci.pPoolSizes = &ds_type_count; |
Tobin Ehlis | c9ac2b6 | 2015-09-11 12:57:55 -0600 | [diff] [blame] | 3152 | |
| 3153 | VkDescriptorPool ds_pool; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 3154 | err = |
| 3155 | vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool); |
Tobin Ehlis | c9ac2b6 | 2015-09-11 12:57:55 -0600 | [diff] [blame] | 3156 | ASSERT_VK_SUCCESS(err); |
| 3157 | |
| 3158 | VkDescriptorSetLayoutBinding dsl_binding = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 3159 | dsl_binding.binding = 0; |
| 3160 | dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 3161 | dsl_binding.descriptorCount = 1; |
| 3162 | dsl_binding.stageFlags = VK_SHADER_STAGE_ALL; |
| 3163 | dsl_binding.pImmutableSamplers = NULL; |
Tobin Ehlis | c9ac2b6 | 2015-09-11 12:57:55 -0600 | [diff] [blame] | 3164 | |
| 3165 | VkDescriptorSetLayoutCreateInfo ds_layout_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 3166 | ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO; |
| 3167 | ds_layout_ci.pNext = NULL; |
| 3168 | ds_layout_ci.bindingCount = 1; |
| 3169 | ds_layout_ci.pBindings = &dsl_binding; |
Tobin Ehlis | c9ac2b6 | 2015-09-11 12:57:55 -0600 | [diff] [blame] | 3170 | |
| 3171 | VkDescriptorSetLayout ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 3172 | err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, |
| 3173 | &ds_layout); |
Tobin Ehlis | c9ac2b6 | 2015-09-11 12:57:55 -0600 | [diff] [blame] | 3174 | ASSERT_VK_SUCCESS(err); |
| 3175 | |
| 3176 | VkDescriptorSet descriptorSet; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 3177 | VkDescriptorSetAllocateInfo alloc_info = {}; |
Chia-I Wu | 00ce540 | 2015-11-10 16:21:09 +0800 | [diff] [blame] | 3178 | alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO; |
Jon Ashburn | f19916e | 2016-01-11 13:12:43 -0700 | [diff] [blame] | 3179 | alloc_info.descriptorSetCount = 1; |
Courtney Goeltzenleuchter | bee18a9 | 2015-10-23 14:21:05 -0600 | [diff] [blame] | 3180 | alloc_info.descriptorPool = ds_pool; |
| 3181 | alloc_info.pSetLayouts = &ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 3182 | err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, |
| 3183 | &descriptorSet); |
Tobin Ehlis | c9ac2b6 | 2015-09-11 12:57:55 -0600 | [diff] [blame] | 3184 | ASSERT_VK_SUCCESS(err); |
| 3185 | |
| 3186 | VkPipelineLayoutCreateInfo pipeline_layout_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 3187 | pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO; |
| 3188 | pipeline_layout_ci.pNext = NULL; |
| 3189 | pipeline_layout_ci.setLayoutCount = 1; |
| 3190 | pipeline_layout_ci.pSetLayouts = &ds_layout; |
Tobin Ehlis | c9ac2b6 | 2015-09-11 12:57:55 -0600 | [diff] [blame] | 3191 | |
| 3192 | VkPipelineLayout pipeline_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 3193 | err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, |
| 3194 | &pipeline_layout); |
Tobin Ehlis | c9ac2b6 | 2015-09-11 12:57:55 -0600 | [diff] [blame] | 3195 | ASSERT_VK_SUCCESS(err); |
| 3196 | |
Mark Young | ad77905 | 2016-01-06 14:26:04 -0700 | [diff] [blame] | 3197 | VkPipeline badPipeline = (VkPipeline)((size_t)0xbaadb1be); |
Tobin Ehlis | c9ac2b6 | 2015-09-11 12:57:55 -0600 | [diff] [blame] | 3198 | |
| 3199 | BeginCommandBuffer(); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 3200 | vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), |
| 3201 | VK_PIPELINE_BIND_POINT_GRAPHICS, badPipeline); |
Tobin Ehlis | c9ac2b6 | 2015-09-11 12:57:55 -0600 | [diff] [blame] | 3202 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 3203 | m_errorMonitor->VerifyFound(); |
Mike Stroyan | d1c84a5 | 2015-08-18 14:40:24 -0600 | [diff] [blame] | 3204 | |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 3205 | vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL); |
| 3206 | vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL); |
| 3207 | vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL); |
Tobin Ehlis | ec59830 | 2015-09-15 15:02:17 -0600 | [diff] [blame] | 3208 | } |
Mike Stroyan | 80fc6c3 | 2016-06-20 15:42:29 -0600 | [diff] [blame] | 3209 | |
Mark Lobodzinski | bc18576 | 2016-06-15 16:28:53 -0600 | [diff] [blame] | 3210 | TEST_F(VkLayerTest, BindImageInvalidMemoryType) { |
| 3211 | VkResult err; |
| 3212 | |
| 3213 | TEST_DESCRIPTION("Test validation check for an invalid memory type index " |
| 3214 | "during bind[Buffer|Image]Memory time"); |
| 3215 | |
Mark Lobodzinski | bc18576 | 2016-06-15 16:28:53 -0600 | [diff] [blame] | 3216 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 3217 | |
| 3218 | // Create an image, allocate memory, set a bad typeIndex and then try to |
| 3219 | // bind it |
| 3220 | VkImage image; |
| 3221 | VkDeviceMemory mem; |
| 3222 | VkMemoryRequirements mem_reqs; |
| 3223 | const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM; |
| 3224 | const int32_t tex_width = 32; |
| 3225 | const int32_t tex_height = 32; |
| 3226 | |
| 3227 | VkImageCreateInfo image_create_info = {}; |
| 3228 | image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO; |
| 3229 | image_create_info.pNext = NULL; |
| 3230 | image_create_info.imageType = VK_IMAGE_TYPE_2D; |
| 3231 | image_create_info.format = tex_format; |
| 3232 | image_create_info.extent.width = tex_width; |
| 3233 | image_create_info.extent.height = tex_height; |
| 3234 | image_create_info.extent.depth = 1; |
| 3235 | image_create_info.mipLevels = 1; |
| 3236 | image_create_info.arrayLayers = 1; |
| 3237 | image_create_info.samples = VK_SAMPLE_COUNT_1_BIT; |
| 3238 | image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL; |
| 3239 | image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT; |
| 3240 | image_create_info.flags = 0; |
| 3241 | |
| 3242 | VkMemoryAllocateInfo mem_alloc = {}; |
| 3243 | mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO; |
| 3244 | mem_alloc.pNext = NULL; |
| 3245 | mem_alloc.allocationSize = 0; |
| 3246 | mem_alloc.memoryTypeIndex = 0; |
| 3247 | |
| 3248 | err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image); |
| 3249 | ASSERT_VK_SUCCESS(err); |
| 3250 | |
| 3251 | vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs); |
| 3252 | mem_alloc.allocationSize = mem_reqs.size; |
Mike Stroyan | 80fc6c3 | 2016-06-20 15:42:29 -0600 | [diff] [blame] | 3253 | |
| 3254 | // Introduce Failure, select invalid TypeIndex |
| 3255 | VkPhysicalDeviceMemoryProperties memory_info; |
| 3256 | |
| 3257 | vkGetPhysicalDeviceMemoryProperties(gpu(), &memory_info); |
| 3258 | unsigned int i; |
| 3259 | for (i = 0; i < memory_info.memoryTypeCount; i++) { |
| 3260 | if ((mem_reqs.memoryTypeBits & (1 << i)) == 0) { |
| 3261 | mem_alloc.memoryTypeIndex = i; |
| 3262 | break; |
| 3263 | } |
| 3264 | } |
| 3265 | if (i >= memory_info.memoryTypeCount) { |
| 3266 | printf("No invalid memory type index could be found; skipped.\n"); |
| 3267 | vkDestroyImage(m_device->device(), image, NULL); |
| 3268 | return; |
| 3269 | } |
| 3270 | |
| 3271 | m_errorMonitor->SetDesiredFailureMsg( |
| 3272 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 3273 | "for this object type are not compatible with the memory"); |
Mark Lobodzinski | bc18576 | 2016-06-15 16:28:53 -0600 | [diff] [blame] | 3274 | |
| 3275 | err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem); |
| 3276 | ASSERT_VK_SUCCESS(err); |
| 3277 | |
| 3278 | err = vkBindImageMemory(m_device->device(), image, mem, 0); |
| 3279 | (void)err; |
| 3280 | |
| 3281 | m_errorMonitor->VerifyFound(); |
| 3282 | |
| 3283 | vkDestroyImage(m_device->device(), image, NULL); |
| 3284 | vkFreeMemory(m_device->device(), mem, NULL); |
| 3285 | } |
Mike Stroyan | 80fc6c3 | 2016-06-20 15:42:29 -0600 | [diff] [blame] | 3286 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 3287 | TEST_F(VkLayerTest, BindInvalidMemory) { |
| 3288 | VkResult err; |
| 3289 | bool pass; |
Tobin Ehlis | ec59830 | 2015-09-15 15:02:17 -0600 | [diff] [blame] | 3290 | |
Courtney Goeltzenleuchter | 7415d5a | 2015-12-09 15:48:16 -0700 | [diff] [blame] | 3291 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 3292 | "Invalid VkDeviceMemory Object "); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 3293 | |
Tobin Ehlis | ec59830 | 2015-09-15 15:02:17 -0600 | [diff] [blame] | 3294 | ASSERT_NO_FATAL_FAILURE(InitState()); |
Tobin Ehlis | ec59830 | 2015-09-15 15:02:17 -0600 | [diff] [blame] | 3295 | |
| 3296 | // 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] | 3297 | VkImage image; |
| 3298 | VkDeviceMemory mem; |
| 3299 | VkMemoryRequirements mem_reqs; |
Tobin Ehlis | ec59830 | 2015-09-15 15:02:17 -0600 | [diff] [blame] | 3300 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 3301 | const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM; |
| 3302 | const int32_t tex_width = 32; |
| 3303 | const int32_t tex_height = 32; |
Tobin Ehlis | ec59830 | 2015-09-15 15:02:17 -0600 | [diff] [blame] | 3304 | |
| 3305 | VkImageCreateInfo image_create_info = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 3306 | image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO; |
| 3307 | image_create_info.pNext = NULL; |
| 3308 | image_create_info.imageType = VK_IMAGE_TYPE_2D; |
| 3309 | image_create_info.format = tex_format; |
| 3310 | image_create_info.extent.width = tex_width; |
| 3311 | image_create_info.extent.height = tex_height; |
| 3312 | image_create_info.extent.depth = 1; |
| 3313 | image_create_info.mipLevels = 1; |
| 3314 | image_create_info.arrayLayers = 1; |
| 3315 | image_create_info.samples = VK_SAMPLE_COUNT_1_BIT; |
| 3316 | image_create_info.tiling = VK_IMAGE_TILING_LINEAR; |
| 3317 | image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT; |
| 3318 | image_create_info.flags = 0; |
Tobin Ehlis | ec59830 | 2015-09-15 15:02:17 -0600 | [diff] [blame] | 3319 | |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 3320 | VkMemoryAllocateInfo mem_alloc = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 3321 | mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO; |
| 3322 | mem_alloc.pNext = NULL; |
| 3323 | mem_alloc.allocationSize = 0; |
| 3324 | mem_alloc.memoryTypeIndex = 0; |
Tobin Ehlis | ec59830 | 2015-09-15 15:02:17 -0600 | [diff] [blame] | 3325 | |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 3326 | err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image); |
Tobin Ehlis | ec59830 | 2015-09-15 15:02:17 -0600 | [diff] [blame] | 3327 | ASSERT_VK_SUCCESS(err); |
| 3328 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 3329 | vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs); |
Tobin Ehlis | ec59830 | 2015-09-15 15:02:17 -0600 | [diff] [blame] | 3330 | |
| 3331 | mem_alloc.allocationSize = mem_reqs.size; |
| 3332 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 3333 | pass = |
| 3334 | m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0); |
Courtney Goeltzenleuchter | 1d2f0dd | 2015-10-22 11:03:31 -0600 | [diff] [blame] | 3335 | ASSERT_TRUE(pass); |
Tobin Ehlis | ec59830 | 2015-09-15 15:02:17 -0600 | [diff] [blame] | 3336 | |
| 3337 | // allocate memory |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 3338 | err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem); |
Tobin Ehlis | ec59830 | 2015-09-15 15:02:17 -0600 | [diff] [blame] | 3339 | ASSERT_VK_SUCCESS(err); |
| 3340 | |
| 3341 | // Introduce validation failure, free memory before binding |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 3342 | vkFreeMemory(m_device->device(), mem, NULL); |
Tobin Ehlis | ec59830 | 2015-09-15 15:02:17 -0600 | [diff] [blame] | 3343 | |
| 3344 | // Try to bind free memory that has been freed |
| 3345 | err = vkBindImageMemory(m_device->device(), image, mem, 0); |
| 3346 | // This may very well return an error. |
| 3347 | (void)err; |
| 3348 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 3349 | m_errorMonitor->VerifyFound(); |
Mike Stroyan | d1c84a5 | 2015-08-18 14:40:24 -0600 | [diff] [blame] | 3350 | |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 3351 | vkDestroyImage(m_device->device(), image, NULL); |
Tobin Ehlis | ec59830 | 2015-09-15 15:02:17 -0600 | [diff] [blame] | 3352 | } |
| 3353 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 3354 | TEST_F(VkLayerTest, BindMemoryToDestroyedObject) { |
| 3355 | VkResult err; |
| 3356 | bool pass; |
Tobin Ehlis | ec59830 | 2015-09-15 15:02:17 -0600 | [diff] [blame] | 3357 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 3358 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 3359 | "Invalid VkImage Object "); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 3360 | |
Tobin Ehlis | ec59830 | 2015-09-15 15:02:17 -0600 | [diff] [blame] | 3361 | ASSERT_NO_FATAL_FAILURE(InitState()); |
Tobin Ehlis | ec59830 | 2015-09-15 15:02:17 -0600 | [diff] [blame] | 3362 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 3363 | // Create an image object, allocate memory, destroy the object and then try |
| 3364 | // to bind it |
| 3365 | VkImage image; |
| 3366 | VkDeviceMemory mem; |
| 3367 | VkMemoryRequirements mem_reqs; |
Tobin Ehlis | ec59830 | 2015-09-15 15:02:17 -0600 | [diff] [blame] | 3368 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 3369 | const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM; |
| 3370 | const int32_t tex_width = 32; |
| 3371 | const int32_t tex_height = 32; |
Tobin Ehlis | ec59830 | 2015-09-15 15:02:17 -0600 | [diff] [blame] | 3372 | |
| 3373 | VkImageCreateInfo image_create_info = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 3374 | image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO; |
| 3375 | image_create_info.pNext = NULL; |
| 3376 | image_create_info.imageType = VK_IMAGE_TYPE_2D; |
| 3377 | image_create_info.format = tex_format; |
| 3378 | image_create_info.extent.width = tex_width; |
| 3379 | image_create_info.extent.height = tex_height; |
| 3380 | image_create_info.extent.depth = 1; |
| 3381 | image_create_info.mipLevels = 1; |
| 3382 | image_create_info.arrayLayers = 1; |
| 3383 | image_create_info.samples = VK_SAMPLE_COUNT_1_BIT; |
| 3384 | image_create_info.tiling = VK_IMAGE_TILING_LINEAR; |
| 3385 | image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT; |
| 3386 | image_create_info.flags = 0; |
Tobin Ehlis | ec59830 | 2015-09-15 15:02:17 -0600 | [diff] [blame] | 3387 | |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 3388 | VkMemoryAllocateInfo mem_alloc = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 3389 | mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO; |
| 3390 | mem_alloc.pNext = NULL; |
| 3391 | mem_alloc.allocationSize = 0; |
| 3392 | mem_alloc.memoryTypeIndex = 0; |
Tobin Ehlis | ec59830 | 2015-09-15 15:02:17 -0600 | [diff] [blame] | 3393 | |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 3394 | err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image); |
Tobin Ehlis | ec59830 | 2015-09-15 15:02:17 -0600 | [diff] [blame] | 3395 | ASSERT_VK_SUCCESS(err); |
| 3396 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 3397 | vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs); |
Tobin Ehlis | ec59830 | 2015-09-15 15:02:17 -0600 | [diff] [blame] | 3398 | |
| 3399 | mem_alloc.allocationSize = mem_reqs.size; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 3400 | pass = |
| 3401 | m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0); |
Courtney Goeltzenleuchter | 1d2f0dd | 2015-10-22 11:03:31 -0600 | [diff] [blame] | 3402 | ASSERT_TRUE(pass); |
Tobin Ehlis | ec59830 | 2015-09-15 15:02:17 -0600 | [diff] [blame] | 3403 | |
| 3404 | // Allocate memory |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 3405 | err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem); |
Tobin Ehlis | ec59830 | 2015-09-15 15:02:17 -0600 | [diff] [blame] | 3406 | ASSERT_VK_SUCCESS(err); |
| 3407 | |
| 3408 | // Introduce validation failure, destroy Image object before binding |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 3409 | vkDestroyImage(m_device->device(), image, NULL); |
Tobin Ehlis | ec59830 | 2015-09-15 15:02:17 -0600 | [diff] [blame] | 3410 | ASSERT_VK_SUCCESS(err); |
| 3411 | |
| 3412 | // Now Try to bind memory to this destroyed object |
| 3413 | err = vkBindImageMemory(m_device->device(), image, mem, 0); |
| 3414 | // This may very well return an error. |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 3415 | (void)err; |
Tobin Ehlis | ec59830 | 2015-09-15 15:02:17 -0600 | [diff] [blame] | 3416 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 3417 | m_errorMonitor->VerifyFound(); |
Mike Stroyan | d1c84a5 | 2015-08-18 14:40:24 -0600 | [diff] [blame] | 3418 | |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 3419 | vkFreeMemory(m_device->device(), mem, NULL); |
Tobin Ehlis | c9ac2b6 | 2015-09-11 12:57:55 -0600 | [diff] [blame] | 3420 | } |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 3421 | |
Mark Lobodzinski | 209b529 | 2015-09-17 09:44:05 -0600 | [diff] [blame] | 3422 | #endif // OBJ_TRACKER_TESTS |
| 3423 | |
Tobin Ehlis | 0788f52 | 2015-05-26 16:11:58 -0600 | [diff] [blame] | 3424 | #if DRAW_STATE_TESTS |
Mark Lobodzinski | c808d44 | 2016-04-14 10:57:23 -0600 | [diff] [blame] | 3425 | |
Chris Forbes | 48a5390 | 2016-06-30 11:46:27 +1200 | [diff] [blame] | 3426 | TEST_F(VkLayerTest, RenderPassInitialLayoutUndefined) { |
| 3427 | TEST_DESCRIPTION("Ensure that CmdBeginRenderPass with an attachment's " |
| 3428 | "initialLayout of VK_IMAGE_LAYOUT_UNDEFINED works when " |
| 3429 | "the command buffer has prior knowledge of that " |
| 3430 | "attachment's layout."); |
| 3431 | |
| 3432 | m_errorMonitor->ExpectSuccess(); |
| 3433 | |
| 3434 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 3435 | |
| 3436 | // A renderpass with one color attachment. |
| 3437 | VkAttachmentDescription attachment = { |
| 3438 | 0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_1_BIT, |
| 3439 | VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_STORE, |
| 3440 | VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, |
| 3441 | VK_IMAGE_LAYOUT_UNDEFINED, |
| 3442 | VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL |
| 3443 | }; |
| 3444 | |
| 3445 | VkAttachmentReference att_ref = { |
| 3446 | 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL |
| 3447 | }; |
| 3448 | |
| 3449 | VkSubpassDescription subpass = { |
| 3450 | 0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, |
| 3451 | 1, &att_ref, nullptr, nullptr, 0, nullptr |
| 3452 | }; |
| 3453 | |
| 3454 | VkRenderPassCreateInfo rpci = { |
| 3455 | VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, |
| 3456 | 0, 1, &attachment, 1, &subpass, 0, nullptr |
| 3457 | }; |
| 3458 | |
| 3459 | VkRenderPass rp; |
| 3460 | VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp); |
| 3461 | ASSERT_VK_SUCCESS(err); |
| 3462 | |
| 3463 | // A compatible framebuffer. |
| 3464 | VkImageObj image(m_device); |
| 3465 | image.init(32, 32, VK_FORMAT_R8G8B8A8_UNORM, |
| 3466 | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, |
| 3467 | VK_IMAGE_TILING_OPTIMAL, 0); |
| 3468 | ASSERT_TRUE(image.initialized()); |
| 3469 | |
| 3470 | VkImageViewCreateInfo ivci = { |
| 3471 | VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO, nullptr, |
| 3472 | 0, image.handle(), VK_IMAGE_VIEW_TYPE_2D, VK_FORMAT_R8G8B8A8_UNORM, |
| 3473 | { |
| 3474 | VK_COMPONENT_SWIZZLE_IDENTITY, |
| 3475 | VK_COMPONENT_SWIZZLE_IDENTITY, |
| 3476 | VK_COMPONENT_SWIZZLE_IDENTITY, |
| 3477 | VK_COMPONENT_SWIZZLE_IDENTITY |
| 3478 | }, |
| 3479 | { |
| 3480 | VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1 |
| 3481 | }, |
| 3482 | }; |
| 3483 | VkImageView view; |
| 3484 | err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view); |
| 3485 | ASSERT_VK_SUCCESS(err); |
| 3486 | |
| 3487 | VkFramebufferCreateInfo fci = { |
| 3488 | VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, |
| 3489 | 0, rp, 1, &view, |
| 3490 | 32, 32, 1 |
| 3491 | }; |
| 3492 | VkFramebuffer fb; |
| 3493 | err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb); |
| 3494 | ASSERT_VK_SUCCESS(err); |
| 3495 | |
| 3496 | // Record a single command buffer which uses this renderpass twice. The |
| 3497 | // bug is triggered at the beginning of the second renderpass, when the |
| 3498 | // command buffer already has a layout recorded for the attachment. |
| 3499 | VkRenderPassBeginInfo rpbi = { |
| 3500 | VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO, nullptr, |
Tobin Ehlis | 0f9aa40 | 2016-07-01 08:47:12 -0600 | [diff] [blame] | 3501 | rp, fb, { { 0, 0 } , { 32, 32 } }, |
Chris Forbes | 48a5390 | 2016-06-30 11:46:27 +1200 | [diff] [blame] | 3502 | 0, nullptr |
| 3503 | }; |
| 3504 | BeginCommandBuffer(); |
| 3505 | vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, |
| 3506 | VK_SUBPASS_CONTENTS_INLINE); |
| 3507 | vkCmdEndRenderPass(m_commandBuffer->handle()); |
| 3508 | vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, |
| 3509 | VK_SUBPASS_CONTENTS_INLINE); |
| 3510 | |
| 3511 | m_errorMonitor->VerifyNotFound(); |
| 3512 | |
| 3513 | vkCmdEndRenderPass(m_commandBuffer->handle()); |
| 3514 | EndCommandBuffer(); |
| 3515 | |
| 3516 | vkDestroyFramebuffer(m_device->device(), fb, nullptr); |
| 3517 | vkDestroyRenderPass(m_device->device(), rp, nullptr); |
| 3518 | vkDestroyImageView(m_device->device(), view, nullptr); |
| 3519 | } |
| 3520 | |
Chris Forbes | 51bf7c9 | 2016-06-30 15:22:08 +1200 | [diff] [blame] | 3521 | TEST_F(VkLayerTest, RenderPassSubpassZeroTransitionsApplied) { |
| 3522 | TEST_DESCRIPTION("Ensure that CmdBeginRenderPass applies the layout " |
| 3523 | "transitions for the first subpass"); |
| 3524 | |
| 3525 | m_errorMonitor->ExpectSuccess(); |
| 3526 | |
| 3527 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 3528 | |
| 3529 | // A renderpass with one color attachment. |
| 3530 | VkAttachmentDescription attachment = { |
| 3531 | 0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_1_BIT, |
| 3532 | VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_STORE, |
| 3533 | VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, |
| 3534 | VK_IMAGE_LAYOUT_UNDEFINED, |
| 3535 | VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL |
| 3536 | }; |
| 3537 | |
| 3538 | VkAttachmentReference att_ref = { |
| 3539 | 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL |
| 3540 | }; |
| 3541 | |
| 3542 | VkSubpassDescription subpass = { |
| 3543 | 0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, |
| 3544 | 1, &att_ref, nullptr, nullptr, 0, nullptr |
| 3545 | }; |
| 3546 | |
| 3547 | VkSubpassDependency dep = { |
Chris Forbes | cb4c7ad | 2016-07-06 10:28:18 +1200 | [diff] [blame] | 3548 | 0, 0, VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT, |
| 3549 | VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT, |
Chris Forbes | 51bf7c9 | 2016-06-30 15:22:08 +1200 | [diff] [blame] | 3550 | VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT, |
| 3551 | VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT, |
| 3552 | VK_DEPENDENCY_BY_REGION_BIT |
| 3553 | }; |
| 3554 | |
| 3555 | VkRenderPassCreateInfo rpci = { |
| 3556 | VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, |
| 3557 | 0, 1, &attachment, 1, &subpass, 1, &dep |
| 3558 | }; |
| 3559 | |
| 3560 | VkResult err; |
| 3561 | VkRenderPass rp; |
| 3562 | err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp); |
| 3563 | ASSERT_VK_SUCCESS(err); |
| 3564 | |
| 3565 | // A compatible framebuffer. |
| 3566 | VkImageObj image(m_device); |
| 3567 | image.init(32, 32, VK_FORMAT_R8G8B8A8_UNORM, |
| 3568 | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, |
| 3569 | VK_IMAGE_TILING_OPTIMAL, 0); |
| 3570 | ASSERT_TRUE(image.initialized()); |
| 3571 | |
| 3572 | VkImageViewCreateInfo ivci = { |
| 3573 | VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO, nullptr, |
| 3574 | 0, image.handle(), VK_IMAGE_VIEW_TYPE_2D, VK_FORMAT_R8G8B8A8_UNORM, |
| 3575 | { |
| 3576 | VK_COMPONENT_SWIZZLE_IDENTITY, |
| 3577 | VK_COMPONENT_SWIZZLE_IDENTITY, |
| 3578 | VK_COMPONENT_SWIZZLE_IDENTITY, |
| 3579 | VK_COMPONENT_SWIZZLE_IDENTITY |
| 3580 | }, |
| 3581 | { |
| 3582 | VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1 |
| 3583 | }, |
| 3584 | }; |
| 3585 | VkImageView view; |
| 3586 | err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view); |
| 3587 | ASSERT_VK_SUCCESS(err); |
| 3588 | |
| 3589 | VkFramebufferCreateInfo fci = { |
| 3590 | VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, |
| 3591 | 0, rp, 1, &view, |
| 3592 | 32, 32, 1 |
| 3593 | }; |
| 3594 | VkFramebuffer fb; |
| 3595 | err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb); |
| 3596 | ASSERT_VK_SUCCESS(err); |
| 3597 | |
| 3598 | // Record a single command buffer which issues a pipeline barrier w/ |
| 3599 | // image memory barrier for the attachment. This detects the previously |
| 3600 | // missing tracking of the subpass layout by throwing a validation error |
| 3601 | // if it doesn't occur. |
| 3602 | VkRenderPassBeginInfo rpbi = { |
| 3603 | VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO, nullptr, |
Tobin Ehlis | 0f9aa40 | 2016-07-01 08:47:12 -0600 | [diff] [blame] | 3604 | rp, fb, { { 0, 0 }, { 32, 32 } }, |
Chris Forbes | 51bf7c9 | 2016-06-30 15:22:08 +1200 | [diff] [blame] | 3605 | 0, nullptr |
| 3606 | }; |
| 3607 | BeginCommandBuffer(); |
| 3608 | vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, |
| 3609 | VK_SUBPASS_CONTENTS_INLINE); |
| 3610 | |
| 3611 | VkImageMemoryBarrier imb = { |
| 3612 | VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER, nullptr, |
| 3613 | VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT, |
| 3614 | VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT, |
| 3615 | VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, |
| 3616 | VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, |
| 3617 | VK_QUEUE_FAMILY_IGNORED, VK_QUEUE_FAMILY_IGNORED, |
| 3618 | image.handle(), |
| 3619 | { VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1 } |
| 3620 | }; |
| 3621 | vkCmdPipelineBarrier(m_commandBuffer->handle(), |
Chris Forbes | cb4c7ad | 2016-07-06 10:28:18 +1200 | [diff] [blame] | 3622 | VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT, |
| 3623 | VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT, |
Chris Forbes | 51bf7c9 | 2016-06-30 15:22:08 +1200 | [diff] [blame] | 3624 | VK_DEPENDENCY_BY_REGION_BIT, |
| 3625 | 0, nullptr, 0, nullptr, 1, &imb); |
| 3626 | |
| 3627 | vkCmdEndRenderPass(m_commandBuffer->handle()); |
| 3628 | m_errorMonitor->VerifyNotFound(); |
| 3629 | EndCommandBuffer(); |
| 3630 | |
| 3631 | vkDestroyFramebuffer(m_device->device(), fb, nullptr); |
| 3632 | vkDestroyRenderPass(m_device->device(), rp, nullptr); |
| 3633 | vkDestroyImageView(m_device->device(), view, nullptr); |
| 3634 | } |
| 3635 | |
Chris Forbes | 6b3d3f4 | 2016-06-30 16:09:47 +1200 | [diff] [blame] | 3636 | TEST_F(VkLayerTest, RenderPassTransitionsAttachmentUnused) { |
| 3637 | TEST_DESCRIPTION("Ensure that layout transitions work correctly without " |
| 3638 | "errors, when an attachment reference is " |
| 3639 | "VK_ATTACHMENT_UNUSED"); |
| 3640 | |
| 3641 | m_errorMonitor->ExpectSuccess(); |
| 3642 | |
| 3643 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 3644 | |
| 3645 | // A renderpass with no attachments |
| 3646 | VkAttachmentReference att_ref = { |
| 3647 | VK_ATTACHMENT_UNUSED, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL |
| 3648 | }; |
| 3649 | |
| 3650 | VkSubpassDescription subpass = { |
| 3651 | 0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, |
| 3652 | 1, &att_ref, nullptr, nullptr, 0, nullptr |
| 3653 | }; |
| 3654 | |
| 3655 | VkRenderPassCreateInfo rpci = { |
| 3656 | VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, |
| 3657 | 0, 0, nullptr, 1, &subpass, 0, nullptr |
| 3658 | }; |
| 3659 | |
| 3660 | VkRenderPass rp; |
| 3661 | VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp); |
| 3662 | ASSERT_VK_SUCCESS(err); |
| 3663 | |
| 3664 | // A compatible framebuffer. |
| 3665 | VkFramebufferCreateInfo fci = { |
| 3666 | VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, |
| 3667 | 0, rp, 0, nullptr, |
| 3668 | 32, 32, 1 |
| 3669 | }; |
| 3670 | VkFramebuffer fb; |
| 3671 | err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb); |
| 3672 | ASSERT_VK_SUCCESS(err); |
| 3673 | |
| 3674 | // Record a command buffer which just begins and ends the renderpass. The |
| 3675 | // bug manifests in BeginRenderPass. |
| 3676 | VkRenderPassBeginInfo rpbi = { |
| 3677 | VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO, nullptr, |
Tobin Ehlis | 0f9aa40 | 2016-07-01 08:47:12 -0600 | [diff] [blame] | 3678 | rp, fb, { { 0, 0 }, { 32, 32 } }, |
Chris Forbes | 6b3d3f4 | 2016-06-30 16:09:47 +1200 | [diff] [blame] | 3679 | 0, nullptr |
| 3680 | }; |
| 3681 | BeginCommandBuffer(); |
| 3682 | vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, |
| 3683 | VK_SUBPASS_CONTENTS_INLINE); |
| 3684 | vkCmdEndRenderPass(m_commandBuffer->handle()); |
| 3685 | m_errorMonitor->VerifyNotFound(); |
| 3686 | EndCommandBuffer(); |
| 3687 | |
| 3688 | vkDestroyFramebuffer(m_device->device(), fb, nullptr); |
| 3689 | vkDestroyRenderPass(m_device->device(), rp, nullptr); |
| 3690 | } |
| 3691 | |
Mark Lobodzinski | ce7eee7 | 2016-06-14 16:33:29 -0600 | [diff] [blame] | 3692 | // This is a positive test. No errors are expected. |
| 3693 | TEST_F(VkLayerTest, StencilLoadOp) { |
| 3694 | TEST_DESCRIPTION("Create a stencil-only attachment with a LOAD_OP set to " |
| 3695 | "CLEAR. stencil[Load|Store]Op used to be ignored."); |
| 3696 | VkResult result = VK_SUCCESS; |
| 3697 | VkImageFormatProperties formatProps; |
| 3698 | vkGetPhysicalDeviceImageFormatProperties( |
| 3699 | gpu(), VK_FORMAT_D24_UNORM_S8_UINT, VK_IMAGE_TYPE_2D, |
| 3700 | VK_IMAGE_TILING_OPTIMAL, VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT | |
| 3701 | VK_IMAGE_USAGE_TRANSFER_SRC_BIT, |
| 3702 | 0, &formatProps); |
| 3703 | if (formatProps.maxExtent.width < 100 || formatProps.maxExtent.height < 100) { |
| 3704 | return; |
| 3705 | } |
| 3706 | |
| 3707 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 3708 | VkFormat depth_stencil_fmt = VK_FORMAT_D24_UNORM_S8_UINT; |
| 3709 | m_depthStencil->Init(m_device, 100, 100, depth_stencil_fmt, |
| 3710 | VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT | |
| 3711 | VK_IMAGE_USAGE_TRANSFER_SRC_BIT); |
| 3712 | VkAttachmentDescription att = {}; |
| 3713 | VkAttachmentReference ref = {}; |
| 3714 | att.format = depth_stencil_fmt; |
| 3715 | att.loadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE; |
| 3716 | att.storeOp = VK_ATTACHMENT_STORE_OP_DONT_CARE; |
| 3717 | att.stencilLoadOp = VK_ATTACHMENT_LOAD_OP_CLEAR; |
| 3718 | att.stencilStoreOp = VK_ATTACHMENT_STORE_OP_STORE; |
| 3719 | att.initialLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL; |
| 3720 | att.finalLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL; |
| 3721 | |
| 3722 | VkClearValue clear; |
| 3723 | clear.depthStencil.depth = 1.0; |
| 3724 | clear.depthStencil.stencil = 0; |
| 3725 | ref.attachment = 0; |
| 3726 | ref.layout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL; |
| 3727 | |
| 3728 | VkSubpassDescription subpass = {}; |
| 3729 | subpass.pipelineBindPoint = VK_PIPELINE_BIND_POINT_GRAPHICS; |
| 3730 | subpass.flags = 0; |
| 3731 | subpass.inputAttachmentCount = 0; |
| 3732 | subpass.pInputAttachments = NULL; |
| 3733 | subpass.colorAttachmentCount = 0; |
| 3734 | subpass.pColorAttachments = NULL; |
| 3735 | subpass.pResolveAttachments = NULL; |
| 3736 | subpass.pDepthStencilAttachment = &ref; |
| 3737 | subpass.preserveAttachmentCount = 0; |
| 3738 | subpass.pPreserveAttachments = NULL; |
| 3739 | |
| 3740 | VkRenderPass rp; |
| 3741 | VkRenderPassCreateInfo rp_info = {}; |
| 3742 | rp_info.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO; |
| 3743 | rp_info.attachmentCount = 1; |
| 3744 | rp_info.pAttachments = &att; |
| 3745 | rp_info.subpassCount = 1; |
| 3746 | rp_info.pSubpasses = &subpass; |
| 3747 | result = vkCreateRenderPass(device(), &rp_info, NULL, &rp); |
| 3748 | ASSERT_VK_SUCCESS(result); |
| 3749 | |
| 3750 | VkImageView *depthView = m_depthStencil->BindInfo(); |
| 3751 | VkFramebufferCreateInfo fb_info = {}; |
| 3752 | fb_info.sType = VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO; |
| 3753 | fb_info.pNext = NULL; |
| 3754 | fb_info.renderPass = rp; |
| 3755 | fb_info.attachmentCount = 1; |
| 3756 | fb_info.pAttachments = depthView; |
| 3757 | fb_info.width = 100; |
| 3758 | fb_info.height = 100; |
| 3759 | fb_info.layers = 1; |
| 3760 | VkFramebuffer fb; |
| 3761 | result = vkCreateFramebuffer(device(), &fb_info, NULL, &fb); |
| 3762 | ASSERT_VK_SUCCESS(result); |
| 3763 | |
| 3764 | |
| 3765 | VkRenderPassBeginInfo rpbinfo = {}; |
| 3766 | rpbinfo.clearValueCount = 1; |
| 3767 | rpbinfo.pClearValues = &clear; |
| 3768 | rpbinfo.pNext = NULL; |
| 3769 | rpbinfo.renderPass = rp; |
| 3770 | rpbinfo.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO; |
| 3771 | rpbinfo.renderArea.extent.width = 100; |
| 3772 | rpbinfo.renderArea.extent.height = 100; |
| 3773 | rpbinfo.renderArea.offset.x = 0; |
| 3774 | rpbinfo.renderArea.offset.y = 0; |
| 3775 | rpbinfo.framebuffer = fb; |
| 3776 | |
| 3777 | VkFence fence = {}; |
| 3778 | VkFenceCreateInfo fence_ci = {}; |
| 3779 | fence_ci.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO; |
| 3780 | fence_ci.pNext = nullptr; |
| 3781 | fence_ci.flags = 0; |
| 3782 | result = vkCreateFence(m_device->device(), &fence_ci, nullptr, &fence); |
| 3783 | ASSERT_VK_SUCCESS(result); |
| 3784 | |
| 3785 | |
| 3786 | m_commandBuffer->BeginCommandBuffer(); |
| 3787 | m_commandBuffer->BeginRenderPass(rpbinfo); |
| 3788 | m_commandBuffer->EndRenderPass(); |
| 3789 | m_commandBuffer->EndCommandBuffer(); |
| 3790 | m_commandBuffer->QueueCommandBuffer(fence); |
| 3791 | |
| 3792 | VkImageObj destImage(m_device); |
| 3793 | destImage.init(100, 100, depth_stencil_fmt, |
| 3794 | VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT | |
| 3795 | VK_IMAGE_USAGE_TRANSFER_DST_BIT, |
| 3796 | VK_IMAGE_TILING_OPTIMAL, 0); |
| 3797 | VkImageMemoryBarrier barrier = {}; |
| 3798 | VkImageSubresourceRange range; |
| 3799 | barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER; |
| 3800 | barrier.srcAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT | |
| 3801 | VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT; |
| 3802 | barrier.dstAccessMask = VK_ACCESS_TRANSFER_READ_BIT | |
| 3803 | VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_READ_BIT; |
| 3804 | barrier.oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL; |
| 3805 | barrier.newLayout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL; |
| 3806 | barrier.image = m_depthStencil->handle(); |
| 3807 | range.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT; |
| 3808 | range.baseMipLevel = 0; |
| 3809 | range.levelCount = 1; |
| 3810 | range.baseArrayLayer = 0; |
| 3811 | range.layerCount = 1; |
| 3812 | barrier.subresourceRange = range; |
| 3813 | vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX); |
| 3814 | VkCommandBufferObj cmdbuf(m_device, m_commandPool); |
| 3815 | cmdbuf.BeginCommandBuffer(); |
| 3816 | cmdbuf.PipelineBarrier(VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, |
| 3817 | VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, nullptr, 0, |
| 3818 | nullptr, 1, &barrier); |
| 3819 | barrier.srcAccessMask = 0; |
| 3820 | barrier.oldLayout = VK_IMAGE_LAYOUT_UNDEFINED; |
| 3821 | barrier.newLayout = VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL; |
| 3822 | barrier.image = destImage.handle(); |
| 3823 | barrier.dstAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT | |
| 3824 | VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT; |
| 3825 | cmdbuf.PipelineBarrier(VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, |
| 3826 | VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, nullptr, 0, |
| 3827 | nullptr, 1, &barrier); |
| 3828 | VkImageCopy cregion; |
| 3829 | cregion.srcSubresource.aspectMask = |
| 3830 | VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT; |
| 3831 | cregion.srcSubresource.mipLevel = 0; |
| 3832 | cregion.srcSubresource.baseArrayLayer = 0; |
| 3833 | cregion.srcSubresource.layerCount = 1; |
| 3834 | cregion.srcOffset.x = 0; |
| 3835 | cregion.srcOffset.y = 0; |
| 3836 | cregion.srcOffset.z = 0; |
| 3837 | cregion.dstSubresource.aspectMask = |
| 3838 | VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT; |
| 3839 | cregion.dstSubresource.mipLevel = 0; |
| 3840 | cregion.dstSubresource.baseArrayLayer = 0; |
| 3841 | cregion.dstSubresource.layerCount = 1; |
| 3842 | cregion.dstOffset.x = 0; |
| 3843 | cregion.dstOffset.y = 0; |
| 3844 | cregion.dstOffset.z = 0; |
| 3845 | cregion.extent.width = 100; |
| 3846 | cregion.extent.height = 100; |
| 3847 | cregion.extent.depth = 1; |
| 3848 | cmdbuf.CopyImage(m_depthStencil->handle(), |
| 3849 | VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, destImage.handle(), |
| 3850 | VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &cregion); |
| 3851 | cmdbuf.EndCommandBuffer(); |
| 3852 | |
| 3853 | VkSubmitInfo submit_info; |
| 3854 | submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO; |
| 3855 | submit_info.pNext = NULL; |
| 3856 | submit_info.waitSemaphoreCount = 0; |
| 3857 | submit_info.pWaitSemaphores = NULL; |
| 3858 | submit_info.pWaitDstStageMask = NULL; |
| 3859 | submit_info.commandBufferCount = 1; |
| 3860 | submit_info.pCommandBuffers = &cmdbuf.handle(); |
| 3861 | submit_info.signalSemaphoreCount = 0; |
| 3862 | submit_info.pSignalSemaphores = NULL; |
| 3863 | |
| 3864 | m_errorMonitor->ExpectSuccess(); |
| 3865 | vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE); |
| 3866 | m_errorMonitor->VerifyNotFound(); |
| 3867 | |
Mark Lobodzinski | d0440da | 2016-06-17 15:10:03 -0600 | [diff] [blame] | 3868 | vkQueueWaitIdle(m_device->m_queue); |
Mark Lobodzinski | ce7eee7 | 2016-06-14 16:33:29 -0600 | [diff] [blame] | 3869 | vkDestroyFence(m_device->device(), fence, nullptr); |
| 3870 | vkDestroyRenderPass(m_device->device(), rp, nullptr); |
| 3871 | vkDestroyFramebuffer(m_device->device(), fb, nullptr); |
| 3872 | } |
| 3873 | |
Mark Lobodzinski | 6d17b9f | 2016-06-16 13:21:38 -0600 | [diff] [blame] | 3874 | TEST_F(VkLayerTest, UnusedPreserveAttachment) { |
| 3875 | TEST_DESCRIPTION("Create a framebuffer where a subpass has a preserve " |
| 3876 | "attachment reference of VK_ATTACHMENT_UNUSED"); |
| 3877 | |
| 3878 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 3879 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 3880 | |
| 3881 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 3882 | "must not be VK_ATTACHMENT_UNUSED"); |
| 3883 | |
| 3884 | VkAttachmentReference color_attach = {}; |
| 3885 | color_attach.layout = VK_IMAGE_LAYOUT_GENERAL; |
| 3886 | color_attach.attachment = 0; |
| 3887 | uint32_t preserve_attachment = VK_ATTACHMENT_UNUSED; |
| 3888 | VkSubpassDescription subpass = {}; |
| 3889 | subpass.colorAttachmentCount = 1; |
| 3890 | subpass.pColorAttachments = &color_attach; |
| 3891 | subpass.preserveAttachmentCount = 1; |
| 3892 | subpass.pPreserveAttachments = &preserve_attachment; |
| 3893 | |
| 3894 | VkRenderPassCreateInfo rpci = {}; |
| 3895 | rpci.subpassCount = 1; |
| 3896 | rpci.pSubpasses = &subpass; |
| 3897 | rpci.attachmentCount = 1; |
| 3898 | VkAttachmentDescription attach_desc = {}; |
| 3899 | attach_desc.format = VK_FORMAT_UNDEFINED; |
| 3900 | rpci.pAttachments = &attach_desc; |
| 3901 | rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO; |
| 3902 | VkRenderPass rp; |
Mark Lobodzinski | a4feeeb | 2016-06-17 12:00:46 -0600 | [diff] [blame] | 3903 | VkResult result = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp); |
Mark Lobodzinski | 6d17b9f | 2016-06-16 13:21:38 -0600 | [diff] [blame] | 3904 | |
| 3905 | m_errorMonitor->VerifyFound(); |
| 3906 | |
Mark Lobodzinski | a4feeeb | 2016-06-17 12:00:46 -0600 | [diff] [blame] | 3907 | if (result == VK_SUCCESS) { |
| 3908 | vkDestroyRenderPass(m_device->device(), rp, NULL); |
| 3909 | } |
Mark Lobodzinski | 6d17b9f | 2016-06-16 13:21:38 -0600 | [diff] [blame] | 3910 | } |
| 3911 | |
Chris Forbes | c538974 | 2016-06-29 11:49:23 +1200 | [diff] [blame] | 3912 | TEST_F(VkLayerTest, CreateRenderPassResolveRequiresColorMsaa) { |
Chris Forbes | 6655bb3 | 2016-07-01 18:27:30 +1200 | [diff] [blame] | 3913 | TEST_DESCRIPTION("Ensure that CreateRenderPass produces a validation error " |
| 3914 | "when the source of a subpass multisample resolve " |
| 3915 | "does not have multiple samples."); |
| 3916 | |
Chris Forbes | c538974 | 2016-06-29 11:49:23 +1200 | [diff] [blame] | 3917 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 3918 | |
| 3919 | m_errorMonitor->SetDesiredFailureMsg( |
| 3920 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Chris Forbes | 6655bb3 | 2016-07-01 18:27:30 +1200 | [diff] [blame] | 3921 | "Subpass 0 requests multisample resolve from attachment 0 which has " |
| 3922 | "VK_SAMPLE_COUNT_1_BIT"); |
Chris Forbes | c538974 | 2016-06-29 11:49:23 +1200 | [diff] [blame] | 3923 | |
| 3924 | VkAttachmentDescription attachments[] = { |
| 3925 | { |
| 3926 | 0, VK_FORMAT_R8G8B8A8_UNORM, |
| 3927 | VK_SAMPLE_COUNT_1_BIT, |
| 3928 | VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, |
| 3929 | VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, |
| 3930 | VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, |
| 3931 | VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL |
| 3932 | }, |
| 3933 | { |
| 3934 | 0, VK_FORMAT_R8G8B8A8_UNORM, |
| 3935 | VK_SAMPLE_COUNT_1_BIT, |
| 3936 | VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, |
| 3937 | VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, |
| 3938 | VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, |
| 3939 | VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL |
| 3940 | }, |
| 3941 | }; |
| 3942 | |
| 3943 | VkAttachmentReference color = { |
| 3944 | 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, |
| 3945 | }; |
| 3946 | |
| 3947 | VkAttachmentReference resolve = { |
| 3948 | 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, |
| 3949 | }; |
| 3950 | |
| 3951 | VkSubpassDescription subpass = { |
| 3952 | 0, VK_PIPELINE_BIND_POINT_GRAPHICS, |
| 3953 | 0, nullptr, |
| 3954 | 1, &color, |
| 3955 | &resolve, |
| 3956 | nullptr, |
| 3957 | 0, nullptr |
| 3958 | }; |
| 3959 | |
| 3960 | VkRenderPassCreateInfo rpci = { |
| 3961 | VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, |
| 3962 | 0, 2, attachments, 1, &subpass, 0, nullptr |
| 3963 | }; |
| 3964 | |
| 3965 | VkRenderPass rp; |
| 3966 | VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp); |
| 3967 | |
| 3968 | m_errorMonitor->VerifyFound(); |
| 3969 | |
| 3970 | if (err == VK_SUCCESS) |
| 3971 | vkDestroyRenderPass(m_device->device(), rp, nullptr); |
| 3972 | } |
| 3973 | |
| 3974 | TEST_F(VkLayerTest, CreateRenderPassResolveRequiresSingleSampleDest) { |
Chris Forbes | 6655bb3 | 2016-07-01 18:27:30 +1200 | [diff] [blame] | 3975 | TEST_DESCRIPTION("Ensure CreateRenderPass produces a validation error " |
| 3976 | "when a subpass multisample resolve operation is " |
| 3977 | "requested, and the destination of that resolve has " |
| 3978 | "multiple samples."); |
| 3979 | |
Chris Forbes | c538974 | 2016-06-29 11:49:23 +1200 | [diff] [blame] | 3980 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 3981 | |
| 3982 | m_errorMonitor->SetDesiredFailureMsg( |
| 3983 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 3984 | "Subpass 0 requests multisample resolve into attachment 1, which " |
| 3985 | "must have VK_SAMPLE_COUNT_1_BIT but has VK_SAMPLE_COUNT_4_BIT"); |
| 3986 | |
| 3987 | VkAttachmentDescription attachments[] = { |
| 3988 | { |
| 3989 | 0, VK_FORMAT_R8G8B8A8_UNORM, |
| 3990 | VK_SAMPLE_COUNT_4_BIT, |
| 3991 | VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, |
| 3992 | VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, |
| 3993 | VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, |
| 3994 | VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL |
| 3995 | }, |
| 3996 | { |
| 3997 | 0, VK_FORMAT_R8G8B8A8_UNORM, |
| 3998 | VK_SAMPLE_COUNT_4_BIT, |
| 3999 | VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, |
| 4000 | VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, |
| 4001 | VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, |
| 4002 | VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL |
| 4003 | }, |
| 4004 | }; |
| 4005 | |
| 4006 | VkAttachmentReference color = { |
| 4007 | 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, |
| 4008 | }; |
| 4009 | |
| 4010 | VkAttachmentReference resolve = { |
| 4011 | 1, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, |
| 4012 | }; |
| 4013 | |
| 4014 | VkSubpassDescription subpass = { |
| 4015 | 0, VK_PIPELINE_BIND_POINT_GRAPHICS, |
| 4016 | 0, nullptr, |
| 4017 | 1, &color, |
| 4018 | &resolve, |
| 4019 | nullptr, |
| 4020 | 0, nullptr |
| 4021 | }; |
| 4022 | |
| 4023 | VkRenderPassCreateInfo rpci = { |
| 4024 | VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, |
| 4025 | 0, 2, attachments, 1, &subpass, 0, nullptr |
| 4026 | }; |
| 4027 | |
| 4028 | VkRenderPass rp; |
| 4029 | VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp); |
| 4030 | |
| 4031 | m_errorMonitor->VerifyFound(); |
| 4032 | |
| 4033 | if (err == VK_SUCCESS) |
| 4034 | vkDestroyRenderPass(m_device->device(), rp, nullptr); |
| 4035 | } |
| 4036 | |
Chris Forbes | 3f128ef | 2016-06-29 14:58:53 +1200 | [diff] [blame] | 4037 | TEST_F(VkLayerTest, CreateRenderPassSubpassSampleCountConsistency) { |
Chris Forbes | 6655bb3 | 2016-07-01 18:27:30 +1200 | [diff] [blame] | 4038 | TEST_DESCRIPTION("Ensure CreateRenderPass produces a validation error " |
| 4039 | "when the color and depth attachments used by a subpass " |
| 4040 | "have inconsistent sample counts"); |
| 4041 | |
Chris Forbes | 3f128ef | 2016-06-29 14:58:53 +1200 | [diff] [blame] | 4042 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 4043 | |
| 4044 | m_errorMonitor->SetDesiredFailureMsg( |
| 4045 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 4046 | "Subpass 0 attempts to render to attachments with inconsistent sample counts"); |
| 4047 | |
| 4048 | VkAttachmentDescription attachments[] = { |
| 4049 | { |
| 4050 | 0, VK_FORMAT_R8G8B8A8_UNORM, |
| 4051 | VK_SAMPLE_COUNT_1_BIT, |
| 4052 | VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, |
| 4053 | VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, |
| 4054 | VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, |
| 4055 | VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL |
| 4056 | }, |
| 4057 | { |
| 4058 | 0, VK_FORMAT_R8G8B8A8_UNORM, |
| 4059 | VK_SAMPLE_COUNT_4_BIT, |
| 4060 | VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, |
| 4061 | VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, |
| 4062 | VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, |
| 4063 | VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL |
| 4064 | }, |
| 4065 | }; |
| 4066 | |
| 4067 | VkAttachmentReference color[] = { |
| 4068 | { |
| 4069 | 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, |
| 4070 | }, |
| 4071 | { |
| 4072 | 1, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, |
| 4073 | }, |
| 4074 | }; |
| 4075 | |
| 4076 | VkSubpassDescription subpass = { |
| 4077 | 0, VK_PIPELINE_BIND_POINT_GRAPHICS, |
| 4078 | 0, nullptr, |
| 4079 | 2, color, |
| 4080 | nullptr, |
| 4081 | nullptr, |
| 4082 | 0, nullptr |
| 4083 | }; |
| 4084 | |
| 4085 | VkRenderPassCreateInfo rpci = { |
| 4086 | VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, |
| 4087 | 0, 2, attachments, 1, &subpass, 0, nullptr |
| 4088 | }; |
| 4089 | |
| 4090 | VkRenderPass rp; |
| 4091 | VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp); |
| 4092 | |
| 4093 | m_errorMonitor->VerifyFound(); |
| 4094 | |
| 4095 | if (err == VK_SUCCESS) |
| 4096 | vkDestroyRenderPass(m_device->device(), rp, nullptr); |
| 4097 | } |
| 4098 | |
Tobin Ehlis | 2545e6f | 2016-06-22 10:42:19 -0600 | [diff] [blame] | 4099 | TEST_F(VkLayerTest, FramebufferCreateErrors) { |
| 4100 | TEST_DESCRIPTION("Hit errors when attempting to create a framebuffer :\n" |
| 4101 | " 1. Mismatch between fb & renderPass attachmentCount\n" |
Tobin Ehlis | d3bb23a | 2016-06-22 13:34:46 -0600 | [diff] [blame] | 4102 | " 2. Use a color image as depthStencil attachment\n" |
Tobin Ehlis | 77d717c | 2016-06-22 14:19:19 -0600 | [diff] [blame] | 4103 | " 3. Mismatch fb & renderPass attachment formats\n" |
Tobin Ehlis | 6cfda64 | 2016-06-22 16:12:58 -0600 | [diff] [blame] | 4104 | " 4. Mismatch fb & renderPass attachment #samples\n" |
Tobin Ehlis | 27f2ae8 | 2016-06-23 07:36:57 -0600 | [diff] [blame] | 4105 | " 5. FB attachment w/ non-1 mip-levels\n" |
Tobin Ehlis | b1f303b | 2016-06-23 08:19:55 -0600 | [diff] [blame] | 4106 | " 6. FB attachment where dimensions don't match\n" |
Tobin Ehlis | 08d4b5e | 2016-06-23 08:52:39 -0600 | [diff] [blame] | 4107 | " 7. FB attachment w/o identity swizzle\n" |
| 4108 | " 8. FB dimensions exceed physical device limits\n"); |
Mark Lobodzinski | 6d17b9f | 2016-06-16 13:21:38 -0600 | [diff] [blame] | 4109 | |
| 4110 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 4111 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 4112 | |
| 4113 | m_errorMonitor->SetDesiredFailureMsg( |
| 4114 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Tobin Ehlis | 2545e6f | 2016-06-22 10:42:19 -0600 | [diff] [blame] | 4115 | "vkCreateFramebuffer(): VkFramebufferCreateInfo attachmentCount of 2 " |
| 4116 | "does not match attachmentCount of 1 of "); |
Mark Lobodzinski | 6d17b9f | 2016-06-16 13:21:38 -0600 | [diff] [blame] | 4117 | |
Tobin Ehlis | 2545e6f | 2016-06-22 10:42:19 -0600 | [diff] [blame] | 4118 | // Create a renderPass with a single color attachment |
Mark Lobodzinski | 6d17b9f | 2016-06-16 13:21:38 -0600 | [diff] [blame] | 4119 | VkAttachmentReference attach = {}; |
| 4120 | attach.layout = VK_IMAGE_LAYOUT_GENERAL; |
| 4121 | VkSubpassDescription subpass = {}; |
Tobin Ehlis | 2545e6f | 2016-06-22 10:42:19 -0600 | [diff] [blame] | 4122 | subpass.pColorAttachments = &attach; |
Mark Lobodzinski | 6d17b9f | 2016-06-16 13:21:38 -0600 | [diff] [blame] | 4123 | VkRenderPassCreateInfo rpci = {}; |
| 4124 | rpci.subpassCount = 1; |
| 4125 | rpci.pSubpasses = &subpass; |
| 4126 | rpci.attachmentCount = 1; |
| 4127 | VkAttachmentDescription attach_desc = {}; |
Tobin Ehlis | d3bb23a | 2016-06-22 13:34:46 -0600 | [diff] [blame] | 4128 | attach_desc.format = VK_FORMAT_B8G8R8A8_UNORM; |
Tobin Ehlis | 77d717c | 2016-06-22 14:19:19 -0600 | [diff] [blame] | 4129 | attach_desc.samples = VK_SAMPLE_COUNT_1_BIT; |
Mark Lobodzinski | 6d17b9f | 2016-06-16 13:21:38 -0600 | [diff] [blame] | 4130 | rpci.pAttachments = &attach_desc; |
| 4131 | rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO; |
| 4132 | VkRenderPass rp; |
| 4133 | VkResult err = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp); |
| 4134 | ASSERT_VK_SUCCESS(err); |
| 4135 | |
Tobin Ehlis | 2545e6f | 2016-06-22 10:42:19 -0600 | [diff] [blame] | 4136 | VkImageView ivs[2]; |
| 4137 | ivs[0] = m_renderTargets[0]->targetView(VK_FORMAT_B8G8R8A8_UNORM); |
| 4138 | ivs[1] = m_renderTargets[0]->targetView(VK_FORMAT_B8G8R8A8_UNORM); |
Mark Lobodzinski | 6d17b9f | 2016-06-16 13:21:38 -0600 | [diff] [blame] | 4139 | VkFramebufferCreateInfo fb_info = {}; |
| 4140 | fb_info.sType = VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO; |
| 4141 | fb_info.pNext = NULL; |
| 4142 | fb_info.renderPass = rp; |
Tobin Ehlis | 2545e6f | 2016-06-22 10:42:19 -0600 | [diff] [blame] | 4143 | // Set mis-matching attachmentCount |
| 4144 | fb_info.attachmentCount = 2; |
| 4145 | fb_info.pAttachments = ivs; |
Mark Lobodzinski | 6d17b9f | 2016-06-16 13:21:38 -0600 | [diff] [blame] | 4146 | fb_info.width = 100; |
| 4147 | fb_info.height = 100; |
| 4148 | fb_info.layers = 1; |
| 4149 | |
| 4150 | VkFramebuffer fb; |
| 4151 | err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb); |
| 4152 | |
| 4153 | m_errorMonitor->VerifyFound(); |
Mark Lobodzinski | 6d17b9f | 2016-06-16 13:21:38 -0600 | [diff] [blame] | 4154 | if (err == VK_SUCCESS) { |
| 4155 | vkDestroyFramebuffer(m_device->device(), fb, NULL); |
| 4156 | } |
| 4157 | vkDestroyRenderPass(m_device->device(), rp, NULL); |
Tobin Ehlis | 2545e6f | 2016-06-22 10:42:19 -0600 | [diff] [blame] | 4158 | |
| 4159 | // Create a renderPass with a depth-stencil attachment created with |
| 4160 | // IMAGE_USAGE_COLOR_ATTACHMENT |
| 4161 | // Add our color attachment to pDepthStencilAttachment |
| 4162 | subpass.pDepthStencilAttachment = &attach; |
| 4163 | subpass.pColorAttachments = NULL; |
| 4164 | VkRenderPass rp_ds; |
| 4165 | err = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp_ds); |
| 4166 | ASSERT_VK_SUCCESS(err); |
| 4167 | // Set correct attachment count, but attachment has COLOR usage bit set |
| 4168 | fb_info.attachmentCount = 1; |
| 4169 | fb_info.renderPass = rp_ds; |
| 4170 | |
| 4171 | m_errorMonitor->SetDesiredFailureMsg( |
| 4172 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 4173 | " conflicts with the image's IMAGE_USAGE flags "); |
| 4174 | err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb); |
| 4175 | |
| 4176 | m_errorMonitor->VerifyFound(); |
| 4177 | if (err == VK_SUCCESS) { |
| 4178 | vkDestroyFramebuffer(m_device->device(), fb, NULL); |
| 4179 | } |
| 4180 | vkDestroyRenderPass(m_device->device(), rp_ds, NULL); |
Tobin Ehlis | d3bb23a | 2016-06-22 13:34:46 -0600 | [diff] [blame] | 4181 | |
| 4182 | // Create new renderpass with alternate attachment format from fb |
| 4183 | attach_desc.format = VK_FORMAT_R8G8B8A8_UNORM; |
| 4184 | subpass.pDepthStencilAttachment = NULL; |
| 4185 | subpass.pColorAttachments = &attach; |
| 4186 | err = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp); |
| 4187 | ASSERT_VK_SUCCESS(err); |
| 4188 | |
| 4189 | // Cause error due to mis-matched formats between rp & fb |
| 4190 | // rp attachment 0 now has RGBA8 but corresponding fb attach is BGRA8 |
| 4191 | fb_info.renderPass = rp; |
| 4192 | m_errorMonitor->SetDesiredFailureMsg( |
| 4193 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 4194 | " has format of VK_FORMAT_B8G8R8A8_UNORM that does not match "); |
| 4195 | err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb); |
| 4196 | |
| 4197 | m_errorMonitor->VerifyFound(); |
| 4198 | if (err == VK_SUCCESS) { |
| 4199 | vkDestroyFramebuffer(m_device->device(), fb, NULL); |
| 4200 | } |
Tobin Ehlis | 77d717c | 2016-06-22 14:19:19 -0600 | [diff] [blame] | 4201 | vkDestroyRenderPass(m_device->device(), rp, NULL); |
| 4202 | |
| 4203 | // Create new renderpass with alternate sample count from fb |
| 4204 | attach_desc.format = VK_FORMAT_B8G8R8A8_UNORM; |
| 4205 | attach_desc.samples = VK_SAMPLE_COUNT_4_BIT; |
| 4206 | err = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp); |
| 4207 | ASSERT_VK_SUCCESS(err); |
| 4208 | |
| 4209 | // Cause error due to mis-matched sample count between rp & fb |
| 4210 | fb_info.renderPass = rp; |
| 4211 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 4212 | " has VK_SAMPLE_COUNT_1_BIT samples " |
| 4213 | "that do not match the " |
| 4214 | "VK_SAMPLE_COUNT_4_BIT "); |
| 4215 | err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb); |
| 4216 | |
| 4217 | m_errorMonitor->VerifyFound(); |
| 4218 | if (err == VK_SUCCESS) { |
| 4219 | vkDestroyFramebuffer(m_device->device(), fb, NULL); |
| 4220 | } |
Tobin Ehlis | d3bb23a | 2016-06-22 13:34:46 -0600 | [diff] [blame] | 4221 | |
| 4222 | vkDestroyRenderPass(m_device->device(), rp, NULL); |
Tobin Ehlis | 6cfda64 | 2016-06-22 16:12:58 -0600 | [diff] [blame] | 4223 | |
| 4224 | // Create a custom imageView with non-1 mip levels |
| 4225 | VkImageObj image(m_device); |
| 4226 | image.init(128, 128, VK_FORMAT_B8G8R8A8_UNORM, |
| 4227 | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0); |
| 4228 | ASSERT_TRUE(image.initialized()); |
| 4229 | |
| 4230 | VkImageView view; |
| 4231 | VkImageViewCreateInfo ivci = {}; |
| 4232 | ivci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO; |
| 4233 | ivci.image = image.handle(); |
| 4234 | ivci.viewType = VK_IMAGE_VIEW_TYPE_2D; |
| 4235 | ivci.format = VK_FORMAT_B8G8R8A8_UNORM; |
| 4236 | ivci.subresourceRange.layerCount = 1; |
| 4237 | ivci.subresourceRange.baseMipLevel = 0; |
| 4238 | // Set level count 2 (only 1 is allowed for FB attachment) |
| 4239 | ivci.subresourceRange.levelCount = 2; |
| 4240 | ivci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; |
| 4241 | err = vkCreateImageView(m_device->device(), &ivci, NULL, &view); |
| 4242 | ASSERT_VK_SUCCESS(err); |
| 4243 | // Re-create renderpass to have matching sample count |
| 4244 | attach_desc.samples = VK_SAMPLE_COUNT_1_BIT; |
| 4245 | err = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp); |
| 4246 | ASSERT_VK_SUCCESS(err); |
| 4247 | |
| 4248 | fb_info.renderPass = rp; |
| 4249 | fb_info.pAttachments = &view; |
| 4250 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 4251 | " has mip levelCount of 2 but only "); |
| 4252 | err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb); |
| 4253 | |
| 4254 | m_errorMonitor->VerifyFound(); |
| 4255 | if (err == VK_SUCCESS) { |
| 4256 | vkDestroyFramebuffer(m_device->device(), fb, NULL); |
| 4257 | } |
Tobin Ehlis | 6cfda64 | 2016-06-22 16:12:58 -0600 | [diff] [blame] | 4258 | vkDestroyImageView(m_device->device(), view, NULL); |
Tobin Ehlis | 27f2ae8 | 2016-06-23 07:36:57 -0600 | [diff] [blame] | 4259 | // Update view to original color buffer and grow FB dimensions too big |
| 4260 | fb_info.pAttachments = ivs; |
| 4261 | fb_info.height = 1024; |
| 4262 | fb_info.width = 1024; |
| 4263 | fb_info.layers = 2; |
| 4264 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 4265 | " Attachment dimensions must be at " |
| 4266 | "least as large. "); |
| 4267 | err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb); |
| 4268 | |
| 4269 | m_errorMonitor->VerifyFound(); |
| 4270 | if (err == VK_SUCCESS) { |
| 4271 | vkDestroyFramebuffer(m_device->device(), fb, NULL); |
| 4272 | } |
Tobin Ehlis | b1f303b | 2016-06-23 08:19:55 -0600 | [diff] [blame] | 4273 | // Create view attachment with non-identity swizzle |
| 4274 | ivci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO; |
| 4275 | ivci.image = image.handle(); |
| 4276 | ivci.viewType = VK_IMAGE_VIEW_TYPE_2D; |
| 4277 | ivci.format = VK_FORMAT_B8G8R8A8_UNORM; |
| 4278 | ivci.subresourceRange.layerCount = 1; |
| 4279 | ivci.subresourceRange.baseMipLevel = 0; |
| 4280 | ivci.subresourceRange.levelCount = 1; |
| 4281 | ivci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; |
| 4282 | ivci.components.r = VK_COMPONENT_SWIZZLE_G; |
| 4283 | ivci.components.g = VK_COMPONENT_SWIZZLE_R; |
| 4284 | ivci.components.b = VK_COMPONENT_SWIZZLE_A; |
| 4285 | ivci.components.a = VK_COMPONENT_SWIZZLE_B; |
| 4286 | err = vkCreateImageView(m_device->device(), &ivci, NULL, &view); |
| 4287 | ASSERT_VK_SUCCESS(err); |
| 4288 | |
| 4289 | fb_info.pAttachments = &view; |
| 4290 | fb_info.height = 100; |
| 4291 | fb_info.width = 100; |
| 4292 | fb_info.layers = 1; |
| 4293 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 4294 | " has non-identy swizzle. All " |
| 4295 | "framebuffer attachments must have " |
| 4296 | "been created with the identity " |
| 4297 | "swizzle. "); |
| 4298 | err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb); |
| 4299 | |
| 4300 | m_errorMonitor->VerifyFound(); |
| 4301 | if (err == VK_SUCCESS) { |
| 4302 | vkDestroyFramebuffer(m_device->device(), fb, NULL); |
| 4303 | } |
| 4304 | vkDestroyImageView(m_device->device(), view, NULL); |
Tobin Ehlis | 08d4b5e | 2016-06-23 08:52:39 -0600 | [diff] [blame] | 4305 | // Request fb that exceeds max dimensions |
| 4306 | // reset attachment to color attachment |
| 4307 | fb_info.pAttachments = ivs; |
| 4308 | fb_info.width = m_device->props.limits.maxFramebufferWidth + 1; |
| 4309 | fb_info.height = m_device->props.limits.maxFramebufferHeight + 1; |
| 4310 | fb_info.layers = m_device->props.limits.maxFramebufferLayers + 1; |
| 4311 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 4312 | " Requested VkFramebufferCreateInfo " |
| 4313 | "dimensions exceed physical device " |
| 4314 | "limits. "); |
| 4315 | err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb); |
| 4316 | |
| 4317 | m_errorMonitor->VerifyFound(); |
| 4318 | if (err == VK_SUCCESS) { |
| 4319 | vkDestroyFramebuffer(m_device->device(), fb, NULL); |
| 4320 | } |
Tobin Ehlis | 27f2ae8 | 2016-06-23 07:36:57 -0600 | [diff] [blame] | 4321 | |
Tobin Ehlis | 6cfda64 | 2016-06-22 16:12:58 -0600 | [diff] [blame] | 4322 | vkDestroyRenderPass(m_device->device(), rp, NULL); |
Mark Lobodzinski | 6d17b9f | 2016-06-16 13:21:38 -0600 | [diff] [blame] | 4323 | } |
| 4324 | |
Mark Lobodzinski | c808d44 | 2016-04-14 10:57:23 -0600 | [diff] [blame] | 4325 | // This is a positive test. No errors should be generated. |
Michael Lentine | 860b0fe | 2016-05-20 10:14:00 -0500 | [diff] [blame] | 4326 | TEST_F(VkLayerTest, WaitEventThenSet) { |
| 4327 | TEST_DESCRIPTION( |
| 4328 | "Wait on a event then set it after the wait has been submitted."); |
| 4329 | |
Michael Lentine | 860b0fe | 2016-05-20 10:14:00 -0500 | [diff] [blame] | 4330 | m_errorMonitor->ExpectSuccess(); |
| 4331 | |
| 4332 | VkEvent event; |
| 4333 | VkEventCreateInfo event_create_info{}; |
| 4334 | event_create_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO; |
| 4335 | vkCreateEvent(m_device->device(), &event_create_info, nullptr, &event); |
| 4336 | |
| 4337 | VkCommandPool command_pool; |
| 4338 | VkCommandPoolCreateInfo pool_create_info{}; |
| 4339 | pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO; |
| 4340 | pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_; |
| 4341 | pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT; |
| 4342 | vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, |
| 4343 | &command_pool); |
| 4344 | |
| 4345 | VkCommandBuffer command_buffer; |
| 4346 | VkCommandBufferAllocateInfo command_buffer_allocate_info{}; |
| 4347 | command_buffer_allocate_info.sType = |
| 4348 | VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO; |
| 4349 | command_buffer_allocate_info.commandPool = command_pool; |
| 4350 | command_buffer_allocate_info.commandBufferCount = 1; |
| 4351 | command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY; |
| 4352 | vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, |
| 4353 | &command_buffer); |
| 4354 | |
| 4355 | VkQueue queue = VK_NULL_HANDLE; |
| 4356 | vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, |
Tony Barbour | fe302c0 | 2016-06-06 13:05:19 -0600 | [diff] [blame] | 4357 | 0, &queue); |
Michael Lentine | 860b0fe | 2016-05-20 10:14:00 -0500 | [diff] [blame] | 4358 | |
| 4359 | { |
| 4360 | VkCommandBufferBeginInfo begin_info{}; |
| 4361 | begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO; |
| 4362 | vkBeginCommandBuffer(command_buffer, &begin_info); |
| 4363 | |
| 4364 | vkCmdWaitEvents(command_buffer, 1, &event, VK_PIPELINE_STAGE_HOST_BIT, |
| 4365 | VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, nullptr, 0, |
| 4366 | nullptr, 0, nullptr); |
| 4367 | vkCmdResetEvent(command_buffer, event, |
| 4368 | VK_PIPELINE_STAGE_ALL_COMMANDS_BIT); |
| 4369 | vkEndCommandBuffer(command_buffer); |
| 4370 | } |
| 4371 | { |
| 4372 | VkSubmitInfo submit_info{}; |
| 4373 | submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO; |
| 4374 | submit_info.commandBufferCount = 1; |
| 4375 | submit_info.pCommandBuffers = &command_buffer; |
| 4376 | submit_info.signalSemaphoreCount = 0; |
| 4377 | submit_info.pSignalSemaphores = nullptr; |
| 4378 | vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE); |
| 4379 | } |
| 4380 | { vkSetEvent(m_device->device(), event); } |
| 4381 | |
| 4382 | vkQueueWaitIdle(queue); |
| 4383 | |
| 4384 | vkDestroyEvent(m_device->device(), event, nullptr); |
| 4385 | vkFreeCommandBuffers(m_device->device(), command_pool, 1, &command_buffer); |
| 4386 | vkDestroyCommandPool(m_device->device(), command_pool, NULL); |
| 4387 | |
| 4388 | m_errorMonitor->VerifyNotFound(); |
| 4389 | } |
Michael Lentine | 5627e69 | 2016-05-20 17:45:02 -0500 | [diff] [blame] | 4390 | // This is a positive test. No errors should be generated. |
| 4391 | TEST_F(VkLayerTest, QueryAndCopyMultipleCommandBuffers) { |
| 4392 | TEST_DESCRIPTION( |
| 4393 | "Issue a query and copy from it on a second command buffer."); |
| 4394 | |
| 4395 | if ((m_device->queue_props.empty()) || |
| 4396 | (m_device->queue_props[0].queueCount < 2)) |
| 4397 | return; |
| 4398 | |
| 4399 | m_errorMonitor->ExpectSuccess(); |
| 4400 | |
| 4401 | VkQueryPool query_pool; |
| 4402 | VkQueryPoolCreateInfo query_pool_create_info{}; |
| 4403 | query_pool_create_info.sType = VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO; |
| 4404 | query_pool_create_info.queryType = VK_QUERY_TYPE_TIMESTAMP; |
| 4405 | query_pool_create_info.queryCount = 1; |
| 4406 | vkCreateQueryPool(m_device->device(), &query_pool_create_info, nullptr, |
| 4407 | &query_pool); |
| 4408 | |
| 4409 | VkCommandPool command_pool; |
| 4410 | VkCommandPoolCreateInfo pool_create_info{}; |
| 4411 | pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO; |
| 4412 | pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_; |
| 4413 | pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT; |
| 4414 | vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, |
| 4415 | &command_pool); |
| 4416 | |
| 4417 | VkCommandBuffer command_buffer[2]; |
| 4418 | VkCommandBufferAllocateInfo command_buffer_allocate_info{}; |
| 4419 | command_buffer_allocate_info.sType = |
| 4420 | VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO; |
| 4421 | command_buffer_allocate_info.commandPool = command_pool; |
| 4422 | command_buffer_allocate_info.commandBufferCount = 2; |
| 4423 | command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY; |
| 4424 | vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, |
| 4425 | command_buffer); |
| 4426 | |
| 4427 | VkQueue queue = VK_NULL_HANDLE; |
| 4428 | vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, |
| 4429 | 1, &queue); |
| 4430 | |
| 4431 | uint32_t qfi = 0; |
| 4432 | VkBufferCreateInfo buff_create_info = {}; |
| 4433 | buff_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO; |
| 4434 | buff_create_info.size = 1024; |
| 4435 | buff_create_info.usage = VK_BUFFER_USAGE_TRANSFER_DST_BIT; |
| 4436 | buff_create_info.queueFamilyIndexCount = 1; |
| 4437 | buff_create_info.pQueueFamilyIndices = &qfi; |
| 4438 | |
| 4439 | VkResult err; |
| 4440 | VkBuffer buffer; |
| 4441 | err = vkCreateBuffer(m_device->device(), &buff_create_info, NULL, &buffer); |
| 4442 | ASSERT_VK_SUCCESS(err); |
| 4443 | VkMemoryAllocateInfo mem_alloc = {}; |
| 4444 | mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO; |
| 4445 | mem_alloc.pNext = NULL; |
| 4446 | mem_alloc.allocationSize = 1024; |
| 4447 | mem_alloc.memoryTypeIndex = 0; |
| 4448 | |
| 4449 | VkMemoryRequirements memReqs; |
| 4450 | vkGetBufferMemoryRequirements(m_device->device(), buffer, &memReqs); |
| 4451 | bool pass = |
| 4452 | m_device->phy().set_memory_type(memReqs.memoryTypeBits, &mem_alloc, 0); |
| 4453 | if (!pass) { |
| 4454 | vkDestroyBuffer(m_device->device(), buffer, NULL); |
| 4455 | return; |
| 4456 | } |
| 4457 | |
| 4458 | VkDeviceMemory mem; |
| 4459 | err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem); |
| 4460 | ASSERT_VK_SUCCESS(err); |
| 4461 | err = vkBindBufferMemory(m_device->device(), buffer, mem, 0); |
| 4462 | ASSERT_VK_SUCCESS(err); |
| 4463 | |
| 4464 | { |
| 4465 | VkCommandBufferBeginInfo begin_info{}; |
| 4466 | begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO; |
| 4467 | vkBeginCommandBuffer(command_buffer[0], &begin_info); |
| 4468 | |
| 4469 | vkCmdResetQueryPool(command_buffer[0], query_pool, 0, 1); |
| 4470 | vkCmdWriteTimestamp(command_buffer[0], |
| 4471 | VK_PIPELINE_STAGE_ALL_GRAPHICS_BIT, query_pool, 0); |
| 4472 | |
| 4473 | vkEndCommandBuffer(command_buffer[0]); |
| 4474 | |
| 4475 | vkBeginCommandBuffer(command_buffer[1], &begin_info); |
| 4476 | |
| 4477 | vkCmdCopyQueryPoolResults(command_buffer[1], query_pool, 0, 1, buffer, |
| 4478 | 0, 0, 0); |
| 4479 | |
| 4480 | vkEndCommandBuffer(command_buffer[1]); |
| 4481 | } |
| 4482 | { |
| 4483 | VkSubmitInfo submit_info{}; |
| 4484 | submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO; |
| 4485 | submit_info.commandBufferCount = 2; |
| 4486 | submit_info.pCommandBuffers = command_buffer; |
| 4487 | submit_info.signalSemaphoreCount = 0; |
| 4488 | submit_info.pSignalSemaphores = nullptr; |
| 4489 | vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE); |
| 4490 | } |
| 4491 | |
| 4492 | vkQueueWaitIdle(queue); |
| 4493 | |
| 4494 | vkDestroyQueryPool(m_device->device(), query_pool, nullptr); |
| 4495 | vkFreeCommandBuffers(m_device->device(), command_pool, 2, command_buffer); |
| 4496 | vkDestroyCommandPool(m_device->device(), command_pool, NULL); |
Tony Barbour | df4c004 | 2016-06-01 15:55:43 -0600 | [diff] [blame] | 4497 | vkDestroyBuffer(m_device->device(), buffer, NULL); |
| 4498 | vkFreeMemory(m_device->device(), mem, NULL); |
Michael Lentine | 5627e69 | 2016-05-20 17:45:02 -0500 | [diff] [blame] | 4499 | |
| 4500 | m_errorMonitor->VerifyNotFound(); |
| 4501 | } |
Michael Lentine | 860b0fe | 2016-05-20 10:14:00 -0500 | [diff] [blame] | 4502 | |
| 4503 | TEST_F(VkLayerTest, ResetEventThenSet) { |
| 4504 | TEST_DESCRIPTION( |
| 4505 | "Reset an event then set it after the reset has been submitted."); |
| 4506 | |
Michael Lentine | 860b0fe | 2016-05-20 10:14:00 -0500 | [diff] [blame] | 4507 | m_errorMonitor->ExpectSuccess(); |
| 4508 | |
| 4509 | VkEvent event; |
| 4510 | VkEventCreateInfo event_create_info{}; |
| 4511 | event_create_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO; |
| 4512 | vkCreateEvent(m_device->device(), &event_create_info, nullptr, &event); |
| 4513 | |
| 4514 | VkCommandPool command_pool; |
| 4515 | VkCommandPoolCreateInfo pool_create_info{}; |
| 4516 | pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO; |
| 4517 | pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_; |
| 4518 | pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT; |
| 4519 | vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, |
| 4520 | &command_pool); |
| 4521 | |
| 4522 | VkCommandBuffer command_buffer; |
| 4523 | VkCommandBufferAllocateInfo command_buffer_allocate_info{}; |
| 4524 | command_buffer_allocate_info.sType = |
| 4525 | VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO; |
| 4526 | command_buffer_allocate_info.commandPool = command_pool; |
| 4527 | command_buffer_allocate_info.commandBufferCount = 1; |
| 4528 | command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY; |
| 4529 | vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, |
| 4530 | &command_buffer); |
| 4531 | |
| 4532 | VkQueue queue = VK_NULL_HANDLE; |
| 4533 | vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, |
Tony Barbour | fe302c0 | 2016-06-06 13:05:19 -0600 | [diff] [blame] | 4534 | 0, &queue); |
Michael Lentine | 860b0fe | 2016-05-20 10:14:00 -0500 | [diff] [blame] | 4535 | |
| 4536 | { |
| 4537 | VkCommandBufferBeginInfo begin_info{}; |
| 4538 | begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO; |
| 4539 | vkBeginCommandBuffer(command_buffer, &begin_info); |
| 4540 | |
| 4541 | vkCmdResetEvent(command_buffer, event, |
| 4542 | VK_PIPELINE_STAGE_ALL_COMMANDS_BIT); |
| 4543 | vkCmdWaitEvents(command_buffer, 1, &event, |
| 4544 | VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, |
| 4545 | VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, nullptr, 0, |
| 4546 | nullptr, 0, nullptr); |
| 4547 | vkEndCommandBuffer(command_buffer); |
| 4548 | } |
| 4549 | { |
| 4550 | VkSubmitInfo submit_info{}; |
| 4551 | submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO; |
| 4552 | submit_info.commandBufferCount = 1; |
| 4553 | submit_info.pCommandBuffers = &command_buffer; |
| 4554 | submit_info.signalSemaphoreCount = 0; |
| 4555 | submit_info.pSignalSemaphores = nullptr; |
| 4556 | vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE); |
| 4557 | } |
| 4558 | { |
| 4559 | m_errorMonitor->SetDesiredFailureMsg( |
| 4560 | VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot call vkSetEvent() on event " |
| 4561 | "0x1 that is already in use by a " |
| 4562 | "command buffer."); |
| 4563 | vkSetEvent(m_device->device(), event); |
| 4564 | m_errorMonitor->VerifyFound(); |
| 4565 | } |
| 4566 | |
| 4567 | vkQueueWaitIdle(queue); |
| 4568 | |
| 4569 | vkDestroyEvent(m_device->device(), event, nullptr); |
| 4570 | vkFreeCommandBuffers(m_device->device(), command_pool, 1, &command_buffer); |
| 4571 | vkDestroyCommandPool(m_device->device(), command_pool, NULL); |
| 4572 | } |
| 4573 | |
| 4574 | // This is a positive test. No errors should be generated. |
Tobin Ehlis | 0bb263b | 2016-05-10 12:13:02 -0600 | [diff] [blame] | 4575 | TEST_F(VkLayerTest, TwoFencesThreeFrames) { |
| 4576 | TEST_DESCRIPTION("Two command buffers with two separate fences are each " |
| 4577 | "run through a Submit & WaitForFences cycle 3 times. This " |
| 4578 | "previously revealed a bug so running this positive test " |
| 4579 | "to prevent a regression."); |
| 4580 | m_errorMonitor->ExpectSuccess(); |
| 4581 | |
| 4582 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 4583 | VkQueue queue = VK_NULL_HANDLE; |
| 4584 | vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, |
| 4585 | 0, &queue); |
| 4586 | |
| 4587 | static const uint32_t NUM_OBJECTS = 2; |
| 4588 | static const uint32_t NUM_FRAMES = 3; |
| 4589 | VkCommandBuffer cmd_buffers[NUM_OBJECTS] = {}; |
| 4590 | VkFence fences[NUM_OBJECTS] = {}; |
| 4591 | |
| 4592 | VkCommandPool cmd_pool; |
| 4593 | VkCommandPoolCreateInfo cmd_pool_ci = {}; |
| 4594 | cmd_pool_ci.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO; |
| 4595 | cmd_pool_ci.queueFamilyIndex = m_device->graphics_queue_node_index_; |
| 4596 | cmd_pool_ci.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT; |
| 4597 | VkResult err = vkCreateCommandPool(m_device->device(), &cmd_pool_ci, |
| 4598 | nullptr, &cmd_pool); |
| 4599 | ASSERT_VK_SUCCESS(err); |
| 4600 | |
| 4601 | VkCommandBufferAllocateInfo cmd_buf_info = {}; |
| 4602 | cmd_buf_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO; |
| 4603 | cmd_buf_info.commandPool = cmd_pool; |
| 4604 | cmd_buf_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY; |
| 4605 | cmd_buf_info.commandBufferCount = 1; |
| 4606 | |
| 4607 | VkFenceCreateInfo fence_ci = {}; |
| 4608 | fence_ci.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO; |
| 4609 | fence_ci.pNext = nullptr; |
| 4610 | fence_ci.flags = 0; |
| 4611 | |
| 4612 | for (uint32_t i = 0; i < NUM_OBJECTS; ++i) { |
| 4613 | err = vkAllocateCommandBuffers(m_device->device(), &cmd_buf_info, |
| 4614 | &cmd_buffers[i]); |
| 4615 | ASSERT_VK_SUCCESS(err); |
| 4616 | err = vkCreateFence(m_device->device(), &fence_ci, nullptr, &fences[i]); |
| 4617 | ASSERT_VK_SUCCESS(err); |
| 4618 | } |
| 4619 | |
| 4620 | for (uint32_t frame = 0; frame < NUM_FRAMES; ++frame) { |
Tobin Ehlis | f902516 | 2016-05-26 06:55:21 -0600 | [diff] [blame] | 4621 | for (uint32_t obj = 0; obj < NUM_OBJECTS; ++obj) { |
| 4622 | // Create empty cmd buffer |
| 4623 | VkCommandBufferBeginInfo cmdBufBeginDesc = {}; |
| 4624 | cmdBufBeginDesc.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO; |
Tobin Ehlis | 0bb263b | 2016-05-10 12:13:02 -0600 | [diff] [blame] | 4625 | |
Tobin Ehlis | f902516 | 2016-05-26 06:55:21 -0600 | [diff] [blame] | 4626 | err = vkBeginCommandBuffer(cmd_buffers[obj], &cmdBufBeginDesc); |
| 4627 | ASSERT_VK_SUCCESS(err); |
| 4628 | err = vkEndCommandBuffer(cmd_buffers[obj]); |
| 4629 | ASSERT_VK_SUCCESS(err); |
Tobin Ehlis | 0bb263b | 2016-05-10 12:13:02 -0600 | [diff] [blame] | 4630 | |
Tobin Ehlis | f902516 | 2016-05-26 06:55:21 -0600 | [diff] [blame] | 4631 | VkSubmitInfo submit_info = {}; |
| 4632 | submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO; |
| 4633 | submit_info.commandBufferCount = 1; |
| 4634 | submit_info.pCommandBuffers = &cmd_buffers[obj]; |
| 4635 | // Submit cmd buffer and wait for fence |
| 4636 | err = vkQueueSubmit(queue, 1, &submit_info, fences[obj]); |
| 4637 | ASSERT_VK_SUCCESS(err); |
| 4638 | err = vkWaitForFences(m_device->device(), 1, &fences[obj], VK_TRUE, |
| 4639 | UINT64_MAX); |
| 4640 | ASSERT_VK_SUCCESS(err); |
| 4641 | err = vkResetFences(m_device->device(), 1, &fences[obj]); |
| 4642 | ASSERT_VK_SUCCESS(err); |
| 4643 | } |
Tobin Ehlis | 0bb263b | 2016-05-10 12:13:02 -0600 | [diff] [blame] | 4644 | } |
| 4645 | m_errorMonitor->VerifyNotFound(); |
Tony Barbour | df4c004 | 2016-06-01 15:55:43 -0600 | [diff] [blame] | 4646 | vkDestroyCommandPool(m_device->device(), cmd_pool, NULL); |
| 4647 | for (uint32_t i = 0; i < NUM_OBJECTS; ++i) { |
| 4648 | vkDestroyFence(m_device->device(), fences[i], nullptr); |
| 4649 | } |
Tobin Ehlis | 0bb263b | 2016-05-10 12:13:02 -0600 | [diff] [blame] | 4650 | } |
| 4651 | // This is a positive test. No errors should be generated. |
Mark Lobodzinski | c808d44 | 2016-04-14 10:57:23 -0600 | [diff] [blame] | 4652 | TEST_F(VkLayerTest, TwoQueueSubmitsSeparateQueuesWithSemaphoreAndOneFenceQWI) { |
| 4653 | |
| 4654 | TEST_DESCRIPTION("Two command buffers, each in a separate QueueSubmit call " |
| 4655 | "submitted on separate queues followed by a QueueWaitIdle."); |
| 4656 | |
Dustin Graves | 4845814 | 2016-04-29 16:11:55 -0600 | [diff] [blame] | 4657 | if ((m_device->queue_props.empty()) || |
| 4658 | (m_device->queue_props[0].queueCount < 2)) |
Tony Barbour | dc18b26 | 2016-04-22 14:49:48 -0600 | [diff] [blame] | 4659 | return; |
| 4660 | |
Mark Lobodzinski | c808d44 | 2016-04-14 10:57:23 -0600 | [diff] [blame] | 4661 | m_errorMonitor->ExpectSuccess(); |
| 4662 | |
| 4663 | VkSemaphore semaphore; |
| 4664 | VkSemaphoreCreateInfo semaphore_create_info{}; |
| 4665 | semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO; |
| 4666 | vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, |
| 4667 | &semaphore); |
| 4668 | |
| 4669 | VkCommandPool command_pool; |
| 4670 | VkCommandPoolCreateInfo pool_create_info{}; |
| 4671 | pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO; |
| 4672 | pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_; |
| 4673 | pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT; |
| 4674 | vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, |
| 4675 | &command_pool); |
| 4676 | |
| 4677 | VkCommandBuffer command_buffer[2]; |
| 4678 | VkCommandBufferAllocateInfo command_buffer_allocate_info{}; |
| 4679 | command_buffer_allocate_info.sType = |
| 4680 | VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO; |
| 4681 | command_buffer_allocate_info.commandPool = command_pool; |
| 4682 | command_buffer_allocate_info.commandBufferCount = 2; |
| 4683 | command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY; |
| 4684 | vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, |
| 4685 | command_buffer); |
| 4686 | |
| 4687 | VkQueue queue = VK_NULL_HANDLE; |
| 4688 | vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, |
| 4689 | 1, &queue); |
| 4690 | |
| 4691 | { |
| 4692 | VkCommandBufferBeginInfo begin_info{}; |
| 4693 | begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO; |
| 4694 | vkBeginCommandBuffer(command_buffer[0], &begin_info); |
| 4695 | |
| 4696 | vkCmdPipelineBarrier(command_buffer[0], |
| 4697 | VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, |
| 4698 | VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, nullptr, |
| 4699 | 0, nullptr, 0, nullptr); |
| 4700 | |
| 4701 | VkViewport viewport{}; |
| 4702 | viewport.maxDepth = 1.0f; |
| 4703 | viewport.minDepth = 0.0f; |
| 4704 | viewport.width = 512; |
| 4705 | viewport.height = 512; |
| 4706 | viewport.x = 0; |
| 4707 | viewport.y = 0; |
| 4708 | vkCmdSetViewport(command_buffer[0], 0, 1, &viewport); |
| 4709 | vkEndCommandBuffer(command_buffer[0]); |
| 4710 | } |
| 4711 | { |
| 4712 | VkCommandBufferBeginInfo begin_info{}; |
| 4713 | begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO; |
| 4714 | vkBeginCommandBuffer(command_buffer[1], &begin_info); |
| 4715 | |
| 4716 | VkViewport viewport{}; |
| 4717 | viewport.maxDepth = 1.0f; |
| 4718 | viewport.minDepth = 0.0f; |
| 4719 | viewport.width = 512; |
| 4720 | viewport.height = 512; |
| 4721 | viewport.x = 0; |
| 4722 | viewport.y = 0; |
| 4723 | vkCmdSetViewport(command_buffer[1], 0, 1, &viewport); |
| 4724 | vkEndCommandBuffer(command_buffer[1]); |
| 4725 | } |
| 4726 | { |
| 4727 | VkSubmitInfo submit_info{}; |
| 4728 | submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO; |
| 4729 | submit_info.commandBufferCount = 1; |
| 4730 | submit_info.pCommandBuffers = &command_buffer[0]; |
| 4731 | submit_info.signalSemaphoreCount = 1; |
| 4732 | submit_info.pSignalSemaphores = &semaphore; |
| 4733 | vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE); |
| 4734 | } |
| 4735 | { |
| 4736 | VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT}; |
| 4737 | VkSubmitInfo submit_info{}; |
| 4738 | submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO; |
| 4739 | submit_info.commandBufferCount = 1; |
| 4740 | submit_info.pCommandBuffers = &command_buffer[1]; |
| 4741 | submit_info.waitSemaphoreCount = 1; |
| 4742 | submit_info.pWaitSemaphores = &semaphore; |
| 4743 | submit_info.pWaitDstStageMask = flags; |
| 4744 | vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE); |
| 4745 | } |
| 4746 | |
| 4747 | vkQueueWaitIdle(m_device->m_queue); |
| 4748 | |
| 4749 | vkDestroySemaphore(m_device->device(), semaphore, nullptr); |
| 4750 | vkFreeCommandBuffers(m_device->device(), command_pool, 2, |
| 4751 | &command_buffer[0]); |
| 4752 | vkDestroyCommandPool(m_device->device(), command_pool, NULL); |
| 4753 | |
| 4754 | m_errorMonitor->VerifyNotFound(); |
| 4755 | } |
| 4756 | |
| 4757 | // This is a positive test. No errors should be generated. |
| 4758 | TEST_F(VkLayerTest, TwoQueueSubmitsSeparateQueuesWithSemaphoreAndOneFenceQWIFence) { |
| 4759 | |
| 4760 | TEST_DESCRIPTION("Two command buffers, each in a separate QueueSubmit call " |
| 4761 | "submitted on separate queues, the second having a fence" |
| 4762 | "followed by a QueueWaitIdle."); |
| 4763 | |
Dustin Graves | 4845814 | 2016-04-29 16:11:55 -0600 | [diff] [blame] | 4764 | if ((m_device->queue_props.empty()) || |
| 4765 | (m_device->queue_props[0].queueCount < 2)) |
Tony Barbour | dc18b26 | 2016-04-22 14:49:48 -0600 | [diff] [blame] | 4766 | return; |
| 4767 | |
Mark Lobodzinski | c808d44 | 2016-04-14 10:57:23 -0600 | [diff] [blame] | 4768 | m_errorMonitor->ExpectSuccess(); |
| 4769 | |
| 4770 | VkFence fence; |
| 4771 | VkFenceCreateInfo fence_create_info{}; |
| 4772 | fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO; |
| 4773 | vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence); |
| 4774 | |
| 4775 | VkSemaphore semaphore; |
| 4776 | VkSemaphoreCreateInfo semaphore_create_info{}; |
| 4777 | semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO; |
| 4778 | vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, |
| 4779 | &semaphore); |
| 4780 | |
| 4781 | VkCommandPool command_pool; |
| 4782 | VkCommandPoolCreateInfo pool_create_info{}; |
| 4783 | pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO; |
| 4784 | pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_; |
| 4785 | pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT; |
| 4786 | vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, |
| 4787 | &command_pool); |
| 4788 | |
| 4789 | VkCommandBuffer command_buffer[2]; |
| 4790 | VkCommandBufferAllocateInfo command_buffer_allocate_info{}; |
| 4791 | command_buffer_allocate_info.sType = |
| 4792 | VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO; |
| 4793 | command_buffer_allocate_info.commandPool = command_pool; |
| 4794 | command_buffer_allocate_info.commandBufferCount = 2; |
| 4795 | command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY; |
| 4796 | vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, |
| 4797 | command_buffer); |
| 4798 | |
| 4799 | VkQueue queue = VK_NULL_HANDLE; |
| 4800 | vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, |
| 4801 | 1, &queue); |
| 4802 | |
| 4803 | { |
| 4804 | VkCommandBufferBeginInfo begin_info{}; |
| 4805 | begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO; |
| 4806 | vkBeginCommandBuffer(command_buffer[0], &begin_info); |
| 4807 | |
| 4808 | vkCmdPipelineBarrier(command_buffer[0], |
| 4809 | VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, |
| 4810 | VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, nullptr, |
| 4811 | 0, nullptr, 0, nullptr); |
| 4812 | |
| 4813 | VkViewport viewport{}; |
| 4814 | viewport.maxDepth = 1.0f; |
| 4815 | viewport.minDepth = 0.0f; |
| 4816 | viewport.width = 512; |
| 4817 | viewport.height = 512; |
| 4818 | viewport.x = 0; |
| 4819 | viewport.y = 0; |
| 4820 | vkCmdSetViewport(command_buffer[0], 0, 1, &viewport); |
| 4821 | vkEndCommandBuffer(command_buffer[0]); |
| 4822 | } |
| 4823 | { |
| 4824 | VkCommandBufferBeginInfo begin_info{}; |
| 4825 | begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO; |
| 4826 | vkBeginCommandBuffer(command_buffer[1], &begin_info); |
| 4827 | |
| 4828 | VkViewport viewport{}; |
| 4829 | viewport.maxDepth = 1.0f; |
| 4830 | viewport.minDepth = 0.0f; |
| 4831 | viewport.width = 512; |
| 4832 | viewport.height = 512; |
| 4833 | viewport.x = 0; |
| 4834 | viewport.y = 0; |
| 4835 | vkCmdSetViewport(command_buffer[1], 0, 1, &viewport); |
| 4836 | vkEndCommandBuffer(command_buffer[1]); |
| 4837 | } |
| 4838 | { |
| 4839 | VkSubmitInfo submit_info{}; |
| 4840 | submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO; |
| 4841 | submit_info.commandBufferCount = 1; |
| 4842 | submit_info.pCommandBuffers = &command_buffer[0]; |
| 4843 | submit_info.signalSemaphoreCount = 1; |
| 4844 | submit_info.pSignalSemaphores = &semaphore; |
| 4845 | vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE); |
| 4846 | } |
| 4847 | { |
| 4848 | VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT}; |
| 4849 | VkSubmitInfo submit_info{}; |
| 4850 | submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO; |
| 4851 | submit_info.commandBufferCount = 1; |
| 4852 | submit_info.pCommandBuffers = &command_buffer[1]; |
| 4853 | submit_info.waitSemaphoreCount = 1; |
| 4854 | submit_info.pWaitSemaphores = &semaphore; |
| 4855 | submit_info.pWaitDstStageMask = flags; |
| 4856 | vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence); |
| 4857 | } |
| 4858 | |
| 4859 | vkQueueWaitIdle(m_device->m_queue); |
| 4860 | |
| 4861 | vkDestroyFence(m_device->device(), fence, nullptr); |
| 4862 | vkDestroySemaphore(m_device->device(), semaphore, nullptr); |
| 4863 | vkFreeCommandBuffers(m_device->device(), command_pool, 2, |
| 4864 | &command_buffer[0]); |
| 4865 | vkDestroyCommandPool(m_device->device(), command_pool, NULL); |
| 4866 | |
| 4867 | m_errorMonitor->VerifyNotFound(); |
| 4868 | } |
| 4869 | |
| 4870 | // This is a positive test. No errors should be generated. |
| 4871 | TEST_F(VkLayerTest, |
| 4872 | TwoQueueSubmitsSeparateQueuesWithSemaphoreAndOneFenceTwoWFF) { |
| 4873 | |
| 4874 | TEST_DESCRIPTION( |
| 4875 | "Two command buffers, each in a separate QueueSubmit call " |
| 4876 | "submitted on separate queues, the second having a fence" |
| 4877 | "followed by two consecutive WaitForFences calls on the same fence."); |
| 4878 | |
Dustin Graves | 4845814 | 2016-04-29 16:11:55 -0600 | [diff] [blame] | 4879 | if ((m_device->queue_props.empty()) || |
| 4880 | (m_device->queue_props[0].queueCount < 2)) |
Tony Barbour | dc18b26 | 2016-04-22 14:49:48 -0600 | [diff] [blame] | 4881 | return; |
| 4882 | |
Mark Lobodzinski | c808d44 | 2016-04-14 10:57:23 -0600 | [diff] [blame] | 4883 | m_errorMonitor->ExpectSuccess(); |
| 4884 | |
| 4885 | VkFence fence; |
| 4886 | VkFenceCreateInfo fence_create_info{}; |
| 4887 | fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO; |
| 4888 | vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence); |
| 4889 | |
| 4890 | VkSemaphore semaphore; |
| 4891 | VkSemaphoreCreateInfo semaphore_create_info{}; |
| 4892 | semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO; |
| 4893 | vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, |
| 4894 | &semaphore); |
| 4895 | |
| 4896 | VkCommandPool command_pool; |
| 4897 | VkCommandPoolCreateInfo pool_create_info{}; |
| 4898 | pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO; |
| 4899 | pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_; |
| 4900 | pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT; |
| 4901 | vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, |
| 4902 | &command_pool); |
| 4903 | |
| 4904 | VkCommandBuffer command_buffer[2]; |
| 4905 | VkCommandBufferAllocateInfo command_buffer_allocate_info{}; |
| 4906 | command_buffer_allocate_info.sType = |
| 4907 | VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO; |
| 4908 | command_buffer_allocate_info.commandPool = command_pool; |
| 4909 | command_buffer_allocate_info.commandBufferCount = 2; |
| 4910 | command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY; |
| 4911 | vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, |
| 4912 | command_buffer); |
| 4913 | |
| 4914 | VkQueue queue = VK_NULL_HANDLE; |
| 4915 | vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, |
| 4916 | 1, &queue); |
| 4917 | |
| 4918 | { |
| 4919 | VkCommandBufferBeginInfo begin_info{}; |
| 4920 | begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO; |
| 4921 | vkBeginCommandBuffer(command_buffer[0], &begin_info); |
| 4922 | |
| 4923 | vkCmdPipelineBarrier(command_buffer[0], |
| 4924 | VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, |
| 4925 | VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, nullptr, |
| 4926 | 0, nullptr, 0, nullptr); |
| 4927 | |
| 4928 | VkViewport viewport{}; |
| 4929 | viewport.maxDepth = 1.0f; |
| 4930 | viewport.minDepth = 0.0f; |
| 4931 | viewport.width = 512; |
| 4932 | viewport.height = 512; |
| 4933 | viewport.x = 0; |
| 4934 | viewport.y = 0; |
| 4935 | vkCmdSetViewport(command_buffer[0], 0, 1, &viewport); |
| 4936 | vkEndCommandBuffer(command_buffer[0]); |
| 4937 | } |
| 4938 | { |
| 4939 | VkCommandBufferBeginInfo begin_info{}; |
| 4940 | begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO; |
| 4941 | vkBeginCommandBuffer(command_buffer[1], &begin_info); |
| 4942 | |
| 4943 | VkViewport viewport{}; |
| 4944 | viewport.maxDepth = 1.0f; |
| 4945 | viewport.minDepth = 0.0f; |
| 4946 | viewport.width = 512; |
| 4947 | viewport.height = 512; |
| 4948 | viewport.x = 0; |
| 4949 | viewport.y = 0; |
| 4950 | vkCmdSetViewport(command_buffer[1], 0, 1, &viewport); |
| 4951 | vkEndCommandBuffer(command_buffer[1]); |
| 4952 | } |
| 4953 | { |
| 4954 | VkSubmitInfo submit_info{}; |
| 4955 | submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO; |
| 4956 | submit_info.commandBufferCount = 1; |
| 4957 | submit_info.pCommandBuffers = &command_buffer[0]; |
| 4958 | submit_info.signalSemaphoreCount = 1; |
| 4959 | submit_info.pSignalSemaphores = &semaphore; |
| 4960 | vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE); |
| 4961 | } |
| 4962 | { |
| 4963 | VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT}; |
| 4964 | VkSubmitInfo submit_info{}; |
| 4965 | submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO; |
| 4966 | submit_info.commandBufferCount = 1; |
| 4967 | submit_info.pCommandBuffers = &command_buffer[1]; |
| 4968 | submit_info.waitSemaphoreCount = 1; |
| 4969 | submit_info.pWaitSemaphores = &semaphore; |
| 4970 | submit_info.pWaitDstStageMask = flags; |
| 4971 | vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence); |
| 4972 | } |
| 4973 | |
| 4974 | vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX); |
| 4975 | vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX); |
| 4976 | |
| 4977 | vkDestroyFence(m_device->device(), fence, nullptr); |
| 4978 | vkDestroySemaphore(m_device->device(), semaphore, nullptr); |
| 4979 | vkFreeCommandBuffers(m_device->device(), command_pool, 2, |
| 4980 | &command_buffer[0]); |
| 4981 | vkDestroyCommandPool(m_device->device(), command_pool, NULL); |
| 4982 | |
| 4983 | m_errorMonitor->VerifyNotFound(); |
| 4984 | } |
| 4985 | |
Chris Forbes | 0f8126b | 2016-06-20 17:48:22 +1200 | [diff] [blame] | 4986 | #if 0 |
| 4987 | TEST_F(VkLayerTest, TwoQueuesEnsureCorrectRetirementWithWorkStolen) { |
| 4988 | if ((m_device->queue_props.empty()) || |
| 4989 | (m_device->queue_props[0].queueCount < 2)) { |
| 4990 | printf("Test requires two queues, skipping\n"); |
| 4991 | return; |
| 4992 | } |
| 4993 | |
| 4994 | VkResult err; |
| 4995 | |
| 4996 | m_errorMonitor->ExpectSuccess(); |
| 4997 | |
| 4998 | VkQueue q0 = m_device->m_queue; |
| 4999 | VkQueue q1 = nullptr; |
| 5000 | vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &q1); |
| 5001 | ASSERT_NE(q1, nullptr); |
| 5002 | |
| 5003 | // An (empty) command buffer. We must have work in the first submission -- |
| 5004 | // the layer treats unfenced work differently from fenced work. |
| 5005 | VkCommandPoolCreateInfo cpci = { VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO, nullptr, 0, 0 }; |
| 5006 | VkCommandPool pool; |
| 5007 | err = vkCreateCommandPool(m_device->device(), &cpci, nullptr, &pool); |
| 5008 | ASSERT_VK_SUCCESS(err); |
| 5009 | VkCommandBufferAllocateInfo cbai = { VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO, nullptr, |
| 5010 | pool, VK_COMMAND_BUFFER_LEVEL_PRIMARY, 1 |
| 5011 | }; |
| 5012 | VkCommandBuffer cb; |
| 5013 | err = vkAllocateCommandBuffers(m_device->device(), &cbai, &cb); |
| 5014 | ASSERT_VK_SUCCESS(err); |
| 5015 | VkCommandBufferBeginInfo cbbi = { VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO, nullptr, |
| 5016 | 0, nullptr |
| 5017 | }; |
| 5018 | err = vkBeginCommandBuffer(cb, &cbbi); |
| 5019 | ASSERT_VK_SUCCESS(err); |
| 5020 | err = vkEndCommandBuffer(cb); |
| 5021 | ASSERT_VK_SUCCESS(err); |
| 5022 | |
| 5023 | // A semaphore |
| 5024 | VkSemaphoreCreateInfo sci = { VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO, nullptr, 0 }; |
| 5025 | VkSemaphore s; |
| 5026 | err = vkCreateSemaphore(m_device->device(), &sci, nullptr, &s); |
| 5027 | ASSERT_VK_SUCCESS(err); |
| 5028 | |
| 5029 | // First submission, to q0 |
| 5030 | VkSubmitInfo s0 = { |
| 5031 | VK_STRUCTURE_TYPE_SUBMIT_INFO, nullptr, |
| 5032 | 0, nullptr, nullptr, |
| 5033 | 1, &cb, |
| 5034 | 1, &s |
| 5035 | }; |
| 5036 | |
| 5037 | err = vkQueueSubmit(q0, 1, &s0, VK_NULL_HANDLE); |
| 5038 | ASSERT_VK_SUCCESS(err); |
| 5039 | |
| 5040 | // Second submission, to q1, waiting on s |
| 5041 | VkFlags waitmask = VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT; // doesn't really matter what this value is. |
| 5042 | VkSubmitInfo s1 = { |
| 5043 | VK_STRUCTURE_TYPE_SUBMIT_INFO, nullptr, |
| 5044 | 1, &s, &waitmask, |
| 5045 | 0, nullptr, |
| 5046 | 0, nullptr |
| 5047 | }; |
| 5048 | |
| 5049 | err = vkQueueSubmit(q1, 1, &s1, VK_NULL_HANDLE); |
| 5050 | ASSERT_VK_SUCCESS(err); |
| 5051 | |
| 5052 | // Wait for q0 idle |
| 5053 | err = vkQueueWaitIdle(q0); |
| 5054 | ASSERT_VK_SUCCESS(err); |
| 5055 | |
| 5056 | // Command buffer should have been completed (it was on q0); reset the pool. |
| 5057 | vkFreeCommandBuffers(m_device->device(), pool, 1, &cb); |
| 5058 | |
| 5059 | m_errorMonitor->VerifyNotFound(); |
| 5060 | |
| 5061 | // Force device completely idle and clean up resources |
| 5062 | vkDeviceWaitIdle(m_device->device()); |
| 5063 | vkDestroyCommandPool(m_device->device(), pool, nullptr); |
| 5064 | vkDestroySemaphore(m_device->device(), s, nullptr); |
| 5065 | } |
| 5066 | #endif |
| 5067 | |
Mark Lobodzinski | c808d44 | 2016-04-14 10:57:23 -0600 | [diff] [blame] | 5068 | // This is a positive test. No errors should be generated. |
| 5069 | TEST_F(VkLayerTest, TwoQueueSubmitsSeparateQueuesWithSemaphoreAndOneFence) { |
| 5070 | |
| 5071 | TEST_DESCRIPTION("Two command buffers, each in a separate QueueSubmit call " |
| 5072 | "submitted on separate queues, the second having a fence, " |
| 5073 | "followed by a WaitForFences call."); |
| 5074 | |
Dustin Graves | 4845814 | 2016-04-29 16:11:55 -0600 | [diff] [blame] | 5075 | if ((m_device->queue_props.empty()) || |
| 5076 | (m_device->queue_props[0].queueCount < 2)) |
Tony Barbour | dc18b26 | 2016-04-22 14:49:48 -0600 | [diff] [blame] | 5077 | return; |
| 5078 | |
Mark Lobodzinski | c808d44 | 2016-04-14 10:57:23 -0600 | [diff] [blame] | 5079 | m_errorMonitor->ExpectSuccess(); |
| 5080 | |
| 5081 | VkFence fence; |
| 5082 | VkFenceCreateInfo fence_create_info{}; |
| 5083 | fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO; |
| 5084 | vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence); |
| 5085 | |
| 5086 | VkSemaphore semaphore; |
| 5087 | VkSemaphoreCreateInfo semaphore_create_info{}; |
| 5088 | semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO; |
| 5089 | vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, |
| 5090 | &semaphore); |
| 5091 | |
| 5092 | VkCommandPool command_pool; |
| 5093 | VkCommandPoolCreateInfo pool_create_info{}; |
| 5094 | pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO; |
| 5095 | pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_; |
| 5096 | pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT; |
| 5097 | vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, |
| 5098 | &command_pool); |
| 5099 | |
| 5100 | VkCommandBuffer command_buffer[2]; |
| 5101 | VkCommandBufferAllocateInfo command_buffer_allocate_info{}; |
| 5102 | command_buffer_allocate_info.sType = |
| 5103 | VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO; |
| 5104 | command_buffer_allocate_info.commandPool = command_pool; |
| 5105 | command_buffer_allocate_info.commandBufferCount = 2; |
| 5106 | command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY; |
| 5107 | vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, |
| 5108 | command_buffer); |
| 5109 | |
| 5110 | VkQueue queue = VK_NULL_HANDLE; |
| 5111 | vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, |
| 5112 | 1, &queue); |
| 5113 | |
| 5114 | |
| 5115 | { |
| 5116 | VkCommandBufferBeginInfo begin_info{}; |
| 5117 | begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO; |
| 5118 | vkBeginCommandBuffer(command_buffer[0], &begin_info); |
| 5119 | |
| 5120 | vkCmdPipelineBarrier(command_buffer[0], |
| 5121 | VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, |
| 5122 | VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, nullptr, |
| 5123 | 0, nullptr, 0, nullptr); |
| 5124 | |
| 5125 | VkViewport viewport{}; |
| 5126 | viewport.maxDepth = 1.0f; |
| 5127 | viewport.minDepth = 0.0f; |
| 5128 | viewport.width = 512; |
| 5129 | viewport.height = 512; |
| 5130 | viewport.x = 0; |
| 5131 | viewport.y = 0; |
| 5132 | vkCmdSetViewport(command_buffer[0], 0, 1, &viewport); |
| 5133 | vkEndCommandBuffer(command_buffer[0]); |
| 5134 | } |
| 5135 | { |
| 5136 | VkCommandBufferBeginInfo begin_info{}; |
| 5137 | begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO; |
| 5138 | vkBeginCommandBuffer(command_buffer[1], &begin_info); |
| 5139 | |
| 5140 | VkViewport viewport{}; |
| 5141 | viewport.maxDepth = 1.0f; |
| 5142 | viewport.minDepth = 0.0f; |
| 5143 | viewport.width = 512; |
| 5144 | viewport.height = 512; |
| 5145 | viewport.x = 0; |
| 5146 | viewport.y = 0; |
| 5147 | vkCmdSetViewport(command_buffer[1], 0, 1, &viewport); |
| 5148 | vkEndCommandBuffer(command_buffer[1]); |
| 5149 | } |
| 5150 | { |
| 5151 | VkSubmitInfo submit_info{}; |
| 5152 | submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO; |
| 5153 | submit_info.commandBufferCount = 1; |
| 5154 | submit_info.pCommandBuffers = &command_buffer[0]; |
| 5155 | submit_info.signalSemaphoreCount = 1; |
| 5156 | submit_info.pSignalSemaphores = &semaphore; |
| 5157 | vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE); |
| 5158 | } |
| 5159 | { |
| 5160 | VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT}; |
| 5161 | VkSubmitInfo submit_info{}; |
| 5162 | submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO; |
| 5163 | submit_info.commandBufferCount = 1; |
| 5164 | submit_info.pCommandBuffers = &command_buffer[1]; |
| 5165 | submit_info.waitSemaphoreCount = 1; |
| 5166 | submit_info.pWaitSemaphores = &semaphore; |
| 5167 | submit_info.pWaitDstStageMask = flags; |
| 5168 | vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence); |
| 5169 | } |
| 5170 | |
| 5171 | vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX); |
| 5172 | |
| 5173 | vkDestroyFence(m_device->device(), fence, nullptr); |
| 5174 | vkDestroySemaphore(m_device->device(), semaphore, nullptr); |
| 5175 | vkFreeCommandBuffers(m_device->device(), command_pool, 2, |
| 5176 | &command_buffer[0]); |
| 5177 | vkDestroyCommandPool(m_device->device(), command_pool, NULL); |
| 5178 | |
| 5179 | m_errorMonitor->VerifyNotFound(); |
| 5180 | } |
| 5181 | |
| 5182 | // This is a positive test. No errors should be generated. |
| 5183 | TEST_F(VkLayerTest, TwoQueueSubmitsOneQueueWithSemaphoreAndOneFence) { |
| 5184 | |
| 5185 | TEST_DESCRIPTION("Two command buffers, each in a separate QueueSubmit call " |
| 5186 | "on the same queue, sharing a signal/wait semaphore, the " |
| 5187 | "second having a fence, " |
| 5188 | "followed by a WaitForFences call."); |
| 5189 | |
| 5190 | m_errorMonitor->ExpectSuccess(); |
| 5191 | |
| 5192 | VkFence fence; |
| 5193 | VkFenceCreateInfo fence_create_info{}; |
| 5194 | fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO; |
| 5195 | vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence); |
| 5196 | |
| 5197 | VkSemaphore semaphore; |
| 5198 | VkSemaphoreCreateInfo semaphore_create_info{}; |
| 5199 | semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO; |
| 5200 | vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, |
| 5201 | &semaphore); |
| 5202 | |
| 5203 | VkCommandPool command_pool; |
| 5204 | VkCommandPoolCreateInfo pool_create_info{}; |
| 5205 | pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO; |
| 5206 | pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_; |
| 5207 | pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT; |
| 5208 | vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, |
| 5209 | &command_pool); |
| 5210 | |
| 5211 | VkCommandBuffer command_buffer[2]; |
| 5212 | VkCommandBufferAllocateInfo command_buffer_allocate_info{}; |
| 5213 | command_buffer_allocate_info.sType = |
| 5214 | VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO; |
| 5215 | command_buffer_allocate_info.commandPool = command_pool; |
| 5216 | command_buffer_allocate_info.commandBufferCount = 2; |
| 5217 | command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY; |
| 5218 | vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, |
| 5219 | command_buffer); |
| 5220 | |
| 5221 | { |
| 5222 | VkCommandBufferBeginInfo begin_info{}; |
| 5223 | begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO; |
| 5224 | vkBeginCommandBuffer(command_buffer[0], &begin_info); |
| 5225 | |
| 5226 | vkCmdPipelineBarrier(command_buffer[0], |
| 5227 | VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, |
| 5228 | VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, nullptr, |
| 5229 | 0, nullptr, 0, nullptr); |
| 5230 | |
| 5231 | VkViewport viewport{}; |
| 5232 | viewport.maxDepth = 1.0f; |
| 5233 | viewport.minDepth = 0.0f; |
| 5234 | viewport.width = 512; |
| 5235 | viewport.height = 512; |
| 5236 | viewport.x = 0; |
| 5237 | viewport.y = 0; |
| 5238 | vkCmdSetViewport(command_buffer[0], 0, 1, &viewport); |
| 5239 | vkEndCommandBuffer(command_buffer[0]); |
| 5240 | } |
| 5241 | { |
| 5242 | VkCommandBufferBeginInfo begin_info{}; |
| 5243 | begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO; |
| 5244 | vkBeginCommandBuffer(command_buffer[1], &begin_info); |
| 5245 | |
| 5246 | VkViewport viewport{}; |
| 5247 | viewport.maxDepth = 1.0f; |
| 5248 | viewport.minDepth = 0.0f; |
| 5249 | viewport.width = 512; |
| 5250 | viewport.height = 512; |
| 5251 | viewport.x = 0; |
| 5252 | viewport.y = 0; |
| 5253 | vkCmdSetViewport(command_buffer[1], 0, 1, &viewport); |
| 5254 | vkEndCommandBuffer(command_buffer[1]); |
| 5255 | } |
| 5256 | { |
| 5257 | VkSubmitInfo submit_info{}; |
| 5258 | submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO; |
| 5259 | submit_info.commandBufferCount = 1; |
| 5260 | submit_info.pCommandBuffers = &command_buffer[0]; |
| 5261 | submit_info.signalSemaphoreCount = 1; |
| 5262 | submit_info.pSignalSemaphores = &semaphore; |
| 5263 | vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE); |
| 5264 | } |
| 5265 | { |
| 5266 | VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT}; |
| 5267 | VkSubmitInfo submit_info{}; |
| 5268 | submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO; |
| 5269 | submit_info.commandBufferCount = 1; |
| 5270 | submit_info.pCommandBuffers = &command_buffer[1]; |
| 5271 | submit_info.waitSemaphoreCount = 1; |
| 5272 | submit_info.pWaitSemaphores = &semaphore; |
| 5273 | submit_info.pWaitDstStageMask = flags; |
| 5274 | vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence); |
| 5275 | } |
| 5276 | |
| 5277 | vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX); |
| 5278 | |
| 5279 | vkDestroyFence(m_device->device(), fence, nullptr); |
| 5280 | vkDestroySemaphore(m_device->device(), semaphore, nullptr); |
| 5281 | vkFreeCommandBuffers(m_device->device(), command_pool, 2, |
| 5282 | &command_buffer[0]); |
| 5283 | vkDestroyCommandPool(m_device->device(), command_pool, NULL); |
| 5284 | |
| 5285 | m_errorMonitor->VerifyNotFound(); |
| 5286 | } |
| 5287 | |
| 5288 | // This is a positive test. No errors should be generated. |
| 5289 | TEST_F(VkLayerTest, TwoQueueSubmitsOneQueueNullQueueSubmitWithFence) { |
| 5290 | |
| 5291 | TEST_DESCRIPTION( |
| 5292 | "Two command buffers, each in a separate QueueSubmit call " |
| 5293 | "on the same queue, no fences, followed by a third QueueSubmit with NO " |
| 5294 | "SubmitInfos but with a fence, followed by a WaitForFences call."); |
| 5295 | |
| 5296 | m_errorMonitor->ExpectSuccess(); |
| 5297 | |
| 5298 | VkFence fence; |
| 5299 | VkFenceCreateInfo fence_create_info{}; |
| 5300 | fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO; |
| 5301 | vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence); |
| 5302 | |
| 5303 | VkCommandPool command_pool; |
| 5304 | VkCommandPoolCreateInfo pool_create_info{}; |
| 5305 | pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO; |
| 5306 | pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_; |
| 5307 | pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT; |
| 5308 | vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, |
| 5309 | &command_pool); |
| 5310 | |
| 5311 | VkCommandBuffer command_buffer[2]; |
| 5312 | VkCommandBufferAllocateInfo command_buffer_allocate_info{}; |
| 5313 | command_buffer_allocate_info.sType = |
| 5314 | VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO; |
| 5315 | command_buffer_allocate_info.commandPool = command_pool; |
| 5316 | command_buffer_allocate_info.commandBufferCount = 2; |
| 5317 | command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY; |
| 5318 | vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, |
| 5319 | command_buffer); |
| 5320 | |
| 5321 | { |
| 5322 | VkCommandBufferBeginInfo begin_info{}; |
| 5323 | begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO; |
| 5324 | vkBeginCommandBuffer(command_buffer[0], &begin_info); |
| 5325 | |
| 5326 | vkCmdPipelineBarrier(command_buffer[0], |
| 5327 | VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, |
| 5328 | VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, nullptr, |
| 5329 | 0, nullptr, 0, nullptr); |
| 5330 | |
| 5331 | VkViewport viewport{}; |
| 5332 | viewport.maxDepth = 1.0f; |
| 5333 | viewport.minDepth = 0.0f; |
| 5334 | viewport.width = 512; |
| 5335 | viewport.height = 512; |
| 5336 | viewport.x = 0; |
| 5337 | viewport.y = 0; |
| 5338 | vkCmdSetViewport(command_buffer[0], 0, 1, &viewport); |
| 5339 | vkEndCommandBuffer(command_buffer[0]); |
| 5340 | } |
| 5341 | { |
| 5342 | VkCommandBufferBeginInfo begin_info{}; |
| 5343 | begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO; |
| 5344 | vkBeginCommandBuffer(command_buffer[1], &begin_info); |
| 5345 | |
| 5346 | VkViewport viewport{}; |
| 5347 | viewport.maxDepth = 1.0f; |
| 5348 | viewport.minDepth = 0.0f; |
| 5349 | viewport.width = 512; |
| 5350 | viewport.height = 512; |
| 5351 | viewport.x = 0; |
| 5352 | viewport.y = 0; |
| 5353 | vkCmdSetViewport(command_buffer[1], 0, 1, &viewport); |
| 5354 | vkEndCommandBuffer(command_buffer[1]); |
| 5355 | } |
| 5356 | { |
| 5357 | VkSubmitInfo submit_info{}; |
| 5358 | submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO; |
| 5359 | submit_info.commandBufferCount = 1; |
| 5360 | submit_info.pCommandBuffers = &command_buffer[0]; |
| 5361 | submit_info.signalSemaphoreCount = 0; |
| 5362 | submit_info.pSignalSemaphores = VK_NULL_HANDLE; |
| 5363 | vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE); |
| 5364 | } |
| 5365 | { |
| 5366 | VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT}; |
| 5367 | VkSubmitInfo submit_info{}; |
| 5368 | submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO; |
| 5369 | submit_info.commandBufferCount = 1; |
| 5370 | submit_info.pCommandBuffers = &command_buffer[1]; |
| 5371 | submit_info.waitSemaphoreCount = 0; |
| 5372 | submit_info.pWaitSemaphores = VK_NULL_HANDLE; |
| 5373 | submit_info.pWaitDstStageMask = flags; |
| 5374 | vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE); |
| 5375 | } |
| 5376 | |
| 5377 | vkQueueSubmit(m_device->m_queue, 0, NULL, fence); |
| 5378 | |
Mike Stroyan | cd1c3e5 | 2016-06-21 09:20:01 -0600 | [diff] [blame] | 5379 | VkResult err = |
| 5380 | vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX); |
| 5381 | ASSERT_VK_SUCCESS(err); |
Mark Lobodzinski | c808d44 | 2016-04-14 10:57:23 -0600 | [diff] [blame] | 5382 | |
| 5383 | vkDestroyFence(m_device->device(), fence, nullptr); |
| 5384 | vkFreeCommandBuffers(m_device->device(), command_pool, 2, |
| 5385 | &command_buffer[0]); |
| 5386 | vkDestroyCommandPool(m_device->device(), command_pool, NULL); |
| 5387 | |
| 5388 | m_errorMonitor->VerifyNotFound(); |
| 5389 | } |
| 5390 | |
| 5391 | // This is a positive test. No errors should be generated. |
| 5392 | TEST_F(VkLayerTest, TwoQueueSubmitsOneQueueOneFence) { |
| 5393 | |
| 5394 | TEST_DESCRIPTION("Two command buffers, each in a separate QueueSubmit call " |
| 5395 | "on the same queue, the second having a fence, followed " |
| 5396 | "by a WaitForFences call."); |
| 5397 | |
| 5398 | m_errorMonitor->ExpectSuccess(); |
| 5399 | |
| 5400 | VkFence fence; |
| 5401 | VkFenceCreateInfo fence_create_info{}; |
| 5402 | fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO; |
| 5403 | vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence); |
| 5404 | |
| 5405 | VkCommandPool command_pool; |
| 5406 | VkCommandPoolCreateInfo pool_create_info{}; |
| 5407 | pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO; |
| 5408 | pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_; |
| 5409 | pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT; |
| 5410 | vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, |
| 5411 | &command_pool); |
| 5412 | |
| 5413 | VkCommandBuffer command_buffer[2]; |
| 5414 | VkCommandBufferAllocateInfo command_buffer_allocate_info{}; |
| 5415 | command_buffer_allocate_info.sType = |
| 5416 | VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO; |
| 5417 | command_buffer_allocate_info.commandPool = command_pool; |
| 5418 | command_buffer_allocate_info.commandBufferCount = 2; |
| 5419 | command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY; |
| 5420 | vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, |
| 5421 | command_buffer); |
| 5422 | |
| 5423 | { |
| 5424 | VkCommandBufferBeginInfo begin_info{}; |
| 5425 | begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO; |
| 5426 | vkBeginCommandBuffer(command_buffer[0], &begin_info); |
| 5427 | |
| 5428 | vkCmdPipelineBarrier(command_buffer[0], |
| 5429 | VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, |
| 5430 | VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, nullptr, |
| 5431 | 0, nullptr, 0, nullptr); |
| 5432 | |
| 5433 | VkViewport viewport{}; |
| 5434 | viewport.maxDepth = 1.0f; |
| 5435 | viewport.minDepth = 0.0f; |
| 5436 | viewport.width = 512; |
| 5437 | viewport.height = 512; |
| 5438 | viewport.x = 0; |
| 5439 | viewport.y = 0; |
| 5440 | vkCmdSetViewport(command_buffer[0], 0, 1, &viewport); |
| 5441 | vkEndCommandBuffer(command_buffer[0]); |
| 5442 | } |
| 5443 | { |
| 5444 | VkCommandBufferBeginInfo begin_info{}; |
| 5445 | begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO; |
| 5446 | vkBeginCommandBuffer(command_buffer[1], &begin_info); |
| 5447 | |
| 5448 | VkViewport viewport{}; |
| 5449 | viewport.maxDepth = 1.0f; |
| 5450 | viewport.minDepth = 0.0f; |
| 5451 | viewport.width = 512; |
| 5452 | viewport.height = 512; |
| 5453 | viewport.x = 0; |
| 5454 | viewport.y = 0; |
| 5455 | vkCmdSetViewport(command_buffer[1], 0, 1, &viewport); |
| 5456 | vkEndCommandBuffer(command_buffer[1]); |
| 5457 | } |
| 5458 | { |
| 5459 | VkSubmitInfo submit_info{}; |
| 5460 | submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO; |
| 5461 | submit_info.commandBufferCount = 1; |
| 5462 | submit_info.pCommandBuffers = &command_buffer[0]; |
| 5463 | submit_info.signalSemaphoreCount = 0; |
| 5464 | submit_info.pSignalSemaphores = VK_NULL_HANDLE; |
| 5465 | vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE); |
| 5466 | } |
| 5467 | { |
| 5468 | VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT}; |
| 5469 | VkSubmitInfo submit_info{}; |
| 5470 | submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO; |
| 5471 | submit_info.commandBufferCount = 1; |
| 5472 | submit_info.pCommandBuffers = &command_buffer[1]; |
| 5473 | submit_info.waitSemaphoreCount = 0; |
| 5474 | submit_info.pWaitSemaphores = VK_NULL_HANDLE; |
| 5475 | submit_info.pWaitDstStageMask = flags; |
| 5476 | vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence); |
| 5477 | } |
| 5478 | |
| 5479 | vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX); |
| 5480 | |
| 5481 | vkDestroyFence(m_device->device(), fence, nullptr); |
| 5482 | vkFreeCommandBuffers(m_device->device(), command_pool, 2, |
| 5483 | &command_buffer[0]); |
| 5484 | vkDestroyCommandPool(m_device->device(), command_pool, NULL); |
| 5485 | |
| 5486 | m_errorMonitor->VerifyNotFound(); |
| 5487 | } |
| 5488 | |
| 5489 | // This is a positive test. No errors should be generated. |
| 5490 | TEST_F(VkLayerTest, TwoSubmitInfosWithSemaphoreOneQueueSubmitsOneFence) { |
| 5491 | |
| 5492 | TEST_DESCRIPTION( |
| 5493 | "Two command buffers each in a separate SubmitInfo sent in a single " |
| 5494 | "QueueSubmit call followed by a WaitForFences call."); |
| 5495 | |
| 5496 | m_errorMonitor->ExpectSuccess(); |
| 5497 | |
| 5498 | VkFence fence; |
| 5499 | VkFenceCreateInfo fence_create_info{}; |
| 5500 | fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO; |
| 5501 | vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence); |
| 5502 | |
| 5503 | VkSemaphore semaphore; |
| 5504 | VkSemaphoreCreateInfo semaphore_create_info{}; |
| 5505 | semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO; |
| 5506 | vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, |
| 5507 | &semaphore); |
| 5508 | |
| 5509 | VkCommandPool command_pool; |
| 5510 | VkCommandPoolCreateInfo pool_create_info{}; |
| 5511 | pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO; |
| 5512 | pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_; |
| 5513 | pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT; |
| 5514 | vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, |
| 5515 | &command_pool); |
| 5516 | |
| 5517 | VkCommandBuffer command_buffer[2]; |
| 5518 | VkCommandBufferAllocateInfo command_buffer_allocate_info{}; |
| 5519 | command_buffer_allocate_info.sType = |
| 5520 | VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO; |
| 5521 | command_buffer_allocate_info.commandPool = command_pool; |
| 5522 | command_buffer_allocate_info.commandBufferCount = 2; |
| 5523 | command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY; |
| 5524 | vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, |
| 5525 | command_buffer); |
| 5526 | |
| 5527 | { |
| 5528 | VkCommandBufferBeginInfo begin_info{}; |
| 5529 | begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO; |
| 5530 | vkBeginCommandBuffer(command_buffer[0], &begin_info); |
| 5531 | |
| 5532 | vkCmdPipelineBarrier(command_buffer[0], |
| 5533 | VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, |
| 5534 | VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, nullptr, |
| 5535 | 0, nullptr, 0, nullptr); |
| 5536 | |
| 5537 | VkViewport viewport{}; |
| 5538 | viewport.maxDepth = 1.0f; |
| 5539 | viewport.minDepth = 0.0f; |
| 5540 | viewport.width = 512; |
| 5541 | viewport.height = 512; |
| 5542 | viewport.x = 0; |
| 5543 | viewport.y = 0; |
| 5544 | vkCmdSetViewport(command_buffer[0], 0, 1, &viewport); |
| 5545 | vkEndCommandBuffer(command_buffer[0]); |
| 5546 | } |
| 5547 | { |
| 5548 | VkCommandBufferBeginInfo begin_info{}; |
| 5549 | begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO; |
| 5550 | vkBeginCommandBuffer(command_buffer[1], &begin_info); |
| 5551 | |
| 5552 | VkViewport viewport{}; |
| 5553 | viewport.maxDepth = 1.0f; |
| 5554 | viewport.minDepth = 0.0f; |
| 5555 | viewport.width = 512; |
| 5556 | viewport.height = 512; |
| 5557 | viewport.x = 0; |
| 5558 | viewport.y = 0; |
| 5559 | vkCmdSetViewport(command_buffer[1], 0, 1, &viewport); |
| 5560 | vkEndCommandBuffer(command_buffer[1]); |
| 5561 | } |
| 5562 | { |
| 5563 | VkSubmitInfo submit_info[2]; |
| 5564 | VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT}; |
| 5565 | |
| 5566 | submit_info[0].sType = VK_STRUCTURE_TYPE_SUBMIT_INFO; |
| 5567 | submit_info[0].pNext = NULL; |
| 5568 | submit_info[0].commandBufferCount = 1; |
| 5569 | submit_info[0].pCommandBuffers = &command_buffer[0]; |
| 5570 | submit_info[0].signalSemaphoreCount = 1; |
| 5571 | submit_info[0].pSignalSemaphores = &semaphore; |
| 5572 | submit_info[0].waitSemaphoreCount = 0; |
| 5573 | submit_info[0].pWaitSemaphores = NULL; |
| 5574 | submit_info[0].pWaitDstStageMask = 0; |
| 5575 | |
| 5576 | submit_info[1].sType = VK_STRUCTURE_TYPE_SUBMIT_INFO; |
| 5577 | submit_info[1].pNext = NULL; |
| 5578 | submit_info[1].commandBufferCount = 1; |
| 5579 | submit_info[1].pCommandBuffers = &command_buffer[1]; |
| 5580 | submit_info[1].waitSemaphoreCount = 1; |
| 5581 | submit_info[1].pWaitSemaphores = &semaphore; |
| 5582 | submit_info[1].pWaitDstStageMask = flags; |
| 5583 | submit_info[1].signalSemaphoreCount = 0; |
| 5584 | submit_info[1].pSignalSemaphores = NULL; |
| 5585 | vkQueueSubmit(m_device->m_queue, 2, &submit_info[0], fence); |
| 5586 | } |
| 5587 | |
| 5588 | vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX); |
| 5589 | |
| 5590 | vkDestroyFence(m_device->device(), fence, nullptr); |
| 5591 | vkFreeCommandBuffers(m_device->device(), command_pool, 2, |
| 5592 | &command_buffer[0]); |
| 5593 | vkDestroyCommandPool(m_device->device(), command_pool, NULL); |
Tony Barbour | df4c004 | 2016-06-01 15:55:43 -0600 | [diff] [blame] | 5594 | vkDestroySemaphore(m_device->device(), semaphore, nullptr); |
Mark Lobodzinski | c808d44 | 2016-04-14 10:57:23 -0600 | [diff] [blame] | 5595 | |
| 5596 | m_errorMonitor->VerifyNotFound(); |
| 5597 | } |
| 5598 | |
Tobin Ehlis | b1a8799 | 2016-05-25 16:42:47 -0600 | [diff] [blame] | 5599 | TEST_F(VkLayerTest, DynamicDepthBiasNotBound) { |
Tobin Ehlis | a5200ef | 2016-05-03 10:34:08 -0600 | [diff] [blame] | 5600 | TEST_DESCRIPTION( |
Tobin Ehlis | b1a8799 | 2016-05-25 16:42:47 -0600 | [diff] [blame] | 5601 | "Run a simple draw calls to validate failure when Depth Bias dynamic " |
| 5602 | "state is required but not correctly bound."); |
| 5603 | |
| 5604 | // Dynamic depth bias |
| 5605 | m_errorMonitor->SetDesiredFailureMsg( |
| 5606 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 5607 | "Dynamic depth bias state not set for this command buffer"); |
| 5608 | VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, |
| 5609 | BsoFailDepthBias); |
| 5610 | m_errorMonitor->VerifyFound(); |
| 5611 | } |
| 5612 | |
| 5613 | TEST_F(VkLayerTest, DynamicLineWidthNotBound) { |
| 5614 | TEST_DESCRIPTION( |
| 5615 | "Run a simple draw calls to validate failure when Line Width dynamic " |
| 5616 | "state is required but not correctly bound."); |
Tobin Ehlis | a5200ef | 2016-05-03 10:34:08 -0600 | [diff] [blame] | 5617 | |
| 5618 | // Dynamic line width |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5619 | m_errorMonitor->SetDesiredFailureMsg( |
| 5620 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 5621 | "Dynamic line width state not set for this command buffer"); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5622 | VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, |
| 5623 | BsoFailLineWidth); |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 5624 | m_errorMonitor->VerifyFound(); |
Tobin Ehlis | b1a8799 | 2016-05-25 16:42:47 -0600 | [diff] [blame] | 5625 | } |
| 5626 | |
| 5627 | TEST_F(VkLayerTest, DynamicViewportNotBound) { |
| 5628 | TEST_DESCRIPTION( |
| 5629 | "Run a simple draw calls to validate failure when Viewport dynamic " |
| 5630 | "state is required but not correctly bound."); |
| 5631 | |
Tobin Ehlis | a5200ef | 2016-05-03 10:34:08 -0600 | [diff] [blame] | 5632 | // Dynamic viewport state |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5633 | m_errorMonitor->SetDesiredFailureMsg( |
| 5634 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 5635 | "Dynamic viewport state not set for this command buffer"); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5636 | VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, |
| 5637 | BsoFailViewport); |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 5638 | m_errorMonitor->VerifyFound(); |
Tobin Ehlis | b1a8799 | 2016-05-25 16:42:47 -0600 | [diff] [blame] | 5639 | } |
| 5640 | |
| 5641 | TEST_F(VkLayerTest, DynamicScissorNotBound) { |
| 5642 | TEST_DESCRIPTION( |
| 5643 | "Run a simple draw calls to validate failure when Scissor dynamic " |
| 5644 | "state is required but not correctly bound."); |
| 5645 | |
Tobin Ehlis | a5200ef | 2016-05-03 10:34:08 -0600 | [diff] [blame] | 5646 | // Dynamic scissor state |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5647 | m_errorMonitor->SetDesiredFailureMsg( |
| 5648 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 5649 | "Dynamic scissor state not set for this command buffer"); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5650 | VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, |
| 5651 | BsoFailScissor); |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 5652 | m_errorMonitor->VerifyFound(); |
Tobin Ehlis | b1a8799 | 2016-05-25 16:42:47 -0600 | [diff] [blame] | 5653 | } |
| 5654 | |
Tobin Ehlis | 21c8835 | 2016-05-26 06:15:45 -0600 | [diff] [blame] | 5655 | TEST_F(VkLayerTest, DynamiBlendConstantsNotBound) { |
Tobin Ehlis | b1a8799 | 2016-05-25 16:42:47 -0600 | [diff] [blame] | 5656 | TEST_DESCRIPTION( |
Tobin Ehlis | 21c8835 | 2016-05-26 06:15:45 -0600 | [diff] [blame] | 5657 | "Run a simple draw calls to validate failure when Blend Constants " |
| 5658 | "dynamic state is required but not correctly bound."); |
| 5659 | // Dynamic blend constant state |
| 5660 | m_errorMonitor->SetDesiredFailureMsg( |
| 5661 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 5662 | "Dynamic blend constants state not set for this command buffer"); |
| 5663 | VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, |
| 5664 | BsoFailBlend); |
| 5665 | m_errorMonitor->VerifyFound(); |
| 5666 | } |
| 5667 | |
| 5668 | TEST_F(VkLayerTest, DynamicDepthBoundsNotBound) { |
| 5669 | TEST_DESCRIPTION( |
| 5670 | "Run a simple draw calls to validate failure when Depth Bounds dynamic " |
Tobin Ehlis | b1a8799 | 2016-05-25 16:42:47 -0600 | [diff] [blame] | 5671 | "state is required but not correctly bound."); |
Tobin Ehlis | 21c8835 | 2016-05-26 06:15:45 -0600 | [diff] [blame] | 5672 | if (!m_device->phy().features().depthBounds) { |
| 5673 | printf("Device does not support depthBounds test; skipped.\n"); |
| 5674 | return; |
| 5675 | } |
| 5676 | // Dynamic depth bounds |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5677 | m_errorMonitor->SetDesiredFailureMsg( |
| 5678 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 5679 | "Dynamic depth bounds state not set for this command buffer"); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5680 | VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, |
| 5681 | BsoFailDepthBounds); |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 5682 | m_errorMonitor->VerifyFound(); |
Tobin Ehlis | b1a8799 | 2016-05-25 16:42:47 -0600 | [diff] [blame] | 5683 | } |
| 5684 | |
| 5685 | TEST_F(VkLayerTest, DynamicStencilReadNotBound) { |
| 5686 | TEST_DESCRIPTION( |
| 5687 | "Run a simple draw calls to validate failure when Stencil Read dynamic " |
| 5688 | "state is required but not correctly bound."); |
Tobin Ehlis | a5200ef | 2016-05-03 10:34:08 -0600 | [diff] [blame] | 5689 | // Dynamic stencil read mask |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5690 | m_errorMonitor->SetDesiredFailureMsg( |
| 5691 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 5692 | "Dynamic stencil read mask state not set for this command buffer"); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5693 | VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, |
| 5694 | BsoFailStencilReadMask); |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 5695 | m_errorMonitor->VerifyFound(); |
Tobin Ehlis | b1a8799 | 2016-05-25 16:42:47 -0600 | [diff] [blame] | 5696 | } |
| 5697 | |
| 5698 | TEST_F(VkLayerTest, DynamicStencilWriteNotBound) { |
| 5699 | TEST_DESCRIPTION( |
| 5700 | "Run a simple draw calls to validate failure when Stencil Write dynamic" |
| 5701 | " state is required but not correctly bound."); |
Tobin Ehlis | a5200ef | 2016-05-03 10:34:08 -0600 | [diff] [blame] | 5702 | // Dynamic stencil write mask |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5703 | m_errorMonitor->SetDesiredFailureMsg( |
| 5704 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 5705 | "Dynamic stencil write mask state not set for this command buffer"); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5706 | VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, |
| 5707 | BsoFailStencilWriteMask); |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 5708 | m_errorMonitor->VerifyFound(); |
Tobin Ehlis | b1a8799 | 2016-05-25 16:42:47 -0600 | [diff] [blame] | 5709 | } |
| 5710 | |
| 5711 | TEST_F(VkLayerTest, DynamicStencilRefNotBound) { |
| 5712 | TEST_DESCRIPTION( |
| 5713 | "Run a simple draw calls to validate failure when Stencil Ref dynamic " |
| 5714 | "state is required but not correctly bound."); |
Tobin Ehlis | a5200ef | 2016-05-03 10:34:08 -0600 | [diff] [blame] | 5715 | // Dynamic stencil reference |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5716 | m_errorMonitor->SetDesiredFailureMsg( |
| 5717 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 5718 | "Dynamic stencil reference state not set for this command buffer"); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5719 | VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, |
| 5720 | BsoFailStencilReference); |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 5721 | m_errorMonitor->VerifyFound(); |
Tobin Ehlis | 963a404 | 2015-09-29 08:18:34 -0600 | [diff] [blame] | 5722 | } |
| 5723 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5724 | TEST_F(VkLayerTest, CommandBufferTwoSubmits) { |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5725 | m_errorMonitor->SetDesiredFailureMsg( |
| 5726 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 5727 | "was begun w/ VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT set, but has " |
| 5728 | "been submitted"); |
Tobin Ehlis | 59278bf | 2015-08-18 07:10:58 -0600 | [diff] [blame] | 5729 | |
Tobin Ehlis | 59278bf | 2015-08-18 07:10:58 -0600 | [diff] [blame] | 5730 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 5731 | ASSERT_NO_FATAL_FAILURE(InitViewport()); |
| 5732 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 5733 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5734 | // We luck out b/c by default the framework creates CB w/ the |
| 5735 | // VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT set |
Tobin Ehlis | 59278bf | 2015-08-18 07:10:58 -0600 | [diff] [blame] | 5736 | BeginCommandBuffer(); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5737 | m_commandBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color, |
| 5738 | m_stencil_clear_color, NULL); |
Tobin Ehlis | 59278bf | 2015-08-18 07:10:58 -0600 | [diff] [blame] | 5739 | EndCommandBuffer(); |
| 5740 | |
Tobin Ehlis | 59278bf | 2015-08-18 07:10:58 -0600 | [diff] [blame] | 5741 | // Bypass framework since it does the waits automatically |
| 5742 | VkResult err = VK_SUCCESS; |
Courtney Goeltzenleuchter | 806c700 | 2015-10-27 11:22:14 -0600 | [diff] [blame] | 5743 | VkSubmitInfo submit_info; |
Chia-I Wu | f9be13c | 2015-10-26 20:37:06 +0800 | [diff] [blame] | 5744 | submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO; |
| 5745 | submit_info.pNext = NULL; |
Chia-I Wu | d50a7d7 | 2015-10-26 20:48:51 +0800 | [diff] [blame] | 5746 | submit_info.waitSemaphoreCount = 0; |
Courtney Goeltzenleuchter | 806c700 | 2015-10-27 11:22:14 -0600 | [diff] [blame] | 5747 | submit_info.pWaitSemaphores = NULL; |
Jon Ashburn | 7f9716c | 2015-12-30 16:42:50 -0700 | [diff] [blame] | 5748 | submit_info.pWaitDstStageMask = NULL; |
Chia-I Wu | d50a7d7 | 2015-10-26 20:48:51 +0800 | [diff] [blame] | 5749 | submit_info.commandBufferCount = 1; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 5750 | submit_info.pCommandBuffers = &m_commandBuffer->handle(); |
Chia-I Wu | d50a7d7 | 2015-10-26 20:48:51 +0800 | [diff] [blame] | 5751 | submit_info.signalSemaphoreCount = 0; |
Courtney Goeltzenleuchter | 806c700 | 2015-10-27 11:22:14 -0600 | [diff] [blame] | 5752 | submit_info.pSignalSemaphores = NULL; |
| 5753 | |
Chris Forbes | 40028e2 | 2016-06-13 09:59:34 +1200 | [diff] [blame] | 5754 | err = vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5755 | ASSERT_VK_SUCCESS(err); |
Tobin Ehlis | 59278bf | 2015-08-18 07:10:58 -0600 | [diff] [blame] | 5756 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5757 | // Cause validation error by re-submitting cmd buffer that should only be |
| 5758 | // submitted once |
Chris Forbes | 40028e2 | 2016-06-13 09:59:34 +1200 | [diff] [blame] | 5759 | err = vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE); |
Tobin Ehlis | 59278bf | 2015-08-18 07:10:58 -0600 | [diff] [blame] | 5760 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 5761 | m_errorMonitor->VerifyFound(); |
Tobin Ehlis | 59278bf | 2015-08-18 07:10:58 -0600 | [diff] [blame] | 5762 | } |
| 5763 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5764 | TEST_F(VkLayerTest, AllocDescriptorFromEmptyPool) { |
Tobin Ehlis | f93f1e3 | 2015-10-20 16:16:04 -0600 | [diff] [blame] | 5765 | // Initiate Draw w/o a PSO bound |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5766 | VkResult err; |
Tobin Ehlis | f93f1e3 | 2015-10-20 16:16:04 -0600 | [diff] [blame] | 5767 | |
Courtney Goeltzenleuchter | 7415d5a | 2015-12-09 15:48:16 -0700 | [diff] [blame] | 5768 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5769 | "Unable to allocate 1 descriptors of " |
| 5770 | "type " |
| 5771 | "VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER "); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 5772 | |
Tobin Ehlis | f93f1e3 | 2015-10-20 16:16:04 -0600 | [diff] [blame] | 5773 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 5774 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
Tobin Ehlis | f93f1e3 | 2015-10-20 16:16:04 -0600 | [diff] [blame] | 5775 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5776 | // Create Pool w/ 1 Sampler descriptor, but try to alloc Uniform Buffer |
| 5777 | // descriptor from it |
Chia-I Wu | 1b99bb2 | 2015-10-27 19:25:11 +0800 | [diff] [blame] | 5778 | VkDescriptorPoolSize ds_type_count = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5779 | ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLER; |
| 5780 | ds_type_count.descriptorCount = 1; |
Tobin Ehlis | f93f1e3 | 2015-10-20 16:16:04 -0600 | [diff] [blame] | 5781 | |
| 5782 | VkDescriptorPoolCreateInfo ds_pool_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5783 | ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO; |
| 5784 | ds_pool_ci.pNext = NULL; |
| 5785 | ds_pool_ci.flags = 0; |
| 5786 | ds_pool_ci.maxSets = 1; |
| 5787 | ds_pool_ci.poolSizeCount = 1; |
| 5788 | ds_pool_ci.pPoolSizes = &ds_type_count; |
Tobin Ehlis | f93f1e3 | 2015-10-20 16:16:04 -0600 | [diff] [blame] | 5789 | |
| 5790 | VkDescriptorPool ds_pool; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5791 | err = |
| 5792 | vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool); |
Tobin Ehlis | f93f1e3 | 2015-10-20 16:16:04 -0600 | [diff] [blame] | 5793 | ASSERT_VK_SUCCESS(err); |
| 5794 | |
| 5795 | VkDescriptorSetLayoutBinding dsl_binding = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5796 | dsl_binding.binding = 0; |
| 5797 | dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 5798 | dsl_binding.descriptorCount = 1; |
| 5799 | dsl_binding.stageFlags = VK_SHADER_STAGE_ALL; |
| 5800 | dsl_binding.pImmutableSamplers = NULL; |
Tobin Ehlis | f93f1e3 | 2015-10-20 16:16:04 -0600 | [diff] [blame] | 5801 | |
| 5802 | VkDescriptorSetLayoutCreateInfo ds_layout_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5803 | ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO; |
| 5804 | ds_layout_ci.pNext = NULL; |
| 5805 | ds_layout_ci.bindingCount = 1; |
| 5806 | ds_layout_ci.pBindings = &dsl_binding; |
Tobin Ehlis | f93f1e3 | 2015-10-20 16:16:04 -0600 | [diff] [blame] | 5807 | |
| 5808 | VkDescriptorSetLayout ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5809 | err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, |
| 5810 | &ds_layout); |
Tobin Ehlis | f93f1e3 | 2015-10-20 16:16:04 -0600 | [diff] [blame] | 5811 | ASSERT_VK_SUCCESS(err); |
| 5812 | |
| 5813 | VkDescriptorSet descriptorSet; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 5814 | VkDescriptorSetAllocateInfo alloc_info = {}; |
Chia-I Wu | 00ce540 | 2015-11-10 16:21:09 +0800 | [diff] [blame] | 5815 | alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO; |
Jon Ashburn | f19916e | 2016-01-11 13:12:43 -0700 | [diff] [blame] | 5816 | alloc_info.descriptorSetCount = 1; |
Courtney Goeltzenleuchter | bee18a9 | 2015-10-23 14:21:05 -0600 | [diff] [blame] | 5817 | alloc_info.descriptorPool = ds_pool; |
| 5818 | alloc_info.pSetLayouts = &ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5819 | err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, |
| 5820 | &descriptorSet); |
Tobin Ehlis | f93f1e3 | 2015-10-20 16:16:04 -0600 | [diff] [blame] | 5821 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 5822 | m_errorMonitor->VerifyFound(); |
Tobin Ehlis | f93f1e3 | 2015-10-20 16:16:04 -0600 | [diff] [blame] | 5823 | |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 5824 | vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL); |
| 5825 | vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL); |
Tobin Ehlis | f93f1e3 | 2015-10-20 16:16:04 -0600 | [diff] [blame] | 5826 | } |
| 5827 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5828 | TEST_F(VkLayerTest, FreeDescriptorFromOneShotPool) { |
| 5829 | VkResult err; |
Tobin Ehlis | e735c69 | 2015-10-08 13:13:50 -0600 | [diff] [blame] | 5830 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5831 | m_errorMonitor->SetDesiredFailureMsg( |
| 5832 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 5833 | "It is invalid to call vkFreeDescriptorSets() with a pool created " |
| 5834 | "without setting VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT."); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 5835 | |
Tobin Ehlis | e735c69 | 2015-10-08 13:13:50 -0600 | [diff] [blame] | 5836 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 5837 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
Tobin Ehlis | e735c69 | 2015-10-08 13:13:50 -0600 | [diff] [blame] | 5838 | |
Chia-I Wu | 1b99bb2 | 2015-10-27 19:25:11 +0800 | [diff] [blame] | 5839 | VkDescriptorPoolSize ds_type_count = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5840 | ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 5841 | ds_type_count.descriptorCount = 1; |
Tobin Ehlis | e735c69 | 2015-10-08 13:13:50 -0600 | [diff] [blame] | 5842 | |
| 5843 | VkDescriptorPoolCreateInfo ds_pool_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5844 | ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO; |
| 5845 | ds_pool_ci.pNext = NULL; |
| 5846 | ds_pool_ci.maxSets = 1; |
| 5847 | ds_pool_ci.poolSizeCount = 1; |
| 5848 | ds_pool_ci.flags = 0; |
| 5849 | // Not specifying VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT means |
| 5850 | // app can only call vkResetDescriptorPool on this pool.; |
| 5851 | ds_pool_ci.pPoolSizes = &ds_type_count; |
Tobin Ehlis | e735c69 | 2015-10-08 13:13:50 -0600 | [diff] [blame] | 5852 | |
| 5853 | VkDescriptorPool ds_pool; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5854 | err = |
| 5855 | vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool); |
Tobin Ehlis | e735c69 | 2015-10-08 13:13:50 -0600 | [diff] [blame] | 5856 | ASSERT_VK_SUCCESS(err); |
| 5857 | |
| 5858 | VkDescriptorSetLayoutBinding dsl_binding = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5859 | dsl_binding.binding = 0; |
| 5860 | dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 5861 | dsl_binding.descriptorCount = 1; |
| 5862 | dsl_binding.stageFlags = VK_SHADER_STAGE_ALL; |
| 5863 | dsl_binding.pImmutableSamplers = NULL; |
Tobin Ehlis | e735c69 | 2015-10-08 13:13:50 -0600 | [diff] [blame] | 5864 | |
| 5865 | VkDescriptorSetLayoutCreateInfo ds_layout_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5866 | ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO; |
| 5867 | ds_layout_ci.pNext = NULL; |
| 5868 | ds_layout_ci.bindingCount = 1; |
| 5869 | ds_layout_ci.pBindings = &dsl_binding; |
Tobin Ehlis | e735c69 | 2015-10-08 13:13:50 -0600 | [diff] [blame] | 5870 | |
| 5871 | VkDescriptorSetLayout ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5872 | err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, |
| 5873 | &ds_layout); |
Tobin Ehlis | e735c69 | 2015-10-08 13:13:50 -0600 | [diff] [blame] | 5874 | ASSERT_VK_SUCCESS(err); |
| 5875 | |
| 5876 | VkDescriptorSet descriptorSet; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 5877 | VkDescriptorSetAllocateInfo alloc_info = {}; |
Chia-I Wu | 00ce540 | 2015-11-10 16:21:09 +0800 | [diff] [blame] | 5878 | alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO; |
Jon Ashburn | f19916e | 2016-01-11 13:12:43 -0700 | [diff] [blame] | 5879 | alloc_info.descriptorSetCount = 1; |
Courtney Goeltzenleuchter | bee18a9 | 2015-10-23 14:21:05 -0600 | [diff] [blame] | 5880 | alloc_info.descriptorPool = ds_pool; |
| 5881 | alloc_info.pSetLayouts = &ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5882 | err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, |
| 5883 | &descriptorSet); |
Tobin Ehlis | e735c69 | 2015-10-08 13:13:50 -0600 | [diff] [blame] | 5884 | ASSERT_VK_SUCCESS(err); |
| 5885 | |
| 5886 | err = vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptorSet); |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 5887 | m_errorMonitor->VerifyFound(); |
Tobin Ehlis | e735c69 | 2015-10-08 13:13:50 -0600 | [diff] [blame] | 5888 | |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 5889 | vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL); |
| 5890 | vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL); |
Tobin Ehlis | e735c69 | 2015-10-08 13:13:50 -0600 | [diff] [blame] | 5891 | } |
| 5892 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5893 | TEST_F(VkLayerTest, InvalidDescriptorPool) { |
Karl Schultz | bdb7595 | 2016-04-19 11:36:49 -0600 | [diff] [blame] | 5894 | // Attempt to clear Descriptor Pool with bad object. |
| 5895 | // ObjectTracker should catch this. |
| 5896 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 5897 | "Invalid VkDescriptorPool Object 0xbaad6001"); |
Mark Lobodzinski | 02bf89d | 2016-05-10 14:45:13 -0600 | [diff] [blame] | 5898 | uint64_t fake_pool_handle = 0xbaad6001; |
| 5899 | VkDescriptorPool bad_pool = reinterpret_cast<VkDescriptorPool &>(fake_pool_handle); |
| 5900 | vkResetDescriptorPool(device(), bad_pool, 0); |
Karl Schultz | bdb7595 | 2016-04-19 11:36:49 -0600 | [diff] [blame] | 5901 | m_errorMonitor->VerifyFound(); |
Tobin Ehlis | 49eb23d | 2015-05-22 12:38:55 -0600 | [diff] [blame] | 5902 | } |
| 5903 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5904 | TEST_F(VkLayerTest, InvalidDescriptorSet) { |
Karl Schultz | bdb7595 | 2016-04-19 11:36:49 -0600 | [diff] [blame] | 5905 | // Attempt to bind an invalid Descriptor Set to a valid Command Buffer |
| 5906 | // ObjectTracker should catch this. |
Tobin Ehlis | 49eb23d | 2015-05-22 12:38:55 -0600 | [diff] [blame] | 5907 | // Create a valid cmd buffer |
Karl Schultz | bdb7595 | 2016-04-19 11:36:49 -0600 | [diff] [blame] | 5908 | // call vkCmdBindDescriptorSets w/ false Descriptor Set |
Mark Lobodzinski | 02bf89d | 2016-05-10 14:45:13 -0600 | [diff] [blame] | 5909 | |
| 5910 | uint64_t fake_set_handle = 0xbaad6001; |
| 5911 | VkDescriptorSet bad_set = reinterpret_cast<VkDescriptorSet &>(fake_set_handle); |
Karl Schultz | bdb7595 | 2016-04-19 11:36:49 -0600 | [diff] [blame] | 5912 | VkResult err; |
| 5913 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 5914 | "Invalid VkDescriptorSet Object 0xbaad6001"); |
| 5915 | |
| 5916 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 5917 | |
| 5918 | VkDescriptorSetLayoutBinding layout_bindings[1] = {}; |
| 5919 | layout_bindings[0].binding = 0; |
| 5920 | layout_bindings[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 5921 | layout_bindings[0].descriptorCount = 1; |
| 5922 | layout_bindings[0].stageFlags = VK_SHADER_STAGE_VERTEX_BIT; |
| 5923 | layout_bindings[0].pImmutableSamplers = NULL; |
| 5924 | |
| 5925 | VkDescriptorSetLayout descriptor_set_layout; |
| 5926 | VkDescriptorSetLayoutCreateInfo dslci = {}; |
| 5927 | dslci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO; |
| 5928 | dslci.pNext = NULL; |
| 5929 | dslci.bindingCount = 1; |
| 5930 | dslci.pBindings = layout_bindings; |
| 5931 | err = vkCreateDescriptorSetLayout(device(), &dslci, NULL, &descriptor_set_layout); |
Karl Schultz | 5cb2111 | 2016-04-21 17:17:40 -0600 | [diff] [blame] | 5932 | ASSERT_VK_SUCCESS(err); |
Karl Schultz | bdb7595 | 2016-04-19 11:36:49 -0600 | [diff] [blame] | 5933 | |
| 5934 | VkPipelineLayout pipeline_layout; |
| 5935 | VkPipelineLayoutCreateInfo plci = {}; |
| 5936 | plci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO; |
| 5937 | plci.pNext = NULL; |
| 5938 | plci.setLayoutCount = 1; |
| 5939 | plci.pSetLayouts = &descriptor_set_layout; |
| 5940 | err = vkCreatePipelineLayout(device(), &plci, NULL, &pipeline_layout); |
Karl Schultz | 5cb2111 | 2016-04-21 17:17:40 -0600 | [diff] [blame] | 5941 | ASSERT_VK_SUCCESS(err); |
Karl Schultz | bdb7595 | 2016-04-19 11:36:49 -0600 | [diff] [blame] | 5942 | |
| 5943 | BeginCommandBuffer(); |
| 5944 | vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, |
Mark Lobodzinski | 02bf89d | 2016-05-10 14:45:13 -0600 | [diff] [blame] | 5945 | pipeline_layout, 0, 1, &bad_set, 0, NULL); |
Karl Schultz | bdb7595 | 2016-04-19 11:36:49 -0600 | [diff] [blame] | 5946 | m_errorMonitor->VerifyFound(); |
| 5947 | EndCommandBuffer(); |
| 5948 | vkDestroyPipelineLayout(device(), pipeline_layout, NULL); |
| 5949 | vkDestroyDescriptorSetLayout(device(), descriptor_set_layout, NULL); |
Tobin Ehlis | 49eb23d | 2015-05-22 12:38:55 -0600 | [diff] [blame] | 5950 | } |
| 5951 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5952 | TEST_F(VkLayerTest, InvalidDescriptorSetLayout) { |
Karl Schultz | bdb7595 | 2016-04-19 11:36:49 -0600 | [diff] [blame] | 5953 | // Attempt to create a Pipeline Layout with an invalid Descriptor Set Layout. |
| 5954 | // ObjectTracker should catch this. |
Mark Lobodzinski | 02bf89d | 2016-05-10 14:45:13 -0600 | [diff] [blame] | 5955 | uint64_t fake_layout_handle = 0xbaad6001; |
| 5956 | VkDescriptorSetLayout bad_layout = reinterpret_cast<VkDescriptorSetLayout &>(fake_layout_handle); |
Karl Schultz | bdb7595 | 2016-04-19 11:36:49 -0600 | [diff] [blame] | 5957 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 5958 | "Invalid VkDescriptorSetLayout Object 0xbaad6001"); |
| 5959 | |
| 5960 | VkPipelineLayout pipeline_layout; |
| 5961 | VkPipelineLayoutCreateInfo plci = {}; |
| 5962 | plci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO; |
| 5963 | plci.pNext = NULL; |
| 5964 | plci.setLayoutCount = 1; |
| 5965 | plci.pSetLayouts = &bad_layout; |
| 5966 | vkCreatePipelineLayout(device(), &plci, NULL, &pipeline_layout); |
| 5967 | |
| 5968 | m_errorMonitor->VerifyFound(); |
Tobin Ehlis | 49eb23d | 2015-05-22 12:38:55 -0600 | [diff] [blame] | 5969 | } |
| 5970 | |
Mark Mueller | d491441 | 2016-06-13 17:52:06 -0600 | [diff] [blame] | 5971 | TEST_F(VkLayerTest, WriteDescriptorSetIntegrityCheck) { |
| 5972 | TEST_DESCRIPTION("This test verifies some requirements of chapter 13.2.3 of the Vulkan Spec " |
| 5973 | "1) A uniform buffer update must have a valid buffer index." |
| 5974 | "2) When using an array of descriptors in a single WriteDescriptor," |
| 5975 | " the descriptor types and stageflags must all be the same." |
| 5976 | "3) Immutable Sampler state must match across descriptors"); |
| 5977 | |
| 5978 | const char *invalid_BufferInfo_ErrorMessage = |
| 5979 | "vkUpdateDescriptorSets: if pDescriptorWrites[0].descriptorType is VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, " |
| 5980 | "VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC or " |
| 5981 | "VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC, pDescriptorWrites[0].pBufferInfo must not be NULL"; |
| 5982 | const char *stateFlag_ErrorMessage = |
Mark Mueller | 5c838ce | 2016-06-16 09:54:29 -0600 | [diff] [blame] | 5983 | "Attempting write update to descriptor set "; |
Mark Mueller | d491441 | 2016-06-13 17:52:06 -0600 | [diff] [blame] | 5984 | const char *immutable_ErrorMessage = |
Mark Mueller | 5c838ce | 2016-06-16 09:54:29 -0600 | [diff] [blame] | 5985 | "Attempting write update to descriptor set "; |
Mark Mueller | d491441 | 2016-06-13 17:52:06 -0600 | [diff] [blame] | 5986 | |
Mark Mueller | d491441 | 2016-06-13 17:52:06 -0600 | [diff] [blame] | 5987 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_BufferInfo_ErrorMessage); |
| 5988 | |
| 5989 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 5990 | VkDescriptorPoolSize ds_type_count[4] = {}; |
| 5991 | ds_type_count[0].type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 5992 | ds_type_count[0].descriptorCount = 1; |
| 5993 | ds_type_count[1].type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER; |
| 5994 | ds_type_count[1].descriptorCount = 1; |
| 5995 | ds_type_count[2].type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER; |
| 5996 | ds_type_count[2].descriptorCount = 1; |
| 5997 | ds_type_count[3].type = VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT; |
| 5998 | ds_type_count[3].descriptorCount = 1; |
| 5999 | |
| 6000 | VkDescriptorPoolCreateInfo ds_pool_ci = {}; |
| 6001 | ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO; |
| 6002 | ds_pool_ci.maxSets = 1; |
| 6003 | ds_pool_ci.poolSizeCount = sizeof(ds_type_count) / sizeof(VkDescriptorPoolSize); |
| 6004 | ds_pool_ci.pPoolSizes = ds_type_count; |
| 6005 | |
| 6006 | VkDescriptorPool ds_pool; |
| 6007 | VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool); |
| 6008 | ASSERT_VK_SUCCESS(err); |
| 6009 | |
Mark Mueller | b989672 | 2016-06-16 09:54:29 -0600 | [diff] [blame] | 6010 | VkDescriptorSetLayoutBinding layout_binding[3] = {}; |
Mark Mueller | d491441 | 2016-06-13 17:52:06 -0600 | [diff] [blame] | 6011 | layout_binding[0].binding = 0; |
| 6012 | layout_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 6013 | layout_binding[0].descriptorCount = 1; |
| 6014 | layout_binding[0].stageFlags = VK_SHADER_STAGE_ALL; |
| 6015 | layout_binding[0].pImmutableSamplers = NULL; |
| 6016 | |
| 6017 | layout_binding[1].binding = 1; |
| 6018 | layout_binding[1].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER; |
| 6019 | layout_binding[1].descriptorCount = 1; |
| 6020 | layout_binding[1].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT; |
| 6021 | layout_binding[1].pImmutableSamplers = NULL; |
| 6022 | |
| 6023 | VkSamplerCreateInfo sampler_ci = {}; |
| 6024 | sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO; |
| 6025 | sampler_ci.pNext = NULL; |
| 6026 | sampler_ci.magFilter = VK_FILTER_NEAREST; |
| 6027 | sampler_ci.minFilter = VK_FILTER_NEAREST; |
| 6028 | sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST; |
| 6029 | sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE; |
| 6030 | sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE; |
| 6031 | sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE; |
| 6032 | sampler_ci.mipLodBias = 1.0; |
| 6033 | sampler_ci.anisotropyEnable = VK_FALSE; |
| 6034 | sampler_ci.maxAnisotropy = 1; |
| 6035 | sampler_ci.compareEnable = VK_FALSE; |
| 6036 | sampler_ci.compareOp = VK_COMPARE_OP_NEVER; |
| 6037 | sampler_ci.minLod = 1.0; |
| 6038 | sampler_ci.maxLod = 1.0; |
| 6039 | sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE; |
| 6040 | sampler_ci.unnormalizedCoordinates = VK_FALSE; |
| 6041 | VkSampler sampler; |
| 6042 | |
| 6043 | err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler); |
| 6044 | ASSERT_VK_SUCCESS(err); |
| 6045 | |
| 6046 | layout_binding[2].binding = 2; |
| 6047 | layout_binding[2].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER; |
| 6048 | layout_binding[2].descriptorCount = 1; |
| 6049 | layout_binding[2].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT; |
| 6050 | layout_binding[2].pImmutableSamplers = static_cast<VkSampler *>(&sampler); |
| 6051 | |
Mark Mueller | d491441 | 2016-06-13 17:52:06 -0600 | [diff] [blame] | 6052 | VkDescriptorSetLayoutCreateInfo ds_layout_ci = {}; |
| 6053 | ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO; |
| 6054 | ds_layout_ci.bindingCount = sizeof(layout_binding) / sizeof(VkDescriptorSetLayoutBinding); |
| 6055 | ds_layout_ci.pBindings = layout_binding; |
| 6056 | VkDescriptorSetLayout ds_layout; |
| 6057 | err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout); |
| 6058 | ASSERT_VK_SUCCESS(err); |
| 6059 | |
| 6060 | VkDescriptorSetAllocateInfo alloc_info = {}; |
| 6061 | alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO; |
| 6062 | alloc_info.descriptorSetCount = 1; |
| 6063 | alloc_info.descriptorPool = ds_pool; |
| 6064 | alloc_info.pSetLayouts = &ds_layout; |
| 6065 | VkDescriptorSet descriptorSet; |
| 6066 | err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet); |
| 6067 | ASSERT_VK_SUCCESS(err); |
| 6068 | |
| 6069 | VkPipelineLayoutCreateInfo pipeline_layout_ci = {}; |
| 6070 | pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO; |
| 6071 | pipeline_layout_ci.pNext = NULL; |
| 6072 | pipeline_layout_ci.setLayoutCount = 1; |
| 6073 | pipeline_layout_ci.pSetLayouts = &ds_layout; |
| 6074 | |
| 6075 | VkPipelineLayout pipeline_layout; |
| 6076 | err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout); |
| 6077 | ASSERT_VK_SUCCESS(err); |
| 6078 | |
Mark Mueller | 5c838ce | 2016-06-16 09:54:29 -0600 | [diff] [blame] | 6079 | VkWriteDescriptorSet descriptor_write = {}; |
Mark Mueller | d491441 | 2016-06-13 17:52:06 -0600 | [diff] [blame] | 6080 | descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET; |
| 6081 | descriptor_write.dstSet = descriptorSet; |
| 6082 | descriptor_write.dstBinding = 0; |
| 6083 | descriptor_write.descriptorCount = 1; |
| 6084 | descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 6085 | |
Mark Mueller | 5c838ce | 2016-06-16 09:54:29 -0600 | [diff] [blame] | 6086 | // 1) The uniform buffer is intentionally invalid here |
Mark Mueller | d491441 | 2016-06-13 17:52:06 -0600 | [diff] [blame] | 6087 | vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL); |
| 6088 | m_errorMonitor->VerifyFound(); |
| 6089 | |
| 6090 | // Create a buffer to update the descriptor with |
| 6091 | uint32_t qfi = 0; |
| 6092 | VkBufferCreateInfo buffCI = {}; |
| 6093 | buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO; |
| 6094 | buffCI.size = 1024; |
| 6095 | buffCI.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT; |
| 6096 | buffCI.queueFamilyIndexCount = 1; |
| 6097 | buffCI.pQueueFamilyIndices = &qfi; |
| 6098 | |
| 6099 | VkBuffer dyub; |
| 6100 | err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &dyub); |
| 6101 | ASSERT_VK_SUCCESS(err); |
| 6102 | VkDescriptorBufferInfo buffInfo = {}; |
| 6103 | buffInfo.buffer = dyub; |
| 6104 | buffInfo.offset = 0; |
| 6105 | buffInfo.range = 1024; |
| 6106 | |
| 6107 | descriptor_write.pBufferInfo = &buffInfo; |
| 6108 | descriptor_write.descriptorCount = 2; |
| 6109 | |
Mark Mueller | 5c838ce | 2016-06-16 09:54:29 -0600 | [diff] [blame] | 6110 | // 2) The stateFlags don't match between the first and second descriptor |
Mark Mueller | d491441 | 2016-06-13 17:52:06 -0600 | [diff] [blame] | 6111 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, stateFlag_ErrorMessage); |
| 6112 | vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL); |
| 6113 | m_errorMonitor->VerifyFound(); |
| 6114 | |
Mark Mueller | 5c838ce | 2016-06-16 09:54:29 -0600 | [diff] [blame] | 6115 | // 3) The second descriptor has a null_ptr pImmutableSamplers and |
| 6116 | // the third descriptor contains an immutable sampler |
Mark Mueller | d491441 | 2016-06-13 17:52:06 -0600 | [diff] [blame] | 6117 | descriptor_write.dstBinding = 1; |
| 6118 | descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER; |
Mark Mueller | 5c838ce | 2016-06-16 09:54:29 -0600 | [diff] [blame] | 6119 | |
| 6120 | |
| 6121 | // Make pImageInfo index non-null to avoid complaints of it missing |
| 6122 | VkDescriptorImageInfo imageInfo = {}; |
| 6123 | imageInfo.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL; |
| 6124 | descriptor_write.pImageInfo = &imageInfo; |
Mark Mueller | d491441 | 2016-06-13 17:52:06 -0600 | [diff] [blame] | 6125 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, immutable_ErrorMessage); |
| 6126 | vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL); |
| 6127 | m_errorMonitor->VerifyFound(); |
| 6128 | |
Mark Mueller | d491441 | 2016-06-13 17:52:06 -0600 | [diff] [blame] | 6129 | vkDestroyBuffer(m_device->device(), dyub, NULL); |
| 6130 | vkDestroySampler(m_device->device(), sampler, NULL); |
| 6131 | vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL); |
| 6132 | vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL); |
| 6133 | vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL); |
| 6134 | } |
| 6135 | |
Tobin Ehlis | 0283c4d | 2016-06-28 17:57:07 -0600 | [diff] [blame] | 6136 | TEST_F(VkLayerTest, InvalidCmdBufferBufferDestroyed) { |
| 6137 | TEST_DESCRIPTION("Attempt to draw with a command buffer that is invalid " |
| 6138 | "due to a buffer dependency being destroyed."); |
| 6139 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 6140 | |
| 6141 | VkImageObj image(m_device); |
| 6142 | image.init(128, 128, VK_FORMAT_B8G8R8A8_UNORM, |
| 6143 | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | |
| 6144 | VK_IMAGE_USAGE_TRANSFER_DST_BIT, |
| 6145 | VK_IMAGE_TILING_OPTIMAL, 0); |
| 6146 | ASSERT_TRUE(image.initialized()); |
| 6147 | |
| 6148 | VkBuffer buffer; |
| 6149 | VkDeviceMemory mem; |
| 6150 | VkMemoryRequirements mem_reqs; |
| 6151 | |
| 6152 | VkBufferCreateInfo buf_info = {}; |
| 6153 | buf_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO; |
| 6154 | buf_info.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT; |
| 6155 | buf_info.size = 256; |
| 6156 | buf_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE; |
| 6157 | VkResult err = vkCreateBuffer(m_device->device(), &buf_info, NULL, &buffer); |
| 6158 | ASSERT_VK_SUCCESS(err); |
| 6159 | |
| 6160 | vkGetBufferMemoryRequirements(m_device->device(), buffer, &mem_reqs); |
| 6161 | |
| 6162 | VkMemoryAllocateInfo alloc_info = {}; |
| 6163 | alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO; |
| 6164 | alloc_info.allocationSize = 256; |
| 6165 | bool pass = false; |
| 6166 | pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &alloc_info, |
| 6167 | VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT); |
| 6168 | if (!pass) { |
| 6169 | vkDestroyBuffer(m_device->device(), buffer, NULL); |
| 6170 | return; |
| 6171 | } |
| 6172 | err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem); |
| 6173 | ASSERT_VK_SUCCESS(err); |
| 6174 | |
| 6175 | err = vkBindBufferMemory(m_device->device(), buffer, mem, 0); |
| 6176 | ASSERT_VK_SUCCESS(err); |
| 6177 | |
| 6178 | VkBufferImageCopy region = {}; |
| 6179 | region.bufferRowLength = 128; |
| 6180 | region.bufferImageHeight = 128; |
| 6181 | region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; |
| 6182 | |
| 6183 | region.imageSubresource.layerCount = 1; |
| 6184 | region.imageExtent.height = 4; |
| 6185 | region.imageExtent.width = 4; |
| 6186 | region.imageExtent.depth = 1; |
| 6187 | m_commandBuffer->BeginCommandBuffer(); |
| 6188 | vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer, |
| 6189 | image.handle(), VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, |
| 6190 | 1, ®ion); |
| 6191 | m_commandBuffer->EndCommandBuffer(); |
| 6192 | |
| 6193 | m_errorMonitor->SetDesiredFailureMsg( |
| 6194 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 6195 | " that is invalid because bound buffer "); |
| 6196 | // Destroy buffer dependency prior to submit to cause ERROR |
| 6197 | vkDestroyBuffer(m_device->device(), buffer, NULL); |
| 6198 | |
| 6199 | VkSubmitInfo submit_info = {}; |
| 6200 | submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO; |
| 6201 | submit_info.commandBufferCount = 1; |
| 6202 | submit_info.pCommandBuffers = &m_commandBuffer->handle(); |
| 6203 | vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE); |
| 6204 | |
| 6205 | m_errorMonitor->VerifyFound(); |
| 6206 | vkFreeMemory(m_device->handle(), mem, NULL); |
| 6207 | } |
| 6208 | |
Tobin Ehlis | 11c8cea | 2016-06-28 17:44:21 -0600 | [diff] [blame] | 6209 | TEST_F(VkLayerTest, InvalidCmdBufferImageDestroyed) { |
| 6210 | TEST_DESCRIPTION("Attempt to draw with a command buffer that is invalid " |
| 6211 | "due to an image dependency being destroyed."); |
| 6212 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 6213 | |
| 6214 | VkImage image; |
| 6215 | const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM; |
| 6216 | VkImageCreateInfo image_create_info = {}; |
| 6217 | image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO; |
| 6218 | image_create_info.pNext = NULL; |
| 6219 | image_create_info.imageType = VK_IMAGE_TYPE_2D; |
| 6220 | image_create_info.format = tex_format; |
| 6221 | image_create_info.extent.width = 32; |
| 6222 | image_create_info.extent.height = 32; |
| 6223 | image_create_info.extent.depth = 1; |
| 6224 | image_create_info.mipLevels = 1; |
| 6225 | image_create_info.arrayLayers = 1; |
| 6226 | image_create_info.samples = VK_SAMPLE_COUNT_1_BIT; |
| 6227 | image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL; |
| 6228 | image_create_info.usage = |
| 6229 | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT; |
| 6230 | image_create_info.flags = 0; |
| 6231 | VkResult err = |
| 6232 | vkCreateImage(m_device->device(), &image_create_info, NULL, &image); |
| 6233 | ASSERT_VK_SUCCESS(err); |
Tobin Ehlis | 3d09fd5 | 2016-07-06 08:12:56 -0600 | [diff] [blame] | 6234 | // Have to bind memory to image before recording cmd in cmd buffer using it |
| 6235 | VkMemoryRequirements mem_reqs; |
| 6236 | VkDeviceMemory image_mem; |
| 6237 | bool pass; |
| 6238 | VkMemoryAllocateInfo mem_alloc = {}; |
| 6239 | mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO; |
| 6240 | mem_alloc.pNext = NULL; |
| 6241 | mem_alloc.memoryTypeIndex = 0; |
| 6242 | vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs); |
| 6243 | mem_alloc.allocationSize = mem_reqs.size; |
| 6244 | pass = |
| 6245 | m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0); |
| 6246 | ASSERT_TRUE(pass); |
| 6247 | err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &image_mem); |
| 6248 | ASSERT_VK_SUCCESS(err); |
| 6249 | err = vkBindImageMemory(m_device->device(), image, image_mem, 0); |
| 6250 | ASSERT_VK_SUCCESS(err); |
Tobin Ehlis | 11c8cea | 2016-06-28 17:44:21 -0600 | [diff] [blame] | 6251 | |
Tobin Ehlis | 11c8cea | 2016-06-28 17:44:21 -0600 | [diff] [blame] | 6252 | m_commandBuffer->BeginCommandBuffer(); |
Tobin Ehlis | 764d707 | 2016-07-01 12:54:29 -0600 | [diff] [blame] | 6253 | VkClearColorValue ccv; |
| 6254 | ccv.float32[0] = 1.0f; |
| 6255 | ccv.float32[1] = 1.0f; |
| 6256 | ccv.float32[2] = 1.0f; |
| 6257 | ccv.float32[3] = 1.0f; |
| 6258 | VkImageSubresourceRange isr = {}; |
| 6259 | isr.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; |
Tobin Ehlis | 3d09fd5 | 2016-07-06 08:12:56 -0600 | [diff] [blame] | 6260 | isr.baseArrayLayer = 0; |
| 6261 | isr.baseMipLevel = 0; |
Tobin Ehlis | 764d707 | 2016-07-01 12:54:29 -0600 | [diff] [blame] | 6262 | isr.layerCount = 1; |
| 6263 | isr.levelCount = 1; |
| 6264 | vkCmdClearColorImage(m_commandBuffer->GetBufferHandle(), image, |
| 6265 | VK_IMAGE_LAYOUT_GENERAL, &ccv, 1, &isr); |
Tobin Ehlis | 11c8cea | 2016-06-28 17:44:21 -0600 | [diff] [blame] | 6266 | m_commandBuffer->EndCommandBuffer(); |
| 6267 | |
| 6268 | m_errorMonitor->SetDesiredFailureMsg( |
| 6269 | VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound image "); |
| 6270 | // Destroy image dependency prior to submit to cause ERROR |
| 6271 | vkDestroyImage(m_device->device(), image, NULL); |
| 6272 | |
| 6273 | VkSubmitInfo submit_info = {}; |
| 6274 | submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO; |
| 6275 | submit_info.commandBufferCount = 1; |
| 6276 | submit_info.pCommandBuffers = &m_commandBuffer->handle(); |
| 6277 | vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE); |
| 6278 | |
| 6279 | m_errorMonitor->VerifyFound(); |
Tobin Ehlis | 3d09fd5 | 2016-07-06 08:12:56 -0600 | [diff] [blame] | 6280 | vkFreeMemory(m_device->device(), image_mem, nullptr); |
Tobin Ehlis | 11c8cea | 2016-06-28 17:44:21 -0600 | [diff] [blame] | 6281 | } |
| 6282 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6283 | TEST_F(VkLayerTest, InvalidPipeline) { |
Karl Schultz | bdb7595 | 2016-04-19 11:36:49 -0600 | [diff] [blame] | 6284 | // Attempt to bind an invalid Pipeline to a valid Command Buffer |
| 6285 | // ObjectTracker should catch this. |
Tobin Ehlis | 49eb23d | 2015-05-22 12:38:55 -0600 | [diff] [blame] | 6286 | // Create a valid cmd buffer |
| 6287 | // call vkCmdBindPipeline w/ false Pipeline |
Mark Lobodzinski | 02bf89d | 2016-05-10 14:45:13 -0600 | [diff] [blame] | 6288 | uint64_t fake_pipeline_handle = 0xbaad6001; |
| 6289 | VkPipeline bad_pipeline = reinterpret_cast<VkPipeline &>(fake_pipeline_handle); |
Karl Schultz | bdb7595 | 2016-04-19 11:36:49 -0600 | [diff] [blame] | 6290 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 6291 | "Invalid VkPipeline Object 0xbaad6001"); |
| 6292 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 6293 | BeginCommandBuffer(); |
| 6294 | vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), |
| 6295 | VK_PIPELINE_BIND_POINT_GRAPHICS, bad_pipeline); |
| 6296 | m_errorMonitor->VerifyFound(); |
Tobin Ehlis | b8b6b27 | 2016-05-02 13:26:06 -0600 | [diff] [blame] | 6297 | // Now issue a draw call with no pipeline bound |
| 6298 | m_errorMonitor->SetDesiredFailureMsg( |
| 6299 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 6300 | "At Draw/Dispatch time no valid VkPipeline is bound!"); |
Tony Barbour | df4c004 | 2016-06-01 15:55:43 -0600 | [diff] [blame] | 6301 | |
Tobin Ehlis | b8b6b27 | 2016-05-02 13:26:06 -0600 | [diff] [blame] | 6302 | BeginCommandBuffer(); |
| 6303 | Draw(1, 0, 0, 0); |
| 6304 | m_errorMonitor->VerifyFound(); |
| 6305 | // Finally same check once more but with Dispatch/Compute |
| 6306 | m_errorMonitor->SetDesiredFailureMsg( |
| 6307 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 6308 | "At Draw/Dispatch time no valid VkPipeline is bound!"); |
Tobin Ehlis | b8b6b27 | 2016-05-02 13:26:06 -0600 | [diff] [blame] | 6309 | BeginCommandBuffer(); |
| 6310 | vkCmdDispatch(m_commandBuffer->GetBufferHandle(), 0, 0, 0); |
| 6311 | m_errorMonitor->VerifyFound(); |
Tobin Ehlis | 49eb23d | 2015-05-22 12:38:55 -0600 | [diff] [blame] | 6312 | } |
| 6313 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6314 | TEST_F(VkLayerTest, DescriptorSetNotUpdated) { |
| 6315 | // Create and update CommandBuffer then call QueueSubmit w/o calling End on |
| 6316 | // CommandBuffer |
| 6317 | VkResult err; |
Tobin Ehlis | 7d1a711 | 2015-05-27 14:32:28 -0600 | [diff] [blame] | 6318 | |
Mark Lobodzinski | 510e20d | 2016-02-11 09:26:16 -0700 | [diff] [blame] | 6319 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6320 | " bound but it was never updated. "); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 6321 | |
Tobin Ehlis | 7d1a711 | 2015-05-27 14:32:28 -0600 | [diff] [blame] | 6322 | ASSERT_NO_FATAL_FAILURE(InitState()); |
Mike Stroyan | 713b2d7 | 2015-08-04 10:49:29 -0600 | [diff] [blame] | 6323 | ASSERT_NO_FATAL_FAILURE(InitViewport()); |
| 6324 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
Chia-I Wu | 1b99bb2 | 2015-10-27 19:25:11 +0800 | [diff] [blame] | 6325 | VkDescriptorPoolSize ds_type_count = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6326 | ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 6327 | ds_type_count.descriptorCount = 1; |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 6328 | |
| 6329 | VkDescriptorPoolCreateInfo ds_pool_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6330 | ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO; |
| 6331 | ds_pool_ci.pNext = NULL; |
| 6332 | ds_pool_ci.maxSets = 1; |
| 6333 | ds_pool_ci.poolSizeCount = 1; |
| 6334 | ds_pool_ci.pPoolSizes = &ds_type_count; |
Mike Stroyan | 713b2d7 | 2015-08-04 10:49:29 -0600 | [diff] [blame] | 6335 | |
Tobin Ehlis | 7d1a711 | 2015-05-27 14:32:28 -0600 | [diff] [blame] | 6336 | VkDescriptorPool ds_pool; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6337 | err = |
| 6338 | vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool); |
Tobin Ehlis | 7d1a711 | 2015-05-27 14:32:28 -0600 | [diff] [blame] | 6339 | ASSERT_VK_SUCCESS(err); |
Tobin Ehlis | 7d1a711 | 2015-05-27 14:32:28 -0600 | [diff] [blame] | 6340 | |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 6341 | VkDescriptorSetLayoutBinding dsl_binding = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6342 | dsl_binding.binding = 0; |
| 6343 | dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 6344 | dsl_binding.descriptorCount = 1; |
| 6345 | dsl_binding.stageFlags = VK_SHADER_STAGE_ALL; |
| 6346 | dsl_binding.pImmutableSamplers = NULL; |
Tobin Ehlis | 7d1a711 | 2015-05-27 14:32:28 -0600 | [diff] [blame] | 6347 | |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 6348 | VkDescriptorSetLayoutCreateInfo ds_layout_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6349 | ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO; |
| 6350 | ds_layout_ci.pNext = NULL; |
| 6351 | ds_layout_ci.bindingCount = 1; |
| 6352 | ds_layout_ci.pBindings = &dsl_binding; |
Tobin Ehlis | 7d1a711 | 2015-05-27 14:32:28 -0600 | [diff] [blame] | 6353 | VkDescriptorSetLayout ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6354 | err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, |
| 6355 | &ds_layout); |
Tobin Ehlis | 7d1a711 | 2015-05-27 14:32:28 -0600 | [diff] [blame] | 6356 | ASSERT_VK_SUCCESS(err); |
| 6357 | |
| 6358 | VkDescriptorSet descriptorSet; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 6359 | VkDescriptorSetAllocateInfo alloc_info = {}; |
Chia-I Wu | 00ce540 | 2015-11-10 16:21:09 +0800 | [diff] [blame] | 6360 | alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO; |
Jon Ashburn | f19916e | 2016-01-11 13:12:43 -0700 | [diff] [blame] | 6361 | alloc_info.descriptorSetCount = 1; |
Courtney Goeltzenleuchter | bee18a9 | 2015-10-23 14:21:05 -0600 | [diff] [blame] | 6362 | alloc_info.descriptorPool = ds_pool; |
| 6363 | alloc_info.pSetLayouts = &ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6364 | err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, |
| 6365 | &descriptorSet); |
Tobin Ehlis | 7d1a711 | 2015-05-27 14:32:28 -0600 | [diff] [blame] | 6366 | ASSERT_VK_SUCCESS(err); |
| 6367 | |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 6368 | VkPipelineLayoutCreateInfo pipeline_layout_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6369 | pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO; |
| 6370 | pipeline_layout_ci.pNext = NULL; |
| 6371 | pipeline_layout_ci.setLayoutCount = 1; |
| 6372 | pipeline_layout_ci.pSetLayouts = &ds_layout; |
Tobin Ehlis | 7d1a711 | 2015-05-27 14:32:28 -0600 | [diff] [blame] | 6373 | |
| 6374 | VkPipelineLayout pipeline_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6375 | err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, |
| 6376 | &pipeline_layout); |
Tobin Ehlis | 7d1a711 | 2015-05-27 14:32:28 -0600 | [diff] [blame] | 6377 | ASSERT_VK_SUCCESS(err); |
| 6378 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6379 | VkShaderObj vs(m_device, bindStateVertShaderText, |
| 6380 | VK_SHADER_STAGE_VERTEX_BIT, this); |
Karl Schultz | bdb7595 | 2016-04-19 11:36:49 -0600 | [diff] [blame] | 6381 | // 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] | 6382 | // on more devices |
| 6383 | VkShaderObj fs(m_device, bindStateFragShaderText, |
| 6384 | VK_SHADER_STAGE_FRAGMENT_BIT, this); |
Tobin Ehlis | 7d1a711 | 2015-05-27 14:32:28 -0600 | [diff] [blame] | 6385 | |
Tony Barbour | c95e4ac | 2015-08-04 17:05:26 -0600 | [diff] [blame] | 6386 | VkPipelineObj pipe(m_device); |
| 6387 | pipe.AddShader(&vs); |
Tony Barbour | 1c94d37 | 2015-08-06 11:21:08 -0600 | [diff] [blame] | 6388 | pipe.AddShader(&fs); |
Mark Young | c89c631 | 2016-03-31 16:03:20 -0600 | [diff] [blame] | 6389 | pipe.AddColorAttachment(); |
Tony Barbour | c95e4ac | 2015-08-04 17:05:26 -0600 | [diff] [blame] | 6390 | pipe.CreateVKPipeline(pipeline_layout, renderPass()); |
Tony Barbour | fe3351b | 2015-07-28 10:17:20 -0600 | [diff] [blame] | 6391 | |
| 6392 | BeginCommandBuffer(); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6393 | vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), |
| 6394 | VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle()); |
| 6395 | vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), |
| 6396 | VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, |
| 6397 | 1, &descriptorSet, 0, NULL); |
Tobin Ehlis | 7d1a711 | 2015-05-27 14:32:28 -0600 | [diff] [blame] | 6398 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 6399 | m_errorMonitor->VerifyFound(); |
Mike Stroyan | d1c84a5 | 2015-08-18 14:40:24 -0600 | [diff] [blame] | 6400 | |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 6401 | vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL); |
| 6402 | vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL); |
| 6403 | vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL); |
Tobin Ehlis | af1f3a4 | 2015-06-25 15:46:59 -0600 | [diff] [blame] | 6404 | } |
| 6405 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6406 | TEST_F(VkLayerTest, InvalidBufferViewObject) { |
Tobin Ehlis | ba31cab | 2015-11-02 15:24:32 -0700 | [diff] [blame] | 6407 | // Create a single TEXEL_BUFFER descriptor and send it an invalid bufferView |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6408 | VkResult err; |
Tobin Ehlis | ba31cab | 2015-11-02 15:24:32 -0700 | [diff] [blame] | 6409 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6410 | m_errorMonitor->SetDesiredFailureMsg( |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 6411 | VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attempted write update to texel buffer " |
| 6412 | "descriptor with invalid buffer view"); |
Tobin Ehlis | ba31cab | 2015-11-02 15:24:32 -0700 | [diff] [blame] | 6413 | |
| 6414 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 6415 | VkDescriptorPoolSize ds_type_count = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6416 | ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER; |
| 6417 | ds_type_count.descriptorCount = 1; |
Tobin Ehlis | ba31cab | 2015-11-02 15:24:32 -0700 | [diff] [blame] | 6418 | |
| 6419 | VkDescriptorPoolCreateInfo ds_pool_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6420 | ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO; |
| 6421 | ds_pool_ci.pNext = NULL; |
| 6422 | ds_pool_ci.maxSets = 1; |
| 6423 | ds_pool_ci.poolSizeCount = 1; |
| 6424 | ds_pool_ci.pPoolSizes = &ds_type_count; |
Tobin Ehlis | ba31cab | 2015-11-02 15:24:32 -0700 | [diff] [blame] | 6425 | |
| 6426 | VkDescriptorPool ds_pool; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6427 | err = |
| 6428 | vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool); |
Tobin Ehlis | ba31cab | 2015-11-02 15:24:32 -0700 | [diff] [blame] | 6429 | ASSERT_VK_SUCCESS(err); |
| 6430 | |
| 6431 | VkDescriptorSetLayoutBinding dsl_binding = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6432 | dsl_binding.binding = 0; |
| 6433 | dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER; |
| 6434 | dsl_binding.descriptorCount = 1; |
| 6435 | dsl_binding.stageFlags = VK_SHADER_STAGE_ALL; |
| 6436 | dsl_binding.pImmutableSamplers = NULL; |
Tobin Ehlis | ba31cab | 2015-11-02 15:24:32 -0700 | [diff] [blame] | 6437 | |
| 6438 | VkDescriptorSetLayoutCreateInfo ds_layout_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6439 | ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO; |
| 6440 | ds_layout_ci.pNext = NULL; |
| 6441 | ds_layout_ci.bindingCount = 1; |
| 6442 | ds_layout_ci.pBindings = &dsl_binding; |
Tobin Ehlis | ba31cab | 2015-11-02 15:24:32 -0700 | [diff] [blame] | 6443 | VkDescriptorSetLayout ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6444 | err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, |
| 6445 | &ds_layout); |
Tobin Ehlis | ba31cab | 2015-11-02 15:24:32 -0700 | [diff] [blame] | 6446 | ASSERT_VK_SUCCESS(err); |
| 6447 | |
| 6448 | VkDescriptorSet descriptorSet; |
| 6449 | VkDescriptorSetAllocateInfo alloc_info = {}; |
Chia-I Wu | 00ce540 | 2015-11-10 16:21:09 +0800 | [diff] [blame] | 6450 | alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO; |
Jon Ashburn | f19916e | 2016-01-11 13:12:43 -0700 | [diff] [blame] | 6451 | alloc_info.descriptorSetCount = 1; |
Tobin Ehlis | ba31cab | 2015-11-02 15:24:32 -0700 | [diff] [blame] | 6452 | alloc_info.descriptorPool = ds_pool; |
| 6453 | alloc_info.pSetLayouts = &ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6454 | err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, |
| 6455 | &descriptorSet); |
Tobin Ehlis | ba31cab | 2015-11-02 15:24:32 -0700 | [diff] [blame] | 6456 | ASSERT_VK_SUCCESS(err); |
| 6457 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6458 | VkBufferView view = |
| 6459 | (VkBufferView)((size_t)0xbaadbeef); // invalid bufferView object |
Tobin Ehlis | ba31cab | 2015-11-02 15:24:32 -0700 | [diff] [blame] | 6460 | VkWriteDescriptorSet descriptor_write; |
| 6461 | memset(&descriptor_write, 0, sizeof(descriptor_write)); |
| 6462 | descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET; |
| 6463 | descriptor_write.dstSet = descriptorSet; |
| 6464 | descriptor_write.dstBinding = 0; |
| 6465 | descriptor_write.descriptorCount = 1; |
| 6466 | descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER; |
| 6467 | descriptor_write.pTexelBufferView = &view; |
| 6468 | |
| 6469 | vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL); |
| 6470 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 6471 | m_errorMonitor->VerifyFound(); |
Tobin Ehlis | ba31cab | 2015-11-02 15:24:32 -0700 | [diff] [blame] | 6472 | |
| 6473 | vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL); |
| 6474 | vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL); |
| 6475 | } |
| 6476 | |
Mark Young | d339ba3 | 2016-05-30 13:28:35 -0600 | [diff] [blame] | 6477 | TEST_F(VkLayerTest, CreateBufferViewNoMemoryBoundToBuffer) { |
| 6478 | TEST_DESCRIPTION("Attempt to create a buffer view with a buffer that has" |
| 6479 | " no memory bound to it."); |
| 6480 | |
| 6481 | VkResult err; |
| 6482 | m_errorMonitor->SetDesiredFailureMsg( |
| 6483 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 6484 | "vkCreateBufferView called with invalid memory "); |
| 6485 | |
| 6486 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 6487 | |
| 6488 | // Create a buffer with no bound memory and then attempt to create |
| 6489 | // a buffer view. |
| 6490 | VkBufferCreateInfo buff_ci = {}; |
| 6491 | buff_ci.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO; |
| 6492 | buff_ci.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT; |
| 6493 | buff_ci.size = 256; |
| 6494 | buff_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE; |
| 6495 | VkBuffer buffer; |
| 6496 | err = vkCreateBuffer(m_device->device(), &buff_ci, NULL, &buffer); |
| 6497 | ASSERT_VK_SUCCESS(err); |
| 6498 | |
| 6499 | VkBufferViewCreateInfo buff_view_ci = {}; |
| 6500 | buff_view_ci.sType = VK_STRUCTURE_TYPE_BUFFER_VIEW_CREATE_INFO; |
| 6501 | buff_view_ci.buffer = buffer; |
| 6502 | buff_view_ci.format = VK_FORMAT_R8_UNORM; |
| 6503 | buff_view_ci.range = VK_WHOLE_SIZE; |
| 6504 | VkBufferView buff_view; |
| 6505 | err = |
| 6506 | vkCreateBufferView(m_device->device(), &buff_view_ci, NULL, &buff_view); |
| 6507 | |
| 6508 | m_errorMonitor->VerifyFound(); |
| 6509 | vkDestroyBuffer(m_device->device(), buffer, NULL); |
| 6510 | // If last error is success, it still created the view, so delete it. |
| 6511 | if (err == VK_SUCCESS) { |
| 6512 | vkDestroyBufferView(m_device->device(), buff_view, NULL); |
| 6513 | } |
| 6514 | } |
| 6515 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6516 | TEST_F(VkLayerTest, InvalidDynamicOffsetCases) { |
| 6517 | // Create a descriptorSet w/ dynamic descriptor and then hit 3 offset error |
| 6518 | // cases: |
Tobin Ehlis | f658505 | 2015-12-17 11:48:42 -0700 | [diff] [blame] | 6519 | // 1. No dynamicOffset supplied |
| 6520 | // 2. Too many dynamicOffsets supplied |
| 6521 | // 3. Dynamic offset oversteps buffer being updated |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6522 | VkResult err; |
Courtney Goeltzenleuchter | 7415d5a | 2015-12-09 15:48:16 -0700 | [diff] [blame] | 6523 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6524 | " requires 1 dynamicOffsets, but only " |
| 6525 | "0 dynamicOffsets are left in " |
| 6526 | "pDynamicOffsets "); |
Tobin Ehlis | 49f903e | 2015-11-04 13:30:34 -0700 | [diff] [blame] | 6527 | |
| 6528 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 6529 | ASSERT_NO_FATAL_FAILURE(InitViewport()); |
| 6530 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 6531 | |
| 6532 | VkDescriptorPoolSize ds_type_count = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6533 | ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC; |
| 6534 | ds_type_count.descriptorCount = 1; |
Tobin Ehlis | 49f903e | 2015-11-04 13:30:34 -0700 | [diff] [blame] | 6535 | |
| 6536 | VkDescriptorPoolCreateInfo ds_pool_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6537 | ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO; |
| 6538 | ds_pool_ci.pNext = NULL; |
| 6539 | ds_pool_ci.maxSets = 1; |
| 6540 | ds_pool_ci.poolSizeCount = 1; |
| 6541 | ds_pool_ci.pPoolSizes = &ds_type_count; |
Tobin Ehlis | 49f903e | 2015-11-04 13:30:34 -0700 | [diff] [blame] | 6542 | |
| 6543 | VkDescriptorPool ds_pool; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6544 | err = |
| 6545 | vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool); |
Tobin Ehlis | 49f903e | 2015-11-04 13:30:34 -0700 | [diff] [blame] | 6546 | ASSERT_VK_SUCCESS(err); |
| 6547 | |
| 6548 | VkDescriptorSetLayoutBinding dsl_binding = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6549 | dsl_binding.binding = 0; |
| 6550 | dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC; |
| 6551 | dsl_binding.descriptorCount = 1; |
| 6552 | dsl_binding.stageFlags = VK_SHADER_STAGE_ALL; |
| 6553 | dsl_binding.pImmutableSamplers = NULL; |
Tobin Ehlis | 49f903e | 2015-11-04 13:30:34 -0700 | [diff] [blame] | 6554 | |
| 6555 | VkDescriptorSetLayoutCreateInfo ds_layout_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6556 | ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO; |
| 6557 | ds_layout_ci.pNext = NULL; |
| 6558 | ds_layout_ci.bindingCount = 1; |
| 6559 | ds_layout_ci.pBindings = &dsl_binding; |
Tobin Ehlis | 49f903e | 2015-11-04 13:30:34 -0700 | [diff] [blame] | 6560 | VkDescriptorSetLayout ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6561 | err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, |
| 6562 | &ds_layout); |
Tobin Ehlis | 49f903e | 2015-11-04 13:30:34 -0700 | [diff] [blame] | 6563 | ASSERT_VK_SUCCESS(err); |
| 6564 | |
| 6565 | VkDescriptorSet descriptorSet; |
| 6566 | VkDescriptorSetAllocateInfo alloc_info = {}; |
Chia-I Wu | 00ce540 | 2015-11-10 16:21:09 +0800 | [diff] [blame] | 6567 | alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO; |
Jon Ashburn | f19916e | 2016-01-11 13:12:43 -0700 | [diff] [blame] | 6568 | alloc_info.descriptorSetCount = 1; |
Tobin Ehlis | 49f903e | 2015-11-04 13:30:34 -0700 | [diff] [blame] | 6569 | alloc_info.descriptorPool = ds_pool; |
| 6570 | alloc_info.pSetLayouts = &ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6571 | err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, |
| 6572 | &descriptorSet); |
Tobin Ehlis | 49f903e | 2015-11-04 13:30:34 -0700 | [diff] [blame] | 6573 | ASSERT_VK_SUCCESS(err); |
| 6574 | |
| 6575 | VkPipelineLayoutCreateInfo pipeline_layout_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6576 | pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO; |
| 6577 | pipeline_layout_ci.pNext = NULL; |
| 6578 | pipeline_layout_ci.setLayoutCount = 1; |
| 6579 | pipeline_layout_ci.pSetLayouts = &ds_layout; |
Tobin Ehlis | 49f903e | 2015-11-04 13:30:34 -0700 | [diff] [blame] | 6580 | |
| 6581 | VkPipelineLayout pipeline_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6582 | err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, |
| 6583 | &pipeline_layout); |
Tobin Ehlis | 49f903e | 2015-11-04 13:30:34 -0700 | [diff] [blame] | 6584 | ASSERT_VK_SUCCESS(err); |
| 6585 | |
| 6586 | // Create a buffer to update the descriptor with |
| 6587 | uint32_t qfi = 0; |
| 6588 | VkBufferCreateInfo buffCI = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6589 | buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO; |
| 6590 | buffCI.size = 1024; |
| 6591 | buffCI.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT; |
| 6592 | buffCI.queueFamilyIndexCount = 1; |
| 6593 | buffCI.pQueueFamilyIndices = &qfi; |
Tobin Ehlis | 49f903e | 2015-11-04 13:30:34 -0700 | [diff] [blame] | 6594 | |
| 6595 | VkBuffer dyub; |
| 6596 | err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &dyub); |
| 6597 | ASSERT_VK_SUCCESS(err); |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 6598 | // Allocate memory and bind to buffer so we can make it to the appropriate |
| 6599 | // error |
| 6600 | VkMemoryAllocateInfo mem_alloc = {}; |
| 6601 | mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO; |
| 6602 | mem_alloc.pNext = NULL; |
| 6603 | mem_alloc.allocationSize = 1024; |
Chris Forbes | b6116cc | 2016-05-08 11:39:59 +1200 | [diff] [blame] | 6604 | mem_alloc.memoryTypeIndex = 0; |
| 6605 | |
| 6606 | VkMemoryRequirements memReqs; |
| 6607 | vkGetBufferMemoryRequirements(m_device->device(), dyub, &memReqs); |
| 6608 | bool pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &mem_alloc, |
| 6609 | 0); |
| 6610 | if (!pass) { |
| 6611 | vkDestroyBuffer(m_device->device(), dyub, NULL); |
| 6612 | return; |
| 6613 | } |
| 6614 | |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 6615 | VkDeviceMemory mem; |
| 6616 | err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem); |
| 6617 | ASSERT_VK_SUCCESS(err); |
| 6618 | err = vkBindBufferMemory(m_device->device(), dyub, mem, 0); |
| 6619 | ASSERT_VK_SUCCESS(err); |
Tobin Ehlis | 49f903e | 2015-11-04 13:30:34 -0700 | [diff] [blame] | 6620 | // Correctly update descriptor to avoid "NOT_UPDATED" error |
| 6621 | VkDescriptorBufferInfo buffInfo = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6622 | buffInfo.buffer = dyub; |
| 6623 | buffInfo.offset = 0; |
| 6624 | buffInfo.range = 1024; |
Tobin Ehlis | 49f903e | 2015-11-04 13:30:34 -0700 | [diff] [blame] | 6625 | |
| 6626 | VkWriteDescriptorSet descriptor_write; |
| 6627 | memset(&descriptor_write, 0, sizeof(descriptor_write)); |
| 6628 | descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET; |
| 6629 | descriptor_write.dstSet = descriptorSet; |
| 6630 | descriptor_write.dstBinding = 0; |
| 6631 | descriptor_write.descriptorCount = 1; |
| 6632 | descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC; |
| 6633 | descriptor_write.pBufferInfo = &buffInfo; |
| 6634 | |
| 6635 | vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL); |
| 6636 | |
| 6637 | BeginCommandBuffer(); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6638 | vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), |
| 6639 | VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, |
| 6640 | 1, &descriptorSet, 0, NULL); |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 6641 | m_errorMonitor->VerifyFound(); |
Tobin Ehlis | f658505 | 2015-12-17 11:48:42 -0700 | [diff] [blame] | 6642 | uint32_t pDynOff[2] = {512, 756}; |
| 6643 | // 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] | 6644 | m_errorMonitor->SetDesiredFailureMsg( |
| 6645 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Tobin Ehlis | f658505 | 2015-12-17 11:48:42 -0700 | [diff] [blame] | 6646 | "Attempting to bind 1 descriptorSets with 1 dynamic descriptors, but "); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6647 | vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), |
| 6648 | VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, |
| 6649 | 1, &descriptorSet, 2, pDynOff); |
Chris Forbes | 7b34280 | 2016-04-07 13:20:10 +1200 | [diff] [blame] | 6650 | m_errorMonitor->VerifyFound(); |
Tobin Ehlis | f658505 | 2015-12-17 11:48:42 -0700 | [diff] [blame] | 6651 | // Finally cause error due to dynamicOffset being too big |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 6652 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 6653 | " dynamic offset 512 combined with " |
| 6654 | "offset 0 and range 1024 that " |
| 6655 | "oversteps the buffer size of 1024"); |
Tobin Ehlis | f658505 | 2015-12-17 11:48:42 -0700 | [diff] [blame] | 6656 | // Create PSO to be used for draw-time errors below |
| 6657 | char const *vsSource = |
Chris Forbes | 7b34280 | 2016-04-07 13:20:10 +1200 | [diff] [blame] | 6658 | "#version 450\n" |
Tobin Ehlis | f658505 | 2015-12-17 11:48:42 -0700 | [diff] [blame] | 6659 | "\n" |
Tony Barbour | e804d20 | 2016-01-05 13:37:45 -0700 | [diff] [blame] | 6660 | "out gl_PerVertex { \n" |
| 6661 | " vec4 gl_Position;\n" |
| 6662 | "};\n" |
Tobin Ehlis | f658505 | 2015-12-17 11:48:42 -0700 | [diff] [blame] | 6663 | "void main(){\n" |
| 6664 | " gl_Position = vec4(1);\n" |
| 6665 | "}\n"; |
| 6666 | char const *fsSource = |
Chris Forbes | 7b34280 | 2016-04-07 13:20:10 +1200 | [diff] [blame] | 6667 | "#version 450\n" |
Tobin Ehlis | f658505 | 2015-12-17 11:48:42 -0700 | [diff] [blame] | 6668 | "\n" |
| 6669 | "layout(location=0) out vec4 x;\n" |
| 6670 | "layout(set=0) layout(binding=0) uniform foo { int x; int y; } bar;\n" |
| 6671 | "void main(){\n" |
| 6672 | " x = vec4(bar.y);\n" |
| 6673 | "}\n"; |
| 6674 | VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this); |
| 6675 | VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this); |
| 6676 | VkPipelineObj pipe(m_device); |
| 6677 | pipe.AddShader(&vs); |
| 6678 | pipe.AddShader(&fs); |
| 6679 | pipe.AddColorAttachment(); |
| 6680 | pipe.CreateVKPipeline(pipeline_layout, renderPass()); |
| 6681 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6682 | vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), |
| 6683 | VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle()); |
| 6684 | // This update should succeed, but offset size of 512 will overstep buffer |
| 6685 | // /w range 1024 & size 1024 |
| 6686 | vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), |
| 6687 | VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, |
| 6688 | 1, &descriptorSet, 1, pDynOff); |
Tobin Ehlis | f658505 | 2015-12-17 11:48:42 -0700 | [diff] [blame] | 6689 | Draw(1, 0, 0, 0); |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 6690 | m_errorMonitor->VerifyFound(); |
Tobin Ehlis | 49f903e | 2015-11-04 13:30:34 -0700 | [diff] [blame] | 6691 | |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 6692 | vkDestroyBuffer(m_device->device(), dyub, NULL); |
Tobin Ehlis | 512098e | 2016-05-05 09:06:12 -0600 | [diff] [blame] | 6693 | vkFreeMemory(m_device->device(), mem, NULL); |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 6694 | |
Tobin Ehlis | 49f903e | 2015-11-04 13:30:34 -0700 | [diff] [blame] | 6695 | vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL); |
Tony Barbour | df4c004 | 2016-06-01 15:55:43 -0600 | [diff] [blame] | 6696 | vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL); |
Tobin Ehlis | 49f903e | 2015-11-04 13:30:34 -0700 | [diff] [blame] | 6697 | vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL); |
| 6698 | } |
| 6699 | |
Tobin Ehlis | 3a23b6a | 2016-02-17 10:35:18 -0700 | [diff] [blame] | 6700 | TEST_F(VkLayerTest, InvalidPushConstants) { |
Tobin Ehlis | 3a23b6a | 2016-02-17 10:35:18 -0700 | [diff] [blame] | 6701 | VkResult err; |
Tobin Ehlis | 3a23b6a | 2016-02-17 10:35:18 -0700 | [diff] [blame] | 6702 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 6703 | ASSERT_NO_FATAL_FAILURE(InitViewport()); |
| 6704 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 6705 | |
Karl Schultz | fc8eaf1 | 2016-05-06 13:56:42 -0600 | [diff] [blame] | 6706 | VkPipelineLayout pipeline_layout; |
Tobin Ehlis | 3a23b6a | 2016-02-17 10:35:18 -0700 | [diff] [blame] | 6707 | VkPushConstantRange pc_range = {}; |
Tobin Ehlis | 3a23b6a | 2016-02-17 10:35:18 -0700 | [diff] [blame] | 6708 | VkPipelineLayoutCreateInfo pipeline_layout_ci = {}; |
| 6709 | pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO; |
| 6710 | pipeline_layout_ci.pushConstantRangeCount = 1; |
| 6711 | pipeline_layout_ci.pPushConstantRanges = &pc_range; |
| 6712 | |
Karl Schultz | fc8eaf1 | 2016-05-06 13:56:42 -0600 | [diff] [blame] | 6713 | // |
| 6714 | // Check for invalid push constant ranges in pipeline layouts. |
| 6715 | // |
| 6716 | struct PipelineLayoutTestCase { |
Karl Schultz | c81037d | 2016-05-12 08:11:23 -0600 | [diff] [blame] | 6717 | VkPushConstantRange const range; |
Karl Schultz | fc8eaf1 | 2016-05-06 13:56:42 -0600 | [diff] [blame] | 6718 | char const *msg; |
| 6719 | }; |
Tobin Ehlis | 3a23b6a | 2016-02-17 10:35:18 -0700 | [diff] [blame] | 6720 | |
Karl Schultz | c81037d | 2016-05-12 08:11:23 -0600 | [diff] [blame] | 6721 | const uint32_t too_big = m_device->props.limits.maxPushConstantsSize + 0x4; |
| 6722 | const std::array<PipelineLayoutTestCase, 10> range_tests = {{ |
| 6723 | {{VK_SHADER_STAGE_VERTEX_BIT, 0, 0}, |
| 6724 | "vkCreatePipelineLayout() call has push constants index 0 with " |
| 6725 | "size 0."}, |
| 6726 | {{VK_SHADER_STAGE_VERTEX_BIT, 0, 1}, |
| 6727 | "vkCreatePipelineLayout() call has push constants index 0 with " |
| 6728 | "size 1."}, |
| 6729 | {{VK_SHADER_STAGE_VERTEX_BIT, 1, 1}, |
| 6730 | "vkCreatePipelineLayout() call has push constants index 0 with " |
| 6731 | "size 1."}, |
| 6732 | {{VK_SHADER_STAGE_VERTEX_BIT, 1, 0}, |
| 6733 | "vkCreatePipelineLayout() call has push constants index 0 with " |
| 6734 | "size 0."}, |
| 6735 | {{VK_SHADER_STAGE_VERTEX_BIT, 1, 4}, |
| 6736 | "vkCreatePipelineLayout() call has push constants index 0 with " |
| 6737 | "offset 1. Offset must"}, |
| 6738 | {{VK_SHADER_STAGE_VERTEX_BIT, 0, too_big}, |
| 6739 | "vkCreatePipelineLayout() call has push constants index 0 " |
| 6740 | "with offset "}, |
| 6741 | {{VK_SHADER_STAGE_VERTEX_BIT, too_big, too_big}, |
| 6742 | "vkCreatePipelineLayout() call has push constants " |
| 6743 | "index 0 with offset "}, |
| 6744 | {{VK_SHADER_STAGE_VERTEX_BIT, too_big, 0}, |
| 6745 | "vkCreatePipelineLayout() call has push constants index 0 " |
| 6746 | "with offset "}, |
| 6747 | {{VK_SHADER_STAGE_VERTEX_BIT, 0xFFFFFFF0, 0x00000020}, |
| 6748 | "vkCreatePipelineLayout() call has push " |
| 6749 | "constants index 0 with offset "}, |
| 6750 | {{VK_SHADER_STAGE_VERTEX_BIT, 0x00000020, 0xFFFFFFF0}, |
| 6751 | "vkCreatePipelineLayout() call has push " |
| 6752 | "constants index 0 with offset "}, |
Karl Schultz | fc8eaf1 | 2016-05-06 13:56:42 -0600 | [diff] [blame] | 6753 | }}; |
| 6754 | |
| 6755 | // Check for invalid offset and size |
Karl Schultz | c81037d | 2016-05-12 08:11:23 -0600 | [diff] [blame] | 6756 | for (const auto &iter : range_tests) { |
| 6757 | pc_range = iter.range; |
Karl Schultz | fc8eaf1 | 2016-05-06 13:56:42 -0600 | [diff] [blame] | 6758 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 6759 | iter.msg); |
| 6760 | err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, |
| 6761 | NULL, &pipeline_layout); |
| 6762 | m_errorMonitor->VerifyFound(); |
| 6763 | if (VK_SUCCESS == err) { |
| 6764 | vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL); |
| 6765 | } |
| 6766 | } |
| 6767 | |
| 6768 | // Check for invalid stage flag |
| 6769 | pc_range.offset = 0; |
| 6770 | pc_range.size = 16; |
| 6771 | pc_range.stageFlags = 0; |
Tobin Ehlis | 3a23b6a | 2016-02-17 10:35:18 -0700 | [diff] [blame] | 6772 | m_errorMonitor->SetDesiredFailureMsg( |
| 6773 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Karl Schultz | fc8eaf1 | 2016-05-06 13:56:42 -0600 | [diff] [blame] | 6774 | "vkCreatePipelineLayout() call has no stageFlags set."); |
Tobin Ehlis | 3a23b6a | 2016-02-17 10:35:18 -0700 | [diff] [blame] | 6775 | err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, |
| 6776 | &pipeline_layout); |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 6777 | m_errorMonitor->VerifyFound(); |
Karl Schultz | fc8eaf1 | 2016-05-06 13:56:42 -0600 | [diff] [blame] | 6778 | if (VK_SUCCESS == err) { |
| 6779 | vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL); |
| 6780 | } |
| 6781 | |
| 6782 | // Check for overlapping ranges |
Karl Schultz | c81037d | 2016-05-12 08:11:23 -0600 | [diff] [blame] | 6783 | const uint32_t ranges_per_test = 5; |
Karl Schultz | fc8eaf1 | 2016-05-06 13:56:42 -0600 | [diff] [blame] | 6784 | struct OverlappingRangeTestCase { |
Karl Schultz | c81037d | 2016-05-12 08:11:23 -0600 | [diff] [blame] | 6785 | VkPushConstantRange const ranges[ranges_per_test]; |
Karl Schultz | fc8eaf1 | 2016-05-06 13:56:42 -0600 | [diff] [blame] | 6786 | char const *msg; |
| 6787 | }; |
| 6788 | |
Karl Schultz | c81037d | 2016-05-12 08:11:23 -0600 | [diff] [blame] | 6789 | const std::array<OverlappingRangeTestCase, 5> overlapping_range_tests = { |
Karl Schultz | fc8eaf1 | 2016-05-06 13:56:42 -0600 | [diff] [blame] | 6790 | {{{{VK_SHADER_STAGE_VERTEX_BIT, 0, 4}, |
| 6791 | {VK_SHADER_STAGE_VERTEX_BIT, 0, 4}, |
| 6792 | {VK_SHADER_STAGE_VERTEX_BIT, 0, 4}, |
| 6793 | {VK_SHADER_STAGE_VERTEX_BIT, 0, 4}, |
| 6794 | {VK_SHADER_STAGE_VERTEX_BIT, 0, 4}}, |
| 6795 | "vkCreatePipelineLayout() call has push constants with overlapping " |
| 6796 | "ranges: 0:[0, 4), 1:[0, 4)"}, |
| 6797 | { |
| 6798 | {{VK_SHADER_STAGE_VERTEX_BIT, 0, 4}, |
| 6799 | {VK_SHADER_STAGE_VERTEX_BIT, 4, 4}, |
| 6800 | {VK_SHADER_STAGE_VERTEX_BIT, 8, 4}, |
| 6801 | {VK_SHADER_STAGE_VERTEX_BIT, 12, 8}, |
| 6802 | {VK_SHADER_STAGE_VERTEX_BIT, 16, 4}}, |
| 6803 | "vkCreatePipelineLayout() call has push constants with " |
| 6804 | "overlapping " |
| 6805 | "ranges: 3:[12, 20), 4:[16, 20)", |
| 6806 | }, |
| 6807 | { |
| 6808 | {{VK_SHADER_STAGE_VERTEX_BIT, 16, 4}, |
| 6809 | {VK_SHADER_STAGE_VERTEX_BIT, 12, 8}, |
| 6810 | {VK_SHADER_STAGE_VERTEX_BIT, 8, 4}, |
| 6811 | {VK_SHADER_STAGE_VERTEX_BIT, 4, 4}, |
| 6812 | {VK_SHADER_STAGE_VERTEX_BIT, 0, 4}}, |
| 6813 | "vkCreatePipelineLayout() call has push constants with " |
| 6814 | "overlapping " |
| 6815 | "ranges: 0:[16, 20), 1:[12, 20)", |
| 6816 | }, |
| 6817 | { |
| 6818 | {{VK_SHADER_STAGE_VERTEX_BIT, 16, 4}, |
| 6819 | {VK_SHADER_STAGE_VERTEX_BIT, 8, 4}, |
| 6820 | {VK_SHADER_STAGE_VERTEX_BIT, 4, 4}, |
| 6821 | {VK_SHADER_STAGE_VERTEX_BIT, 12, 8}, |
| 6822 | {VK_SHADER_STAGE_VERTEX_BIT, 0, 4}}, |
| 6823 | "vkCreatePipelineLayout() call has push constants with " |
| 6824 | "overlapping " |
| 6825 | "ranges: 0:[16, 20), 3:[12, 20)", |
| 6826 | }, |
| 6827 | { |
| 6828 | {{VK_SHADER_STAGE_VERTEX_BIT, 16, 4}, |
| 6829 | {VK_SHADER_STAGE_VERTEX_BIT, 32, 4}, |
| 6830 | {VK_SHADER_STAGE_VERTEX_BIT, 4, 96}, |
| 6831 | {VK_SHADER_STAGE_VERTEX_BIT, 40, 8}, |
| 6832 | {VK_SHADER_STAGE_VERTEX_BIT, 52, 4}}, |
| 6833 | "vkCreatePipelineLayout() call has push constants with " |
| 6834 | "overlapping " |
| 6835 | "ranges: 0:[16, 20), 2:[4, 100)", |
| 6836 | }}}; |
Karl Schultz | fc8eaf1 | 2016-05-06 13:56:42 -0600 | [diff] [blame] | 6837 | |
Karl Schultz | c81037d | 2016-05-12 08:11:23 -0600 | [diff] [blame] | 6838 | for (const auto &iter : overlapping_range_tests) { |
Karl Schultz | fc8eaf1 | 2016-05-06 13:56:42 -0600 | [diff] [blame] | 6839 | pipeline_layout_ci.pPushConstantRanges = iter.ranges; |
Karl Schultz | c81037d | 2016-05-12 08:11:23 -0600 | [diff] [blame] | 6840 | pipeline_layout_ci.pushConstantRangeCount = ranges_per_test; |
| 6841 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, |
Karl Schultz | fc8eaf1 | 2016-05-06 13:56:42 -0600 | [diff] [blame] | 6842 | iter.msg); |
| 6843 | err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, |
| 6844 | NULL, &pipeline_layout); |
| 6845 | m_errorMonitor->VerifyFound(); |
| 6846 | if (VK_SUCCESS == err) { |
| 6847 | vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL); |
| 6848 | } |
| 6849 | } |
| 6850 | |
| 6851 | // 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] | 6852 | const std::array<OverlappingRangeTestCase, 2> overlapping_range_tests_pos = |
| 6853 | {{{{{VK_SHADER_STAGE_VERTEX_BIT, 0, 4}, |
| 6854 | {VK_SHADER_STAGE_VERTEX_BIT, 4, 4}, |
| 6855 | {VK_SHADER_STAGE_VERTEX_BIT, 8, 4}, |
| 6856 | {VK_SHADER_STAGE_VERTEX_BIT, 12, 4}, |
| 6857 | {VK_SHADER_STAGE_VERTEX_BIT, 16, 4}}, |
| 6858 | ""}, |
| 6859 | {{{VK_SHADER_STAGE_VERTEX_BIT, 92, 24}, |
| 6860 | {VK_SHADER_STAGE_VERTEX_BIT, 80, 4}, |
| 6861 | {VK_SHADER_STAGE_VERTEX_BIT, 64, 8}, |
| 6862 | {VK_SHADER_STAGE_VERTEX_BIT, 4, 16}, |
| 6863 | {VK_SHADER_STAGE_VERTEX_BIT, 0, 4}}, |
| 6864 | ""}}}; |
| 6865 | for (const auto &iter : overlapping_range_tests_pos) { |
Karl Schultz | fc8eaf1 | 2016-05-06 13:56:42 -0600 | [diff] [blame] | 6866 | pipeline_layout_ci.pPushConstantRanges = iter.ranges; |
| 6867 | m_errorMonitor->ExpectSuccess(); |
| 6868 | err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, |
| 6869 | NULL, &pipeline_layout); |
| 6870 | m_errorMonitor->VerifyNotFound(); |
| 6871 | if (VK_SUCCESS == err) { |
| 6872 | vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL); |
| 6873 | } |
| 6874 | } |
| 6875 | |
| 6876 | // |
| 6877 | // CmdPushConstants tests |
| 6878 | // |
Karl Schultz | c81037d | 2016-05-12 08:11:23 -0600 | [diff] [blame] | 6879 | const uint8_t dummy_values[100] = {}; |
Karl Schultz | fc8eaf1 | 2016-05-06 13:56:42 -0600 | [diff] [blame] | 6880 | |
| 6881 | // 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] | 6882 | const std::array<PipelineLayoutTestCase, 16> cmd_range_tests = {{ |
| 6883 | {{VK_SHADER_STAGE_VERTEX_BIT, 0, 0}, |
| 6884 | "vkCmdPushConstants() call has push constants with size 0. Size " |
| 6885 | "must be greater than zero and a multiple of 4."}, |
| 6886 | {{VK_SHADER_STAGE_VERTEX_BIT, 0, 1}, |
| 6887 | "vkCmdPushConstants() call has push constants with size 1. Size " |
| 6888 | "must be greater than zero and a multiple of 4."}, |
| 6889 | {{VK_SHADER_STAGE_VERTEX_BIT, 1, 1}, |
| 6890 | "vkCmdPushConstants() call has push constants with size 1. Size " |
| 6891 | "must be greater than zero and a multiple of 4."}, |
| 6892 | {{VK_SHADER_STAGE_VERTEX_BIT, 1, 0}, |
| 6893 | "vkCmdPushConstants() call has push constants with offset 1. " |
| 6894 | "Offset must be a multiple of 4."}, |
| 6895 | {{VK_SHADER_STAGE_VERTEX_BIT, 1, 4}, |
| 6896 | "vkCmdPushConstants() call has push constants with offset 1. " |
| 6897 | "Offset must be a multiple of 4."}, |
| 6898 | {{VK_SHADER_STAGE_VERTEX_BIT, 0, 20}, |
| 6899 | "vkCmdPushConstants() Push constant range [0, 20) with stageFlags = " |
| 6900 | "0x1 not within flag-matching ranges in pipeline layout"}, |
| 6901 | {{VK_SHADER_STAGE_VERTEX_BIT, 60, 8}, |
| 6902 | "vkCmdPushConstants() Push constant range [60, 68) with stageFlags = " |
| 6903 | "0x1 not within flag-matching ranges in pipeline layout"}, |
| 6904 | {{VK_SHADER_STAGE_VERTEX_BIT, 76, 8}, |
| 6905 | "vkCmdPushConstants() Push constant range [76, 84) with stageFlags = " |
| 6906 | "0x1 not within flag-matching ranges in pipeline layout"}, |
| 6907 | {{VK_SHADER_STAGE_VERTEX_BIT, 0, 80}, |
| 6908 | "vkCmdPushConstants() Push constant range [0, 80) with stageFlags = " |
| 6909 | "0x1 not within flag-matching ranges in pipeline layout"}, |
| 6910 | {{VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT, 0, 4}, |
| 6911 | "vkCmdPushConstants() stageFlags = 0x2 do not match the stageFlags in " |
| 6912 | "any of the ranges in pipeline layout"}, |
| 6913 | {{VK_SHADER_STAGE_VERTEX_BIT | VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT, |
| 6914 | 0, 16}, |
| 6915 | "vkCmdPushConstants() stageFlags = 0x3 do not match the stageFlags in " |
| 6916 | "any of the ranges in pipeline layout"}, |
| 6917 | {{VK_SHADER_STAGE_VERTEX_BIT, 0, too_big}, |
Karl Schultz | fc8eaf1 | 2016-05-06 13:56:42 -0600 | [diff] [blame] | 6918 | "vkCmdPushConstants() call has push constants with offset "}, |
Karl Schultz | c81037d | 2016-05-12 08:11:23 -0600 | [diff] [blame] | 6919 | {{VK_SHADER_STAGE_VERTEX_BIT, too_big, too_big}, |
Karl Schultz | fc8eaf1 | 2016-05-06 13:56:42 -0600 | [diff] [blame] | 6920 | "vkCmdPushConstants() call has push constants with offset "}, |
Karl Schultz | c81037d | 2016-05-12 08:11:23 -0600 | [diff] [blame] | 6921 | {{VK_SHADER_STAGE_VERTEX_BIT, too_big, 0}, |
Karl Schultz | fc8eaf1 | 2016-05-06 13:56:42 -0600 | [diff] [blame] | 6922 | "vkCmdPushConstants() call has push constants with offset "}, |
Karl Schultz | c81037d | 2016-05-12 08:11:23 -0600 | [diff] [blame] | 6923 | {{VK_SHADER_STAGE_VERTEX_BIT, 0xFFFFFFF0, 0x00000020}, |
Karl Schultz | fc8eaf1 | 2016-05-06 13:56:42 -0600 | [diff] [blame] | 6924 | "vkCmdPushConstants() call has push constants with offset "}, |
Karl Schultz | c81037d | 2016-05-12 08:11:23 -0600 | [diff] [blame] | 6925 | {{VK_SHADER_STAGE_VERTEX_BIT, 0x00000020, 0xFFFFFFF0}, |
Karl Schultz | fc8eaf1 | 2016-05-06 13:56:42 -0600 | [diff] [blame] | 6926 | "vkCmdPushConstants() call has push constants with offset "}, |
| 6927 | }}; |
| 6928 | |
| 6929 | // Two ranges for testing robustness |
Karl Schultz | c81037d | 2016-05-12 08:11:23 -0600 | [diff] [blame] | 6930 | const VkPushConstantRange pc_range2[] = { |
Karl Schultz | fc8eaf1 | 2016-05-06 13:56:42 -0600 | [diff] [blame] | 6931 | {VK_SHADER_STAGE_VERTEX_BIT, 64, 16}, |
Karl Schultz | c81037d | 2016-05-12 08:11:23 -0600 | [diff] [blame] | 6932 | {VK_SHADER_STAGE_VERTEX_BIT, 0, 16}, |
Karl Schultz | fc8eaf1 | 2016-05-06 13:56:42 -0600 | [diff] [blame] | 6933 | }; |
Karl Schultz | c81037d | 2016-05-12 08:11:23 -0600 | [diff] [blame] | 6934 | pipeline_layout_ci.pushConstantRangeCount = |
| 6935 | sizeof(pc_range2) / sizeof(VkPushConstantRange); |
Karl Schultz | fc8eaf1 | 2016-05-06 13:56:42 -0600 | [diff] [blame] | 6936 | pipeline_layout_ci.pPushConstantRanges = pc_range2; |
Tobin Ehlis | 3a23b6a | 2016-02-17 10:35:18 -0700 | [diff] [blame] | 6937 | err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, |
| 6938 | &pipeline_layout); |
| 6939 | ASSERT_VK_SUCCESS(err); |
| 6940 | BeginCommandBuffer(); |
Karl Schultz | c81037d | 2016-05-12 08:11:23 -0600 | [diff] [blame] | 6941 | for (const auto &iter : cmd_range_tests) { |
Karl Schultz | fc8eaf1 | 2016-05-06 13:56:42 -0600 | [diff] [blame] | 6942 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 6943 | iter.msg); |
| 6944 | vkCmdPushConstants(m_commandBuffer->GetBufferHandle(), pipeline_layout, |
Karl Schultz | c81037d | 2016-05-12 08:11:23 -0600 | [diff] [blame] | 6945 | iter.range.stageFlags, iter.range.offset, |
| 6946 | iter.range.size, dummy_values); |
Karl Schultz | fc8eaf1 | 2016-05-06 13:56:42 -0600 | [diff] [blame] | 6947 | m_errorMonitor->VerifyFound(); |
| 6948 | } |
| 6949 | |
| 6950 | // Check for invalid stage flag |
| 6951 | m_errorMonitor->SetDesiredFailureMsg( |
| 6952 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 6953 | "vkCmdPushConstants() call has no stageFlags set."); |
| 6954 | vkCmdPushConstants(m_commandBuffer->GetBufferHandle(), pipeline_layout, 0, |
Karl Schultz | c81037d | 2016-05-12 08:11:23 -0600 | [diff] [blame] | 6955 | 0, 16, dummy_values); |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 6956 | m_errorMonitor->VerifyFound(); |
Karl Schultz | c81037d | 2016-05-12 08:11:23 -0600 | [diff] [blame] | 6957 | EndCommandBuffer(); |
| 6958 | vkResetCommandBuffer(m_commandBuffer->GetBufferHandle(), 0); |
| 6959 | vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL); |
Karl Schultz | fc8eaf1 | 2016-05-06 13:56:42 -0600 | [diff] [blame] | 6960 | |
Karl Schultz | c81037d | 2016-05-12 08:11:23 -0600 | [diff] [blame] | 6961 | // overlapping range tests with cmd |
| 6962 | const std::array<PipelineLayoutTestCase, 3> cmd_overlap_tests = {{ |
| 6963 | {{VK_SHADER_STAGE_VERTEX_BIT, 0, 20}, |
| 6964 | "vkCmdPushConstants() Push constant range [0, 20) with stageFlags = " |
| 6965 | "0x1 not within flag-matching ranges in pipeline layout"}, |
| 6966 | {{VK_SHADER_STAGE_VERTEX_BIT, 16, 4}, |
| 6967 | "vkCmdPushConstants() Push constant range [16, 20) with stageFlags = " |
| 6968 | "0x1 not within flag-matching ranges in pipeline layout"}, |
| 6969 | {{VK_SHADER_STAGE_VERTEX_BIT, 40, 16}, |
| 6970 | "vkCmdPushConstants() Push constant range [40, 56) with stageFlags = " |
| 6971 | "0x1 not within flag-matching ranges in pipeline layout"}, |
| 6972 | }}; |
| 6973 | const VkPushConstantRange pc_range3[] = { |
| 6974 | {VK_SHADER_STAGE_VERTEX_BIT, 20, 16}, |
| 6975 | {VK_SHADER_STAGE_VERTEX_BIT, 0, 16}, |
| 6976 | {VK_SHADER_STAGE_VERTEX_BIT, 0, 4}, |
| 6977 | {VK_SHADER_STAGE_VERTEX_BIT, 44, 8}, |
| 6978 | {VK_SHADER_STAGE_VERTEX_BIT, 80, 12}, |
| 6979 | {VK_SHADER_STAGE_VERTEX_BIT, 36, 8}, |
| 6980 | {VK_SHADER_STAGE_VERTEX_BIT, 56, 28}, |
| 6981 | }; |
| 6982 | pipeline_layout_ci.pushConstantRangeCount = |
| 6983 | sizeof(pc_range3) / sizeof(VkPushConstantRange); |
| 6984 | pipeline_layout_ci.pPushConstantRanges = pc_range3; |
| 6985 | err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, |
| 6986 | &pipeline_layout); |
| 6987 | ASSERT_VK_SUCCESS(err); |
| 6988 | BeginCommandBuffer(); |
| 6989 | for (const auto &iter : cmd_overlap_tests) { |
| 6990 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 6991 | iter.msg); |
| 6992 | vkCmdPushConstants(m_commandBuffer->GetBufferHandle(), pipeline_layout, |
| 6993 | iter.range.stageFlags, iter.range.offset, |
| 6994 | iter.range.size, dummy_values); |
| 6995 | m_errorMonitor->VerifyFound(); |
| 6996 | } |
| 6997 | EndCommandBuffer(); |
| 6998 | vkResetCommandBuffer(m_commandBuffer->GetBufferHandle(), 0); |
| 6999 | vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL); |
| 7000 | |
| 7001 | // positive overlapping range tests with cmd |
| 7002 | const std::array<PipelineLayoutTestCase, 4> cmd_overlap_tests_pos = {{ |
| 7003 | {{VK_SHADER_STAGE_VERTEX_BIT, 0, 16}, ""}, |
| 7004 | {{VK_SHADER_STAGE_VERTEX_BIT, 0, 4}, ""}, |
| 7005 | {{VK_SHADER_STAGE_VERTEX_BIT, 20, 12}, ""}, |
| 7006 | {{VK_SHADER_STAGE_VERTEX_BIT, 56, 36}, ""}, |
| 7007 | }}; |
| 7008 | const VkPushConstantRange pc_range4[] = { |
| 7009 | {VK_SHADER_STAGE_VERTEX_BIT, 0, 64}, |
| 7010 | {VK_SHADER_STAGE_VERTEX_BIT, 20, 16}, |
| 7011 | {VK_SHADER_STAGE_VERTEX_BIT, 0, 16}, |
| 7012 | {VK_SHADER_STAGE_VERTEX_BIT, 0, 4}, |
| 7013 | {VK_SHADER_STAGE_VERTEX_BIT, 44, 8}, |
| 7014 | {VK_SHADER_STAGE_VERTEX_BIT, 80, 12}, |
| 7015 | {VK_SHADER_STAGE_VERTEX_BIT, 36, 8}, |
| 7016 | {VK_SHADER_STAGE_VERTEX_BIT, 56, 28}, |
| 7017 | }; |
| 7018 | pipeline_layout_ci.pushConstantRangeCount = |
| 7019 | sizeof(pc_range4) / sizeof(VkPushConstantRange); |
| 7020 | pipeline_layout_ci.pPushConstantRanges = pc_range4; |
| 7021 | err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, |
| 7022 | &pipeline_layout); |
| 7023 | ASSERT_VK_SUCCESS(err); |
| 7024 | BeginCommandBuffer(); |
| 7025 | for (const auto &iter : cmd_overlap_tests_pos) { |
| 7026 | m_errorMonitor->ExpectSuccess(); |
| 7027 | vkCmdPushConstants(m_commandBuffer->GetBufferHandle(), pipeline_layout, |
| 7028 | iter.range.stageFlags, iter.range.offset, |
| 7029 | iter.range.size, dummy_values); |
| 7030 | m_errorMonitor->VerifyNotFound(); |
| 7031 | } |
| 7032 | EndCommandBuffer(); |
| 7033 | vkResetCommandBuffer(m_commandBuffer->GetBufferHandle(), 0); |
Tobin Ehlis | 3a23b6a | 2016-02-17 10:35:18 -0700 | [diff] [blame] | 7034 | vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL); |
| 7035 | } |
| 7036 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7037 | TEST_F(VkLayerTest, DescriptorSetCompatibility) { |
Tobin Ehlis | 559c638 | 2015-11-05 09:52:49 -0700 | [diff] [blame] | 7038 | // Test various desriptorSet errors with bad binding combinations |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7039 | VkResult err; |
Tobin Ehlis | 559c638 | 2015-11-05 09:52:49 -0700 | [diff] [blame] | 7040 | |
| 7041 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 7042 | ASSERT_NO_FATAL_FAILURE(InitViewport()); |
| 7043 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 7044 | |
Mike Stroyan | b8a6100 | 2016-06-20 16:00:28 -0600 | [diff] [blame] | 7045 | const VkFormat tex_format = VK_FORMAT_R8G8B8A8_UNORM; |
| 7046 | VkImageTiling tiling; |
| 7047 | VkFormatProperties format_properties; |
| 7048 | vkGetPhysicalDeviceFormatProperties(gpu(), tex_format, &format_properties); |
| 7049 | if (format_properties.linearTilingFeatures & |
| 7050 | VK_FORMAT_FEATURE_STORAGE_IMAGE_BIT) { |
| 7051 | tiling = VK_IMAGE_TILING_LINEAR; |
| 7052 | } else if (format_properties.optimalTilingFeatures & |
| 7053 | VK_FORMAT_FEATURE_STORAGE_IMAGE_BIT) { |
| 7054 | tiling = VK_IMAGE_TILING_OPTIMAL; |
| 7055 | } else { |
| 7056 | printf("Device does not support VK_FORMAT_FEATURE_STORAGE_IMAGE_BIT; " |
| 7057 | "skipped.\n"); |
| 7058 | return; |
| 7059 | } |
| 7060 | |
Tobin Ehlis | 559c638 | 2015-11-05 09:52:49 -0700 | [diff] [blame] | 7061 | static const uint32_t NUM_DESCRIPTOR_TYPES = 5; |
| 7062 | VkDescriptorPoolSize ds_type_count[NUM_DESCRIPTOR_TYPES] = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7063 | ds_type_count[0].type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 7064 | ds_type_count[0].descriptorCount = 10; |
| 7065 | ds_type_count[1].type = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE; |
| 7066 | ds_type_count[1].descriptorCount = 2; |
| 7067 | ds_type_count[2].type = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE; |
| 7068 | ds_type_count[2].descriptorCount = 2; |
| 7069 | ds_type_count[3].type = VK_DESCRIPTOR_TYPE_SAMPLER; |
| 7070 | ds_type_count[3].descriptorCount = 5; |
| 7071 | // TODO : LunarG ILO driver currently asserts in desc.c w/ INPUT_ATTACHMENT |
| 7072 | // type |
| 7073 | // ds_type_count[4].type = VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT; |
| 7074 | ds_type_count[4].type = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER; |
| 7075 | ds_type_count[4].descriptorCount = 2; |
Tobin Ehlis | 559c638 | 2015-11-05 09:52:49 -0700 | [diff] [blame] | 7076 | |
| 7077 | VkDescriptorPoolCreateInfo ds_pool_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7078 | ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO; |
| 7079 | ds_pool_ci.pNext = NULL; |
| 7080 | ds_pool_ci.maxSets = 5; |
| 7081 | ds_pool_ci.poolSizeCount = NUM_DESCRIPTOR_TYPES; |
| 7082 | ds_pool_ci.pPoolSizes = ds_type_count; |
Tobin Ehlis | 559c638 | 2015-11-05 09:52:49 -0700 | [diff] [blame] | 7083 | |
| 7084 | VkDescriptorPool ds_pool; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7085 | err = |
| 7086 | vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool); |
Tobin Ehlis | 559c638 | 2015-11-05 09:52:49 -0700 | [diff] [blame] | 7087 | ASSERT_VK_SUCCESS(err); |
| 7088 | |
| 7089 | static const uint32_t MAX_DS_TYPES_IN_LAYOUT = 2; |
| 7090 | VkDescriptorSetLayoutBinding dsl_binding[MAX_DS_TYPES_IN_LAYOUT] = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7091 | dsl_binding[0].binding = 0; |
| 7092 | dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 7093 | dsl_binding[0].descriptorCount = 5; |
| 7094 | dsl_binding[0].stageFlags = VK_SHADER_STAGE_ALL; |
| 7095 | dsl_binding[0].pImmutableSamplers = NULL; |
Tobin Ehlis | 559c638 | 2015-11-05 09:52:49 -0700 | [diff] [blame] | 7096 | |
Tobin Ehlis | 8fab656 | 2015-12-01 09:57:09 -0700 | [diff] [blame] | 7097 | // Create layout identical to set0 layout but w/ different stageFlags |
| 7098 | VkDescriptorSetLayoutBinding dsl_fs_stage_only = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7099 | dsl_fs_stage_only.binding = 0; |
| 7100 | dsl_fs_stage_only.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 7101 | dsl_fs_stage_only.descriptorCount = 5; |
| 7102 | dsl_fs_stage_only.stageFlags = |
| 7103 | VK_SHADER_STAGE_FRAGMENT_BIT; // Different stageFlags to cause error at |
| 7104 | // bind time |
| 7105 | dsl_fs_stage_only.pImmutableSamplers = NULL; |
Tobin Ehlis | 559c638 | 2015-11-05 09:52:49 -0700 | [diff] [blame] | 7106 | VkDescriptorSetLayoutCreateInfo ds_layout_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7107 | ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO; |
| 7108 | ds_layout_ci.pNext = NULL; |
| 7109 | ds_layout_ci.bindingCount = 1; |
| 7110 | ds_layout_ci.pBindings = dsl_binding; |
Tobin Ehlis | 559c638 | 2015-11-05 09:52:49 -0700 | [diff] [blame] | 7111 | static const uint32_t NUM_LAYOUTS = 4; |
| 7112 | VkDescriptorSetLayout ds_layout[NUM_LAYOUTS] = {}; |
Tobin Ehlis | 8fab656 | 2015-12-01 09:57:09 -0700 | [diff] [blame] | 7113 | VkDescriptorSetLayout ds_layout_fs_only = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7114 | // Create 4 unique layouts for full pipelineLayout, and 1 special fs-only |
| 7115 | // layout for error case |
| 7116 | err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, |
| 7117 | &ds_layout[0]); |
Tobin Ehlis | 559c638 | 2015-11-05 09:52:49 -0700 | [diff] [blame] | 7118 | ASSERT_VK_SUCCESS(err); |
Jon Ashburn | 6e23c1f | 2015-12-30 18:01:16 -0700 | [diff] [blame] | 7119 | ds_layout_ci.pBindings = &dsl_fs_stage_only; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7120 | err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, |
| 7121 | &ds_layout_fs_only); |
Tobin Ehlis | 8fab656 | 2015-12-01 09:57:09 -0700 | [diff] [blame] | 7122 | ASSERT_VK_SUCCESS(err); |
Tobin Ehlis | 559c638 | 2015-11-05 09:52:49 -0700 | [diff] [blame] | 7123 | dsl_binding[0].binding = 0; |
| 7124 | dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE; |
Tobin Ehlis | 8fab656 | 2015-12-01 09:57:09 -0700 | [diff] [blame] | 7125 | dsl_binding[0].descriptorCount = 2; |
Mike Stroyan | 9c70cdb | 2016-01-06 14:14:17 -0700 | [diff] [blame] | 7126 | dsl_binding[1].binding = 1; |
| 7127 | dsl_binding[1].descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE; |
| 7128 | dsl_binding[1].descriptorCount = 2; |
| 7129 | dsl_binding[1].stageFlags = VK_SHADER_STAGE_ALL; |
| 7130 | dsl_binding[1].pImmutableSamplers = NULL; |
Jon Ashburn | 6e23c1f | 2015-12-30 18:01:16 -0700 | [diff] [blame] | 7131 | ds_layout_ci.pBindings = dsl_binding; |
Tobin Ehlis | 559c638 | 2015-11-05 09:52:49 -0700 | [diff] [blame] | 7132 | ds_layout_ci.bindingCount = 2; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7133 | err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, |
| 7134 | &ds_layout[1]); |
Tobin Ehlis | 559c638 | 2015-11-05 09:52:49 -0700 | [diff] [blame] | 7135 | ASSERT_VK_SUCCESS(err); |
| 7136 | dsl_binding[0].binding = 0; |
| 7137 | dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER; |
Tobin Ehlis | 8fab656 | 2015-12-01 09:57:09 -0700 | [diff] [blame] | 7138 | dsl_binding[0].descriptorCount = 5; |
Tobin Ehlis | 559c638 | 2015-11-05 09:52:49 -0700 | [diff] [blame] | 7139 | ds_layout_ci.bindingCount = 1; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7140 | err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, |
| 7141 | &ds_layout[2]); |
Tobin Ehlis | 559c638 | 2015-11-05 09:52:49 -0700 | [diff] [blame] | 7142 | ASSERT_VK_SUCCESS(err); |
| 7143 | dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER; |
Tobin Ehlis | 8fab656 | 2015-12-01 09:57:09 -0700 | [diff] [blame] | 7144 | dsl_binding[0].descriptorCount = 2; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7145 | err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, |
| 7146 | &ds_layout[3]); |
Tobin Ehlis | 559c638 | 2015-11-05 09:52:49 -0700 | [diff] [blame] | 7147 | ASSERT_VK_SUCCESS(err); |
| 7148 | |
| 7149 | static const uint32_t NUM_SETS = 4; |
| 7150 | VkDescriptorSet descriptorSet[NUM_SETS] = {}; |
| 7151 | VkDescriptorSetAllocateInfo alloc_info = {}; |
Tobin Ehlis | 8fab656 | 2015-12-01 09:57:09 -0700 | [diff] [blame] | 7152 | alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO; |
Jon Ashburn | f19916e | 2016-01-11 13:12:43 -0700 | [diff] [blame] | 7153 | alloc_info.descriptorSetCount = NUM_LAYOUTS; |
Tobin Ehlis | 559c638 | 2015-11-05 09:52:49 -0700 | [diff] [blame] | 7154 | alloc_info.descriptorPool = ds_pool; |
| 7155 | alloc_info.pSetLayouts = ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7156 | err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, |
| 7157 | descriptorSet); |
Tobin Ehlis | 559c638 | 2015-11-05 09:52:49 -0700 | [diff] [blame] | 7158 | ASSERT_VK_SUCCESS(err); |
Tobin Ehlis | 8fab656 | 2015-12-01 09:57:09 -0700 | [diff] [blame] | 7159 | VkDescriptorSet ds0_fs_only = {}; |
Jon Ashburn | f19916e | 2016-01-11 13:12:43 -0700 | [diff] [blame] | 7160 | alloc_info.descriptorSetCount = 1; |
Tobin Ehlis | 8fab656 | 2015-12-01 09:57:09 -0700 | [diff] [blame] | 7161 | alloc_info.pSetLayouts = &ds_layout_fs_only; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7162 | err = |
| 7163 | vkAllocateDescriptorSets(m_device->device(), &alloc_info, &ds0_fs_only); |
Tobin Ehlis | 8fab656 | 2015-12-01 09:57:09 -0700 | [diff] [blame] | 7164 | ASSERT_VK_SUCCESS(err); |
Tobin Ehlis | 559c638 | 2015-11-05 09:52:49 -0700 | [diff] [blame] | 7165 | |
| 7166 | VkPipelineLayoutCreateInfo pipeline_layout_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7167 | pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO; |
| 7168 | pipeline_layout_ci.pNext = NULL; |
| 7169 | pipeline_layout_ci.setLayoutCount = NUM_LAYOUTS; |
| 7170 | pipeline_layout_ci.pSetLayouts = ds_layout; |
Tobin Ehlis | 559c638 | 2015-11-05 09:52:49 -0700 | [diff] [blame] | 7171 | |
| 7172 | VkPipelineLayout pipeline_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7173 | err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, |
| 7174 | &pipeline_layout); |
Tobin Ehlis | 559c638 | 2015-11-05 09:52:49 -0700 | [diff] [blame] | 7175 | ASSERT_VK_SUCCESS(err); |
Tobin Ehlis | 8fab656 | 2015-12-01 09:57:09 -0700 | [diff] [blame] | 7176 | // Create pipelineLayout with only one setLayout |
| 7177 | pipeline_layout_ci.setLayoutCount = 1; |
| 7178 | VkPipelineLayout single_pipe_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7179 | err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, |
| 7180 | &single_pipe_layout); |
Tobin Ehlis | 8fab656 | 2015-12-01 09:57:09 -0700 | [diff] [blame] | 7181 | ASSERT_VK_SUCCESS(err); |
| 7182 | // Create pipelineLayout with 2 descriptor setLayout at index 0 |
| 7183 | pipeline_layout_ci.pSetLayouts = &ds_layout[3]; |
| 7184 | VkPipelineLayout pipe_layout_one_desc; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7185 | err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, |
| 7186 | &pipe_layout_one_desc); |
Tobin Ehlis | 8fab656 | 2015-12-01 09:57:09 -0700 | [diff] [blame] | 7187 | ASSERT_VK_SUCCESS(err); |
| 7188 | // Create pipelineLayout with 5 SAMPLER descriptor setLayout at index 0 |
| 7189 | pipeline_layout_ci.pSetLayouts = &ds_layout[2]; |
| 7190 | VkPipelineLayout pipe_layout_five_samp; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7191 | err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, |
| 7192 | &pipe_layout_five_samp); |
Tobin Ehlis | 8fab656 | 2015-12-01 09:57:09 -0700 | [diff] [blame] | 7193 | ASSERT_VK_SUCCESS(err); |
| 7194 | // Create pipelineLayout with UB type, but stageFlags for FS only |
| 7195 | pipeline_layout_ci.pSetLayouts = &ds_layout_fs_only; |
| 7196 | VkPipelineLayout pipe_layout_fs_only; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7197 | err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, |
| 7198 | &pipe_layout_fs_only); |
Tobin Ehlis | 8fab656 | 2015-12-01 09:57:09 -0700 | [diff] [blame] | 7199 | ASSERT_VK_SUCCESS(err); |
| 7200 | // Create pipelineLayout w/ incompatible set0 layout, but set1 is fine |
| 7201 | VkDescriptorSetLayout pl_bad_s0[2] = {}; |
| 7202 | pl_bad_s0[0] = ds_layout_fs_only; |
| 7203 | pl_bad_s0[1] = ds_layout[1]; |
| 7204 | pipeline_layout_ci.setLayoutCount = 2; |
| 7205 | pipeline_layout_ci.pSetLayouts = pl_bad_s0; |
| 7206 | VkPipelineLayout pipe_layout_bad_set0; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7207 | err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, |
| 7208 | &pipe_layout_bad_set0); |
Tobin Ehlis | 8fab656 | 2015-12-01 09:57:09 -0700 | [diff] [blame] | 7209 | ASSERT_VK_SUCCESS(err); |
Tobin Ehlis | 559c638 | 2015-11-05 09:52:49 -0700 | [diff] [blame] | 7210 | |
| 7211 | // Create a buffer to update the descriptor with |
| 7212 | uint32_t qfi = 0; |
| 7213 | VkBufferCreateInfo buffCI = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7214 | buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO; |
| 7215 | buffCI.size = 1024; |
| 7216 | buffCI.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT; |
| 7217 | buffCI.queueFamilyIndexCount = 1; |
| 7218 | buffCI.pQueueFamilyIndices = &qfi; |
Tobin Ehlis | 559c638 | 2015-11-05 09:52:49 -0700 | [diff] [blame] | 7219 | |
| 7220 | VkBuffer dyub; |
| 7221 | err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &dyub); |
| 7222 | ASSERT_VK_SUCCESS(err); |
| 7223 | // Correctly update descriptor to avoid "NOT_UPDATED" error |
| 7224 | static const uint32_t NUM_BUFFS = 5; |
| 7225 | VkDescriptorBufferInfo buffInfo[NUM_BUFFS] = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7226 | for (uint32_t i = 0; i < NUM_BUFFS; ++i) { |
Tobin Ehlis | 559c638 | 2015-11-05 09:52:49 -0700 | [diff] [blame] | 7227 | buffInfo[i].buffer = dyub; |
| 7228 | buffInfo[i].offset = 0; |
| 7229 | buffInfo[i].range = 1024; |
| 7230 | } |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7231 | VkImage image; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7232 | const int32_t tex_width = 32; |
| 7233 | const int32_t tex_height = 32; |
Tobin Ehlis | 8fab656 | 2015-12-01 09:57:09 -0700 | [diff] [blame] | 7234 | VkImageCreateInfo image_create_info = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7235 | image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO; |
| 7236 | image_create_info.pNext = NULL; |
| 7237 | image_create_info.imageType = VK_IMAGE_TYPE_2D; |
| 7238 | image_create_info.format = tex_format; |
| 7239 | image_create_info.extent.width = tex_width; |
| 7240 | image_create_info.extent.height = tex_height; |
| 7241 | image_create_info.extent.depth = 1; |
| 7242 | image_create_info.mipLevels = 1; |
| 7243 | image_create_info.arrayLayers = 1; |
| 7244 | image_create_info.samples = VK_SAMPLE_COUNT_1_BIT; |
Mike Stroyan | b8a6100 | 2016-06-20 16:00:28 -0600 | [diff] [blame] | 7245 | image_create_info.tiling = tiling; |
| 7246 | image_create_info.usage = |
| 7247 | VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_STORAGE_BIT; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7248 | image_create_info.flags = 0; |
Tobin Ehlis | 8fab656 | 2015-12-01 09:57:09 -0700 | [diff] [blame] | 7249 | err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image); |
| 7250 | ASSERT_VK_SUCCESS(err); |
Tobin Ehlis | 559c638 | 2015-11-05 09:52:49 -0700 | [diff] [blame] | 7251 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7252 | VkMemoryRequirements memReqs; |
| 7253 | VkDeviceMemory imageMem; |
| 7254 | bool pass; |
Mike Stroyan | 9c70cdb | 2016-01-06 14:14:17 -0700 | [diff] [blame] | 7255 | VkMemoryAllocateInfo memAlloc = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7256 | memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO; |
| 7257 | memAlloc.pNext = NULL; |
| 7258 | memAlloc.allocationSize = 0; |
| 7259 | memAlloc.memoryTypeIndex = 0; |
Mike Stroyan | 9c70cdb | 2016-01-06 14:14:17 -0700 | [diff] [blame] | 7260 | vkGetImageMemoryRequirements(m_device->device(), image, &memReqs); |
| 7261 | memAlloc.allocationSize = memReqs.size; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7262 | pass = |
| 7263 | m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0); |
Mike Stroyan | 9c70cdb | 2016-01-06 14:14:17 -0700 | [diff] [blame] | 7264 | ASSERT_TRUE(pass); |
| 7265 | err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &imageMem); |
| 7266 | ASSERT_VK_SUCCESS(err); |
| 7267 | err = vkBindImageMemory(m_device->device(), image, imageMem, 0); |
| 7268 | ASSERT_VK_SUCCESS(err); |
| 7269 | |
Tobin Ehlis | 8fab656 | 2015-12-01 09:57:09 -0700 | [diff] [blame] | 7270 | VkImageViewCreateInfo image_view_create_info = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7271 | image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO; |
| 7272 | image_view_create_info.image = image; |
| 7273 | image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D; |
| 7274 | image_view_create_info.format = tex_format; |
| 7275 | image_view_create_info.subresourceRange.layerCount = 1; |
| 7276 | image_view_create_info.subresourceRange.baseMipLevel = 0; |
| 7277 | image_view_create_info.subresourceRange.levelCount = 1; |
| 7278 | image_view_create_info.subresourceRange.aspectMask = |
| 7279 | VK_IMAGE_ASPECT_COLOR_BIT; |
Tobin Ehlis | 559c638 | 2015-11-05 09:52:49 -0700 | [diff] [blame] | 7280 | |
Tobin Ehlis | 8fab656 | 2015-12-01 09:57:09 -0700 | [diff] [blame] | 7281 | VkImageView view; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7282 | err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, |
| 7283 | &view); |
Tobin Ehlis | 8fab656 | 2015-12-01 09:57:09 -0700 | [diff] [blame] | 7284 | ASSERT_VK_SUCCESS(err); |
Tobin Ehlis | 991d45a | 2016-01-06 08:48:41 -0700 | [diff] [blame] | 7285 | VkDescriptorImageInfo imageInfo[4] = {}; |
Tobin Ehlis | 8fab656 | 2015-12-01 09:57:09 -0700 | [diff] [blame] | 7286 | imageInfo[0].imageView = view; |
| 7287 | imageInfo[0].imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL; |
| 7288 | imageInfo[1].imageView = view; |
| 7289 | imageInfo[1].imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL; |
Tobin Ehlis | 991d45a | 2016-01-06 08:48:41 -0700 | [diff] [blame] | 7290 | imageInfo[2].imageView = view; |
| 7291 | imageInfo[2].imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL; |
| 7292 | imageInfo[3].imageView = view; |
| 7293 | imageInfo[3].imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL; |
Tobin Ehlis | 8fab656 | 2015-12-01 09:57:09 -0700 | [diff] [blame] | 7294 | |
| 7295 | static const uint32_t NUM_SET_UPDATES = 3; |
| 7296 | VkWriteDescriptorSet descriptor_write[NUM_SET_UPDATES] = {}; |
| 7297 | descriptor_write[0].sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET; |
| 7298 | descriptor_write[0].dstSet = descriptorSet[0]; |
| 7299 | descriptor_write[0].dstBinding = 0; |
| 7300 | descriptor_write[0].descriptorCount = 5; |
| 7301 | descriptor_write[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 7302 | descriptor_write[0].pBufferInfo = buffInfo; |
| 7303 | descriptor_write[1].sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET; |
| 7304 | descriptor_write[1].dstSet = descriptorSet[1]; |
| 7305 | descriptor_write[1].dstBinding = 0; |
| 7306 | descriptor_write[1].descriptorCount = 2; |
| 7307 | descriptor_write[1].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE; |
| 7308 | descriptor_write[1].pImageInfo = imageInfo; |
| 7309 | descriptor_write[2].sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET; |
| 7310 | descriptor_write[2].dstSet = descriptorSet[1]; |
| 7311 | descriptor_write[2].dstBinding = 1; |
| 7312 | descriptor_write[2].descriptorCount = 2; |
| 7313 | descriptor_write[2].descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE; |
Tobin Ehlis | 991d45a | 2016-01-06 08:48:41 -0700 | [diff] [blame] | 7314 | descriptor_write[2].pImageInfo = &imageInfo[2]; |
Tobin Ehlis | 8fab656 | 2015-12-01 09:57:09 -0700 | [diff] [blame] | 7315 | |
| 7316 | vkUpdateDescriptorSets(m_device->device(), 3, descriptor_write, 0, NULL); |
Tobin Ehlis | 559c638 | 2015-11-05 09:52:49 -0700 | [diff] [blame] | 7317 | |
Tobin Ehlis | 8845283 | 2015-12-03 09:40:56 -0700 | [diff] [blame] | 7318 | // Create PSO to be used for draw-time errors below |
| 7319 | char const *vsSource = |
Chris Forbes | 7b34280 | 2016-04-07 13:20:10 +1200 | [diff] [blame] | 7320 | "#version 450\n" |
Tobin Ehlis | 8845283 | 2015-12-03 09:40:56 -0700 | [diff] [blame] | 7321 | "\n" |
Tony Barbour | e804d20 | 2016-01-05 13:37:45 -0700 | [diff] [blame] | 7322 | "out gl_PerVertex {\n" |
| 7323 | " vec4 gl_Position;\n" |
| 7324 | "};\n" |
Tobin Ehlis | 8845283 | 2015-12-03 09:40:56 -0700 | [diff] [blame] | 7325 | "void main(){\n" |
| 7326 | " gl_Position = vec4(1);\n" |
| 7327 | "}\n"; |
| 7328 | char const *fsSource = |
Chris Forbes | 7b34280 | 2016-04-07 13:20:10 +1200 | [diff] [blame] | 7329 | "#version 450\n" |
Tobin Ehlis | 8845283 | 2015-12-03 09:40:56 -0700 | [diff] [blame] | 7330 | "\n" |
| 7331 | "layout(location=0) out vec4 x;\n" |
| 7332 | "layout(set=0) layout(binding=0) uniform foo { int x; int y; } bar;\n" |
| 7333 | "void main(){\n" |
| 7334 | " x = vec4(bar.y);\n" |
| 7335 | "}\n"; |
| 7336 | VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this); |
| 7337 | VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this); |
Tobin Ehlis | 559c638 | 2015-11-05 09:52:49 -0700 | [diff] [blame] | 7338 | VkPipelineObj pipe(m_device); |
| 7339 | pipe.AddShader(&vs); |
| 7340 | pipe.AddShader(&fs); |
Tobin Ehlis | 8845283 | 2015-12-03 09:40:56 -0700 | [diff] [blame] | 7341 | pipe.AddColorAttachment(); |
| 7342 | pipe.CreateVKPipeline(pipe_layout_fs_only, renderPass()); |
Tobin Ehlis | 559c638 | 2015-11-05 09:52:49 -0700 | [diff] [blame] | 7343 | |
| 7344 | BeginCommandBuffer(); |
Tobin Ehlis | 8845283 | 2015-12-03 09:40:56 -0700 | [diff] [blame] | 7345 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7346 | vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), |
| 7347 | VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle()); |
| 7348 | // NOTE : I believe LunarG ilo driver has bug (LX#189) that requires binding |
| 7349 | // of PSO |
| 7350 | // here before binding DSs. Otherwise we assert in cmd_copy_dset_data() of |
| 7351 | // cmd_pipeline.c |
| 7352 | // due to the fact that cmd_alloc_dset_data() has not been called in |
| 7353 | // cmd_bind_graphics_pipeline() |
| 7354 | // TODO : Want to cause various binding incompatibility issues here to test |
| 7355 | // DrawState |
Tobin Ehlis | 559c638 | 2015-11-05 09:52:49 -0700 | [diff] [blame] | 7356 | // First cause various verify_layout_compatibility() fails |
| 7357 | // Second disturb early and late sets and verify INFO msgs |
Tobin Ehlis | 8fab656 | 2015-12-01 09:57:09 -0700 | [diff] [blame] | 7358 | // verify_set_layout_compatibility fail cases: |
| 7359 | // 1. invalid VkPipelineLayout (layout) passed into vkCmdBindDescriptorSets |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7360 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Tobin Ehlis | 10fad69 | 2016-07-07 12:00:36 -0600 | [diff] [blame] | 7361 | "Invalid VkPipelineLayout Object "); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7362 | vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), |
| 7363 | VK_PIPELINE_BIND_POINT_GRAPHICS, |
| 7364 | (VkPipelineLayout)((size_t)0xbaadb1be), 0, 1, |
| 7365 | &descriptorSet[0], 0, NULL); |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 7366 | m_errorMonitor->VerifyFound(); |
| 7367 | |
Tobin Ehlis | 8fab656 | 2015-12-01 09:57:09 -0700 | [diff] [blame] | 7368 | // 2. layoutIndex exceeds # of layouts in layout |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7369 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 7370 | " attempting to bind set to index 1"); |
| 7371 | vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), |
| 7372 | VK_PIPELINE_BIND_POINT_GRAPHICS, single_pipe_layout, |
| 7373 | 0, 2, &descriptorSet[0], 0, NULL); |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 7374 | m_errorMonitor->VerifyFound(); |
| 7375 | |
Tobin Ehlis | 8fab656 | 2015-12-01 09:57:09 -0700 | [diff] [blame] | 7376 | vkDestroyPipelineLayout(m_device->device(), single_pipe_layout, NULL); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7377 | // 3. Pipeline setLayout[0] has 2 descriptors, but set being bound has 5 |
| 7378 | // descriptors |
| 7379 | m_errorMonitor->SetDesiredFailureMsg( |
| 7380 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Tobin Ehlis | 2d9deec | 2016-04-21 14:19:26 -0600 | [diff] [blame] | 7381 | " has 2 descriptors, but DescriptorSetLayout "); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7382 | vkCmdBindDescriptorSets( |
| 7383 | m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, |
| 7384 | pipe_layout_one_desc, 0, 1, &descriptorSet[0], 0, NULL); |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 7385 | m_errorMonitor->VerifyFound(); |
| 7386 | |
Tobin Ehlis | 8fab656 | 2015-12-01 09:57:09 -0700 | [diff] [blame] | 7387 | vkDestroyPipelineLayout(m_device->device(), pipe_layout_one_desc, NULL); |
| 7388 | // 4. same # of descriptors but mismatch in type |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7389 | m_errorMonitor->SetDesiredFailureMsg( |
| 7390 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Tobin Ehlis | 2d9deec | 2016-04-21 14:19:26 -0600 | [diff] [blame] | 7391 | " is type 'VK_DESCRIPTOR_TYPE_SAMPLER' but binding "); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7392 | vkCmdBindDescriptorSets( |
| 7393 | m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, |
| 7394 | pipe_layout_five_samp, 0, 1, &descriptorSet[0], 0, NULL); |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 7395 | m_errorMonitor->VerifyFound(); |
| 7396 | |
Tobin Ehlis | 8fab656 | 2015-12-01 09:57:09 -0700 | [diff] [blame] | 7397 | vkDestroyPipelineLayout(m_device->device(), pipe_layout_five_samp, NULL); |
| 7398 | // 5. same # of descriptors but mismatch in stageFlags |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7399 | m_errorMonitor->SetDesiredFailureMsg( |
| 7400 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Tobin Ehlis | 2d9deec | 2016-04-21 14:19:26 -0600 | [diff] [blame] | 7401 | " has stageFlags 16 but binding 0 for DescriptorSetLayout "); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7402 | vkCmdBindDescriptorSets( |
| 7403 | m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, |
| 7404 | pipe_layout_fs_only, 0, 1, &descriptorSet[0], 0, NULL); |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 7405 | m_errorMonitor->VerifyFound(); |
| 7406 | |
Tobin Ehlis | 8fab656 | 2015-12-01 09:57:09 -0700 | [diff] [blame] | 7407 | // Cause INFO messages due to disturbing previously bound Sets |
| 7408 | // First bind sets 0 & 1 |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7409 | vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), |
| 7410 | VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, |
| 7411 | 2, &descriptorSet[0], 0, NULL); |
Tobin Ehlis | 8fab656 | 2015-12-01 09:57:09 -0700 | [diff] [blame] | 7412 | // 1. Disturb bound set0 by re-binding set1 w/ updated pipelineLayout |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7413 | m_errorMonitor->SetDesiredFailureMsg( |
Mark Lobodzinski | 510e20d | 2016-02-11 09:26:16 -0700 | [diff] [blame] | 7414 | VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7415 | " previously bound as set #0 was disturbed "); |
| 7416 | vkCmdBindDescriptorSets( |
| 7417 | m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, |
| 7418 | pipe_layout_bad_set0, 1, 1, &descriptorSet[1], 0, NULL); |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 7419 | m_errorMonitor->VerifyFound(); |
| 7420 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7421 | vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), |
| 7422 | VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, |
| 7423 | 2, &descriptorSet[0], 0, NULL); |
Tobin Ehlis | 8fab656 | 2015-12-01 09:57:09 -0700 | [diff] [blame] | 7424 | // 2. Disturb set after last bound set |
Mark Lobodzinski | 510e20d | 2016-02-11 09:26:16 -0700 | [diff] [blame] | 7425 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7426 | " newly bound as set #0 so set #1 and " |
| 7427 | "any subsequent sets were disturbed "); |
| 7428 | vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), |
| 7429 | VK_PIPELINE_BIND_POINT_GRAPHICS, |
| 7430 | pipe_layout_fs_only, 0, 1, &ds0_fs_only, 0, NULL); |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 7431 | m_errorMonitor->VerifyFound(); |
| 7432 | |
Tobin Ehlis | 10fad69 | 2016-07-07 12:00:36 -0600 | [diff] [blame] | 7433 | // Now that we're done actively using the pipelineLayout that gfx pipeline |
| 7434 | // was created with, we should be able to delete it. Do that now to verify |
| 7435 | // that validation obeys pipelineLayout lifetime |
| 7436 | vkDestroyPipelineLayout(m_device->device(), pipe_layout_fs_only, NULL); |
| 7437 | |
Tobin Ehlis | 8845283 | 2015-12-03 09:40:56 -0700 | [diff] [blame] | 7438 | // Cause draw-time errors due to PSO incompatibilities |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7439 | // 1. Error due to not binding required set (we actually use same code as |
| 7440 | // above to disturb set0) |
| 7441 | vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), |
| 7442 | VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, |
| 7443 | 2, &descriptorSet[0], 0, NULL); |
| 7444 | vkCmdBindDescriptorSets( |
| 7445 | m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, |
| 7446 | pipe_layout_bad_set0, 1, 1, &descriptorSet[1], 0, NULL); |
| 7447 | m_errorMonitor->SetDesiredFailureMsg( |
| 7448 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 7449 | " uses set #0 but that set is not bound."); |
Tobin Ehlis | 8845283 | 2015-12-03 09:40:56 -0700 | [diff] [blame] | 7450 | Draw(1, 0, 0, 0); |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 7451 | m_errorMonitor->VerifyFound(); |
| 7452 | |
Tobin Ehlis | 991d45a | 2016-01-06 08:48:41 -0700 | [diff] [blame] | 7453 | vkDestroyPipelineLayout(m_device->device(), pipe_layout_bad_set0, NULL); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7454 | // 2. Error due to bound set not being compatible with PSO's |
| 7455 | // VkPipelineLayout (diff stageFlags in this case) |
| 7456 | vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), |
| 7457 | VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, |
| 7458 | 2, &descriptorSet[0], 0, NULL); |
| 7459 | m_errorMonitor->SetDesiredFailureMsg( |
| 7460 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 7461 | " bound as set #0 is not compatible with "); |
Tobin Ehlis | 8845283 | 2015-12-03 09:40:56 -0700 | [diff] [blame] | 7462 | Draw(1, 0, 0, 0); |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 7463 | m_errorMonitor->VerifyFound(); |
| 7464 | |
Tobin Ehlis | 8fab656 | 2015-12-01 09:57:09 -0700 | [diff] [blame] | 7465 | // Remaining clean-up |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7466 | for (uint32_t i = 0; i < NUM_LAYOUTS; ++i) { |
Tobin Ehlis | 8fab656 | 2015-12-01 09:57:09 -0700 | [diff] [blame] | 7467 | vkDestroyDescriptorSetLayout(m_device->device(), ds_layout[i], NULL); |
| 7468 | } |
| 7469 | vkDestroyDescriptorSetLayout(m_device->device(), ds_layout_fs_only, NULL); |
Tobin Ehlis | 9bfd449 | 2016-05-05 15:09:11 -0600 | [diff] [blame] | 7470 | vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &ds0_fs_only); |
| 7471 | vkFreeDescriptorSets(m_device->device(), ds_pool, NUM_SETS, descriptorSet); |
Tobin Ehlis | 8fab656 | 2015-12-01 09:57:09 -0700 | [diff] [blame] | 7472 | vkDestroyBuffer(m_device->device(), dyub, NULL); |
Tobin Ehlis | 559c638 | 2015-11-05 09:52:49 -0700 | [diff] [blame] | 7473 | vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL); |
| 7474 | vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL); |
Tony Barbour | df4c004 | 2016-06-01 15:55:43 -0600 | [diff] [blame] | 7475 | vkFreeMemory(m_device->device(), imageMem, NULL); |
| 7476 | vkDestroyImage(m_device->device(), image, NULL); |
| 7477 | vkDestroyImageView(m_device->device(), view, NULL); |
Tobin Ehlis | 559c638 | 2015-11-05 09:52:49 -0700 | [diff] [blame] | 7478 | } |
Tobin Ehlis | 559c638 | 2015-11-05 09:52:49 -0700 | [diff] [blame] | 7479 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7480 | TEST_F(VkLayerTest, NoBeginCommandBuffer) { |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 7481 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7482 | m_errorMonitor->SetDesiredFailureMsg( |
| 7483 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 7484 | "You must call vkBeginCommandBuffer() before this call to "); |
Tobin Ehlis | af1f3a4 | 2015-06-25 15:46:59 -0600 | [diff] [blame] | 7485 | |
| 7486 | ASSERT_NO_FATAL_FAILURE(InitState()); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 7487 | VkCommandBufferObj commandBuffer(m_device, m_commandPool); |
Tobin Ehlis | af1f3a4 | 2015-06-25 15:46:59 -0600 | [diff] [blame] | 7488 | // Call EndCommandBuffer() w/o calling BeginCommandBuffer() |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 7489 | vkEndCommandBuffer(commandBuffer.GetBufferHandle()); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 7490 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 7491 | m_errorMonitor->VerifyFound(); |
Tobin Ehlis | af1f3a4 | 2015-06-25 15:46:59 -0600 | [diff] [blame] | 7492 | } |
| 7493 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7494 | TEST_F(VkLayerTest, SecondaryCommandBufferNullRenderpass) { |
| 7495 | VkResult err; |
| 7496 | VkCommandBuffer draw_cmd; |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 7497 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7498 | m_errorMonitor->SetDesiredFailureMsg( |
| 7499 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Tobin Ehlis | 61b36f3 | 2015-12-16 08:19:42 -0700 | [diff] [blame] | 7500 | " must specify a valid renderpass parameter."); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 7501 | |
Mark Lobodzinski | d9139a6 | 2015-08-04 16:24:20 -0600 | [diff] [blame] | 7502 | ASSERT_NO_FATAL_FAILURE(InitState()); |
Mark Lobodzinski | d9139a6 | 2015-08-04 16:24:20 -0600 | [diff] [blame] | 7503 | |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 7504 | VkCommandBufferAllocateInfo cmd = {}; |
Chia-I Wu | 00ce540 | 2015-11-10 16:21:09 +0800 | [diff] [blame] | 7505 | cmd.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO; |
Cody Northrop | b456970 | 2015-08-04 17:35:57 -0600 | [diff] [blame] | 7506 | cmd.pNext = NULL; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 7507 | cmd.commandPool = m_commandPool; |
| 7508 | cmd.level = VK_COMMAND_BUFFER_LEVEL_SECONDARY; |
Jon Ashburn | f19916e | 2016-01-11 13:12:43 -0700 | [diff] [blame] | 7509 | cmd.commandBufferCount = 1; |
Cody Northrop | b456970 | 2015-08-04 17:35:57 -0600 | [diff] [blame] | 7510 | |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 7511 | err = vkAllocateCommandBuffers(m_device->device(), &cmd, &draw_cmd); |
Mike Stroyan | d1c84a5 | 2015-08-18 14:40:24 -0600 | [diff] [blame] | 7512 | ASSERT_VK_SUCCESS(err); |
Mark Lobodzinski | d9139a6 | 2015-08-04 16:24:20 -0600 | [diff] [blame] | 7513 | |
| 7514 | // Force the failure by not setting the Renderpass and Framebuffer fields |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 7515 | VkCommandBufferBeginInfo cmd_buf_info = {}; |
Jon Ashburn | f19916e | 2016-01-11 13:12:43 -0700 | [diff] [blame] | 7516 | VkCommandBufferInheritanceInfo cmd_buf_hinfo = {}; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 7517 | cmd_buf_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO; |
Cody Northrop | b456970 | 2015-08-04 17:35:57 -0600 | [diff] [blame] | 7518 | cmd_buf_info.pNext = NULL; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7519 | cmd_buf_info.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT | |
| 7520 | VK_COMMAND_BUFFER_USAGE_RENDER_PASS_CONTINUE_BIT; |
Jon Ashburn | f19916e | 2016-01-11 13:12:43 -0700 | [diff] [blame] | 7521 | cmd_buf_info.pInheritanceInfo = &cmd_buf_hinfo; |
Mark Lobodzinski | d9139a6 | 2015-08-04 16:24:20 -0600 | [diff] [blame] | 7522 | |
| 7523 | // The error should be caught by validation of the BeginCommandBuffer call |
| 7524 | vkBeginCommandBuffer(draw_cmd, &cmd_buf_info); |
| 7525 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 7526 | m_errorMonitor->VerifyFound(); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 7527 | vkFreeCommandBuffers(m_device->device(), m_commandPool, 1, &draw_cmd); |
Mark Lobodzinski | d9139a6 | 2015-08-04 16:24:20 -0600 | [diff] [blame] | 7528 | } |
| 7529 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7530 | TEST_F(VkLayerTest, CommandBufferResetErrors) { |
Tobin Ehlis | ac0ef84 | 2015-12-14 13:46:38 -0700 | [diff] [blame] | 7531 | // Cause error due to Begin while recording CB |
| 7532 | // Then cause 2 errors for attempting to reset CB w/o having |
| 7533 | // VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT set for the pool from |
| 7534 | // which CBs were allocated. Note that this bit is off by default. |
Courtney Goeltzenleuchter | 7415d5a | 2015-12-09 15:48:16 -0700 | [diff] [blame] | 7535 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7536 | "Cannot call Begin on CB"); |
Tobin Ehlis | ac0ef84 | 2015-12-14 13:46:38 -0700 | [diff] [blame] | 7537 | |
| 7538 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 7539 | |
| 7540 | // Calls AllocateCommandBuffers |
| 7541 | VkCommandBufferObj commandBuffer(m_device, m_commandPool); |
| 7542 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7543 | // Force the failure by setting the Renderpass and Framebuffer fields with |
| 7544 | // (fake) data |
Tobin Ehlis | ac0ef84 | 2015-12-14 13:46:38 -0700 | [diff] [blame] | 7545 | VkCommandBufferBeginInfo cmd_buf_info = {}; |
Jon Ashburn | f19916e | 2016-01-11 13:12:43 -0700 | [diff] [blame] | 7546 | VkCommandBufferInheritanceInfo cmd_buf_hinfo = {}; |
Tobin Ehlis | ac0ef84 | 2015-12-14 13:46:38 -0700 | [diff] [blame] | 7547 | cmd_buf_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO; |
| 7548 | cmd_buf_info.pNext = NULL; |
| 7549 | cmd_buf_info.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT; |
Jon Ashburn | f19916e | 2016-01-11 13:12:43 -0700 | [diff] [blame] | 7550 | cmd_buf_info.pInheritanceInfo = &cmd_buf_hinfo; |
Tobin Ehlis | ac0ef84 | 2015-12-14 13:46:38 -0700 | [diff] [blame] | 7551 | |
| 7552 | // Begin CB to transition to recording state |
| 7553 | vkBeginCommandBuffer(commandBuffer.GetBufferHandle(), &cmd_buf_info); |
| 7554 | // Can't re-begin. This should trigger error |
| 7555 | vkBeginCommandBuffer(commandBuffer.GetBufferHandle(), &cmd_buf_info); |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 7556 | m_errorMonitor->VerifyFound(); |
| 7557 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7558 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 7559 | "Attempt to reset command buffer "); |
Tobin Ehlis | ac0ef84 | 2015-12-14 13:46:38 -0700 | [diff] [blame] | 7560 | VkCommandBufferResetFlags flags = 0; // Don't care about flags for this test |
| 7561 | // Reset attempt will trigger error due to incorrect CommandPool state |
| 7562 | vkResetCommandBuffer(commandBuffer.GetBufferHandle(), flags); |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 7563 | m_errorMonitor->VerifyFound(); |
| 7564 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7565 | m_errorMonitor->SetDesiredFailureMsg( |
| 7566 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 7567 | " attempts to implicitly reset cmdBuffer created from "); |
Tobin Ehlis | ac0ef84 | 2015-12-14 13:46:38 -0700 | [diff] [blame] | 7568 | // Transition CB to RECORDED state |
| 7569 | vkEndCommandBuffer(commandBuffer.GetBufferHandle()); |
| 7570 | // Now attempting to Begin will implicitly reset, which triggers error |
| 7571 | vkBeginCommandBuffer(commandBuffer.GetBufferHandle(), &cmd_buf_info); |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 7572 | m_errorMonitor->VerifyFound(); |
Tobin Ehlis | ac0ef84 | 2015-12-14 13:46:38 -0700 | [diff] [blame] | 7573 | } |
| 7574 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7575 | TEST_F(VkLayerTest, InvalidPipelineCreateState) { |
Tobin Ehlis | af1f3a4 | 2015-06-25 15:46:59 -0600 | [diff] [blame] | 7576 | // Attempt to Create Gfx Pipeline w/o a VS |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7577 | VkResult err; |
Tobin Ehlis | af1f3a4 | 2015-06-25 15:46:59 -0600 | [diff] [blame] | 7578 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7579 | m_errorMonitor->SetDesiredFailureMsg( |
| 7580 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 7581 | "Invalid Pipeline CreateInfo State: Vtx Shader required"); |
| 7582 | |
Tobin Ehlis | af1f3a4 | 2015-06-25 15:46:59 -0600 | [diff] [blame] | 7583 | ASSERT_NO_FATAL_FAILURE(InitState()); |
Tobin Ehlis | c9ac2b6 | 2015-09-11 12:57:55 -0600 | [diff] [blame] | 7584 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
Mark Lobodzinski | 209b529 | 2015-09-17 09:44:05 -0600 | [diff] [blame] | 7585 | |
Chia-I Wu | 1b99bb2 | 2015-10-27 19:25:11 +0800 | [diff] [blame] | 7586 | VkDescriptorPoolSize ds_type_count = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7587 | ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 7588 | ds_type_count.descriptorCount = 1; |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 7589 | |
| 7590 | VkDescriptorPoolCreateInfo ds_pool_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7591 | ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO; |
| 7592 | ds_pool_ci.pNext = NULL; |
| 7593 | ds_pool_ci.maxSets = 1; |
| 7594 | ds_pool_ci.poolSizeCount = 1; |
| 7595 | ds_pool_ci.pPoolSizes = &ds_type_count; |
Mark Lobodzinski | 209b529 | 2015-09-17 09:44:05 -0600 | [diff] [blame] | 7596 | |
Tobin Ehlis | af1f3a4 | 2015-06-25 15:46:59 -0600 | [diff] [blame] | 7597 | VkDescriptorPool ds_pool; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7598 | err = |
| 7599 | vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool); |
Tobin Ehlis | af1f3a4 | 2015-06-25 15:46:59 -0600 | [diff] [blame] | 7600 | ASSERT_VK_SUCCESS(err); |
| 7601 | |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 7602 | VkDescriptorSetLayoutBinding dsl_binding = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7603 | dsl_binding.binding = 0; |
| 7604 | dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 7605 | dsl_binding.descriptorCount = 1; |
| 7606 | dsl_binding.stageFlags = VK_SHADER_STAGE_ALL; |
| 7607 | dsl_binding.pImmutableSamplers = NULL; |
Tobin Ehlis | af1f3a4 | 2015-06-25 15:46:59 -0600 | [diff] [blame] | 7608 | |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 7609 | VkDescriptorSetLayoutCreateInfo ds_layout_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7610 | ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO; |
| 7611 | ds_layout_ci.pNext = NULL; |
| 7612 | ds_layout_ci.bindingCount = 1; |
| 7613 | ds_layout_ci.pBindings = &dsl_binding; |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 7614 | |
Tobin Ehlis | af1f3a4 | 2015-06-25 15:46:59 -0600 | [diff] [blame] | 7615 | VkDescriptorSetLayout ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7616 | err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, |
| 7617 | &ds_layout); |
Tobin Ehlis | af1f3a4 | 2015-06-25 15:46:59 -0600 | [diff] [blame] | 7618 | ASSERT_VK_SUCCESS(err); |
| 7619 | |
| 7620 | VkDescriptorSet descriptorSet; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 7621 | VkDescriptorSetAllocateInfo alloc_info = {}; |
Chia-I Wu | 00ce540 | 2015-11-10 16:21:09 +0800 | [diff] [blame] | 7622 | alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO; |
Jon Ashburn | f19916e | 2016-01-11 13:12:43 -0700 | [diff] [blame] | 7623 | alloc_info.descriptorSetCount = 1; |
Courtney Goeltzenleuchter | bee18a9 | 2015-10-23 14:21:05 -0600 | [diff] [blame] | 7624 | alloc_info.descriptorPool = ds_pool; |
| 7625 | alloc_info.pSetLayouts = &ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7626 | err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, |
| 7627 | &descriptorSet); |
Tobin Ehlis | af1f3a4 | 2015-06-25 15:46:59 -0600 | [diff] [blame] | 7628 | ASSERT_VK_SUCCESS(err); |
| 7629 | |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 7630 | VkPipelineLayoutCreateInfo pipeline_layout_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7631 | pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO; |
| 7632 | pipeline_layout_ci.setLayoutCount = 1; |
| 7633 | pipeline_layout_ci.pSetLayouts = &ds_layout; |
Tobin Ehlis | af1f3a4 | 2015-06-25 15:46:59 -0600 | [diff] [blame] | 7634 | |
| 7635 | VkPipelineLayout pipeline_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7636 | err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, |
| 7637 | &pipeline_layout); |
Tobin Ehlis | af1f3a4 | 2015-06-25 15:46:59 -0600 | [diff] [blame] | 7638 | ASSERT_VK_SUCCESS(err); |
| 7639 | |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 7640 | VkViewport vp = {}; // Just need dummy vp to point to |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7641 | VkRect2D sc = {}; // dummy scissor to point to |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 7642 | |
| 7643 | VkPipelineViewportStateCreateInfo vp_state_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7644 | vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO; |
| 7645 | vp_state_ci.scissorCount = 1; |
| 7646 | vp_state_ci.pScissors = ≻ |
| 7647 | vp_state_ci.viewportCount = 1; |
| 7648 | vp_state_ci.pViewports = &vp; |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 7649 | |
Karl Schultz | dfdb8d4 | 2016-03-08 10:30:21 -0700 | [diff] [blame] | 7650 | VkPipelineRasterizationStateCreateInfo rs_state_ci = {}; |
| 7651 | rs_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO; |
| 7652 | rs_state_ci.polygonMode = VK_POLYGON_MODE_FILL; |
| 7653 | rs_state_ci.cullMode = VK_CULL_MODE_BACK_BIT; |
| 7654 | rs_state_ci.frontFace = VK_FRONT_FACE_COUNTER_CLOCKWISE; |
| 7655 | rs_state_ci.depthClampEnable = VK_FALSE; |
| 7656 | rs_state_ci.rasterizerDiscardEnable = VK_FALSE; |
| 7657 | rs_state_ci.depthBiasEnable = VK_FALSE; |
| 7658 | |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 7659 | VkGraphicsPipelineCreateInfo gp_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7660 | gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO; |
| 7661 | gp_ci.pViewportState = &vp_state_ci; |
Karl Schultz | dfdb8d4 | 2016-03-08 10:30:21 -0700 | [diff] [blame] | 7662 | gp_ci.pRasterizationState = &rs_state_ci; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7663 | gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT; |
| 7664 | gp_ci.layout = pipeline_layout; |
| 7665 | gp_ci.renderPass = renderPass(); |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 7666 | |
| 7667 | VkPipelineCacheCreateInfo pc_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7668 | pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO; |
| 7669 | pc_ci.initialDataSize = 0; |
| 7670 | pc_ci.pInitialData = 0; |
Tobin Ehlis | af1f3a4 | 2015-06-25 15:46:59 -0600 | [diff] [blame] | 7671 | |
| 7672 | VkPipeline pipeline; |
Jon Ashburn | c669cc6 | 2015-07-09 15:02:25 -0600 | [diff] [blame] | 7673 | VkPipelineCache pipelineCache; |
| 7674 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7675 | err = |
| 7676 | vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache); |
Jon Ashburn | c669cc6 | 2015-07-09 15:02:25 -0600 | [diff] [blame] | 7677 | ASSERT_VK_SUCCESS(err); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7678 | err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, |
| 7679 | &gp_ci, NULL, &pipeline); |
Tobin Ehlis | 7d1a711 | 2015-05-27 14:32:28 -0600 | [diff] [blame] | 7680 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 7681 | m_errorMonitor->VerifyFound(); |
Mike Stroyan | d1c84a5 | 2015-08-18 14:40:24 -0600 | [diff] [blame] | 7682 | |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 7683 | vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL); |
| 7684 | vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL); |
| 7685 | vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL); |
| 7686 | vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL); |
Tobin Ehlis | af1f3a4 | 2015-06-25 15:46:59 -0600 | [diff] [blame] | 7687 | } |
Tobin Ehlis | 912df02 | 2015-09-17 08:46:18 -0600 | [diff] [blame] | 7688 | /*// TODO : This test should be good, but needs Tess support in compiler to run |
| 7689 | TEST_F(VkLayerTest, InvalidPatchControlPoints) |
| 7690 | { |
| 7691 | // Attempt to Create Gfx Pipeline w/o a VS |
Tobin Ehlis | 912df02 | 2015-09-17 08:46:18 -0600 | [diff] [blame] | 7692 | VkResult err; |
Tobin Ehlis | af1f3a4 | 2015-06-25 15:46:59 -0600 | [diff] [blame] | 7693 | |
Courtney Goeltzenleuchter | 7415d5a | 2015-12-09 15:48:16 -0700 | [diff] [blame] | 7694 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7695 | "Invalid Pipeline CreateInfo State: VK_PRIMITIVE_TOPOLOGY_PATCH |
| 7696 | primitive "); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 7697 | |
Tobin Ehlis | 912df02 | 2015-09-17 08:46:18 -0600 | [diff] [blame] | 7698 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 7699 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
Tobin Ehlis | 912df02 | 2015-09-17 08:46:18 -0600 | [diff] [blame] | 7700 | |
Chia-I Wu | 1b99bb2 | 2015-10-27 19:25:11 +0800 | [diff] [blame] | 7701 | VkDescriptorPoolSize ds_type_count = {}; |
Tobin Ehlis | 912df02 | 2015-09-17 08:46:18 -0600 | [diff] [blame] | 7702 | ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
Chia-I Wu | d50a7d7 | 2015-10-26 20:48:51 +0800 | [diff] [blame] | 7703 | ds_type_count.descriptorCount = 1; |
Tobin Ehlis | 912df02 | 2015-09-17 08:46:18 -0600 | [diff] [blame] | 7704 | |
| 7705 | VkDescriptorPoolCreateInfo ds_pool_ci = {}; |
| 7706 | ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO; |
| 7707 | ds_pool_ci.pNext = NULL; |
Chia-I Wu | 1b99bb2 | 2015-10-27 19:25:11 +0800 | [diff] [blame] | 7708 | ds_pool_ci.poolSizeCount = 1; |
| 7709 | ds_pool_ci.pPoolSizes = &ds_type_count; |
Tobin Ehlis | 912df02 | 2015-09-17 08:46:18 -0600 | [diff] [blame] | 7710 | |
| 7711 | VkDescriptorPool ds_pool; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7712 | err = vkCreateDescriptorPool(m_device->device(), |
| 7713 | 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] | 7714 | ASSERT_VK_SUCCESS(err); |
| 7715 | |
| 7716 | VkDescriptorSetLayoutBinding dsl_binding = {}; |
Chia-I Wu | d46e6ae | 2015-10-31 00:31:16 +0800 | [diff] [blame] | 7717 | dsl_binding.binding = 0; |
Tobin Ehlis | 912df02 | 2015-09-17 08:46:18 -0600 | [diff] [blame] | 7718 | dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
Chia-I Wu | 0212448 | 2015-11-06 06:42:02 +0800 | [diff] [blame] | 7719 | dsl_binding.descriptorCount = 1; |
Tobin Ehlis | 912df02 | 2015-09-17 08:46:18 -0600 | [diff] [blame] | 7720 | dsl_binding.stageFlags = VK_SHADER_STAGE_ALL; |
| 7721 | dsl_binding.pImmutableSamplers = NULL; |
| 7722 | |
| 7723 | VkDescriptorSetLayoutCreateInfo ds_layout_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7724 | ds_layout_ci.sType = |
| 7725 | VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO; |
Tobin Ehlis | 912df02 | 2015-09-17 08:46:18 -0600 | [diff] [blame] | 7726 | ds_layout_ci.pNext = NULL; |
Chia-I Wu | d50a7d7 | 2015-10-26 20:48:51 +0800 | [diff] [blame] | 7727 | ds_layout_ci.bindingCount = 1; |
Jon Ashburn | 6e23c1f | 2015-12-30 18:01:16 -0700 | [diff] [blame] | 7728 | ds_layout_ci.pBindings = &dsl_binding; |
Tobin Ehlis | 912df02 | 2015-09-17 08:46:18 -0600 | [diff] [blame] | 7729 | |
| 7730 | VkDescriptorSetLayout ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7731 | err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, |
| 7732 | &ds_layout); |
Tobin Ehlis | 912df02 | 2015-09-17 08:46:18 -0600 | [diff] [blame] | 7733 | ASSERT_VK_SUCCESS(err); |
| 7734 | |
| 7735 | VkDescriptorSet descriptorSet; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7736 | err = vkAllocateDescriptorSets(m_device->device(), ds_pool, |
| 7737 | VK_DESCRIPTOR_SET_USAGE_NON_FREE, 1, &ds_layout, &descriptorSet); |
Tobin Ehlis | 912df02 | 2015-09-17 08:46:18 -0600 | [diff] [blame] | 7738 | ASSERT_VK_SUCCESS(err); |
| 7739 | |
| 7740 | VkPipelineLayoutCreateInfo pipeline_layout_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7741 | pipeline_layout_ci.sType = |
| 7742 | VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO; |
Tobin Ehlis | 912df02 | 2015-09-17 08:46:18 -0600 | [diff] [blame] | 7743 | pipeline_layout_ci.pNext = NULL; |
Chia-I Wu | d50a7d7 | 2015-10-26 20:48:51 +0800 | [diff] [blame] | 7744 | pipeline_layout_ci.setLayoutCount = 1; |
Tobin Ehlis | 912df02 | 2015-09-17 08:46:18 -0600 | [diff] [blame] | 7745 | pipeline_layout_ci.pSetLayouts = &ds_layout; |
| 7746 | |
| 7747 | VkPipelineLayout pipeline_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7748 | err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, |
| 7749 | &pipeline_layout); |
Tobin Ehlis | 912df02 | 2015-09-17 08:46:18 -0600 | [diff] [blame] | 7750 | ASSERT_VK_SUCCESS(err); |
| 7751 | |
| 7752 | VkPipelineShaderStageCreateInfo shaderStages[3]; |
| 7753 | memset(&shaderStages, 0, 3 * sizeof(VkPipelineShaderStageCreateInfo)); |
| 7754 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7755 | VkShaderObj vs(m_device,bindStateVertShaderText,VK_SHADER_STAGE_VERTEX_BIT, |
| 7756 | this); |
Tobin Ehlis | 912df02 | 2015-09-17 08:46:18 -0600 | [diff] [blame] | 7757 | // 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] | 7758 | VkShaderObj |
| 7759 | tc(m_device,bindStateVertShaderText,VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT, |
| 7760 | this); |
| 7761 | VkShaderObj |
| 7762 | te(m_device,bindStateVertShaderText,VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT, |
| 7763 | this); |
Tobin Ehlis | 912df02 | 2015-09-17 08:46:18 -0600 | [diff] [blame] | 7764 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7765 | shaderStages[0].sType = |
| 7766 | VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO; |
Courtney Goeltzenleuchter | d263550 | 2015-10-21 17:08:06 -0600 | [diff] [blame] | 7767 | shaderStages[0].stage = VK_SHADER_STAGE_VERTEX_BIT; |
Tobin Ehlis | 912df02 | 2015-09-17 08:46:18 -0600 | [diff] [blame] | 7768 | shaderStages[0].shader = vs.handle(); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7769 | shaderStages[1].sType = |
| 7770 | VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO; |
Courtney Goeltzenleuchter | d263550 | 2015-10-21 17:08:06 -0600 | [diff] [blame] | 7771 | shaderStages[1].stage = VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT; |
Tobin Ehlis | 912df02 | 2015-09-17 08:46:18 -0600 | [diff] [blame] | 7772 | shaderStages[1].shader = tc.handle(); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7773 | shaderStages[2].sType = |
| 7774 | VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO; |
Courtney Goeltzenleuchter | d263550 | 2015-10-21 17:08:06 -0600 | [diff] [blame] | 7775 | shaderStages[2].stage = VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT; |
Tobin Ehlis | 912df02 | 2015-09-17 08:46:18 -0600 | [diff] [blame] | 7776 | shaderStages[2].shader = te.handle(); |
| 7777 | |
| 7778 | VkPipelineInputAssemblyStateCreateInfo iaCI = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7779 | iaCI.sType = |
| 7780 | VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO; |
Chia-I Wu | 515eb8f | 2015-10-31 00:31:16 +0800 | [diff] [blame] | 7781 | iaCI.topology = VK_PRIMITIVE_TOPOLOGY_PATCH_LIST; |
Tobin Ehlis | 912df02 | 2015-09-17 08:46:18 -0600 | [diff] [blame] | 7782 | |
| 7783 | VkPipelineTessellationStateCreateInfo tsCI = {}; |
| 7784 | tsCI.sType = VK_STRUCTURE_TYPE_PIPELINE_TESSELLATION_STATE_CREATE_INFO; |
| 7785 | tsCI.patchControlPoints = 0; // This will cause an error |
| 7786 | |
| 7787 | VkGraphicsPipelineCreateInfo gp_ci = {}; |
| 7788 | gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO; |
| 7789 | gp_ci.pNext = NULL; |
| 7790 | gp_ci.stageCount = 3; |
| 7791 | gp_ci.pStages = shaderStages; |
| 7792 | gp_ci.pVertexInputState = NULL; |
| 7793 | gp_ci.pInputAssemblyState = &iaCI; |
| 7794 | gp_ci.pTessellationState = &tsCI; |
| 7795 | gp_ci.pViewportState = NULL; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 7796 | gp_ci.pRasterizationState = NULL; |
Tobin Ehlis | 912df02 | 2015-09-17 08:46:18 -0600 | [diff] [blame] | 7797 | gp_ci.pMultisampleState = NULL; |
| 7798 | gp_ci.pDepthStencilState = NULL; |
| 7799 | gp_ci.pColorBlendState = NULL; |
| 7800 | gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT; |
| 7801 | gp_ci.layout = pipeline_layout; |
| 7802 | gp_ci.renderPass = renderPass(); |
| 7803 | |
| 7804 | VkPipelineCacheCreateInfo pc_ci = {}; |
| 7805 | pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO; |
| 7806 | pc_ci.pNext = NULL; |
| 7807 | pc_ci.initialSize = 0; |
| 7808 | pc_ci.initialData = 0; |
| 7809 | pc_ci.maxSize = 0; |
| 7810 | |
| 7811 | VkPipeline pipeline; |
| 7812 | VkPipelineCache pipelineCache; |
| 7813 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7814 | err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, |
| 7815 | &pipelineCache); |
Tobin Ehlis | 912df02 | 2015-09-17 08:46:18 -0600 | [diff] [blame] | 7816 | ASSERT_VK_SUCCESS(err); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7817 | err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, |
| 7818 | &gp_ci, NULL, &pipeline); |
Tobin Ehlis | 912df02 | 2015-09-17 08:46:18 -0600 | [diff] [blame] | 7819 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 7820 | m_errorMonitor->VerifyFound(); |
Mike Stroyan | d1c84a5 | 2015-08-18 14:40:24 -0600 | [diff] [blame] | 7821 | |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 7822 | vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL); |
| 7823 | vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL); |
| 7824 | vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL); |
| 7825 | vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL); |
Tobin Ehlis | 912df02 | 2015-09-17 08:46:18 -0600 | [diff] [blame] | 7826 | } |
| 7827 | */ |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 7828 | // Set scissor and viewport counts to different numbers |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7829 | TEST_F(VkLayerTest, PSOViewportScissorCountMismatch) { |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7830 | VkResult err; |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 7831 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7832 | m_errorMonitor->SetDesiredFailureMsg( |
| 7833 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 7834 | "Gfx Pipeline viewport count (1) must match scissor count (0)."); |
| 7835 | |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 7836 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 7837 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 7838 | |
Chia-I Wu | 1b99bb2 | 2015-10-27 19:25:11 +0800 | [diff] [blame] | 7839 | VkDescriptorPoolSize ds_type_count = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7840 | ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 7841 | ds_type_count.descriptorCount = 1; |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 7842 | |
| 7843 | VkDescriptorPoolCreateInfo ds_pool_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7844 | ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO; |
| 7845 | ds_pool_ci.maxSets = 1; |
| 7846 | ds_pool_ci.poolSizeCount = 1; |
| 7847 | ds_pool_ci.pPoolSizes = &ds_type_count; |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 7848 | |
| 7849 | VkDescriptorPool ds_pool; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7850 | err = |
| 7851 | vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool); |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 7852 | ASSERT_VK_SUCCESS(err); |
| 7853 | |
| 7854 | VkDescriptorSetLayoutBinding dsl_binding = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7855 | dsl_binding.binding = 0; |
| 7856 | dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 7857 | dsl_binding.descriptorCount = 1; |
| 7858 | dsl_binding.stageFlags = VK_SHADER_STAGE_ALL; |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 7859 | |
| 7860 | VkDescriptorSetLayoutCreateInfo ds_layout_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7861 | ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO; |
| 7862 | ds_layout_ci.bindingCount = 1; |
| 7863 | ds_layout_ci.pBindings = &dsl_binding; |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 7864 | |
| 7865 | VkDescriptorSetLayout ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7866 | err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, |
| 7867 | &ds_layout); |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 7868 | ASSERT_VK_SUCCESS(err); |
| 7869 | |
| 7870 | VkDescriptorSet descriptorSet; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 7871 | VkDescriptorSetAllocateInfo alloc_info = {}; |
Chia-I Wu | 00ce540 | 2015-11-10 16:21:09 +0800 | [diff] [blame] | 7872 | alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO; |
Jon Ashburn | f19916e | 2016-01-11 13:12:43 -0700 | [diff] [blame] | 7873 | alloc_info.descriptorSetCount = 1; |
Courtney Goeltzenleuchter | bee18a9 | 2015-10-23 14:21:05 -0600 | [diff] [blame] | 7874 | alloc_info.descriptorPool = ds_pool; |
| 7875 | alloc_info.pSetLayouts = &ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7876 | err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, |
| 7877 | &descriptorSet); |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 7878 | ASSERT_VK_SUCCESS(err); |
| 7879 | |
| 7880 | VkPipelineLayoutCreateInfo pipeline_layout_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7881 | pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO; |
| 7882 | pipeline_layout_ci.setLayoutCount = 1; |
| 7883 | pipeline_layout_ci.pSetLayouts = &ds_layout; |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 7884 | |
| 7885 | VkPipelineLayout pipeline_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7886 | err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, |
| 7887 | &pipeline_layout); |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 7888 | ASSERT_VK_SUCCESS(err); |
| 7889 | |
| 7890 | VkViewport vp = {}; // Just need dummy vp to point to |
| 7891 | |
| 7892 | VkPipelineViewportStateCreateInfo vp_state_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7893 | vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO; |
| 7894 | vp_state_ci.scissorCount = 0; |
| 7895 | vp_state_ci.viewportCount = 1; // Count mismatch should cause error |
| 7896 | vp_state_ci.pViewports = &vp; |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 7897 | |
Karl Schultz | dfdb8d4 | 2016-03-08 10:30:21 -0700 | [diff] [blame] | 7898 | VkPipelineRasterizationStateCreateInfo rs_state_ci = {}; |
| 7899 | rs_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO; |
| 7900 | rs_state_ci.polygonMode = VK_POLYGON_MODE_FILL; |
| 7901 | rs_state_ci.cullMode = VK_CULL_MODE_BACK_BIT; |
| 7902 | rs_state_ci.frontFace = VK_FRONT_FACE_COUNTER_CLOCKWISE; |
| 7903 | rs_state_ci.depthClampEnable = VK_FALSE; |
| 7904 | rs_state_ci.rasterizerDiscardEnable = VK_FALSE; |
| 7905 | rs_state_ci.depthBiasEnable = VK_FALSE; |
| 7906 | |
Cody Northrop | eb3a6c1 | 2015-10-05 14:44:45 -0600 | [diff] [blame] | 7907 | VkPipelineShaderStageCreateInfo shaderStages[2]; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7908 | memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo)); |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 7909 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7910 | VkShaderObj vs(m_device, bindStateVertShaderText, |
| 7911 | VK_SHADER_STAGE_VERTEX_BIT, this); |
| 7912 | VkShaderObj fs(m_device, bindStateFragShaderText, |
| 7913 | VK_SHADER_STAGE_FRAGMENT_BIT, |
Karl Schultz | bdb7595 | 2016-04-19 11:36:49 -0600 | [diff] [blame] | 7914 | this); // We shouldn't need a fragment shader |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7915 | // but add it to be able to run on more devices |
Chia-I Wu | 28e0691 | 2015-10-31 00:31:16 +0800 | [diff] [blame] | 7916 | shaderStages[0] = vs.GetStageCreateInfo(); |
| 7917 | shaderStages[1] = fs.GetStageCreateInfo(); |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 7918 | |
| 7919 | VkGraphicsPipelineCreateInfo gp_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7920 | gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO; |
| 7921 | gp_ci.stageCount = 2; |
| 7922 | gp_ci.pStages = shaderStages; |
| 7923 | gp_ci.pViewportState = &vp_state_ci; |
Karl Schultz | dfdb8d4 | 2016-03-08 10:30:21 -0700 | [diff] [blame] | 7924 | gp_ci.pRasterizationState = &rs_state_ci; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7925 | gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT; |
| 7926 | gp_ci.layout = pipeline_layout; |
| 7927 | gp_ci.renderPass = renderPass(); |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 7928 | |
| 7929 | VkPipelineCacheCreateInfo pc_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7930 | pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO; |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 7931 | |
| 7932 | VkPipeline pipeline; |
| 7933 | VkPipelineCache pipelineCache; |
| 7934 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7935 | err = |
| 7936 | vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache); |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 7937 | ASSERT_VK_SUCCESS(err); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7938 | err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, |
| 7939 | &gp_ci, NULL, &pipeline); |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 7940 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 7941 | m_errorMonitor->VerifyFound(); |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 7942 | |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 7943 | vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL); |
| 7944 | vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL); |
| 7945 | vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL); |
| 7946 | vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL); |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 7947 | } |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7948 | // Don't set viewport state in PSO. This is an error b/c we always need this |
| 7949 | // state |
Tobin Ehlis | d332f28 | 2015-10-02 11:00:56 -0600 | [diff] [blame] | 7950 | // 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] | 7951 | TEST_F(VkLayerTest, PSOViewportStateNotSet) { |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 7952 | // Attempt to Create Gfx Pipeline w/o a VS |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7953 | VkResult err; |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 7954 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7955 | m_errorMonitor->SetDesiredFailureMsg( |
| 7956 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 7957 | "Gfx Pipeline pViewportState is null. Even if "); |
| 7958 | |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 7959 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 7960 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 7961 | |
Chia-I Wu | 1b99bb2 | 2015-10-27 19:25:11 +0800 | [diff] [blame] | 7962 | VkDescriptorPoolSize ds_type_count = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7963 | ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 7964 | ds_type_count.descriptorCount = 1; |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 7965 | |
| 7966 | VkDescriptorPoolCreateInfo ds_pool_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7967 | ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO; |
| 7968 | ds_pool_ci.maxSets = 1; |
| 7969 | ds_pool_ci.poolSizeCount = 1; |
| 7970 | ds_pool_ci.pPoolSizes = &ds_type_count; |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 7971 | |
| 7972 | VkDescriptorPool ds_pool; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7973 | err = |
| 7974 | vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool); |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 7975 | ASSERT_VK_SUCCESS(err); |
| 7976 | |
| 7977 | VkDescriptorSetLayoutBinding dsl_binding = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7978 | dsl_binding.binding = 0; |
| 7979 | dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 7980 | dsl_binding.descriptorCount = 1; |
| 7981 | dsl_binding.stageFlags = VK_SHADER_STAGE_ALL; |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 7982 | |
| 7983 | VkDescriptorSetLayoutCreateInfo ds_layout_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7984 | ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO; |
| 7985 | ds_layout_ci.bindingCount = 1; |
| 7986 | ds_layout_ci.pBindings = &dsl_binding; |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 7987 | |
| 7988 | VkDescriptorSetLayout ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7989 | err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, |
| 7990 | &ds_layout); |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 7991 | ASSERT_VK_SUCCESS(err); |
| 7992 | |
| 7993 | VkDescriptorSet descriptorSet; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 7994 | VkDescriptorSetAllocateInfo alloc_info = {}; |
Chia-I Wu | 00ce540 | 2015-11-10 16:21:09 +0800 | [diff] [blame] | 7995 | alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO; |
Jon Ashburn | f19916e | 2016-01-11 13:12:43 -0700 | [diff] [blame] | 7996 | alloc_info.descriptorSetCount = 1; |
Courtney Goeltzenleuchter | bee18a9 | 2015-10-23 14:21:05 -0600 | [diff] [blame] | 7997 | alloc_info.descriptorPool = ds_pool; |
| 7998 | alloc_info.pSetLayouts = &ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7999 | err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, |
| 8000 | &descriptorSet); |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 8001 | ASSERT_VK_SUCCESS(err); |
| 8002 | |
| 8003 | VkPipelineLayoutCreateInfo pipeline_layout_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8004 | pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO; |
| 8005 | pipeline_layout_ci.setLayoutCount = 1; |
| 8006 | pipeline_layout_ci.pSetLayouts = &ds_layout; |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 8007 | |
| 8008 | VkPipelineLayout pipeline_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8009 | err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, |
| 8010 | &pipeline_layout); |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 8011 | ASSERT_VK_SUCCESS(err); |
| 8012 | |
| 8013 | VkDynamicState sc_state = VK_DYNAMIC_STATE_SCISSOR; |
| 8014 | // Set scissor as dynamic to avoid second error |
| 8015 | VkPipelineDynamicStateCreateInfo dyn_state_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8016 | dyn_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO; |
| 8017 | dyn_state_ci.dynamicStateCount = 1; |
| 8018 | dyn_state_ci.pDynamicStates = &sc_state; |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 8019 | |
Cody Northrop | eb3a6c1 | 2015-10-05 14:44:45 -0600 | [diff] [blame] | 8020 | VkPipelineShaderStageCreateInfo shaderStages[2]; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8021 | memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo)); |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 8022 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8023 | VkShaderObj vs(m_device, bindStateVertShaderText, |
| 8024 | VK_SHADER_STAGE_VERTEX_BIT, this); |
| 8025 | VkShaderObj fs(m_device, bindStateFragShaderText, |
| 8026 | VK_SHADER_STAGE_FRAGMENT_BIT, |
Karl Schultz | bdb7595 | 2016-04-19 11:36:49 -0600 | [diff] [blame] | 8027 | this); // We shouldn't need a fragment shader |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8028 | // but add it to be able to run on more devices |
Chia-I Wu | 28e0691 | 2015-10-31 00:31:16 +0800 | [diff] [blame] | 8029 | shaderStages[0] = vs.GetStageCreateInfo(); |
| 8030 | shaderStages[1] = fs.GetStageCreateInfo(); |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 8031 | |
Karl Schultz | dfdb8d4 | 2016-03-08 10:30:21 -0700 | [diff] [blame] | 8032 | |
| 8033 | VkPipelineRasterizationStateCreateInfo rs_state_ci = {}; |
| 8034 | rs_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO; |
| 8035 | rs_state_ci.polygonMode = VK_POLYGON_MODE_FILL; |
| 8036 | rs_state_ci.cullMode = VK_CULL_MODE_BACK_BIT; |
| 8037 | rs_state_ci.frontFace = VK_FRONT_FACE_COUNTER_CLOCKWISE; |
| 8038 | rs_state_ci.depthClampEnable = VK_FALSE; |
| 8039 | rs_state_ci.rasterizerDiscardEnable = VK_FALSE; |
| 8040 | rs_state_ci.depthBiasEnable = VK_FALSE; |
| 8041 | |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 8042 | VkGraphicsPipelineCreateInfo gp_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8043 | gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO; |
| 8044 | gp_ci.stageCount = 2; |
| 8045 | gp_ci.pStages = shaderStages; |
Karl Schultz | dfdb8d4 | 2016-03-08 10:30:21 -0700 | [diff] [blame] | 8046 | gp_ci.pRasterizationState = &rs_state_ci; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8047 | gp_ci.pViewportState = NULL; // Not setting VP state w/o dynamic vp state |
| 8048 | // should cause validation error |
| 8049 | gp_ci.pDynamicState = &dyn_state_ci; |
| 8050 | gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT; |
| 8051 | gp_ci.layout = pipeline_layout; |
| 8052 | gp_ci.renderPass = renderPass(); |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 8053 | |
| 8054 | VkPipelineCacheCreateInfo pc_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8055 | pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO; |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 8056 | |
| 8057 | VkPipeline pipeline; |
| 8058 | VkPipelineCache pipelineCache; |
| 8059 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8060 | err = |
| 8061 | vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache); |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 8062 | ASSERT_VK_SUCCESS(err); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8063 | err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, |
| 8064 | &gp_ci, NULL, &pipeline); |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 8065 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 8066 | m_errorMonitor->VerifyFound(); |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 8067 | |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 8068 | vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL); |
| 8069 | vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL); |
| 8070 | vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL); |
| 8071 | vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL); |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 8072 | } |
| 8073 | // Create PSO w/o non-zero viewportCount but no viewport data |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8074 | // Then run second test where dynamic scissor count doesn't match PSO scissor |
| 8075 | // count |
| 8076 | TEST_F(VkLayerTest, PSOViewportCountWithoutDataAndDynScissorMismatch) { |
| 8077 | VkResult err; |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 8078 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8079 | m_errorMonitor->SetDesiredFailureMsg( |
| 8080 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 8081 | "Gfx Pipeline viewportCount is 1, but pViewports is NULL. "); |
| 8082 | |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 8083 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 8084 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 8085 | |
Chia-I Wu | 1b99bb2 | 2015-10-27 19:25:11 +0800 | [diff] [blame] | 8086 | VkDescriptorPoolSize ds_type_count = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8087 | ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 8088 | ds_type_count.descriptorCount = 1; |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 8089 | |
| 8090 | VkDescriptorPoolCreateInfo ds_pool_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8091 | ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO; |
| 8092 | ds_pool_ci.maxSets = 1; |
| 8093 | ds_pool_ci.poolSizeCount = 1; |
| 8094 | ds_pool_ci.pPoolSizes = &ds_type_count; |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 8095 | |
| 8096 | VkDescriptorPool ds_pool; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8097 | err = |
| 8098 | vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool); |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 8099 | ASSERT_VK_SUCCESS(err); |
| 8100 | |
| 8101 | VkDescriptorSetLayoutBinding dsl_binding = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8102 | dsl_binding.binding = 0; |
| 8103 | dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 8104 | dsl_binding.descriptorCount = 1; |
| 8105 | dsl_binding.stageFlags = VK_SHADER_STAGE_ALL; |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 8106 | |
| 8107 | VkDescriptorSetLayoutCreateInfo ds_layout_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8108 | ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO; |
| 8109 | ds_layout_ci.bindingCount = 1; |
| 8110 | ds_layout_ci.pBindings = &dsl_binding; |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 8111 | |
| 8112 | VkDescriptorSetLayout ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8113 | err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, |
| 8114 | &ds_layout); |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 8115 | ASSERT_VK_SUCCESS(err); |
| 8116 | |
| 8117 | VkDescriptorSet descriptorSet; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 8118 | VkDescriptorSetAllocateInfo alloc_info = {}; |
Chia-I Wu | 00ce540 | 2015-11-10 16:21:09 +0800 | [diff] [blame] | 8119 | alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO; |
Jon Ashburn | f19916e | 2016-01-11 13:12:43 -0700 | [diff] [blame] | 8120 | alloc_info.descriptorSetCount = 1; |
Courtney Goeltzenleuchter | bee18a9 | 2015-10-23 14:21:05 -0600 | [diff] [blame] | 8121 | alloc_info.descriptorPool = ds_pool; |
| 8122 | alloc_info.pSetLayouts = &ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8123 | err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, |
| 8124 | &descriptorSet); |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 8125 | ASSERT_VK_SUCCESS(err); |
| 8126 | |
| 8127 | VkPipelineLayoutCreateInfo pipeline_layout_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8128 | pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO; |
| 8129 | pipeline_layout_ci.setLayoutCount = 1; |
| 8130 | pipeline_layout_ci.pSetLayouts = &ds_layout; |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 8131 | |
| 8132 | VkPipelineLayout pipeline_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8133 | err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, |
| 8134 | &pipeline_layout); |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 8135 | ASSERT_VK_SUCCESS(err); |
| 8136 | |
| 8137 | VkPipelineViewportStateCreateInfo vp_state_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8138 | vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO; |
| 8139 | vp_state_ci.viewportCount = 1; |
| 8140 | vp_state_ci.pViewports = NULL; // Null vp w/ count of 1 should cause error |
| 8141 | vp_state_ci.scissorCount = 1; |
| 8142 | vp_state_ci.pScissors = |
| 8143 | NULL; // Scissor is dynamic (below) so this won't cause error |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 8144 | |
| 8145 | VkDynamicState sc_state = VK_DYNAMIC_STATE_SCISSOR; |
| 8146 | // Set scissor as dynamic to avoid that error |
| 8147 | VkPipelineDynamicStateCreateInfo dyn_state_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8148 | dyn_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO; |
| 8149 | dyn_state_ci.dynamicStateCount = 1; |
| 8150 | dyn_state_ci.pDynamicStates = &sc_state; |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 8151 | |
Cody Northrop | eb3a6c1 | 2015-10-05 14:44:45 -0600 | [diff] [blame] | 8152 | VkPipelineShaderStageCreateInfo shaderStages[2]; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8153 | memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo)); |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 8154 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8155 | VkShaderObj vs(m_device, bindStateVertShaderText, |
| 8156 | VK_SHADER_STAGE_VERTEX_BIT, this); |
| 8157 | VkShaderObj fs(m_device, bindStateFragShaderText, |
| 8158 | VK_SHADER_STAGE_FRAGMENT_BIT, |
Karl Schultz | bdb7595 | 2016-04-19 11:36:49 -0600 | [diff] [blame] | 8159 | this); // We shouldn't need a fragment shader |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8160 | // but add it to be able to run on more devices |
Chia-I Wu | 28e0691 | 2015-10-31 00:31:16 +0800 | [diff] [blame] | 8161 | shaderStages[0] = vs.GetStageCreateInfo(); |
| 8162 | shaderStages[1] = fs.GetStageCreateInfo(); |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 8163 | |
Cody Northrop | f6622dc | 2015-10-06 10:33:21 -0600 | [diff] [blame] | 8164 | VkPipelineVertexInputStateCreateInfo vi_ci = {}; |
| 8165 | vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO; |
| 8166 | vi_ci.pNext = nullptr; |
Chia-I Wu | d50a7d7 | 2015-10-26 20:48:51 +0800 | [diff] [blame] | 8167 | vi_ci.vertexBindingDescriptionCount = 0; |
Cody Northrop | f6622dc | 2015-10-06 10:33:21 -0600 | [diff] [blame] | 8168 | vi_ci.pVertexBindingDescriptions = nullptr; |
Chia-I Wu | d50a7d7 | 2015-10-26 20:48:51 +0800 | [diff] [blame] | 8169 | vi_ci.vertexAttributeDescriptionCount = 0; |
Cody Northrop | f6622dc | 2015-10-06 10:33:21 -0600 | [diff] [blame] | 8170 | vi_ci.pVertexAttributeDescriptions = nullptr; |
| 8171 | |
| 8172 | VkPipelineInputAssemblyStateCreateInfo ia_ci = {}; |
| 8173 | ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO; |
| 8174 | ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP; |
| 8175 | |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 8176 | VkPipelineRasterizationStateCreateInfo rs_ci = {}; |
Chia-I Wu | 1b99bb2 | 2015-10-27 19:25:11 +0800 | [diff] [blame] | 8177 | rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO; |
Cody Northrop | f6622dc | 2015-10-06 10:33:21 -0600 | [diff] [blame] | 8178 | rs_ci.pNext = nullptr; |
| 8179 | |
Mark Young | c89c631 | 2016-03-31 16:03:20 -0600 | [diff] [blame] | 8180 | VkPipelineColorBlendAttachmentState att = {}; |
| 8181 | att.blendEnable = VK_FALSE; |
| 8182 | att.colorWriteMask = 0xf; |
| 8183 | |
Cody Northrop | f6622dc | 2015-10-06 10:33:21 -0600 | [diff] [blame] | 8184 | VkPipelineColorBlendStateCreateInfo cb_ci = {}; |
| 8185 | cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO; |
| 8186 | cb_ci.pNext = nullptr; |
Mark Young | c89c631 | 2016-03-31 16:03:20 -0600 | [diff] [blame] | 8187 | cb_ci.attachmentCount = 1; |
| 8188 | cb_ci.pAttachments = &att; |
Cody Northrop | f6622dc | 2015-10-06 10:33:21 -0600 | [diff] [blame] | 8189 | |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 8190 | VkGraphicsPipelineCreateInfo gp_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8191 | gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO; |
| 8192 | gp_ci.stageCount = 2; |
| 8193 | gp_ci.pStages = shaderStages; |
| 8194 | gp_ci.pVertexInputState = &vi_ci; |
| 8195 | gp_ci.pInputAssemblyState = &ia_ci; |
| 8196 | gp_ci.pViewportState = &vp_state_ci; |
| 8197 | gp_ci.pRasterizationState = &rs_ci; |
| 8198 | gp_ci.pColorBlendState = &cb_ci; |
| 8199 | gp_ci.pDynamicState = &dyn_state_ci; |
| 8200 | gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT; |
| 8201 | gp_ci.layout = pipeline_layout; |
| 8202 | gp_ci.renderPass = renderPass(); |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 8203 | |
| 8204 | VkPipelineCacheCreateInfo pc_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8205 | pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO; |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 8206 | |
| 8207 | VkPipeline pipeline; |
| 8208 | VkPipelineCache pipelineCache; |
| 8209 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8210 | err = |
| 8211 | vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache); |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 8212 | ASSERT_VK_SUCCESS(err); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8213 | err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, |
| 8214 | &gp_ci, NULL, &pipeline); |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 8215 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 8216 | m_errorMonitor->VerifyFound(); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 8217 | |
Tobin Ehlis | d332f28 | 2015-10-02 11:00:56 -0600 | [diff] [blame] | 8218 | // 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] | 8219 | // First need to successfully create the PSO from above by setting |
| 8220 | // pViewports |
| 8221 | m_errorMonitor->SetDesiredFailureMsg( |
| 8222 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 8223 | "Dynamic scissorCount from vkCmdSetScissor() is 2, but PSO " |
| 8224 | "scissorCount is 1. These counts must match."); |
| 8225 | |
| 8226 | VkViewport vp = {}; // Just need dummy vp to point to |
| 8227 | vp_state_ci.pViewports = &vp; |
| 8228 | err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, |
| 8229 | &gp_ci, NULL, &pipeline); |
| 8230 | ASSERT_VK_SUCCESS(err); |
| 8231 | BeginCommandBuffer(); |
| 8232 | vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), |
| 8233 | VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline); |
| 8234 | VkRect2D scissors[2] = {}; // don't care about data |
| 8235 | // Count of 2 doesn't match PSO count of 1 |
| 8236 | vkCmdSetScissor(m_commandBuffer->GetBufferHandle(), 0, 2, scissors); |
| 8237 | Draw(1, 0, 0, 0); |
| 8238 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 8239 | m_errorMonitor->VerifyFound(); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8240 | |
| 8241 | vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL); |
| 8242 | vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL); |
| 8243 | vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL); |
| 8244 | vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL); |
Tony Barbour | df4c004 | 2016-06-01 15:55:43 -0600 | [diff] [blame] | 8245 | vkDestroyPipeline(m_device->device(), pipeline, NULL); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8246 | } |
| 8247 | // Create PSO w/o non-zero scissorCount but no scissor data |
| 8248 | // Then run second test where dynamic viewportCount doesn't match PSO |
| 8249 | // viewportCount |
| 8250 | TEST_F(VkLayerTest, PSOScissorCountWithoutDataAndDynViewportMismatch) { |
| 8251 | VkResult err; |
| 8252 | |
| 8253 | m_errorMonitor->SetDesiredFailureMsg( |
| 8254 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 8255 | "Gfx Pipeline scissorCount is 1, but pScissors is NULL. "); |
| 8256 | |
| 8257 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 8258 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 8259 | |
| 8260 | VkDescriptorPoolSize ds_type_count = {}; |
| 8261 | ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 8262 | ds_type_count.descriptorCount = 1; |
| 8263 | |
| 8264 | VkDescriptorPoolCreateInfo ds_pool_ci = {}; |
| 8265 | ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO; |
| 8266 | ds_pool_ci.maxSets = 1; |
| 8267 | ds_pool_ci.poolSizeCount = 1; |
| 8268 | ds_pool_ci.pPoolSizes = &ds_type_count; |
| 8269 | |
| 8270 | VkDescriptorPool ds_pool; |
| 8271 | err = |
| 8272 | vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool); |
| 8273 | ASSERT_VK_SUCCESS(err); |
| 8274 | |
| 8275 | VkDescriptorSetLayoutBinding dsl_binding = {}; |
| 8276 | dsl_binding.binding = 0; |
| 8277 | dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 8278 | dsl_binding.descriptorCount = 1; |
| 8279 | dsl_binding.stageFlags = VK_SHADER_STAGE_ALL; |
| 8280 | |
| 8281 | VkDescriptorSetLayoutCreateInfo ds_layout_ci = {}; |
| 8282 | ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO; |
| 8283 | ds_layout_ci.bindingCount = 1; |
| 8284 | ds_layout_ci.pBindings = &dsl_binding; |
| 8285 | |
| 8286 | VkDescriptorSetLayout ds_layout; |
| 8287 | err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, |
| 8288 | &ds_layout); |
| 8289 | ASSERT_VK_SUCCESS(err); |
| 8290 | |
| 8291 | VkDescriptorSet descriptorSet; |
| 8292 | VkDescriptorSetAllocateInfo alloc_info = {}; |
| 8293 | alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO; |
| 8294 | alloc_info.descriptorSetCount = 1; |
| 8295 | alloc_info.descriptorPool = ds_pool; |
| 8296 | alloc_info.pSetLayouts = &ds_layout; |
| 8297 | err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, |
| 8298 | &descriptorSet); |
| 8299 | ASSERT_VK_SUCCESS(err); |
| 8300 | |
| 8301 | VkPipelineLayoutCreateInfo pipeline_layout_ci = {}; |
| 8302 | pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO; |
| 8303 | pipeline_layout_ci.setLayoutCount = 1; |
| 8304 | pipeline_layout_ci.pSetLayouts = &ds_layout; |
| 8305 | |
| 8306 | VkPipelineLayout pipeline_layout; |
| 8307 | err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, |
| 8308 | &pipeline_layout); |
| 8309 | ASSERT_VK_SUCCESS(err); |
| 8310 | |
| 8311 | VkPipelineViewportStateCreateInfo vp_state_ci = {}; |
| 8312 | vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO; |
| 8313 | vp_state_ci.scissorCount = 1; |
| 8314 | vp_state_ci.pScissors = |
| 8315 | NULL; // Null scissor w/ count of 1 should cause error |
| 8316 | vp_state_ci.viewportCount = 1; |
| 8317 | vp_state_ci.pViewports = |
| 8318 | NULL; // vp is dynamic (below) so this won't cause error |
| 8319 | |
| 8320 | VkDynamicState vp_state = VK_DYNAMIC_STATE_VIEWPORT; |
| 8321 | // Set scissor as dynamic to avoid that error |
| 8322 | VkPipelineDynamicStateCreateInfo dyn_state_ci = {}; |
| 8323 | dyn_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO; |
| 8324 | dyn_state_ci.dynamicStateCount = 1; |
| 8325 | dyn_state_ci.pDynamicStates = &vp_state; |
| 8326 | |
| 8327 | VkPipelineShaderStageCreateInfo shaderStages[2]; |
| 8328 | memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo)); |
| 8329 | |
| 8330 | VkShaderObj vs(m_device, bindStateVertShaderText, |
| 8331 | VK_SHADER_STAGE_VERTEX_BIT, this); |
| 8332 | VkShaderObj fs(m_device, bindStateFragShaderText, |
| 8333 | VK_SHADER_STAGE_FRAGMENT_BIT, |
Karl Schultz | bdb7595 | 2016-04-19 11:36:49 -0600 | [diff] [blame] | 8334 | this); // We shouldn't need a fragment shader |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8335 | // but add it to be able to run on more devices |
| 8336 | shaderStages[0] = vs.GetStageCreateInfo(); |
| 8337 | shaderStages[1] = fs.GetStageCreateInfo(); |
| 8338 | |
| 8339 | VkPipelineVertexInputStateCreateInfo vi_ci = {}; |
| 8340 | vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO; |
| 8341 | vi_ci.pNext = nullptr; |
| 8342 | vi_ci.vertexBindingDescriptionCount = 0; |
| 8343 | vi_ci.pVertexBindingDescriptions = nullptr; |
| 8344 | vi_ci.vertexAttributeDescriptionCount = 0; |
| 8345 | vi_ci.pVertexAttributeDescriptions = nullptr; |
| 8346 | |
| 8347 | VkPipelineInputAssemblyStateCreateInfo ia_ci = {}; |
| 8348 | ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO; |
| 8349 | ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP; |
| 8350 | |
| 8351 | VkPipelineRasterizationStateCreateInfo rs_ci = {}; |
| 8352 | rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO; |
| 8353 | rs_ci.pNext = nullptr; |
| 8354 | |
Mark Young | c89c631 | 2016-03-31 16:03:20 -0600 | [diff] [blame] | 8355 | VkPipelineColorBlendAttachmentState att = {}; |
| 8356 | att.blendEnable = VK_FALSE; |
| 8357 | att.colorWriteMask = 0xf; |
| 8358 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8359 | VkPipelineColorBlendStateCreateInfo cb_ci = {}; |
| 8360 | cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO; |
| 8361 | cb_ci.pNext = nullptr; |
Mark Young | c89c631 | 2016-03-31 16:03:20 -0600 | [diff] [blame] | 8362 | cb_ci.attachmentCount = 1; |
| 8363 | cb_ci.pAttachments = &att; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8364 | |
| 8365 | VkGraphicsPipelineCreateInfo gp_ci = {}; |
| 8366 | gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO; |
| 8367 | gp_ci.stageCount = 2; |
| 8368 | gp_ci.pStages = shaderStages; |
| 8369 | gp_ci.pVertexInputState = &vi_ci; |
| 8370 | gp_ci.pInputAssemblyState = &ia_ci; |
| 8371 | gp_ci.pViewportState = &vp_state_ci; |
| 8372 | gp_ci.pRasterizationState = &rs_ci; |
| 8373 | gp_ci.pColorBlendState = &cb_ci; |
| 8374 | gp_ci.pDynamicState = &dyn_state_ci; |
| 8375 | gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT; |
| 8376 | gp_ci.layout = pipeline_layout; |
| 8377 | gp_ci.renderPass = renderPass(); |
| 8378 | |
| 8379 | VkPipelineCacheCreateInfo pc_ci = {}; |
| 8380 | pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO; |
| 8381 | |
| 8382 | VkPipeline pipeline; |
| 8383 | VkPipelineCache pipelineCache; |
| 8384 | |
| 8385 | err = |
| 8386 | vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache); |
| 8387 | ASSERT_VK_SUCCESS(err); |
| 8388 | err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, |
| 8389 | &gp_ci, NULL, &pipeline); |
| 8390 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 8391 | m_errorMonitor->VerifyFound(); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8392 | |
| 8393 | // Now hit second fail case where we set scissor w/ different count than PSO |
| 8394 | // First need to successfully create the PSO from above by setting |
| 8395 | // pViewports |
| 8396 | m_errorMonitor->SetDesiredFailureMsg( |
| 8397 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 8398 | "Dynamic viewportCount from vkCmdSetViewport() is 2, but PSO " |
| 8399 | "viewportCount is 1. These counts must match."); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 8400 | |
Tobin Ehlis | d332f28 | 2015-10-02 11:00:56 -0600 | [diff] [blame] | 8401 | VkRect2D sc = {}; // Just need dummy vp to point to |
| 8402 | vp_state_ci.pScissors = ≻ |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8403 | err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, |
| 8404 | &gp_ci, NULL, &pipeline); |
Tobin Ehlis | d332f28 | 2015-10-02 11:00:56 -0600 | [diff] [blame] | 8405 | ASSERT_VK_SUCCESS(err); |
| 8406 | BeginCommandBuffer(); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8407 | vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), |
| 8408 | VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline); |
Tobin Ehlis | d332f28 | 2015-10-02 11:00:56 -0600 | [diff] [blame] | 8409 | VkViewport viewports[2] = {}; // don't care about data |
| 8410 | // Count of 2 doesn't match PSO count of 1 |
Jon Ashburn | 19d3bf1 | 2015-12-30 14:06:55 -0700 | [diff] [blame] | 8411 | vkCmdSetViewport(m_commandBuffer->GetBufferHandle(), 0, 2, viewports); |
Tobin Ehlis | d332f28 | 2015-10-02 11:00:56 -0600 | [diff] [blame] | 8412 | Draw(1, 0, 0, 0); |
| 8413 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 8414 | m_errorMonitor->VerifyFound(); |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 8415 | |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 8416 | vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL); |
| 8417 | vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL); |
| 8418 | vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL); |
| 8419 | vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL); |
Tony Barbour | df4c004 | 2016-06-01 15:55:43 -0600 | [diff] [blame] | 8420 | vkDestroyPipeline(m_device->device(), pipeline, NULL); |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 8421 | } |
| 8422 | |
Mark Young | 7394fdd | 2016-03-31 14:56:43 -0600 | [diff] [blame] | 8423 | TEST_F(VkLayerTest, PSOLineWidthInvalid) { |
| 8424 | VkResult err; |
| 8425 | |
| 8426 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Mark Young | 4710795 | 2016-05-02 15:59:55 -0600 | [diff] [blame] | 8427 | "Attempt to set lineWidth to -1"); |
Mark Young | 7394fdd | 2016-03-31 14:56:43 -0600 | [diff] [blame] | 8428 | |
| 8429 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 8430 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 8431 | |
| 8432 | VkDescriptorPoolSize ds_type_count = {}; |
| 8433 | ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 8434 | ds_type_count.descriptorCount = 1; |
| 8435 | |
| 8436 | VkDescriptorPoolCreateInfo ds_pool_ci = {}; |
| 8437 | ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO; |
| 8438 | ds_pool_ci.maxSets = 1; |
| 8439 | ds_pool_ci.poolSizeCount = 1; |
| 8440 | ds_pool_ci.pPoolSizes = &ds_type_count; |
| 8441 | |
| 8442 | VkDescriptorPool ds_pool; |
| 8443 | err = |
| 8444 | vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool); |
| 8445 | ASSERT_VK_SUCCESS(err); |
| 8446 | |
| 8447 | VkDescriptorSetLayoutBinding dsl_binding = {}; |
| 8448 | dsl_binding.binding = 0; |
| 8449 | dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 8450 | dsl_binding.descriptorCount = 1; |
| 8451 | dsl_binding.stageFlags = VK_SHADER_STAGE_ALL; |
| 8452 | |
| 8453 | VkDescriptorSetLayoutCreateInfo ds_layout_ci = {}; |
| 8454 | ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO; |
| 8455 | ds_layout_ci.bindingCount = 1; |
| 8456 | ds_layout_ci.pBindings = &dsl_binding; |
| 8457 | |
| 8458 | VkDescriptorSetLayout ds_layout; |
| 8459 | err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, |
| 8460 | &ds_layout); |
| 8461 | ASSERT_VK_SUCCESS(err); |
| 8462 | |
| 8463 | VkDescriptorSet descriptorSet; |
| 8464 | VkDescriptorSetAllocateInfo alloc_info = {}; |
| 8465 | alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO; |
| 8466 | alloc_info.descriptorSetCount = 1; |
| 8467 | alloc_info.descriptorPool = ds_pool; |
| 8468 | alloc_info.pSetLayouts = &ds_layout; |
| 8469 | err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, |
| 8470 | &descriptorSet); |
| 8471 | ASSERT_VK_SUCCESS(err); |
| 8472 | |
| 8473 | VkPipelineLayoutCreateInfo pipeline_layout_ci = {}; |
| 8474 | pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO; |
| 8475 | pipeline_layout_ci.setLayoutCount = 1; |
| 8476 | pipeline_layout_ci.pSetLayouts = &ds_layout; |
| 8477 | |
| 8478 | VkPipelineLayout pipeline_layout; |
| 8479 | err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, |
| 8480 | &pipeline_layout); |
| 8481 | ASSERT_VK_SUCCESS(err); |
| 8482 | |
| 8483 | VkPipelineViewportStateCreateInfo vp_state_ci = {}; |
| 8484 | vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO; |
| 8485 | vp_state_ci.scissorCount = 1; |
| 8486 | vp_state_ci.pScissors = NULL; |
| 8487 | vp_state_ci.viewportCount = 1; |
| 8488 | vp_state_ci.pViewports = NULL; |
| 8489 | |
| 8490 | VkDynamicState dynamic_states[3] = {VK_DYNAMIC_STATE_VIEWPORT, |
| 8491 | VK_DYNAMIC_STATE_SCISSOR, |
| 8492 | VK_DYNAMIC_STATE_LINE_WIDTH}; |
| 8493 | // Set scissor as dynamic to avoid that error |
| 8494 | VkPipelineDynamicStateCreateInfo dyn_state_ci = {}; |
| 8495 | dyn_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO; |
| 8496 | dyn_state_ci.dynamicStateCount = 2; |
| 8497 | dyn_state_ci.pDynamicStates = dynamic_states; |
| 8498 | |
| 8499 | VkPipelineShaderStageCreateInfo shaderStages[2]; |
| 8500 | memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo)); |
| 8501 | |
| 8502 | VkShaderObj vs(m_device, bindStateVertShaderText, |
| 8503 | VK_SHADER_STAGE_VERTEX_BIT, this); |
| 8504 | VkShaderObj fs(m_device, bindStateFragShaderText, |
| 8505 | VK_SHADER_STAGE_FRAGMENT_BIT, |
| 8506 | this); // TODO - We shouldn't need a fragment shader |
| 8507 | // but add it to be able to run on more devices |
| 8508 | shaderStages[0] = vs.GetStageCreateInfo(); |
| 8509 | shaderStages[1] = fs.GetStageCreateInfo(); |
| 8510 | |
| 8511 | VkPipelineVertexInputStateCreateInfo vi_ci = {}; |
| 8512 | vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO; |
| 8513 | vi_ci.pNext = nullptr; |
| 8514 | vi_ci.vertexBindingDescriptionCount = 0; |
| 8515 | vi_ci.pVertexBindingDescriptions = nullptr; |
| 8516 | vi_ci.vertexAttributeDescriptionCount = 0; |
| 8517 | vi_ci.pVertexAttributeDescriptions = nullptr; |
| 8518 | |
| 8519 | VkPipelineInputAssemblyStateCreateInfo ia_ci = {}; |
| 8520 | ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO; |
| 8521 | ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP; |
| 8522 | |
| 8523 | VkPipelineRasterizationStateCreateInfo rs_ci = {}; |
| 8524 | rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO; |
| 8525 | rs_ci.pNext = nullptr; |
| 8526 | |
Mark Young | 4710795 | 2016-05-02 15:59:55 -0600 | [diff] [blame] | 8527 | // Check too low (line width of -1.0f). |
| 8528 | rs_ci.lineWidth = -1.0f; |
Mark Young | 7394fdd | 2016-03-31 14:56:43 -0600 | [diff] [blame] | 8529 | |
| 8530 | VkPipelineColorBlendAttachmentState att = {}; |
| 8531 | att.blendEnable = VK_FALSE; |
| 8532 | att.colorWriteMask = 0xf; |
| 8533 | |
| 8534 | VkPipelineColorBlendStateCreateInfo cb_ci = {}; |
| 8535 | cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO; |
| 8536 | cb_ci.pNext = nullptr; |
| 8537 | cb_ci.attachmentCount = 1; |
| 8538 | cb_ci.pAttachments = &att; |
| 8539 | |
| 8540 | VkGraphicsPipelineCreateInfo gp_ci = {}; |
| 8541 | gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO; |
| 8542 | gp_ci.stageCount = 2; |
| 8543 | gp_ci.pStages = shaderStages; |
| 8544 | gp_ci.pVertexInputState = &vi_ci; |
| 8545 | gp_ci.pInputAssemblyState = &ia_ci; |
| 8546 | gp_ci.pViewportState = &vp_state_ci; |
| 8547 | gp_ci.pRasterizationState = &rs_ci; |
| 8548 | gp_ci.pColorBlendState = &cb_ci; |
| 8549 | gp_ci.pDynamicState = &dyn_state_ci; |
| 8550 | gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT; |
| 8551 | gp_ci.layout = pipeline_layout; |
| 8552 | gp_ci.renderPass = renderPass(); |
| 8553 | |
| 8554 | VkPipelineCacheCreateInfo pc_ci = {}; |
| 8555 | pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO; |
| 8556 | |
| 8557 | VkPipeline pipeline; |
| 8558 | VkPipelineCache pipelineCache; |
| 8559 | |
| 8560 | err = |
| 8561 | vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache); |
| 8562 | ASSERT_VK_SUCCESS(err); |
| 8563 | err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, |
| 8564 | &gp_ci, NULL, &pipeline); |
| 8565 | |
| 8566 | m_errorMonitor->VerifyFound(); |
Tony Barbour | df4c004 | 2016-06-01 15:55:43 -0600 | [diff] [blame] | 8567 | vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL); |
Mark Young | 7394fdd | 2016-03-31 14:56:43 -0600 | [diff] [blame] | 8568 | |
| 8569 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 8570 | "Attempt to set lineWidth to 65536"); |
| 8571 | |
| 8572 | // Check too high (line width of 65536.0f). |
| 8573 | rs_ci.lineWidth = 65536.0f; |
| 8574 | |
| 8575 | err = |
| 8576 | vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache); |
| 8577 | ASSERT_VK_SUCCESS(err); |
| 8578 | err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, |
| 8579 | &gp_ci, NULL, &pipeline); |
| 8580 | |
| 8581 | m_errorMonitor->VerifyFound(); |
Tony Barbour | df4c004 | 2016-06-01 15:55:43 -0600 | [diff] [blame] | 8582 | vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL); |
Mark Young | 7394fdd | 2016-03-31 14:56:43 -0600 | [diff] [blame] | 8583 | |
| 8584 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Mark Young | 4710795 | 2016-05-02 15:59:55 -0600 | [diff] [blame] | 8585 | "Attempt to set lineWidth to -1"); |
Mark Young | 7394fdd | 2016-03-31 14:56:43 -0600 | [diff] [blame] | 8586 | |
| 8587 | dyn_state_ci.dynamicStateCount = 3; |
| 8588 | |
| 8589 | rs_ci.lineWidth = 1.0f; |
| 8590 | |
| 8591 | err = |
| 8592 | vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache); |
| 8593 | ASSERT_VK_SUCCESS(err); |
| 8594 | err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, |
| 8595 | &gp_ci, NULL, &pipeline); |
| 8596 | BeginCommandBuffer(); |
| 8597 | vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), |
| 8598 | VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline); |
| 8599 | |
| 8600 | // Check too low with dynamic setting. |
Mark Young | 4710795 | 2016-05-02 15:59:55 -0600 | [diff] [blame] | 8601 | vkCmdSetLineWidth(m_commandBuffer->GetBufferHandle(), -1.0f); |
Mark Young | 7394fdd | 2016-03-31 14:56:43 -0600 | [diff] [blame] | 8602 | m_errorMonitor->VerifyFound(); |
| 8603 | |
| 8604 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 8605 | "Attempt to set lineWidth to 65536"); |
| 8606 | |
| 8607 | // Check too high with dynamic setting. |
| 8608 | vkCmdSetLineWidth(m_commandBuffer->GetBufferHandle(), 65536.0f); |
| 8609 | m_errorMonitor->VerifyFound(); |
| 8610 | EndCommandBuffer(); |
| 8611 | |
| 8612 | vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL); |
| 8613 | vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL); |
| 8614 | vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL); |
| 8615 | vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL); |
Tony Barbour | df4c004 | 2016-06-01 15:55:43 -0600 | [diff] [blame] | 8616 | vkDestroyPipeline(m_device->device(), pipeline, NULL); |
Mark Young | 7394fdd | 2016-03-31 14:56:43 -0600 | [diff] [blame] | 8617 | } |
| 8618 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8619 | TEST_F(VkLayerTest, NullRenderPass) { |
Tobin Ehlis | 98aa0ed | 2015-06-25 16:27:19 -0600 | [diff] [blame] | 8620 | // Bind a NULL RenderPass |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8621 | m_errorMonitor->SetDesiredFailureMsg( |
| 8622 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 8623 | "You cannot use a NULL RenderPass object in vkCmdBeginRenderPass()"); |
Tobin Ehlis | 98aa0ed | 2015-06-25 16:27:19 -0600 | [diff] [blame] | 8624 | |
| 8625 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 8626 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
Tobin Ehlis | 98aa0ed | 2015-06-25 16:27:19 -0600 | [diff] [blame] | 8627 | |
Tony Barbour | fe3351b | 2015-07-28 10:17:20 -0600 | [diff] [blame] | 8628 | BeginCommandBuffer(); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8629 | // Don't care about RenderPass handle b/c error should be flagged before |
| 8630 | // that |
| 8631 | vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), NULL, |
| 8632 | VK_SUBPASS_CONTENTS_INLINE); |
Tobin Ehlis | 98aa0ed | 2015-06-25 16:27:19 -0600 | [diff] [blame] | 8633 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 8634 | m_errorMonitor->VerifyFound(); |
Tobin Ehlis | 98aa0ed | 2015-06-25 16:27:19 -0600 | [diff] [blame] | 8635 | } |
| 8636 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8637 | TEST_F(VkLayerTest, RenderPassWithinRenderPass) { |
Tobin Ehlis | af1f3a4 | 2015-06-25 15:46:59 -0600 | [diff] [blame] | 8638 | // Bind a BeginRenderPass within an active RenderPass |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8639 | m_errorMonitor->SetDesiredFailureMsg( |
| 8640 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 8641 | "It is invalid to issue this call inside an active render pass"); |
Tobin Ehlis | af1f3a4 | 2015-06-25 15:46:59 -0600 | [diff] [blame] | 8642 | |
| 8643 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 8644 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
Tobin Ehlis | af1f3a4 | 2015-06-25 15:46:59 -0600 | [diff] [blame] | 8645 | |
Tony Barbour | fe3351b | 2015-07-28 10:17:20 -0600 | [diff] [blame] | 8646 | BeginCommandBuffer(); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8647 | // Just create a dummy Renderpass that's non-NULL so we can get to the |
| 8648 | // proper error |
Chris Forbes | 38ae7c4 | 2016-06-21 20:51:44 +1200 | [diff] [blame] | 8649 | vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &m_renderPassBeginInfo, |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8650 | VK_SUBPASS_CONTENTS_INLINE); |
Tobin Ehlis | af1f3a4 | 2015-06-25 15:46:59 -0600 | [diff] [blame] | 8651 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 8652 | m_errorMonitor->VerifyFound(); |
Tobin Ehlis | 49eb23d | 2015-05-22 12:38:55 -0600 | [diff] [blame] | 8653 | } |
| 8654 | |
Chris Forbes | 2eeabe3 | 2016-06-21 20:52:34 +1200 | [diff] [blame] | 8655 | TEST_F(VkLayerTest, RenderPassSecondaryCommandBuffersMultipleTimes) { |
| 8656 | m_errorMonitor->ExpectSuccess(); |
| 8657 | |
| 8658 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 8659 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 8660 | |
| 8661 | BeginCommandBuffer(); // framework implicitly begins the renderpass. |
| 8662 | vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle()); // end implicit. |
| 8663 | |
| 8664 | vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &m_renderPassBeginInfo, |
| 8665 | VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS); |
| 8666 | vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle()); |
| 8667 | m_errorMonitor->VerifyNotFound(); |
| 8668 | vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &m_renderPassBeginInfo, |
| 8669 | VK_SUBPASS_CONTENTS_INLINE); |
| 8670 | m_errorMonitor->VerifyNotFound(); |
| 8671 | vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle()); |
| 8672 | m_errorMonitor->VerifyNotFound(); |
| 8673 | |
| 8674 | m_commandBuffer->EndCommandBuffer(); |
| 8675 | m_errorMonitor->VerifyNotFound(); |
| 8676 | } |
| 8677 | |
Tobin Ehlis | 5a1c033 | 2016-05-31 13:59:26 -0600 | [diff] [blame] | 8678 | TEST_F(VkLayerTest, RenderPassClearOpMismatch) { |
| 8679 | TEST_DESCRIPTION("Begin a renderPass where clearValueCount is less than" |
| 8680 | "the number of renderPass attachments that use loadOp" |
| 8681 | "VK_ATTACHMENT_LOAD_OP_CLEAR."); |
| 8682 | |
| 8683 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 8684 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 8685 | |
| 8686 | // Create a renderPass with a single attachment that uses loadOp CLEAR |
| 8687 | VkAttachmentReference attach = {}; |
| 8688 | attach.layout = VK_IMAGE_LAYOUT_GENERAL; |
| 8689 | VkSubpassDescription subpass = {}; |
| 8690 | subpass.inputAttachmentCount = 1; |
| 8691 | subpass.pInputAttachments = &attach; |
| 8692 | VkRenderPassCreateInfo rpci = {}; |
| 8693 | rpci.subpassCount = 1; |
| 8694 | rpci.pSubpasses = &subpass; |
| 8695 | rpci.attachmentCount = 1; |
| 8696 | VkAttachmentDescription attach_desc = {}; |
| 8697 | attach_desc.format = VK_FORMAT_UNDEFINED; |
| 8698 | // Set loadOp to CLEAR |
| 8699 | attach_desc.loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR; |
| 8700 | rpci.pAttachments = &attach_desc; |
| 8701 | rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO; |
| 8702 | VkRenderPass rp; |
| 8703 | vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp); |
| 8704 | |
| 8705 | VkCommandBufferInheritanceInfo hinfo = {}; |
| 8706 | hinfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO; |
| 8707 | hinfo.renderPass = VK_NULL_HANDLE; |
| 8708 | hinfo.subpass = 0; |
| 8709 | hinfo.framebuffer = VK_NULL_HANDLE; |
| 8710 | hinfo.occlusionQueryEnable = VK_FALSE; |
| 8711 | hinfo.queryFlags = 0; |
| 8712 | hinfo.pipelineStatistics = 0; |
| 8713 | VkCommandBufferBeginInfo info = {}; |
| 8714 | info.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT; |
| 8715 | info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO; |
| 8716 | info.pInheritanceInfo = &hinfo; |
| 8717 | |
| 8718 | vkBeginCommandBuffer(m_commandBuffer->handle(), &info); |
| 8719 | VkRenderPassBeginInfo rp_begin = {}; |
| 8720 | rp_begin.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO; |
| 8721 | rp_begin.pNext = NULL; |
| 8722 | rp_begin.renderPass = renderPass(); |
| 8723 | rp_begin.framebuffer = framebuffer(); |
| 8724 | rp_begin.clearValueCount = 0; // Should be 1 |
| 8725 | |
| 8726 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 8727 | " has a clearValueCount of 0 but the " |
| 8728 | "actual number of attachments in " |
| 8729 | "renderPass "); |
| 8730 | |
| 8731 | vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &rp_begin, |
| 8732 | VK_SUBPASS_CONTENTS_INLINE); |
| 8733 | |
| 8734 | m_errorMonitor->VerifyFound(); |
Mark Lobodzinski | 5c70ebd | 2016-06-09 13:45:00 -0600 | [diff] [blame] | 8735 | |
| 8736 | vkDestroyRenderPass(m_device->device(), rp, NULL); |
Tobin Ehlis | 5a1c033 | 2016-05-31 13:59:26 -0600 | [diff] [blame] | 8737 | } |
| 8738 | |
Cody Northrop | 3bb4d96 | 2016-05-09 16:15:57 -0600 | [diff] [blame] | 8739 | TEST_F(VkLayerTest, EndCommandBufferWithinRenderPass) { |
| 8740 | |
| 8741 | TEST_DESCRIPTION("End a command buffer with an active render pass"); |
| 8742 | |
| 8743 | m_errorMonitor->SetDesiredFailureMsg( |
| 8744 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 8745 | "It is invalid to issue this call inside an active render pass"); |
| 8746 | |
| 8747 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 8748 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 8749 | |
| 8750 | // The framework's BeginCommandBuffer calls CreateRenderPass |
| 8751 | BeginCommandBuffer(); |
| 8752 | |
| 8753 | // Call directly into vkEndCommandBuffer instead of the |
| 8754 | // the framework's EndCommandBuffer, which inserts a |
| 8755 | // vkEndRenderPass |
| 8756 | vkEndCommandBuffer(m_commandBuffer->GetBufferHandle()); |
| 8757 | |
| 8758 | m_errorMonitor->VerifyFound(); |
| 8759 | |
| 8760 | // TODO: Add test for VK_COMMAND_BUFFER_LEVEL_SECONDARY |
| 8761 | // TODO: Add test for VK_COMMAND_BUFFER_USAGE_RENDER_PASS_CONTINUE_BIT |
| 8762 | } |
| 8763 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8764 | TEST_F(VkLayerTest, FillBufferWithinRenderPass) { |
Mark Lobodzinski | d563950 | 2015-09-24 09:51:47 -0600 | [diff] [blame] | 8765 | // Call CmdFillBuffer within an active renderpass |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8766 | m_errorMonitor->SetDesiredFailureMsg( |
| 8767 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 8768 | "It is invalid to issue this call inside an active render pass"); |
Mark Lobodzinski | d563950 | 2015-09-24 09:51:47 -0600 | [diff] [blame] | 8769 | |
| 8770 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 8771 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
Mark Lobodzinski | d563950 | 2015-09-24 09:51:47 -0600 | [diff] [blame] | 8772 | |
| 8773 | // Renderpass is started here |
| 8774 | BeginCommandBuffer(); |
| 8775 | |
| 8776 | VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 8777 | vk_testing::Buffer dstBuffer; |
| 8778 | dstBuffer.init_as_dst(*m_device, (VkDeviceSize)1024, reqs); |
Mark Lobodzinski | d563950 | 2015-09-24 09:51:47 -0600 | [diff] [blame] | 8779 | |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 8780 | m_commandBuffer->FillBuffer(dstBuffer.handle(), 0, 4, 0x11111111); |
Mark Lobodzinski | d563950 | 2015-09-24 09:51:47 -0600 | [diff] [blame] | 8781 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 8782 | m_errorMonitor->VerifyFound(); |
Mark Lobodzinski | d563950 | 2015-09-24 09:51:47 -0600 | [diff] [blame] | 8783 | } |
| 8784 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8785 | TEST_F(VkLayerTest, UpdateBufferWithinRenderPass) { |
Mark Lobodzinski | d563950 | 2015-09-24 09:51:47 -0600 | [diff] [blame] | 8786 | // Call CmdUpdateBuffer within an active renderpass |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8787 | m_errorMonitor->SetDesiredFailureMsg( |
| 8788 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 8789 | "It is invalid to issue this call inside an active render pass"); |
Mark Lobodzinski | d563950 | 2015-09-24 09:51:47 -0600 | [diff] [blame] | 8790 | |
| 8791 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 8792 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
Mark Lobodzinski | d563950 | 2015-09-24 09:51:47 -0600 | [diff] [blame] | 8793 | |
| 8794 | // Renderpass is started here |
| 8795 | BeginCommandBuffer(); |
| 8796 | |
| 8797 | VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 8798 | vk_testing::Buffer dstBuffer; |
| 8799 | dstBuffer.init_as_dst(*m_device, (VkDeviceSize)1024, reqs); |
Mark Lobodzinski | d563950 | 2015-09-24 09:51:47 -0600 | [diff] [blame] | 8800 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8801 | VkDeviceSize dstOffset = 0; |
| 8802 | VkDeviceSize dataSize = 1024; |
Karl Schultz | ee34449 | 2016-07-11 15:09:57 -0600 | [diff] [blame] | 8803 | const void *pData = NULL; |
Mark Lobodzinski | d563950 | 2015-09-24 09:51:47 -0600 | [diff] [blame] | 8804 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8805 | vkCmdUpdateBuffer(m_commandBuffer->GetBufferHandle(), dstBuffer.handle(), |
| 8806 | dstOffset, dataSize, pData); |
Mark Lobodzinski | d563950 | 2015-09-24 09:51:47 -0600 | [diff] [blame] | 8807 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 8808 | m_errorMonitor->VerifyFound(); |
Mark Lobodzinski | d563950 | 2015-09-24 09:51:47 -0600 | [diff] [blame] | 8809 | } |
| 8810 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8811 | TEST_F(VkLayerTest, ClearColorImageWithinRenderPass) { |
Mark Lobodzinski | d563950 | 2015-09-24 09:51:47 -0600 | [diff] [blame] | 8812 | // Call CmdClearColorImage within an active RenderPass |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8813 | m_errorMonitor->SetDesiredFailureMsg( |
| 8814 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 8815 | "It is invalid to issue this call inside an active render pass"); |
Mark Lobodzinski | d563950 | 2015-09-24 09:51:47 -0600 | [diff] [blame] | 8816 | |
| 8817 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 8818 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
Mark Lobodzinski | d563950 | 2015-09-24 09:51:47 -0600 | [diff] [blame] | 8819 | |
| 8820 | // Renderpass is started here |
| 8821 | BeginCommandBuffer(); |
| 8822 | |
Michael Lentine | 0a369f6 | 2016-02-03 16:51:46 -0600 | [diff] [blame] | 8823 | VkClearColorValue clear_color; |
| 8824 | memset(clear_color.uint32, 0, sizeof(uint32_t) * 4); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8825 | VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT; |
| 8826 | const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM; |
| 8827 | const int32_t tex_width = 32; |
| 8828 | const int32_t tex_height = 32; |
| 8829 | VkImageCreateInfo image_create_info = {}; |
| 8830 | image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO; |
| 8831 | image_create_info.pNext = NULL; |
| 8832 | image_create_info.imageType = VK_IMAGE_TYPE_2D; |
| 8833 | image_create_info.format = tex_format; |
| 8834 | image_create_info.extent.width = tex_width; |
| 8835 | image_create_info.extent.height = tex_height; |
| 8836 | image_create_info.extent.depth = 1; |
| 8837 | image_create_info.mipLevels = 1; |
| 8838 | image_create_info.arrayLayers = 1; |
| 8839 | image_create_info.samples = VK_SAMPLE_COUNT_1_BIT; |
| 8840 | image_create_info.tiling = VK_IMAGE_TILING_LINEAR; |
| 8841 | image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT; |
Mark Lobodzinski | d563950 | 2015-09-24 09:51:47 -0600 | [diff] [blame] | 8842 | |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 8843 | vk_testing::Image dstImage; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8844 | dstImage.init(*m_device, (const VkImageCreateInfo &)image_create_info, |
| 8845 | reqs); |
Mark Lobodzinski | d563950 | 2015-09-24 09:51:47 -0600 | [diff] [blame] | 8846 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8847 | const VkImageSubresourceRange range = vk_testing::Image::subresource_range( |
| 8848 | image_create_info, VK_IMAGE_ASPECT_COLOR_BIT); |
Mark Lobodzinski | d563950 | 2015-09-24 09:51:47 -0600 | [diff] [blame] | 8849 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8850 | vkCmdClearColorImage(m_commandBuffer->GetBufferHandle(), dstImage.handle(), |
| 8851 | VK_IMAGE_LAYOUT_GENERAL, &clear_color, 1, &range); |
Mark Lobodzinski | d563950 | 2015-09-24 09:51:47 -0600 | [diff] [blame] | 8852 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 8853 | m_errorMonitor->VerifyFound(); |
Mark Lobodzinski | d563950 | 2015-09-24 09:51:47 -0600 | [diff] [blame] | 8854 | } |
| 8855 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8856 | TEST_F(VkLayerTest, ClearDepthStencilImageWithinRenderPass) { |
Mark Lobodzinski | d563950 | 2015-09-24 09:51:47 -0600 | [diff] [blame] | 8857 | // Call CmdClearDepthStencilImage within an active RenderPass |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8858 | m_errorMonitor->SetDesiredFailureMsg( |
| 8859 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 8860 | "It is invalid to issue this call inside an active render pass"); |
Mark Lobodzinski | d563950 | 2015-09-24 09:51:47 -0600 | [diff] [blame] | 8861 | |
| 8862 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 8863 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
Mark Lobodzinski | d563950 | 2015-09-24 09:51:47 -0600 | [diff] [blame] | 8864 | |
| 8865 | // Renderpass is started here |
| 8866 | BeginCommandBuffer(); |
| 8867 | |
| 8868 | VkClearDepthStencilValue clear_value = {0}; |
Dustin Graves | a2e5c94 | 2016-02-11 18:28:06 -0700 | [diff] [blame] | 8869 | VkMemoryPropertyFlags reqs = 0; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8870 | VkImageCreateInfo image_create_info = vk_testing::Image::create_info(); |
| 8871 | image_create_info.imageType = VK_IMAGE_TYPE_2D; |
| 8872 | image_create_info.format = VK_FORMAT_D24_UNORM_S8_UINT; |
| 8873 | image_create_info.extent.width = 64; |
| 8874 | image_create_info.extent.height = 64; |
| 8875 | image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL; |
| 8876 | image_create_info.usage = VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT; |
Mark Lobodzinski | d563950 | 2015-09-24 09:51:47 -0600 | [diff] [blame] | 8877 | |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 8878 | vk_testing::Image dstImage; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8879 | dstImage.init(*m_device, (const VkImageCreateInfo &)image_create_info, |
| 8880 | reqs); |
Mark Lobodzinski | d563950 | 2015-09-24 09:51:47 -0600 | [diff] [blame] | 8881 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8882 | const VkImageSubresourceRange range = vk_testing::Image::subresource_range( |
| 8883 | image_create_info, VK_IMAGE_ASPECT_DEPTH_BIT); |
Mark Lobodzinski | d563950 | 2015-09-24 09:51:47 -0600 | [diff] [blame] | 8884 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8885 | vkCmdClearDepthStencilImage( |
| 8886 | m_commandBuffer->GetBufferHandle(), dstImage.handle(), |
| 8887 | VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL, &clear_value, 1, |
| 8888 | &range); |
Mark Lobodzinski | d563950 | 2015-09-24 09:51:47 -0600 | [diff] [blame] | 8889 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 8890 | m_errorMonitor->VerifyFound(); |
Mark Lobodzinski | d563950 | 2015-09-24 09:51:47 -0600 | [diff] [blame] | 8891 | } |
| 8892 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8893 | TEST_F(VkLayerTest, ClearColorAttachmentsOutsideRenderPass) { |
Courtney Goeltzenleuchter | c9323e0 | 2015-10-15 16:51:05 -0600 | [diff] [blame] | 8894 | // Call CmdClearAttachmentss outside of an active RenderPass |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8895 | VkResult err; |
Mark Lobodzinski | d563950 | 2015-09-24 09:51:47 -0600 | [diff] [blame] | 8896 | |
Courtney Goeltzenleuchter | 7415d5a | 2015-12-09 15:48:16 -0700 | [diff] [blame] | 8897 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8898 | "vkCmdClearAttachments: This call " |
| 8899 | "must be issued inside an active " |
| 8900 | "render pass"); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 8901 | |
Mark Lobodzinski | d563950 | 2015-09-24 09:51:47 -0600 | [diff] [blame] | 8902 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 8903 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
Mark Lobodzinski | d563950 | 2015-09-24 09:51:47 -0600 | [diff] [blame] | 8904 | |
| 8905 | // Start no RenderPass |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 8906 | err = m_commandBuffer->BeginCommandBuffer(); |
Mark Lobodzinski | d563950 | 2015-09-24 09:51:47 -0600 | [diff] [blame] | 8907 | ASSERT_VK_SUCCESS(err); |
| 8908 | |
Courtney Goeltzenleuchter | c9323e0 | 2015-10-15 16:51:05 -0600 | [diff] [blame] | 8909 | VkClearAttachment color_attachment; |
| 8910 | color_attachment.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; |
| 8911 | color_attachment.clearValue.color.float32[0] = 0; |
| 8912 | color_attachment.clearValue.color.float32[1] = 0; |
| 8913 | color_attachment.clearValue.color.float32[2] = 0; |
| 8914 | color_attachment.clearValue.color.float32[3] = 0; |
| 8915 | color_attachment.colorAttachment = 0; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8916 | VkClearRect clear_rect = {{{0, 0}, {32, 32}}}; |
| 8917 | vkCmdClearAttachments(m_commandBuffer->GetBufferHandle(), 1, |
| 8918 | &color_attachment, 1, &clear_rect); |
Mark Lobodzinski | d563950 | 2015-09-24 09:51:47 -0600 | [diff] [blame] | 8919 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 8920 | m_errorMonitor->VerifyFound(); |
Mark Lobodzinski | d563950 | 2015-09-24 09:51:47 -0600 | [diff] [blame] | 8921 | } |
| 8922 | |
Karl Schultz | 9e66a29 | 2016-04-21 15:57:51 -0600 | [diff] [blame] | 8923 | TEST_F(VkLayerTest, BufferMemoryBarrierNoBuffer) { |
| 8924 | // Try to add a buffer memory barrier with no buffer. |
| 8925 | m_errorMonitor->SetDesiredFailureMsg( |
| 8926 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 8927 | "required parameter pBufferMemoryBarriers[i].buffer specified as VK_NULL_HANDLE"); |
| 8928 | |
| 8929 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 8930 | BeginCommandBuffer(); |
| 8931 | |
| 8932 | VkBufferMemoryBarrier buf_barrier = {}; |
| 8933 | buf_barrier.sType = VK_STRUCTURE_TYPE_BUFFER_MEMORY_BARRIER; |
| 8934 | buf_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT; |
| 8935 | buf_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT; |
| 8936 | buf_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED; |
| 8937 | buf_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED; |
| 8938 | buf_barrier.buffer = VK_NULL_HANDLE; |
| 8939 | buf_barrier.offset = 0; |
| 8940 | buf_barrier.size = VK_WHOLE_SIZE; |
| 8941 | vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), |
| 8942 | VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, |
| 8943 | 0, 0, nullptr, 1, &buf_barrier, 0, nullptr); |
| 8944 | |
| 8945 | m_errorMonitor->VerifyFound(); |
| 8946 | } |
| 8947 | |
Tony Barbour | 7fd5c0f | 2016-05-03 16:11:53 -0600 | [diff] [blame] | 8948 | TEST_F(VkLayerTest, InvalidBarriers) { |
| 8949 | TEST_DESCRIPTION("A variety of ways to get VK_INVALID_BARRIER "); |
| 8950 | |
| 8951 | m_errorMonitor->SetDesiredFailureMsg( |
| 8952 | VK_DEBUG_REPORT_ERROR_BIT_EXT, "Barriers cannot be set during subpass"); |
| 8953 | |
| 8954 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 8955 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 8956 | |
| 8957 | VkMemoryBarrier mem_barrier = {}; |
| 8958 | mem_barrier.sType = VK_STRUCTURE_TYPE_MEMORY_BARRIER; |
| 8959 | mem_barrier.pNext = NULL; |
| 8960 | mem_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT; |
| 8961 | mem_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT; |
| 8962 | BeginCommandBuffer(); |
| 8963 | // BeginCommandBuffer() starts a render pass |
| 8964 | vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), |
| 8965 | VK_PIPELINE_STAGE_HOST_BIT, |
| 8966 | VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 1, |
| 8967 | &mem_barrier, 0, nullptr, 0, nullptr); |
| 8968 | m_errorMonitor->VerifyFound(); |
| 8969 | |
| 8970 | m_errorMonitor->SetDesiredFailureMsg( |
| 8971 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 8972 | "Image Layout cannot be transitioned to UNDEFINED"); |
| 8973 | VkImageObj image(m_device); |
| 8974 | image.init(128, 128, VK_FORMAT_B8G8R8A8_UNORM, |
| 8975 | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0); |
| 8976 | ASSERT_TRUE(image.initialized()); |
| 8977 | VkImageMemoryBarrier img_barrier = {}; |
| 8978 | img_barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER; |
| 8979 | img_barrier.pNext = NULL; |
| 8980 | img_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT; |
| 8981 | img_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT; |
| 8982 | img_barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL; |
| 8983 | // New layout can't be UNDEFINED |
| 8984 | img_barrier.newLayout = VK_IMAGE_LAYOUT_UNDEFINED; |
| 8985 | img_barrier.image = image.handle(); |
| 8986 | img_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED; |
| 8987 | img_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED; |
| 8988 | img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; |
| 8989 | img_barrier.subresourceRange.baseArrayLayer = 0; |
| 8990 | img_barrier.subresourceRange.baseMipLevel = 0; |
| 8991 | img_barrier.subresourceRange.layerCount = 1; |
| 8992 | img_barrier.subresourceRange.levelCount = 1; |
| 8993 | vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), |
| 8994 | VK_PIPELINE_STAGE_HOST_BIT, |
| 8995 | VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0, nullptr, 0, |
| 8996 | nullptr, 1, &img_barrier); |
| 8997 | m_errorMonitor->VerifyFound(); |
| 8998 | img_barrier.newLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL; |
| 8999 | |
| 9000 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 9001 | "Subresource must have the sum of the " |
| 9002 | "baseArrayLayer"); |
| 9003 | // baseArrayLayer + layerCount must be <= image's arrayLayers |
| 9004 | img_barrier.subresourceRange.baseArrayLayer = 1; |
| 9005 | vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), |
| 9006 | VK_PIPELINE_STAGE_HOST_BIT, |
| 9007 | VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0, nullptr, 0, |
| 9008 | nullptr, 1, &img_barrier); |
| 9009 | m_errorMonitor->VerifyFound(); |
| 9010 | img_barrier.subresourceRange.baseArrayLayer = 0; |
| 9011 | |
| 9012 | m_errorMonitor->SetDesiredFailureMsg( |
| 9013 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 9014 | "Subresource must have the sum of the baseMipLevel"); |
| 9015 | // baseMipLevel + levelCount must be <= image's mipLevels |
| 9016 | img_barrier.subresourceRange.baseMipLevel = 1; |
| 9017 | vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), |
| 9018 | VK_PIPELINE_STAGE_HOST_BIT, |
| 9019 | VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0, nullptr, 0, |
| 9020 | nullptr, 1, &img_barrier); |
| 9021 | m_errorMonitor->VerifyFound(); |
| 9022 | img_barrier.subresourceRange.baseMipLevel = 0; |
| 9023 | |
| 9024 | m_errorMonitor->SetDesiredFailureMsg( |
| 9025 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 9026 | "Buffer Barriers cannot be used during a render pass"); |
| 9027 | vk_testing::Buffer buffer; |
| 9028 | buffer.init(*m_device, 256); |
| 9029 | VkBufferMemoryBarrier buf_barrier = {}; |
| 9030 | buf_barrier.sType = VK_STRUCTURE_TYPE_BUFFER_MEMORY_BARRIER; |
| 9031 | buf_barrier.pNext = NULL; |
| 9032 | buf_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT; |
| 9033 | buf_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT; |
| 9034 | buf_barrier.buffer = buffer.handle(); |
| 9035 | buf_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED; |
| 9036 | buf_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED; |
| 9037 | buf_barrier.offset = 0; |
| 9038 | buf_barrier.size = VK_WHOLE_SIZE; |
| 9039 | // Can't send buffer barrier during a render pass |
| 9040 | vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), |
| 9041 | VK_PIPELINE_STAGE_HOST_BIT, |
| 9042 | VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0, nullptr, 1, |
| 9043 | &buf_barrier, 0, nullptr); |
| 9044 | m_errorMonitor->VerifyFound(); |
| 9045 | vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle()); |
| 9046 | |
| 9047 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 9048 | "which is not less than total size"); |
| 9049 | buf_barrier.offset = 257; |
| 9050 | // Offset greater than total size |
| 9051 | vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), |
| 9052 | VK_PIPELINE_STAGE_HOST_BIT, |
| 9053 | VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0, nullptr, 1, |
| 9054 | &buf_barrier, 0, nullptr); |
| 9055 | m_errorMonitor->VerifyFound(); |
| 9056 | buf_barrier.offset = 0; |
| 9057 | |
| 9058 | m_errorMonitor->SetDesiredFailureMsg( |
| 9059 | VK_DEBUG_REPORT_ERROR_BIT_EXT, "whose sum is greater than total size"); |
| 9060 | buf_barrier.size = 257; |
| 9061 | // Size greater than total size |
| 9062 | vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), |
| 9063 | VK_PIPELINE_STAGE_HOST_BIT, |
| 9064 | VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0, nullptr, 1, |
| 9065 | &buf_barrier, 0, nullptr); |
| 9066 | m_errorMonitor->VerifyFound(); |
| 9067 | buf_barrier.size = VK_WHOLE_SIZE; |
| 9068 | |
| 9069 | m_errorMonitor->SetDesiredFailureMsg( |
| 9070 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 9071 | "Image is a depth and stencil format and thus must " |
| 9072 | "have both VK_IMAGE_ASPECT_DEPTH_BIT and " |
| 9073 | "VK_IMAGE_ASPECT_STENCIL_BIT set."); |
| 9074 | VkDepthStencilObj ds_image(m_device); |
| 9075 | ds_image.Init(m_device, 128, 128, VK_FORMAT_D24_UNORM_S8_UINT); |
| 9076 | ASSERT_TRUE(ds_image.initialized()); |
| 9077 | img_barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL; |
| 9078 | img_barrier.newLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL; |
| 9079 | img_barrier.image = ds_image.handle(); |
| 9080 | // Leave aspectMask at COLOR on purpose |
| 9081 | vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), |
| 9082 | VK_PIPELINE_STAGE_HOST_BIT, |
| 9083 | VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0, nullptr, 0, |
| 9084 | nullptr, 1, &img_barrier); |
| 9085 | m_errorMonitor->VerifyFound(); |
| 9086 | } |
| 9087 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9088 | TEST_F(VkLayerTest, IdxBufferAlignmentError) { |
Tobin Ehlis | c4c2318 | 2015-09-17 12:24:13 -0600 | [diff] [blame] | 9089 | // Bind a BeginRenderPass within an active RenderPass |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9090 | VkResult err; |
Tobin Ehlis | c4c2318 | 2015-09-17 12:24:13 -0600 | [diff] [blame] | 9091 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9092 | m_errorMonitor->SetDesiredFailureMsg( |
| 9093 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 9094 | "vkCmdBindIndexBuffer() offset (0x7) does not fall on "); |
| 9095 | |
Tobin Ehlis | c4c2318 | 2015-09-17 12:24:13 -0600 | [diff] [blame] | 9096 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 9097 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
Tobin Ehlis | c4c2318 | 2015-09-17 12:24:13 -0600 | [diff] [blame] | 9098 | uint32_t qfi = 0; |
| 9099 | VkBufferCreateInfo buffCI = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9100 | buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO; |
| 9101 | buffCI.size = 1024; |
| 9102 | buffCI.usage = VK_BUFFER_USAGE_INDEX_BUFFER_BIT; |
| 9103 | buffCI.queueFamilyIndexCount = 1; |
| 9104 | buffCI.pQueueFamilyIndices = &qfi; |
Tobin Ehlis | c4c2318 | 2015-09-17 12:24:13 -0600 | [diff] [blame] | 9105 | |
| 9106 | VkBuffer ib; |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 9107 | err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &ib); |
Tobin Ehlis | c4c2318 | 2015-09-17 12:24:13 -0600 | [diff] [blame] | 9108 | ASSERT_VK_SUCCESS(err); |
| 9109 | |
| 9110 | BeginCommandBuffer(); |
| 9111 | ASSERT_VK_SUCCESS(err); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9112 | // vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), |
| 9113 | // VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle()); |
Tobin Ehlis | c4c2318 | 2015-09-17 12:24:13 -0600 | [diff] [blame] | 9114 | // 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] | 9115 | vkCmdBindIndexBuffer(m_commandBuffer->GetBufferHandle(), ib, 7, |
| 9116 | VK_INDEX_TYPE_UINT16); |
Tobin Ehlis | c4c2318 | 2015-09-17 12:24:13 -0600 | [diff] [blame] | 9117 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 9118 | m_errorMonitor->VerifyFound(); |
Mike Stroyan | d1c84a5 | 2015-08-18 14:40:24 -0600 | [diff] [blame] | 9119 | |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 9120 | vkDestroyBuffer(m_device->device(), ib, NULL); |
Tobin Ehlis | c4c2318 | 2015-09-17 12:24:13 -0600 | [diff] [blame] | 9121 | } |
| 9122 | |
Mark Lobodzinski | 52a6e7d | 2016-02-25 15:09:52 -0700 | [diff] [blame] | 9123 | TEST_F(VkLayerTest, InvalidQueueFamilyIndex) { |
| 9124 | // Create an out-of-range queueFamilyIndex |
| 9125 | m_errorMonitor->SetDesiredFailureMsg( |
| 9126 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Dustin Graves | de62853 | 2016-04-21 16:30:17 -0600 | [diff] [blame] | 9127 | "vkCreateBuffer: pCreateInfo->pQueueFamilyIndices[0] (777) must be one " |
| 9128 | "of the indices specified when the device was created, via the " |
| 9129 | "VkDeviceQueueCreateInfo structure."); |
Mark Lobodzinski | 52a6e7d | 2016-02-25 15:09:52 -0700 | [diff] [blame] | 9130 | |
| 9131 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 9132 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 9133 | VkBufferCreateInfo buffCI = {}; |
| 9134 | buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO; |
| 9135 | buffCI.size = 1024; |
| 9136 | buffCI.usage = VK_BUFFER_USAGE_INDEX_BUFFER_BIT; |
| 9137 | buffCI.queueFamilyIndexCount = 1; |
| 9138 | // Introduce failure by specifying invalid queue_family_index |
| 9139 | uint32_t qfi = 777; |
| 9140 | buffCI.pQueueFamilyIndices = &qfi; |
Tobin Ehlis | 24aab04 | 2016-03-24 10:54:18 -0600 | [diff] [blame] | 9141 | buffCI.sharingMode = VK_SHARING_MODE_CONCURRENT; // qfi only matters in CONCURRENT mode |
Mark Lobodzinski | 52a6e7d | 2016-02-25 15:09:52 -0700 | [diff] [blame] | 9142 | |
| 9143 | VkBuffer ib; |
| 9144 | vkCreateBuffer(m_device->device(), &buffCI, NULL, &ib); |
| 9145 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 9146 | m_errorMonitor->VerifyFound(); |
Tony Barbour | df4c004 | 2016-06-01 15:55:43 -0600 | [diff] [blame] | 9147 | vkDestroyBuffer(m_device->device(), ib, NULL); |
Mark Lobodzinski | 52a6e7d | 2016-02-25 15:09:52 -0700 | [diff] [blame] | 9148 | } |
| 9149 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9150 | TEST_F(VkLayerTest, ExecuteCommandsPrimaryCB) { |
| 9151 | // Attempt vkCmdExecuteCommands w/ a primary cmd buffer (should only be |
| 9152 | // secondary) |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 9153 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9154 | m_errorMonitor->SetDesiredFailureMsg( |
| 9155 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 9156 | "vkCmdExecuteCommands() called w/ Primary Cmd Buffer "); |
Tobin Ehlis | 4b34ddc | 2015-09-17 14:18:16 -0600 | [diff] [blame] | 9157 | |
| 9158 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 9159 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
Tobin Ehlis | 4b34ddc | 2015-09-17 14:18:16 -0600 | [diff] [blame] | 9160 | |
| 9161 | BeginCommandBuffer(); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9162 | // ASSERT_VK_SUCCESS(err); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 9163 | VkCommandBuffer primCB = m_commandBuffer->GetBufferHandle(); |
| 9164 | vkCmdExecuteCommands(m_commandBuffer->GetBufferHandle(), 1, &primCB); |
Tobin Ehlis | 4b34ddc | 2015-09-17 14:18:16 -0600 | [diff] [blame] | 9165 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 9166 | m_errorMonitor->VerifyFound(); |
Tobin Ehlis | 4b34ddc | 2015-09-17 14:18:16 -0600 | [diff] [blame] | 9167 | } |
| 9168 | |
Tobin Ehlis | 17826bd | 2016-05-25 11:12:50 -0600 | [diff] [blame] | 9169 | TEST_F(VkLayerTest, DSUsageBitsErrors) { |
| 9170 | TEST_DESCRIPTION("Attempt to update descriptor sets for images and buffers " |
| 9171 | "that do not have correct usage bits sets."); |
| 9172 | VkResult err; |
| 9173 | |
| 9174 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 9175 | VkDescriptorPoolSize ds_type_count[VK_DESCRIPTOR_TYPE_RANGE_SIZE] = {}; |
| 9176 | for (uint32_t i = 0; i < VK_DESCRIPTOR_TYPE_RANGE_SIZE; ++i) { |
| 9177 | ds_type_count[i].type = VkDescriptorType(i); |
| 9178 | ds_type_count[i].descriptorCount = 1; |
| 9179 | } |
| 9180 | VkDescriptorPoolCreateInfo ds_pool_ci = {}; |
| 9181 | ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO; |
| 9182 | ds_pool_ci.pNext = NULL; |
| 9183 | ds_pool_ci.maxSets = VK_DESCRIPTOR_TYPE_RANGE_SIZE; |
| 9184 | ds_pool_ci.poolSizeCount = VK_DESCRIPTOR_TYPE_RANGE_SIZE; |
| 9185 | ds_pool_ci.pPoolSizes = ds_type_count; |
| 9186 | |
| 9187 | VkDescriptorPool ds_pool; |
| 9188 | err = |
| 9189 | vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool); |
| 9190 | ASSERT_VK_SUCCESS(err); |
| 9191 | |
| 9192 | // Create 10 layouts where each has a single descriptor of different type |
| 9193 | VkDescriptorSetLayoutBinding dsl_binding[VK_DESCRIPTOR_TYPE_RANGE_SIZE] = |
| 9194 | {}; |
| 9195 | for (uint32_t i = 0; i < VK_DESCRIPTOR_TYPE_RANGE_SIZE; ++i) { |
| 9196 | dsl_binding[i].binding = 0; |
| 9197 | dsl_binding[i].descriptorType = VkDescriptorType(i); |
| 9198 | dsl_binding[i].descriptorCount = 1; |
| 9199 | dsl_binding[i].stageFlags = VK_SHADER_STAGE_ALL; |
| 9200 | dsl_binding[i].pImmutableSamplers = NULL; |
| 9201 | } |
| 9202 | |
| 9203 | VkDescriptorSetLayoutCreateInfo ds_layout_ci = {}; |
| 9204 | ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO; |
| 9205 | ds_layout_ci.pNext = NULL; |
| 9206 | ds_layout_ci.bindingCount = 1; |
| 9207 | VkDescriptorSetLayout ds_layouts[VK_DESCRIPTOR_TYPE_RANGE_SIZE]; |
| 9208 | for (uint32_t i = 0; i < VK_DESCRIPTOR_TYPE_RANGE_SIZE; ++i) { |
| 9209 | ds_layout_ci.pBindings = dsl_binding + i; |
| 9210 | err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, |
| 9211 | NULL, ds_layouts + i); |
| 9212 | ASSERT_VK_SUCCESS(err); |
| 9213 | } |
| 9214 | VkDescriptorSet descriptor_sets[VK_DESCRIPTOR_TYPE_RANGE_SIZE] = {}; |
| 9215 | VkDescriptorSetAllocateInfo alloc_info = {}; |
| 9216 | alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO; |
| 9217 | alloc_info.descriptorSetCount = VK_DESCRIPTOR_TYPE_RANGE_SIZE; |
| 9218 | alloc_info.descriptorPool = ds_pool; |
| 9219 | alloc_info.pSetLayouts = ds_layouts; |
| 9220 | err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, |
| 9221 | descriptor_sets); |
| 9222 | ASSERT_VK_SUCCESS(err); |
| 9223 | |
| 9224 | // Create a buffer & bufferView to be used for invalid updates |
| 9225 | VkBufferCreateInfo buff_ci = {}; |
| 9226 | buff_ci.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO; |
| 9227 | // This usage is not valid for any descriptor type |
| 9228 | buff_ci.usage = VK_BUFFER_USAGE_TRANSFER_SRC_BIT; |
| 9229 | buff_ci.size = 256; |
| 9230 | buff_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE; |
| 9231 | VkBuffer buffer; |
| 9232 | err = vkCreateBuffer(m_device->device(), &buff_ci, NULL, &buffer); |
| 9233 | ASSERT_VK_SUCCESS(err); |
| 9234 | |
| 9235 | VkBufferViewCreateInfo buff_view_ci = {}; |
| 9236 | buff_view_ci.sType = VK_STRUCTURE_TYPE_BUFFER_VIEW_CREATE_INFO; |
| 9237 | buff_view_ci.buffer = buffer; |
| 9238 | buff_view_ci.format = VK_FORMAT_R8_UNORM; |
| 9239 | buff_view_ci.range = VK_WHOLE_SIZE; |
| 9240 | VkBufferView buff_view; |
| 9241 | err = |
| 9242 | vkCreateBufferView(m_device->device(), &buff_view_ci, NULL, &buff_view); |
| 9243 | ASSERT_VK_SUCCESS(err); |
| 9244 | |
| 9245 | // Create an image to be used for invalid updates |
| 9246 | VkImageCreateInfo image_ci = {}; |
| 9247 | image_ci.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO; |
| 9248 | image_ci.imageType = VK_IMAGE_TYPE_2D; |
| 9249 | image_ci.format = VK_FORMAT_R8G8B8A8_UNORM; |
| 9250 | image_ci.extent.width = 64; |
| 9251 | image_ci.extent.height = 64; |
| 9252 | image_ci.extent.depth = 1; |
| 9253 | image_ci.mipLevels = 1; |
| 9254 | image_ci.arrayLayers = 1; |
| 9255 | image_ci.samples = VK_SAMPLE_COUNT_1_BIT; |
| 9256 | image_ci.tiling = VK_IMAGE_TILING_LINEAR; |
| 9257 | image_ci.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED; |
| 9258 | // This usage is not valid for any descriptor type |
| 9259 | image_ci.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT; |
| 9260 | image_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE; |
| 9261 | VkImage image; |
| 9262 | err = vkCreateImage(m_device->device(), &image_ci, NULL, &image); |
| 9263 | ASSERT_VK_SUCCESS(err); |
| 9264 | // Bind memory to image |
| 9265 | VkMemoryRequirements mem_reqs; |
| 9266 | VkDeviceMemory image_mem; |
| 9267 | bool pass; |
| 9268 | VkMemoryAllocateInfo mem_alloc = {}; |
| 9269 | mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO; |
| 9270 | mem_alloc.pNext = NULL; |
| 9271 | mem_alloc.allocationSize = 0; |
| 9272 | mem_alloc.memoryTypeIndex = 0; |
| 9273 | vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs); |
| 9274 | mem_alloc.allocationSize = mem_reqs.size; |
| 9275 | pass = |
| 9276 | m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0); |
| 9277 | ASSERT_TRUE(pass); |
| 9278 | err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &image_mem); |
| 9279 | ASSERT_VK_SUCCESS(err); |
| 9280 | err = vkBindImageMemory(m_device->device(), image, image_mem, 0); |
| 9281 | ASSERT_VK_SUCCESS(err); |
| 9282 | // Now create view for image |
| 9283 | VkImageViewCreateInfo image_view_ci = {}; |
| 9284 | image_view_ci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO; |
| 9285 | image_view_ci.image = image; |
| 9286 | image_view_ci.format = VK_FORMAT_R8G8B8A8_UNORM; |
| 9287 | image_view_ci.viewType = VK_IMAGE_VIEW_TYPE_2D; |
| 9288 | image_view_ci.subresourceRange.layerCount = 1; |
| 9289 | image_view_ci.subresourceRange.baseArrayLayer = 0; |
| 9290 | image_view_ci.subresourceRange.levelCount = 1; |
| 9291 | image_view_ci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; |
| 9292 | VkImageView image_view; |
| 9293 | err = vkCreateImageView(m_device->device(), &image_view_ci, NULL, |
| 9294 | &image_view); |
| 9295 | ASSERT_VK_SUCCESS(err); |
| 9296 | |
| 9297 | VkDescriptorBufferInfo buff_info = {}; |
| 9298 | buff_info.buffer = buffer; |
| 9299 | VkDescriptorImageInfo img_info = {}; |
| 9300 | img_info.imageView = image_view; |
| 9301 | VkWriteDescriptorSet descriptor_write = {}; |
| 9302 | descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET; |
| 9303 | descriptor_write.dstBinding = 0; |
| 9304 | descriptor_write.descriptorCount = 1; |
| 9305 | descriptor_write.pTexelBufferView = &buff_view; |
| 9306 | descriptor_write.pBufferInfo = &buff_info; |
| 9307 | descriptor_write.pImageInfo = &img_info; |
| 9308 | |
| 9309 | // These error messages align with VkDescriptorType struct |
| 9310 | const char *error_msgs[] = { |
| 9311 | "", // placeholder, no error for SAMPLER descriptor |
| 9312 | " does not have VK_IMAGE_USAGE_SAMPLED_BIT set.", |
| 9313 | " does not have VK_IMAGE_USAGE_SAMPLED_BIT set.", |
| 9314 | " does not have VK_IMAGE_USAGE_STORAGE_BIT set.", |
| 9315 | " does not have VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT set.", |
| 9316 | " does not have VK_BUFFER_USAGE_STORAGE_TEXEL_BUFFER_BIT set.", |
| 9317 | " does not have VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT set.", |
| 9318 | " does not have VK_BUFFER_USAGE_STORAGE_BUFFER_BIT set.", |
| 9319 | " does not have VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT set.", |
| 9320 | " does not have VK_BUFFER_USAGE_STORAGE_BUFFER_BIT set.", |
| 9321 | " does not have VK_IMAGE_USAGE_INPUT_ATTACHMENT_BIT set."}; |
| 9322 | // Start loop at 1 as SAMPLER desc type has no usage bit error |
| 9323 | for (uint32_t i = 1; i < VK_DESCRIPTOR_TYPE_RANGE_SIZE; ++i) { |
| 9324 | descriptor_write.descriptorType = VkDescriptorType(i); |
| 9325 | descriptor_write.dstSet = descriptor_sets[i]; |
| 9326 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 9327 | error_msgs[i]); |
| 9328 | |
| 9329 | vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, |
| 9330 | NULL); |
| 9331 | |
| 9332 | m_errorMonitor->VerifyFound(); |
| 9333 | vkDestroyDescriptorSetLayout(m_device->device(), ds_layouts[i], NULL); |
| 9334 | } |
| 9335 | vkDestroyDescriptorSetLayout(m_device->device(), ds_layouts[0], NULL); |
| 9336 | vkDestroyImage(m_device->device(), image, NULL); |
Tony Barbour | df4c004 | 2016-06-01 15:55:43 -0600 | [diff] [blame] | 9337 | vkFreeMemory(m_device->device(), image_mem, NULL); |
Tobin Ehlis | 17826bd | 2016-05-25 11:12:50 -0600 | [diff] [blame] | 9338 | vkDestroyImageView(m_device->device(), image_view, NULL); |
| 9339 | vkDestroyBuffer(m_device->device(), buffer, NULL); |
| 9340 | vkDestroyBufferView(m_device->device(), buff_view, NULL); |
| 9341 | vkFreeDescriptorSets(m_device->device(), ds_pool, |
| 9342 | VK_DESCRIPTOR_TYPE_RANGE_SIZE, descriptor_sets); |
| 9343 | vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL); |
| 9344 | } |
| 9345 | |
Tobin Ehlis | 585f66d | 2016-07-01 18:23:58 -0600 | [diff] [blame] | 9346 | TEST_F(VkLayerTest, DSBufferInfoErrors) { |
| 9347 | TEST_DESCRIPTION( |
| 9348 | "Attempt to update buffer descriptor set that has incorrect " |
| 9349 | "parameters in VkDescriptorBufferInfo struct. This includes:\n" |
| 9350 | "1. offset value greater than buffer size\n" |
| 9351 | "2. range value of 0\n" |
| 9352 | "3. range value greater than buffer (size - offset)"); |
| 9353 | VkResult err; |
| 9354 | |
| 9355 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 9356 | VkDescriptorPoolSize ds_type_count = {}; |
| 9357 | ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 9358 | ds_type_count.descriptorCount = 1; |
| 9359 | |
| 9360 | VkDescriptorPoolCreateInfo ds_pool_ci = {}; |
| 9361 | ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO; |
| 9362 | ds_pool_ci.pNext = NULL; |
| 9363 | ds_pool_ci.maxSets = 1; |
| 9364 | ds_pool_ci.poolSizeCount = 1; |
| 9365 | ds_pool_ci.pPoolSizes = &ds_type_count; |
| 9366 | |
| 9367 | VkDescriptorPool ds_pool; |
| 9368 | err = |
| 9369 | vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool); |
| 9370 | ASSERT_VK_SUCCESS(err); |
| 9371 | |
| 9372 | // Create layout with single uniform buffer descriptor |
| 9373 | VkDescriptorSetLayoutBinding dsl_binding = {}; |
| 9374 | dsl_binding.binding = 0; |
| 9375 | dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 9376 | dsl_binding.descriptorCount = 1; |
| 9377 | dsl_binding.stageFlags = VK_SHADER_STAGE_ALL; |
| 9378 | dsl_binding.pImmutableSamplers = NULL; |
| 9379 | |
| 9380 | VkDescriptorSetLayoutCreateInfo ds_layout_ci = {}; |
| 9381 | ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO; |
| 9382 | ds_layout_ci.pNext = NULL; |
| 9383 | ds_layout_ci.bindingCount = 1; |
| 9384 | ds_layout_ci.pBindings = &dsl_binding; |
| 9385 | VkDescriptorSetLayout ds_layout; |
| 9386 | err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, |
| 9387 | &ds_layout); |
| 9388 | ASSERT_VK_SUCCESS(err); |
| 9389 | |
| 9390 | VkDescriptorSet descriptor_set = {}; |
| 9391 | VkDescriptorSetAllocateInfo alloc_info = {}; |
| 9392 | alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO; |
| 9393 | alloc_info.descriptorSetCount = 1; |
| 9394 | alloc_info.descriptorPool = ds_pool; |
| 9395 | alloc_info.pSetLayouts = &ds_layout; |
| 9396 | err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, |
| 9397 | &descriptor_set); |
| 9398 | ASSERT_VK_SUCCESS(err); |
| 9399 | |
| 9400 | // Create a buffer to be used for invalid updates |
| 9401 | VkBufferCreateInfo buff_ci = {}; |
| 9402 | buff_ci.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO; |
| 9403 | buff_ci.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT; |
| 9404 | buff_ci.size = 256; |
| 9405 | buff_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE; |
| 9406 | VkBuffer buffer; |
| 9407 | err = vkCreateBuffer(m_device->device(), &buff_ci, NULL, &buffer); |
| 9408 | ASSERT_VK_SUCCESS(err); |
| 9409 | // Have to bind memory to buffer before descriptor update |
| 9410 | VkMemoryAllocateInfo mem_alloc = {}; |
| 9411 | mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO; |
| 9412 | mem_alloc.pNext = NULL; |
| 9413 | mem_alloc.allocationSize = 256; |
| 9414 | mem_alloc.memoryTypeIndex = 0; |
| 9415 | |
| 9416 | VkMemoryRequirements mem_reqs; |
| 9417 | vkGetBufferMemoryRequirements(m_device->device(), buffer, &mem_reqs); |
| 9418 | bool pass = |
| 9419 | m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0); |
| 9420 | if (!pass) { |
| 9421 | vkDestroyBuffer(m_device->device(), buffer, NULL); |
| 9422 | return; |
| 9423 | } |
| 9424 | |
| 9425 | VkDeviceMemory mem; |
| 9426 | err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem); |
| 9427 | ASSERT_VK_SUCCESS(err); |
| 9428 | err = vkBindBufferMemory(m_device->device(), buffer, mem, 0); |
| 9429 | ASSERT_VK_SUCCESS(err); |
| 9430 | |
| 9431 | VkDescriptorBufferInfo buff_info = {}; |
| 9432 | buff_info.buffer = buffer; |
| 9433 | // First make offset 1 larger than buffer size |
| 9434 | buff_info.offset = 257; |
| 9435 | buff_info.range = VK_WHOLE_SIZE; |
| 9436 | VkWriteDescriptorSet descriptor_write = {}; |
| 9437 | descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET; |
| 9438 | descriptor_write.dstBinding = 0; |
| 9439 | descriptor_write.descriptorCount = 1; |
| 9440 | descriptor_write.pTexelBufferView = nullptr; |
| 9441 | descriptor_write.pBufferInfo = &buff_info; |
| 9442 | descriptor_write.pImageInfo = nullptr; |
| 9443 | |
| 9444 | descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 9445 | descriptor_write.dstSet = descriptor_set; |
| 9446 | m_errorMonitor->SetDesiredFailureMsg( |
| 9447 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 9448 | " offset of 257 is greater than buffer "); |
| 9449 | |
| 9450 | vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL); |
| 9451 | |
| 9452 | m_errorMonitor->VerifyFound(); |
| 9453 | // Now cause error due to range of 0 |
| 9454 | buff_info.offset = 0; |
| 9455 | buff_info.range = 0; |
| 9456 | m_errorMonitor->SetDesiredFailureMsg( |
| 9457 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 9458 | " range is not VK_WHOLE_SIZE and is zero, which is not allowed."); |
| 9459 | |
| 9460 | vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL); |
| 9461 | |
| 9462 | m_errorMonitor->VerifyFound(); |
| 9463 | // Now cause error due to range exceeding buffer size - offset |
| 9464 | buff_info.offset = 128; |
| 9465 | buff_info.range = 200; |
| 9466 | m_errorMonitor->SetDesiredFailureMsg( |
| 9467 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 9468 | " range is 200 which is greater than buffer size "); |
| 9469 | |
| 9470 | vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL); |
| 9471 | |
| 9472 | m_errorMonitor->VerifyFound(); |
Mark Lobodzinski | 4bb5409 | 2016-07-06 14:27:19 -0600 | [diff] [blame] | 9473 | vkFreeMemory(m_device->device(), mem, NULL); |
Tobin Ehlis | 585f66d | 2016-07-01 18:23:58 -0600 | [diff] [blame] | 9474 | vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL); |
| 9475 | vkDestroyBuffer(m_device->device(), buffer, NULL); |
| 9476 | vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptor_set); |
| 9477 | vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL); |
| 9478 | } |
| 9479 | |
Tobin Ehlis | 2fc296b | 2016-06-15 14:05:27 -0600 | [diff] [blame] | 9480 | TEST_F(VkLayerTest, DSAspectBitsErrors) { |
| 9481 | // TODO : Initially only catching case where DEPTH & STENCIL aspect bits |
| 9482 | // are set, but could expand this test to hit more cases. |
| 9483 | TEST_DESCRIPTION("Attempt to update descriptor sets for images " |
| 9484 | "that do not have correct aspect bits sets."); |
| 9485 | VkResult err; |
| 9486 | |
| 9487 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 9488 | VkDescriptorPoolSize ds_type_count = {}; |
| 9489 | ds_type_count.type = VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT; |
| 9490 | ds_type_count.descriptorCount = 1; |
| 9491 | |
| 9492 | VkDescriptorPoolCreateInfo ds_pool_ci = {}; |
| 9493 | ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO; |
| 9494 | ds_pool_ci.pNext = NULL; |
| 9495 | ds_pool_ci.maxSets = 5; |
| 9496 | ds_pool_ci.poolSizeCount = 1; |
| 9497 | ds_pool_ci.pPoolSizes = &ds_type_count; |
| 9498 | |
| 9499 | VkDescriptorPool ds_pool; |
| 9500 | err = |
| 9501 | vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool); |
| 9502 | ASSERT_VK_SUCCESS(err); |
| 9503 | |
| 9504 | VkDescriptorSetLayoutBinding dsl_binding = {}; |
| 9505 | dsl_binding.binding = 0; |
| 9506 | dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT; |
| 9507 | dsl_binding.descriptorCount = 1; |
| 9508 | dsl_binding.stageFlags = VK_SHADER_STAGE_ALL; |
| 9509 | dsl_binding.pImmutableSamplers = NULL; |
| 9510 | |
| 9511 | VkDescriptorSetLayoutCreateInfo ds_layout_ci = {}; |
| 9512 | ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO; |
| 9513 | ds_layout_ci.pNext = NULL; |
| 9514 | ds_layout_ci.bindingCount = 1; |
| 9515 | ds_layout_ci.pBindings = &dsl_binding; |
| 9516 | VkDescriptorSetLayout ds_layout; |
| 9517 | err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, |
| 9518 | &ds_layout); |
| 9519 | ASSERT_VK_SUCCESS(err); |
| 9520 | |
| 9521 | VkDescriptorSet descriptor_set = {}; |
| 9522 | VkDescriptorSetAllocateInfo alloc_info = {}; |
| 9523 | alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO; |
| 9524 | alloc_info.descriptorSetCount = 1; |
| 9525 | alloc_info.descriptorPool = ds_pool; |
| 9526 | alloc_info.pSetLayouts = &ds_layout; |
| 9527 | err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, |
| 9528 | &descriptor_set); |
| 9529 | ASSERT_VK_SUCCESS(err); |
| 9530 | |
| 9531 | // Create an image to be used for invalid updates |
| 9532 | VkImageCreateInfo image_ci = {}; |
| 9533 | image_ci.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO; |
| 9534 | image_ci.imageType = VK_IMAGE_TYPE_2D; |
| 9535 | image_ci.format = VK_FORMAT_D24_UNORM_S8_UINT; |
| 9536 | image_ci.extent.width = 64; |
| 9537 | image_ci.extent.height = 64; |
| 9538 | image_ci.extent.depth = 1; |
| 9539 | image_ci.mipLevels = 1; |
| 9540 | image_ci.arrayLayers = 1; |
| 9541 | image_ci.samples = VK_SAMPLE_COUNT_1_BIT; |
| 9542 | image_ci.tiling = VK_IMAGE_TILING_LINEAR; |
| 9543 | image_ci.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED; |
| 9544 | image_ci.usage = VK_IMAGE_USAGE_SAMPLED_BIT; |
| 9545 | image_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE; |
| 9546 | VkImage image; |
| 9547 | err = vkCreateImage(m_device->device(), &image_ci, NULL, &image); |
| 9548 | ASSERT_VK_SUCCESS(err); |
| 9549 | // Bind memory to image |
| 9550 | VkMemoryRequirements mem_reqs; |
| 9551 | VkDeviceMemory image_mem; |
| 9552 | bool pass; |
| 9553 | VkMemoryAllocateInfo mem_alloc = {}; |
| 9554 | mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO; |
| 9555 | mem_alloc.pNext = NULL; |
| 9556 | mem_alloc.allocationSize = 0; |
| 9557 | mem_alloc.memoryTypeIndex = 0; |
| 9558 | vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs); |
| 9559 | mem_alloc.allocationSize = mem_reqs.size; |
| 9560 | pass = |
| 9561 | m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0); |
| 9562 | ASSERT_TRUE(pass); |
| 9563 | err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &image_mem); |
| 9564 | ASSERT_VK_SUCCESS(err); |
| 9565 | err = vkBindImageMemory(m_device->device(), image, image_mem, 0); |
| 9566 | ASSERT_VK_SUCCESS(err); |
| 9567 | // Now create view for image |
| 9568 | VkImageViewCreateInfo image_view_ci = {}; |
| 9569 | image_view_ci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO; |
| 9570 | image_view_ci.image = image; |
| 9571 | image_view_ci.format = VK_FORMAT_D24_UNORM_S8_UINT; |
| 9572 | image_view_ci.viewType = VK_IMAGE_VIEW_TYPE_2D; |
| 9573 | image_view_ci.subresourceRange.layerCount = 1; |
| 9574 | image_view_ci.subresourceRange.baseArrayLayer = 0; |
| 9575 | image_view_ci.subresourceRange.levelCount = 1; |
| 9576 | // Setting both depth & stencil aspect bits is illegal for descriptor |
| 9577 | image_view_ci.subresourceRange.aspectMask = |
| 9578 | VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT; |
| 9579 | |
| 9580 | VkImageView image_view; |
| 9581 | err = vkCreateImageView(m_device->device(), &image_view_ci, NULL, |
| 9582 | &image_view); |
| 9583 | ASSERT_VK_SUCCESS(err); |
| 9584 | |
| 9585 | VkDescriptorImageInfo img_info = {}; |
| 9586 | img_info.imageView = image_view; |
| 9587 | VkWriteDescriptorSet descriptor_write = {}; |
| 9588 | descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET; |
| 9589 | descriptor_write.dstBinding = 0; |
| 9590 | descriptor_write.descriptorCount = 1; |
| 9591 | descriptor_write.pTexelBufferView = NULL; |
| 9592 | descriptor_write.pBufferInfo = NULL; |
| 9593 | descriptor_write.pImageInfo = &img_info; |
| 9594 | descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT; |
| 9595 | descriptor_write.dstSet = descriptor_set; |
| 9596 | const char *error_msg = " please only set either VK_IMAGE_ASPECT_DEPTH_BIT " |
| 9597 | "or VK_IMAGE_ASPECT_STENCIL_BIT "; |
| 9598 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 9599 | error_msg); |
| 9600 | |
| 9601 | vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL); |
| 9602 | |
| 9603 | m_errorMonitor->VerifyFound(); |
| 9604 | vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL); |
| 9605 | vkDestroyImage(m_device->device(), image, NULL); |
| 9606 | vkFreeMemory(m_device->device(), image_mem, NULL); |
| 9607 | vkDestroyImageView(m_device->device(), image_view, NULL); |
| 9608 | vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptor_set); |
| 9609 | vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL); |
| 9610 | } |
| 9611 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9612 | TEST_F(VkLayerTest, DSTypeMismatch) { |
Tobin Ehlis | 49eb23d | 2015-05-22 12:38:55 -0600 | [diff] [blame] | 9613 | // 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] | 9614 | VkResult err; |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 9615 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9616 | m_errorMonitor->SetDesiredFailureMsg( |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 9617 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 9618 | " binding #0 with type VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER but update " |
| 9619 | "type is VK_DESCRIPTOR_TYPE_SAMPLER"); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 9620 | |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 9621 | ASSERT_NO_FATAL_FAILURE(InitState()); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9622 | // VkDescriptorSetObj descriptorSet(m_device); |
Chia-I Wu | 1b99bb2 | 2015-10-27 19:25:11 +0800 | [diff] [blame] | 9623 | VkDescriptorPoolSize ds_type_count = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9624 | ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 9625 | ds_type_count.descriptorCount = 1; |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 9626 | |
| 9627 | VkDescriptorPoolCreateInfo ds_pool_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9628 | ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO; |
| 9629 | ds_pool_ci.pNext = NULL; |
| 9630 | ds_pool_ci.maxSets = 1; |
| 9631 | ds_pool_ci.poolSizeCount = 1; |
| 9632 | ds_pool_ci.pPoolSizes = &ds_type_count; |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 9633 | |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 9634 | VkDescriptorPool ds_pool; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9635 | err = |
| 9636 | vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool); |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 9637 | ASSERT_VK_SUCCESS(err); |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 9638 | VkDescriptorSetLayoutBinding dsl_binding = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9639 | dsl_binding.binding = 0; |
| 9640 | dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 9641 | dsl_binding.descriptorCount = 1; |
| 9642 | dsl_binding.stageFlags = VK_SHADER_STAGE_ALL; |
| 9643 | dsl_binding.pImmutableSamplers = NULL; |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 9644 | |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 9645 | VkDescriptorSetLayoutCreateInfo ds_layout_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9646 | ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO; |
| 9647 | ds_layout_ci.pNext = NULL; |
| 9648 | ds_layout_ci.bindingCount = 1; |
| 9649 | ds_layout_ci.pBindings = &dsl_binding; |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 9650 | |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 9651 | VkDescriptorSetLayout ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9652 | err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, |
| 9653 | &ds_layout); |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 9654 | ASSERT_VK_SUCCESS(err); |
| 9655 | |
| 9656 | VkDescriptorSet descriptorSet; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 9657 | VkDescriptorSetAllocateInfo alloc_info = {}; |
Chia-I Wu | 00ce540 | 2015-11-10 16:21:09 +0800 | [diff] [blame] | 9658 | alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO; |
Jon Ashburn | f19916e | 2016-01-11 13:12:43 -0700 | [diff] [blame] | 9659 | alloc_info.descriptorSetCount = 1; |
Courtney Goeltzenleuchter | bee18a9 | 2015-10-23 14:21:05 -0600 | [diff] [blame] | 9660 | alloc_info.descriptorPool = ds_pool; |
| 9661 | alloc_info.pSetLayouts = &ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9662 | err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, |
| 9663 | &descriptorSet); |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 9664 | ASSERT_VK_SUCCESS(err); |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 9665 | |
Tobin Ehlis | 30db8f8 | 2016-05-05 08:19:48 -0600 | [diff] [blame] | 9666 | VkSamplerCreateInfo sampler_ci = {}; |
| 9667 | sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO; |
| 9668 | sampler_ci.pNext = NULL; |
| 9669 | sampler_ci.magFilter = VK_FILTER_NEAREST; |
| 9670 | sampler_ci.minFilter = VK_FILTER_NEAREST; |
| 9671 | sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST; |
| 9672 | sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE; |
| 9673 | sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE; |
| 9674 | sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE; |
| 9675 | sampler_ci.mipLodBias = 1.0; |
| 9676 | sampler_ci.anisotropyEnable = VK_FALSE; |
| 9677 | sampler_ci.maxAnisotropy = 1; |
| 9678 | sampler_ci.compareEnable = VK_FALSE; |
| 9679 | sampler_ci.compareOp = VK_COMPARE_OP_NEVER; |
| 9680 | sampler_ci.minLod = 1.0; |
| 9681 | sampler_ci.maxLod = 1.0; |
| 9682 | sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE; |
| 9683 | sampler_ci.unnormalizedCoordinates = VK_FALSE; |
| 9684 | VkSampler sampler; |
| 9685 | err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler); |
| 9686 | ASSERT_VK_SUCCESS(err); |
| 9687 | |
| 9688 | VkDescriptorImageInfo info = {}; |
| 9689 | info.sampler = sampler; |
Chia-I Wu | 9d00ed7 | 2015-05-25 16:27:55 +0800 | [diff] [blame] | 9690 | |
| 9691 | VkWriteDescriptorSet descriptor_write; |
| 9692 | memset(&descriptor_write, 0, sizeof(descriptor_write)); |
| 9693 | descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 9694 | descriptor_write.dstSet = descriptorSet; |
Chia-I Wu | d50a7d7 | 2015-10-26 20:48:51 +0800 | [diff] [blame] | 9695 | descriptor_write.descriptorCount = 1; |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 9696 | // This is a mismatched type for the layout which expects BUFFER |
Chia-I Wu | 9d00ed7 | 2015-05-25 16:27:55 +0800 | [diff] [blame] | 9697 | descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER; |
Courtney Goeltzenleuchter | 4cb6d92 | 2015-10-23 13:38:14 -0600 | [diff] [blame] | 9698 | descriptor_write.pImageInfo = &info; |
Chia-I Wu | 9d00ed7 | 2015-05-25 16:27:55 +0800 | [diff] [blame] | 9699 | |
| 9700 | vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL); |
| 9701 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 9702 | m_errorMonitor->VerifyFound(); |
Mike Stroyan | d1c84a5 | 2015-08-18 14:40:24 -0600 | [diff] [blame] | 9703 | |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 9704 | vkDestroySampler(m_device->device(), sampler, NULL); |
| 9705 | vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL); |
| 9706 | vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL); |
Tobin Ehlis | 49eb23d | 2015-05-22 12:38:55 -0600 | [diff] [blame] | 9707 | } |
| 9708 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9709 | TEST_F(VkLayerTest, DSUpdateOutOfBounds) { |
Tobin Ehlis | 49eb23d | 2015-05-22 12:38:55 -0600 | [diff] [blame] | 9710 | // For overlapping Update, have arrayIndex exceed that of layout |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9711 | VkResult err; |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 9712 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9713 | m_errorMonitor->SetDesiredFailureMsg( |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 9714 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 9715 | " binding #0 with 1 total descriptors but update of 1 descriptors " |
| 9716 | "starting at binding offset of 0 combined with update array element " |
| 9717 | "offset of 1 oversteps the size of this descriptor set."); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 9718 | |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 9719 | ASSERT_NO_FATAL_FAILURE(InitState()); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9720 | // VkDescriptorSetObj descriptorSet(m_device); |
Chia-I Wu | 1b99bb2 | 2015-10-27 19:25:11 +0800 | [diff] [blame] | 9721 | VkDescriptorPoolSize ds_type_count = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9722 | ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 9723 | ds_type_count.descriptorCount = 1; |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 9724 | |
| 9725 | VkDescriptorPoolCreateInfo ds_pool_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9726 | ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO; |
| 9727 | ds_pool_ci.pNext = NULL; |
| 9728 | ds_pool_ci.maxSets = 1; |
| 9729 | ds_pool_ci.poolSizeCount = 1; |
| 9730 | ds_pool_ci.pPoolSizes = &ds_type_count; |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 9731 | |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 9732 | VkDescriptorPool ds_pool; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9733 | err = |
| 9734 | vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool); |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 9735 | ASSERT_VK_SUCCESS(err); |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 9736 | |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 9737 | VkDescriptorSetLayoutBinding dsl_binding = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9738 | dsl_binding.binding = 0; |
| 9739 | dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 9740 | dsl_binding.descriptorCount = 1; |
| 9741 | dsl_binding.stageFlags = VK_SHADER_STAGE_ALL; |
| 9742 | dsl_binding.pImmutableSamplers = NULL; |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 9743 | |
| 9744 | VkDescriptorSetLayoutCreateInfo ds_layout_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9745 | ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO; |
| 9746 | ds_layout_ci.pNext = NULL; |
| 9747 | ds_layout_ci.bindingCount = 1; |
| 9748 | ds_layout_ci.pBindings = &dsl_binding; |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 9749 | |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 9750 | VkDescriptorSetLayout ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9751 | err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, |
| 9752 | &ds_layout); |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 9753 | ASSERT_VK_SUCCESS(err); |
| 9754 | |
| 9755 | VkDescriptorSet descriptorSet; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 9756 | VkDescriptorSetAllocateInfo alloc_info = {}; |
Chia-I Wu | 00ce540 | 2015-11-10 16:21:09 +0800 | [diff] [blame] | 9757 | alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO; |
Jon Ashburn | f19916e | 2016-01-11 13:12:43 -0700 | [diff] [blame] | 9758 | alloc_info.descriptorSetCount = 1; |
Courtney Goeltzenleuchter | bee18a9 | 2015-10-23 14:21:05 -0600 | [diff] [blame] | 9759 | alloc_info.descriptorPool = ds_pool; |
| 9760 | alloc_info.pSetLayouts = &ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9761 | err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, |
| 9762 | &descriptorSet); |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 9763 | ASSERT_VK_SUCCESS(err); |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 9764 | |
Tobin Ehlis | 30db8f8 | 2016-05-05 08:19:48 -0600 | [diff] [blame] | 9765 | // Correctly update descriptor to avoid "NOT_UPDATED" error |
| 9766 | VkDescriptorBufferInfo buff_info = {}; |
| 9767 | buff_info.buffer = |
| 9768 | VkBuffer(0); // Don't care about buffer handle for this test |
| 9769 | buff_info.offset = 0; |
| 9770 | buff_info.range = 1024; |
Chia-I Wu | 9d00ed7 | 2015-05-25 16:27:55 +0800 | [diff] [blame] | 9771 | |
| 9772 | VkWriteDescriptorSet descriptor_write; |
| 9773 | memset(&descriptor_write, 0, sizeof(descriptor_write)); |
| 9774 | descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 9775 | descriptor_write.dstSet = descriptorSet; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9776 | descriptor_write.dstArrayElement = |
| 9777 | 1; /* This index out of bounds for the update */ |
Chia-I Wu | d50a7d7 | 2015-10-26 20:48:51 +0800 | [diff] [blame] | 9778 | descriptor_write.descriptorCount = 1; |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 9779 | descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 9780 | descriptor_write.pBufferInfo = &buff_info; |
Chia-I Wu | 9d00ed7 | 2015-05-25 16:27:55 +0800 | [diff] [blame] | 9781 | |
| 9782 | vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL); |
| 9783 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 9784 | m_errorMonitor->VerifyFound(); |
Mike Stroyan | d1c84a5 | 2015-08-18 14:40:24 -0600 | [diff] [blame] | 9785 | |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 9786 | vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL); |
| 9787 | vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL); |
Tobin Ehlis | 49eb23d | 2015-05-22 12:38:55 -0600 | [diff] [blame] | 9788 | } |
| 9789 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9790 | TEST_F(VkLayerTest, InvalidDSUpdateIndex) { |
| 9791 | // Create layout w/ count of 1 and attempt update to that layout w/ binding |
| 9792 | // index 2 |
| 9793 | VkResult err; |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 9794 | |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 9795 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 9796 | " does not have binding 2."); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 9797 | |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 9798 | ASSERT_NO_FATAL_FAILURE(InitState()); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9799 | // VkDescriptorSetObj descriptorSet(m_device); |
Chia-I Wu | 1b99bb2 | 2015-10-27 19:25:11 +0800 | [diff] [blame] | 9800 | VkDescriptorPoolSize ds_type_count = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9801 | ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 9802 | ds_type_count.descriptorCount = 1; |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 9803 | |
| 9804 | VkDescriptorPoolCreateInfo ds_pool_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9805 | ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO; |
| 9806 | ds_pool_ci.pNext = NULL; |
| 9807 | ds_pool_ci.maxSets = 1; |
| 9808 | ds_pool_ci.poolSizeCount = 1; |
| 9809 | ds_pool_ci.pPoolSizes = &ds_type_count; |
Courtney Goeltzenleuchter | fe908d3 | 2015-09-16 16:12:45 -0600 | [diff] [blame] | 9810 | |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 9811 | VkDescriptorPool ds_pool; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9812 | err = |
| 9813 | vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool); |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 9814 | ASSERT_VK_SUCCESS(err); |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 9815 | |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 9816 | VkDescriptorSetLayoutBinding dsl_binding = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9817 | dsl_binding.binding = 0; |
| 9818 | dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 9819 | dsl_binding.descriptorCount = 1; |
| 9820 | dsl_binding.stageFlags = VK_SHADER_STAGE_ALL; |
| 9821 | dsl_binding.pImmutableSamplers = NULL; |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 9822 | |
| 9823 | VkDescriptorSetLayoutCreateInfo ds_layout_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9824 | ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO; |
| 9825 | ds_layout_ci.pNext = NULL; |
| 9826 | ds_layout_ci.bindingCount = 1; |
| 9827 | ds_layout_ci.pBindings = &dsl_binding; |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 9828 | VkDescriptorSetLayout ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9829 | err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, |
| 9830 | &ds_layout); |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 9831 | ASSERT_VK_SUCCESS(err); |
| 9832 | |
| 9833 | VkDescriptorSet descriptorSet; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 9834 | VkDescriptorSetAllocateInfo alloc_info = {}; |
Chia-I Wu | 00ce540 | 2015-11-10 16:21:09 +0800 | [diff] [blame] | 9835 | alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO; |
Jon Ashburn | f19916e | 2016-01-11 13:12:43 -0700 | [diff] [blame] | 9836 | alloc_info.descriptorSetCount = 1; |
Courtney Goeltzenleuchter | bee18a9 | 2015-10-23 14:21:05 -0600 | [diff] [blame] | 9837 | alloc_info.descriptorPool = ds_pool; |
| 9838 | alloc_info.pSetLayouts = &ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9839 | err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, |
| 9840 | &descriptorSet); |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 9841 | ASSERT_VK_SUCCESS(err); |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 9842 | |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 9843 | VkSamplerCreateInfo sampler_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9844 | sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO; |
| 9845 | sampler_ci.pNext = NULL; |
| 9846 | sampler_ci.magFilter = VK_FILTER_NEAREST; |
| 9847 | sampler_ci.minFilter = VK_FILTER_NEAREST; |
| 9848 | sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST; |
| 9849 | sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE; |
| 9850 | sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE; |
| 9851 | sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE; |
| 9852 | sampler_ci.mipLodBias = 1.0; |
| 9853 | sampler_ci.anisotropyEnable = VK_FALSE; |
| 9854 | sampler_ci.maxAnisotropy = 1; |
| 9855 | sampler_ci.compareEnable = VK_FALSE; |
| 9856 | sampler_ci.compareOp = VK_COMPARE_OP_NEVER; |
| 9857 | sampler_ci.minLod = 1.0; |
| 9858 | sampler_ci.maxLod = 1.0; |
| 9859 | sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE; |
| 9860 | sampler_ci.unnormalizedCoordinates = VK_FALSE; |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 9861 | |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 9862 | VkSampler sampler; |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 9863 | err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler); |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 9864 | ASSERT_VK_SUCCESS(err); |
Chia-I Wu | 9d00ed7 | 2015-05-25 16:27:55 +0800 | [diff] [blame] | 9865 | |
Courtney Goeltzenleuchter | 4cb6d92 | 2015-10-23 13:38:14 -0600 | [diff] [blame] | 9866 | VkDescriptorImageInfo info = {}; |
| 9867 | info.sampler = sampler; |
Chia-I Wu | 9d00ed7 | 2015-05-25 16:27:55 +0800 | [diff] [blame] | 9868 | |
| 9869 | VkWriteDescriptorSet descriptor_write; |
| 9870 | memset(&descriptor_write, 0, sizeof(descriptor_write)); |
| 9871 | descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 9872 | descriptor_write.dstSet = descriptorSet; |
| 9873 | descriptor_write.dstBinding = 2; |
Chia-I Wu | d50a7d7 | 2015-10-26 20:48:51 +0800 | [diff] [blame] | 9874 | descriptor_write.descriptorCount = 1; |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 9875 | // 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] | 9876 | descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER; |
Courtney Goeltzenleuchter | 4cb6d92 | 2015-10-23 13:38:14 -0600 | [diff] [blame] | 9877 | descriptor_write.pImageInfo = &info; |
Chia-I Wu | 9d00ed7 | 2015-05-25 16:27:55 +0800 | [diff] [blame] | 9878 | |
| 9879 | vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL); |
| 9880 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 9881 | m_errorMonitor->VerifyFound(); |
Mike Stroyan | d1c84a5 | 2015-08-18 14:40:24 -0600 | [diff] [blame] | 9882 | |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 9883 | vkDestroySampler(m_device->device(), sampler, NULL); |
| 9884 | vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL); |
| 9885 | vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL); |
Tobin Ehlis | 49eb23d | 2015-05-22 12:38:55 -0600 | [diff] [blame] | 9886 | } |
| 9887 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9888 | TEST_F(VkLayerTest, InvalidDSUpdateStruct) { |
| 9889 | // Call UpdateDS w/ struct type other than valid VK_STRUCTUR_TYPE_UPDATE_* |
| 9890 | // types |
| 9891 | VkResult err; |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 9892 | |
Courtney Goeltzenleuchter | 7415d5a | 2015-12-09 15:48:16 -0700 | [diff] [blame] | 9893 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Tobin Ehlis | 660bcdc | 2016-05-17 10:39:46 -0600 | [diff] [blame] | 9894 | ".sType must be VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET"); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 9895 | |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 9896 | ASSERT_NO_FATAL_FAILURE(InitState()); |
Mark Lobodzinski | 209b529 | 2015-09-17 09:44:05 -0600 | [diff] [blame] | 9897 | |
Chia-I Wu | 1b99bb2 | 2015-10-27 19:25:11 +0800 | [diff] [blame] | 9898 | VkDescriptorPoolSize ds_type_count = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9899 | ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 9900 | ds_type_count.descriptorCount = 1; |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 9901 | |
| 9902 | VkDescriptorPoolCreateInfo ds_pool_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9903 | ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO; |
| 9904 | ds_pool_ci.pNext = NULL; |
| 9905 | ds_pool_ci.maxSets = 1; |
| 9906 | ds_pool_ci.poolSizeCount = 1; |
| 9907 | ds_pool_ci.pPoolSizes = &ds_type_count; |
Courtney Goeltzenleuchter | fe908d3 | 2015-09-16 16:12:45 -0600 | [diff] [blame] | 9908 | |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 9909 | VkDescriptorPool ds_pool; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9910 | err = |
| 9911 | vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool); |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 9912 | ASSERT_VK_SUCCESS(err); |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 9913 | VkDescriptorSetLayoutBinding dsl_binding = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9914 | dsl_binding.binding = 0; |
| 9915 | dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 9916 | dsl_binding.descriptorCount = 1; |
| 9917 | dsl_binding.stageFlags = VK_SHADER_STAGE_ALL; |
| 9918 | dsl_binding.pImmutableSamplers = NULL; |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 9919 | |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 9920 | VkDescriptorSetLayoutCreateInfo ds_layout_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9921 | ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO; |
| 9922 | ds_layout_ci.pNext = NULL; |
| 9923 | ds_layout_ci.bindingCount = 1; |
| 9924 | ds_layout_ci.pBindings = &dsl_binding; |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 9925 | |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 9926 | VkDescriptorSetLayout ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9927 | err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, |
| 9928 | &ds_layout); |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 9929 | ASSERT_VK_SUCCESS(err); |
| 9930 | |
| 9931 | VkDescriptorSet descriptorSet; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 9932 | VkDescriptorSetAllocateInfo alloc_info = {}; |
Chia-I Wu | 00ce540 | 2015-11-10 16:21:09 +0800 | [diff] [blame] | 9933 | alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO; |
Jon Ashburn | f19916e | 2016-01-11 13:12:43 -0700 | [diff] [blame] | 9934 | alloc_info.descriptorSetCount = 1; |
Courtney Goeltzenleuchter | bee18a9 | 2015-10-23 14:21:05 -0600 | [diff] [blame] | 9935 | alloc_info.descriptorPool = ds_pool; |
| 9936 | alloc_info.pSetLayouts = &ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9937 | err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, |
| 9938 | &descriptorSet); |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 9939 | ASSERT_VK_SUCCESS(err); |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 9940 | |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 9941 | VkSamplerCreateInfo sampler_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9942 | sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO; |
| 9943 | sampler_ci.pNext = NULL; |
| 9944 | sampler_ci.magFilter = VK_FILTER_NEAREST; |
| 9945 | sampler_ci.minFilter = VK_FILTER_NEAREST; |
| 9946 | sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST; |
| 9947 | sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE; |
| 9948 | sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE; |
| 9949 | sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE; |
| 9950 | sampler_ci.mipLodBias = 1.0; |
| 9951 | sampler_ci.anisotropyEnable = VK_FALSE; |
| 9952 | sampler_ci.maxAnisotropy = 1; |
| 9953 | sampler_ci.compareEnable = VK_FALSE; |
| 9954 | sampler_ci.compareOp = VK_COMPARE_OP_NEVER; |
| 9955 | sampler_ci.minLod = 1.0; |
| 9956 | sampler_ci.maxLod = 1.0; |
| 9957 | sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE; |
| 9958 | sampler_ci.unnormalizedCoordinates = VK_FALSE; |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 9959 | VkSampler sampler; |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 9960 | err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler); |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 9961 | ASSERT_VK_SUCCESS(err); |
Chia-I Wu | 9d00ed7 | 2015-05-25 16:27:55 +0800 | [diff] [blame] | 9962 | |
Courtney Goeltzenleuchter | 4cb6d92 | 2015-10-23 13:38:14 -0600 | [diff] [blame] | 9963 | VkDescriptorImageInfo info = {}; |
| 9964 | info.sampler = sampler; |
Chia-I Wu | 9d00ed7 | 2015-05-25 16:27:55 +0800 | [diff] [blame] | 9965 | |
| 9966 | VkWriteDescriptorSet descriptor_write; |
| 9967 | memset(&descriptor_write, 0, sizeof(descriptor_write)); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9968 | descriptor_write.sType = |
| 9969 | (VkStructureType)0x99999999; /* Intentionally broken struct type */ |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 9970 | descriptor_write.dstSet = descriptorSet; |
Chia-I Wu | d50a7d7 | 2015-10-26 20:48:51 +0800 | [diff] [blame] | 9971 | descriptor_write.descriptorCount = 1; |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 9972 | // 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] | 9973 | descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER; |
Courtney Goeltzenleuchter | 4cb6d92 | 2015-10-23 13:38:14 -0600 | [diff] [blame] | 9974 | descriptor_write.pImageInfo = &info; |
Chia-I Wu | 9d00ed7 | 2015-05-25 16:27:55 +0800 | [diff] [blame] | 9975 | |
| 9976 | vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL); |
| 9977 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 9978 | m_errorMonitor->VerifyFound(); |
Mike Stroyan | d1c84a5 | 2015-08-18 14:40:24 -0600 | [diff] [blame] | 9979 | |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 9980 | vkDestroySampler(m_device->device(), sampler, NULL); |
| 9981 | vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL); |
| 9982 | vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL); |
Tobin Ehlis | 49eb23d | 2015-05-22 12:38:55 -0600 | [diff] [blame] | 9983 | } |
| 9984 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9985 | TEST_F(VkLayerTest, SampleDescriptorUpdateError) { |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 9986 | // Create a single Sampler descriptor and send it an invalid Sampler |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9987 | VkResult err; |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 9988 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9989 | m_errorMonitor->SetDesiredFailureMsg( |
| 9990 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 9991 | "Attempted write update to sampler descriptor with invalid sampler"); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 9992 | |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 9993 | ASSERT_NO_FATAL_FAILURE(InitState()); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9994 | // TODO : Farm Descriptor setup code to helper function(s) to reduce copied |
| 9995 | // code |
Chia-I Wu | 1b99bb2 | 2015-10-27 19:25:11 +0800 | [diff] [blame] | 9996 | VkDescriptorPoolSize ds_type_count = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9997 | ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLER; |
| 9998 | ds_type_count.descriptorCount = 1; |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 9999 | |
| 10000 | VkDescriptorPoolCreateInfo ds_pool_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 10001 | ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO; |
| 10002 | ds_pool_ci.pNext = NULL; |
| 10003 | ds_pool_ci.maxSets = 1; |
| 10004 | ds_pool_ci.poolSizeCount = 1; |
| 10005 | ds_pool_ci.pPoolSizes = &ds_type_count; |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 10006 | |
| 10007 | VkDescriptorPool ds_pool; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 10008 | err = |
| 10009 | vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool); |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 10010 | ASSERT_VK_SUCCESS(err); |
| 10011 | |
| 10012 | VkDescriptorSetLayoutBinding dsl_binding = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 10013 | dsl_binding.binding = 0; |
| 10014 | dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER; |
| 10015 | dsl_binding.descriptorCount = 1; |
| 10016 | dsl_binding.stageFlags = VK_SHADER_STAGE_ALL; |
| 10017 | dsl_binding.pImmutableSamplers = NULL; |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 10018 | |
| 10019 | VkDescriptorSetLayoutCreateInfo ds_layout_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 10020 | ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO; |
| 10021 | ds_layout_ci.pNext = NULL; |
| 10022 | ds_layout_ci.bindingCount = 1; |
| 10023 | ds_layout_ci.pBindings = &dsl_binding; |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 10024 | VkDescriptorSetLayout ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 10025 | err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, |
| 10026 | &ds_layout); |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 10027 | ASSERT_VK_SUCCESS(err); |
| 10028 | |
| 10029 | VkDescriptorSet descriptorSet; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 10030 | VkDescriptorSetAllocateInfo alloc_info = {}; |
Chia-I Wu | 00ce540 | 2015-11-10 16:21:09 +0800 | [diff] [blame] | 10031 | alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO; |
Jon Ashburn | f19916e | 2016-01-11 13:12:43 -0700 | [diff] [blame] | 10032 | alloc_info.descriptorSetCount = 1; |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 10033 | alloc_info.descriptorPool = ds_pool; |
| 10034 | alloc_info.pSetLayouts = &ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 10035 | err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, |
| 10036 | &descriptorSet); |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 10037 | ASSERT_VK_SUCCESS(err); |
| 10038 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 10039 | VkSampler sampler = |
| 10040 | (VkSampler)((size_t)0xbaadbeef); // Sampler with invalid handle |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 10041 | |
| 10042 | VkDescriptorImageInfo descriptor_info; |
| 10043 | memset(&descriptor_info, 0, sizeof(VkDescriptorImageInfo)); |
| 10044 | descriptor_info.sampler = sampler; |
| 10045 | |
| 10046 | VkWriteDescriptorSet descriptor_write; |
| 10047 | memset(&descriptor_write, 0, sizeof(descriptor_write)); |
| 10048 | descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 10049 | descriptor_write.dstSet = descriptorSet; |
| 10050 | descriptor_write.dstBinding = 0; |
Chia-I Wu | d50a7d7 | 2015-10-26 20:48:51 +0800 | [diff] [blame] | 10051 | descriptor_write.descriptorCount = 1; |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 10052 | descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER; |
| 10053 | descriptor_write.pImageInfo = &descriptor_info; |
| 10054 | |
| 10055 | vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL); |
| 10056 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 10057 | m_errorMonitor->VerifyFound(); |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 10058 | |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 10059 | vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL); |
| 10060 | vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL); |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 10061 | } |
| 10062 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 10063 | TEST_F(VkLayerTest, ImageViewDescriptorUpdateError) { |
| 10064 | // Create a single combined Image/Sampler descriptor and send it an invalid |
| 10065 | // imageView |
| 10066 | VkResult err; |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 10067 | |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 10068 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 10069 | "Attempted write update to combined " |
| 10070 | "image sampler descriptor failed due " |
Tobin Ehlis | 63c4b8a | 2016-05-09 10:29:34 -0600 | [diff] [blame] | 10071 | "to: Invalid VkImageView:"); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 10072 | |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 10073 | ASSERT_NO_FATAL_FAILURE(InitState()); |
Chia-I Wu | 1b99bb2 | 2015-10-27 19:25:11 +0800 | [diff] [blame] | 10074 | VkDescriptorPoolSize ds_type_count = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 10075 | ds_type_count.type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER; |
| 10076 | ds_type_count.descriptorCount = 1; |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 10077 | |
| 10078 | VkDescriptorPoolCreateInfo ds_pool_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 10079 | ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO; |
| 10080 | ds_pool_ci.pNext = NULL; |
| 10081 | ds_pool_ci.maxSets = 1; |
| 10082 | ds_pool_ci.poolSizeCount = 1; |
| 10083 | ds_pool_ci.pPoolSizes = &ds_type_count; |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 10084 | |
| 10085 | VkDescriptorPool ds_pool; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 10086 | err = |
| 10087 | vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool); |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 10088 | ASSERT_VK_SUCCESS(err); |
| 10089 | |
| 10090 | VkDescriptorSetLayoutBinding dsl_binding = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 10091 | dsl_binding.binding = 0; |
| 10092 | dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER; |
| 10093 | dsl_binding.descriptorCount = 1; |
| 10094 | dsl_binding.stageFlags = VK_SHADER_STAGE_ALL; |
| 10095 | dsl_binding.pImmutableSamplers = NULL; |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 10096 | |
| 10097 | VkDescriptorSetLayoutCreateInfo ds_layout_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 10098 | ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO; |
| 10099 | ds_layout_ci.pNext = NULL; |
| 10100 | ds_layout_ci.bindingCount = 1; |
| 10101 | ds_layout_ci.pBindings = &dsl_binding; |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 10102 | VkDescriptorSetLayout ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 10103 | err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, |
| 10104 | &ds_layout); |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 10105 | ASSERT_VK_SUCCESS(err); |
| 10106 | |
| 10107 | VkDescriptorSet descriptorSet; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 10108 | VkDescriptorSetAllocateInfo alloc_info = {}; |
Chia-I Wu | 00ce540 | 2015-11-10 16:21:09 +0800 | [diff] [blame] | 10109 | alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO; |
Jon Ashburn | f19916e | 2016-01-11 13:12:43 -0700 | [diff] [blame] | 10110 | alloc_info.descriptorSetCount = 1; |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 10111 | alloc_info.descriptorPool = ds_pool; |
| 10112 | alloc_info.pSetLayouts = &ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 10113 | err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, |
| 10114 | &descriptorSet); |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 10115 | ASSERT_VK_SUCCESS(err); |
| 10116 | |
| 10117 | VkSamplerCreateInfo sampler_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 10118 | sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO; |
| 10119 | sampler_ci.pNext = NULL; |
| 10120 | sampler_ci.magFilter = VK_FILTER_NEAREST; |
| 10121 | sampler_ci.minFilter = VK_FILTER_NEAREST; |
| 10122 | sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST; |
| 10123 | sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE; |
| 10124 | sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE; |
| 10125 | sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE; |
| 10126 | sampler_ci.mipLodBias = 1.0; |
| 10127 | sampler_ci.anisotropyEnable = VK_FALSE; |
| 10128 | sampler_ci.maxAnisotropy = 1; |
| 10129 | sampler_ci.compareEnable = VK_FALSE; |
| 10130 | sampler_ci.compareOp = VK_COMPARE_OP_NEVER; |
| 10131 | sampler_ci.minLod = 1.0; |
| 10132 | sampler_ci.maxLod = 1.0; |
| 10133 | sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE; |
| 10134 | sampler_ci.unnormalizedCoordinates = VK_FALSE; |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 10135 | |
| 10136 | VkSampler sampler; |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 10137 | err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler); |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 10138 | ASSERT_VK_SUCCESS(err); |
| 10139 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 10140 | VkImageView view = |
| 10141 | (VkImageView)((size_t)0xbaadbeef); // invalid imageView object |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 10142 | |
| 10143 | VkDescriptorImageInfo descriptor_info; |
| 10144 | memset(&descriptor_info, 0, sizeof(VkDescriptorImageInfo)); |
| 10145 | descriptor_info.sampler = sampler; |
| 10146 | descriptor_info.imageView = view; |
| 10147 | |
| 10148 | VkWriteDescriptorSet descriptor_write; |
| 10149 | memset(&descriptor_write, 0, sizeof(descriptor_write)); |
| 10150 | descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 10151 | descriptor_write.dstSet = descriptorSet; |
| 10152 | descriptor_write.dstBinding = 0; |
Chia-I Wu | d50a7d7 | 2015-10-26 20:48:51 +0800 | [diff] [blame] | 10153 | descriptor_write.descriptorCount = 1; |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 10154 | descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER; |
| 10155 | descriptor_write.pImageInfo = &descriptor_info; |
| 10156 | |
| 10157 | vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL); |
| 10158 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 10159 | m_errorMonitor->VerifyFound(); |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 10160 | |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 10161 | vkDestroySampler(m_device->device(), sampler, NULL); |
| 10162 | vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL); |
| 10163 | vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL); |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 10164 | } |
| 10165 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 10166 | TEST_F(VkLayerTest, CopyDescriptorUpdateErrors) { |
| 10167 | // Create DS w/ layout of 2 types, write update 1 and attempt to copy-update |
| 10168 | // into the other |
| 10169 | VkResult err; |
Tobin Ehlis | 04356f9 | 2015-10-27 16:35:27 -0600 | [diff] [blame] | 10170 | |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 10171 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 10172 | " binding #1 with type " |
| 10173 | "VK_DESCRIPTOR_TYPE_SAMPLER. Types do " |
| 10174 | "not match."); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 10175 | |
Tobin Ehlis | 04356f9 | 2015-10-27 16:35:27 -0600 | [diff] [blame] | 10176 | ASSERT_NO_FATAL_FAILURE(InitState()); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 10177 | // VkDescriptorSetObj descriptorSet(m_device); |
Chia-I Wu | 1b99bb2 | 2015-10-27 19:25:11 +0800 | [diff] [blame] | 10178 | VkDescriptorPoolSize ds_type_count[2] = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 10179 | ds_type_count[0].type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 10180 | ds_type_count[0].descriptorCount = 1; |
| 10181 | ds_type_count[1].type = VK_DESCRIPTOR_TYPE_SAMPLER; |
| 10182 | ds_type_count[1].descriptorCount = 1; |
Tobin Ehlis | 04356f9 | 2015-10-27 16:35:27 -0600 | [diff] [blame] | 10183 | |
| 10184 | VkDescriptorPoolCreateInfo ds_pool_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 10185 | ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO; |
| 10186 | ds_pool_ci.pNext = NULL; |
| 10187 | ds_pool_ci.maxSets = 1; |
| 10188 | ds_pool_ci.poolSizeCount = 2; |
| 10189 | ds_pool_ci.pPoolSizes = ds_type_count; |
Tobin Ehlis | 04356f9 | 2015-10-27 16:35:27 -0600 | [diff] [blame] | 10190 | |
| 10191 | VkDescriptorPool ds_pool; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 10192 | err = |
| 10193 | vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool); |
Tobin Ehlis | 04356f9 | 2015-10-27 16:35:27 -0600 | [diff] [blame] | 10194 | ASSERT_VK_SUCCESS(err); |
| 10195 | VkDescriptorSetLayoutBinding dsl_binding[2] = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 10196 | dsl_binding[0].binding = 0; |
| 10197 | dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 10198 | dsl_binding[0].descriptorCount = 1; |
| 10199 | dsl_binding[0].stageFlags = VK_SHADER_STAGE_ALL; |
| 10200 | dsl_binding[0].pImmutableSamplers = NULL; |
| 10201 | dsl_binding[1].binding = 1; |
| 10202 | dsl_binding[1].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER; |
| 10203 | dsl_binding[1].descriptorCount = 1; |
| 10204 | dsl_binding[1].stageFlags = VK_SHADER_STAGE_ALL; |
| 10205 | dsl_binding[1].pImmutableSamplers = NULL; |
Tobin Ehlis | 04356f9 | 2015-10-27 16:35:27 -0600 | [diff] [blame] | 10206 | |
| 10207 | VkDescriptorSetLayoutCreateInfo ds_layout_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 10208 | ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO; |
| 10209 | ds_layout_ci.pNext = NULL; |
| 10210 | ds_layout_ci.bindingCount = 2; |
| 10211 | ds_layout_ci.pBindings = dsl_binding; |
Tobin Ehlis | 04356f9 | 2015-10-27 16:35:27 -0600 | [diff] [blame] | 10212 | |
| 10213 | VkDescriptorSetLayout ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 10214 | err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, |
| 10215 | &ds_layout); |
Tobin Ehlis | 04356f9 | 2015-10-27 16:35:27 -0600 | [diff] [blame] | 10216 | ASSERT_VK_SUCCESS(err); |
| 10217 | |
| 10218 | VkDescriptorSet descriptorSet; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 10219 | VkDescriptorSetAllocateInfo alloc_info = {}; |
Chia-I Wu | 00ce540 | 2015-11-10 16:21:09 +0800 | [diff] [blame] | 10220 | alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO; |
Jon Ashburn | f19916e | 2016-01-11 13:12:43 -0700 | [diff] [blame] | 10221 | alloc_info.descriptorSetCount = 1; |
Tobin Ehlis | 04356f9 | 2015-10-27 16:35:27 -0600 | [diff] [blame] | 10222 | alloc_info.descriptorPool = ds_pool; |
| 10223 | alloc_info.pSetLayouts = &ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 10224 | err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, |
| 10225 | &descriptorSet); |
Tobin Ehlis | 04356f9 | 2015-10-27 16:35:27 -0600 | [diff] [blame] | 10226 | ASSERT_VK_SUCCESS(err); |
| 10227 | |
| 10228 | VkSamplerCreateInfo sampler_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 10229 | sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO; |
| 10230 | sampler_ci.pNext = NULL; |
| 10231 | sampler_ci.magFilter = VK_FILTER_NEAREST; |
| 10232 | sampler_ci.minFilter = VK_FILTER_NEAREST; |
| 10233 | sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST; |
| 10234 | sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE; |
| 10235 | sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE; |
| 10236 | sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE; |
| 10237 | sampler_ci.mipLodBias = 1.0; |
| 10238 | sampler_ci.anisotropyEnable = VK_FALSE; |
| 10239 | sampler_ci.maxAnisotropy = 1; |
| 10240 | sampler_ci.compareEnable = VK_FALSE; |
| 10241 | sampler_ci.compareOp = VK_COMPARE_OP_NEVER; |
| 10242 | sampler_ci.minLod = 1.0; |
| 10243 | sampler_ci.maxLod = 1.0; |
| 10244 | sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE; |
| 10245 | sampler_ci.unnormalizedCoordinates = VK_FALSE; |
Tobin Ehlis | 04356f9 | 2015-10-27 16:35:27 -0600 | [diff] [blame] | 10246 | |
| 10247 | VkSampler sampler; |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 10248 | err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler); |
Tobin Ehlis | 04356f9 | 2015-10-27 16:35:27 -0600 | [diff] [blame] | 10249 | ASSERT_VK_SUCCESS(err); |
| 10250 | |
| 10251 | VkDescriptorImageInfo info = {}; |
| 10252 | info.sampler = sampler; |
| 10253 | |
| 10254 | VkWriteDescriptorSet descriptor_write; |
| 10255 | memset(&descriptor_write, 0, sizeof(VkWriteDescriptorSet)); |
| 10256 | descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 10257 | descriptor_write.dstSet = descriptorSet; |
| 10258 | descriptor_write.dstBinding = 1; // SAMPLER binding from layout above |
Chia-I Wu | d50a7d7 | 2015-10-26 20:48:51 +0800 | [diff] [blame] | 10259 | descriptor_write.descriptorCount = 1; |
Tobin Ehlis | 04356f9 | 2015-10-27 16:35:27 -0600 | [diff] [blame] | 10260 | descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER; |
| 10261 | descriptor_write.pImageInfo = &info; |
| 10262 | // This write update should succeed |
| 10263 | vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL); |
| 10264 | // Now perform a copy update that fails due to type mismatch |
| 10265 | VkCopyDescriptorSet copy_ds_update; |
| 10266 | memset(©_ds_update, 0, sizeof(VkCopyDescriptorSet)); |
| 10267 | copy_ds_update.sType = VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET; |
| 10268 | copy_ds_update.srcSet = descriptorSet; |
Mark Young | 2992748 | 2016-05-04 14:38:51 -0600 | [diff] [blame] | 10269 | copy_ds_update.srcBinding = 1; // Copy from SAMPLER binding |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 10270 | copy_ds_update.dstSet = descriptorSet; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 10271 | copy_ds_update.dstBinding = 0; // ERROR : copy to UNIFORM binding |
Chia-I Wu | d50a7d7 | 2015-10-26 20:48:51 +0800 | [diff] [blame] | 10272 | copy_ds_update.descriptorCount = 1; // copy 1 descriptor |
Tobin Ehlis | 04356f9 | 2015-10-27 16:35:27 -0600 | [diff] [blame] | 10273 | vkUpdateDescriptorSets(m_device->device(), 0, NULL, 1, ©_ds_update); |
| 10274 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 10275 | m_errorMonitor->VerifyFound(); |
Tobin Ehlis | 04356f9 | 2015-10-27 16:35:27 -0600 | [diff] [blame] | 10276 | // 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] | 10277 | m_errorMonitor->SetDesiredFailureMsg( |
| 10278 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 10279 | " does not have copy update src binding of 3."); |
Tobin Ehlis | 04356f9 | 2015-10-27 16:35:27 -0600 | [diff] [blame] | 10280 | memset(©_ds_update, 0, sizeof(VkCopyDescriptorSet)); |
| 10281 | copy_ds_update.sType = VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET; |
| 10282 | copy_ds_update.srcSet = descriptorSet; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 10283 | copy_ds_update.srcBinding = |
| 10284 | 3; // ERROR : Invalid binding for matching layout |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 10285 | copy_ds_update.dstSet = descriptorSet; |
| 10286 | copy_ds_update.dstBinding = 0; |
Mark Young | 2992748 | 2016-05-04 14:38:51 -0600 | [diff] [blame] | 10287 | copy_ds_update.descriptorCount = 1; // Copy 1 descriptor |
Tobin Ehlis | 04356f9 | 2015-10-27 16:35:27 -0600 | [diff] [blame] | 10288 | vkUpdateDescriptorSets(m_device->device(), 0, NULL, 1, ©_ds_update); |
| 10289 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 10290 | m_errorMonitor->VerifyFound(); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 10291 | |
Tobin Ehlis | 04356f9 | 2015-10-27 16:35:27 -0600 | [diff] [blame] | 10292 | // 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] | 10293 | m_errorMonitor->SetDesiredFailureMsg( |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 10294 | VK_DEBUG_REPORT_ERROR_BIT_EXT, " binding#1 with offset index of 1 plus " |
| 10295 | "update array offset of 0 and update of " |
| 10296 | "5 descriptors oversteps total number " |
| 10297 | "of descriptors in set: 2."); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 10298 | |
Tobin Ehlis | 04356f9 | 2015-10-27 16:35:27 -0600 | [diff] [blame] | 10299 | memset(©_ds_update, 0, sizeof(VkCopyDescriptorSet)); |
| 10300 | copy_ds_update.sType = VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET; |
| 10301 | copy_ds_update.srcSet = descriptorSet; |
| 10302 | copy_ds_update.srcBinding = 1; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 10303 | copy_ds_update.dstSet = descriptorSet; |
| 10304 | copy_ds_update.dstBinding = 0; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 10305 | copy_ds_update.descriptorCount = |
| 10306 | 5; // ERROR copy 5 descriptors (out of bounds for layout) |
Tobin Ehlis | 04356f9 | 2015-10-27 16:35:27 -0600 | [diff] [blame] | 10307 | vkUpdateDescriptorSets(m_device->device(), 0, NULL, 1, ©_ds_update); |
| 10308 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 10309 | m_errorMonitor->VerifyFound(); |
Tobin Ehlis | 04356f9 | 2015-10-27 16:35:27 -0600 | [diff] [blame] | 10310 | |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 10311 | vkDestroySampler(m_device->device(), sampler, NULL); |
| 10312 | vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL); |
| 10313 | vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL); |
Tobin Ehlis | 04356f9 | 2015-10-27 16:35:27 -0600 | [diff] [blame] | 10314 | } |
| 10315 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 10316 | TEST_F(VkLayerTest, NumSamplesMismatch) { |
| 10317 | // Create CommandBuffer where MSAA samples doesn't match RenderPass |
| 10318 | // sampleCount |
| 10319 | VkResult err; |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 10320 | |
Courtney Goeltzenleuchter | 7415d5a | 2015-12-09 15:48:16 -0700 | [diff] [blame] | 10321 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 10322 | "Num samples mismatch! "); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 10323 | |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 10324 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 10325 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
Chia-I Wu | 1b99bb2 | 2015-10-27 19:25:11 +0800 | [diff] [blame] | 10326 | VkDescriptorPoolSize ds_type_count = {}; |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 10327 | ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
Chia-I Wu | d50a7d7 | 2015-10-26 20:48:51 +0800 | [diff] [blame] | 10328 | ds_type_count.descriptorCount = 1; |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 10329 | |
| 10330 | VkDescriptorPoolCreateInfo ds_pool_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 10331 | ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO; |
| 10332 | ds_pool_ci.pNext = NULL; |
| 10333 | ds_pool_ci.maxSets = 1; |
| 10334 | ds_pool_ci.poolSizeCount = 1; |
| 10335 | ds_pool_ci.pPoolSizes = &ds_type_count; |
Courtney Goeltzenleuchter | fe908d3 | 2015-09-16 16:12:45 -0600 | [diff] [blame] | 10336 | |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 10337 | VkDescriptorPool ds_pool; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 10338 | err = |
| 10339 | vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool); |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 10340 | ASSERT_VK_SUCCESS(err); |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 10341 | |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 10342 | VkDescriptorSetLayoutBinding dsl_binding = {}; |
Chia-I Wu | d46e6ae | 2015-10-31 00:31:16 +0800 | [diff] [blame] | 10343 | dsl_binding.binding = 0; |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 10344 | dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
Chia-I Wu | 0212448 | 2015-11-06 06:42:02 +0800 | [diff] [blame] | 10345 | dsl_binding.descriptorCount = 1; |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 10346 | dsl_binding.stageFlags = VK_SHADER_STAGE_ALL; |
| 10347 | dsl_binding.pImmutableSamplers = NULL; |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 10348 | |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 10349 | VkDescriptorSetLayoutCreateInfo ds_layout_ci = {}; |
| 10350 | ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO; |
| 10351 | ds_layout_ci.pNext = NULL; |
Chia-I Wu | d50a7d7 | 2015-10-26 20:48:51 +0800 | [diff] [blame] | 10352 | ds_layout_ci.bindingCount = 1; |
Jon Ashburn | 6e23c1f | 2015-12-30 18:01:16 -0700 | [diff] [blame] | 10353 | ds_layout_ci.pBindings = &dsl_binding; |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 10354 | |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 10355 | VkDescriptorSetLayout ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 10356 | err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, |
| 10357 | &ds_layout); |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 10358 | ASSERT_VK_SUCCESS(err); |
| 10359 | |
| 10360 | VkDescriptorSet descriptorSet; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 10361 | VkDescriptorSetAllocateInfo alloc_info = {}; |
Chia-I Wu | 00ce540 | 2015-11-10 16:21:09 +0800 | [diff] [blame] | 10362 | alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO; |
Jon Ashburn | f19916e | 2016-01-11 13:12:43 -0700 | [diff] [blame] | 10363 | alloc_info.descriptorSetCount = 1; |
Courtney Goeltzenleuchter | bee18a9 | 2015-10-23 14:21:05 -0600 | [diff] [blame] | 10364 | alloc_info.descriptorPool = ds_pool; |
| 10365 | alloc_info.pSetLayouts = &ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 10366 | err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, |
| 10367 | &descriptorSet); |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 10368 | ASSERT_VK_SUCCESS(err); |
| 10369 | |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 10370 | VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 10371 | pipe_ms_state_ci.sType = |
| 10372 | VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO; |
| 10373 | pipe_ms_state_ci.pNext = NULL; |
| 10374 | pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_4_BIT; |
| 10375 | pipe_ms_state_ci.sampleShadingEnable = 0; |
| 10376 | pipe_ms_state_ci.minSampleShading = 1.0; |
| 10377 | pipe_ms_state_ci.pSampleMask = NULL; |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 10378 | |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 10379 | VkPipelineLayoutCreateInfo pipeline_layout_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 10380 | pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO; |
| 10381 | pipeline_layout_ci.pNext = NULL; |
| 10382 | pipeline_layout_ci.setLayoutCount = 1; |
| 10383 | pipeline_layout_ci.pSetLayouts = &ds_layout; |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 10384 | |
| 10385 | VkPipelineLayout pipeline_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 10386 | err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, |
| 10387 | &pipeline_layout); |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 10388 | ASSERT_VK_SUCCESS(err); |
| 10389 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 10390 | VkShaderObj vs(m_device, bindStateVertShaderText, |
| 10391 | VK_SHADER_STAGE_VERTEX_BIT, this); |
| 10392 | VkShaderObj fs(m_device, bindStateFragShaderText, |
| 10393 | VK_SHADER_STAGE_FRAGMENT_BIT, |
Karl Schultz | bdb7595 | 2016-04-19 11:36:49 -0600 | [diff] [blame] | 10394 | this); // We shouldn't need a fragment shader |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 10395 | // but add it to be able to run on more devices |
Tony Barbour | 62e1a5b | 2015-08-06 10:16:07 -0600 | [diff] [blame] | 10396 | VkPipelineObj pipe(m_device); |
| 10397 | pipe.AddShader(&vs); |
Tony Barbour | 1c94d37 | 2015-08-06 11:21:08 -0600 | [diff] [blame] | 10398 | pipe.AddShader(&fs); |
Mark Young | c89c631 | 2016-03-31 16:03:20 -0600 | [diff] [blame] | 10399 | pipe.AddColorAttachment(); |
Tony Barbour | 62e1a5b | 2015-08-06 10:16:07 -0600 | [diff] [blame] | 10400 | pipe.SetMSAA(&pipe_ms_state_ci); |
| 10401 | pipe.CreateVKPipeline(pipeline_layout, renderPass()); |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 10402 | |
Tony Barbour | fe3351b | 2015-07-28 10:17:20 -0600 | [diff] [blame] | 10403 | BeginCommandBuffer(); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 10404 | vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), |
| 10405 | VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle()); |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 10406 | |
Mark Young | 2992748 | 2016-05-04 14:38:51 -0600 | [diff] [blame] | 10407 | // Render triangle (the error should trigger on the attempt to draw). |
| 10408 | Draw(3, 1, 0, 0); |
| 10409 | |
| 10410 | // Finalize recording of the command buffer |
| 10411 | EndCommandBuffer(); |
| 10412 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 10413 | m_errorMonitor->VerifyFound(); |
Mike Stroyan | d1c84a5 | 2015-08-18 14:40:24 -0600 | [diff] [blame] | 10414 | |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 10415 | vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL); |
| 10416 | vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL); |
| 10417 | vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL); |
Tobin Ehlis | 49eb23d | 2015-05-22 12:38:55 -0600 | [diff] [blame] | 10418 | } |
Mark Young | 2992748 | 2016-05-04 14:38:51 -0600 | [diff] [blame] | 10419 | |
Tobin Ehlis | 85aa15a | 2016-06-15 10:52:37 -0600 | [diff] [blame] | 10420 | TEST_F(VkLayerTest, RenderPassIncompatible) { |
| 10421 | TEST_DESCRIPTION("Hit RenderPass incompatible cases. " |
| 10422 | "Initial case is drawing with an active renderpass that's " |
| 10423 | "not compatible with the bound PSO's creation renderpass"); |
| 10424 | VkResult err; |
| 10425 | |
| 10426 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 10427 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 10428 | |
| 10429 | VkDescriptorSetLayoutBinding dsl_binding = {}; |
| 10430 | dsl_binding.binding = 0; |
| 10431 | dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 10432 | dsl_binding.descriptorCount = 1; |
| 10433 | dsl_binding.stageFlags = VK_SHADER_STAGE_ALL; |
| 10434 | dsl_binding.pImmutableSamplers = NULL; |
| 10435 | |
| 10436 | VkDescriptorSetLayoutCreateInfo ds_layout_ci = {}; |
| 10437 | ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO; |
| 10438 | ds_layout_ci.pNext = NULL; |
| 10439 | ds_layout_ci.bindingCount = 1; |
| 10440 | ds_layout_ci.pBindings = &dsl_binding; |
| 10441 | |
| 10442 | VkDescriptorSetLayout ds_layout; |
| 10443 | err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, |
| 10444 | &ds_layout); |
| 10445 | ASSERT_VK_SUCCESS(err); |
| 10446 | |
| 10447 | VkPipelineLayoutCreateInfo pipeline_layout_ci = {}; |
| 10448 | pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO; |
| 10449 | pipeline_layout_ci.pNext = NULL; |
| 10450 | pipeline_layout_ci.setLayoutCount = 1; |
| 10451 | pipeline_layout_ci.pSetLayouts = &ds_layout; |
| 10452 | |
| 10453 | VkPipelineLayout pipeline_layout; |
| 10454 | err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, |
| 10455 | &pipeline_layout); |
| 10456 | ASSERT_VK_SUCCESS(err); |
| 10457 | |
| 10458 | VkShaderObj vs(m_device, bindStateVertShaderText, |
| 10459 | VK_SHADER_STAGE_VERTEX_BIT, this); |
| 10460 | VkShaderObj fs(m_device, bindStateFragShaderText, |
| 10461 | VK_SHADER_STAGE_FRAGMENT_BIT, |
| 10462 | this); // We shouldn't need a fragment shader |
| 10463 | // but add it to be able to run on more devices |
| 10464 | // Create a renderpass that will be incompatible with default renderpass |
| 10465 | VkAttachmentReference attach = {}; |
| 10466 | attach.layout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL; |
| 10467 | VkAttachmentReference color_att = {}; |
| 10468 | color_att.layout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL; |
| 10469 | VkSubpassDescription subpass = {}; |
| 10470 | subpass.inputAttachmentCount = 1; |
| 10471 | subpass.pInputAttachments = &attach; |
| 10472 | subpass.colorAttachmentCount = 1; |
| 10473 | subpass.pColorAttachments = &color_att; |
| 10474 | VkRenderPassCreateInfo rpci = {}; |
| 10475 | rpci.subpassCount = 1; |
| 10476 | rpci.pSubpasses = &subpass; |
| 10477 | rpci.attachmentCount = 1; |
| 10478 | VkAttachmentDescription attach_desc = {}; |
| 10479 | attach_desc.samples = VK_SAMPLE_COUNT_1_BIT; |
Cody Northrop | bd16af1 | 2016-06-21 09:25:48 -0600 | [diff] [blame] | 10480 | // Format incompatible with PSO RP color attach format B8G8R8A8_UNORM |
| 10481 | attach_desc.format = VK_FORMAT_R8G8B8A8_UNORM; |
Tobin Ehlis | 85aa15a | 2016-06-15 10:52:37 -0600 | [diff] [blame] | 10482 | rpci.pAttachments = &attach_desc; |
| 10483 | rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO; |
| 10484 | VkRenderPass rp; |
| 10485 | vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp); |
| 10486 | VkPipelineObj pipe(m_device); |
| 10487 | pipe.AddShader(&vs); |
| 10488 | pipe.AddShader(&fs); |
| 10489 | pipe.AddColorAttachment(); |
| 10490 | VkViewport view_port = {}; |
| 10491 | m_viewports.push_back(view_port); |
| 10492 | pipe.SetViewport(m_viewports); |
| 10493 | VkRect2D rect = {}; |
| 10494 | m_scissors.push_back(rect); |
| 10495 | pipe.SetScissor(m_scissors); |
| 10496 | pipe.CreateVKPipeline(pipeline_layout, renderPass()); |
| 10497 | |
| 10498 | VkCommandBufferInheritanceInfo cbii = {}; |
| 10499 | cbii.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO; |
| 10500 | cbii.renderPass = rp; |
| 10501 | cbii.subpass = 0; |
| 10502 | VkCommandBufferBeginInfo cbbi = {}; |
| 10503 | cbbi.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO; |
| 10504 | cbbi.pInheritanceInfo = &cbii; |
| 10505 | vkBeginCommandBuffer(m_commandBuffer->handle(), &cbbi); |
| 10506 | VkRenderPassBeginInfo rpbi = {}; |
| 10507 | rpbi.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO; |
| 10508 | rpbi.framebuffer = m_framebuffer; |
| 10509 | rpbi.renderPass = rp; |
| 10510 | vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &rpbi, |
| 10511 | VK_SUBPASS_CONTENTS_INLINE); |
| 10512 | vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), |
| 10513 | VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle()); |
| 10514 | |
| 10515 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 10516 | " is incompatible w/ gfx pipeline "); |
| 10517 | // Render triangle (the error should trigger on the attempt to draw). |
| 10518 | Draw(3, 1, 0, 0); |
| 10519 | |
| 10520 | // Finalize recording of the command buffer |
| 10521 | EndCommandBuffer(); |
| 10522 | |
| 10523 | m_errorMonitor->VerifyFound(); |
| 10524 | |
| 10525 | vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL); |
| 10526 | vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL); |
| 10527 | vkDestroyRenderPass(m_device->device(), rp, NULL); |
| 10528 | } |
| 10529 | |
Mark Young | c89c631 | 2016-03-31 16:03:20 -0600 | [diff] [blame] | 10530 | TEST_F(VkLayerTest, NumBlendAttachMismatch) { |
| 10531 | // Create Pipeline where the number of blend attachments doesn't match the |
| 10532 | // number of color attachments. In this case, we don't add any color |
| 10533 | // blend attachments even though we have a color attachment. |
| 10534 | VkResult err; |
| 10535 | |
| 10536 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Mark Young | 2992748 | 2016-05-04 14:38:51 -0600 | [diff] [blame] | 10537 | "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] | 10538 | |
| 10539 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 10540 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 10541 | VkDescriptorPoolSize ds_type_count = {}; |
| 10542 | ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 10543 | ds_type_count.descriptorCount = 1; |
| 10544 | |
| 10545 | VkDescriptorPoolCreateInfo ds_pool_ci = {}; |
| 10546 | ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO; |
| 10547 | ds_pool_ci.pNext = NULL; |
| 10548 | ds_pool_ci.maxSets = 1; |
| 10549 | ds_pool_ci.poolSizeCount = 1; |
| 10550 | ds_pool_ci.pPoolSizes = &ds_type_count; |
| 10551 | |
| 10552 | VkDescriptorPool ds_pool; |
| 10553 | err = |
| 10554 | vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool); |
| 10555 | ASSERT_VK_SUCCESS(err); |
| 10556 | |
| 10557 | VkDescriptorSetLayoutBinding dsl_binding = {}; |
| 10558 | dsl_binding.binding = 0; |
| 10559 | dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 10560 | dsl_binding.descriptorCount = 1; |
| 10561 | dsl_binding.stageFlags = VK_SHADER_STAGE_ALL; |
| 10562 | dsl_binding.pImmutableSamplers = NULL; |
| 10563 | |
| 10564 | VkDescriptorSetLayoutCreateInfo ds_layout_ci = {}; |
| 10565 | ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO; |
| 10566 | ds_layout_ci.pNext = NULL; |
| 10567 | ds_layout_ci.bindingCount = 1; |
| 10568 | ds_layout_ci.pBindings = &dsl_binding; |
| 10569 | |
| 10570 | VkDescriptorSetLayout ds_layout; |
| 10571 | err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, |
| 10572 | &ds_layout); |
| 10573 | ASSERT_VK_SUCCESS(err); |
| 10574 | |
| 10575 | VkDescriptorSet descriptorSet; |
| 10576 | VkDescriptorSetAllocateInfo alloc_info = {}; |
| 10577 | alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO; |
| 10578 | alloc_info.descriptorSetCount = 1; |
| 10579 | alloc_info.descriptorPool = ds_pool; |
| 10580 | alloc_info.pSetLayouts = &ds_layout; |
| 10581 | err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, |
| 10582 | &descriptorSet); |
| 10583 | ASSERT_VK_SUCCESS(err); |
| 10584 | |
| 10585 | VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {}; |
| 10586 | pipe_ms_state_ci.sType = |
| 10587 | VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO; |
| 10588 | pipe_ms_state_ci.pNext = NULL; |
| 10589 | pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT; |
| 10590 | pipe_ms_state_ci.sampleShadingEnable = 0; |
| 10591 | pipe_ms_state_ci.minSampleShading = 1.0; |
| 10592 | pipe_ms_state_ci.pSampleMask = NULL; |
| 10593 | |
| 10594 | VkPipelineLayoutCreateInfo pipeline_layout_ci = {}; |
| 10595 | pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO; |
| 10596 | pipeline_layout_ci.pNext = NULL; |
| 10597 | pipeline_layout_ci.setLayoutCount = 1; |
| 10598 | pipeline_layout_ci.pSetLayouts = &ds_layout; |
| 10599 | |
| 10600 | VkPipelineLayout pipeline_layout; |
| 10601 | err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, |
| 10602 | &pipeline_layout); |
| 10603 | ASSERT_VK_SUCCESS(err); |
| 10604 | |
| 10605 | VkShaderObj vs(m_device, bindStateVertShaderText, |
| 10606 | VK_SHADER_STAGE_VERTEX_BIT, this); |
| 10607 | VkShaderObj fs(m_device, bindStateFragShaderText, |
| 10608 | VK_SHADER_STAGE_FRAGMENT_BIT, |
Karl Schultz | bdb7595 | 2016-04-19 11:36:49 -0600 | [diff] [blame] | 10609 | this); // We shouldn't need a fragment shader |
Mark Young | c89c631 | 2016-03-31 16:03:20 -0600 | [diff] [blame] | 10610 | // but add it to be able to run on more devices |
| 10611 | VkPipelineObj pipe(m_device); |
| 10612 | pipe.AddShader(&vs); |
| 10613 | pipe.AddShader(&fs); |
| 10614 | pipe.SetMSAA(&pipe_ms_state_ci); |
| 10615 | pipe.CreateVKPipeline(pipeline_layout, renderPass()); |
| 10616 | |
| 10617 | BeginCommandBuffer(); |
| 10618 | vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), |
| 10619 | VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle()); |
| 10620 | |
Mark Young | 2992748 | 2016-05-04 14:38:51 -0600 | [diff] [blame] | 10621 | // Render triangle (the error should trigger on the attempt to draw). |
| 10622 | Draw(3, 1, 0, 0); |
| 10623 | |
| 10624 | // Finalize recording of the command buffer |
| 10625 | EndCommandBuffer(); |
| 10626 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 10627 | m_errorMonitor->VerifyFound(); |
Mark Young | c89c631 | 2016-03-31 16:03:20 -0600 | [diff] [blame] | 10628 | |
| 10629 | vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL); |
| 10630 | vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL); |
| 10631 | vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL); |
| 10632 | } |
Mark Young | 2992748 | 2016-05-04 14:38:51 -0600 | [diff] [blame] | 10633 | |
Mark Mueller | d491441 | 2016-06-13 17:52:06 -0600 | [diff] [blame] | 10634 | TEST_F(VkLayerTest, MissingClearAttachment) { |
| 10635 | TEST_DESCRIPTION("Points to a wrong colorAttachment index in a VkClearAttachment " |
| 10636 | "structure passed to vkCmdClearAttachments"); |
| 10637 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 10638 | "vkCmdClearAttachments() attachment index 1 not found in attachment " |
| 10639 | "reference array of active subpass 0"); |
| 10640 | |
| 10641 | VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailCmdClearAttachments); |
| 10642 | m_errorMonitor->VerifyFound(); |
| 10643 | } |
| 10644 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 10645 | TEST_F(VkLayerTest, ClearCmdNoDraw) { |
| 10646 | // Create CommandBuffer where we add ClearCmd for FB Color attachment prior |
| 10647 | // to issuing a Draw |
| 10648 | VkResult err; |
Tobin Ehlis | 53eddda | 2015-07-01 16:46:13 -0600 | [diff] [blame] | 10649 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 10650 | m_errorMonitor->SetDesiredFailureMsg( |
Tony Barbour | 7e56d30 | 2016-03-02 15:12:01 -0700 | [diff] [blame] | 10651 | VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 10652 | "vkCmdClearAttachments() issued on CB object "); |
| 10653 | |
Tobin Ehlis | 53eddda | 2015-07-01 16:46:13 -0600 | [diff] [blame] | 10654 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 10655 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 10656 | |
Chia-I Wu | 1b99bb2 | 2015-10-27 19:25:11 +0800 | [diff] [blame] | 10657 | VkDescriptorPoolSize ds_type_count = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 10658 | ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 10659 | ds_type_count.descriptorCount = 1; |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 10660 | |
| 10661 | VkDescriptorPoolCreateInfo ds_pool_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 10662 | ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO; |
| 10663 | ds_pool_ci.pNext = NULL; |
| 10664 | ds_pool_ci.maxSets = 1; |
| 10665 | ds_pool_ci.poolSizeCount = 1; |
| 10666 | ds_pool_ci.pPoolSizes = &ds_type_count; |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 10667 | |
Tobin Ehlis | 53eddda | 2015-07-01 16:46:13 -0600 | [diff] [blame] | 10668 | VkDescriptorPool ds_pool; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 10669 | err = |
| 10670 | vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool); |
Tobin Ehlis | 53eddda | 2015-07-01 16:46:13 -0600 | [diff] [blame] | 10671 | ASSERT_VK_SUCCESS(err); |
| 10672 | |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 10673 | VkDescriptorSetLayoutBinding dsl_binding = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 10674 | dsl_binding.binding = 0; |
| 10675 | dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 10676 | dsl_binding.descriptorCount = 1; |
| 10677 | dsl_binding.stageFlags = VK_SHADER_STAGE_ALL; |
| 10678 | dsl_binding.pImmutableSamplers = NULL; |
Tobin Ehlis | 53eddda | 2015-07-01 16:46:13 -0600 | [diff] [blame] | 10679 | |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 10680 | VkDescriptorSetLayoutCreateInfo ds_layout_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 10681 | ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO; |
| 10682 | ds_layout_ci.pNext = NULL; |
| 10683 | ds_layout_ci.bindingCount = 1; |
| 10684 | ds_layout_ci.pBindings = &dsl_binding; |
Mark Lobodzinski | 209b529 | 2015-09-17 09:44:05 -0600 | [diff] [blame] | 10685 | |
Tobin Ehlis | 53eddda | 2015-07-01 16:46:13 -0600 | [diff] [blame] | 10686 | VkDescriptorSetLayout ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 10687 | err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, |
| 10688 | &ds_layout); |
Tobin Ehlis | 53eddda | 2015-07-01 16:46:13 -0600 | [diff] [blame] | 10689 | ASSERT_VK_SUCCESS(err); |
| 10690 | |
| 10691 | VkDescriptorSet descriptorSet; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 10692 | VkDescriptorSetAllocateInfo alloc_info = {}; |
Chia-I Wu | 00ce540 | 2015-11-10 16:21:09 +0800 | [diff] [blame] | 10693 | alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO; |
Jon Ashburn | f19916e | 2016-01-11 13:12:43 -0700 | [diff] [blame] | 10694 | alloc_info.descriptorSetCount = 1; |
Courtney Goeltzenleuchter | bee18a9 | 2015-10-23 14:21:05 -0600 | [diff] [blame] | 10695 | alloc_info.descriptorPool = ds_pool; |
| 10696 | alloc_info.pSetLayouts = &ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 10697 | err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, |
| 10698 | &descriptorSet); |
Tobin Ehlis | 53eddda | 2015-07-01 16:46:13 -0600 | [diff] [blame] | 10699 | ASSERT_VK_SUCCESS(err); |
| 10700 | |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 10701 | VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 10702 | pipe_ms_state_ci.sType = |
| 10703 | VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO; |
| 10704 | pipe_ms_state_ci.pNext = NULL; |
| 10705 | pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_4_BIT; |
| 10706 | pipe_ms_state_ci.sampleShadingEnable = 0; |
| 10707 | pipe_ms_state_ci.minSampleShading = 1.0; |
| 10708 | pipe_ms_state_ci.pSampleMask = NULL; |
Tobin Ehlis | 53eddda | 2015-07-01 16:46:13 -0600 | [diff] [blame] | 10709 | |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 10710 | VkPipelineLayoutCreateInfo pipeline_layout_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 10711 | pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO; |
| 10712 | pipeline_layout_ci.pNext = NULL; |
| 10713 | pipeline_layout_ci.setLayoutCount = 1; |
| 10714 | pipeline_layout_ci.pSetLayouts = &ds_layout; |
Tobin Ehlis | 53eddda | 2015-07-01 16:46:13 -0600 | [diff] [blame] | 10715 | |
| 10716 | VkPipelineLayout pipeline_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 10717 | err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, |
| 10718 | &pipeline_layout); |
Tobin Ehlis | 53eddda | 2015-07-01 16:46:13 -0600 | [diff] [blame] | 10719 | ASSERT_VK_SUCCESS(err); |
Mark Lobodzinski | 209b529 | 2015-09-17 09:44:05 -0600 | [diff] [blame] | 10720 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 10721 | VkShaderObj vs(m_device, bindStateVertShaderText, |
| 10722 | VK_SHADER_STAGE_VERTEX_BIT, this); |
Karl Schultz | bdb7595 | 2016-04-19 11:36:49 -0600 | [diff] [blame] | 10723 | // 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] | 10724 | // on more devices |
| 10725 | VkShaderObj fs(m_device, bindStateFragShaderText, |
| 10726 | VK_SHADER_STAGE_FRAGMENT_BIT, this); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 10727 | |
Tony Barbour | 62e1a5b | 2015-08-06 10:16:07 -0600 | [diff] [blame] | 10728 | VkPipelineObj pipe(m_device); |
| 10729 | pipe.AddShader(&vs); |
Tony Barbour | 1c94d37 | 2015-08-06 11:21:08 -0600 | [diff] [blame] | 10730 | pipe.AddShader(&fs); |
Tony Barbour | 62e1a5b | 2015-08-06 10:16:07 -0600 | [diff] [blame] | 10731 | pipe.SetMSAA(&pipe_ms_state_ci); |
| 10732 | pipe.CreateVKPipeline(pipeline_layout, renderPass()); |
Tony Barbour | fe3351b | 2015-07-28 10:17:20 -0600 | [diff] [blame] | 10733 | |
| 10734 | BeginCommandBuffer(); |
Tobin Ehlis | 53eddda | 2015-07-01 16:46:13 -0600 | [diff] [blame] | 10735 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 10736 | // Main thing we care about for this test is that the VkImage obj we're |
| 10737 | // clearing matches Color Attachment of FB |
Tobin Ehlis | 53eddda | 2015-07-01 16:46:13 -0600 | [diff] [blame] | 10738 | // Also pass down other dummy params to keep driver and paramchecker happy |
Courtney Goeltzenleuchter | c9323e0 | 2015-10-15 16:51:05 -0600 | [diff] [blame] | 10739 | VkClearAttachment color_attachment; |
| 10740 | color_attachment.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; |
| 10741 | color_attachment.clearValue.color.float32[0] = 1.0; |
| 10742 | color_attachment.clearValue.color.float32[1] = 1.0; |
| 10743 | color_attachment.clearValue.color.float32[2] = 1.0; |
| 10744 | color_attachment.clearValue.color.float32[3] = 1.0; |
| 10745 | color_attachment.colorAttachment = 0; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 10746 | VkClearRect clear_rect = { |
| 10747 | {{0, 0}, {(uint32_t)m_width, (uint32_t)m_height}}}; |
Tobin Ehlis | 53eddda | 2015-07-01 16:46:13 -0600 | [diff] [blame] | 10748 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 10749 | vkCmdClearAttachments(m_commandBuffer->GetBufferHandle(), 1, |
| 10750 | &color_attachment, 1, &clear_rect); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 10751 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 10752 | m_errorMonitor->VerifyFound(); |
Mike Stroyan | d1c84a5 | 2015-08-18 14:40:24 -0600 | [diff] [blame] | 10753 | |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 10754 | vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL); |
| 10755 | vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL); |
| 10756 | vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL); |
Tobin Ehlis | 53eddda | 2015-07-01 16:46:13 -0600 | [diff] [blame] | 10757 | } |
| 10758 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 10759 | TEST_F(VkLayerTest, VtxBufferBadIndex) { |
| 10760 | VkResult err; |
Tobin Ehlis | 502480b | 2015-06-24 15:53:07 -0600 | [diff] [blame] | 10761 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 10762 | m_errorMonitor->SetDesiredFailureMsg( |
Mark Lobodzinski | 510e20d | 2016-02-11 09:26:16 -0700 | [diff] [blame] | 10763 | VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, |
Mark Lobodzinski | dfcd9b6 | 2015-12-14 15:14:10 -0700 | [diff] [blame] | 10764 | "but no vertex buffers are attached to this Pipeline State Object"); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 10765 | |
Tobin Ehlis | 502480b | 2015-06-24 15:53:07 -0600 | [diff] [blame] | 10766 | ASSERT_NO_FATAL_FAILURE(InitState()); |
Tobin Ehlis | d332f28 | 2015-10-02 11:00:56 -0600 | [diff] [blame] | 10767 | ASSERT_NO_FATAL_FAILURE(InitViewport()); |
Tobin Ehlis | 502480b | 2015-06-24 15:53:07 -0600 | [diff] [blame] | 10768 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 10769 | |
Chia-I Wu | 1b99bb2 | 2015-10-27 19:25:11 +0800 | [diff] [blame] | 10770 | VkDescriptorPoolSize ds_type_count = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 10771 | ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 10772 | ds_type_count.descriptorCount = 1; |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 10773 | |
| 10774 | VkDescriptorPoolCreateInfo ds_pool_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 10775 | ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO; |
| 10776 | ds_pool_ci.pNext = NULL; |
| 10777 | ds_pool_ci.maxSets = 1; |
| 10778 | ds_pool_ci.poolSizeCount = 1; |
| 10779 | ds_pool_ci.pPoolSizes = &ds_type_count; |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 10780 | |
Courtney Goeltzenleuchter | fe908d3 | 2015-09-16 16:12:45 -0600 | [diff] [blame] | 10781 | VkDescriptorPool ds_pool; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 10782 | err = |
| 10783 | vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool); |
Tobin Ehlis | 502480b | 2015-06-24 15:53:07 -0600 | [diff] [blame] | 10784 | ASSERT_VK_SUCCESS(err); |
| 10785 | |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 10786 | VkDescriptorSetLayoutBinding dsl_binding = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 10787 | dsl_binding.binding = 0; |
| 10788 | dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 10789 | dsl_binding.descriptorCount = 1; |
| 10790 | dsl_binding.stageFlags = VK_SHADER_STAGE_ALL; |
| 10791 | dsl_binding.pImmutableSamplers = NULL; |
Tobin Ehlis | 502480b | 2015-06-24 15:53:07 -0600 | [diff] [blame] | 10792 | |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 10793 | VkDescriptorSetLayoutCreateInfo ds_layout_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 10794 | ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO; |
| 10795 | ds_layout_ci.pNext = NULL; |
| 10796 | ds_layout_ci.bindingCount = 1; |
| 10797 | ds_layout_ci.pBindings = &dsl_binding; |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 10798 | |
Tobin Ehlis | 502480b | 2015-06-24 15:53:07 -0600 | [diff] [blame] | 10799 | VkDescriptorSetLayout ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 10800 | err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, |
| 10801 | &ds_layout); |
Tobin Ehlis | 502480b | 2015-06-24 15:53:07 -0600 | [diff] [blame] | 10802 | ASSERT_VK_SUCCESS(err); |
| 10803 | |
| 10804 | VkDescriptorSet descriptorSet; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 10805 | VkDescriptorSetAllocateInfo alloc_info = {}; |
Chia-I Wu | 00ce540 | 2015-11-10 16:21:09 +0800 | [diff] [blame] | 10806 | alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO; |
Jon Ashburn | f19916e | 2016-01-11 13:12:43 -0700 | [diff] [blame] | 10807 | alloc_info.descriptorSetCount = 1; |
Courtney Goeltzenleuchter | bee18a9 | 2015-10-23 14:21:05 -0600 | [diff] [blame] | 10808 | alloc_info.descriptorPool = ds_pool; |
| 10809 | alloc_info.pSetLayouts = &ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 10810 | err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, |
| 10811 | &descriptorSet); |
Tobin Ehlis | 502480b | 2015-06-24 15:53:07 -0600 | [diff] [blame] | 10812 | ASSERT_VK_SUCCESS(err); |
| 10813 | |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 10814 | VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 10815 | pipe_ms_state_ci.sType = |
| 10816 | VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO; |
| 10817 | pipe_ms_state_ci.pNext = NULL; |
| 10818 | pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT; |
| 10819 | pipe_ms_state_ci.sampleShadingEnable = 0; |
| 10820 | pipe_ms_state_ci.minSampleShading = 1.0; |
| 10821 | pipe_ms_state_ci.pSampleMask = NULL; |
Tobin Ehlis | 502480b | 2015-06-24 15:53:07 -0600 | [diff] [blame] | 10822 | |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 10823 | VkPipelineLayoutCreateInfo pipeline_layout_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 10824 | pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO; |
| 10825 | pipeline_layout_ci.pNext = NULL; |
| 10826 | pipeline_layout_ci.setLayoutCount = 1; |
| 10827 | pipeline_layout_ci.pSetLayouts = &ds_layout; |
| 10828 | VkPipelineLayout pipeline_layout; |
Tobin Ehlis | 502480b | 2015-06-24 15:53:07 -0600 | [diff] [blame] | 10829 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 10830 | err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, |
| 10831 | &pipeline_layout); |
Tobin Ehlis | 502480b | 2015-06-24 15:53:07 -0600 | [diff] [blame] | 10832 | ASSERT_VK_SUCCESS(err); |
| 10833 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 10834 | VkShaderObj vs(m_device, bindStateVertShaderText, |
| 10835 | VK_SHADER_STAGE_VERTEX_BIT, this); |
| 10836 | VkShaderObj fs(m_device, bindStateFragShaderText, |
| 10837 | VK_SHADER_STAGE_FRAGMENT_BIT, |
Karl Schultz | bdb7595 | 2016-04-19 11:36:49 -0600 | [diff] [blame] | 10838 | this); // We shouldn't need a fragment shader |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 10839 | // but add it to be able to run on more devices |
Tony Barbour | 62e1a5b | 2015-08-06 10:16:07 -0600 | [diff] [blame] | 10840 | VkPipelineObj pipe(m_device); |
| 10841 | pipe.AddShader(&vs); |
Tony Barbour | 1c94d37 | 2015-08-06 11:21:08 -0600 | [diff] [blame] | 10842 | pipe.AddShader(&fs); |
Mark Young | c89c631 | 2016-03-31 16:03:20 -0600 | [diff] [blame] | 10843 | pipe.AddColorAttachment(); |
Tony Barbour | 62e1a5b | 2015-08-06 10:16:07 -0600 | [diff] [blame] | 10844 | pipe.SetMSAA(&pipe_ms_state_ci); |
Tobin Ehlis | d332f28 | 2015-10-02 11:00:56 -0600 | [diff] [blame] | 10845 | pipe.SetViewport(m_viewports); |
| 10846 | pipe.SetScissor(m_scissors); |
Tony Barbour | 62e1a5b | 2015-08-06 10:16:07 -0600 | [diff] [blame] | 10847 | pipe.CreateVKPipeline(pipeline_layout, renderPass()); |
Tony Barbour | fe3351b | 2015-07-28 10:17:20 -0600 | [diff] [blame] | 10848 | |
| 10849 | BeginCommandBuffer(); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 10850 | vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), |
| 10851 | VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle()); |
Tobin Ehlis | f7bf450 | 2015-09-09 15:12:35 -0600 | [diff] [blame] | 10852 | // Don't care about actual data, just need to get to draw to flag error |
| 10853 | static const float vbo_data[3] = {1.f, 0.f, 1.f}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 10854 | VkConstantBufferObj vbo(m_device, sizeof(vbo_data), sizeof(float), |
| 10855 | (const void *)&vbo_data); |
Tobin Ehlis | f7bf450 | 2015-09-09 15:12:35 -0600 | [diff] [blame] | 10856 | 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] | 10857 | Draw(1, 0, 0, 0); |
Tobin Ehlis | 502480b | 2015-06-24 15:53:07 -0600 | [diff] [blame] | 10858 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 10859 | m_errorMonitor->VerifyFound(); |
Mike Stroyan | d1c84a5 | 2015-08-18 14:40:24 -0600 | [diff] [blame] | 10860 | |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 10861 | vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL); |
| 10862 | vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL); |
| 10863 | vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL); |
Tobin Ehlis | 502480b | 2015-06-24 15:53:07 -0600 | [diff] [blame] | 10864 | } |
Tobin Ehlis | c555a3c | 2016-05-04 14:08:34 -0600 | [diff] [blame] | 10865 | // INVALID_IMAGE_LAYOUT tests (one other case is hit by MapMemWithoutHostVisibleBit and not here) |
| 10866 | TEST_F(VkLayerTest, InvalidImageLayout) { |
| 10867 | TEST_DESCRIPTION("Hit all possible validation checks associated with the " |
| 10868 | "DRAWSTATE_INVALID_IMAGE_LAYOUT enum. Generally these involve having" |
| 10869 | "images in the wrong layout when they're copied or transitioned."); |
| 10870 | // 3 in ValidateCmdBufImageLayouts |
| 10871 | // * -1 Attempt to submit cmd buf w/ deleted image |
| 10872 | // * -2 Cmd buf submit of image w/ layout not matching first use w/ subresource |
| 10873 | // * -3 Cmd buf submit of image w/ layout not matching first use w/o subresource |
| 10874 | m_errorMonitor->SetDesiredFailureMsg( |
| 10875 | VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, |
| 10876 | "Layout for input image should be TRANSFER_SRC_OPTIMAL instead of GENERAL."); |
| 10877 | |
| 10878 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 10879 | // Create src & dst images to use for copy operations |
| 10880 | VkImage src_image; |
| 10881 | VkImage dst_image; |
| 10882 | |
| 10883 | const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM; |
| 10884 | const int32_t tex_width = 32; |
| 10885 | const int32_t tex_height = 32; |
| 10886 | |
| 10887 | VkImageCreateInfo image_create_info = {}; |
| 10888 | image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO; |
| 10889 | image_create_info.pNext = NULL; |
| 10890 | image_create_info.imageType = VK_IMAGE_TYPE_2D; |
| 10891 | image_create_info.format = tex_format; |
| 10892 | image_create_info.extent.width = tex_width; |
| 10893 | image_create_info.extent.height = tex_height; |
| 10894 | image_create_info.extent.depth = 1; |
| 10895 | image_create_info.mipLevels = 1; |
| 10896 | image_create_info.arrayLayers = 4; |
| 10897 | image_create_info.samples = VK_SAMPLE_COUNT_1_BIT; |
| 10898 | image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL; |
| 10899 | image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT; |
| 10900 | image_create_info.flags = 0; |
| 10901 | |
| 10902 | VkResult err = vkCreateImage(m_device->device(), &image_create_info, NULL, &src_image); |
| 10903 | ASSERT_VK_SUCCESS(err); |
| 10904 | err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dst_image); |
| 10905 | ASSERT_VK_SUCCESS(err); |
| 10906 | |
| 10907 | BeginCommandBuffer(); |
| 10908 | VkImageCopy copyRegion; |
| 10909 | copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; |
| 10910 | copyRegion.srcSubresource.mipLevel = 0; |
| 10911 | copyRegion.srcSubresource.baseArrayLayer = 0; |
| 10912 | copyRegion.srcSubresource.layerCount = 1; |
| 10913 | copyRegion.srcOffset.x = 0; |
| 10914 | copyRegion.srcOffset.y = 0; |
| 10915 | copyRegion.srcOffset.z = 0; |
| 10916 | copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; |
| 10917 | copyRegion.dstSubresource.mipLevel = 0; |
| 10918 | copyRegion.dstSubresource.baseArrayLayer = 0; |
| 10919 | copyRegion.dstSubresource.layerCount = 1; |
| 10920 | copyRegion.dstOffset.x = 0; |
| 10921 | copyRegion.dstOffset.y = 0; |
| 10922 | copyRegion.dstOffset.z = 0; |
| 10923 | copyRegion.extent.width = 1; |
| 10924 | copyRegion.extent.height = 1; |
| 10925 | copyRegion.extent.depth = 1; |
| 10926 | m_commandBuffer->CopyImage(src_image, VK_IMAGE_LAYOUT_GENERAL, dst_image, VK_IMAGE_LAYOUT_GENERAL, 1, ©Region); |
| 10927 | m_errorMonitor->VerifyFound(); |
| 10928 | // Now cause error due to src image layout changing |
| 10929 | m_errorMonitor->SetDesiredFailureMsg( |
| 10930 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 10931 | "Cannot copy from an image whose source layout is VK_IMAGE_LAYOUT_UNDEFINED and doesn't match the current layout VK_IMAGE_LAYOUT_GENERAL."); |
| 10932 | m_commandBuffer->CopyImage(src_image, VK_IMAGE_LAYOUT_UNDEFINED, dst_image, VK_IMAGE_LAYOUT_GENERAL, 1, ©Region); |
| 10933 | m_errorMonitor->VerifyFound(); |
| 10934 | // Final src error is due to bad layout type |
| 10935 | m_errorMonitor->SetDesiredFailureMsg( |
| 10936 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 10937 | "Layout for input image is VK_IMAGE_LAYOUT_UNDEFINED but can only be TRANSFER_SRC_OPTIMAL or GENERAL."); |
| 10938 | m_commandBuffer->CopyImage(src_image, VK_IMAGE_LAYOUT_UNDEFINED, dst_image, VK_IMAGE_LAYOUT_GENERAL, 1, ©Region); |
| 10939 | m_errorMonitor->VerifyFound(); |
| 10940 | // Now verify same checks for dst |
| 10941 | m_errorMonitor->SetDesiredFailureMsg( |
| 10942 | VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, |
| 10943 | "Layout for output image should be TRANSFER_DST_OPTIMAL instead of GENERAL."); |
| 10944 | m_commandBuffer->CopyImage(src_image, VK_IMAGE_LAYOUT_GENERAL, dst_image, VK_IMAGE_LAYOUT_GENERAL, 1, ©Region); |
| 10945 | m_errorMonitor->VerifyFound(); |
| 10946 | // Now cause error due to src image layout changing |
| 10947 | m_errorMonitor->SetDesiredFailureMsg( |
| 10948 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 10949 | "Cannot copy from an image whose dest layout is VK_IMAGE_LAYOUT_UNDEFINED and doesn't match the current layout VK_IMAGE_LAYOUT_GENERAL."); |
| 10950 | m_commandBuffer->CopyImage(src_image, VK_IMAGE_LAYOUT_GENERAL, dst_image, VK_IMAGE_LAYOUT_UNDEFINED, 1, ©Region); |
| 10951 | m_errorMonitor->VerifyFound(); |
| 10952 | m_errorMonitor->SetDesiredFailureMsg( |
| 10953 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 10954 | "Layout for output image is VK_IMAGE_LAYOUT_UNDEFINED but can only be TRANSFER_DST_OPTIMAL or GENERAL."); |
| 10955 | m_commandBuffer->CopyImage(src_image, VK_IMAGE_LAYOUT_GENERAL, dst_image, VK_IMAGE_LAYOUT_UNDEFINED, 1, ©Region); |
| 10956 | m_errorMonitor->VerifyFound(); |
| 10957 | // Now cause error due to bad image layout transition in PipelineBarrier |
| 10958 | VkImageMemoryBarrier image_barrier[1] = {}; |
| 10959 | image_barrier[0].oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL; |
| 10960 | image_barrier[0].image = src_image; |
| 10961 | image_barrier[0].subresourceRange.layerCount = 2; |
| 10962 | image_barrier[0].subresourceRange.levelCount = 2; |
| 10963 | image_barrier[0].subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; |
| 10964 | m_errorMonitor->SetDesiredFailureMsg( |
| 10965 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 10966 | "You cannot transition the layout from VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL when current layout is VK_IMAGE_LAYOUT_GENERAL."); |
| 10967 | vkCmdPipelineBarrier(m_commandBuffer->handle(), VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, NULL, 0, NULL, 1, image_barrier); |
| 10968 | m_errorMonitor->VerifyFound(); |
| 10969 | |
| 10970 | // Finally some layout errors at RenderPass create time |
| 10971 | // Just hacking in specific state to get to the errors we want so don't copy this unless you know what you're doing. |
| 10972 | VkAttachmentReference attach = {}; |
| 10973 | // perf warning for GENERAL layout w/ non-DS input attachment |
| 10974 | attach.layout = VK_IMAGE_LAYOUT_GENERAL; |
| 10975 | VkSubpassDescription subpass = {}; |
| 10976 | subpass.inputAttachmentCount = 1; |
| 10977 | subpass.pInputAttachments = &attach; |
| 10978 | VkRenderPassCreateInfo rpci = {}; |
| 10979 | rpci.subpassCount = 1; |
| 10980 | rpci.pSubpasses = &subpass; |
| 10981 | rpci.attachmentCount = 1; |
| 10982 | VkAttachmentDescription attach_desc = {}; |
| 10983 | attach_desc.format = VK_FORMAT_UNDEFINED; |
| 10984 | rpci.pAttachments = &attach_desc; |
Tobin Ehlis | 1efce02 | 2016-05-11 10:40:34 -0600 | [diff] [blame] | 10985 | rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO; |
Tobin Ehlis | c555a3c | 2016-05-04 14:08:34 -0600 | [diff] [blame] | 10986 | VkRenderPass rp; |
| 10987 | m_errorMonitor->SetDesiredFailureMsg( |
| 10988 | VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, |
| 10989 | "Layout for input attachment is GENERAL but should be READ_ONLY_OPTIMAL."); |
| 10990 | vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp); |
| 10991 | m_errorMonitor->VerifyFound(); |
| 10992 | // error w/ non-general layout |
| 10993 | attach.layout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL; |
| 10994 | |
| 10995 | m_errorMonitor->SetDesiredFailureMsg( |
| 10996 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 10997 | "Layout for input attachment is VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL but can only be READ_ONLY_OPTIMAL or GENERAL."); |
| 10998 | vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp); |
| 10999 | m_errorMonitor->VerifyFound(); |
| 11000 | subpass.inputAttachmentCount = 0; |
| 11001 | subpass.colorAttachmentCount = 1; |
| 11002 | subpass.pColorAttachments = &attach; |
| 11003 | attach.layout = VK_IMAGE_LAYOUT_GENERAL; |
| 11004 | // perf warning for GENERAL layout on color attachment |
| 11005 | m_errorMonitor->SetDesiredFailureMsg( |
| 11006 | VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, |
| 11007 | "Layout for color attachment is GENERAL but should be COLOR_ATTACHMENT_OPTIMAL."); |
| 11008 | vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp); |
| 11009 | m_errorMonitor->VerifyFound(); |
| 11010 | // error w/ non-color opt or GENERAL layout for color attachment |
| 11011 | attach.layout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL; |
| 11012 | m_errorMonitor->SetDesiredFailureMsg( |
| 11013 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 11014 | "Layout for color attachment is VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL but can only be COLOR_ATTACHMENT_OPTIMAL or GENERAL."); |
| 11015 | vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp); |
| 11016 | m_errorMonitor->VerifyFound(); |
| 11017 | subpass.colorAttachmentCount = 0; |
| 11018 | subpass.pDepthStencilAttachment = &attach; |
| 11019 | attach.layout = VK_IMAGE_LAYOUT_GENERAL; |
| 11020 | // perf warning for GENERAL layout on DS attachment |
| 11021 | m_errorMonitor->SetDesiredFailureMsg( |
| 11022 | VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, |
| 11023 | "Layout for depth attachment is GENERAL but should be DEPTH_STENCIL_ATTACHMENT_OPTIMAL."); |
| 11024 | vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp); |
| 11025 | m_errorMonitor->VerifyFound(); |
| 11026 | // error w/ non-ds opt or GENERAL layout for color attachment |
| 11027 | attach.layout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL; |
| 11028 | m_errorMonitor->SetDesiredFailureMsg( |
| 11029 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 11030 | "Layout for depth attachment is VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL but can only be DEPTH_STENCIL_ATTACHMENT_OPTIMAL or GENERAL."); |
| 11031 | vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp); |
| 11032 | m_errorMonitor->VerifyFound(); |
Tobin Ehlis | 1efce02 | 2016-05-11 10:40:34 -0600 | [diff] [blame] | 11033 | // For this error we need a valid renderpass so create default one |
| 11034 | attach.layout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL; |
| 11035 | attach.attachment = 0; |
| 11036 | attach_desc.format = VK_FORMAT_D24_UNORM_S8_UINT; |
| 11037 | attach_desc.samples = VK_SAMPLE_COUNT_1_BIT; |
| 11038 | attach_desc.storeOp = VK_ATTACHMENT_STORE_OP_STORE; |
| 11039 | attach_desc.stencilLoadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE; |
| 11040 | attach_desc.stencilStoreOp = VK_ATTACHMENT_STORE_OP_DONT_CARE; |
| 11041 | // Can't do a CLEAR load on READ_ONLY initialLayout |
| 11042 | attach_desc.loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR; |
| 11043 | attach_desc.initialLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL; |
| 11044 | attach_desc.finalLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL; |
| 11045 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 11046 | " with invalid first layout " |
| 11047 | "VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_" |
| 11048 | "ONLY_OPTIMAL"); |
| 11049 | vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp); |
| 11050 | m_errorMonitor->VerifyFound(); |
Tobin Ehlis | c555a3c | 2016-05-04 14:08:34 -0600 | [diff] [blame] | 11051 | |
| 11052 | vkDestroyImage(m_device->device(), src_image, NULL); |
| 11053 | vkDestroyImage(m_device->device(), dst_image, NULL); |
| 11054 | } |
Mark Lobodzinski | 209b529 | 2015-09-17 09:44:05 -0600 | [diff] [blame] | 11055 | #endif // DRAW_STATE_TESTS |
| 11056 | |
Tobin Ehlis | 0788f52 | 2015-05-26 16:11:58 -0600 | [diff] [blame] | 11057 | #if THREADING_TESTS |
Mike Stroyan | accf769 | 2015-05-12 16:00:45 -0600 | [diff] [blame] | 11058 | #if GTEST_IS_THREADSAFE |
| 11059 | struct thread_data_struct { |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 11060 | VkCommandBuffer commandBuffer; |
Mike Stroyan | accf769 | 2015-05-12 16:00:45 -0600 | [diff] [blame] | 11061 | VkEvent event; |
| 11062 | bool bailout; |
| 11063 | }; |
| 11064 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 11065 | extern "C" void *AddToCommandBuffer(void *arg) { |
| 11066 | struct thread_data_struct *data = (struct thread_data_struct *)arg; |
Mike Stroyan | accf769 | 2015-05-12 16:00:45 -0600 | [diff] [blame] | 11067 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 11068 | for (int i = 0; i < 10000; i++) { |
| 11069 | vkCmdSetEvent(data->commandBuffer, data->event, |
| 11070 | VK_PIPELINE_STAGE_ALL_COMMANDS_BIT); |
Mike Stroyan | accf769 | 2015-05-12 16:00:45 -0600 | [diff] [blame] | 11071 | if (data->bailout) { |
| 11072 | break; |
| 11073 | } |
| 11074 | } |
| 11075 | return NULL; |
| 11076 | } |
| 11077 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 11078 | TEST_F(VkLayerTest, ThreadCommandBufferCollision) { |
Mike Stroyan | 4268d1f | 2015-07-13 14:45:35 -0600 | [diff] [blame] | 11079 | test_platform_thread thread; |
Mike Stroyan | accf769 | 2015-05-12 16:00:45 -0600 | [diff] [blame] | 11080 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 11081 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 11082 | "THREADING ERROR"); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 11083 | |
Mike Stroyan | accf769 | 2015-05-12 16:00:45 -0600 | [diff] [blame] | 11084 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 11085 | ASSERT_NO_FATAL_FAILURE(InitViewport()); |
| 11086 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 11087 | |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 11088 | // Calls AllocateCommandBuffers |
| 11089 | VkCommandBufferObj commandBuffer(m_device, m_commandPool); |
Mark Lobodzinski | 5495d13 | 2015-09-30 16:19:16 -0600 | [diff] [blame] | 11090 | |
| 11091 | // Avoid creating RenderPass |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 11092 | commandBuffer.BeginCommandBuffer(); |
Mike Stroyan | accf769 | 2015-05-12 16:00:45 -0600 | [diff] [blame] | 11093 | |
| 11094 | VkEventCreateInfo event_info; |
| 11095 | VkEvent event; |
Mike Stroyan | accf769 | 2015-05-12 16:00:45 -0600 | [diff] [blame] | 11096 | VkResult err; |
| 11097 | |
| 11098 | memset(&event_info, 0, sizeof(event_info)); |
| 11099 | event_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO; |
| 11100 | |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 11101 | err = vkCreateEvent(device(), &event_info, NULL, &event); |
Mike Stroyan | accf769 | 2015-05-12 16:00:45 -0600 | [diff] [blame] | 11102 | ASSERT_VK_SUCCESS(err); |
| 11103 | |
Mike Stroyan | accf769 | 2015-05-12 16:00:45 -0600 | [diff] [blame] | 11104 | err = vkResetEvent(device(), event); |
| 11105 | ASSERT_VK_SUCCESS(err); |
| 11106 | |
| 11107 | struct thread_data_struct data; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 11108 | data.commandBuffer = commandBuffer.GetBufferHandle(); |
Mike Stroyan | accf769 | 2015-05-12 16:00:45 -0600 | [diff] [blame] | 11109 | data.event = event; |
| 11110 | data.bailout = false; |
| 11111 | m_errorMonitor->SetBailout(&data.bailout); |
| 11112 | // Add many entries to command buffer from another thread. |
Mike Stroyan | 4268d1f | 2015-07-13 14:45:35 -0600 | [diff] [blame] | 11113 | test_platform_thread_create(&thread, AddToCommandBuffer, (void *)&data); |
Mike Stroyan | accf769 | 2015-05-12 16:00:45 -0600 | [diff] [blame] | 11114 | // Add many entries to command buffer from this thread at the same time. |
| 11115 | AddToCommandBuffer(&data); |
Mark Lobodzinski | 5495d13 | 2015-09-30 16:19:16 -0600 | [diff] [blame] | 11116 | |
Mike Stroyan | 4268d1f | 2015-07-13 14:45:35 -0600 | [diff] [blame] | 11117 | test_platform_thread_join(thread, NULL); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 11118 | commandBuffer.EndCommandBuffer(); |
Mike Stroyan | accf769 | 2015-05-12 16:00:45 -0600 | [diff] [blame] | 11119 | |
Mike Stroyan | 10b8cb7 | 2016-01-22 15:22:03 -0700 | [diff] [blame] | 11120 | m_errorMonitor->SetBailout(NULL); |
| 11121 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 11122 | m_errorMonitor->VerifyFound(); |
Mike Stroyan | accf769 | 2015-05-12 16:00:45 -0600 | [diff] [blame] | 11123 | |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 11124 | vkDestroyEvent(device(), event, NULL); |
Mike Stroyan | accf769 | 2015-05-12 16:00:45 -0600 | [diff] [blame] | 11125 | } |
Mark Lobodzinski | 209b529 | 2015-09-17 09:44:05 -0600 | [diff] [blame] | 11126 | #endif // GTEST_IS_THREADSAFE |
| 11127 | #endif // THREADING_TESTS |
| 11128 | |
Chris Forbes | 9f7ff63 | 2015-05-25 11:13:08 +1200 | [diff] [blame] | 11129 | #if SHADER_CHECKER_TESTS |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 11130 | TEST_F(VkLayerTest, InvalidSPIRVCodeSize) { |
Courtney Goeltzenleuchter | 7415d5a | 2015-12-09 15:48:16 -0700 | [diff] [blame] | 11131 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Chris Forbes | b4afd0f | 2016-04-04 10:48:35 +1200 | [diff] [blame] | 11132 | "Invalid SPIR-V header"); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 11133 | |
Courtney Goeltzenleuchter | 00c52b2 | 2015-09-16 12:58:29 -0600 | [diff] [blame] | 11134 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 11135 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 11136 | |
Courtney Goeltzenleuchter | 00c52b2 | 2015-09-16 12:58:29 -0600 | [diff] [blame] | 11137 | VkShaderModule module; |
| 11138 | VkShaderModuleCreateInfo moduleCreateInfo; |
| 11139 | struct icd_spv_header spv; |
| 11140 | |
| 11141 | spv.magic = ICD_SPV_MAGIC; |
| 11142 | spv.version = ICD_SPV_VERSION; |
| 11143 | spv.gen_magic = 0; |
| 11144 | |
| 11145 | moduleCreateInfo.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO; |
| 11146 | moduleCreateInfo.pNext = NULL; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 11147 | moduleCreateInfo.pCode = (const uint32_t *)&spv; |
Courtney Goeltzenleuchter | 00c52b2 | 2015-09-16 12:58:29 -0600 | [diff] [blame] | 11148 | moduleCreateInfo.codeSize = 4; |
| 11149 | moduleCreateInfo.flags = 0; |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 11150 | vkCreateShaderModule(m_device->device(), &moduleCreateInfo, NULL, &module); |
Courtney Goeltzenleuchter | 00c52b2 | 2015-09-16 12:58:29 -0600 | [diff] [blame] | 11151 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 11152 | m_errorMonitor->VerifyFound(); |
Courtney Goeltzenleuchter | 00c52b2 | 2015-09-16 12:58:29 -0600 | [diff] [blame] | 11153 | } |
| 11154 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 11155 | TEST_F(VkLayerTest, InvalidSPIRVMagic) { |
Courtney Goeltzenleuchter | 7415d5a | 2015-12-09 15:48:16 -0700 | [diff] [blame] | 11156 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Chris Forbes | b4afd0f | 2016-04-04 10:48:35 +1200 | [diff] [blame] | 11157 | "Invalid SPIR-V magic number"); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 11158 | |
Courtney Goeltzenleuchter | 00c52b2 | 2015-09-16 12:58:29 -0600 | [diff] [blame] | 11159 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 11160 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 11161 | |
Courtney Goeltzenleuchter | 00c52b2 | 2015-09-16 12:58:29 -0600 | [diff] [blame] | 11162 | VkShaderModule module; |
| 11163 | VkShaderModuleCreateInfo moduleCreateInfo; |
| 11164 | struct icd_spv_header spv; |
| 11165 | |
| 11166 | spv.magic = ~ICD_SPV_MAGIC; |
| 11167 | spv.version = ICD_SPV_VERSION; |
| 11168 | spv.gen_magic = 0; |
| 11169 | |
| 11170 | moduleCreateInfo.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO; |
| 11171 | moduleCreateInfo.pNext = NULL; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 11172 | moduleCreateInfo.pCode = (const uint32_t *)&spv; |
Courtney Goeltzenleuchter | 00c52b2 | 2015-09-16 12:58:29 -0600 | [diff] [blame] | 11173 | moduleCreateInfo.codeSize = sizeof(spv) + 10; |
| 11174 | moduleCreateInfo.flags = 0; |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 11175 | vkCreateShaderModule(m_device->device(), &moduleCreateInfo, NULL, &module); |
Courtney Goeltzenleuchter | 00c52b2 | 2015-09-16 12:58:29 -0600 | [diff] [blame] | 11176 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 11177 | m_errorMonitor->VerifyFound(); |
Courtney Goeltzenleuchter | 00c52b2 | 2015-09-16 12:58:29 -0600 | [diff] [blame] | 11178 | } |
| 11179 | |
Chris Forbes | b4afd0f | 2016-04-04 10:48:35 +1200 | [diff] [blame] | 11180 | #if 0 |
| 11181 | // Not currently covered by SPIRV-Tools validator |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 11182 | TEST_F(VkLayerTest, InvalidSPIRVVersion) { |
Courtney Goeltzenleuchter | 7415d5a | 2015-12-09 15:48:16 -0700 | [diff] [blame] | 11183 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Chris Forbes | b4afd0f | 2016-04-04 10:48:35 +1200 | [diff] [blame] | 11184 | "Invalid SPIR-V header"); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 11185 | |
Courtney Goeltzenleuchter | 00c52b2 | 2015-09-16 12:58:29 -0600 | [diff] [blame] | 11186 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 11187 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 11188 | |
Courtney Goeltzenleuchter | 00c52b2 | 2015-09-16 12:58:29 -0600 | [diff] [blame] | 11189 | VkShaderModule module; |
| 11190 | VkShaderModuleCreateInfo moduleCreateInfo; |
| 11191 | struct icd_spv_header spv; |
| 11192 | |
| 11193 | spv.magic = ICD_SPV_MAGIC; |
| 11194 | spv.version = ~ICD_SPV_VERSION; |
| 11195 | spv.gen_magic = 0; |
| 11196 | |
| 11197 | moduleCreateInfo.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO; |
| 11198 | moduleCreateInfo.pNext = NULL; |
| 11199 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 11200 | moduleCreateInfo.pCode = (const uint32_t *)&spv; |
Courtney Goeltzenleuchter | 00c52b2 | 2015-09-16 12:58:29 -0600 | [diff] [blame] | 11201 | moduleCreateInfo.codeSize = sizeof(spv) + 10; |
| 11202 | moduleCreateInfo.flags = 0; |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 11203 | vkCreateShaderModule(m_device->device(), &moduleCreateInfo, NULL, &module); |
Courtney Goeltzenleuchter | 00c52b2 | 2015-09-16 12:58:29 -0600 | [diff] [blame] | 11204 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 11205 | m_errorMonitor->VerifyFound(); |
Courtney Goeltzenleuchter | 00c52b2 | 2015-09-16 12:58:29 -0600 | [diff] [blame] | 11206 | } |
Chris Forbes | b4afd0f | 2016-04-04 10:48:35 +1200 | [diff] [blame] | 11207 | #endif |
Courtney Goeltzenleuchter | 00c52b2 | 2015-09-16 12:58:29 -0600 | [diff] [blame] | 11208 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 11209 | TEST_F(VkLayerTest, CreatePipelineVertexOutputNotConsumed) { |
Mark Lobodzinski | 510e20d | 2016-02-11 09:26:16 -0700 | [diff] [blame] | 11210 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 11211 | "not consumed by fragment shader"); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 11212 | |
Chris Forbes | 9f7ff63 | 2015-05-25 11:13:08 +1200 | [diff] [blame] | 11213 | ASSERT_NO_FATAL_FAILURE(InitState()); |
Tobin Ehlis | c9ac2b6 | 2015-09-11 12:57:55 -0600 | [diff] [blame] | 11214 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
Chris Forbes | 9f7ff63 | 2015-05-25 11:13:08 +1200 | [diff] [blame] | 11215 | |
| 11216 | char const *vsSource = |
Chris Forbes | 3846771 | 2016-04-04 17:28:05 +1200 | [diff] [blame] | 11217 | "#version 450\n" |
Chris Forbes | 9f7ff63 | 2015-05-25 11:13:08 +1200 | [diff] [blame] | 11218 | "\n" |
| 11219 | "layout(location=0) out float x;\n" |
Tony Barbour | e804d20 | 2016-01-05 13:37:45 -0700 | [diff] [blame] | 11220 | "out gl_PerVertex {\n" |
| 11221 | " vec4 gl_Position;\n" |
| 11222 | "};\n" |
Chris Forbes | 9f7ff63 | 2015-05-25 11:13:08 +1200 | [diff] [blame] | 11223 | "void main(){\n" |
| 11224 | " gl_Position = vec4(1);\n" |
| 11225 | " x = 0;\n" |
| 11226 | "}\n"; |
| 11227 | char const *fsSource = |
Chris Forbes | 3846771 | 2016-04-04 17:28:05 +1200 | [diff] [blame] | 11228 | "#version 450\n" |
Chris Forbes | 9f7ff63 | 2015-05-25 11:13:08 +1200 | [diff] [blame] | 11229 | "\n" |
| 11230 | "layout(location=0) out vec4 color;\n" |
| 11231 | "void main(){\n" |
| 11232 | " color = vec4(1);\n" |
| 11233 | "}\n"; |
| 11234 | |
Courtney Goeltzenleuchter | d263550 | 2015-10-21 17:08:06 -0600 | [diff] [blame] | 11235 | VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this); |
| 11236 | VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this); |
Chris Forbes | 9f7ff63 | 2015-05-25 11:13:08 +1200 | [diff] [blame] | 11237 | |
| 11238 | VkPipelineObj pipe(m_device); |
Chia-I Wu | 08accc6 | 2015-07-07 11:50:03 +0800 | [diff] [blame] | 11239 | pipe.AddColorAttachment(); |
Chris Forbes | 9f7ff63 | 2015-05-25 11:13:08 +1200 | [diff] [blame] | 11240 | pipe.AddShader(&vs); |
| 11241 | pipe.AddShader(&fs); |
| 11242 | |
Chris Forbes | 9f7ff63 | 2015-05-25 11:13:08 +1200 | [diff] [blame] | 11243 | VkDescriptorSetObj descriptorSet(m_device); |
| 11244 | descriptorSet.AppendDummy(); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 11245 | descriptorSet.CreateVKDescriptorSet(m_commandBuffer); |
Chris Forbes | 9f7ff63 | 2015-05-25 11:13:08 +1200 | [diff] [blame] | 11246 | |
Tony Barbour | 5781e8f | 2015-08-04 16:23:11 -0600 | [diff] [blame] | 11247 | pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass()); |
Chris Forbes | 9f7ff63 | 2015-05-25 11:13:08 +1200 | [diff] [blame] | 11248 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 11249 | m_errorMonitor->VerifyFound(); |
Chris Forbes | 9f7ff63 | 2015-05-25 11:13:08 +1200 | [diff] [blame] | 11250 | } |
Chris Forbes | 9f7ff63 | 2015-05-25 11:13:08 +1200 | [diff] [blame] | 11251 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 11252 | TEST_F(VkLayerTest, CreatePipelineFragmentInputNotProvided) { |
Courtney Goeltzenleuchter | 7415d5a | 2015-12-09 15:48:16 -0700 | [diff] [blame] | 11253 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 11254 | "not written by vertex shader"); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 11255 | |
Chris Forbes | 59cb88d | 2015-05-25 11:13:13 +1200 | [diff] [blame] | 11256 | ASSERT_NO_FATAL_FAILURE(InitState()); |
Tobin Ehlis | c9ac2b6 | 2015-09-11 12:57:55 -0600 | [diff] [blame] | 11257 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
Chris Forbes | 59cb88d | 2015-05-25 11:13:13 +1200 | [diff] [blame] | 11258 | |
| 11259 | char const *vsSource = |
Chris Forbes | 3846771 | 2016-04-04 17:28:05 +1200 | [diff] [blame] | 11260 | "#version 450\n" |
Chris Forbes | 59cb88d | 2015-05-25 11:13:13 +1200 | [diff] [blame] | 11261 | "\n" |
Tony Barbour | e804d20 | 2016-01-05 13:37:45 -0700 | [diff] [blame] | 11262 | "out gl_PerVertex {\n" |
| 11263 | " vec4 gl_Position;\n" |
| 11264 | "};\n" |
Chris Forbes | 59cb88d | 2015-05-25 11:13:13 +1200 | [diff] [blame] | 11265 | "void main(){\n" |
| 11266 | " gl_Position = vec4(1);\n" |
| 11267 | "}\n"; |
| 11268 | char const *fsSource = |
Chris Forbes | 3846771 | 2016-04-04 17:28:05 +1200 | [diff] [blame] | 11269 | "#version 450\n" |
Chris Forbes | 59cb88d | 2015-05-25 11:13:13 +1200 | [diff] [blame] | 11270 | "\n" |
| 11271 | "layout(location=0) in float x;\n" |
| 11272 | "layout(location=0) out vec4 color;\n" |
| 11273 | "void main(){\n" |
| 11274 | " color = vec4(x);\n" |
| 11275 | "}\n"; |
| 11276 | |
Courtney Goeltzenleuchter | d263550 | 2015-10-21 17:08:06 -0600 | [diff] [blame] | 11277 | VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this); |
| 11278 | VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this); |
Chris Forbes | 59cb88d | 2015-05-25 11:13:13 +1200 | [diff] [blame] | 11279 | |
| 11280 | VkPipelineObj pipe(m_device); |
Chia-I Wu | 08accc6 | 2015-07-07 11:50:03 +0800 | [diff] [blame] | 11281 | pipe.AddColorAttachment(); |
Chris Forbes | 59cb88d | 2015-05-25 11:13:13 +1200 | [diff] [blame] | 11282 | pipe.AddShader(&vs); |
| 11283 | pipe.AddShader(&fs); |
| 11284 | |
Chris Forbes | 59cb88d | 2015-05-25 11:13:13 +1200 | [diff] [blame] | 11285 | VkDescriptorSetObj descriptorSet(m_device); |
| 11286 | descriptorSet.AppendDummy(); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 11287 | descriptorSet.CreateVKDescriptorSet(m_commandBuffer); |
Chris Forbes | 59cb88d | 2015-05-25 11:13:13 +1200 | [diff] [blame] | 11288 | |
Tony Barbour | 5781e8f | 2015-08-04 16:23:11 -0600 | [diff] [blame] | 11289 | pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass()); |
Chris Forbes | 59cb88d | 2015-05-25 11:13:13 +1200 | [diff] [blame] | 11290 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 11291 | m_errorMonitor->VerifyFound(); |
Chris Forbes | 59cb88d | 2015-05-25 11:13:13 +1200 | [diff] [blame] | 11292 | } |
| 11293 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 11294 | TEST_F(VkLayerTest, CreatePipelineFragmentInputNotProvidedInBlock) { |
Chris Forbes | a3e85f6 | 2016-01-15 14:53:11 +1300 | [diff] [blame] | 11295 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 11296 | "not written by vertex shader"); |
Chris Forbes | a3e85f6 | 2016-01-15 14:53:11 +1300 | [diff] [blame] | 11297 | |
| 11298 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 11299 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 11300 | |
| 11301 | char const *vsSource = |
Chris Forbes | 3846771 | 2016-04-04 17:28:05 +1200 | [diff] [blame] | 11302 | "#version 450\n" |
Chris Forbes | a3e85f6 | 2016-01-15 14:53:11 +1300 | [diff] [blame] | 11303 | "\n" |
| 11304 | "out gl_PerVertex {\n" |
| 11305 | " vec4 gl_Position;\n" |
| 11306 | "};\n" |
| 11307 | "void main(){\n" |
| 11308 | " gl_Position = vec4(1);\n" |
| 11309 | "}\n"; |
| 11310 | char const *fsSource = |
| 11311 | "#version 450\n" |
Chris Forbes | a3e85f6 | 2016-01-15 14:53:11 +1300 | [diff] [blame] | 11312 | "\n" |
| 11313 | "in block { layout(location=0) float x; } ins;\n" |
| 11314 | "layout(location=0) out vec4 color;\n" |
| 11315 | "void main(){\n" |
| 11316 | " color = vec4(ins.x);\n" |
| 11317 | "}\n"; |
| 11318 | |
| 11319 | VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this); |
| 11320 | VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this); |
| 11321 | |
| 11322 | VkPipelineObj pipe(m_device); |
| 11323 | pipe.AddColorAttachment(); |
| 11324 | pipe.AddShader(&vs); |
| 11325 | pipe.AddShader(&fs); |
| 11326 | |
| 11327 | VkDescriptorSetObj descriptorSet(m_device); |
| 11328 | descriptorSet.AppendDummy(); |
| 11329 | descriptorSet.CreateVKDescriptorSet(m_commandBuffer); |
| 11330 | |
| 11331 | pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass()); |
| 11332 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 11333 | m_errorMonitor->VerifyFound(); |
Chris Forbes | a3e85f6 | 2016-01-15 14:53:11 +1300 | [diff] [blame] | 11334 | } |
| 11335 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 11336 | TEST_F(VkLayerTest, CreatePipelineVsFsTypeMismatchArraySize) { |
Chris Forbes | 0036fd1 | 2016-01-26 14:19:49 +1300 | [diff] [blame] | 11337 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Chris Forbes | e992882 | 2016-02-17 14:44:52 +1300 | [diff] [blame] | 11338 | "Type mismatch on location 0.0: 'ptr to " |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 11339 | "output arr[2] of float32' vs 'ptr to " |
| 11340 | "input arr[3] of float32'"); |
Chris Forbes | 0036fd1 | 2016-01-26 14:19:49 +1300 | [diff] [blame] | 11341 | |
| 11342 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 11343 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 11344 | |
| 11345 | char const *vsSource = |
Chris Forbes | 3846771 | 2016-04-04 17:28:05 +1200 | [diff] [blame] | 11346 | "#version 450\n" |
Chris Forbes | 0036fd1 | 2016-01-26 14:19:49 +1300 | [diff] [blame] | 11347 | "\n" |
| 11348 | "layout(location=0) out float x[2];\n" |
| 11349 | "out gl_PerVertex {\n" |
| 11350 | " vec4 gl_Position;\n" |
| 11351 | "};\n" |
| 11352 | "void main(){\n" |
| 11353 | " x[0] = 0; x[1] = 0;\n" |
| 11354 | " gl_Position = vec4(1);\n" |
| 11355 | "}\n"; |
| 11356 | char const *fsSource = |
Chris Forbes | 3846771 | 2016-04-04 17:28:05 +1200 | [diff] [blame] | 11357 | "#version 450\n" |
Chris Forbes | 0036fd1 | 2016-01-26 14:19:49 +1300 | [diff] [blame] | 11358 | "\n" |
| 11359 | "layout(location=0) in float x[3];\n" |
| 11360 | "layout(location=0) out vec4 color;\n" |
| 11361 | "void main(){\n" |
| 11362 | " color = vec4(x[0] + x[1] + x[2]);\n" |
| 11363 | "}\n"; |
| 11364 | |
| 11365 | VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this); |
| 11366 | VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this); |
| 11367 | |
| 11368 | VkPipelineObj pipe(m_device); |
| 11369 | pipe.AddColorAttachment(); |
| 11370 | pipe.AddShader(&vs); |
| 11371 | pipe.AddShader(&fs); |
| 11372 | |
| 11373 | VkDescriptorSetObj descriptorSet(m_device); |
| 11374 | descriptorSet.AppendDummy(); |
| 11375 | descriptorSet.CreateVKDescriptorSet(m_commandBuffer); |
| 11376 | |
| 11377 | pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass()); |
| 11378 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 11379 | m_errorMonitor->VerifyFound(); |
Chris Forbes | 0036fd1 | 2016-01-26 14:19:49 +1300 | [diff] [blame] | 11380 | } |
| 11381 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 11382 | TEST_F(VkLayerTest, CreatePipelineVsFsTypeMismatch) { |
Courtney Goeltzenleuchter | 7415d5a | 2015-12-09 15:48:16 -0700 | [diff] [blame] | 11383 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 11384 | "Type mismatch on location 0"); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 11385 | |
Chris Forbes | b56af56 | 2015-05-25 11:13:17 +1200 | [diff] [blame] | 11386 | ASSERT_NO_FATAL_FAILURE(InitState()); |
Tobin Ehlis | c9ac2b6 | 2015-09-11 12:57:55 -0600 | [diff] [blame] | 11387 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
Chris Forbes | b56af56 | 2015-05-25 11:13:17 +1200 | [diff] [blame] | 11388 | |
| 11389 | char const *vsSource = |
Chris Forbes | 3846771 | 2016-04-04 17:28:05 +1200 | [diff] [blame] | 11390 | "#version 450\n" |
Chris Forbes | b56af56 | 2015-05-25 11:13:17 +1200 | [diff] [blame] | 11391 | "\n" |
| 11392 | "layout(location=0) out int x;\n" |
Tony Barbour | e804d20 | 2016-01-05 13:37:45 -0700 | [diff] [blame] | 11393 | "out gl_PerVertex {\n" |
| 11394 | " vec4 gl_Position;\n" |
| 11395 | "};\n" |
Chris Forbes | b56af56 | 2015-05-25 11:13:17 +1200 | [diff] [blame] | 11396 | "void main(){\n" |
| 11397 | " x = 0;\n" |
| 11398 | " gl_Position = vec4(1);\n" |
| 11399 | "}\n"; |
| 11400 | char const *fsSource = |
Chris Forbes | 3846771 | 2016-04-04 17:28:05 +1200 | [diff] [blame] | 11401 | "#version 450\n" |
Chris Forbes | b56af56 | 2015-05-25 11:13:17 +1200 | [diff] [blame] | 11402 | "\n" |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 11403 | "layout(location=0) in float x;\n" /* VS writes int */ |
Chris Forbes | b56af56 | 2015-05-25 11:13:17 +1200 | [diff] [blame] | 11404 | "layout(location=0) out vec4 color;\n" |
| 11405 | "void main(){\n" |
| 11406 | " color = vec4(x);\n" |
| 11407 | "}\n"; |
| 11408 | |
Courtney Goeltzenleuchter | d263550 | 2015-10-21 17:08:06 -0600 | [diff] [blame] | 11409 | VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this); |
| 11410 | VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this); |
Chris Forbes | b56af56 | 2015-05-25 11:13:17 +1200 | [diff] [blame] | 11411 | |
| 11412 | VkPipelineObj pipe(m_device); |
Chia-I Wu | 08accc6 | 2015-07-07 11:50:03 +0800 | [diff] [blame] | 11413 | pipe.AddColorAttachment(); |
Chris Forbes | b56af56 | 2015-05-25 11:13:17 +1200 | [diff] [blame] | 11414 | pipe.AddShader(&vs); |
| 11415 | pipe.AddShader(&fs); |
| 11416 | |
Chris Forbes | b56af56 | 2015-05-25 11:13:17 +1200 | [diff] [blame] | 11417 | VkDescriptorSetObj descriptorSet(m_device); |
| 11418 | descriptorSet.AppendDummy(); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 11419 | descriptorSet.CreateVKDescriptorSet(m_commandBuffer); |
Chris Forbes | b56af56 | 2015-05-25 11:13:17 +1200 | [diff] [blame] | 11420 | |
Tony Barbour | 5781e8f | 2015-08-04 16:23:11 -0600 | [diff] [blame] | 11421 | pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass()); |
Chris Forbes | b56af56 | 2015-05-25 11:13:17 +1200 | [diff] [blame] | 11422 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 11423 | m_errorMonitor->VerifyFound(); |
Chris Forbes | b56af56 | 2015-05-25 11:13:17 +1200 | [diff] [blame] | 11424 | } |
| 11425 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 11426 | TEST_F(VkLayerTest, CreatePipelineVsFsTypeMismatchInBlock) { |
Chris Forbes | a3e85f6 | 2016-01-15 14:53:11 +1300 | [diff] [blame] | 11427 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 11428 | "Type mismatch on location 0"); |
Chris Forbes | a3e85f6 | 2016-01-15 14:53:11 +1300 | [diff] [blame] | 11429 | |
| 11430 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 11431 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 11432 | |
| 11433 | char const *vsSource = |
| 11434 | "#version 450\n" |
Chris Forbes | a3e85f6 | 2016-01-15 14:53:11 +1300 | [diff] [blame] | 11435 | "\n" |
| 11436 | "out block { layout(location=0) int x; } outs;\n" |
| 11437 | "out gl_PerVertex {\n" |
| 11438 | " vec4 gl_Position;\n" |
| 11439 | "};\n" |
| 11440 | "void main(){\n" |
| 11441 | " outs.x = 0;\n" |
| 11442 | " gl_Position = vec4(1);\n" |
| 11443 | "}\n"; |
| 11444 | char const *fsSource = |
| 11445 | "#version 450\n" |
Chris Forbes | a3e85f6 | 2016-01-15 14:53:11 +1300 | [diff] [blame] | 11446 | "\n" |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 11447 | "in block { layout(location=0) float x; } ins;\n" /* VS writes int */ |
Chris Forbes | a3e85f6 | 2016-01-15 14:53:11 +1300 | [diff] [blame] | 11448 | "layout(location=0) out vec4 color;\n" |
| 11449 | "void main(){\n" |
| 11450 | " color = vec4(ins.x);\n" |
| 11451 | "}\n"; |
| 11452 | |
| 11453 | VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this); |
| 11454 | VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this); |
| 11455 | |
| 11456 | VkPipelineObj pipe(m_device); |
| 11457 | pipe.AddColorAttachment(); |
| 11458 | pipe.AddShader(&vs); |
| 11459 | pipe.AddShader(&fs); |
| 11460 | |
| 11461 | VkDescriptorSetObj descriptorSet(m_device); |
| 11462 | descriptorSet.AppendDummy(); |
| 11463 | descriptorSet.CreateVKDescriptorSet(m_commandBuffer); |
| 11464 | |
| 11465 | pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass()); |
| 11466 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 11467 | m_errorMonitor->VerifyFound(); |
Chris Forbes | e992882 | 2016-02-17 14:44:52 +1300 | [diff] [blame] | 11468 | } |
| 11469 | |
| 11470 | TEST_F(VkLayerTest, CreatePipelineVsFsMismatchByLocation) { |
| 11471 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 11472 | "location 0.0 which is not written by vertex shader"); |
| 11473 | |
| 11474 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 11475 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 11476 | |
| 11477 | char const *vsSource = |
| 11478 | "#version 450\n" |
Chris Forbes | e992882 | 2016-02-17 14:44:52 +1300 | [diff] [blame] | 11479 | "\n" |
| 11480 | "out block { layout(location=1) float x; } outs;\n" |
| 11481 | "out gl_PerVertex {\n" |
| 11482 | " vec4 gl_Position;\n" |
| 11483 | "};\n" |
| 11484 | "void main(){\n" |
| 11485 | " outs.x = 0;\n" |
| 11486 | " gl_Position = vec4(1);\n" |
| 11487 | "}\n"; |
| 11488 | char const *fsSource = |
| 11489 | "#version 450\n" |
Chris Forbes | e992882 | 2016-02-17 14:44:52 +1300 | [diff] [blame] | 11490 | "\n" |
| 11491 | "in block { layout(location=0) float x; } ins;\n" |
| 11492 | "layout(location=0) out vec4 color;\n" |
| 11493 | "void main(){\n" |
| 11494 | " color = vec4(ins.x);\n" |
| 11495 | "}\n"; |
| 11496 | |
| 11497 | VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this); |
| 11498 | VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this); |
| 11499 | |
| 11500 | VkPipelineObj pipe(m_device); |
| 11501 | pipe.AddColorAttachment(); |
| 11502 | pipe.AddShader(&vs); |
| 11503 | pipe.AddShader(&fs); |
| 11504 | |
| 11505 | VkDescriptorSetObj descriptorSet(m_device); |
| 11506 | descriptorSet.AppendDummy(); |
| 11507 | descriptorSet.CreateVKDescriptorSet(m_commandBuffer); |
| 11508 | |
| 11509 | pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass()); |
| 11510 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 11511 | m_errorMonitor->VerifyFound(); |
Chris Forbes | e992882 | 2016-02-17 14:44:52 +1300 | [diff] [blame] | 11512 | } |
| 11513 | |
| 11514 | TEST_F(VkLayerTest, CreatePipelineVsFsMismatchByComponent) { |
| 11515 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 11516 | "location 0.1 which is not written by vertex shader"); |
| 11517 | |
| 11518 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 11519 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 11520 | |
| 11521 | char const *vsSource = |
| 11522 | "#version 450\n" |
Chris Forbes | e992882 | 2016-02-17 14:44:52 +1300 | [diff] [blame] | 11523 | "\n" |
| 11524 | "out block { layout(location=0, component=0) float x; } outs;\n" |
| 11525 | "out gl_PerVertex {\n" |
| 11526 | " vec4 gl_Position;\n" |
| 11527 | "};\n" |
| 11528 | "void main(){\n" |
| 11529 | " outs.x = 0;\n" |
| 11530 | " gl_Position = vec4(1);\n" |
| 11531 | "}\n"; |
| 11532 | char const *fsSource = |
| 11533 | "#version 450\n" |
Chris Forbes | e992882 | 2016-02-17 14:44:52 +1300 | [diff] [blame] | 11534 | "\n" |
| 11535 | "in block { layout(location=0, component=1) float x; } ins;\n" |
| 11536 | "layout(location=0) out vec4 color;\n" |
| 11537 | "void main(){\n" |
| 11538 | " color = vec4(ins.x);\n" |
| 11539 | "}\n"; |
| 11540 | |
| 11541 | VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this); |
| 11542 | VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this); |
| 11543 | |
| 11544 | VkPipelineObj pipe(m_device); |
| 11545 | pipe.AddColorAttachment(); |
| 11546 | pipe.AddShader(&vs); |
| 11547 | pipe.AddShader(&fs); |
| 11548 | |
| 11549 | VkDescriptorSetObj descriptorSet(m_device); |
| 11550 | descriptorSet.AppendDummy(); |
| 11551 | descriptorSet.CreateVKDescriptorSet(m_commandBuffer); |
| 11552 | |
| 11553 | pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass()); |
| 11554 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 11555 | m_errorMonitor->VerifyFound(); |
Chris Forbes | a3e85f6 | 2016-01-15 14:53:11 +1300 | [diff] [blame] | 11556 | } |
| 11557 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 11558 | TEST_F(VkLayerTest, CreatePipelineAttribNotConsumed) { |
Mark Lobodzinski | 510e20d | 2016-02-11 09:26:16 -0700 | [diff] [blame] | 11559 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 11560 | "location 0 not consumed by VS"); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 11561 | |
Chris Forbes | de136e0 | 2015-05-25 11:13:28 +1200 | [diff] [blame] | 11562 | ASSERT_NO_FATAL_FAILURE(InitState()); |
Tobin Ehlis | c9ac2b6 | 2015-09-11 12:57:55 -0600 | [diff] [blame] | 11563 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
Chris Forbes | de136e0 | 2015-05-25 11:13:28 +1200 | [diff] [blame] | 11564 | |
| 11565 | VkVertexInputBindingDescription input_binding; |
| 11566 | memset(&input_binding, 0, sizeof(input_binding)); |
| 11567 | |
| 11568 | VkVertexInputAttributeDescription input_attrib; |
| 11569 | memset(&input_attrib, 0, sizeof(input_attrib)); |
| 11570 | input_attrib.format = VK_FORMAT_R32_SFLOAT; |
| 11571 | |
| 11572 | char const *vsSource = |
Chris Forbes | 3846771 | 2016-04-04 17:28:05 +1200 | [diff] [blame] | 11573 | "#version 450\n" |
Chris Forbes | de136e0 | 2015-05-25 11:13:28 +1200 | [diff] [blame] | 11574 | "\n" |
Tony Barbour | e804d20 | 2016-01-05 13:37:45 -0700 | [diff] [blame] | 11575 | "out gl_PerVertex {\n" |
| 11576 | " vec4 gl_Position;\n" |
| 11577 | "};\n" |
Chris Forbes | de136e0 | 2015-05-25 11:13:28 +1200 | [diff] [blame] | 11578 | "void main(){\n" |
| 11579 | " gl_Position = vec4(1);\n" |
| 11580 | "}\n"; |
| 11581 | char const *fsSource = |
Chris Forbes | 3846771 | 2016-04-04 17:28:05 +1200 | [diff] [blame] | 11582 | "#version 450\n" |
Chris Forbes | de136e0 | 2015-05-25 11:13:28 +1200 | [diff] [blame] | 11583 | "\n" |
| 11584 | "layout(location=0) out vec4 color;\n" |
| 11585 | "void main(){\n" |
| 11586 | " color = vec4(1);\n" |
| 11587 | "}\n"; |
| 11588 | |
Courtney Goeltzenleuchter | d263550 | 2015-10-21 17:08:06 -0600 | [diff] [blame] | 11589 | VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this); |
| 11590 | VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this); |
Chris Forbes | de136e0 | 2015-05-25 11:13:28 +1200 | [diff] [blame] | 11591 | |
| 11592 | VkPipelineObj pipe(m_device); |
Chia-I Wu | 08accc6 | 2015-07-07 11:50:03 +0800 | [diff] [blame] | 11593 | pipe.AddColorAttachment(); |
Chris Forbes | de136e0 | 2015-05-25 11:13:28 +1200 | [diff] [blame] | 11594 | pipe.AddShader(&vs); |
| 11595 | pipe.AddShader(&fs); |
| 11596 | |
| 11597 | pipe.AddVertexInputBindings(&input_binding, 1); |
| 11598 | pipe.AddVertexInputAttribs(&input_attrib, 1); |
| 11599 | |
Chris Forbes | de136e0 | 2015-05-25 11:13:28 +1200 | [diff] [blame] | 11600 | VkDescriptorSetObj descriptorSet(m_device); |
| 11601 | descriptorSet.AppendDummy(); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 11602 | descriptorSet.CreateVKDescriptorSet(m_commandBuffer); |
Chris Forbes | de136e0 | 2015-05-25 11:13:28 +1200 | [diff] [blame] | 11603 | |
Tony Barbour | 5781e8f | 2015-08-04 16:23:11 -0600 | [diff] [blame] | 11604 | pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass()); |
Chris Forbes | de136e0 | 2015-05-25 11:13:28 +1200 | [diff] [blame] | 11605 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 11606 | m_errorMonitor->VerifyFound(); |
Chris Forbes | de136e0 | 2015-05-25 11:13:28 +1200 | [diff] [blame] | 11607 | } |
| 11608 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 11609 | TEST_F(VkLayerTest, CreatePipelineAttribLocationMismatch) { |
Mark Lobodzinski | 510e20d | 2016-02-11 09:26:16 -0700 | [diff] [blame] | 11610 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 11611 | "location 0 not consumed by VS"); |
Chris Forbes | 7d83cd5 | 2016-01-15 11:32:03 +1300 | [diff] [blame] | 11612 | |
| 11613 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 11614 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 11615 | |
| 11616 | VkVertexInputBindingDescription input_binding; |
| 11617 | memset(&input_binding, 0, sizeof(input_binding)); |
| 11618 | |
| 11619 | VkVertexInputAttributeDescription input_attrib; |
| 11620 | memset(&input_attrib, 0, sizeof(input_attrib)); |
| 11621 | input_attrib.format = VK_FORMAT_R32_SFLOAT; |
| 11622 | |
| 11623 | char const *vsSource = |
Chris Forbes | 3846771 | 2016-04-04 17:28:05 +1200 | [diff] [blame] | 11624 | "#version 450\n" |
Chris Forbes | 7d83cd5 | 2016-01-15 11:32:03 +1300 | [diff] [blame] | 11625 | "\n" |
| 11626 | "layout(location=1) in float x;\n" |
| 11627 | "out gl_PerVertex {\n" |
| 11628 | " vec4 gl_Position;\n" |
| 11629 | "};\n" |
| 11630 | "void main(){\n" |
| 11631 | " gl_Position = vec4(x);\n" |
| 11632 | "}\n"; |
| 11633 | char const *fsSource = |
Chris Forbes | 3846771 | 2016-04-04 17:28:05 +1200 | [diff] [blame] | 11634 | "#version 450\n" |
Chris Forbes | 7d83cd5 | 2016-01-15 11:32:03 +1300 | [diff] [blame] | 11635 | "\n" |
| 11636 | "layout(location=0) out vec4 color;\n" |
| 11637 | "void main(){\n" |
| 11638 | " color = vec4(1);\n" |
| 11639 | "}\n"; |
| 11640 | |
| 11641 | VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this); |
| 11642 | VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this); |
| 11643 | |
| 11644 | VkPipelineObj pipe(m_device); |
| 11645 | pipe.AddColorAttachment(); |
| 11646 | pipe.AddShader(&vs); |
| 11647 | pipe.AddShader(&fs); |
| 11648 | |
| 11649 | pipe.AddVertexInputBindings(&input_binding, 1); |
| 11650 | pipe.AddVertexInputAttribs(&input_attrib, 1); |
| 11651 | |
| 11652 | VkDescriptorSetObj descriptorSet(m_device); |
| 11653 | descriptorSet.AppendDummy(); |
| 11654 | descriptorSet.CreateVKDescriptorSet(m_commandBuffer); |
| 11655 | |
| 11656 | pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass()); |
| 11657 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 11658 | m_errorMonitor->VerifyFound(); |
Chris Forbes | 7d83cd5 | 2016-01-15 11:32:03 +1300 | [diff] [blame] | 11659 | } |
| 11660 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 11661 | TEST_F(VkLayerTest, CreatePipelineAttribNotProvided) { |
| 11662 | m_errorMonitor->SetDesiredFailureMsg( |
| 11663 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 11664 | "VS consumes input at location 0 but not provided"); |
| 11665 | |
Chris Forbes | 62e8e50 | 2015-05-25 11:13:29 +1200 | [diff] [blame] | 11666 | ASSERT_NO_FATAL_FAILURE(InitState()); |
Tobin Ehlis | c9ac2b6 | 2015-09-11 12:57:55 -0600 | [diff] [blame] | 11667 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
Chris Forbes | 62e8e50 | 2015-05-25 11:13:29 +1200 | [diff] [blame] | 11668 | |
| 11669 | char const *vsSource = |
Chris Forbes | 3846771 | 2016-04-04 17:28:05 +1200 | [diff] [blame] | 11670 | "#version 450\n" |
Chris Forbes | 62e8e50 | 2015-05-25 11:13:29 +1200 | [diff] [blame] | 11671 | "\n" |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 11672 | "layout(location=0) in vec4 x;\n" /* not provided */ |
Tony Barbour | e804d20 | 2016-01-05 13:37:45 -0700 | [diff] [blame] | 11673 | "out gl_PerVertex {\n" |
| 11674 | " vec4 gl_Position;\n" |
| 11675 | "};\n" |
Chris Forbes | 62e8e50 | 2015-05-25 11:13:29 +1200 | [diff] [blame] | 11676 | "void main(){\n" |
| 11677 | " gl_Position = x;\n" |
| 11678 | "}\n"; |
| 11679 | char const *fsSource = |
Chris Forbes | 3846771 | 2016-04-04 17:28:05 +1200 | [diff] [blame] | 11680 | "#version 450\n" |
Chris Forbes | 62e8e50 | 2015-05-25 11:13:29 +1200 | [diff] [blame] | 11681 | "\n" |
| 11682 | "layout(location=0) out vec4 color;\n" |
| 11683 | "void main(){\n" |
| 11684 | " color = vec4(1);\n" |
| 11685 | "}\n"; |
| 11686 | |
Courtney Goeltzenleuchter | d263550 | 2015-10-21 17:08:06 -0600 | [diff] [blame] | 11687 | VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this); |
| 11688 | VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this); |
Chris Forbes | 62e8e50 | 2015-05-25 11:13:29 +1200 | [diff] [blame] | 11689 | |
| 11690 | VkPipelineObj pipe(m_device); |
Chia-I Wu | 08accc6 | 2015-07-07 11:50:03 +0800 | [diff] [blame] | 11691 | pipe.AddColorAttachment(); |
Chris Forbes | 62e8e50 | 2015-05-25 11:13:29 +1200 | [diff] [blame] | 11692 | pipe.AddShader(&vs); |
| 11693 | pipe.AddShader(&fs); |
| 11694 | |
Chris Forbes | 62e8e50 | 2015-05-25 11:13:29 +1200 | [diff] [blame] | 11695 | VkDescriptorSetObj descriptorSet(m_device); |
| 11696 | descriptorSet.AppendDummy(); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 11697 | descriptorSet.CreateVKDescriptorSet(m_commandBuffer); |
Chris Forbes | 62e8e50 | 2015-05-25 11:13:29 +1200 | [diff] [blame] | 11698 | |
Tony Barbour | 5781e8f | 2015-08-04 16:23:11 -0600 | [diff] [blame] | 11699 | pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass()); |
Chris Forbes | 62e8e50 | 2015-05-25 11:13:29 +1200 | [diff] [blame] | 11700 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 11701 | m_errorMonitor->VerifyFound(); |
Chris Forbes | 62e8e50 | 2015-05-25 11:13:29 +1200 | [diff] [blame] | 11702 | } |
| 11703 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 11704 | TEST_F(VkLayerTest, CreatePipelineAttribTypeMismatch) { |
| 11705 | m_errorMonitor->SetDesiredFailureMsg( |
| 11706 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 11707 | "location 0 does not match VS input type"); |
| 11708 | |
Chris Forbes | c97d98e | 2015-05-25 11:13:31 +1200 | [diff] [blame] | 11709 | ASSERT_NO_FATAL_FAILURE(InitState()); |
Tobin Ehlis | c9ac2b6 | 2015-09-11 12:57:55 -0600 | [diff] [blame] | 11710 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
Chris Forbes | c97d98e | 2015-05-25 11:13:31 +1200 | [diff] [blame] | 11711 | |
| 11712 | VkVertexInputBindingDescription input_binding; |
| 11713 | memset(&input_binding, 0, sizeof(input_binding)); |
| 11714 | |
| 11715 | VkVertexInputAttributeDescription input_attrib; |
| 11716 | memset(&input_attrib, 0, sizeof(input_attrib)); |
| 11717 | input_attrib.format = VK_FORMAT_R32_SFLOAT; |
| 11718 | |
| 11719 | char const *vsSource = |
Chris Forbes | 3846771 | 2016-04-04 17:28:05 +1200 | [diff] [blame] | 11720 | "#version 450\n" |
Chris Forbes | c97d98e | 2015-05-25 11:13:31 +1200 | [diff] [blame] | 11721 | "\n" |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 11722 | "layout(location=0) in int x;\n" /* attrib provided float */ |
Tony Barbour | e804d20 | 2016-01-05 13:37:45 -0700 | [diff] [blame] | 11723 | "out gl_PerVertex {\n" |
| 11724 | " vec4 gl_Position;\n" |
| 11725 | "};\n" |
Chris Forbes | c97d98e | 2015-05-25 11:13:31 +1200 | [diff] [blame] | 11726 | "void main(){\n" |
| 11727 | " gl_Position = vec4(x);\n" |
| 11728 | "}\n"; |
| 11729 | char const *fsSource = |
Chris Forbes | 3846771 | 2016-04-04 17:28:05 +1200 | [diff] [blame] | 11730 | "#version 450\n" |
Chris Forbes | c97d98e | 2015-05-25 11:13:31 +1200 | [diff] [blame] | 11731 | "\n" |
| 11732 | "layout(location=0) out vec4 color;\n" |
| 11733 | "void main(){\n" |
| 11734 | " color = vec4(1);\n" |
| 11735 | "}\n"; |
| 11736 | |
Courtney Goeltzenleuchter | d263550 | 2015-10-21 17:08:06 -0600 | [diff] [blame] | 11737 | VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this); |
| 11738 | VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this); |
Chris Forbes | c97d98e | 2015-05-25 11:13:31 +1200 | [diff] [blame] | 11739 | |
| 11740 | VkPipelineObj pipe(m_device); |
Chia-I Wu | 08accc6 | 2015-07-07 11:50:03 +0800 | [diff] [blame] | 11741 | pipe.AddColorAttachment(); |
Chris Forbes | c97d98e | 2015-05-25 11:13:31 +1200 | [diff] [blame] | 11742 | pipe.AddShader(&vs); |
| 11743 | pipe.AddShader(&fs); |
| 11744 | |
| 11745 | pipe.AddVertexInputBindings(&input_binding, 1); |
| 11746 | pipe.AddVertexInputAttribs(&input_attrib, 1); |
| 11747 | |
Chris Forbes | c97d98e | 2015-05-25 11:13:31 +1200 | [diff] [blame] | 11748 | VkDescriptorSetObj descriptorSet(m_device); |
| 11749 | descriptorSet.AppendDummy(); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 11750 | descriptorSet.CreateVKDescriptorSet(m_commandBuffer); |
Chris Forbes | c97d98e | 2015-05-25 11:13:31 +1200 | [diff] [blame] | 11751 | |
Tony Barbour | 5781e8f | 2015-08-04 16:23:11 -0600 | [diff] [blame] | 11752 | pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass()); |
Chris Forbes | c97d98e | 2015-05-25 11:13:31 +1200 | [diff] [blame] | 11753 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 11754 | m_errorMonitor->VerifyFound(); |
Chris Forbes | c97d98e | 2015-05-25 11:13:31 +1200 | [diff] [blame] | 11755 | } |
| 11756 | |
Chris Forbes | c68b43c | 2016-04-06 11:18:47 +1200 | [diff] [blame] | 11757 | TEST_F(VkLayerTest, CreatePipelineDuplicateStage) { |
| 11758 | m_errorMonitor->SetDesiredFailureMsg( |
| 11759 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 11760 | "Multiple shaders provided for stage VK_SHADER_STAGE_VERTEX_BIT"); |
| 11761 | |
| 11762 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 11763 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 11764 | |
| 11765 | char const *vsSource = |
| 11766 | "#version 450\n" |
| 11767 | "\n" |
| 11768 | "out gl_PerVertex {\n" |
| 11769 | " vec4 gl_Position;\n" |
| 11770 | "};\n" |
| 11771 | "void main(){\n" |
| 11772 | " gl_Position = vec4(1);\n" |
| 11773 | "}\n"; |
| 11774 | char const *fsSource = |
| 11775 | "#version 450\n" |
| 11776 | "\n" |
| 11777 | "layout(location=0) out vec4 color;\n" |
| 11778 | "void main(){\n" |
| 11779 | " color = vec4(1);\n" |
| 11780 | "}\n"; |
| 11781 | |
| 11782 | VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this); |
| 11783 | VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this); |
| 11784 | |
| 11785 | VkPipelineObj pipe(m_device); |
| 11786 | pipe.AddColorAttachment(); |
| 11787 | pipe.AddShader(&vs); |
| 11788 | pipe.AddShader(&vs); |
| 11789 | pipe.AddShader(&fs); |
| 11790 | |
| 11791 | VkDescriptorSetObj descriptorSet(m_device); |
| 11792 | descriptorSet.AppendDummy(); |
| 11793 | descriptorSet.CreateVKDescriptorSet(m_commandBuffer); |
| 11794 | |
| 11795 | pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass()); |
| 11796 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 11797 | m_errorMonitor->VerifyFound(); |
Chris Forbes | c68b43c | 2016-04-06 11:18:47 +1200 | [diff] [blame] | 11798 | } |
| 11799 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 11800 | TEST_F(VkLayerTest, CreatePipelineAttribMatrixType) { |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 11801 | m_errorMonitor->ExpectSuccess(); |
Chris Forbes | 2682b24 | 2015-11-24 11:13:14 +1300 | [diff] [blame] | 11802 | |
| 11803 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 11804 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 11805 | |
| 11806 | VkVertexInputBindingDescription input_binding; |
| 11807 | memset(&input_binding, 0, sizeof(input_binding)); |
| 11808 | |
| 11809 | VkVertexInputAttributeDescription input_attribs[2]; |
| 11810 | memset(input_attribs, 0, sizeof(input_attribs)); |
| 11811 | |
| 11812 | for (int i = 0; i < 2; i++) { |
| 11813 | input_attribs[i].format = VK_FORMAT_R32G32B32A32_SFLOAT; |
| 11814 | input_attribs[i].location = i; |
| 11815 | } |
| 11816 | |
| 11817 | char const *vsSource = |
Chris Forbes | 3846771 | 2016-04-04 17:28:05 +1200 | [diff] [blame] | 11818 | "#version 450\n" |
Chris Forbes | 2682b24 | 2015-11-24 11:13:14 +1300 | [diff] [blame] | 11819 | "\n" |
| 11820 | "layout(location=0) in mat2x4 x;\n" |
Tony Barbour | e804d20 | 2016-01-05 13:37:45 -0700 | [diff] [blame] | 11821 | "out gl_PerVertex {\n" |
| 11822 | " vec4 gl_Position;\n" |
| 11823 | "};\n" |
Chris Forbes | 2682b24 | 2015-11-24 11:13:14 +1300 | [diff] [blame] | 11824 | "void main(){\n" |
| 11825 | " gl_Position = x[0] + x[1];\n" |
| 11826 | "}\n"; |
| 11827 | char const *fsSource = |
Chris Forbes | 3846771 | 2016-04-04 17:28:05 +1200 | [diff] [blame] | 11828 | "#version 450\n" |
Chris Forbes | 2682b24 | 2015-11-24 11:13:14 +1300 | [diff] [blame] | 11829 | "\n" |
| 11830 | "layout(location=0) out vec4 color;\n" |
| 11831 | "void main(){\n" |
| 11832 | " color = vec4(1);\n" |
| 11833 | "}\n"; |
| 11834 | |
| 11835 | VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this); |
| 11836 | VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this); |
| 11837 | |
| 11838 | VkPipelineObj pipe(m_device); |
| 11839 | pipe.AddColorAttachment(); |
| 11840 | pipe.AddShader(&vs); |
| 11841 | pipe.AddShader(&fs); |
| 11842 | |
| 11843 | pipe.AddVertexInputBindings(&input_binding, 1); |
| 11844 | pipe.AddVertexInputAttribs(input_attribs, 2); |
| 11845 | |
| 11846 | VkDescriptorSetObj descriptorSet(m_device); |
| 11847 | descriptorSet.AppendDummy(); |
| 11848 | descriptorSet.CreateVKDescriptorSet(m_commandBuffer); |
| 11849 | |
| 11850 | pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass()); |
| 11851 | |
| 11852 | /* expect success */ |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 11853 | m_errorMonitor->VerifyNotFound(); |
Chris Forbes | 2682b24 | 2015-11-24 11:13:14 +1300 | [diff] [blame] | 11854 | } |
| 11855 | |
Chris Forbes | 2682b24 | 2015-11-24 11:13:14 +1300 | [diff] [blame] | 11856 | TEST_F(VkLayerTest, CreatePipelineAttribArrayType) |
| 11857 | { |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 11858 | m_errorMonitor->ExpectSuccess(); |
Chris Forbes | 2682b24 | 2015-11-24 11:13:14 +1300 | [diff] [blame] | 11859 | |
| 11860 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 11861 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 11862 | |
| 11863 | VkVertexInputBindingDescription input_binding; |
| 11864 | memset(&input_binding, 0, sizeof(input_binding)); |
| 11865 | |
| 11866 | VkVertexInputAttributeDescription input_attribs[2]; |
| 11867 | memset(input_attribs, 0, sizeof(input_attribs)); |
| 11868 | |
| 11869 | for (int i = 0; i < 2; i++) { |
| 11870 | input_attribs[i].format = VK_FORMAT_R32G32B32A32_SFLOAT; |
| 11871 | input_attribs[i].location = i; |
| 11872 | } |
| 11873 | |
| 11874 | char const *vsSource = |
Chris Forbes | 3846771 | 2016-04-04 17:28:05 +1200 | [diff] [blame] | 11875 | "#version 450\n" |
Chris Forbes | 2682b24 | 2015-11-24 11:13:14 +1300 | [diff] [blame] | 11876 | "\n" |
| 11877 | "layout(location=0) in vec4 x[2];\n" |
Tony Barbour | e804d20 | 2016-01-05 13:37:45 -0700 | [diff] [blame] | 11878 | "out gl_PerVertex {\n" |
| 11879 | " vec4 gl_Position;\n" |
| 11880 | "};\n" |
Chris Forbes | 2682b24 | 2015-11-24 11:13:14 +1300 | [diff] [blame] | 11881 | "void main(){\n" |
| 11882 | " gl_Position = x[0] + x[1];\n" |
| 11883 | "}\n"; |
| 11884 | char const *fsSource = |
Chris Forbes | 3846771 | 2016-04-04 17:28:05 +1200 | [diff] [blame] | 11885 | "#version 450\n" |
Chris Forbes | 2682b24 | 2015-11-24 11:13:14 +1300 | [diff] [blame] | 11886 | "\n" |
| 11887 | "layout(location=0) out vec4 color;\n" |
| 11888 | "void main(){\n" |
| 11889 | " color = vec4(1);\n" |
| 11890 | "}\n"; |
| 11891 | |
| 11892 | VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this); |
| 11893 | VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this); |
| 11894 | |
| 11895 | VkPipelineObj pipe(m_device); |
| 11896 | pipe.AddColorAttachment(); |
| 11897 | pipe.AddShader(&vs); |
| 11898 | pipe.AddShader(&fs); |
| 11899 | |
| 11900 | pipe.AddVertexInputBindings(&input_binding, 1); |
| 11901 | pipe.AddVertexInputAttribs(input_attribs, 2); |
| 11902 | |
| 11903 | VkDescriptorSetObj descriptorSet(m_device); |
| 11904 | descriptorSet.AppendDummy(); |
| 11905 | descriptorSet.CreateVKDescriptorSet(m_commandBuffer); |
| 11906 | |
| 11907 | pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass()); |
| 11908 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 11909 | m_errorMonitor->VerifyNotFound(); |
Chris Forbes | 2682b24 | 2015-11-24 11:13:14 +1300 | [diff] [blame] | 11910 | } |
Chris Forbes | 2682b24 | 2015-11-24 11:13:14 +1300 | [diff] [blame] | 11911 | |
Chris Forbes | bc290ce | 2016-07-06 12:01:49 +1200 | [diff] [blame] | 11912 | TEST_F(VkLayerTest, CreatePipelineAttribComponents) |
| 11913 | { |
| 11914 | m_errorMonitor->ExpectSuccess(); |
| 11915 | |
| 11916 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 11917 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 11918 | |
| 11919 | VkVertexInputBindingDescription input_binding; |
| 11920 | memset(&input_binding, 0, sizeof(input_binding)); |
| 11921 | |
| 11922 | VkVertexInputAttributeDescription input_attribs[3]; |
| 11923 | memset(input_attribs, 0, sizeof(input_attribs)); |
| 11924 | |
| 11925 | for (int i = 0; i < 3; i++) { |
| 11926 | input_attribs[i].format = VK_FORMAT_R32G32B32A32_SFLOAT; |
| 11927 | input_attribs[i].location = i; |
| 11928 | } |
| 11929 | |
| 11930 | char const *vsSource = |
| 11931 | "#version 450\n" |
| 11932 | "\n" |
| 11933 | "layout(location=0) in vec4 x;\n" |
| 11934 | "layout(location=1) in vec3 y1;\n" |
| 11935 | "layout(location=1, component=3) in float y2;\n" |
| 11936 | "layout(location=2) in vec4 z;\n" |
| 11937 | "out gl_PerVertex {\n" |
| 11938 | " vec4 gl_Position;\n" |
| 11939 | "};\n" |
| 11940 | "void main(){\n" |
| 11941 | " gl_Position = x + vec4(y1, y2) + z;\n" |
| 11942 | "}\n"; |
| 11943 | char const *fsSource = |
| 11944 | "#version 450\n" |
| 11945 | "\n" |
| 11946 | "layout(location=0) out vec4 color;\n" |
| 11947 | "void main(){\n" |
| 11948 | " color = vec4(1);\n" |
| 11949 | "}\n"; |
| 11950 | |
| 11951 | VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this); |
| 11952 | VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this); |
| 11953 | |
| 11954 | VkPipelineObj pipe(m_device); |
| 11955 | pipe.AddColorAttachment(); |
| 11956 | pipe.AddShader(&vs); |
| 11957 | pipe.AddShader(&fs); |
| 11958 | |
| 11959 | pipe.AddVertexInputBindings(&input_binding, 1); |
| 11960 | pipe.AddVertexInputAttribs(input_attribs, 3); |
| 11961 | |
| 11962 | VkDescriptorSetObj descriptorSet(m_device); |
| 11963 | descriptorSet.AppendDummy(); |
| 11964 | descriptorSet.CreateVKDescriptorSet(m_commandBuffer); |
| 11965 | |
| 11966 | pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass()); |
| 11967 | |
| 11968 | m_errorMonitor->VerifyNotFound(); |
| 11969 | } |
| 11970 | |
Chris Forbes | 4ea14fc | 2016-04-04 18:52:54 +1200 | [diff] [blame] | 11971 | TEST_F(VkLayerTest, CreatePipelineSimplePositive) |
| 11972 | { |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 11973 | m_errorMonitor->ExpectSuccess(); |
Chris Forbes | 4ea14fc | 2016-04-04 18:52:54 +1200 | [diff] [blame] | 11974 | |
| 11975 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 11976 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 11977 | |
| 11978 | char const *vsSource = |
| 11979 | "#version 450\n" |
| 11980 | "out gl_PerVertex {\n" |
| 11981 | " vec4 gl_Position;\n" |
| 11982 | "};\n" |
| 11983 | "void main(){\n" |
| 11984 | " gl_Position = vec4(0);\n" |
| 11985 | "}\n"; |
| 11986 | char const *fsSource = |
| 11987 | "#version 450\n" |
| 11988 | "\n" |
| 11989 | "layout(location=0) out vec4 color;\n" |
| 11990 | "void main(){\n" |
| 11991 | " color = vec4(1);\n" |
| 11992 | "}\n"; |
| 11993 | |
| 11994 | VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this); |
| 11995 | VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this); |
| 11996 | |
| 11997 | VkPipelineObj pipe(m_device); |
| 11998 | pipe.AddColorAttachment(); |
| 11999 | pipe.AddShader(&vs); |
| 12000 | pipe.AddShader(&fs); |
| 12001 | |
| 12002 | VkDescriptorSetObj descriptorSet(m_device); |
| 12003 | descriptorSet.AppendDummy(); |
| 12004 | descriptorSet.CreateVKDescriptorSet(m_commandBuffer); |
| 12005 | |
| 12006 | pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass()); |
| 12007 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 12008 | m_errorMonitor->VerifyNotFound(); |
Chris Forbes | 4ea14fc | 2016-04-04 18:52:54 +1200 | [diff] [blame] | 12009 | } |
| 12010 | |
Chris Forbes | 912c919 | 2016-04-05 17:50:35 +1200 | [diff] [blame] | 12011 | TEST_F(VkLayerTest, CreatePipelineRelaxedTypeMatch) |
| 12012 | { |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 12013 | m_errorMonitor->ExpectSuccess(); |
Chris Forbes | 912c919 | 2016-04-05 17:50:35 +1200 | [diff] [blame] | 12014 | |
| 12015 | // VK 1.0.8 Specification, 14.1.3 "Additionally,..." block |
| 12016 | |
| 12017 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 12018 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 12019 | |
| 12020 | char const *vsSource = |
| 12021 | "#version 450\n" |
| 12022 | "out gl_PerVertex {\n" |
| 12023 | " vec4 gl_Position;\n" |
| 12024 | "};\n" |
| 12025 | "layout(location=0) out vec3 x;\n" |
| 12026 | "layout(location=1) out ivec3 y;\n" |
| 12027 | "layout(location=2) out vec3 z;\n" |
| 12028 | "void main(){\n" |
| 12029 | " gl_Position = vec4(0);\n" |
| 12030 | " x = vec3(0); y = ivec3(0); z = vec3(0);\n" |
| 12031 | "}\n"; |
| 12032 | char const *fsSource = |
| 12033 | "#version 450\n" |
| 12034 | "\n" |
| 12035 | "layout(location=0) out vec4 color;\n" |
| 12036 | "layout(location=0) in float x;\n" |
| 12037 | "layout(location=1) flat in int y;\n" |
| 12038 | "layout(location=2) in vec2 z;\n" |
| 12039 | "void main(){\n" |
| 12040 | " color = vec4(1 + x + y + z.x);\n" |
| 12041 | "}\n"; |
| 12042 | |
| 12043 | VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this); |
| 12044 | VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this); |
| 12045 | |
| 12046 | VkPipelineObj pipe(m_device); |
| 12047 | pipe.AddColorAttachment(); |
| 12048 | pipe.AddShader(&vs); |
| 12049 | pipe.AddShader(&fs); |
| 12050 | |
| 12051 | VkDescriptorSetObj descriptorSet(m_device); |
| 12052 | descriptorSet.AppendDummy(); |
| 12053 | descriptorSet.CreateVKDescriptorSet(m_commandBuffer); |
| 12054 | |
Mike Stroyan | 255e958 | 2016-06-24 09:49:32 -0600 | [diff] [blame] | 12055 | VkResult err = VK_SUCCESS; |
| 12056 | err = |
| 12057 | pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass()); |
| 12058 | ASSERT_VK_SUCCESS(err); |
| 12059 | |
Chris Forbes | 912c919 | 2016-04-05 17:50:35 +1200 | [diff] [blame] | 12060 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 12061 | m_errorMonitor->VerifyNotFound(); |
Chris Forbes | 912c919 | 2016-04-05 17:50:35 +1200 | [diff] [blame] | 12062 | } |
| 12063 | |
Chris Forbes | 4ea14fc | 2016-04-04 18:52:54 +1200 | [diff] [blame] | 12064 | TEST_F(VkLayerTest, CreatePipelineTessPerVertex) |
| 12065 | { |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 12066 | m_errorMonitor->ExpectSuccess(); |
Chris Forbes | 4ea14fc | 2016-04-04 18:52:54 +1200 | [diff] [blame] | 12067 | |
| 12068 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 12069 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 12070 | |
Chris Forbes | c1e852d | 2016-04-04 19:26:42 +1200 | [diff] [blame] | 12071 | if (!m_device->phy().features().tessellationShader) { |
| 12072 | printf("Device does not support tessellation shaders; skipped.\n"); |
| 12073 | return; |
| 12074 | } |
| 12075 | |
Chris Forbes | 4ea14fc | 2016-04-04 18:52:54 +1200 | [diff] [blame] | 12076 | char const *vsSource = |
| 12077 | "#version 450\n" |
| 12078 | "void main(){}\n"; |
| 12079 | char const *tcsSource = |
| 12080 | "#version 450\n" |
| 12081 | "layout(location=0) out int x[];\n" |
| 12082 | "layout(vertices=3) out;\n" |
| 12083 | "void main(){\n" |
| 12084 | " gl_TessLevelOuter[0] = gl_TessLevelOuter[1] = gl_TessLevelOuter[2] = 1;\n" |
| 12085 | " gl_TessLevelInner[0] = 1;\n" |
| 12086 | " x[gl_InvocationID] = gl_InvocationID;\n" |
| 12087 | "}\n"; |
| 12088 | char const *tesSource = |
| 12089 | "#version 450\n" |
| 12090 | "layout(triangles, equal_spacing, cw) in;\n" |
| 12091 | "layout(location=0) in int x[];\n" |
| 12092 | "out gl_PerVertex { vec4 gl_Position; };\n" |
| 12093 | "void main(){\n" |
| 12094 | " gl_Position.xyz = gl_TessCoord;\n" |
| 12095 | " gl_Position.w = x[0] + x[1] + x[2];\n" |
| 12096 | "}\n"; |
| 12097 | char const *fsSource = |
| 12098 | "#version 450\n" |
| 12099 | "layout(location=0) out vec4 color;\n" |
| 12100 | "void main(){\n" |
| 12101 | " color = vec4(1);\n" |
| 12102 | "}\n"; |
| 12103 | |
| 12104 | VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this); |
| 12105 | VkShaderObj tcs(m_device, tcsSource, VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT, this); |
| 12106 | VkShaderObj tes(m_device, tesSource, VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT, this); |
| 12107 | VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this); |
| 12108 | |
| 12109 | VkPipelineInputAssemblyStateCreateInfo iasci{ |
| 12110 | VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO, |
| 12111 | nullptr, |
| 12112 | 0, |
| 12113 | VK_PRIMITIVE_TOPOLOGY_PATCH_LIST, |
| 12114 | VK_FALSE}; |
| 12115 | |
Chris Forbes | b4cacb6 | 2016-04-04 19:15:00 +1200 | [diff] [blame] | 12116 | VkPipelineTessellationStateCreateInfo tsci{ |
| 12117 | VK_STRUCTURE_TYPE_PIPELINE_TESSELLATION_STATE_CREATE_INFO, |
| 12118 | nullptr, |
| 12119 | 0, |
| 12120 | 3}; |
| 12121 | |
Chris Forbes | 4ea14fc | 2016-04-04 18:52:54 +1200 | [diff] [blame] | 12122 | VkPipelineObj pipe(m_device); |
| 12123 | pipe.SetInputAssembly(&iasci); |
Chris Forbes | b4cacb6 | 2016-04-04 19:15:00 +1200 | [diff] [blame] | 12124 | pipe.SetTessellation(&tsci); |
Chris Forbes | 4ea14fc | 2016-04-04 18:52:54 +1200 | [diff] [blame] | 12125 | pipe.AddColorAttachment(); |
| 12126 | pipe.AddShader(&vs); |
| 12127 | pipe.AddShader(&tcs); |
| 12128 | pipe.AddShader(&tes); |
| 12129 | pipe.AddShader(&fs); |
| 12130 | |
| 12131 | VkDescriptorSetObj descriptorSet(m_device); |
| 12132 | descriptorSet.AppendDummy(); |
| 12133 | descriptorSet.CreateVKDescriptorSet(m_commandBuffer); |
| 12134 | |
| 12135 | pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass()); |
| 12136 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 12137 | m_errorMonitor->VerifyNotFound(); |
Chris Forbes | 4ea14fc | 2016-04-04 18:52:54 +1200 | [diff] [blame] | 12138 | } |
| 12139 | |
Chris Forbes | a0ab815 | 2016-04-20 13:34:27 +1200 | [diff] [blame] | 12140 | TEST_F(VkLayerTest, CreatePipelineGeometryInputBlockPositive) |
| 12141 | { |
| 12142 | m_errorMonitor->ExpectSuccess(); |
| 12143 | |
| 12144 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 12145 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 12146 | |
| 12147 | if (!m_device->phy().features().geometryShader) { |
| 12148 | printf("Device does not support geometry shaders; skipped.\n"); |
| 12149 | return; |
| 12150 | } |
| 12151 | |
| 12152 | char const *vsSource = |
| 12153 | "#version 450\n" |
| 12154 | "layout(location=0) out VertexData { vec4 x; } vs_out;\n" |
| 12155 | "void main(){\n" |
| 12156 | " vs_out.x = vec4(1);\n" |
| 12157 | "}\n"; |
| 12158 | char const *gsSource = |
| 12159 | "#version 450\n" |
| 12160 | "layout(triangles) in;\n" |
| 12161 | "layout(triangle_strip, max_vertices=3) out;\n" |
| 12162 | "layout(location=0) in VertexData { vec4 x; } gs_in[];\n" |
| 12163 | "out gl_PerVertex { vec4 gl_Position; };\n" |
| 12164 | "void main() {\n" |
| 12165 | " gl_Position = gs_in[0].x;\n" |
| 12166 | " EmitVertex();\n" |
| 12167 | "}\n"; |
| 12168 | char const *fsSource = |
| 12169 | "#version 450\n" |
| 12170 | "layout(location=0) out vec4 color;\n" |
| 12171 | "void main(){\n" |
| 12172 | " color = vec4(1);\n" |
| 12173 | "}\n"; |
| 12174 | |
| 12175 | VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this); |
| 12176 | VkShaderObj gs(m_device, gsSource, VK_SHADER_STAGE_GEOMETRY_BIT, this); |
| 12177 | VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this); |
| 12178 | |
| 12179 | VkPipelineObj pipe(m_device); |
| 12180 | pipe.AddColorAttachment(); |
| 12181 | pipe.AddShader(&vs); |
| 12182 | pipe.AddShader(&gs); |
| 12183 | pipe.AddShader(&fs); |
| 12184 | |
| 12185 | VkDescriptorSetObj descriptorSet(m_device); |
| 12186 | descriptorSet.AppendDummy(); |
| 12187 | descriptorSet.CreateVKDescriptorSet(m_commandBuffer); |
| 12188 | |
| 12189 | pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass()); |
| 12190 | |
| 12191 | m_errorMonitor->VerifyNotFound(); |
| 12192 | } |
| 12193 | |
Chris Forbes | a0193bc | 2016-04-04 19:19:47 +1200 | [diff] [blame] | 12194 | TEST_F(VkLayerTest, CreatePipelineTessPatchDecorationMismatch) |
| 12195 | { |
| 12196 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 12197 | "is per-vertex in tessellation control shader stage " |
| 12198 | "but per-patch in tessellation evaluation shader stage"); |
| 12199 | |
| 12200 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 12201 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 12202 | |
Chris Forbes | c1e852d | 2016-04-04 19:26:42 +1200 | [diff] [blame] | 12203 | if (!m_device->phy().features().tessellationShader) { |
| 12204 | printf("Device does not support tessellation shaders; skipped.\n"); |
| 12205 | return; |
| 12206 | } |
| 12207 | |
Chris Forbes | a0193bc | 2016-04-04 19:19:47 +1200 | [diff] [blame] | 12208 | char const *vsSource = |
| 12209 | "#version 450\n" |
| 12210 | "void main(){}\n"; |
| 12211 | char const *tcsSource = |
| 12212 | "#version 450\n" |
| 12213 | "layout(location=0) out int x[];\n" |
| 12214 | "layout(vertices=3) out;\n" |
| 12215 | "void main(){\n" |
| 12216 | " gl_TessLevelOuter[0] = gl_TessLevelOuter[1] = gl_TessLevelOuter[2] = 1;\n" |
| 12217 | " gl_TessLevelInner[0] = 1;\n" |
| 12218 | " x[gl_InvocationID] = gl_InvocationID;\n" |
| 12219 | "}\n"; |
| 12220 | char const *tesSource = |
| 12221 | "#version 450\n" |
| 12222 | "layout(triangles, equal_spacing, cw) in;\n" |
| 12223 | "layout(location=0) patch in int x;\n" |
| 12224 | "out gl_PerVertex { vec4 gl_Position; };\n" |
| 12225 | "void main(){\n" |
| 12226 | " gl_Position.xyz = gl_TessCoord;\n" |
| 12227 | " gl_Position.w = x;\n" |
| 12228 | "}\n"; |
| 12229 | char const *fsSource = |
| 12230 | "#version 450\n" |
| 12231 | "layout(location=0) out vec4 color;\n" |
| 12232 | "void main(){\n" |
| 12233 | " color = vec4(1);\n" |
| 12234 | "}\n"; |
| 12235 | |
| 12236 | VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this); |
| 12237 | VkShaderObj tcs(m_device, tcsSource, VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT, this); |
| 12238 | VkShaderObj tes(m_device, tesSource, VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT, this); |
| 12239 | VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this); |
| 12240 | |
| 12241 | VkPipelineInputAssemblyStateCreateInfo iasci{ |
| 12242 | VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO, |
| 12243 | nullptr, |
| 12244 | 0, |
| 12245 | VK_PRIMITIVE_TOPOLOGY_PATCH_LIST, |
| 12246 | VK_FALSE}; |
| 12247 | |
| 12248 | VkPipelineTessellationStateCreateInfo tsci{ |
| 12249 | VK_STRUCTURE_TYPE_PIPELINE_TESSELLATION_STATE_CREATE_INFO, |
| 12250 | nullptr, |
| 12251 | 0, |
| 12252 | 3}; |
| 12253 | |
| 12254 | VkPipelineObj pipe(m_device); |
| 12255 | pipe.SetInputAssembly(&iasci); |
| 12256 | pipe.SetTessellation(&tsci); |
| 12257 | pipe.AddColorAttachment(); |
| 12258 | pipe.AddShader(&vs); |
| 12259 | pipe.AddShader(&tcs); |
| 12260 | pipe.AddShader(&tes); |
| 12261 | pipe.AddShader(&fs); |
| 12262 | |
| 12263 | VkDescriptorSetObj descriptorSet(m_device); |
| 12264 | descriptorSet.AppendDummy(); |
| 12265 | descriptorSet.CreateVKDescriptorSet(m_commandBuffer); |
| 12266 | |
| 12267 | pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass()); |
| 12268 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 12269 | m_errorMonitor->VerifyFound(); |
Chris Forbes | a0193bc | 2016-04-04 19:19:47 +1200 | [diff] [blame] | 12270 | } |
| 12271 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12272 | TEST_F(VkLayerTest, CreatePipelineAttribBindingConflict) { |
| 12273 | m_errorMonitor->SetDesiredFailureMsg( |
| 12274 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 12275 | "Duplicate vertex input binding descriptions for binding 0"); |
| 12276 | |
Chris Forbes | 280ba2c | 2015-06-12 11:16:41 +1200 | [diff] [blame] | 12277 | ASSERT_NO_FATAL_FAILURE(InitState()); |
Tobin Ehlis | c9ac2b6 | 2015-09-11 12:57:55 -0600 | [diff] [blame] | 12278 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
Chris Forbes | 280ba2c | 2015-06-12 11:16:41 +1200 | [diff] [blame] | 12279 | |
| 12280 | /* Two binding descriptions for binding 0 */ |
| 12281 | VkVertexInputBindingDescription input_bindings[2]; |
| 12282 | memset(input_bindings, 0, sizeof(input_bindings)); |
| 12283 | |
| 12284 | VkVertexInputAttributeDescription input_attrib; |
| 12285 | memset(&input_attrib, 0, sizeof(input_attrib)); |
| 12286 | input_attrib.format = VK_FORMAT_R32_SFLOAT; |
| 12287 | |
| 12288 | char const *vsSource = |
Chris Forbes | 3846771 | 2016-04-04 17:28:05 +1200 | [diff] [blame] | 12289 | "#version 450\n" |
Chris Forbes | 280ba2c | 2015-06-12 11:16:41 +1200 | [diff] [blame] | 12290 | "\n" |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12291 | "layout(location=0) in float x;\n" /* attrib provided float */ |
Tony Barbour | e804d20 | 2016-01-05 13:37:45 -0700 | [diff] [blame] | 12292 | "out gl_PerVertex {\n" |
| 12293 | " vec4 gl_Position;\n" |
| 12294 | "};\n" |
Chris Forbes | 280ba2c | 2015-06-12 11:16:41 +1200 | [diff] [blame] | 12295 | "void main(){\n" |
| 12296 | " gl_Position = vec4(x);\n" |
| 12297 | "}\n"; |
| 12298 | char const *fsSource = |
Chris Forbes | 3846771 | 2016-04-04 17:28:05 +1200 | [diff] [blame] | 12299 | "#version 450\n" |
Chris Forbes | 280ba2c | 2015-06-12 11:16:41 +1200 | [diff] [blame] | 12300 | "\n" |
| 12301 | "layout(location=0) out vec4 color;\n" |
| 12302 | "void main(){\n" |
| 12303 | " color = vec4(1);\n" |
| 12304 | "}\n"; |
| 12305 | |
Courtney Goeltzenleuchter | d263550 | 2015-10-21 17:08:06 -0600 | [diff] [blame] | 12306 | VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this); |
| 12307 | VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this); |
Chris Forbes | 280ba2c | 2015-06-12 11:16:41 +1200 | [diff] [blame] | 12308 | |
| 12309 | VkPipelineObj pipe(m_device); |
Chia-I Wu | 08accc6 | 2015-07-07 11:50:03 +0800 | [diff] [blame] | 12310 | pipe.AddColorAttachment(); |
Chris Forbes | 280ba2c | 2015-06-12 11:16:41 +1200 | [diff] [blame] | 12311 | pipe.AddShader(&vs); |
| 12312 | pipe.AddShader(&fs); |
| 12313 | |
| 12314 | pipe.AddVertexInputBindings(input_bindings, 2); |
| 12315 | pipe.AddVertexInputAttribs(&input_attrib, 1); |
| 12316 | |
Chris Forbes | 280ba2c | 2015-06-12 11:16:41 +1200 | [diff] [blame] | 12317 | VkDescriptorSetObj descriptorSet(m_device); |
| 12318 | descriptorSet.AppendDummy(); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 12319 | descriptorSet.CreateVKDescriptorSet(m_commandBuffer); |
Chris Forbes | 280ba2c | 2015-06-12 11:16:41 +1200 | [diff] [blame] | 12320 | |
Tony Barbour | 5781e8f | 2015-08-04 16:23:11 -0600 | [diff] [blame] | 12321 | pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass()); |
Chris Forbes | 280ba2c | 2015-06-12 11:16:41 +1200 | [diff] [blame] | 12322 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 12323 | m_errorMonitor->VerifyFound(); |
Chris Forbes | 280ba2c | 2015-06-12 11:16:41 +1200 | [diff] [blame] | 12324 | } |
Chris Forbes | 8f68b56 | 2015-05-25 11:13:32 +1200 | [diff] [blame] | 12325 | |
Chris Forbes | 35efec7 | 2016-04-21 14:32:08 +1200 | [diff] [blame] | 12326 | TEST_F(VkLayerTest, CreatePipeline64BitAttributesPositive) { |
| 12327 | m_errorMonitor->ExpectSuccess(); |
| 12328 | |
| 12329 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 12330 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 12331 | |
Chris Forbes | 91cf3a8 | 2016-06-28 17:51:35 +1200 | [diff] [blame] | 12332 | if (!m_device->phy().features().shaderFloat64) { |
Chris Forbes | 35efec7 | 2016-04-21 14:32:08 +1200 | [diff] [blame] | 12333 | printf("Device does not support 64bit vertex attributes; skipped.\n"); |
| 12334 | return; |
| 12335 | } |
| 12336 | |
| 12337 | VkVertexInputBindingDescription input_bindings[1]; |
| 12338 | memset(input_bindings, 0, sizeof(input_bindings)); |
| 12339 | |
| 12340 | VkVertexInputAttributeDescription input_attribs[4]; |
| 12341 | memset(input_attribs, 0, sizeof(input_attribs)); |
| 12342 | input_attribs[0].location = 0; |
| 12343 | input_attribs[0].offset = 0; |
| 12344 | input_attribs[0].format = VK_FORMAT_R64G64B64A64_SFLOAT; |
| 12345 | input_attribs[1].location = 2; |
| 12346 | input_attribs[1].offset = 32; |
| 12347 | input_attribs[1].format = VK_FORMAT_R64G64B64A64_SFLOAT; |
| 12348 | input_attribs[2].location = 4; |
| 12349 | input_attribs[2].offset = 64; |
| 12350 | input_attribs[2].format = VK_FORMAT_R64G64B64A64_SFLOAT; |
| 12351 | input_attribs[3].location = 6; |
| 12352 | input_attribs[3].offset = 96; |
| 12353 | input_attribs[3].format = VK_FORMAT_R64G64B64A64_SFLOAT; |
| 12354 | |
| 12355 | char const *vsSource = |
| 12356 | "#version 450\n" |
| 12357 | "\n" |
| 12358 | "layout(location=0) in dmat4 x;\n" |
| 12359 | "out gl_PerVertex {\n" |
| 12360 | " vec4 gl_Position;\n" |
| 12361 | "};\n" |
| 12362 | "void main(){\n" |
| 12363 | " gl_Position = vec4(x[0][0]);\n" |
| 12364 | "}\n"; |
| 12365 | char const *fsSource = |
| 12366 | "#version 450\n" |
| 12367 | "\n" |
| 12368 | "layout(location=0) out vec4 color;\n" |
| 12369 | "void main(){\n" |
| 12370 | " color = vec4(1);\n" |
| 12371 | "}\n"; |
| 12372 | |
| 12373 | VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this); |
| 12374 | VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this); |
| 12375 | |
| 12376 | VkPipelineObj pipe(m_device); |
| 12377 | pipe.AddColorAttachment(); |
| 12378 | pipe.AddShader(&vs); |
| 12379 | pipe.AddShader(&fs); |
| 12380 | |
| 12381 | pipe.AddVertexInputBindings(input_bindings, 1); |
| 12382 | pipe.AddVertexInputAttribs(input_attribs, 4); |
| 12383 | |
| 12384 | VkDescriptorSetObj descriptorSet(m_device); |
| 12385 | descriptorSet.AppendDummy(); |
| 12386 | descriptorSet.CreateVKDescriptorSet(m_commandBuffer); |
| 12387 | |
| 12388 | pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass()); |
| 12389 | |
| 12390 | m_errorMonitor->VerifyNotFound(); |
| 12391 | } |
| 12392 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12393 | TEST_F(VkLayerTest, CreatePipelineFragmentOutputNotWritten) { |
Courtney Goeltzenleuchter | 7415d5a | 2015-12-09 15:48:16 -0700 | [diff] [blame] | 12394 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12395 | "Attachment 0 not written by FS"); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 12396 | |
Chris Forbes | 4d6d1e5 | 2015-05-25 11:13:40 +1200 | [diff] [blame] | 12397 | ASSERT_NO_FATAL_FAILURE(InitState()); |
Chris Forbes | 4d6d1e5 | 2015-05-25 11:13:40 +1200 | [diff] [blame] | 12398 | |
| 12399 | char const *vsSource = |
Chris Forbes | 3846771 | 2016-04-04 17:28:05 +1200 | [diff] [blame] | 12400 | "#version 450\n" |
Chris Forbes | 4d6d1e5 | 2015-05-25 11:13:40 +1200 | [diff] [blame] | 12401 | "\n" |
Tony Barbour | e804d20 | 2016-01-05 13:37:45 -0700 | [diff] [blame] | 12402 | "out gl_PerVertex {\n" |
| 12403 | " vec4 gl_Position;\n" |
| 12404 | "};\n" |
Chris Forbes | 4d6d1e5 | 2015-05-25 11:13:40 +1200 | [diff] [blame] | 12405 | "void main(){\n" |
| 12406 | " gl_Position = vec4(1);\n" |
| 12407 | "}\n"; |
| 12408 | char const *fsSource = |
Chris Forbes | 3846771 | 2016-04-04 17:28:05 +1200 | [diff] [blame] | 12409 | "#version 450\n" |
Chris Forbes | 4d6d1e5 | 2015-05-25 11:13:40 +1200 | [diff] [blame] | 12410 | "\n" |
| 12411 | "void main(){\n" |
| 12412 | "}\n"; |
| 12413 | |
Courtney Goeltzenleuchter | d263550 | 2015-10-21 17:08:06 -0600 | [diff] [blame] | 12414 | VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this); |
| 12415 | VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this); |
Chris Forbes | 4d6d1e5 | 2015-05-25 11:13:40 +1200 | [diff] [blame] | 12416 | |
| 12417 | VkPipelineObj pipe(m_device); |
| 12418 | pipe.AddShader(&vs); |
| 12419 | pipe.AddShader(&fs); |
| 12420 | |
Chia-I Wu | 08accc6 | 2015-07-07 11:50:03 +0800 | [diff] [blame] | 12421 | /* set up CB 0, not written */ |
| 12422 | pipe.AddColorAttachment(); |
| 12423 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
Chris Forbes | 4d6d1e5 | 2015-05-25 11:13:40 +1200 | [diff] [blame] | 12424 | |
Chris Forbes | 4d6d1e5 | 2015-05-25 11:13:40 +1200 | [diff] [blame] | 12425 | VkDescriptorSetObj descriptorSet(m_device); |
| 12426 | descriptorSet.AppendDummy(); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 12427 | descriptorSet.CreateVKDescriptorSet(m_commandBuffer); |
Chris Forbes | 4d6d1e5 | 2015-05-25 11:13:40 +1200 | [diff] [blame] | 12428 | |
Tony Barbour | 5781e8f | 2015-08-04 16:23:11 -0600 | [diff] [blame] | 12429 | pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass()); |
Chris Forbes | 4d6d1e5 | 2015-05-25 11:13:40 +1200 | [diff] [blame] | 12430 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 12431 | m_errorMonitor->VerifyFound(); |
Chris Forbes | 4d6d1e5 | 2015-05-25 11:13:40 +1200 | [diff] [blame] | 12432 | } |
| 12433 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12434 | TEST_F(VkLayerTest, CreatePipelineFragmentOutputNotConsumed) { |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12435 | m_errorMonitor->SetDesiredFailureMsg( |
Mark Lobodzinski | 510e20d | 2016-02-11 09:26:16 -0700 | [diff] [blame] | 12436 | VK_DEBUG_REPORT_WARNING_BIT_EXT, |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 12437 | "FS writes to output location 1 with no matching attachment"); |
| 12438 | |
Chris Forbes | f3fffaa | 2015-05-25 11:13:43 +1200 | [diff] [blame] | 12439 | ASSERT_NO_FATAL_FAILURE(InitState()); |
Chris Forbes | f3fffaa | 2015-05-25 11:13:43 +1200 | [diff] [blame] | 12440 | |
| 12441 | char const *vsSource = |
Chris Forbes | 3846771 | 2016-04-04 17:28:05 +1200 | [diff] [blame] | 12442 | "#version 450\n" |
Chris Forbes | f3fffaa | 2015-05-25 11:13:43 +1200 | [diff] [blame] | 12443 | "\n" |
Tony Barbour | e804d20 | 2016-01-05 13:37:45 -0700 | [diff] [blame] | 12444 | "out gl_PerVertex {\n" |
| 12445 | " vec4 gl_Position;\n" |
| 12446 | "};\n" |
Chris Forbes | f3fffaa | 2015-05-25 11:13:43 +1200 | [diff] [blame] | 12447 | "void main(){\n" |
| 12448 | " gl_Position = vec4(1);\n" |
| 12449 | "}\n"; |
| 12450 | char const *fsSource = |
Chris Forbes | 3846771 | 2016-04-04 17:28:05 +1200 | [diff] [blame] | 12451 | "#version 450\n" |
Chris Forbes | f3fffaa | 2015-05-25 11:13:43 +1200 | [diff] [blame] | 12452 | "\n" |
| 12453 | "layout(location=0) out vec4 x;\n" |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12454 | "layout(location=1) out vec4 y;\n" /* no matching attachment for this */ |
Chris Forbes | f3fffaa | 2015-05-25 11:13:43 +1200 | [diff] [blame] | 12455 | "void main(){\n" |
| 12456 | " x = vec4(1);\n" |
| 12457 | " y = vec4(1);\n" |
| 12458 | "}\n"; |
| 12459 | |
Courtney Goeltzenleuchter | d263550 | 2015-10-21 17:08:06 -0600 | [diff] [blame] | 12460 | VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this); |
| 12461 | VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this); |
Chris Forbes | f3fffaa | 2015-05-25 11:13:43 +1200 | [diff] [blame] | 12462 | |
| 12463 | VkPipelineObj pipe(m_device); |
| 12464 | pipe.AddShader(&vs); |
| 12465 | pipe.AddShader(&fs); |
| 12466 | |
Chia-I Wu | 08accc6 | 2015-07-07 11:50:03 +0800 | [diff] [blame] | 12467 | /* set up CB 0, not written */ |
| 12468 | pipe.AddColorAttachment(); |
| 12469 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
Chris Forbes | f3fffaa | 2015-05-25 11:13:43 +1200 | [diff] [blame] | 12470 | /* FS writes CB 1, but we don't configure it */ |
| 12471 | |
Chris Forbes | f3fffaa | 2015-05-25 11:13:43 +1200 | [diff] [blame] | 12472 | VkDescriptorSetObj descriptorSet(m_device); |
| 12473 | descriptorSet.AppendDummy(); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 12474 | descriptorSet.CreateVKDescriptorSet(m_commandBuffer); |
Chris Forbes | f3fffaa | 2015-05-25 11:13:43 +1200 | [diff] [blame] | 12475 | |
Tony Barbour | 5781e8f | 2015-08-04 16:23:11 -0600 | [diff] [blame] | 12476 | pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass()); |
Chris Forbes | f3fffaa | 2015-05-25 11:13:43 +1200 | [diff] [blame] | 12477 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 12478 | m_errorMonitor->VerifyFound(); |
Chris Forbes | f3fffaa | 2015-05-25 11:13:43 +1200 | [diff] [blame] | 12479 | } |
| 12480 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12481 | TEST_F(VkLayerTest, CreatePipelineFragmentOutputTypeMismatch) { |
Courtney Goeltzenleuchter | 7415d5a | 2015-12-09 15:48:16 -0700 | [diff] [blame] | 12482 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12483 | "does not match FS output type"); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 12484 | |
Chris Forbes | a36d69e | 2015-05-25 11:13:44 +1200 | [diff] [blame] | 12485 | ASSERT_NO_FATAL_FAILURE(InitState()); |
Chris Forbes | a36d69e | 2015-05-25 11:13:44 +1200 | [diff] [blame] | 12486 | |
| 12487 | char const *vsSource = |
Chris Forbes | 3846771 | 2016-04-04 17:28:05 +1200 | [diff] [blame] | 12488 | "#version 450\n" |
Chris Forbes | a36d69e | 2015-05-25 11:13:44 +1200 | [diff] [blame] | 12489 | "\n" |
Tony Barbour | e804d20 | 2016-01-05 13:37:45 -0700 | [diff] [blame] | 12490 | "out gl_PerVertex {\n" |
| 12491 | " vec4 gl_Position;\n" |
| 12492 | "};\n" |
Chris Forbes | a36d69e | 2015-05-25 11:13:44 +1200 | [diff] [blame] | 12493 | "void main(){\n" |
| 12494 | " gl_Position = vec4(1);\n" |
| 12495 | "}\n"; |
| 12496 | char const *fsSource = |
Chris Forbes | 3846771 | 2016-04-04 17:28:05 +1200 | [diff] [blame] | 12497 | "#version 450\n" |
Chris Forbes | a36d69e | 2015-05-25 11:13:44 +1200 | [diff] [blame] | 12498 | "\n" |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12499 | "layout(location=0) out ivec4 x;\n" /* not UNORM */ |
Chris Forbes | a36d69e | 2015-05-25 11:13:44 +1200 | [diff] [blame] | 12500 | "void main(){\n" |
| 12501 | " x = ivec4(1);\n" |
| 12502 | "}\n"; |
| 12503 | |
Courtney Goeltzenleuchter | d263550 | 2015-10-21 17:08:06 -0600 | [diff] [blame] | 12504 | VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this); |
| 12505 | VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this); |
Chris Forbes | a36d69e | 2015-05-25 11:13:44 +1200 | [diff] [blame] | 12506 | |
| 12507 | VkPipelineObj pipe(m_device); |
| 12508 | pipe.AddShader(&vs); |
| 12509 | pipe.AddShader(&fs); |
| 12510 | |
Chia-I Wu | 08accc6 | 2015-07-07 11:50:03 +0800 | [diff] [blame] | 12511 | /* set up CB 0; type is UNORM by default */ |
| 12512 | pipe.AddColorAttachment(); |
| 12513 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
Chris Forbes | a36d69e | 2015-05-25 11:13:44 +1200 | [diff] [blame] | 12514 | |
Chris Forbes | a36d69e | 2015-05-25 11:13:44 +1200 | [diff] [blame] | 12515 | VkDescriptorSetObj descriptorSet(m_device); |
| 12516 | descriptorSet.AppendDummy(); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 12517 | descriptorSet.CreateVKDescriptorSet(m_commandBuffer); |
Chris Forbes | a36d69e | 2015-05-25 11:13:44 +1200 | [diff] [blame] | 12518 | |
Tony Barbour | 5781e8f | 2015-08-04 16:23:11 -0600 | [diff] [blame] | 12519 | pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass()); |
Chris Forbes | a36d69e | 2015-05-25 11:13:44 +1200 | [diff] [blame] | 12520 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 12521 | m_errorMonitor->VerifyFound(); |
Chris Forbes | a36d69e | 2015-05-25 11:13:44 +1200 | [diff] [blame] | 12522 | } |
Chris Forbes | 7b1b893 | 2015-06-05 14:43:36 +1200 | [diff] [blame] | 12523 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12524 | TEST_F(VkLayerTest, CreatePipelineUniformBlockNotProvided) { |
Courtney Goeltzenleuchter | 7415d5a | 2015-12-09 15:48:16 -0700 | [diff] [blame] | 12525 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12526 | "not declared in pipeline layout"); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 12527 | |
Chris Forbes | 556c76c | 2015-08-14 12:04:59 +1200 | [diff] [blame] | 12528 | ASSERT_NO_FATAL_FAILURE(InitState()); |
Chris Forbes | 556c76c | 2015-08-14 12:04:59 +1200 | [diff] [blame] | 12529 | |
| 12530 | char const *vsSource = |
Chris Forbes | 3846771 | 2016-04-04 17:28:05 +1200 | [diff] [blame] | 12531 | "#version 450\n" |
Chris Forbes | 556c76c | 2015-08-14 12:04:59 +1200 | [diff] [blame] | 12532 | "\n" |
Tony Barbour | e804d20 | 2016-01-05 13:37:45 -0700 | [diff] [blame] | 12533 | "out gl_PerVertex {\n" |
| 12534 | " vec4 gl_Position;\n" |
| 12535 | "};\n" |
Chris Forbes | 556c76c | 2015-08-14 12:04:59 +1200 | [diff] [blame] | 12536 | "void main(){\n" |
| 12537 | " gl_Position = vec4(1);\n" |
| 12538 | "}\n"; |
| 12539 | char const *fsSource = |
Chris Forbes | 3846771 | 2016-04-04 17:28:05 +1200 | [diff] [blame] | 12540 | "#version 450\n" |
Chris Forbes | 556c76c | 2015-08-14 12:04:59 +1200 | [diff] [blame] | 12541 | "\n" |
| 12542 | "layout(location=0) out vec4 x;\n" |
| 12543 | "layout(set=0) layout(binding=0) uniform foo { int x; int y; } bar;\n" |
| 12544 | "void main(){\n" |
| 12545 | " x = vec4(bar.y);\n" |
| 12546 | "}\n"; |
| 12547 | |
Courtney Goeltzenleuchter | d263550 | 2015-10-21 17:08:06 -0600 | [diff] [blame] | 12548 | VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this); |
| 12549 | VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this); |
Chris Forbes | 556c76c | 2015-08-14 12:04:59 +1200 | [diff] [blame] | 12550 | |
Chris Forbes | 556c76c | 2015-08-14 12:04:59 +1200 | [diff] [blame] | 12551 | VkPipelineObj pipe(m_device); |
| 12552 | pipe.AddShader(&vs); |
| 12553 | pipe.AddShader(&fs); |
| 12554 | |
| 12555 | /* set up CB 0; type is UNORM by default */ |
| 12556 | pipe.AddColorAttachment(); |
| 12557 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 12558 | |
| 12559 | VkDescriptorSetObj descriptorSet(m_device); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 12560 | descriptorSet.CreateVKDescriptorSet(m_commandBuffer); |
Chris Forbes | 556c76c | 2015-08-14 12:04:59 +1200 | [diff] [blame] | 12561 | |
| 12562 | pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass()); |
| 12563 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 12564 | m_errorMonitor->VerifyFound(); |
Chris Forbes | 556c76c | 2015-08-14 12:04:59 +1200 | [diff] [blame] | 12565 | } |
| 12566 | |
Chris Forbes | 5c59e90 | 2016-02-26 16:56:09 +1300 | [diff] [blame] | 12567 | TEST_F(VkLayerTest, CreatePipelinePushConstantsNotInLayout) { |
| 12568 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 12569 | "not declared in layout"); |
| 12570 | |
| 12571 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 12572 | |
| 12573 | char const *vsSource = |
| 12574 | "#version 450\n" |
Chris Forbes | 5c59e90 | 2016-02-26 16:56:09 +1300 | [diff] [blame] | 12575 | "\n" |
| 12576 | "layout(push_constant, std430) uniform foo { float x; } consts;\n" |
| 12577 | "out gl_PerVertex {\n" |
| 12578 | " vec4 gl_Position;\n" |
| 12579 | "};\n" |
| 12580 | "void main(){\n" |
| 12581 | " gl_Position = vec4(consts.x);\n" |
| 12582 | "}\n"; |
| 12583 | char const *fsSource = |
| 12584 | "#version 450\n" |
Chris Forbes | 5c59e90 | 2016-02-26 16:56:09 +1300 | [diff] [blame] | 12585 | "\n" |
| 12586 | "layout(location=0) out vec4 x;\n" |
| 12587 | "void main(){\n" |
| 12588 | " x = vec4(1);\n" |
| 12589 | "}\n"; |
| 12590 | |
| 12591 | VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this); |
| 12592 | VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this); |
| 12593 | |
| 12594 | VkPipelineObj pipe(m_device); |
| 12595 | pipe.AddShader(&vs); |
| 12596 | pipe.AddShader(&fs); |
| 12597 | |
| 12598 | /* set up CB 0; type is UNORM by default */ |
| 12599 | pipe.AddColorAttachment(); |
| 12600 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 12601 | |
| 12602 | VkDescriptorSetObj descriptorSet(m_device); |
| 12603 | descriptorSet.CreateVKDescriptorSet(m_commandBuffer); |
| 12604 | |
| 12605 | pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass()); |
| 12606 | |
| 12607 | /* should have generated an error -- no push constant ranges provided! */ |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 12608 | m_errorMonitor->VerifyFound(); |
Chris Forbes | 5c59e90 | 2016-02-26 16:56:09 +1300 | [diff] [blame] | 12609 | } |
| 12610 | |
Chris Forbes | 10eb9ae | 2016-05-31 16:09:42 +1200 | [diff] [blame] | 12611 | TEST_F(VkLayerTest, CreateComputePipelineMissingDescriptor) { |
| 12612 | m_errorMonitor->SetDesiredFailureMsg( |
| 12613 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 12614 | "Shader uses descriptor slot 0.0"); |
| 12615 | |
| 12616 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 12617 | |
| 12618 | char const *csSource = |
| 12619 | "#version 450\n" |
| 12620 | "\n" |
| 12621 | "layout(local_size_x=1) in;\n" |
| 12622 | "layout(set=0, binding=0) buffer block { vec4 x; };\n" |
| 12623 | "void main(){\n" |
| 12624 | " x = vec4(1);\n" |
| 12625 | "}\n"; |
| 12626 | |
| 12627 | VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this); |
| 12628 | |
| 12629 | VkDescriptorSetObj descriptorSet(m_device); |
| 12630 | descriptorSet.CreateVKDescriptorSet(m_commandBuffer); |
| 12631 | |
| 12632 | VkComputePipelineCreateInfo cpci = { |
| 12633 | VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO, |
| 12634 | nullptr, 0, { |
| 12635 | VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, |
| 12636 | nullptr, 0, VK_SHADER_STAGE_COMPUTE_BIT, |
| 12637 | cs.handle(), "main", nullptr |
| 12638 | }, |
| 12639 | descriptorSet.GetPipelineLayout(), |
| 12640 | VK_NULL_HANDLE, -1 |
| 12641 | }; |
| 12642 | |
| 12643 | VkPipeline pipe; |
| 12644 | VkResult err = vkCreateComputePipelines( |
| 12645 | m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe); |
| 12646 | |
| 12647 | m_errorMonitor->VerifyFound(); |
| 12648 | |
| 12649 | if (err == VK_SUCCESS) { |
| 12650 | vkDestroyPipeline(m_device->device(), pipe, nullptr); |
| 12651 | } |
| 12652 | } |
| 12653 | |
| 12654 | TEST_F(VkLayerTest, CreateComputePipelineMissingDescriptorUnusedPositive) { |
| 12655 | m_errorMonitor->ExpectSuccess(); |
| 12656 | |
| 12657 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 12658 | |
| 12659 | char const *csSource = |
| 12660 | "#version 450\n" |
| 12661 | "\n" |
| 12662 | "layout(local_size_x=1) in;\n" |
| 12663 | "layout(set=0, binding=0) buffer block { vec4 x; };\n" |
| 12664 | "void main(){\n" |
| 12665 | " // x is not used.\n" |
| 12666 | "}\n"; |
| 12667 | |
| 12668 | VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this); |
| 12669 | |
| 12670 | VkDescriptorSetObj descriptorSet(m_device); |
| 12671 | descriptorSet.CreateVKDescriptorSet(m_commandBuffer); |
| 12672 | |
| 12673 | VkComputePipelineCreateInfo cpci = { |
| 12674 | VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO, |
| 12675 | nullptr, 0, { |
| 12676 | VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, |
| 12677 | nullptr, 0, VK_SHADER_STAGE_COMPUTE_BIT, |
| 12678 | cs.handle(), "main", nullptr |
| 12679 | }, |
| 12680 | descriptorSet.GetPipelineLayout(), |
| 12681 | VK_NULL_HANDLE, -1 |
| 12682 | }; |
| 12683 | |
| 12684 | VkPipeline pipe; |
| 12685 | VkResult err = vkCreateComputePipelines( |
| 12686 | m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe); |
| 12687 | |
| 12688 | m_errorMonitor->VerifyNotFound(); |
| 12689 | |
| 12690 | if (err == VK_SUCCESS) { |
| 12691 | vkDestroyPipeline(m_device->device(), pipe, nullptr); |
| 12692 | } |
| 12693 | } |
| 12694 | |
Mark Lobodzinski | 209b529 | 2015-09-17 09:44:05 -0600 | [diff] [blame] | 12695 | #endif // SHADER_CHECKER_TESTS |
| 12696 | |
| 12697 | #if DEVICE_LIMITS_TESTS |
Mark Young | c48c4c1 | 2016-04-11 14:26:49 -0600 | [diff] [blame] | 12698 | TEST_F(VkLayerTest, CreateImageLimitsViolationMaxWidth) { |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12699 | m_errorMonitor->SetDesiredFailureMsg( |
| 12700 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 12701 | "CreateImage extents exceed allowable limits for format"); |
Mark Lobodzinski | 6f2274e | 2015-09-22 09:33:21 -0600 | [diff] [blame] | 12702 | |
| 12703 | ASSERT_NO_FATAL_FAILURE(InitState()); |
Mark Lobodzinski | 6f2274e | 2015-09-22 09:33:21 -0600 | [diff] [blame] | 12704 | |
| 12705 | // Create an image |
| 12706 | VkImage image; |
| 12707 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12708 | const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM; |
| 12709 | const int32_t tex_width = 32; |
| 12710 | const int32_t tex_height = 32; |
Mark Lobodzinski | 6f2274e | 2015-09-22 09:33:21 -0600 | [diff] [blame] | 12711 | |
| 12712 | VkImageCreateInfo image_create_info = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12713 | image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO; |
| 12714 | image_create_info.pNext = NULL; |
| 12715 | image_create_info.imageType = VK_IMAGE_TYPE_2D; |
| 12716 | image_create_info.format = tex_format; |
| 12717 | image_create_info.extent.width = tex_width; |
Mark Lobodzinski | 6f2274e | 2015-09-22 09:33:21 -0600 | [diff] [blame] | 12718 | image_create_info.extent.height = tex_height; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12719 | image_create_info.extent.depth = 1; |
| 12720 | image_create_info.mipLevels = 1; |
| 12721 | image_create_info.arrayLayers = 1; |
| 12722 | image_create_info.samples = VK_SAMPLE_COUNT_1_BIT; |
| 12723 | image_create_info.tiling = VK_IMAGE_TILING_LINEAR; |
| 12724 | image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT; |
| 12725 | image_create_info.flags = 0; |
Mark Lobodzinski | 6f2274e | 2015-09-22 09:33:21 -0600 | [diff] [blame] | 12726 | |
| 12727 | // Introduce error by sending down a bogus width extent |
| 12728 | image_create_info.extent.width = 65536; |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 12729 | vkCreateImage(m_device->device(), &image_create_info, NULL, &image); |
Mark Lobodzinski | 6f2274e | 2015-09-22 09:33:21 -0600 | [diff] [blame] | 12730 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 12731 | m_errorMonitor->VerifyFound(); |
Mark Lobodzinski | 6f2274e | 2015-09-22 09:33:21 -0600 | [diff] [blame] | 12732 | } |
| 12733 | |
Mark Young | c48c4c1 | 2016-04-11 14:26:49 -0600 | [diff] [blame] | 12734 | TEST_F(VkLayerTest, CreateImageLimitsViolationMinWidth) { |
| 12735 | m_errorMonitor->SetDesiredFailureMsg( |
| 12736 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 12737 | "CreateImage extents is 0 for at least one required dimension"); |
| 12738 | |
| 12739 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 12740 | |
| 12741 | // Create an image |
| 12742 | VkImage image; |
| 12743 | |
| 12744 | const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM; |
| 12745 | const int32_t tex_width = 32; |
| 12746 | const int32_t tex_height = 32; |
| 12747 | |
| 12748 | VkImageCreateInfo image_create_info = {}; |
| 12749 | image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO; |
| 12750 | image_create_info.pNext = NULL; |
| 12751 | image_create_info.imageType = VK_IMAGE_TYPE_2D; |
| 12752 | image_create_info.format = tex_format; |
| 12753 | image_create_info.extent.width = tex_width; |
| 12754 | image_create_info.extent.height = tex_height; |
| 12755 | image_create_info.extent.depth = 1; |
| 12756 | image_create_info.mipLevels = 1; |
| 12757 | image_create_info.arrayLayers = 1; |
| 12758 | image_create_info.samples = VK_SAMPLE_COUNT_1_BIT; |
| 12759 | image_create_info.tiling = VK_IMAGE_TILING_LINEAR; |
| 12760 | image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT; |
| 12761 | image_create_info.flags = 0; |
| 12762 | |
| 12763 | // Introduce error by sending down a bogus width extent |
| 12764 | image_create_info.extent.width = 0; |
| 12765 | vkCreateImage(m_device->device(), &image_create_info, NULL, &image); |
| 12766 | |
| 12767 | m_errorMonitor->VerifyFound(); |
| 12768 | } |
Mark Lobodzinski | 209b529 | 2015-09-17 09:44:05 -0600 | [diff] [blame] | 12769 | #endif // DEVICE_LIMITS_TESTS |
Chris Forbes | a36d69e | 2015-05-25 11:13:44 +1200 | [diff] [blame] | 12770 | |
Tobin Ehlis | cde0889 | 2015-09-22 10:11:37 -0600 | [diff] [blame] | 12771 | #if IMAGE_TESTS |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12772 | TEST_F(VkLayerTest, InvalidImageView) { |
| 12773 | VkResult err; |
Tobin Ehlis | cde0889 | 2015-09-22 10:11:37 -0600 | [diff] [blame] | 12774 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12775 | m_errorMonitor->SetDesiredFailureMsg( |
| 12776 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 12777 | "vkCreateImageView called with baseMipLevel 10 "); |
| 12778 | |
Tobin Ehlis | cde0889 | 2015-09-22 10:11:37 -0600 | [diff] [blame] | 12779 | ASSERT_NO_FATAL_FAILURE(InitState()); |
Tobin Ehlis | cde0889 | 2015-09-22 10:11:37 -0600 | [diff] [blame] | 12780 | |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12781 | // Create an image and try to create a view with bad baseMipLevel |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12782 | VkImage image; |
Tobin Ehlis | cde0889 | 2015-09-22 10:11:37 -0600 | [diff] [blame] | 12783 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12784 | const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM; |
| 12785 | const int32_t tex_width = 32; |
| 12786 | const int32_t tex_height = 32; |
Tobin Ehlis | cde0889 | 2015-09-22 10:11:37 -0600 | [diff] [blame] | 12787 | |
| 12788 | VkImageCreateInfo image_create_info = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12789 | image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO; |
| 12790 | image_create_info.pNext = NULL; |
| 12791 | image_create_info.imageType = VK_IMAGE_TYPE_2D; |
| 12792 | image_create_info.format = tex_format; |
| 12793 | image_create_info.extent.width = tex_width; |
| 12794 | image_create_info.extent.height = tex_height; |
| 12795 | image_create_info.extent.depth = 1; |
| 12796 | image_create_info.mipLevels = 1; |
| 12797 | image_create_info.arrayLayers = 1; |
| 12798 | image_create_info.samples = VK_SAMPLE_COUNT_1_BIT; |
| 12799 | image_create_info.tiling = VK_IMAGE_TILING_LINEAR; |
| 12800 | image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT; |
| 12801 | image_create_info.flags = 0; |
Tobin Ehlis | cde0889 | 2015-09-22 10:11:37 -0600 | [diff] [blame] | 12802 | |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 12803 | err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image); |
Tobin Ehlis | cde0889 | 2015-09-22 10:11:37 -0600 | [diff] [blame] | 12804 | ASSERT_VK_SUCCESS(err); |
| 12805 | |
| 12806 | VkImageViewCreateInfo image_view_create_info = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12807 | image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO; |
| 12808 | image_view_create_info.image = image; |
| 12809 | image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D; |
| 12810 | image_view_create_info.format = tex_format; |
| 12811 | image_view_create_info.subresourceRange.layerCount = 1; |
| 12812 | image_view_create_info.subresourceRange.baseMipLevel = 10; // cause an error |
| 12813 | image_view_create_info.subresourceRange.levelCount = 1; |
| 12814 | image_view_create_info.subresourceRange.aspectMask = |
| 12815 | VK_IMAGE_ASPECT_COLOR_BIT; |
Tobin Ehlis | cde0889 | 2015-09-22 10:11:37 -0600 | [diff] [blame] | 12816 | |
| 12817 | VkImageView view; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12818 | err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, |
| 12819 | &view); |
Tobin Ehlis | cde0889 | 2015-09-22 10:11:37 -0600 | [diff] [blame] | 12820 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 12821 | m_errorMonitor->VerifyFound(); |
Tony Barbour | df4c004 | 2016-06-01 15:55:43 -0600 | [diff] [blame] | 12822 | vkDestroyImage(m_device->device(), image, NULL); |
Tobin Ehlis | cde0889 | 2015-09-22 10:11:37 -0600 | [diff] [blame] | 12823 | } |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12824 | |
Mark Young | d339ba3 | 2016-05-30 13:28:35 -0600 | [diff] [blame] | 12825 | TEST_F(VkLayerTest, CreateImageViewNoMemoryBoundToImage) { |
| 12826 | VkResult err; |
| 12827 | |
| 12828 | m_errorMonitor->SetDesiredFailureMsg( |
| 12829 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 12830 | "vkCreateImageView called with invalid memory "); |
| 12831 | |
| 12832 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 12833 | |
| 12834 | // Create an image and try to create a view with no memory backing the image |
| 12835 | VkImage image; |
| 12836 | |
| 12837 | const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM; |
| 12838 | const int32_t tex_width = 32; |
| 12839 | const int32_t tex_height = 32; |
| 12840 | |
| 12841 | VkImageCreateInfo image_create_info = {}; |
| 12842 | image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO; |
| 12843 | image_create_info.pNext = NULL; |
| 12844 | image_create_info.imageType = VK_IMAGE_TYPE_2D; |
| 12845 | image_create_info.format = tex_format; |
| 12846 | image_create_info.extent.width = tex_width; |
| 12847 | image_create_info.extent.height = tex_height; |
| 12848 | image_create_info.extent.depth = 1; |
| 12849 | image_create_info.mipLevels = 1; |
| 12850 | image_create_info.arrayLayers = 1; |
| 12851 | image_create_info.samples = VK_SAMPLE_COUNT_1_BIT; |
| 12852 | image_create_info.tiling = VK_IMAGE_TILING_LINEAR; |
| 12853 | image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT; |
| 12854 | image_create_info.flags = 0; |
| 12855 | |
| 12856 | err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image); |
| 12857 | ASSERT_VK_SUCCESS(err); |
| 12858 | |
| 12859 | VkImageViewCreateInfo image_view_create_info = {}; |
| 12860 | image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO; |
| 12861 | image_view_create_info.image = image; |
| 12862 | image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D; |
| 12863 | image_view_create_info.format = tex_format; |
| 12864 | image_view_create_info.subresourceRange.layerCount = 1; |
| 12865 | image_view_create_info.subresourceRange.baseMipLevel = 0; |
| 12866 | image_view_create_info.subresourceRange.levelCount = 1; |
| 12867 | image_view_create_info.subresourceRange.aspectMask = |
| 12868 | VK_IMAGE_ASPECT_COLOR_BIT; |
| 12869 | |
| 12870 | VkImageView view; |
| 12871 | err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, |
| 12872 | &view); |
| 12873 | |
| 12874 | m_errorMonitor->VerifyFound(); |
| 12875 | vkDestroyImage(m_device->device(), image, NULL); |
| 12876 | // If last error is success, it still created the view, so delete it. |
| 12877 | if (err == VK_SUCCESS) { |
| 12878 | vkDestroyImageView(m_device->device(), view, NULL); |
| 12879 | } |
| 12880 | |
| 12881 | } |
| 12882 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12883 | TEST_F(VkLayerTest, InvalidImageViewAspect) { |
Tobin Ehlis | 1f567a2 | 2016-05-25 16:15:18 -0600 | [diff] [blame] | 12884 | TEST_DESCRIPTION( |
| 12885 | "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] | 12886 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12887 | "vkCreateImageView: Color image " |
| 12888 | "formats must have ONLY the " |
| 12889 | "VK_IMAGE_ASPECT_COLOR_BIT set"); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 12890 | |
Mark Lobodzinski | dc86b85 | 2015-10-23 14:20:31 -0600 | [diff] [blame] | 12891 | ASSERT_NO_FATAL_FAILURE(InitState()); |
Mark Lobodzinski | dc86b85 | 2015-10-23 14:20:31 -0600 | [diff] [blame] | 12892 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12893 | const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM; |
Tobin Ehlis | 1f567a2 | 2016-05-25 16:15:18 -0600 | [diff] [blame] | 12894 | VkImageObj image(m_device); |
| 12895 | image.init(32, 32, tex_format, VK_IMAGE_USAGE_SAMPLED_BIT, |
| 12896 | VK_IMAGE_TILING_LINEAR, 0); |
| 12897 | ASSERT_TRUE(image.initialized()); |
Mark Lobodzinski | dc86b85 | 2015-10-23 14:20:31 -0600 | [diff] [blame] | 12898 | |
| 12899 | VkImageViewCreateInfo image_view_create_info = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12900 | image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO; |
Tobin Ehlis | 1f567a2 | 2016-05-25 16:15:18 -0600 | [diff] [blame] | 12901 | image_view_create_info.image = image.handle(); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12902 | image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D; |
| 12903 | image_view_create_info.format = tex_format; |
| 12904 | image_view_create_info.subresourceRange.baseMipLevel = 0; |
| 12905 | image_view_create_info.subresourceRange.levelCount = 1; |
| 12906 | // Cause an error by setting an invalid image aspect |
| 12907 | image_view_create_info.subresourceRange.aspectMask = |
| 12908 | VK_IMAGE_ASPECT_METADATA_BIT; |
Mark Lobodzinski | dc86b85 | 2015-10-23 14:20:31 -0600 | [diff] [blame] | 12909 | |
| 12910 | VkImageView view; |
Tobin Ehlis | 1f567a2 | 2016-05-25 16:15:18 -0600 | [diff] [blame] | 12911 | vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view); |
Mark Lobodzinski | dc86b85 | 2015-10-23 14:20:31 -0600 | [diff] [blame] | 12912 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 12913 | m_errorMonitor->VerifyFound(); |
Mark Lobodzinski | dc86b85 | 2015-10-23 14:20:31 -0600 | [diff] [blame] | 12914 | } |
| 12915 | |
Mark Lobodzinski | db11763 | 2016-03-31 10:45:56 -0600 | [diff] [blame] | 12916 | TEST_F(VkLayerTest, CopyImageLayerCountMismatch) { |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12917 | VkResult err; |
| 12918 | bool pass; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12919 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12920 | m_errorMonitor->SetDesiredFailureMsg( |
| 12921 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Mark Lobodzinski | db11763 | 2016-03-31 10:45:56 -0600 | [diff] [blame] | 12922 | "vkCmdCopyImage: number of layers in source and destination subresources for pRegions"); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 12923 | |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12924 | ASSERT_NO_FATAL_FAILURE(InitState()); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12925 | |
| 12926 | // Create two images of different types and try to copy between them |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12927 | VkImage srcImage; |
| 12928 | VkImage dstImage; |
| 12929 | VkDeviceMemory srcMem; |
| 12930 | VkDeviceMemory destMem; |
| 12931 | VkMemoryRequirements memReqs; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12932 | |
| 12933 | VkImageCreateInfo image_create_info = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12934 | image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO; |
| 12935 | image_create_info.pNext = NULL; |
| 12936 | image_create_info.imageType = VK_IMAGE_TYPE_2D; |
| 12937 | image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM; |
| 12938 | image_create_info.extent.width = 32; |
| 12939 | image_create_info.extent.height = 32; |
| 12940 | image_create_info.extent.depth = 1; |
| 12941 | image_create_info.mipLevels = 1; |
Mark Lobodzinski | db11763 | 2016-03-31 10:45:56 -0600 | [diff] [blame] | 12942 | image_create_info.arrayLayers = 4; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12943 | image_create_info.samples = VK_SAMPLE_COUNT_1_BIT; |
| 12944 | image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL; |
| 12945 | image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT; |
| 12946 | image_create_info.flags = 0; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12947 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12948 | err = |
| 12949 | vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12950 | ASSERT_VK_SUCCESS(err); |
| 12951 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12952 | err = |
| 12953 | vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12954 | ASSERT_VK_SUCCESS(err); |
| 12955 | |
| 12956 | // Allocate memory |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 12957 | VkMemoryAllocateInfo memAlloc = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12958 | memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO; |
| 12959 | memAlloc.pNext = NULL; |
| 12960 | memAlloc.allocationSize = 0; |
| 12961 | memAlloc.memoryTypeIndex = 0; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12962 | |
Courtney Goeltzenleuchter | 06d8947 | 2015-10-20 16:40:38 -0600 | [diff] [blame] | 12963 | vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12964 | memAlloc.allocationSize = memReqs.size; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12965 | pass = |
| 12966 | m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0); |
Courtney Goeltzenleuchter | 1d2f0dd | 2015-10-22 11:03:31 -0600 | [diff] [blame] | 12967 | ASSERT_TRUE(pass); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 12968 | err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12969 | ASSERT_VK_SUCCESS(err); |
| 12970 | |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 12971 | vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12972 | memAlloc.allocationSize = memReqs.size; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12973 | pass = |
| 12974 | m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12975 | ASSERT_VK_SUCCESS(err); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 12976 | err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12977 | ASSERT_VK_SUCCESS(err); |
| 12978 | |
| 12979 | err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0); |
| 12980 | ASSERT_VK_SUCCESS(err); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 12981 | err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12982 | ASSERT_VK_SUCCESS(err); |
| 12983 | |
| 12984 | BeginCommandBuffer(); |
| 12985 | VkImageCopy copyRegion; |
Chia-I Wu | ab83a0e | 2015-10-27 19:00:15 +0800 | [diff] [blame] | 12986 | copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12987 | copyRegion.srcSubresource.mipLevel = 0; |
Courtney Goeltzenleuchter | 8367ce0 | 2015-10-16 09:46:00 -0600 | [diff] [blame] | 12988 | copyRegion.srcSubresource.baseArrayLayer = 0; |
Mark Lobodzinski | db11763 | 2016-03-31 10:45:56 -0600 | [diff] [blame] | 12989 | copyRegion.srcSubresource.layerCount = 1; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12990 | copyRegion.srcOffset.x = 0; |
| 12991 | copyRegion.srcOffset.y = 0; |
| 12992 | copyRegion.srcOffset.z = 0; |
Chia-I Wu | ab83a0e | 2015-10-27 19:00:15 +0800 | [diff] [blame] | 12993 | copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 12994 | copyRegion.dstSubresource.mipLevel = 0; |
| 12995 | copyRegion.dstSubresource.baseArrayLayer = 0; |
Mark Lobodzinski | db11763 | 2016-03-31 10:45:56 -0600 | [diff] [blame] | 12996 | // Introduce failure by forcing the dst layerCount to differ from src |
| 12997 | copyRegion.dstSubresource.layerCount = 3; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 12998 | copyRegion.dstOffset.x = 0; |
| 12999 | copyRegion.dstOffset.y = 0; |
| 13000 | copyRegion.dstOffset.z = 0; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 13001 | copyRegion.extent.width = 1; |
| 13002 | copyRegion.extent.height = 1; |
| 13003 | copyRegion.extent.depth = 1; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 13004 | m_commandBuffer->CopyImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, |
| 13005 | VK_IMAGE_LAYOUT_GENERAL, 1, ©Region); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 13006 | EndCommandBuffer(); |
| 13007 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 13008 | m_errorMonitor->VerifyFound(); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 13009 | |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 13010 | vkDestroyImage(m_device->device(), srcImage, NULL); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 13011 | vkDestroyImage(m_device->device(), dstImage, NULL); |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 13012 | vkFreeMemory(m_device->device(), srcMem, NULL); |
| 13013 | vkFreeMemory(m_device->device(), destMem, NULL); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 13014 | } |
| 13015 | |
Tony Barbour | d667364 | 2016-05-05 14:46:39 -0600 | [diff] [blame] | 13016 | TEST_F(VkLayerTest, ImageLayerUnsupportedFormat) { |
| 13017 | |
| 13018 | TEST_DESCRIPTION("Creating images with unsuported formats "); |
| 13019 | |
| 13020 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 13021 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 13022 | VkImageObj image(m_device); |
| 13023 | image.init(128, 128, VK_FORMAT_B8G8R8A8_UNORM, |
| 13024 | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | |
| 13025 | VK_IMAGE_USAGE_TRANSFER_DST_BIT, |
| 13026 | VK_IMAGE_TILING_OPTIMAL, 0); |
| 13027 | ASSERT_TRUE(image.initialized()); |
| 13028 | |
Mark Lobodzinski | ba5c686 | 2016-05-17 08:14:00 -0600 | [diff] [blame] | 13029 | // Create image with unsupported format - Expect FORMAT_UNSUPPORTED |
| 13030 | VkImageCreateInfo image_create_info; |
| 13031 | image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO; |
| 13032 | image_create_info.pNext = NULL; |
| 13033 | image_create_info.imageType = VK_IMAGE_TYPE_2D; |
| 13034 | image_create_info.format = VK_FORMAT_UNDEFINED; |
| 13035 | image_create_info.extent.width = 32; |
| 13036 | image_create_info.extent.height = 32; |
| 13037 | image_create_info.extent.depth = 1; |
| 13038 | image_create_info.mipLevels = 1; |
| 13039 | image_create_info.arrayLayers = 1; |
| 13040 | image_create_info.samples = VK_SAMPLE_COUNT_1_BIT; |
| 13041 | image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL; |
| 13042 | image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT; |
| 13043 | image_create_info.flags = 0; |
| 13044 | |
| 13045 | m_errorMonitor->SetDesiredFailureMsg( |
| 13046 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 13047 | "vkCreateImage: VkFormat for image must not be VK_FORMAT_UNDEFINED"); |
| 13048 | |
| 13049 | VkImage localImage; |
| 13050 | vkCreateImage(m_device->handle(), &image_create_info, NULL, &localImage); |
| 13051 | m_errorMonitor->VerifyFound(); |
| 13052 | |
Tony Barbour | d667364 | 2016-05-05 14:46:39 -0600 | [diff] [blame] | 13053 | VkFormat unsupported = VK_FORMAT_UNDEFINED; |
Mark Lobodzinski | ba5c686 | 2016-05-17 08:14:00 -0600 | [diff] [blame] | 13054 | // Look for a format that is COMPLETELY unsupported with this hardware |
Tony Barbour | d667364 | 2016-05-05 14:46:39 -0600 | [diff] [blame] | 13055 | for (int f = VK_FORMAT_BEGIN_RANGE; f <= VK_FORMAT_END_RANGE; f++) { |
| 13056 | VkFormat format = static_cast<VkFormat>(f); |
| 13057 | VkFormatProperties fProps = m_device->format_properties(format); |
| 13058 | if (format != VK_FORMAT_UNDEFINED && fProps.linearTilingFeatures == 0 && |
| 13059 | fProps.optimalTilingFeatures == 0) { |
| 13060 | unsupported = format; |
| 13061 | break; |
| 13062 | } |
| 13063 | } |
Mark Lobodzinski | ba5c686 | 2016-05-17 08:14:00 -0600 | [diff] [blame] | 13064 | |
Tony Barbour | d667364 | 2016-05-05 14:46:39 -0600 | [diff] [blame] | 13065 | if (unsupported != VK_FORMAT_UNDEFINED) { |
Tony Barbour | d667364 | 2016-05-05 14:46:39 -0600 | [diff] [blame] | 13066 | image_create_info.format = unsupported; |
Tony Barbour | d667364 | 2016-05-05 14:46:39 -0600 | [diff] [blame] | 13067 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Mark Lobodzinski | ba5c686 | 2016-05-17 08:14:00 -0600 | [diff] [blame] | 13068 | "is an unsupported format"); |
Tony Barbour | d667364 | 2016-05-05 14:46:39 -0600 | [diff] [blame] | 13069 | |
Mark Lobodzinski | ba5c686 | 2016-05-17 08:14:00 -0600 | [diff] [blame] | 13070 | vkCreateImage(m_device->handle(), &image_create_info, NULL, &localImage); |
Tony Barbour | d667364 | 2016-05-05 14:46:39 -0600 | [diff] [blame] | 13071 | m_errorMonitor->VerifyFound(); |
| 13072 | } |
| 13073 | } |
| 13074 | |
| 13075 | TEST_F(VkLayerTest, ImageLayerViewTests) { |
| 13076 | VkResult ret; |
| 13077 | TEST_DESCRIPTION("Passing bad parameters to CreateImageView"); |
| 13078 | |
| 13079 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 13080 | |
| 13081 | VkImageObj image(m_device); |
| 13082 | image.init(128, 128, VK_FORMAT_B8G8R8A8_UNORM, |
| 13083 | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | |
| 13084 | VK_IMAGE_USAGE_TRANSFER_DST_BIT, |
| 13085 | VK_IMAGE_TILING_OPTIMAL, 0); |
| 13086 | ASSERT_TRUE(image.initialized()); |
| 13087 | |
| 13088 | VkImageView imgView; |
| 13089 | VkImageViewCreateInfo imgViewInfo = {}; |
| 13090 | imgViewInfo.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO; |
| 13091 | imgViewInfo.image = image.handle(); |
| 13092 | imgViewInfo.viewType = VK_IMAGE_VIEW_TYPE_2D; |
| 13093 | imgViewInfo.format = VK_FORMAT_B8G8R8A8_UNORM; |
| 13094 | imgViewInfo.subresourceRange.layerCount = 1; |
| 13095 | imgViewInfo.subresourceRange.baseMipLevel = 0; |
| 13096 | imgViewInfo.subresourceRange.levelCount = 1; |
| 13097 | imgViewInfo.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; |
| 13098 | |
| 13099 | m_errorMonitor->SetDesiredFailureMsg( |
| 13100 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 13101 | "vkCreateImageView called with baseMipLevel"); |
| 13102 | // View can't have baseMipLevel >= image's mipLevels - Expect |
| 13103 | // VIEW_CREATE_ERROR |
| 13104 | imgViewInfo.subresourceRange.baseMipLevel = 1; |
| 13105 | vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView); |
| 13106 | m_errorMonitor->VerifyFound(); |
| 13107 | imgViewInfo.subresourceRange.baseMipLevel = 0; |
| 13108 | |
| 13109 | m_errorMonitor->SetDesiredFailureMsg( |
| 13110 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 13111 | "vkCreateImageView called with baseArrayLayer"); |
| 13112 | // View can't have baseArrayLayer >= image's arraySize - Expect |
| 13113 | // VIEW_CREATE_ERROR |
| 13114 | imgViewInfo.subresourceRange.baseArrayLayer = 1; |
| 13115 | vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView); |
| 13116 | m_errorMonitor->VerifyFound(); |
| 13117 | imgViewInfo.subresourceRange.baseArrayLayer = 0; |
| 13118 | |
| 13119 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 13120 | "vkCreateImageView called with 0 in " |
| 13121 | "pCreateInfo->subresourceRange." |
| 13122 | "levelCount"); |
| 13123 | // View's levelCount can't be 0 - Expect VIEW_CREATE_ERROR |
| 13124 | imgViewInfo.subresourceRange.levelCount = 0; |
| 13125 | vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView); |
| 13126 | m_errorMonitor->VerifyFound(); |
| 13127 | imgViewInfo.subresourceRange.levelCount = 1; |
| 13128 | |
| 13129 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 13130 | "vkCreateImageView called with 0 in " |
| 13131 | "pCreateInfo->subresourceRange." |
| 13132 | "layerCount"); |
| 13133 | // View's layerCount can't be 0 - Expect VIEW_CREATE_ERROR |
| 13134 | imgViewInfo.subresourceRange.layerCount = 0; |
| 13135 | vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView); |
| 13136 | m_errorMonitor->VerifyFound(); |
| 13137 | imgViewInfo.subresourceRange.layerCount = 1; |
| 13138 | |
| 13139 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 13140 | "but both must be color formats"); |
| 13141 | // Can't use depth format for view into color image - Expect INVALID_FORMAT |
| 13142 | imgViewInfo.format = VK_FORMAT_D24_UNORM_S8_UINT; |
| 13143 | vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView); |
| 13144 | m_errorMonitor->VerifyFound(); |
| 13145 | imgViewInfo.format = VK_FORMAT_B8G8R8A8_UNORM; |
| 13146 | |
| 13147 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 13148 | "Formats MUST be IDENTICAL unless " |
| 13149 | "VK_IMAGE_CREATE_MUTABLE_FORMAT BIT " |
| 13150 | "was set on image creation."); |
| 13151 | // Same compatibility class but no MUTABLE_FORMAT bit - Expect |
| 13152 | // VIEW_CREATE_ERROR |
| 13153 | imgViewInfo.format = VK_FORMAT_B8G8R8A8_UINT; |
| 13154 | vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView); |
| 13155 | m_errorMonitor->VerifyFound(); |
| 13156 | imgViewInfo.format = VK_FORMAT_B8G8R8A8_UNORM; |
| 13157 | |
| 13158 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 13159 | "can support ImageViews with " |
| 13160 | "differing formats but they must be " |
| 13161 | "in the same compatibility class."); |
| 13162 | // Have MUTABLE_FORMAT bit but not in same compatibility class - Expect |
| 13163 | // VIEW_CREATE_ERROR |
| 13164 | VkImageCreateInfo mutImgInfo = image.create_info(); |
| 13165 | VkImage mutImage; |
| 13166 | mutImgInfo.format = VK_FORMAT_R8_UINT; |
| 13167 | assert( |
| 13168 | m_device->format_properties(VK_FORMAT_R8_UINT).optimalTilingFeatures & |
| 13169 | VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT); |
| 13170 | mutImgInfo.flags = VK_IMAGE_CREATE_MUTABLE_FORMAT_BIT; |
| 13171 | mutImgInfo.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT; |
| 13172 | ret = vkCreateImage(m_device->handle(), &mutImgInfo, NULL, &mutImage); |
| 13173 | ASSERT_VK_SUCCESS(ret); |
| 13174 | imgViewInfo.image = mutImage; |
| 13175 | vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView); |
| 13176 | m_errorMonitor->VerifyFound(); |
| 13177 | imgViewInfo.image = image.handle(); |
| 13178 | vkDestroyImage(m_device->handle(), mutImage, NULL); |
| 13179 | } |
| 13180 | |
| 13181 | TEST_F(VkLayerTest, MiscImageLayerTests) { |
| 13182 | |
| 13183 | TEST_DESCRIPTION("Image layer tests that don't belong elsewhare"); |
| 13184 | |
| 13185 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 13186 | |
| 13187 | VkImageObj image(m_device); |
| 13188 | image.init(128, 128, VK_FORMAT_B8G8R8A8_UNORM, |
| 13189 | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | |
| 13190 | VK_IMAGE_USAGE_TRANSFER_DST_BIT, |
| 13191 | VK_IMAGE_TILING_OPTIMAL, 0); |
| 13192 | ASSERT_TRUE(image.initialized()); |
| 13193 | |
| 13194 | m_errorMonitor->SetDesiredFailureMsg( |
| 13195 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 13196 | "number of layers in image subresource is zero"); |
| 13197 | vk_testing::Buffer buffer; |
| 13198 | VkMemoryPropertyFlags reqs = 0; |
| 13199 | buffer.init_as_src(*m_device, 128 * 128 * 4, reqs); |
| 13200 | VkBufferImageCopy region = {}; |
| 13201 | region.bufferRowLength = 128; |
| 13202 | region.bufferImageHeight = 128; |
| 13203 | region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; |
| 13204 | // layerCount can't be 0 - Expect MISMATCHED_IMAGE_ASPECT |
| 13205 | region.imageSubresource.layerCount = 0; |
| 13206 | region.imageExtent.height = 4; |
| 13207 | region.imageExtent.width = 4; |
| 13208 | region.imageExtent.depth = 1; |
| 13209 | m_commandBuffer->BeginCommandBuffer(); |
| 13210 | vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), |
| 13211 | image.handle(), VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, |
| 13212 | 1, ®ion); |
| 13213 | m_errorMonitor->VerifyFound(); |
| 13214 | region.imageSubresource.layerCount = 1; |
| 13215 | |
| 13216 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 13217 | "aspectMasks for each region must " |
| 13218 | "specify only COLOR or DEPTH or " |
| 13219 | "STENCIL"); |
| 13220 | // Expect MISMATCHED_IMAGE_ASPECT |
| 13221 | region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_METADATA_BIT; |
| 13222 | vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), |
| 13223 | image.handle(), VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, |
| 13224 | 1, ®ion); |
| 13225 | m_errorMonitor->VerifyFound(); |
| 13226 | region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; |
| 13227 | |
| 13228 | m_errorMonitor->SetDesiredFailureMsg( |
| 13229 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 13230 | "If the format of srcImage is a depth, stencil, depth stencil or " |
| 13231 | "integer-based format then filter must be VK_FILTER_NEAREST"); |
| 13232 | // Expect INVALID_FILTER |
| 13233 | VkImageObj intImage1(m_device); |
| 13234 | intImage1.init(128, 128, VK_FORMAT_R8_UINT, |
| 13235 | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, |
| 13236 | 0); |
| 13237 | VkImageObj intImage2(m_device); |
| 13238 | intImage2.init(128, 128, VK_FORMAT_R8_UINT, |
| 13239 | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, |
| 13240 | 0); |
| 13241 | VkImageBlit blitRegion = {}; |
| 13242 | blitRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; |
| 13243 | blitRegion.srcSubresource.baseArrayLayer = 0; |
| 13244 | blitRegion.srcSubresource.layerCount = 1; |
| 13245 | blitRegion.srcSubresource.mipLevel = 0; |
| 13246 | blitRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; |
| 13247 | blitRegion.dstSubresource.baseArrayLayer = 0; |
| 13248 | blitRegion.dstSubresource.layerCount = 1; |
| 13249 | blitRegion.dstSubresource.mipLevel = 0; |
| 13250 | |
| 13251 | vkCmdBlitImage(m_commandBuffer->GetBufferHandle(), intImage1.handle(), |
| 13252 | intImage1.layout(), intImage2.handle(), intImage2.layout(), |
| 13253 | 16, &blitRegion, VK_FILTER_LINEAR); |
| 13254 | m_errorMonitor->VerifyFound(); |
| 13255 | |
| 13256 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 13257 | "called with 0 in ppMemoryBarriers"); |
| 13258 | VkImageMemoryBarrier img_barrier; |
| 13259 | img_barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER; |
| 13260 | img_barrier.pNext = NULL; |
| 13261 | img_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT; |
| 13262 | img_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT; |
| 13263 | img_barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL; |
| 13264 | img_barrier.newLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL; |
| 13265 | img_barrier.image = image.handle(); |
| 13266 | img_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED; |
| 13267 | img_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED; |
| 13268 | img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; |
| 13269 | img_barrier.subresourceRange.baseArrayLayer = 0; |
| 13270 | img_barrier.subresourceRange.baseMipLevel = 0; |
| 13271 | // layerCount should not be 0 - Expect INVALID_IMAGE_RESOURCE |
| 13272 | img_barrier.subresourceRange.layerCount = 0; |
| 13273 | img_barrier.subresourceRange.levelCount = 1; |
| 13274 | vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), |
| 13275 | VK_PIPELINE_STAGE_HOST_BIT, |
| 13276 | VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0, nullptr, 0, |
| 13277 | nullptr, 1, &img_barrier); |
| 13278 | m_errorMonitor->VerifyFound(); |
| 13279 | img_barrier.subresourceRange.layerCount = 1; |
| 13280 | } |
| 13281 | |
| 13282 | TEST_F(VkLayerTest, ImageFormatLimits) { |
| 13283 | |
| 13284 | TEST_DESCRIPTION("Exceed the limits of image format "); |
| 13285 | |
| 13286 | m_errorMonitor->SetDesiredFailureMsg( |
| 13287 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 13288 | "CreateImage extents exceed allowable limits for format"); |
| 13289 | VkImageCreateInfo image_create_info = {}; |
| 13290 | image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO; |
| 13291 | image_create_info.pNext = NULL; |
| 13292 | image_create_info.imageType = VK_IMAGE_TYPE_2D; |
| 13293 | image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM; |
| 13294 | image_create_info.extent.width = 32; |
| 13295 | image_create_info.extent.height = 32; |
| 13296 | image_create_info.extent.depth = 1; |
| 13297 | image_create_info.mipLevels = 1; |
| 13298 | image_create_info.arrayLayers = 1; |
| 13299 | image_create_info.samples = VK_SAMPLE_COUNT_1_BIT; |
| 13300 | image_create_info.tiling = VK_IMAGE_TILING_LINEAR; |
| 13301 | image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT; |
| 13302 | image_create_info.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED; |
| 13303 | image_create_info.flags = 0; |
| 13304 | |
| 13305 | VkImage nullImg; |
| 13306 | VkImageFormatProperties imgFmtProps; |
| 13307 | vkGetPhysicalDeviceImageFormatProperties( |
| 13308 | gpu(), image_create_info.format, image_create_info.imageType, |
| 13309 | image_create_info.tiling, image_create_info.usage, |
| 13310 | image_create_info.flags, &imgFmtProps); |
| 13311 | image_create_info.extent.depth = imgFmtProps.maxExtent.depth + 1; |
| 13312 | // Expect INVALID_FORMAT_LIMITS_VIOLATION |
| 13313 | vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg); |
| 13314 | m_errorMonitor->VerifyFound(); |
| 13315 | image_create_info.extent.depth = 1; |
| 13316 | |
| 13317 | m_errorMonitor->SetDesiredFailureMsg( |
| 13318 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 13319 | "exceeds allowable maximum supported by format of"); |
| 13320 | image_create_info.mipLevels = imgFmtProps.maxMipLevels + 1; |
| 13321 | // Expect INVALID_FORMAT_LIMITS_VIOLATION |
| 13322 | vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg); |
| 13323 | m_errorMonitor->VerifyFound(); |
| 13324 | image_create_info.mipLevels = 1; |
| 13325 | |
| 13326 | m_errorMonitor->SetDesiredFailureMsg( |
| 13327 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 13328 | "exceeds allowable maximum supported by format of"); |
| 13329 | image_create_info.arrayLayers = imgFmtProps.maxArrayLayers + 1; |
| 13330 | // Expect INVALID_FORMAT_LIMITS_VIOLATION |
| 13331 | vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg); |
| 13332 | m_errorMonitor->VerifyFound(); |
| 13333 | image_create_info.arrayLayers = 1; |
| 13334 | |
| 13335 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 13336 | "is not supported by format"); |
| 13337 | int samples = imgFmtProps.sampleCounts >> 1; |
| 13338 | image_create_info.samples = (VkSampleCountFlagBits)samples; |
| 13339 | // Expect INVALID_FORMAT_LIMITS_VIOLATION |
| 13340 | vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg); |
| 13341 | m_errorMonitor->VerifyFound(); |
| 13342 | image_create_info.samples = VK_SAMPLE_COUNT_1_BIT; |
| 13343 | |
| 13344 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 13345 | "pCreateInfo->initialLayout, must be " |
| 13346 | "VK_IMAGE_LAYOUT_UNDEFINED or " |
| 13347 | "VK_IMAGE_LAYOUT_PREINITIALIZED"); |
| 13348 | image_create_info.initialLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL; |
| 13349 | // Expect INVALID_LAYOUT |
| 13350 | vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg); |
| 13351 | m_errorMonitor->VerifyFound(); |
| 13352 | image_create_info.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED; |
| 13353 | } |
| 13354 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 13355 | TEST_F(VkLayerTest, CopyImageFormatSizeMismatch) { |
Karl Schultz | bdb7595 | 2016-04-19 11:36:49 -0600 | [diff] [blame] | 13356 | VkResult err; |
| 13357 | bool pass; |
| 13358 | |
| 13359 | // Create color images with different format sizes and try to copy between them |
| 13360 | m_errorMonitor->SetDesiredFailureMsg( |
| 13361 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 13362 | "vkCmdCopyImage called with unmatched source and dest image format sizes"); |
| 13363 | |
| 13364 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 13365 | |
| 13366 | // Create two images of different types and try to copy between them |
| 13367 | VkImage srcImage; |
| 13368 | VkImage dstImage; |
| 13369 | VkDeviceMemory srcMem; |
| 13370 | VkDeviceMemory destMem; |
| 13371 | VkMemoryRequirements memReqs; |
| 13372 | |
| 13373 | VkImageCreateInfo image_create_info = {}; |
| 13374 | image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO; |
| 13375 | image_create_info.pNext = NULL; |
| 13376 | image_create_info.imageType = VK_IMAGE_TYPE_2D; |
| 13377 | image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM; |
| 13378 | image_create_info.extent.width = 32; |
| 13379 | image_create_info.extent.height = 32; |
| 13380 | image_create_info.extent.depth = 1; |
| 13381 | image_create_info.mipLevels = 1; |
| 13382 | image_create_info.arrayLayers = 1; |
| 13383 | image_create_info.samples = VK_SAMPLE_COUNT_1_BIT; |
| 13384 | image_create_info.tiling = VK_IMAGE_TILING_LINEAR; |
| 13385 | image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT; |
| 13386 | image_create_info.flags = 0; |
| 13387 | |
| 13388 | err = |
| 13389 | vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage); |
| 13390 | ASSERT_VK_SUCCESS(err); |
| 13391 | |
| 13392 | image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT; |
| 13393 | // Introduce failure by creating second image with a different-sized format. |
| 13394 | image_create_info.format = VK_FORMAT_R5G5B5A1_UNORM_PACK16; |
| 13395 | |
| 13396 | err = |
| 13397 | vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage); |
| 13398 | ASSERT_VK_SUCCESS(err); |
| 13399 | |
| 13400 | // Allocate memory |
| 13401 | VkMemoryAllocateInfo memAlloc = {}; |
| 13402 | memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO; |
| 13403 | memAlloc.pNext = NULL; |
| 13404 | memAlloc.allocationSize = 0; |
| 13405 | memAlloc.memoryTypeIndex = 0; |
| 13406 | |
| 13407 | vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs); |
| 13408 | memAlloc.allocationSize = memReqs.size; |
| 13409 | pass = |
| 13410 | m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0); |
| 13411 | ASSERT_TRUE(pass); |
| 13412 | err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem); |
| 13413 | ASSERT_VK_SUCCESS(err); |
| 13414 | |
| 13415 | vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs); |
| 13416 | memAlloc.allocationSize = memReqs.size; |
| 13417 | pass = |
| 13418 | m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0); |
| 13419 | ASSERT_TRUE(pass); |
| 13420 | err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem); |
| 13421 | ASSERT_VK_SUCCESS(err); |
| 13422 | |
| 13423 | err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0); |
| 13424 | ASSERT_VK_SUCCESS(err); |
| 13425 | err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0); |
| 13426 | ASSERT_VK_SUCCESS(err); |
| 13427 | |
| 13428 | BeginCommandBuffer(); |
| 13429 | VkImageCopy copyRegion; |
| 13430 | copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; |
| 13431 | copyRegion.srcSubresource.mipLevel = 0; |
| 13432 | copyRegion.srcSubresource.baseArrayLayer = 0; |
| 13433 | copyRegion.srcSubresource.layerCount = 0; |
| 13434 | copyRegion.srcOffset.x = 0; |
| 13435 | copyRegion.srcOffset.y = 0; |
| 13436 | copyRegion.srcOffset.z = 0; |
| 13437 | copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; |
| 13438 | copyRegion.dstSubresource.mipLevel = 0; |
| 13439 | copyRegion.dstSubresource.baseArrayLayer = 0; |
| 13440 | copyRegion.dstSubresource.layerCount = 0; |
| 13441 | copyRegion.dstOffset.x = 0; |
| 13442 | copyRegion.dstOffset.y = 0; |
| 13443 | copyRegion.dstOffset.z = 0; |
| 13444 | copyRegion.extent.width = 1; |
| 13445 | copyRegion.extent.height = 1; |
| 13446 | copyRegion.extent.depth = 1; |
| 13447 | m_commandBuffer->CopyImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, |
| 13448 | VK_IMAGE_LAYOUT_GENERAL, 1, ©Region); |
| 13449 | EndCommandBuffer(); |
| 13450 | |
| 13451 | m_errorMonitor->VerifyFound(); |
| 13452 | |
| 13453 | vkDestroyImage(m_device->device(), srcImage, NULL); |
| 13454 | vkDestroyImage(m_device->device(), dstImage, NULL); |
| 13455 | vkFreeMemory(m_device->device(), srcMem, NULL); |
| 13456 | vkFreeMemory(m_device->device(), destMem, NULL); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 13457 | } |
| 13458 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 13459 | TEST_F(VkLayerTest, CopyImageDepthStencilFormatMismatch) { |
| 13460 | VkResult err; |
| 13461 | bool pass; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 13462 | |
Mark Lobodzinski | db11763 | 2016-03-31 10:45:56 -0600 | [diff] [blame] | 13463 | // 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] | 13464 | m_errorMonitor->SetDesiredFailureMsg( |
| 13465 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Mark Lobodzinski | db11763 | 2016-03-31 10:45:56 -0600 | [diff] [blame] | 13466 | "vkCmdCopyImage called with unmatched source and dest image depth"); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 13467 | |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 13468 | ASSERT_NO_FATAL_FAILURE(InitState()); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 13469 | |
| 13470 | // Create two images of different types and try to copy between them |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 13471 | VkImage srcImage; |
| 13472 | VkImage dstImage; |
| 13473 | VkDeviceMemory srcMem; |
| 13474 | VkDeviceMemory destMem; |
| 13475 | VkMemoryRequirements memReqs; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 13476 | |
| 13477 | VkImageCreateInfo image_create_info = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 13478 | image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO; |
| 13479 | image_create_info.pNext = NULL; |
| 13480 | image_create_info.imageType = VK_IMAGE_TYPE_2D; |
| 13481 | image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM; |
| 13482 | image_create_info.extent.width = 32; |
| 13483 | image_create_info.extent.height = 32; |
| 13484 | image_create_info.extent.depth = 1; |
| 13485 | image_create_info.mipLevels = 1; |
| 13486 | image_create_info.arrayLayers = 1; |
| 13487 | image_create_info.samples = VK_SAMPLE_COUNT_1_BIT; |
| 13488 | image_create_info.tiling = VK_IMAGE_TILING_LINEAR; |
| 13489 | image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT; |
| 13490 | image_create_info.flags = 0; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 13491 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 13492 | err = |
| 13493 | vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 13494 | ASSERT_VK_SUCCESS(err); |
| 13495 | |
Karl Schultz | bdb7595 | 2016-04-19 11:36:49 -0600 | [diff] [blame] | 13496 | image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT; |
| 13497 | |
Mark Lobodzinski | db11763 | 2016-03-31 10:45:56 -0600 | [diff] [blame] | 13498 | // Introduce failure by creating second image with a depth/stencil format |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 13499 | image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL; |
Mark Lobodzinski | db11763 | 2016-03-31 10:45:56 -0600 | [diff] [blame] | 13500 | image_create_info.format = VK_FORMAT_D24_UNORM_S8_UINT; |
| 13501 | image_create_info.usage = VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 13502 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 13503 | err = |
| 13504 | vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 13505 | ASSERT_VK_SUCCESS(err); |
| 13506 | |
| 13507 | // Allocate memory |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 13508 | VkMemoryAllocateInfo memAlloc = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 13509 | memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO; |
| 13510 | memAlloc.pNext = NULL; |
| 13511 | memAlloc.allocationSize = 0; |
| 13512 | memAlloc.memoryTypeIndex = 0; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 13513 | |
Courtney Goeltzenleuchter | 06d8947 | 2015-10-20 16:40:38 -0600 | [diff] [blame] | 13514 | vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 13515 | memAlloc.allocationSize = memReqs.size; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 13516 | pass = |
| 13517 | m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0); |
Courtney Goeltzenleuchter | 1d2f0dd | 2015-10-22 11:03:31 -0600 | [diff] [blame] | 13518 | ASSERT_TRUE(pass); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 13519 | err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 13520 | ASSERT_VK_SUCCESS(err); |
| 13521 | |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 13522 | vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 13523 | memAlloc.allocationSize = memReqs.size; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 13524 | pass = |
| 13525 | m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0); |
Courtney Goeltzenleuchter | 1d2f0dd | 2015-10-22 11:03:31 -0600 | [diff] [blame] | 13526 | ASSERT_TRUE(pass); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 13527 | err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 13528 | ASSERT_VK_SUCCESS(err); |
| 13529 | |
| 13530 | err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0); |
| 13531 | ASSERT_VK_SUCCESS(err); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 13532 | err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 13533 | ASSERT_VK_SUCCESS(err); |
| 13534 | |
| 13535 | BeginCommandBuffer(); |
| 13536 | VkImageCopy copyRegion; |
Chia-I Wu | ab83a0e | 2015-10-27 19:00:15 +0800 | [diff] [blame] | 13537 | copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 13538 | copyRegion.srcSubresource.mipLevel = 0; |
Courtney Goeltzenleuchter | 8367ce0 | 2015-10-16 09:46:00 -0600 | [diff] [blame] | 13539 | copyRegion.srcSubresource.baseArrayLayer = 0; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 13540 | copyRegion.srcSubresource.layerCount = 0; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 13541 | copyRegion.srcOffset.x = 0; |
| 13542 | copyRegion.srcOffset.y = 0; |
| 13543 | copyRegion.srcOffset.z = 0; |
Chia-I Wu | ab83a0e | 2015-10-27 19:00:15 +0800 | [diff] [blame] | 13544 | copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 13545 | copyRegion.dstSubresource.mipLevel = 0; |
| 13546 | copyRegion.dstSubresource.baseArrayLayer = 0; |
| 13547 | copyRegion.dstSubresource.layerCount = 0; |
| 13548 | copyRegion.dstOffset.x = 0; |
| 13549 | copyRegion.dstOffset.y = 0; |
| 13550 | copyRegion.dstOffset.z = 0; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 13551 | copyRegion.extent.width = 1; |
| 13552 | copyRegion.extent.height = 1; |
| 13553 | copyRegion.extent.depth = 1; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 13554 | m_commandBuffer->CopyImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, |
| 13555 | VK_IMAGE_LAYOUT_GENERAL, 1, ©Region); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 13556 | EndCommandBuffer(); |
| 13557 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 13558 | m_errorMonitor->VerifyFound(); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 13559 | |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 13560 | vkDestroyImage(m_device->device(), srcImage, NULL); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 13561 | vkDestroyImage(m_device->device(), dstImage, NULL); |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 13562 | vkFreeMemory(m_device->device(), srcMem, NULL); |
| 13563 | vkFreeMemory(m_device->device(), destMem, NULL); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 13564 | } |
| 13565 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 13566 | TEST_F(VkLayerTest, ResolveImageLowSampleCount) { |
| 13567 | VkResult err; |
| 13568 | bool pass; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 13569 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 13570 | m_errorMonitor->SetDesiredFailureMsg( |
| 13571 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 13572 | "vkCmdResolveImage called with source sample count less than 2."); |
| 13573 | |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 13574 | ASSERT_NO_FATAL_FAILURE(InitState()); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 13575 | |
| 13576 | // 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] | 13577 | VkImage srcImage; |
| 13578 | VkImage dstImage; |
| 13579 | VkDeviceMemory srcMem; |
| 13580 | VkDeviceMemory destMem; |
| 13581 | VkMemoryRequirements memReqs; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 13582 | |
| 13583 | VkImageCreateInfo image_create_info = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 13584 | image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO; |
| 13585 | image_create_info.pNext = NULL; |
| 13586 | image_create_info.imageType = VK_IMAGE_TYPE_2D; |
| 13587 | image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM; |
| 13588 | image_create_info.extent.width = 32; |
| 13589 | image_create_info.extent.height = 1; |
| 13590 | image_create_info.extent.depth = 1; |
| 13591 | image_create_info.mipLevels = 1; |
| 13592 | image_create_info.arrayLayers = 1; |
| 13593 | image_create_info.samples = VK_SAMPLE_COUNT_1_BIT; |
| 13594 | image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL; |
| 13595 | image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT; |
| 13596 | image_create_info.flags = 0; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 13597 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 13598 | err = |
| 13599 | vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 13600 | ASSERT_VK_SUCCESS(err); |
| 13601 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 13602 | image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 13603 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 13604 | err = |
| 13605 | vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 13606 | ASSERT_VK_SUCCESS(err); |
| 13607 | |
| 13608 | // Allocate memory |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 13609 | VkMemoryAllocateInfo memAlloc = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 13610 | memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO; |
| 13611 | memAlloc.pNext = NULL; |
| 13612 | memAlloc.allocationSize = 0; |
| 13613 | memAlloc.memoryTypeIndex = 0; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 13614 | |
Courtney Goeltzenleuchter | 06d8947 | 2015-10-20 16:40:38 -0600 | [diff] [blame] | 13615 | vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 13616 | memAlloc.allocationSize = memReqs.size; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 13617 | pass = |
| 13618 | m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0); |
Courtney Goeltzenleuchter | 1d2f0dd | 2015-10-22 11:03:31 -0600 | [diff] [blame] | 13619 | ASSERT_TRUE(pass); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 13620 | err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 13621 | ASSERT_VK_SUCCESS(err); |
| 13622 | |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 13623 | vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 13624 | memAlloc.allocationSize = memReqs.size; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 13625 | pass = |
| 13626 | m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0); |
Courtney Goeltzenleuchter | 1d2f0dd | 2015-10-22 11:03:31 -0600 | [diff] [blame] | 13627 | ASSERT_TRUE(pass); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 13628 | err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 13629 | ASSERT_VK_SUCCESS(err); |
| 13630 | |
| 13631 | err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0); |
| 13632 | ASSERT_VK_SUCCESS(err); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 13633 | err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 13634 | ASSERT_VK_SUCCESS(err); |
| 13635 | |
| 13636 | BeginCommandBuffer(); |
| 13637 | // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest? |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 13638 | // VK_IMAGE_LAYOUT_UNDEFINED = 0, |
| 13639 | // VK_IMAGE_LAYOUT_GENERAL = 1, |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 13640 | VkImageResolve resolveRegion; |
Chia-I Wu | ab83a0e | 2015-10-27 19:00:15 +0800 | [diff] [blame] | 13641 | resolveRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 13642 | resolveRegion.srcSubresource.mipLevel = 0; |
Courtney Goeltzenleuchter | 8367ce0 | 2015-10-16 09:46:00 -0600 | [diff] [blame] | 13643 | resolveRegion.srcSubresource.baseArrayLayer = 0; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 13644 | resolveRegion.srcSubresource.layerCount = 0; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 13645 | resolveRegion.srcOffset.x = 0; |
| 13646 | resolveRegion.srcOffset.y = 0; |
| 13647 | resolveRegion.srcOffset.z = 0; |
Chia-I Wu | ab83a0e | 2015-10-27 19:00:15 +0800 | [diff] [blame] | 13648 | resolveRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 13649 | resolveRegion.dstSubresource.mipLevel = 0; |
| 13650 | resolveRegion.dstSubresource.baseArrayLayer = 0; |
| 13651 | resolveRegion.dstSubresource.layerCount = 0; |
| 13652 | resolveRegion.dstOffset.x = 0; |
| 13653 | resolveRegion.dstOffset.y = 0; |
| 13654 | resolveRegion.dstOffset.z = 0; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 13655 | resolveRegion.extent.width = 1; |
| 13656 | resolveRegion.extent.height = 1; |
| 13657 | resolveRegion.extent.depth = 1; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 13658 | m_commandBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, |
| 13659 | VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 13660 | EndCommandBuffer(); |
| 13661 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 13662 | m_errorMonitor->VerifyFound(); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 13663 | |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 13664 | vkDestroyImage(m_device->device(), srcImage, NULL); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 13665 | vkDestroyImage(m_device->device(), dstImage, NULL); |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 13666 | vkFreeMemory(m_device->device(), srcMem, NULL); |
| 13667 | vkFreeMemory(m_device->device(), destMem, NULL); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 13668 | } |
| 13669 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 13670 | TEST_F(VkLayerTest, ResolveImageHighSampleCount) { |
| 13671 | VkResult err; |
| 13672 | bool pass; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 13673 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 13674 | m_errorMonitor->SetDesiredFailureMsg( |
| 13675 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 13676 | "vkCmdResolveImage called with dest sample count greater than 1."); |
| 13677 | |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 13678 | ASSERT_NO_FATAL_FAILURE(InitState()); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 13679 | |
Chris Forbes | a753069 | 2016-05-08 12:35:39 +1200 | [diff] [blame] | 13680 | // 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] | 13681 | VkImage srcImage; |
| 13682 | VkImage dstImage; |
| 13683 | VkDeviceMemory srcMem; |
| 13684 | VkDeviceMemory destMem; |
| 13685 | VkMemoryRequirements memReqs; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 13686 | |
| 13687 | VkImageCreateInfo image_create_info = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 13688 | image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO; |
| 13689 | image_create_info.pNext = NULL; |
| 13690 | image_create_info.imageType = VK_IMAGE_TYPE_2D; |
| 13691 | image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM; |
| 13692 | image_create_info.extent.width = 32; |
| 13693 | image_create_info.extent.height = 1; |
| 13694 | image_create_info.extent.depth = 1; |
| 13695 | image_create_info.mipLevels = 1; |
| 13696 | image_create_info.arrayLayers = 1; |
Chris Forbes | a753069 | 2016-05-08 12:35:39 +1200 | [diff] [blame] | 13697 | image_create_info.samples = VK_SAMPLE_COUNT_4_BIT; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 13698 | image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL; |
| 13699 | // Note: Some implementations expect color attachment usage for any |
| 13700 | // multisample surface |
| 13701 | image_create_info.usage = |
| 13702 | VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT; |
| 13703 | image_create_info.flags = 0; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 13704 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 13705 | err = |
| 13706 | vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 13707 | ASSERT_VK_SUCCESS(err); |
| 13708 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 13709 | // Note: Some implementations expect color attachment usage for any |
| 13710 | // multisample surface |
| 13711 | image_create_info.usage = |
| 13712 | VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 13713 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 13714 | err = |
| 13715 | vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 13716 | ASSERT_VK_SUCCESS(err); |
| 13717 | |
| 13718 | // Allocate memory |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 13719 | VkMemoryAllocateInfo memAlloc = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 13720 | memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO; |
| 13721 | memAlloc.pNext = NULL; |
| 13722 | memAlloc.allocationSize = 0; |
| 13723 | memAlloc.memoryTypeIndex = 0; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 13724 | |
Courtney Goeltzenleuchter | 06d8947 | 2015-10-20 16:40:38 -0600 | [diff] [blame] | 13725 | vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 13726 | memAlloc.allocationSize = memReqs.size; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 13727 | pass = |
| 13728 | m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0); |
Courtney Goeltzenleuchter | 1d2f0dd | 2015-10-22 11:03:31 -0600 | [diff] [blame] | 13729 | ASSERT_TRUE(pass); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 13730 | err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 13731 | ASSERT_VK_SUCCESS(err); |
| 13732 | |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 13733 | vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 13734 | memAlloc.allocationSize = memReqs.size; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 13735 | pass = |
| 13736 | m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0); |
Courtney Goeltzenleuchter | 1d2f0dd | 2015-10-22 11:03:31 -0600 | [diff] [blame] | 13737 | ASSERT_TRUE(pass); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 13738 | err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 13739 | ASSERT_VK_SUCCESS(err); |
| 13740 | |
| 13741 | err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0); |
| 13742 | ASSERT_VK_SUCCESS(err); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 13743 | err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 13744 | ASSERT_VK_SUCCESS(err); |
| 13745 | |
| 13746 | BeginCommandBuffer(); |
| 13747 | // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest? |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 13748 | // VK_IMAGE_LAYOUT_UNDEFINED = 0, |
| 13749 | // VK_IMAGE_LAYOUT_GENERAL = 1, |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 13750 | VkImageResolve resolveRegion; |
Chia-I Wu | ab83a0e | 2015-10-27 19:00:15 +0800 | [diff] [blame] | 13751 | resolveRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 13752 | resolveRegion.srcSubresource.mipLevel = 0; |
Courtney Goeltzenleuchter | 8367ce0 | 2015-10-16 09:46:00 -0600 | [diff] [blame] | 13753 | resolveRegion.srcSubresource.baseArrayLayer = 0; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 13754 | resolveRegion.srcSubresource.layerCount = 0; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 13755 | resolveRegion.srcOffset.x = 0; |
| 13756 | resolveRegion.srcOffset.y = 0; |
| 13757 | resolveRegion.srcOffset.z = 0; |
Chia-I Wu | ab83a0e | 2015-10-27 19:00:15 +0800 | [diff] [blame] | 13758 | resolveRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 13759 | resolveRegion.dstSubresource.mipLevel = 0; |
| 13760 | resolveRegion.dstSubresource.baseArrayLayer = 0; |
| 13761 | resolveRegion.dstSubresource.layerCount = 0; |
| 13762 | resolveRegion.dstOffset.x = 0; |
| 13763 | resolveRegion.dstOffset.y = 0; |
| 13764 | resolveRegion.dstOffset.z = 0; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 13765 | resolveRegion.extent.width = 1; |
| 13766 | resolveRegion.extent.height = 1; |
| 13767 | resolveRegion.extent.depth = 1; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 13768 | m_commandBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, |
| 13769 | VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 13770 | EndCommandBuffer(); |
| 13771 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 13772 | m_errorMonitor->VerifyFound(); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 13773 | |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 13774 | vkDestroyImage(m_device->device(), srcImage, NULL); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 13775 | vkDestroyImage(m_device->device(), dstImage, NULL); |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 13776 | vkFreeMemory(m_device->device(), srcMem, NULL); |
| 13777 | vkFreeMemory(m_device->device(), destMem, NULL); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 13778 | } |
| 13779 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 13780 | TEST_F(VkLayerTest, ResolveImageFormatMismatch) { |
| 13781 | VkResult err; |
| 13782 | bool pass; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 13783 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 13784 | m_errorMonitor->SetDesiredFailureMsg( |
| 13785 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 13786 | "vkCmdResolveImage called with unmatched source and dest formats."); |
| 13787 | |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 13788 | ASSERT_NO_FATAL_FAILURE(InitState()); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 13789 | |
| 13790 | // Create two images of different types and try to copy between them |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 13791 | VkImage srcImage; |
| 13792 | VkImage dstImage; |
| 13793 | VkDeviceMemory srcMem; |
| 13794 | VkDeviceMemory destMem; |
| 13795 | VkMemoryRequirements memReqs; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 13796 | |
| 13797 | VkImageCreateInfo image_create_info = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 13798 | image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO; |
| 13799 | image_create_info.pNext = NULL; |
| 13800 | image_create_info.imageType = VK_IMAGE_TYPE_2D; |
| 13801 | image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM; |
| 13802 | image_create_info.extent.width = 32; |
| 13803 | image_create_info.extent.height = 1; |
| 13804 | image_create_info.extent.depth = 1; |
| 13805 | image_create_info.mipLevels = 1; |
| 13806 | image_create_info.arrayLayers = 1; |
| 13807 | image_create_info.samples = VK_SAMPLE_COUNT_2_BIT; |
| 13808 | image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL; |
| 13809 | // Note: Some implementations expect color attachment usage for any |
| 13810 | // multisample surface |
| 13811 | image_create_info.usage = |
| 13812 | VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT; |
| 13813 | image_create_info.flags = 0; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 13814 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 13815 | err = |
| 13816 | vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 13817 | ASSERT_VK_SUCCESS(err); |
| 13818 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 13819 | // Set format to something other than source image |
| 13820 | image_create_info.format = VK_FORMAT_R32_SFLOAT; |
| 13821 | // Note: Some implementations expect color attachment usage for any |
| 13822 | // multisample surface |
| 13823 | image_create_info.usage = |
| 13824 | VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT; |
| 13825 | image_create_info.samples = VK_SAMPLE_COUNT_1_BIT; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 13826 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 13827 | err = |
| 13828 | vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 13829 | ASSERT_VK_SUCCESS(err); |
| 13830 | |
| 13831 | // Allocate memory |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 13832 | VkMemoryAllocateInfo memAlloc = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 13833 | memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO; |
| 13834 | memAlloc.pNext = NULL; |
| 13835 | memAlloc.allocationSize = 0; |
| 13836 | memAlloc.memoryTypeIndex = 0; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 13837 | |
Courtney Goeltzenleuchter | 06d8947 | 2015-10-20 16:40:38 -0600 | [diff] [blame] | 13838 | vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 13839 | memAlloc.allocationSize = memReqs.size; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 13840 | pass = |
| 13841 | m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0); |
Courtney Goeltzenleuchter | 1d2f0dd | 2015-10-22 11:03:31 -0600 | [diff] [blame] | 13842 | ASSERT_TRUE(pass); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 13843 | err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 13844 | ASSERT_VK_SUCCESS(err); |
| 13845 | |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 13846 | vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 13847 | memAlloc.allocationSize = memReqs.size; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 13848 | pass = |
| 13849 | m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0); |
Courtney Goeltzenleuchter | 1d2f0dd | 2015-10-22 11:03:31 -0600 | [diff] [blame] | 13850 | ASSERT_TRUE(pass); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 13851 | err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 13852 | ASSERT_VK_SUCCESS(err); |
| 13853 | |
| 13854 | err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0); |
| 13855 | ASSERT_VK_SUCCESS(err); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 13856 | err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 13857 | ASSERT_VK_SUCCESS(err); |
| 13858 | |
| 13859 | BeginCommandBuffer(); |
| 13860 | // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest? |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 13861 | // VK_IMAGE_LAYOUT_UNDEFINED = 0, |
| 13862 | // VK_IMAGE_LAYOUT_GENERAL = 1, |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 13863 | VkImageResolve resolveRegion; |
Chia-I Wu | ab83a0e | 2015-10-27 19:00:15 +0800 | [diff] [blame] | 13864 | resolveRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 13865 | resolveRegion.srcSubresource.mipLevel = 0; |
Courtney Goeltzenleuchter | 8367ce0 | 2015-10-16 09:46:00 -0600 | [diff] [blame] | 13866 | resolveRegion.srcSubresource.baseArrayLayer = 0; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 13867 | resolveRegion.srcSubresource.layerCount = 0; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 13868 | resolveRegion.srcOffset.x = 0; |
| 13869 | resolveRegion.srcOffset.y = 0; |
| 13870 | resolveRegion.srcOffset.z = 0; |
Chia-I Wu | ab83a0e | 2015-10-27 19:00:15 +0800 | [diff] [blame] | 13871 | resolveRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 13872 | resolveRegion.dstSubresource.mipLevel = 0; |
| 13873 | resolveRegion.dstSubresource.baseArrayLayer = 0; |
| 13874 | resolveRegion.dstSubresource.layerCount = 0; |
| 13875 | resolveRegion.dstOffset.x = 0; |
| 13876 | resolveRegion.dstOffset.y = 0; |
| 13877 | resolveRegion.dstOffset.z = 0; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 13878 | resolveRegion.extent.width = 1; |
| 13879 | resolveRegion.extent.height = 1; |
| 13880 | resolveRegion.extent.depth = 1; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 13881 | m_commandBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, |
| 13882 | VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 13883 | EndCommandBuffer(); |
| 13884 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 13885 | m_errorMonitor->VerifyFound(); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 13886 | |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 13887 | vkDestroyImage(m_device->device(), srcImage, NULL); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 13888 | vkDestroyImage(m_device->device(), dstImage, NULL); |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 13889 | vkFreeMemory(m_device->device(), srcMem, NULL); |
| 13890 | vkFreeMemory(m_device->device(), destMem, NULL); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 13891 | } |
| 13892 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 13893 | TEST_F(VkLayerTest, ResolveImageTypeMismatch) { |
| 13894 | VkResult err; |
| 13895 | bool pass; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 13896 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 13897 | m_errorMonitor->SetDesiredFailureMsg( |
| 13898 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 13899 | "vkCmdResolveImage called with unmatched source and dest image types."); |
| 13900 | |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 13901 | ASSERT_NO_FATAL_FAILURE(InitState()); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 13902 | |
| 13903 | // Create two images of different types and try to copy between them |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 13904 | VkImage srcImage; |
| 13905 | VkImage dstImage; |
| 13906 | VkDeviceMemory srcMem; |
| 13907 | VkDeviceMemory destMem; |
| 13908 | VkMemoryRequirements memReqs; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 13909 | |
| 13910 | VkImageCreateInfo image_create_info = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 13911 | image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO; |
| 13912 | image_create_info.pNext = NULL; |
| 13913 | image_create_info.imageType = VK_IMAGE_TYPE_2D; |
| 13914 | image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM; |
| 13915 | image_create_info.extent.width = 32; |
| 13916 | image_create_info.extent.height = 1; |
| 13917 | image_create_info.extent.depth = 1; |
| 13918 | image_create_info.mipLevels = 1; |
| 13919 | image_create_info.arrayLayers = 1; |
| 13920 | image_create_info.samples = VK_SAMPLE_COUNT_2_BIT; |
| 13921 | image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL; |
| 13922 | // Note: Some implementations expect color attachment usage for any |
| 13923 | // multisample surface |
| 13924 | image_create_info.usage = |
| 13925 | VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT; |
| 13926 | image_create_info.flags = 0; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 13927 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 13928 | err = |
| 13929 | vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 13930 | ASSERT_VK_SUCCESS(err); |
| 13931 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 13932 | image_create_info.imageType = VK_IMAGE_TYPE_1D; |
| 13933 | // Note: Some implementations expect color attachment usage for any |
| 13934 | // multisample surface |
| 13935 | image_create_info.usage = |
| 13936 | VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT; |
| 13937 | image_create_info.samples = VK_SAMPLE_COUNT_1_BIT; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 13938 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 13939 | err = |
| 13940 | vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 13941 | ASSERT_VK_SUCCESS(err); |
| 13942 | |
| 13943 | // Allocate memory |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 13944 | VkMemoryAllocateInfo memAlloc = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 13945 | memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO; |
| 13946 | memAlloc.pNext = NULL; |
| 13947 | memAlloc.allocationSize = 0; |
| 13948 | memAlloc.memoryTypeIndex = 0; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 13949 | |
Courtney Goeltzenleuchter | 06d8947 | 2015-10-20 16:40:38 -0600 | [diff] [blame] | 13950 | vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 13951 | memAlloc.allocationSize = memReqs.size; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 13952 | pass = |
| 13953 | m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0); |
Courtney Goeltzenleuchter | 1d2f0dd | 2015-10-22 11:03:31 -0600 | [diff] [blame] | 13954 | ASSERT_TRUE(pass); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 13955 | err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 13956 | ASSERT_VK_SUCCESS(err); |
| 13957 | |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 13958 | vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 13959 | memAlloc.allocationSize = memReqs.size; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 13960 | pass = |
| 13961 | m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0); |
Courtney Goeltzenleuchter | 1d2f0dd | 2015-10-22 11:03:31 -0600 | [diff] [blame] | 13962 | ASSERT_TRUE(pass); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 13963 | err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 13964 | ASSERT_VK_SUCCESS(err); |
| 13965 | |
| 13966 | err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0); |
| 13967 | ASSERT_VK_SUCCESS(err); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 13968 | err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 13969 | ASSERT_VK_SUCCESS(err); |
| 13970 | |
| 13971 | BeginCommandBuffer(); |
| 13972 | // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest? |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 13973 | // VK_IMAGE_LAYOUT_UNDEFINED = 0, |
| 13974 | // VK_IMAGE_LAYOUT_GENERAL = 1, |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 13975 | VkImageResolve resolveRegion; |
Chia-I Wu | ab83a0e | 2015-10-27 19:00:15 +0800 | [diff] [blame] | 13976 | resolveRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 13977 | resolveRegion.srcSubresource.mipLevel = 0; |
Courtney Goeltzenleuchter | 8367ce0 | 2015-10-16 09:46:00 -0600 | [diff] [blame] | 13978 | resolveRegion.srcSubresource.baseArrayLayer = 0; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 13979 | resolveRegion.srcSubresource.layerCount = 0; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 13980 | resolveRegion.srcOffset.x = 0; |
| 13981 | resolveRegion.srcOffset.y = 0; |
| 13982 | resolveRegion.srcOffset.z = 0; |
Chia-I Wu | ab83a0e | 2015-10-27 19:00:15 +0800 | [diff] [blame] | 13983 | resolveRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 13984 | resolveRegion.dstSubresource.mipLevel = 0; |
| 13985 | resolveRegion.dstSubresource.baseArrayLayer = 0; |
| 13986 | resolveRegion.dstSubresource.layerCount = 0; |
| 13987 | resolveRegion.dstOffset.x = 0; |
| 13988 | resolveRegion.dstOffset.y = 0; |
| 13989 | resolveRegion.dstOffset.z = 0; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 13990 | resolveRegion.extent.width = 1; |
| 13991 | resolveRegion.extent.height = 1; |
| 13992 | resolveRegion.extent.depth = 1; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 13993 | m_commandBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, |
| 13994 | VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 13995 | EndCommandBuffer(); |
| 13996 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 13997 | m_errorMonitor->VerifyFound(); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 13998 | |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 13999 | vkDestroyImage(m_device->device(), srcImage, NULL); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 14000 | vkDestroyImage(m_device->device(), dstImage, NULL); |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 14001 | vkFreeMemory(m_device->device(), srcMem, NULL); |
| 14002 | vkFreeMemory(m_device->device(), destMem, NULL); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 14003 | } |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 14004 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 14005 | TEST_F(VkLayerTest, DepthStencilImageViewWithColorAspectBitError) { |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 14006 | // 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] | 14007 | // to using a DS format, then cause it to hit error due to COLOR_BIT not |
| 14008 | // set in aspect |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 14009 | // The image format check comes 2nd in validation so we trigger it first, |
| 14010 | // 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] | 14011 | VkResult err; |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 14012 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 14013 | m_errorMonitor->SetDesiredFailureMsg( |
| 14014 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 14015 | "Combination depth/stencil image formats can have only the "); |
| 14016 | |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 14017 | ASSERT_NO_FATAL_FAILURE(InitState()); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 14018 | |
Chia-I Wu | 1b99bb2 | 2015-10-27 19:25:11 +0800 | [diff] [blame] | 14019 | VkDescriptorPoolSize ds_type_count = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 14020 | ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE; |
| 14021 | ds_type_count.descriptorCount = 1; |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 14022 | |
| 14023 | VkDescriptorPoolCreateInfo ds_pool_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 14024 | ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO; |
| 14025 | ds_pool_ci.pNext = NULL; |
| 14026 | ds_pool_ci.maxSets = 1; |
| 14027 | ds_pool_ci.poolSizeCount = 1; |
| 14028 | ds_pool_ci.pPoolSizes = &ds_type_count; |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 14029 | |
| 14030 | VkDescriptorPool ds_pool; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 14031 | err = |
| 14032 | vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool); |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 14033 | ASSERT_VK_SUCCESS(err); |
| 14034 | |
| 14035 | VkDescriptorSetLayoutBinding dsl_binding = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 14036 | dsl_binding.binding = 0; |
| 14037 | dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE; |
| 14038 | dsl_binding.descriptorCount = 1; |
| 14039 | dsl_binding.stageFlags = VK_SHADER_STAGE_ALL; |
| 14040 | dsl_binding.pImmutableSamplers = NULL; |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 14041 | |
| 14042 | VkDescriptorSetLayoutCreateInfo ds_layout_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 14043 | ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO; |
| 14044 | ds_layout_ci.pNext = NULL; |
| 14045 | ds_layout_ci.bindingCount = 1; |
| 14046 | ds_layout_ci.pBindings = &dsl_binding; |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 14047 | VkDescriptorSetLayout ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 14048 | err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, |
| 14049 | &ds_layout); |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 14050 | ASSERT_VK_SUCCESS(err); |
| 14051 | |
| 14052 | VkDescriptorSet descriptorSet; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 14053 | VkDescriptorSetAllocateInfo alloc_info = {}; |
Chia-I Wu | 00ce540 | 2015-11-10 16:21:09 +0800 | [diff] [blame] | 14054 | alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO; |
Jon Ashburn | f19916e | 2016-01-11 13:12:43 -0700 | [diff] [blame] | 14055 | alloc_info.descriptorSetCount = 1; |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 14056 | alloc_info.descriptorPool = ds_pool; |
| 14057 | alloc_info.pSetLayouts = &ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 14058 | err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, |
| 14059 | &descriptorSet); |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 14060 | ASSERT_VK_SUCCESS(err); |
| 14061 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 14062 | VkImage image_bad; |
| 14063 | VkImage image_good; |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 14064 | // One bad format and one good format for Color attachment |
Tobin Ehlis | 269f032 | 2016-05-25 16:24:21 -0600 | [diff] [blame] | 14065 | const VkFormat tex_format_bad = VK_FORMAT_D24_UNORM_S8_UINT; |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 14066 | const VkFormat tex_format_good = VK_FORMAT_B8G8R8A8_UNORM; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 14067 | const int32_t tex_width = 32; |
| 14068 | const int32_t tex_height = 32; |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 14069 | |
| 14070 | VkImageCreateInfo image_create_info = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 14071 | image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO; |
| 14072 | image_create_info.pNext = NULL; |
| 14073 | image_create_info.imageType = VK_IMAGE_TYPE_2D; |
| 14074 | image_create_info.format = tex_format_bad; |
| 14075 | image_create_info.extent.width = tex_width; |
| 14076 | image_create_info.extent.height = tex_height; |
| 14077 | image_create_info.extent.depth = 1; |
| 14078 | image_create_info.mipLevels = 1; |
| 14079 | image_create_info.arrayLayers = 1; |
| 14080 | image_create_info.samples = VK_SAMPLE_COUNT_1_BIT; |
| 14081 | image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL; |
| 14082 | image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT | |
| 14083 | VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT; |
| 14084 | image_create_info.flags = 0; |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 14085 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 14086 | err = |
| 14087 | vkCreateImage(m_device->device(), &image_create_info, NULL, &image_bad); |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 14088 | ASSERT_VK_SUCCESS(err); |
| 14089 | image_create_info.format = tex_format_good; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 14090 | image_create_info.usage = |
| 14091 | VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT; |
| 14092 | err = vkCreateImage(m_device->device(), &image_create_info, NULL, |
| 14093 | &image_good); |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 14094 | ASSERT_VK_SUCCESS(err); |
| 14095 | |
| 14096 | VkImageViewCreateInfo image_view_create_info = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 14097 | image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO; |
| 14098 | image_view_create_info.image = image_bad; |
| 14099 | image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D; |
| 14100 | image_view_create_info.format = tex_format_bad; |
| 14101 | image_view_create_info.subresourceRange.baseArrayLayer = 0; |
| 14102 | image_view_create_info.subresourceRange.baseMipLevel = 0; |
| 14103 | image_view_create_info.subresourceRange.layerCount = 1; |
| 14104 | image_view_create_info.subresourceRange.levelCount = 1; |
| 14105 | image_view_create_info.subresourceRange.aspectMask = |
| 14106 | VK_IMAGE_ASPECT_COLOR_BIT; |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 14107 | |
| 14108 | VkImageView view; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 14109 | err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, |
| 14110 | &view); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 14111 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 14112 | m_errorMonitor->VerifyFound(); |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 14113 | |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 14114 | vkDestroyImage(m_device->device(), image_bad, NULL); |
| 14115 | vkDestroyImage(m_device->device(), image_good, NULL); |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 14116 | vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL); |
| 14117 | vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL); |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 14118 | } |
Tobin Ehlis | 6e23d77 | 2016-05-19 11:08:34 -0600 | [diff] [blame] | 14119 | |
| 14120 | TEST_F(VkLayerTest, ClearImageErrors) { |
| 14121 | TEST_DESCRIPTION("Call ClearColorImage w/ a depth|stencil image and " |
| 14122 | "ClearDepthStencilImage with a color image."); |
| 14123 | |
| 14124 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 14125 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 14126 | |
| 14127 | // Renderpass is started here so end it as Clear cmds can't be in renderpass |
| 14128 | BeginCommandBuffer(); |
| 14129 | m_commandBuffer->EndRenderPass(); |
| 14130 | |
| 14131 | // Color image |
| 14132 | VkClearColorValue clear_color; |
| 14133 | memset(clear_color.uint32, 0, sizeof(uint32_t) * 4); |
| 14134 | VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT; |
| 14135 | const VkFormat color_format = VK_FORMAT_B8G8R8A8_UNORM; |
| 14136 | const int32_t img_width = 32; |
| 14137 | const int32_t img_height = 32; |
| 14138 | VkImageCreateInfo image_create_info = {}; |
| 14139 | image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO; |
| 14140 | image_create_info.pNext = NULL; |
| 14141 | image_create_info.imageType = VK_IMAGE_TYPE_2D; |
| 14142 | image_create_info.format = color_format; |
| 14143 | image_create_info.extent.width = img_width; |
| 14144 | image_create_info.extent.height = img_height; |
| 14145 | image_create_info.extent.depth = 1; |
| 14146 | image_create_info.mipLevels = 1; |
| 14147 | image_create_info.arrayLayers = 1; |
| 14148 | image_create_info.samples = VK_SAMPLE_COUNT_1_BIT; |
| 14149 | image_create_info.tiling = VK_IMAGE_TILING_LINEAR; |
| 14150 | image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT; |
| 14151 | |
| 14152 | vk_testing::Image color_image; |
| 14153 | color_image.init(*m_device, (const VkImageCreateInfo &)image_create_info, |
| 14154 | reqs); |
| 14155 | |
| 14156 | const VkImageSubresourceRange color_range = |
| 14157 | vk_testing::Image::subresource_range(image_create_info, |
| 14158 | VK_IMAGE_ASPECT_COLOR_BIT); |
| 14159 | |
| 14160 | // Depth/Stencil image |
| 14161 | VkClearDepthStencilValue clear_value = {0}; |
| 14162 | reqs = 0; // don't need HOST_VISIBLE DS image |
| 14163 | VkImageCreateInfo ds_image_create_info = vk_testing::Image::create_info(); |
| 14164 | ds_image_create_info.imageType = VK_IMAGE_TYPE_2D; |
| 14165 | ds_image_create_info.format = VK_FORMAT_D24_UNORM_S8_UINT; |
| 14166 | ds_image_create_info.extent.width = 64; |
| 14167 | ds_image_create_info.extent.height = 64; |
| 14168 | ds_image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL; |
| 14169 | ds_image_create_info.usage = VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT; |
| 14170 | |
| 14171 | vk_testing::Image ds_image; |
| 14172 | ds_image.init(*m_device, (const VkImageCreateInfo &)ds_image_create_info, |
| 14173 | reqs); |
| 14174 | |
| 14175 | const VkImageSubresourceRange ds_range = |
| 14176 | vk_testing::Image::subresource_range(ds_image_create_info, |
| 14177 | VK_IMAGE_ASPECT_DEPTH_BIT); |
| 14178 | |
| 14179 | m_errorMonitor->SetDesiredFailureMsg( |
| 14180 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 14181 | "vkCmdClearColorImage called with depth/stencil image."); |
| 14182 | |
| 14183 | vkCmdClearColorImage(m_commandBuffer->GetBufferHandle(), ds_image.handle(), |
| 14184 | VK_IMAGE_LAYOUT_GENERAL, &clear_color, 1, |
| 14185 | &color_range); |
| 14186 | |
| 14187 | m_errorMonitor->VerifyFound(); |
| 14188 | |
Tony Barbour | 26434b9 | 2016-06-02 09:43:50 -0600 | [diff] [blame] | 14189 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 14190 | "vkCmdClearColorImage called with " |
| 14191 | "image created without " |
| 14192 | "VK_IMAGE_USAGE_TRANSFER_DST_BIT"); |
| 14193 | |
| 14194 | vkCmdClearColorImage(m_commandBuffer->GetBufferHandle(), ds_image.handle(), |
| 14195 | VK_IMAGE_LAYOUT_GENERAL, &clear_color, 1, |
| 14196 | &color_range); |
| 14197 | |
| 14198 | m_errorMonitor->VerifyFound(); |
| 14199 | |
Tobin Ehlis | 6e23d77 | 2016-05-19 11:08:34 -0600 | [diff] [blame] | 14200 | // Call CmdClearDepthStencilImage with color image |
| 14201 | m_errorMonitor->SetDesiredFailureMsg( |
| 14202 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 14203 | "vkCmdClearDepthStencilImage called without a depth/stencil image."); |
| 14204 | |
| 14205 | vkCmdClearDepthStencilImage( |
| 14206 | m_commandBuffer->GetBufferHandle(), color_image.handle(), |
| 14207 | VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL, &clear_value, 1, |
| 14208 | &ds_range); |
| 14209 | |
| 14210 | m_errorMonitor->VerifyFound(); |
| 14211 | } |
Tobin Ehlis | cde0889 | 2015-09-22 10:11:37 -0600 | [diff] [blame] | 14212 | #endif // IMAGE_TESTS |
| 14213 | |
Tony Barbour | 300a608 | 2015-04-07 13:44:53 -0600 | [diff] [blame] | 14214 | int main(int argc, char **argv) { |
| 14215 | int result; |
| 14216 | |
Cody Northrop | 8e54a40 | 2016-03-08 22:25:52 -0700 | [diff] [blame] | 14217 | #ifdef ANDROID |
| 14218 | int vulkanSupport = InitVulkan(); |
| 14219 | if (vulkanSupport == 0) |
| 14220 | return 1; |
| 14221 | #endif |
| 14222 | |
Tony Barbour | 300a608 | 2015-04-07 13:44:53 -0600 | [diff] [blame] | 14223 | ::testing::InitGoogleTest(&argc, argv); |
Tony Barbour | 6918cd5 | 2015-04-09 12:58:51 -0600 | [diff] [blame] | 14224 | VkTestFramework::InitArgs(&argc, argv); |
Tony Barbour | 300a608 | 2015-04-07 13:44:53 -0600 | [diff] [blame] | 14225 | |
| 14226 | ::testing::AddGlobalTestEnvironment(new TestEnvironment); |
| 14227 | |
| 14228 | result = RUN_ALL_TESTS(); |
| 14229 | |
Tony Barbour | 6918cd5 | 2015-04-09 12:58:51 -0600 | [diff] [blame] | 14230 | VkTestFramework::Finish(); |
Tony Barbour | 300a608 | 2015-04-07 13:44:53 -0600 | [diff] [blame] | 14231 | return result; |
| 14232 | } |