Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2015-2016 The Khronos Group Inc. |
| 3 | * Copyright (c) 2015-2016 Valve Corporation |
| 4 | * Copyright (c) 2015-2016 LunarG, Inc. |
Michael Lentine | 0a369f6 | 2016-02-03 16:51:46 -0600 | [diff] [blame] | 5 | * Copyright (c) 2015-2016 Google, Inc. |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6 | * |
Jon Ashburn | 3ebf125 | 2016-04-19 11:30:31 -0600 | [diff] [blame] | 7 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 8 | * you may not use this file except in compliance with the License. |
| 9 | * You may obtain a copy of the License at |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 10 | * |
Jon Ashburn | 3ebf125 | 2016-04-19 11:30:31 -0600 | [diff] [blame] | 11 | * http://www.apache.org/licenses/LICENSE-2.0 |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12 | * |
| 13 | * Author: Chia-I Wu <olvaffe@gmail.com> |
| 14 | * Author: Chris Forbes <chrisf@ijw.co.nz> |
| 15 | * Author: Courtney Goeltzenleuchter <courtney@LunarG.com> |
| 16 | * Author: Mark Lobodzinski <mark@lunarg.com> |
| 17 | * Author: Mike Stroyan <mike@LunarG.com> |
| 18 | * Author: Tobin Ehlis <tobine@google.com> |
| 19 | * Author: Tony Barbour <tony@LunarG.com> |
| 20 | */ |
Tony Barbour | 65c48b3 | 2015-11-17 10:02:56 -0700 | [diff] [blame] | 21 | |
Cody Northrop | 8e54a40 | 2016-03-08 22:25:52 -0700 | [diff] [blame] | 22 | #ifdef ANDROID |
| 23 | #include "vulkan_wrapper.h" |
| 24 | #else |
David Pinedo | 9316d3b | 2015-11-06 12:54:48 -0700 | [diff] [blame] | 25 | #include <vulkan/vulkan.h> |
Cody Northrop | 8e54a40 | 2016-03-08 22:25:52 -0700 | [diff] [blame] | 26 | #endif |
Courtney Goeltzenleuchter | 58f3eff | 2015-10-07 13:28:58 -0600 | [diff] [blame] | 27 | #include "test_common.h" |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 28 | #include "vkrenderframework.h" |
Tobin Ehlis | a0cb02e | 2015-07-03 10:15:26 -0600 | [diff] [blame] | 29 | #include "vk_layer_config.h" |
Jon Ashburn | 7fa7e22 | 2016-02-02 12:08:10 -0700 | [diff] [blame] | 30 | #include "icd-spv.h" |
Tony Barbour | 300a608 | 2015-04-07 13:44:53 -0600 | [diff] [blame] | 31 | |
Mark Lobodzinski | 3780e14 | 2015-05-14 15:08:13 -0500 | [diff] [blame] | 32 | #define GLM_FORCE_RADIANS |
| 33 | #include "glm/glm.hpp" |
| 34 | #include <glm/gtc/matrix_transform.hpp> |
| 35 | |
Dustin Graves | ffa90fa | 2016-05-06 11:20:38 -0600 | [diff] [blame] | 36 | #define PARAMETER_VALIDATION_TESTS 1 |
Tobin Ehlis | 0788f52 | 2015-05-26 16:11:58 -0600 | [diff] [blame] | 37 | #define MEM_TRACKER_TESTS 1 |
| 38 | #define OBJ_TRACKER_TESTS 1 |
| 39 | #define DRAW_STATE_TESTS 1 |
| 40 | #define THREADING_TESTS 1 |
Chris Forbes | 9f7ff63 | 2015-05-25 11:13:08 +1200 | [diff] [blame] | 41 | #define SHADER_CHECKER_TESTS 1 |
Mark Lobodzinski | 209b529 | 2015-09-17 09:44:05 -0600 | [diff] [blame] | 42 | #define DEVICE_LIMITS_TESTS 1 |
Tobin Ehlis | cde0889 | 2015-09-22 10:11:37 -0600 | [diff] [blame] | 43 | #define IMAGE_TESTS 1 |
Tobin Ehlis | 0788f52 | 2015-05-26 16:11:58 -0600 | [diff] [blame] | 44 | |
Mark Lobodzinski | 3780e14 | 2015-05-14 15:08:13 -0500 | [diff] [blame] | 45 | //-------------------------------------------------------------------------------------- |
| 46 | // Mesh and VertexFormat Data |
| 47 | //-------------------------------------------------------------------------------------- |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 48 | struct Vertex { |
| 49 | float posX, posY, posZ, posW; // Position data |
| 50 | float r, g, b, a; // Color |
Mark Lobodzinski | 3780e14 | 2015-05-14 15:08:13 -0500 | [diff] [blame] | 51 | }; |
| 52 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 53 | #define XYZ1(_x_, _y_, _z_) (_x_), (_y_), (_z_), 1.f |
Mark Lobodzinski | 3780e14 | 2015-05-14 15:08:13 -0500 | [diff] [blame] | 54 | |
| 55 | typedef enum _BsoFailSelect { |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 56 | BsoFailNone = 0x00000000, |
| 57 | BsoFailLineWidth = 0x00000001, |
| 58 | BsoFailDepthBias = 0x00000002, |
| 59 | BsoFailViewport = 0x00000004, |
| 60 | BsoFailScissor = 0x00000008, |
| 61 | BsoFailBlend = 0x00000010, |
| 62 | BsoFailDepthBounds = 0x00000020, |
| 63 | BsoFailStencilReadMask = 0x00000040, |
| 64 | BsoFailStencilWriteMask = 0x00000080, |
| 65 | BsoFailStencilReference = 0x00000100, |
Mark Mueller | d491441 | 2016-06-13 17:52:06 -0600 | [diff] [blame] | 66 | BsoFailCmdClearAttachments = 0x00000200, |
Mark Lobodzinski | 3780e14 | 2015-05-14 15:08:13 -0500 | [diff] [blame] | 67 | } BsoFailSelect; |
| 68 | |
| 69 | struct vktriangle_vs_uniform { |
| 70 | // Must start with MVP |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 71 | float mvp[4][4]; |
| 72 | float position[3][4]; |
| 73 | float color[3][4]; |
Mark Lobodzinski | 3780e14 | 2015-05-14 15:08:13 -0500 | [diff] [blame] | 74 | }; |
| 75 | |
Mark Lobodzinski | 75a97e6 | 2015-06-02 09:41:30 -0500 | [diff] [blame] | 76 | static const char bindStateVertShaderText[] = |
Chris Forbes | 7b34280 | 2016-04-07 13:20:10 +1200 | [diff] [blame] | 77 | "#version 450\n" |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 78 | "vec2 vertices[3];\n" |
| 79 | "out gl_PerVertex {\n" |
| 80 | " vec4 gl_Position;\n" |
| 81 | "};\n" |
| 82 | "void main() {\n" |
| 83 | " vertices[0] = vec2(-1.0, -1.0);\n" |
| 84 | " vertices[1] = vec2( 1.0, -1.0);\n" |
| 85 | " vertices[2] = vec2( 0.0, 1.0);\n" |
| 86 | " gl_Position = vec4(vertices[gl_VertexIndex % 3], 0.0, 1.0);\n" |
| 87 | "}\n"; |
Mark Lobodzinski | 3780e14 | 2015-05-14 15:08:13 -0500 | [diff] [blame] | 88 | |
Mark Lobodzinski | 75a97e6 | 2015-06-02 09:41:30 -0500 | [diff] [blame] | 89 | static const char bindStateFragShaderText[] = |
Chris Forbes | 7b34280 | 2016-04-07 13:20:10 +1200 | [diff] [blame] | 90 | "#version 450\n" |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 91 | "\n" |
| 92 | "layout(location = 0) out vec4 uFragColor;\n" |
| 93 | "void main(){\n" |
| 94 | " uFragColor = vec4(0,1,0,1);\n" |
| 95 | "}\n"; |
Mark Lobodzinski | 3780e14 | 2015-05-14 15:08:13 -0500 | [diff] [blame] | 96 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 97 | static VKAPI_ATTR VkBool32 VKAPI_CALL |
| 98 | myDbgFunc(VkFlags msgFlags, VkDebugReportObjectTypeEXT objType, |
| 99 | uint64_t srcObject, size_t location, int32_t msgCode, |
| 100 | const char *pLayerPrefix, const char *pMsg, void *pUserData); |
Tony Barbour | 300a608 | 2015-04-07 13:44:53 -0600 | [diff] [blame] | 101 | |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 102 | // ******************************************************** |
| 103 | // ErrorMonitor Usage: |
| 104 | // |
| 105 | // Call SetDesiredFailureMsg with a string to be compared against all |
| 106 | // encountered log messages. Passing NULL will match all log messages. |
| 107 | // logMsg will return true for skipCall only if msg is matched or NULL. |
| 108 | // |
| 109 | // Call DesiredMsgFound to determine if the desired failure message |
| 110 | // was encountered. |
| 111 | |
Tony Barbour | 300a608 | 2015-04-07 13:44:53 -0600 | [diff] [blame] | 112 | class ErrorMonitor { |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 113 | public: |
| 114 | ErrorMonitor() { |
Mike Stroyan | 4268d1f | 2015-07-13 14:45:35 -0600 | [diff] [blame] | 115 | test_platform_thread_create_mutex(&m_mutex); |
| 116 | test_platform_thread_lock_mutex(&m_mutex); |
Mark Lobodzinski | 510e20d | 2016-02-11 09:26:16 -0700 | [diff] [blame] | 117 | m_msgFlags = VK_DEBUG_REPORT_INFORMATION_BIT_EXT; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 118 | m_bailout = NULL; |
Mike Stroyan | 4268d1f | 2015-07-13 14:45:35 -0600 | [diff] [blame] | 119 | test_platform_thread_unlock_mutex(&m_mutex); |
Tony Barbour | 300a608 | 2015-04-07 13:44:53 -0600 | [diff] [blame] | 120 | } |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 121 | |
Dustin Graves | 4845814 | 2016-04-29 16:11:55 -0600 | [diff] [blame] | 122 | ~ErrorMonitor() { test_platform_thread_delete_mutex(&m_mutex); } |
| 123 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 124 | void SetDesiredFailureMsg(VkFlags msgFlags, const char *msgString) { |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 125 | // also discard all collected messages to this point |
Mike Stroyan | 4268d1f | 2015-07-13 14:45:35 -0600 | [diff] [blame] | 126 | test_platform_thread_lock_mutex(&m_mutex); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 127 | m_failureMsg.clear(); |
| 128 | m_otherMsgs.clear(); |
| 129 | m_desiredMsg = msgString; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 130 | m_msgFound = VK_FALSE; |
| 131 | m_msgFlags = msgFlags; |
Mike Stroyan | 4268d1f | 2015-07-13 14:45:35 -0600 | [diff] [blame] | 132 | test_platform_thread_unlock_mutex(&m_mutex); |
Tony Barbour | 300a608 | 2015-04-07 13:44:53 -0600 | [diff] [blame] | 133 | } |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 134 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 135 | VkBool32 CheckForDesiredMsg(VkFlags msgFlags, const char *msgString) { |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 136 | VkBool32 result = VK_FALSE; |
Mike Stroyan | 4268d1f | 2015-07-13 14:45:35 -0600 | [diff] [blame] | 137 | test_platform_thread_lock_mutex(&m_mutex); |
Mike Stroyan | accf769 | 2015-05-12 16:00:45 -0600 | [diff] [blame] | 138 | if (m_bailout != NULL) { |
| 139 | *m_bailout = true; |
| 140 | } |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 141 | string errorString(msgString); |
| 142 | if (msgFlags & m_msgFlags) { |
| 143 | if (errorString.find(m_desiredMsg) != string::npos) { |
Chris Forbes | c7b8ad7 | 2016-04-04 18:50:38 +1200 | [diff] [blame] | 144 | if (m_msgFound) { /* if multiple matches, don't lose all but the last! */ |
| 145 | m_otherMsgs.push_back(m_failureMsg); |
| 146 | } |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 147 | m_failureMsg = errorString; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 148 | m_msgFound = VK_TRUE; |
| 149 | result = VK_TRUE; |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 150 | } else { |
| 151 | m_otherMsgs.push_back(errorString); |
| 152 | } |
| 153 | } |
Mike Stroyan | 4268d1f | 2015-07-13 14:45:35 -0600 | [diff] [blame] | 154 | test_platform_thread_unlock_mutex(&m_mutex); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 155 | return result; |
Mike Stroyan | accf769 | 2015-05-12 16:00:45 -0600 | [diff] [blame] | 156 | } |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 157 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 158 | vector<string> GetOtherFailureMsgs(void) { return m_otherMsgs; } |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 159 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 160 | string GetFailureMsg(void) { return m_failureMsg; } |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 161 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 162 | VkBool32 DesiredMsgFound(void) { return m_msgFound; } |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 163 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 164 | void SetBailout(bool *bailout) { m_bailout = bailout; } |
Tony Barbour | 300a608 | 2015-04-07 13:44:53 -0600 | [diff] [blame] | 165 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 166 | void DumpFailureMsgs(void) { |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 167 | vector<string> otherMsgs = GetOtherFailureMsgs(); |
| 168 | cout << "Other error messages logged for this test were:" << endl; |
| 169 | for (auto iter = otherMsgs.begin(); iter != otherMsgs.end(); iter++) { |
| 170 | cout << " " << *iter << endl; |
| 171 | } |
| 172 | } |
| 173 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 174 | /* helpers */ |
| 175 | |
| 176 | void ExpectSuccess() { |
| 177 | // match anything |
| 178 | SetDesiredFailureMsg(~0u, ""); |
| 179 | } |
| 180 | |
| 181 | void VerifyFound() { |
| 182 | // Not seeing the desired message is a failure. /Before/ throwing, dump |
| 183 | // any other messages. |
| 184 | if (!DesiredMsgFound()) { |
| 185 | DumpFailureMsgs(); |
| 186 | FAIL() << "Did not receive expected error '" << m_desiredMsg << "'"; |
| 187 | } |
| 188 | } |
| 189 | |
| 190 | void VerifyNotFound() { |
| 191 | // ExpectSuccess() configured us to match anything. Any error is a |
| 192 | // failure. |
| 193 | if (DesiredMsgFound()) { |
| 194 | DumpFailureMsgs(); |
| 195 | FAIL() << "Expected to succeed but got error: " << GetFailureMsg(); |
| 196 | } |
| 197 | } |
| 198 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 199 | private: |
| 200 | VkFlags m_msgFlags; |
| 201 | string m_desiredMsg; |
| 202 | string m_failureMsg; |
| 203 | vector<string> m_otherMsgs; |
Mike Stroyan | 4268d1f | 2015-07-13 14:45:35 -0600 | [diff] [blame] | 204 | test_platform_thread_mutex m_mutex; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 205 | bool *m_bailout; |
| 206 | VkBool32 m_msgFound; |
Tony Barbour | 300a608 | 2015-04-07 13:44:53 -0600 | [diff] [blame] | 207 | }; |
Mark Lobodzinski | 3780e14 | 2015-05-14 15:08:13 -0500 | [diff] [blame] | 208 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 209 | static VKAPI_ATTR VkBool32 VKAPI_CALL |
| 210 | myDbgFunc(VkFlags msgFlags, VkDebugReportObjectTypeEXT objType, |
| 211 | uint64_t srcObject, size_t location, int32_t msgCode, |
| 212 | const char *pLayerPrefix, const char *pMsg, void *pUserData) { |
| 213 | if (msgFlags & |
Mark Lobodzinski | 510e20d | 2016-02-11 09:26:16 -0700 | [diff] [blame] | 214 | (VK_DEBUG_REPORT_WARNING_BIT_EXT | VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 215 | VK_DEBUG_REPORT_ERROR_BIT_EXT)) { |
Tony Barbour | 0b4d956 | 2015-04-09 10:48:04 -0600 | [diff] [blame] | 216 | ErrorMonitor *errMonitor = (ErrorMonitor *)pUserData; |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 217 | return errMonitor->CheckForDesiredMsg(msgFlags, pMsg); |
Tony Barbour | 0b4d956 | 2015-04-09 10:48:04 -0600 | [diff] [blame] | 218 | } |
Courtney Goeltzenleuchter | 0664083 | 2015-09-04 13:52:24 -0600 | [diff] [blame] | 219 | return false; |
Tony Barbour | 300a608 | 2015-04-07 13:44:53 -0600 | [diff] [blame] | 220 | } |
Mark Lobodzinski | 3780e14 | 2015-05-14 15:08:13 -0500 | [diff] [blame] | 221 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 222 | class VkLayerTest : public VkRenderFramework { |
| 223 | public: |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 224 | VkResult BeginCommandBuffer(VkCommandBufferObj &commandBuffer); |
| 225 | VkResult EndCommandBuffer(VkCommandBufferObj &commandBuffer); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 226 | void VKTriangleTest(const char *vertShaderText, const char *fragShaderText, |
| 227 | BsoFailSelect failMask); |
| 228 | void GenericDrawPreparation(VkCommandBufferObj *commandBuffer, |
| 229 | VkPipelineObj &pipelineobj, |
| 230 | VkDescriptorSetObj &descriptorSet, |
| 231 | BsoFailSelect failMask); |
| 232 | void GenericDrawPreparation(VkPipelineObj &pipelineobj, |
| 233 | VkDescriptorSetObj &descriptorSet, |
| 234 | BsoFailSelect failMask) { |
| 235 | GenericDrawPreparation(m_commandBuffer, pipelineobj, descriptorSet, |
| 236 | failMask); |
| 237 | } |
Tony Barbour | 300a608 | 2015-04-07 13:44:53 -0600 | [diff] [blame] | 238 | |
Tony Barbour | fe3351b | 2015-07-28 10:17:20 -0600 | [diff] [blame] | 239 | /* Convenience functions that use built-in command buffer */ |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 240 | VkResult BeginCommandBuffer() { |
| 241 | return BeginCommandBuffer(*m_commandBuffer); |
| 242 | } |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 243 | VkResult EndCommandBuffer() { return EndCommandBuffer(*m_commandBuffer); } |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 244 | void Draw(uint32_t vertexCount, uint32_t instanceCount, |
| 245 | uint32_t firstVertex, uint32_t firstInstance) { |
| 246 | m_commandBuffer->Draw(vertexCount, instanceCount, firstVertex, |
| 247 | firstInstance); |
| 248 | } |
| 249 | void DrawIndexed(uint32_t indexCount, uint32_t instanceCount, |
| 250 | uint32_t firstIndex, int32_t vertexOffset, |
| 251 | uint32_t firstInstance) { |
| 252 | m_commandBuffer->DrawIndexed(indexCount, instanceCount, firstIndex, |
| 253 | vertexOffset, firstInstance); |
| 254 | } |
Mark Lobodzinski | cf0ae75 | 2016-06-23 10:02:24 -0600 | [diff] [blame] | 255 | void QueueCommandBuffer() { m_commandBuffer->QueueCommandBuffer(); } |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 256 | void QueueCommandBuffer(const VkFence &fence) { |
| 257 | m_commandBuffer->QueueCommandBuffer(fence); |
| 258 | } |
| 259 | void BindVertexBuffer(VkConstantBufferObj *vertexBuffer, |
| 260 | VkDeviceSize offset, uint32_t binding) { |
| 261 | m_commandBuffer->BindVertexBuffer(vertexBuffer, offset, binding); |
| 262 | } |
| 263 | void BindIndexBuffer(VkIndexBufferObj *indexBuffer, VkDeviceSize offset) { |
| 264 | m_commandBuffer->BindIndexBuffer(indexBuffer, offset); |
| 265 | } |
| 266 | |
| 267 | protected: |
| 268 | ErrorMonitor *m_errorMonitor; |
Ian Elliott | 2c1daf5 | 2016-05-12 09:41:46 -0600 | [diff] [blame] | 269 | bool m_enableWSI; |
Tony Barbour | 300a608 | 2015-04-07 13:44:53 -0600 | [diff] [blame] | 270 | |
| 271 | virtual void SetUp() { |
Courtney Goeltzenleuchter | cd69eee | 2015-07-06 09:10:47 -0600 | [diff] [blame] | 272 | std::vector<const char *> instance_layer_names; |
| 273 | std::vector<const char *> device_layer_names; |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 274 | std::vector<const char *> instance_extension_names; |
| 275 | std::vector<const char *> device_extension_names; |
Tony Barbour | 3fdff9e | 2015-04-23 12:55:36 -0600 | [diff] [blame] | 276 | |
Courtney Goeltzenleuchter | 7415d5a | 2015-12-09 15:48:16 -0700 | [diff] [blame] | 277 | instance_extension_names.push_back(VK_EXT_DEBUG_REPORT_EXTENSION_NAME); |
Courtney Goeltzenleuchter | c2b06fe | 2015-06-16 15:59:11 -0600 | [diff] [blame] | 278 | /* |
| 279 | * Since CreateDbgMsgCallback is an instance level extension call |
| 280 | * any extension / layer that utilizes that feature also needs |
| 281 | * to be enabled at create instance time. |
| 282 | */ |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 283 | // Use Threading layer first to protect others from |
| 284 | // ThreadCommandBufferCollision test |
Courtney Goeltzenleuchter | 7688532 | 2016-02-06 17:11:22 -0700 | [diff] [blame] | 285 | instance_layer_names.push_back("VK_LAYER_GOOGLE_threading"); |
Tobin Ehlis | 24aab04 | 2016-03-24 10:54:18 -0600 | [diff] [blame] | 286 | instance_layer_names.push_back("VK_LAYER_LUNARG_parameter_validation"); |
Michael Lentine | 03107b4 | 2015-12-11 10:49:51 -0800 | [diff] [blame] | 287 | instance_layer_names.push_back("VK_LAYER_LUNARG_object_tracker"); |
Tobin Ehlis | c96f806 | 2016-03-09 16:12:48 -0700 | [diff] [blame] | 288 | instance_layer_names.push_back("VK_LAYER_LUNARG_core_validation"); |
Michael Lentine | 03107b4 | 2015-12-11 10:49:51 -0800 | [diff] [blame] | 289 | instance_layer_names.push_back("VK_LAYER_LUNARG_device_limits"); |
| 290 | instance_layer_names.push_back("VK_LAYER_LUNARG_image"); |
Ian Elliott | e48a138 | 2016-04-28 14:22:58 -0600 | [diff] [blame] | 291 | instance_layer_names.push_back("VK_LAYER_LUNARG_swapchain"); |
Dustin Graves | eaa78cd | 2016-01-26 16:30:22 -0700 | [diff] [blame] | 292 | instance_layer_names.push_back("VK_LAYER_GOOGLE_unique_objects"); |
Courtney Goeltzenleuchter | d971b61 | 2015-06-17 20:51:59 -0600 | [diff] [blame] | 293 | |
Courtney Goeltzenleuchter | 7688532 | 2016-02-06 17:11:22 -0700 | [diff] [blame] | 294 | device_layer_names.push_back("VK_LAYER_GOOGLE_threading"); |
Tobin Ehlis | 24aab04 | 2016-03-24 10:54:18 -0600 | [diff] [blame] | 295 | device_layer_names.push_back("VK_LAYER_LUNARG_parameter_validation"); |
Michael Lentine | 03107b4 | 2015-12-11 10:49:51 -0800 | [diff] [blame] | 296 | device_layer_names.push_back("VK_LAYER_LUNARG_object_tracker"); |
Tobin Ehlis | c96f806 | 2016-03-09 16:12:48 -0700 | [diff] [blame] | 297 | device_layer_names.push_back("VK_LAYER_LUNARG_core_validation"); |
Michael Lentine | 03107b4 | 2015-12-11 10:49:51 -0800 | [diff] [blame] | 298 | device_layer_names.push_back("VK_LAYER_LUNARG_device_limits"); |
| 299 | device_layer_names.push_back("VK_LAYER_LUNARG_image"); |
Ian Elliott | e48a138 | 2016-04-28 14:22:58 -0600 | [diff] [blame] | 300 | device_layer_names.push_back("VK_LAYER_LUNARG_swapchain"); |
Dustin Graves | eaa78cd | 2016-01-26 16:30:22 -0700 | [diff] [blame] | 301 | device_layer_names.push_back("VK_LAYER_GOOGLE_unique_objects"); |
Tony Barbour | 300a608 | 2015-04-07 13:44:53 -0600 | [diff] [blame] | 302 | |
Ian Elliott | 2c1daf5 | 2016-05-12 09:41:46 -0600 | [diff] [blame] | 303 | if (m_enableWSI) { |
| 304 | instance_extension_names.push_back(VK_KHR_SURFACE_EXTENSION_NAME); |
| 305 | device_extension_names.push_back(VK_KHR_SWAPCHAIN_EXTENSION_NAME); |
| 306 | #ifdef NEED_TO_TEST_THIS_ON_PLATFORM |
| 307 | #if defined(VK_USE_PLATFORM_ANDROID_KHR) |
| 308 | instance_extension_names.push_back(VK_KHR_ANDROID_SURFACE_EXTENSION_NAME); |
| 309 | #endif // VK_USE_PLATFORM_ANDROID_KHR |
| 310 | #if defined(VK_USE_PLATFORM_MIR_KHR) |
| 311 | instance_extension_names.push_back(VK_KHR_MIR_SURFACE_EXTENSION_NAME); |
| 312 | #endif // VK_USE_PLATFORM_MIR_KHR |
| 313 | #if defined(VK_USE_PLATFORM_WAYLAND_KHR) |
| 314 | instance_extension_names.push_back(VK_KHR_WAYLAND_SURFACE_EXTENSION_NAME); |
| 315 | #endif // VK_USE_PLATFORM_WAYLAND_KHR |
| 316 | #if defined(VK_USE_PLATFORM_WIN32_KHR) |
| 317 | instance_extension_names.push_back(VK_KHR_WIN32_SURFACE_EXTENSION_NAME); |
| 318 | #endif // VK_USE_PLATFORM_WIN32_KHR |
| 319 | #endif // NEED_TO_TEST_THIS_ON_PLATFORM |
| 320 | #if defined(VK_USE_PLATFORM_XCB_KHR) |
| 321 | instance_extension_names.push_back(VK_KHR_XCB_SURFACE_EXTENSION_NAME); |
| 322 | #elif defined(VK_USE_PLATFORM_XLIB_KHR) |
| 323 | instance_extension_names.push_back(VK_KHR_XLIB_SURFACE_EXTENSION_NAME); |
| 324 | #endif // VK_USE_PLATFORM_XLIB_KHR |
| 325 | } |
| 326 | |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 327 | this->app_info.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO; |
Tony Barbour | 300a608 | 2015-04-07 13:44:53 -0600 | [diff] [blame] | 328 | this->app_info.pNext = NULL; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 329 | this->app_info.pApplicationName = "layer_tests"; |
| 330 | this->app_info.applicationVersion = 1; |
Tony Barbour | 300a608 | 2015-04-07 13:44:53 -0600 | [diff] [blame] | 331 | this->app_info.pEngineName = "unittest"; |
| 332 | this->app_info.engineVersion = 1; |
Jon Ashburn | c5012ff | 2016-03-22 13:57:46 -0600 | [diff] [blame] | 333 | this->app_info.apiVersion = VK_API_VERSION_1_0; |
Tony Barbour | 300a608 | 2015-04-07 13:44:53 -0600 | [diff] [blame] | 334 | |
Tony Barbour | 15524c3 | 2015-04-29 17:34:29 -0600 | [diff] [blame] | 335 | m_errorMonitor = new ErrorMonitor; |
Courtney Goeltzenleuchter | cd69eee | 2015-07-06 09:10:47 -0600 | [diff] [blame] | 336 | InitFramework(instance_layer_names, device_layer_names, |
| 337 | instance_extension_names, device_extension_names, |
| 338 | myDbgFunc, m_errorMonitor); |
Tony Barbour | 300a608 | 2015-04-07 13:44:53 -0600 | [diff] [blame] | 339 | } |
| 340 | |
| 341 | virtual void TearDown() { |
| 342 | // Clean up resources before we reset |
Tony Barbour | 300a608 | 2015-04-07 13:44:53 -0600 | [diff] [blame] | 343 | ShutdownFramework(); |
Tony Barbour | 0b4d956 | 2015-04-09 10:48:04 -0600 | [diff] [blame] | 344 | delete m_errorMonitor; |
Tony Barbour | 300a608 | 2015-04-07 13:44:53 -0600 | [diff] [blame] | 345 | } |
Ian Elliott | 2c1daf5 | 2016-05-12 09:41:46 -0600 | [diff] [blame] | 346 | |
| 347 | VkLayerTest() { |
| 348 | m_enableWSI = false; |
| 349 | } |
Tony Barbour | 300a608 | 2015-04-07 13:44:53 -0600 | [diff] [blame] | 350 | }; |
Mark Lobodzinski | 3780e14 | 2015-05-14 15:08:13 -0500 | [diff] [blame] | 351 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 352 | VkResult VkLayerTest::BeginCommandBuffer(VkCommandBufferObj &commandBuffer) { |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 353 | VkResult result; |
Tony Barbour | 300a608 | 2015-04-07 13:44:53 -0600 | [diff] [blame] | 354 | |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 355 | result = commandBuffer.BeginCommandBuffer(); |
Tony Barbour | 300a608 | 2015-04-07 13:44:53 -0600 | [diff] [blame] | 356 | |
| 357 | /* |
| 358 | * For render test all drawing happens in a single render pass |
| 359 | * on a single command buffer. |
| 360 | */ |
Chris Forbes | 76a5eeb | 2015-06-16 14:05:59 +1200 | [diff] [blame] | 361 | if (VK_SUCCESS == result && renderPass()) { |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 362 | commandBuffer.BeginRenderPass(renderPassBeginInfo()); |
Tony Barbour | 300a608 | 2015-04-07 13:44:53 -0600 | [diff] [blame] | 363 | } |
| 364 | |
| 365 | return result; |
| 366 | } |
| 367 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 368 | VkResult VkLayerTest::EndCommandBuffer(VkCommandBufferObj &commandBuffer) { |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 369 | VkResult result; |
Tony Barbour | 300a608 | 2015-04-07 13:44:53 -0600 | [diff] [blame] | 370 | |
Chris Forbes | 76a5eeb | 2015-06-16 14:05:59 +1200 | [diff] [blame] | 371 | if (renderPass()) { |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 372 | commandBuffer.EndRenderPass(); |
Chris Forbes | 76a5eeb | 2015-06-16 14:05:59 +1200 | [diff] [blame] | 373 | } |
Tony Barbour | 300a608 | 2015-04-07 13:44:53 -0600 | [diff] [blame] | 374 | |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 375 | result = commandBuffer.EndCommandBuffer(); |
Tony Barbour | 300a608 | 2015-04-07 13:44:53 -0600 | [diff] [blame] | 376 | |
| 377 | return result; |
| 378 | } |
| 379 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 380 | void VkLayerTest::VKTriangleTest(const char *vertShaderText, |
| 381 | const char *fragShaderText, |
| 382 | BsoFailSelect failMask) { |
Mark Lobodzinski | 3780e14 | 2015-05-14 15:08:13 -0500 | [diff] [blame] | 383 | // Create identity matrix |
| 384 | int i; |
| 385 | struct vktriangle_vs_uniform data; |
| 386 | |
| 387 | glm::mat4 Projection = glm::mat4(1.0f); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 388 | glm::mat4 View = glm::mat4(1.0f); |
| 389 | glm::mat4 Model = glm::mat4(1.0f); |
| 390 | glm::mat4 MVP = Projection * View * Model; |
Mark Lobodzinski | 3780e14 | 2015-05-14 15:08:13 -0500 | [diff] [blame] | 391 | const int matrixSize = sizeof(MVP); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 392 | const int bufSize = sizeof(vktriangle_vs_uniform) / sizeof(float); |
Mark Lobodzinski | 3780e14 | 2015-05-14 15:08:13 -0500 | [diff] [blame] | 393 | |
| 394 | memcpy(&data.mvp, &MVP[0][0], matrixSize); |
| 395 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 396 | static const Vertex tri_data[] = { |
| 397 | {XYZ1(-1, -1, 0), XYZ1(1.f, 0.f, 0.f)}, |
| 398 | {XYZ1(1, -1, 0), XYZ1(0.f, 1.f, 0.f)}, |
| 399 | {XYZ1(0, 1, 0), XYZ1(0.f, 0.f, 1.f)}, |
Mark Lobodzinski | 3780e14 | 2015-05-14 15:08:13 -0500 | [diff] [blame] | 400 | }; |
| 401 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 402 | for (i = 0; i < 3; i++) { |
Mark Lobodzinski | 3780e14 | 2015-05-14 15:08:13 -0500 | [diff] [blame] | 403 | data.position[i][0] = tri_data[i].posX; |
| 404 | data.position[i][1] = tri_data[i].posY; |
| 405 | data.position[i][2] = tri_data[i].posZ; |
| 406 | data.position[i][3] = tri_data[i].posW; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 407 | data.color[i][0] = tri_data[i].r; |
| 408 | data.color[i][1] = tri_data[i].g; |
| 409 | data.color[i][2] = tri_data[i].b; |
| 410 | data.color[i][3] = tri_data[i].a; |
Mark Lobodzinski | 3780e14 | 2015-05-14 15:08:13 -0500 | [diff] [blame] | 411 | } |
| 412 | |
| 413 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 414 | ASSERT_NO_FATAL_FAILURE(InitViewport()); |
| 415 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 416 | VkConstantBufferObj constantBuffer(m_device, bufSize * 2, sizeof(float), |
| 417 | (const void *)&data); |
Mark Lobodzinski | 3780e14 | 2015-05-14 15:08:13 -0500 | [diff] [blame] | 418 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 419 | VkShaderObj vs(m_device, vertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this); |
| 420 | VkShaderObj ps(m_device, fragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, |
| 421 | this); |
Mark Lobodzinski | 3780e14 | 2015-05-14 15:08:13 -0500 | [diff] [blame] | 422 | |
| 423 | VkPipelineObj pipelineobj(m_device); |
Chia-I Wu | 08accc6 | 2015-07-07 11:50:03 +0800 | [diff] [blame] | 424 | pipelineobj.AddColorAttachment(); |
Mark Lobodzinski | 3780e14 | 2015-05-14 15:08:13 -0500 | [diff] [blame] | 425 | pipelineobj.AddShader(&vs); |
| 426 | pipelineobj.AddShader(&ps); |
Courtney Goeltzenleuchter | 507ba97 | 2015-09-30 16:16:57 -0600 | [diff] [blame] | 427 | if (failMask & BsoFailLineWidth) { |
| 428 | pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_LINE_WIDTH); |
Tobin Ehlis | 7a1d235 | 2016-03-28 11:18:19 -0600 | [diff] [blame] | 429 | VkPipelineInputAssemblyStateCreateInfo ia_state = {}; |
| 430 | ia_state.sType = |
| 431 | VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO; |
| 432 | ia_state.topology = VK_PRIMITIVE_TOPOLOGY_LINE_LIST; |
| 433 | pipelineobj.SetInputAssembly(&ia_state); |
Courtney Goeltzenleuchter | 507ba97 | 2015-09-30 16:16:57 -0600 | [diff] [blame] | 434 | } |
| 435 | if (failMask & BsoFailDepthBias) { |
| 436 | pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_DEPTH_BIAS); |
Tobin Ehlis | 7a1d235 | 2016-03-28 11:18:19 -0600 | [diff] [blame] | 437 | VkPipelineRasterizationStateCreateInfo rs_state = {}; |
| 438 | rs_state.sType = |
| 439 | VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO; |
| 440 | rs_state.depthBiasEnable = VK_TRUE; |
Mark Young | 7394fdd | 2016-03-31 14:56:43 -0600 | [diff] [blame] | 441 | rs_state.lineWidth = 1.0f; |
Tobin Ehlis | 7a1d235 | 2016-03-28 11:18:19 -0600 | [diff] [blame] | 442 | pipelineobj.SetRasterization(&rs_state); |
Courtney Goeltzenleuchter | 507ba97 | 2015-09-30 16:16:57 -0600 | [diff] [blame] | 443 | } |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 444 | // Viewport and scissors must stay in synch or other errors will occur than |
| 445 | // the ones we want |
Courtney Goeltzenleuchter | 507ba97 | 2015-09-30 16:16:57 -0600 | [diff] [blame] | 446 | if (failMask & BsoFailViewport) { |
| 447 | pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_VIEWPORT); |
Tobin Ehlis | d332f28 | 2015-10-02 11:00:56 -0600 | [diff] [blame] | 448 | m_viewports.clear(); |
| 449 | m_scissors.clear(); |
Courtney Goeltzenleuchter | 507ba97 | 2015-09-30 16:16:57 -0600 | [diff] [blame] | 450 | } |
| 451 | if (failMask & BsoFailScissor) { |
| 452 | pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_SCISSOR); |
Tobin Ehlis | d332f28 | 2015-10-02 11:00:56 -0600 | [diff] [blame] | 453 | m_scissors.clear(); |
| 454 | m_viewports.clear(); |
Courtney Goeltzenleuchter | 507ba97 | 2015-09-30 16:16:57 -0600 | [diff] [blame] | 455 | } |
| 456 | if (failMask & BsoFailBlend) { |
| 457 | pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_BLEND_CONSTANTS); |
Tobin Ehlis | 7a1d235 | 2016-03-28 11:18:19 -0600 | [diff] [blame] | 458 | VkPipelineColorBlendAttachmentState att_state = {}; |
| 459 | att_state.dstAlphaBlendFactor = VK_BLEND_FACTOR_CONSTANT_COLOR; |
| 460 | att_state.blendEnable = VK_TRUE; |
| 461 | pipelineobj.AddColorAttachment(0, &att_state); |
Courtney Goeltzenleuchter | 507ba97 | 2015-09-30 16:16:57 -0600 | [diff] [blame] | 462 | } |
| 463 | if (failMask & BsoFailDepthBounds) { |
| 464 | pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_DEPTH_BOUNDS); |
| 465 | } |
| 466 | if (failMask & BsoFailStencilReadMask) { |
| 467 | pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_STENCIL_COMPARE_MASK); |
| 468 | } |
| 469 | if (failMask & BsoFailStencilWriteMask) { |
| 470 | pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_STENCIL_WRITE_MASK); |
| 471 | } |
| 472 | if (failMask & BsoFailStencilReference) { |
| 473 | pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_STENCIL_REFERENCE); |
| 474 | } |
Mark Lobodzinski | 3780e14 | 2015-05-14 15:08:13 -0500 | [diff] [blame] | 475 | |
| 476 | VkDescriptorSetObj descriptorSet(m_device); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 477 | descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, |
| 478 | constantBuffer); |
Mark Lobodzinski | 3780e14 | 2015-05-14 15:08:13 -0500 | [diff] [blame] | 479 | |
| 480 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
Tony Barbour | fe3351b | 2015-07-28 10:17:20 -0600 | [diff] [blame] | 481 | ASSERT_VK_SUCCESS(BeginCommandBuffer()); |
Mark Lobodzinski | 3780e14 | 2015-05-14 15:08:13 -0500 | [diff] [blame] | 482 | |
Tony Barbour | fe3351b | 2015-07-28 10:17:20 -0600 | [diff] [blame] | 483 | GenericDrawPreparation(pipelineobj, descriptorSet, failMask); |
Mark Lobodzinski | 3780e14 | 2015-05-14 15:08:13 -0500 | [diff] [blame] | 484 | |
| 485 | // render triangle |
Courtney Goeltzenleuchter | 08c2637 | 2015-09-23 12:31:50 -0600 | [diff] [blame] | 486 | Draw(3, 1, 0, 0); |
Mark Lobodzinski | 3780e14 | 2015-05-14 15:08:13 -0500 | [diff] [blame] | 487 | |
Mark Mueller | d491441 | 2016-06-13 17:52:06 -0600 | [diff] [blame] | 488 | if (failMask & BsoFailCmdClearAttachments) { |
| 489 | VkClearAttachment color_attachment = {}; |
| 490 | color_attachment.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; |
| 491 | color_attachment.colorAttachment = 1; // Someone who knew what they were doing would use 0 for the index; |
| 492 | VkClearRect clear_rect = {{{0, 0}, {static_cast<uint32_t>(m_width), static_cast<uint32_t>(m_height)}}, 0, 0}; |
| 493 | |
| 494 | vkCmdClearAttachments(m_commandBuffer->GetBufferHandle(), 1, |
| 495 | &color_attachment, 1, &clear_rect); |
| 496 | } |
| 497 | |
Mark Lobodzinski | 3780e14 | 2015-05-14 15:08:13 -0500 | [diff] [blame] | 498 | // finalize recording of the command buffer |
Tony Barbour | fe3351b | 2015-07-28 10:17:20 -0600 | [diff] [blame] | 499 | EndCommandBuffer(); |
Mark Lobodzinski | 3780e14 | 2015-05-14 15:08:13 -0500 | [diff] [blame] | 500 | |
Tony Barbour | fe3351b | 2015-07-28 10:17:20 -0600 | [diff] [blame] | 501 | QueueCommandBuffer(); |
Mark Lobodzinski | 3780e14 | 2015-05-14 15:08:13 -0500 | [diff] [blame] | 502 | } |
| 503 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 504 | void VkLayerTest::GenericDrawPreparation(VkCommandBufferObj *commandBuffer, |
| 505 | VkPipelineObj &pipelineobj, |
| 506 | VkDescriptorSetObj &descriptorSet, |
| 507 | BsoFailSelect failMask) { |
Mark Lobodzinski | 3780e14 | 2015-05-14 15:08:13 -0500 | [diff] [blame] | 508 | if (m_depthStencil->Initialized()) { |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 509 | commandBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color, |
| 510 | m_stencil_clear_color, m_depthStencil); |
Mark Lobodzinski | 3780e14 | 2015-05-14 15:08:13 -0500 | [diff] [blame] | 511 | } else { |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 512 | commandBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color, |
| 513 | m_stencil_clear_color, NULL); |
Mark Lobodzinski | 3780e14 | 2015-05-14 15:08:13 -0500 | [diff] [blame] | 514 | } |
| 515 | |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 516 | commandBuffer->PrepareAttachments(); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 517 | // Make sure depthWriteEnable is set so that Depth fail test will work |
| 518 | // correctly |
| 519 | // Make sure stencilTestEnable is set so that Stencil fail test will work |
| 520 | // correctly |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 521 | VkStencilOpState stencil = {}; |
Chia-I Wu | 1b99bb2 | 2015-10-27 19:25:11 +0800 | [diff] [blame] | 522 | stencil.failOp = VK_STENCIL_OP_KEEP; |
| 523 | stencil.passOp = VK_STENCIL_OP_KEEP; |
| 524 | stencil.depthFailOp = VK_STENCIL_OP_KEEP; |
| 525 | stencil.compareOp = VK_COMPARE_OP_NEVER; |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 526 | |
| 527 | VkPipelineDepthStencilStateCreateInfo ds_ci = {}; |
| 528 | ds_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DEPTH_STENCIL_STATE_CREATE_INFO; |
Courtney Goeltzenleuchter | 507ba97 | 2015-09-30 16:16:57 -0600 | [diff] [blame] | 529 | ds_ci.pNext = NULL; |
| 530 | ds_ci.depthTestEnable = VK_FALSE; |
| 531 | ds_ci.depthWriteEnable = VK_TRUE; |
| 532 | ds_ci.depthCompareOp = VK_COMPARE_OP_NEVER; |
| 533 | ds_ci.depthBoundsTestEnable = VK_FALSE; |
Tobin Ehlis | 7a1d235 | 2016-03-28 11:18:19 -0600 | [diff] [blame] | 534 | if (failMask & BsoFailDepthBounds) { |
| 535 | ds_ci.depthBoundsTestEnable = VK_TRUE; |
Tobin Ehlis | 21c8835 | 2016-05-26 06:15:45 -0600 | [diff] [blame] | 536 | ds_ci.maxDepthBounds = 0.0f; |
| 537 | ds_ci.minDepthBounds = 0.0f; |
Tobin Ehlis | 7a1d235 | 2016-03-28 11:18:19 -0600 | [diff] [blame] | 538 | } |
Courtney Goeltzenleuchter | 507ba97 | 2015-09-30 16:16:57 -0600 | [diff] [blame] | 539 | ds_ci.stencilTestEnable = VK_TRUE; |
| 540 | ds_ci.front = stencil; |
| 541 | ds_ci.back = stencil; |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 542 | |
Tobin Ehlis | 4bf96d1 | 2015-06-25 11:58:41 -0600 | [diff] [blame] | 543 | pipelineobj.SetDepthStencil(&ds_ci); |
Tobin Ehlis | d332f28 | 2015-10-02 11:00:56 -0600 | [diff] [blame] | 544 | pipelineobj.SetViewport(m_viewports); |
| 545 | pipelineobj.SetScissor(m_scissors); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 546 | descriptorSet.CreateVKDescriptorSet(commandBuffer); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 547 | VkResult err = pipelineobj.CreateVKPipeline( |
| 548 | descriptorSet.GetPipelineLayout(), renderPass()); |
Cody Northrop | 29a08f2 | 2015-08-27 10:20:35 -0600 | [diff] [blame] | 549 | ASSERT_VK_SUCCESS(err); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 550 | commandBuffer->BindPipeline(pipelineobj); |
| 551 | commandBuffer->BindDescriptorSet(descriptorSet); |
Mark Lobodzinski | 3780e14 | 2015-05-14 15:08:13 -0500 | [diff] [blame] | 552 | } |
| 553 | |
Ian Elliott | 2c1daf5 | 2016-05-12 09:41:46 -0600 | [diff] [blame] | 554 | class VkWsiEnabledLayerTest : public VkLayerTest { |
| 555 | public: |
| 556 | protected: |
| 557 | VkWsiEnabledLayerTest() { |
| 558 | m_enableWSI = true; |
| 559 | } |
| 560 | }; |
| 561 | |
Mark Lobodzinski | 3780e14 | 2015-05-14 15:08:13 -0500 | [diff] [blame] | 562 | // ******************************************************************************************************************** |
| 563 | // ******************************************************************************************************************** |
| 564 | // ******************************************************************************************************************** |
| 565 | // ******************************************************************************************************************** |
Dustin Graves | ffa90fa | 2016-05-06 11:20:38 -0600 | [diff] [blame] | 566 | #if PARAMETER_VALIDATION_TESTS |
| 567 | TEST_F(VkLayerTest, RequiredParameter) { |
| 568 | TEST_DESCRIPTION("Specify VK_NULL_HANDLE, NULL, and 0 for required handle, " |
| 569 | "pointer, array, and array count parameters"); |
| 570 | |
| 571 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 572 | |
| 573 | m_errorMonitor->SetDesiredFailureMsg( |
| 574 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 575 | "required parameter pFeatures specified as NULL"); |
| 576 | // Specify NULL for a pointer to a handle |
| 577 | // Expected to trigger an error with |
| 578 | // parameter_validation::validate_required_pointer |
| 579 | vkGetPhysicalDeviceFeatures(gpu(), NULL); |
| 580 | m_errorMonitor->VerifyFound(); |
| 581 | |
| 582 | m_errorMonitor->SetDesiredFailureMsg( |
| 583 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Dustin Graves | a4bb8c1 | 2016-05-16 17:22:51 -0600 | [diff] [blame] | 584 | "required parameter pQueueFamilyPropertyCount specified as NULL"); |
Dustin Graves | ffa90fa | 2016-05-06 11:20:38 -0600 | [diff] [blame] | 585 | // Specify NULL for pointer to array count |
| 586 | // Expected to trigger an error with parameter_validation::validate_array |
Dustin Graves | a4bb8c1 | 2016-05-16 17:22:51 -0600 | [diff] [blame] | 587 | vkGetPhysicalDeviceQueueFamilyProperties(gpu(), NULL, NULL); |
Dustin Graves | ffa90fa | 2016-05-06 11:20:38 -0600 | [diff] [blame] | 588 | m_errorMonitor->VerifyFound(); |
| 589 | |
| 590 | m_errorMonitor->SetDesiredFailureMsg( |
| 591 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 592 | "parameter viewportCount must be greater than 0"); |
| 593 | // Specify 0 for a required array count |
| 594 | // Expected to trigger an error with parameter_validation::validate_array |
| 595 | VkViewport view_port = {}; |
| 596 | m_commandBuffer->SetViewport(0, 0, &view_port); |
| 597 | m_errorMonitor->VerifyFound(); |
| 598 | |
| 599 | m_errorMonitor->SetDesiredFailureMsg( |
| 600 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 601 | "required parameter pViewports specified as NULL"); |
| 602 | // Specify NULL for a required array |
| 603 | // Expected to trigger an error with parameter_validation::validate_array |
| 604 | m_commandBuffer->SetViewport(0, 1, NULL); |
| 605 | m_errorMonitor->VerifyFound(); |
| 606 | |
| 607 | m_errorMonitor->SetDesiredFailureMsg( |
| 608 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 609 | "required parameter memory specified as VK_NULL_HANDLE"); |
| 610 | // Specify VK_NULL_HANDLE for a required handle |
| 611 | // Expected to trigger an error with |
| 612 | // parameter_validation::validate_required_handle |
| 613 | vkUnmapMemory(device(), VK_NULL_HANDLE); |
| 614 | m_errorMonitor->VerifyFound(); |
| 615 | |
| 616 | m_errorMonitor->SetDesiredFailureMsg( |
| 617 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 618 | "required parameter pFences[0] specified as VK_NULL_HANDLE"); |
| 619 | // Specify VK_NULL_HANDLE for a required handle array entry |
| 620 | // Expected to trigger an error with |
| 621 | // parameter_validation::validate_required_handle_array |
| 622 | VkFence fence = VK_NULL_HANDLE; |
| 623 | vkResetFences(device(), 1, &fence); |
| 624 | m_errorMonitor->VerifyFound(); |
| 625 | |
| 626 | m_errorMonitor->SetDesiredFailureMsg( |
| 627 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 628 | "required parameter pAllocateInfo specified as NULL"); |
| 629 | // Specify NULL for a required struct pointer |
| 630 | // Expected to trigger an error with |
| 631 | // parameter_validation::validate_struct_type |
| 632 | VkDeviceMemory memory = VK_NULL_HANDLE; |
| 633 | vkAllocateMemory(device(), NULL, NULL, &memory); |
| 634 | m_errorMonitor->VerifyFound(); |
| 635 | |
| 636 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 637 | "value of faceMask must not be 0"); |
| 638 | // Specify 0 for a required VkFlags parameter |
| 639 | // Expected to trigger an error with parameter_validation::validate_flags |
| 640 | m_commandBuffer->SetStencilReference(0, 0); |
| 641 | m_errorMonitor->VerifyFound(); |
| 642 | |
| 643 | m_errorMonitor->SetDesiredFailureMsg( |
| 644 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 645 | "value of pSubmits[i].pWaitDstStageMask[0] must not be 0"); |
| 646 | // Specify 0 for a required VkFlags array entry |
| 647 | // Expected to trigger an error with |
| 648 | // parameter_validation::validate_flags_array |
| 649 | VkSemaphore semaphore = VK_NULL_HANDLE; |
| 650 | VkPipelineStageFlags stageFlags = 0; |
| 651 | VkSubmitInfo submitInfo = {}; |
| 652 | submitInfo.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO; |
| 653 | submitInfo.waitSemaphoreCount = 1; |
| 654 | submitInfo.pWaitSemaphores = &semaphore; |
| 655 | submitInfo.pWaitDstStageMask = &stageFlags; |
| 656 | vkQueueSubmit(m_device->m_queue, 1, &submitInfo, VK_NULL_HANDLE); |
| 657 | m_errorMonitor->VerifyFound(); |
| 658 | } |
Dustin Graves | c99cf5a | 2016-05-09 14:40:29 -0600 | [diff] [blame] | 659 | |
Dustin Graves | fce74c0 | 2016-05-10 11:42:58 -0600 | [diff] [blame] | 660 | TEST_F(VkLayerTest, ReservedParameter) { |
| 661 | TEST_DESCRIPTION("Specify a non-zero value for a reserved parameter"); |
| 662 | |
| 663 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 664 | |
| 665 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 666 | " must be 0"); |
| 667 | // Specify 0 for a reserved VkFlags parameter |
| 668 | // Expected to trigger an error with |
| 669 | // parameter_validation::validate_reserved_flags |
| 670 | VkEvent event_handle = VK_NULL_HANDLE; |
| 671 | VkEventCreateInfo event_info = {}; |
| 672 | event_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO; |
| 673 | event_info.flags = 1; |
| 674 | vkCreateEvent(device(), &event_info, NULL, &event_handle); |
| 675 | m_errorMonitor->VerifyFound(); |
| 676 | } |
| 677 | |
Dustin Graves | c99cf5a | 2016-05-09 14:40:29 -0600 | [diff] [blame] | 678 | TEST_F(VkLayerTest, InvalidStructSType) { |
| 679 | TEST_DESCRIPTION("Specify an invalid VkStructureType for a Vulkan " |
| 680 | "structure's sType field"); |
| 681 | |
| 682 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 683 | |
| 684 | m_errorMonitor->SetDesiredFailureMsg( |
| 685 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 686 | "parameter pAllocateInfo->sType must be"); |
| 687 | // Zero struct memory, effectively setting sType to |
| 688 | // VK_STRUCTURE_TYPE_APPLICATION_INFO |
| 689 | // Expected to trigger an error with |
| 690 | // parameter_validation::validate_struct_type |
| 691 | VkMemoryAllocateInfo alloc_info = {}; |
| 692 | VkDeviceMemory memory = VK_NULL_HANDLE; |
| 693 | vkAllocateMemory(device(), &alloc_info, NULL, &memory); |
| 694 | m_errorMonitor->VerifyFound(); |
| 695 | |
| 696 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 697 | "parameter pSubmits[0].sType must be"); |
| 698 | // Zero struct memory, effectively setting sType to |
| 699 | // VK_STRUCTURE_TYPE_APPLICATION_INFO |
| 700 | // Expected to trigger an error with |
| 701 | // parameter_validation::validate_struct_type_array |
| 702 | VkSubmitInfo submit_info = {}; |
| 703 | vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE); |
| 704 | m_errorMonitor->VerifyFound(); |
| 705 | } |
| 706 | |
| 707 | TEST_F(VkLayerTest, InvalidStructPNext) { |
| 708 | TEST_DESCRIPTION( |
| 709 | "Specify an invalid value for a Vulkan structure's pNext field"); |
| 710 | |
| 711 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 712 | |
| 713 | m_errorMonitor->SetDesiredFailureMsg( |
| 714 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 715 | "value of pAllocateInfo->pNext must be NULL"); |
| 716 | // Set VkMemoryAllocateInfo::pNext to a non-NULL value, when pNext must be |
| 717 | // NULL |
| 718 | // Expected to trigger an error with |
| 719 | // parameter_validation::validate_struct_pnext |
| 720 | VkDeviceMemory memory = VK_NULL_HANDLE; |
| 721 | // Zero-initialization will provide the correct sType |
| 722 | VkApplicationInfo app_info = {}; |
Dustin Graves | 47b6cba | 2016-05-10 17:34:38 -0600 | [diff] [blame] | 723 | VkMemoryAllocateInfo memory_alloc_info = {}; |
| 724 | memory_alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO; |
| 725 | memory_alloc_info.pNext = &app_info; |
| 726 | vkAllocateMemory(device(), &memory_alloc_info, NULL, &memory); |
Dustin Graves | c99cf5a | 2016-05-09 14:40:29 -0600 | [diff] [blame] | 727 | m_errorMonitor->VerifyFound(); |
| 728 | |
Dustin Graves | 47b6cba | 2016-05-10 17:34:38 -0600 | [diff] [blame] | 729 | m_errorMonitor->SetDesiredFailureMsg( |
| 730 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 731 | " chain includes a structure with unexpected VkStructureType "); |
| 732 | // Set VkGraphicsPipelineCreateInfo::VkPipelineRasterizationStateCreateInfo::pNext to an invalid structure, when pNext is allowed to be a non-NULL value |
| 733 | // Expected to trigger an error with |
| 734 | // parameter_validation::validate_struct_pnext |
| 735 | VkDescriptorPoolSize ds_type_count = {}; |
| 736 | ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 737 | ds_type_count.descriptorCount = 1; |
| 738 | |
| 739 | VkDescriptorPoolCreateInfo ds_pool_ci = {}; |
| 740 | ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO; |
| 741 | ds_pool_ci.pNext = NULL; |
| 742 | ds_pool_ci.maxSets = 1; |
| 743 | ds_pool_ci.poolSizeCount = 1; |
| 744 | ds_pool_ci.pPoolSizes = &ds_type_count; |
| 745 | |
| 746 | VkDescriptorPool ds_pool; |
| 747 | VkResult err = |
| 748 | vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool); |
| 749 | ASSERT_VK_SUCCESS(err); |
| 750 | |
| 751 | VkDescriptorSetLayoutBinding dsl_binding = {}; |
| 752 | dsl_binding.binding = 0; |
| 753 | dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 754 | dsl_binding.descriptorCount = 1; |
| 755 | dsl_binding.stageFlags = VK_SHADER_STAGE_ALL; |
| 756 | dsl_binding.pImmutableSamplers = NULL; |
| 757 | |
| 758 | VkDescriptorSetLayoutCreateInfo ds_layout_ci = {}; |
| 759 | ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO; |
| 760 | ds_layout_ci.pNext = NULL; |
| 761 | ds_layout_ci.bindingCount = 1; |
| 762 | ds_layout_ci.pBindings = &dsl_binding; |
| 763 | |
| 764 | VkDescriptorSetLayout ds_layout; |
| 765 | err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, |
| 766 | &ds_layout); |
| 767 | ASSERT_VK_SUCCESS(err); |
| 768 | |
| 769 | VkDescriptorSet descriptorSet; |
| 770 | VkDescriptorSetAllocateInfo ds_alloc_info = {}; |
| 771 | ds_alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO; |
| 772 | ds_alloc_info.descriptorSetCount = 1; |
| 773 | ds_alloc_info.descriptorPool = ds_pool; |
| 774 | ds_alloc_info.pSetLayouts = &ds_layout; |
| 775 | err = vkAllocateDescriptorSets(m_device->device(), &ds_alloc_info, |
| 776 | &descriptorSet); |
| 777 | ASSERT_VK_SUCCESS(err); |
| 778 | |
| 779 | VkPipelineLayoutCreateInfo pipeline_layout_ci = {}; |
| 780 | pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO; |
| 781 | pipeline_layout_ci.setLayoutCount = 1; |
| 782 | pipeline_layout_ci.pSetLayouts = &ds_layout; |
| 783 | |
| 784 | VkPipelineLayout pipeline_layout; |
| 785 | err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, |
| 786 | &pipeline_layout); |
| 787 | ASSERT_VK_SUCCESS(err); |
| 788 | |
| 789 | VkViewport vp = {}; // Just need dummy vp to point to |
| 790 | VkRect2D sc = {}; // dummy scissor to point to |
| 791 | |
| 792 | VkPipelineViewportStateCreateInfo vp_state_ci = {}; |
| 793 | vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO; |
| 794 | vp_state_ci.scissorCount = 1; |
| 795 | vp_state_ci.pScissors = ≻ |
| 796 | vp_state_ci.viewportCount = 1; |
| 797 | vp_state_ci.pViewports = &vp; |
| 798 | |
| 799 | VkPipelineRasterizationStateCreateInfo rs_state_ci = {}; |
| 800 | rs_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO; |
| 801 | rs_state_ci.polygonMode = VK_POLYGON_MODE_FILL; |
| 802 | rs_state_ci.cullMode = VK_CULL_MODE_BACK_BIT; |
| 803 | rs_state_ci.frontFace = VK_FRONT_FACE_COUNTER_CLOCKWISE; |
| 804 | rs_state_ci.depthClampEnable = VK_FALSE; |
| 805 | rs_state_ci.rasterizerDiscardEnable = VK_FALSE; |
| 806 | rs_state_ci.depthBiasEnable = VK_FALSE; |
| 807 | |
| 808 | VkGraphicsPipelineCreateInfo gp_ci = {}; |
| 809 | gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO; |
| 810 | gp_ci.pViewportState = &vp_state_ci; |
| 811 | gp_ci.pRasterizationState = &rs_state_ci; |
| 812 | gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT; |
| 813 | gp_ci.layout = pipeline_layout; |
| 814 | gp_ci.renderPass = renderPass(); |
| 815 | |
| 816 | VkPipelineCacheCreateInfo pc_ci = {}; |
| 817 | pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO; |
| 818 | pc_ci.initialDataSize = 0; |
| 819 | pc_ci.pInitialData = 0; |
| 820 | |
| 821 | VkPipeline pipeline; |
| 822 | VkPipelineCache pipelineCache; |
| 823 | |
| 824 | err = |
| 825 | vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache); |
| 826 | ASSERT_VK_SUCCESS(err); |
| 827 | |
| 828 | // Set VkPipelineRasterizationStateCreateInfo::pNext to an invalid value |
| 829 | VkApplicationInfo invalid_pnext_struct = {}; |
| 830 | rs_state_ci.pNext = &invalid_pnext_struct; |
| 831 | |
| 832 | vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, |
| 833 | &gp_ci, NULL, &pipeline); |
| 834 | m_errorMonitor->VerifyFound(); |
Tony Barbour | df4c004 | 2016-06-01 15:55:43 -0600 | [diff] [blame] | 835 | vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL); |
| 836 | vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL); |
| 837 | vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL); |
| 838 | vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL); |
| 839 | |
Dustin Graves | c99cf5a | 2016-05-09 14:40:29 -0600 | [diff] [blame] | 840 | } |
Dustin Graves | 5d33d53 | 2016-05-09 16:21:12 -0600 | [diff] [blame] | 841 | |
| 842 | TEST_F(VkLayerTest, UnrecognizedValue) { |
| 843 | TEST_DESCRIPTION( |
| 844 | "Specify unrecognized Vulkan enumeration, flags, and VkBool32 values"); |
| 845 | |
| 846 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 847 | |
| 848 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 849 | "does not fall within the begin..end " |
| 850 | "range of the core VkFormat " |
| 851 | "enumeration tokens"); |
| 852 | // Specify an invalid VkFormat value |
| 853 | // Expected to trigger an error with |
| 854 | // parameter_validation::validate_ranged_enum |
| 855 | VkFormatProperties format_properties; |
| 856 | vkGetPhysicalDeviceFormatProperties(gpu(), static_cast<VkFormat>(8000), |
| 857 | &format_properties); |
| 858 | m_errorMonitor->VerifyFound(); |
| 859 | |
| 860 | m_errorMonitor->SetDesiredFailureMsg( |
| 861 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 862 | "contains flag bits that are not recognized members of"); |
| 863 | // Specify an invalid VkFlags bitmask value |
| 864 | // Expected to trigger an error with parameter_validation::validate_flags |
| 865 | VkImageFormatProperties image_format_properties; |
| 866 | vkGetPhysicalDeviceImageFormatProperties( |
| 867 | gpu(), VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_TYPE_2D, |
| 868 | VK_IMAGE_TILING_OPTIMAL, static_cast<VkImageUsageFlags>(1 << 25), 0, |
| 869 | &image_format_properties); |
| 870 | m_errorMonitor->VerifyFound(); |
| 871 | |
| 872 | m_errorMonitor->SetDesiredFailureMsg( |
| 873 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 874 | "contains flag bits that are not recognized members of"); |
| 875 | // Specify an invalid VkFlags array entry |
| 876 | // Expected to trigger an error with |
| 877 | // parameter_validation::validate_flags_array |
| 878 | VkSemaphore semaphore = VK_NULL_HANDLE; |
| 879 | VkPipelineStageFlags stage_flags = |
| 880 | static_cast<VkPipelineStageFlags>(1 << 25); |
| 881 | VkSubmitInfo submit_info = {}; |
| 882 | submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO; |
| 883 | submit_info.waitSemaphoreCount = 1; |
| 884 | submit_info.pWaitSemaphores = &semaphore; |
| 885 | submit_info.pWaitDstStageMask = &stage_flags; |
| 886 | vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE); |
| 887 | m_errorMonitor->VerifyFound(); |
| 888 | |
| 889 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, |
| 890 | "is neither VK_TRUE nor VK_FALSE"); |
| 891 | // Specify an invalid VkBool32 value |
| 892 | // Expected to trigger a warning with |
| 893 | // parameter_validation::validate_bool32 |
| 894 | VkSampler sampler = VK_NULL_HANDLE; |
| 895 | VkSamplerCreateInfo sampler_info = {}; |
| 896 | sampler_info.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO; |
| 897 | sampler_info.pNext = NULL; |
| 898 | sampler_info.magFilter = VK_FILTER_NEAREST; |
| 899 | sampler_info.minFilter = VK_FILTER_NEAREST; |
| 900 | sampler_info.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST; |
| 901 | sampler_info.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE; |
| 902 | sampler_info.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE; |
| 903 | sampler_info.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE; |
| 904 | sampler_info.mipLodBias = 1.0; |
| 905 | sampler_info.maxAnisotropy = 1; |
| 906 | sampler_info.compareEnable = VK_FALSE; |
| 907 | sampler_info.compareOp = VK_COMPARE_OP_NEVER; |
| 908 | sampler_info.minLod = 1.0; |
| 909 | sampler_info.maxLod = 1.0; |
| 910 | sampler_info.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE; |
| 911 | sampler_info.unnormalizedCoordinates = VK_FALSE; |
| 912 | // Not VK_TRUE or VK_FALSE |
| 913 | sampler_info.anisotropyEnable = 3; |
| 914 | vkCreateSampler(m_device->device(), &sampler_info, NULL, &sampler); |
| 915 | m_errorMonitor->VerifyFound(); |
| 916 | } |
Dustin Graves | fce74c0 | 2016-05-10 11:42:58 -0600 | [diff] [blame] | 917 | |
| 918 | TEST_F(VkLayerTest, FailedReturnValue) { |
| 919 | TEST_DESCRIPTION("Check for a message describing a VkResult failure code"); |
| 920 | |
| 921 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 922 | |
Dustin Graves | 13c1e2b | 2016-05-16 15:31:02 -0600 | [diff] [blame] | 923 | // Find an unsupported image format |
| 924 | VkFormat unsupported = VK_FORMAT_UNDEFINED; |
| 925 | for (int f = VK_FORMAT_BEGIN_RANGE; f <= VK_FORMAT_END_RANGE; f++) { |
| 926 | VkFormat format = static_cast<VkFormat>(f); |
| 927 | VkFormatProperties fProps = m_device->format_properties(format); |
| 928 | if (format != VK_FORMAT_UNDEFINED && fProps.linearTilingFeatures == 0 && |
| 929 | fProps.optimalTilingFeatures == 0) { |
| 930 | unsupported = format; |
| 931 | break; |
| 932 | } |
| 933 | } |
| 934 | |
| 935 | if (unsupported != VK_FORMAT_UNDEFINED) { |
| 936 | m_errorMonitor->SetDesiredFailureMsg( |
| 937 | VK_DEBUG_REPORT_WARNING_BIT_EXT, |
| 938 | "the requested format is not supported on this device"); |
| 939 | // Specify an unsupported VkFormat value to generate a |
| 940 | // VK_ERROR_FORMAT_NOT_SUPPORTED return code |
| 941 | // Expected to trigger a warning from |
| 942 | // parameter_validation::validate_result |
| 943 | VkImageFormatProperties image_format_properties; |
| 944 | VkResult err = vkGetPhysicalDeviceImageFormatProperties( |
| 945 | gpu(), unsupported, VK_IMAGE_TYPE_2D, VK_IMAGE_TILING_OPTIMAL, |
| 946 | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, 0, &image_format_properties); |
| 947 | ASSERT_TRUE(err == VK_ERROR_FORMAT_NOT_SUPPORTED); |
| 948 | m_errorMonitor->VerifyFound(); |
| 949 | } |
Dustin Graves | fce74c0 | 2016-05-10 11:42:58 -0600 | [diff] [blame] | 950 | } |
Mark Lobodzinski | e090fef | 2016-06-09 17:04:56 -0600 | [diff] [blame] | 951 | |
| 952 | TEST_F(VkLayerTest, UpdateBufferAlignment) { |
| 953 | TEST_DESCRIPTION("Check alignment parameters for vkCmdUpdateBuffer"); |
| 954 | uint32_t updateData[] = { 1, 2, 3, 4, 5, 6, 7, 8 }; |
| 955 | |
| 956 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 957 | |
| 958 | VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT; |
| 959 | vk_testing::Buffer buffer; |
| 960 | buffer.init_as_dst(*m_device, (VkDeviceSize)20, reqs); |
| 961 | |
| 962 | BeginCommandBuffer(); |
| 963 | // Introduce failure by using dstOffset that is not multiple of 4 |
| 964 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 965 | " is not a multiple of 4"); |
| 966 | m_commandBuffer->UpdateBuffer(buffer.handle(), 1, 4, updateData); |
| 967 | m_errorMonitor->VerifyFound(); |
| 968 | |
| 969 | // Introduce failure by using dataSize that is not multiple of 4 |
| 970 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 971 | " is not a multiple of 4"); |
| 972 | m_commandBuffer->UpdateBuffer(buffer.handle(), 0, 6, updateData); |
| 973 | m_errorMonitor->VerifyFound(); |
| 974 | |
| 975 | // Introduce failure by using dataSize that is < 0 |
| 976 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 977 | "must be greater than zero and less than or equal to 65536"); |
| 978 | m_commandBuffer->UpdateBuffer(buffer.handle(), 0, -44, updateData); |
| 979 | m_errorMonitor->VerifyFound(); |
| 980 | |
| 981 | // Introduce failure by using dataSize that is > 65536 |
| 982 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 983 | "must be greater than zero and less than or equal to 65536"); |
| 984 | m_commandBuffer->UpdateBuffer(buffer.handle(), 0, 80000, updateData); |
| 985 | m_errorMonitor->VerifyFound(); |
| 986 | |
| 987 | EndCommandBuffer(); |
| 988 | } |
| 989 | |
| 990 | TEST_F(VkLayerTest, FillBufferAlignment) { |
| 991 | TEST_DESCRIPTION("Check alignment parameters for vkCmdFillBuffer"); |
| 992 | |
| 993 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 994 | |
| 995 | VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT; |
| 996 | vk_testing::Buffer buffer; |
| 997 | buffer.init_as_dst(*m_device, (VkDeviceSize)20, reqs); |
| 998 | |
| 999 | BeginCommandBuffer(); |
| 1000 | |
| 1001 | // Introduce failure by using dstOffset that is not multiple of 4 |
| 1002 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 1003 | " is not a multiple of 4"); |
| 1004 | m_commandBuffer->FillBuffer(buffer.handle(), 1, 4, 0x11111111); |
| 1005 | m_errorMonitor->VerifyFound(); |
| 1006 | |
| 1007 | // Introduce failure by using size that is not multiple of 4 |
| 1008 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 1009 | " is not a multiple of 4"); |
| 1010 | m_commandBuffer->FillBuffer(buffer.handle(), 0, 6, 0x11111111); |
| 1011 | m_errorMonitor->VerifyFound(); |
| 1012 | |
| 1013 | // Introduce failure by using size that is zero |
| 1014 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 1015 | "must be greater than zero"); |
| 1016 | m_commandBuffer->FillBuffer(buffer.handle(), 0, 0, 0x11111111); |
| 1017 | m_errorMonitor->VerifyFound(); |
| 1018 | |
| 1019 | EndCommandBuffer(); |
| 1020 | } |
Dustin Graves | ffa90fa | 2016-05-06 11:20:38 -0600 | [diff] [blame] | 1021 | #endif // PARAMETER_VALIDATION_TESTS |
| 1022 | |
Tobin Ehlis | 0788f52 | 2015-05-26 16:11:58 -0600 | [diff] [blame] | 1023 | #if MEM_TRACKER_TESTS |
Tobin Ehlis | 8fab656 | 2015-12-01 09:57:09 -0700 | [diff] [blame] | 1024 | #if 0 |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 1025 | TEST_F(VkLayerTest, CallResetCommandBufferBeforeCompletion) |
Mark Lobodzinski | ccb2b04 | 2015-05-19 10:28:29 -0500 | [diff] [blame] | 1026 | { |
| 1027 | vk_testing::Fence testFence; |
Mark Lobodzinski | ccb2b04 | 2015-05-19 10:28:29 -0500 | [diff] [blame] | 1028 | VkFenceCreateInfo fenceInfo = {}; |
| 1029 | fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO; |
| 1030 | fenceInfo.pNext = NULL; |
| 1031 | fenceInfo.flags = 0; |
| 1032 | |
Courtney Goeltzenleuchter | 7415d5a | 2015-12-09 15:48:16 -0700 | [diff] [blame] | 1033 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Resetting CB"); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 1034 | |
Mark Lobodzinski | ccb2b04 | 2015-05-19 10:28:29 -0500 | [diff] [blame] | 1035 | ASSERT_NO_FATAL_FAILURE(InitState()); |
Tony Barbour | c1eb1a5 | 2015-07-20 13:00:10 -0600 | [diff] [blame] | 1036 | |
| 1037 | VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT; |
| 1038 | vk_testing::Buffer buffer; |
| 1039 | buffer.init_as_dst(*m_device, (VkDeviceSize)20, reqs); |
Mark Lobodzinski | ccb2b04 | 2015-05-19 10:28:29 -0500 | [diff] [blame] | 1040 | |
Tony Barbour | fe3351b | 2015-07-28 10:17:20 -0600 | [diff] [blame] | 1041 | BeginCommandBuffer(); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 1042 | m_commandBuffer->FillBuffer(buffer.handle(), 0, 4, 0x11111111); |
Tony Barbour | fe3351b | 2015-07-28 10:17:20 -0600 | [diff] [blame] | 1043 | EndCommandBuffer(); |
Mark Lobodzinski | ccb2b04 | 2015-05-19 10:28:29 -0500 | [diff] [blame] | 1044 | |
| 1045 | testFence.init(*m_device, fenceInfo); |
| 1046 | |
| 1047 | // Bypass framework since it does the waits automatically |
| 1048 | VkResult err = VK_SUCCESS; |
Courtney Goeltzenleuchter | 806c700 | 2015-10-27 11:22:14 -0600 | [diff] [blame] | 1049 | VkSubmitInfo submit_info; |
Chia-I Wu | f9be13c | 2015-10-26 20:37:06 +0800 | [diff] [blame] | 1050 | submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO; |
| 1051 | submit_info.pNext = NULL; |
Chia-I Wu | d50a7d7 | 2015-10-26 20:48:51 +0800 | [diff] [blame] | 1052 | submit_info.waitSemaphoreCount = 0; |
Courtney Goeltzenleuchter | 806c700 | 2015-10-27 11:22:14 -0600 | [diff] [blame] | 1053 | submit_info.pWaitSemaphores = NULL; |
Jon Ashburn | 7f9716c | 2015-12-30 16:42:50 -0700 | [diff] [blame] | 1054 | submit_info.pWaitDstStageMask = NULL; |
Chia-I Wu | d50a7d7 | 2015-10-26 20:48:51 +0800 | [diff] [blame] | 1055 | submit_info.commandBufferCount = 1; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 1056 | submit_info.pCommandBuffers = &m_commandBuffer->handle(); |
Chia-I Wu | d50a7d7 | 2015-10-26 20:48:51 +0800 | [diff] [blame] | 1057 | submit_info.signalSemaphoreCount = 0; |
Courtney Goeltzenleuchter | 806c700 | 2015-10-27 11:22:14 -0600 | [diff] [blame] | 1058 | submit_info.pSignalSemaphores = NULL; |
Courtney Goeltzenleuchter | 646b907 | 2015-10-20 18:04:07 -0600 | [diff] [blame] | 1059 | |
| 1060 | err = vkQueueSubmit( m_device->m_queue, 1, &submit_info, testFence.handle()); |
Mark Lobodzinski | ccb2b04 | 2015-05-19 10:28:29 -0500 | [diff] [blame] | 1061 | ASSERT_VK_SUCCESS( err ); |
| 1062 | |
Mark Lobodzinski | ccb2b04 | 2015-05-19 10:28:29 -0500 | [diff] [blame] | 1063 | // Introduce failure by calling begin again before checking fence |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 1064 | vkResetCommandBuffer(m_commandBuffer->handle(), 0); |
Mark Lobodzinski | ccb2b04 | 2015-05-19 10:28:29 -0500 | [diff] [blame] | 1065 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 1066 | m_errorMonitor->VerifyFound(); |
Mark Lobodzinski | ccb2b04 | 2015-05-19 10:28:29 -0500 | [diff] [blame] | 1067 | } |
| 1068 | |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 1069 | TEST_F(VkLayerTest, CallBeginCommandBufferBeforeCompletion) |
Mark Lobodzinski | ccb2b04 | 2015-05-19 10:28:29 -0500 | [diff] [blame] | 1070 | { |
| 1071 | vk_testing::Fence testFence; |
Mark Lobodzinski | ccb2b04 | 2015-05-19 10:28:29 -0500 | [diff] [blame] | 1072 | VkFenceCreateInfo fenceInfo = {}; |
| 1073 | fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO; |
| 1074 | fenceInfo.pNext = NULL; |
| 1075 | fenceInfo.flags = 0; |
| 1076 | |
Courtney Goeltzenleuchter | 7415d5a | 2015-12-09 15:48:16 -0700 | [diff] [blame] | 1077 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Calling vkBeginCommandBuffer() on active CB"); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 1078 | |
Mark Lobodzinski | ccb2b04 | 2015-05-19 10:28:29 -0500 | [diff] [blame] | 1079 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 1080 | ASSERT_NO_FATAL_FAILURE(InitViewport()); |
| 1081 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 1082 | |
Tony Barbour | fe3351b | 2015-07-28 10:17:20 -0600 | [diff] [blame] | 1083 | BeginCommandBuffer(); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 1084 | m_commandBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color, m_stencil_clear_color, NULL); |
Tony Barbour | fe3351b | 2015-07-28 10:17:20 -0600 | [diff] [blame] | 1085 | EndCommandBuffer(); |
Mark Lobodzinski | ccb2b04 | 2015-05-19 10:28:29 -0500 | [diff] [blame] | 1086 | |
| 1087 | testFence.init(*m_device, fenceInfo); |
| 1088 | |
| 1089 | // Bypass framework since it does the waits automatically |
| 1090 | VkResult err = VK_SUCCESS; |
Courtney Goeltzenleuchter | 806c700 | 2015-10-27 11:22:14 -0600 | [diff] [blame] | 1091 | VkSubmitInfo submit_info; |
Chia-I Wu | f9be13c | 2015-10-26 20:37:06 +0800 | [diff] [blame] | 1092 | submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO; |
| 1093 | submit_info.pNext = NULL; |
Chia-I Wu | d50a7d7 | 2015-10-26 20:48:51 +0800 | [diff] [blame] | 1094 | submit_info.waitSemaphoreCount = 0; |
Courtney Goeltzenleuchter | 806c700 | 2015-10-27 11:22:14 -0600 | [diff] [blame] | 1095 | submit_info.pWaitSemaphores = NULL; |
Jon Ashburn | 7f9716c | 2015-12-30 16:42:50 -0700 | [diff] [blame] | 1096 | submit_info.pWaitDstStageMask = NULL; |
Chia-I Wu | d50a7d7 | 2015-10-26 20:48:51 +0800 | [diff] [blame] | 1097 | submit_info.commandBufferCount = 1; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 1098 | submit_info.pCommandBuffers = &m_commandBuffer->handle(); |
Chia-I Wu | d50a7d7 | 2015-10-26 20:48:51 +0800 | [diff] [blame] | 1099 | submit_info.signalSemaphoreCount = 0; |
Courtney Goeltzenleuchter | 806c700 | 2015-10-27 11:22:14 -0600 | [diff] [blame] | 1100 | submit_info.pSignalSemaphores = NULL; |
Courtney Goeltzenleuchter | 646b907 | 2015-10-20 18:04:07 -0600 | [diff] [blame] | 1101 | |
| 1102 | err = vkQueueSubmit( m_device->m_queue, 1, &submit_info, testFence.handle()); |
Mark Lobodzinski | ccb2b04 | 2015-05-19 10:28:29 -0500 | [diff] [blame] | 1103 | ASSERT_VK_SUCCESS( err ); |
| 1104 | |
Jon Ashburn | f19916e | 2016-01-11 13:12:43 -0700 | [diff] [blame] | 1105 | VkCommandBufferInheritanceInfo hinfo = {}; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 1106 | VkCommandBufferBeginInfo info = {}; |
| 1107 | info.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT; |
| 1108 | info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO; |
Mark Lobodzinski | 5fcc421 | 2015-09-14 17:43:42 -0600 | [diff] [blame] | 1109 | info.renderPass = VK_NULL_HANDLE; |
| 1110 | info.subpass = 0; |
| 1111 | info.framebuffer = VK_NULL_HANDLE; |
Chia-I Wu | b8d47ae | 2015-11-11 10:18:12 +0800 | [diff] [blame] | 1112 | info.occlusionQueryEnable = VK_FALSE; |
| 1113 | info.queryFlags = 0; |
| 1114 | info.pipelineStatistics = 0; |
Mark Lobodzinski | 5fcc421 | 2015-09-14 17:43:42 -0600 | [diff] [blame] | 1115 | |
| 1116 | // Introduce failure by calling BCB again before checking fence |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 1117 | vkBeginCommandBuffer(m_commandBuffer->handle(), &info); |
Mark Lobodzinski | ccb2b04 | 2015-05-19 10:28:29 -0500 | [diff] [blame] | 1118 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 1119 | m_errorMonitor->VerifyFound(); |
Mark Lobodzinski | ccb2b04 | 2015-05-19 10:28:29 -0500 | [diff] [blame] | 1120 | } |
Tobin Ehlis | 8fab656 | 2015-12-01 09:57:09 -0700 | [diff] [blame] | 1121 | #endif |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 1122 | |
Mark Lobodzinski | 152fe25 | 2016-05-03 16:49:15 -0600 | [diff] [blame] | 1123 | // This is a positive test. No failures are expected. |
| 1124 | TEST_F(VkLayerTest, TestAliasedMemoryTracking) { |
| 1125 | VkResult err; |
| 1126 | bool pass; |
| 1127 | |
| 1128 | TEST_DESCRIPTION("Create a buffer, allocate memory, bind memory, destroy " |
| 1129 | "the buffer, create an image, and bind the same memory to " |
| 1130 | "it"); |
| 1131 | |
| 1132 | m_errorMonitor->ExpectSuccess(); |
| 1133 | |
| 1134 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 1135 | |
| 1136 | VkBuffer buffer; |
| 1137 | VkImage image; |
| 1138 | VkDeviceMemory mem; |
| 1139 | VkMemoryRequirements mem_reqs; |
| 1140 | |
| 1141 | VkBufferCreateInfo buf_info = {}; |
| 1142 | buf_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO; |
| 1143 | buf_info.pNext = NULL; |
| 1144 | buf_info.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT; |
| 1145 | buf_info.size = 256; |
| 1146 | buf_info.queueFamilyIndexCount = 0; |
| 1147 | buf_info.pQueueFamilyIndices = NULL; |
| 1148 | buf_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE; |
| 1149 | buf_info.flags = 0; |
| 1150 | err = vkCreateBuffer(m_device->device(), &buf_info, NULL, &buffer); |
| 1151 | ASSERT_VK_SUCCESS(err); |
| 1152 | |
| 1153 | vkGetBufferMemoryRequirements(m_device->device(), buffer, &mem_reqs); |
| 1154 | |
| 1155 | VkMemoryAllocateInfo alloc_info = {}; |
| 1156 | alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO; |
| 1157 | alloc_info.pNext = NULL; |
| 1158 | alloc_info.memoryTypeIndex = 0; |
| 1159 | |
| 1160 | // Ensure memory is big enough for both bindings |
| 1161 | alloc_info.allocationSize = 0x10000; |
| 1162 | |
| 1163 | pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &alloc_info, |
| 1164 | VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT); |
| 1165 | if (!pass) { |
| 1166 | vkDestroyBuffer(m_device->device(), buffer, NULL); |
| 1167 | return; |
| 1168 | } |
| 1169 | |
| 1170 | err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem); |
| 1171 | ASSERT_VK_SUCCESS(err); |
| 1172 | |
| 1173 | uint8_t *pData; |
| 1174 | err = vkMapMemory(m_device->device(), mem, 0, mem_reqs.size, 0, |
| 1175 | (void **)&pData); |
| 1176 | ASSERT_VK_SUCCESS(err); |
| 1177 | |
Mark Lobodzinski | 2abefa9 | 2016-05-05 11:45:57 -0600 | [diff] [blame] | 1178 | memset(pData, 0xCADECADE, static_cast<size_t>(mem_reqs.size)); |
Mark Lobodzinski | 152fe25 | 2016-05-03 16:49:15 -0600 | [diff] [blame] | 1179 | |
| 1180 | vkUnmapMemory(m_device->device(), mem); |
| 1181 | |
| 1182 | err = vkBindBufferMemory(m_device->device(), buffer, mem, 0); |
| 1183 | ASSERT_VK_SUCCESS(err); |
| 1184 | |
| 1185 | // NOW, destroy the buffer. Obviously, the resource no longer occupies this |
| 1186 | // memory. In fact, it was never used by the GPU. |
| 1187 | // Just be be sure, wait for idle. |
| 1188 | vkDestroyBuffer(m_device->device(), buffer, NULL); |
| 1189 | vkDeviceWaitIdle(m_device->device()); |
| 1190 | |
| 1191 | VkImageCreateInfo image_create_info = {}; |
| 1192 | image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO; |
| 1193 | image_create_info.pNext = NULL; |
| 1194 | image_create_info.imageType = VK_IMAGE_TYPE_2D; |
| 1195 | image_create_info.format = VK_FORMAT_R8G8B8A8_UNORM; |
| 1196 | image_create_info.extent.width = 64; |
| 1197 | image_create_info.extent.height = 64; |
| 1198 | image_create_info.extent.depth = 1; |
| 1199 | image_create_info.mipLevels = 1; |
| 1200 | image_create_info.arrayLayers = 1; |
| 1201 | image_create_info.samples = VK_SAMPLE_COUNT_1_BIT; |
| 1202 | image_create_info.tiling = VK_IMAGE_TILING_LINEAR; |
| 1203 | image_create_info.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED; |
| 1204 | image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT; |
| 1205 | image_create_info.queueFamilyIndexCount = 0; |
| 1206 | image_create_info.pQueueFamilyIndices = NULL; |
| 1207 | image_create_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE; |
| 1208 | image_create_info.flags = 0; |
| 1209 | |
| 1210 | VkMemoryAllocateInfo mem_alloc = {}; |
| 1211 | mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO; |
| 1212 | mem_alloc.pNext = NULL; |
| 1213 | mem_alloc.allocationSize = 0; |
| 1214 | mem_alloc.memoryTypeIndex = 0; |
| 1215 | |
| 1216 | /* Create a mappable image. It will be the texture if linear images are ok |
| 1217 | * to be textures or it will be the staging image if they are not. |
| 1218 | */ |
| 1219 | err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image); |
| 1220 | ASSERT_VK_SUCCESS(err); |
| 1221 | |
| 1222 | vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs); |
| 1223 | |
| 1224 | mem_alloc.allocationSize = mem_reqs.size; |
| 1225 | |
| 1226 | pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, |
| 1227 | VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT); |
| 1228 | if (!pass) { |
| 1229 | vkDestroyImage(m_device->device(), image, NULL); |
| 1230 | return; |
| 1231 | } |
| 1232 | |
Tobin Ehlis | 077ded3 | 2016-05-12 17:39:13 -0600 | [diff] [blame] | 1233 | // VALIDATION FAILURE: |
Mark Lobodzinski | 152fe25 | 2016-05-03 16:49:15 -0600 | [diff] [blame] | 1234 | err = vkBindImageMemory(m_device->device(), image, mem, 0); |
| 1235 | ASSERT_VK_SUCCESS(err); |
| 1236 | |
| 1237 | m_errorMonitor->VerifyNotFound(); |
| 1238 | |
Tony Barbour | df4c004 | 2016-06-01 15:55:43 -0600 | [diff] [blame] | 1239 | vkFreeMemory(m_device->device(), mem, NULL); |
Mark Lobodzinski | 152fe25 | 2016-05-03 16:49:15 -0600 | [diff] [blame] | 1240 | vkDestroyBuffer(m_device->device(), buffer, NULL); |
| 1241 | vkDestroyImage(m_device->device(), image, NULL); |
| 1242 | } |
| 1243 | |
Tobin Ehlis | f11be98 | 2016-05-11 13:52:53 -0600 | [diff] [blame] | 1244 | TEST_F(VkLayerTest, InvalidMemoryAliasing) { |
| 1245 | TEST_DESCRIPTION("Create a buffer and image, allocate memory, and bind the " |
| 1246 | "buffer and image to memory such that they will alias."); |
| 1247 | VkResult err; |
| 1248 | bool pass; |
| 1249 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 1250 | |
Tobin Ehlis | 077ded3 | 2016-05-12 17:39:13 -0600 | [diff] [blame] | 1251 | VkBuffer buffer, buffer2; |
Tobin Ehlis | f11be98 | 2016-05-11 13:52:53 -0600 | [diff] [blame] | 1252 | VkImage image; |
| 1253 | VkDeviceMemory mem; // buffer will be bound first |
| 1254 | VkDeviceMemory mem_img; // image bound first |
Tobin Ehlis | 077ded3 | 2016-05-12 17:39:13 -0600 | [diff] [blame] | 1255 | VkMemoryRequirements buff_mem_reqs, img_mem_reqs; |
Tobin Ehlis | f11be98 | 2016-05-11 13:52:53 -0600 | [diff] [blame] | 1256 | |
| 1257 | VkBufferCreateInfo buf_info = {}; |
| 1258 | buf_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO; |
| 1259 | buf_info.pNext = NULL; |
| 1260 | buf_info.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT; |
| 1261 | buf_info.size = 256; |
| 1262 | buf_info.queueFamilyIndexCount = 0; |
| 1263 | buf_info.pQueueFamilyIndices = NULL; |
| 1264 | buf_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE; |
| 1265 | buf_info.flags = 0; |
| 1266 | err = vkCreateBuffer(m_device->device(), &buf_info, NULL, &buffer); |
| 1267 | ASSERT_VK_SUCCESS(err); |
| 1268 | |
Tobin Ehlis | 077ded3 | 2016-05-12 17:39:13 -0600 | [diff] [blame] | 1269 | vkGetBufferMemoryRequirements(m_device->device(), buffer, &buff_mem_reqs); |
Tobin Ehlis | f11be98 | 2016-05-11 13:52:53 -0600 | [diff] [blame] | 1270 | |
| 1271 | VkImageCreateInfo image_create_info = {}; |
| 1272 | image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO; |
| 1273 | image_create_info.pNext = NULL; |
| 1274 | image_create_info.imageType = VK_IMAGE_TYPE_2D; |
| 1275 | image_create_info.format = VK_FORMAT_R8G8B8A8_UNORM; |
| 1276 | image_create_info.extent.width = 64; |
| 1277 | image_create_info.extent.height = 64; |
| 1278 | image_create_info.extent.depth = 1; |
| 1279 | image_create_info.mipLevels = 1; |
| 1280 | image_create_info.arrayLayers = 1; |
| 1281 | image_create_info.samples = VK_SAMPLE_COUNT_1_BIT; |
| 1282 | image_create_info.tiling = VK_IMAGE_TILING_LINEAR; |
| 1283 | image_create_info.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED; |
| 1284 | image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT; |
| 1285 | image_create_info.queueFamilyIndexCount = 0; |
| 1286 | image_create_info.pQueueFamilyIndices = NULL; |
| 1287 | image_create_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE; |
| 1288 | image_create_info.flags = 0; |
| 1289 | |
Tobin Ehlis | f11be98 | 2016-05-11 13:52:53 -0600 | [diff] [blame] | 1290 | err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image); |
| 1291 | ASSERT_VK_SUCCESS(err); |
| 1292 | |
Tobin Ehlis | 077ded3 | 2016-05-12 17:39:13 -0600 | [diff] [blame] | 1293 | vkGetImageMemoryRequirements(m_device->device(), image, &img_mem_reqs); |
| 1294 | |
| 1295 | VkMemoryAllocateInfo alloc_info = {}; |
| 1296 | alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO; |
| 1297 | alloc_info.pNext = NULL; |
| 1298 | alloc_info.memoryTypeIndex = 0; |
| 1299 | // Ensure memory is big enough for both bindings |
| 1300 | alloc_info.allocationSize = buff_mem_reqs.size + img_mem_reqs.size; |
| 1301 | pass = m_device->phy().set_memory_type( |
| 1302 | buff_mem_reqs.memoryTypeBits | img_mem_reqs.memoryTypeBits, &alloc_info, |
| 1303 | VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT); |
Tobin Ehlis | f11be98 | 2016-05-11 13:52:53 -0600 | [diff] [blame] | 1304 | if (!pass) { |
Tobin Ehlis | 077ded3 | 2016-05-12 17:39:13 -0600 | [diff] [blame] | 1305 | vkDestroyBuffer(m_device->device(), buffer, NULL); |
Tobin Ehlis | f11be98 | 2016-05-11 13:52:53 -0600 | [diff] [blame] | 1306 | vkDestroyImage(m_device->device(), image, NULL); |
| 1307 | return; |
| 1308 | } |
Tobin Ehlis | 077ded3 | 2016-05-12 17:39:13 -0600 | [diff] [blame] | 1309 | err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem); |
| 1310 | ASSERT_VK_SUCCESS(err); |
| 1311 | err = vkBindBufferMemory(m_device->device(), buffer, mem, 0); |
| 1312 | ASSERT_VK_SUCCESS(err); |
| 1313 | |
Tobin Ehlis | f11be98 | 2016-05-11 13:52:53 -0600 | [diff] [blame] | 1314 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 1315 | " is aliased with buffer 0x"); |
Tobin Ehlis | 077ded3 | 2016-05-12 17:39:13 -0600 | [diff] [blame] | 1316 | // VALIDATION FAILURE due to image mapping overlapping buffer mapping |
Tobin Ehlis | f11be98 | 2016-05-11 13:52:53 -0600 | [diff] [blame] | 1317 | err = vkBindImageMemory(m_device->device(), image, mem, 0); |
| 1318 | m_errorMonitor->VerifyFound(); |
| 1319 | |
| 1320 | // Now correctly bind image to second mem allocation before incorrectly |
Tobin Ehlis | 077ded3 | 2016-05-12 17:39:13 -0600 | [diff] [blame] | 1321 | // aliasing buffer2 |
| 1322 | err = vkCreateBuffer(m_device->device(), &buf_info, NULL, &buffer2); |
| 1323 | ASSERT_VK_SUCCESS(err); |
Tobin Ehlis | f11be98 | 2016-05-11 13:52:53 -0600 | [diff] [blame] | 1324 | err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem_img); |
| 1325 | ASSERT_VK_SUCCESS(err); |
| 1326 | err = vkBindImageMemory(m_device->device(), image, mem_img, 0); |
| 1327 | ASSERT_VK_SUCCESS(err); |
| 1328 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 1329 | " is aliased with image 0x"); |
Tobin Ehlis | 077ded3 | 2016-05-12 17:39:13 -0600 | [diff] [blame] | 1330 | err = vkBindBufferMemory(m_device->device(), buffer2, mem_img, 0); |
Tobin Ehlis | f11be98 | 2016-05-11 13:52:53 -0600 | [diff] [blame] | 1331 | m_errorMonitor->VerifyFound(); |
| 1332 | |
| 1333 | vkDestroyBuffer(m_device->device(), buffer, NULL); |
Tobin Ehlis | 077ded3 | 2016-05-12 17:39:13 -0600 | [diff] [blame] | 1334 | vkDestroyBuffer(m_device->device(), buffer2, NULL); |
Tobin Ehlis | f11be98 | 2016-05-11 13:52:53 -0600 | [diff] [blame] | 1335 | vkDestroyImage(m_device->device(), image, NULL); |
| 1336 | vkFreeMemory(m_device->device(), mem, NULL); |
| 1337 | vkFreeMemory(m_device->device(), mem_img, NULL); |
| 1338 | } |
| 1339 | |
Tobin Ehlis | 3537252 | 2016-05-12 08:32:31 -0600 | [diff] [blame] | 1340 | TEST_F(VkLayerTest, InvalidMemoryMapping) { |
| 1341 | TEST_DESCRIPTION("Attempt to map memory in a number of incorrect ways"); |
| 1342 | VkResult err; |
| 1343 | bool pass; |
| 1344 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 1345 | |
| 1346 | VkBuffer buffer; |
| 1347 | VkDeviceMemory mem; |
| 1348 | VkMemoryRequirements mem_reqs; |
| 1349 | |
| 1350 | VkBufferCreateInfo buf_info = {}; |
| 1351 | buf_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO; |
| 1352 | buf_info.pNext = NULL; |
| 1353 | buf_info.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT; |
| 1354 | buf_info.size = 256; |
| 1355 | buf_info.queueFamilyIndexCount = 0; |
| 1356 | buf_info.pQueueFamilyIndices = NULL; |
| 1357 | buf_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE; |
| 1358 | buf_info.flags = 0; |
| 1359 | err = vkCreateBuffer(m_device->device(), &buf_info, NULL, &buffer); |
| 1360 | ASSERT_VK_SUCCESS(err); |
| 1361 | |
| 1362 | vkGetBufferMemoryRequirements(m_device->device(), buffer, &mem_reqs); |
| 1363 | VkMemoryAllocateInfo alloc_info = {}; |
| 1364 | alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO; |
| 1365 | alloc_info.pNext = NULL; |
| 1366 | alloc_info.memoryTypeIndex = 0; |
| 1367 | |
| 1368 | // Ensure memory is big enough for both bindings |
| 1369 | static const VkDeviceSize allocation_size = 0x10000; |
| 1370 | alloc_info.allocationSize = allocation_size; |
| 1371 | pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &alloc_info, |
| 1372 | VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT); |
| 1373 | if (!pass) { |
| 1374 | vkDestroyBuffer(m_device->device(), buffer, NULL); |
| 1375 | return; |
| 1376 | } |
| 1377 | err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem); |
| 1378 | ASSERT_VK_SUCCESS(err); |
| 1379 | |
| 1380 | uint8_t *pData; |
| 1381 | // Attempt to map memory size 0 is invalid |
| 1382 | m_errorMonitor->SetDesiredFailureMsg( |
| 1383 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 1384 | "VkMapMemory: Attempting to map memory range of size zero"); |
| 1385 | err = vkMapMemory(m_device->device(), mem, 0, 0, 0, (void **)&pData); |
| 1386 | m_errorMonitor->VerifyFound(); |
| 1387 | // Map memory twice |
| 1388 | err = vkMapMemory(m_device->device(), mem, 0, mem_reqs.size, 0, |
| 1389 | (void **)&pData); |
| 1390 | ASSERT_VK_SUCCESS(err); |
| 1391 | m_errorMonitor->SetDesiredFailureMsg( |
| 1392 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 1393 | "VkMapMemory: Attempting to map memory on an already-mapped object "); |
| 1394 | err = vkMapMemory(m_device->device(), mem, 0, mem_reqs.size, 0, |
| 1395 | (void **)&pData); |
| 1396 | m_errorMonitor->VerifyFound(); |
| 1397 | |
| 1398 | // Unmap the memory to avoid re-map error |
| 1399 | vkUnmapMemory(m_device->device(), mem); |
| 1400 | // overstep allocation with VK_WHOLE_SIZE |
| 1401 | m_errorMonitor->SetDesiredFailureMsg( |
| 1402 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 1403 | " with size of VK_WHOLE_SIZE oversteps total array size 0x"); |
| 1404 | err = vkMapMemory(m_device->device(), mem, allocation_size + 1, |
| 1405 | VK_WHOLE_SIZE, 0, (void **)&pData); |
| 1406 | m_errorMonitor->VerifyFound(); |
| 1407 | // overstep allocation w/o VK_WHOLE_SIZE |
| 1408 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 1409 | " oversteps total array size 0x"); |
| 1410 | err = vkMapMemory(m_device->device(), mem, 1, allocation_size, 0, |
| 1411 | (void **)&pData); |
| 1412 | m_errorMonitor->VerifyFound(); |
| 1413 | // Now error due to unmapping memory that's not mapped |
| 1414 | m_errorMonitor->SetDesiredFailureMsg( |
| 1415 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 1416 | "Unmapping Memory without memory being mapped: "); |
| 1417 | vkUnmapMemory(m_device->device(), mem); |
| 1418 | m_errorMonitor->VerifyFound(); |
| 1419 | // Now map memory and cause errors due to flushing invalid ranges |
| 1420 | err = vkMapMemory(m_device->device(), mem, 16, VK_WHOLE_SIZE, 0, |
| 1421 | (void **)&pData); |
| 1422 | ASSERT_VK_SUCCESS(err); |
| 1423 | VkMappedMemoryRange mmr = {}; |
Chris Forbes | 3aec089 | 2016-06-13 10:29:26 +1200 | [diff] [blame] | 1424 | mmr.sType = VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE; |
Tobin Ehlis | 3537252 | 2016-05-12 08:32:31 -0600 | [diff] [blame] | 1425 | mmr.memory = mem; |
| 1426 | mmr.offset = 15; // Error b/c offset less than offset of mapped mem |
| 1427 | m_errorMonitor->SetDesiredFailureMsg( |
| 1428 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 1429 | ") is less than Memory Object's offset ("); |
| 1430 | vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr); |
| 1431 | m_errorMonitor->VerifyFound(); |
| 1432 | // Now flush range that oversteps mapped range |
| 1433 | vkUnmapMemory(m_device->device(), mem); |
| 1434 | err = vkMapMemory(m_device->device(), mem, 0, 256, 0, (void **)&pData); |
| 1435 | ASSERT_VK_SUCCESS(err); |
| 1436 | mmr.offset = 16; |
| 1437 | mmr.size = 256; // flushing bounds (272) exceed mapped bounds (256) |
| 1438 | m_errorMonitor->SetDesiredFailureMsg( |
| 1439 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 1440 | ") exceeds the Memory Object's upper-bound ("); |
| 1441 | vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr); |
| 1442 | m_errorMonitor->VerifyFound(); |
| 1443 | |
| 1444 | pass = |
| 1445 | m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &alloc_info, |
| 1446 | VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT, |
| 1447 | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT); |
| 1448 | if (!pass) { |
| 1449 | vkFreeMemory(m_device->device(), mem, NULL); |
| 1450 | vkDestroyBuffer(m_device->device(), buffer, NULL); |
| 1451 | return; |
| 1452 | } |
| 1453 | // TODO : If we can get HOST_VISIBLE w/o HOST_COHERENT we can test cases of |
| 1454 | // MEMTRACK_INVALID_MAP in validateAndCopyNoncoherentMemoryToDriver() |
| 1455 | |
| 1456 | vkDestroyBuffer(m_device->device(), buffer, NULL); |
| 1457 | vkFreeMemory(m_device->device(), mem, NULL); |
| 1458 | } |
| 1459 | |
Ian Elliott | 1c32c77 | 2016-04-28 14:47:13 -0600 | [diff] [blame] | 1460 | TEST_F(VkLayerTest, EnableWsiBeforeUse) { |
| 1461 | VkResult err; |
| 1462 | bool pass; |
| 1463 | |
Ian Elliott | 489eec0 | 2016-05-05 14:12:44 -0600 | [diff] [blame] | 1464 | // FIXME: After we turn on this code for non-Linux platforms, uncomment the |
| 1465 | // following declaration (which is temporarily being moved below): |
| 1466 | // VkSurfaceKHR surface = VK_NULL_HANDLE; |
Ian Elliott | 1c32c77 | 2016-04-28 14:47:13 -0600 | [diff] [blame] | 1467 | VkSwapchainKHR swapchain = VK_NULL_HANDLE; |
| 1468 | VkSwapchainCreateInfoKHR swapchain_create_info = {}; |
| 1469 | uint32_t swapchain_image_count = 0; |
| 1470 | // VkImage swapchain_images[1] = {VK_NULL_HANDLE}; |
| 1471 | uint32_t image_index = 0; |
| 1472 | // VkPresentInfoKHR present_info = {}; |
| 1473 | |
| 1474 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 1475 | |
Ian Elliott | 3f06ce5 | 2016-04-29 14:46:21 -0600 | [diff] [blame] | 1476 | #ifdef NEED_TO_TEST_THIS_ON_PLATFORM |
| 1477 | #if defined(VK_USE_PLATFORM_ANDROID_KHR) |
| 1478 | // Use the functions from the VK_KHR_android_surface extension without |
| 1479 | // enabling that extension: |
| 1480 | |
| 1481 | // Create a surface: |
| 1482 | VkAndroidSurfaceCreateInfoKHR android_create_info = {}; |
Ian Elliott | 3f06ce5 | 2016-04-29 14:46:21 -0600 | [diff] [blame] | 1483 | m_errorMonitor->SetDesiredFailureMsg( |
| 1484 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 1485 | "extension was not enabled for this"); |
| 1486 | err = vkCreateAndroidSurfaceKHR(instance(), &android_create_info, NULL, |
| 1487 | &surface); |
| 1488 | pass = (err != VK_SUCCESS); |
| 1489 | ASSERT_TRUE(pass); |
| 1490 | m_errorMonitor->VerifyFound(); |
| 1491 | #endif // VK_USE_PLATFORM_ANDROID_KHR |
| 1492 | |
| 1493 | |
| 1494 | #if defined(VK_USE_PLATFORM_MIR_KHR) |
| 1495 | // Use the functions from the VK_KHR_mir_surface extension without enabling |
| 1496 | // that extension: |
| 1497 | |
| 1498 | // Create a surface: |
| 1499 | VkMirSurfaceCreateInfoKHR mir_create_info = {}; |
Ian Elliott | 3f06ce5 | 2016-04-29 14:46:21 -0600 | [diff] [blame] | 1500 | m_errorMonitor->SetDesiredFailureMsg( |
| 1501 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 1502 | "extension was not enabled for this"); |
| 1503 | err = vkCreateMirSurfaceKHR(instance(), &mir_create_info, NULL, &surface); |
| 1504 | pass = (err != VK_SUCCESS); |
| 1505 | ASSERT_TRUE(pass); |
| 1506 | m_errorMonitor->VerifyFound(); |
| 1507 | |
| 1508 | // Tell whether an mir_connection supports presentation: |
| 1509 | MirConnection *mir_connection = NULL; |
| 1510 | m_errorMonitor->SetDesiredFailureMsg( |
| 1511 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 1512 | "extension was not enabled for this"); |
| 1513 | vkGetPhysicalDeviceMirPresentationSupportKHR(gpu(), 0, mir_connection, |
| 1514 | visual_id); |
| 1515 | m_errorMonitor->VerifyFound(); |
| 1516 | #endif // VK_USE_PLATFORM_MIR_KHR |
| 1517 | |
| 1518 | |
| 1519 | #if defined(VK_USE_PLATFORM_WAYLAND_KHR) |
| 1520 | // Use the functions from the VK_KHR_wayland_surface extension without |
| 1521 | // enabling that extension: |
| 1522 | |
| 1523 | // Create a surface: |
| 1524 | VkWaylandSurfaceCreateInfoKHR wayland_create_info = {}; |
Ian Elliott | 3f06ce5 | 2016-04-29 14:46:21 -0600 | [diff] [blame] | 1525 | m_errorMonitor->SetDesiredFailureMsg( |
| 1526 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 1527 | "extension was not enabled for this"); |
| 1528 | err = vkCreateWaylandSurfaceKHR(instance(), &wayland_create_info, NULL, |
| 1529 | &surface); |
| 1530 | pass = (err != VK_SUCCESS); |
| 1531 | ASSERT_TRUE(pass); |
| 1532 | m_errorMonitor->VerifyFound(); |
| 1533 | |
| 1534 | // Tell whether an wayland_display supports presentation: |
| 1535 | struct wl_display wayland_display = {}; |
| 1536 | m_errorMonitor->SetDesiredFailureMsg( |
| 1537 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 1538 | "extension was not enabled for this"); |
| 1539 | vkGetPhysicalDeviceWaylandPresentationSupportKHR(gpu(), 0, |
| 1540 | &wayland_display); |
| 1541 | m_errorMonitor->VerifyFound(); |
| 1542 | #endif // VK_USE_PLATFORM_WAYLAND_KHR |
Ian Elliott | 489eec0 | 2016-05-05 14:12:44 -0600 | [diff] [blame] | 1543 | #endif // NEED_TO_TEST_THIS_ON_PLATFORM |
Ian Elliott | 3f06ce5 | 2016-04-29 14:46:21 -0600 | [diff] [blame] | 1544 | |
| 1545 | |
| 1546 | #if defined(VK_USE_PLATFORM_WIN32_KHR) |
Ian Elliott | 489eec0 | 2016-05-05 14:12:44 -0600 | [diff] [blame] | 1547 | // FIXME: REMOVE THIS HERE, AND UNCOMMENT ABOVE, WHEN THIS TEST HAS BEEN PORTED |
| 1548 | // TO NON-LINUX PLATFORMS: |
| 1549 | VkSurfaceKHR surface = VK_NULL_HANDLE; |
Ian Elliott | 3f06ce5 | 2016-04-29 14:46:21 -0600 | [diff] [blame] | 1550 | // Use the functions from the VK_KHR_win32_surface extension without |
| 1551 | // enabling that extension: |
| 1552 | |
| 1553 | // Create a surface: |
| 1554 | VkWin32SurfaceCreateInfoKHR win32_create_info = {}; |
Ian Elliott | 3f06ce5 | 2016-04-29 14:46:21 -0600 | [diff] [blame] | 1555 | m_errorMonitor->SetDesiredFailureMsg( |
| 1556 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 1557 | "extension was not enabled for this"); |
| 1558 | err = vkCreateWin32SurfaceKHR(instance(), &win32_create_info, NULL, |
| 1559 | &surface); |
| 1560 | pass = (err != VK_SUCCESS); |
| 1561 | ASSERT_TRUE(pass); |
| 1562 | m_errorMonitor->VerifyFound(); |
| 1563 | |
| 1564 | // Tell whether win32 supports presentation: |
Ian Elliott | 3f06ce5 | 2016-04-29 14:46:21 -0600 | [diff] [blame] | 1565 | m_errorMonitor->SetDesiredFailureMsg( |
| 1566 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 1567 | "extension was not enabled for this"); |
Ian Elliott | 489eec0 | 2016-05-05 14:12:44 -0600 | [diff] [blame] | 1568 | vkGetPhysicalDeviceWin32PresentationSupportKHR(gpu(), 0); |
Ian Elliott | 3f06ce5 | 2016-04-29 14:46:21 -0600 | [diff] [blame] | 1569 | m_errorMonitor->VerifyFound(); |
Ian Elliott | 489eec0 | 2016-05-05 14:12:44 -0600 | [diff] [blame] | 1570 | // Set this (for now, until all platforms are supported and tested): |
| 1571 | #define NEED_TO_TEST_THIS_ON_PLATFORM |
| 1572 | #endif // VK_USE_PLATFORM_WIN32_KHR |
Ian Elliott | 3f06ce5 | 2016-04-29 14:46:21 -0600 | [diff] [blame] | 1573 | |
| 1574 | |
Ian Elliott | 1c32c77 | 2016-04-28 14:47:13 -0600 | [diff] [blame] | 1575 | #if defined(VK_USE_PLATFORM_XCB_KHR) |
Ian Elliott | 489eec0 | 2016-05-05 14:12:44 -0600 | [diff] [blame] | 1576 | // FIXME: REMOVE THIS HERE, AND UNCOMMENT ABOVE, WHEN THIS TEST HAS BEEN PORTED |
| 1577 | // TO NON-LINUX PLATFORMS: |
| 1578 | VkSurfaceKHR surface = VK_NULL_HANDLE; |
Ian Elliott | 1c32c77 | 2016-04-28 14:47:13 -0600 | [diff] [blame] | 1579 | // Use the functions from the VK_KHR_xcb_surface extension without enabling |
| 1580 | // that extension: |
| 1581 | |
| 1582 | // Create a surface: |
| 1583 | VkXcbSurfaceCreateInfoKHR xcb_create_info = {}; |
Ian Elliott | 1c32c77 | 2016-04-28 14:47:13 -0600 | [diff] [blame] | 1584 | m_errorMonitor->SetDesiredFailureMsg( |
| 1585 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 1586 | "extension was not enabled for this"); |
| 1587 | err = vkCreateXcbSurfaceKHR(instance(), &xcb_create_info, NULL, &surface); |
| 1588 | pass = (err != VK_SUCCESS); |
| 1589 | ASSERT_TRUE(pass); |
| 1590 | m_errorMonitor->VerifyFound(); |
| 1591 | |
| 1592 | // Tell whether an xcb_visualid_t supports presentation: |
Ian Elliott | 3f06ce5 | 2016-04-29 14:46:21 -0600 | [diff] [blame] | 1593 | xcb_connection_t *xcb_connection = NULL; |
Ian Elliott | 1c32c77 | 2016-04-28 14:47:13 -0600 | [diff] [blame] | 1594 | xcb_visualid_t visual_id = 0; |
| 1595 | m_errorMonitor->SetDesiredFailureMsg( |
| 1596 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 1597 | "extension was not enabled for this"); |
Ian Elliott | 3f06ce5 | 2016-04-29 14:46:21 -0600 | [diff] [blame] | 1598 | vkGetPhysicalDeviceXcbPresentationSupportKHR(gpu(), 0, xcb_connection, |
Ian Elliott | 1c32c77 | 2016-04-28 14:47:13 -0600 | [diff] [blame] | 1599 | visual_id); |
| 1600 | m_errorMonitor->VerifyFound(); |
Ian Elliott | 489eec0 | 2016-05-05 14:12:44 -0600 | [diff] [blame] | 1601 | // Set this (for now, until all platforms are supported and tested): |
| 1602 | #define NEED_TO_TEST_THIS_ON_PLATFORM |
Ian Elliott | 1c32c77 | 2016-04-28 14:47:13 -0600 | [diff] [blame] | 1603 | #endif // VK_USE_PLATFORM_XCB_KHR |
| 1604 | |
| 1605 | |
Ian Elliott | 1263081 | 2016-04-29 14:35:43 -0600 | [diff] [blame] | 1606 | #if defined(VK_USE_PLATFORM_XLIB_KHR) |
| 1607 | // Use the functions from the VK_KHR_xlib_surface extension without enabling |
| 1608 | // that extension: |
| 1609 | |
| 1610 | // Create a surface: |
| 1611 | VkXlibSurfaceCreateInfoKHR xlib_create_info = {}; |
Ian Elliott | 1263081 | 2016-04-29 14:35:43 -0600 | [diff] [blame] | 1612 | m_errorMonitor->SetDesiredFailureMsg( |
| 1613 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 1614 | "extension was not enabled for this"); |
| 1615 | err = vkCreateXlibSurfaceKHR(instance(), &xlib_create_info, NULL, &surface); |
| 1616 | pass = (err != VK_SUCCESS); |
| 1617 | ASSERT_TRUE(pass); |
| 1618 | m_errorMonitor->VerifyFound(); |
| 1619 | |
| 1620 | // Tell whether an Xlib VisualID supports presentation: |
| 1621 | Display *dpy = NULL; |
| 1622 | VisualID visual = 0; |
| 1623 | m_errorMonitor->SetDesiredFailureMsg( |
| 1624 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 1625 | "extension was not enabled for this"); |
| 1626 | vkGetPhysicalDeviceXlibPresentationSupportKHR(gpu(), 0, dpy, visual); |
| 1627 | m_errorMonitor->VerifyFound(); |
Ian Elliott | 489eec0 | 2016-05-05 14:12:44 -0600 | [diff] [blame] | 1628 | // Set this (for now, until all platforms are supported and tested): |
| 1629 | #define NEED_TO_TEST_THIS_ON_PLATFORM |
Ian Elliott | 1263081 | 2016-04-29 14:35:43 -0600 | [diff] [blame] | 1630 | #endif // VK_USE_PLATFORM_XLIB_KHR |
| 1631 | |
| 1632 | |
Ian Elliott | 1c32c77 | 2016-04-28 14:47:13 -0600 | [diff] [blame] | 1633 | // Use the functions from the VK_KHR_surface extension without enabling |
| 1634 | // that extension: |
| 1635 | |
Ian Elliott | 489eec0 | 2016-05-05 14:12:44 -0600 | [diff] [blame] | 1636 | #ifdef NEED_TO_TEST_THIS_ON_PLATFORM |
Ian Elliott | 1c32c77 | 2016-04-28 14:47:13 -0600 | [diff] [blame] | 1637 | // Destroy a surface: |
| 1638 | m_errorMonitor->SetDesiredFailureMsg( |
| 1639 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 1640 | "extension was not enabled for this"); |
| 1641 | vkDestroySurfaceKHR(instance(), surface, NULL); |
| 1642 | m_errorMonitor->VerifyFound(); |
| 1643 | |
| 1644 | // Check if surface supports presentation: |
| 1645 | VkBool32 supported = false; |
| 1646 | m_errorMonitor->SetDesiredFailureMsg( |
| 1647 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 1648 | "extension was not enabled for this"); |
| 1649 | err = vkGetPhysicalDeviceSurfaceSupportKHR(gpu(), 0, surface, &supported); |
| 1650 | pass = (err != VK_SUCCESS); |
| 1651 | ASSERT_TRUE(pass); |
| 1652 | m_errorMonitor->VerifyFound(); |
| 1653 | |
| 1654 | // Check surface capabilities: |
| 1655 | VkSurfaceCapabilitiesKHR capabilities = {}; |
| 1656 | m_errorMonitor->SetDesiredFailureMsg( |
| 1657 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 1658 | "extension was not enabled for this"); |
| 1659 | err = vkGetPhysicalDeviceSurfaceCapabilitiesKHR(gpu(), surface, |
| 1660 | &capabilities); |
| 1661 | pass = (err != VK_SUCCESS); |
| 1662 | ASSERT_TRUE(pass); |
| 1663 | m_errorMonitor->VerifyFound(); |
| 1664 | |
| 1665 | // Check surface formats: |
| 1666 | uint32_t format_count = 0; |
| 1667 | VkSurfaceFormatKHR *formats = NULL; |
| 1668 | m_errorMonitor->SetDesiredFailureMsg( |
| 1669 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 1670 | "extension was not enabled for this"); |
| 1671 | err = vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, |
| 1672 | &format_count, formats); |
| 1673 | pass = (err != VK_SUCCESS); |
| 1674 | ASSERT_TRUE(pass); |
| 1675 | m_errorMonitor->VerifyFound(); |
| 1676 | |
| 1677 | // Check surface present modes: |
| 1678 | uint32_t present_mode_count = 0; |
| 1679 | VkSurfaceFormatKHR *present_modes = NULL; |
| 1680 | m_errorMonitor->SetDesiredFailureMsg( |
| 1681 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 1682 | "extension was not enabled for this"); |
| 1683 | err = vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, |
| 1684 | &present_mode_count, present_modes); |
| 1685 | pass = (err != VK_SUCCESS); |
| 1686 | ASSERT_TRUE(pass); |
| 1687 | m_errorMonitor->VerifyFound(); |
Ian Elliott | 489eec0 | 2016-05-05 14:12:44 -0600 | [diff] [blame] | 1688 | #endif // NEED_TO_TEST_THIS_ON_PLATFORM |
Ian Elliott | 1c32c77 | 2016-04-28 14:47:13 -0600 | [diff] [blame] | 1689 | |
| 1690 | |
| 1691 | // Use the functions from the VK_KHR_swapchain extension without enabling |
| 1692 | // that extension: |
| 1693 | |
| 1694 | // Create a swapchain: |
| 1695 | m_errorMonitor->SetDesiredFailureMsg( |
| 1696 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 1697 | "extension was not enabled for this"); |
| 1698 | swapchain_create_info.sType = VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR; |
| 1699 | swapchain_create_info.pNext = NULL; |
Ian Elliott | 1c32c77 | 2016-04-28 14:47:13 -0600 | [diff] [blame] | 1700 | err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, |
| 1701 | NULL, &swapchain); |
| 1702 | pass = (err != VK_SUCCESS); |
| 1703 | ASSERT_TRUE(pass); |
| 1704 | m_errorMonitor->VerifyFound(); |
| 1705 | |
| 1706 | // Get the images from the swapchain: |
| 1707 | m_errorMonitor->SetDesiredFailureMsg( |
| 1708 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 1709 | "extension was not enabled for this"); |
| 1710 | err = vkGetSwapchainImagesKHR(m_device->device(), swapchain, |
| 1711 | &swapchain_image_count, NULL); |
| 1712 | pass = (err != VK_SUCCESS); |
| 1713 | ASSERT_TRUE(pass); |
| 1714 | m_errorMonitor->VerifyFound(); |
| 1715 | |
| 1716 | // Try to acquire an image: |
| 1717 | m_errorMonitor->SetDesiredFailureMsg( |
| 1718 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 1719 | "extension was not enabled for this"); |
| 1720 | err = vkAcquireNextImageKHR(m_device->device(), swapchain, 0, |
| 1721 | VK_NULL_HANDLE, VK_NULL_HANDLE, &image_index); |
| 1722 | pass = (err != VK_SUCCESS); |
| 1723 | ASSERT_TRUE(pass); |
| 1724 | m_errorMonitor->VerifyFound(); |
| 1725 | |
| 1726 | // Try to present an image: |
Ian Elliott | 2c1daf5 | 2016-05-12 09:41:46 -0600 | [diff] [blame] | 1727 | // |
| 1728 | // NOTE: Currently can't test this because a real swapchain is needed (as |
| 1729 | // opposed to the fake one we created) in order for the layer to lookup the |
| 1730 | // VkDevice used to enable the extension: |
Ian Elliott | 1c32c77 | 2016-04-28 14:47:13 -0600 | [diff] [blame] | 1731 | |
| 1732 | // Destroy the swapchain: |
| 1733 | m_errorMonitor->SetDesiredFailureMsg( |
| 1734 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 1735 | "extension was not enabled for this"); |
| 1736 | vkDestroySwapchainKHR(m_device->device(), swapchain, NULL); |
| 1737 | m_errorMonitor->VerifyFound(); |
| 1738 | } |
| 1739 | |
Ian Elliott | 2c1daf5 | 2016-05-12 09:41:46 -0600 | [diff] [blame] | 1740 | TEST_F(VkWsiEnabledLayerTest, TestEnabledWsi) { |
Ian Elliott | 2c1daf5 | 2016-05-12 09:41:46 -0600 | [diff] [blame] | 1741 | |
Dustin Graves | 6c6d898 | 2016-05-17 10:09:21 -0600 | [diff] [blame] | 1742 | #if defined(VK_USE_PLATFORM_XCB_KHR) |
Ian Elliott | 2c1daf5 | 2016-05-12 09:41:46 -0600 | [diff] [blame] | 1743 | VkSurfaceKHR surface = VK_NULL_HANDLE; |
Mark Lobodzinski | 085d27a | 2016-05-17 09:34:26 -0600 | [diff] [blame] | 1744 | |
Mark Lobodzinski | 085d27a | 2016-05-17 09:34:26 -0600 | [diff] [blame] | 1745 | VkResult err; |
| 1746 | bool pass; |
Ian Elliott | 2c1daf5 | 2016-05-12 09:41:46 -0600 | [diff] [blame] | 1747 | VkSwapchainKHR swapchain = VK_NULL_HANDLE; |
| 1748 | VkSwapchainCreateInfoKHR swapchain_create_info = {}; |
Mark Lobodzinski | 085d27a | 2016-05-17 09:34:26 -0600 | [diff] [blame] | 1749 | // uint32_t swapchain_image_count = 0; |
| 1750 | // VkImage swapchain_images[1] = {VK_NULL_HANDLE}; |
| 1751 | // uint32_t image_index = 0; |
| 1752 | // VkPresentInfoKHR present_info = {}; |
Ian Elliott | 2c1daf5 | 2016-05-12 09:41:46 -0600 | [diff] [blame] | 1753 | |
| 1754 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 1755 | |
| 1756 | // Use the create function from one of the VK_KHR_*_surface extension in |
| 1757 | // order to create a surface, testing all known errors in the process, |
| 1758 | // before successfully creating a surface: |
| 1759 | // First, try to create a surface without a VkXcbSurfaceCreateInfoKHR: |
Mark Lobodzinski | 085d27a | 2016-05-17 09:34:26 -0600 | [diff] [blame] | 1760 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 1761 | "called with NULL pointer"); |
Ian Elliott | 2c1daf5 | 2016-05-12 09:41:46 -0600 | [diff] [blame] | 1762 | err = vkCreateXcbSurfaceKHR(instance(), NULL, NULL, &surface); |
| 1763 | pass = (err != VK_SUCCESS); |
| 1764 | ASSERT_TRUE(pass); |
| 1765 | m_errorMonitor->VerifyFound(); |
| 1766 | |
| 1767 | // Next, try to create a surface with the wrong |
| 1768 | // VkXcbSurfaceCreateInfoKHR::sType: |
| 1769 | VkXcbSurfaceCreateInfoKHR xcb_create_info = {}; |
| 1770 | xcb_create_info.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO; |
Mark Lobodzinski | 085d27a | 2016-05-17 09:34:26 -0600 | [diff] [blame] | 1771 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 1772 | "called with the wrong value for"); |
Ian Elliott | 2c1daf5 | 2016-05-12 09:41:46 -0600 | [diff] [blame] | 1773 | err = vkCreateXcbSurfaceKHR(instance(), &xcb_create_info, NULL, &surface); |
| 1774 | pass = (err != VK_SUCCESS); |
| 1775 | ASSERT_TRUE(pass); |
| 1776 | m_errorMonitor->VerifyFound(); |
| 1777 | |
Ian Elliott | 2c1daf5 | 2016-05-12 09:41:46 -0600 | [diff] [blame] | 1778 | // Create a native window, and then correctly create a surface: |
| 1779 | xcb_connection_t *connection; |
| 1780 | xcb_screen_t *screen; |
| 1781 | xcb_window_t xcb_window; |
| 1782 | xcb_intern_atom_reply_t *atom_wm_delete_window; |
| 1783 | |
| 1784 | const xcb_setup_t *setup; |
| 1785 | xcb_screen_iterator_t iter; |
| 1786 | int scr; |
| 1787 | uint32_t value_mask, value_list[32]; |
| 1788 | int width = 1; |
| 1789 | int height = 1; |
| 1790 | |
| 1791 | connection = xcb_connect(NULL, &scr); |
| 1792 | ASSERT_TRUE(connection != NULL); |
| 1793 | setup = xcb_get_setup(connection); |
| 1794 | iter = xcb_setup_roots_iterator(setup); |
| 1795 | while (scr-- > 0) |
| 1796 | xcb_screen_next(&iter); |
| 1797 | screen = iter.data; |
| 1798 | |
| 1799 | xcb_window = xcb_generate_id(connection); |
| 1800 | |
| 1801 | value_mask = XCB_CW_BACK_PIXEL | XCB_CW_EVENT_MASK; |
| 1802 | value_list[0] = screen->black_pixel; |
| 1803 | value_list[1] = XCB_EVENT_MASK_KEY_RELEASE | XCB_EVENT_MASK_EXPOSURE | |
| 1804 | XCB_EVENT_MASK_STRUCTURE_NOTIFY; |
| 1805 | |
| 1806 | xcb_create_window(connection, XCB_COPY_FROM_PARENT, xcb_window, |
| 1807 | screen->root, 0, 0, width, height, 0, |
| 1808 | XCB_WINDOW_CLASS_INPUT_OUTPUT, screen->root_visual, |
| 1809 | value_mask, value_list); |
| 1810 | |
| 1811 | /* Magic code that will send notification when window is destroyed */ |
| 1812 | xcb_intern_atom_cookie_t cookie = |
| 1813 | xcb_intern_atom(connection, 1, 12, "WM_PROTOCOLS"); |
| 1814 | xcb_intern_atom_reply_t *reply = |
| 1815 | xcb_intern_atom_reply(connection, cookie, 0); |
| 1816 | |
| 1817 | xcb_intern_atom_cookie_t cookie2 = |
| 1818 | xcb_intern_atom(connection, 0, 16, "WM_DELETE_WINDOW"); |
Mark Lobodzinski | 085d27a | 2016-05-17 09:34:26 -0600 | [diff] [blame] | 1819 | atom_wm_delete_window = xcb_intern_atom_reply(connection, cookie2, 0); |
Ian Elliott | 2c1daf5 | 2016-05-12 09:41:46 -0600 | [diff] [blame] | 1820 | xcb_change_property(connection, XCB_PROP_MODE_REPLACE, xcb_window, |
| 1821 | (*reply).atom, 4, 32, 1, |
| 1822 | &(*atom_wm_delete_window).atom); |
| 1823 | free(reply); |
| 1824 | |
| 1825 | xcb_map_window(connection, xcb_window); |
| 1826 | |
| 1827 | // Force the x/y coordinates to 100,100 results are identical in consecutive |
| 1828 | // runs |
| 1829 | const uint32_t coords[] = {100, 100}; |
| 1830 | xcb_configure_window(connection, xcb_window, |
| 1831 | XCB_CONFIG_WINDOW_X | XCB_CONFIG_WINDOW_Y, coords); |
| 1832 | |
Ian Elliott | 2c1daf5 | 2016-05-12 09:41:46 -0600 | [diff] [blame] | 1833 | // Finally, try to correctly create a surface: |
| 1834 | xcb_create_info.sType = VK_STRUCTURE_TYPE_XCB_SURFACE_CREATE_INFO_KHR; |
| 1835 | xcb_create_info.pNext = NULL; |
| 1836 | xcb_create_info.flags = 0; |
| 1837 | xcb_create_info.connection = connection; |
| 1838 | xcb_create_info.window = xcb_window; |
| 1839 | err = vkCreateXcbSurfaceKHR(instance(), &xcb_create_info, NULL, &surface); |
| 1840 | pass = (err == VK_SUCCESS); |
| 1841 | ASSERT_TRUE(pass); |
| 1842 | |
Ian Elliott | 2c1daf5 | 2016-05-12 09:41:46 -0600 | [diff] [blame] | 1843 | // Check if surface supports presentation: |
| 1844 | |
| 1845 | // 1st, do so without having queried the queue families: |
| 1846 | VkBool32 supported = false; |
| 1847 | // TODO: Get the following error to come out: |
| 1848 | m_errorMonitor->SetDesiredFailureMsg( |
| 1849 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 1850 | "called before calling the vkGetPhysicalDeviceQueueFamilyProperties " |
| 1851 | "function"); |
| 1852 | err = vkGetPhysicalDeviceSurfaceSupportKHR(gpu(), 0, surface, &supported); |
| 1853 | pass = (err != VK_SUCCESS); |
Mark Lobodzinski | 085d27a | 2016-05-17 09:34:26 -0600 | [diff] [blame] | 1854 | // ASSERT_TRUE(pass); |
| 1855 | // m_errorMonitor->VerifyFound(); |
Ian Elliott | 2c1daf5 | 2016-05-12 09:41:46 -0600 | [diff] [blame] | 1856 | |
| 1857 | // Next, query a queue family index that's too large: |
| 1858 | m_errorMonitor->SetDesiredFailureMsg( |
| 1859 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 1860 | "called with a queueFamilyIndex that is too large"); |
Mark Lobodzinski | 085d27a | 2016-05-17 09:34:26 -0600 | [diff] [blame] | 1861 | err = vkGetPhysicalDeviceSurfaceSupportKHR(gpu(), 100000, surface, |
| 1862 | &supported); |
Ian Elliott | 2c1daf5 | 2016-05-12 09:41:46 -0600 | [diff] [blame] | 1863 | pass = (err != VK_SUCCESS); |
| 1864 | ASSERT_TRUE(pass); |
| 1865 | m_errorMonitor->VerifyFound(); |
| 1866 | |
| 1867 | // Finally, do so correctly: |
Mark Lobodzinski | 085d27a | 2016-05-17 09:34:26 -0600 | [diff] [blame] | 1868 | // FIXME: THIS ISN'T CORRECT--MUST QUERY UNTIL WE FIND A QUEUE FAMILY THAT'S |
| 1869 | // SUPPORTED |
Ian Elliott | 2c1daf5 | 2016-05-12 09:41:46 -0600 | [diff] [blame] | 1870 | err = vkGetPhysicalDeviceSurfaceSupportKHR(gpu(), 0, surface, &supported); |
| 1871 | pass = (err == VK_SUCCESS); |
| 1872 | ASSERT_TRUE(pass); |
| 1873 | |
Ian Elliott | 2c1daf5 | 2016-05-12 09:41:46 -0600 | [diff] [blame] | 1874 | // Before proceeding, try to create a swapchain without having called |
| 1875 | // vkGetPhysicalDeviceSurfaceCapabilitiesKHR(): |
| 1876 | swapchain_create_info.sType = VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR; |
| 1877 | swapchain_create_info.pNext = NULL; |
| 1878 | swapchain_create_info.flags = 0; |
| 1879 | m_errorMonitor->SetDesiredFailureMsg( |
| 1880 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 1881 | "called before calling vkGetPhysicalDeviceSurfaceCapabilitiesKHR()."); |
Mark Lobodzinski | 085d27a | 2016-05-17 09:34:26 -0600 | [diff] [blame] | 1882 | err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, |
| 1883 | &swapchain); |
Ian Elliott | 2c1daf5 | 2016-05-12 09:41:46 -0600 | [diff] [blame] | 1884 | pass = (err != VK_SUCCESS); |
| 1885 | ASSERT_TRUE(pass); |
| 1886 | m_errorMonitor->VerifyFound(); |
| 1887 | |
Ian Elliott | 2c1daf5 | 2016-05-12 09:41:46 -0600 | [diff] [blame] | 1888 | // Get the surface capabilities: |
| 1889 | VkSurfaceCapabilitiesKHR surface_capabilities; |
| 1890 | |
| 1891 | // Do so correctly (only error logged by this entrypoint is if the |
| 1892 | // extension isn't enabled): |
| 1893 | err = vkGetPhysicalDeviceSurfaceCapabilitiesKHR(gpu(), surface, |
| 1894 | &surface_capabilities); |
| 1895 | pass = (err == VK_SUCCESS); |
| 1896 | ASSERT_TRUE(pass); |
| 1897 | |
Ian Elliott | 2c1daf5 | 2016-05-12 09:41:46 -0600 | [diff] [blame] | 1898 | // Get the surface formats: |
| 1899 | uint32_t surface_format_count; |
| 1900 | |
| 1901 | // First, try without a pointer to surface_format_count: |
Mark Lobodzinski | 085d27a | 2016-05-17 09:34:26 -0600 | [diff] [blame] | 1902 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 1903 | "called with NULL pointer"); |
Ian Elliott | 2c1daf5 | 2016-05-12 09:41:46 -0600 | [diff] [blame] | 1904 | vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, NULL, NULL); |
| 1905 | pass = (err == VK_SUCCESS); |
| 1906 | ASSERT_TRUE(pass); |
| 1907 | m_errorMonitor->VerifyFound(); |
| 1908 | |
| 1909 | // Next, call with a non-NULL pSurfaceFormats, even though we haven't |
| 1910 | // correctly done a 1st try (to get the count): |
| 1911 | m_errorMonitor->SetDesiredFailureMsg( |
| 1912 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 1913 | "but no prior positive value has been seen for"); |
| 1914 | surface_format_count = 0; |
| 1915 | vkGetPhysicalDeviceSurfaceFormatsKHR( |
Mark Lobodzinski | 085d27a | 2016-05-17 09:34:26 -0600 | [diff] [blame] | 1916 | gpu(), surface, &surface_format_count, |
| 1917 | (VkSurfaceFormatKHR *)&surface_format_count); |
Ian Elliott | 2c1daf5 | 2016-05-12 09:41:46 -0600 | [diff] [blame] | 1918 | pass = (err == VK_SUCCESS); |
| 1919 | ASSERT_TRUE(pass); |
| 1920 | m_errorMonitor->VerifyFound(); |
| 1921 | |
| 1922 | // Next, correctly do a 1st try (with a NULL pointer to surface_formats): |
Mark Lobodzinski | 085d27a | 2016-05-17 09:34:26 -0600 | [diff] [blame] | 1923 | vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &surface_format_count, |
| 1924 | NULL); |
Ian Elliott | 2c1daf5 | 2016-05-12 09:41:46 -0600 | [diff] [blame] | 1925 | pass = (err == VK_SUCCESS); |
| 1926 | ASSERT_TRUE(pass); |
| 1927 | |
| 1928 | // Allocate memory for the correct number of VkSurfaceFormatKHR's: |
Mark Lobodzinski | 085d27a | 2016-05-17 09:34:26 -0600 | [diff] [blame] | 1929 | VkSurfaceFormatKHR *surface_formats = (VkSurfaceFormatKHR *)malloc( |
| 1930 | surface_format_count * sizeof(VkSurfaceFormatKHR)); |
Ian Elliott | 2c1daf5 | 2016-05-12 09:41:46 -0600 | [diff] [blame] | 1931 | |
| 1932 | // Next, do a 2nd try with surface_format_count being set too high: |
| 1933 | surface_format_count += 5; |
Mark Lobodzinski | 085d27a | 2016-05-17 09:34:26 -0600 | [diff] [blame] | 1934 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 1935 | "that is greater than the value"); |
| 1936 | vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &surface_format_count, |
Ian Elliott | 2c1daf5 | 2016-05-12 09:41:46 -0600 | [diff] [blame] | 1937 | surface_formats); |
| 1938 | pass = (err == VK_SUCCESS); |
| 1939 | ASSERT_TRUE(pass); |
| 1940 | m_errorMonitor->VerifyFound(); |
| 1941 | |
| 1942 | // Finally, do a correct 1st and 2nd try: |
Mark Lobodzinski | 085d27a | 2016-05-17 09:34:26 -0600 | [diff] [blame] | 1943 | vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &surface_format_count, |
| 1944 | NULL); |
Ian Elliott | 2c1daf5 | 2016-05-12 09:41:46 -0600 | [diff] [blame] | 1945 | pass = (err == VK_SUCCESS); |
| 1946 | ASSERT_TRUE(pass); |
Mark Lobodzinski | 085d27a | 2016-05-17 09:34:26 -0600 | [diff] [blame] | 1947 | vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &surface_format_count, |
Ian Elliott | 2c1daf5 | 2016-05-12 09:41:46 -0600 | [diff] [blame] | 1948 | surface_formats); |
| 1949 | pass = (err == VK_SUCCESS); |
| 1950 | ASSERT_TRUE(pass); |
| 1951 | |
Ian Elliott | 2c1daf5 | 2016-05-12 09:41:46 -0600 | [diff] [blame] | 1952 | // Get the surface present modes: |
| 1953 | uint32_t surface_present_mode_count; |
| 1954 | |
| 1955 | // First, try without a pointer to surface_format_count: |
Mark Lobodzinski | 085d27a | 2016-05-17 09:34:26 -0600 | [diff] [blame] | 1956 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 1957 | "called with NULL pointer"); |
Ian Elliott | 2c1daf5 | 2016-05-12 09:41:46 -0600 | [diff] [blame] | 1958 | vkGetPhysicalDeviceSurfacePresentModesKHR(gpu(), surface, NULL, NULL); |
| 1959 | pass = (err == VK_SUCCESS); |
| 1960 | ASSERT_TRUE(pass); |
| 1961 | m_errorMonitor->VerifyFound(); |
| 1962 | |
| 1963 | // Next, call with a non-NULL VkPresentModeKHR, even though we haven't |
| 1964 | // correctly done a 1st try (to get the count): |
| 1965 | m_errorMonitor->SetDesiredFailureMsg( |
| 1966 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 1967 | "but no prior positive value has been seen for"); |
| 1968 | surface_present_mode_count = 0; |
| 1969 | vkGetPhysicalDeviceSurfacePresentModesKHR( |
Mark Lobodzinski | 085d27a | 2016-05-17 09:34:26 -0600 | [diff] [blame] | 1970 | gpu(), surface, &surface_present_mode_count, |
| 1971 | (VkPresentModeKHR *)&surface_present_mode_count); |
Ian Elliott | 2c1daf5 | 2016-05-12 09:41:46 -0600 | [diff] [blame] | 1972 | pass = (err == VK_SUCCESS); |
| 1973 | ASSERT_TRUE(pass); |
| 1974 | m_errorMonitor->VerifyFound(); |
| 1975 | |
| 1976 | // Next, correctly do a 1st try (with a NULL pointer to surface_formats): |
Mark Lobodzinski | 085d27a | 2016-05-17 09:34:26 -0600 | [diff] [blame] | 1977 | vkGetPhysicalDeviceSurfacePresentModesKHR( |
| 1978 | gpu(), surface, &surface_present_mode_count, NULL); |
Ian Elliott | 2c1daf5 | 2016-05-12 09:41:46 -0600 | [diff] [blame] | 1979 | pass = (err == VK_SUCCESS); |
| 1980 | ASSERT_TRUE(pass); |
| 1981 | |
| 1982 | // Allocate memory for the correct number of VkSurfaceFormatKHR's: |
Mark Lobodzinski | 085d27a | 2016-05-17 09:34:26 -0600 | [diff] [blame] | 1983 | VkPresentModeKHR *surface_present_modes = (VkPresentModeKHR *)malloc( |
| 1984 | surface_present_mode_count * sizeof(VkPresentModeKHR)); |
Ian Elliott | 2c1daf5 | 2016-05-12 09:41:46 -0600 | [diff] [blame] | 1985 | |
| 1986 | // Next, do a 2nd try with surface_format_count being set too high: |
| 1987 | surface_present_mode_count += 5; |
Mark Lobodzinski | 085d27a | 2016-05-17 09:34:26 -0600 | [diff] [blame] | 1988 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 1989 | "that is greater than the value"); |
| 1990 | vkGetPhysicalDeviceSurfacePresentModesKHR( |
| 1991 | gpu(), surface, &surface_present_mode_count, surface_present_modes); |
Ian Elliott | 2c1daf5 | 2016-05-12 09:41:46 -0600 | [diff] [blame] | 1992 | pass = (err == VK_SUCCESS); |
| 1993 | ASSERT_TRUE(pass); |
| 1994 | m_errorMonitor->VerifyFound(); |
| 1995 | |
| 1996 | // Finally, do a correct 1st and 2nd try: |
Mark Lobodzinski | 085d27a | 2016-05-17 09:34:26 -0600 | [diff] [blame] | 1997 | vkGetPhysicalDeviceSurfacePresentModesKHR( |
| 1998 | gpu(), surface, &surface_present_mode_count, NULL); |
Ian Elliott | 2c1daf5 | 2016-05-12 09:41:46 -0600 | [diff] [blame] | 1999 | pass = (err == VK_SUCCESS); |
| 2000 | ASSERT_TRUE(pass); |
Mark Lobodzinski | 085d27a | 2016-05-17 09:34:26 -0600 | [diff] [blame] | 2001 | vkGetPhysicalDeviceSurfacePresentModesKHR( |
| 2002 | gpu(), surface, &surface_present_mode_count, surface_present_modes); |
Ian Elliott | 2c1daf5 | 2016-05-12 09:41:46 -0600 | [diff] [blame] | 2003 | pass = (err == VK_SUCCESS); |
| 2004 | ASSERT_TRUE(pass); |
| 2005 | |
Ian Elliott | 2c1daf5 | 2016-05-12 09:41:46 -0600 | [diff] [blame] | 2006 | // Create a swapchain: |
| 2007 | |
| 2008 | // First, try without a pointer to swapchain_create_info: |
Mark Lobodzinski | 085d27a | 2016-05-17 09:34:26 -0600 | [diff] [blame] | 2009 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 2010 | "called with NULL pointer"); |
Ian Elliott | 2c1daf5 | 2016-05-12 09:41:46 -0600 | [diff] [blame] | 2011 | err = vkCreateSwapchainKHR(m_device->device(), NULL, NULL, &swapchain); |
| 2012 | pass = (err != VK_SUCCESS); |
| 2013 | ASSERT_TRUE(pass); |
| 2014 | m_errorMonitor->VerifyFound(); |
| 2015 | |
| 2016 | // Next, call with a non-NULL swapchain_create_info, that has the wrong |
| 2017 | // sType: |
| 2018 | swapchain_create_info.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO; |
Mark Lobodzinski | 085d27a | 2016-05-17 09:34:26 -0600 | [diff] [blame] | 2019 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 2020 | "called with the wrong value for"); |
| 2021 | err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, |
| 2022 | &swapchain); |
Ian Elliott | 2c1daf5 | 2016-05-12 09:41:46 -0600 | [diff] [blame] | 2023 | pass = (err != VK_SUCCESS); |
| 2024 | ASSERT_TRUE(pass); |
| 2025 | m_errorMonitor->VerifyFound(); |
| 2026 | |
| 2027 | // Next, call with a NULL swapchain pointer: |
| 2028 | swapchain_create_info.sType = VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR; |
| 2029 | swapchain_create_info.pNext = NULL; |
| 2030 | swapchain_create_info.flags = 0; |
Mark Lobodzinski | 085d27a | 2016-05-17 09:34:26 -0600 | [diff] [blame] | 2031 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 2032 | "called with NULL pointer"); |
| 2033 | err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, |
| 2034 | NULL); |
Ian Elliott | 2c1daf5 | 2016-05-12 09:41:46 -0600 | [diff] [blame] | 2035 | pass = (err != VK_SUCCESS); |
| 2036 | ASSERT_TRUE(pass); |
| 2037 | m_errorMonitor->VerifyFound(); |
| 2038 | |
Mark Lobodzinski | 085d27a | 2016-05-17 09:34:26 -0600 | [diff] [blame] | 2039 | // TODO: Enhance swapchain layer so that |
| 2040 | // swapchain_create_info.queueFamilyIndexCount is checked against something? |
Ian Elliott | 2c1daf5 | 2016-05-12 09:41:46 -0600 | [diff] [blame] | 2041 | |
| 2042 | // Next, call with a queue family index that's too large: |
| 2043 | uint32_t queueFamilyIndex[2] = {100000, 0}; |
| 2044 | swapchain_create_info.imageSharingMode = VK_SHARING_MODE_CONCURRENT; |
| 2045 | swapchain_create_info.queueFamilyIndexCount = 2; |
| 2046 | swapchain_create_info.pQueueFamilyIndices = queueFamilyIndex; |
| 2047 | m_errorMonitor->SetDesiredFailureMsg( |
| 2048 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 2049 | "called with a queueFamilyIndex that is too large"); |
Mark Lobodzinski | 085d27a | 2016-05-17 09:34:26 -0600 | [diff] [blame] | 2050 | err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, |
| 2051 | &swapchain); |
Ian Elliott | 2c1daf5 | 2016-05-12 09:41:46 -0600 | [diff] [blame] | 2052 | pass = (err != VK_SUCCESS); |
| 2053 | ASSERT_TRUE(pass); |
| 2054 | m_errorMonitor->VerifyFound(); |
| 2055 | |
| 2056 | // Next, call a queueFamilyIndexCount that's too small for CONCURRENT: |
| 2057 | swapchain_create_info.imageSharingMode = VK_SHARING_MODE_CONCURRENT; |
| 2058 | swapchain_create_info.queueFamilyIndexCount = 1; |
| 2059 | m_errorMonitor->SetDesiredFailureMsg( |
| 2060 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 2061 | "but with a bad value(s) for pCreateInfo->queueFamilyIndexCount or " |
| 2062 | "pCreateInfo->pQueueFamilyIndices)."); |
Mark Lobodzinski | 085d27a | 2016-05-17 09:34:26 -0600 | [diff] [blame] | 2063 | err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, |
| 2064 | &swapchain); |
Ian Elliott | 2c1daf5 | 2016-05-12 09:41:46 -0600 | [diff] [blame] | 2065 | pass = (err != VK_SUCCESS); |
| 2066 | ASSERT_TRUE(pass); |
| 2067 | m_errorMonitor->VerifyFound(); |
| 2068 | |
| 2069 | // Next, call with an invalid imageSharingMode: |
| 2070 | swapchain_create_info.imageSharingMode = VK_SHARING_MODE_MAX_ENUM; |
| 2071 | swapchain_create_info.queueFamilyIndexCount = 1; |
| 2072 | m_errorMonitor->SetDesiredFailureMsg( |
| 2073 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 2074 | "called with a non-supported pCreateInfo->imageSharingMode (i.e."); |
Mark Lobodzinski | 085d27a | 2016-05-17 09:34:26 -0600 | [diff] [blame] | 2075 | err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, |
| 2076 | &swapchain); |
Ian Elliott | 2c1daf5 | 2016-05-12 09:41:46 -0600 | [diff] [blame] | 2077 | pass = (err != VK_SUCCESS); |
| 2078 | ASSERT_TRUE(pass); |
| 2079 | m_errorMonitor->VerifyFound(); |
| 2080 | // Fix for the future: |
Mark Lobodzinski | 085d27a | 2016-05-17 09:34:26 -0600 | [diff] [blame] | 2081 | // FIXME: THIS ISN'T CORRECT--MUST QUERY UNTIL WE FIND A QUEUE FAMILY THAT'S |
| 2082 | // SUPPORTED |
Ian Elliott | 2c1daf5 | 2016-05-12 09:41:46 -0600 | [diff] [blame] | 2083 | swapchain_create_info.queueFamilyIndexCount = 0; |
| 2084 | queueFamilyIndex[0] = 0; |
| 2085 | swapchain_create_info.imageSharingMode = VK_SHARING_MODE_EXCLUSIVE; |
| 2086 | |
Mark Lobodzinski | 085d27a | 2016-05-17 09:34:26 -0600 | [diff] [blame] | 2087 | // TODO: CONTINUE TESTING VALIDATION OF vkCreateSwapchainKHR() ... |
Ian Elliott | 2c1daf5 | 2016-05-12 09:41:46 -0600 | [diff] [blame] | 2088 | // Get the images from a swapchain: |
Ian Elliott | 2c1daf5 | 2016-05-12 09:41:46 -0600 | [diff] [blame] | 2089 | // Acquire an image from a swapchain: |
Ian Elliott | 2c1daf5 | 2016-05-12 09:41:46 -0600 | [diff] [blame] | 2090 | // Present an image to a swapchain: |
Ian Elliott | 2c1daf5 | 2016-05-12 09:41:46 -0600 | [diff] [blame] | 2091 | // Destroy the swapchain: |
| 2092 | |
Mark Lobodzinski | 085d27a | 2016-05-17 09:34:26 -0600 | [diff] [blame] | 2093 | // TODOs: |
| 2094 | // |
| 2095 | // - Try destroying the device without first destroying the swapchain |
| 2096 | // |
| 2097 | // - Try destroying the device without first destroying the surface |
| 2098 | // |
| 2099 | // - Try destroying the surface without first destroying the swapchain |
Ian Elliott | 2c1daf5 | 2016-05-12 09:41:46 -0600 | [diff] [blame] | 2100 | |
| 2101 | // Destroy the surface: |
| 2102 | vkDestroySurfaceKHR(instance(), surface, NULL); |
| 2103 | |
Ian Elliott | 2c1daf5 | 2016-05-12 09:41:46 -0600 | [diff] [blame] | 2104 | // Tear down the window: |
| 2105 | xcb_destroy_window(connection, xcb_window); |
| 2106 | xcb_disconnect(connection); |
| 2107 | |
| 2108 | #else // VK_USE_PLATFORM_XCB_KHR |
Mark Lobodzinski | 085d27a | 2016-05-17 09:34:26 -0600 | [diff] [blame] | 2109 | return; |
Ian Elliott | 2c1daf5 | 2016-05-12 09:41:46 -0600 | [diff] [blame] | 2110 | #endif // VK_USE_PLATFORM_XCB_KHR |
| 2111 | } |
| 2112 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 2113 | TEST_F(VkLayerTest, MapMemWithoutHostVisibleBit) { |
| 2114 | VkResult err; |
| 2115 | bool pass; |
Mark Lobodzinski | 3780e14 | 2015-05-14 15:08:13 -0500 | [diff] [blame] | 2116 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 2117 | m_errorMonitor->SetDesiredFailureMsg( |
| 2118 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 2119 | "Mapping Memory without VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT"); |
| 2120 | |
Mark Lobodzinski | 3780e14 | 2015-05-14 15:08:13 -0500 | [diff] [blame] | 2121 | ASSERT_NO_FATAL_FAILURE(InitState()); |
Mark Lobodzinski | 3780e14 | 2015-05-14 15:08:13 -0500 | [diff] [blame] | 2122 | |
| 2123 | // Create an image, allocate memory, free it, and then try to bind it |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 2124 | VkImage image; |
| 2125 | VkDeviceMemory mem; |
| 2126 | VkMemoryRequirements mem_reqs; |
Mark Lobodzinski | 3780e14 | 2015-05-14 15:08:13 -0500 | [diff] [blame] | 2127 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 2128 | const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM; |
| 2129 | const int32_t tex_width = 32; |
| 2130 | const int32_t tex_height = 32; |
Mark Lobodzinski | 3780e14 | 2015-05-14 15:08:13 -0500 | [diff] [blame] | 2131 | |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 2132 | VkImageCreateInfo image_create_info = {}; |
| 2133 | image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 2134 | image_create_info.pNext = NULL; |
| 2135 | image_create_info.imageType = VK_IMAGE_TYPE_2D; |
| 2136 | image_create_info.format = tex_format; |
| 2137 | image_create_info.extent.width = tex_width; |
| 2138 | image_create_info.extent.height = tex_height; |
| 2139 | image_create_info.extent.depth = 1; |
| 2140 | image_create_info.mipLevels = 1; |
| 2141 | image_create_info.arrayLayers = 1; |
| 2142 | image_create_info.samples = VK_SAMPLE_COUNT_1_BIT; |
| 2143 | image_create_info.tiling = VK_IMAGE_TILING_LINEAR; |
| 2144 | image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT; |
| 2145 | image_create_info.flags = 0; |
Mark Lobodzinski | 5fcc421 | 2015-09-14 17:43:42 -0600 | [diff] [blame] | 2146 | |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 2147 | VkMemoryAllocateInfo mem_alloc = {}; |
Chia-I Wu | 00ce540 | 2015-11-10 16:21:09 +0800 | [diff] [blame] | 2148 | mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 2149 | mem_alloc.pNext = NULL; |
| 2150 | mem_alloc.allocationSize = 0; |
| 2151 | // Introduce failure, do NOT set memProps to |
| 2152 | // VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT |
| 2153 | mem_alloc.memoryTypeIndex = 1; |
Mark Lobodzinski | 3780e14 | 2015-05-14 15:08:13 -0500 | [diff] [blame] | 2154 | |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 2155 | err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image); |
Mark Lobodzinski | 3780e14 | 2015-05-14 15:08:13 -0500 | [diff] [blame] | 2156 | ASSERT_VK_SUCCESS(err); |
| 2157 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 2158 | vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs); |
Mark Lobodzinski | 3780e14 | 2015-05-14 15:08:13 -0500 | [diff] [blame] | 2159 | |
Mark Lobodzinski | 2306535 | 2015-05-29 09:32:35 -0500 | [diff] [blame] | 2160 | mem_alloc.allocationSize = mem_reqs.size; |
Mark Lobodzinski | 3780e14 | 2015-05-14 15:08:13 -0500 | [diff] [blame] | 2161 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 2162 | pass = |
| 2163 | m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0, |
| 2164 | VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT); |
| 2165 | if (!pass) { // If we can't find any unmappable memory this test doesn't |
| 2166 | // make sense |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 2167 | vkDestroyImage(m_device->device(), image, NULL); |
Tony Barbour | 02fdc7d | 2015-08-04 16:13:01 -0600 | [diff] [blame] | 2168 | return; |
Mike Stroyan | d1c84a5 | 2015-08-18 14:40:24 -0600 | [diff] [blame] | 2169 | } |
Mike Stroyan | 713b2d7 | 2015-08-04 10:49:29 -0600 | [diff] [blame] | 2170 | |
Mark Lobodzinski | 3780e14 | 2015-05-14 15:08:13 -0500 | [diff] [blame] | 2171 | // allocate memory |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 2172 | err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem); |
Mark Lobodzinski | 3780e14 | 2015-05-14 15:08:13 -0500 | [diff] [blame] | 2173 | ASSERT_VK_SUCCESS(err); |
| 2174 | |
| 2175 | // Try to bind free memory that has been freed |
Tony Barbour | 67e9915 | 2015-07-10 14:10:27 -0600 | [diff] [blame] | 2176 | err = vkBindImageMemory(m_device->device(), image, mem, 0); |
Mark Lobodzinski | 3780e14 | 2015-05-14 15:08:13 -0500 | [diff] [blame] | 2177 | ASSERT_VK_SUCCESS(err); |
| 2178 | |
| 2179 | // Map memory as if to initialize the image |
| 2180 | void *mappedAddress = NULL; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 2181 | err = vkMapMemory(m_device->device(), mem, 0, VK_WHOLE_SIZE, 0, |
| 2182 | &mappedAddress); |
Mark Lobodzinski | 3780e14 | 2015-05-14 15:08:13 -0500 | [diff] [blame] | 2183 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 2184 | m_errorMonitor->VerifyFound(); |
Mike Stroyan | d1c84a5 | 2015-08-18 14:40:24 -0600 | [diff] [blame] | 2185 | |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 2186 | vkDestroyImage(m_device->device(), image, NULL); |
Tony Barbour | df4c004 | 2016-06-01 15:55:43 -0600 | [diff] [blame] | 2187 | vkFreeMemory(m_device->device(), mem, NULL); |
Mark Lobodzinski | 3780e14 | 2015-05-14 15:08:13 -0500 | [diff] [blame] | 2188 | } |
| 2189 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 2190 | TEST_F(VkLayerTest, RebindMemory) { |
| 2191 | VkResult err; |
| 2192 | bool pass; |
Mark Lobodzinski | 944aab1 | 2015-06-05 13:59:04 -0500 | [diff] [blame] | 2193 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 2194 | m_errorMonitor->SetDesiredFailureMsg( |
| 2195 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 2196 | "which has already been bound to mem object"); |
| 2197 | |
Mark Lobodzinski | 944aab1 | 2015-06-05 13:59:04 -0500 | [diff] [blame] | 2198 | ASSERT_NO_FATAL_FAILURE(InitState()); |
Mark Lobodzinski | 944aab1 | 2015-06-05 13:59:04 -0500 | [diff] [blame] | 2199 | |
| 2200 | // Create an image, allocate memory, free it, and then try to bind it |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 2201 | VkImage image; |
| 2202 | VkDeviceMemory mem1; |
| 2203 | VkDeviceMemory mem2; |
| 2204 | VkMemoryRequirements mem_reqs; |
Mark Lobodzinski | 944aab1 | 2015-06-05 13:59:04 -0500 | [diff] [blame] | 2205 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 2206 | const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM; |
| 2207 | const int32_t tex_width = 32; |
| 2208 | const int32_t tex_height = 32; |
Mark Lobodzinski | 944aab1 | 2015-06-05 13:59:04 -0500 | [diff] [blame] | 2209 | |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 2210 | VkImageCreateInfo image_create_info = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 2211 | image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO; |
| 2212 | image_create_info.pNext = NULL; |
| 2213 | image_create_info.imageType = VK_IMAGE_TYPE_2D; |
| 2214 | image_create_info.format = tex_format; |
| 2215 | image_create_info.extent.width = tex_width; |
| 2216 | image_create_info.extent.height = tex_height; |
| 2217 | image_create_info.extent.depth = 1; |
| 2218 | image_create_info.mipLevels = 1; |
| 2219 | image_create_info.arrayLayers = 1; |
| 2220 | image_create_info.samples = VK_SAMPLE_COUNT_1_BIT; |
| 2221 | image_create_info.tiling = VK_IMAGE_TILING_LINEAR; |
| 2222 | image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT; |
| 2223 | image_create_info.flags = 0; |
Mark Lobodzinski | 944aab1 | 2015-06-05 13:59:04 -0500 | [diff] [blame] | 2224 | |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 2225 | VkMemoryAllocateInfo mem_alloc = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 2226 | mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO; |
| 2227 | mem_alloc.pNext = NULL; |
| 2228 | mem_alloc.allocationSize = 0; |
| 2229 | mem_alloc.memoryTypeIndex = 0; |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 2230 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 2231 | // Introduce failure, do NOT set memProps to |
| 2232 | // VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 2233 | mem_alloc.memoryTypeIndex = 1; |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 2234 | err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image); |
Mark Lobodzinski | 944aab1 | 2015-06-05 13:59:04 -0500 | [diff] [blame] | 2235 | ASSERT_VK_SUCCESS(err); |
| 2236 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 2237 | vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs); |
Mark Lobodzinski | 944aab1 | 2015-06-05 13:59:04 -0500 | [diff] [blame] | 2238 | |
| 2239 | mem_alloc.allocationSize = mem_reqs.size; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 2240 | pass = |
| 2241 | m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0); |
Courtney Goeltzenleuchter | 1d2f0dd | 2015-10-22 11:03:31 -0600 | [diff] [blame] | 2242 | ASSERT_TRUE(pass); |
Mark Lobodzinski | 944aab1 | 2015-06-05 13:59:04 -0500 | [diff] [blame] | 2243 | |
| 2244 | // allocate 2 memory objects |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 2245 | err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem1); |
Mark Lobodzinski | 944aab1 | 2015-06-05 13:59:04 -0500 | [diff] [blame] | 2246 | ASSERT_VK_SUCCESS(err); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 2247 | err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem2); |
Mark Lobodzinski | 944aab1 | 2015-06-05 13:59:04 -0500 | [diff] [blame] | 2248 | ASSERT_VK_SUCCESS(err); |
| 2249 | |
| 2250 | // Bind first memory object to Image object |
Tony Barbour | 67e9915 | 2015-07-10 14:10:27 -0600 | [diff] [blame] | 2251 | err = vkBindImageMemory(m_device->device(), image, mem1, 0); |
Mark Lobodzinski | 944aab1 | 2015-06-05 13:59:04 -0500 | [diff] [blame] | 2252 | ASSERT_VK_SUCCESS(err); |
| 2253 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 2254 | // Introduce validation failure, try to bind a different memory object to |
| 2255 | // the same image object |
Tony Barbour | 67e9915 | 2015-07-10 14:10:27 -0600 | [diff] [blame] | 2256 | err = vkBindImageMemory(m_device->device(), image, mem2, 0); |
Mark Lobodzinski | 944aab1 | 2015-06-05 13:59:04 -0500 | [diff] [blame] | 2257 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 2258 | m_errorMonitor->VerifyFound(); |
Mike Stroyan | d1c84a5 | 2015-08-18 14:40:24 -0600 | [diff] [blame] | 2259 | |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 2260 | vkDestroyImage(m_device->device(), image, NULL); |
| 2261 | vkFreeMemory(m_device->device(), mem1, NULL); |
| 2262 | vkFreeMemory(m_device->device(), mem2, NULL); |
Mark Lobodzinski | 944aab1 | 2015-06-05 13:59:04 -0500 | [diff] [blame] | 2263 | } |
Mark Lobodzinski | 3780e14 | 2015-05-14 15:08:13 -0500 | [diff] [blame] | 2264 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 2265 | TEST_F(VkLayerTest, SubmitSignaledFence) { |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 2266 | vk_testing::Fence testFence; |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 2267 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 2268 | m_errorMonitor->SetDesiredFailureMsg( |
| 2269 | VK_DEBUG_REPORT_ERROR_BIT_EXT, "submitted in SIGNALED state. Fences " |
| 2270 | "must be reset before being submitted"); |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 2271 | |
| 2272 | VkFenceCreateInfo fenceInfo = {}; |
Tony Barbour | 0b4d956 | 2015-04-09 10:48:04 -0600 | [diff] [blame] | 2273 | fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO; |
| 2274 | fenceInfo.pNext = NULL; |
| 2275 | fenceInfo.flags = VK_FENCE_CREATE_SIGNALED_BIT; |
Tony Barbour | 300a608 | 2015-04-07 13:44:53 -0600 | [diff] [blame] | 2276 | |
Tony Barbour | 300a608 | 2015-04-07 13:44:53 -0600 | [diff] [blame] | 2277 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 2278 | ASSERT_NO_FATAL_FAILURE(InitViewport()); |
| 2279 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 2280 | |
Tony Barbour | fe3351b | 2015-07-28 10:17:20 -0600 | [diff] [blame] | 2281 | BeginCommandBuffer(); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 2282 | m_commandBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color, |
| 2283 | m_stencil_clear_color, NULL); |
Tony Barbour | fe3351b | 2015-07-28 10:17:20 -0600 | [diff] [blame] | 2284 | EndCommandBuffer(); |
Tony Barbour | 300a608 | 2015-04-07 13:44:53 -0600 | [diff] [blame] | 2285 | |
| 2286 | testFence.init(*m_device, fenceInfo); |
Mark Lobodzinski | 5fcc421 | 2015-09-14 17:43:42 -0600 | [diff] [blame] | 2287 | |
Courtney Goeltzenleuchter | 806c700 | 2015-10-27 11:22:14 -0600 | [diff] [blame] | 2288 | VkSubmitInfo submit_info; |
Chia-I Wu | f9be13c | 2015-10-26 20:37:06 +0800 | [diff] [blame] | 2289 | submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO; |
| 2290 | submit_info.pNext = NULL; |
Chia-I Wu | d50a7d7 | 2015-10-26 20:48:51 +0800 | [diff] [blame] | 2291 | submit_info.waitSemaphoreCount = 0; |
Courtney Goeltzenleuchter | 806c700 | 2015-10-27 11:22:14 -0600 | [diff] [blame] | 2292 | submit_info.pWaitSemaphores = NULL; |
Jon Ashburn | 7f9716c | 2015-12-30 16:42:50 -0700 | [diff] [blame] | 2293 | submit_info.pWaitDstStageMask = NULL; |
Chia-I Wu | d50a7d7 | 2015-10-26 20:48:51 +0800 | [diff] [blame] | 2294 | submit_info.commandBufferCount = 1; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 2295 | submit_info.pCommandBuffers = &m_commandBuffer->handle(); |
Chia-I Wu | d50a7d7 | 2015-10-26 20:48:51 +0800 | [diff] [blame] | 2296 | submit_info.signalSemaphoreCount = 0; |
Courtney Goeltzenleuchter | 806c700 | 2015-10-27 11:22:14 -0600 | [diff] [blame] | 2297 | submit_info.pSignalSemaphores = NULL; |
Courtney Goeltzenleuchter | 646b907 | 2015-10-20 18:04:07 -0600 | [diff] [blame] | 2298 | |
| 2299 | vkQueueSubmit(m_device->m_queue, 1, &submit_info, testFence.handle()); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 2300 | vkQueueWaitIdle(m_device->m_queue); |
Mark Lobodzinski | 5fcc421 | 2015-09-14 17:43:42 -0600 | [diff] [blame] | 2301 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 2302 | m_errorMonitor->VerifyFound(); |
Tony Barbour | 0b4d956 | 2015-04-09 10:48:04 -0600 | [diff] [blame] | 2303 | } |
Tobin Ehlis | aff7ae9 | 2016-04-18 15:45:20 -0600 | [diff] [blame] | 2304 | // This is a positive test. We used to expect error in this case but spec now |
| 2305 | // allows it |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 2306 | TEST_F(VkLayerTest, ResetUnsignaledFence) { |
Tobin Ehlis | aff7ae9 | 2016-04-18 15:45:20 -0600 | [diff] [blame] | 2307 | m_errorMonitor->ExpectSuccess(); |
Tony Barbour | 0b4d956 | 2015-04-09 10:48:04 -0600 | [diff] [blame] | 2308 | vk_testing::Fence testFence; |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 2309 | VkFenceCreateInfo fenceInfo = {}; |
Tony Barbour | 0b4d956 | 2015-04-09 10:48:04 -0600 | [diff] [blame] | 2310 | fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO; |
| 2311 | fenceInfo.pNext = NULL; |
| 2312 | |
Tony Barbour | 0b4d956 | 2015-04-09 10:48:04 -0600 | [diff] [blame] | 2313 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 2314 | testFence.init(*m_device, fenceInfo); |
Chia-I Wu | d9e8e82 | 2015-07-03 11:45:55 +0800 | [diff] [blame] | 2315 | VkFence fences[1] = {testFence.handle()}; |
Tobin Ehlis | aff7ae9 | 2016-04-18 15:45:20 -0600 | [diff] [blame] | 2316 | VkResult result = vkResetFences(m_device->device(), 1, fences); |
| 2317 | ASSERT_VK_SUCCESS(result); |
Tony Barbour | 300a608 | 2015-04-07 13:44:53 -0600 | [diff] [blame] | 2318 | |
Tobin Ehlis | aff7ae9 | 2016-04-18 15:45:20 -0600 | [diff] [blame] | 2319 | m_errorMonitor->VerifyNotFound(); |
Tony Barbour | 300a608 | 2015-04-07 13:44:53 -0600 | [diff] [blame] | 2320 | } |
Tobin Ehlis | 41376e1 | 2015-07-03 08:45:14 -0600 | [diff] [blame] | 2321 | |
Chris Forbes | e70b7d3 | 2016-06-15 15:49:12 +1200 | [diff] [blame] | 2322 | #if 0 |
| 2323 | TEST_F(VkLayerTest, LongFenceChain) |
| 2324 | { |
| 2325 | m_errorMonitor->ExpectSuccess(); |
| 2326 | |
| 2327 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 2328 | VkResult err; |
| 2329 | |
| 2330 | std::vector<VkFence> fences; |
| 2331 | |
| 2332 | const int chainLength = 32768; |
| 2333 | |
| 2334 | for (int i = 0; i < chainLength; i++) { |
| 2335 | VkFenceCreateInfo fci = { VK_STRUCTURE_TYPE_FENCE_CREATE_INFO, nullptr, 0 }; |
| 2336 | VkFence fence; |
| 2337 | err = vkCreateFence(m_device->device(), &fci, nullptr, &fence); |
| 2338 | ASSERT_VK_SUCCESS(err); |
| 2339 | |
| 2340 | fences.push_back(fence); |
| 2341 | |
| 2342 | VkSubmitInfo si = { VK_STRUCTURE_TYPE_SUBMIT_INFO, nullptr, 0, nullptr, nullptr, |
| 2343 | 0, nullptr, 0, nullptr }; |
| 2344 | err = vkQueueSubmit(m_device->m_queue, 1, &si, fence); |
| 2345 | ASSERT_VK_SUCCESS(err); |
| 2346 | |
| 2347 | } |
| 2348 | |
| 2349 | // BOOM, stack overflow. |
| 2350 | vkWaitForFences(m_device->device(), 1, &fences.back(), VK_TRUE, UINT64_MAX); |
| 2351 | |
| 2352 | for (auto fence : fences) |
| 2353 | vkDestroyFence(m_device->device(), fence, nullptr); |
| 2354 | |
| 2355 | m_errorMonitor->VerifyNotFound(); |
| 2356 | } |
| 2357 | #endif |
| 2358 | |
Chris Forbes | 18127d1 | 2016-06-08 16:52:28 +1200 | [diff] [blame] | 2359 | TEST_F(VkLayerTest, CommandBufferSimultaneousUseSync) |
| 2360 | { |
| 2361 | m_errorMonitor->ExpectSuccess(); |
| 2362 | |
| 2363 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 2364 | VkResult err; |
| 2365 | |
| 2366 | // Record (empty!) command buffer that can be submitted multiple times |
| 2367 | // simultaneously. |
| 2368 | VkCommandBufferBeginInfo cbbi = { |
| 2369 | VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO, nullptr, |
| 2370 | VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT, nullptr |
| 2371 | }; |
| 2372 | m_commandBuffer->BeginCommandBuffer(&cbbi); |
| 2373 | m_commandBuffer->EndCommandBuffer(); |
| 2374 | |
| 2375 | VkFenceCreateInfo fci = { VK_STRUCTURE_TYPE_FENCE_CREATE_INFO, nullptr, 0 }; |
| 2376 | VkFence fence; |
| 2377 | err = vkCreateFence(m_device->device(), &fci, nullptr, &fence); |
| 2378 | ASSERT_VK_SUCCESS(err); |
| 2379 | |
| 2380 | VkSemaphoreCreateInfo sci = { VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO, nullptr, 0 }; |
| 2381 | VkSemaphore s1, s2; |
| 2382 | err = vkCreateSemaphore(m_device->device(), &sci, nullptr, &s1); |
| 2383 | ASSERT_VK_SUCCESS(err); |
| 2384 | err = vkCreateSemaphore(m_device->device(), &sci, nullptr, &s2); |
| 2385 | ASSERT_VK_SUCCESS(err); |
| 2386 | |
| 2387 | // Submit CB once signaling s1, with fence so we can roll forward to its retirement. |
| 2388 | VkSubmitInfo si = { VK_STRUCTURE_TYPE_SUBMIT_INFO, nullptr, 0, nullptr, nullptr, |
| 2389 | 1, &m_commandBuffer->handle(), 1, &s1 }; |
| 2390 | err = vkQueueSubmit(m_device->m_queue, 1, &si, fence); |
| 2391 | ASSERT_VK_SUCCESS(err); |
| 2392 | |
| 2393 | // Submit CB again, signaling s2. |
| 2394 | si.pSignalSemaphores = &s2; |
| 2395 | err = vkQueueSubmit(m_device->m_queue, 1, &si, VK_NULL_HANDLE); |
| 2396 | ASSERT_VK_SUCCESS(err); |
| 2397 | |
| 2398 | // Wait for fence. |
| 2399 | err = vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX); |
| 2400 | ASSERT_VK_SUCCESS(err); |
| 2401 | |
| 2402 | // CB is still in flight from second submission, but semaphore s1 is no |
| 2403 | // longer in flight. delete it. |
| 2404 | vkDestroySemaphore(m_device->device(), s1, nullptr); |
| 2405 | |
| 2406 | m_errorMonitor->VerifyNotFound(); |
| 2407 | |
| 2408 | // Force device idle and clean up remaining objects |
| 2409 | vkDeviceWaitIdle(m_device->device()); |
| 2410 | vkDestroySemaphore(m_device->device(), s2, nullptr); |
| 2411 | vkDestroyFence(m_device->device(), fence, nullptr); |
| 2412 | } |
| 2413 | |
Chris Forbes | 4e44c91 | 2016-06-16 10:20:00 +1200 | [diff] [blame] | 2414 | TEST_F(VkLayerTest, FenceCreateSignaledWaitHandling) |
| 2415 | { |
| 2416 | m_errorMonitor->ExpectSuccess(); |
| 2417 | |
| 2418 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 2419 | VkResult err; |
| 2420 | |
| 2421 | // A fence created signaled |
| 2422 | VkFenceCreateInfo fci1 = { VK_STRUCTURE_TYPE_FENCE_CREATE_INFO, nullptr, VK_FENCE_CREATE_SIGNALED_BIT }; |
| 2423 | VkFence f1; |
| 2424 | err = vkCreateFence(m_device->device(), &fci1, nullptr, &f1); |
| 2425 | ASSERT_VK_SUCCESS(err); |
| 2426 | |
| 2427 | // A fence created not |
| 2428 | VkFenceCreateInfo fci2 = { VK_STRUCTURE_TYPE_FENCE_CREATE_INFO, nullptr, 0 }; |
| 2429 | VkFence f2; |
| 2430 | err = vkCreateFence(m_device->device(), &fci2, nullptr, &f2); |
| 2431 | ASSERT_VK_SUCCESS(err); |
| 2432 | |
| 2433 | // Submit the unsignaled fence |
| 2434 | VkSubmitInfo si = { VK_STRUCTURE_TYPE_SUBMIT_INFO, nullptr, 0, nullptr, nullptr, |
| 2435 | 0, nullptr, 0, nullptr }; |
| 2436 | err = vkQueueSubmit(m_device->m_queue, 1, &si, f2); |
| 2437 | |
| 2438 | // Wait on both fences, with signaled first. |
| 2439 | VkFence fences[] = { f1, f2 }; |
| 2440 | vkWaitForFences(m_device->device(), 2, fences, VK_TRUE, UINT64_MAX); |
| 2441 | |
| 2442 | // Should have both retired! |
| 2443 | vkDestroyFence(m_device->device(), f1, nullptr); |
| 2444 | vkDestroyFence(m_device->device(), f2, nullptr); |
| 2445 | |
| 2446 | m_errorMonitor->VerifyNotFound(); |
| 2447 | } |
| 2448 | |
Tobin Ehlis | 41376e1 | 2015-07-03 08:45:14 -0600 | [diff] [blame] | 2449 | TEST_F(VkLayerTest, InvalidUsageBits) |
| 2450 | { |
Tony Barbour | f92621a | 2016-05-02 14:28:12 -0600 | [diff] [blame] | 2451 | TEST_DESCRIPTION( |
Karl Schultz | b5bc11e | 2016-05-04 08:36:08 -0600 | [diff] [blame] | 2452 | "Specify wrong usage for image then create conflicting view of image " |
Tony Barbour | f92621a | 2016-05-02 14:28:12 -0600 | [diff] [blame] | 2453 | "Initialize buffer with wrong usage then perform copy expecting errors " |
| 2454 | "from both the image and the buffer (2 calls)"); |
Courtney Goeltzenleuchter | 7415d5a | 2015-12-09 15:48:16 -0700 | [diff] [blame] | 2455 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 2456 | "Invalid usage flag for image "); |
Tobin Ehlis | 41376e1 | 2015-07-03 08:45:14 -0600 | [diff] [blame] | 2457 | |
| 2458 | ASSERT_NO_FATAL_FAILURE(InitState()); |
Tony Barbour | f92621a | 2016-05-02 14:28:12 -0600 | [diff] [blame] | 2459 | VkImageObj image(m_device); |
| 2460 | // Initialize image with USAGE_INPUT_ATTACHMENT |
Tobin Ehlis | 8b313c0 | 2016-05-25 15:01:52 -0600 | [diff] [blame] | 2461 | image.init(128, 128, VK_FORMAT_D24_UNORM_S8_UINT, |
Karl Schultz | b5bc11e | 2016-05-04 08:36:08 -0600 | [diff] [blame] | 2462 | VK_IMAGE_USAGE_INPUT_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0); |
| 2463 | ASSERT_TRUE(image.initialized()); |
Tobin Ehlis | 41376e1 | 2015-07-03 08:45:14 -0600 | [diff] [blame] | 2464 | |
Tony Barbour | f92621a | 2016-05-02 14:28:12 -0600 | [diff] [blame] | 2465 | VkImageView dsv; |
| 2466 | VkImageViewCreateInfo dsvci = {}; |
| 2467 | dsvci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO; |
| 2468 | dsvci.image = image.handle(); |
| 2469 | dsvci.viewType = VK_IMAGE_VIEW_TYPE_2D; |
| 2470 | dsvci.format = VK_FORMAT_D32_SFLOAT_S8_UINT; |
| 2471 | dsvci.subresourceRange.layerCount = 1; |
| 2472 | dsvci.subresourceRange.baseMipLevel = 0; |
| 2473 | dsvci.subresourceRange.levelCount = 1; |
| 2474 | dsvci.subresourceRange.aspectMask = |
| 2475 | VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT; |
Tobin Ehlis | 41376e1 | 2015-07-03 08:45:14 -0600 | [diff] [blame] | 2476 | |
Tony Barbour | f92621a | 2016-05-02 14:28:12 -0600 | [diff] [blame] | 2477 | // Create a view with depth / stencil aspect for image with different usage |
| 2478 | vkCreateImageView(m_device->device(), &dsvci, NULL, &dsv); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 2479 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 2480 | m_errorMonitor->VerifyFound(); |
Tony Barbour | f92621a | 2016-05-02 14:28:12 -0600 | [diff] [blame] | 2481 | |
| 2482 | // Initialize buffer with TRANSFER_DST usage |
| 2483 | vk_testing::Buffer buffer; |
| 2484 | VkMemoryPropertyFlags reqs = 0; |
| 2485 | buffer.init_as_dst(*m_device, 128 * 128, reqs); |
| 2486 | VkBufferImageCopy region = {}; |
| 2487 | region.bufferRowLength = 128; |
| 2488 | region.bufferImageHeight = 128; |
| 2489 | region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; |
| 2490 | region.imageSubresource.layerCount = 1; |
| 2491 | region.imageExtent.height = 16; |
| 2492 | region.imageExtent.width = 16; |
| 2493 | region.imageExtent.depth = 1; |
| 2494 | |
| 2495 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 2496 | "Invalid usage flag for buffer "); |
| 2497 | // Buffer usage not set to TRANSFER_SRC and image usage not set to |
| 2498 | // TRANSFER_DST |
| 2499 | BeginCommandBuffer(); |
| 2500 | vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), |
| 2501 | image.handle(), VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, |
| 2502 | 1, ®ion); |
| 2503 | m_errorMonitor->VerifyFound(); |
| 2504 | |
| 2505 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 2506 | "Invalid usage flag for image "); |
| 2507 | vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), |
| 2508 | image.handle(), VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, |
| 2509 | 1, ®ion); |
| 2510 | m_errorMonitor->VerifyFound(); |
Tobin Ehlis | 41376e1 | 2015-07-03 08:45:14 -0600 | [diff] [blame] | 2511 | } |
Mark Lobodzinski | 209b529 | 2015-09-17 09:44:05 -0600 | [diff] [blame] | 2512 | #endif // MEM_TRACKER_TESTS |
| 2513 | |
Tobin Ehlis | 4bf96d1 | 2015-06-25 11:58:41 -0600 | [diff] [blame] | 2514 | #if OBJ_TRACKER_TESTS |
Mark Lobodzinski | fc5cc66 | 2016-05-02 17:17:41 -0600 | [diff] [blame] | 2515 | |
| 2516 | TEST_F(VkLayerTest, LeakAnObject) { |
| 2517 | VkResult err; |
| 2518 | |
| 2519 | TEST_DESCRIPTION( |
| 2520 | "Create a fence and destroy its device without first destroying the fence."); |
| 2521 | |
| 2522 | // Note that we have to create a new device since destroying the |
| 2523 | // framework's device causes Teardown() to fail and just calling Teardown |
| 2524 | // will destroy the errorMonitor. |
| 2525 | |
| 2526 | m_errorMonitor->SetDesiredFailureMsg( |
| 2527 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 2528 | "OBJ ERROR : VK_DEBUG_REPORT_OBJECT_TYPE_FENCE_EXT object"); |
| 2529 | |
| 2530 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 2531 | |
| 2532 | const std::vector<VkQueueFamilyProperties> queue_props = |
| 2533 | m_device->queue_props; |
| 2534 | std::vector<VkDeviceQueueCreateInfo> queue_info; |
| 2535 | queue_info.reserve(queue_props.size()); |
| 2536 | std::vector<std::vector<float>> queue_priorities; |
| 2537 | for (uint32_t i = 0; i < (uint32_t)queue_props.size(); i++) { |
| 2538 | VkDeviceQueueCreateInfo qi = {}; |
| 2539 | qi.sType = VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO; |
| 2540 | qi.pNext = NULL; |
| 2541 | qi.queueFamilyIndex = i; |
| 2542 | qi.queueCount = queue_props[i].queueCount; |
| 2543 | queue_priorities.emplace_back(qi.queueCount, 0.0f); |
| 2544 | qi.pQueuePriorities = queue_priorities[i].data(); |
| 2545 | queue_info.push_back(qi); |
| 2546 | } |
| 2547 | |
| 2548 | std::vector<const char *> device_layer_names; |
| 2549 | std::vector<const char *> device_extension_names; |
| 2550 | device_layer_names.push_back("VK_LAYER_GOOGLE_threading"); |
| 2551 | device_layer_names.push_back("VK_LAYER_LUNARG_parameter_validation"); |
| 2552 | device_layer_names.push_back("VK_LAYER_LUNARG_object_tracker"); |
| 2553 | device_layer_names.push_back("VK_LAYER_LUNARG_core_validation"); |
| 2554 | device_layer_names.push_back("VK_LAYER_LUNARG_device_limits"); |
| 2555 | device_layer_names.push_back("VK_LAYER_LUNARG_image"); |
| 2556 | device_layer_names.push_back("VK_LAYER_GOOGLE_unique_objects"); |
| 2557 | |
| 2558 | // The sacrificial device object |
| 2559 | VkDevice testDevice; |
| 2560 | VkDeviceCreateInfo device_create_info = {}; |
| 2561 | auto features = m_device->phy().features(); |
| 2562 | device_create_info.sType = VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO; |
| 2563 | device_create_info.pNext = NULL; |
| 2564 | device_create_info.queueCreateInfoCount = queue_info.size(); |
| 2565 | device_create_info.pQueueCreateInfos = queue_info.data(); |
| 2566 | device_create_info.enabledLayerCount = device_layer_names.size(); |
| 2567 | device_create_info.ppEnabledLayerNames = device_layer_names.data(); |
| 2568 | device_create_info.pEnabledFeatures = &features; |
| 2569 | err = vkCreateDevice(gpu(), &device_create_info, NULL, &testDevice); |
| 2570 | ASSERT_VK_SUCCESS(err); |
| 2571 | |
| 2572 | VkFence fence; |
| 2573 | VkFenceCreateInfo fence_create_info = {}; |
| 2574 | fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO; |
| 2575 | fence_create_info.pNext = NULL; |
| 2576 | fence_create_info.flags = 0; |
| 2577 | err = vkCreateFence(testDevice, &fence_create_info, NULL, &fence); |
| 2578 | ASSERT_VK_SUCCESS(err); |
| 2579 | |
| 2580 | // Induce failure by not calling vkDestroyFence |
| 2581 | vkDestroyDevice(testDevice, NULL); |
| 2582 | m_errorMonitor->VerifyFound(); |
| 2583 | } |
| 2584 | |
| 2585 | TEST_F(VkLayerTest, InvalidCommandPoolConsistency) { |
| 2586 | |
| 2587 | TEST_DESCRIPTION("Allocate command buffers from one command pool and " |
| 2588 | "attempt to delete them from another."); |
| 2589 | |
| 2590 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 2591 | "FreeCommandBuffers is attempting to free Command Buffer"); |
| 2592 | |
| 2593 | VkCommandPool command_pool_one; |
| 2594 | VkCommandPool command_pool_two; |
| 2595 | |
| 2596 | VkCommandPoolCreateInfo pool_create_info{}; |
| 2597 | pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO; |
| 2598 | pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_; |
| 2599 | pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT; |
| 2600 | |
| 2601 | vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, |
| 2602 | &command_pool_one); |
| 2603 | |
| 2604 | vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, |
| 2605 | &command_pool_two); |
| 2606 | |
| 2607 | VkCommandBuffer command_buffer[9]; |
| 2608 | VkCommandBufferAllocateInfo command_buffer_allocate_info{}; |
| 2609 | command_buffer_allocate_info.sType = |
| 2610 | VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO; |
| 2611 | command_buffer_allocate_info.commandPool = command_pool_one; |
| 2612 | command_buffer_allocate_info.commandBufferCount = 9; |
| 2613 | command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY; |
| 2614 | vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, |
| 2615 | command_buffer); |
| 2616 | |
| 2617 | vkFreeCommandBuffers(m_device->device(), command_pool_two, 4, |
| 2618 | &command_buffer[3]); |
| 2619 | |
| 2620 | m_errorMonitor->VerifyFound(); |
| 2621 | |
| 2622 | vkDestroyCommandPool(m_device->device(), command_pool_one, NULL); |
| 2623 | vkDestroyCommandPool(m_device->device(), command_pool_two, NULL); |
| 2624 | } |
| 2625 | |
| 2626 | TEST_F(VkLayerTest, InvalidDescriptorPoolConsistency) { |
| 2627 | VkResult err; |
| 2628 | |
| 2629 | TEST_DESCRIPTION("Allocate descriptor sets from one DS pool and " |
| 2630 | "attempt to delete them from another."); |
| 2631 | |
| 2632 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 2633 | "FreeDescriptorSets is attempting to free descriptorSet"); |
| 2634 | |
| 2635 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 2636 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 2637 | |
| 2638 | VkDescriptorPoolSize ds_type_count = {}; |
| 2639 | ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLER; |
| 2640 | ds_type_count.descriptorCount = 1; |
| 2641 | |
| 2642 | VkDescriptorPoolCreateInfo ds_pool_ci = {}; |
| 2643 | ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO; |
| 2644 | ds_pool_ci.pNext = NULL; |
| 2645 | ds_pool_ci.flags = 0; |
| 2646 | ds_pool_ci.maxSets = 1; |
| 2647 | ds_pool_ci.poolSizeCount = 1; |
| 2648 | ds_pool_ci.pPoolSizes = &ds_type_count; |
| 2649 | |
| 2650 | VkDescriptorPool ds_pool_one; |
| 2651 | err = |
| 2652 | vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool_one); |
| 2653 | ASSERT_VK_SUCCESS(err); |
| 2654 | |
| 2655 | // Create a second descriptor pool |
| 2656 | VkDescriptorPool ds_pool_two; |
| 2657 | err = |
| 2658 | vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool_two); |
| 2659 | ASSERT_VK_SUCCESS(err); |
| 2660 | |
| 2661 | VkDescriptorSetLayoutBinding dsl_binding = {}; |
| 2662 | dsl_binding.binding = 0; |
| 2663 | dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER; |
| 2664 | dsl_binding.descriptorCount = 1; |
| 2665 | dsl_binding.stageFlags = VK_SHADER_STAGE_ALL; |
| 2666 | dsl_binding.pImmutableSamplers = NULL; |
| 2667 | |
| 2668 | VkDescriptorSetLayoutCreateInfo ds_layout_ci = {}; |
| 2669 | ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO; |
| 2670 | ds_layout_ci.pNext = NULL; |
| 2671 | ds_layout_ci.bindingCount = 1; |
| 2672 | ds_layout_ci.pBindings = &dsl_binding; |
| 2673 | |
| 2674 | VkDescriptorSetLayout ds_layout; |
| 2675 | err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, |
| 2676 | &ds_layout); |
| 2677 | ASSERT_VK_SUCCESS(err); |
| 2678 | |
| 2679 | VkDescriptorSet descriptorSet; |
| 2680 | VkDescriptorSetAllocateInfo alloc_info = {}; |
| 2681 | alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO; |
| 2682 | alloc_info.descriptorSetCount = 1; |
| 2683 | alloc_info.descriptorPool = ds_pool_one; |
| 2684 | alloc_info.pSetLayouts = &ds_layout; |
| 2685 | err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, |
| 2686 | &descriptorSet); |
| 2687 | ASSERT_VK_SUCCESS(err); |
| 2688 | |
| 2689 | err = vkFreeDescriptorSets(m_device->device(), ds_pool_two, 1, &descriptorSet); |
| 2690 | |
| 2691 | m_errorMonitor->VerifyFound(); |
| 2692 | |
| 2693 | vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL); |
| 2694 | vkDestroyDescriptorPool(m_device->device(), ds_pool_one, NULL); |
| 2695 | vkDestroyDescriptorPool(m_device->device(), ds_pool_two, NULL); |
| 2696 | } |
| 2697 | |
| 2698 | TEST_F(VkLayerTest, CreateUnknownObject) { |
| 2699 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 2700 | "Invalid VkImage Object "); |
| 2701 | |
| 2702 | TEST_DESCRIPTION( |
| 2703 | "Pass an invalid image object handle into a Vulkan API call."); |
| 2704 | |
| 2705 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 2706 | |
| 2707 | // Pass bogus handle into GetImageMemoryRequirements |
| 2708 | VkMemoryRequirements mem_reqs; |
| 2709 | uint64_t fakeImageHandle = 0xCADECADE; |
| 2710 | VkImage fauxImage = reinterpret_cast<VkImage &>(fakeImageHandle); |
| 2711 | |
| 2712 | vkGetImageMemoryRequirements(m_device->device(), fauxImage, &mem_reqs); |
| 2713 | |
| 2714 | m_errorMonitor->VerifyFound(); |
| 2715 | } |
| 2716 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 2717 | TEST_F(VkLayerTest, PipelineNotBound) { |
| 2718 | VkResult err; |
Tobin Ehlis | c9ac2b6 | 2015-09-11 12:57:55 -0600 | [diff] [blame] | 2719 | |
Mark Lobodzinski | fc5cc66 | 2016-05-02 17:17:41 -0600 | [diff] [blame] | 2720 | TEST_DESCRIPTION( |
| 2721 | "Pass in an invalid pipeline object handle into a Vulkan API call."); |
| 2722 | |
Courtney Goeltzenleuchter | 7415d5a | 2015-12-09 15:48:16 -0700 | [diff] [blame] | 2723 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 2724 | "Invalid VkPipeline Object "); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 2725 | |
Tobin Ehlis | c9ac2b6 | 2015-09-11 12:57:55 -0600 | [diff] [blame] | 2726 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 2727 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
Tobin Ehlis | c9ac2b6 | 2015-09-11 12:57:55 -0600 | [diff] [blame] | 2728 | |
Chia-I Wu | 1b99bb2 | 2015-10-27 19:25:11 +0800 | [diff] [blame] | 2729 | VkDescriptorPoolSize ds_type_count = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 2730 | ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 2731 | ds_type_count.descriptorCount = 1; |
Tobin Ehlis | c9ac2b6 | 2015-09-11 12:57:55 -0600 | [diff] [blame] | 2732 | |
| 2733 | VkDescriptorPoolCreateInfo ds_pool_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 2734 | ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO; |
| 2735 | ds_pool_ci.pNext = NULL; |
| 2736 | ds_pool_ci.maxSets = 1; |
| 2737 | ds_pool_ci.poolSizeCount = 1; |
| 2738 | ds_pool_ci.pPoolSizes = &ds_type_count; |
Tobin Ehlis | c9ac2b6 | 2015-09-11 12:57:55 -0600 | [diff] [blame] | 2739 | |
| 2740 | VkDescriptorPool ds_pool; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 2741 | err = |
| 2742 | vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool); |
Tobin Ehlis | c9ac2b6 | 2015-09-11 12:57:55 -0600 | [diff] [blame] | 2743 | ASSERT_VK_SUCCESS(err); |
| 2744 | |
| 2745 | VkDescriptorSetLayoutBinding dsl_binding = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 2746 | dsl_binding.binding = 0; |
| 2747 | dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 2748 | dsl_binding.descriptorCount = 1; |
| 2749 | dsl_binding.stageFlags = VK_SHADER_STAGE_ALL; |
| 2750 | dsl_binding.pImmutableSamplers = NULL; |
Tobin Ehlis | c9ac2b6 | 2015-09-11 12:57:55 -0600 | [diff] [blame] | 2751 | |
| 2752 | VkDescriptorSetLayoutCreateInfo ds_layout_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 2753 | ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO; |
| 2754 | ds_layout_ci.pNext = NULL; |
| 2755 | ds_layout_ci.bindingCount = 1; |
| 2756 | ds_layout_ci.pBindings = &dsl_binding; |
Tobin Ehlis | c9ac2b6 | 2015-09-11 12:57:55 -0600 | [diff] [blame] | 2757 | |
| 2758 | VkDescriptorSetLayout ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 2759 | err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, |
| 2760 | &ds_layout); |
Tobin Ehlis | c9ac2b6 | 2015-09-11 12:57:55 -0600 | [diff] [blame] | 2761 | ASSERT_VK_SUCCESS(err); |
| 2762 | |
| 2763 | VkDescriptorSet descriptorSet; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 2764 | VkDescriptorSetAllocateInfo alloc_info = {}; |
Chia-I Wu | 00ce540 | 2015-11-10 16:21:09 +0800 | [diff] [blame] | 2765 | alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO; |
Jon Ashburn | f19916e | 2016-01-11 13:12:43 -0700 | [diff] [blame] | 2766 | alloc_info.descriptorSetCount = 1; |
Courtney Goeltzenleuchter | bee18a9 | 2015-10-23 14:21:05 -0600 | [diff] [blame] | 2767 | alloc_info.descriptorPool = ds_pool; |
| 2768 | alloc_info.pSetLayouts = &ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 2769 | err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, |
| 2770 | &descriptorSet); |
Tobin Ehlis | c9ac2b6 | 2015-09-11 12:57:55 -0600 | [diff] [blame] | 2771 | ASSERT_VK_SUCCESS(err); |
| 2772 | |
| 2773 | VkPipelineLayoutCreateInfo pipeline_layout_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 2774 | pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO; |
| 2775 | pipeline_layout_ci.pNext = NULL; |
| 2776 | pipeline_layout_ci.setLayoutCount = 1; |
| 2777 | pipeline_layout_ci.pSetLayouts = &ds_layout; |
Tobin Ehlis | c9ac2b6 | 2015-09-11 12:57:55 -0600 | [diff] [blame] | 2778 | |
| 2779 | VkPipelineLayout pipeline_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 2780 | err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, |
| 2781 | &pipeline_layout); |
Tobin Ehlis | c9ac2b6 | 2015-09-11 12:57:55 -0600 | [diff] [blame] | 2782 | ASSERT_VK_SUCCESS(err); |
| 2783 | |
Mark Young | ad77905 | 2016-01-06 14:26:04 -0700 | [diff] [blame] | 2784 | VkPipeline badPipeline = (VkPipeline)((size_t)0xbaadb1be); |
Tobin Ehlis | c9ac2b6 | 2015-09-11 12:57:55 -0600 | [diff] [blame] | 2785 | |
| 2786 | BeginCommandBuffer(); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 2787 | vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), |
| 2788 | VK_PIPELINE_BIND_POINT_GRAPHICS, badPipeline); |
Tobin Ehlis | c9ac2b6 | 2015-09-11 12:57:55 -0600 | [diff] [blame] | 2789 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 2790 | m_errorMonitor->VerifyFound(); |
Mike Stroyan | d1c84a5 | 2015-08-18 14:40:24 -0600 | [diff] [blame] | 2791 | |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 2792 | vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL); |
| 2793 | vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL); |
| 2794 | vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL); |
Tobin Ehlis | ec59830 | 2015-09-15 15:02:17 -0600 | [diff] [blame] | 2795 | } |
Mike Stroyan | 80fc6c3 | 2016-06-20 15:42:29 -0600 | [diff] [blame] | 2796 | |
Mark Lobodzinski | bc18576 | 2016-06-15 16:28:53 -0600 | [diff] [blame] | 2797 | TEST_F(VkLayerTest, BindImageInvalidMemoryType) { |
| 2798 | VkResult err; |
| 2799 | |
| 2800 | TEST_DESCRIPTION("Test validation check for an invalid memory type index " |
| 2801 | "during bind[Buffer|Image]Memory time"); |
| 2802 | |
Mark Lobodzinski | bc18576 | 2016-06-15 16:28:53 -0600 | [diff] [blame] | 2803 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 2804 | |
| 2805 | // Create an image, allocate memory, set a bad typeIndex and then try to |
| 2806 | // bind it |
| 2807 | VkImage image; |
| 2808 | VkDeviceMemory mem; |
| 2809 | VkMemoryRequirements mem_reqs; |
| 2810 | const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM; |
| 2811 | const int32_t tex_width = 32; |
| 2812 | const int32_t tex_height = 32; |
| 2813 | |
| 2814 | VkImageCreateInfo image_create_info = {}; |
| 2815 | image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO; |
| 2816 | image_create_info.pNext = NULL; |
| 2817 | image_create_info.imageType = VK_IMAGE_TYPE_2D; |
| 2818 | image_create_info.format = tex_format; |
| 2819 | image_create_info.extent.width = tex_width; |
| 2820 | image_create_info.extent.height = tex_height; |
| 2821 | image_create_info.extent.depth = 1; |
| 2822 | image_create_info.mipLevels = 1; |
| 2823 | image_create_info.arrayLayers = 1; |
| 2824 | image_create_info.samples = VK_SAMPLE_COUNT_1_BIT; |
| 2825 | image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL; |
| 2826 | image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT; |
| 2827 | image_create_info.flags = 0; |
| 2828 | |
| 2829 | VkMemoryAllocateInfo mem_alloc = {}; |
| 2830 | mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO; |
| 2831 | mem_alloc.pNext = NULL; |
| 2832 | mem_alloc.allocationSize = 0; |
| 2833 | mem_alloc.memoryTypeIndex = 0; |
| 2834 | |
| 2835 | err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image); |
| 2836 | ASSERT_VK_SUCCESS(err); |
| 2837 | |
| 2838 | vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs); |
| 2839 | mem_alloc.allocationSize = mem_reqs.size; |
Mike Stroyan | 80fc6c3 | 2016-06-20 15:42:29 -0600 | [diff] [blame] | 2840 | |
| 2841 | // Introduce Failure, select invalid TypeIndex |
| 2842 | VkPhysicalDeviceMemoryProperties memory_info; |
| 2843 | |
| 2844 | vkGetPhysicalDeviceMemoryProperties(gpu(), &memory_info); |
| 2845 | unsigned int i; |
| 2846 | for (i = 0; i < memory_info.memoryTypeCount; i++) { |
| 2847 | if ((mem_reqs.memoryTypeBits & (1 << i)) == 0) { |
| 2848 | mem_alloc.memoryTypeIndex = i; |
| 2849 | break; |
| 2850 | } |
| 2851 | } |
| 2852 | if (i >= memory_info.memoryTypeCount) { |
| 2853 | printf("No invalid memory type index could be found; skipped.\n"); |
| 2854 | vkDestroyImage(m_device->device(), image, NULL); |
| 2855 | return; |
| 2856 | } |
| 2857 | |
| 2858 | m_errorMonitor->SetDesiredFailureMsg( |
| 2859 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 2860 | "for this object type are not compatible with the memory"); |
Mark Lobodzinski | bc18576 | 2016-06-15 16:28:53 -0600 | [diff] [blame] | 2861 | |
| 2862 | err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem); |
| 2863 | ASSERT_VK_SUCCESS(err); |
| 2864 | |
| 2865 | err = vkBindImageMemory(m_device->device(), image, mem, 0); |
| 2866 | (void)err; |
| 2867 | |
| 2868 | m_errorMonitor->VerifyFound(); |
| 2869 | |
| 2870 | vkDestroyImage(m_device->device(), image, NULL); |
| 2871 | vkFreeMemory(m_device->device(), mem, NULL); |
| 2872 | } |
Mike Stroyan | 80fc6c3 | 2016-06-20 15:42:29 -0600 | [diff] [blame] | 2873 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 2874 | TEST_F(VkLayerTest, BindInvalidMemory) { |
| 2875 | VkResult err; |
| 2876 | bool pass; |
Tobin Ehlis | ec59830 | 2015-09-15 15:02:17 -0600 | [diff] [blame] | 2877 | |
Courtney Goeltzenleuchter | 7415d5a | 2015-12-09 15:48:16 -0700 | [diff] [blame] | 2878 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 2879 | "Invalid VkDeviceMemory Object "); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 2880 | |
Tobin Ehlis | ec59830 | 2015-09-15 15:02:17 -0600 | [diff] [blame] | 2881 | ASSERT_NO_FATAL_FAILURE(InitState()); |
Tobin Ehlis | ec59830 | 2015-09-15 15:02:17 -0600 | [diff] [blame] | 2882 | |
| 2883 | // 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] | 2884 | VkImage image; |
| 2885 | VkDeviceMemory mem; |
| 2886 | VkMemoryRequirements mem_reqs; |
Tobin Ehlis | ec59830 | 2015-09-15 15:02:17 -0600 | [diff] [blame] | 2887 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 2888 | const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM; |
| 2889 | const int32_t tex_width = 32; |
| 2890 | const int32_t tex_height = 32; |
Tobin Ehlis | ec59830 | 2015-09-15 15:02:17 -0600 | [diff] [blame] | 2891 | |
| 2892 | VkImageCreateInfo image_create_info = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 2893 | image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO; |
| 2894 | image_create_info.pNext = NULL; |
| 2895 | image_create_info.imageType = VK_IMAGE_TYPE_2D; |
| 2896 | image_create_info.format = tex_format; |
| 2897 | image_create_info.extent.width = tex_width; |
| 2898 | image_create_info.extent.height = tex_height; |
| 2899 | image_create_info.extent.depth = 1; |
| 2900 | image_create_info.mipLevels = 1; |
| 2901 | image_create_info.arrayLayers = 1; |
| 2902 | image_create_info.samples = VK_SAMPLE_COUNT_1_BIT; |
| 2903 | image_create_info.tiling = VK_IMAGE_TILING_LINEAR; |
| 2904 | image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT; |
| 2905 | image_create_info.flags = 0; |
Tobin Ehlis | ec59830 | 2015-09-15 15:02:17 -0600 | [diff] [blame] | 2906 | |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 2907 | VkMemoryAllocateInfo mem_alloc = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 2908 | mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO; |
| 2909 | mem_alloc.pNext = NULL; |
| 2910 | mem_alloc.allocationSize = 0; |
| 2911 | mem_alloc.memoryTypeIndex = 0; |
Tobin Ehlis | ec59830 | 2015-09-15 15:02:17 -0600 | [diff] [blame] | 2912 | |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 2913 | err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image); |
Tobin Ehlis | ec59830 | 2015-09-15 15:02:17 -0600 | [diff] [blame] | 2914 | ASSERT_VK_SUCCESS(err); |
| 2915 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 2916 | vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs); |
Tobin Ehlis | ec59830 | 2015-09-15 15:02:17 -0600 | [diff] [blame] | 2917 | |
| 2918 | mem_alloc.allocationSize = mem_reqs.size; |
| 2919 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 2920 | pass = |
| 2921 | m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0); |
Courtney Goeltzenleuchter | 1d2f0dd | 2015-10-22 11:03:31 -0600 | [diff] [blame] | 2922 | ASSERT_TRUE(pass); |
Tobin Ehlis | ec59830 | 2015-09-15 15:02:17 -0600 | [diff] [blame] | 2923 | |
| 2924 | // allocate memory |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 2925 | err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem); |
Tobin Ehlis | ec59830 | 2015-09-15 15:02:17 -0600 | [diff] [blame] | 2926 | ASSERT_VK_SUCCESS(err); |
| 2927 | |
| 2928 | // Introduce validation failure, free memory before binding |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 2929 | vkFreeMemory(m_device->device(), mem, NULL); |
Tobin Ehlis | ec59830 | 2015-09-15 15:02:17 -0600 | [diff] [blame] | 2930 | |
| 2931 | // Try to bind free memory that has been freed |
| 2932 | err = vkBindImageMemory(m_device->device(), image, mem, 0); |
| 2933 | // This may very well return an error. |
| 2934 | (void)err; |
| 2935 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 2936 | m_errorMonitor->VerifyFound(); |
Mike Stroyan | d1c84a5 | 2015-08-18 14:40:24 -0600 | [diff] [blame] | 2937 | |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 2938 | vkDestroyImage(m_device->device(), image, NULL); |
Tobin Ehlis | ec59830 | 2015-09-15 15:02:17 -0600 | [diff] [blame] | 2939 | } |
| 2940 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 2941 | TEST_F(VkLayerTest, BindMemoryToDestroyedObject) { |
| 2942 | VkResult err; |
| 2943 | bool pass; |
Tobin Ehlis | ec59830 | 2015-09-15 15:02:17 -0600 | [diff] [blame] | 2944 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 2945 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 2946 | "Invalid VkImage Object "); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 2947 | |
Tobin Ehlis | ec59830 | 2015-09-15 15:02:17 -0600 | [diff] [blame] | 2948 | ASSERT_NO_FATAL_FAILURE(InitState()); |
Tobin Ehlis | ec59830 | 2015-09-15 15:02:17 -0600 | [diff] [blame] | 2949 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 2950 | // Create an image object, allocate memory, destroy the object and then try |
| 2951 | // to bind it |
| 2952 | VkImage image; |
| 2953 | VkDeviceMemory mem; |
| 2954 | VkMemoryRequirements mem_reqs; |
Tobin Ehlis | ec59830 | 2015-09-15 15:02:17 -0600 | [diff] [blame] | 2955 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 2956 | const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM; |
| 2957 | const int32_t tex_width = 32; |
| 2958 | const int32_t tex_height = 32; |
Tobin Ehlis | ec59830 | 2015-09-15 15:02:17 -0600 | [diff] [blame] | 2959 | |
| 2960 | VkImageCreateInfo image_create_info = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 2961 | image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO; |
| 2962 | image_create_info.pNext = NULL; |
| 2963 | image_create_info.imageType = VK_IMAGE_TYPE_2D; |
| 2964 | image_create_info.format = tex_format; |
| 2965 | image_create_info.extent.width = tex_width; |
| 2966 | image_create_info.extent.height = tex_height; |
| 2967 | image_create_info.extent.depth = 1; |
| 2968 | image_create_info.mipLevels = 1; |
| 2969 | image_create_info.arrayLayers = 1; |
| 2970 | image_create_info.samples = VK_SAMPLE_COUNT_1_BIT; |
| 2971 | image_create_info.tiling = VK_IMAGE_TILING_LINEAR; |
| 2972 | image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT; |
| 2973 | image_create_info.flags = 0; |
Tobin Ehlis | ec59830 | 2015-09-15 15:02:17 -0600 | [diff] [blame] | 2974 | |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 2975 | VkMemoryAllocateInfo mem_alloc = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 2976 | mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO; |
| 2977 | mem_alloc.pNext = NULL; |
| 2978 | mem_alloc.allocationSize = 0; |
| 2979 | mem_alloc.memoryTypeIndex = 0; |
Tobin Ehlis | ec59830 | 2015-09-15 15:02:17 -0600 | [diff] [blame] | 2980 | |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 2981 | err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image); |
Tobin Ehlis | ec59830 | 2015-09-15 15:02:17 -0600 | [diff] [blame] | 2982 | ASSERT_VK_SUCCESS(err); |
| 2983 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 2984 | vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs); |
Tobin Ehlis | ec59830 | 2015-09-15 15:02:17 -0600 | [diff] [blame] | 2985 | |
| 2986 | mem_alloc.allocationSize = mem_reqs.size; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 2987 | pass = |
| 2988 | m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0); |
Courtney Goeltzenleuchter | 1d2f0dd | 2015-10-22 11:03:31 -0600 | [diff] [blame] | 2989 | ASSERT_TRUE(pass); |
Tobin Ehlis | ec59830 | 2015-09-15 15:02:17 -0600 | [diff] [blame] | 2990 | |
| 2991 | // Allocate memory |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 2992 | err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem); |
Tobin Ehlis | ec59830 | 2015-09-15 15:02:17 -0600 | [diff] [blame] | 2993 | ASSERT_VK_SUCCESS(err); |
| 2994 | |
| 2995 | // Introduce validation failure, destroy Image object before binding |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 2996 | vkDestroyImage(m_device->device(), image, NULL); |
Tobin Ehlis | ec59830 | 2015-09-15 15:02:17 -0600 | [diff] [blame] | 2997 | ASSERT_VK_SUCCESS(err); |
| 2998 | |
| 2999 | // Now Try to bind memory to this destroyed object |
| 3000 | err = vkBindImageMemory(m_device->device(), image, mem, 0); |
| 3001 | // This may very well return an error. |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 3002 | (void)err; |
Tobin Ehlis | ec59830 | 2015-09-15 15:02:17 -0600 | [diff] [blame] | 3003 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 3004 | m_errorMonitor->VerifyFound(); |
Mike Stroyan | d1c84a5 | 2015-08-18 14:40:24 -0600 | [diff] [blame] | 3005 | |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 3006 | vkFreeMemory(m_device->device(), mem, NULL); |
Tobin Ehlis | c9ac2b6 | 2015-09-11 12:57:55 -0600 | [diff] [blame] | 3007 | } |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 3008 | |
Mark Lobodzinski | 209b529 | 2015-09-17 09:44:05 -0600 | [diff] [blame] | 3009 | #endif // OBJ_TRACKER_TESTS |
| 3010 | |
Tobin Ehlis | 0788f52 | 2015-05-26 16:11:58 -0600 | [diff] [blame] | 3011 | #if DRAW_STATE_TESTS |
Mark Lobodzinski | c808d44 | 2016-04-14 10:57:23 -0600 | [diff] [blame] | 3012 | |
Chris Forbes | 48a5390 | 2016-06-30 11:46:27 +1200 | [diff] [blame] | 3013 | TEST_F(VkLayerTest, RenderPassInitialLayoutUndefined) { |
| 3014 | TEST_DESCRIPTION("Ensure that CmdBeginRenderPass with an attachment's " |
| 3015 | "initialLayout of VK_IMAGE_LAYOUT_UNDEFINED works when " |
| 3016 | "the command buffer has prior knowledge of that " |
| 3017 | "attachment's layout."); |
| 3018 | |
| 3019 | m_errorMonitor->ExpectSuccess(); |
| 3020 | |
| 3021 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 3022 | |
| 3023 | // A renderpass with one color attachment. |
| 3024 | VkAttachmentDescription attachment = { |
| 3025 | 0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_1_BIT, |
| 3026 | VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_STORE, |
| 3027 | VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, |
| 3028 | VK_IMAGE_LAYOUT_UNDEFINED, |
| 3029 | VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL |
| 3030 | }; |
| 3031 | |
| 3032 | VkAttachmentReference att_ref = { |
| 3033 | 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL |
| 3034 | }; |
| 3035 | |
| 3036 | VkSubpassDescription subpass = { |
| 3037 | 0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, |
| 3038 | 1, &att_ref, nullptr, nullptr, 0, nullptr |
| 3039 | }; |
| 3040 | |
| 3041 | VkRenderPassCreateInfo rpci = { |
| 3042 | VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, |
| 3043 | 0, 1, &attachment, 1, &subpass, 0, nullptr |
| 3044 | }; |
| 3045 | |
| 3046 | VkRenderPass rp; |
| 3047 | VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp); |
| 3048 | ASSERT_VK_SUCCESS(err); |
| 3049 | |
| 3050 | // A compatible framebuffer. |
| 3051 | VkImageObj image(m_device); |
| 3052 | image.init(32, 32, VK_FORMAT_R8G8B8A8_UNORM, |
| 3053 | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, |
| 3054 | VK_IMAGE_TILING_OPTIMAL, 0); |
| 3055 | ASSERT_TRUE(image.initialized()); |
| 3056 | |
| 3057 | VkImageViewCreateInfo ivci = { |
| 3058 | VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO, nullptr, |
| 3059 | 0, image.handle(), VK_IMAGE_VIEW_TYPE_2D, VK_FORMAT_R8G8B8A8_UNORM, |
| 3060 | { |
| 3061 | VK_COMPONENT_SWIZZLE_IDENTITY, |
| 3062 | VK_COMPONENT_SWIZZLE_IDENTITY, |
| 3063 | VK_COMPONENT_SWIZZLE_IDENTITY, |
| 3064 | VK_COMPONENT_SWIZZLE_IDENTITY |
| 3065 | }, |
| 3066 | { |
| 3067 | VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1 |
| 3068 | }, |
| 3069 | }; |
| 3070 | VkImageView view; |
| 3071 | err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view); |
| 3072 | ASSERT_VK_SUCCESS(err); |
| 3073 | |
| 3074 | VkFramebufferCreateInfo fci = { |
| 3075 | VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, |
| 3076 | 0, rp, 1, &view, |
| 3077 | 32, 32, 1 |
| 3078 | }; |
| 3079 | VkFramebuffer fb; |
| 3080 | err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb); |
| 3081 | ASSERT_VK_SUCCESS(err); |
| 3082 | |
| 3083 | // Record a single command buffer which uses this renderpass twice. The |
| 3084 | // bug is triggered at the beginning of the second renderpass, when the |
| 3085 | // command buffer already has a layout recorded for the attachment. |
| 3086 | VkRenderPassBeginInfo rpbi = { |
| 3087 | VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO, nullptr, |
Tobin Ehlis | 0f9aa40 | 2016-07-01 08:47:12 -0600 | [diff] [blame] | 3088 | rp, fb, { { 0, 0 } , { 32, 32 } }, |
Chris Forbes | 48a5390 | 2016-06-30 11:46:27 +1200 | [diff] [blame] | 3089 | 0, nullptr |
| 3090 | }; |
| 3091 | BeginCommandBuffer(); |
| 3092 | vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, |
| 3093 | VK_SUBPASS_CONTENTS_INLINE); |
| 3094 | vkCmdEndRenderPass(m_commandBuffer->handle()); |
| 3095 | vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, |
| 3096 | VK_SUBPASS_CONTENTS_INLINE); |
| 3097 | |
| 3098 | m_errorMonitor->VerifyNotFound(); |
| 3099 | |
| 3100 | vkCmdEndRenderPass(m_commandBuffer->handle()); |
| 3101 | EndCommandBuffer(); |
| 3102 | |
| 3103 | vkDestroyFramebuffer(m_device->device(), fb, nullptr); |
| 3104 | vkDestroyRenderPass(m_device->device(), rp, nullptr); |
| 3105 | vkDestroyImageView(m_device->device(), view, nullptr); |
| 3106 | } |
| 3107 | |
Chris Forbes | 51bf7c9 | 2016-06-30 15:22:08 +1200 | [diff] [blame] | 3108 | TEST_F(VkLayerTest, RenderPassSubpassZeroTransitionsApplied) { |
| 3109 | TEST_DESCRIPTION("Ensure that CmdBeginRenderPass applies the layout " |
| 3110 | "transitions for the first subpass"); |
| 3111 | |
| 3112 | m_errorMonitor->ExpectSuccess(); |
| 3113 | |
| 3114 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 3115 | |
| 3116 | // A renderpass with one color attachment. |
| 3117 | VkAttachmentDescription attachment = { |
| 3118 | 0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_1_BIT, |
| 3119 | VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_STORE, |
| 3120 | VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, |
| 3121 | VK_IMAGE_LAYOUT_UNDEFINED, |
| 3122 | VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL |
| 3123 | }; |
| 3124 | |
| 3125 | VkAttachmentReference att_ref = { |
| 3126 | 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL |
| 3127 | }; |
| 3128 | |
| 3129 | VkSubpassDescription subpass = { |
| 3130 | 0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, |
| 3131 | 1, &att_ref, nullptr, nullptr, 0, nullptr |
| 3132 | }; |
| 3133 | |
| 3134 | VkSubpassDependency dep = { |
Chris Forbes | cb4c7ad | 2016-07-06 10:28:18 +1200 | [diff] [blame] | 3135 | 0, 0, VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT, |
| 3136 | VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT, |
Chris Forbes | 51bf7c9 | 2016-06-30 15:22:08 +1200 | [diff] [blame] | 3137 | VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT, |
| 3138 | VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT, |
| 3139 | VK_DEPENDENCY_BY_REGION_BIT |
| 3140 | }; |
| 3141 | |
| 3142 | VkRenderPassCreateInfo rpci = { |
| 3143 | VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, |
| 3144 | 0, 1, &attachment, 1, &subpass, 1, &dep |
| 3145 | }; |
| 3146 | |
| 3147 | VkResult err; |
| 3148 | VkRenderPass rp; |
| 3149 | err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp); |
| 3150 | ASSERT_VK_SUCCESS(err); |
| 3151 | |
| 3152 | // A compatible framebuffer. |
| 3153 | VkImageObj image(m_device); |
| 3154 | image.init(32, 32, VK_FORMAT_R8G8B8A8_UNORM, |
| 3155 | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, |
| 3156 | VK_IMAGE_TILING_OPTIMAL, 0); |
| 3157 | ASSERT_TRUE(image.initialized()); |
| 3158 | |
| 3159 | VkImageViewCreateInfo ivci = { |
| 3160 | VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO, nullptr, |
| 3161 | 0, image.handle(), VK_IMAGE_VIEW_TYPE_2D, VK_FORMAT_R8G8B8A8_UNORM, |
| 3162 | { |
| 3163 | VK_COMPONENT_SWIZZLE_IDENTITY, |
| 3164 | VK_COMPONENT_SWIZZLE_IDENTITY, |
| 3165 | VK_COMPONENT_SWIZZLE_IDENTITY, |
| 3166 | VK_COMPONENT_SWIZZLE_IDENTITY |
| 3167 | }, |
| 3168 | { |
| 3169 | VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1 |
| 3170 | }, |
| 3171 | }; |
| 3172 | VkImageView view; |
| 3173 | err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view); |
| 3174 | ASSERT_VK_SUCCESS(err); |
| 3175 | |
| 3176 | VkFramebufferCreateInfo fci = { |
| 3177 | VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, |
| 3178 | 0, rp, 1, &view, |
| 3179 | 32, 32, 1 |
| 3180 | }; |
| 3181 | VkFramebuffer fb; |
| 3182 | err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb); |
| 3183 | ASSERT_VK_SUCCESS(err); |
| 3184 | |
| 3185 | // Record a single command buffer which issues a pipeline barrier w/ |
| 3186 | // image memory barrier for the attachment. This detects the previously |
| 3187 | // missing tracking of the subpass layout by throwing a validation error |
| 3188 | // if it doesn't occur. |
| 3189 | VkRenderPassBeginInfo rpbi = { |
| 3190 | VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO, nullptr, |
Tobin Ehlis | 0f9aa40 | 2016-07-01 08:47:12 -0600 | [diff] [blame] | 3191 | rp, fb, { { 0, 0 }, { 32, 32 } }, |
Chris Forbes | 51bf7c9 | 2016-06-30 15:22:08 +1200 | [diff] [blame] | 3192 | 0, nullptr |
| 3193 | }; |
| 3194 | BeginCommandBuffer(); |
| 3195 | vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, |
| 3196 | VK_SUBPASS_CONTENTS_INLINE); |
| 3197 | |
| 3198 | VkImageMemoryBarrier imb = { |
| 3199 | VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER, nullptr, |
| 3200 | VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT, |
| 3201 | VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT, |
| 3202 | VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, |
| 3203 | VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, |
| 3204 | VK_QUEUE_FAMILY_IGNORED, VK_QUEUE_FAMILY_IGNORED, |
| 3205 | image.handle(), |
| 3206 | { VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1 } |
| 3207 | }; |
| 3208 | vkCmdPipelineBarrier(m_commandBuffer->handle(), |
Chris Forbes | cb4c7ad | 2016-07-06 10:28:18 +1200 | [diff] [blame] | 3209 | VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT, |
| 3210 | VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT, |
Chris Forbes | 51bf7c9 | 2016-06-30 15:22:08 +1200 | [diff] [blame] | 3211 | VK_DEPENDENCY_BY_REGION_BIT, |
| 3212 | 0, nullptr, 0, nullptr, 1, &imb); |
| 3213 | |
| 3214 | vkCmdEndRenderPass(m_commandBuffer->handle()); |
| 3215 | m_errorMonitor->VerifyNotFound(); |
| 3216 | EndCommandBuffer(); |
| 3217 | |
| 3218 | vkDestroyFramebuffer(m_device->device(), fb, nullptr); |
| 3219 | vkDestroyRenderPass(m_device->device(), rp, nullptr); |
| 3220 | vkDestroyImageView(m_device->device(), view, nullptr); |
| 3221 | } |
| 3222 | |
Chris Forbes | 6b3d3f4 | 2016-06-30 16:09:47 +1200 | [diff] [blame] | 3223 | TEST_F(VkLayerTest, RenderPassTransitionsAttachmentUnused) { |
| 3224 | TEST_DESCRIPTION("Ensure that layout transitions work correctly without " |
| 3225 | "errors, when an attachment reference is " |
| 3226 | "VK_ATTACHMENT_UNUSED"); |
| 3227 | |
| 3228 | m_errorMonitor->ExpectSuccess(); |
| 3229 | |
| 3230 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 3231 | |
| 3232 | // A renderpass with no attachments |
| 3233 | VkAttachmentReference att_ref = { |
| 3234 | VK_ATTACHMENT_UNUSED, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL |
| 3235 | }; |
| 3236 | |
| 3237 | VkSubpassDescription subpass = { |
| 3238 | 0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, |
| 3239 | 1, &att_ref, nullptr, nullptr, 0, nullptr |
| 3240 | }; |
| 3241 | |
| 3242 | VkRenderPassCreateInfo rpci = { |
| 3243 | VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, |
| 3244 | 0, 0, nullptr, 1, &subpass, 0, nullptr |
| 3245 | }; |
| 3246 | |
| 3247 | VkRenderPass rp; |
| 3248 | VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp); |
| 3249 | ASSERT_VK_SUCCESS(err); |
| 3250 | |
| 3251 | // A compatible framebuffer. |
| 3252 | VkFramebufferCreateInfo fci = { |
| 3253 | VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, |
| 3254 | 0, rp, 0, nullptr, |
| 3255 | 32, 32, 1 |
| 3256 | }; |
| 3257 | VkFramebuffer fb; |
| 3258 | err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb); |
| 3259 | ASSERT_VK_SUCCESS(err); |
| 3260 | |
| 3261 | // Record a command buffer which just begins and ends the renderpass. The |
| 3262 | // bug manifests in BeginRenderPass. |
| 3263 | VkRenderPassBeginInfo rpbi = { |
| 3264 | VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO, nullptr, |
Tobin Ehlis | 0f9aa40 | 2016-07-01 08:47:12 -0600 | [diff] [blame] | 3265 | rp, fb, { { 0, 0 }, { 32, 32 } }, |
Chris Forbes | 6b3d3f4 | 2016-06-30 16:09:47 +1200 | [diff] [blame] | 3266 | 0, nullptr |
| 3267 | }; |
| 3268 | BeginCommandBuffer(); |
| 3269 | vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, |
| 3270 | VK_SUBPASS_CONTENTS_INLINE); |
| 3271 | vkCmdEndRenderPass(m_commandBuffer->handle()); |
| 3272 | m_errorMonitor->VerifyNotFound(); |
| 3273 | EndCommandBuffer(); |
| 3274 | |
| 3275 | vkDestroyFramebuffer(m_device->device(), fb, nullptr); |
| 3276 | vkDestroyRenderPass(m_device->device(), rp, nullptr); |
| 3277 | } |
| 3278 | |
Mark Lobodzinski | ce7eee7 | 2016-06-14 16:33:29 -0600 | [diff] [blame] | 3279 | // This is a positive test. No errors are expected. |
| 3280 | TEST_F(VkLayerTest, StencilLoadOp) { |
| 3281 | TEST_DESCRIPTION("Create a stencil-only attachment with a LOAD_OP set to " |
| 3282 | "CLEAR. stencil[Load|Store]Op used to be ignored."); |
| 3283 | VkResult result = VK_SUCCESS; |
| 3284 | VkImageFormatProperties formatProps; |
| 3285 | vkGetPhysicalDeviceImageFormatProperties( |
| 3286 | gpu(), VK_FORMAT_D24_UNORM_S8_UINT, VK_IMAGE_TYPE_2D, |
| 3287 | VK_IMAGE_TILING_OPTIMAL, VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT | |
| 3288 | VK_IMAGE_USAGE_TRANSFER_SRC_BIT, |
| 3289 | 0, &formatProps); |
| 3290 | if (formatProps.maxExtent.width < 100 || formatProps.maxExtent.height < 100) { |
| 3291 | return; |
| 3292 | } |
| 3293 | |
| 3294 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 3295 | VkFormat depth_stencil_fmt = VK_FORMAT_D24_UNORM_S8_UINT; |
| 3296 | m_depthStencil->Init(m_device, 100, 100, depth_stencil_fmt, |
| 3297 | VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT | |
| 3298 | VK_IMAGE_USAGE_TRANSFER_SRC_BIT); |
| 3299 | VkAttachmentDescription att = {}; |
| 3300 | VkAttachmentReference ref = {}; |
| 3301 | att.format = depth_stencil_fmt; |
| 3302 | att.loadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE; |
| 3303 | att.storeOp = VK_ATTACHMENT_STORE_OP_DONT_CARE; |
| 3304 | att.stencilLoadOp = VK_ATTACHMENT_LOAD_OP_CLEAR; |
| 3305 | att.stencilStoreOp = VK_ATTACHMENT_STORE_OP_STORE; |
| 3306 | att.initialLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL; |
| 3307 | att.finalLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL; |
| 3308 | |
| 3309 | VkClearValue clear; |
| 3310 | clear.depthStencil.depth = 1.0; |
| 3311 | clear.depthStencil.stencil = 0; |
| 3312 | ref.attachment = 0; |
| 3313 | ref.layout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL; |
| 3314 | |
| 3315 | VkSubpassDescription subpass = {}; |
| 3316 | subpass.pipelineBindPoint = VK_PIPELINE_BIND_POINT_GRAPHICS; |
| 3317 | subpass.flags = 0; |
| 3318 | subpass.inputAttachmentCount = 0; |
| 3319 | subpass.pInputAttachments = NULL; |
| 3320 | subpass.colorAttachmentCount = 0; |
| 3321 | subpass.pColorAttachments = NULL; |
| 3322 | subpass.pResolveAttachments = NULL; |
| 3323 | subpass.pDepthStencilAttachment = &ref; |
| 3324 | subpass.preserveAttachmentCount = 0; |
| 3325 | subpass.pPreserveAttachments = NULL; |
| 3326 | |
| 3327 | VkRenderPass rp; |
| 3328 | VkRenderPassCreateInfo rp_info = {}; |
| 3329 | rp_info.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO; |
| 3330 | rp_info.attachmentCount = 1; |
| 3331 | rp_info.pAttachments = &att; |
| 3332 | rp_info.subpassCount = 1; |
| 3333 | rp_info.pSubpasses = &subpass; |
| 3334 | result = vkCreateRenderPass(device(), &rp_info, NULL, &rp); |
| 3335 | ASSERT_VK_SUCCESS(result); |
| 3336 | |
| 3337 | VkImageView *depthView = m_depthStencil->BindInfo(); |
| 3338 | VkFramebufferCreateInfo fb_info = {}; |
| 3339 | fb_info.sType = VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO; |
| 3340 | fb_info.pNext = NULL; |
| 3341 | fb_info.renderPass = rp; |
| 3342 | fb_info.attachmentCount = 1; |
| 3343 | fb_info.pAttachments = depthView; |
| 3344 | fb_info.width = 100; |
| 3345 | fb_info.height = 100; |
| 3346 | fb_info.layers = 1; |
| 3347 | VkFramebuffer fb; |
| 3348 | result = vkCreateFramebuffer(device(), &fb_info, NULL, &fb); |
| 3349 | ASSERT_VK_SUCCESS(result); |
| 3350 | |
| 3351 | |
| 3352 | VkRenderPassBeginInfo rpbinfo = {}; |
| 3353 | rpbinfo.clearValueCount = 1; |
| 3354 | rpbinfo.pClearValues = &clear; |
| 3355 | rpbinfo.pNext = NULL; |
| 3356 | rpbinfo.renderPass = rp; |
| 3357 | rpbinfo.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO; |
| 3358 | rpbinfo.renderArea.extent.width = 100; |
| 3359 | rpbinfo.renderArea.extent.height = 100; |
| 3360 | rpbinfo.renderArea.offset.x = 0; |
| 3361 | rpbinfo.renderArea.offset.y = 0; |
| 3362 | rpbinfo.framebuffer = fb; |
| 3363 | |
| 3364 | VkFence fence = {}; |
| 3365 | VkFenceCreateInfo fence_ci = {}; |
| 3366 | fence_ci.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO; |
| 3367 | fence_ci.pNext = nullptr; |
| 3368 | fence_ci.flags = 0; |
| 3369 | result = vkCreateFence(m_device->device(), &fence_ci, nullptr, &fence); |
| 3370 | ASSERT_VK_SUCCESS(result); |
| 3371 | |
| 3372 | |
| 3373 | m_commandBuffer->BeginCommandBuffer(); |
| 3374 | m_commandBuffer->BeginRenderPass(rpbinfo); |
| 3375 | m_commandBuffer->EndRenderPass(); |
| 3376 | m_commandBuffer->EndCommandBuffer(); |
| 3377 | m_commandBuffer->QueueCommandBuffer(fence); |
| 3378 | |
| 3379 | VkImageObj destImage(m_device); |
| 3380 | destImage.init(100, 100, depth_stencil_fmt, |
| 3381 | VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT | |
| 3382 | VK_IMAGE_USAGE_TRANSFER_DST_BIT, |
| 3383 | VK_IMAGE_TILING_OPTIMAL, 0); |
| 3384 | VkImageMemoryBarrier barrier = {}; |
| 3385 | VkImageSubresourceRange range; |
| 3386 | barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER; |
| 3387 | barrier.srcAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT | |
| 3388 | VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT; |
| 3389 | barrier.dstAccessMask = VK_ACCESS_TRANSFER_READ_BIT | |
| 3390 | VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_READ_BIT; |
| 3391 | barrier.oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL; |
| 3392 | barrier.newLayout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL; |
| 3393 | barrier.image = m_depthStencil->handle(); |
| 3394 | range.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT; |
| 3395 | range.baseMipLevel = 0; |
| 3396 | range.levelCount = 1; |
| 3397 | range.baseArrayLayer = 0; |
| 3398 | range.layerCount = 1; |
| 3399 | barrier.subresourceRange = range; |
| 3400 | vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX); |
| 3401 | VkCommandBufferObj cmdbuf(m_device, m_commandPool); |
| 3402 | cmdbuf.BeginCommandBuffer(); |
| 3403 | cmdbuf.PipelineBarrier(VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, |
| 3404 | VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, nullptr, 0, |
| 3405 | nullptr, 1, &barrier); |
| 3406 | barrier.srcAccessMask = 0; |
| 3407 | barrier.oldLayout = VK_IMAGE_LAYOUT_UNDEFINED; |
| 3408 | barrier.newLayout = VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL; |
| 3409 | barrier.image = destImage.handle(); |
| 3410 | barrier.dstAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT | |
| 3411 | VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT; |
| 3412 | cmdbuf.PipelineBarrier(VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, |
| 3413 | VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, nullptr, 0, |
| 3414 | nullptr, 1, &barrier); |
| 3415 | VkImageCopy cregion; |
| 3416 | cregion.srcSubresource.aspectMask = |
| 3417 | VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT; |
| 3418 | cregion.srcSubresource.mipLevel = 0; |
| 3419 | cregion.srcSubresource.baseArrayLayer = 0; |
| 3420 | cregion.srcSubresource.layerCount = 1; |
| 3421 | cregion.srcOffset.x = 0; |
| 3422 | cregion.srcOffset.y = 0; |
| 3423 | cregion.srcOffset.z = 0; |
| 3424 | cregion.dstSubresource.aspectMask = |
| 3425 | VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT; |
| 3426 | cregion.dstSubresource.mipLevel = 0; |
| 3427 | cregion.dstSubresource.baseArrayLayer = 0; |
| 3428 | cregion.dstSubresource.layerCount = 1; |
| 3429 | cregion.dstOffset.x = 0; |
| 3430 | cregion.dstOffset.y = 0; |
| 3431 | cregion.dstOffset.z = 0; |
| 3432 | cregion.extent.width = 100; |
| 3433 | cregion.extent.height = 100; |
| 3434 | cregion.extent.depth = 1; |
| 3435 | cmdbuf.CopyImage(m_depthStencil->handle(), |
| 3436 | VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, destImage.handle(), |
| 3437 | VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &cregion); |
| 3438 | cmdbuf.EndCommandBuffer(); |
| 3439 | |
| 3440 | VkSubmitInfo submit_info; |
| 3441 | submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO; |
| 3442 | submit_info.pNext = NULL; |
| 3443 | submit_info.waitSemaphoreCount = 0; |
| 3444 | submit_info.pWaitSemaphores = NULL; |
| 3445 | submit_info.pWaitDstStageMask = NULL; |
| 3446 | submit_info.commandBufferCount = 1; |
| 3447 | submit_info.pCommandBuffers = &cmdbuf.handle(); |
| 3448 | submit_info.signalSemaphoreCount = 0; |
| 3449 | submit_info.pSignalSemaphores = NULL; |
| 3450 | |
| 3451 | m_errorMonitor->ExpectSuccess(); |
| 3452 | vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE); |
| 3453 | m_errorMonitor->VerifyNotFound(); |
| 3454 | |
Mark Lobodzinski | d0440da | 2016-06-17 15:10:03 -0600 | [diff] [blame] | 3455 | vkQueueWaitIdle(m_device->m_queue); |
Mark Lobodzinski | ce7eee7 | 2016-06-14 16:33:29 -0600 | [diff] [blame] | 3456 | vkDestroyFence(m_device->device(), fence, nullptr); |
| 3457 | vkDestroyRenderPass(m_device->device(), rp, nullptr); |
| 3458 | vkDestroyFramebuffer(m_device->device(), fb, nullptr); |
| 3459 | } |
| 3460 | |
Mark Lobodzinski | 6d17b9f | 2016-06-16 13:21:38 -0600 | [diff] [blame] | 3461 | TEST_F(VkLayerTest, UnusedPreserveAttachment) { |
| 3462 | TEST_DESCRIPTION("Create a framebuffer where a subpass has a preserve " |
| 3463 | "attachment reference of VK_ATTACHMENT_UNUSED"); |
| 3464 | |
| 3465 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 3466 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 3467 | |
| 3468 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 3469 | "must not be VK_ATTACHMENT_UNUSED"); |
| 3470 | |
| 3471 | VkAttachmentReference color_attach = {}; |
| 3472 | color_attach.layout = VK_IMAGE_LAYOUT_GENERAL; |
| 3473 | color_attach.attachment = 0; |
| 3474 | uint32_t preserve_attachment = VK_ATTACHMENT_UNUSED; |
| 3475 | VkSubpassDescription subpass = {}; |
| 3476 | subpass.colorAttachmentCount = 1; |
| 3477 | subpass.pColorAttachments = &color_attach; |
| 3478 | subpass.preserveAttachmentCount = 1; |
| 3479 | subpass.pPreserveAttachments = &preserve_attachment; |
| 3480 | |
| 3481 | VkRenderPassCreateInfo rpci = {}; |
| 3482 | rpci.subpassCount = 1; |
| 3483 | rpci.pSubpasses = &subpass; |
| 3484 | rpci.attachmentCount = 1; |
| 3485 | VkAttachmentDescription attach_desc = {}; |
| 3486 | attach_desc.format = VK_FORMAT_UNDEFINED; |
| 3487 | rpci.pAttachments = &attach_desc; |
| 3488 | rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO; |
| 3489 | VkRenderPass rp; |
Mark Lobodzinski | a4feeeb | 2016-06-17 12:00:46 -0600 | [diff] [blame] | 3490 | VkResult result = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp); |
Mark Lobodzinski | 6d17b9f | 2016-06-16 13:21:38 -0600 | [diff] [blame] | 3491 | |
| 3492 | m_errorMonitor->VerifyFound(); |
| 3493 | |
Mark Lobodzinski | a4feeeb | 2016-06-17 12:00:46 -0600 | [diff] [blame] | 3494 | if (result == VK_SUCCESS) { |
| 3495 | vkDestroyRenderPass(m_device->device(), rp, NULL); |
| 3496 | } |
Mark Lobodzinski | 6d17b9f | 2016-06-16 13:21:38 -0600 | [diff] [blame] | 3497 | } |
| 3498 | |
Chris Forbes | c538974 | 2016-06-29 11:49:23 +1200 | [diff] [blame] | 3499 | TEST_F(VkLayerTest, CreateRenderPassResolveRequiresColorMsaa) { |
Chris Forbes | 6655bb3 | 2016-07-01 18:27:30 +1200 | [diff] [blame] | 3500 | TEST_DESCRIPTION("Ensure that CreateRenderPass produces a validation error " |
| 3501 | "when the source of a subpass multisample resolve " |
| 3502 | "does not have multiple samples."); |
| 3503 | |
Chris Forbes | c538974 | 2016-06-29 11:49:23 +1200 | [diff] [blame] | 3504 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 3505 | |
| 3506 | m_errorMonitor->SetDesiredFailureMsg( |
| 3507 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Chris Forbes | 6655bb3 | 2016-07-01 18:27:30 +1200 | [diff] [blame] | 3508 | "Subpass 0 requests multisample resolve from attachment 0 which has " |
| 3509 | "VK_SAMPLE_COUNT_1_BIT"); |
Chris Forbes | c538974 | 2016-06-29 11:49:23 +1200 | [diff] [blame] | 3510 | |
| 3511 | VkAttachmentDescription attachments[] = { |
| 3512 | { |
| 3513 | 0, VK_FORMAT_R8G8B8A8_UNORM, |
| 3514 | VK_SAMPLE_COUNT_1_BIT, |
| 3515 | VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, |
| 3516 | VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, |
| 3517 | VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, |
| 3518 | VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL |
| 3519 | }, |
| 3520 | { |
| 3521 | 0, VK_FORMAT_R8G8B8A8_UNORM, |
| 3522 | VK_SAMPLE_COUNT_1_BIT, |
| 3523 | VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, |
| 3524 | VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, |
| 3525 | VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, |
| 3526 | VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL |
| 3527 | }, |
| 3528 | }; |
| 3529 | |
| 3530 | VkAttachmentReference color = { |
| 3531 | 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, |
| 3532 | }; |
| 3533 | |
| 3534 | VkAttachmentReference resolve = { |
| 3535 | 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, |
| 3536 | }; |
| 3537 | |
| 3538 | VkSubpassDescription subpass = { |
| 3539 | 0, VK_PIPELINE_BIND_POINT_GRAPHICS, |
| 3540 | 0, nullptr, |
| 3541 | 1, &color, |
| 3542 | &resolve, |
| 3543 | nullptr, |
| 3544 | 0, nullptr |
| 3545 | }; |
| 3546 | |
| 3547 | VkRenderPassCreateInfo rpci = { |
| 3548 | VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, |
| 3549 | 0, 2, attachments, 1, &subpass, 0, nullptr |
| 3550 | }; |
| 3551 | |
| 3552 | VkRenderPass rp; |
| 3553 | VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp); |
| 3554 | |
| 3555 | m_errorMonitor->VerifyFound(); |
| 3556 | |
| 3557 | if (err == VK_SUCCESS) |
| 3558 | vkDestroyRenderPass(m_device->device(), rp, nullptr); |
| 3559 | } |
| 3560 | |
| 3561 | TEST_F(VkLayerTest, CreateRenderPassResolveRequiresSingleSampleDest) { |
Chris Forbes | 6655bb3 | 2016-07-01 18:27:30 +1200 | [diff] [blame] | 3562 | TEST_DESCRIPTION("Ensure CreateRenderPass produces a validation error " |
| 3563 | "when a subpass multisample resolve operation is " |
| 3564 | "requested, and the destination of that resolve has " |
| 3565 | "multiple samples."); |
| 3566 | |
Chris Forbes | c538974 | 2016-06-29 11:49:23 +1200 | [diff] [blame] | 3567 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 3568 | |
| 3569 | m_errorMonitor->SetDesiredFailureMsg( |
| 3570 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 3571 | "Subpass 0 requests multisample resolve into attachment 1, which " |
| 3572 | "must have VK_SAMPLE_COUNT_1_BIT but has VK_SAMPLE_COUNT_4_BIT"); |
| 3573 | |
| 3574 | VkAttachmentDescription attachments[] = { |
| 3575 | { |
| 3576 | 0, VK_FORMAT_R8G8B8A8_UNORM, |
| 3577 | VK_SAMPLE_COUNT_4_BIT, |
| 3578 | VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, |
| 3579 | VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, |
| 3580 | VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, |
| 3581 | VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL |
| 3582 | }, |
| 3583 | { |
| 3584 | 0, VK_FORMAT_R8G8B8A8_UNORM, |
| 3585 | VK_SAMPLE_COUNT_4_BIT, |
| 3586 | VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, |
| 3587 | VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, |
| 3588 | VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, |
| 3589 | VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL |
| 3590 | }, |
| 3591 | }; |
| 3592 | |
| 3593 | VkAttachmentReference color = { |
| 3594 | 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, |
| 3595 | }; |
| 3596 | |
| 3597 | VkAttachmentReference resolve = { |
| 3598 | 1, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, |
| 3599 | }; |
| 3600 | |
| 3601 | VkSubpassDescription subpass = { |
| 3602 | 0, VK_PIPELINE_BIND_POINT_GRAPHICS, |
| 3603 | 0, nullptr, |
| 3604 | 1, &color, |
| 3605 | &resolve, |
| 3606 | nullptr, |
| 3607 | 0, nullptr |
| 3608 | }; |
| 3609 | |
| 3610 | VkRenderPassCreateInfo rpci = { |
| 3611 | VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, |
| 3612 | 0, 2, attachments, 1, &subpass, 0, nullptr |
| 3613 | }; |
| 3614 | |
| 3615 | VkRenderPass rp; |
| 3616 | VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp); |
| 3617 | |
| 3618 | m_errorMonitor->VerifyFound(); |
| 3619 | |
| 3620 | if (err == VK_SUCCESS) |
| 3621 | vkDestroyRenderPass(m_device->device(), rp, nullptr); |
| 3622 | } |
| 3623 | |
Chris Forbes | 3f128ef | 2016-06-29 14:58:53 +1200 | [diff] [blame] | 3624 | TEST_F(VkLayerTest, CreateRenderPassSubpassSampleCountConsistency) { |
Chris Forbes | 6655bb3 | 2016-07-01 18:27:30 +1200 | [diff] [blame] | 3625 | TEST_DESCRIPTION("Ensure CreateRenderPass produces a validation error " |
| 3626 | "when the color and depth attachments used by a subpass " |
| 3627 | "have inconsistent sample counts"); |
| 3628 | |
Chris Forbes | 3f128ef | 2016-06-29 14:58:53 +1200 | [diff] [blame] | 3629 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 3630 | |
| 3631 | m_errorMonitor->SetDesiredFailureMsg( |
| 3632 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 3633 | "Subpass 0 attempts to render to attachments with inconsistent sample counts"); |
| 3634 | |
| 3635 | VkAttachmentDescription attachments[] = { |
| 3636 | { |
| 3637 | 0, VK_FORMAT_R8G8B8A8_UNORM, |
| 3638 | VK_SAMPLE_COUNT_1_BIT, |
| 3639 | VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, |
| 3640 | VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, |
| 3641 | VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, |
| 3642 | VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL |
| 3643 | }, |
| 3644 | { |
| 3645 | 0, VK_FORMAT_R8G8B8A8_UNORM, |
| 3646 | VK_SAMPLE_COUNT_4_BIT, |
| 3647 | VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, |
| 3648 | VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, |
| 3649 | VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, |
| 3650 | VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL |
| 3651 | }, |
| 3652 | }; |
| 3653 | |
| 3654 | VkAttachmentReference color[] = { |
| 3655 | { |
| 3656 | 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, |
| 3657 | }, |
| 3658 | { |
| 3659 | 1, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, |
| 3660 | }, |
| 3661 | }; |
| 3662 | |
| 3663 | VkSubpassDescription subpass = { |
| 3664 | 0, VK_PIPELINE_BIND_POINT_GRAPHICS, |
| 3665 | 0, nullptr, |
| 3666 | 2, color, |
| 3667 | nullptr, |
| 3668 | nullptr, |
| 3669 | 0, nullptr |
| 3670 | }; |
| 3671 | |
| 3672 | VkRenderPassCreateInfo rpci = { |
| 3673 | VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, |
| 3674 | 0, 2, attachments, 1, &subpass, 0, nullptr |
| 3675 | }; |
| 3676 | |
| 3677 | VkRenderPass rp; |
| 3678 | VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp); |
| 3679 | |
| 3680 | m_errorMonitor->VerifyFound(); |
| 3681 | |
| 3682 | if (err == VK_SUCCESS) |
| 3683 | vkDestroyRenderPass(m_device->device(), rp, nullptr); |
| 3684 | } |
| 3685 | |
Tobin Ehlis | 2545e6f | 2016-06-22 10:42:19 -0600 | [diff] [blame] | 3686 | TEST_F(VkLayerTest, FramebufferCreateErrors) { |
| 3687 | TEST_DESCRIPTION("Hit errors when attempting to create a framebuffer :\n" |
| 3688 | " 1. Mismatch between fb & renderPass attachmentCount\n" |
Tobin Ehlis | d3bb23a | 2016-06-22 13:34:46 -0600 | [diff] [blame] | 3689 | " 2. Use a color image as depthStencil attachment\n" |
Tobin Ehlis | 77d717c | 2016-06-22 14:19:19 -0600 | [diff] [blame] | 3690 | " 3. Mismatch fb & renderPass attachment formats\n" |
Tobin Ehlis | 6cfda64 | 2016-06-22 16:12:58 -0600 | [diff] [blame] | 3691 | " 4. Mismatch fb & renderPass attachment #samples\n" |
Tobin Ehlis | 27f2ae8 | 2016-06-23 07:36:57 -0600 | [diff] [blame] | 3692 | " 5. FB attachment w/ non-1 mip-levels\n" |
Tobin Ehlis | b1f303b | 2016-06-23 08:19:55 -0600 | [diff] [blame] | 3693 | " 6. FB attachment where dimensions don't match\n" |
Tobin Ehlis | 08d4b5e | 2016-06-23 08:52:39 -0600 | [diff] [blame] | 3694 | " 7. FB attachment w/o identity swizzle\n" |
| 3695 | " 8. FB dimensions exceed physical device limits\n"); |
Mark Lobodzinski | 6d17b9f | 2016-06-16 13:21:38 -0600 | [diff] [blame] | 3696 | |
| 3697 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 3698 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 3699 | |
| 3700 | m_errorMonitor->SetDesiredFailureMsg( |
| 3701 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Tobin Ehlis | 2545e6f | 2016-06-22 10:42:19 -0600 | [diff] [blame] | 3702 | "vkCreateFramebuffer(): VkFramebufferCreateInfo attachmentCount of 2 " |
| 3703 | "does not match attachmentCount of 1 of "); |
Mark Lobodzinski | 6d17b9f | 2016-06-16 13:21:38 -0600 | [diff] [blame] | 3704 | |
Tobin Ehlis | 2545e6f | 2016-06-22 10:42:19 -0600 | [diff] [blame] | 3705 | // Create a renderPass with a single color attachment |
Mark Lobodzinski | 6d17b9f | 2016-06-16 13:21:38 -0600 | [diff] [blame] | 3706 | VkAttachmentReference attach = {}; |
| 3707 | attach.layout = VK_IMAGE_LAYOUT_GENERAL; |
| 3708 | VkSubpassDescription subpass = {}; |
Tobin Ehlis | 2545e6f | 2016-06-22 10:42:19 -0600 | [diff] [blame] | 3709 | subpass.pColorAttachments = &attach; |
Mark Lobodzinski | 6d17b9f | 2016-06-16 13:21:38 -0600 | [diff] [blame] | 3710 | VkRenderPassCreateInfo rpci = {}; |
| 3711 | rpci.subpassCount = 1; |
| 3712 | rpci.pSubpasses = &subpass; |
| 3713 | rpci.attachmentCount = 1; |
| 3714 | VkAttachmentDescription attach_desc = {}; |
Tobin Ehlis | d3bb23a | 2016-06-22 13:34:46 -0600 | [diff] [blame] | 3715 | attach_desc.format = VK_FORMAT_B8G8R8A8_UNORM; |
Tobin Ehlis | 77d717c | 2016-06-22 14:19:19 -0600 | [diff] [blame] | 3716 | attach_desc.samples = VK_SAMPLE_COUNT_1_BIT; |
Mark Lobodzinski | 6d17b9f | 2016-06-16 13:21:38 -0600 | [diff] [blame] | 3717 | rpci.pAttachments = &attach_desc; |
| 3718 | rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO; |
| 3719 | VkRenderPass rp; |
| 3720 | VkResult err = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp); |
| 3721 | ASSERT_VK_SUCCESS(err); |
| 3722 | |
Tobin Ehlis | 2545e6f | 2016-06-22 10:42:19 -0600 | [diff] [blame] | 3723 | VkImageView ivs[2]; |
| 3724 | ivs[0] = m_renderTargets[0]->targetView(VK_FORMAT_B8G8R8A8_UNORM); |
| 3725 | ivs[1] = m_renderTargets[0]->targetView(VK_FORMAT_B8G8R8A8_UNORM); |
Mark Lobodzinski | 6d17b9f | 2016-06-16 13:21:38 -0600 | [diff] [blame] | 3726 | VkFramebufferCreateInfo fb_info = {}; |
| 3727 | fb_info.sType = VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO; |
| 3728 | fb_info.pNext = NULL; |
| 3729 | fb_info.renderPass = rp; |
Tobin Ehlis | 2545e6f | 2016-06-22 10:42:19 -0600 | [diff] [blame] | 3730 | // Set mis-matching attachmentCount |
| 3731 | fb_info.attachmentCount = 2; |
| 3732 | fb_info.pAttachments = ivs; |
Mark Lobodzinski | 6d17b9f | 2016-06-16 13:21:38 -0600 | [diff] [blame] | 3733 | fb_info.width = 100; |
| 3734 | fb_info.height = 100; |
| 3735 | fb_info.layers = 1; |
| 3736 | |
| 3737 | VkFramebuffer fb; |
| 3738 | err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb); |
| 3739 | |
| 3740 | m_errorMonitor->VerifyFound(); |
Mark Lobodzinski | 6d17b9f | 2016-06-16 13:21:38 -0600 | [diff] [blame] | 3741 | if (err == VK_SUCCESS) { |
| 3742 | vkDestroyFramebuffer(m_device->device(), fb, NULL); |
| 3743 | } |
| 3744 | vkDestroyRenderPass(m_device->device(), rp, NULL); |
Tobin Ehlis | 2545e6f | 2016-06-22 10:42:19 -0600 | [diff] [blame] | 3745 | |
| 3746 | // Create a renderPass with a depth-stencil attachment created with |
| 3747 | // IMAGE_USAGE_COLOR_ATTACHMENT |
| 3748 | // Add our color attachment to pDepthStencilAttachment |
| 3749 | subpass.pDepthStencilAttachment = &attach; |
| 3750 | subpass.pColorAttachments = NULL; |
| 3751 | VkRenderPass rp_ds; |
| 3752 | err = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp_ds); |
| 3753 | ASSERT_VK_SUCCESS(err); |
| 3754 | // Set correct attachment count, but attachment has COLOR usage bit set |
| 3755 | fb_info.attachmentCount = 1; |
| 3756 | fb_info.renderPass = rp_ds; |
| 3757 | |
| 3758 | m_errorMonitor->SetDesiredFailureMsg( |
| 3759 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 3760 | " conflicts with the image's IMAGE_USAGE flags "); |
| 3761 | err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb); |
| 3762 | |
| 3763 | m_errorMonitor->VerifyFound(); |
| 3764 | if (err == VK_SUCCESS) { |
| 3765 | vkDestroyFramebuffer(m_device->device(), fb, NULL); |
| 3766 | } |
| 3767 | vkDestroyRenderPass(m_device->device(), rp_ds, NULL); |
Tobin Ehlis | d3bb23a | 2016-06-22 13:34:46 -0600 | [diff] [blame] | 3768 | |
| 3769 | // Create new renderpass with alternate attachment format from fb |
| 3770 | attach_desc.format = VK_FORMAT_R8G8B8A8_UNORM; |
| 3771 | subpass.pDepthStencilAttachment = NULL; |
| 3772 | subpass.pColorAttachments = &attach; |
| 3773 | err = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp); |
| 3774 | ASSERT_VK_SUCCESS(err); |
| 3775 | |
| 3776 | // Cause error due to mis-matched formats between rp & fb |
| 3777 | // rp attachment 0 now has RGBA8 but corresponding fb attach is BGRA8 |
| 3778 | fb_info.renderPass = rp; |
| 3779 | m_errorMonitor->SetDesiredFailureMsg( |
| 3780 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 3781 | " has format of VK_FORMAT_B8G8R8A8_UNORM that does not match "); |
| 3782 | err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb); |
| 3783 | |
| 3784 | m_errorMonitor->VerifyFound(); |
| 3785 | if (err == VK_SUCCESS) { |
| 3786 | vkDestroyFramebuffer(m_device->device(), fb, NULL); |
| 3787 | } |
Tobin Ehlis | 77d717c | 2016-06-22 14:19:19 -0600 | [diff] [blame] | 3788 | vkDestroyRenderPass(m_device->device(), rp, NULL); |
| 3789 | |
| 3790 | // Create new renderpass with alternate sample count from fb |
| 3791 | attach_desc.format = VK_FORMAT_B8G8R8A8_UNORM; |
| 3792 | attach_desc.samples = VK_SAMPLE_COUNT_4_BIT; |
| 3793 | err = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp); |
| 3794 | ASSERT_VK_SUCCESS(err); |
| 3795 | |
| 3796 | // Cause error due to mis-matched sample count between rp & fb |
| 3797 | fb_info.renderPass = rp; |
| 3798 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 3799 | " has VK_SAMPLE_COUNT_1_BIT samples " |
| 3800 | "that do not match the " |
| 3801 | "VK_SAMPLE_COUNT_4_BIT "); |
| 3802 | err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb); |
| 3803 | |
| 3804 | m_errorMonitor->VerifyFound(); |
| 3805 | if (err == VK_SUCCESS) { |
| 3806 | vkDestroyFramebuffer(m_device->device(), fb, NULL); |
| 3807 | } |
Tobin Ehlis | d3bb23a | 2016-06-22 13:34:46 -0600 | [diff] [blame] | 3808 | |
| 3809 | vkDestroyRenderPass(m_device->device(), rp, NULL); |
Tobin Ehlis | 6cfda64 | 2016-06-22 16:12:58 -0600 | [diff] [blame] | 3810 | |
| 3811 | // Create a custom imageView with non-1 mip levels |
| 3812 | VkImageObj image(m_device); |
| 3813 | image.init(128, 128, VK_FORMAT_B8G8R8A8_UNORM, |
| 3814 | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0); |
| 3815 | ASSERT_TRUE(image.initialized()); |
| 3816 | |
| 3817 | VkImageView view; |
| 3818 | VkImageViewCreateInfo ivci = {}; |
| 3819 | ivci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO; |
| 3820 | ivci.image = image.handle(); |
| 3821 | ivci.viewType = VK_IMAGE_VIEW_TYPE_2D; |
| 3822 | ivci.format = VK_FORMAT_B8G8R8A8_UNORM; |
| 3823 | ivci.subresourceRange.layerCount = 1; |
| 3824 | ivci.subresourceRange.baseMipLevel = 0; |
| 3825 | // Set level count 2 (only 1 is allowed for FB attachment) |
| 3826 | ivci.subresourceRange.levelCount = 2; |
| 3827 | ivci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; |
| 3828 | err = vkCreateImageView(m_device->device(), &ivci, NULL, &view); |
| 3829 | ASSERT_VK_SUCCESS(err); |
| 3830 | // Re-create renderpass to have matching sample count |
| 3831 | attach_desc.samples = VK_SAMPLE_COUNT_1_BIT; |
| 3832 | err = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp); |
| 3833 | ASSERT_VK_SUCCESS(err); |
| 3834 | |
| 3835 | fb_info.renderPass = rp; |
| 3836 | fb_info.pAttachments = &view; |
| 3837 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 3838 | " has mip levelCount of 2 but only "); |
| 3839 | err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb); |
| 3840 | |
| 3841 | m_errorMonitor->VerifyFound(); |
| 3842 | if (err == VK_SUCCESS) { |
| 3843 | vkDestroyFramebuffer(m_device->device(), fb, NULL); |
| 3844 | } |
Tobin Ehlis | 6cfda64 | 2016-06-22 16:12:58 -0600 | [diff] [blame] | 3845 | vkDestroyImageView(m_device->device(), view, NULL); |
Tobin Ehlis | 27f2ae8 | 2016-06-23 07:36:57 -0600 | [diff] [blame] | 3846 | // Update view to original color buffer and grow FB dimensions too big |
| 3847 | fb_info.pAttachments = ivs; |
| 3848 | fb_info.height = 1024; |
| 3849 | fb_info.width = 1024; |
| 3850 | fb_info.layers = 2; |
| 3851 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 3852 | " Attachment dimensions must be at " |
| 3853 | "least as large. "); |
| 3854 | err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb); |
| 3855 | |
| 3856 | m_errorMonitor->VerifyFound(); |
| 3857 | if (err == VK_SUCCESS) { |
| 3858 | vkDestroyFramebuffer(m_device->device(), fb, NULL); |
| 3859 | } |
Tobin Ehlis | b1f303b | 2016-06-23 08:19:55 -0600 | [diff] [blame] | 3860 | // Create view attachment with non-identity swizzle |
| 3861 | ivci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO; |
| 3862 | ivci.image = image.handle(); |
| 3863 | ivci.viewType = VK_IMAGE_VIEW_TYPE_2D; |
| 3864 | ivci.format = VK_FORMAT_B8G8R8A8_UNORM; |
| 3865 | ivci.subresourceRange.layerCount = 1; |
| 3866 | ivci.subresourceRange.baseMipLevel = 0; |
| 3867 | ivci.subresourceRange.levelCount = 1; |
| 3868 | ivci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; |
| 3869 | ivci.components.r = VK_COMPONENT_SWIZZLE_G; |
| 3870 | ivci.components.g = VK_COMPONENT_SWIZZLE_R; |
| 3871 | ivci.components.b = VK_COMPONENT_SWIZZLE_A; |
| 3872 | ivci.components.a = VK_COMPONENT_SWIZZLE_B; |
| 3873 | err = vkCreateImageView(m_device->device(), &ivci, NULL, &view); |
| 3874 | ASSERT_VK_SUCCESS(err); |
| 3875 | |
| 3876 | fb_info.pAttachments = &view; |
| 3877 | fb_info.height = 100; |
| 3878 | fb_info.width = 100; |
| 3879 | fb_info.layers = 1; |
| 3880 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 3881 | " has non-identy swizzle. All " |
| 3882 | "framebuffer attachments must have " |
| 3883 | "been created with the identity " |
| 3884 | "swizzle. "); |
| 3885 | err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb); |
| 3886 | |
| 3887 | m_errorMonitor->VerifyFound(); |
| 3888 | if (err == VK_SUCCESS) { |
| 3889 | vkDestroyFramebuffer(m_device->device(), fb, NULL); |
| 3890 | } |
| 3891 | vkDestroyImageView(m_device->device(), view, NULL); |
Tobin Ehlis | 08d4b5e | 2016-06-23 08:52:39 -0600 | [diff] [blame] | 3892 | // Request fb that exceeds max dimensions |
| 3893 | // reset attachment to color attachment |
| 3894 | fb_info.pAttachments = ivs; |
| 3895 | fb_info.width = m_device->props.limits.maxFramebufferWidth + 1; |
| 3896 | fb_info.height = m_device->props.limits.maxFramebufferHeight + 1; |
| 3897 | fb_info.layers = m_device->props.limits.maxFramebufferLayers + 1; |
| 3898 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 3899 | " Requested VkFramebufferCreateInfo " |
| 3900 | "dimensions exceed physical device " |
| 3901 | "limits. "); |
| 3902 | err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb); |
| 3903 | |
| 3904 | m_errorMonitor->VerifyFound(); |
| 3905 | if (err == VK_SUCCESS) { |
| 3906 | vkDestroyFramebuffer(m_device->device(), fb, NULL); |
| 3907 | } |
Tobin Ehlis | 27f2ae8 | 2016-06-23 07:36:57 -0600 | [diff] [blame] | 3908 | |
Tobin Ehlis | 6cfda64 | 2016-06-22 16:12:58 -0600 | [diff] [blame] | 3909 | vkDestroyRenderPass(m_device->device(), rp, NULL); |
Mark Lobodzinski | 6d17b9f | 2016-06-16 13:21:38 -0600 | [diff] [blame] | 3910 | } |
| 3911 | |
Mark Lobodzinski | c808d44 | 2016-04-14 10:57:23 -0600 | [diff] [blame] | 3912 | // This is a positive test. No errors should be generated. |
Michael Lentine | 860b0fe | 2016-05-20 10:14:00 -0500 | [diff] [blame] | 3913 | TEST_F(VkLayerTest, WaitEventThenSet) { |
| 3914 | TEST_DESCRIPTION( |
| 3915 | "Wait on a event then set it after the wait has been submitted."); |
| 3916 | |
Michael Lentine | 860b0fe | 2016-05-20 10:14:00 -0500 | [diff] [blame] | 3917 | m_errorMonitor->ExpectSuccess(); |
| 3918 | |
| 3919 | VkEvent event; |
| 3920 | VkEventCreateInfo event_create_info{}; |
| 3921 | event_create_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO; |
| 3922 | vkCreateEvent(m_device->device(), &event_create_info, nullptr, &event); |
| 3923 | |
| 3924 | VkCommandPool command_pool; |
| 3925 | VkCommandPoolCreateInfo pool_create_info{}; |
| 3926 | pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO; |
| 3927 | pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_; |
| 3928 | pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT; |
| 3929 | vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, |
| 3930 | &command_pool); |
| 3931 | |
| 3932 | VkCommandBuffer command_buffer; |
| 3933 | VkCommandBufferAllocateInfo command_buffer_allocate_info{}; |
| 3934 | command_buffer_allocate_info.sType = |
| 3935 | VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO; |
| 3936 | command_buffer_allocate_info.commandPool = command_pool; |
| 3937 | command_buffer_allocate_info.commandBufferCount = 1; |
| 3938 | command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY; |
| 3939 | vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, |
| 3940 | &command_buffer); |
| 3941 | |
| 3942 | VkQueue queue = VK_NULL_HANDLE; |
| 3943 | vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, |
Tony Barbour | fe302c0 | 2016-06-06 13:05:19 -0600 | [diff] [blame] | 3944 | 0, &queue); |
Michael Lentine | 860b0fe | 2016-05-20 10:14:00 -0500 | [diff] [blame] | 3945 | |
| 3946 | { |
| 3947 | VkCommandBufferBeginInfo begin_info{}; |
| 3948 | begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO; |
| 3949 | vkBeginCommandBuffer(command_buffer, &begin_info); |
| 3950 | |
| 3951 | vkCmdWaitEvents(command_buffer, 1, &event, VK_PIPELINE_STAGE_HOST_BIT, |
| 3952 | VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, nullptr, 0, |
| 3953 | nullptr, 0, nullptr); |
| 3954 | vkCmdResetEvent(command_buffer, event, |
| 3955 | VK_PIPELINE_STAGE_ALL_COMMANDS_BIT); |
| 3956 | vkEndCommandBuffer(command_buffer); |
| 3957 | } |
| 3958 | { |
| 3959 | VkSubmitInfo submit_info{}; |
| 3960 | submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO; |
| 3961 | submit_info.commandBufferCount = 1; |
| 3962 | submit_info.pCommandBuffers = &command_buffer; |
| 3963 | submit_info.signalSemaphoreCount = 0; |
| 3964 | submit_info.pSignalSemaphores = nullptr; |
| 3965 | vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE); |
| 3966 | } |
| 3967 | { vkSetEvent(m_device->device(), event); } |
| 3968 | |
| 3969 | vkQueueWaitIdle(queue); |
| 3970 | |
| 3971 | vkDestroyEvent(m_device->device(), event, nullptr); |
| 3972 | vkFreeCommandBuffers(m_device->device(), command_pool, 1, &command_buffer); |
| 3973 | vkDestroyCommandPool(m_device->device(), command_pool, NULL); |
| 3974 | |
| 3975 | m_errorMonitor->VerifyNotFound(); |
| 3976 | } |
Michael Lentine | 5627e69 | 2016-05-20 17:45:02 -0500 | [diff] [blame] | 3977 | // This is a positive test. No errors should be generated. |
| 3978 | TEST_F(VkLayerTest, QueryAndCopyMultipleCommandBuffers) { |
| 3979 | TEST_DESCRIPTION( |
| 3980 | "Issue a query and copy from it on a second command buffer."); |
| 3981 | |
| 3982 | if ((m_device->queue_props.empty()) || |
| 3983 | (m_device->queue_props[0].queueCount < 2)) |
| 3984 | return; |
| 3985 | |
| 3986 | m_errorMonitor->ExpectSuccess(); |
| 3987 | |
| 3988 | VkQueryPool query_pool; |
| 3989 | VkQueryPoolCreateInfo query_pool_create_info{}; |
| 3990 | query_pool_create_info.sType = VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO; |
| 3991 | query_pool_create_info.queryType = VK_QUERY_TYPE_TIMESTAMP; |
| 3992 | query_pool_create_info.queryCount = 1; |
| 3993 | vkCreateQueryPool(m_device->device(), &query_pool_create_info, nullptr, |
| 3994 | &query_pool); |
| 3995 | |
| 3996 | VkCommandPool command_pool; |
| 3997 | VkCommandPoolCreateInfo pool_create_info{}; |
| 3998 | pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO; |
| 3999 | pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_; |
| 4000 | pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT; |
| 4001 | vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, |
| 4002 | &command_pool); |
| 4003 | |
| 4004 | VkCommandBuffer command_buffer[2]; |
| 4005 | VkCommandBufferAllocateInfo command_buffer_allocate_info{}; |
| 4006 | command_buffer_allocate_info.sType = |
| 4007 | VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO; |
| 4008 | command_buffer_allocate_info.commandPool = command_pool; |
| 4009 | command_buffer_allocate_info.commandBufferCount = 2; |
| 4010 | command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY; |
| 4011 | vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, |
| 4012 | command_buffer); |
| 4013 | |
| 4014 | VkQueue queue = VK_NULL_HANDLE; |
| 4015 | vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, |
| 4016 | 1, &queue); |
| 4017 | |
| 4018 | uint32_t qfi = 0; |
| 4019 | VkBufferCreateInfo buff_create_info = {}; |
| 4020 | buff_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO; |
| 4021 | buff_create_info.size = 1024; |
| 4022 | buff_create_info.usage = VK_BUFFER_USAGE_TRANSFER_DST_BIT; |
| 4023 | buff_create_info.queueFamilyIndexCount = 1; |
| 4024 | buff_create_info.pQueueFamilyIndices = &qfi; |
| 4025 | |
| 4026 | VkResult err; |
| 4027 | VkBuffer buffer; |
| 4028 | err = vkCreateBuffer(m_device->device(), &buff_create_info, NULL, &buffer); |
| 4029 | ASSERT_VK_SUCCESS(err); |
| 4030 | VkMemoryAllocateInfo mem_alloc = {}; |
| 4031 | mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO; |
| 4032 | mem_alloc.pNext = NULL; |
| 4033 | mem_alloc.allocationSize = 1024; |
| 4034 | mem_alloc.memoryTypeIndex = 0; |
| 4035 | |
| 4036 | VkMemoryRequirements memReqs; |
| 4037 | vkGetBufferMemoryRequirements(m_device->device(), buffer, &memReqs); |
| 4038 | bool pass = |
| 4039 | m_device->phy().set_memory_type(memReqs.memoryTypeBits, &mem_alloc, 0); |
| 4040 | if (!pass) { |
| 4041 | vkDestroyBuffer(m_device->device(), buffer, NULL); |
| 4042 | return; |
| 4043 | } |
| 4044 | |
| 4045 | VkDeviceMemory mem; |
| 4046 | err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem); |
| 4047 | ASSERT_VK_SUCCESS(err); |
| 4048 | err = vkBindBufferMemory(m_device->device(), buffer, mem, 0); |
| 4049 | ASSERT_VK_SUCCESS(err); |
| 4050 | |
| 4051 | { |
| 4052 | VkCommandBufferBeginInfo begin_info{}; |
| 4053 | begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO; |
| 4054 | vkBeginCommandBuffer(command_buffer[0], &begin_info); |
| 4055 | |
| 4056 | vkCmdResetQueryPool(command_buffer[0], query_pool, 0, 1); |
| 4057 | vkCmdWriteTimestamp(command_buffer[0], |
| 4058 | VK_PIPELINE_STAGE_ALL_GRAPHICS_BIT, query_pool, 0); |
| 4059 | |
| 4060 | vkEndCommandBuffer(command_buffer[0]); |
| 4061 | |
| 4062 | vkBeginCommandBuffer(command_buffer[1], &begin_info); |
| 4063 | |
| 4064 | vkCmdCopyQueryPoolResults(command_buffer[1], query_pool, 0, 1, buffer, |
| 4065 | 0, 0, 0); |
| 4066 | |
| 4067 | vkEndCommandBuffer(command_buffer[1]); |
| 4068 | } |
| 4069 | { |
| 4070 | VkSubmitInfo submit_info{}; |
| 4071 | submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO; |
| 4072 | submit_info.commandBufferCount = 2; |
| 4073 | submit_info.pCommandBuffers = command_buffer; |
| 4074 | submit_info.signalSemaphoreCount = 0; |
| 4075 | submit_info.pSignalSemaphores = nullptr; |
| 4076 | vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE); |
| 4077 | } |
| 4078 | |
| 4079 | vkQueueWaitIdle(queue); |
| 4080 | |
| 4081 | vkDestroyQueryPool(m_device->device(), query_pool, nullptr); |
| 4082 | vkFreeCommandBuffers(m_device->device(), command_pool, 2, command_buffer); |
| 4083 | vkDestroyCommandPool(m_device->device(), command_pool, NULL); |
Tony Barbour | df4c004 | 2016-06-01 15:55:43 -0600 | [diff] [blame] | 4084 | vkDestroyBuffer(m_device->device(), buffer, NULL); |
| 4085 | vkFreeMemory(m_device->device(), mem, NULL); |
Michael Lentine | 5627e69 | 2016-05-20 17:45:02 -0500 | [diff] [blame] | 4086 | |
| 4087 | m_errorMonitor->VerifyNotFound(); |
| 4088 | } |
Michael Lentine | 860b0fe | 2016-05-20 10:14:00 -0500 | [diff] [blame] | 4089 | |
| 4090 | TEST_F(VkLayerTest, ResetEventThenSet) { |
| 4091 | TEST_DESCRIPTION( |
| 4092 | "Reset an event then set it after the reset has been submitted."); |
| 4093 | |
Michael Lentine | 860b0fe | 2016-05-20 10:14:00 -0500 | [diff] [blame] | 4094 | m_errorMonitor->ExpectSuccess(); |
| 4095 | |
| 4096 | VkEvent event; |
| 4097 | VkEventCreateInfo event_create_info{}; |
| 4098 | event_create_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO; |
| 4099 | vkCreateEvent(m_device->device(), &event_create_info, nullptr, &event); |
| 4100 | |
| 4101 | VkCommandPool command_pool; |
| 4102 | VkCommandPoolCreateInfo pool_create_info{}; |
| 4103 | pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO; |
| 4104 | pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_; |
| 4105 | pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT; |
| 4106 | vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, |
| 4107 | &command_pool); |
| 4108 | |
| 4109 | VkCommandBuffer command_buffer; |
| 4110 | VkCommandBufferAllocateInfo command_buffer_allocate_info{}; |
| 4111 | command_buffer_allocate_info.sType = |
| 4112 | VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO; |
| 4113 | command_buffer_allocate_info.commandPool = command_pool; |
| 4114 | command_buffer_allocate_info.commandBufferCount = 1; |
| 4115 | command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY; |
| 4116 | vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, |
| 4117 | &command_buffer); |
| 4118 | |
| 4119 | VkQueue queue = VK_NULL_HANDLE; |
| 4120 | vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, |
Tony Barbour | fe302c0 | 2016-06-06 13:05:19 -0600 | [diff] [blame] | 4121 | 0, &queue); |
Michael Lentine | 860b0fe | 2016-05-20 10:14:00 -0500 | [diff] [blame] | 4122 | |
| 4123 | { |
| 4124 | VkCommandBufferBeginInfo begin_info{}; |
| 4125 | begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO; |
| 4126 | vkBeginCommandBuffer(command_buffer, &begin_info); |
| 4127 | |
| 4128 | vkCmdResetEvent(command_buffer, event, |
| 4129 | VK_PIPELINE_STAGE_ALL_COMMANDS_BIT); |
| 4130 | vkCmdWaitEvents(command_buffer, 1, &event, |
| 4131 | VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, |
| 4132 | VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, nullptr, 0, |
| 4133 | nullptr, 0, nullptr); |
| 4134 | vkEndCommandBuffer(command_buffer); |
| 4135 | } |
| 4136 | { |
| 4137 | VkSubmitInfo submit_info{}; |
| 4138 | submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO; |
| 4139 | submit_info.commandBufferCount = 1; |
| 4140 | submit_info.pCommandBuffers = &command_buffer; |
| 4141 | submit_info.signalSemaphoreCount = 0; |
| 4142 | submit_info.pSignalSemaphores = nullptr; |
| 4143 | vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE); |
| 4144 | } |
| 4145 | { |
| 4146 | m_errorMonitor->SetDesiredFailureMsg( |
| 4147 | VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot call vkSetEvent() on event " |
| 4148 | "0x1 that is already in use by a " |
| 4149 | "command buffer."); |
| 4150 | vkSetEvent(m_device->device(), event); |
| 4151 | m_errorMonitor->VerifyFound(); |
| 4152 | } |
| 4153 | |
| 4154 | vkQueueWaitIdle(queue); |
| 4155 | |
| 4156 | vkDestroyEvent(m_device->device(), event, nullptr); |
| 4157 | vkFreeCommandBuffers(m_device->device(), command_pool, 1, &command_buffer); |
| 4158 | vkDestroyCommandPool(m_device->device(), command_pool, NULL); |
| 4159 | } |
| 4160 | |
| 4161 | // This is a positive test. No errors should be generated. |
Tobin Ehlis | 0bb263b | 2016-05-10 12:13:02 -0600 | [diff] [blame] | 4162 | TEST_F(VkLayerTest, TwoFencesThreeFrames) { |
| 4163 | TEST_DESCRIPTION("Two command buffers with two separate fences are each " |
| 4164 | "run through a Submit & WaitForFences cycle 3 times. This " |
| 4165 | "previously revealed a bug so running this positive test " |
| 4166 | "to prevent a regression."); |
| 4167 | m_errorMonitor->ExpectSuccess(); |
| 4168 | |
| 4169 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 4170 | VkQueue queue = VK_NULL_HANDLE; |
| 4171 | vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, |
| 4172 | 0, &queue); |
| 4173 | |
| 4174 | static const uint32_t NUM_OBJECTS = 2; |
| 4175 | static const uint32_t NUM_FRAMES = 3; |
| 4176 | VkCommandBuffer cmd_buffers[NUM_OBJECTS] = {}; |
| 4177 | VkFence fences[NUM_OBJECTS] = {}; |
| 4178 | |
| 4179 | VkCommandPool cmd_pool; |
| 4180 | VkCommandPoolCreateInfo cmd_pool_ci = {}; |
| 4181 | cmd_pool_ci.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO; |
| 4182 | cmd_pool_ci.queueFamilyIndex = m_device->graphics_queue_node_index_; |
| 4183 | cmd_pool_ci.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT; |
| 4184 | VkResult err = vkCreateCommandPool(m_device->device(), &cmd_pool_ci, |
| 4185 | nullptr, &cmd_pool); |
| 4186 | ASSERT_VK_SUCCESS(err); |
| 4187 | |
| 4188 | VkCommandBufferAllocateInfo cmd_buf_info = {}; |
| 4189 | cmd_buf_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO; |
| 4190 | cmd_buf_info.commandPool = cmd_pool; |
| 4191 | cmd_buf_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY; |
| 4192 | cmd_buf_info.commandBufferCount = 1; |
| 4193 | |
| 4194 | VkFenceCreateInfo fence_ci = {}; |
| 4195 | fence_ci.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO; |
| 4196 | fence_ci.pNext = nullptr; |
| 4197 | fence_ci.flags = 0; |
| 4198 | |
| 4199 | for (uint32_t i = 0; i < NUM_OBJECTS; ++i) { |
| 4200 | err = vkAllocateCommandBuffers(m_device->device(), &cmd_buf_info, |
| 4201 | &cmd_buffers[i]); |
| 4202 | ASSERT_VK_SUCCESS(err); |
| 4203 | err = vkCreateFence(m_device->device(), &fence_ci, nullptr, &fences[i]); |
| 4204 | ASSERT_VK_SUCCESS(err); |
| 4205 | } |
| 4206 | |
| 4207 | for (uint32_t frame = 0; frame < NUM_FRAMES; ++frame) { |
Tobin Ehlis | f902516 | 2016-05-26 06:55:21 -0600 | [diff] [blame] | 4208 | for (uint32_t obj = 0; obj < NUM_OBJECTS; ++obj) { |
| 4209 | // Create empty cmd buffer |
| 4210 | VkCommandBufferBeginInfo cmdBufBeginDesc = {}; |
| 4211 | cmdBufBeginDesc.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO; |
Tobin Ehlis | 0bb263b | 2016-05-10 12:13:02 -0600 | [diff] [blame] | 4212 | |
Tobin Ehlis | f902516 | 2016-05-26 06:55:21 -0600 | [diff] [blame] | 4213 | err = vkBeginCommandBuffer(cmd_buffers[obj], &cmdBufBeginDesc); |
| 4214 | ASSERT_VK_SUCCESS(err); |
| 4215 | err = vkEndCommandBuffer(cmd_buffers[obj]); |
| 4216 | ASSERT_VK_SUCCESS(err); |
Tobin Ehlis | 0bb263b | 2016-05-10 12:13:02 -0600 | [diff] [blame] | 4217 | |
Tobin Ehlis | f902516 | 2016-05-26 06:55:21 -0600 | [diff] [blame] | 4218 | VkSubmitInfo submit_info = {}; |
| 4219 | submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO; |
| 4220 | submit_info.commandBufferCount = 1; |
| 4221 | submit_info.pCommandBuffers = &cmd_buffers[obj]; |
| 4222 | // Submit cmd buffer and wait for fence |
| 4223 | err = vkQueueSubmit(queue, 1, &submit_info, fences[obj]); |
| 4224 | ASSERT_VK_SUCCESS(err); |
| 4225 | err = vkWaitForFences(m_device->device(), 1, &fences[obj], VK_TRUE, |
| 4226 | UINT64_MAX); |
| 4227 | ASSERT_VK_SUCCESS(err); |
| 4228 | err = vkResetFences(m_device->device(), 1, &fences[obj]); |
| 4229 | ASSERT_VK_SUCCESS(err); |
| 4230 | } |
Tobin Ehlis | 0bb263b | 2016-05-10 12:13:02 -0600 | [diff] [blame] | 4231 | } |
| 4232 | m_errorMonitor->VerifyNotFound(); |
Tony Barbour | df4c004 | 2016-06-01 15:55:43 -0600 | [diff] [blame] | 4233 | vkDestroyCommandPool(m_device->device(), cmd_pool, NULL); |
| 4234 | for (uint32_t i = 0; i < NUM_OBJECTS; ++i) { |
| 4235 | vkDestroyFence(m_device->device(), fences[i], nullptr); |
| 4236 | } |
Tobin Ehlis | 0bb263b | 2016-05-10 12:13:02 -0600 | [diff] [blame] | 4237 | } |
| 4238 | // This is a positive test. No errors should be generated. |
Mark Lobodzinski | c808d44 | 2016-04-14 10:57:23 -0600 | [diff] [blame] | 4239 | TEST_F(VkLayerTest, TwoQueueSubmitsSeparateQueuesWithSemaphoreAndOneFenceQWI) { |
| 4240 | |
| 4241 | TEST_DESCRIPTION("Two command buffers, each in a separate QueueSubmit call " |
| 4242 | "submitted on separate queues followed by a QueueWaitIdle."); |
| 4243 | |
Dustin Graves | 4845814 | 2016-04-29 16:11:55 -0600 | [diff] [blame] | 4244 | if ((m_device->queue_props.empty()) || |
| 4245 | (m_device->queue_props[0].queueCount < 2)) |
Tony Barbour | dc18b26 | 2016-04-22 14:49:48 -0600 | [diff] [blame] | 4246 | return; |
| 4247 | |
Mark Lobodzinski | c808d44 | 2016-04-14 10:57:23 -0600 | [diff] [blame] | 4248 | m_errorMonitor->ExpectSuccess(); |
| 4249 | |
| 4250 | VkSemaphore semaphore; |
| 4251 | VkSemaphoreCreateInfo semaphore_create_info{}; |
| 4252 | semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO; |
| 4253 | vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, |
| 4254 | &semaphore); |
| 4255 | |
| 4256 | VkCommandPool command_pool; |
| 4257 | VkCommandPoolCreateInfo pool_create_info{}; |
| 4258 | pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO; |
| 4259 | pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_; |
| 4260 | pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT; |
| 4261 | vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, |
| 4262 | &command_pool); |
| 4263 | |
| 4264 | VkCommandBuffer command_buffer[2]; |
| 4265 | VkCommandBufferAllocateInfo command_buffer_allocate_info{}; |
| 4266 | command_buffer_allocate_info.sType = |
| 4267 | VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO; |
| 4268 | command_buffer_allocate_info.commandPool = command_pool; |
| 4269 | command_buffer_allocate_info.commandBufferCount = 2; |
| 4270 | command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY; |
| 4271 | vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, |
| 4272 | command_buffer); |
| 4273 | |
| 4274 | VkQueue queue = VK_NULL_HANDLE; |
| 4275 | vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, |
| 4276 | 1, &queue); |
| 4277 | |
| 4278 | { |
| 4279 | VkCommandBufferBeginInfo begin_info{}; |
| 4280 | begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO; |
| 4281 | vkBeginCommandBuffer(command_buffer[0], &begin_info); |
| 4282 | |
| 4283 | vkCmdPipelineBarrier(command_buffer[0], |
| 4284 | VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, |
| 4285 | VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, nullptr, |
| 4286 | 0, nullptr, 0, nullptr); |
| 4287 | |
| 4288 | VkViewport viewport{}; |
| 4289 | viewport.maxDepth = 1.0f; |
| 4290 | viewport.minDepth = 0.0f; |
| 4291 | viewport.width = 512; |
| 4292 | viewport.height = 512; |
| 4293 | viewport.x = 0; |
| 4294 | viewport.y = 0; |
| 4295 | vkCmdSetViewport(command_buffer[0], 0, 1, &viewport); |
| 4296 | vkEndCommandBuffer(command_buffer[0]); |
| 4297 | } |
| 4298 | { |
| 4299 | VkCommandBufferBeginInfo begin_info{}; |
| 4300 | begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO; |
| 4301 | vkBeginCommandBuffer(command_buffer[1], &begin_info); |
| 4302 | |
| 4303 | VkViewport viewport{}; |
| 4304 | viewport.maxDepth = 1.0f; |
| 4305 | viewport.minDepth = 0.0f; |
| 4306 | viewport.width = 512; |
| 4307 | viewport.height = 512; |
| 4308 | viewport.x = 0; |
| 4309 | viewport.y = 0; |
| 4310 | vkCmdSetViewport(command_buffer[1], 0, 1, &viewport); |
| 4311 | vkEndCommandBuffer(command_buffer[1]); |
| 4312 | } |
| 4313 | { |
| 4314 | VkSubmitInfo submit_info{}; |
| 4315 | submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO; |
| 4316 | submit_info.commandBufferCount = 1; |
| 4317 | submit_info.pCommandBuffers = &command_buffer[0]; |
| 4318 | submit_info.signalSemaphoreCount = 1; |
| 4319 | submit_info.pSignalSemaphores = &semaphore; |
| 4320 | vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE); |
| 4321 | } |
| 4322 | { |
| 4323 | VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT}; |
| 4324 | VkSubmitInfo submit_info{}; |
| 4325 | submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO; |
| 4326 | submit_info.commandBufferCount = 1; |
| 4327 | submit_info.pCommandBuffers = &command_buffer[1]; |
| 4328 | submit_info.waitSemaphoreCount = 1; |
| 4329 | submit_info.pWaitSemaphores = &semaphore; |
| 4330 | submit_info.pWaitDstStageMask = flags; |
| 4331 | vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE); |
| 4332 | } |
| 4333 | |
| 4334 | vkQueueWaitIdle(m_device->m_queue); |
| 4335 | |
| 4336 | vkDestroySemaphore(m_device->device(), semaphore, nullptr); |
| 4337 | vkFreeCommandBuffers(m_device->device(), command_pool, 2, |
| 4338 | &command_buffer[0]); |
| 4339 | vkDestroyCommandPool(m_device->device(), command_pool, NULL); |
| 4340 | |
| 4341 | m_errorMonitor->VerifyNotFound(); |
| 4342 | } |
| 4343 | |
| 4344 | // This is a positive test. No errors should be generated. |
| 4345 | TEST_F(VkLayerTest, TwoQueueSubmitsSeparateQueuesWithSemaphoreAndOneFenceQWIFence) { |
| 4346 | |
| 4347 | TEST_DESCRIPTION("Two command buffers, each in a separate QueueSubmit call " |
| 4348 | "submitted on separate queues, the second having a fence" |
| 4349 | "followed by a QueueWaitIdle."); |
| 4350 | |
Dustin Graves | 4845814 | 2016-04-29 16:11:55 -0600 | [diff] [blame] | 4351 | if ((m_device->queue_props.empty()) || |
| 4352 | (m_device->queue_props[0].queueCount < 2)) |
Tony Barbour | dc18b26 | 2016-04-22 14:49:48 -0600 | [diff] [blame] | 4353 | return; |
| 4354 | |
Mark Lobodzinski | c808d44 | 2016-04-14 10:57:23 -0600 | [diff] [blame] | 4355 | m_errorMonitor->ExpectSuccess(); |
| 4356 | |
| 4357 | VkFence fence; |
| 4358 | VkFenceCreateInfo fence_create_info{}; |
| 4359 | fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO; |
| 4360 | vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence); |
| 4361 | |
| 4362 | VkSemaphore semaphore; |
| 4363 | VkSemaphoreCreateInfo semaphore_create_info{}; |
| 4364 | semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO; |
| 4365 | vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, |
| 4366 | &semaphore); |
| 4367 | |
| 4368 | VkCommandPool command_pool; |
| 4369 | VkCommandPoolCreateInfo pool_create_info{}; |
| 4370 | pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO; |
| 4371 | pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_; |
| 4372 | pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT; |
| 4373 | vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, |
| 4374 | &command_pool); |
| 4375 | |
| 4376 | VkCommandBuffer command_buffer[2]; |
| 4377 | VkCommandBufferAllocateInfo command_buffer_allocate_info{}; |
| 4378 | command_buffer_allocate_info.sType = |
| 4379 | VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO; |
| 4380 | command_buffer_allocate_info.commandPool = command_pool; |
| 4381 | command_buffer_allocate_info.commandBufferCount = 2; |
| 4382 | command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY; |
| 4383 | vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, |
| 4384 | command_buffer); |
| 4385 | |
| 4386 | VkQueue queue = VK_NULL_HANDLE; |
| 4387 | vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, |
| 4388 | 1, &queue); |
| 4389 | |
| 4390 | { |
| 4391 | VkCommandBufferBeginInfo begin_info{}; |
| 4392 | begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO; |
| 4393 | vkBeginCommandBuffer(command_buffer[0], &begin_info); |
| 4394 | |
| 4395 | vkCmdPipelineBarrier(command_buffer[0], |
| 4396 | VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, |
| 4397 | VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, nullptr, |
| 4398 | 0, nullptr, 0, nullptr); |
| 4399 | |
| 4400 | VkViewport viewport{}; |
| 4401 | viewport.maxDepth = 1.0f; |
| 4402 | viewport.minDepth = 0.0f; |
| 4403 | viewport.width = 512; |
| 4404 | viewport.height = 512; |
| 4405 | viewport.x = 0; |
| 4406 | viewport.y = 0; |
| 4407 | vkCmdSetViewport(command_buffer[0], 0, 1, &viewport); |
| 4408 | vkEndCommandBuffer(command_buffer[0]); |
| 4409 | } |
| 4410 | { |
| 4411 | VkCommandBufferBeginInfo begin_info{}; |
| 4412 | begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO; |
| 4413 | vkBeginCommandBuffer(command_buffer[1], &begin_info); |
| 4414 | |
| 4415 | VkViewport viewport{}; |
| 4416 | viewport.maxDepth = 1.0f; |
| 4417 | viewport.minDepth = 0.0f; |
| 4418 | viewport.width = 512; |
| 4419 | viewport.height = 512; |
| 4420 | viewport.x = 0; |
| 4421 | viewport.y = 0; |
| 4422 | vkCmdSetViewport(command_buffer[1], 0, 1, &viewport); |
| 4423 | vkEndCommandBuffer(command_buffer[1]); |
| 4424 | } |
| 4425 | { |
| 4426 | VkSubmitInfo submit_info{}; |
| 4427 | submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO; |
| 4428 | submit_info.commandBufferCount = 1; |
| 4429 | submit_info.pCommandBuffers = &command_buffer[0]; |
| 4430 | submit_info.signalSemaphoreCount = 1; |
| 4431 | submit_info.pSignalSemaphores = &semaphore; |
| 4432 | vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE); |
| 4433 | } |
| 4434 | { |
| 4435 | VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT}; |
| 4436 | VkSubmitInfo submit_info{}; |
| 4437 | submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO; |
| 4438 | submit_info.commandBufferCount = 1; |
| 4439 | submit_info.pCommandBuffers = &command_buffer[1]; |
| 4440 | submit_info.waitSemaphoreCount = 1; |
| 4441 | submit_info.pWaitSemaphores = &semaphore; |
| 4442 | submit_info.pWaitDstStageMask = flags; |
| 4443 | vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence); |
| 4444 | } |
| 4445 | |
| 4446 | vkQueueWaitIdle(m_device->m_queue); |
| 4447 | |
| 4448 | vkDestroyFence(m_device->device(), fence, nullptr); |
| 4449 | vkDestroySemaphore(m_device->device(), semaphore, nullptr); |
| 4450 | vkFreeCommandBuffers(m_device->device(), command_pool, 2, |
| 4451 | &command_buffer[0]); |
| 4452 | vkDestroyCommandPool(m_device->device(), command_pool, NULL); |
| 4453 | |
| 4454 | m_errorMonitor->VerifyNotFound(); |
| 4455 | } |
| 4456 | |
| 4457 | // This is a positive test. No errors should be generated. |
| 4458 | TEST_F(VkLayerTest, |
| 4459 | TwoQueueSubmitsSeparateQueuesWithSemaphoreAndOneFenceTwoWFF) { |
| 4460 | |
| 4461 | TEST_DESCRIPTION( |
| 4462 | "Two command buffers, each in a separate QueueSubmit call " |
| 4463 | "submitted on separate queues, the second having a fence" |
| 4464 | "followed by two consecutive WaitForFences calls on the same fence."); |
| 4465 | |
Dustin Graves | 4845814 | 2016-04-29 16:11:55 -0600 | [diff] [blame] | 4466 | if ((m_device->queue_props.empty()) || |
| 4467 | (m_device->queue_props[0].queueCount < 2)) |
Tony Barbour | dc18b26 | 2016-04-22 14:49:48 -0600 | [diff] [blame] | 4468 | return; |
| 4469 | |
Mark Lobodzinski | c808d44 | 2016-04-14 10:57:23 -0600 | [diff] [blame] | 4470 | m_errorMonitor->ExpectSuccess(); |
| 4471 | |
| 4472 | VkFence fence; |
| 4473 | VkFenceCreateInfo fence_create_info{}; |
| 4474 | fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO; |
| 4475 | vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence); |
| 4476 | |
| 4477 | VkSemaphore semaphore; |
| 4478 | VkSemaphoreCreateInfo semaphore_create_info{}; |
| 4479 | semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO; |
| 4480 | vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, |
| 4481 | &semaphore); |
| 4482 | |
| 4483 | VkCommandPool command_pool; |
| 4484 | VkCommandPoolCreateInfo pool_create_info{}; |
| 4485 | pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO; |
| 4486 | pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_; |
| 4487 | pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT; |
| 4488 | vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, |
| 4489 | &command_pool); |
| 4490 | |
| 4491 | VkCommandBuffer command_buffer[2]; |
| 4492 | VkCommandBufferAllocateInfo command_buffer_allocate_info{}; |
| 4493 | command_buffer_allocate_info.sType = |
| 4494 | VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO; |
| 4495 | command_buffer_allocate_info.commandPool = command_pool; |
| 4496 | command_buffer_allocate_info.commandBufferCount = 2; |
| 4497 | command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY; |
| 4498 | vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, |
| 4499 | command_buffer); |
| 4500 | |
| 4501 | VkQueue queue = VK_NULL_HANDLE; |
| 4502 | vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, |
| 4503 | 1, &queue); |
| 4504 | |
| 4505 | { |
| 4506 | VkCommandBufferBeginInfo begin_info{}; |
| 4507 | begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO; |
| 4508 | vkBeginCommandBuffer(command_buffer[0], &begin_info); |
| 4509 | |
| 4510 | vkCmdPipelineBarrier(command_buffer[0], |
| 4511 | VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, |
| 4512 | VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, nullptr, |
| 4513 | 0, nullptr, 0, nullptr); |
| 4514 | |
| 4515 | VkViewport viewport{}; |
| 4516 | viewport.maxDepth = 1.0f; |
| 4517 | viewport.minDepth = 0.0f; |
| 4518 | viewport.width = 512; |
| 4519 | viewport.height = 512; |
| 4520 | viewport.x = 0; |
| 4521 | viewport.y = 0; |
| 4522 | vkCmdSetViewport(command_buffer[0], 0, 1, &viewport); |
| 4523 | vkEndCommandBuffer(command_buffer[0]); |
| 4524 | } |
| 4525 | { |
| 4526 | VkCommandBufferBeginInfo begin_info{}; |
| 4527 | begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO; |
| 4528 | vkBeginCommandBuffer(command_buffer[1], &begin_info); |
| 4529 | |
| 4530 | VkViewport viewport{}; |
| 4531 | viewport.maxDepth = 1.0f; |
| 4532 | viewport.minDepth = 0.0f; |
| 4533 | viewport.width = 512; |
| 4534 | viewport.height = 512; |
| 4535 | viewport.x = 0; |
| 4536 | viewport.y = 0; |
| 4537 | vkCmdSetViewport(command_buffer[1], 0, 1, &viewport); |
| 4538 | vkEndCommandBuffer(command_buffer[1]); |
| 4539 | } |
| 4540 | { |
| 4541 | VkSubmitInfo submit_info{}; |
| 4542 | submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO; |
| 4543 | submit_info.commandBufferCount = 1; |
| 4544 | submit_info.pCommandBuffers = &command_buffer[0]; |
| 4545 | submit_info.signalSemaphoreCount = 1; |
| 4546 | submit_info.pSignalSemaphores = &semaphore; |
| 4547 | vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE); |
| 4548 | } |
| 4549 | { |
| 4550 | VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT}; |
| 4551 | VkSubmitInfo submit_info{}; |
| 4552 | submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO; |
| 4553 | submit_info.commandBufferCount = 1; |
| 4554 | submit_info.pCommandBuffers = &command_buffer[1]; |
| 4555 | submit_info.waitSemaphoreCount = 1; |
| 4556 | submit_info.pWaitSemaphores = &semaphore; |
| 4557 | submit_info.pWaitDstStageMask = flags; |
| 4558 | vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence); |
| 4559 | } |
| 4560 | |
| 4561 | vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX); |
| 4562 | vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX); |
| 4563 | |
| 4564 | vkDestroyFence(m_device->device(), fence, nullptr); |
| 4565 | vkDestroySemaphore(m_device->device(), semaphore, nullptr); |
| 4566 | vkFreeCommandBuffers(m_device->device(), command_pool, 2, |
| 4567 | &command_buffer[0]); |
| 4568 | vkDestroyCommandPool(m_device->device(), command_pool, NULL); |
| 4569 | |
| 4570 | m_errorMonitor->VerifyNotFound(); |
| 4571 | } |
| 4572 | |
Chris Forbes | 0f8126b | 2016-06-20 17:48:22 +1200 | [diff] [blame] | 4573 | #if 0 |
| 4574 | TEST_F(VkLayerTest, TwoQueuesEnsureCorrectRetirementWithWorkStolen) { |
| 4575 | if ((m_device->queue_props.empty()) || |
| 4576 | (m_device->queue_props[0].queueCount < 2)) { |
| 4577 | printf("Test requires two queues, skipping\n"); |
| 4578 | return; |
| 4579 | } |
| 4580 | |
| 4581 | VkResult err; |
| 4582 | |
| 4583 | m_errorMonitor->ExpectSuccess(); |
| 4584 | |
| 4585 | VkQueue q0 = m_device->m_queue; |
| 4586 | VkQueue q1 = nullptr; |
| 4587 | vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &q1); |
| 4588 | ASSERT_NE(q1, nullptr); |
| 4589 | |
| 4590 | // An (empty) command buffer. We must have work in the first submission -- |
| 4591 | // the layer treats unfenced work differently from fenced work. |
| 4592 | VkCommandPoolCreateInfo cpci = { VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO, nullptr, 0, 0 }; |
| 4593 | VkCommandPool pool; |
| 4594 | err = vkCreateCommandPool(m_device->device(), &cpci, nullptr, &pool); |
| 4595 | ASSERT_VK_SUCCESS(err); |
| 4596 | VkCommandBufferAllocateInfo cbai = { VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO, nullptr, |
| 4597 | pool, VK_COMMAND_BUFFER_LEVEL_PRIMARY, 1 |
| 4598 | }; |
| 4599 | VkCommandBuffer cb; |
| 4600 | err = vkAllocateCommandBuffers(m_device->device(), &cbai, &cb); |
| 4601 | ASSERT_VK_SUCCESS(err); |
| 4602 | VkCommandBufferBeginInfo cbbi = { VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO, nullptr, |
| 4603 | 0, nullptr |
| 4604 | }; |
| 4605 | err = vkBeginCommandBuffer(cb, &cbbi); |
| 4606 | ASSERT_VK_SUCCESS(err); |
| 4607 | err = vkEndCommandBuffer(cb); |
| 4608 | ASSERT_VK_SUCCESS(err); |
| 4609 | |
| 4610 | // A semaphore |
| 4611 | VkSemaphoreCreateInfo sci = { VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO, nullptr, 0 }; |
| 4612 | VkSemaphore s; |
| 4613 | err = vkCreateSemaphore(m_device->device(), &sci, nullptr, &s); |
| 4614 | ASSERT_VK_SUCCESS(err); |
| 4615 | |
| 4616 | // First submission, to q0 |
| 4617 | VkSubmitInfo s0 = { |
| 4618 | VK_STRUCTURE_TYPE_SUBMIT_INFO, nullptr, |
| 4619 | 0, nullptr, nullptr, |
| 4620 | 1, &cb, |
| 4621 | 1, &s |
| 4622 | }; |
| 4623 | |
| 4624 | err = vkQueueSubmit(q0, 1, &s0, VK_NULL_HANDLE); |
| 4625 | ASSERT_VK_SUCCESS(err); |
| 4626 | |
| 4627 | // Second submission, to q1, waiting on s |
| 4628 | VkFlags waitmask = VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT; // doesn't really matter what this value is. |
| 4629 | VkSubmitInfo s1 = { |
| 4630 | VK_STRUCTURE_TYPE_SUBMIT_INFO, nullptr, |
| 4631 | 1, &s, &waitmask, |
| 4632 | 0, nullptr, |
| 4633 | 0, nullptr |
| 4634 | }; |
| 4635 | |
| 4636 | err = vkQueueSubmit(q1, 1, &s1, VK_NULL_HANDLE); |
| 4637 | ASSERT_VK_SUCCESS(err); |
| 4638 | |
| 4639 | // Wait for q0 idle |
| 4640 | err = vkQueueWaitIdle(q0); |
| 4641 | ASSERT_VK_SUCCESS(err); |
| 4642 | |
| 4643 | // Command buffer should have been completed (it was on q0); reset the pool. |
| 4644 | vkFreeCommandBuffers(m_device->device(), pool, 1, &cb); |
| 4645 | |
| 4646 | m_errorMonitor->VerifyNotFound(); |
| 4647 | |
| 4648 | // Force device completely idle and clean up resources |
| 4649 | vkDeviceWaitIdle(m_device->device()); |
| 4650 | vkDestroyCommandPool(m_device->device(), pool, nullptr); |
| 4651 | vkDestroySemaphore(m_device->device(), s, nullptr); |
| 4652 | } |
| 4653 | #endif |
| 4654 | |
Mark Lobodzinski | c808d44 | 2016-04-14 10:57:23 -0600 | [diff] [blame] | 4655 | // This is a positive test. No errors should be generated. |
| 4656 | TEST_F(VkLayerTest, TwoQueueSubmitsSeparateQueuesWithSemaphoreAndOneFence) { |
| 4657 | |
| 4658 | TEST_DESCRIPTION("Two command buffers, each in a separate QueueSubmit call " |
| 4659 | "submitted on separate queues, the second having a fence, " |
| 4660 | "followed by a WaitForFences call."); |
| 4661 | |
Dustin Graves | 4845814 | 2016-04-29 16:11:55 -0600 | [diff] [blame] | 4662 | if ((m_device->queue_props.empty()) || |
| 4663 | (m_device->queue_props[0].queueCount < 2)) |
Tony Barbour | dc18b26 | 2016-04-22 14:49:48 -0600 | [diff] [blame] | 4664 | return; |
| 4665 | |
Mark Lobodzinski | c808d44 | 2016-04-14 10:57:23 -0600 | [diff] [blame] | 4666 | m_errorMonitor->ExpectSuccess(); |
| 4667 | |
| 4668 | VkFence fence; |
| 4669 | VkFenceCreateInfo fence_create_info{}; |
| 4670 | fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO; |
| 4671 | vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence); |
| 4672 | |
| 4673 | VkSemaphore semaphore; |
| 4674 | VkSemaphoreCreateInfo semaphore_create_info{}; |
| 4675 | semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO; |
| 4676 | vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, |
| 4677 | &semaphore); |
| 4678 | |
| 4679 | VkCommandPool command_pool; |
| 4680 | VkCommandPoolCreateInfo pool_create_info{}; |
| 4681 | pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO; |
| 4682 | pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_; |
| 4683 | pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT; |
| 4684 | vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, |
| 4685 | &command_pool); |
| 4686 | |
| 4687 | VkCommandBuffer command_buffer[2]; |
| 4688 | VkCommandBufferAllocateInfo command_buffer_allocate_info{}; |
| 4689 | command_buffer_allocate_info.sType = |
| 4690 | VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO; |
| 4691 | command_buffer_allocate_info.commandPool = command_pool; |
| 4692 | command_buffer_allocate_info.commandBufferCount = 2; |
| 4693 | command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY; |
| 4694 | vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, |
| 4695 | command_buffer); |
| 4696 | |
| 4697 | VkQueue queue = VK_NULL_HANDLE; |
| 4698 | vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, |
| 4699 | 1, &queue); |
| 4700 | |
| 4701 | |
| 4702 | { |
| 4703 | VkCommandBufferBeginInfo begin_info{}; |
| 4704 | begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO; |
| 4705 | vkBeginCommandBuffer(command_buffer[0], &begin_info); |
| 4706 | |
| 4707 | vkCmdPipelineBarrier(command_buffer[0], |
| 4708 | VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, |
| 4709 | VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, nullptr, |
| 4710 | 0, nullptr, 0, nullptr); |
| 4711 | |
| 4712 | VkViewport viewport{}; |
| 4713 | viewport.maxDepth = 1.0f; |
| 4714 | viewport.minDepth = 0.0f; |
| 4715 | viewport.width = 512; |
| 4716 | viewport.height = 512; |
| 4717 | viewport.x = 0; |
| 4718 | viewport.y = 0; |
| 4719 | vkCmdSetViewport(command_buffer[0], 0, 1, &viewport); |
| 4720 | vkEndCommandBuffer(command_buffer[0]); |
| 4721 | } |
| 4722 | { |
| 4723 | VkCommandBufferBeginInfo begin_info{}; |
| 4724 | begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO; |
| 4725 | vkBeginCommandBuffer(command_buffer[1], &begin_info); |
| 4726 | |
| 4727 | VkViewport viewport{}; |
| 4728 | viewport.maxDepth = 1.0f; |
| 4729 | viewport.minDepth = 0.0f; |
| 4730 | viewport.width = 512; |
| 4731 | viewport.height = 512; |
| 4732 | viewport.x = 0; |
| 4733 | viewport.y = 0; |
| 4734 | vkCmdSetViewport(command_buffer[1], 0, 1, &viewport); |
| 4735 | vkEndCommandBuffer(command_buffer[1]); |
| 4736 | } |
| 4737 | { |
| 4738 | VkSubmitInfo submit_info{}; |
| 4739 | submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO; |
| 4740 | submit_info.commandBufferCount = 1; |
| 4741 | submit_info.pCommandBuffers = &command_buffer[0]; |
| 4742 | submit_info.signalSemaphoreCount = 1; |
| 4743 | submit_info.pSignalSemaphores = &semaphore; |
| 4744 | vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE); |
| 4745 | } |
| 4746 | { |
| 4747 | VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT}; |
| 4748 | VkSubmitInfo submit_info{}; |
| 4749 | submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO; |
| 4750 | submit_info.commandBufferCount = 1; |
| 4751 | submit_info.pCommandBuffers = &command_buffer[1]; |
| 4752 | submit_info.waitSemaphoreCount = 1; |
| 4753 | submit_info.pWaitSemaphores = &semaphore; |
| 4754 | submit_info.pWaitDstStageMask = flags; |
| 4755 | vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence); |
| 4756 | } |
| 4757 | |
| 4758 | vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX); |
| 4759 | |
| 4760 | vkDestroyFence(m_device->device(), fence, nullptr); |
| 4761 | vkDestroySemaphore(m_device->device(), semaphore, nullptr); |
| 4762 | vkFreeCommandBuffers(m_device->device(), command_pool, 2, |
| 4763 | &command_buffer[0]); |
| 4764 | vkDestroyCommandPool(m_device->device(), command_pool, NULL); |
| 4765 | |
| 4766 | m_errorMonitor->VerifyNotFound(); |
| 4767 | } |
| 4768 | |
| 4769 | // This is a positive test. No errors should be generated. |
| 4770 | TEST_F(VkLayerTest, TwoQueueSubmitsOneQueueWithSemaphoreAndOneFence) { |
| 4771 | |
| 4772 | TEST_DESCRIPTION("Two command buffers, each in a separate QueueSubmit call " |
| 4773 | "on the same queue, sharing a signal/wait semaphore, the " |
| 4774 | "second having a fence, " |
| 4775 | "followed by a WaitForFences call."); |
| 4776 | |
| 4777 | m_errorMonitor->ExpectSuccess(); |
| 4778 | |
| 4779 | VkFence fence; |
| 4780 | VkFenceCreateInfo fence_create_info{}; |
| 4781 | fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO; |
| 4782 | vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence); |
| 4783 | |
| 4784 | VkSemaphore semaphore; |
| 4785 | VkSemaphoreCreateInfo semaphore_create_info{}; |
| 4786 | semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO; |
| 4787 | vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, |
| 4788 | &semaphore); |
| 4789 | |
| 4790 | VkCommandPool command_pool; |
| 4791 | VkCommandPoolCreateInfo pool_create_info{}; |
| 4792 | pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO; |
| 4793 | pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_; |
| 4794 | pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT; |
| 4795 | vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, |
| 4796 | &command_pool); |
| 4797 | |
| 4798 | VkCommandBuffer command_buffer[2]; |
| 4799 | VkCommandBufferAllocateInfo command_buffer_allocate_info{}; |
| 4800 | command_buffer_allocate_info.sType = |
| 4801 | VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO; |
| 4802 | command_buffer_allocate_info.commandPool = command_pool; |
| 4803 | command_buffer_allocate_info.commandBufferCount = 2; |
| 4804 | command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY; |
| 4805 | vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, |
| 4806 | command_buffer); |
| 4807 | |
| 4808 | { |
| 4809 | VkCommandBufferBeginInfo begin_info{}; |
| 4810 | begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO; |
| 4811 | vkBeginCommandBuffer(command_buffer[0], &begin_info); |
| 4812 | |
| 4813 | vkCmdPipelineBarrier(command_buffer[0], |
| 4814 | VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, |
| 4815 | VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, nullptr, |
| 4816 | 0, nullptr, 0, nullptr); |
| 4817 | |
| 4818 | VkViewport viewport{}; |
| 4819 | viewport.maxDepth = 1.0f; |
| 4820 | viewport.minDepth = 0.0f; |
| 4821 | viewport.width = 512; |
| 4822 | viewport.height = 512; |
| 4823 | viewport.x = 0; |
| 4824 | viewport.y = 0; |
| 4825 | vkCmdSetViewport(command_buffer[0], 0, 1, &viewport); |
| 4826 | vkEndCommandBuffer(command_buffer[0]); |
| 4827 | } |
| 4828 | { |
| 4829 | VkCommandBufferBeginInfo begin_info{}; |
| 4830 | begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO; |
| 4831 | vkBeginCommandBuffer(command_buffer[1], &begin_info); |
| 4832 | |
| 4833 | VkViewport viewport{}; |
| 4834 | viewport.maxDepth = 1.0f; |
| 4835 | viewport.minDepth = 0.0f; |
| 4836 | viewport.width = 512; |
| 4837 | viewport.height = 512; |
| 4838 | viewport.x = 0; |
| 4839 | viewport.y = 0; |
| 4840 | vkCmdSetViewport(command_buffer[1], 0, 1, &viewport); |
| 4841 | vkEndCommandBuffer(command_buffer[1]); |
| 4842 | } |
| 4843 | { |
| 4844 | VkSubmitInfo submit_info{}; |
| 4845 | submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO; |
| 4846 | submit_info.commandBufferCount = 1; |
| 4847 | submit_info.pCommandBuffers = &command_buffer[0]; |
| 4848 | submit_info.signalSemaphoreCount = 1; |
| 4849 | submit_info.pSignalSemaphores = &semaphore; |
| 4850 | vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE); |
| 4851 | } |
| 4852 | { |
| 4853 | VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT}; |
| 4854 | VkSubmitInfo submit_info{}; |
| 4855 | submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO; |
| 4856 | submit_info.commandBufferCount = 1; |
| 4857 | submit_info.pCommandBuffers = &command_buffer[1]; |
| 4858 | submit_info.waitSemaphoreCount = 1; |
| 4859 | submit_info.pWaitSemaphores = &semaphore; |
| 4860 | submit_info.pWaitDstStageMask = flags; |
| 4861 | vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence); |
| 4862 | } |
| 4863 | |
| 4864 | vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX); |
| 4865 | |
| 4866 | vkDestroyFence(m_device->device(), fence, nullptr); |
| 4867 | vkDestroySemaphore(m_device->device(), semaphore, nullptr); |
| 4868 | vkFreeCommandBuffers(m_device->device(), command_pool, 2, |
| 4869 | &command_buffer[0]); |
| 4870 | vkDestroyCommandPool(m_device->device(), command_pool, NULL); |
| 4871 | |
| 4872 | m_errorMonitor->VerifyNotFound(); |
| 4873 | } |
| 4874 | |
| 4875 | // This is a positive test. No errors should be generated. |
| 4876 | TEST_F(VkLayerTest, TwoQueueSubmitsOneQueueNullQueueSubmitWithFence) { |
| 4877 | |
| 4878 | TEST_DESCRIPTION( |
| 4879 | "Two command buffers, each in a separate QueueSubmit call " |
| 4880 | "on the same queue, no fences, followed by a third QueueSubmit with NO " |
| 4881 | "SubmitInfos but with a fence, followed by a WaitForFences call."); |
| 4882 | |
| 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 | VkCommandPool command_pool; |
| 4891 | VkCommandPoolCreateInfo pool_create_info{}; |
| 4892 | pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO; |
| 4893 | pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_; |
| 4894 | pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT; |
| 4895 | vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, |
| 4896 | &command_pool); |
| 4897 | |
| 4898 | VkCommandBuffer command_buffer[2]; |
| 4899 | VkCommandBufferAllocateInfo command_buffer_allocate_info{}; |
| 4900 | command_buffer_allocate_info.sType = |
| 4901 | VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO; |
| 4902 | command_buffer_allocate_info.commandPool = command_pool; |
| 4903 | command_buffer_allocate_info.commandBufferCount = 2; |
| 4904 | command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY; |
| 4905 | vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, |
| 4906 | command_buffer); |
| 4907 | |
| 4908 | { |
| 4909 | VkCommandBufferBeginInfo begin_info{}; |
| 4910 | begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO; |
| 4911 | vkBeginCommandBuffer(command_buffer[0], &begin_info); |
| 4912 | |
| 4913 | vkCmdPipelineBarrier(command_buffer[0], |
| 4914 | VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, |
| 4915 | VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, nullptr, |
| 4916 | 0, nullptr, 0, nullptr); |
| 4917 | |
| 4918 | VkViewport viewport{}; |
| 4919 | viewport.maxDepth = 1.0f; |
| 4920 | viewport.minDepth = 0.0f; |
| 4921 | viewport.width = 512; |
| 4922 | viewport.height = 512; |
| 4923 | viewport.x = 0; |
| 4924 | viewport.y = 0; |
| 4925 | vkCmdSetViewport(command_buffer[0], 0, 1, &viewport); |
| 4926 | vkEndCommandBuffer(command_buffer[0]); |
| 4927 | } |
| 4928 | { |
| 4929 | VkCommandBufferBeginInfo begin_info{}; |
| 4930 | begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO; |
| 4931 | vkBeginCommandBuffer(command_buffer[1], &begin_info); |
| 4932 | |
| 4933 | VkViewport viewport{}; |
| 4934 | viewport.maxDepth = 1.0f; |
| 4935 | viewport.minDepth = 0.0f; |
| 4936 | viewport.width = 512; |
| 4937 | viewport.height = 512; |
| 4938 | viewport.x = 0; |
| 4939 | viewport.y = 0; |
| 4940 | vkCmdSetViewport(command_buffer[1], 0, 1, &viewport); |
| 4941 | vkEndCommandBuffer(command_buffer[1]); |
| 4942 | } |
| 4943 | { |
| 4944 | VkSubmitInfo submit_info{}; |
| 4945 | submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO; |
| 4946 | submit_info.commandBufferCount = 1; |
| 4947 | submit_info.pCommandBuffers = &command_buffer[0]; |
| 4948 | submit_info.signalSemaphoreCount = 0; |
| 4949 | submit_info.pSignalSemaphores = VK_NULL_HANDLE; |
| 4950 | vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE); |
| 4951 | } |
| 4952 | { |
| 4953 | VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT}; |
| 4954 | VkSubmitInfo submit_info{}; |
| 4955 | submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO; |
| 4956 | submit_info.commandBufferCount = 1; |
| 4957 | submit_info.pCommandBuffers = &command_buffer[1]; |
| 4958 | submit_info.waitSemaphoreCount = 0; |
| 4959 | submit_info.pWaitSemaphores = VK_NULL_HANDLE; |
| 4960 | submit_info.pWaitDstStageMask = flags; |
| 4961 | vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE); |
| 4962 | } |
| 4963 | |
| 4964 | vkQueueSubmit(m_device->m_queue, 0, NULL, fence); |
| 4965 | |
Mike Stroyan | cd1c3e5 | 2016-06-21 09:20:01 -0600 | [diff] [blame] | 4966 | VkResult err = |
| 4967 | vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX); |
| 4968 | ASSERT_VK_SUCCESS(err); |
Mark Lobodzinski | c808d44 | 2016-04-14 10:57:23 -0600 | [diff] [blame] | 4969 | |
| 4970 | vkDestroyFence(m_device->device(), fence, nullptr); |
| 4971 | vkFreeCommandBuffers(m_device->device(), command_pool, 2, |
| 4972 | &command_buffer[0]); |
| 4973 | vkDestroyCommandPool(m_device->device(), command_pool, NULL); |
| 4974 | |
| 4975 | m_errorMonitor->VerifyNotFound(); |
| 4976 | } |
| 4977 | |
| 4978 | // This is a positive test. No errors should be generated. |
| 4979 | TEST_F(VkLayerTest, TwoQueueSubmitsOneQueueOneFence) { |
| 4980 | |
| 4981 | TEST_DESCRIPTION("Two command buffers, each in a separate QueueSubmit call " |
| 4982 | "on the same queue, the second having a fence, followed " |
| 4983 | "by a WaitForFences call."); |
| 4984 | |
| 4985 | m_errorMonitor->ExpectSuccess(); |
| 4986 | |
| 4987 | VkFence fence; |
| 4988 | VkFenceCreateInfo fence_create_info{}; |
| 4989 | fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO; |
| 4990 | vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence); |
| 4991 | |
| 4992 | VkCommandPool command_pool; |
| 4993 | VkCommandPoolCreateInfo pool_create_info{}; |
| 4994 | pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO; |
| 4995 | pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_; |
| 4996 | pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT; |
| 4997 | vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, |
| 4998 | &command_pool); |
| 4999 | |
| 5000 | VkCommandBuffer command_buffer[2]; |
| 5001 | VkCommandBufferAllocateInfo command_buffer_allocate_info{}; |
| 5002 | command_buffer_allocate_info.sType = |
| 5003 | VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO; |
| 5004 | command_buffer_allocate_info.commandPool = command_pool; |
| 5005 | command_buffer_allocate_info.commandBufferCount = 2; |
| 5006 | command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY; |
| 5007 | vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, |
| 5008 | command_buffer); |
| 5009 | |
| 5010 | { |
| 5011 | VkCommandBufferBeginInfo begin_info{}; |
| 5012 | begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO; |
| 5013 | vkBeginCommandBuffer(command_buffer[0], &begin_info); |
| 5014 | |
| 5015 | vkCmdPipelineBarrier(command_buffer[0], |
| 5016 | VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, |
| 5017 | VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, nullptr, |
| 5018 | 0, nullptr, 0, nullptr); |
| 5019 | |
| 5020 | VkViewport viewport{}; |
| 5021 | viewport.maxDepth = 1.0f; |
| 5022 | viewport.minDepth = 0.0f; |
| 5023 | viewport.width = 512; |
| 5024 | viewport.height = 512; |
| 5025 | viewport.x = 0; |
| 5026 | viewport.y = 0; |
| 5027 | vkCmdSetViewport(command_buffer[0], 0, 1, &viewport); |
| 5028 | vkEndCommandBuffer(command_buffer[0]); |
| 5029 | } |
| 5030 | { |
| 5031 | VkCommandBufferBeginInfo begin_info{}; |
| 5032 | begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO; |
| 5033 | vkBeginCommandBuffer(command_buffer[1], &begin_info); |
| 5034 | |
| 5035 | VkViewport viewport{}; |
| 5036 | viewport.maxDepth = 1.0f; |
| 5037 | viewport.minDepth = 0.0f; |
| 5038 | viewport.width = 512; |
| 5039 | viewport.height = 512; |
| 5040 | viewport.x = 0; |
| 5041 | viewport.y = 0; |
| 5042 | vkCmdSetViewport(command_buffer[1], 0, 1, &viewport); |
| 5043 | vkEndCommandBuffer(command_buffer[1]); |
| 5044 | } |
| 5045 | { |
| 5046 | VkSubmitInfo submit_info{}; |
| 5047 | submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO; |
| 5048 | submit_info.commandBufferCount = 1; |
| 5049 | submit_info.pCommandBuffers = &command_buffer[0]; |
| 5050 | submit_info.signalSemaphoreCount = 0; |
| 5051 | submit_info.pSignalSemaphores = VK_NULL_HANDLE; |
| 5052 | vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE); |
| 5053 | } |
| 5054 | { |
| 5055 | VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT}; |
| 5056 | VkSubmitInfo submit_info{}; |
| 5057 | submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO; |
| 5058 | submit_info.commandBufferCount = 1; |
| 5059 | submit_info.pCommandBuffers = &command_buffer[1]; |
| 5060 | submit_info.waitSemaphoreCount = 0; |
| 5061 | submit_info.pWaitSemaphores = VK_NULL_HANDLE; |
| 5062 | submit_info.pWaitDstStageMask = flags; |
| 5063 | vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence); |
| 5064 | } |
| 5065 | |
| 5066 | vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX); |
| 5067 | |
| 5068 | vkDestroyFence(m_device->device(), fence, nullptr); |
| 5069 | vkFreeCommandBuffers(m_device->device(), command_pool, 2, |
| 5070 | &command_buffer[0]); |
| 5071 | vkDestroyCommandPool(m_device->device(), command_pool, NULL); |
| 5072 | |
| 5073 | m_errorMonitor->VerifyNotFound(); |
| 5074 | } |
| 5075 | |
| 5076 | // This is a positive test. No errors should be generated. |
| 5077 | TEST_F(VkLayerTest, TwoSubmitInfosWithSemaphoreOneQueueSubmitsOneFence) { |
| 5078 | |
| 5079 | TEST_DESCRIPTION( |
| 5080 | "Two command buffers each in a separate SubmitInfo sent in a single " |
| 5081 | "QueueSubmit call followed by a WaitForFences call."); |
| 5082 | |
| 5083 | m_errorMonitor->ExpectSuccess(); |
| 5084 | |
| 5085 | VkFence fence; |
| 5086 | VkFenceCreateInfo fence_create_info{}; |
| 5087 | fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO; |
| 5088 | vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence); |
| 5089 | |
| 5090 | VkSemaphore semaphore; |
| 5091 | VkSemaphoreCreateInfo semaphore_create_info{}; |
| 5092 | semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO; |
| 5093 | vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, |
| 5094 | &semaphore); |
| 5095 | |
| 5096 | VkCommandPool command_pool; |
| 5097 | VkCommandPoolCreateInfo pool_create_info{}; |
| 5098 | pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO; |
| 5099 | pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_; |
| 5100 | pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT; |
| 5101 | vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, |
| 5102 | &command_pool); |
| 5103 | |
| 5104 | VkCommandBuffer command_buffer[2]; |
| 5105 | VkCommandBufferAllocateInfo command_buffer_allocate_info{}; |
| 5106 | command_buffer_allocate_info.sType = |
| 5107 | VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO; |
| 5108 | command_buffer_allocate_info.commandPool = command_pool; |
| 5109 | command_buffer_allocate_info.commandBufferCount = 2; |
| 5110 | command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY; |
| 5111 | vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, |
| 5112 | command_buffer); |
| 5113 | |
| 5114 | { |
| 5115 | VkCommandBufferBeginInfo begin_info{}; |
| 5116 | begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO; |
| 5117 | vkBeginCommandBuffer(command_buffer[0], &begin_info); |
| 5118 | |
| 5119 | vkCmdPipelineBarrier(command_buffer[0], |
| 5120 | VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, |
| 5121 | VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, nullptr, |
| 5122 | 0, nullptr, 0, nullptr); |
| 5123 | |
| 5124 | VkViewport viewport{}; |
| 5125 | viewport.maxDepth = 1.0f; |
| 5126 | viewport.minDepth = 0.0f; |
| 5127 | viewport.width = 512; |
| 5128 | viewport.height = 512; |
| 5129 | viewport.x = 0; |
| 5130 | viewport.y = 0; |
| 5131 | vkCmdSetViewport(command_buffer[0], 0, 1, &viewport); |
| 5132 | vkEndCommandBuffer(command_buffer[0]); |
| 5133 | } |
| 5134 | { |
| 5135 | VkCommandBufferBeginInfo begin_info{}; |
| 5136 | begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO; |
| 5137 | vkBeginCommandBuffer(command_buffer[1], &begin_info); |
| 5138 | |
| 5139 | VkViewport viewport{}; |
| 5140 | viewport.maxDepth = 1.0f; |
| 5141 | viewport.minDepth = 0.0f; |
| 5142 | viewport.width = 512; |
| 5143 | viewport.height = 512; |
| 5144 | viewport.x = 0; |
| 5145 | viewport.y = 0; |
| 5146 | vkCmdSetViewport(command_buffer[1], 0, 1, &viewport); |
| 5147 | vkEndCommandBuffer(command_buffer[1]); |
| 5148 | } |
| 5149 | { |
| 5150 | VkSubmitInfo submit_info[2]; |
| 5151 | VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT}; |
| 5152 | |
| 5153 | submit_info[0].sType = VK_STRUCTURE_TYPE_SUBMIT_INFO; |
| 5154 | submit_info[0].pNext = NULL; |
| 5155 | submit_info[0].commandBufferCount = 1; |
| 5156 | submit_info[0].pCommandBuffers = &command_buffer[0]; |
| 5157 | submit_info[0].signalSemaphoreCount = 1; |
| 5158 | submit_info[0].pSignalSemaphores = &semaphore; |
| 5159 | submit_info[0].waitSemaphoreCount = 0; |
| 5160 | submit_info[0].pWaitSemaphores = NULL; |
| 5161 | submit_info[0].pWaitDstStageMask = 0; |
| 5162 | |
| 5163 | submit_info[1].sType = VK_STRUCTURE_TYPE_SUBMIT_INFO; |
| 5164 | submit_info[1].pNext = NULL; |
| 5165 | submit_info[1].commandBufferCount = 1; |
| 5166 | submit_info[1].pCommandBuffers = &command_buffer[1]; |
| 5167 | submit_info[1].waitSemaphoreCount = 1; |
| 5168 | submit_info[1].pWaitSemaphores = &semaphore; |
| 5169 | submit_info[1].pWaitDstStageMask = flags; |
| 5170 | submit_info[1].signalSemaphoreCount = 0; |
| 5171 | submit_info[1].pSignalSemaphores = NULL; |
| 5172 | vkQueueSubmit(m_device->m_queue, 2, &submit_info[0], fence); |
| 5173 | } |
| 5174 | |
| 5175 | vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX); |
| 5176 | |
| 5177 | vkDestroyFence(m_device->device(), fence, nullptr); |
| 5178 | vkFreeCommandBuffers(m_device->device(), command_pool, 2, |
| 5179 | &command_buffer[0]); |
| 5180 | vkDestroyCommandPool(m_device->device(), command_pool, NULL); |
Tony Barbour | df4c004 | 2016-06-01 15:55:43 -0600 | [diff] [blame] | 5181 | vkDestroySemaphore(m_device->device(), semaphore, nullptr); |
Mark Lobodzinski | c808d44 | 2016-04-14 10:57:23 -0600 | [diff] [blame] | 5182 | |
| 5183 | m_errorMonitor->VerifyNotFound(); |
| 5184 | } |
| 5185 | |
Tobin Ehlis | b1a8799 | 2016-05-25 16:42:47 -0600 | [diff] [blame] | 5186 | TEST_F(VkLayerTest, DynamicDepthBiasNotBound) { |
Tobin Ehlis | a5200ef | 2016-05-03 10:34:08 -0600 | [diff] [blame] | 5187 | TEST_DESCRIPTION( |
Tobin Ehlis | b1a8799 | 2016-05-25 16:42:47 -0600 | [diff] [blame] | 5188 | "Run a simple draw calls to validate failure when Depth Bias dynamic " |
| 5189 | "state is required but not correctly bound."); |
| 5190 | |
| 5191 | // Dynamic depth bias |
| 5192 | m_errorMonitor->SetDesiredFailureMsg( |
| 5193 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 5194 | "Dynamic depth bias state not set for this command buffer"); |
| 5195 | VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, |
| 5196 | BsoFailDepthBias); |
| 5197 | m_errorMonitor->VerifyFound(); |
| 5198 | } |
| 5199 | |
| 5200 | TEST_F(VkLayerTest, DynamicLineWidthNotBound) { |
| 5201 | TEST_DESCRIPTION( |
| 5202 | "Run a simple draw calls to validate failure when Line Width dynamic " |
| 5203 | "state is required but not correctly bound."); |
Tobin Ehlis | a5200ef | 2016-05-03 10:34:08 -0600 | [diff] [blame] | 5204 | |
| 5205 | // Dynamic line width |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5206 | m_errorMonitor->SetDesiredFailureMsg( |
| 5207 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 5208 | "Dynamic line width state not set for this command buffer"); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5209 | VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, |
| 5210 | BsoFailLineWidth); |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 5211 | m_errorMonitor->VerifyFound(); |
Tobin Ehlis | b1a8799 | 2016-05-25 16:42:47 -0600 | [diff] [blame] | 5212 | } |
| 5213 | |
| 5214 | TEST_F(VkLayerTest, DynamicViewportNotBound) { |
| 5215 | TEST_DESCRIPTION( |
| 5216 | "Run a simple draw calls to validate failure when Viewport dynamic " |
| 5217 | "state is required but not correctly bound."); |
| 5218 | |
Tobin Ehlis | a5200ef | 2016-05-03 10:34:08 -0600 | [diff] [blame] | 5219 | // Dynamic viewport state |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5220 | m_errorMonitor->SetDesiredFailureMsg( |
| 5221 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 5222 | "Dynamic viewport state not set for this command buffer"); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5223 | VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, |
| 5224 | BsoFailViewport); |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 5225 | m_errorMonitor->VerifyFound(); |
Tobin Ehlis | b1a8799 | 2016-05-25 16:42:47 -0600 | [diff] [blame] | 5226 | } |
| 5227 | |
| 5228 | TEST_F(VkLayerTest, DynamicScissorNotBound) { |
| 5229 | TEST_DESCRIPTION( |
| 5230 | "Run a simple draw calls to validate failure when Scissor dynamic " |
| 5231 | "state is required but not correctly bound."); |
| 5232 | |
Tobin Ehlis | a5200ef | 2016-05-03 10:34:08 -0600 | [diff] [blame] | 5233 | // Dynamic scissor state |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5234 | m_errorMonitor->SetDesiredFailureMsg( |
| 5235 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 5236 | "Dynamic scissor state not set for this command buffer"); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5237 | VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, |
| 5238 | BsoFailScissor); |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 5239 | m_errorMonitor->VerifyFound(); |
Tobin Ehlis | b1a8799 | 2016-05-25 16:42:47 -0600 | [diff] [blame] | 5240 | } |
| 5241 | |
Tobin Ehlis | 21c8835 | 2016-05-26 06:15:45 -0600 | [diff] [blame] | 5242 | TEST_F(VkLayerTest, DynamiBlendConstantsNotBound) { |
Tobin Ehlis | b1a8799 | 2016-05-25 16:42:47 -0600 | [diff] [blame] | 5243 | TEST_DESCRIPTION( |
Tobin Ehlis | 21c8835 | 2016-05-26 06:15:45 -0600 | [diff] [blame] | 5244 | "Run a simple draw calls to validate failure when Blend Constants " |
| 5245 | "dynamic state is required but not correctly bound."); |
| 5246 | // Dynamic blend constant state |
| 5247 | m_errorMonitor->SetDesiredFailureMsg( |
| 5248 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 5249 | "Dynamic blend constants state not set for this command buffer"); |
| 5250 | VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, |
| 5251 | BsoFailBlend); |
| 5252 | m_errorMonitor->VerifyFound(); |
| 5253 | } |
| 5254 | |
| 5255 | TEST_F(VkLayerTest, DynamicDepthBoundsNotBound) { |
| 5256 | TEST_DESCRIPTION( |
| 5257 | "Run a simple draw calls to validate failure when Depth Bounds dynamic " |
Tobin Ehlis | b1a8799 | 2016-05-25 16:42:47 -0600 | [diff] [blame] | 5258 | "state is required but not correctly bound."); |
Tobin Ehlis | 21c8835 | 2016-05-26 06:15:45 -0600 | [diff] [blame] | 5259 | if (!m_device->phy().features().depthBounds) { |
| 5260 | printf("Device does not support depthBounds test; skipped.\n"); |
| 5261 | return; |
| 5262 | } |
| 5263 | // Dynamic depth bounds |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5264 | m_errorMonitor->SetDesiredFailureMsg( |
| 5265 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 5266 | "Dynamic depth bounds state not set for this command buffer"); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5267 | VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, |
| 5268 | BsoFailDepthBounds); |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 5269 | m_errorMonitor->VerifyFound(); |
Tobin Ehlis | b1a8799 | 2016-05-25 16:42:47 -0600 | [diff] [blame] | 5270 | } |
| 5271 | |
| 5272 | TEST_F(VkLayerTest, DynamicStencilReadNotBound) { |
| 5273 | TEST_DESCRIPTION( |
| 5274 | "Run a simple draw calls to validate failure when Stencil Read dynamic " |
| 5275 | "state is required but not correctly bound."); |
Tobin Ehlis | a5200ef | 2016-05-03 10:34:08 -0600 | [diff] [blame] | 5276 | // Dynamic stencil read mask |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5277 | m_errorMonitor->SetDesiredFailureMsg( |
| 5278 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 5279 | "Dynamic stencil read mask state not set for this command buffer"); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5280 | VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, |
| 5281 | BsoFailStencilReadMask); |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 5282 | m_errorMonitor->VerifyFound(); |
Tobin Ehlis | b1a8799 | 2016-05-25 16:42:47 -0600 | [diff] [blame] | 5283 | } |
| 5284 | |
| 5285 | TEST_F(VkLayerTest, DynamicStencilWriteNotBound) { |
| 5286 | TEST_DESCRIPTION( |
| 5287 | "Run a simple draw calls to validate failure when Stencil Write dynamic" |
| 5288 | " state is required but not correctly bound."); |
Tobin Ehlis | a5200ef | 2016-05-03 10:34:08 -0600 | [diff] [blame] | 5289 | // Dynamic stencil write mask |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5290 | m_errorMonitor->SetDesiredFailureMsg( |
| 5291 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 5292 | "Dynamic stencil write mask state not set for this command buffer"); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5293 | VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, |
| 5294 | BsoFailStencilWriteMask); |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 5295 | m_errorMonitor->VerifyFound(); |
Tobin Ehlis | b1a8799 | 2016-05-25 16:42:47 -0600 | [diff] [blame] | 5296 | } |
| 5297 | |
| 5298 | TEST_F(VkLayerTest, DynamicStencilRefNotBound) { |
| 5299 | TEST_DESCRIPTION( |
| 5300 | "Run a simple draw calls to validate failure when Stencil Ref dynamic " |
| 5301 | "state is required but not correctly bound."); |
Tobin Ehlis | a5200ef | 2016-05-03 10:34:08 -0600 | [diff] [blame] | 5302 | // Dynamic stencil reference |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5303 | m_errorMonitor->SetDesiredFailureMsg( |
| 5304 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 5305 | "Dynamic stencil reference state not set for this command buffer"); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5306 | VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, |
| 5307 | BsoFailStencilReference); |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 5308 | m_errorMonitor->VerifyFound(); |
Tobin Ehlis | 963a404 | 2015-09-29 08:18:34 -0600 | [diff] [blame] | 5309 | } |
| 5310 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5311 | TEST_F(VkLayerTest, CommandBufferTwoSubmits) { |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5312 | m_errorMonitor->SetDesiredFailureMsg( |
| 5313 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 5314 | "was begun w/ VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT set, but has " |
| 5315 | "been submitted"); |
Tobin Ehlis | 59278bf | 2015-08-18 07:10:58 -0600 | [diff] [blame] | 5316 | |
Tobin Ehlis | 59278bf | 2015-08-18 07:10:58 -0600 | [diff] [blame] | 5317 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 5318 | ASSERT_NO_FATAL_FAILURE(InitViewport()); |
| 5319 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 5320 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5321 | // We luck out b/c by default the framework creates CB w/ the |
| 5322 | // VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT set |
Tobin Ehlis | 59278bf | 2015-08-18 07:10:58 -0600 | [diff] [blame] | 5323 | BeginCommandBuffer(); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5324 | m_commandBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color, |
| 5325 | m_stencil_clear_color, NULL); |
Tobin Ehlis | 59278bf | 2015-08-18 07:10:58 -0600 | [diff] [blame] | 5326 | EndCommandBuffer(); |
| 5327 | |
Tobin Ehlis | 59278bf | 2015-08-18 07:10:58 -0600 | [diff] [blame] | 5328 | // Bypass framework since it does the waits automatically |
| 5329 | VkResult err = VK_SUCCESS; |
Courtney Goeltzenleuchter | 806c700 | 2015-10-27 11:22:14 -0600 | [diff] [blame] | 5330 | VkSubmitInfo submit_info; |
Chia-I Wu | f9be13c | 2015-10-26 20:37:06 +0800 | [diff] [blame] | 5331 | submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO; |
| 5332 | submit_info.pNext = NULL; |
Chia-I Wu | d50a7d7 | 2015-10-26 20:48:51 +0800 | [diff] [blame] | 5333 | submit_info.waitSemaphoreCount = 0; |
Courtney Goeltzenleuchter | 806c700 | 2015-10-27 11:22:14 -0600 | [diff] [blame] | 5334 | submit_info.pWaitSemaphores = NULL; |
Jon Ashburn | 7f9716c | 2015-12-30 16:42:50 -0700 | [diff] [blame] | 5335 | submit_info.pWaitDstStageMask = NULL; |
Chia-I Wu | d50a7d7 | 2015-10-26 20:48:51 +0800 | [diff] [blame] | 5336 | submit_info.commandBufferCount = 1; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 5337 | submit_info.pCommandBuffers = &m_commandBuffer->handle(); |
Chia-I Wu | d50a7d7 | 2015-10-26 20:48:51 +0800 | [diff] [blame] | 5338 | submit_info.signalSemaphoreCount = 0; |
Courtney Goeltzenleuchter | 806c700 | 2015-10-27 11:22:14 -0600 | [diff] [blame] | 5339 | submit_info.pSignalSemaphores = NULL; |
| 5340 | |
Chris Forbes | 40028e2 | 2016-06-13 09:59:34 +1200 | [diff] [blame] | 5341 | err = vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5342 | ASSERT_VK_SUCCESS(err); |
Tobin Ehlis | 59278bf | 2015-08-18 07:10:58 -0600 | [diff] [blame] | 5343 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5344 | // Cause validation error by re-submitting cmd buffer that should only be |
| 5345 | // submitted once |
Chris Forbes | 40028e2 | 2016-06-13 09:59:34 +1200 | [diff] [blame] | 5346 | err = vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE); |
Tobin Ehlis | 59278bf | 2015-08-18 07:10:58 -0600 | [diff] [blame] | 5347 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 5348 | m_errorMonitor->VerifyFound(); |
Tobin Ehlis | 59278bf | 2015-08-18 07:10:58 -0600 | [diff] [blame] | 5349 | } |
| 5350 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5351 | TEST_F(VkLayerTest, AllocDescriptorFromEmptyPool) { |
Tobin Ehlis | f93f1e3 | 2015-10-20 16:16:04 -0600 | [diff] [blame] | 5352 | // Initiate Draw w/o a PSO bound |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5353 | VkResult err; |
Tobin Ehlis | f93f1e3 | 2015-10-20 16:16:04 -0600 | [diff] [blame] | 5354 | |
Courtney Goeltzenleuchter | 7415d5a | 2015-12-09 15:48:16 -0700 | [diff] [blame] | 5355 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5356 | "Unable to allocate 1 descriptors of " |
| 5357 | "type " |
| 5358 | "VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER "); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 5359 | |
Tobin Ehlis | f93f1e3 | 2015-10-20 16:16:04 -0600 | [diff] [blame] | 5360 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 5361 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
Tobin Ehlis | f93f1e3 | 2015-10-20 16:16:04 -0600 | [diff] [blame] | 5362 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5363 | // Create Pool w/ 1 Sampler descriptor, but try to alloc Uniform Buffer |
| 5364 | // descriptor from it |
Chia-I Wu | 1b99bb2 | 2015-10-27 19:25:11 +0800 | [diff] [blame] | 5365 | VkDescriptorPoolSize ds_type_count = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5366 | ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLER; |
| 5367 | ds_type_count.descriptorCount = 1; |
Tobin Ehlis | f93f1e3 | 2015-10-20 16:16:04 -0600 | [diff] [blame] | 5368 | |
| 5369 | VkDescriptorPoolCreateInfo ds_pool_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5370 | ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO; |
| 5371 | ds_pool_ci.pNext = NULL; |
| 5372 | ds_pool_ci.flags = 0; |
| 5373 | ds_pool_ci.maxSets = 1; |
| 5374 | ds_pool_ci.poolSizeCount = 1; |
| 5375 | ds_pool_ci.pPoolSizes = &ds_type_count; |
Tobin Ehlis | f93f1e3 | 2015-10-20 16:16:04 -0600 | [diff] [blame] | 5376 | |
| 5377 | VkDescriptorPool ds_pool; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5378 | err = |
| 5379 | vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool); |
Tobin Ehlis | f93f1e3 | 2015-10-20 16:16:04 -0600 | [diff] [blame] | 5380 | ASSERT_VK_SUCCESS(err); |
| 5381 | |
| 5382 | VkDescriptorSetLayoutBinding dsl_binding = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5383 | dsl_binding.binding = 0; |
| 5384 | dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 5385 | dsl_binding.descriptorCount = 1; |
| 5386 | dsl_binding.stageFlags = VK_SHADER_STAGE_ALL; |
| 5387 | dsl_binding.pImmutableSamplers = NULL; |
Tobin Ehlis | f93f1e3 | 2015-10-20 16:16:04 -0600 | [diff] [blame] | 5388 | |
| 5389 | VkDescriptorSetLayoutCreateInfo ds_layout_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5390 | ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO; |
| 5391 | ds_layout_ci.pNext = NULL; |
| 5392 | ds_layout_ci.bindingCount = 1; |
| 5393 | ds_layout_ci.pBindings = &dsl_binding; |
Tobin Ehlis | f93f1e3 | 2015-10-20 16:16:04 -0600 | [diff] [blame] | 5394 | |
| 5395 | VkDescriptorSetLayout ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5396 | err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, |
| 5397 | &ds_layout); |
Tobin Ehlis | f93f1e3 | 2015-10-20 16:16:04 -0600 | [diff] [blame] | 5398 | ASSERT_VK_SUCCESS(err); |
| 5399 | |
| 5400 | VkDescriptorSet descriptorSet; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 5401 | VkDescriptorSetAllocateInfo alloc_info = {}; |
Chia-I Wu | 00ce540 | 2015-11-10 16:21:09 +0800 | [diff] [blame] | 5402 | alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO; |
Jon Ashburn | f19916e | 2016-01-11 13:12:43 -0700 | [diff] [blame] | 5403 | alloc_info.descriptorSetCount = 1; |
Courtney Goeltzenleuchter | bee18a9 | 2015-10-23 14:21:05 -0600 | [diff] [blame] | 5404 | alloc_info.descriptorPool = ds_pool; |
| 5405 | alloc_info.pSetLayouts = &ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5406 | err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, |
| 5407 | &descriptorSet); |
Tobin Ehlis | f93f1e3 | 2015-10-20 16:16:04 -0600 | [diff] [blame] | 5408 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 5409 | m_errorMonitor->VerifyFound(); |
Tobin Ehlis | f93f1e3 | 2015-10-20 16:16:04 -0600 | [diff] [blame] | 5410 | |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 5411 | vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL); |
| 5412 | vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL); |
Tobin Ehlis | f93f1e3 | 2015-10-20 16:16:04 -0600 | [diff] [blame] | 5413 | } |
| 5414 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5415 | TEST_F(VkLayerTest, FreeDescriptorFromOneShotPool) { |
| 5416 | VkResult err; |
Tobin Ehlis | e735c69 | 2015-10-08 13:13:50 -0600 | [diff] [blame] | 5417 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5418 | m_errorMonitor->SetDesiredFailureMsg( |
| 5419 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 5420 | "It is invalid to call vkFreeDescriptorSets() with a pool created " |
| 5421 | "without setting VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT."); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 5422 | |
Tobin Ehlis | e735c69 | 2015-10-08 13:13:50 -0600 | [diff] [blame] | 5423 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 5424 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
Tobin Ehlis | e735c69 | 2015-10-08 13:13:50 -0600 | [diff] [blame] | 5425 | |
Chia-I Wu | 1b99bb2 | 2015-10-27 19:25:11 +0800 | [diff] [blame] | 5426 | VkDescriptorPoolSize ds_type_count = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5427 | ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 5428 | ds_type_count.descriptorCount = 1; |
Tobin Ehlis | e735c69 | 2015-10-08 13:13:50 -0600 | [diff] [blame] | 5429 | |
| 5430 | VkDescriptorPoolCreateInfo ds_pool_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5431 | ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO; |
| 5432 | ds_pool_ci.pNext = NULL; |
| 5433 | ds_pool_ci.maxSets = 1; |
| 5434 | ds_pool_ci.poolSizeCount = 1; |
| 5435 | ds_pool_ci.flags = 0; |
| 5436 | // Not specifying VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT means |
| 5437 | // app can only call vkResetDescriptorPool on this pool.; |
| 5438 | ds_pool_ci.pPoolSizes = &ds_type_count; |
Tobin Ehlis | e735c69 | 2015-10-08 13:13:50 -0600 | [diff] [blame] | 5439 | |
| 5440 | VkDescriptorPool ds_pool; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5441 | err = |
| 5442 | vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool); |
Tobin Ehlis | e735c69 | 2015-10-08 13:13:50 -0600 | [diff] [blame] | 5443 | ASSERT_VK_SUCCESS(err); |
| 5444 | |
| 5445 | VkDescriptorSetLayoutBinding dsl_binding = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5446 | dsl_binding.binding = 0; |
| 5447 | dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 5448 | dsl_binding.descriptorCount = 1; |
| 5449 | dsl_binding.stageFlags = VK_SHADER_STAGE_ALL; |
| 5450 | dsl_binding.pImmutableSamplers = NULL; |
Tobin Ehlis | e735c69 | 2015-10-08 13:13:50 -0600 | [diff] [blame] | 5451 | |
| 5452 | VkDescriptorSetLayoutCreateInfo ds_layout_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5453 | ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO; |
| 5454 | ds_layout_ci.pNext = NULL; |
| 5455 | ds_layout_ci.bindingCount = 1; |
| 5456 | ds_layout_ci.pBindings = &dsl_binding; |
Tobin Ehlis | e735c69 | 2015-10-08 13:13:50 -0600 | [diff] [blame] | 5457 | |
| 5458 | VkDescriptorSetLayout ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5459 | err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, |
| 5460 | &ds_layout); |
Tobin Ehlis | e735c69 | 2015-10-08 13:13:50 -0600 | [diff] [blame] | 5461 | ASSERT_VK_SUCCESS(err); |
| 5462 | |
| 5463 | VkDescriptorSet descriptorSet; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 5464 | VkDescriptorSetAllocateInfo alloc_info = {}; |
Chia-I Wu | 00ce540 | 2015-11-10 16:21:09 +0800 | [diff] [blame] | 5465 | alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO; |
Jon Ashburn | f19916e | 2016-01-11 13:12:43 -0700 | [diff] [blame] | 5466 | alloc_info.descriptorSetCount = 1; |
Courtney Goeltzenleuchter | bee18a9 | 2015-10-23 14:21:05 -0600 | [diff] [blame] | 5467 | alloc_info.descriptorPool = ds_pool; |
| 5468 | alloc_info.pSetLayouts = &ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5469 | err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, |
| 5470 | &descriptorSet); |
Tobin Ehlis | e735c69 | 2015-10-08 13:13:50 -0600 | [diff] [blame] | 5471 | ASSERT_VK_SUCCESS(err); |
| 5472 | |
| 5473 | err = vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptorSet); |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 5474 | m_errorMonitor->VerifyFound(); |
Tobin Ehlis | e735c69 | 2015-10-08 13:13:50 -0600 | [diff] [blame] | 5475 | |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 5476 | vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL); |
| 5477 | vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL); |
Tobin Ehlis | e735c69 | 2015-10-08 13:13:50 -0600 | [diff] [blame] | 5478 | } |
| 5479 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5480 | TEST_F(VkLayerTest, InvalidDescriptorPool) { |
Karl Schultz | bdb7595 | 2016-04-19 11:36:49 -0600 | [diff] [blame] | 5481 | // Attempt to clear Descriptor Pool with bad object. |
| 5482 | // ObjectTracker should catch this. |
| 5483 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 5484 | "Invalid VkDescriptorPool Object 0xbaad6001"); |
Mark Lobodzinski | 02bf89d | 2016-05-10 14:45:13 -0600 | [diff] [blame] | 5485 | uint64_t fake_pool_handle = 0xbaad6001; |
| 5486 | VkDescriptorPool bad_pool = reinterpret_cast<VkDescriptorPool &>(fake_pool_handle); |
| 5487 | vkResetDescriptorPool(device(), bad_pool, 0); |
Karl Schultz | bdb7595 | 2016-04-19 11:36:49 -0600 | [diff] [blame] | 5488 | m_errorMonitor->VerifyFound(); |
Tobin Ehlis | 49eb23d | 2015-05-22 12:38:55 -0600 | [diff] [blame] | 5489 | } |
| 5490 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5491 | TEST_F(VkLayerTest, InvalidDescriptorSet) { |
Karl Schultz | bdb7595 | 2016-04-19 11:36:49 -0600 | [diff] [blame] | 5492 | // Attempt to bind an invalid Descriptor Set to a valid Command Buffer |
| 5493 | // ObjectTracker should catch this. |
Tobin Ehlis | 49eb23d | 2015-05-22 12:38:55 -0600 | [diff] [blame] | 5494 | // Create a valid cmd buffer |
Karl Schultz | bdb7595 | 2016-04-19 11:36:49 -0600 | [diff] [blame] | 5495 | // call vkCmdBindDescriptorSets w/ false Descriptor Set |
Mark Lobodzinski | 02bf89d | 2016-05-10 14:45:13 -0600 | [diff] [blame] | 5496 | |
| 5497 | uint64_t fake_set_handle = 0xbaad6001; |
| 5498 | VkDescriptorSet bad_set = reinterpret_cast<VkDescriptorSet &>(fake_set_handle); |
Karl Schultz | bdb7595 | 2016-04-19 11:36:49 -0600 | [diff] [blame] | 5499 | VkResult err; |
| 5500 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 5501 | "Invalid VkDescriptorSet Object 0xbaad6001"); |
| 5502 | |
| 5503 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 5504 | |
| 5505 | VkDescriptorSetLayoutBinding layout_bindings[1] = {}; |
| 5506 | layout_bindings[0].binding = 0; |
| 5507 | layout_bindings[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 5508 | layout_bindings[0].descriptorCount = 1; |
| 5509 | layout_bindings[0].stageFlags = VK_SHADER_STAGE_VERTEX_BIT; |
| 5510 | layout_bindings[0].pImmutableSamplers = NULL; |
| 5511 | |
| 5512 | VkDescriptorSetLayout descriptor_set_layout; |
| 5513 | VkDescriptorSetLayoutCreateInfo dslci = {}; |
| 5514 | dslci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO; |
| 5515 | dslci.pNext = NULL; |
| 5516 | dslci.bindingCount = 1; |
| 5517 | dslci.pBindings = layout_bindings; |
| 5518 | err = vkCreateDescriptorSetLayout(device(), &dslci, NULL, &descriptor_set_layout); |
Karl Schultz | 5cb2111 | 2016-04-21 17:17:40 -0600 | [diff] [blame] | 5519 | ASSERT_VK_SUCCESS(err); |
Karl Schultz | bdb7595 | 2016-04-19 11:36:49 -0600 | [diff] [blame] | 5520 | |
| 5521 | VkPipelineLayout pipeline_layout; |
| 5522 | VkPipelineLayoutCreateInfo plci = {}; |
| 5523 | plci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO; |
| 5524 | plci.pNext = NULL; |
| 5525 | plci.setLayoutCount = 1; |
| 5526 | plci.pSetLayouts = &descriptor_set_layout; |
| 5527 | err = vkCreatePipelineLayout(device(), &plci, NULL, &pipeline_layout); |
Karl Schultz | 5cb2111 | 2016-04-21 17:17:40 -0600 | [diff] [blame] | 5528 | ASSERT_VK_SUCCESS(err); |
Karl Schultz | bdb7595 | 2016-04-19 11:36:49 -0600 | [diff] [blame] | 5529 | |
| 5530 | BeginCommandBuffer(); |
| 5531 | vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, |
Mark Lobodzinski | 02bf89d | 2016-05-10 14:45:13 -0600 | [diff] [blame] | 5532 | pipeline_layout, 0, 1, &bad_set, 0, NULL); |
Karl Schultz | bdb7595 | 2016-04-19 11:36:49 -0600 | [diff] [blame] | 5533 | m_errorMonitor->VerifyFound(); |
| 5534 | EndCommandBuffer(); |
| 5535 | vkDestroyPipelineLayout(device(), pipeline_layout, NULL); |
| 5536 | vkDestroyDescriptorSetLayout(device(), descriptor_set_layout, NULL); |
Tobin Ehlis | 49eb23d | 2015-05-22 12:38:55 -0600 | [diff] [blame] | 5537 | } |
| 5538 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5539 | TEST_F(VkLayerTest, InvalidDescriptorSetLayout) { |
Karl Schultz | bdb7595 | 2016-04-19 11:36:49 -0600 | [diff] [blame] | 5540 | // Attempt to create a Pipeline Layout with an invalid Descriptor Set Layout. |
| 5541 | // ObjectTracker should catch this. |
Mark Lobodzinski | 02bf89d | 2016-05-10 14:45:13 -0600 | [diff] [blame] | 5542 | uint64_t fake_layout_handle = 0xbaad6001; |
| 5543 | VkDescriptorSetLayout bad_layout = reinterpret_cast<VkDescriptorSetLayout &>(fake_layout_handle); |
Karl Schultz | bdb7595 | 2016-04-19 11:36:49 -0600 | [diff] [blame] | 5544 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 5545 | "Invalid VkDescriptorSetLayout Object 0xbaad6001"); |
| 5546 | |
| 5547 | VkPipelineLayout pipeline_layout; |
| 5548 | VkPipelineLayoutCreateInfo plci = {}; |
| 5549 | plci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO; |
| 5550 | plci.pNext = NULL; |
| 5551 | plci.setLayoutCount = 1; |
| 5552 | plci.pSetLayouts = &bad_layout; |
| 5553 | vkCreatePipelineLayout(device(), &plci, NULL, &pipeline_layout); |
| 5554 | |
| 5555 | m_errorMonitor->VerifyFound(); |
Tobin Ehlis | 49eb23d | 2015-05-22 12:38:55 -0600 | [diff] [blame] | 5556 | } |
| 5557 | |
Mark Mueller | d491441 | 2016-06-13 17:52:06 -0600 | [diff] [blame] | 5558 | TEST_F(VkLayerTest, WriteDescriptorSetIntegrityCheck) { |
| 5559 | TEST_DESCRIPTION("This test verifies some requirements of chapter 13.2.3 of the Vulkan Spec " |
| 5560 | "1) A uniform buffer update must have a valid buffer index." |
| 5561 | "2) When using an array of descriptors in a single WriteDescriptor," |
| 5562 | " the descriptor types and stageflags must all be the same." |
| 5563 | "3) Immutable Sampler state must match across descriptors"); |
| 5564 | |
| 5565 | const char *invalid_BufferInfo_ErrorMessage = |
| 5566 | "vkUpdateDescriptorSets: if pDescriptorWrites[0].descriptorType is VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, " |
| 5567 | "VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC or " |
| 5568 | "VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC, pDescriptorWrites[0].pBufferInfo must not be NULL"; |
| 5569 | const char *stateFlag_ErrorMessage = |
Mark Mueller | 5c838ce | 2016-06-16 09:54:29 -0600 | [diff] [blame] | 5570 | "Attempting write update to descriptor set "; |
Mark Mueller | d491441 | 2016-06-13 17:52:06 -0600 | [diff] [blame] | 5571 | const char *immutable_ErrorMessage = |
Mark Mueller | 5c838ce | 2016-06-16 09:54:29 -0600 | [diff] [blame] | 5572 | "Attempting write update to descriptor set "; |
Mark Mueller | d491441 | 2016-06-13 17:52:06 -0600 | [diff] [blame] | 5573 | |
Mark Mueller | d491441 | 2016-06-13 17:52:06 -0600 | [diff] [blame] | 5574 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_BufferInfo_ErrorMessage); |
| 5575 | |
| 5576 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 5577 | VkDescriptorPoolSize ds_type_count[4] = {}; |
| 5578 | ds_type_count[0].type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 5579 | ds_type_count[0].descriptorCount = 1; |
| 5580 | ds_type_count[1].type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER; |
| 5581 | ds_type_count[1].descriptorCount = 1; |
| 5582 | ds_type_count[2].type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER; |
| 5583 | ds_type_count[2].descriptorCount = 1; |
| 5584 | ds_type_count[3].type = VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT; |
| 5585 | ds_type_count[3].descriptorCount = 1; |
| 5586 | |
| 5587 | VkDescriptorPoolCreateInfo ds_pool_ci = {}; |
| 5588 | ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO; |
| 5589 | ds_pool_ci.maxSets = 1; |
| 5590 | ds_pool_ci.poolSizeCount = sizeof(ds_type_count) / sizeof(VkDescriptorPoolSize); |
| 5591 | ds_pool_ci.pPoolSizes = ds_type_count; |
| 5592 | |
| 5593 | VkDescriptorPool ds_pool; |
| 5594 | VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool); |
| 5595 | ASSERT_VK_SUCCESS(err); |
| 5596 | |
Mark Mueller | b989672 | 2016-06-16 09:54:29 -0600 | [diff] [blame] | 5597 | VkDescriptorSetLayoutBinding layout_binding[3] = {}; |
Mark Mueller | d491441 | 2016-06-13 17:52:06 -0600 | [diff] [blame] | 5598 | layout_binding[0].binding = 0; |
| 5599 | layout_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 5600 | layout_binding[0].descriptorCount = 1; |
| 5601 | layout_binding[0].stageFlags = VK_SHADER_STAGE_ALL; |
| 5602 | layout_binding[0].pImmutableSamplers = NULL; |
| 5603 | |
| 5604 | layout_binding[1].binding = 1; |
| 5605 | layout_binding[1].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER; |
| 5606 | layout_binding[1].descriptorCount = 1; |
| 5607 | layout_binding[1].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT; |
| 5608 | layout_binding[1].pImmutableSamplers = NULL; |
| 5609 | |
| 5610 | VkSamplerCreateInfo sampler_ci = {}; |
| 5611 | sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO; |
| 5612 | sampler_ci.pNext = NULL; |
| 5613 | sampler_ci.magFilter = VK_FILTER_NEAREST; |
| 5614 | sampler_ci.minFilter = VK_FILTER_NEAREST; |
| 5615 | sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST; |
| 5616 | sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE; |
| 5617 | sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE; |
| 5618 | sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE; |
| 5619 | sampler_ci.mipLodBias = 1.0; |
| 5620 | sampler_ci.anisotropyEnable = VK_FALSE; |
| 5621 | sampler_ci.maxAnisotropy = 1; |
| 5622 | sampler_ci.compareEnable = VK_FALSE; |
| 5623 | sampler_ci.compareOp = VK_COMPARE_OP_NEVER; |
| 5624 | sampler_ci.minLod = 1.0; |
| 5625 | sampler_ci.maxLod = 1.0; |
| 5626 | sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE; |
| 5627 | sampler_ci.unnormalizedCoordinates = VK_FALSE; |
| 5628 | VkSampler sampler; |
| 5629 | |
| 5630 | err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler); |
| 5631 | ASSERT_VK_SUCCESS(err); |
| 5632 | |
| 5633 | layout_binding[2].binding = 2; |
| 5634 | layout_binding[2].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER; |
| 5635 | layout_binding[2].descriptorCount = 1; |
| 5636 | layout_binding[2].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT; |
| 5637 | layout_binding[2].pImmutableSamplers = static_cast<VkSampler *>(&sampler); |
| 5638 | |
Mark Mueller | d491441 | 2016-06-13 17:52:06 -0600 | [diff] [blame] | 5639 | VkDescriptorSetLayoutCreateInfo ds_layout_ci = {}; |
| 5640 | ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO; |
| 5641 | ds_layout_ci.bindingCount = sizeof(layout_binding) / sizeof(VkDescriptorSetLayoutBinding); |
| 5642 | ds_layout_ci.pBindings = layout_binding; |
| 5643 | VkDescriptorSetLayout ds_layout; |
| 5644 | err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout); |
| 5645 | ASSERT_VK_SUCCESS(err); |
| 5646 | |
| 5647 | VkDescriptorSetAllocateInfo alloc_info = {}; |
| 5648 | alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO; |
| 5649 | alloc_info.descriptorSetCount = 1; |
| 5650 | alloc_info.descriptorPool = ds_pool; |
| 5651 | alloc_info.pSetLayouts = &ds_layout; |
| 5652 | VkDescriptorSet descriptorSet; |
| 5653 | err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet); |
| 5654 | ASSERT_VK_SUCCESS(err); |
| 5655 | |
| 5656 | VkPipelineLayoutCreateInfo pipeline_layout_ci = {}; |
| 5657 | pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO; |
| 5658 | pipeline_layout_ci.pNext = NULL; |
| 5659 | pipeline_layout_ci.setLayoutCount = 1; |
| 5660 | pipeline_layout_ci.pSetLayouts = &ds_layout; |
| 5661 | |
| 5662 | VkPipelineLayout pipeline_layout; |
| 5663 | err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout); |
| 5664 | ASSERT_VK_SUCCESS(err); |
| 5665 | |
Mark Mueller | 5c838ce | 2016-06-16 09:54:29 -0600 | [diff] [blame] | 5666 | VkWriteDescriptorSet descriptor_write = {}; |
Mark Mueller | d491441 | 2016-06-13 17:52:06 -0600 | [diff] [blame] | 5667 | descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET; |
| 5668 | descriptor_write.dstSet = descriptorSet; |
| 5669 | descriptor_write.dstBinding = 0; |
| 5670 | descriptor_write.descriptorCount = 1; |
| 5671 | descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 5672 | |
Mark Mueller | 5c838ce | 2016-06-16 09:54:29 -0600 | [diff] [blame] | 5673 | // 1) The uniform buffer is intentionally invalid here |
Mark Mueller | d491441 | 2016-06-13 17:52:06 -0600 | [diff] [blame] | 5674 | vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL); |
| 5675 | m_errorMonitor->VerifyFound(); |
| 5676 | |
| 5677 | // Create a buffer to update the descriptor with |
| 5678 | uint32_t qfi = 0; |
| 5679 | VkBufferCreateInfo buffCI = {}; |
| 5680 | buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO; |
| 5681 | buffCI.size = 1024; |
| 5682 | buffCI.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT; |
| 5683 | buffCI.queueFamilyIndexCount = 1; |
| 5684 | buffCI.pQueueFamilyIndices = &qfi; |
| 5685 | |
| 5686 | VkBuffer dyub; |
| 5687 | err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &dyub); |
| 5688 | ASSERT_VK_SUCCESS(err); |
| 5689 | VkDescriptorBufferInfo buffInfo = {}; |
| 5690 | buffInfo.buffer = dyub; |
| 5691 | buffInfo.offset = 0; |
| 5692 | buffInfo.range = 1024; |
| 5693 | |
| 5694 | descriptor_write.pBufferInfo = &buffInfo; |
| 5695 | descriptor_write.descriptorCount = 2; |
| 5696 | |
Mark Mueller | 5c838ce | 2016-06-16 09:54:29 -0600 | [diff] [blame] | 5697 | // 2) The stateFlags don't match between the first and second descriptor |
Mark Mueller | d491441 | 2016-06-13 17:52:06 -0600 | [diff] [blame] | 5698 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, stateFlag_ErrorMessage); |
| 5699 | vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL); |
| 5700 | m_errorMonitor->VerifyFound(); |
| 5701 | |
Mark Mueller | 5c838ce | 2016-06-16 09:54:29 -0600 | [diff] [blame] | 5702 | // 3) The second descriptor has a null_ptr pImmutableSamplers and |
| 5703 | // the third descriptor contains an immutable sampler |
Mark Mueller | d491441 | 2016-06-13 17:52:06 -0600 | [diff] [blame] | 5704 | descriptor_write.dstBinding = 1; |
| 5705 | descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER; |
Mark Mueller | 5c838ce | 2016-06-16 09:54:29 -0600 | [diff] [blame] | 5706 | |
| 5707 | |
| 5708 | // Make pImageInfo index non-null to avoid complaints of it missing |
| 5709 | VkDescriptorImageInfo imageInfo = {}; |
| 5710 | imageInfo.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL; |
| 5711 | descriptor_write.pImageInfo = &imageInfo; |
Mark Mueller | d491441 | 2016-06-13 17:52:06 -0600 | [diff] [blame] | 5712 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, immutable_ErrorMessage); |
| 5713 | vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL); |
| 5714 | m_errorMonitor->VerifyFound(); |
| 5715 | |
Mark Mueller | d491441 | 2016-06-13 17:52:06 -0600 | [diff] [blame] | 5716 | vkDestroyBuffer(m_device->device(), dyub, NULL); |
| 5717 | vkDestroySampler(m_device->device(), sampler, NULL); |
| 5718 | vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL); |
| 5719 | vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL); |
| 5720 | vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL); |
| 5721 | } |
| 5722 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5723 | TEST_F(VkLayerTest, InvalidPipeline) { |
Karl Schultz | bdb7595 | 2016-04-19 11:36:49 -0600 | [diff] [blame] | 5724 | // Attempt to bind an invalid Pipeline to a valid Command Buffer |
| 5725 | // ObjectTracker should catch this. |
Tobin Ehlis | 49eb23d | 2015-05-22 12:38:55 -0600 | [diff] [blame] | 5726 | // Create a valid cmd buffer |
| 5727 | // call vkCmdBindPipeline w/ false Pipeline |
Mark Lobodzinski | 02bf89d | 2016-05-10 14:45:13 -0600 | [diff] [blame] | 5728 | uint64_t fake_pipeline_handle = 0xbaad6001; |
| 5729 | VkPipeline bad_pipeline = reinterpret_cast<VkPipeline &>(fake_pipeline_handle); |
Karl Schultz | bdb7595 | 2016-04-19 11:36:49 -0600 | [diff] [blame] | 5730 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 5731 | "Invalid VkPipeline Object 0xbaad6001"); |
| 5732 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 5733 | BeginCommandBuffer(); |
| 5734 | vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), |
| 5735 | VK_PIPELINE_BIND_POINT_GRAPHICS, bad_pipeline); |
| 5736 | m_errorMonitor->VerifyFound(); |
Tobin Ehlis | b8b6b27 | 2016-05-02 13:26:06 -0600 | [diff] [blame] | 5737 | // Now issue a draw call with no pipeline bound |
| 5738 | m_errorMonitor->SetDesiredFailureMsg( |
| 5739 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 5740 | "At Draw/Dispatch time no valid VkPipeline is bound!"); |
Tony Barbour | df4c004 | 2016-06-01 15:55:43 -0600 | [diff] [blame] | 5741 | |
Tobin Ehlis | b8b6b27 | 2016-05-02 13:26:06 -0600 | [diff] [blame] | 5742 | BeginCommandBuffer(); |
| 5743 | Draw(1, 0, 0, 0); |
| 5744 | m_errorMonitor->VerifyFound(); |
| 5745 | // Finally same check once more but with Dispatch/Compute |
| 5746 | m_errorMonitor->SetDesiredFailureMsg( |
| 5747 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 5748 | "At Draw/Dispatch time no valid VkPipeline is bound!"); |
Tobin Ehlis | b8b6b27 | 2016-05-02 13:26:06 -0600 | [diff] [blame] | 5749 | BeginCommandBuffer(); |
| 5750 | vkCmdDispatch(m_commandBuffer->GetBufferHandle(), 0, 0, 0); |
| 5751 | m_errorMonitor->VerifyFound(); |
Tobin Ehlis | 49eb23d | 2015-05-22 12:38:55 -0600 | [diff] [blame] | 5752 | } |
| 5753 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5754 | TEST_F(VkLayerTest, DescriptorSetNotUpdated) { |
| 5755 | // Create and update CommandBuffer then call QueueSubmit w/o calling End on |
| 5756 | // CommandBuffer |
| 5757 | VkResult err; |
Tobin Ehlis | 7d1a711 | 2015-05-27 14:32:28 -0600 | [diff] [blame] | 5758 | |
Mark Lobodzinski | 510e20d | 2016-02-11 09:26:16 -0700 | [diff] [blame] | 5759 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5760 | " bound but it was never updated. "); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 5761 | |
Tobin Ehlis | 7d1a711 | 2015-05-27 14:32:28 -0600 | [diff] [blame] | 5762 | ASSERT_NO_FATAL_FAILURE(InitState()); |
Mike Stroyan | 713b2d7 | 2015-08-04 10:49:29 -0600 | [diff] [blame] | 5763 | ASSERT_NO_FATAL_FAILURE(InitViewport()); |
| 5764 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
Chia-I Wu | 1b99bb2 | 2015-10-27 19:25:11 +0800 | [diff] [blame] | 5765 | VkDescriptorPoolSize ds_type_count = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5766 | ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 5767 | ds_type_count.descriptorCount = 1; |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 5768 | |
| 5769 | VkDescriptorPoolCreateInfo ds_pool_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5770 | ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO; |
| 5771 | ds_pool_ci.pNext = NULL; |
| 5772 | ds_pool_ci.maxSets = 1; |
| 5773 | ds_pool_ci.poolSizeCount = 1; |
| 5774 | ds_pool_ci.pPoolSizes = &ds_type_count; |
Mike Stroyan | 713b2d7 | 2015-08-04 10:49:29 -0600 | [diff] [blame] | 5775 | |
Tobin Ehlis | 7d1a711 | 2015-05-27 14:32:28 -0600 | [diff] [blame] | 5776 | VkDescriptorPool ds_pool; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5777 | err = |
| 5778 | vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool); |
Tobin Ehlis | 7d1a711 | 2015-05-27 14:32:28 -0600 | [diff] [blame] | 5779 | ASSERT_VK_SUCCESS(err); |
Tobin Ehlis | 7d1a711 | 2015-05-27 14:32:28 -0600 | [diff] [blame] | 5780 | |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 5781 | VkDescriptorSetLayoutBinding dsl_binding = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5782 | dsl_binding.binding = 0; |
| 5783 | dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 5784 | dsl_binding.descriptorCount = 1; |
| 5785 | dsl_binding.stageFlags = VK_SHADER_STAGE_ALL; |
| 5786 | dsl_binding.pImmutableSamplers = NULL; |
Tobin Ehlis | 7d1a711 | 2015-05-27 14:32:28 -0600 | [diff] [blame] | 5787 | |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 5788 | VkDescriptorSetLayoutCreateInfo ds_layout_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5789 | ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO; |
| 5790 | ds_layout_ci.pNext = NULL; |
| 5791 | ds_layout_ci.bindingCount = 1; |
| 5792 | ds_layout_ci.pBindings = &dsl_binding; |
Tobin Ehlis | 7d1a711 | 2015-05-27 14:32:28 -0600 | [diff] [blame] | 5793 | VkDescriptorSetLayout ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5794 | err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, |
| 5795 | &ds_layout); |
Tobin Ehlis | 7d1a711 | 2015-05-27 14:32:28 -0600 | [diff] [blame] | 5796 | ASSERT_VK_SUCCESS(err); |
| 5797 | |
| 5798 | VkDescriptorSet descriptorSet; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 5799 | VkDescriptorSetAllocateInfo alloc_info = {}; |
Chia-I Wu | 00ce540 | 2015-11-10 16:21:09 +0800 | [diff] [blame] | 5800 | alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO; |
Jon Ashburn | f19916e | 2016-01-11 13:12:43 -0700 | [diff] [blame] | 5801 | alloc_info.descriptorSetCount = 1; |
Courtney Goeltzenleuchter | bee18a9 | 2015-10-23 14:21:05 -0600 | [diff] [blame] | 5802 | alloc_info.descriptorPool = ds_pool; |
| 5803 | alloc_info.pSetLayouts = &ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5804 | err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, |
| 5805 | &descriptorSet); |
Tobin Ehlis | 7d1a711 | 2015-05-27 14:32:28 -0600 | [diff] [blame] | 5806 | ASSERT_VK_SUCCESS(err); |
| 5807 | |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 5808 | VkPipelineLayoutCreateInfo pipeline_layout_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5809 | pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO; |
| 5810 | pipeline_layout_ci.pNext = NULL; |
| 5811 | pipeline_layout_ci.setLayoutCount = 1; |
| 5812 | pipeline_layout_ci.pSetLayouts = &ds_layout; |
Tobin Ehlis | 7d1a711 | 2015-05-27 14:32:28 -0600 | [diff] [blame] | 5813 | |
| 5814 | VkPipelineLayout pipeline_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5815 | err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, |
| 5816 | &pipeline_layout); |
Tobin Ehlis | 7d1a711 | 2015-05-27 14:32:28 -0600 | [diff] [blame] | 5817 | ASSERT_VK_SUCCESS(err); |
| 5818 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5819 | VkShaderObj vs(m_device, bindStateVertShaderText, |
| 5820 | VK_SHADER_STAGE_VERTEX_BIT, this); |
Karl Schultz | bdb7595 | 2016-04-19 11:36:49 -0600 | [diff] [blame] | 5821 | // 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] | 5822 | // on more devices |
| 5823 | VkShaderObj fs(m_device, bindStateFragShaderText, |
| 5824 | VK_SHADER_STAGE_FRAGMENT_BIT, this); |
Tobin Ehlis | 7d1a711 | 2015-05-27 14:32:28 -0600 | [diff] [blame] | 5825 | |
Tony Barbour | c95e4ac | 2015-08-04 17:05:26 -0600 | [diff] [blame] | 5826 | VkPipelineObj pipe(m_device); |
| 5827 | pipe.AddShader(&vs); |
Tony Barbour | 1c94d37 | 2015-08-06 11:21:08 -0600 | [diff] [blame] | 5828 | pipe.AddShader(&fs); |
Mark Young | c89c631 | 2016-03-31 16:03:20 -0600 | [diff] [blame] | 5829 | pipe.AddColorAttachment(); |
Tony Barbour | c95e4ac | 2015-08-04 17:05:26 -0600 | [diff] [blame] | 5830 | pipe.CreateVKPipeline(pipeline_layout, renderPass()); |
Tony Barbour | fe3351b | 2015-07-28 10:17:20 -0600 | [diff] [blame] | 5831 | |
| 5832 | BeginCommandBuffer(); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5833 | vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), |
| 5834 | VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle()); |
| 5835 | vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), |
| 5836 | VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, |
| 5837 | 1, &descriptorSet, 0, NULL); |
Tobin Ehlis | 7d1a711 | 2015-05-27 14:32:28 -0600 | [diff] [blame] | 5838 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 5839 | m_errorMonitor->VerifyFound(); |
Mike Stroyan | d1c84a5 | 2015-08-18 14:40:24 -0600 | [diff] [blame] | 5840 | |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 5841 | vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL); |
| 5842 | vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL); |
| 5843 | vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL); |
Tobin Ehlis | af1f3a4 | 2015-06-25 15:46:59 -0600 | [diff] [blame] | 5844 | } |
| 5845 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5846 | TEST_F(VkLayerTest, InvalidBufferViewObject) { |
Tobin Ehlis | ba31cab | 2015-11-02 15:24:32 -0700 | [diff] [blame] | 5847 | // Create a single TEXEL_BUFFER descriptor and send it an invalid bufferView |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5848 | VkResult err; |
Tobin Ehlis | ba31cab | 2015-11-02 15:24:32 -0700 | [diff] [blame] | 5849 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5850 | m_errorMonitor->SetDesiredFailureMsg( |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 5851 | VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attempted write update to texel buffer " |
| 5852 | "descriptor with invalid buffer view"); |
Tobin Ehlis | ba31cab | 2015-11-02 15:24:32 -0700 | [diff] [blame] | 5853 | |
| 5854 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 5855 | VkDescriptorPoolSize ds_type_count = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5856 | ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER; |
| 5857 | ds_type_count.descriptorCount = 1; |
Tobin Ehlis | ba31cab | 2015-11-02 15:24:32 -0700 | [diff] [blame] | 5858 | |
| 5859 | VkDescriptorPoolCreateInfo ds_pool_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5860 | ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO; |
| 5861 | ds_pool_ci.pNext = NULL; |
| 5862 | ds_pool_ci.maxSets = 1; |
| 5863 | ds_pool_ci.poolSizeCount = 1; |
| 5864 | ds_pool_ci.pPoolSizes = &ds_type_count; |
Tobin Ehlis | ba31cab | 2015-11-02 15:24:32 -0700 | [diff] [blame] | 5865 | |
| 5866 | VkDescriptorPool ds_pool; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5867 | err = |
| 5868 | vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool); |
Tobin Ehlis | ba31cab | 2015-11-02 15:24:32 -0700 | [diff] [blame] | 5869 | ASSERT_VK_SUCCESS(err); |
| 5870 | |
| 5871 | VkDescriptorSetLayoutBinding dsl_binding = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5872 | dsl_binding.binding = 0; |
| 5873 | dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER; |
| 5874 | dsl_binding.descriptorCount = 1; |
| 5875 | dsl_binding.stageFlags = VK_SHADER_STAGE_ALL; |
| 5876 | dsl_binding.pImmutableSamplers = NULL; |
Tobin Ehlis | ba31cab | 2015-11-02 15:24:32 -0700 | [diff] [blame] | 5877 | |
| 5878 | VkDescriptorSetLayoutCreateInfo ds_layout_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5879 | ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO; |
| 5880 | ds_layout_ci.pNext = NULL; |
| 5881 | ds_layout_ci.bindingCount = 1; |
| 5882 | ds_layout_ci.pBindings = &dsl_binding; |
Tobin Ehlis | ba31cab | 2015-11-02 15:24:32 -0700 | [diff] [blame] | 5883 | VkDescriptorSetLayout ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5884 | err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, |
| 5885 | &ds_layout); |
Tobin Ehlis | ba31cab | 2015-11-02 15:24:32 -0700 | [diff] [blame] | 5886 | ASSERT_VK_SUCCESS(err); |
| 5887 | |
| 5888 | VkDescriptorSet descriptorSet; |
| 5889 | VkDescriptorSetAllocateInfo alloc_info = {}; |
Chia-I Wu | 00ce540 | 2015-11-10 16:21:09 +0800 | [diff] [blame] | 5890 | alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO; |
Jon Ashburn | f19916e | 2016-01-11 13:12:43 -0700 | [diff] [blame] | 5891 | alloc_info.descriptorSetCount = 1; |
Tobin Ehlis | ba31cab | 2015-11-02 15:24:32 -0700 | [diff] [blame] | 5892 | alloc_info.descriptorPool = ds_pool; |
| 5893 | alloc_info.pSetLayouts = &ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5894 | err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, |
| 5895 | &descriptorSet); |
Tobin Ehlis | ba31cab | 2015-11-02 15:24:32 -0700 | [diff] [blame] | 5896 | ASSERT_VK_SUCCESS(err); |
| 5897 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5898 | VkBufferView view = |
| 5899 | (VkBufferView)((size_t)0xbaadbeef); // invalid bufferView object |
Tobin Ehlis | ba31cab | 2015-11-02 15:24:32 -0700 | [diff] [blame] | 5900 | VkWriteDescriptorSet descriptor_write; |
| 5901 | memset(&descriptor_write, 0, sizeof(descriptor_write)); |
| 5902 | descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET; |
| 5903 | descriptor_write.dstSet = descriptorSet; |
| 5904 | descriptor_write.dstBinding = 0; |
| 5905 | descriptor_write.descriptorCount = 1; |
| 5906 | descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER; |
| 5907 | descriptor_write.pTexelBufferView = &view; |
| 5908 | |
| 5909 | vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL); |
| 5910 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 5911 | m_errorMonitor->VerifyFound(); |
Tobin Ehlis | ba31cab | 2015-11-02 15:24:32 -0700 | [diff] [blame] | 5912 | |
| 5913 | vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL); |
| 5914 | vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL); |
| 5915 | } |
| 5916 | |
Mark Young | d339ba3 | 2016-05-30 13:28:35 -0600 | [diff] [blame] | 5917 | TEST_F(VkLayerTest, CreateBufferViewNoMemoryBoundToBuffer) { |
| 5918 | TEST_DESCRIPTION("Attempt to create a buffer view with a buffer that has" |
| 5919 | " no memory bound to it."); |
| 5920 | |
| 5921 | VkResult err; |
| 5922 | m_errorMonitor->SetDesiredFailureMsg( |
| 5923 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 5924 | "vkCreateBufferView called with invalid memory "); |
| 5925 | |
| 5926 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 5927 | |
| 5928 | // Create a buffer with no bound memory and then attempt to create |
| 5929 | // a buffer view. |
| 5930 | VkBufferCreateInfo buff_ci = {}; |
| 5931 | buff_ci.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO; |
| 5932 | buff_ci.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT; |
| 5933 | buff_ci.size = 256; |
| 5934 | buff_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE; |
| 5935 | VkBuffer buffer; |
| 5936 | err = vkCreateBuffer(m_device->device(), &buff_ci, NULL, &buffer); |
| 5937 | ASSERT_VK_SUCCESS(err); |
| 5938 | |
| 5939 | VkBufferViewCreateInfo buff_view_ci = {}; |
| 5940 | buff_view_ci.sType = VK_STRUCTURE_TYPE_BUFFER_VIEW_CREATE_INFO; |
| 5941 | buff_view_ci.buffer = buffer; |
| 5942 | buff_view_ci.format = VK_FORMAT_R8_UNORM; |
| 5943 | buff_view_ci.range = VK_WHOLE_SIZE; |
| 5944 | VkBufferView buff_view; |
| 5945 | err = |
| 5946 | vkCreateBufferView(m_device->device(), &buff_view_ci, NULL, &buff_view); |
| 5947 | |
| 5948 | m_errorMonitor->VerifyFound(); |
| 5949 | vkDestroyBuffer(m_device->device(), buffer, NULL); |
| 5950 | // If last error is success, it still created the view, so delete it. |
| 5951 | if (err == VK_SUCCESS) { |
| 5952 | vkDestroyBufferView(m_device->device(), buff_view, NULL); |
| 5953 | } |
| 5954 | } |
| 5955 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5956 | TEST_F(VkLayerTest, InvalidDynamicOffsetCases) { |
| 5957 | // Create a descriptorSet w/ dynamic descriptor and then hit 3 offset error |
| 5958 | // cases: |
Tobin Ehlis | f658505 | 2015-12-17 11:48:42 -0700 | [diff] [blame] | 5959 | // 1. No dynamicOffset supplied |
| 5960 | // 2. Too many dynamicOffsets supplied |
| 5961 | // 3. Dynamic offset oversteps buffer being updated |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5962 | VkResult err; |
Courtney Goeltzenleuchter | 7415d5a | 2015-12-09 15:48:16 -0700 | [diff] [blame] | 5963 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5964 | " requires 1 dynamicOffsets, but only " |
| 5965 | "0 dynamicOffsets are left in " |
| 5966 | "pDynamicOffsets "); |
Tobin Ehlis | 49f903e | 2015-11-04 13:30:34 -0700 | [diff] [blame] | 5967 | |
| 5968 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 5969 | ASSERT_NO_FATAL_FAILURE(InitViewport()); |
| 5970 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 5971 | |
| 5972 | VkDescriptorPoolSize ds_type_count = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5973 | ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC; |
| 5974 | ds_type_count.descriptorCount = 1; |
Tobin Ehlis | 49f903e | 2015-11-04 13:30:34 -0700 | [diff] [blame] | 5975 | |
| 5976 | VkDescriptorPoolCreateInfo ds_pool_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5977 | ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO; |
| 5978 | ds_pool_ci.pNext = NULL; |
| 5979 | ds_pool_ci.maxSets = 1; |
| 5980 | ds_pool_ci.poolSizeCount = 1; |
| 5981 | ds_pool_ci.pPoolSizes = &ds_type_count; |
Tobin Ehlis | 49f903e | 2015-11-04 13:30:34 -0700 | [diff] [blame] | 5982 | |
| 5983 | VkDescriptorPool ds_pool; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5984 | err = |
| 5985 | vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool); |
Tobin Ehlis | 49f903e | 2015-11-04 13:30:34 -0700 | [diff] [blame] | 5986 | ASSERT_VK_SUCCESS(err); |
| 5987 | |
| 5988 | VkDescriptorSetLayoutBinding dsl_binding = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5989 | dsl_binding.binding = 0; |
| 5990 | dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC; |
| 5991 | dsl_binding.descriptorCount = 1; |
| 5992 | dsl_binding.stageFlags = VK_SHADER_STAGE_ALL; |
| 5993 | dsl_binding.pImmutableSamplers = NULL; |
Tobin Ehlis | 49f903e | 2015-11-04 13:30:34 -0700 | [diff] [blame] | 5994 | |
| 5995 | VkDescriptorSetLayoutCreateInfo ds_layout_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5996 | ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO; |
| 5997 | ds_layout_ci.pNext = NULL; |
| 5998 | ds_layout_ci.bindingCount = 1; |
| 5999 | ds_layout_ci.pBindings = &dsl_binding; |
Tobin Ehlis | 49f903e | 2015-11-04 13:30:34 -0700 | [diff] [blame] | 6000 | VkDescriptorSetLayout ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6001 | err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, |
| 6002 | &ds_layout); |
Tobin Ehlis | 49f903e | 2015-11-04 13:30:34 -0700 | [diff] [blame] | 6003 | ASSERT_VK_SUCCESS(err); |
| 6004 | |
| 6005 | VkDescriptorSet descriptorSet; |
| 6006 | VkDescriptorSetAllocateInfo alloc_info = {}; |
Chia-I Wu | 00ce540 | 2015-11-10 16:21:09 +0800 | [diff] [blame] | 6007 | alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO; |
Jon Ashburn | f19916e | 2016-01-11 13:12:43 -0700 | [diff] [blame] | 6008 | alloc_info.descriptorSetCount = 1; |
Tobin Ehlis | 49f903e | 2015-11-04 13:30:34 -0700 | [diff] [blame] | 6009 | alloc_info.descriptorPool = ds_pool; |
| 6010 | alloc_info.pSetLayouts = &ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6011 | err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, |
| 6012 | &descriptorSet); |
Tobin Ehlis | 49f903e | 2015-11-04 13:30:34 -0700 | [diff] [blame] | 6013 | ASSERT_VK_SUCCESS(err); |
| 6014 | |
| 6015 | VkPipelineLayoutCreateInfo pipeline_layout_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6016 | pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO; |
| 6017 | pipeline_layout_ci.pNext = NULL; |
| 6018 | pipeline_layout_ci.setLayoutCount = 1; |
| 6019 | pipeline_layout_ci.pSetLayouts = &ds_layout; |
Tobin Ehlis | 49f903e | 2015-11-04 13:30:34 -0700 | [diff] [blame] | 6020 | |
| 6021 | VkPipelineLayout pipeline_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6022 | err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, |
| 6023 | &pipeline_layout); |
Tobin Ehlis | 49f903e | 2015-11-04 13:30:34 -0700 | [diff] [blame] | 6024 | ASSERT_VK_SUCCESS(err); |
| 6025 | |
| 6026 | // Create a buffer to update the descriptor with |
| 6027 | uint32_t qfi = 0; |
| 6028 | VkBufferCreateInfo buffCI = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6029 | buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO; |
| 6030 | buffCI.size = 1024; |
| 6031 | buffCI.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT; |
| 6032 | buffCI.queueFamilyIndexCount = 1; |
| 6033 | buffCI.pQueueFamilyIndices = &qfi; |
Tobin Ehlis | 49f903e | 2015-11-04 13:30:34 -0700 | [diff] [blame] | 6034 | |
| 6035 | VkBuffer dyub; |
| 6036 | err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &dyub); |
| 6037 | ASSERT_VK_SUCCESS(err); |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 6038 | // Allocate memory and bind to buffer so we can make it to the appropriate |
| 6039 | // error |
| 6040 | VkMemoryAllocateInfo mem_alloc = {}; |
| 6041 | mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO; |
| 6042 | mem_alloc.pNext = NULL; |
| 6043 | mem_alloc.allocationSize = 1024; |
Chris Forbes | b6116cc | 2016-05-08 11:39:59 +1200 | [diff] [blame] | 6044 | mem_alloc.memoryTypeIndex = 0; |
| 6045 | |
| 6046 | VkMemoryRequirements memReqs; |
| 6047 | vkGetBufferMemoryRequirements(m_device->device(), dyub, &memReqs); |
| 6048 | bool pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &mem_alloc, |
| 6049 | 0); |
| 6050 | if (!pass) { |
| 6051 | vkDestroyBuffer(m_device->device(), dyub, NULL); |
| 6052 | return; |
| 6053 | } |
| 6054 | |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 6055 | VkDeviceMemory mem; |
| 6056 | err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem); |
| 6057 | ASSERT_VK_SUCCESS(err); |
| 6058 | err = vkBindBufferMemory(m_device->device(), dyub, mem, 0); |
| 6059 | ASSERT_VK_SUCCESS(err); |
Tobin Ehlis | 49f903e | 2015-11-04 13:30:34 -0700 | [diff] [blame] | 6060 | // Correctly update descriptor to avoid "NOT_UPDATED" error |
| 6061 | VkDescriptorBufferInfo buffInfo = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6062 | buffInfo.buffer = dyub; |
| 6063 | buffInfo.offset = 0; |
| 6064 | buffInfo.range = 1024; |
Tobin Ehlis | 49f903e | 2015-11-04 13:30:34 -0700 | [diff] [blame] | 6065 | |
| 6066 | VkWriteDescriptorSet descriptor_write; |
| 6067 | memset(&descriptor_write, 0, sizeof(descriptor_write)); |
| 6068 | descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET; |
| 6069 | descriptor_write.dstSet = descriptorSet; |
| 6070 | descriptor_write.dstBinding = 0; |
| 6071 | descriptor_write.descriptorCount = 1; |
| 6072 | descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC; |
| 6073 | descriptor_write.pBufferInfo = &buffInfo; |
| 6074 | |
| 6075 | vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL); |
| 6076 | |
| 6077 | BeginCommandBuffer(); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6078 | vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), |
| 6079 | VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, |
| 6080 | 1, &descriptorSet, 0, NULL); |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 6081 | m_errorMonitor->VerifyFound(); |
Tobin Ehlis | f658505 | 2015-12-17 11:48:42 -0700 | [diff] [blame] | 6082 | uint32_t pDynOff[2] = {512, 756}; |
| 6083 | // 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] | 6084 | m_errorMonitor->SetDesiredFailureMsg( |
| 6085 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Tobin Ehlis | f658505 | 2015-12-17 11:48:42 -0700 | [diff] [blame] | 6086 | "Attempting to bind 1 descriptorSets with 1 dynamic descriptors, but "); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6087 | vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), |
| 6088 | VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, |
| 6089 | 1, &descriptorSet, 2, pDynOff); |
Chris Forbes | 7b34280 | 2016-04-07 13:20:10 +1200 | [diff] [blame] | 6090 | m_errorMonitor->VerifyFound(); |
Tobin Ehlis | f658505 | 2015-12-17 11:48:42 -0700 | [diff] [blame] | 6091 | // Finally cause error due to dynamicOffset being too big |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 6092 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 6093 | " dynamic offset 512 combined with " |
| 6094 | "offset 0 and range 1024 that " |
| 6095 | "oversteps the buffer size of 1024"); |
Tobin Ehlis | f658505 | 2015-12-17 11:48:42 -0700 | [diff] [blame] | 6096 | // Create PSO to be used for draw-time errors below |
| 6097 | char const *vsSource = |
Chris Forbes | 7b34280 | 2016-04-07 13:20:10 +1200 | [diff] [blame] | 6098 | "#version 450\n" |
Tobin Ehlis | f658505 | 2015-12-17 11:48:42 -0700 | [diff] [blame] | 6099 | "\n" |
Tony Barbour | e804d20 | 2016-01-05 13:37:45 -0700 | [diff] [blame] | 6100 | "out gl_PerVertex { \n" |
| 6101 | " vec4 gl_Position;\n" |
| 6102 | "};\n" |
Tobin Ehlis | f658505 | 2015-12-17 11:48:42 -0700 | [diff] [blame] | 6103 | "void main(){\n" |
| 6104 | " gl_Position = vec4(1);\n" |
| 6105 | "}\n"; |
| 6106 | char const *fsSource = |
Chris Forbes | 7b34280 | 2016-04-07 13:20:10 +1200 | [diff] [blame] | 6107 | "#version 450\n" |
Tobin Ehlis | f658505 | 2015-12-17 11:48:42 -0700 | [diff] [blame] | 6108 | "\n" |
| 6109 | "layout(location=0) out vec4 x;\n" |
| 6110 | "layout(set=0) layout(binding=0) uniform foo { int x; int y; } bar;\n" |
| 6111 | "void main(){\n" |
| 6112 | " x = vec4(bar.y);\n" |
| 6113 | "}\n"; |
| 6114 | VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this); |
| 6115 | VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this); |
| 6116 | VkPipelineObj pipe(m_device); |
| 6117 | pipe.AddShader(&vs); |
| 6118 | pipe.AddShader(&fs); |
| 6119 | pipe.AddColorAttachment(); |
| 6120 | pipe.CreateVKPipeline(pipeline_layout, renderPass()); |
| 6121 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6122 | vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), |
| 6123 | VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle()); |
| 6124 | // This update should succeed, but offset size of 512 will overstep buffer |
| 6125 | // /w range 1024 & size 1024 |
| 6126 | vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), |
| 6127 | VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, |
| 6128 | 1, &descriptorSet, 1, pDynOff); |
Tobin Ehlis | f658505 | 2015-12-17 11:48:42 -0700 | [diff] [blame] | 6129 | Draw(1, 0, 0, 0); |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 6130 | m_errorMonitor->VerifyFound(); |
Tobin Ehlis | 49f903e | 2015-11-04 13:30:34 -0700 | [diff] [blame] | 6131 | |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 6132 | vkDestroyBuffer(m_device->device(), dyub, NULL); |
Tobin Ehlis | 512098e | 2016-05-05 09:06:12 -0600 | [diff] [blame] | 6133 | vkFreeMemory(m_device->device(), mem, NULL); |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 6134 | |
Tobin Ehlis | 49f903e | 2015-11-04 13:30:34 -0700 | [diff] [blame] | 6135 | vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL); |
Tony Barbour | df4c004 | 2016-06-01 15:55:43 -0600 | [diff] [blame] | 6136 | vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL); |
Tobin Ehlis | 49f903e | 2015-11-04 13:30:34 -0700 | [diff] [blame] | 6137 | vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL); |
| 6138 | } |
| 6139 | |
Tobin Ehlis | 3a23b6a | 2016-02-17 10:35:18 -0700 | [diff] [blame] | 6140 | TEST_F(VkLayerTest, InvalidPushConstants) { |
Tobin Ehlis | 3a23b6a | 2016-02-17 10:35:18 -0700 | [diff] [blame] | 6141 | VkResult err; |
Tobin Ehlis | 3a23b6a | 2016-02-17 10:35:18 -0700 | [diff] [blame] | 6142 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 6143 | ASSERT_NO_FATAL_FAILURE(InitViewport()); |
| 6144 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 6145 | |
Karl Schultz | fc8eaf1 | 2016-05-06 13:56:42 -0600 | [diff] [blame] | 6146 | VkPipelineLayout pipeline_layout; |
Tobin Ehlis | 3a23b6a | 2016-02-17 10:35:18 -0700 | [diff] [blame] | 6147 | VkPushConstantRange pc_range = {}; |
Tobin Ehlis | 3a23b6a | 2016-02-17 10:35:18 -0700 | [diff] [blame] | 6148 | VkPipelineLayoutCreateInfo pipeline_layout_ci = {}; |
| 6149 | pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO; |
| 6150 | pipeline_layout_ci.pushConstantRangeCount = 1; |
| 6151 | pipeline_layout_ci.pPushConstantRanges = &pc_range; |
| 6152 | |
Karl Schultz | fc8eaf1 | 2016-05-06 13:56:42 -0600 | [diff] [blame] | 6153 | // |
| 6154 | // Check for invalid push constant ranges in pipeline layouts. |
| 6155 | // |
| 6156 | struct PipelineLayoutTestCase { |
Karl Schultz | c81037d | 2016-05-12 08:11:23 -0600 | [diff] [blame] | 6157 | VkPushConstantRange const range; |
Karl Schultz | fc8eaf1 | 2016-05-06 13:56:42 -0600 | [diff] [blame] | 6158 | char const *msg; |
| 6159 | }; |
Tobin Ehlis | 3a23b6a | 2016-02-17 10:35:18 -0700 | [diff] [blame] | 6160 | |
Karl Schultz | c81037d | 2016-05-12 08:11:23 -0600 | [diff] [blame] | 6161 | const uint32_t too_big = m_device->props.limits.maxPushConstantsSize + 0x4; |
| 6162 | const std::array<PipelineLayoutTestCase, 10> range_tests = {{ |
| 6163 | {{VK_SHADER_STAGE_VERTEX_BIT, 0, 0}, |
| 6164 | "vkCreatePipelineLayout() call has push constants index 0 with " |
| 6165 | "size 0."}, |
| 6166 | {{VK_SHADER_STAGE_VERTEX_BIT, 0, 1}, |
| 6167 | "vkCreatePipelineLayout() call has push constants index 0 with " |
| 6168 | "size 1."}, |
| 6169 | {{VK_SHADER_STAGE_VERTEX_BIT, 1, 1}, |
| 6170 | "vkCreatePipelineLayout() call has push constants index 0 with " |
| 6171 | "size 1."}, |
| 6172 | {{VK_SHADER_STAGE_VERTEX_BIT, 1, 0}, |
| 6173 | "vkCreatePipelineLayout() call has push constants index 0 with " |
| 6174 | "size 0."}, |
| 6175 | {{VK_SHADER_STAGE_VERTEX_BIT, 1, 4}, |
| 6176 | "vkCreatePipelineLayout() call has push constants index 0 with " |
| 6177 | "offset 1. Offset must"}, |
| 6178 | {{VK_SHADER_STAGE_VERTEX_BIT, 0, too_big}, |
| 6179 | "vkCreatePipelineLayout() call has push constants index 0 " |
| 6180 | "with offset "}, |
| 6181 | {{VK_SHADER_STAGE_VERTEX_BIT, too_big, too_big}, |
| 6182 | "vkCreatePipelineLayout() call has push constants " |
| 6183 | "index 0 with offset "}, |
| 6184 | {{VK_SHADER_STAGE_VERTEX_BIT, too_big, 0}, |
| 6185 | "vkCreatePipelineLayout() call has push constants index 0 " |
| 6186 | "with offset "}, |
| 6187 | {{VK_SHADER_STAGE_VERTEX_BIT, 0xFFFFFFF0, 0x00000020}, |
| 6188 | "vkCreatePipelineLayout() call has push " |
| 6189 | "constants index 0 with offset "}, |
| 6190 | {{VK_SHADER_STAGE_VERTEX_BIT, 0x00000020, 0xFFFFFFF0}, |
| 6191 | "vkCreatePipelineLayout() call has push " |
| 6192 | "constants index 0 with offset "}, |
Karl Schultz | fc8eaf1 | 2016-05-06 13:56:42 -0600 | [diff] [blame] | 6193 | }}; |
| 6194 | |
| 6195 | // Check for invalid offset and size |
Karl Schultz | c81037d | 2016-05-12 08:11:23 -0600 | [diff] [blame] | 6196 | for (const auto &iter : range_tests) { |
| 6197 | pc_range = iter.range; |
Karl Schultz | fc8eaf1 | 2016-05-06 13:56:42 -0600 | [diff] [blame] | 6198 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 6199 | iter.msg); |
| 6200 | err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, |
| 6201 | NULL, &pipeline_layout); |
| 6202 | m_errorMonitor->VerifyFound(); |
| 6203 | if (VK_SUCCESS == err) { |
| 6204 | vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL); |
| 6205 | } |
| 6206 | } |
| 6207 | |
| 6208 | // Check for invalid stage flag |
| 6209 | pc_range.offset = 0; |
| 6210 | pc_range.size = 16; |
| 6211 | pc_range.stageFlags = 0; |
Tobin Ehlis | 3a23b6a | 2016-02-17 10:35:18 -0700 | [diff] [blame] | 6212 | m_errorMonitor->SetDesiredFailureMsg( |
| 6213 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Karl Schultz | fc8eaf1 | 2016-05-06 13:56:42 -0600 | [diff] [blame] | 6214 | "vkCreatePipelineLayout() call has no stageFlags set."); |
Tobin Ehlis | 3a23b6a | 2016-02-17 10:35:18 -0700 | [diff] [blame] | 6215 | err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, |
| 6216 | &pipeline_layout); |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 6217 | m_errorMonitor->VerifyFound(); |
Karl Schultz | fc8eaf1 | 2016-05-06 13:56:42 -0600 | [diff] [blame] | 6218 | if (VK_SUCCESS == err) { |
| 6219 | vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL); |
| 6220 | } |
| 6221 | |
| 6222 | // Check for overlapping ranges |
Karl Schultz | c81037d | 2016-05-12 08:11:23 -0600 | [diff] [blame] | 6223 | const uint32_t ranges_per_test = 5; |
Karl Schultz | fc8eaf1 | 2016-05-06 13:56:42 -0600 | [diff] [blame] | 6224 | struct OverlappingRangeTestCase { |
Karl Schultz | c81037d | 2016-05-12 08:11:23 -0600 | [diff] [blame] | 6225 | VkPushConstantRange const ranges[ranges_per_test]; |
Karl Schultz | fc8eaf1 | 2016-05-06 13:56:42 -0600 | [diff] [blame] | 6226 | char const *msg; |
| 6227 | }; |
| 6228 | |
Karl Schultz | c81037d | 2016-05-12 08:11:23 -0600 | [diff] [blame] | 6229 | const std::array<OverlappingRangeTestCase, 5> overlapping_range_tests = { |
Karl Schultz | fc8eaf1 | 2016-05-06 13:56:42 -0600 | [diff] [blame] | 6230 | {{{{VK_SHADER_STAGE_VERTEX_BIT, 0, 4}, |
| 6231 | {VK_SHADER_STAGE_VERTEX_BIT, 0, 4}, |
| 6232 | {VK_SHADER_STAGE_VERTEX_BIT, 0, 4}, |
| 6233 | {VK_SHADER_STAGE_VERTEX_BIT, 0, 4}, |
| 6234 | {VK_SHADER_STAGE_VERTEX_BIT, 0, 4}}, |
| 6235 | "vkCreatePipelineLayout() call has push constants with overlapping " |
| 6236 | "ranges: 0:[0, 4), 1:[0, 4)"}, |
| 6237 | { |
| 6238 | {{VK_SHADER_STAGE_VERTEX_BIT, 0, 4}, |
| 6239 | {VK_SHADER_STAGE_VERTEX_BIT, 4, 4}, |
| 6240 | {VK_SHADER_STAGE_VERTEX_BIT, 8, 4}, |
| 6241 | {VK_SHADER_STAGE_VERTEX_BIT, 12, 8}, |
| 6242 | {VK_SHADER_STAGE_VERTEX_BIT, 16, 4}}, |
| 6243 | "vkCreatePipelineLayout() call has push constants with " |
| 6244 | "overlapping " |
| 6245 | "ranges: 3:[12, 20), 4:[16, 20)", |
| 6246 | }, |
| 6247 | { |
| 6248 | {{VK_SHADER_STAGE_VERTEX_BIT, 16, 4}, |
| 6249 | {VK_SHADER_STAGE_VERTEX_BIT, 12, 8}, |
| 6250 | {VK_SHADER_STAGE_VERTEX_BIT, 8, 4}, |
| 6251 | {VK_SHADER_STAGE_VERTEX_BIT, 4, 4}, |
| 6252 | {VK_SHADER_STAGE_VERTEX_BIT, 0, 4}}, |
| 6253 | "vkCreatePipelineLayout() call has push constants with " |
| 6254 | "overlapping " |
| 6255 | "ranges: 0:[16, 20), 1:[12, 20)", |
| 6256 | }, |
| 6257 | { |
| 6258 | {{VK_SHADER_STAGE_VERTEX_BIT, 16, 4}, |
| 6259 | {VK_SHADER_STAGE_VERTEX_BIT, 8, 4}, |
| 6260 | {VK_SHADER_STAGE_VERTEX_BIT, 4, 4}, |
| 6261 | {VK_SHADER_STAGE_VERTEX_BIT, 12, 8}, |
| 6262 | {VK_SHADER_STAGE_VERTEX_BIT, 0, 4}}, |
| 6263 | "vkCreatePipelineLayout() call has push constants with " |
| 6264 | "overlapping " |
| 6265 | "ranges: 0:[16, 20), 3:[12, 20)", |
| 6266 | }, |
| 6267 | { |
| 6268 | {{VK_SHADER_STAGE_VERTEX_BIT, 16, 4}, |
| 6269 | {VK_SHADER_STAGE_VERTEX_BIT, 32, 4}, |
| 6270 | {VK_SHADER_STAGE_VERTEX_BIT, 4, 96}, |
| 6271 | {VK_SHADER_STAGE_VERTEX_BIT, 40, 8}, |
| 6272 | {VK_SHADER_STAGE_VERTEX_BIT, 52, 4}}, |
| 6273 | "vkCreatePipelineLayout() call has push constants with " |
| 6274 | "overlapping " |
| 6275 | "ranges: 0:[16, 20), 2:[4, 100)", |
| 6276 | }}}; |
Karl Schultz | fc8eaf1 | 2016-05-06 13:56:42 -0600 | [diff] [blame] | 6277 | |
Karl Schultz | c81037d | 2016-05-12 08:11:23 -0600 | [diff] [blame] | 6278 | for (const auto &iter : overlapping_range_tests) { |
Karl Schultz | fc8eaf1 | 2016-05-06 13:56:42 -0600 | [diff] [blame] | 6279 | pipeline_layout_ci.pPushConstantRanges = iter.ranges; |
Karl Schultz | c81037d | 2016-05-12 08:11:23 -0600 | [diff] [blame] | 6280 | pipeline_layout_ci.pushConstantRangeCount = ranges_per_test; |
| 6281 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, |
Karl Schultz | fc8eaf1 | 2016-05-06 13:56:42 -0600 | [diff] [blame] | 6282 | iter.msg); |
| 6283 | err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, |
| 6284 | NULL, &pipeline_layout); |
| 6285 | m_errorMonitor->VerifyFound(); |
| 6286 | if (VK_SUCCESS == err) { |
| 6287 | vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL); |
| 6288 | } |
| 6289 | } |
| 6290 | |
| 6291 | // 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] | 6292 | const std::array<OverlappingRangeTestCase, 2> overlapping_range_tests_pos = |
| 6293 | {{{{{VK_SHADER_STAGE_VERTEX_BIT, 0, 4}, |
| 6294 | {VK_SHADER_STAGE_VERTEX_BIT, 4, 4}, |
| 6295 | {VK_SHADER_STAGE_VERTEX_BIT, 8, 4}, |
| 6296 | {VK_SHADER_STAGE_VERTEX_BIT, 12, 4}, |
| 6297 | {VK_SHADER_STAGE_VERTEX_BIT, 16, 4}}, |
| 6298 | ""}, |
| 6299 | {{{VK_SHADER_STAGE_VERTEX_BIT, 92, 24}, |
| 6300 | {VK_SHADER_STAGE_VERTEX_BIT, 80, 4}, |
| 6301 | {VK_SHADER_STAGE_VERTEX_BIT, 64, 8}, |
| 6302 | {VK_SHADER_STAGE_VERTEX_BIT, 4, 16}, |
| 6303 | {VK_SHADER_STAGE_VERTEX_BIT, 0, 4}}, |
| 6304 | ""}}}; |
| 6305 | for (const auto &iter : overlapping_range_tests_pos) { |
Karl Schultz | fc8eaf1 | 2016-05-06 13:56:42 -0600 | [diff] [blame] | 6306 | pipeline_layout_ci.pPushConstantRanges = iter.ranges; |
| 6307 | m_errorMonitor->ExpectSuccess(); |
| 6308 | err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, |
| 6309 | NULL, &pipeline_layout); |
| 6310 | m_errorMonitor->VerifyNotFound(); |
| 6311 | if (VK_SUCCESS == err) { |
| 6312 | vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL); |
| 6313 | } |
| 6314 | } |
| 6315 | |
| 6316 | // |
| 6317 | // CmdPushConstants tests |
| 6318 | // |
Karl Schultz | c81037d | 2016-05-12 08:11:23 -0600 | [diff] [blame] | 6319 | const uint8_t dummy_values[100] = {}; |
Karl Schultz | fc8eaf1 | 2016-05-06 13:56:42 -0600 | [diff] [blame] | 6320 | |
| 6321 | // 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] | 6322 | const std::array<PipelineLayoutTestCase, 16> cmd_range_tests = {{ |
| 6323 | {{VK_SHADER_STAGE_VERTEX_BIT, 0, 0}, |
| 6324 | "vkCmdPushConstants() call has push constants with size 0. Size " |
| 6325 | "must be greater than zero and a multiple of 4."}, |
| 6326 | {{VK_SHADER_STAGE_VERTEX_BIT, 0, 1}, |
| 6327 | "vkCmdPushConstants() call has push constants with size 1. Size " |
| 6328 | "must be greater than zero and a multiple of 4."}, |
| 6329 | {{VK_SHADER_STAGE_VERTEX_BIT, 1, 1}, |
| 6330 | "vkCmdPushConstants() call has push constants with size 1. Size " |
| 6331 | "must be greater than zero and a multiple of 4."}, |
| 6332 | {{VK_SHADER_STAGE_VERTEX_BIT, 1, 0}, |
| 6333 | "vkCmdPushConstants() call has push constants with offset 1. " |
| 6334 | "Offset must be a multiple of 4."}, |
| 6335 | {{VK_SHADER_STAGE_VERTEX_BIT, 1, 4}, |
| 6336 | "vkCmdPushConstants() call has push constants with offset 1. " |
| 6337 | "Offset must be a multiple of 4."}, |
| 6338 | {{VK_SHADER_STAGE_VERTEX_BIT, 0, 20}, |
| 6339 | "vkCmdPushConstants() Push constant range [0, 20) with stageFlags = " |
| 6340 | "0x1 not within flag-matching ranges in pipeline layout"}, |
| 6341 | {{VK_SHADER_STAGE_VERTEX_BIT, 60, 8}, |
| 6342 | "vkCmdPushConstants() Push constant range [60, 68) with stageFlags = " |
| 6343 | "0x1 not within flag-matching ranges in pipeline layout"}, |
| 6344 | {{VK_SHADER_STAGE_VERTEX_BIT, 76, 8}, |
| 6345 | "vkCmdPushConstants() Push constant range [76, 84) with stageFlags = " |
| 6346 | "0x1 not within flag-matching ranges in pipeline layout"}, |
| 6347 | {{VK_SHADER_STAGE_VERTEX_BIT, 0, 80}, |
| 6348 | "vkCmdPushConstants() Push constant range [0, 80) with stageFlags = " |
| 6349 | "0x1 not within flag-matching ranges in pipeline layout"}, |
| 6350 | {{VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT, 0, 4}, |
| 6351 | "vkCmdPushConstants() stageFlags = 0x2 do not match the stageFlags in " |
| 6352 | "any of the ranges in pipeline layout"}, |
| 6353 | {{VK_SHADER_STAGE_VERTEX_BIT | VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT, |
| 6354 | 0, 16}, |
| 6355 | "vkCmdPushConstants() stageFlags = 0x3 do not match the stageFlags in " |
| 6356 | "any of the ranges in pipeline layout"}, |
| 6357 | {{VK_SHADER_STAGE_VERTEX_BIT, 0, too_big}, |
Karl Schultz | fc8eaf1 | 2016-05-06 13:56:42 -0600 | [diff] [blame] | 6358 | "vkCmdPushConstants() call has push constants with offset "}, |
Karl Schultz | c81037d | 2016-05-12 08:11:23 -0600 | [diff] [blame] | 6359 | {{VK_SHADER_STAGE_VERTEX_BIT, too_big, too_big}, |
Karl Schultz | fc8eaf1 | 2016-05-06 13:56:42 -0600 | [diff] [blame] | 6360 | "vkCmdPushConstants() call has push constants with offset "}, |
Karl Schultz | c81037d | 2016-05-12 08:11:23 -0600 | [diff] [blame] | 6361 | {{VK_SHADER_STAGE_VERTEX_BIT, too_big, 0}, |
Karl Schultz | fc8eaf1 | 2016-05-06 13:56:42 -0600 | [diff] [blame] | 6362 | "vkCmdPushConstants() call has push constants with offset "}, |
Karl Schultz | c81037d | 2016-05-12 08:11:23 -0600 | [diff] [blame] | 6363 | {{VK_SHADER_STAGE_VERTEX_BIT, 0xFFFFFFF0, 0x00000020}, |
Karl Schultz | fc8eaf1 | 2016-05-06 13:56:42 -0600 | [diff] [blame] | 6364 | "vkCmdPushConstants() call has push constants with offset "}, |
Karl Schultz | c81037d | 2016-05-12 08:11:23 -0600 | [diff] [blame] | 6365 | {{VK_SHADER_STAGE_VERTEX_BIT, 0x00000020, 0xFFFFFFF0}, |
Karl Schultz | fc8eaf1 | 2016-05-06 13:56:42 -0600 | [diff] [blame] | 6366 | "vkCmdPushConstants() call has push constants with offset "}, |
| 6367 | }}; |
| 6368 | |
| 6369 | // Two ranges for testing robustness |
Karl Schultz | c81037d | 2016-05-12 08:11:23 -0600 | [diff] [blame] | 6370 | const VkPushConstantRange pc_range2[] = { |
Karl Schultz | fc8eaf1 | 2016-05-06 13:56:42 -0600 | [diff] [blame] | 6371 | {VK_SHADER_STAGE_VERTEX_BIT, 64, 16}, |
Karl Schultz | c81037d | 2016-05-12 08:11:23 -0600 | [diff] [blame] | 6372 | {VK_SHADER_STAGE_VERTEX_BIT, 0, 16}, |
Karl Schultz | fc8eaf1 | 2016-05-06 13:56:42 -0600 | [diff] [blame] | 6373 | }; |
Karl Schultz | c81037d | 2016-05-12 08:11:23 -0600 | [diff] [blame] | 6374 | pipeline_layout_ci.pushConstantRangeCount = |
| 6375 | sizeof(pc_range2) / sizeof(VkPushConstantRange); |
Karl Schultz | fc8eaf1 | 2016-05-06 13:56:42 -0600 | [diff] [blame] | 6376 | pipeline_layout_ci.pPushConstantRanges = pc_range2; |
Tobin Ehlis | 3a23b6a | 2016-02-17 10:35:18 -0700 | [diff] [blame] | 6377 | err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, |
| 6378 | &pipeline_layout); |
| 6379 | ASSERT_VK_SUCCESS(err); |
| 6380 | BeginCommandBuffer(); |
Karl Schultz | c81037d | 2016-05-12 08:11:23 -0600 | [diff] [blame] | 6381 | for (const auto &iter : cmd_range_tests) { |
Karl Schultz | fc8eaf1 | 2016-05-06 13:56:42 -0600 | [diff] [blame] | 6382 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 6383 | iter.msg); |
| 6384 | vkCmdPushConstants(m_commandBuffer->GetBufferHandle(), pipeline_layout, |
Karl Schultz | c81037d | 2016-05-12 08:11:23 -0600 | [diff] [blame] | 6385 | iter.range.stageFlags, iter.range.offset, |
| 6386 | iter.range.size, dummy_values); |
Karl Schultz | fc8eaf1 | 2016-05-06 13:56:42 -0600 | [diff] [blame] | 6387 | m_errorMonitor->VerifyFound(); |
| 6388 | } |
| 6389 | |
| 6390 | // Check for invalid stage flag |
| 6391 | m_errorMonitor->SetDesiredFailureMsg( |
| 6392 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 6393 | "vkCmdPushConstants() call has no stageFlags set."); |
| 6394 | vkCmdPushConstants(m_commandBuffer->GetBufferHandle(), pipeline_layout, 0, |
Karl Schultz | c81037d | 2016-05-12 08:11:23 -0600 | [diff] [blame] | 6395 | 0, 16, dummy_values); |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 6396 | m_errorMonitor->VerifyFound(); |
Karl Schultz | c81037d | 2016-05-12 08:11:23 -0600 | [diff] [blame] | 6397 | EndCommandBuffer(); |
| 6398 | vkResetCommandBuffer(m_commandBuffer->GetBufferHandle(), 0); |
| 6399 | vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL); |
Karl Schultz | fc8eaf1 | 2016-05-06 13:56:42 -0600 | [diff] [blame] | 6400 | |
Karl Schultz | c81037d | 2016-05-12 08:11:23 -0600 | [diff] [blame] | 6401 | // overlapping range tests with cmd |
| 6402 | const std::array<PipelineLayoutTestCase, 3> cmd_overlap_tests = {{ |
| 6403 | {{VK_SHADER_STAGE_VERTEX_BIT, 0, 20}, |
| 6404 | "vkCmdPushConstants() Push constant range [0, 20) with stageFlags = " |
| 6405 | "0x1 not within flag-matching ranges in pipeline layout"}, |
| 6406 | {{VK_SHADER_STAGE_VERTEX_BIT, 16, 4}, |
| 6407 | "vkCmdPushConstants() Push constant range [16, 20) with stageFlags = " |
| 6408 | "0x1 not within flag-matching ranges in pipeline layout"}, |
| 6409 | {{VK_SHADER_STAGE_VERTEX_BIT, 40, 16}, |
| 6410 | "vkCmdPushConstants() Push constant range [40, 56) with stageFlags = " |
| 6411 | "0x1 not within flag-matching ranges in pipeline layout"}, |
| 6412 | }}; |
| 6413 | const VkPushConstantRange pc_range3[] = { |
| 6414 | {VK_SHADER_STAGE_VERTEX_BIT, 20, 16}, |
| 6415 | {VK_SHADER_STAGE_VERTEX_BIT, 0, 16}, |
| 6416 | {VK_SHADER_STAGE_VERTEX_BIT, 0, 4}, |
| 6417 | {VK_SHADER_STAGE_VERTEX_BIT, 44, 8}, |
| 6418 | {VK_SHADER_STAGE_VERTEX_BIT, 80, 12}, |
| 6419 | {VK_SHADER_STAGE_VERTEX_BIT, 36, 8}, |
| 6420 | {VK_SHADER_STAGE_VERTEX_BIT, 56, 28}, |
| 6421 | }; |
| 6422 | pipeline_layout_ci.pushConstantRangeCount = |
| 6423 | sizeof(pc_range3) / sizeof(VkPushConstantRange); |
| 6424 | pipeline_layout_ci.pPushConstantRanges = pc_range3; |
| 6425 | err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, |
| 6426 | &pipeline_layout); |
| 6427 | ASSERT_VK_SUCCESS(err); |
| 6428 | BeginCommandBuffer(); |
| 6429 | for (const auto &iter : cmd_overlap_tests) { |
| 6430 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 6431 | iter.msg); |
| 6432 | vkCmdPushConstants(m_commandBuffer->GetBufferHandle(), pipeline_layout, |
| 6433 | iter.range.stageFlags, iter.range.offset, |
| 6434 | iter.range.size, dummy_values); |
| 6435 | m_errorMonitor->VerifyFound(); |
| 6436 | } |
| 6437 | EndCommandBuffer(); |
| 6438 | vkResetCommandBuffer(m_commandBuffer->GetBufferHandle(), 0); |
| 6439 | vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL); |
| 6440 | |
| 6441 | // positive overlapping range tests with cmd |
| 6442 | const std::array<PipelineLayoutTestCase, 4> cmd_overlap_tests_pos = {{ |
| 6443 | {{VK_SHADER_STAGE_VERTEX_BIT, 0, 16}, ""}, |
| 6444 | {{VK_SHADER_STAGE_VERTEX_BIT, 0, 4}, ""}, |
| 6445 | {{VK_SHADER_STAGE_VERTEX_BIT, 20, 12}, ""}, |
| 6446 | {{VK_SHADER_STAGE_VERTEX_BIT, 56, 36}, ""}, |
| 6447 | }}; |
| 6448 | const VkPushConstantRange pc_range4[] = { |
| 6449 | {VK_SHADER_STAGE_VERTEX_BIT, 0, 64}, |
| 6450 | {VK_SHADER_STAGE_VERTEX_BIT, 20, 16}, |
| 6451 | {VK_SHADER_STAGE_VERTEX_BIT, 0, 16}, |
| 6452 | {VK_SHADER_STAGE_VERTEX_BIT, 0, 4}, |
| 6453 | {VK_SHADER_STAGE_VERTEX_BIT, 44, 8}, |
| 6454 | {VK_SHADER_STAGE_VERTEX_BIT, 80, 12}, |
| 6455 | {VK_SHADER_STAGE_VERTEX_BIT, 36, 8}, |
| 6456 | {VK_SHADER_STAGE_VERTEX_BIT, 56, 28}, |
| 6457 | }; |
| 6458 | pipeline_layout_ci.pushConstantRangeCount = |
| 6459 | sizeof(pc_range4) / sizeof(VkPushConstantRange); |
| 6460 | pipeline_layout_ci.pPushConstantRanges = pc_range4; |
| 6461 | err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, |
| 6462 | &pipeline_layout); |
| 6463 | ASSERT_VK_SUCCESS(err); |
| 6464 | BeginCommandBuffer(); |
| 6465 | for (const auto &iter : cmd_overlap_tests_pos) { |
| 6466 | m_errorMonitor->ExpectSuccess(); |
| 6467 | vkCmdPushConstants(m_commandBuffer->GetBufferHandle(), pipeline_layout, |
| 6468 | iter.range.stageFlags, iter.range.offset, |
| 6469 | iter.range.size, dummy_values); |
| 6470 | m_errorMonitor->VerifyNotFound(); |
| 6471 | } |
| 6472 | EndCommandBuffer(); |
| 6473 | vkResetCommandBuffer(m_commandBuffer->GetBufferHandle(), 0); |
Tobin Ehlis | 3a23b6a | 2016-02-17 10:35:18 -0700 | [diff] [blame] | 6474 | vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL); |
| 6475 | } |
| 6476 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6477 | TEST_F(VkLayerTest, DescriptorSetCompatibility) { |
Tobin Ehlis | 559c638 | 2015-11-05 09:52:49 -0700 | [diff] [blame] | 6478 | // Test various desriptorSet errors with bad binding combinations |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6479 | VkResult err; |
Tobin Ehlis | 559c638 | 2015-11-05 09:52:49 -0700 | [diff] [blame] | 6480 | |
| 6481 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 6482 | ASSERT_NO_FATAL_FAILURE(InitViewport()); |
| 6483 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 6484 | |
Mike Stroyan | b8a6100 | 2016-06-20 16:00:28 -0600 | [diff] [blame] | 6485 | const VkFormat tex_format = VK_FORMAT_R8G8B8A8_UNORM; |
| 6486 | VkImageTiling tiling; |
| 6487 | VkFormatProperties format_properties; |
| 6488 | vkGetPhysicalDeviceFormatProperties(gpu(), tex_format, &format_properties); |
| 6489 | if (format_properties.linearTilingFeatures & |
| 6490 | VK_FORMAT_FEATURE_STORAGE_IMAGE_BIT) { |
| 6491 | tiling = VK_IMAGE_TILING_LINEAR; |
| 6492 | } else if (format_properties.optimalTilingFeatures & |
| 6493 | VK_FORMAT_FEATURE_STORAGE_IMAGE_BIT) { |
| 6494 | tiling = VK_IMAGE_TILING_OPTIMAL; |
| 6495 | } else { |
| 6496 | printf("Device does not support VK_FORMAT_FEATURE_STORAGE_IMAGE_BIT; " |
| 6497 | "skipped.\n"); |
| 6498 | return; |
| 6499 | } |
| 6500 | |
Tobin Ehlis | 559c638 | 2015-11-05 09:52:49 -0700 | [diff] [blame] | 6501 | static const uint32_t NUM_DESCRIPTOR_TYPES = 5; |
| 6502 | VkDescriptorPoolSize ds_type_count[NUM_DESCRIPTOR_TYPES] = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6503 | ds_type_count[0].type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 6504 | ds_type_count[0].descriptorCount = 10; |
| 6505 | ds_type_count[1].type = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE; |
| 6506 | ds_type_count[1].descriptorCount = 2; |
| 6507 | ds_type_count[2].type = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE; |
| 6508 | ds_type_count[2].descriptorCount = 2; |
| 6509 | ds_type_count[3].type = VK_DESCRIPTOR_TYPE_SAMPLER; |
| 6510 | ds_type_count[3].descriptorCount = 5; |
| 6511 | // TODO : LunarG ILO driver currently asserts in desc.c w/ INPUT_ATTACHMENT |
| 6512 | // type |
| 6513 | // ds_type_count[4].type = VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT; |
| 6514 | ds_type_count[4].type = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER; |
| 6515 | ds_type_count[4].descriptorCount = 2; |
Tobin Ehlis | 559c638 | 2015-11-05 09:52:49 -0700 | [diff] [blame] | 6516 | |
| 6517 | VkDescriptorPoolCreateInfo ds_pool_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6518 | ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO; |
| 6519 | ds_pool_ci.pNext = NULL; |
| 6520 | ds_pool_ci.maxSets = 5; |
| 6521 | ds_pool_ci.poolSizeCount = NUM_DESCRIPTOR_TYPES; |
| 6522 | ds_pool_ci.pPoolSizes = ds_type_count; |
Tobin Ehlis | 559c638 | 2015-11-05 09:52:49 -0700 | [diff] [blame] | 6523 | |
| 6524 | VkDescriptorPool ds_pool; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6525 | err = |
| 6526 | vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool); |
Tobin Ehlis | 559c638 | 2015-11-05 09:52:49 -0700 | [diff] [blame] | 6527 | ASSERT_VK_SUCCESS(err); |
| 6528 | |
| 6529 | static const uint32_t MAX_DS_TYPES_IN_LAYOUT = 2; |
| 6530 | VkDescriptorSetLayoutBinding dsl_binding[MAX_DS_TYPES_IN_LAYOUT] = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6531 | dsl_binding[0].binding = 0; |
| 6532 | dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 6533 | dsl_binding[0].descriptorCount = 5; |
| 6534 | dsl_binding[0].stageFlags = VK_SHADER_STAGE_ALL; |
| 6535 | dsl_binding[0].pImmutableSamplers = NULL; |
Tobin Ehlis | 559c638 | 2015-11-05 09:52:49 -0700 | [diff] [blame] | 6536 | |
Tobin Ehlis | 8fab656 | 2015-12-01 09:57:09 -0700 | [diff] [blame] | 6537 | // Create layout identical to set0 layout but w/ different stageFlags |
| 6538 | VkDescriptorSetLayoutBinding dsl_fs_stage_only = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6539 | dsl_fs_stage_only.binding = 0; |
| 6540 | dsl_fs_stage_only.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 6541 | dsl_fs_stage_only.descriptorCount = 5; |
| 6542 | dsl_fs_stage_only.stageFlags = |
| 6543 | VK_SHADER_STAGE_FRAGMENT_BIT; // Different stageFlags to cause error at |
| 6544 | // bind time |
| 6545 | dsl_fs_stage_only.pImmutableSamplers = NULL; |
Tobin Ehlis | 559c638 | 2015-11-05 09:52:49 -0700 | [diff] [blame] | 6546 | VkDescriptorSetLayoutCreateInfo ds_layout_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6547 | ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO; |
| 6548 | ds_layout_ci.pNext = NULL; |
| 6549 | ds_layout_ci.bindingCount = 1; |
| 6550 | ds_layout_ci.pBindings = dsl_binding; |
Tobin Ehlis | 559c638 | 2015-11-05 09:52:49 -0700 | [diff] [blame] | 6551 | static const uint32_t NUM_LAYOUTS = 4; |
| 6552 | VkDescriptorSetLayout ds_layout[NUM_LAYOUTS] = {}; |
Tobin Ehlis | 8fab656 | 2015-12-01 09:57:09 -0700 | [diff] [blame] | 6553 | VkDescriptorSetLayout ds_layout_fs_only = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6554 | // Create 4 unique layouts for full pipelineLayout, and 1 special fs-only |
| 6555 | // layout for error case |
| 6556 | err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, |
| 6557 | &ds_layout[0]); |
Tobin Ehlis | 559c638 | 2015-11-05 09:52:49 -0700 | [diff] [blame] | 6558 | ASSERT_VK_SUCCESS(err); |
Jon Ashburn | 6e23c1f | 2015-12-30 18:01:16 -0700 | [diff] [blame] | 6559 | ds_layout_ci.pBindings = &dsl_fs_stage_only; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6560 | err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, |
| 6561 | &ds_layout_fs_only); |
Tobin Ehlis | 8fab656 | 2015-12-01 09:57:09 -0700 | [diff] [blame] | 6562 | ASSERT_VK_SUCCESS(err); |
Tobin Ehlis | 559c638 | 2015-11-05 09:52:49 -0700 | [diff] [blame] | 6563 | dsl_binding[0].binding = 0; |
| 6564 | dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE; |
Tobin Ehlis | 8fab656 | 2015-12-01 09:57:09 -0700 | [diff] [blame] | 6565 | dsl_binding[0].descriptorCount = 2; |
Mike Stroyan | 9c70cdb | 2016-01-06 14:14:17 -0700 | [diff] [blame] | 6566 | dsl_binding[1].binding = 1; |
| 6567 | dsl_binding[1].descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE; |
| 6568 | dsl_binding[1].descriptorCount = 2; |
| 6569 | dsl_binding[1].stageFlags = VK_SHADER_STAGE_ALL; |
| 6570 | dsl_binding[1].pImmutableSamplers = NULL; |
Jon Ashburn | 6e23c1f | 2015-12-30 18:01:16 -0700 | [diff] [blame] | 6571 | ds_layout_ci.pBindings = dsl_binding; |
Tobin Ehlis | 559c638 | 2015-11-05 09:52:49 -0700 | [diff] [blame] | 6572 | ds_layout_ci.bindingCount = 2; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6573 | err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, |
| 6574 | &ds_layout[1]); |
Tobin Ehlis | 559c638 | 2015-11-05 09:52:49 -0700 | [diff] [blame] | 6575 | ASSERT_VK_SUCCESS(err); |
| 6576 | dsl_binding[0].binding = 0; |
| 6577 | dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER; |
Tobin Ehlis | 8fab656 | 2015-12-01 09:57:09 -0700 | [diff] [blame] | 6578 | dsl_binding[0].descriptorCount = 5; |
Tobin Ehlis | 559c638 | 2015-11-05 09:52:49 -0700 | [diff] [blame] | 6579 | ds_layout_ci.bindingCount = 1; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6580 | err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, |
| 6581 | &ds_layout[2]); |
Tobin Ehlis | 559c638 | 2015-11-05 09:52:49 -0700 | [diff] [blame] | 6582 | ASSERT_VK_SUCCESS(err); |
| 6583 | dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER; |
Tobin Ehlis | 8fab656 | 2015-12-01 09:57:09 -0700 | [diff] [blame] | 6584 | dsl_binding[0].descriptorCount = 2; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6585 | err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, |
| 6586 | &ds_layout[3]); |
Tobin Ehlis | 559c638 | 2015-11-05 09:52:49 -0700 | [diff] [blame] | 6587 | ASSERT_VK_SUCCESS(err); |
| 6588 | |
| 6589 | static const uint32_t NUM_SETS = 4; |
| 6590 | VkDescriptorSet descriptorSet[NUM_SETS] = {}; |
| 6591 | VkDescriptorSetAllocateInfo alloc_info = {}; |
Tobin Ehlis | 8fab656 | 2015-12-01 09:57:09 -0700 | [diff] [blame] | 6592 | alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO; |
Jon Ashburn | f19916e | 2016-01-11 13:12:43 -0700 | [diff] [blame] | 6593 | alloc_info.descriptorSetCount = NUM_LAYOUTS; |
Tobin Ehlis | 559c638 | 2015-11-05 09:52:49 -0700 | [diff] [blame] | 6594 | alloc_info.descriptorPool = ds_pool; |
| 6595 | alloc_info.pSetLayouts = ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6596 | err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, |
| 6597 | descriptorSet); |
Tobin Ehlis | 559c638 | 2015-11-05 09:52:49 -0700 | [diff] [blame] | 6598 | ASSERT_VK_SUCCESS(err); |
Tobin Ehlis | 8fab656 | 2015-12-01 09:57:09 -0700 | [diff] [blame] | 6599 | VkDescriptorSet ds0_fs_only = {}; |
Jon Ashburn | f19916e | 2016-01-11 13:12:43 -0700 | [diff] [blame] | 6600 | alloc_info.descriptorSetCount = 1; |
Tobin Ehlis | 8fab656 | 2015-12-01 09:57:09 -0700 | [diff] [blame] | 6601 | alloc_info.pSetLayouts = &ds_layout_fs_only; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6602 | err = |
| 6603 | vkAllocateDescriptorSets(m_device->device(), &alloc_info, &ds0_fs_only); |
Tobin Ehlis | 8fab656 | 2015-12-01 09:57:09 -0700 | [diff] [blame] | 6604 | ASSERT_VK_SUCCESS(err); |
Tobin Ehlis | 559c638 | 2015-11-05 09:52:49 -0700 | [diff] [blame] | 6605 | |
| 6606 | VkPipelineLayoutCreateInfo pipeline_layout_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6607 | pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO; |
| 6608 | pipeline_layout_ci.pNext = NULL; |
| 6609 | pipeline_layout_ci.setLayoutCount = NUM_LAYOUTS; |
| 6610 | pipeline_layout_ci.pSetLayouts = ds_layout; |
Tobin Ehlis | 559c638 | 2015-11-05 09:52:49 -0700 | [diff] [blame] | 6611 | |
| 6612 | VkPipelineLayout pipeline_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6613 | err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, |
| 6614 | &pipeline_layout); |
Tobin Ehlis | 559c638 | 2015-11-05 09:52:49 -0700 | [diff] [blame] | 6615 | ASSERT_VK_SUCCESS(err); |
Tobin Ehlis | 8fab656 | 2015-12-01 09:57:09 -0700 | [diff] [blame] | 6616 | // Create pipelineLayout with only one setLayout |
| 6617 | pipeline_layout_ci.setLayoutCount = 1; |
| 6618 | VkPipelineLayout single_pipe_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6619 | err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, |
| 6620 | &single_pipe_layout); |
Tobin Ehlis | 8fab656 | 2015-12-01 09:57:09 -0700 | [diff] [blame] | 6621 | ASSERT_VK_SUCCESS(err); |
| 6622 | // Create pipelineLayout with 2 descriptor setLayout at index 0 |
| 6623 | pipeline_layout_ci.pSetLayouts = &ds_layout[3]; |
| 6624 | VkPipelineLayout pipe_layout_one_desc; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6625 | err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, |
| 6626 | &pipe_layout_one_desc); |
Tobin Ehlis | 8fab656 | 2015-12-01 09:57:09 -0700 | [diff] [blame] | 6627 | ASSERT_VK_SUCCESS(err); |
| 6628 | // Create pipelineLayout with 5 SAMPLER descriptor setLayout at index 0 |
| 6629 | pipeline_layout_ci.pSetLayouts = &ds_layout[2]; |
| 6630 | VkPipelineLayout pipe_layout_five_samp; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6631 | err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, |
| 6632 | &pipe_layout_five_samp); |
Tobin Ehlis | 8fab656 | 2015-12-01 09:57:09 -0700 | [diff] [blame] | 6633 | ASSERT_VK_SUCCESS(err); |
| 6634 | // Create pipelineLayout with UB type, but stageFlags for FS only |
| 6635 | pipeline_layout_ci.pSetLayouts = &ds_layout_fs_only; |
| 6636 | VkPipelineLayout pipe_layout_fs_only; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6637 | err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, |
| 6638 | &pipe_layout_fs_only); |
Tobin Ehlis | 8fab656 | 2015-12-01 09:57:09 -0700 | [diff] [blame] | 6639 | ASSERT_VK_SUCCESS(err); |
| 6640 | // Create pipelineLayout w/ incompatible set0 layout, but set1 is fine |
| 6641 | VkDescriptorSetLayout pl_bad_s0[2] = {}; |
| 6642 | pl_bad_s0[0] = ds_layout_fs_only; |
| 6643 | pl_bad_s0[1] = ds_layout[1]; |
| 6644 | pipeline_layout_ci.setLayoutCount = 2; |
| 6645 | pipeline_layout_ci.pSetLayouts = pl_bad_s0; |
| 6646 | VkPipelineLayout pipe_layout_bad_set0; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6647 | err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, |
| 6648 | &pipe_layout_bad_set0); |
Tobin Ehlis | 8fab656 | 2015-12-01 09:57:09 -0700 | [diff] [blame] | 6649 | ASSERT_VK_SUCCESS(err); |
Tobin Ehlis | 559c638 | 2015-11-05 09:52:49 -0700 | [diff] [blame] | 6650 | |
| 6651 | // Create a buffer to update the descriptor with |
| 6652 | uint32_t qfi = 0; |
| 6653 | VkBufferCreateInfo buffCI = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6654 | buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO; |
| 6655 | buffCI.size = 1024; |
| 6656 | buffCI.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT; |
| 6657 | buffCI.queueFamilyIndexCount = 1; |
| 6658 | buffCI.pQueueFamilyIndices = &qfi; |
Tobin Ehlis | 559c638 | 2015-11-05 09:52:49 -0700 | [diff] [blame] | 6659 | |
| 6660 | VkBuffer dyub; |
| 6661 | err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &dyub); |
| 6662 | ASSERT_VK_SUCCESS(err); |
| 6663 | // Correctly update descriptor to avoid "NOT_UPDATED" error |
| 6664 | static const uint32_t NUM_BUFFS = 5; |
| 6665 | VkDescriptorBufferInfo buffInfo[NUM_BUFFS] = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6666 | for (uint32_t i = 0; i < NUM_BUFFS; ++i) { |
Tobin Ehlis | 559c638 | 2015-11-05 09:52:49 -0700 | [diff] [blame] | 6667 | buffInfo[i].buffer = dyub; |
| 6668 | buffInfo[i].offset = 0; |
| 6669 | buffInfo[i].range = 1024; |
| 6670 | } |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6671 | VkImage image; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6672 | const int32_t tex_width = 32; |
| 6673 | const int32_t tex_height = 32; |
Tobin Ehlis | 8fab656 | 2015-12-01 09:57:09 -0700 | [diff] [blame] | 6674 | VkImageCreateInfo image_create_info = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6675 | image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO; |
| 6676 | image_create_info.pNext = NULL; |
| 6677 | image_create_info.imageType = VK_IMAGE_TYPE_2D; |
| 6678 | image_create_info.format = tex_format; |
| 6679 | image_create_info.extent.width = tex_width; |
| 6680 | image_create_info.extent.height = tex_height; |
| 6681 | image_create_info.extent.depth = 1; |
| 6682 | image_create_info.mipLevels = 1; |
| 6683 | image_create_info.arrayLayers = 1; |
| 6684 | image_create_info.samples = VK_SAMPLE_COUNT_1_BIT; |
Mike Stroyan | b8a6100 | 2016-06-20 16:00:28 -0600 | [diff] [blame] | 6685 | image_create_info.tiling = tiling; |
| 6686 | image_create_info.usage = |
| 6687 | VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_STORAGE_BIT; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6688 | image_create_info.flags = 0; |
Tobin Ehlis | 8fab656 | 2015-12-01 09:57:09 -0700 | [diff] [blame] | 6689 | err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image); |
| 6690 | ASSERT_VK_SUCCESS(err); |
Tobin Ehlis | 559c638 | 2015-11-05 09:52:49 -0700 | [diff] [blame] | 6691 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6692 | VkMemoryRequirements memReqs; |
| 6693 | VkDeviceMemory imageMem; |
| 6694 | bool pass; |
Mike Stroyan | 9c70cdb | 2016-01-06 14:14:17 -0700 | [diff] [blame] | 6695 | VkMemoryAllocateInfo memAlloc = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6696 | memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO; |
| 6697 | memAlloc.pNext = NULL; |
| 6698 | memAlloc.allocationSize = 0; |
| 6699 | memAlloc.memoryTypeIndex = 0; |
Mike Stroyan | 9c70cdb | 2016-01-06 14:14:17 -0700 | [diff] [blame] | 6700 | vkGetImageMemoryRequirements(m_device->device(), image, &memReqs); |
| 6701 | memAlloc.allocationSize = memReqs.size; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6702 | pass = |
| 6703 | m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0); |
Mike Stroyan | 9c70cdb | 2016-01-06 14:14:17 -0700 | [diff] [blame] | 6704 | ASSERT_TRUE(pass); |
| 6705 | err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &imageMem); |
| 6706 | ASSERT_VK_SUCCESS(err); |
| 6707 | err = vkBindImageMemory(m_device->device(), image, imageMem, 0); |
| 6708 | ASSERT_VK_SUCCESS(err); |
| 6709 | |
Tobin Ehlis | 8fab656 | 2015-12-01 09:57:09 -0700 | [diff] [blame] | 6710 | VkImageViewCreateInfo image_view_create_info = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6711 | image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO; |
| 6712 | image_view_create_info.image = image; |
| 6713 | image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D; |
| 6714 | image_view_create_info.format = tex_format; |
| 6715 | image_view_create_info.subresourceRange.layerCount = 1; |
| 6716 | image_view_create_info.subresourceRange.baseMipLevel = 0; |
| 6717 | image_view_create_info.subresourceRange.levelCount = 1; |
| 6718 | image_view_create_info.subresourceRange.aspectMask = |
| 6719 | VK_IMAGE_ASPECT_COLOR_BIT; |
Tobin Ehlis | 559c638 | 2015-11-05 09:52:49 -0700 | [diff] [blame] | 6720 | |
Tobin Ehlis | 8fab656 | 2015-12-01 09:57:09 -0700 | [diff] [blame] | 6721 | VkImageView view; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6722 | err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, |
| 6723 | &view); |
Tobin Ehlis | 8fab656 | 2015-12-01 09:57:09 -0700 | [diff] [blame] | 6724 | ASSERT_VK_SUCCESS(err); |
Tobin Ehlis | 991d45a | 2016-01-06 08:48:41 -0700 | [diff] [blame] | 6725 | VkDescriptorImageInfo imageInfo[4] = {}; |
Tobin Ehlis | 8fab656 | 2015-12-01 09:57:09 -0700 | [diff] [blame] | 6726 | imageInfo[0].imageView = view; |
| 6727 | imageInfo[0].imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL; |
| 6728 | imageInfo[1].imageView = view; |
| 6729 | imageInfo[1].imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL; |
Tobin Ehlis | 991d45a | 2016-01-06 08:48:41 -0700 | [diff] [blame] | 6730 | imageInfo[2].imageView = view; |
| 6731 | imageInfo[2].imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL; |
| 6732 | imageInfo[3].imageView = view; |
| 6733 | imageInfo[3].imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL; |
Tobin Ehlis | 8fab656 | 2015-12-01 09:57:09 -0700 | [diff] [blame] | 6734 | |
| 6735 | static const uint32_t NUM_SET_UPDATES = 3; |
| 6736 | VkWriteDescriptorSet descriptor_write[NUM_SET_UPDATES] = {}; |
| 6737 | descriptor_write[0].sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET; |
| 6738 | descriptor_write[0].dstSet = descriptorSet[0]; |
| 6739 | descriptor_write[0].dstBinding = 0; |
| 6740 | descriptor_write[0].descriptorCount = 5; |
| 6741 | descriptor_write[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 6742 | descriptor_write[0].pBufferInfo = buffInfo; |
| 6743 | descriptor_write[1].sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET; |
| 6744 | descriptor_write[1].dstSet = descriptorSet[1]; |
| 6745 | descriptor_write[1].dstBinding = 0; |
| 6746 | descriptor_write[1].descriptorCount = 2; |
| 6747 | descriptor_write[1].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE; |
| 6748 | descriptor_write[1].pImageInfo = imageInfo; |
| 6749 | descriptor_write[2].sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET; |
| 6750 | descriptor_write[2].dstSet = descriptorSet[1]; |
| 6751 | descriptor_write[2].dstBinding = 1; |
| 6752 | descriptor_write[2].descriptorCount = 2; |
| 6753 | descriptor_write[2].descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE; |
Tobin Ehlis | 991d45a | 2016-01-06 08:48:41 -0700 | [diff] [blame] | 6754 | descriptor_write[2].pImageInfo = &imageInfo[2]; |
Tobin Ehlis | 8fab656 | 2015-12-01 09:57:09 -0700 | [diff] [blame] | 6755 | |
| 6756 | vkUpdateDescriptorSets(m_device->device(), 3, descriptor_write, 0, NULL); |
Tobin Ehlis | 559c638 | 2015-11-05 09:52:49 -0700 | [diff] [blame] | 6757 | |
Tobin Ehlis | 8845283 | 2015-12-03 09:40:56 -0700 | [diff] [blame] | 6758 | // Create PSO to be used for draw-time errors below |
| 6759 | char const *vsSource = |
Chris Forbes | 7b34280 | 2016-04-07 13:20:10 +1200 | [diff] [blame] | 6760 | "#version 450\n" |
Tobin Ehlis | 8845283 | 2015-12-03 09:40:56 -0700 | [diff] [blame] | 6761 | "\n" |
Tony Barbour | e804d20 | 2016-01-05 13:37:45 -0700 | [diff] [blame] | 6762 | "out gl_PerVertex {\n" |
| 6763 | " vec4 gl_Position;\n" |
| 6764 | "};\n" |
Tobin Ehlis | 8845283 | 2015-12-03 09:40:56 -0700 | [diff] [blame] | 6765 | "void main(){\n" |
| 6766 | " gl_Position = vec4(1);\n" |
| 6767 | "}\n"; |
| 6768 | char const *fsSource = |
Chris Forbes | 7b34280 | 2016-04-07 13:20:10 +1200 | [diff] [blame] | 6769 | "#version 450\n" |
Tobin Ehlis | 8845283 | 2015-12-03 09:40:56 -0700 | [diff] [blame] | 6770 | "\n" |
| 6771 | "layout(location=0) out vec4 x;\n" |
| 6772 | "layout(set=0) layout(binding=0) uniform foo { int x; int y; } bar;\n" |
| 6773 | "void main(){\n" |
| 6774 | " x = vec4(bar.y);\n" |
| 6775 | "}\n"; |
| 6776 | VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this); |
| 6777 | VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this); |
Tobin Ehlis | 559c638 | 2015-11-05 09:52:49 -0700 | [diff] [blame] | 6778 | VkPipelineObj pipe(m_device); |
| 6779 | pipe.AddShader(&vs); |
| 6780 | pipe.AddShader(&fs); |
Tobin Ehlis | 8845283 | 2015-12-03 09:40:56 -0700 | [diff] [blame] | 6781 | pipe.AddColorAttachment(); |
| 6782 | pipe.CreateVKPipeline(pipe_layout_fs_only, renderPass()); |
Tobin Ehlis | 559c638 | 2015-11-05 09:52:49 -0700 | [diff] [blame] | 6783 | |
| 6784 | BeginCommandBuffer(); |
Tobin Ehlis | 8845283 | 2015-12-03 09:40:56 -0700 | [diff] [blame] | 6785 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6786 | vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), |
| 6787 | VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle()); |
| 6788 | // NOTE : I believe LunarG ilo driver has bug (LX#189) that requires binding |
| 6789 | // of PSO |
| 6790 | // here before binding DSs. Otherwise we assert in cmd_copy_dset_data() of |
| 6791 | // cmd_pipeline.c |
| 6792 | // due to the fact that cmd_alloc_dset_data() has not been called in |
| 6793 | // cmd_bind_graphics_pipeline() |
| 6794 | // TODO : Want to cause various binding incompatibility issues here to test |
| 6795 | // DrawState |
Tobin Ehlis | 559c638 | 2015-11-05 09:52:49 -0700 | [diff] [blame] | 6796 | // First cause various verify_layout_compatibility() fails |
| 6797 | // Second disturb early and late sets and verify INFO msgs |
Tobin Ehlis | 8fab656 | 2015-12-01 09:57:09 -0700 | [diff] [blame] | 6798 | // verify_set_layout_compatibility fail cases: |
| 6799 | // 1. invalid VkPipelineLayout (layout) passed into vkCmdBindDescriptorSets |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6800 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 6801 | " due to: invalid VkPipelineLayout "); |
| 6802 | vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), |
| 6803 | VK_PIPELINE_BIND_POINT_GRAPHICS, |
| 6804 | (VkPipelineLayout)((size_t)0xbaadb1be), 0, 1, |
| 6805 | &descriptorSet[0], 0, NULL); |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 6806 | m_errorMonitor->VerifyFound(); |
| 6807 | |
Tobin Ehlis | 8fab656 | 2015-12-01 09:57:09 -0700 | [diff] [blame] | 6808 | // 2. layoutIndex exceeds # of layouts in layout |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6809 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 6810 | " attempting to bind set to index 1"); |
| 6811 | vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), |
| 6812 | VK_PIPELINE_BIND_POINT_GRAPHICS, single_pipe_layout, |
| 6813 | 0, 2, &descriptorSet[0], 0, NULL); |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 6814 | m_errorMonitor->VerifyFound(); |
| 6815 | |
Tobin Ehlis | 8fab656 | 2015-12-01 09:57:09 -0700 | [diff] [blame] | 6816 | vkDestroyPipelineLayout(m_device->device(), single_pipe_layout, NULL); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6817 | // 3. Pipeline setLayout[0] has 2 descriptors, but set being bound has 5 |
| 6818 | // descriptors |
| 6819 | m_errorMonitor->SetDesiredFailureMsg( |
| 6820 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Tobin Ehlis | 2d9deec | 2016-04-21 14:19:26 -0600 | [diff] [blame] | 6821 | " has 2 descriptors, but DescriptorSetLayout "); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6822 | vkCmdBindDescriptorSets( |
| 6823 | m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, |
| 6824 | pipe_layout_one_desc, 0, 1, &descriptorSet[0], 0, NULL); |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 6825 | m_errorMonitor->VerifyFound(); |
| 6826 | |
Tobin Ehlis | 8fab656 | 2015-12-01 09:57:09 -0700 | [diff] [blame] | 6827 | vkDestroyPipelineLayout(m_device->device(), pipe_layout_one_desc, NULL); |
| 6828 | // 4. same # of descriptors but mismatch in type |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6829 | m_errorMonitor->SetDesiredFailureMsg( |
| 6830 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Tobin Ehlis | 2d9deec | 2016-04-21 14:19:26 -0600 | [diff] [blame] | 6831 | " is type 'VK_DESCRIPTOR_TYPE_SAMPLER' but binding "); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6832 | vkCmdBindDescriptorSets( |
| 6833 | m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, |
| 6834 | pipe_layout_five_samp, 0, 1, &descriptorSet[0], 0, NULL); |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 6835 | m_errorMonitor->VerifyFound(); |
| 6836 | |
Tobin Ehlis | 8fab656 | 2015-12-01 09:57:09 -0700 | [diff] [blame] | 6837 | vkDestroyPipelineLayout(m_device->device(), pipe_layout_five_samp, NULL); |
| 6838 | // 5. same # of descriptors but mismatch in stageFlags |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6839 | m_errorMonitor->SetDesiredFailureMsg( |
| 6840 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Tobin Ehlis | 2d9deec | 2016-04-21 14:19:26 -0600 | [diff] [blame] | 6841 | " has stageFlags 16 but binding 0 for DescriptorSetLayout "); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6842 | vkCmdBindDescriptorSets( |
| 6843 | m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, |
| 6844 | pipe_layout_fs_only, 0, 1, &descriptorSet[0], 0, NULL); |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 6845 | m_errorMonitor->VerifyFound(); |
| 6846 | |
Tobin Ehlis | 8fab656 | 2015-12-01 09:57:09 -0700 | [diff] [blame] | 6847 | // Cause INFO messages due to disturbing previously bound Sets |
| 6848 | // First bind sets 0 & 1 |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6849 | vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), |
| 6850 | VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, |
| 6851 | 2, &descriptorSet[0], 0, NULL); |
Tobin Ehlis | 8fab656 | 2015-12-01 09:57:09 -0700 | [diff] [blame] | 6852 | // 1. Disturb bound set0 by re-binding set1 w/ updated pipelineLayout |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6853 | m_errorMonitor->SetDesiredFailureMsg( |
Mark Lobodzinski | 510e20d | 2016-02-11 09:26:16 -0700 | [diff] [blame] | 6854 | VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6855 | " previously bound as set #0 was disturbed "); |
| 6856 | vkCmdBindDescriptorSets( |
| 6857 | m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, |
| 6858 | pipe_layout_bad_set0, 1, 1, &descriptorSet[1], 0, NULL); |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 6859 | m_errorMonitor->VerifyFound(); |
| 6860 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6861 | vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), |
| 6862 | VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, |
| 6863 | 2, &descriptorSet[0], 0, NULL); |
Tobin Ehlis | 8fab656 | 2015-12-01 09:57:09 -0700 | [diff] [blame] | 6864 | // 2. Disturb set after last bound set |
Mark Lobodzinski | 510e20d | 2016-02-11 09:26:16 -0700 | [diff] [blame] | 6865 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6866 | " newly bound as set #0 so set #1 and " |
| 6867 | "any subsequent sets were disturbed "); |
| 6868 | vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), |
| 6869 | VK_PIPELINE_BIND_POINT_GRAPHICS, |
| 6870 | pipe_layout_fs_only, 0, 1, &ds0_fs_only, 0, NULL); |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 6871 | m_errorMonitor->VerifyFound(); |
| 6872 | |
Tobin Ehlis | 8845283 | 2015-12-03 09:40:56 -0700 | [diff] [blame] | 6873 | // Cause draw-time errors due to PSO incompatibilities |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6874 | // 1. Error due to not binding required set (we actually use same code as |
| 6875 | // above to disturb set0) |
| 6876 | vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), |
| 6877 | VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, |
| 6878 | 2, &descriptorSet[0], 0, NULL); |
| 6879 | vkCmdBindDescriptorSets( |
| 6880 | m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, |
| 6881 | pipe_layout_bad_set0, 1, 1, &descriptorSet[1], 0, NULL); |
| 6882 | m_errorMonitor->SetDesiredFailureMsg( |
| 6883 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 6884 | " uses set #0 but that set is not bound."); |
Tobin Ehlis | 8845283 | 2015-12-03 09:40:56 -0700 | [diff] [blame] | 6885 | Draw(1, 0, 0, 0); |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 6886 | m_errorMonitor->VerifyFound(); |
| 6887 | |
Tobin Ehlis | 991d45a | 2016-01-06 08:48:41 -0700 | [diff] [blame] | 6888 | vkDestroyPipelineLayout(m_device->device(), pipe_layout_bad_set0, NULL); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6889 | // 2. Error due to bound set not being compatible with PSO's |
| 6890 | // VkPipelineLayout (diff stageFlags in this case) |
| 6891 | vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), |
| 6892 | VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, |
| 6893 | 2, &descriptorSet[0], 0, NULL); |
| 6894 | m_errorMonitor->SetDesiredFailureMsg( |
| 6895 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 6896 | " bound as set #0 is not compatible with "); |
Tobin Ehlis | 8845283 | 2015-12-03 09:40:56 -0700 | [diff] [blame] | 6897 | Draw(1, 0, 0, 0); |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 6898 | m_errorMonitor->VerifyFound(); |
| 6899 | |
Tobin Ehlis | 8fab656 | 2015-12-01 09:57:09 -0700 | [diff] [blame] | 6900 | // Remaining clean-up |
| 6901 | vkDestroyPipelineLayout(m_device->device(), pipe_layout_fs_only, NULL); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6902 | for (uint32_t i = 0; i < NUM_LAYOUTS; ++i) { |
Tobin Ehlis | 8fab656 | 2015-12-01 09:57:09 -0700 | [diff] [blame] | 6903 | vkDestroyDescriptorSetLayout(m_device->device(), ds_layout[i], NULL); |
| 6904 | } |
| 6905 | vkDestroyDescriptorSetLayout(m_device->device(), ds_layout_fs_only, NULL); |
Tobin Ehlis | 9bfd449 | 2016-05-05 15:09:11 -0600 | [diff] [blame] | 6906 | vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &ds0_fs_only); |
| 6907 | vkFreeDescriptorSets(m_device->device(), ds_pool, NUM_SETS, descriptorSet); |
Tobin Ehlis | 8fab656 | 2015-12-01 09:57:09 -0700 | [diff] [blame] | 6908 | vkDestroyBuffer(m_device->device(), dyub, NULL); |
Tobin Ehlis | 559c638 | 2015-11-05 09:52:49 -0700 | [diff] [blame] | 6909 | vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL); |
| 6910 | vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL); |
Tony Barbour | df4c004 | 2016-06-01 15:55:43 -0600 | [diff] [blame] | 6911 | vkFreeMemory(m_device->device(), imageMem, NULL); |
| 6912 | vkDestroyImage(m_device->device(), image, NULL); |
| 6913 | vkDestroyImageView(m_device->device(), view, NULL); |
Tobin Ehlis | 559c638 | 2015-11-05 09:52:49 -0700 | [diff] [blame] | 6914 | } |
Tobin Ehlis | 559c638 | 2015-11-05 09:52:49 -0700 | [diff] [blame] | 6915 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6916 | TEST_F(VkLayerTest, NoBeginCommandBuffer) { |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 6917 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6918 | m_errorMonitor->SetDesiredFailureMsg( |
| 6919 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 6920 | "You must call vkBeginCommandBuffer() before this call to "); |
Tobin Ehlis | af1f3a4 | 2015-06-25 15:46:59 -0600 | [diff] [blame] | 6921 | |
| 6922 | ASSERT_NO_FATAL_FAILURE(InitState()); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 6923 | VkCommandBufferObj commandBuffer(m_device, m_commandPool); |
Tobin Ehlis | af1f3a4 | 2015-06-25 15:46:59 -0600 | [diff] [blame] | 6924 | // Call EndCommandBuffer() w/o calling BeginCommandBuffer() |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 6925 | vkEndCommandBuffer(commandBuffer.GetBufferHandle()); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 6926 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 6927 | m_errorMonitor->VerifyFound(); |
Tobin Ehlis | af1f3a4 | 2015-06-25 15:46:59 -0600 | [diff] [blame] | 6928 | } |
| 6929 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6930 | TEST_F(VkLayerTest, SecondaryCommandBufferNullRenderpass) { |
| 6931 | VkResult err; |
| 6932 | VkCommandBuffer draw_cmd; |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 6933 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6934 | m_errorMonitor->SetDesiredFailureMsg( |
| 6935 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Tobin Ehlis | 61b36f3 | 2015-12-16 08:19:42 -0700 | [diff] [blame] | 6936 | " must specify a valid renderpass parameter."); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 6937 | |
Mark Lobodzinski | d9139a6 | 2015-08-04 16:24:20 -0600 | [diff] [blame] | 6938 | ASSERT_NO_FATAL_FAILURE(InitState()); |
Mark Lobodzinski | d9139a6 | 2015-08-04 16:24:20 -0600 | [diff] [blame] | 6939 | |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 6940 | VkCommandBufferAllocateInfo cmd = {}; |
Chia-I Wu | 00ce540 | 2015-11-10 16:21:09 +0800 | [diff] [blame] | 6941 | cmd.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO; |
Cody Northrop | b456970 | 2015-08-04 17:35:57 -0600 | [diff] [blame] | 6942 | cmd.pNext = NULL; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 6943 | cmd.commandPool = m_commandPool; |
| 6944 | cmd.level = VK_COMMAND_BUFFER_LEVEL_SECONDARY; |
Jon Ashburn | f19916e | 2016-01-11 13:12:43 -0700 | [diff] [blame] | 6945 | cmd.commandBufferCount = 1; |
Cody Northrop | b456970 | 2015-08-04 17:35:57 -0600 | [diff] [blame] | 6946 | |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 6947 | err = vkAllocateCommandBuffers(m_device->device(), &cmd, &draw_cmd); |
Mike Stroyan | d1c84a5 | 2015-08-18 14:40:24 -0600 | [diff] [blame] | 6948 | ASSERT_VK_SUCCESS(err); |
Mark Lobodzinski | d9139a6 | 2015-08-04 16:24:20 -0600 | [diff] [blame] | 6949 | |
| 6950 | // Force the failure by not setting the Renderpass and Framebuffer fields |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 6951 | VkCommandBufferBeginInfo cmd_buf_info = {}; |
Jon Ashburn | f19916e | 2016-01-11 13:12:43 -0700 | [diff] [blame] | 6952 | VkCommandBufferInheritanceInfo cmd_buf_hinfo = {}; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 6953 | cmd_buf_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO; |
Cody Northrop | b456970 | 2015-08-04 17:35:57 -0600 | [diff] [blame] | 6954 | cmd_buf_info.pNext = NULL; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6955 | cmd_buf_info.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT | |
| 6956 | VK_COMMAND_BUFFER_USAGE_RENDER_PASS_CONTINUE_BIT; |
Jon Ashburn | f19916e | 2016-01-11 13:12:43 -0700 | [diff] [blame] | 6957 | cmd_buf_info.pInheritanceInfo = &cmd_buf_hinfo; |
Mark Lobodzinski | d9139a6 | 2015-08-04 16:24:20 -0600 | [diff] [blame] | 6958 | |
| 6959 | // The error should be caught by validation of the BeginCommandBuffer call |
| 6960 | vkBeginCommandBuffer(draw_cmd, &cmd_buf_info); |
| 6961 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 6962 | m_errorMonitor->VerifyFound(); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 6963 | vkFreeCommandBuffers(m_device->device(), m_commandPool, 1, &draw_cmd); |
Mark Lobodzinski | d9139a6 | 2015-08-04 16:24:20 -0600 | [diff] [blame] | 6964 | } |
| 6965 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6966 | TEST_F(VkLayerTest, CommandBufferResetErrors) { |
Tobin Ehlis | ac0ef84 | 2015-12-14 13:46:38 -0700 | [diff] [blame] | 6967 | // Cause error due to Begin while recording CB |
| 6968 | // Then cause 2 errors for attempting to reset CB w/o having |
| 6969 | // VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT set for the pool from |
| 6970 | // which CBs were allocated. Note that this bit is off by default. |
Courtney Goeltzenleuchter | 7415d5a | 2015-12-09 15:48:16 -0700 | [diff] [blame] | 6971 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6972 | "Cannot call Begin on CB"); |
Tobin Ehlis | ac0ef84 | 2015-12-14 13:46:38 -0700 | [diff] [blame] | 6973 | |
| 6974 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 6975 | |
| 6976 | // Calls AllocateCommandBuffers |
| 6977 | VkCommandBufferObj commandBuffer(m_device, m_commandPool); |
| 6978 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6979 | // Force the failure by setting the Renderpass and Framebuffer fields with |
| 6980 | // (fake) data |
Tobin Ehlis | ac0ef84 | 2015-12-14 13:46:38 -0700 | [diff] [blame] | 6981 | VkCommandBufferBeginInfo cmd_buf_info = {}; |
Jon Ashburn | f19916e | 2016-01-11 13:12:43 -0700 | [diff] [blame] | 6982 | VkCommandBufferInheritanceInfo cmd_buf_hinfo = {}; |
Tobin Ehlis | ac0ef84 | 2015-12-14 13:46:38 -0700 | [diff] [blame] | 6983 | cmd_buf_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO; |
| 6984 | cmd_buf_info.pNext = NULL; |
| 6985 | cmd_buf_info.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT; |
Jon Ashburn | f19916e | 2016-01-11 13:12:43 -0700 | [diff] [blame] | 6986 | cmd_buf_info.pInheritanceInfo = &cmd_buf_hinfo; |
Tobin Ehlis | ac0ef84 | 2015-12-14 13:46:38 -0700 | [diff] [blame] | 6987 | |
| 6988 | // Begin CB to transition to recording state |
| 6989 | vkBeginCommandBuffer(commandBuffer.GetBufferHandle(), &cmd_buf_info); |
| 6990 | // Can't re-begin. This should trigger error |
| 6991 | vkBeginCommandBuffer(commandBuffer.GetBufferHandle(), &cmd_buf_info); |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 6992 | m_errorMonitor->VerifyFound(); |
| 6993 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6994 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 6995 | "Attempt to reset command buffer "); |
Tobin Ehlis | ac0ef84 | 2015-12-14 13:46:38 -0700 | [diff] [blame] | 6996 | VkCommandBufferResetFlags flags = 0; // Don't care about flags for this test |
| 6997 | // Reset attempt will trigger error due to incorrect CommandPool state |
| 6998 | vkResetCommandBuffer(commandBuffer.GetBufferHandle(), flags); |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 6999 | m_errorMonitor->VerifyFound(); |
| 7000 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7001 | m_errorMonitor->SetDesiredFailureMsg( |
| 7002 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 7003 | " attempts to implicitly reset cmdBuffer created from "); |
Tobin Ehlis | ac0ef84 | 2015-12-14 13:46:38 -0700 | [diff] [blame] | 7004 | // Transition CB to RECORDED state |
| 7005 | vkEndCommandBuffer(commandBuffer.GetBufferHandle()); |
| 7006 | // Now attempting to Begin will implicitly reset, which triggers error |
| 7007 | vkBeginCommandBuffer(commandBuffer.GetBufferHandle(), &cmd_buf_info); |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 7008 | m_errorMonitor->VerifyFound(); |
Tobin Ehlis | ac0ef84 | 2015-12-14 13:46:38 -0700 | [diff] [blame] | 7009 | } |
| 7010 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7011 | TEST_F(VkLayerTest, InvalidPipelineCreateState) { |
Tobin Ehlis | af1f3a4 | 2015-06-25 15:46:59 -0600 | [diff] [blame] | 7012 | // Attempt to Create Gfx Pipeline w/o a VS |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7013 | VkResult err; |
Tobin Ehlis | af1f3a4 | 2015-06-25 15:46:59 -0600 | [diff] [blame] | 7014 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7015 | m_errorMonitor->SetDesiredFailureMsg( |
| 7016 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 7017 | "Invalid Pipeline CreateInfo State: Vtx Shader required"); |
| 7018 | |
Tobin Ehlis | af1f3a4 | 2015-06-25 15:46:59 -0600 | [diff] [blame] | 7019 | ASSERT_NO_FATAL_FAILURE(InitState()); |
Tobin Ehlis | c9ac2b6 | 2015-09-11 12:57:55 -0600 | [diff] [blame] | 7020 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
Mark Lobodzinski | 209b529 | 2015-09-17 09:44:05 -0600 | [diff] [blame] | 7021 | |
Chia-I Wu | 1b99bb2 | 2015-10-27 19:25:11 +0800 | [diff] [blame] | 7022 | VkDescriptorPoolSize ds_type_count = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7023 | ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 7024 | ds_type_count.descriptorCount = 1; |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 7025 | |
| 7026 | VkDescriptorPoolCreateInfo ds_pool_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7027 | ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO; |
| 7028 | ds_pool_ci.pNext = NULL; |
| 7029 | ds_pool_ci.maxSets = 1; |
| 7030 | ds_pool_ci.poolSizeCount = 1; |
| 7031 | ds_pool_ci.pPoolSizes = &ds_type_count; |
Mark Lobodzinski | 209b529 | 2015-09-17 09:44:05 -0600 | [diff] [blame] | 7032 | |
Tobin Ehlis | af1f3a4 | 2015-06-25 15:46:59 -0600 | [diff] [blame] | 7033 | VkDescriptorPool ds_pool; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7034 | err = |
| 7035 | vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool); |
Tobin Ehlis | af1f3a4 | 2015-06-25 15:46:59 -0600 | [diff] [blame] | 7036 | ASSERT_VK_SUCCESS(err); |
| 7037 | |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 7038 | VkDescriptorSetLayoutBinding dsl_binding = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7039 | dsl_binding.binding = 0; |
| 7040 | dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 7041 | dsl_binding.descriptorCount = 1; |
| 7042 | dsl_binding.stageFlags = VK_SHADER_STAGE_ALL; |
| 7043 | dsl_binding.pImmutableSamplers = NULL; |
Tobin Ehlis | af1f3a4 | 2015-06-25 15:46:59 -0600 | [diff] [blame] | 7044 | |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 7045 | VkDescriptorSetLayoutCreateInfo ds_layout_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7046 | ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO; |
| 7047 | ds_layout_ci.pNext = NULL; |
| 7048 | ds_layout_ci.bindingCount = 1; |
| 7049 | ds_layout_ci.pBindings = &dsl_binding; |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 7050 | |
Tobin Ehlis | af1f3a4 | 2015-06-25 15:46:59 -0600 | [diff] [blame] | 7051 | VkDescriptorSetLayout ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7052 | err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, |
| 7053 | &ds_layout); |
Tobin Ehlis | af1f3a4 | 2015-06-25 15:46:59 -0600 | [diff] [blame] | 7054 | ASSERT_VK_SUCCESS(err); |
| 7055 | |
| 7056 | VkDescriptorSet descriptorSet; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 7057 | VkDescriptorSetAllocateInfo alloc_info = {}; |
Chia-I Wu | 00ce540 | 2015-11-10 16:21:09 +0800 | [diff] [blame] | 7058 | alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO; |
Jon Ashburn | f19916e | 2016-01-11 13:12:43 -0700 | [diff] [blame] | 7059 | alloc_info.descriptorSetCount = 1; |
Courtney Goeltzenleuchter | bee18a9 | 2015-10-23 14:21:05 -0600 | [diff] [blame] | 7060 | alloc_info.descriptorPool = ds_pool; |
| 7061 | alloc_info.pSetLayouts = &ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7062 | err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, |
| 7063 | &descriptorSet); |
Tobin Ehlis | af1f3a4 | 2015-06-25 15:46:59 -0600 | [diff] [blame] | 7064 | ASSERT_VK_SUCCESS(err); |
| 7065 | |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 7066 | VkPipelineLayoutCreateInfo pipeline_layout_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7067 | pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO; |
| 7068 | pipeline_layout_ci.setLayoutCount = 1; |
| 7069 | pipeline_layout_ci.pSetLayouts = &ds_layout; |
Tobin Ehlis | af1f3a4 | 2015-06-25 15:46:59 -0600 | [diff] [blame] | 7070 | |
| 7071 | VkPipelineLayout pipeline_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7072 | err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, |
| 7073 | &pipeline_layout); |
Tobin Ehlis | af1f3a4 | 2015-06-25 15:46:59 -0600 | [diff] [blame] | 7074 | ASSERT_VK_SUCCESS(err); |
| 7075 | |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 7076 | VkViewport vp = {}; // Just need dummy vp to point to |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7077 | VkRect2D sc = {}; // dummy scissor to point to |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 7078 | |
| 7079 | VkPipelineViewportStateCreateInfo vp_state_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7080 | vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO; |
| 7081 | vp_state_ci.scissorCount = 1; |
| 7082 | vp_state_ci.pScissors = ≻ |
| 7083 | vp_state_ci.viewportCount = 1; |
| 7084 | vp_state_ci.pViewports = &vp; |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 7085 | |
Karl Schultz | dfdb8d4 | 2016-03-08 10:30:21 -0700 | [diff] [blame] | 7086 | VkPipelineRasterizationStateCreateInfo rs_state_ci = {}; |
| 7087 | rs_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO; |
| 7088 | rs_state_ci.polygonMode = VK_POLYGON_MODE_FILL; |
| 7089 | rs_state_ci.cullMode = VK_CULL_MODE_BACK_BIT; |
| 7090 | rs_state_ci.frontFace = VK_FRONT_FACE_COUNTER_CLOCKWISE; |
| 7091 | rs_state_ci.depthClampEnable = VK_FALSE; |
| 7092 | rs_state_ci.rasterizerDiscardEnable = VK_FALSE; |
| 7093 | rs_state_ci.depthBiasEnable = VK_FALSE; |
| 7094 | |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 7095 | VkGraphicsPipelineCreateInfo gp_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7096 | gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO; |
| 7097 | gp_ci.pViewportState = &vp_state_ci; |
Karl Schultz | dfdb8d4 | 2016-03-08 10:30:21 -0700 | [diff] [blame] | 7098 | gp_ci.pRasterizationState = &rs_state_ci; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7099 | gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT; |
| 7100 | gp_ci.layout = pipeline_layout; |
| 7101 | gp_ci.renderPass = renderPass(); |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 7102 | |
| 7103 | VkPipelineCacheCreateInfo pc_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7104 | pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO; |
| 7105 | pc_ci.initialDataSize = 0; |
| 7106 | pc_ci.pInitialData = 0; |
Tobin Ehlis | af1f3a4 | 2015-06-25 15:46:59 -0600 | [diff] [blame] | 7107 | |
| 7108 | VkPipeline pipeline; |
Jon Ashburn | c669cc6 | 2015-07-09 15:02:25 -0600 | [diff] [blame] | 7109 | VkPipelineCache pipelineCache; |
| 7110 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7111 | err = |
| 7112 | vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache); |
Jon Ashburn | c669cc6 | 2015-07-09 15:02:25 -0600 | [diff] [blame] | 7113 | ASSERT_VK_SUCCESS(err); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7114 | err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, |
| 7115 | &gp_ci, NULL, &pipeline); |
Tobin Ehlis | 7d1a711 | 2015-05-27 14:32:28 -0600 | [diff] [blame] | 7116 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 7117 | m_errorMonitor->VerifyFound(); |
Mike Stroyan | d1c84a5 | 2015-08-18 14:40:24 -0600 | [diff] [blame] | 7118 | |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 7119 | vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL); |
| 7120 | vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL); |
| 7121 | vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL); |
| 7122 | vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL); |
Tobin Ehlis | af1f3a4 | 2015-06-25 15:46:59 -0600 | [diff] [blame] | 7123 | } |
Tobin Ehlis | 912df02 | 2015-09-17 08:46:18 -0600 | [diff] [blame] | 7124 | /*// TODO : This test should be good, but needs Tess support in compiler to run |
| 7125 | TEST_F(VkLayerTest, InvalidPatchControlPoints) |
| 7126 | { |
| 7127 | // Attempt to Create Gfx Pipeline w/o a VS |
Tobin Ehlis | 912df02 | 2015-09-17 08:46:18 -0600 | [diff] [blame] | 7128 | VkResult err; |
Tobin Ehlis | af1f3a4 | 2015-06-25 15:46:59 -0600 | [diff] [blame] | 7129 | |
Courtney Goeltzenleuchter | 7415d5a | 2015-12-09 15:48:16 -0700 | [diff] [blame] | 7130 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7131 | "Invalid Pipeline CreateInfo State: VK_PRIMITIVE_TOPOLOGY_PATCH |
| 7132 | primitive "); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 7133 | |
Tobin Ehlis | 912df02 | 2015-09-17 08:46:18 -0600 | [diff] [blame] | 7134 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 7135 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
Tobin Ehlis | 912df02 | 2015-09-17 08:46:18 -0600 | [diff] [blame] | 7136 | |
Chia-I Wu | 1b99bb2 | 2015-10-27 19:25:11 +0800 | [diff] [blame] | 7137 | VkDescriptorPoolSize ds_type_count = {}; |
Tobin Ehlis | 912df02 | 2015-09-17 08:46:18 -0600 | [diff] [blame] | 7138 | ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
Chia-I Wu | d50a7d7 | 2015-10-26 20:48:51 +0800 | [diff] [blame] | 7139 | ds_type_count.descriptorCount = 1; |
Tobin Ehlis | 912df02 | 2015-09-17 08:46:18 -0600 | [diff] [blame] | 7140 | |
| 7141 | VkDescriptorPoolCreateInfo ds_pool_ci = {}; |
| 7142 | ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO; |
| 7143 | ds_pool_ci.pNext = NULL; |
Chia-I Wu | 1b99bb2 | 2015-10-27 19:25:11 +0800 | [diff] [blame] | 7144 | ds_pool_ci.poolSizeCount = 1; |
| 7145 | ds_pool_ci.pPoolSizes = &ds_type_count; |
Tobin Ehlis | 912df02 | 2015-09-17 08:46:18 -0600 | [diff] [blame] | 7146 | |
| 7147 | VkDescriptorPool ds_pool; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7148 | err = vkCreateDescriptorPool(m_device->device(), |
| 7149 | 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] | 7150 | ASSERT_VK_SUCCESS(err); |
| 7151 | |
| 7152 | VkDescriptorSetLayoutBinding dsl_binding = {}; |
Chia-I Wu | d46e6ae | 2015-10-31 00:31:16 +0800 | [diff] [blame] | 7153 | dsl_binding.binding = 0; |
Tobin Ehlis | 912df02 | 2015-09-17 08:46:18 -0600 | [diff] [blame] | 7154 | dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
Chia-I Wu | 0212448 | 2015-11-06 06:42:02 +0800 | [diff] [blame] | 7155 | dsl_binding.descriptorCount = 1; |
Tobin Ehlis | 912df02 | 2015-09-17 08:46:18 -0600 | [diff] [blame] | 7156 | dsl_binding.stageFlags = VK_SHADER_STAGE_ALL; |
| 7157 | dsl_binding.pImmutableSamplers = NULL; |
| 7158 | |
| 7159 | VkDescriptorSetLayoutCreateInfo ds_layout_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7160 | ds_layout_ci.sType = |
| 7161 | VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO; |
Tobin Ehlis | 912df02 | 2015-09-17 08:46:18 -0600 | [diff] [blame] | 7162 | ds_layout_ci.pNext = NULL; |
Chia-I Wu | d50a7d7 | 2015-10-26 20:48:51 +0800 | [diff] [blame] | 7163 | ds_layout_ci.bindingCount = 1; |
Jon Ashburn | 6e23c1f | 2015-12-30 18:01:16 -0700 | [diff] [blame] | 7164 | ds_layout_ci.pBindings = &dsl_binding; |
Tobin Ehlis | 912df02 | 2015-09-17 08:46:18 -0600 | [diff] [blame] | 7165 | |
| 7166 | VkDescriptorSetLayout ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7167 | err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, |
| 7168 | &ds_layout); |
Tobin Ehlis | 912df02 | 2015-09-17 08:46:18 -0600 | [diff] [blame] | 7169 | ASSERT_VK_SUCCESS(err); |
| 7170 | |
| 7171 | VkDescriptorSet descriptorSet; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7172 | err = vkAllocateDescriptorSets(m_device->device(), ds_pool, |
| 7173 | VK_DESCRIPTOR_SET_USAGE_NON_FREE, 1, &ds_layout, &descriptorSet); |
Tobin Ehlis | 912df02 | 2015-09-17 08:46:18 -0600 | [diff] [blame] | 7174 | ASSERT_VK_SUCCESS(err); |
| 7175 | |
| 7176 | VkPipelineLayoutCreateInfo pipeline_layout_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7177 | pipeline_layout_ci.sType = |
| 7178 | VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO; |
Tobin Ehlis | 912df02 | 2015-09-17 08:46:18 -0600 | [diff] [blame] | 7179 | pipeline_layout_ci.pNext = NULL; |
Chia-I Wu | d50a7d7 | 2015-10-26 20:48:51 +0800 | [diff] [blame] | 7180 | pipeline_layout_ci.setLayoutCount = 1; |
Tobin Ehlis | 912df02 | 2015-09-17 08:46:18 -0600 | [diff] [blame] | 7181 | pipeline_layout_ci.pSetLayouts = &ds_layout; |
| 7182 | |
| 7183 | VkPipelineLayout pipeline_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7184 | err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, |
| 7185 | &pipeline_layout); |
Tobin Ehlis | 912df02 | 2015-09-17 08:46:18 -0600 | [diff] [blame] | 7186 | ASSERT_VK_SUCCESS(err); |
| 7187 | |
| 7188 | VkPipelineShaderStageCreateInfo shaderStages[3]; |
| 7189 | memset(&shaderStages, 0, 3 * sizeof(VkPipelineShaderStageCreateInfo)); |
| 7190 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7191 | VkShaderObj vs(m_device,bindStateVertShaderText,VK_SHADER_STAGE_VERTEX_BIT, |
| 7192 | this); |
Tobin Ehlis | 912df02 | 2015-09-17 08:46:18 -0600 | [diff] [blame] | 7193 | // 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] | 7194 | VkShaderObj |
| 7195 | tc(m_device,bindStateVertShaderText,VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT, |
| 7196 | this); |
| 7197 | VkShaderObj |
| 7198 | te(m_device,bindStateVertShaderText,VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT, |
| 7199 | this); |
Tobin Ehlis | 912df02 | 2015-09-17 08:46:18 -0600 | [diff] [blame] | 7200 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7201 | shaderStages[0].sType = |
| 7202 | VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO; |
Courtney Goeltzenleuchter | d263550 | 2015-10-21 17:08:06 -0600 | [diff] [blame] | 7203 | shaderStages[0].stage = VK_SHADER_STAGE_VERTEX_BIT; |
Tobin Ehlis | 912df02 | 2015-09-17 08:46:18 -0600 | [diff] [blame] | 7204 | shaderStages[0].shader = vs.handle(); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7205 | shaderStages[1].sType = |
| 7206 | VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO; |
Courtney Goeltzenleuchter | d263550 | 2015-10-21 17:08:06 -0600 | [diff] [blame] | 7207 | shaderStages[1].stage = VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT; |
Tobin Ehlis | 912df02 | 2015-09-17 08:46:18 -0600 | [diff] [blame] | 7208 | shaderStages[1].shader = tc.handle(); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7209 | shaderStages[2].sType = |
| 7210 | VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO; |
Courtney Goeltzenleuchter | d263550 | 2015-10-21 17:08:06 -0600 | [diff] [blame] | 7211 | shaderStages[2].stage = VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT; |
Tobin Ehlis | 912df02 | 2015-09-17 08:46:18 -0600 | [diff] [blame] | 7212 | shaderStages[2].shader = te.handle(); |
| 7213 | |
| 7214 | VkPipelineInputAssemblyStateCreateInfo iaCI = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7215 | iaCI.sType = |
| 7216 | VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO; |
Chia-I Wu | 515eb8f | 2015-10-31 00:31:16 +0800 | [diff] [blame] | 7217 | iaCI.topology = VK_PRIMITIVE_TOPOLOGY_PATCH_LIST; |
Tobin Ehlis | 912df02 | 2015-09-17 08:46:18 -0600 | [diff] [blame] | 7218 | |
| 7219 | VkPipelineTessellationStateCreateInfo tsCI = {}; |
| 7220 | tsCI.sType = VK_STRUCTURE_TYPE_PIPELINE_TESSELLATION_STATE_CREATE_INFO; |
| 7221 | tsCI.patchControlPoints = 0; // This will cause an error |
| 7222 | |
| 7223 | VkGraphicsPipelineCreateInfo gp_ci = {}; |
| 7224 | gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO; |
| 7225 | gp_ci.pNext = NULL; |
| 7226 | gp_ci.stageCount = 3; |
| 7227 | gp_ci.pStages = shaderStages; |
| 7228 | gp_ci.pVertexInputState = NULL; |
| 7229 | gp_ci.pInputAssemblyState = &iaCI; |
| 7230 | gp_ci.pTessellationState = &tsCI; |
| 7231 | gp_ci.pViewportState = NULL; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 7232 | gp_ci.pRasterizationState = NULL; |
Tobin Ehlis | 912df02 | 2015-09-17 08:46:18 -0600 | [diff] [blame] | 7233 | gp_ci.pMultisampleState = NULL; |
| 7234 | gp_ci.pDepthStencilState = NULL; |
| 7235 | gp_ci.pColorBlendState = NULL; |
| 7236 | gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT; |
| 7237 | gp_ci.layout = pipeline_layout; |
| 7238 | gp_ci.renderPass = renderPass(); |
| 7239 | |
| 7240 | VkPipelineCacheCreateInfo pc_ci = {}; |
| 7241 | pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO; |
| 7242 | pc_ci.pNext = NULL; |
| 7243 | pc_ci.initialSize = 0; |
| 7244 | pc_ci.initialData = 0; |
| 7245 | pc_ci.maxSize = 0; |
| 7246 | |
| 7247 | VkPipeline pipeline; |
| 7248 | VkPipelineCache pipelineCache; |
| 7249 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7250 | err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, |
| 7251 | &pipelineCache); |
Tobin Ehlis | 912df02 | 2015-09-17 08:46:18 -0600 | [diff] [blame] | 7252 | ASSERT_VK_SUCCESS(err); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7253 | err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, |
| 7254 | &gp_ci, NULL, &pipeline); |
Tobin Ehlis | 912df02 | 2015-09-17 08:46:18 -0600 | [diff] [blame] | 7255 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 7256 | m_errorMonitor->VerifyFound(); |
Mike Stroyan | d1c84a5 | 2015-08-18 14:40:24 -0600 | [diff] [blame] | 7257 | |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 7258 | vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL); |
| 7259 | vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL); |
| 7260 | vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL); |
| 7261 | vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL); |
Tobin Ehlis | 912df02 | 2015-09-17 08:46:18 -0600 | [diff] [blame] | 7262 | } |
| 7263 | */ |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 7264 | // Set scissor and viewport counts to different numbers |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7265 | TEST_F(VkLayerTest, PSOViewportScissorCountMismatch) { |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7266 | VkResult err; |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 7267 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7268 | m_errorMonitor->SetDesiredFailureMsg( |
| 7269 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 7270 | "Gfx Pipeline viewport count (1) must match scissor count (0)."); |
| 7271 | |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 7272 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 7273 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 7274 | |
Chia-I Wu | 1b99bb2 | 2015-10-27 19:25:11 +0800 | [diff] [blame] | 7275 | VkDescriptorPoolSize ds_type_count = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7276 | ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 7277 | ds_type_count.descriptorCount = 1; |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 7278 | |
| 7279 | VkDescriptorPoolCreateInfo ds_pool_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7280 | ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO; |
| 7281 | ds_pool_ci.maxSets = 1; |
| 7282 | ds_pool_ci.poolSizeCount = 1; |
| 7283 | ds_pool_ci.pPoolSizes = &ds_type_count; |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 7284 | |
| 7285 | VkDescriptorPool ds_pool; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7286 | err = |
| 7287 | vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool); |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 7288 | ASSERT_VK_SUCCESS(err); |
| 7289 | |
| 7290 | VkDescriptorSetLayoutBinding dsl_binding = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7291 | dsl_binding.binding = 0; |
| 7292 | dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 7293 | dsl_binding.descriptorCount = 1; |
| 7294 | dsl_binding.stageFlags = VK_SHADER_STAGE_ALL; |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 7295 | |
| 7296 | VkDescriptorSetLayoutCreateInfo ds_layout_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7297 | ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO; |
| 7298 | ds_layout_ci.bindingCount = 1; |
| 7299 | ds_layout_ci.pBindings = &dsl_binding; |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 7300 | |
| 7301 | VkDescriptorSetLayout ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7302 | err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, |
| 7303 | &ds_layout); |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 7304 | ASSERT_VK_SUCCESS(err); |
| 7305 | |
| 7306 | VkDescriptorSet descriptorSet; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 7307 | VkDescriptorSetAllocateInfo alloc_info = {}; |
Chia-I Wu | 00ce540 | 2015-11-10 16:21:09 +0800 | [diff] [blame] | 7308 | alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO; |
Jon Ashburn | f19916e | 2016-01-11 13:12:43 -0700 | [diff] [blame] | 7309 | alloc_info.descriptorSetCount = 1; |
Courtney Goeltzenleuchter | bee18a9 | 2015-10-23 14:21:05 -0600 | [diff] [blame] | 7310 | alloc_info.descriptorPool = ds_pool; |
| 7311 | alloc_info.pSetLayouts = &ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7312 | err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, |
| 7313 | &descriptorSet); |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 7314 | ASSERT_VK_SUCCESS(err); |
| 7315 | |
| 7316 | VkPipelineLayoutCreateInfo pipeline_layout_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7317 | pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO; |
| 7318 | pipeline_layout_ci.setLayoutCount = 1; |
| 7319 | pipeline_layout_ci.pSetLayouts = &ds_layout; |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 7320 | |
| 7321 | VkPipelineLayout pipeline_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7322 | err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, |
| 7323 | &pipeline_layout); |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 7324 | ASSERT_VK_SUCCESS(err); |
| 7325 | |
| 7326 | VkViewport vp = {}; // Just need dummy vp to point to |
| 7327 | |
| 7328 | VkPipelineViewportStateCreateInfo vp_state_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7329 | vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO; |
| 7330 | vp_state_ci.scissorCount = 0; |
| 7331 | vp_state_ci.viewportCount = 1; // Count mismatch should cause error |
| 7332 | vp_state_ci.pViewports = &vp; |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 7333 | |
Karl Schultz | dfdb8d4 | 2016-03-08 10:30:21 -0700 | [diff] [blame] | 7334 | VkPipelineRasterizationStateCreateInfo rs_state_ci = {}; |
| 7335 | rs_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO; |
| 7336 | rs_state_ci.polygonMode = VK_POLYGON_MODE_FILL; |
| 7337 | rs_state_ci.cullMode = VK_CULL_MODE_BACK_BIT; |
| 7338 | rs_state_ci.frontFace = VK_FRONT_FACE_COUNTER_CLOCKWISE; |
| 7339 | rs_state_ci.depthClampEnable = VK_FALSE; |
| 7340 | rs_state_ci.rasterizerDiscardEnable = VK_FALSE; |
| 7341 | rs_state_ci.depthBiasEnable = VK_FALSE; |
| 7342 | |
Cody Northrop | eb3a6c1 | 2015-10-05 14:44:45 -0600 | [diff] [blame] | 7343 | VkPipelineShaderStageCreateInfo shaderStages[2]; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7344 | memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo)); |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 7345 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7346 | VkShaderObj vs(m_device, bindStateVertShaderText, |
| 7347 | VK_SHADER_STAGE_VERTEX_BIT, this); |
| 7348 | VkShaderObj fs(m_device, bindStateFragShaderText, |
| 7349 | VK_SHADER_STAGE_FRAGMENT_BIT, |
Karl Schultz | bdb7595 | 2016-04-19 11:36:49 -0600 | [diff] [blame] | 7350 | this); // We shouldn't need a fragment shader |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7351 | // but add it to be able to run on more devices |
Chia-I Wu | 28e0691 | 2015-10-31 00:31:16 +0800 | [diff] [blame] | 7352 | shaderStages[0] = vs.GetStageCreateInfo(); |
| 7353 | shaderStages[1] = fs.GetStageCreateInfo(); |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 7354 | |
| 7355 | VkGraphicsPipelineCreateInfo gp_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7356 | gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO; |
| 7357 | gp_ci.stageCount = 2; |
| 7358 | gp_ci.pStages = shaderStages; |
| 7359 | gp_ci.pViewportState = &vp_state_ci; |
Karl Schultz | dfdb8d4 | 2016-03-08 10:30:21 -0700 | [diff] [blame] | 7360 | gp_ci.pRasterizationState = &rs_state_ci; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7361 | gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT; |
| 7362 | gp_ci.layout = pipeline_layout; |
| 7363 | gp_ci.renderPass = renderPass(); |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 7364 | |
| 7365 | VkPipelineCacheCreateInfo pc_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7366 | pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO; |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 7367 | |
| 7368 | VkPipeline pipeline; |
| 7369 | VkPipelineCache pipelineCache; |
| 7370 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7371 | err = |
| 7372 | vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache); |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 7373 | ASSERT_VK_SUCCESS(err); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7374 | err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, |
| 7375 | &gp_ci, NULL, &pipeline); |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 7376 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 7377 | m_errorMonitor->VerifyFound(); |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 7378 | |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 7379 | vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL); |
| 7380 | vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL); |
| 7381 | vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL); |
| 7382 | vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL); |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 7383 | } |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7384 | // Don't set viewport state in PSO. This is an error b/c we always need this |
| 7385 | // state |
Tobin Ehlis | d332f28 | 2015-10-02 11:00:56 -0600 | [diff] [blame] | 7386 | // 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] | 7387 | TEST_F(VkLayerTest, PSOViewportStateNotSet) { |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 7388 | // Attempt to Create Gfx Pipeline w/o a VS |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7389 | VkResult err; |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 7390 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7391 | m_errorMonitor->SetDesiredFailureMsg( |
| 7392 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 7393 | "Gfx Pipeline pViewportState is null. Even if "); |
| 7394 | |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 7395 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 7396 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 7397 | |
Chia-I Wu | 1b99bb2 | 2015-10-27 19:25:11 +0800 | [diff] [blame] | 7398 | VkDescriptorPoolSize ds_type_count = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7399 | ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 7400 | ds_type_count.descriptorCount = 1; |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 7401 | |
| 7402 | VkDescriptorPoolCreateInfo ds_pool_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7403 | ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO; |
| 7404 | ds_pool_ci.maxSets = 1; |
| 7405 | ds_pool_ci.poolSizeCount = 1; |
| 7406 | ds_pool_ci.pPoolSizes = &ds_type_count; |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 7407 | |
| 7408 | VkDescriptorPool ds_pool; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7409 | err = |
| 7410 | vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool); |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 7411 | ASSERT_VK_SUCCESS(err); |
| 7412 | |
| 7413 | VkDescriptorSetLayoutBinding dsl_binding = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7414 | dsl_binding.binding = 0; |
| 7415 | dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 7416 | dsl_binding.descriptorCount = 1; |
| 7417 | dsl_binding.stageFlags = VK_SHADER_STAGE_ALL; |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 7418 | |
| 7419 | VkDescriptorSetLayoutCreateInfo ds_layout_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7420 | ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO; |
| 7421 | ds_layout_ci.bindingCount = 1; |
| 7422 | ds_layout_ci.pBindings = &dsl_binding; |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 7423 | |
| 7424 | VkDescriptorSetLayout ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7425 | err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, |
| 7426 | &ds_layout); |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 7427 | ASSERT_VK_SUCCESS(err); |
| 7428 | |
| 7429 | VkDescriptorSet descriptorSet; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 7430 | VkDescriptorSetAllocateInfo alloc_info = {}; |
Chia-I Wu | 00ce540 | 2015-11-10 16:21:09 +0800 | [diff] [blame] | 7431 | alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO; |
Jon Ashburn | f19916e | 2016-01-11 13:12:43 -0700 | [diff] [blame] | 7432 | alloc_info.descriptorSetCount = 1; |
Courtney Goeltzenleuchter | bee18a9 | 2015-10-23 14:21:05 -0600 | [diff] [blame] | 7433 | alloc_info.descriptorPool = ds_pool; |
| 7434 | alloc_info.pSetLayouts = &ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7435 | err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, |
| 7436 | &descriptorSet); |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 7437 | ASSERT_VK_SUCCESS(err); |
| 7438 | |
| 7439 | VkPipelineLayoutCreateInfo pipeline_layout_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7440 | pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO; |
| 7441 | pipeline_layout_ci.setLayoutCount = 1; |
| 7442 | pipeline_layout_ci.pSetLayouts = &ds_layout; |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 7443 | |
| 7444 | VkPipelineLayout pipeline_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7445 | err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, |
| 7446 | &pipeline_layout); |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 7447 | ASSERT_VK_SUCCESS(err); |
| 7448 | |
| 7449 | VkDynamicState sc_state = VK_DYNAMIC_STATE_SCISSOR; |
| 7450 | // Set scissor as dynamic to avoid second error |
| 7451 | VkPipelineDynamicStateCreateInfo dyn_state_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7452 | dyn_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO; |
| 7453 | dyn_state_ci.dynamicStateCount = 1; |
| 7454 | dyn_state_ci.pDynamicStates = &sc_state; |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 7455 | |
Cody Northrop | eb3a6c1 | 2015-10-05 14:44:45 -0600 | [diff] [blame] | 7456 | VkPipelineShaderStageCreateInfo shaderStages[2]; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7457 | memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo)); |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 7458 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7459 | VkShaderObj vs(m_device, bindStateVertShaderText, |
| 7460 | VK_SHADER_STAGE_VERTEX_BIT, this); |
| 7461 | VkShaderObj fs(m_device, bindStateFragShaderText, |
| 7462 | VK_SHADER_STAGE_FRAGMENT_BIT, |
Karl Schultz | bdb7595 | 2016-04-19 11:36:49 -0600 | [diff] [blame] | 7463 | this); // We shouldn't need a fragment shader |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7464 | // but add it to be able to run on more devices |
Chia-I Wu | 28e0691 | 2015-10-31 00:31:16 +0800 | [diff] [blame] | 7465 | shaderStages[0] = vs.GetStageCreateInfo(); |
| 7466 | shaderStages[1] = fs.GetStageCreateInfo(); |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 7467 | |
Karl Schultz | dfdb8d4 | 2016-03-08 10:30:21 -0700 | [diff] [blame] | 7468 | |
| 7469 | VkPipelineRasterizationStateCreateInfo rs_state_ci = {}; |
| 7470 | rs_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO; |
| 7471 | rs_state_ci.polygonMode = VK_POLYGON_MODE_FILL; |
| 7472 | rs_state_ci.cullMode = VK_CULL_MODE_BACK_BIT; |
| 7473 | rs_state_ci.frontFace = VK_FRONT_FACE_COUNTER_CLOCKWISE; |
| 7474 | rs_state_ci.depthClampEnable = VK_FALSE; |
| 7475 | rs_state_ci.rasterizerDiscardEnable = VK_FALSE; |
| 7476 | rs_state_ci.depthBiasEnable = VK_FALSE; |
| 7477 | |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 7478 | VkGraphicsPipelineCreateInfo gp_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7479 | gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO; |
| 7480 | gp_ci.stageCount = 2; |
| 7481 | gp_ci.pStages = shaderStages; |
Karl Schultz | dfdb8d4 | 2016-03-08 10:30:21 -0700 | [diff] [blame] | 7482 | gp_ci.pRasterizationState = &rs_state_ci; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7483 | gp_ci.pViewportState = NULL; // Not setting VP state w/o dynamic vp state |
| 7484 | // should cause validation error |
| 7485 | gp_ci.pDynamicState = &dyn_state_ci; |
| 7486 | gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT; |
| 7487 | gp_ci.layout = pipeline_layout; |
| 7488 | gp_ci.renderPass = renderPass(); |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 7489 | |
| 7490 | VkPipelineCacheCreateInfo pc_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7491 | pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO; |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 7492 | |
| 7493 | VkPipeline pipeline; |
| 7494 | VkPipelineCache pipelineCache; |
| 7495 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7496 | err = |
| 7497 | vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache); |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 7498 | ASSERT_VK_SUCCESS(err); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7499 | err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, |
| 7500 | &gp_ci, NULL, &pipeline); |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 7501 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 7502 | m_errorMonitor->VerifyFound(); |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 7503 | |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 7504 | vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL); |
| 7505 | vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL); |
| 7506 | vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL); |
| 7507 | vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL); |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 7508 | } |
| 7509 | // Create PSO w/o non-zero viewportCount but no viewport data |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7510 | // Then run second test where dynamic scissor count doesn't match PSO scissor |
| 7511 | // count |
| 7512 | TEST_F(VkLayerTest, PSOViewportCountWithoutDataAndDynScissorMismatch) { |
| 7513 | VkResult err; |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 7514 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7515 | m_errorMonitor->SetDesiredFailureMsg( |
| 7516 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 7517 | "Gfx Pipeline viewportCount is 1, but pViewports is NULL. "); |
| 7518 | |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 7519 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 7520 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 7521 | |
Chia-I Wu | 1b99bb2 | 2015-10-27 19:25:11 +0800 | [diff] [blame] | 7522 | VkDescriptorPoolSize ds_type_count = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7523 | ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 7524 | ds_type_count.descriptorCount = 1; |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 7525 | |
| 7526 | VkDescriptorPoolCreateInfo ds_pool_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7527 | ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO; |
| 7528 | ds_pool_ci.maxSets = 1; |
| 7529 | ds_pool_ci.poolSizeCount = 1; |
| 7530 | ds_pool_ci.pPoolSizes = &ds_type_count; |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 7531 | |
| 7532 | VkDescriptorPool ds_pool; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7533 | err = |
| 7534 | vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool); |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 7535 | ASSERT_VK_SUCCESS(err); |
| 7536 | |
| 7537 | VkDescriptorSetLayoutBinding dsl_binding = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7538 | dsl_binding.binding = 0; |
| 7539 | dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 7540 | dsl_binding.descriptorCount = 1; |
| 7541 | dsl_binding.stageFlags = VK_SHADER_STAGE_ALL; |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 7542 | |
| 7543 | VkDescriptorSetLayoutCreateInfo ds_layout_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7544 | ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO; |
| 7545 | ds_layout_ci.bindingCount = 1; |
| 7546 | ds_layout_ci.pBindings = &dsl_binding; |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 7547 | |
| 7548 | VkDescriptorSetLayout ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7549 | err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, |
| 7550 | &ds_layout); |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 7551 | ASSERT_VK_SUCCESS(err); |
| 7552 | |
| 7553 | VkDescriptorSet descriptorSet; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 7554 | VkDescriptorSetAllocateInfo alloc_info = {}; |
Chia-I Wu | 00ce540 | 2015-11-10 16:21:09 +0800 | [diff] [blame] | 7555 | alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO; |
Jon Ashburn | f19916e | 2016-01-11 13:12:43 -0700 | [diff] [blame] | 7556 | alloc_info.descriptorSetCount = 1; |
Courtney Goeltzenleuchter | bee18a9 | 2015-10-23 14:21:05 -0600 | [diff] [blame] | 7557 | alloc_info.descriptorPool = ds_pool; |
| 7558 | alloc_info.pSetLayouts = &ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7559 | err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, |
| 7560 | &descriptorSet); |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 7561 | ASSERT_VK_SUCCESS(err); |
| 7562 | |
| 7563 | VkPipelineLayoutCreateInfo pipeline_layout_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7564 | pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO; |
| 7565 | pipeline_layout_ci.setLayoutCount = 1; |
| 7566 | pipeline_layout_ci.pSetLayouts = &ds_layout; |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 7567 | |
| 7568 | VkPipelineLayout pipeline_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7569 | err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, |
| 7570 | &pipeline_layout); |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 7571 | ASSERT_VK_SUCCESS(err); |
| 7572 | |
| 7573 | VkPipelineViewportStateCreateInfo vp_state_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7574 | vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO; |
| 7575 | vp_state_ci.viewportCount = 1; |
| 7576 | vp_state_ci.pViewports = NULL; // Null vp w/ count of 1 should cause error |
| 7577 | vp_state_ci.scissorCount = 1; |
| 7578 | vp_state_ci.pScissors = |
| 7579 | NULL; // Scissor is dynamic (below) so this won't cause error |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 7580 | |
| 7581 | VkDynamicState sc_state = VK_DYNAMIC_STATE_SCISSOR; |
| 7582 | // Set scissor as dynamic to avoid that error |
| 7583 | VkPipelineDynamicStateCreateInfo dyn_state_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7584 | dyn_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO; |
| 7585 | dyn_state_ci.dynamicStateCount = 1; |
| 7586 | dyn_state_ci.pDynamicStates = &sc_state; |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 7587 | |
Cody Northrop | eb3a6c1 | 2015-10-05 14:44:45 -0600 | [diff] [blame] | 7588 | VkPipelineShaderStageCreateInfo shaderStages[2]; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7589 | memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo)); |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 7590 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7591 | VkShaderObj vs(m_device, bindStateVertShaderText, |
| 7592 | VK_SHADER_STAGE_VERTEX_BIT, this); |
| 7593 | VkShaderObj fs(m_device, bindStateFragShaderText, |
| 7594 | VK_SHADER_STAGE_FRAGMENT_BIT, |
Karl Schultz | bdb7595 | 2016-04-19 11:36:49 -0600 | [diff] [blame] | 7595 | this); // We shouldn't need a fragment shader |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7596 | // but add it to be able to run on more devices |
Chia-I Wu | 28e0691 | 2015-10-31 00:31:16 +0800 | [diff] [blame] | 7597 | shaderStages[0] = vs.GetStageCreateInfo(); |
| 7598 | shaderStages[1] = fs.GetStageCreateInfo(); |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 7599 | |
Cody Northrop | f6622dc | 2015-10-06 10:33:21 -0600 | [diff] [blame] | 7600 | VkPipelineVertexInputStateCreateInfo vi_ci = {}; |
| 7601 | vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO; |
| 7602 | vi_ci.pNext = nullptr; |
Chia-I Wu | d50a7d7 | 2015-10-26 20:48:51 +0800 | [diff] [blame] | 7603 | vi_ci.vertexBindingDescriptionCount = 0; |
Cody Northrop | f6622dc | 2015-10-06 10:33:21 -0600 | [diff] [blame] | 7604 | vi_ci.pVertexBindingDescriptions = nullptr; |
Chia-I Wu | d50a7d7 | 2015-10-26 20:48:51 +0800 | [diff] [blame] | 7605 | vi_ci.vertexAttributeDescriptionCount = 0; |
Cody Northrop | f6622dc | 2015-10-06 10:33:21 -0600 | [diff] [blame] | 7606 | vi_ci.pVertexAttributeDescriptions = nullptr; |
| 7607 | |
| 7608 | VkPipelineInputAssemblyStateCreateInfo ia_ci = {}; |
| 7609 | ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO; |
| 7610 | ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP; |
| 7611 | |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 7612 | VkPipelineRasterizationStateCreateInfo rs_ci = {}; |
Chia-I Wu | 1b99bb2 | 2015-10-27 19:25:11 +0800 | [diff] [blame] | 7613 | rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO; |
Cody Northrop | f6622dc | 2015-10-06 10:33:21 -0600 | [diff] [blame] | 7614 | rs_ci.pNext = nullptr; |
| 7615 | |
Mark Young | c89c631 | 2016-03-31 16:03:20 -0600 | [diff] [blame] | 7616 | VkPipelineColorBlendAttachmentState att = {}; |
| 7617 | att.blendEnable = VK_FALSE; |
| 7618 | att.colorWriteMask = 0xf; |
| 7619 | |
Cody Northrop | f6622dc | 2015-10-06 10:33:21 -0600 | [diff] [blame] | 7620 | VkPipelineColorBlendStateCreateInfo cb_ci = {}; |
| 7621 | cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO; |
| 7622 | cb_ci.pNext = nullptr; |
Mark Young | c89c631 | 2016-03-31 16:03:20 -0600 | [diff] [blame] | 7623 | cb_ci.attachmentCount = 1; |
| 7624 | cb_ci.pAttachments = &att; |
Cody Northrop | f6622dc | 2015-10-06 10:33:21 -0600 | [diff] [blame] | 7625 | |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 7626 | VkGraphicsPipelineCreateInfo gp_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7627 | gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO; |
| 7628 | gp_ci.stageCount = 2; |
| 7629 | gp_ci.pStages = shaderStages; |
| 7630 | gp_ci.pVertexInputState = &vi_ci; |
| 7631 | gp_ci.pInputAssemblyState = &ia_ci; |
| 7632 | gp_ci.pViewportState = &vp_state_ci; |
| 7633 | gp_ci.pRasterizationState = &rs_ci; |
| 7634 | gp_ci.pColorBlendState = &cb_ci; |
| 7635 | gp_ci.pDynamicState = &dyn_state_ci; |
| 7636 | gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT; |
| 7637 | gp_ci.layout = pipeline_layout; |
| 7638 | gp_ci.renderPass = renderPass(); |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 7639 | |
| 7640 | VkPipelineCacheCreateInfo pc_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7641 | pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO; |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 7642 | |
| 7643 | VkPipeline pipeline; |
| 7644 | VkPipelineCache pipelineCache; |
| 7645 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7646 | err = |
| 7647 | vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache); |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 7648 | ASSERT_VK_SUCCESS(err); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7649 | err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, |
| 7650 | &gp_ci, NULL, &pipeline); |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 7651 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 7652 | m_errorMonitor->VerifyFound(); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 7653 | |
Tobin Ehlis | d332f28 | 2015-10-02 11:00:56 -0600 | [diff] [blame] | 7654 | // 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] | 7655 | // First need to successfully create the PSO from above by setting |
| 7656 | // pViewports |
| 7657 | m_errorMonitor->SetDesiredFailureMsg( |
| 7658 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 7659 | "Dynamic scissorCount from vkCmdSetScissor() is 2, but PSO " |
| 7660 | "scissorCount is 1. These counts must match."); |
| 7661 | |
| 7662 | VkViewport vp = {}; // Just need dummy vp to point to |
| 7663 | vp_state_ci.pViewports = &vp; |
| 7664 | err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, |
| 7665 | &gp_ci, NULL, &pipeline); |
| 7666 | ASSERT_VK_SUCCESS(err); |
| 7667 | BeginCommandBuffer(); |
| 7668 | vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), |
| 7669 | VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline); |
| 7670 | VkRect2D scissors[2] = {}; // don't care about data |
| 7671 | // Count of 2 doesn't match PSO count of 1 |
| 7672 | vkCmdSetScissor(m_commandBuffer->GetBufferHandle(), 0, 2, scissors); |
| 7673 | Draw(1, 0, 0, 0); |
| 7674 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 7675 | m_errorMonitor->VerifyFound(); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7676 | |
| 7677 | vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL); |
| 7678 | vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL); |
| 7679 | vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL); |
| 7680 | vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL); |
Tony Barbour | df4c004 | 2016-06-01 15:55:43 -0600 | [diff] [blame] | 7681 | vkDestroyPipeline(m_device->device(), pipeline, NULL); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7682 | } |
| 7683 | // Create PSO w/o non-zero scissorCount but no scissor data |
| 7684 | // Then run second test where dynamic viewportCount doesn't match PSO |
| 7685 | // viewportCount |
| 7686 | TEST_F(VkLayerTest, PSOScissorCountWithoutDataAndDynViewportMismatch) { |
| 7687 | VkResult err; |
| 7688 | |
| 7689 | m_errorMonitor->SetDesiredFailureMsg( |
| 7690 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 7691 | "Gfx Pipeline scissorCount is 1, but pScissors is NULL. "); |
| 7692 | |
| 7693 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 7694 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 7695 | |
| 7696 | VkDescriptorPoolSize ds_type_count = {}; |
| 7697 | ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 7698 | ds_type_count.descriptorCount = 1; |
| 7699 | |
| 7700 | VkDescriptorPoolCreateInfo ds_pool_ci = {}; |
| 7701 | ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO; |
| 7702 | ds_pool_ci.maxSets = 1; |
| 7703 | ds_pool_ci.poolSizeCount = 1; |
| 7704 | ds_pool_ci.pPoolSizes = &ds_type_count; |
| 7705 | |
| 7706 | VkDescriptorPool ds_pool; |
| 7707 | err = |
| 7708 | vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool); |
| 7709 | ASSERT_VK_SUCCESS(err); |
| 7710 | |
| 7711 | VkDescriptorSetLayoutBinding dsl_binding = {}; |
| 7712 | dsl_binding.binding = 0; |
| 7713 | dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 7714 | dsl_binding.descriptorCount = 1; |
| 7715 | dsl_binding.stageFlags = VK_SHADER_STAGE_ALL; |
| 7716 | |
| 7717 | VkDescriptorSetLayoutCreateInfo ds_layout_ci = {}; |
| 7718 | ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO; |
| 7719 | ds_layout_ci.bindingCount = 1; |
| 7720 | ds_layout_ci.pBindings = &dsl_binding; |
| 7721 | |
| 7722 | VkDescriptorSetLayout ds_layout; |
| 7723 | err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, |
| 7724 | &ds_layout); |
| 7725 | ASSERT_VK_SUCCESS(err); |
| 7726 | |
| 7727 | VkDescriptorSet descriptorSet; |
| 7728 | VkDescriptorSetAllocateInfo alloc_info = {}; |
| 7729 | alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO; |
| 7730 | alloc_info.descriptorSetCount = 1; |
| 7731 | alloc_info.descriptorPool = ds_pool; |
| 7732 | alloc_info.pSetLayouts = &ds_layout; |
| 7733 | err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, |
| 7734 | &descriptorSet); |
| 7735 | ASSERT_VK_SUCCESS(err); |
| 7736 | |
| 7737 | VkPipelineLayoutCreateInfo pipeline_layout_ci = {}; |
| 7738 | pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO; |
| 7739 | pipeline_layout_ci.setLayoutCount = 1; |
| 7740 | pipeline_layout_ci.pSetLayouts = &ds_layout; |
| 7741 | |
| 7742 | VkPipelineLayout pipeline_layout; |
| 7743 | err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, |
| 7744 | &pipeline_layout); |
| 7745 | ASSERT_VK_SUCCESS(err); |
| 7746 | |
| 7747 | VkPipelineViewportStateCreateInfo vp_state_ci = {}; |
| 7748 | vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO; |
| 7749 | vp_state_ci.scissorCount = 1; |
| 7750 | vp_state_ci.pScissors = |
| 7751 | NULL; // Null scissor w/ count of 1 should cause error |
| 7752 | vp_state_ci.viewportCount = 1; |
| 7753 | vp_state_ci.pViewports = |
| 7754 | NULL; // vp is dynamic (below) so this won't cause error |
| 7755 | |
| 7756 | VkDynamicState vp_state = VK_DYNAMIC_STATE_VIEWPORT; |
| 7757 | // Set scissor as dynamic to avoid that error |
| 7758 | VkPipelineDynamicStateCreateInfo dyn_state_ci = {}; |
| 7759 | dyn_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO; |
| 7760 | dyn_state_ci.dynamicStateCount = 1; |
| 7761 | dyn_state_ci.pDynamicStates = &vp_state; |
| 7762 | |
| 7763 | VkPipelineShaderStageCreateInfo shaderStages[2]; |
| 7764 | memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo)); |
| 7765 | |
| 7766 | VkShaderObj vs(m_device, bindStateVertShaderText, |
| 7767 | VK_SHADER_STAGE_VERTEX_BIT, this); |
| 7768 | VkShaderObj fs(m_device, bindStateFragShaderText, |
| 7769 | VK_SHADER_STAGE_FRAGMENT_BIT, |
Karl Schultz | bdb7595 | 2016-04-19 11:36:49 -0600 | [diff] [blame] | 7770 | this); // We shouldn't need a fragment shader |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7771 | // but add it to be able to run on more devices |
| 7772 | shaderStages[0] = vs.GetStageCreateInfo(); |
| 7773 | shaderStages[1] = fs.GetStageCreateInfo(); |
| 7774 | |
| 7775 | VkPipelineVertexInputStateCreateInfo vi_ci = {}; |
| 7776 | vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO; |
| 7777 | vi_ci.pNext = nullptr; |
| 7778 | vi_ci.vertexBindingDescriptionCount = 0; |
| 7779 | vi_ci.pVertexBindingDescriptions = nullptr; |
| 7780 | vi_ci.vertexAttributeDescriptionCount = 0; |
| 7781 | vi_ci.pVertexAttributeDescriptions = nullptr; |
| 7782 | |
| 7783 | VkPipelineInputAssemblyStateCreateInfo ia_ci = {}; |
| 7784 | ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO; |
| 7785 | ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP; |
| 7786 | |
| 7787 | VkPipelineRasterizationStateCreateInfo rs_ci = {}; |
| 7788 | rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO; |
| 7789 | rs_ci.pNext = nullptr; |
| 7790 | |
Mark Young | c89c631 | 2016-03-31 16:03:20 -0600 | [diff] [blame] | 7791 | VkPipelineColorBlendAttachmentState att = {}; |
| 7792 | att.blendEnable = VK_FALSE; |
| 7793 | att.colorWriteMask = 0xf; |
| 7794 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7795 | VkPipelineColorBlendStateCreateInfo cb_ci = {}; |
| 7796 | cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO; |
| 7797 | cb_ci.pNext = nullptr; |
Mark Young | c89c631 | 2016-03-31 16:03:20 -0600 | [diff] [blame] | 7798 | cb_ci.attachmentCount = 1; |
| 7799 | cb_ci.pAttachments = &att; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7800 | |
| 7801 | VkGraphicsPipelineCreateInfo gp_ci = {}; |
| 7802 | gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO; |
| 7803 | gp_ci.stageCount = 2; |
| 7804 | gp_ci.pStages = shaderStages; |
| 7805 | gp_ci.pVertexInputState = &vi_ci; |
| 7806 | gp_ci.pInputAssemblyState = &ia_ci; |
| 7807 | gp_ci.pViewportState = &vp_state_ci; |
| 7808 | gp_ci.pRasterizationState = &rs_ci; |
| 7809 | gp_ci.pColorBlendState = &cb_ci; |
| 7810 | gp_ci.pDynamicState = &dyn_state_ci; |
| 7811 | gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT; |
| 7812 | gp_ci.layout = pipeline_layout; |
| 7813 | gp_ci.renderPass = renderPass(); |
| 7814 | |
| 7815 | VkPipelineCacheCreateInfo pc_ci = {}; |
| 7816 | pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO; |
| 7817 | |
| 7818 | VkPipeline pipeline; |
| 7819 | VkPipelineCache pipelineCache; |
| 7820 | |
| 7821 | err = |
| 7822 | vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache); |
| 7823 | ASSERT_VK_SUCCESS(err); |
| 7824 | err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, |
| 7825 | &gp_ci, NULL, &pipeline); |
| 7826 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 7827 | m_errorMonitor->VerifyFound(); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7828 | |
| 7829 | // Now hit second fail case where we set scissor w/ different count than PSO |
| 7830 | // First need to successfully create the PSO from above by setting |
| 7831 | // pViewports |
| 7832 | m_errorMonitor->SetDesiredFailureMsg( |
| 7833 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 7834 | "Dynamic viewportCount from vkCmdSetViewport() is 2, but PSO " |
| 7835 | "viewportCount is 1. These counts must match."); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 7836 | |
Tobin Ehlis | d332f28 | 2015-10-02 11:00:56 -0600 | [diff] [blame] | 7837 | VkRect2D sc = {}; // Just need dummy vp to point to |
| 7838 | vp_state_ci.pScissors = ≻ |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7839 | err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, |
| 7840 | &gp_ci, NULL, &pipeline); |
Tobin Ehlis | d332f28 | 2015-10-02 11:00:56 -0600 | [diff] [blame] | 7841 | ASSERT_VK_SUCCESS(err); |
| 7842 | BeginCommandBuffer(); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7843 | vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), |
| 7844 | VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline); |
Tobin Ehlis | d332f28 | 2015-10-02 11:00:56 -0600 | [diff] [blame] | 7845 | VkViewport viewports[2] = {}; // don't care about data |
| 7846 | // Count of 2 doesn't match PSO count of 1 |
Jon Ashburn | 19d3bf1 | 2015-12-30 14:06:55 -0700 | [diff] [blame] | 7847 | vkCmdSetViewport(m_commandBuffer->GetBufferHandle(), 0, 2, viewports); |
Tobin Ehlis | d332f28 | 2015-10-02 11:00:56 -0600 | [diff] [blame] | 7848 | Draw(1, 0, 0, 0); |
| 7849 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 7850 | m_errorMonitor->VerifyFound(); |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 7851 | |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 7852 | vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL); |
| 7853 | vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL); |
| 7854 | vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL); |
| 7855 | vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL); |
Tony Barbour | df4c004 | 2016-06-01 15:55:43 -0600 | [diff] [blame] | 7856 | vkDestroyPipeline(m_device->device(), pipeline, NULL); |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 7857 | } |
| 7858 | |
Mark Young | 7394fdd | 2016-03-31 14:56:43 -0600 | [diff] [blame] | 7859 | TEST_F(VkLayerTest, PSOLineWidthInvalid) { |
| 7860 | VkResult err; |
| 7861 | |
| 7862 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Mark Young | 4710795 | 2016-05-02 15:59:55 -0600 | [diff] [blame] | 7863 | "Attempt to set lineWidth to -1"); |
Mark Young | 7394fdd | 2016-03-31 14:56:43 -0600 | [diff] [blame] | 7864 | |
| 7865 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 7866 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 7867 | |
| 7868 | VkDescriptorPoolSize ds_type_count = {}; |
| 7869 | ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 7870 | ds_type_count.descriptorCount = 1; |
| 7871 | |
| 7872 | VkDescriptorPoolCreateInfo ds_pool_ci = {}; |
| 7873 | ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO; |
| 7874 | ds_pool_ci.maxSets = 1; |
| 7875 | ds_pool_ci.poolSizeCount = 1; |
| 7876 | ds_pool_ci.pPoolSizes = &ds_type_count; |
| 7877 | |
| 7878 | VkDescriptorPool ds_pool; |
| 7879 | err = |
| 7880 | vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool); |
| 7881 | ASSERT_VK_SUCCESS(err); |
| 7882 | |
| 7883 | VkDescriptorSetLayoutBinding dsl_binding = {}; |
| 7884 | dsl_binding.binding = 0; |
| 7885 | dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 7886 | dsl_binding.descriptorCount = 1; |
| 7887 | dsl_binding.stageFlags = VK_SHADER_STAGE_ALL; |
| 7888 | |
| 7889 | VkDescriptorSetLayoutCreateInfo ds_layout_ci = {}; |
| 7890 | ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO; |
| 7891 | ds_layout_ci.bindingCount = 1; |
| 7892 | ds_layout_ci.pBindings = &dsl_binding; |
| 7893 | |
| 7894 | VkDescriptorSetLayout ds_layout; |
| 7895 | err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, |
| 7896 | &ds_layout); |
| 7897 | ASSERT_VK_SUCCESS(err); |
| 7898 | |
| 7899 | VkDescriptorSet descriptorSet; |
| 7900 | VkDescriptorSetAllocateInfo alloc_info = {}; |
| 7901 | alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO; |
| 7902 | alloc_info.descriptorSetCount = 1; |
| 7903 | alloc_info.descriptorPool = ds_pool; |
| 7904 | alloc_info.pSetLayouts = &ds_layout; |
| 7905 | err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, |
| 7906 | &descriptorSet); |
| 7907 | ASSERT_VK_SUCCESS(err); |
| 7908 | |
| 7909 | VkPipelineLayoutCreateInfo pipeline_layout_ci = {}; |
| 7910 | pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO; |
| 7911 | pipeline_layout_ci.setLayoutCount = 1; |
| 7912 | pipeline_layout_ci.pSetLayouts = &ds_layout; |
| 7913 | |
| 7914 | VkPipelineLayout pipeline_layout; |
| 7915 | err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, |
| 7916 | &pipeline_layout); |
| 7917 | ASSERT_VK_SUCCESS(err); |
| 7918 | |
| 7919 | VkPipelineViewportStateCreateInfo vp_state_ci = {}; |
| 7920 | vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO; |
| 7921 | vp_state_ci.scissorCount = 1; |
| 7922 | vp_state_ci.pScissors = NULL; |
| 7923 | vp_state_ci.viewportCount = 1; |
| 7924 | vp_state_ci.pViewports = NULL; |
| 7925 | |
| 7926 | VkDynamicState dynamic_states[3] = {VK_DYNAMIC_STATE_VIEWPORT, |
| 7927 | VK_DYNAMIC_STATE_SCISSOR, |
| 7928 | VK_DYNAMIC_STATE_LINE_WIDTH}; |
| 7929 | // Set scissor as dynamic to avoid that error |
| 7930 | VkPipelineDynamicStateCreateInfo dyn_state_ci = {}; |
| 7931 | dyn_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO; |
| 7932 | dyn_state_ci.dynamicStateCount = 2; |
| 7933 | dyn_state_ci.pDynamicStates = dynamic_states; |
| 7934 | |
| 7935 | VkPipelineShaderStageCreateInfo shaderStages[2]; |
| 7936 | memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo)); |
| 7937 | |
| 7938 | VkShaderObj vs(m_device, bindStateVertShaderText, |
| 7939 | VK_SHADER_STAGE_VERTEX_BIT, this); |
| 7940 | VkShaderObj fs(m_device, bindStateFragShaderText, |
| 7941 | VK_SHADER_STAGE_FRAGMENT_BIT, |
| 7942 | this); // TODO - We shouldn't need a fragment shader |
| 7943 | // but add it to be able to run on more devices |
| 7944 | shaderStages[0] = vs.GetStageCreateInfo(); |
| 7945 | shaderStages[1] = fs.GetStageCreateInfo(); |
| 7946 | |
| 7947 | VkPipelineVertexInputStateCreateInfo vi_ci = {}; |
| 7948 | vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO; |
| 7949 | vi_ci.pNext = nullptr; |
| 7950 | vi_ci.vertexBindingDescriptionCount = 0; |
| 7951 | vi_ci.pVertexBindingDescriptions = nullptr; |
| 7952 | vi_ci.vertexAttributeDescriptionCount = 0; |
| 7953 | vi_ci.pVertexAttributeDescriptions = nullptr; |
| 7954 | |
| 7955 | VkPipelineInputAssemblyStateCreateInfo ia_ci = {}; |
| 7956 | ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO; |
| 7957 | ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP; |
| 7958 | |
| 7959 | VkPipelineRasterizationStateCreateInfo rs_ci = {}; |
| 7960 | rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO; |
| 7961 | rs_ci.pNext = nullptr; |
| 7962 | |
Mark Young | 4710795 | 2016-05-02 15:59:55 -0600 | [diff] [blame] | 7963 | // Check too low (line width of -1.0f). |
| 7964 | rs_ci.lineWidth = -1.0f; |
Mark Young | 7394fdd | 2016-03-31 14:56:43 -0600 | [diff] [blame] | 7965 | |
| 7966 | VkPipelineColorBlendAttachmentState att = {}; |
| 7967 | att.blendEnable = VK_FALSE; |
| 7968 | att.colorWriteMask = 0xf; |
| 7969 | |
| 7970 | VkPipelineColorBlendStateCreateInfo cb_ci = {}; |
| 7971 | cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO; |
| 7972 | cb_ci.pNext = nullptr; |
| 7973 | cb_ci.attachmentCount = 1; |
| 7974 | cb_ci.pAttachments = &att; |
| 7975 | |
| 7976 | VkGraphicsPipelineCreateInfo gp_ci = {}; |
| 7977 | gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO; |
| 7978 | gp_ci.stageCount = 2; |
| 7979 | gp_ci.pStages = shaderStages; |
| 7980 | gp_ci.pVertexInputState = &vi_ci; |
| 7981 | gp_ci.pInputAssemblyState = &ia_ci; |
| 7982 | gp_ci.pViewportState = &vp_state_ci; |
| 7983 | gp_ci.pRasterizationState = &rs_ci; |
| 7984 | gp_ci.pColorBlendState = &cb_ci; |
| 7985 | gp_ci.pDynamicState = &dyn_state_ci; |
| 7986 | gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT; |
| 7987 | gp_ci.layout = pipeline_layout; |
| 7988 | gp_ci.renderPass = renderPass(); |
| 7989 | |
| 7990 | VkPipelineCacheCreateInfo pc_ci = {}; |
| 7991 | pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO; |
| 7992 | |
| 7993 | VkPipeline pipeline; |
| 7994 | VkPipelineCache pipelineCache; |
| 7995 | |
| 7996 | err = |
| 7997 | vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache); |
| 7998 | ASSERT_VK_SUCCESS(err); |
| 7999 | err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, |
| 8000 | &gp_ci, NULL, &pipeline); |
| 8001 | |
| 8002 | m_errorMonitor->VerifyFound(); |
Tony Barbour | df4c004 | 2016-06-01 15:55:43 -0600 | [diff] [blame] | 8003 | vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL); |
Mark Young | 7394fdd | 2016-03-31 14:56:43 -0600 | [diff] [blame] | 8004 | |
| 8005 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 8006 | "Attempt to set lineWidth to 65536"); |
| 8007 | |
| 8008 | // Check too high (line width of 65536.0f). |
| 8009 | rs_ci.lineWidth = 65536.0f; |
| 8010 | |
| 8011 | err = |
| 8012 | vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache); |
| 8013 | ASSERT_VK_SUCCESS(err); |
| 8014 | err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, |
| 8015 | &gp_ci, NULL, &pipeline); |
| 8016 | |
| 8017 | m_errorMonitor->VerifyFound(); |
Tony Barbour | df4c004 | 2016-06-01 15:55:43 -0600 | [diff] [blame] | 8018 | vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL); |
Mark Young | 7394fdd | 2016-03-31 14:56:43 -0600 | [diff] [blame] | 8019 | |
| 8020 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Mark Young | 4710795 | 2016-05-02 15:59:55 -0600 | [diff] [blame] | 8021 | "Attempt to set lineWidth to -1"); |
Mark Young | 7394fdd | 2016-03-31 14:56:43 -0600 | [diff] [blame] | 8022 | |
| 8023 | dyn_state_ci.dynamicStateCount = 3; |
| 8024 | |
| 8025 | rs_ci.lineWidth = 1.0f; |
| 8026 | |
| 8027 | err = |
| 8028 | vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache); |
| 8029 | ASSERT_VK_SUCCESS(err); |
| 8030 | err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, |
| 8031 | &gp_ci, NULL, &pipeline); |
| 8032 | BeginCommandBuffer(); |
| 8033 | vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), |
| 8034 | VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline); |
| 8035 | |
| 8036 | // Check too low with dynamic setting. |
Mark Young | 4710795 | 2016-05-02 15:59:55 -0600 | [diff] [blame] | 8037 | vkCmdSetLineWidth(m_commandBuffer->GetBufferHandle(), -1.0f); |
Mark Young | 7394fdd | 2016-03-31 14:56:43 -0600 | [diff] [blame] | 8038 | m_errorMonitor->VerifyFound(); |
| 8039 | |
| 8040 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 8041 | "Attempt to set lineWidth to 65536"); |
| 8042 | |
| 8043 | // Check too high with dynamic setting. |
| 8044 | vkCmdSetLineWidth(m_commandBuffer->GetBufferHandle(), 65536.0f); |
| 8045 | m_errorMonitor->VerifyFound(); |
| 8046 | EndCommandBuffer(); |
| 8047 | |
| 8048 | vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL); |
| 8049 | vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL); |
| 8050 | vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL); |
| 8051 | vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL); |
Tony Barbour | df4c004 | 2016-06-01 15:55:43 -0600 | [diff] [blame] | 8052 | vkDestroyPipeline(m_device->device(), pipeline, NULL); |
Mark Young | 7394fdd | 2016-03-31 14:56:43 -0600 | [diff] [blame] | 8053 | } |
| 8054 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8055 | TEST_F(VkLayerTest, NullRenderPass) { |
Tobin Ehlis | 98aa0ed | 2015-06-25 16:27:19 -0600 | [diff] [blame] | 8056 | // Bind a NULL RenderPass |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8057 | m_errorMonitor->SetDesiredFailureMsg( |
| 8058 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 8059 | "You cannot use a NULL RenderPass object in vkCmdBeginRenderPass()"); |
Tobin Ehlis | 98aa0ed | 2015-06-25 16:27:19 -0600 | [diff] [blame] | 8060 | |
| 8061 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 8062 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
Tobin Ehlis | 98aa0ed | 2015-06-25 16:27:19 -0600 | [diff] [blame] | 8063 | |
Tony Barbour | fe3351b | 2015-07-28 10:17:20 -0600 | [diff] [blame] | 8064 | BeginCommandBuffer(); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8065 | // Don't care about RenderPass handle b/c error should be flagged before |
| 8066 | // that |
| 8067 | vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), NULL, |
| 8068 | VK_SUBPASS_CONTENTS_INLINE); |
Tobin Ehlis | 98aa0ed | 2015-06-25 16:27:19 -0600 | [diff] [blame] | 8069 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 8070 | m_errorMonitor->VerifyFound(); |
Tobin Ehlis | 98aa0ed | 2015-06-25 16:27:19 -0600 | [diff] [blame] | 8071 | } |
| 8072 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8073 | TEST_F(VkLayerTest, RenderPassWithinRenderPass) { |
Tobin Ehlis | af1f3a4 | 2015-06-25 15:46:59 -0600 | [diff] [blame] | 8074 | // Bind a BeginRenderPass within an active RenderPass |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8075 | m_errorMonitor->SetDesiredFailureMsg( |
| 8076 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 8077 | "It is invalid to issue this call inside an active render pass"); |
Tobin Ehlis | af1f3a4 | 2015-06-25 15:46:59 -0600 | [diff] [blame] | 8078 | |
| 8079 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 8080 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
Tobin Ehlis | af1f3a4 | 2015-06-25 15:46:59 -0600 | [diff] [blame] | 8081 | |
Tony Barbour | fe3351b | 2015-07-28 10:17:20 -0600 | [diff] [blame] | 8082 | BeginCommandBuffer(); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8083 | // Just create a dummy Renderpass that's non-NULL so we can get to the |
| 8084 | // proper error |
Chris Forbes | 38ae7c4 | 2016-06-21 20:51:44 +1200 | [diff] [blame] | 8085 | vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &m_renderPassBeginInfo, |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8086 | VK_SUBPASS_CONTENTS_INLINE); |
Tobin Ehlis | af1f3a4 | 2015-06-25 15:46:59 -0600 | [diff] [blame] | 8087 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 8088 | m_errorMonitor->VerifyFound(); |
Tobin Ehlis | 49eb23d | 2015-05-22 12:38:55 -0600 | [diff] [blame] | 8089 | } |
| 8090 | |
Chris Forbes | 2eeabe3 | 2016-06-21 20:52:34 +1200 | [diff] [blame] | 8091 | TEST_F(VkLayerTest, RenderPassSecondaryCommandBuffersMultipleTimes) { |
| 8092 | m_errorMonitor->ExpectSuccess(); |
| 8093 | |
| 8094 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 8095 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 8096 | |
| 8097 | BeginCommandBuffer(); // framework implicitly begins the renderpass. |
| 8098 | vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle()); // end implicit. |
| 8099 | |
| 8100 | vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &m_renderPassBeginInfo, |
| 8101 | VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS); |
| 8102 | vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle()); |
| 8103 | m_errorMonitor->VerifyNotFound(); |
| 8104 | vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &m_renderPassBeginInfo, |
| 8105 | VK_SUBPASS_CONTENTS_INLINE); |
| 8106 | m_errorMonitor->VerifyNotFound(); |
| 8107 | vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle()); |
| 8108 | m_errorMonitor->VerifyNotFound(); |
| 8109 | |
| 8110 | m_commandBuffer->EndCommandBuffer(); |
| 8111 | m_errorMonitor->VerifyNotFound(); |
| 8112 | } |
| 8113 | |
Tobin Ehlis | 5a1c033 | 2016-05-31 13:59:26 -0600 | [diff] [blame] | 8114 | TEST_F(VkLayerTest, RenderPassClearOpMismatch) { |
| 8115 | TEST_DESCRIPTION("Begin a renderPass where clearValueCount is less than" |
| 8116 | "the number of renderPass attachments that use loadOp" |
| 8117 | "VK_ATTACHMENT_LOAD_OP_CLEAR."); |
| 8118 | |
| 8119 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 8120 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 8121 | |
| 8122 | // Create a renderPass with a single attachment that uses loadOp CLEAR |
| 8123 | VkAttachmentReference attach = {}; |
| 8124 | attach.layout = VK_IMAGE_LAYOUT_GENERAL; |
| 8125 | VkSubpassDescription subpass = {}; |
| 8126 | subpass.inputAttachmentCount = 1; |
| 8127 | subpass.pInputAttachments = &attach; |
| 8128 | VkRenderPassCreateInfo rpci = {}; |
| 8129 | rpci.subpassCount = 1; |
| 8130 | rpci.pSubpasses = &subpass; |
| 8131 | rpci.attachmentCount = 1; |
| 8132 | VkAttachmentDescription attach_desc = {}; |
| 8133 | attach_desc.format = VK_FORMAT_UNDEFINED; |
| 8134 | // Set loadOp to CLEAR |
| 8135 | attach_desc.loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR; |
| 8136 | rpci.pAttachments = &attach_desc; |
| 8137 | rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO; |
| 8138 | VkRenderPass rp; |
| 8139 | vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp); |
| 8140 | |
| 8141 | VkCommandBufferInheritanceInfo hinfo = {}; |
| 8142 | hinfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO; |
| 8143 | hinfo.renderPass = VK_NULL_HANDLE; |
| 8144 | hinfo.subpass = 0; |
| 8145 | hinfo.framebuffer = VK_NULL_HANDLE; |
| 8146 | hinfo.occlusionQueryEnable = VK_FALSE; |
| 8147 | hinfo.queryFlags = 0; |
| 8148 | hinfo.pipelineStatistics = 0; |
| 8149 | VkCommandBufferBeginInfo info = {}; |
| 8150 | info.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT; |
| 8151 | info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO; |
| 8152 | info.pInheritanceInfo = &hinfo; |
| 8153 | |
| 8154 | vkBeginCommandBuffer(m_commandBuffer->handle(), &info); |
| 8155 | VkRenderPassBeginInfo rp_begin = {}; |
| 8156 | rp_begin.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO; |
| 8157 | rp_begin.pNext = NULL; |
| 8158 | rp_begin.renderPass = renderPass(); |
| 8159 | rp_begin.framebuffer = framebuffer(); |
| 8160 | rp_begin.clearValueCount = 0; // Should be 1 |
| 8161 | |
| 8162 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 8163 | " has a clearValueCount of 0 but the " |
| 8164 | "actual number of attachments in " |
| 8165 | "renderPass "); |
| 8166 | |
| 8167 | vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &rp_begin, |
| 8168 | VK_SUBPASS_CONTENTS_INLINE); |
| 8169 | |
| 8170 | m_errorMonitor->VerifyFound(); |
Mark Lobodzinski | 5c70ebd | 2016-06-09 13:45:00 -0600 | [diff] [blame] | 8171 | |
| 8172 | vkDestroyRenderPass(m_device->device(), rp, NULL); |
Tobin Ehlis | 5a1c033 | 2016-05-31 13:59:26 -0600 | [diff] [blame] | 8173 | } |
| 8174 | |
Cody Northrop | 3bb4d96 | 2016-05-09 16:15:57 -0600 | [diff] [blame] | 8175 | TEST_F(VkLayerTest, EndCommandBufferWithinRenderPass) { |
| 8176 | |
| 8177 | TEST_DESCRIPTION("End a command buffer with an active render pass"); |
| 8178 | |
| 8179 | m_errorMonitor->SetDesiredFailureMsg( |
| 8180 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 8181 | "It is invalid to issue this call inside an active render pass"); |
| 8182 | |
| 8183 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 8184 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 8185 | |
| 8186 | // The framework's BeginCommandBuffer calls CreateRenderPass |
| 8187 | BeginCommandBuffer(); |
| 8188 | |
| 8189 | // Call directly into vkEndCommandBuffer instead of the |
| 8190 | // the framework's EndCommandBuffer, which inserts a |
| 8191 | // vkEndRenderPass |
| 8192 | vkEndCommandBuffer(m_commandBuffer->GetBufferHandle()); |
| 8193 | |
| 8194 | m_errorMonitor->VerifyFound(); |
| 8195 | |
| 8196 | // TODO: Add test for VK_COMMAND_BUFFER_LEVEL_SECONDARY |
| 8197 | // TODO: Add test for VK_COMMAND_BUFFER_USAGE_RENDER_PASS_CONTINUE_BIT |
| 8198 | } |
| 8199 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8200 | TEST_F(VkLayerTest, FillBufferWithinRenderPass) { |
Mark Lobodzinski | d563950 | 2015-09-24 09:51:47 -0600 | [diff] [blame] | 8201 | // Call CmdFillBuffer within an active renderpass |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8202 | m_errorMonitor->SetDesiredFailureMsg( |
| 8203 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 8204 | "It is invalid to issue this call inside an active render pass"); |
Mark Lobodzinski | d563950 | 2015-09-24 09:51:47 -0600 | [diff] [blame] | 8205 | |
| 8206 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 8207 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
Mark Lobodzinski | d563950 | 2015-09-24 09:51:47 -0600 | [diff] [blame] | 8208 | |
| 8209 | // Renderpass is started here |
| 8210 | BeginCommandBuffer(); |
| 8211 | |
| 8212 | VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 8213 | vk_testing::Buffer dstBuffer; |
| 8214 | dstBuffer.init_as_dst(*m_device, (VkDeviceSize)1024, reqs); |
Mark Lobodzinski | d563950 | 2015-09-24 09:51:47 -0600 | [diff] [blame] | 8215 | |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 8216 | m_commandBuffer->FillBuffer(dstBuffer.handle(), 0, 4, 0x11111111); |
Mark Lobodzinski | d563950 | 2015-09-24 09:51:47 -0600 | [diff] [blame] | 8217 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 8218 | m_errorMonitor->VerifyFound(); |
Mark Lobodzinski | d563950 | 2015-09-24 09:51:47 -0600 | [diff] [blame] | 8219 | } |
| 8220 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8221 | TEST_F(VkLayerTest, UpdateBufferWithinRenderPass) { |
Mark Lobodzinski | d563950 | 2015-09-24 09:51:47 -0600 | [diff] [blame] | 8222 | // Call CmdUpdateBuffer within an active renderpass |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8223 | m_errorMonitor->SetDesiredFailureMsg( |
| 8224 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 8225 | "It is invalid to issue this call inside an active render pass"); |
Mark Lobodzinski | d563950 | 2015-09-24 09:51:47 -0600 | [diff] [blame] | 8226 | |
| 8227 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 8228 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
Mark Lobodzinski | d563950 | 2015-09-24 09:51:47 -0600 | [diff] [blame] | 8229 | |
| 8230 | // Renderpass is started here |
| 8231 | BeginCommandBuffer(); |
| 8232 | |
| 8233 | VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 8234 | vk_testing::Buffer dstBuffer; |
| 8235 | dstBuffer.init_as_dst(*m_device, (VkDeviceSize)1024, reqs); |
Mark Lobodzinski | d563950 | 2015-09-24 09:51:47 -0600 | [diff] [blame] | 8236 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8237 | VkDeviceSize dstOffset = 0; |
| 8238 | VkDeviceSize dataSize = 1024; |
| 8239 | const uint32_t *pData = NULL; |
Mark Lobodzinski | d563950 | 2015-09-24 09:51:47 -0600 | [diff] [blame] | 8240 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8241 | vkCmdUpdateBuffer(m_commandBuffer->GetBufferHandle(), dstBuffer.handle(), |
| 8242 | dstOffset, dataSize, pData); |
Mark Lobodzinski | d563950 | 2015-09-24 09:51:47 -0600 | [diff] [blame] | 8243 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 8244 | m_errorMonitor->VerifyFound(); |
Mark Lobodzinski | d563950 | 2015-09-24 09:51:47 -0600 | [diff] [blame] | 8245 | } |
| 8246 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8247 | TEST_F(VkLayerTest, ClearColorImageWithinRenderPass) { |
Mark Lobodzinski | d563950 | 2015-09-24 09:51:47 -0600 | [diff] [blame] | 8248 | // Call CmdClearColorImage within an active RenderPass |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8249 | m_errorMonitor->SetDesiredFailureMsg( |
| 8250 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 8251 | "It is invalid to issue this call inside an active render pass"); |
Mark Lobodzinski | d563950 | 2015-09-24 09:51:47 -0600 | [diff] [blame] | 8252 | |
| 8253 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 8254 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
Mark Lobodzinski | d563950 | 2015-09-24 09:51:47 -0600 | [diff] [blame] | 8255 | |
| 8256 | // Renderpass is started here |
| 8257 | BeginCommandBuffer(); |
| 8258 | |
Michael Lentine | 0a369f6 | 2016-02-03 16:51:46 -0600 | [diff] [blame] | 8259 | VkClearColorValue clear_color; |
| 8260 | memset(clear_color.uint32, 0, sizeof(uint32_t) * 4); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8261 | VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT; |
| 8262 | const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM; |
| 8263 | const int32_t tex_width = 32; |
| 8264 | const int32_t tex_height = 32; |
| 8265 | VkImageCreateInfo image_create_info = {}; |
| 8266 | image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO; |
| 8267 | image_create_info.pNext = NULL; |
| 8268 | image_create_info.imageType = VK_IMAGE_TYPE_2D; |
| 8269 | image_create_info.format = tex_format; |
| 8270 | image_create_info.extent.width = tex_width; |
| 8271 | image_create_info.extent.height = tex_height; |
| 8272 | image_create_info.extent.depth = 1; |
| 8273 | image_create_info.mipLevels = 1; |
| 8274 | image_create_info.arrayLayers = 1; |
| 8275 | image_create_info.samples = VK_SAMPLE_COUNT_1_BIT; |
| 8276 | image_create_info.tiling = VK_IMAGE_TILING_LINEAR; |
| 8277 | image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT; |
Mark Lobodzinski | d563950 | 2015-09-24 09:51:47 -0600 | [diff] [blame] | 8278 | |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 8279 | vk_testing::Image dstImage; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8280 | dstImage.init(*m_device, (const VkImageCreateInfo &)image_create_info, |
| 8281 | reqs); |
Mark Lobodzinski | d563950 | 2015-09-24 09:51:47 -0600 | [diff] [blame] | 8282 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8283 | const VkImageSubresourceRange range = vk_testing::Image::subresource_range( |
| 8284 | image_create_info, VK_IMAGE_ASPECT_COLOR_BIT); |
Mark Lobodzinski | d563950 | 2015-09-24 09:51:47 -0600 | [diff] [blame] | 8285 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8286 | vkCmdClearColorImage(m_commandBuffer->GetBufferHandle(), dstImage.handle(), |
| 8287 | VK_IMAGE_LAYOUT_GENERAL, &clear_color, 1, &range); |
Mark Lobodzinski | d563950 | 2015-09-24 09:51:47 -0600 | [diff] [blame] | 8288 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 8289 | m_errorMonitor->VerifyFound(); |
Mark Lobodzinski | d563950 | 2015-09-24 09:51:47 -0600 | [diff] [blame] | 8290 | } |
| 8291 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8292 | TEST_F(VkLayerTest, ClearDepthStencilImageWithinRenderPass) { |
Mark Lobodzinski | d563950 | 2015-09-24 09:51:47 -0600 | [diff] [blame] | 8293 | // Call CmdClearDepthStencilImage within an active RenderPass |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8294 | m_errorMonitor->SetDesiredFailureMsg( |
| 8295 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 8296 | "It is invalid to issue this call inside an active render pass"); |
Mark Lobodzinski | d563950 | 2015-09-24 09:51:47 -0600 | [diff] [blame] | 8297 | |
| 8298 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 8299 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
Mark Lobodzinski | d563950 | 2015-09-24 09:51:47 -0600 | [diff] [blame] | 8300 | |
| 8301 | // Renderpass is started here |
| 8302 | BeginCommandBuffer(); |
| 8303 | |
| 8304 | VkClearDepthStencilValue clear_value = {0}; |
Dustin Graves | a2e5c94 | 2016-02-11 18:28:06 -0700 | [diff] [blame] | 8305 | VkMemoryPropertyFlags reqs = 0; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8306 | VkImageCreateInfo image_create_info = vk_testing::Image::create_info(); |
| 8307 | image_create_info.imageType = VK_IMAGE_TYPE_2D; |
| 8308 | image_create_info.format = VK_FORMAT_D24_UNORM_S8_UINT; |
| 8309 | image_create_info.extent.width = 64; |
| 8310 | image_create_info.extent.height = 64; |
| 8311 | image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL; |
| 8312 | image_create_info.usage = VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT; |
Mark Lobodzinski | d563950 | 2015-09-24 09:51:47 -0600 | [diff] [blame] | 8313 | |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 8314 | vk_testing::Image dstImage; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8315 | dstImage.init(*m_device, (const VkImageCreateInfo &)image_create_info, |
| 8316 | reqs); |
Mark Lobodzinski | d563950 | 2015-09-24 09:51:47 -0600 | [diff] [blame] | 8317 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8318 | const VkImageSubresourceRange range = vk_testing::Image::subresource_range( |
| 8319 | image_create_info, VK_IMAGE_ASPECT_DEPTH_BIT); |
Mark Lobodzinski | d563950 | 2015-09-24 09:51:47 -0600 | [diff] [blame] | 8320 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8321 | vkCmdClearDepthStencilImage( |
| 8322 | m_commandBuffer->GetBufferHandle(), dstImage.handle(), |
| 8323 | VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL, &clear_value, 1, |
| 8324 | &range); |
Mark Lobodzinski | d563950 | 2015-09-24 09:51:47 -0600 | [diff] [blame] | 8325 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 8326 | m_errorMonitor->VerifyFound(); |
Mark Lobodzinski | d563950 | 2015-09-24 09:51:47 -0600 | [diff] [blame] | 8327 | } |
| 8328 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8329 | TEST_F(VkLayerTest, ClearColorAttachmentsOutsideRenderPass) { |
Courtney Goeltzenleuchter | c9323e0 | 2015-10-15 16:51:05 -0600 | [diff] [blame] | 8330 | // Call CmdClearAttachmentss outside of an active RenderPass |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8331 | VkResult err; |
Mark Lobodzinski | d563950 | 2015-09-24 09:51:47 -0600 | [diff] [blame] | 8332 | |
Courtney Goeltzenleuchter | 7415d5a | 2015-12-09 15:48:16 -0700 | [diff] [blame] | 8333 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8334 | "vkCmdClearAttachments: This call " |
| 8335 | "must be issued inside an active " |
| 8336 | "render pass"); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 8337 | |
Mark Lobodzinski | d563950 | 2015-09-24 09:51:47 -0600 | [diff] [blame] | 8338 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 8339 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
Mark Lobodzinski | d563950 | 2015-09-24 09:51:47 -0600 | [diff] [blame] | 8340 | |
| 8341 | // Start no RenderPass |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 8342 | err = m_commandBuffer->BeginCommandBuffer(); |
Mark Lobodzinski | d563950 | 2015-09-24 09:51:47 -0600 | [diff] [blame] | 8343 | ASSERT_VK_SUCCESS(err); |
| 8344 | |
Courtney Goeltzenleuchter | c9323e0 | 2015-10-15 16:51:05 -0600 | [diff] [blame] | 8345 | VkClearAttachment color_attachment; |
| 8346 | color_attachment.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; |
| 8347 | color_attachment.clearValue.color.float32[0] = 0; |
| 8348 | color_attachment.clearValue.color.float32[1] = 0; |
| 8349 | color_attachment.clearValue.color.float32[2] = 0; |
| 8350 | color_attachment.clearValue.color.float32[3] = 0; |
| 8351 | color_attachment.colorAttachment = 0; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8352 | VkClearRect clear_rect = {{{0, 0}, {32, 32}}}; |
| 8353 | vkCmdClearAttachments(m_commandBuffer->GetBufferHandle(), 1, |
| 8354 | &color_attachment, 1, &clear_rect); |
Mark Lobodzinski | d563950 | 2015-09-24 09:51:47 -0600 | [diff] [blame] | 8355 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 8356 | m_errorMonitor->VerifyFound(); |
Mark Lobodzinski | d563950 | 2015-09-24 09:51:47 -0600 | [diff] [blame] | 8357 | } |
| 8358 | |
Karl Schultz | 9e66a29 | 2016-04-21 15:57:51 -0600 | [diff] [blame] | 8359 | TEST_F(VkLayerTest, BufferMemoryBarrierNoBuffer) { |
| 8360 | // Try to add a buffer memory barrier with no buffer. |
| 8361 | m_errorMonitor->SetDesiredFailureMsg( |
| 8362 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 8363 | "required parameter pBufferMemoryBarriers[i].buffer specified as VK_NULL_HANDLE"); |
| 8364 | |
| 8365 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 8366 | BeginCommandBuffer(); |
| 8367 | |
| 8368 | VkBufferMemoryBarrier buf_barrier = {}; |
| 8369 | buf_barrier.sType = VK_STRUCTURE_TYPE_BUFFER_MEMORY_BARRIER; |
| 8370 | buf_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT; |
| 8371 | buf_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT; |
| 8372 | buf_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED; |
| 8373 | buf_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED; |
| 8374 | buf_barrier.buffer = VK_NULL_HANDLE; |
| 8375 | buf_barrier.offset = 0; |
| 8376 | buf_barrier.size = VK_WHOLE_SIZE; |
| 8377 | vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), |
| 8378 | VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, |
| 8379 | 0, 0, nullptr, 1, &buf_barrier, 0, nullptr); |
| 8380 | |
| 8381 | m_errorMonitor->VerifyFound(); |
| 8382 | } |
| 8383 | |
Tony Barbour | 7fd5c0f | 2016-05-03 16:11:53 -0600 | [diff] [blame] | 8384 | TEST_F(VkLayerTest, InvalidBarriers) { |
| 8385 | TEST_DESCRIPTION("A variety of ways to get VK_INVALID_BARRIER "); |
| 8386 | |
| 8387 | m_errorMonitor->SetDesiredFailureMsg( |
| 8388 | VK_DEBUG_REPORT_ERROR_BIT_EXT, "Barriers cannot be set during subpass"); |
| 8389 | |
| 8390 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 8391 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 8392 | |
| 8393 | VkMemoryBarrier mem_barrier = {}; |
| 8394 | mem_barrier.sType = VK_STRUCTURE_TYPE_MEMORY_BARRIER; |
| 8395 | mem_barrier.pNext = NULL; |
| 8396 | mem_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT; |
| 8397 | mem_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT; |
| 8398 | BeginCommandBuffer(); |
| 8399 | // BeginCommandBuffer() starts a render pass |
| 8400 | vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), |
| 8401 | VK_PIPELINE_STAGE_HOST_BIT, |
| 8402 | VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 1, |
| 8403 | &mem_barrier, 0, nullptr, 0, nullptr); |
| 8404 | m_errorMonitor->VerifyFound(); |
| 8405 | |
| 8406 | m_errorMonitor->SetDesiredFailureMsg( |
| 8407 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 8408 | "Image Layout cannot be transitioned to UNDEFINED"); |
| 8409 | VkImageObj image(m_device); |
| 8410 | image.init(128, 128, VK_FORMAT_B8G8R8A8_UNORM, |
| 8411 | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0); |
| 8412 | ASSERT_TRUE(image.initialized()); |
| 8413 | VkImageMemoryBarrier img_barrier = {}; |
| 8414 | img_barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER; |
| 8415 | img_barrier.pNext = NULL; |
| 8416 | img_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT; |
| 8417 | img_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT; |
| 8418 | img_barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL; |
| 8419 | // New layout can't be UNDEFINED |
| 8420 | img_barrier.newLayout = VK_IMAGE_LAYOUT_UNDEFINED; |
| 8421 | img_barrier.image = image.handle(); |
| 8422 | img_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED; |
| 8423 | img_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED; |
| 8424 | img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; |
| 8425 | img_barrier.subresourceRange.baseArrayLayer = 0; |
| 8426 | img_barrier.subresourceRange.baseMipLevel = 0; |
| 8427 | img_barrier.subresourceRange.layerCount = 1; |
| 8428 | img_barrier.subresourceRange.levelCount = 1; |
| 8429 | vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), |
| 8430 | VK_PIPELINE_STAGE_HOST_BIT, |
| 8431 | VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0, nullptr, 0, |
| 8432 | nullptr, 1, &img_barrier); |
| 8433 | m_errorMonitor->VerifyFound(); |
| 8434 | img_barrier.newLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL; |
| 8435 | |
| 8436 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 8437 | "Subresource must have the sum of the " |
| 8438 | "baseArrayLayer"); |
| 8439 | // baseArrayLayer + layerCount must be <= image's arrayLayers |
| 8440 | img_barrier.subresourceRange.baseArrayLayer = 1; |
| 8441 | vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), |
| 8442 | VK_PIPELINE_STAGE_HOST_BIT, |
| 8443 | VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0, nullptr, 0, |
| 8444 | nullptr, 1, &img_barrier); |
| 8445 | m_errorMonitor->VerifyFound(); |
| 8446 | img_barrier.subresourceRange.baseArrayLayer = 0; |
| 8447 | |
| 8448 | m_errorMonitor->SetDesiredFailureMsg( |
| 8449 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 8450 | "Subresource must have the sum of the baseMipLevel"); |
| 8451 | // baseMipLevel + levelCount must be <= image's mipLevels |
| 8452 | img_barrier.subresourceRange.baseMipLevel = 1; |
| 8453 | vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), |
| 8454 | VK_PIPELINE_STAGE_HOST_BIT, |
| 8455 | VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0, nullptr, 0, |
| 8456 | nullptr, 1, &img_barrier); |
| 8457 | m_errorMonitor->VerifyFound(); |
| 8458 | img_barrier.subresourceRange.baseMipLevel = 0; |
| 8459 | |
| 8460 | m_errorMonitor->SetDesiredFailureMsg( |
| 8461 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 8462 | "Buffer Barriers cannot be used during a render pass"); |
| 8463 | vk_testing::Buffer buffer; |
| 8464 | buffer.init(*m_device, 256); |
| 8465 | VkBufferMemoryBarrier buf_barrier = {}; |
| 8466 | buf_barrier.sType = VK_STRUCTURE_TYPE_BUFFER_MEMORY_BARRIER; |
| 8467 | buf_barrier.pNext = NULL; |
| 8468 | buf_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT; |
| 8469 | buf_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT; |
| 8470 | buf_barrier.buffer = buffer.handle(); |
| 8471 | buf_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED; |
| 8472 | buf_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED; |
| 8473 | buf_barrier.offset = 0; |
| 8474 | buf_barrier.size = VK_WHOLE_SIZE; |
| 8475 | // Can't send buffer barrier during a render pass |
| 8476 | vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), |
| 8477 | VK_PIPELINE_STAGE_HOST_BIT, |
| 8478 | VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0, nullptr, 1, |
| 8479 | &buf_barrier, 0, nullptr); |
| 8480 | m_errorMonitor->VerifyFound(); |
| 8481 | vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle()); |
| 8482 | |
| 8483 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 8484 | "which is not less than total size"); |
| 8485 | buf_barrier.offset = 257; |
| 8486 | // Offset greater than total size |
| 8487 | vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), |
| 8488 | VK_PIPELINE_STAGE_HOST_BIT, |
| 8489 | VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0, nullptr, 1, |
| 8490 | &buf_barrier, 0, nullptr); |
| 8491 | m_errorMonitor->VerifyFound(); |
| 8492 | buf_barrier.offset = 0; |
| 8493 | |
| 8494 | m_errorMonitor->SetDesiredFailureMsg( |
| 8495 | VK_DEBUG_REPORT_ERROR_BIT_EXT, "whose sum is greater than total size"); |
| 8496 | buf_barrier.size = 257; |
| 8497 | // Size greater than total size |
| 8498 | vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), |
| 8499 | VK_PIPELINE_STAGE_HOST_BIT, |
| 8500 | VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0, nullptr, 1, |
| 8501 | &buf_barrier, 0, nullptr); |
| 8502 | m_errorMonitor->VerifyFound(); |
| 8503 | buf_barrier.size = VK_WHOLE_SIZE; |
| 8504 | |
| 8505 | m_errorMonitor->SetDesiredFailureMsg( |
| 8506 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 8507 | "Image is a depth and stencil format and thus must " |
| 8508 | "have both VK_IMAGE_ASPECT_DEPTH_BIT and " |
| 8509 | "VK_IMAGE_ASPECT_STENCIL_BIT set."); |
| 8510 | VkDepthStencilObj ds_image(m_device); |
| 8511 | ds_image.Init(m_device, 128, 128, VK_FORMAT_D24_UNORM_S8_UINT); |
| 8512 | ASSERT_TRUE(ds_image.initialized()); |
| 8513 | img_barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL; |
| 8514 | img_barrier.newLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL; |
| 8515 | img_barrier.image = ds_image.handle(); |
| 8516 | // Leave aspectMask at COLOR on purpose |
| 8517 | vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), |
| 8518 | VK_PIPELINE_STAGE_HOST_BIT, |
| 8519 | VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0, nullptr, 0, |
| 8520 | nullptr, 1, &img_barrier); |
| 8521 | m_errorMonitor->VerifyFound(); |
| 8522 | } |
| 8523 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8524 | TEST_F(VkLayerTest, IdxBufferAlignmentError) { |
Tobin Ehlis | c4c2318 | 2015-09-17 12:24:13 -0600 | [diff] [blame] | 8525 | // Bind a BeginRenderPass within an active RenderPass |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8526 | VkResult err; |
Tobin Ehlis | c4c2318 | 2015-09-17 12:24:13 -0600 | [diff] [blame] | 8527 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8528 | m_errorMonitor->SetDesiredFailureMsg( |
| 8529 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 8530 | "vkCmdBindIndexBuffer() offset (0x7) does not fall on "); |
| 8531 | |
Tobin Ehlis | c4c2318 | 2015-09-17 12:24:13 -0600 | [diff] [blame] | 8532 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 8533 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
Tobin Ehlis | c4c2318 | 2015-09-17 12:24:13 -0600 | [diff] [blame] | 8534 | uint32_t qfi = 0; |
| 8535 | VkBufferCreateInfo buffCI = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8536 | buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO; |
| 8537 | buffCI.size = 1024; |
| 8538 | buffCI.usage = VK_BUFFER_USAGE_INDEX_BUFFER_BIT; |
| 8539 | buffCI.queueFamilyIndexCount = 1; |
| 8540 | buffCI.pQueueFamilyIndices = &qfi; |
Tobin Ehlis | c4c2318 | 2015-09-17 12:24:13 -0600 | [diff] [blame] | 8541 | |
| 8542 | VkBuffer ib; |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 8543 | err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &ib); |
Tobin Ehlis | c4c2318 | 2015-09-17 12:24:13 -0600 | [diff] [blame] | 8544 | ASSERT_VK_SUCCESS(err); |
| 8545 | |
| 8546 | BeginCommandBuffer(); |
| 8547 | ASSERT_VK_SUCCESS(err); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8548 | // vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), |
| 8549 | // VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle()); |
Tobin Ehlis | c4c2318 | 2015-09-17 12:24:13 -0600 | [diff] [blame] | 8550 | // 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] | 8551 | vkCmdBindIndexBuffer(m_commandBuffer->GetBufferHandle(), ib, 7, |
| 8552 | VK_INDEX_TYPE_UINT16); |
Tobin Ehlis | c4c2318 | 2015-09-17 12:24:13 -0600 | [diff] [blame] | 8553 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 8554 | m_errorMonitor->VerifyFound(); |
Mike Stroyan | d1c84a5 | 2015-08-18 14:40:24 -0600 | [diff] [blame] | 8555 | |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 8556 | vkDestroyBuffer(m_device->device(), ib, NULL); |
Tobin Ehlis | c4c2318 | 2015-09-17 12:24:13 -0600 | [diff] [blame] | 8557 | } |
| 8558 | |
Mark Lobodzinski | 52a6e7d | 2016-02-25 15:09:52 -0700 | [diff] [blame] | 8559 | TEST_F(VkLayerTest, InvalidQueueFamilyIndex) { |
| 8560 | // Create an out-of-range queueFamilyIndex |
| 8561 | m_errorMonitor->SetDesiredFailureMsg( |
| 8562 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Dustin Graves | de62853 | 2016-04-21 16:30:17 -0600 | [diff] [blame] | 8563 | "vkCreateBuffer: pCreateInfo->pQueueFamilyIndices[0] (777) must be one " |
| 8564 | "of the indices specified when the device was created, via the " |
| 8565 | "VkDeviceQueueCreateInfo structure."); |
Mark Lobodzinski | 52a6e7d | 2016-02-25 15:09:52 -0700 | [diff] [blame] | 8566 | |
| 8567 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 8568 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 8569 | VkBufferCreateInfo buffCI = {}; |
| 8570 | buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO; |
| 8571 | buffCI.size = 1024; |
| 8572 | buffCI.usage = VK_BUFFER_USAGE_INDEX_BUFFER_BIT; |
| 8573 | buffCI.queueFamilyIndexCount = 1; |
| 8574 | // Introduce failure by specifying invalid queue_family_index |
| 8575 | uint32_t qfi = 777; |
| 8576 | buffCI.pQueueFamilyIndices = &qfi; |
Tobin Ehlis | 24aab04 | 2016-03-24 10:54:18 -0600 | [diff] [blame] | 8577 | buffCI.sharingMode = VK_SHARING_MODE_CONCURRENT; // qfi only matters in CONCURRENT mode |
Mark Lobodzinski | 52a6e7d | 2016-02-25 15:09:52 -0700 | [diff] [blame] | 8578 | |
| 8579 | VkBuffer ib; |
| 8580 | vkCreateBuffer(m_device->device(), &buffCI, NULL, &ib); |
| 8581 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 8582 | m_errorMonitor->VerifyFound(); |
Tony Barbour | df4c004 | 2016-06-01 15:55:43 -0600 | [diff] [blame] | 8583 | vkDestroyBuffer(m_device->device(), ib, NULL); |
Mark Lobodzinski | 52a6e7d | 2016-02-25 15:09:52 -0700 | [diff] [blame] | 8584 | } |
| 8585 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8586 | TEST_F(VkLayerTest, ExecuteCommandsPrimaryCB) { |
| 8587 | // Attempt vkCmdExecuteCommands w/ a primary cmd buffer (should only be |
| 8588 | // secondary) |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 8589 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8590 | m_errorMonitor->SetDesiredFailureMsg( |
| 8591 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 8592 | "vkCmdExecuteCommands() called w/ Primary Cmd Buffer "); |
Tobin Ehlis | 4b34ddc | 2015-09-17 14:18:16 -0600 | [diff] [blame] | 8593 | |
| 8594 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 8595 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
Tobin Ehlis | 4b34ddc | 2015-09-17 14:18:16 -0600 | [diff] [blame] | 8596 | |
| 8597 | BeginCommandBuffer(); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8598 | // ASSERT_VK_SUCCESS(err); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 8599 | VkCommandBuffer primCB = m_commandBuffer->GetBufferHandle(); |
| 8600 | vkCmdExecuteCommands(m_commandBuffer->GetBufferHandle(), 1, &primCB); |
Tobin Ehlis | 4b34ddc | 2015-09-17 14:18:16 -0600 | [diff] [blame] | 8601 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 8602 | m_errorMonitor->VerifyFound(); |
Tobin Ehlis | 4b34ddc | 2015-09-17 14:18:16 -0600 | [diff] [blame] | 8603 | } |
| 8604 | |
Tobin Ehlis | 17826bd | 2016-05-25 11:12:50 -0600 | [diff] [blame] | 8605 | TEST_F(VkLayerTest, DSUsageBitsErrors) { |
| 8606 | TEST_DESCRIPTION("Attempt to update descriptor sets for images and buffers " |
| 8607 | "that do not have correct usage bits sets."); |
| 8608 | VkResult err; |
| 8609 | |
| 8610 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 8611 | VkDescriptorPoolSize ds_type_count[VK_DESCRIPTOR_TYPE_RANGE_SIZE] = {}; |
| 8612 | for (uint32_t i = 0; i < VK_DESCRIPTOR_TYPE_RANGE_SIZE; ++i) { |
| 8613 | ds_type_count[i].type = VkDescriptorType(i); |
| 8614 | ds_type_count[i].descriptorCount = 1; |
| 8615 | } |
| 8616 | VkDescriptorPoolCreateInfo ds_pool_ci = {}; |
| 8617 | ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO; |
| 8618 | ds_pool_ci.pNext = NULL; |
| 8619 | ds_pool_ci.maxSets = VK_DESCRIPTOR_TYPE_RANGE_SIZE; |
| 8620 | ds_pool_ci.poolSizeCount = VK_DESCRIPTOR_TYPE_RANGE_SIZE; |
| 8621 | ds_pool_ci.pPoolSizes = ds_type_count; |
| 8622 | |
| 8623 | VkDescriptorPool ds_pool; |
| 8624 | err = |
| 8625 | vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool); |
| 8626 | ASSERT_VK_SUCCESS(err); |
| 8627 | |
| 8628 | // Create 10 layouts where each has a single descriptor of different type |
| 8629 | VkDescriptorSetLayoutBinding dsl_binding[VK_DESCRIPTOR_TYPE_RANGE_SIZE] = |
| 8630 | {}; |
| 8631 | for (uint32_t i = 0; i < VK_DESCRIPTOR_TYPE_RANGE_SIZE; ++i) { |
| 8632 | dsl_binding[i].binding = 0; |
| 8633 | dsl_binding[i].descriptorType = VkDescriptorType(i); |
| 8634 | dsl_binding[i].descriptorCount = 1; |
| 8635 | dsl_binding[i].stageFlags = VK_SHADER_STAGE_ALL; |
| 8636 | dsl_binding[i].pImmutableSamplers = NULL; |
| 8637 | } |
| 8638 | |
| 8639 | VkDescriptorSetLayoutCreateInfo ds_layout_ci = {}; |
| 8640 | ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO; |
| 8641 | ds_layout_ci.pNext = NULL; |
| 8642 | ds_layout_ci.bindingCount = 1; |
| 8643 | VkDescriptorSetLayout ds_layouts[VK_DESCRIPTOR_TYPE_RANGE_SIZE]; |
| 8644 | for (uint32_t i = 0; i < VK_DESCRIPTOR_TYPE_RANGE_SIZE; ++i) { |
| 8645 | ds_layout_ci.pBindings = dsl_binding + i; |
| 8646 | err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, |
| 8647 | NULL, ds_layouts + i); |
| 8648 | ASSERT_VK_SUCCESS(err); |
| 8649 | } |
| 8650 | VkDescriptorSet descriptor_sets[VK_DESCRIPTOR_TYPE_RANGE_SIZE] = {}; |
| 8651 | VkDescriptorSetAllocateInfo alloc_info = {}; |
| 8652 | alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO; |
| 8653 | alloc_info.descriptorSetCount = VK_DESCRIPTOR_TYPE_RANGE_SIZE; |
| 8654 | alloc_info.descriptorPool = ds_pool; |
| 8655 | alloc_info.pSetLayouts = ds_layouts; |
| 8656 | err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, |
| 8657 | descriptor_sets); |
| 8658 | ASSERT_VK_SUCCESS(err); |
| 8659 | |
| 8660 | // Create a buffer & bufferView to be used for invalid updates |
| 8661 | VkBufferCreateInfo buff_ci = {}; |
| 8662 | buff_ci.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO; |
| 8663 | // This usage is not valid for any descriptor type |
| 8664 | buff_ci.usage = VK_BUFFER_USAGE_TRANSFER_SRC_BIT; |
| 8665 | buff_ci.size = 256; |
| 8666 | buff_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE; |
| 8667 | VkBuffer buffer; |
| 8668 | err = vkCreateBuffer(m_device->device(), &buff_ci, NULL, &buffer); |
| 8669 | ASSERT_VK_SUCCESS(err); |
| 8670 | |
| 8671 | VkBufferViewCreateInfo buff_view_ci = {}; |
| 8672 | buff_view_ci.sType = VK_STRUCTURE_TYPE_BUFFER_VIEW_CREATE_INFO; |
| 8673 | buff_view_ci.buffer = buffer; |
| 8674 | buff_view_ci.format = VK_FORMAT_R8_UNORM; |
| 8675 | buff_view_ci.range = VK_WHOLE_SIZE; |
| 8676 | VkBufferView buff_view; |
| 8677 | err = |
| 8678 | vkCreateBufferView(m_device->device(), &buff_view_ci, NULL, &buff_view); |
| 8679 | ASSERT_VK_SUCCESS(err); |
| 8680 | |
| 8681 | // Create an image to be used for invalid updates |
| 8682 | VkImageCreateInfo image_ci = {}; |
| 8683 | image_ci.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO; |
| 8684 | image_ci.imageType = VK_IMAGE_TYPE_2D; |
| 8685 | image_ci.format = VK_FORMAT_R8G8B8A8_UNORM; |
| 8686 | image_ci.extent.width = 64; |
| 8687 | image_ci.extent.height = 64; |
| 8688 | image_ci.extent.depth = 1; |
| 8689 | image_ci.mipLevels = 1; |
| 8690 | image_ci.arrayLayers = 1; |
| 8691 | image_ci.samples = VK_SAMPLE_COUNT_1_BIT; |
| 8692 | image_ci.tiling = VK_IMAGE_TILING_LINEAR; |
| 8693 | image_ci.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED; |
| 8694 | // This usage is not valid for any descriptor type |
| 8695 | image_ci.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT; |
| 8696 | image_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE; |
| 8697 | VkImage image; |
| 8698 | err = vkCreateImage(m_device->device(), &image_ci, NULL, &image); |
| 8699 | ASSERT_VK_SUCCESS(err); |
| 8700 | // Bind memory to image |
| 8701 | VkMemoryRequirements mem_reqs; |
| 8702 | VkDeviceMemory image_mem; |
| 8703 | bool pass; |
| 8704 | VkMemoryAllocateInfo mem_alloc = {}; |
| 8705 | mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO; |
| 8706 | mem_alloc.pNext = NULL; |
| 8707 | mem_alloc.allocationSize = 0; |
| 8708 | mem_alloc.memoryTypeIndex = 0; |
| 8709 | vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs); |
| 8710 | mem_alloc.allocationSize = mem_reqs.size; |
| 8711 | pass = |
| 8712 | m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0); |
| 8713 | ASSERT_TRUE(pass); |
| 8714 | err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &image_mem); |
| 8715 | ASSERT_VK_SUCCESS(err); |
| 8716 | err = vkBindImageMemory(m_device->device(), image, image_mem, 0); |
| 8717 | ASSERT_VK_SUCCESS(err); |
| 8718 | // Now create view for image |
| 8719 | VkImageViewCreateInfo image_view_ci = {}; |
| 8720 | image_view_ci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO; |
| 8721 | image_view_ci.image = image; |
| 8722 | image_view_ci.format = VK_FORMAT_R8G8B8A8_UNORM; |
| 8723 | image_view_ci.viewType = VK_IMAGE_VIEW_TYPE_2D; |
| 8724 | image_view_ci.subresourceRange.layerCount = 1; |
| 8725 | image_view_ci.subresourceRange.baseArrayLayer = 0; |
| 8726 | image_view_ci.subresourceRange.levelCount = 1; |
| 8727 | image_view_ci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; |
| 8728 | VkImageView image_view; |
| 8729 | err = vkCreateImageView(m_device->device(), &image_view_ci, NULL, |
| 8730 | &image_view); |
| 8731 | ASSERT_VK_SUCCESS(err); |
| 8732 | |
| 8733 | VkDescriptorBufferInfo buff_info = {}; |
| 8734 | buff_info.buffer = buffer; |
| 8735 | VkDescriptorImageInfo img_info = {}; |
| 8736 | img_info.imageView = image_view; |
| 8737 | VkWriteDescriptorSet descriptor_write = {}; |
| 8738 | descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET; |
| 8739 | descriptor_write.dstBinding = 0; |
| 8740 | descriptor_write.descriptorCount = 1; |
| 8741 | descriptor_write.pTexelBufferView = &buff_view; |
| 8742 | descriptor_write.pBufferInfo = &buff_info; |
| 8743 | descriptor_write.pImageInfo = &img_info; |
| 8744 | |
| 8745 | // These error messages align with VkDescriptorType struct |
| 8746 | const char *error_msgs[] = { |
| 8747 | "", // placeholder, no error for SAMPLER descriptor |
| 8748 | " does not have VK_IMAGE_USAGE_SAMPLED_BIT set.", |
| 8749 | " does not have VK_IMAGE_USAGE_SAMPLED_BIT set.", |
| 8750 | " does not have VK_IMAGE_USAGE_STORAGE_BIT set.", |
| 8751 | " does not have VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT set.", |
| 8752 | " does not have VK_BUFFER_USAGE_STORAGE_TEXEL_BUFFER_BIT set.", |
| 8753 | " does not have VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT set.", |
| 8754 | " does not have VK_BUFFER_USAGE_STORAGE_BUFFER_BIT set.", |
| 8755 | " does not have VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT set.", |
| 8756 | " does not have VK_BUFFER_USAGE_STORAGE_BUFFER_BIT set.", |
| 8757 | " does not have VK_IMAGE_USAGE_INPUT_ATTACHMENT_BIT set."}; |
| 8758 | // Start loop at 1 as SAMPLER desc type has no usage bit error |
| 8759 | for (uint32_t i = 1; i < VK_DESCRIPTOR_TYPE_RANGE_SIZE; ++i) { |
| 8760 | descriptor_write.descriptorType = VkDescriptorType(i); |
| 8761 | descriptor_write.dstSet = descriptor_sets[i]; |
| 8762 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 8763 | error_msgs[i]); |
| 8764 | |
| 8765 | vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, |
| 8766 | NULL); |
| 8767 | |
| 8768 | m_errorMonitor->VerifyFound(); |
| 8769 | vkDestroyDescriptorSetLayout(m_device->device(), ds_layouts[i], NULL); |
| 8770 | } |
| 8771 | vkDestroyDescriptorSetLayout(m_device->device(), ds_layouts[0], NULL); |
| 8772 | vkDestroyImage(m_device->device(), image, NULL); |
Tony Barbour | df4c004 | 2016-06-01 15:55:43 -0600 | [diff] [blame] | 8773 | vkFreeMemory(m_device->device(), image_mem, NULL); |
Tobin Ehlis | 17826bd | 2016-05-25 11:12:50 -0600 | [diff] [blame] | 8774 | vkDestroyImageView(m_device->device(), image_view, NULL); |
| 8775 | vkDestroyBuffer(m_device->device(), buffer, NULL); |
| 8776 | vkDestroyBufferView(m_device->device(), buff_view, NULL); |
| 8777 | vkFreeDescriptorSets(m_device->device(), ds_pool, |
| 8778 | VK_DESCRIPTOR_TYPE_RANGE_SIZE, descriptor_sets); |
| 8779 | vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL); |
| 8780 | } |
| 8781 | |
Tobin Ehlis | 2fc296b | 2016-06-15 14:05:27 -0600 | [diff] [blame] | 8782 | TEST_F(VkLayerTest, DSAspectBitsErrors) { |
| 8783 | // TODO : Initially only catching case where DEPTH & STENCIL aspect bits |
| 8784 | // are set, but could expand this test to hit more cases. |
| 8785 | TEST_DESCRIPTION("Attempt to update descriptor sets for images " |
| 8786 | "that do not have correct aspect bits sets."); |
| 8787 | VkResult err; |
| 8788 | |
| 8789 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 8790 | VkDescriptorPoolSize ds_type_count = {}; |
| 8791 | ds_type_count.type = VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT; |
| 8792 | ds_type_count.descriptorCount = 1; |
| 8793 | |
| 8794 | VkDescriptorPoolCreateInfo ds_pool_ci = {}; |
| 8795 | ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO; |
| 8796 | ds_pool_ci.pNext = NULL; |
| 8797 | ds_pool_ci.maxSets = 5; |
| 8798 | ds_pool_ci.poolSizeCount = 1; |
| 8799 | ds_pool_ci.pPoolSizes = &ds_type_count; |
| 8800 | |
| 8801 | VkDescriptorPool ds_pool; |
| 8802 | err = |
| 8803 | vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool); |
| 8804 | ASSERT_VK_SUCCESS(err); |
| 8805 | |
| 8806 | VkDescriptorSetLayoutBinding dsl_binding = {}; |
| 8807 | dsl_binding.binding = 0; |
| 8808 | dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT; |
| 8809 | dsl_binding.descriptorCount = 1; |
| 8810 | dsl_binding.stageFlags = VK_SHADER_STAGE_ALL; |
| 8811 | dsl_binding.pImmutableSamplers = NULL; |
| 8812 | |
| 8813 | VkDescriptorSetLayoutCreateInfo ds_layout_ci = {}; |
| 8814 | ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO; |
| 8815 | ds_layout_ci.pNext = NULL; |
| 8816 | ds_layout_ci.bindingCount = 1; |
| 8817 | ds_layout_ci.pBindings = &dsl_binding; |
| 8818 | VkDescriptorSetLayout ds_layout; |
| 8819 | err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, |
| 8820 | &ds_layout); |
| 8821 | ASSERT_VK_SUCCESS(err); |
| 8822 | |
| 8823 | VkDescriptorSet descriptor_set = {}; |
| 8824 | VkDescriptorSetAllocateInfo alloc_info = {}; |
| 8825 | alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO; |
| 8826 | alloc_info.descriptorSetCount = 1; |
| 8827 | alloc_info.descriptorPool = ds_pool; |
| 8828 | alloc_info.pSetLayouts = &ds_layout; |
| 8829 | err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, |
| 8830 | &descriptor_set); |
| 8831 | ASSERT_VK_SUCCESS(err); |
| 8832 | |
| 8833 | // Create an image to be used for invalid updates |
| 8834 | VkImageCreateInfo image_ci = {}; |
| 8835 | image_ci.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO; |
| 8836 | image_ci.imageType = VK_IMAGE_TYPE_2D; |
| 8837 | image_ci.format = VK_FORMAT_D24_UNORM_S8_UINT; |
| 8838 | image_ci.extent.width = 64; |
| 8839 | image_ci.extent.height = 64; |
| 8840 | image_ci.extent.depth = 1; |
| 8841 | image_ci.mipLevels = 1; |
| 8842 | image_ci.arrayLayers = 1; |
| 8843 | image_ci.samples = VK_SAMPLE_COUNT_1_BIT; |
| 8844 | image_ci.tiling = VK_IMAGE_TILING_LINEAR; |
| 8845 | image_ci.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED; |
| 8846 | image_ci.usage = VK_IMAGE_USAGE_SAMPLED_BIT; |
| 8847 | image_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE; |
| 8848 | VkImage image; |
| 8849 | err = vkCreateImage(m_device->device(), &image_ci, NULL, &image); |
| 8850 | ASSERT_VK_SUCCESS(err); |
| 8851 | // Bind memory to image |
| 8852 | VkMemoryRequirements mem_reqs; |
| 8853 | VkDeviceMemory image_mem; |
| 8854 | bool pass; |
| 8855 | VkMemoryAllocateInfo mem_alloc = {}; |
| 8856 | mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO; |
| 8857 | mem_alloc.pNext = NULL; |
| 8858 | mem_alloc.allocationSize = 0; |
| 8859 | mem_alloc.memoryTypeIndex = 0; |
| 8860 | vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs); |
| 8861 | mem_alloc.allocationSize = mem_reqs.size; |
| 8862 | pass = |
| 8863 | m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0); |
| 8864 | ASSERT_TRUE(pass); |
| 8865 | err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &image_mem); |
| 8866 | ASSERT_VK_SUCCESS(err); |
| 8867 | err = vkBindImageMemory(m_device->device(), image, image_mem, 0); |
| 8868 | ASSERT_VK_SUCCESS(err); |
| 8869 | // Now create view for image |
| 8870 | VkImageViewCreateInfo image_view_ci = {}; |
| 8871 | image_view_ci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO; |
| 8872 | image_view_ci.image = image; |
| 8873 | image_view_ci.format = VK_FORMAT_D24_UNORM_S8_UINT; |
| 8874 | image_view_ci.viewType = VK_IMAGE_VIEW_TYPE_2D; |
| 8875 | image_view_ci.subresourceRange.layerCount = 1; |
| 8876 | image_view_ci.subresourceRange.baseArrayLayer = 0; |
| 8877 | image_view_ci.subresourceRange.levelCount = 1; |
| 8878 | // Setting both depth & stencil aspect bits is illegal for descriptor |
| 8879 | image_view_ci.subresourceRange.aspectMask = |
| 8880 | VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT; |
| 8881 | |
| 8882 | VkImageView image_view; |
| 8883 | err = vkCreateImageView(m_device->device(), &image_view_ci, NULL, |
| 8884 | &image_view); |
| 8885 | ASSERT_VK_SUCCESS(err); |
| 8886 | |
| 8887 | VkDescriptorImageInfo img_info = {}; |
| 8888 | img_info.imageView = image_view; |
| 8889 | VkWriteDescriptorSet descriptor_write = {}; |
| 8890 | descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET; |
| 8891 | descriptor_write.dstBinding = 0; |
| 8892 | descriptor_write.descriptorCount = 1; |
| 8893 | descriptor_write.pTexelBufferView = NULL; |
| 8894 | descriptor_write.pBufferInfo = NULL; |
| 8895 | descriptor_write.pImageInfo = &img_info; |
| 8896 | descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT; |
| 8897 | descriptor_write.dstSet = descriptor_set; |
| 8898 | const char *error_msg = " please only set either VK_IMAGE_ASPECT_DEPTH_BIT " |
| 8899 | "or VK_IMAGE_ASPECT_STENCIL_BIT "; |
| 8900 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 8901 | error_msg); |
| 8902 | |
| 8903 | vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL); |
| 8904 | |
| 8905 | m_errorMonitor->VerifyFound(); |
| 8906 | vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL); |
| 8907 | vkDestroyImage(m_device->device(), image, NULL); |
| 8908 | vkFreeMemory(m_device->device(), image_mem, NULL); |
| 8909 | vkDestroyImageView(m_device->device(), image_view, NULL); |
| 8910 | vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptor_set); |
| 8911 | vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL); |
| 8912 | } |
| 8913 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8914 | TEST_F(VkLayerTest, DSTypeMismatch) { |
Tobin Ehlis | 49eb23d | 2015-05-22 12:38:55 -0600 | [diff] [blame] | 8915 | // 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] | 8916 | VkResult err; |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 8917 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8918 | m_errorMonitor->SetDesiredFailureMsg( |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 8919 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 8920 | " binding #0 with type VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER but update " |
| 8921 | "type is VK_DESCRIPTOR_TYPE_SAMPLER"); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 8922 | |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 8923 | ASSERT_NO_FATAL_FAILURE(InitState()); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8924 | // VkDescriptorSetObj descriptorSet(m_device); |
Chia-I Wu | 1b99bb2 | 2015-10-27 19:25:11 +0800 | [diff] [blame] | 8925 | VkDescriptorPoolSize ds_type_count = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8926 | ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 8927 | ds_type_count.descriptorCount = 1; |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 8928 | |
| 8929 | VkDescriptorPoolCreateInfo ds_pool_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8930 | ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO; |
| 8931 | ds_pool_ci.pNext = NULL; |
| 8932 | ds_pool_ci.maxSets = 1; |
| 8933 | ds_pool_ci.poolSizeCount = 1; |
| 8934 | ds_pool_ci.pPoolSizes = &ds_type_count; |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 8935 | |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 8936 | VkDescriptorPool ds_pool; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8937 | err = |
| 8938 | vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool); |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 8939 | ASSERT_VK_SUCCESS(err); |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 8940 | VkDescriptorSetLayoutBinding dsl_binding = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8941 | dsl_binding.binding = 0; |
| 8942 | dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 8943 | dsl_binding.descriptorCount = 1; |
| 8944 | dsl_binding.stageFlags = VK_SHADER_STAGE_ALL; |
| 8945 | dsl_binding.pImmutableSamplers = NULL; |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 8946 | |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 8947 | VkDescriptorSetLayoutCreateInfo ds_layout_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8948 | ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO; |
| 8949 | ds_layout_ci.pNext = NULL; |
| 8950 | ds_layout_ci.bindingCount = 1; |
| 8951 | ds_layout_ci.pBindings = &dsl_binding; |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 8952 | |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 8953 | VkDescriptorSetLayout ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8954 | err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, |
| 8955 | &ds_layout); |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 8956 | ASSERT_VK_SUCCESS(err); |
| 8957 | |
| 8958 | VkDescriptorSet descriptorSet; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 8959 | VkDescriptorSetAllocateInfo alloc_info = {}; |
Chia-I Wu | 00ce540 | 2015-11-10 16:21:09 +0800 | [diff] [blame] | 8960 | alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO; |
Jon Ashburn | f19916e | 2016-01-11 13:12:43 -0700 | [diff] [blame] | 8961 | alloc_info.descriptorSetCount = 1; |
Courtney Goeltzenleuchter | bee18a9 | 2015-10-23 14:21:05 -0600 | [diff] [blame] | 8962 | alloc_info.descriptorPool = ds_pool; |
| 8963 | alloc_info.pSetLayouts = &ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8964 | err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, |
| 8965 | &descriptorSet); |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 8966 | ASSERT_VK_SUCCESS(err); |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 8967 | |
Tobin Ehlis | 30db8f8 | 2016-05-05 08:19:48 -0600 | [diff] [blame] | 8968 | VkSamplerCreateInfo sampler_ci = {}; |
| 8969 | sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO; |
| 8970 | sampler_ci.pNext = NULL; |
| 8971 | sampler_ci.magFilter = VK_FILTER_NEAREST; |
| 8972 | sampler_ci.minFilter = VK_FILTER_NEAREST; |
| 8973 | sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST; |
| 8974 | sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE; |
| 8975 | sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE; |
| 8976 | sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE; |
| 8977 | sampler_ci.mipLodBias = 1.0; |
| 8978 | sampler_ci.anisotropyEnable = VK_FALSE; |
| 8979 | sampler_ci.maxAnisotropy = 1; |
| 8980 | sampler_ci.compareEnable = VK_FALSE; |
| 8981 | sampler_ci.compareOp = VK_COMPARE_OP_NEVER; |
| 8982 | sampler_ci.minLod = 1.0; |
| 8983 | sampler_ci.maxLod = 1.0; |
| 8984 | sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE; |
| 8985 | sampler_ci.unnormalizedCoordinates = VK_FALSE; |
| 8986 | VkSampler sampler; |
| 8987 | err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler); |
| 8988 | ASSERT_VK_SUCCESS(err); |
| 8989 | |
| 8990 | VkDescriptorImageInfo info = {}; |
| 8991 | info.sampler = sampler; |
Chia-I Wu | 9d00ed7 | 2015-05-25 16:27:55 +0800 | [diff] [blame] | 8992 | |
| 8993 | VkWriteDescriptorSet descriptor_write; |
| 8994 | memset(&descriptor_write, 0, sizeof(descriptor_write)); |
| 8995 | descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 8996 | descriptor_write.dstSet = descriptorSet; |
Chia-I Wu | d50a7d7 | 2015-10-26 20:48:51 +0800 | [diff] [blame] | 8997 | descriptor_write.descriptorCount = 1; |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 8998 | // This is a mismatched type for the layout which expects BUFFER |
Chia-I Wu | 9d00ed7 | 2015-05-25 16:27:55 +0800 | [diff] [blame] | 8999 | descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER; |
Courtney Goeltzenleuchter | 4cb6d92 | 2015-10-23 13:38:14 -0600 | [diff] [blame] | 9000 | descriptor_write.pImageInfo = &info; |
Chia-I Wu | 9d00ed7 | 2015-05-25 16:27:55 +0800 | [diff] [blame] | 9001 | |
| 9002 | vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL); |
| 9003 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 9004 | m_errorMonitor->VerifyFound(); |
Mike Stroyan | d1c84a5 | 2015-08-18 14:40:24 -0600 | [diff] [blame] | 9005 | |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 9006 | vkDestroySampler(m_device->device(), sampler, NULL); |
| 9007 | vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL); |
| 9008 | vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL); |
Tobin Ehlis | 49eb23d | 2015-05-22 12:38:55 -0600 | [diff] [blame] | 9009 | } |
| 9010 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9011 | TEST_F(VkLayerTest, DSUpdateOutOfBounds) { |
Tobin Ehlis | 49eb23d | 2015-05-22 12:38:55 -0600 | [diff] [blame] | 9012 | // For overlapping Update, have arrayIndex exceed that of layout |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9013 | VkResult err; |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 9014 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9015 | m_errorMonitor->SetDesiredFailureMsg( |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 9016 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 9017 | " binding #0 with 1 total descriptors but update of 1 descriptors " |
| 9018 | "starting at binding offset of 0 combined with update array element " |
| 9019 | "offset of 1 oversteps the size of this descriptor set."); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 9020 | |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 9021 | ASSERT_NO_FATAL_FAILURE(InitState()); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9022 | // VkDescriptorSetObj descriptorSet(m_device); |
Chia-I Wu | 1b99bb2 | 2015-10-27 19:25:11 +0800 | [diff] [blame] | 9023 | VkDescriptorPoolSize ds_type_count = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9024 | ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 9025 | ds_type_count.descriptorCount = 1; |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 9026 | |
| 9027 | VkDescriptorPoolCreateInfo ds_pool_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9028 | ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO; |
| 9029 | ds_pool_ci.pNext = NULL; |
| 9030 | ds_pool_ci.maxSets = 1; |
| 9031 | ds_pool_ci.poolSizeCount = 1; |
| 9032 | ds_pool_ci.pPoolSizes = &ds_type_count; |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 9033 | |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 9034 | VkDescriptorPool ds_pool; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9035 | err = |
| 9036 | vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool); |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 9037 | ASSERT_VK_SUCCESS(err); |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 9038 | |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 9039 | VkDescriptorSetLayoutBinding dsl_binding = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9040 | dsl_binding.binding = 0; |
| 9041 | dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 9042 | dsl_binding.descriptorCount = 1; |
| 9043 | dsl_binding.stageFlags = VK_SHADER_STAGE_ALL; |
| 9044 | dsl_binding.pImmutableSamplers = NULL; |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 9045 | |
| 9046 | VkDescriptorSetLayoutCreateInfo ds_layout_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9047 | ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO; |
| 9048 | ds_layout_ci.pNext = NULL; |
| 9049 | ds_layout_ci.bindingCount = 1; |
| 9050 | ds_layout_ci.pBindings = &dsl_binding; |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 9051 | |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 9052 | VkDescriptorSetLayout ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9053 | err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, |
| 9054 | &ds_layout); |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 9055 | ASSERT_VK_SUCCESS(err); |
| 9056 | |
| 9057 | VkDescriptorSet descriptorSet; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 9058 | VkDescriptorSetAllocateInfo alloc_info = {}; |
Chia-I Wu | 00ce540 | 2015-11-10 16:21:09 +0800 | [diff] [blame] | 9059 | alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO; |
Jon Ashburn | f19916e | 2016-01-11 13:12:43 -0700 | [diff] [blame] | 9060 | alloc_info.descriptorSetCount = 1; |
Courtney Goeltzenleuchter | bee18a9 | 2015-10-23 14:21:05 -0600 | [diff] [blame] | 9061 | alloc_info.descriptorPool = ds_pool; |
| 9062 | alloc_info.pSetLayouts = &ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9063 | err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, |
| 9064 | &descriptorSet); |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 9065 | ASSERT_VK_SUCCESS(err); |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 9066 | |
Tobin Ehlis | 30db8f8 | 2016-05-05 08:19:48 -0600 | [diff] [blame] | 9067 | // Correctly update descriptor to avoid "NOT_UPDATED" error |
| 9068 | VkDescriptorBufferInfo buff_info = {}; |
| 9069 | buff_info.buffer = |
| 9070 | VkBuffer(0); // Don't care about buffer handle for this test |
| 9071 | buff_info.offset = 0; |
| 9072 | buff_info.range = 1024; |
Chia-I Wu | 9d00ed7 | 2015-05-25 16:27:55 +0800 | [diff] [blame] | 9073 | |
| 9074 | VkWriteDescriptorSet descriptor_write; |
| 9075 | memset(&descriptor_write, 0, sizeof(descriptor_write)); |
| 9076 | descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 9077 | descriptor_write.dstSet = descriptorSet; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9078 | descriptor_write.dstArrayElement = |
| 9079 | 1; /* This index out of bounds for the update */ |
Chia-I Wu | d50a7d7 | 2015-10-26 20:48:51 +0800 | [diff] [blame] | 9080 | descriptor_write.descriptorCount = 1; |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 9081 | descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 9082 | descriptor_write.pBufferInfo = &buff_info; |
Chia-I Wu | 9d00ed7 | 2015-05-25 16:27:55 +0800 | [diff] [blame] | 9083 | |
| 9084 | vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL); |
| 9085 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 9086 | m_errorMonitor->VerifyFound(); |
Mike Stroyan | d1c84a5 | 2015-08-18 14:40:24 -0600 | [diff] [blame] | 9087 | |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 9088 | vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL); |
| 9089 | vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL); |
Tobin Ehlis | 49eb23d | 2015-05-22 12:38:55 -0600 | [diff] [blame] | 9090 | } |
| 9091 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9092 | TEST_F(VkLayerTest, InvalidDSUpdateIndex) { |
| 9093 | // Create layout w/ count of 1 and attempt update to that layout w/ binding |
| 9094 | // index 2 |
| 9095 | VkResult err; |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 9096 | |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 9097 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 9098 | " does not have binding 2."); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 9099 | |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 9100 | ASSERT_NO_FATAL_FAILURE(InitState()); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9101 | // VkDescriptorSetObj descriptorSet(m_device); |
Chia-I Wu | 1b99bb2 | 2015-10-27 19:25:11 +0800 | [diff] [blame] | 9102 | VkDescriptorPoolSize ds_type_count = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9103 | ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 9104 | ds_type_count.descriptorCount = 1; |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 9105 | |
| 9106 | VkDescriptorPoolCreateInfo ds_pool_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9107 | ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO; |
| 9108 | ds_pool_ci.pNext = NULL; |
| 9109 | ds_pool_ci.maxSets = 1; |
| 9110 | ds_pool_ci.poolSizeCount = 1; |
| 9111 | ds_pool_ci.pPoolSizes = &ds_type_count; |
Courtney Goeltzenleuchter | fe908d3 | 2015-09-16 16:12:45 -0600 | [diff] [blame] | 9112 | |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 9113 | VkDescriptorPool ds_pool; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9114 | err = |
| 9115 | vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool); |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 9116 | ASSERT_VK_SUCCESS(err); |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 9117 | |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 9118 | VkDescriptorSetLayoutBinding dsl_binding = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9119 | dsl_binding.binding = 0; |
| 9120 | dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 9121 | dsl_binding.descriptorCount = 1; |
| 9122 | dsl_binding.stageFlags = VK_SHADER_STAGE_ALL; |
| 9123 | dsl_binding.pImmutableSamplers = NULL; |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 9124 | |
| 9125 | VkDescriptorSetLayoutCreateInfo ds_layout_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9126 | ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO; |
| 9127 | ds_layout_ci.pNext = NULL; |
| 9128 | ds_layout_ci.bindingCount = 1; |
| 9129 | ds_layout_ci.pBindings = &dsl_binding; |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 9130 | VkDescriptorSetLayout ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9131 | err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, |
| 9132 | &ds_layout); |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 9133 | ASSERT_VK_SUCCESS(err); |
| 9134 | |
| 9135 | VkDescriptorSet descriptorSet; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 9136 | VkDescriptorSetAllocateInfo alloc_info = {}; |
Chia-I Wu | 00ce540 | 2015-11-10 16:21:09 +0800 | [diff] [blame] | 9137 | alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO; |
Jon Ashburn | f19916e | 2016-01-11 13:12:43 -0700 | [diff] [blame] | 9138 | alloc_info.descriptorSetCount = 1; |
Courtney Goeltzenleuchter | bee18a9 | 2015-10-23 14:21:05 -0600 | [diff] [blame] | 9139 | alloc_info.descriptorPool = ds_pool; |
| 9140 | alloc_info.pSetLayouts = &ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9141 | err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, |
| 9142 | &descriptorSet); |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 9143 | ASSERT_VK_SUCCESS(err); |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 9144 | |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 9145 | VkSamplerCreateInfo sampler_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9146 | sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO; |
| 9147 | sampler_ci.pNext = NULL; |
| 9148 | sampler_ci.magFilter = VK_FILTER_NEAREST; |
| 9149 | sampler_ci.minFilter = VK_FILTER_NEAREST; |
| 9150 | sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST; |
| 9151 | sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE; |
| 9152 | sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE; |
| 9153 | sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE; |
| 9154 | sampler_ci.mipLodBias = 1.0; |
| 9155 | sampler_ci.anisotropyEnable = VK_FALSE; |
| 9156 | sampler_ci.maxAnisotropy = 1; |
| 9157 | sampler_ci.compareEnable = VK_FALSE; |
| 9158 | sampler_ci.compareOp = VK_COMPARE_OP_NEVER; |
| 9159 | sampler_ci.minLod = 1.0; |
| 9160 | sampler_ci.maxLod = 1.0; |
| 9161 | sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE; |
| 9162 | sampler_ci.unnormalizedCoordinates = VK_FALSE; |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 9163 | |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 9164 | VkSampler sampler; |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 9165 | err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler); |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 9166 | ASSERT_VK_SUCCESS(err); |
Chia-I Wu | 9d00ed7 | 2015-05-25 16:27:55 +0800 | [diff] [blame] | 9167 | |
Courtney Goeltzenleuchter | 4cb6d92 | 2015-10-23 13:38:14 -0600 | [diff] [blame] | 9168 | VkDescriptorImageInfo info = {}; |
| 9169 | info.sampler = sampler; |
Chia-I Wu | 9d00ed7 | 2015-05-25 16:27:55 +0800 | [diff] [blame] | 9170 | |
| 9171 | VkWriteDescriptorSet descriptor_write; |
| 9172 | memset(&descriptor_write, 0, sizeof(descriptor_write)); |
| 9173 | descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 9174 | descriptor_write.dstSet = descriptorSet; |
| 9175 | descriptor_write.dstBinding = 2; |
Chia-I Wu | d50a7d7 | 2015-10-26 20:48:51 +0800 | [diff] [blame] | 9176 | descriptor_write.descriptorCount = 1; |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 9177 | // 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] | 9178 | descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER; |
Courtney Goeltzenleuchter | 4cb6d92 | 2015-10-23 13:38:14 -0600 | [diff] [blame] | 9179 | descriptor_write.pImageInfo = &info; |
Chia-I Wu | 9d00ed7 | 2015-05-25 16:27:55 +0800 | [diff] [blame] | 9180 | |
| 9181 | vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL); |
| 9182 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 9183 | m_errorMonitor->VerifyFound(); |
Mike Stroyan | d1c84a5 | 2015-08-18 14:40:24 -0600 | [diff] [blame] | 9184 | |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 9185 | vkDestroySampler(m_device->device(), sampler, NULL); |
| 9186 | vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL); |
| 9187 | vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL); |
Tobin Ehlis | 49eb23d | 2015-05-22 12:38:55 -0600 | [diff] [blame] | 9188 | } |
| 9189 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9190 | TEST_F(VkLayerTest, InvalidDSUpdateStruct) { |
| 9191 | // Call UpdateDS w/ struct type other than valid VK_STRUCTUR_TYPE_UPDATE_* |
| 9192 | // types |
| 9193 | VkResult err; |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 9194 | |
Courtney Goeltzenleuchter | 7415d5a | 2015-12-09 15:48:16 -0700 | [diff] [blame] | 9195 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Tobin Ehlis | 660bcdc | 2016-05-17 10:39:46 -0600 | [diff] [blame] | 9196 | ".sType must be VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET"); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 9197 | |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 9198 | ASSERT_NO_FATAL_FAILURE(InitState()); |
Mark Lobodzinski | 209b529 | 2015-09-17 09:44:05 -0600 | [diff] [blame] | 9199 | |
Chia-I Wu | 1b99bb2 | 2015-10-27 19:25:11 +0800 | [diff] [blame] | 9200 | VkDescriptorPoolSize ds_type_count = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9201 | ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 9202 | ds_type_count.descriptorCount = 1; |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 9203 | |
| 9204 | VkDescriptorPoolCreateInfo ds_pool_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9205 | ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO; |
| 9206 | ds_pool_ci.pNext = NULL; |
| 9207 | ds_pool_ci.maxSets = 1; |
| 9208 | ds_pool_ci.poolSizeCount = 1; |
| 9209 | ds_pool_ci.pPoolSizes = &ds_type_count; |
Courtney Goeltzenleuchter | fe908d3 | 2015-09-16 16:12:45 -0600 | [diff] [blame] | 9210 | |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 9211 | VkDescriptorPool ds_pool; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9212 | err = |
| 9213 | vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool); |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 9214 | ASSERT_VK_SUCCESS(err); |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 9215 | VkDescriptorSetLayoutBinding dsl_binding = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9216 | dsl_binding.binding = 0; |
| 9217 | dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 9218 | dsl_binding.descriptorCount = 1; |
| 9219 | dsl_binding.stageFlags = VK_SHADER_STAGE_ALL; |
| 9220 | dsl_binding.pImmutableSamplers = NULL; |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 9221 | |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 9222 | VkDescriptorSetLayoutCreateInfo ds_layout_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9223 | ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO; |
| 9224 | ds_layout_ci.pNext = NULL; |
| 9225 | ds_layout_ci.bindingCount = 1; |
| 9226 | ds_layout_ci.pBindings = &dsl_binding; |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 9227 | |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 9228 | VkDescriptorSetLayout ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9229 | err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, |
| 9230 | &ds_layout); |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 9231 | ASSERT_VK_SUCCESS(err); |
| 9232 | |
| 9233 | VkDescriptorSet descriptorSet; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 9234 | VkDescriptorSetAllocateInfo alloc_info = {}; |
Chia-I Wu | 00ce540 | 2015-11-10 16:21:09 +0800 | [diff] [blame] | 9235 | alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO; |
Jon Ashburn | f19916e | 2016-01-11 13:12:43 -0700 | [diff] [blame] | 9236 | alloc_info.descriptorSetCount = 1; |
Courtney Goeltzenleuchter | bee18a9 | 2015-10-23 14:21:05 -0600 | [diff] [blame] | 9237 | alloc_info.descriptorPool = ds_pool; |
| 9238 | alloc_info.pSetLayouts = &ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9239 | err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, |
| 9240 | &descriptorSet); |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 9241 | ASSERT_VK_SUCCESS(err); |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 9242 | |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 9243 | VkSamplerCreateInfo sampler_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9244 | sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO; |
| 9245 | sampler_ci.pNext = NULL; |
| 9246 | sampler_ci.magFilter = VK_FILTER_NEAREST; |
| 9247 | sampler_ci.minFilter = VK_FILTER_NEAREST; |
| 9248 | sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST; |
| 9249 | sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE; |
| 9250 | sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE; |
| 9251 | sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE; |
| 9252 | sampler_ci.mipLodBias = 1.0; |
| 9253 | sampler_ci.anisotropyEnable = VK_FALSE; |
| 9254 | sampler_ci.maxAnisotropy = 1; |
| 9255 | sampler_ci.compareEnable = VK_FALSE; |
| 9256 | sampler_ci.compareOp = VK_COMPARE_OP_NEVER; |
| 9257 | sampler_ci.minLod = 1.0; |
| 9258 | sampler_ci.maxLod = 1.0; |
| 9259 | sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE; |
| 9260 | sampler_ci.unnormalizedCoordinates = VK_FALSE; |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 9261 | VkSampler sampler; |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 9262 | err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler); |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 9263 | ASSERT_VK_SUCCESS(err); |
Chia-I Wu | 9d00ed7 | 2015-05-25 16:27:55 +0800 | [diff] [blame] | 9264 | |
Courtney Goeltzenleuchter | 4cb6d92 | 2015-10-23 13:38:14 -0600 | [diff] [blame] | 9265 | VkDescriptorImageInfo info = {}; |
| 9266 | info.sampler = sampler; |
Chia-I Wu | 9d00ed7 | 2015-05-25 16:27:55 +0800 | [diff] [blame] | 9267 | |
| 9268 | VkWriteDescriptorSet descriptor_write; |
| 9269 | memset(&descriptor_write, 0, sizeof(descriptor_write)); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9270 | descriptor_write.sType = |
| 9271 | (VkStructureType)0x99999999; /* Intentionally broken struct type */ |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 9272 | descriptor_write.dstSet = descriptorSet; |
Chia-I Wu | d50a7d7 | 2015-10-26 20:48:51 +0800 | [diff] [blame] | 9273 | descriptor_write.descriptorCount = 1; |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 9274 | // 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] | 9275 | descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER; |
Courtney Goeltzenleuchter | 4cb6d92 | 2015-10-23 13:38:14 -0600 | [diff] [blame] | 9276 | descriptor_write.pImageInfo = &info; |
Chia-I Wu | 9d00ed7 | 2015-05-25 16:27:55 +0800 | [diff] [blame] | 9277 | |
| 9278 | vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL); |
| 9279 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 9280 | m_errorMonitor->VerifyFound(); |
Mike Stroyan | d1c84a5 | 2015-08-18 14:40:24 -0600 | [diff] [blame] | 9281 | |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 9282 | vkDestroySampler(m_device->device(), sampler, NULL); |
| 9283 | vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL); |
| 9284 | vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL); |
Tobin Ehlis | 49eb23d | 2015-05-22 12:38:55 -0600 | [diff] [blame] | 9285 | } |
| 9286 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9287 | TEST_F(VkLayerTest, SampleDescriptorUpdateError) { |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 9288 | // Create a single Sampler descriptor and send it an invalid Sampler |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9289 | VkResult err; |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 9290 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9291 | m_errorMonitor->SetDesiredFailureMsg( |
| 9292 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 9293 | "Attempted write update to sampler descriptor with invalid sampler"); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 9294 | |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 9295 | ASSERT_NO_FATAL_FAILURE(InitState()); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9296 | // TODO : Farm Descriptor setup code to helper function(s) to reduce copied |
| 9297 | // code |
Chia-I Wu | 1b99bb2 | 2015-10-27 19:25:11 +0800 | [diff] [blame] | 9298 | VkDescriptorPoolSize ds_type_count = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9299 | ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLER; |
| 9300 | ds_type_count.descriptorCount = 1; |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 9301 | |
| 9302 | VkDescriptorPoolCreateInfo ds_pool_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9303 | ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO; |
| 9304 | ds_pool_ci.pNext = NULL; |
| 9305 | ds_pool_ci.maxSets = 1; |
| 9306 | ds_pool_ci.poolSizeCount = 1; |
| 9307 | ds_pool_ci.pPoolSizes = &ds_type_count; |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 9308 | |
| 9309 | VkDescriptorPool ds_pool; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9310 | err = |
| 9311 | vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool); |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 9312 | ASSERT_VK_SUCCESS(err); |
| 9313 | |
| 9314 | VkDescriptorSetLayoutBinding dsl_binding = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9315 | dsl_binding.binding = 0; |
| 9316 | dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER; |
| 9317 | dsl_binding.descriptorCount = 1; |
| 9318 | dsl_binding.stageFlags = VK_SHADER_STAGE_ALL; |
| 9319 | dsl_binding.pImmutableSamplers = NULL; |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 9320 | |
| 9321 | VkDescriptorSetLayoutCreateInfo ds_layout_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9322 | ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO; |
| 9323 | ds_layout_ci.pNext = NULL; |
| 9324 | ds_layout_ci.bindingCount = 1; |
| 9325 | ds_layout_ci.pBindings = &dsl_binding; |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 9326 | VkDescriptorSetLayout ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9327 | err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, |
| 9328 | &ds_layout); |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 9329 | ASSERT_VK_SUCCESS(err); |
| 9330 | |
| 9331 | VkDescriptorSet descriptorSet; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 9332 | VkDescriptorSetAllocateInfo alloc_info = {}; |
Chia-I Wu | 00ce540 | 2015-11-10 16:21:09 +0800 | [diff] [blame] | 9333 | alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO; |
Jon Ashburn | f19916e | 2016-01-11 13:12:43 -0700 | [diff] [blame] | 9334 | alloc_info.descriptorSetCount = 1; |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 9335 | alloc_info.descriptorPool = ds_pool; |
| 9336 | alloc_info.pSetLayouts = &ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9337 | err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, |
| 9338 | &descriptorSet); |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 9339 | ASSERT_VK_SUCCESS(err); |
| 9340 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9341 | VkSampler sampler = |
| 9342 | (VkSampler)((size_t)0xbaadbeef); // Sampler with invalid handle |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 9343 | |
| 9344 | VkDescriptorImageInfo descriptor_info; |
| 9345 | memset(&descriptor_info, 0, sizeof(VkDescriptorImageInfo)); |
| 9346 | descriptor_info.sampler = sampler; |
| 9347 | |
| 9348 | VkWriteDescriptorSet descriptor_write; |
| 9349 | memset(&descriptor_write, 0, sizeof(descriptor_write)); |
| 9350 | descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 9351 | descriptor_write.dstSet = descriptorSet; |
| 9352 | descriptor_write.dstBinding = 0; |
Chia-I Wu | d50a7d7 | 2015-10-26 20:48:51 +0800 | [diff] [blame] | 9353 | descriptor_write.descriptorCount = 1; |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 9354 | descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER; |
| 9355 | descriptor_write.pImageInfo = &descriptor_info; |
| 9356 | |
| 9357 | vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL); |
| 9358 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 9359 | m_errorMonitor->VerifyFound(); |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 9360 | |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 9361 | vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL); |
| 9362 | vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL); |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 9363 | } |
| 9364 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9365 | TEST_F(VkLayerTest, ImageViewDescriptorUpdateError) { |
| 9366 | // Create a single combined Image/Sampler descriptor and send it an invalid |
| 9367 | // imageView |
| 9368 | VkResult err; |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 9369 | |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 9370 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 9371 | "Attempted write update to combined " |
| 9372 | "image sampler descriptor failed due " |
Tobin Ehlis | 63c4b8a | 2016-05-09 10:29:34 -0600 | [diff] [blame] | 9373 | "to: Invalid VkImageView:"); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 9374 | |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 9375 | ASSERT_NO_FATAL_FAILURE(InitState()); |
Chia-I Wu | 1b99bb2 | 2015-10-27 19:25:11 +0800 | [diff] [blame] | 9376 | VkDescriptorPoolSize ds_type_count = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9377 | ds_type_count.type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER; |
| 9378 | ds_type_count.descriptorCount = 1; |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 9379 | |
| 9380 | VkDescriptorPoolCreateInfo ds_pool_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9381 | ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO; |
| 9382 | ds_pool_ci.pNext = NULL; |
| 9383 | ds_pool_ci.maxSets = 1; |
| 9384 | ds_pool_ci.poolSizeCount = 1; |
| 9385 | ds_pool_ci.pPoolSizes = &ds_type_count; |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 9386 | |
| 9387 | VkDescriptorPool ds_pool; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9388 | err = |
| 9389 | vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool); |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 9390 | ASSERT_VK_SUCCESS(err); |
| 9391 | |
| 9392 | VkDescriptorSetLayoutBinding dsl_binding = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9393 | dsl_binding.binding = 0; |
| 9394 | dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER; |
| 9395 | dsl_binding.descriptorCount = 1; |
| 9396 | dsl_binding.stageFlags = VK_SHADER_STAGE_ALL; |
| 9397 | dsl_binding.pImmutableSamplers = NULL; |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 9398 | |
| 9399 | VkDescriptorSetLayoutCreateInfo ds_layout_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9400 | ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO; |
| 9401 | ds_layout_ci.pNext = NULL; |
| 9402 | ds_layout_ci.bindingCount = 1; |
| 9403 | ds_layout_ci.pBindings = &dsl_binding; |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 9404 | VkDescriptorSetLayout ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9405 | err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, |
| 9406 | &ds_layout); |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 9407 | ASSERT_VK_SUCCESS(err); |
| 9408 | |
| 9409 | VkDescriptorSet descriptorSet; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 9410 | VkDescriptorSetAllocateInfo alloc_info = {}; |
Chia-I Wu | 00ce540 | 2015-11-10 16:21:09 +0800 | [diff] [blame] | 9411 | alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO; |
Jon Ashburn | f19916e | 2016-01-11 13:12:43 -0700 | [diff] [blame] | 9412 | alloc_info.descriptorSetCount = 1; |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 9413 | alloc_info.descriptorPool = ds_pool; |
| 9414 | alloc_info.pSetLayouts = &ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9415 | err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, |
| 9416 | &descriptorSet); |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 9417 | ASSERT_VK_SUCCESS(err); |
| 9418 | |
| 9419 | VkSamplerCreateInfo sampler_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9420 | sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO; |
| 9421 | sampler_ci.pNext = NULL; |
| 9422 | sampler_ci.magFilter = VK_FILTER_NEAREST; |
| 9423 | sampler_ci.minFilter = VK_FILTER_NEAREST; |
| 9424 | sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST; |
| 9425 | sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE; |
| 9426 | sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE; |
| 9427 | sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE; |
| 9428 | sampler_ci.mipLodBias = 1.0; |
| 9429 | sampler_ci.anisotropyEnable = VK_FALSE; |
| 9430 | sampler_ci.maxAnisotropy = 1; |
| 9431 | sampler_ci.compareEnable = VK_FALSE; |
| 9432 | sampler_ci.compareOp = VK_COMPARE_OP_NEVER; |
| 9433 | sampler_ci.minLod = 1.0; |
| 9434 | sampler_ci.maxLod = 1.0; |
| 9435 | sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE; |
| 9436 | sampler_ci.unnormalizedCoordinates = VK_FALSE; |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 9437 | |
| 9438 | VkSampler sampler; |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 9439 | err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler); |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 9440 | ASSERT_VK_SUCCESS(err); |
| 9441 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9442 | VkImageView view = |
| 9443 | (VkImageView)((size_t)0xbaadbeef); // invalid imageView object |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 9444 | |
| 9445 | VkDescriptorImageInfo descriptor_info; |
| 9446 | memset(&descriptor_info, 0, sizeof(VkDescriptorImageInfo)); |
| 9447 | descriptor_info.sampler = sampler; |
| 9448 | descriptor_info.imageView = view; |
| 9449 | |
| 9450 | VkWriteDescriptorSet descriptor_write; |
| 9451 | memset(&descriptor_write, 0, sizeof(descriptor_write)); |
| 9452 | descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 9453 | descriptor_write.dstSet = descriptorSet; |
| 9454 | descriptor_write.dstBinding = 0; |
Chia-I Wu | d50a7d7 | 2015-10-26 20:48:51 +0800 | [diff] [blame] | 9455 | descriptor_write.descriptorCount = 1; |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 9456 | descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER; |
| 9457 | descriptor_write.pImageInfo = &descriptor_info; |
| 9458 | |
| 9459 | vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL); |
| 9460 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 9461 | m_errorMonitor->VerifyFound(); |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 9462 | |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 9463 | vkDestroySampler(m_device->device(), sampler, NULL); |
| 9464 | vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL); |
| 9465 | vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL); |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 9466 | } |
| 9467 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9468 | TEST_F(VkLayerTest, CopyDescriptorUpdateErrors) { |
| 9469 | // Create DS w/ layout of 2 types, write update 1 and attempt to copy-update |
| 9470 | // into the other |
| 9471 | VkResult err; |
Tobin Ehlis | 04356f9 | 2015-10-27 16:35:27 -0600 | [diff] [blame] | 9472 | |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 9473 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 9474 | " binding #1 with type " |
| 9475 | "VK_DESCRIPTOR_TYPE_SAMPLER. Types do " |
| 9476 | "not match."); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 9477 | |
Tobin Ehlis | 04356f9 | 2015-10-27 16:35:27 -0600 | [diff] [blame] | 9478 | ASSERT_NO_FATAL_FAILURE(InitState()); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9479 | // VkDescriptorSetObj descriptorSet(m_device); |
Chia-I Wu | 1b99bb2 | 2015-10-27 19:25:11 +0800 | [diff] [blame] | 9480 | VkDescriptorPoolSize ds_type_count[2] = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9481 | ds_type_count[0].type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 9482 | ds_type_count[0].descriptorCount = 1; |
| 9483 | ds_type_count[1].type = VK_DESCRIPTOR_TYPE_SAMPLER; |
| 9484 | ds_type_count[1].descriptorCount = 1; |
Tobin Ehlis | 04356f9 | 2015-10-27 16:35:27 -0600 | [diff] [blame] | 9485 | |
| 9486 | VkDescriptorPoolCreateInfo ds_pool_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9487 | ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO; |
| 9488 | ds_pool_ci.pNext = NULL; |
| 9489 | ds_pool_ci.maxSets = 1; |
| 9490 | ds_pool_ci.poolSizeCount = 2; |
| 9491 | ds_pool_ci.pPoolSizes = ds_type_count; |
Tobin Ehlis | 04356f9 | 2015-10-27 16:35:27 -0600 | [diff] [blame] | 9492 | |
| 9493 | VkDescriptorPool ds_pool; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9494 | err = |
| 9495 | vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool); |
Tobin Ehlis | 04356f9 | 2015-10-27 16:35:27 -0600 | [diff] [blame] | 9496 | ASSERT_VK_SUCCESS(err); |
| 9497 | VkDescriptorSetLayoutBinding dsl_binding[2] = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9498 | dsl_binding[0].binding = 0; |
| 9499 | dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 9500 | dsl_binding[0].descriptorCount = 1; |
| 9501 | dsl_binding[0].stageFlags = VK_SHADER_STAGE_ALL; |
| 9502 | dsl_binding[0].pImmutableSamplers = NULL; |
| 9503 | dsl_binding[1].binding = 1; |
| 9504 | dsl_binding[1].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER; |
| 9505 | dsl_binding[1].descriptorCount = 1; |
| 9506 | dsl_binding[1].stageFlags = VK_SHADER_STAGE_ALL; |
| 9507 | dsl_binding[1].pImmutableSamplers = NULL; |
Tobin Ehlis | 04356f9 | 2015-10-27 16:35:27 -0600 | [diff] [blame] | 9508 | |
| 9509 | VkDescriptorSetLayoutCreateInfo ds_layout_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9510 | ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO; |
| 9511 | ds_layout_ci.pNext = NULL; |
| 9512 | ds_layout_ci.bindingCount = 2; |
| 9513 | ds_layout_ci.pBindings = dsl_binding; |
Tobin Ehlis | 04356f9 | 2015-10-27 16:35:27 -0600 | [diff] [blame] | 9514 | |
| 9515 | VkDescriptorSetLayout ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9516 | err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, |
| 9517 | &ds_layout); |
Tobin Ehlis | 04356f9 | 2015-10-27 16:35:27 -0600 | [diff] [blame] | 9518 | ASSERT_VK_SUCCESS(err); |
| 9519 | |
| 9520 | VkDescriptorSet descriptorSet; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 9521 | VkDescriptorSetAllocateInfo alloc_info = {}; |
Chia-I Wu | 00ce540 | 2015-11-10 16:21:09 +0800 | [diff] [blame] | 9522 | alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO; |
Jon Ashburn | f19916e | 2016-01-11 13:12:43 -0700 | [diff] [blame] | 9523 | alloc_info.descriptorSetCount = 1; |
Tobin Ehlis | 04356f9 | 2015-10-27 16:35:27 -0600 | [diff] [blame] | 9524 | alloc_info.descriptorPool = ds_pool; |
| 9525 | alloc_info.pSetLayouts = &ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9526 | err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, |
| 9527 | &descriptorSet); |
Tobin Ehlis | 04356f9 | 2015-10-27 16:35:27 -0600 | [diff] [blame] | 9528 | ASSERT_VK_SUCCESS(err); |
| 9529 | |
| 9530 | VkSamplerCreateInfo sampler_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9531 | sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO; |
| 9532 | sampler_ci.pNext = NULL; |
| 9533 | sampler_ci.magFilter = VK_FILTER_NEAREST; |
| 9534 | sampler_ci.minFilter = VK_FILTER_NEAREST; |
| 9535 | sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST; |
| 9536 | sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE; |
| 9537 | sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE; |
| 9538 | sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE; |
| 9539 | sampler_ci.mipLodBias = 1.0; |
| 9540 | sampler_ci.anisotropyEnable = VK_FALSE; |
| 9541 | sampler_ci.maxAnisotropy = 1; |
| 9542 | sampler_ci.compareEnable = VK_FALSE; |
| 9543 | sampler_ci.compareOp = VK_COMPARE_OP_NEVER; |
| 9544 | sampler_ci.minLod = 1.0; |
| 9545 | sampler_ci.maxLod = 1.0; |
| 9546 | sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE; |
| 9547 | sampler_ci.unnormalizedCoordinates = VK_FALSE; |
Tobin Ehlis | 04356f9 | 2015-10-27 16:35:27 -0600 | [diff] [blame] | 9548 | |
| 9549 | VkSampler sampler; |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 9550 | err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler); |
Tobin Ehlis | 04356f9 | 2015-10-27 16:35:27 -0600 | [diff] [blame] | 9551 | ASSERT_VK_SUCCESS(err); |
| 9552 | |
| 9553 | VkDescriptorImageInfo info = {}; |
| 9554 | info.sampler = sampler; |
| 9555 | |
| 9556 | VkWriteDescriptorSet descriptor_write; |
| 9557 | memset(&descriptor_write, 0, sizeof(VkWriteDescriptorSet)); |
| 9558 | descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 9559 | descriptor_write.dstSet = descriptorSet; |
| 9560 | descriptor_write.dstBinding = 1; // SAMPLER binding from layout above |
Chia-I Wu | d50a7d7 | 2015-10-26 20:48:51 +0800 | [diff] [blame] | 9561 | descriptor_write.descriptorCount = 1; |
Tobin Ehlis | 04356f9 | 2015-10-27 16:35:27 -0600 | [diff] [blame] | 9562 | descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER; |
| 9563 | descriptor_write.pImageInfo = &info; |
| 9564 | // This write update should succeed |
| 9565 | vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL); |
| 9566 | // Now perform a copy update that fails due to type mismatch |
| 9567 | VkCopyDescriptorSet copy_ds_update; |
| 9568 | memset(©_ds_update, 0, sizeof(VkCopyDescriptorSet)); |
| 9569 | copy_ds_update.sType = VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET; |
| 9570 | copy_ds_update.srcSet = descriptorSet; |
Mark Young | 2992748 | 2016-05-04 14:38:51 -0600 | [diff] [blame] | 9571 | copy_ds_update.srcBinding = 1; // Copy from SAMPLER binding |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 9572 | copy_ds_update.dstSet = descriptorSet; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9573 | copy_ds_update.dstBinding = 0; // ERROR : copy to UNIFORM binding |
Chia-I Wu | d50a7d7 | 2015-10-26 20:48:51 +0800 | [diff] [blame] | 9574 | copy_ds_update.descriptorCount = 1; // copy 1 descriptor |
Tobin Ehlis | 04356f9 | 2015-10-27 16:35:27 -0600 | [diff] [blame] | 9575 | vkUpdateDescriptorSets(m_device->device(), 0, NULL, 1, ©_ds_update); |
| 9576 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 9577 | m_errorMonitor->VerifyFound(); |
Tobin Ehlis | 04356f9 | 2015-10-27 16:35:27 -0600 | [diff] [blame] | 9578 | // 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] | 9579 | m_errorMonitor->SetDesiredFailureMsg( |
| 9580 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 9581 | " does not have copy update src binding of 3."); |
Tobin Ehlis | 04356f9 | 2015-10-27 16:35:27 -0600 | [diff] [blame] | 9582 | memset(©_ds_update, 0, sizeof(VkCopyDescriptorSet)); |
| 9583 | copy_ds_update.sType = VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET; |
| 9584 | copy_ds_update.srcSet = descriptorSet; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9585 | copy_ds_update.srcBinding = |
| 9586 | 3; // ERROR : Invalid binding for matching layout |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 9587 | copy_ds_update.dstSet = descriptorSet; |
| 9588 | copy_ds_update.dstBinding = 0; |
Mark Young | 2992748 | 2016-05-04 14:38:51 -0600 | [diff] [blame] | 9589 | copy_ds_update.descriptorCount = 1; // Copy 1 descriptor |
Tobin Ehlis | 04356f9 | 2015-10-27 16:35:27 -0600 | [diff] [blame] | 9590 | vkUpdateDescriptorSets(m_device->device(), 0, NULL, 1, ©_ds_update); |
| 9591 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 9592 | m_errorMonitor->VerifyFound(); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 9593 | |
Tobin Ehlis | 04356f9 | 2015-10-27 16:35:27 -0600 | [diff] [blame] | 9594 | // 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] | 9595 | m_errorMonitor->SetDesiredFailureMsg( |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 9596 | VK_DEBUG_REPORT_ERROR_BIT_EXT, " binding#1 with offset index of 1 plus " |
| 9597 | "update array offset of 0 and update of " |
| 9598 | "5 descriptors oversteps total number " |
| 9599 | "of descriptors in set: 2."); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 9600 | |
Tobin Ehlis | 04356f9 | 2015-10-27 16:35:27 -0600 | [diff] [blame] | 9601 | memset(©_ds_update, 0, sizeof(VkCopyDescriptorSet)); |
| 9602 | copy_ds_update.sType = VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET; |
| 9603 | copy_ds_update.srcSet = descriptorSet; |
| 9604 | copy_ds_update.srcBinding = 1; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 9605 | copy_ds_update.dstSet = descriptorSet; |
| 9606 | copy_ds_update.dstBinding = 0; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9607 | copy_ds_update.descriptorCount = |
| 9608 | 5; // ERROR copy 5 descriptors (out of bounds for layout) |
Tobin Ehlis | 04356f9 | 2015-10-27 16:35:27 -0600 | [diff] [blame] | 9609 | vkUpdateDescriptorSets(m_device->device(), 0, NULL, 1, ©_ds_update); |
| 9610 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 9611 | m_errorMonitor->VerifyFound(); |
Tobin Ehlis | 04356f9 | 2015-10-27 16:35:27 -0600 | [diff] [blame] | 9612 | |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 9613 | vkDestroySampler(m_device->device(), sampler, NULL); |
| 9614 | vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL); |
| 9615 | vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL); |
Tobin Ehlis | 04356f9 | 2015-10-27 16:35:27 -0600 | [diff] [blame] | 9616 | } |
| 9617 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9618 | TEST_F(VkLayerTest, NumSamplesMismatch) { |
| 9619 | // Create CommandBuffer where MSAA samples doesn't match RenderPass |
| 9620 | // sampleCount |
| 9621 | VkResult err; |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 9622 | |
Courtney Goeltzenleuchter | 7415d5a | 2015-12-09 15:48:16 -0700 | [diff] [blame] | 9623 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9624 | "Num samples mismatch! "); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 9625 | |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 9626 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 9627 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
Chia-I Wu | 1b99bb2 | 2015-10-27 19:25:11 +0800 | [diff] [blame] | 9628 | VkDescriptorPoolSize ds_type_count = {}; |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 9629 | ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
Chia-I Wu | d50a7d7 | 2015-10-26 20:48:51 +0800 | [diff] [blame] | 9630 | ds_type_count.descriptorCount = 1; |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 9631 | |
| 9632 | VkDescriptorPoolCreateInfo ds_pool_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9633 | ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO; |
| 9634 | ds_pool_ci.pNext = NULL; |
| 9635 | ds_pool_ci.maxSets = 1; |
| 9636 | ds_pool_ci.poolSizeCount = 1; |
| 9637 | ds_pool_ci.pPoolSizes = &ds_type_count; |
Courtney Goeltzenleuchter | fe908d3 | 2015-09-16 16:12:45 -0600 | [diff] [blame] | 9638 | |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 9639 | VkDescriptorPool ds_pool; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9640 | err = |
| 9641 | vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool); |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 9642 | ASSERT_VK_SUCCESS(err); |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 9643 | |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 9644 | VkDescriptorSetLayoutBinding dsl_binding = {}; |
Chia-I Wu | d46e6ae | 2015-10-31 00:31:16 +0800 | [diff] [blame] | 9645 | dsl_binding.binding = 0; |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 9646 | dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
Chia-I Wu | 0212448 | 2015-11-06 06:42:02 +0800 | [diff] [blame] | 9647 | dsl_binding.descriptorCount = 1; |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 9648 | dsl_binding.stageFlags = VK_SHADER_STAGE_ALL; |
| 9649 | dsl_binding.pImmutableSamplers = NULL; |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 9650 | |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 9651 | VkDescriptorSetLayoutCreateInfo ds_layout_ci = {}; |
| 9652 | ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO; |
| 9653 | ds_layout_ci.pNext = NULL; |
Chia-I Wu | d50a7d7 | 2015-10-26 20:48:51 +0800 | [diff] [blame] | 9654 | ds_layout_ci.bindingCount = 1; |
Jon Ashburn | 6e23c1f | 2015-12-30 18:01:16 -0700 | [diff] [blame] | 9655 | ds_layout_ci.pBindings = &dsl_binding; |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 9656 | |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 9657 | VkDescriptorSetLayout ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9658 | err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, |
| 9659 | &ds_layout); |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 9660 | ASSERT_VK_SUCCESS(err); |
| 9661 | |
| 9662 | VkDescriptorSet descriptorSet; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 9663 | VkDescriptorSetAllocateInfo alloc_info = {}; |
Chia-I Wu | 00ce540 | 2015-11-10 16:21:09 +0800 | [diff] [blame] | 9664 | alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO; |
Jon Ashburn | f19916e | 2016-01-11 13:12:43 -0700 | [diff] [blame] | 9665 | alloc_info.descriptorSetCount = 1; |
Courtney Goeltzenleuchter | bee18a9 | 2015-10-23 14:21:05 -0600 | [diff] [blame] | 9666 | alloc_info.descriptorPool = ds_pool; |
| 9667 | alloc_info.pSetLayouts = &ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9668 | err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, |
| 9669 | &descriptorSet); |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 9670 | ASSERT_VK_SUCCESS(err); |
| 9671 | |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 9672 | VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9673 | pipe_ms_state_ci.sType = |
| 9674 | VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO; |
| 9675 | pipe_ms_state_ci.pNext = NULL; |
| 9676 | pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_4_BIT; |
| 9677 | pipe_ms_state_ci.sampleShadingEnable = 0; |
| 9678 | pipe_ms_state_ci.minSampleShading = 1.0; |
| 9679 | pipe_ms_state_ci.pSampleMask = NULL; |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 9680 | |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 9681 | VkPipelineLayoutCreateInfo pipeline_layout_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9682 | pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO; |
| 9683 | pipeline_layout_ci.pNext = NULL; |
| 9684 | pipeline_layout_ci.setLayoutCount = 1; |
| 9685 | pipeline_layout_ci.pSetLayouts = &ds_layout; |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 9686 | |
| 9687 | VkPipelineLayout pipeline_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9688 | err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, |
| 9689 | &pipeline_layout); |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 9690 | ASSERT_VK_SUCCESS(err); |
| 9691 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9692 | VkShaderObj vs(m_device, bindStateVertShaderText, |
| 9693 | VK_SHADER_STAGE_VERTEX_BIT, this); |
| 9694 | VkShaderObj fs(m_device, bindStateFragShaderText, |
| 9695 | VK_SHADER_STAGE_FRAGMENT_BIT, |
Karl Schultz | bdb7595 | 2016-04-19 11:36:49 -0600 | [diff] [blame] | 9696 | this); // We shouldn't need a fragment shader |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9697 | // but add it to be able to run on more devices |
Tony Barbour | 62e1a5b | 2015-08-06 10:16:07 -0600 | [diff] [blame] | 9698 | VkPipelineObj pipe(m_device); |
| 9699 | pipe.AddShader(&vs); |
Tony Barbour | 1c94d37 | 2015-08-06 11:21:08 -0600 | [diff] [blame] | 9700 | pipe.AddShader(&fs); |
Mark Young | c89c631 | 2016-03-31 16:03:20 -0600 | [diff] [blame] | 9701 | pipe.AddColorAttachment(); |
Tony Barbour | 62e1a5b | 2015-08-06 10:16:07 -0600 | [diff] [blame] | 9702 | pipe.SetMSAA(&pipe_ms_state_ci); |
| 9703 | pipe.CreateVKPipeline(pipeline_layout, renderPass()); |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 9704 | |
Tony Barbour | fe3351b | 2015-07-28 10:17:20 -0600 | [diff] [blame] | 9705 | BeginCommandBuffer(); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9706 | vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), |
| 9707 | VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle()); |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 9708 | |
Mark Young | 2992748 | 2016-05-04 14:38:51 -0600 | [diff] [blame] | 9709 | // Render triangle (the error should trigger on the attempt to draw). |
| 9710 | Draw(3, 1, 0, 0); |
| 9711 | |
| 9712 | // Finalize recording of the command buffer |
| 9713 | EndCommandBuffer(); |
| 9714 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 9715 | m_errorMonitor->VerifyFound(); |
Mike Stroyan | d1c84a5 | 2015-08-18 14:40:24 -0600 | [diff] [blame] | 9716 | |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 9717 | vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL); |
| 9718 | vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL); |
| 9719 | vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL); |
Tobin Ehlis | 49eb23d | 2015-05-22 12:38:55 -0600 | [diff] [blame] | 9720 | } |
Mark Young | 2992748 | 2016-05-04 14:38:51 -0600 | [diff] [blame] | 9721 | |
Tobin Ehlis | 85aa15a | 2016-06-15 10:52:37 -0600 | [diff] [blame] | 9722 | TEST_F(VkLayerTest, RenderPassIncompatible) { |
| 9723 | TEST_DESCRIPTION("Hit RenderPass incompatible cases. " |
| 9724 | "Initial case is drawing with an active renderpass that's " |
| 9725 | "not compatible with the bound PSO's creation renderpass"); |
| 9726 | VkResult err; |
| 9727 | |
| 9728 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 9729 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 9730 | |
| 9731 | VkDescriptorSetLayoutBinding dsl_binding = {}; |
| 9732 | dsl_binding.binding = 0; |
| 9733 | dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 9734 | dsl_binding.descriptorCount = 1; |
| 9735 | dsl_binding.stageFlags = VK_SHADER_STAGE_ALL; |
| 9736 | dsl_binding.pImmutableSamplers = NULL; |
| 9737 | |
| 9738 | VkDescriptorSetLayoutCreateInfo ds_layout_ci = {}; |
| 9739 | ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO; |
| 9740 | ds_layout_ci.pNext = NULL; |
| 9741 | ds_layout_ci.bindingCount = 1; |
| 9742 | ds_layout_ci.pBindings = &dsl_binding; |
| 9743 | |
| 9744 | VkDescriptorSetLayout ds_layout; |
| 9745 | err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, |
| 9746 | &ds_layout); |
| 9747 | ASSERT_VK_SUCCESS(err); |
| 9748 | |
| 9749 | VkPipelineLayoutCreateInfo pipeline_layout_ci = {}; |
| 9750 | pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO; |
| 9751 | pipeline_layout_ci.pNext = NULL; |
| 9752 | pipeline_layout_ci.setLayoutCount = 1; |
| 9753 | pipeline_layout_ci.pSetLayouts = &ds_layout; |
| 9754 | |
| 9755 | VkPipelineLayout pipeline_layout; |
| 9756 | err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, |
| 9757 | &pipeline_layout); |
| 9758 | ASSERT_VK_SUCCESS(err); |
| 9759 | |
| 9760 | VkShaderObj vs(m_device, bindStateVertShaderText, |
| 9761 | VK_SHADER_STAGE_VERTEX_BIT, this); |
| 9762 | VkShaderObj fs(m_device, bindStateFragShaderText, |
| 9763 | VK_SHADER_STAGE_FRAGMENT_BIT, |
| 9764 | this); // We shouldn't need a fragment shader |
| 9765 | // but add it to be able to run on more devices |
| 9766 | // Create a renderpass that will be incompatible with default renderpass |
| 9767 | VkAttachmentReference attach = {}; |
| 9768 | attach.layout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL; |
| 9769 | VkAttachmentReference color_att = {}; |
| 9770 | color_att.layout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL; |
| 9771 | VkSubpassDescription subpass = {}; |
| 9772 | subpass.inputAttachmentCount = 1; |
| 9773 | subpass.pInputAttachments = &attach; |
| 9774 | subpass.colorAttachmentCount = 1; |
| 9775 | subpass.pColorAttachments = &color_att; |
| 9776 | VkRenderPassCreateInfo rpci = {}; |
| 9777 | rpci.subpassCount = 1; |
| 9778 | rpci.pSubpasses = &subpass; |
| 9779 | rpci.attachmentCount = 1; |
| 9780 | VkAttachmentDescription attach_desc = {}; |
| 9781 | attach_desc.samples = VK_SAMPLE_COUNT_1_BIT; |
Cody Northrop | bd16af1 | 2016-06-21 09:25:48 -0600 | [diff] [blame] | 9782 | // Format incompatible with PSO RP color attach format B8G8R8A8_UNORM |
| 9783 | attach_desc.format = VK_FORMAT_R8G8B8A8_UNORM; |
Tobin Ehlis | 85aa15a | 2016-06-15 10:52:37 -0600 | [diff] [blame] | 9784 | rpci.pAttachments = &attach_desc; |
| 9785 | rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO; |
| 9786 | VkRenderPass rp; |
| 9787 | vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp); |
| 9788 | VkPipelineObj pipe(m_device); |
| 9789 | pipe.AddShader(&vs); |
| 9790 | pipe.AddShader(&fs); |
| 9791 | pipe.AddColorAttachment(); |
| 9792 | VkViewport view_port = {}; |
| 9793 | m_viewports.push_back(view_port); |
| 9794 | pipe.SetViewport(m_viewports); |
| 9795 | VkRect2D rect = {}; |
| 9796 | m_scissors.push_back(rect); |
| 9797 | pipe.SetScissor(m_scissors); |
| 9798 | pipe.CreateVKPipeline(pipeline_layout, renderPass()); |
| 9799 | |
| 9800 | VkCommandBufferInheritanceInfo cbii = {}; |
| 9801 | cbii.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO; |
| 9802 | cbii.renderPass = rp; |
| 9803 | cbii.subpass = 0; |
| 9804 | VkCommandBufferBeginInfo cbbi = {}; |
| 9805 | cbbi.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO; |
| 9806 | cbbi.pInheritanceInfo = &cbii; |
| 9807 | vkBeginCommandBuffer(m_commandBuffer->handle(), &cbbi); |
| 9808 | VkRenderPassBeginInfo rpbi = {}; |
| 9809 | rpbi.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO; |
| 9810 | rpbi.framebuffer = m_framebuffer; |
| 9811 | rpbi.renderPass = rp; |
| 9812 | vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &rpbi, |
| 9813 | VK_SUBPASS_CONTENTS_INLINE); |
| 9814 | vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), |
| 9815 | VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle()); |
| 9816 | |
| 9817 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 9818 | " is incompatible w/ gfx pipeline "); |
| 9819 | // Render triangle (the error should trigger on the attempt to draw). |
| 9820 | Draw(3, 1, 0, 0); |
| 9821 | |
| 9822 | // Finalize recording of the command buffer |
| 9823 | EndCommandBuffer(); |
| 9824 | |
| 9825 | m_errorMonitor->VerifyFound(); |
| 9826 | |
| 9827 | vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL); |
| 9828 | vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL); |
| 9829 | vkDestroyRenderPass(m_device->device(), rp, NULL); |
| 9830 | } |
| 9831 | |
Mark Young | c89c631 | 2016-03-31 16:03:20 -0600 | [diff] [blame] | 9832 | TEST_F(VkLayerTest, NumBlendAttachMismatch) { |
| 9833 | // Create Pipeline where the number of blend attachments doesn't match the |
| 9834 | // number of color attachments. In this case, we don't add any color |
| 9835 | // blend attachments even though we have a color attachment. |
| 9836 | VkResult err; |
| 9837 | |
| 9838 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Mark Young | 2992748 | 2016-05-04 14:38:51 -0600 | [diff] [blame] | 9839 | "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] | 9840 | |
| 9841 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 9842 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 9843 | VkDescriptorPoolSize ds_type_count = {}; |
| 9844 | ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 9845 | ds_type_count.descriptorCount = 1; |
| 9846 | |
| 9847 | VkDescriptorPoolCreateInfo ds_pool_ci = {}; |
| 9848 | ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO; |
| 9849 | ds_pool_ci.pNext = NULL; |
| 9850 | ds_pool_ci.maxSets = 1; |
| 9851 | ds_pool_ci.poolSizeCount = 1; |
| 9852 | ds_pool_ci.pPoolSizes = &ds_type_count; |
| 9853 | |
| 9854 | VkDescriptorPool ds_pool; |
| 9855 | err = |
| 9856 | vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool); |
| 9857 | ASSERT_VK_SUCCESS(err); |
| 9858 | |
| 9859 | VkDescriptorSetLayoutBinding dsl_binding = {}; |
| 9860 | dsl_binding.binding = 0; |
| 9861 | dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 9862 | dsl_binding.descriptorCount = 1; |
| 9863 | dsl_binding.stageFlags = VK_SHADER_STAGE_ALL; |
| 9864 | dsl_binding.pImmutableSamplers = NULL; |
| 9865 | |
| 9866 | VkDescriptorSetLayoutCreateInfo ds_layout_ci = {}; |
| 9867 | ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO; |
| 9868 | ds_layout_ci.pNext = NULL; |
| 9869 | ds_layout_ci.bindingCount = 1; |
| 9870 | ds_layout_ci.pBindings = &dsl_binding; |
| 9871 | |
| 9872 | VkDescriptorSetLayout ds_layout; |
| 9873 | err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, |
| 9874 | &ds_layout); |
| 9875 | ASSERT_VK_SUCCESS(err); |
| 9876 | |
| 9877 | VkDescriptorSet descriptorSet; |
| 9878 | VkDescriptorSetAllocateInfo alloc_info = {}; |
| 9879 | alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO; |
| 9880 | alloc_info.descriptorSetCount = 1; |
| 9881 | alloc_info.descriptorPool = ds_pool; |
| 9882 | alloc_info.pSetLayouts = &ds_layout; |
| 9883 | err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, |
| 9884 | &descriptorSet); |
| 9885 | ASSERT_VK_SUCCESS(err); |
| 9886 | |
| 9887 | VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {}; |
| 9888 | pipe_ms_state_ci.sType = |
| 9889 | VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO; |
| 9890 | pipe_ms_state_ci.pNext = NULL; |
| 9891 | pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT; |
| 9892 | pipe_ms_state_ci.sampleShadingEnable = 0; |
| 9893 | pipe_ms_state_ci.minSampleShading = 1.0; |
| 9894 | pipe_ms_state_ci.pSampleMask = NULL; |
| 9895 | |
| 9896 | VkPipelineLayoutCreateInfo pipeline_layout_ci = {}; |
| 9897 | pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO; |
| 9898 | pipeline_layout_ci.pNext = NULL; |
| 9899 | pipeline_layout_ci.setLayoutCount = 1; |
| 9900 | pipeline_layout_ci.pSetLayouts = &ds_layout; |
| 9901 | |
| 9902 | VkPipelineLayout pipeline_layout; |
| 9903 | err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, |
| 9904 | &pipeline_layout); |
| 9905 | ASSERT_VK_SUCCESS(err); |
| 9906 | |
| 9907 | VkShaderObj vs(m_device, bindStateVertShaderText, |
| 9908 | VK_SHADER_STAGE_VERTEX_BIT, this); |
| 9909 | VkShaderObj fs(m_device, bindStateFragShaderText, |
| 9910 | VK_SHADER_STAGE_FRAGMENT_BIT, |
Karl Schultz | bdb7595 | 2016-04-19 11:36:49 -0600 | [diff] [blame] | 9911 | this); // We shouldn't need a fragment shader |
Mark Young | c89c631 | 2016-03-31 16:03:20 -0600 | [diff] [blame] | 9912 | // but add it to be able to run on more devices |
| 9913 | VkPipelineObj pipe(m_device); |
| 9914 | pipe.AddShader(&vs); |
| 9915 | pipe.AddShader(&fs); |
| 9916 | pipe.SetMSAA(&pipe_ms_state_ci); |
| 9917 | pipe.CreateVKPipeline(pipeline_layout, renderPass()); |
| 9918 | |
| 9919 | BeginCommandBuffer(); |
| 9920 | vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), |
| 9921 | VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle()); |
| 9922 | |
Mark Young | 2992748 | 2016-05-04 14:38:51 -0600 | [diff] [blame] | 9923 | // Render triangle (the error should trigger on the attempt to draw). |
| 9924 | Draw(3, 1, 0, 0); |
| 9925 | |
| 9926 | // Finalize recording of the command buffer |
| 9927 | EndCommandBuffer(); |
| 9928 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 9929 | m_errorMonitor->VerifyFound(); |
Mark Young | c89c631 | 2016-03-31 16:03:20 -0600 | [diff] [blame] | 9930 | |
| 9931 | vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL); |
| 9932 | vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL); |
| 9933 | vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL); |
| 9934 | } |
Mark Young | 2992748 | 2016-05-04 14:38:51 -0600 | [diff] [blame] | 9935 | |
Mark Mueller | d491441 | 2016-06-13 17:52:06 -0600 | [diff] [blame] | 9936 | TEST_F(VkLayerTest, MissingClearAttachment) { |
| 9937 | TEST_DESCRIPTION("Points to a wrong colorAttachment index in a VkClearAttachment " |
| 9938 | "structure passed to vkCmdClearAttachments"); |
| 9939 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 9940 | "vkCmdClearAttachments() attachment index 1 not found in attachment " |
| 9941 | "reference array of active subpass 0"); |
| 9942 | |
| 9943 | VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailCmdClearAttachments); |
| 9944 | m_errorMonitor->VerifyFound(); |
| 9945 | } |
| 9946 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9947 | TEST_F(VkLayerTest, ClearCmdNoDraw) { |
| 9948 | // Create CommandBuffer where we add ClearCmd for FB Color attachment prior |
| 9949 | // to issuing a Draw |
| 9950 | VkResult err; |
Tobin Ehlis | 53eddda | 2015-07-01 16:46:13 -0600 | [diff] [blame] | 9951 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9952 | m_errorMonitor->SetDesiredFailureMsg( |
Tony Barbour | 7e56d30 | 2016-03-02 15:12:01 -0700 | [diff] [blame] | 9953 | VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 9954 | "vkCmdClearAttachments() issued on CB object "); |
| 9955 | |
Tobin Ehlis | 53eddda | 2015-07-01 16:46:13 -0600 | [diff] [blame] | 9956 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 9957 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 9958 | |
Chia-I Wu | 1b99bb2 | 2015-10-27 19:25:11 +0800 | [diff] [blame] | 9959 | VkDescriptorPoolSize ds_type_count = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9960 | ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 9961 | ds_type_count.descriptorCount = 1; |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 9962 | |
| 9963 | VkDescriptorPoolCreateInfo ds_pool_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9964 | ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO; |
| 9965 | ds_pool_ci.pNext = NULL; |
| 9966 | ds_pool_ci.maxSets = 1; |
| 9967 | ds_pool_ci.poolSizeCount = 1; |
| 9968 | ds_pool_ci.pPoolSizes = &ds_type_count; |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 9969 | |
Tobin Ehlis | 53eddda | 2015-07-01 16:46:13 -0600 | [diff] [blame] | 9970 | VkDescriptorPool ds_pool; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9971 | err = |
| 9972 | vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool); |
Tobin Ehlis | 53eddda | 2015-07-01 16:46:13 -0600 | [diff] [blame] | 9973 | ASSERT_VK_SUCCESS(err); |
| 9974 | |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 9975 | VkDescriptorSetLayoutBinding dsl_binding = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9976 | dsl_binding.binding = 0; |
| 9977 | dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 9978 | dsl_binding.descriptorCount = 1; |
| 9979 | dsl_binding.stageFlags = VK_SHADER_STAGE_ALL; |
| 9980 | dsl_binding.pImmutableSamplers = NULL; |
Tobin Ehlis | 53eddda | 2015-07-01 16:46:13 -0600 | [diff] [blame] | 9981 | |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 9982 | VkDescriptorSetLayoutCreateInfo ds_layout_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9983 | ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO; |
| 9984 | ds_layout_ci.pNext = NULL; |
| 9985 | ds_layout_ci.bindingCount = 1; |
| 9986 | ds_layout_ci.pBindings = &dsl_binding; |
Mark Lobodzinski | 209b529 | 2015-09-17 09:44:05 -0600 | [diff] [blame] | 9987 | |
Tobin Ehlis | 53eddda | 2015-07-01 16:46:13 -0600 | [diff] [blame] | 9988 | VkDescriptorSetLayout ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9989 | err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, |
| 9990 | &ds_layout); |
Tobin Ehlis | 53eddda | 2015-07-01 16:46:13 -0600 | [diff] [blame] | 9991 | ASSERT_VK_SUCCESS(err); |
| 9992 | |
| 9993 | VkDescriptorSet descriptorSet; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 9994 | VkDescriptorSetAllocateInfo alloc_info = {}; |
Chia-I Wu | 00ce540 | 2015-11-10 16:21:09 +0800 | [diff] [blame] | 9995 | alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO; |
Jon Ashburn | f19916e | 2016-01-11 13:12:43 -0700 | [diff] [blame] | 9996 | alloc_info.descriptorSetCount = 1; |
Courtney Goeltzenleuchter | bee18a9 | 2015-10-23 14:21:05 -0600 | [diff] [blame] | 9997 | alloc_info.descriptorPool = ds_pool; |
| 9998 | alloc_info.pSetLayouts = &ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9999 | err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, |
| 10000 | &descriptorSet); |
Tobin Ehlis | 53eddda | 2015-07-01 16:46:13 -0600 | [diff] [blame] | 10001 | ASSERT_VK_SUCCESS(err); |
| 10002 | |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 10003 | VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 10004 | pipe_ms_state_ci.sType = |
| 10005 | VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO; |
| 10006 | pipe_ms_state_ci.pNext = NULL; |
| 10007 | pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_4_BIT; |
| 10008 | pipe_ms_state_ci.sampleShadingEnable = 0; |
| 10009 | pipe_ms_state_ci.minSampleShading = 1.0; |
| 10010 | pipe_ms_state_ci.pSampleMask = NULL; |
Tobin Ehlis | 53eddda | 2015-07-01 16:46:13 -0600 | [diff] [blame] | 10011 | |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 10012 | VkPipelineLayoutCreateInfo pipeline_layout_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 10013 | pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO; |
| 10014 | pipeline_layout_ci.pNext = NULL; |
| 10015 | pipeline_layout_ci.setLayoutCount = 1; |
| 10016 | pipeline_layout_ci.pSetLayouts = &ds_layout; |
Tobin Ehlis | 53eddda | 2015-07-01 16:46:13 -0600 | [diff] [blame] | 10017 | |
| 10018 | VkPipelineLayout pipeline_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 10019 | err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, |
| 10020 | &pipeline_layout); |
Tobin Ehlis | 53eddda | 2015-07-01 16:46:13 -0600 | [diff] [blame] | 10021 | ASSERT_VK_SUCCESS(err); |
Mark Lobodzinski | 209b529 | 2015-09-17 09:44:05 -0600 | [diff] [blame] | 10022 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 10023 | VkShaderObj vs(m_device, bindStateVertShaderText, |
| 10024 | VK_SHADER_STAGE_VERTEX_BIT, this); |
Karl Schultz | bdb7595 | 2016-04-19 11:36:49 -0600 | [diff] [blame] | 10025 | // 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] | 10026 | // on more devices |
| 10027 | VkShaderObj fs(m_device, bindStateFragShaderText, |
| 10028 | VK_SHADER_STAGE_FRAGMENT_BIT, this); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 10029 | |
Tony Barbour | 62e1a5b | 2015-08-06 10:16:07 -0600 | [diff] [blame] | 10030 | VkPipelineObj pipe(m_device); |
| 10031 | pipe.AddShader(&vs); |
Tony Barbour | 1c94d37 | 2015-08-06 11:21:08 -0600 | [diff] [blame] | 10032 | pipe.AddShader(&fs); |
Tony Barbour | 62e1a5b | 2015-08-06 10:16:07 -0600 | [diff] [blame] | 10033 | pipe.SetMSAA(&pipe_ms_state_ci); |
| 10034 | pipe.CreateVKPipeline(pipeline_layout, renderPass()); |
Tony Barbour | fe3351b | 2015-07-28 10:17:20 -0600 | [diff] [blame] | 10035 | |
| 10036 | BeginCommandBuffer(); |
Tobin Ehlis | 53eddda | 2015-07-01 16:46:13 -0600 | [diff] [blame] | 10037 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 10038 | // Main thing we care about for this test is that the VkImage obj we're |
| 10039 | // clearing matches Color Attachment of FB |
Tobin Ehlis | 53eddda | 2015-07-01 16:46:13 -0600 | [diff] [blame] | 10040 | // Also pass down other dummy params to keep driver and paramchecker happy |
Courtney Goeltzenleuchter | c9323e0 | 2015-10-15 16:51:05 -0600 | [diff] [blame] | 10041 | VkClearAttachment color_attachment; |
| 10042 | color_attachment.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; |
| 10043 | color_attachment.clearValue.color.float32[0] = 1.0; |
| 10044 | color_attachment.clearValue.color.float32[1] = 1.0; |
| 10045 | color_attachment.clearValue.color.float32[2] = 1.0; |
| 10046 | color_attachment.clearValue.color.float32[3] = 1.0; |
| 10047 | color_attachment.colorAttachment = 0; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 10048 | VkClearRect clear_rect = { |
| 10049 | {{0, 0}, {(uint32_t)m_width, (uint32_t)m_height}}}; |
Tobin Ehlis | 53eddda | 2015-07-01 16:46:13 -0600 | [diff] [blame] | 10050 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 10051 | vkCmdClearAttachments(m_commandBuffer->GetBufferHandle(), 1, |
| 10052 | &color_attachment, 1, &clear_rect); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 10053 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 10054 | m_errorMonitor->VerifyFound(); |
Mike Stroyan | d1c84a5 | 2015-08-18 14:40:24 -0600 | [diff] [blame] | 10055 | |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 10056 | vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL); |
| 10057 | vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL); |
| 10058 | vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL); |
Tobin Ehlis | 53eddda | 2015-07-01 16:46:13 -0600 | [diff] [blame] | 10059 | } |
| 10060 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 10061 | TEST_F(VkLayerTest, VtxBufferBadIndex) { |
| 10062 | VkResult err; |
Tobin Ehlis | 502480b | 2015-06-24 15:53:07 -0600 | [diff] [blame] | 10063 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 10064 | m_errorMonitor->SetDesiredFailureMsg( |
Mark Lobodzinski | 510e20d | 2016-02-11 09:26:16 -0700 | [diff] [blame] | 10065 | VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, |
Mark Lobodzinski | dfcd9b6 | 2015-12-14 15:14:10 -0700 | [diff] [blame] | 10066 | "but no vertex buffers are attached to this Pipeline State Object"); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 10067 | |
Tobin Ehlis | 502480b | 2015-06-24 15:53:07 -0600 | [diff] [blame] | 10068 | ASSERT_NO_FATAL_FAILURE(InitState()); |
Tobin Ehlis | d332f28 | 2015-10-02 11:00:56 -0600 | [diff] [blame] | 10069 | ASSERT_NO_FATAL_FAILURE(InitViewport()); |
Tobin Ehlis | 502480b | 2015-06-24 15:53:07 -0600 | [diff] [blame] | 10070 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 10071 | |
Chia-I Wu | 1b99bb2 | 2015-10-27 19:25:11 +0800 | [diff] [blame] | 10072 | VkDescriptorPoolSize ds_type_count = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 10073 | ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 10074 | ds_type_count.descriptorCount = 1; |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 10075 | |
| 10076 | VkDescriptorPoolCreateInfo ds_pool_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 10077 | ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO; |
| 10078 | ds_pool_ci.pNext = NULL; |
| 10079 | ds_pool_ci.maxSets = 1; |
| 10080 | ds_pool_ci.poolSizeCount = 1; |
| 10081 | ds_pool_ci.pPoolSizes = &ds_type_count; |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 10082 | |
Courtney Goeltzenleuchter | fe908d3 | 2015-09-16 16:12:45 -0600 | [diff] [blame] | 10083 | VkDescriptorPool ds_pool; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 10084 | err = |
| 10085 | vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool); |
Tobin Ehlis | 502480b | 2015-06-24 15:53:07 -0600 | [diff] [blame] | 10086 | ASSERT_VK_SUCCESS(err); |
| 10087 | |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 10088 | VkDescriptorSetLayoutBinding dsl_binding = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 10089 | dsl_binding.binding = 0; |
| 10090 | dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 10091 | dsl_binding.descriptorCount = 1; |
| 10092 | dsl_binding.stageFlags = VK_SHADER_STAGE_ALL; |
| 10093 | dsl_binding.pImmutableSamplers = NULL; |
Tobin Ehlis | 502480b | 2015-06-24 15:53:07 -0600 | [diff] [blame] | 10094 | |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 10095 | VkDescriptorSetLayoutCreateInfo ds_layout_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 10096 | ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO; |
| 10097 | ds_layout_ci.pNext = NULL; |
| 10098 | ds_layout_ci.bindingCount = 1; |
| 10099 | ds_layout_ci.pBindings = &dsl_binding; |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 10100 | |
Tobin Ehlis | 502480b | 2015-06-24 15:53:07 -0600 | [diff] [blame] | 10101 | VkDescriptorSetLayout ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 10102 | err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, |
| 10103 | &ds_layout); |
Tobin Ehlis | 502480b | 2015-06-24 15:53:07 -0600 | [diff] [blame] | 10104 | ASSERT_VK_SUCCESS(err); |
| 10105 | |
| 10106 | VkDescriptorSet descriptorSet; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 10107 | VkDescriptorSetAllocateInfo alloc_info = {}; |
Chia-I Wu | 00ce540 | 2015-11-10 16:21:09 +0800 | [diff] [blame] | 10108 | alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO; |
Jon Ashburn | f19916e | 2016-01-11 13:12:43 -0700 | [diff] [blame] | 10109 | alloc_info.descriptorSetCount = 1; |
Courtney Goeltzenleuchter | bee18a9 | 2015-10-23 14:21:05 -0600 | [diff] [blame] | 10110 | alloc_info.descriptorPool = ds_pool; |
| 10111 | alloc_info.pSetLayouts = &ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 10112 | err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, |
| 10113 | &descriptorSet); |
Tobin Ehlis | 502480b | 2015-06-24 15:53:07 -0600 | [diff] [blame] | 10114 | ASSERT_VK_SUCCESS(err); |
| 10115 | |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 10116 | VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 10117 | pipe_ms_state_ci.sType = |
| 10118 | VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO; |
| 10119 | pipe_ms_state_ci.pNext = NULL; |
| 10120 | pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT; |
| 10121 | pipe_ms_state_ci.sampleShadingEnable = 0; |
| 10122 | pipe_ms_state_ci.minSampleShading = 1.0; |
| 10123 | pipe_ms_state_ci.pSampleMask = NULL; |
Tobin Ehlis | 502480b | 2015-06-24 15:53:07 -0600 | [diff] [blame] | 10124 | |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 10125 | VkPipelineLayoutCreateInfo pipeline_layout_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 10126 | pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO; |
| 10127 | pipeline_layout_ci.pNext = NULL; |
| 10128 | pipeline_layout_ci.setLayoutCount = 1; |
| 10129 | pipeline_layout_ci.pSetLayouts = &ds_layout; |
| 10130 | VkPipelineLayout pipeline_layout; |
Tobin Ehlis | 502480b | 2015-06-24 15:53:07 -0600 | [diff] [blame] | 10131 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 10132 | err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, |
| 10133 | &pipeline_layout); |
Tobin Ehlis | 502480b | 2015-06-24 15:53:07 -0600 | [diff] [blame] | 10134 | ASSERT_VK_SUCCESS(err); |
| 10135 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 10136 | VkShaderObj vs(m_device, bindStateVertShaderText, |
| 10137 | VK_SHADER_STAGE_VERTEX_BIT, this); |
| 10138 | VkShaderObj fs(m_device, bindStateFragShaderText, |
| 10139 | VK_SHADER_STAGE_FRAGMENT_BIT, |
Karl Schultz | bdb7595 | 2016-04-19 11:36:49 -0600 | [diff] [blame] | 10140 | this); // We shouldn't need a fragment shader |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 10141 | // but add it to be able to run on more devices |
Tony Barbour | 62e1a5b | 2015-08-06 10:16:07 -0600 | [diff] [blame] | 10142 | VkPipelineObj pipe(m_device); |
| 10143 | pipe.AddShader(&vs); |
Tony Barbour | 1c94d37 | 2015-08-06 11:21:08 -0600 | [diff] [blame] | 10144 | pipe.AddShader(&fs); |
Mark Young | c89c631 | 2016-03-31 16:03:20 -0600 | [diff] [blame] | 10145 | pipe.AddColorAttachment(); |
Tony Barbour | 62e1a5b | 2015-08-06 10:16:07 -0600 | [diff] [blame] | 10146 | pipe.SetMSAA(&pipe_ms_state_ci); |
Tobin Ehlis | d332f28 | 2015-10-02 11:00:56 -0600 | [diff] [blame] | 10147 | pipe.SetViewport(m_viewports); |
| 10148 | pipe.SetScissor(m_scissors); |
Tony Barbour | 62e1a5b | 2015-08-06 10:16:07 -0600 | [diff] [blame] | 10149 | pipe.CreateVKPipeline(pipeline_layout, renderPass()); |
Tony Barbour | fe3351b | 2015-07-28 10:17:20 -0600 | [diff] [blame] | 10150 | |
| 10151 | BeginCommandBuffer(); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 10152 | vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), |
| 10153 | VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle()); |
Tobin Ehlis | f7bf450 | 2015-09-09 15:12:35 -0600 | [diff] [blame] | 10154 | // Don't care about actual data, just need to get to draw to flag error |
| 10155 | static const float vbo_data[3] = {1.f, 0.f, 1.f}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 10156 | VkConstantBufferObj vbo(m_device, sizeof(vbo_data), sizeof(float), |
| 10157 | (const void *)&vbo_data); |
Tobin Ehlis | f7bf450 | 2015-09-09 15:12:35 -0600 | [diff] [blame] | 10158 | 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] | 10159 | Draw(1, 0, 0, 0); |
Tobin Ehlis | 502480b | 2015-06-24 15:53:07 -0600 | [diff] [blame] | 10160 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 10161 | m_errorMonitor->VerifyFound(); |
Mike Stroyan | d1c84a5 | 2015-08-18 14:40:24 -0600 | [diff] [blame] | 10162 | |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 10163 | vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL); |
| 10164 | vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL); |
| 10165 | vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL); |
Tobin Ehlis | 502480b | 2015-06-24 15:53:07 -0600 | [diff] [blame] | 10166 | } |
Tobin Ehlis | c555a3c | 2016-05-04 14:08:34 -0600 | [diff] [blame] | 10167 | // INVALID_IMAGE_LAYOUT tests (one other case is hit by MapMemWithoutHostVisibleBit and not here) |
| 10168 | TEST_F(VkLayerTest, InvalidImageLayout) { |
| 10169 | TEST_DESCRIPTION("Hit all possible validation checks associated with the " |
| 10170 | "DRAWSTATE_INVALID_IMAGE_LAYOUT enum. Generally these involve having" |
| 10171 | "images in the wrong layout when they're copied or transitioned."); |
| 10172 | // 3 in ValidateCmdBufImageLayouts |
| 10173 | // * -1 Attempt to submit cmd buf w/ deleted image |
| 10174 | // * -2 Cmd buf submit of image w/ layout not matching first use w/ subresource |
| 10175 | // * -3 Cmd buf submit of image w/ layout not matching first use w/o subresource |
| 10176 | m_errorMonitor->SetDesiredFailureMsg( |
| 10177 | VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, |
| 10178 | "Layout for input image should be TRANSFER_SRC_OPTIMAL instead of GENERAL."); |
| 10179 | |
| 10180 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 10181 | // Create src & dst images to use for copy operations |
| 10182 | VkImage src_image; |
| 10183 | VkImage dst_image; |
| 10184 | |
| 10185 | const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM; |
| 10186 | const int32_t tex_width = 32; |
| 10187 | const int32_t tex_height = 32; |
| 10188 | |
| 10189 | VkImageCreateInfo image_create_info = {}; |
| 10190 | image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO; |
| 10191 | image_create_info.pNext = NULL; |
| 10192 | image_create_info.imageType = VK_IMAGE_TYPE_2D; |
| 10193 | image_create_info.format = tex_format; |
| 10194 | image_create_info.extent.width = tex_width; |
| 10195 | image_create_info.extent.height = tex_height; |
| 10196 | image_create_info.extent.depth = 1; |
| 10197 | image_create_info.mipLevels = 1; |
| 10198 | image_create_info.arrayLayers = 4; |
| 10199 | image_create_info.samples = VK_SAMPLE_COUNT_1_BIT; |
| 10200 | image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL; |
| 10201 | image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT; |
| 10202 | image_create_info.flags = 0; |
| 10203 | |
| 10204 | VkResult err = vkCreateImage(m_device->device(), &image_create_info, NULL, &src_image); |
| 10205 | ASSERT_VK_SUCCESS(err); |
| 10206 | err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dst_image); |
| 10207 | ASSERT_VK_SUCCESS(err); |
| 10208 | |
| 10209 | BeginCommandBuffer(); |
| 10210 | VkImageCopy copyRegion; |
| 10211 | copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; |
| 10212 | copyRegion.srcSubresource.mipLevel = 0; |
| 10213 | copyRegion.srcSubresource.baseArrayLayer = 0; |
| 10214 | copyRegion.srcSubresource.layerCount = 1; |
| 10215 | copyRegion.srcOffset.x = 0; |
| 10216 | copyRegion.srcOffset.y = 0; |
| 10217 | copyRegion.srcOffset.z = 0; |
| 10218 | copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; |
| 10219 | copyRegion.dstSubresource.mipLevel = 0; |
| 10220 | copyRegion.dstSubresource.baseArrayLayer = 0; |
| 10221 | copyRegion.dstSubresource.layerCount = 1; |
| 10222 | copyRegion.dstOffset.x = 0; |
| 10223 | copyRegion.dstOffset.y = 0; |
| 10224 | copyRegion.dstOffset.z = 0; |
| 10225 | copyRegion.extent.width = 1; |
| 10226 | copyRegion.extent.height = 1; |
| 10227 | copyRegion.extent.depth = 1; |
| 10228 | m_commandBuffer->CopyImage(src_image, VK_IMAGE_LAYOUT_GENERAL, dst_image, VK_IMAGE_LAYOUT_GENERAL, 1, ©Region); |
| 10229 | m_errorMonitor->VerifyFound(); |
| 10230 | // Now cause error due to src image layout changing |
| 10231 | m_errorMonitor->SetDesiredFailureMsg( |
| 10232 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 10233 | "Cannot copy from an image whose source layout is VK_IMAGE_LAYOUT_UNDEFINED and doesn't match the current layout VK_IMAGE_LAYOUT_GENERAL."); |
| 10234 | m_commandBuffer->CopyImage(src_image, VK_IMAGE_LAYOUT_UNDEFINED, dst_image, VK_IMAGE_LAYOUT_GENERAL, 1, ©Region); |
| 10235 | m_errorMonitor->VerifyFound(); |
| 10236 | // Final src error is due to bad layout type |
| 10237 | m_errorMonitor->SetDesiredFailureMsg( |
| 10238 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 10239 | "Layout for input image is VK_IMAGE_LAYOUT_UNDEFINED but can only be TRANSFER_SRC_OPTIMAL or GENERAL."); |
| 10240 | m_commandBuffer->CopyImage(src_image, VK_IMAGE_LAYOUT_UNDEFINED, dst_image, VK_IMAGE_LAYOUT_GENERAL, 1, ©Region); |
| 10241 | m_errorMonitor->VerifyFound(); |
| 10242 | // Now verify same checks for dst |
| 10243 | m_errorMonitor->SetDesiredFailureMsg( |
| 10244 | VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, |
| 10245 | "Layout for output image should be TRANSFER_DST_OPTIMAL instead of GENERAL."); |
| 10246 | m_commandBuffer->CopyImage(src_image, VK_IMAGE_LAYOUT_GENERAL, dst_image, VK_IMAGE_LAYOUT_GENERAL, 1, ©Region); |
| 10247 | m_errorMonitor->VerifyFound(); |
| 10248 | // Now cause error due to src image layout changing |
| 10249 | m_errorMonitor->SetDesiredFailureMsg( |
| 10250 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 10251 | "Cannot copy from an image whose dest layout is VK_IMAGE_LAYOUT_UNDEFINED and doesn't match the current layout VK_IMAGE_LAYOUT_GENERAL."); |
| 10252 | m_commandBuffer->CopyImage(src_image, VK_IMAGE_LAYOUT_GENERAL, dst_image, VK_IMAGE_LAYOUT_UNDEFINED, 1, ©Region); |
| 10253 | m_errorMonitor->VerifyFound(); |
| 10254 | m_errorMonitor->SetDesiredFailureMsg( |
| 10255 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 10256 | "Layout for output image is VK_IMAGE_LAYOUT_UNDEFINED but can only be TRANSFER_DST_OPTIMAL or GENERAL."); |
| 10257 | m_commandBuffer->CopyImage(src_image, VK_IMAGE_LAYOUT_GENERAL, dst_image, VK_IMAGE_LAYOUT_UNDEFINED, 1, ©Region); |
| 10258 | m_errorMonitor->VerifyFound(); |
| 10259 | // Now cause error due to bad image layout transition in PipelineBarrier |
| 10260 | VkImageMemoryBarrier image_barrier[1] = {}; |
| 10261 | image_barrier[0].oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL; |
| 10262 | image_barrier[0].image = src_image; |
| 10263 | image_barrier[0].subresourceRange.layerCount = 2; |
| 10264 | image_barrier[0].subresourceRange.levelCount = 2; |
| 10265 | image_barrier[0].subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; |
| 10266 | m_errorMonitor->SetDesiredFailureMsg( |
| 10267 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 10268 | "You cannot transition the layout from VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL when current layout is VK_IMAGE_LAYOUT_GENERAL."); |
| 10269 | vkCmdPipelineBarrier(m_commandBuffer->handle(), VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, NULL, 0, NULL, 1, image_barrier); |
| 10270 | m_errorMonitor->VerifyFound(); |
| 10271 | |
| 10272 | // Finally some layout errors at RenderPass create time |
| 10273 | // Just hacking in specific state to get to the errors we want so don't copy this unless you know what you're doing. |
| 10274 | VkAttachmentReference attach = {}; |
| 10275 | // perf warning for GENERAL layout w/ non-DS input attachment |
| 10276 | attach.layout = VK_IMAGE_LAYOUT_GENERAL; |
| 10277 | VkSubpassDescription subpass = {}; |
| 10278 | subpass.inputAttachmentCount = 1; |
| 10279 | subpass.pInputAttachments = &attach; |
| 10280 | VkRenderPassCreateInfo rpci = {}; |
| 10281 | rpci.subpassCount = 1; |
| 10282 | rpci.pSubpasses = &subpass; |
| 10283 | rpci.attachmentCount = 1; |
| 10284 | VkAttachmentDescription attach_desc = {}; |
| 10285 | attach_desc.format = VK_FORMAT_UNDEFINED; |
| 10286 | rpci.pAttachments = &attach_desc; |
Tobin Ehlis | 1efce02 | 2016-05-11 10:40:34 -0600 | [diff] [blame] | 10287 | rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO; |
Tobin Ehlis | c555a3c | 2016-05-04 14:08:34 -0600 | [diff] [blame] | 10288 | VkRenderPass rp; |
| 10289 | m_errorMonitor->SetDesiredFailureMsg( |
| 10290 | VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, |
| 10291 | "Layout for input attachment is GENERAL but should be READ_ONLY_OPTIMAL."); |
| 10292 | vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp); |
| 10293 | m_errorMonitor->VerifyFound(); |
| 10294 | // error w/ non-general layout |
| 10295 | attach.layout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL; |
| 10296 | |
| 10297 | m_errorMonitor->SetDesiredFailureMsg( |
| 10298 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 10299 | "Layout for input attachment is VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL but can only be READ_ONLY_OPTIMAL or GENERAL."); |
| 10300 | vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp); |
| 10301 | m_errorMonitor->VerifyFound(); |
| 10302 | subpass.inputAttachmentCount = 0; |
| 10303 | subpass.colorAttachmentCount = 1; |
| 10304 | subpass.pColorAttachments = &attach; |
| 10305 | attach.layout = VK_IMAGE_LAYOUT_GENERAL; |
| 10306 | // perf warning for GENERAL layout on color attachment |
| 10307 | m_errorMonitor->SetDesiredFailureMsg( |
| 10308 | VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, |
| 10309 | "Layout for color attachment is GENERAL but should be COLOR_ATTACHMENT_OPTIMAL."); |
| 10310 | vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp); |
| 10311 | m_errorMonitor->VerifyFound(); |
| 10312 | // error w/ non-color opt or GENERAL layout for color attachment |
| 10313 | attach.layout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL; |
| 10314 | m_errorMonitor->SetDesiredFailureMsg( |
| 10315 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 10316 | "Layout for color attachment is VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL but can only be COLOR_ATTACHMENT_OPTIMAL or GENERAL."); |
| 10317 | vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp); |
| 10318 | m_errorMonitor->VerifyFound(); |
| 10319 | subpass.colorAttachmentCount = 0; |
| 10320 | subpass.pDepthStencilAttachment = &attach; |
| 10321 | attach.layout = VK_IMAGE_LAYOUT_GENERAL; |
| 10322 | // perf warning for GENERAL layout on DS attachment |
| 10323 | m_errorMonitor->SetDesiredFailureMsg( |
| 10324 | VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, |
| 10325 | "Layout for depth attachment is GENERAL but should be DEPTH_STENCIL_ATTACHMENT_OPTIMAL."); |
| 10326 | vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp); |
| 10327 | m_errorMonitor->VerifyFound(); |
| 10328 | // error w/ non-ds opt or GENERAL layout for color attachment |
| 10329 | attach.layout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL; |
| 10330 | m_errorMonitor->SetDesiredFailureMsg( |
| 10331 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 10332 | "Layout for depth attachment is VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL but can only be DEPTH_STENCIL_ATTACHMENT_OPTIMAL or GENERAL."); |
| 10333 | vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp); |
| 10334 | m_errorMonitor->VerifyFound(); |
Tobin Ehlis | 1efce02 | 2016-05-11 10:40:34 -0600 | [diff] [blame] | 10335 | // For this error we need a valid renderpass so create default one |
| 10336 | attach.layout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL; |
| 10337 | attach.attachment = 0; |
| 10338 | attach_desc.format = VK_FORMAT_D24_UNORM_S8_UINT; |
| 10339 | attach_desc.samples = VK_SAMPLE_COUNT_1_BIT; |
| 10340 | attach_desc.storeOp = VK_ATTACHMENT_STORE_OP_STORE; |
| 10341 | attach_desc.stencilLoadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE; |
| 10342 | attach_desc.stencilStoreOp = VK_ATTACHMENT_STORE_OP_DONT_CARE; |
| 10343 | // Can't do a CLEAR load on READ_ONLY initialLayout |
| 10344 | attach_desc.loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR; |
| 10345 | attach_desc.initialLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL; |
| 10346 | attach_desc.finalLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL; |
| 10347 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 10348 | " with invalid first layout " |
| 10349 | "VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_" |
| 10350 | "ONLY_OPTIMAL"); |
| 10351 | vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp); |
| 10352 | m_errorMonitor->VerifyFound(); |
Tobin Ehlis | c555a3c | 2016-05-04 14:08:34 -0600 | [diff] [blame] | 10353 | |
| 10354 | vkDestroyImage(m_device->device(), src_image, NULL); |
| 10355 | vkDestroyImage(m_device->device(), dst_image, NULL); |
| 10356 | } |
Mark Lobodzinski | 209b529 | 2015-09-17 09:44:05 -0600 | [diff] [blame] | 10357 | #endif // DRAW_STATE_TESTS |
| 10358 | |
Tobin Ehlis | 0788f52 | 2015-05-26 16:11:58 -0600 | [diff] [blame] | 10359 | #if THREADING_TESTS |
Mike Stroyan | accf769 | 2015-05-12 16:00:45 -0600 | [diff] [blame] | 10360 | #if GTEST_IS_THREADSAFE |
| 10361 | struct thread_data_struct { |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 10362 | VkCommandBuffer commandBuffer; |
Mike Stroyan | accf769 | 2015-05-12 16:00:45 -0600 | [diff] [blame] | 10363 | VkEvent event; |
| 10364 | bool bailout; |
| 10365 | }; |
| 10366 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 10367 | extern "C" void *AddToCommandBuffer(void *arg) { |
| 10368 | struct thread_data_struct *data = (struct thread_data_struct *)arg; |
Mike Stroyan | accf769 | 2015-05-12 16:00:45 -0600 | [diff] [blame] | 10369 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 10370 | for (int i = 0; i < 10000; i++) { |
| 10371 | vkCmdSetEvent(data->commandBuffer, data->event, |
| 10372 | VK_PIPELINE_STAGE_ALL_COMMANDS_BIT); |
Mike Stroyan | accf769 | 2015-05-12 16:00:45 -0600 | [diff] [blame] | 10373 | if (data->bailout) { |
| 10374 | break; |
| 10375 | } |
| 10376 | } |
| 10377 | return NULL; |
| 10378 | } |
| 10379 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 10380 | TEST_F(VkLayerTest, ThreadCommandBufferCollision) { |
Mike Stroyan | 4268d1f | 2015-07-13 14:45:35 -0600 | [diff] [blame] | 10381 | test_platform_thread thread; |
Mike Stroyan | accf769 | 2015-05-12 16:00:45 -0600 | [diff] [blame] | 10382 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 10383 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 10384 | "THREADING ERROR"); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 10385 | |
Mike Stroyan | accf769 | 2015-05-12 16:00:45 -0600 | [diff] [blame] | 10386 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 10387 | ASSERT_NO_FATAL_FAILURE(InitViewport()); |
| 10388 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 10389 | |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 10390 | // Calls AllocateCommandBuffers |
| 10391 | VkCommandBufferObj commandBuffer(m_device, m_commandPool); |
Mark Lobodzinski | 5495d13 | 2015-09-30 16:19:16 -0600 | [diff] [blame] | 10392 | |
| 10393 | // Avoid creating RenderPass |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 10394 | commandBuffer.BeginCommandBuffer(); |
Mike Stroyan | accf769 | 2015-05-12 16:00:45 -0600 | [diff] [blame] | 10395 | |
| 10396 | VkEventCreateInfo event_info; |
| 10397 | VkEvent event; |
Mike Stroyan | accf769 | 2015-05-12 16:00:45 -0600 | [diff] [blame] | 10398 | VkResult err; |
| 10399 | |
| 10400 | memset(&event_info, 0, sizeof(event_info)); |
| 10401 | event_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO; |
| 10402 | |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 10403 | err = vkCreateEvent(device(), &event_info, NULL, &event); |
Mike Stroyan | accf769 | 2015-05-12 16:00:45 -0600 | [diff] [blame] | 10404 | ASSERT_VK_SUCCESS(err); |
| 10405 | |
Mike Stroyan | accf769 | 2015-05-12 16:00:45 -0600 | [diff] [blame] | 10406 | err = vkResetEvent(device(), event); |
| 10407 | ASSERT_VK_SUCCESS(err); |
| 10408 | |
| 10409 | struct thread_data_struct data; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 10410 | data.commandBuffer = commandBuffer.GetBufferHandle(); |
Mike Stroyan | accf769 | 2015-05-12 16:00:45 -0600 | [diff] [blame] | 10411 | data.event = event; |
| 10412 | data.bailout = false; |
| 10413 | m_errorMonitor->SetBailout(&data.bailout); |
| 10414 | // Add many entries to command buffer from another thread. |
Mike Stroyan | 4268d1f | 2015-07-13 14:45:35 -0600 | [diff] [blame] | 10415 | test_platform_thread_create(&thread, AddToCommandBuffer, (void *)&data); |
Mike Stroyan | accf769 | 2015-05-12 16:00:45 -0600 | [diff] [blame] | 10416 | // Add many entries to command buffer from this thread at the same time. |
| 10417 | AddToCommandBuffer(&data); |
Mark Lobodzinski | 5495d13 | 2015-09-30 16:19:16 -0600 | [diff] [blame] | 10418 | |
Mike Stroyan | 4268d1f | 2015-07-13 14:45:35 -0600 | [diff] [blame] | 10419 | test_platform_thread_join(thread, NULL); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 10420 | commandBuffer.EndCommandBuffer(); |
Mike Stroyan | accf769 | 2015-05-12 16:00:45 -0600 | [diff] [blame] | 10421 | |
Mike Stroyan | 10b8cb7 | 2016-01-22 15:22:03 -0700 | [diff] [blame] | 10422 | m_errorMonitor->SetBailout(NULL); |
| 10423 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 10424 | m_errorMonitor->VerifyFound(); |
Mike Stroyan | accf769 | 2015-05-12 16:00:45 -0600 | [diff] [blame] | 10425 | |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 10426 | vkDestroyEvent(device(), event, NULL); |
Mike Stroyan | accf769 | 2015-05-12 16:00:45 -0600 | [diff] [blame] | 10427 | } |
Mark Lobodzinski | 209b529 | 2015-09-17 09:44:05 -0600 | [diff] [blame] | 10428 | #endif // GTEST_IS_THREADSAFE |
| 10429 | #endif // THREADING_TESTS |
| 10430 | |
Chris Forbes | 9f7ff63 | 2015-05-25 11:13:08 +1200 | [diff] [blame] | 10431 | #if SHADER_CHECKER_TESTS |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 10432 | TEST_F(VkLayerTest, InvalidSPIRVCodeSize) { |
Courtney Goeltzenleuchter | 7415d5a | 2015-12-09 15:48:16 -0700 | [diff] [blame] | 10433 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Chris Forbes | b4afd0f | 2016-04-04 10:48:35 +1200 | [diff] [blame] | 10434 | "Invalid SPIR-V header"); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 10435 | |
Courtney Goeltzenleuchter | 00c52b2 | 2015-09-16 12:58:29 -0600 | [diff] [blame] | 10436 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 10437 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 10438 | |
Courtney Goeltzenleuchter | 00c52b2 | 2015-09-16 12:58:29 -0600 | [diff] [blame] | 10439 | VkShaderModule module; |
| 10440 | VkShaderModuleCreateInfo moduleCreateInfo; |
| 10441 | struct icd_spv_header spv; |
| 10442 | |
| 10443 | spv.magic = ICD_SPV_MAGIC; |
| 10444 | spv.version = ICD_SPV_VERSION; |
| 10445 | spv.gen_magic = 0; |
| 10446 | |
| 10447 | moduleCreateInfo.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO; |
| 10448 | moduleCreateInfo.pNext = NULL; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 10449 | moduleCreateInfo.pCode = (const uint32_t *)&spv; |
Courtney Goeltzenleuchter | 00c52b2 | 2015-09-16 12:58:29 -0600 | [diff] [blame] | 10450 | moduleCreateInfo.codeSize = 4; |
| 10451 | moduleCreateInfo.flags = 0; |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 10452 | vkCreateShaderModule(m_device->device(), &moduleCreateInfo, NULL, &module); |
Courtney Goeltzenleuchter | 00c52b2 | 2015-09-16 12:58:29 -0600 | [diff] [blame] | 10453 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 10454 | m_errorMonitor->VerifyFound(); |
Courtney Goeltzenleuchter | 00c52b2 | 2015-09-16 12:58:29 -0600 | [diff] [blame] | 10455 | } |
| 10456 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 10457 | TEST_F(VkLayerTest, InvalidSPIRVMagic) { |
Courtney Goeltzenleuchter | 7415d5a | 2015-12-09 15:48:16 -0700 | [diff] [blame] | 10458 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Chris Forbes | b4afd0f | 2016-04-04 10:48:35 +1200 | [diff] [blame] | 10459 | "Invalid SPIR-V magic number"); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 10460 | |
Courtney Goeltzenleuchter | 00c52b2 | 2015-09-16 12:58:29 -0600 | [diff] [blame] | 10461 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 10462 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 10463 | |
Courtney Goeltzenleuchter | 00c52b2 | 2015-09-16 12:58:29 -0600 | [diff] [blame] | 10464 | VkShaderModule module; |
| 10465 | VkShaderModuleCreateInfo moduleCreateInfo; |
| 10466 | struct icd_spv_header spv; |
| 10467 | |
| 10468 | spv.magic = ~ICD_SPV_MAGIC; |
| 10469 | spv.version = ICD_SPV_VERSION; |
| 10470 | spv.gen_magic = 0; |
| 10471 | |
| 10472 | moduleCreateInfo.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO; |
| 10473 | moduleCreateInfo.pNext = NULL; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 10474 | moduleCreateInfo.pCode = (const uint32_t *)&spv; |
Courtney Goeltzenleuchter | 00c52b2 | 2015-09-16 12:58:29 -0600 | [diff] [blame] | 10475 | moduleCreateInfo.codeSize = sizeof(spv) + 10; |
| 10476 | moduleCreateInfo.flags = 0; |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 10477 | vkCreateShaderModule(m_device->device(), &moduleCreateInfo, NULL, &module); |
Courtney Goeltzenleuchter | 00c52b2 | 2015-09-16 12:58:29 -0600 | [diff] [blame] | 10478 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 10479 | m_errorMonitor->VerifyFound(); |
Courtney Goeltzenleuchter | 00c52b2 | 2015-09-16 12:58:29 -0600 | [diff] [blame] | 10480 | } |
| 10481 | |
Chris Forbes | b4afd0f | 2016-04-04 10:48:35 +1200 | [diff] [blame] | 10482 | #if 0 |
| 10483 | // Not currently covered by SPIRV-Tools validator |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 10484 | TEST_F(VkLayerTest, InvalidSPIRVVersion) { |
Courtney Goeltzenleuchter | 7415d5a | 2015-12-09 15:48:16 -0700 | [diff] [blame] | 10485 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Chris Forbes | b4afd0f | 2016-04-04 10:48:35 +1200 | [diff] [blame] | 10486 | "Invalid SPIR-V header"); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 10487 | |
Courtney Goeltzenleuchter | 00c52b2 | 2015-09-16 12:58:29 -0600 | [diff] [blame] | 10488 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 10489 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 10490 | |
Courtney Goeltzenleuchter | 00c52b2 | 2015-09-16 12:58:29 -0600 | [diff] [blame] | 10491 | VkShaderModule module; |
| 10492 | VkShaderModuleCreateInfo moduleCreateInfo; |
| 10493 | struct icd_spv_header spv; |
| 10494 | |
| 10495 | spv.magic = ICD_SPV_MAGIC; |
| 10496 | spv.version = ~ICD_SPV_VERSION; |
| 10497 | spv.gen_magic = 0; |
| 10498 | |
| 10499 | moduleCreateInfo.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO; |
| 10500 | moduleCreateInfo.pNext = NULL; |
| 10501 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 10502 | moduleCreateInfo.pCode = (const uint32_t *)&spv; |
Courtney Goeltzenleuchter | 00c52b2 | 2015-09-16 12:58:29 -0600 | [diff] [blame] | 10503 | moduleCreateInfo.codeSize = sizeof(spv) + 10; |
| 10504 | moduleCreateInfo.flags = 0; |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 10505 | vkCreateShaderModule(m_device->device(), &moduleCreateInfo, NULL, &module); |
Courtney Goeltzenleuchter | 00c52b2 | 2015-09-16 12:58:29 -0600 | [diff] [blame] | 10506 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 10507 | m_errorMonitor->VerifyFound(); |
Courtney Goeltzenleuchter | 00c52b2 | 2015-09-16 12:58:29 -0600 | [diff] [blame] | 10508 | } |
Chris Forbes | b4afd0f | 2016-04-04 10:48:35 +1200 | [diff] [blame] | 10509 | #endif |
Courtney Goeltzenleuchter | 00c52b2 | 2015-09-16 12:58:29 -0600 | [diff] [blame] | 10510 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 10511 | TEST_F(VkLayerTest, CreatePipelineVertexOutputNotConsumed) { |
Mark Lobodzinski | 510e20d | 2016-02-11 09:26:16 -0700 | [diff] [blame] | 10512 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 10513 | "not consumed by fragment shader"); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 10514 | |
Chris Forbes | 9f7ff63 | 2015-05-25 11:13:08 +1200 | [diff] [blame] | 10515 | ASSERT_NO_FATAL_FAILURE(InitState()); |
Tobin Ehlis | c9ac2b6 | 2015-09-11 12:57:55 -0600 | [diff] [blame] | 10516 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
Chris Forbes | 9f7ff63 | 2015-05-25 11:13:08 +1200 | [diff] [blame] | 10517 | |
| 10518 | char const *vsSource = |
Chris Forbes | 3846771 | 2016-04-04 17:28:05 +1200 | [diff] [blame] | 10519 | "#version 450\n" |
Chris Forbes | 9f7ff63 | 2015-05-25 11:13:08 +1200 | [diff] [blame] | 10520 | "\n" |
| 10521 | "layout(location=0) out float x;\n" |
Tony Barbour | e804d20 | 2016-01-05 13:37:45 -0700 | [diff] [blame] | 10522 | "out gl_PerVertex {\n" |
| 10523 | " vec4 gl_Position;\n" |
| 10524 | "};\n" |
Chris Forbes | 9f7ff63 | 2015-05-25 11:13:08 +1200 | [diff] [blame] | 10525 | "void main(){\n" |
| 10526 | " gl_Position = vec4(1);\n" |
| 10527 | " x = 0;\n" |
| 10528 | "}\n"; |
| 10529 | char const *fsSource = |
Chris Forbes | 3846771 | 2016-04-04 17:28:05 +1200 | [diff] [blame] | 10530 | "#version 450\n" |
Chris Forbes | 9f7ff63 | 2015-05-25 11:13:08 +1200 | [diff] [blame] | 10531 | "\n" |
| 10532 | "layout(location=0) out vec4 color;\n" |
| 10533 | "void main(){\n" |
| 10534 | " color = vec4(1);\n" |
| 10535 | "}\n"; |
| 10536 | |
Courtney Goeltzenleuchter | d263550 | 2015-10-21 17:08:06 -0600 | [diff] [blame] | 10537 | VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this); |
| 10538 | VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this); |
Chris Forbes | 9f7ff63 | 2015-05-25 11:13:08 +1200 | [diff] [blame] | 10539 | |
| 10540 | VkPipelineObj pipe(m_device); |
Chia-I Wu | 08accc6 | 2015-07-07 11:50:03 +0800 | [diff] [blame] | 10541 | pipe.AddColorAttachment(); |
Chris Forbes | 9f7ff63 | 2015-05-25 11:13:08 +1200 | [diff] [blame] | 10542 | pipe.AddShader(&vs); |
| 10543 | pipe.AddShader(&fs); |
| 10544 | |
Chris Forbes | 9f7ff63 | 2015-05-25 11:13:08 +1200 | [diff] [blame] | 10545 | VkDescriptorSetObj descriptorSet(m_device); |
| 10546 | descriptorSet.AppendDummy(); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 10547 | descriptorSet.CreateVKDescriptorSet(m_commandBuffer); |
Chris Forbes | 9f7ff63 | 2015-05-25 11:13:08 +1200 | [diff] [blame] | 10548 | |
Tony Barbour | 5781e8f | 2015-08-04 16:23:11 -0600 | [diff] [blame] | 10549 | pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass()); |
Chris Forbes | 9f7ff63 | 2015-05-25 11:13:08 +1200 | [diff] [blame] | 10550 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 10551 | m_errorMonitor->VerifyFound(); |
Chris Forbes | 9f7ff63 | 2015-05-25 11:13:08 +1200 | [diff] [blame] | 10552 | } |
Chris Forbes | 9f7ff63 | 2015-05-25 11:13:08 +1200 | [diff] [blame] | 10553 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 10554 | TEST_F(VkLayerTest, CreatePipelineFragmentInputNotProvided) { |
Courtney Goeltzenleuchter | 7415d5a | 2015-12-09 15:48:16 -0700 | [diff] [blame] | 10555 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 10556 | "not written by vertex shader"); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 10557 | |
Chris Forbes | 59cb88d | 2015-05-25 11:13:13 +1200 | [diff] [blame] | 10558 | ASSERT_NO_FATAL_FAILURE(InitState()); |
Tobin Ehlis | c9ac2b6 | 2015-09-11 12:57:55 -0600 | [diff] [blame] | 10559 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
Chris Forbes | 59cb88d | 2015-05-25 11:13:13 +1200 | [diff] [blame] | 10560 | |
| 10561 | char const *vsSource = |
Chris Forbes | 3846771 | 2016-04-04 17:28:05 +1200 | [diff] [blame] | 10562 | "#version 450\n" |
Chris Forbes | 59cb88d | 2015-05-25 11:13:13 +1200 | [diff] [blame] | 10563 | "\n" |
Tony Barbour | e804d20 | 2016-01-05 13:37:45 -0700 | [diff] [blame] | 10564 | "out gl_PerVertex {\n" |
| 10565 | " vec4 gl_Position;\n" |
| 10566 | "};\n" |
Chris Forbes | 59cb88d | 2015-05-25 11:13:13 +1200 | [diff] [blame] | 10567 | "void main(){\n" |
| 10568 | " gl_Position = vec4(1);\n" |
| 10569 | "}\n"; |
| 10570 | char const *fsSource = |
Chris Forbes | 3846771 | 2016-04-04 17:28:05 +1200 | [diff] [blame] | 10571 | "#version 450\n" |
Chris Forbes | 59cb88d | 2015-05-25 11:13:13 +1200 | [diff] [blame] | 10572 | "\n" |
| 10573 | "layout(location=0) in float x;\n" |
| 10574 | "layout(location=0) out vec4 color;\n" |
| 10575 | "void main(){\n" |
| 10576 | " color = vec4(x);\n" |
| 10577 | "}\n"; |
| 10578 | |
Courtney Goeltzenleuchter | d263550 | 2015-10-21 17:08:06 -0600 | [diff] [blame] | 10579 | VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this); |
| 10580 | VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this); |
Chris Forbes | 59cb88d | 2015-05-25 11:13:13 +1200 | [diff] [blame] | 10581 | |
| 10582 | VkPipelineObj pipe(m_device); |
Chia-I Wu | 08accc6 | 2015-07-07 11:50:03 +0800 | [diff] [blame] | 10583 | pipe.AddColorAttachment(); |
Chris Forbes | 59cb88d | 2015-05-25 11:13:13 +1200 | [diff] [blame] | 10584 | pipe.AddShader(&vs); |
| 10585 | pipe.AddShader(&fs); |
| 10586 | |
Chris Forbes | 59cb88d | 2015-05-25 11:13:13 +1200 | [diff] [blame] | 10587 | VkDescriptorSetObj descriptorSet(m_device); |
| 10588 | descriptorSet.AppendDummy(); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 10589 | descriptorSet.CreateVKDescriptorSet(m_commandBuffer); |
Chris Forbes | 59cb88d | 2015-05-25 11:13:13 +1200 | [diff] [blame] | 10590 | |
Tony Barbour | 5781e8f | 2015-08-04 16:23:11 -0600 | [diff] [blame] | 10591 | pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass()); |
Chris Forbes | 59cb88d | 2015-05-25 11:13:13 +1200 | [diff] [blame] | 10592 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 10593 | m_errorMonitor->VerifyFound(); |
Chris Forbes | 59cb88d | 2015-05-25 11:13:13 +1200 | [diff] [blame] | 10594 | } |
| 10595 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 10596 | TEST_F(VkLayerTest, CreatePipelineFragmentInputNotProvidedInBlock) { |
Chris Forbes | a3e85f6 | 2016-01-15 14:53:11 +1300 | [diff] [blame] | 10597 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 10598 | "not written by vertex shader"); |
Chris Forbes | a3e85f6 | 2016-01-15 14:53:11 +1300 | [diff] [blame] | 10599 | |
| 10600 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 10601 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 10602 | |
| 10603 | char const *vsSource = |
Chris Forbes | 3846771 | 2016-04-04 17:28:05 +1200 | [diff] [blame] | 10604 | "#version 450\n" |
Chris Forbes | a3e85f6 | 2016-01-15 14:53:11 +1300 | [diff] [blame] | 10605 | "\n" |
| 10606 | "out gl_PerVertex {\n" |
| 10607 | " vec4 gl_Position;\n" |
| 10608 | "};\n" |
| 10609 | "void main(){\n" |
| 10610 | " gl_Position = vec4(1);\n" |
| 10611 | "}\n"; |
| 10612 | char const *fsSource = |
| 10613 | "#version 450\n" |
Chris Forbes | a3e85f6 | 2016-01-15 14:53:11 +1300 | [diff] [blame] | 10614 | "\n" |
| 10615 | "in block { layout(location=0) float x; } ins;\n" |
| 10616 | "layout(location=0) out vec4 color;\n" |
| 10617 | "void main(){\n" |
| 10618 | " color = vec4(ins.x);\n" |
| 10619 | "}\n"; |
| 10620 | |
| 10621 | VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this); |
| 10622 | VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this); |
| 10623 | |
| 10624 | VkPipelineObj pipe(m_device); |
| 10625 | pipe.AddColorAttachment(); |
| 10626 | pipe.AddShader(&vs); |
| 10627 | pipe.AddShader(&fs); |
| 10628 | |
| 10629 | VkDescriptorSetObj descriptorSet(m_device); |
| 10630 | descriptorSet.AppendDummy(); |
| 10631 | descriptorSet.CreateVKDescriptorSet(m_commandBuffer); |
| 10632 | |
| 10633 | pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass()); |
| 10634 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 10635 | m_errorMonitor->VerifyFound(); |
Chris Forbes | a3e85f6 | 2016-01-15 14:53:11 +1300 | [diff] [blame] | 10636 | } |
| 10637 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 10638 | TEST_F(VkLayerTest, CreatePipelineVsFsTypeMismatchArraySize) { |
Chris Forbes | 0036fd1 | 2016-01-26 14:19:49 +1300 | [diff] [blame] | 10639 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Chris Forbes | e992882 | 2016-02-17 14:44:52 +1300 | [diff] [blame] | 10640 | "Type mismatch on location 0.0: 'ptr to " |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 10641 | "output arr[2] of float32' vs 'ptr to " |
| 10642 | "input arr[3] of float32'"); |
Chris Forbes | 0036fd1 | 2016-01-26 14:19:49 +1300 | [diff] [blame] | 10643 | |
| 10644 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 10645 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 10646 | |
| 10647 | char const *vsSource = |
Chris Forbes | 3846771 | 2016-04-04 17:28:05 +1200 | [diff] [blame] | 10648 | "#version 450\n" |
Chris Forbes | 0036fd1 | 2016-01-26 14:19:49 +1300 | [diff] [blame] | 10649 | "\n" |
| 10650 | "layout(location=0) out float x[2];\n" |
| 10651 | "out gl_PerVertex {\n" |
| 10652 | " vec4 gl_Position;\n" |
| 10653 | "};\n" |
| 10654 | "void main(){\n" |
| 10655 | " x[0] = 0; x[1] = 0;\n" |
| 10656 | " gl_Position = vec4(1);\n" |
| 10657 | "}\n"; |
| 10658 | char const *fsSource = |
Chris Forbes | 3846771 | 2016-04-04 17:28:05 +1200 | [diff] [blame] | 10659 | "#version 450\n" |
Chris Forbes | 0036fd1 | 2016-01-26 14:19:49 +1300 | [diff] [blame] | 10660 | "\n" |
| 10661 | "layout(location=0) in float x[3];\n" |
| 10662 | "layout(location=0) out vec4 color;\n" |
| 10663 | "void main(){\n" |
| 10664 | " color = vec4(x[0] + x[1] + x[2]);\n" |
| 10665 | "}\n"; |
| 10666 | |
| 10667 | VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this); |
| 10668 | VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this); |
| 10669 | |
| 10670 | VkPipelineObj pipe(m_device); |
| 10671 | pipe.AddColorAttachment(); |
| 10672 | pipe.AddShader(&vs); |
| 10673 | pipe.AddShader(&fs); |
| 10674 | |
| 10675 | VkDescriptorSetObj descriptorSet(m_device); |
| 10676 | descriptorSet.AppendDummy(); |
| 10677 | descriptorSet.CreateVKDescriptorSet(m_commandBuffer); |
| 10678 | |
| 10679 | pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass()); |
| 10680 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 10681 | m_errorMonitor->VerifyFound(); |
Chris Forbes | 0036fd1 | 2016-01-26 14:19:49 +1300 | [diff] [blame] | 10682 | } |
| 10683 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 10684 | TEST_F(VkLayerTest, CreatePipelineVsFsTypeMismatch) { |
Courtney Goeltzenleuchter | 7415d5a | 2015-12-09 15:48:16 -0700 | [diff] [blame] | 10685 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 10686 | "Type mismatch on location 0"); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 10687 | |
Chris Forbes | b56af56 | 2015-05-25 11:13:17 +1200 | [diff] [blame] | 10688 | ASSERT_NO_FATAL_FAILURE(InitState()); |
Tobin Ehlis | c9ac2b6 | 2015-09-11 12:57:55 -0600 | [diff] [blame] | 10689 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
Chris Forbes | b56af56 | 2015-05-25 11:13:17 +1200 | [diff] [blame] | 10690 | |
| 10691 | char const *vsSource = |
Chris Forbes | 3846771 | 2016-04-04 17:28:05 +1200 | [diff] [blame] | 10692 | "#version 450\n" |
Chris Forbes | b56af56 | 2015-05-25 11:13:17 +1200 | [diff] [blame] | 10693 | "\n" |
| 10694 | "layout(location=0) out int x;\n" |
Tony Barbour | e804d20 | 2016-01-05 13:37:45 -0700 | [diff] [blame] | 10695 | "out gl_PerVertex {\n" |
| 10696 | " vec4 gl_Position;\n" |
| 10697 | "};\n" |
Chris Forbes | b56af56 | 2015-05-25 11:13:17 +1200 | [diff] [blame] | 10698 | "void main(){\n" |
| 10699 | " x = 0;\n" |
| 10700 | " gl_Position = vec4(1);\n" |
| 10701 | "}\n"; |
| 10702 | char const *fsSource = |
Chris Forbes | 3846771 | 2016-04-04 17:28:05 +1200 | [diff] [blame] | 10703 | "#version 450\n" |
Chris Forbes | b56af56 | 2015-05-25 11:13:17 +1200 | [diff] [blame] | 10704 | "\n" |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 10705 | "layout(location=0) in float x;\n" /* VS writes int */ |
Chris Forbes | b56af56 | 2015-05-25 11:13:17 +1200 | [diff] [blame] | 10706 | "layout(location=0) out vec4 color;\n" |
| 10707 | "void main(){\n" |
| 10708 | " color = vec4(x);\n" |
| 10709 | "}\n"; |
| 10710 | |
Courtney Goeltzenleuchter | d263550 | 2015-10-21 17:08:06 -0600 | [diff] [blame] | 10711 | VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this); |
| 10712 | VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this); |
Chris Forbes | b56af56 | 2015-05-25 11:13:17 +1200 | [diff] [blame] | 10713 | |
| 10714 | VkPipelineObj pipe(m_device); |
Chia-I Wu | 08accc6 | 2015-07-07 11:50:03 +0800 | [diff] [blame] | 10715 | pipe.AddColorAttachment(); |
Chris Forbes | b56af56 | 2015-05-25 11:13:17 +1200 | [diff] [blame] | 10716 | pipe.AddShader(&vs); |
| 10717 | pipe.AddShader(&fs); |
| 10718 | |
Chris Forbes | b56af56 | 2015-05-25 11:13:17 +1200 | [diff] [blame] | 10719 | VkDescriptorSetObj descriptorSet(m_device); |
| 10720 | descriptorSet.AppendDummy(); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 10721 | descriptorSet.CreateVKDescriptorSet(m_commandBuffer); |
Chris Forbes | b56af56 | 2015-05-25 11:13:17 +1200 | [diff] [blame] | 10722 | |
Tony Barbour | 5781e8f | 2015-08-04 16:23:11 -0600 | [diff] [blame] | 10723 | pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass()); |
Chris Forbes | b56af56 | 2015-05-25 11:13:17 +1200 | [diff] [blame] | 10724 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 10725 | m_errorMonitor->VerifyFound(); |
Chris Forbes | b56af56 | 2015-05-25 11:13:17 +1200 | [diff] [blame] | 10726 | } |
| 10727 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 10728 | TEST_F(VkLayerTest, CreatePipelineVsFsTypeMismatchInBlock) { |
Chris Forbes | a3e85f6 | 2016-01-15 14:53:11 +1300 | [diff] [blame] | 10729 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 10730 | "Type mismatch on location 0"); |
Chris Forbes | a3e85f6 | 2016-01-15 14:53:11 +1300 | [diff] [blame] | 10731 | |
| 10732 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 10733 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 10734 | |
| 10735 | char const *vsSource = |
| 10736 | "#version 450\n" |
Chris Forbes | a3e85f6 | 2016-01-15 14:53:11 +1300 | [diff] [blame] | 10737 | "\n" |
| 10738 | "out block { layout(location=0) int x; } outs;\n" |
| 10739 | "out gl_PerVertex {\n" |
| 10740 | " vec4 gl_Position;\n" |
| 10741 | "};\n" |
| 10742 | "void main(){\n" |
| 10743 | " outs.x = 0;\n" |
| 10744 | " gl_Position = vec4(1);\n" |
| 10745 | "}\n"; |
| 10746 | char const *fsSource = |
| 10747 | "#version 450\n" |
Chris Forbes | a3e85f6 | 2016-01-15 14:53:11 +1300 | [diff] [blame] | 10748 | "\n" |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 10749 | "in block { layout(location=0) float x; } ins;\n" /* VS writes int */ |
Chris Forbes | a3e85f6 | 2016-01-15 14:53:11 +1300 | [diff] [blame] | 10750 | "layout(location=0) out vec4 color;\n" |
| 10751 | "void main(){\n" |
| 10752 | " color = vec4(ins.x);\n" |
| 10753 | "}\n"; |
| 10754 | |
| 10755 | VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this); |
| 10756 | VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this); |
| 10757 | |
| 10758 | VkPipelineObj pipe(m_device); |
| 10759 | pipe.AddColorAttachment(); |
| 10760 | pipe.AddShader(&vs); |
| 10761 | pipe.AddShader(&fs); |
| 10762 | |
| 10763 | VkDescriptorSetObj descriptorSet(m_device); |
| 10764 | descriptorSet.AppendDummy(); |
| 10765 | descriptorSet.CreateVKDescriptorSet(m_commandBuffer); |
| 10766 | |
| 10767 | pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass()); |
| 10768 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 10769 | m_errorMonitor->VerifyFound(); |
Chris Forbes | e992882 | 2016-02-17 14:44:52 +1300 | [diff] [blame] | 10770 | } |
| 10771 | |
| 10772 | TEST_F(VkLayerTest, CreatePipelineVsFsMismatchByLocation) { |
| 10773 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 10774 | "location 0.0 which is not written by vertex shader"); |
| 10775 | |
| 10776 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 10777 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 10778 | |
| 10779 | char const *vsSource = |
| 10780 | "#version 450\n" |
Chris Forbes | e992882 | 2016-02-17 14:44:52 +1300 | [diff] [blame] | 10781 | "\n" |
| 10782 | "out block { layout(location=1) float x; } outs;\n" |
| 10783 | "out gl_PerVertex {\n" |
| 10784 | " vec4 gl_Position;\n" |
| 10785 | "};\n" |
| 10786 | "void main(){\n" |
| 10787 | " outs.x = 0;\n" |
| 10788 | " gl_Position = vec4(1);\n" |
| 10789 | "}\n"; |
| 10790 | char const *fsSource = |
| 10791 | "#version 450\n" |
Chris Forbes | e992882 | 2016-02-17 14:44:52 +1300 | [diff] [blame] | 10792 | "\n" |
| 10793 | "in block { layout(location=0) float x; } ins;\n" |
| 10794 | "layout(location=0) out vec4 color;\n" |
| 10795 | "void main(){\n" |
| 10796 | " color = vec4(ins.x);\n" |
| 10797 | "}\n"; |
| 10798 | |
| 10799 | VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this); |
| 10800 | VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this); |
| 10801 | |
| 10802 | VkPipelineObj pipe(m_device); |
| 10803 | pipe.AddColorAttachment(); |
| 10804 | pipe.AddShader(&vs); |
| 10805 | pipe.AddShader(&fs); |
| 10806 | |
| 10807 | VkDescriptorSetObj descriptorSet(m_device); |
| 10808 | descriptorSet.AppendDummy(); |
| 10809 | descriptorSet.CreateVKDescriptorSet(m_commandBuffer); |
| 10810 | |
| 10811 | pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass()); |
| 10812 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 10813 | m_errorMonitor->VerifyFound(); |
Chris Forbes | e992882 | 2016-02-17 14:44:52 +1300 | [diff] [blame] | 10814 | } |
| 10815 | |
| 10816 | TEST_F(VkLayerTest, CreatePipelineVsFsMismatchByComponent) { |
| 10817 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 10818 | "location 0.1 which is not written by vertex shader"); |
| 10819 | |
| 10820 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 10821 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 10822 | |
| 10823 | char const *vsSource = |
| 10824 | "#version 450\n" |
Chris Forbes | e992882 | 2016-02-17 14:44:52 +1300 | [diff] [blame] | 10825 | "\n" |
| 10826 | "out block { layout(location=0, component=0) float x; } outs;\n" |
| 10827 | "out gl_PerVertex {\n" |
| 10828 | " vec4 gl_Position;\n" |
| 10829 | "};\n" |
| 10830 | "void main(){\n" |
| 10831 | " outs.x = 0;\n" |
| 10832 | " gl_Position = vec4(1);\n" |
| 10833 | "}\n"; |
| 10834 | char const *fsSource = |
| 10835 | "#version 450\n" |
Chris Forbes | e992882 | 2016-02-17 14:44:52 +1300 | [diff] [blame] | 10836 | "\n" |
| 10837 | "in block { layout(location=0, component=1) float x; } ins;\n" |
| 10838 | "layout(location=0) out vec4 color;\n" |
| 10839 | "void main(){\n" |
| 10840 | " color = vec4(ins.x);\n" |
| 10841 | "}\n"; |
| 10842 | |
| 10843 | VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this); |
| 10844 | VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this); |
| 10845 | |
| 10846 | VkPipelineObj pipe(m_device); |
| 10847 | pipe.AddColorAttachment(); |
| 10848 | pipe.AddShader(&vs); |
| 10849 | pipe.AddShader(&fs); |
| 10850 | |
| 10851 | VkDescriptorSetObj descriptorSet(m_device); |
| 10852 | descriptorSet.AppendDummy(); |
| 10853 | descriptorSet.CreateVKDescriptorSet(m_commandBuffer); |
| 10854 | |
| 10855 | pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass()); |
| 10856 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 10857 | m_errorMonitor->VerifyFound(); |
Chris Forbes | a3e85f6 | 2016-01-15 14:53:11 +1300 | [diff] [blame] | 10858 | } |
| 10859 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 10860 | TEST_F(VkLayerTest, CreatePipelineAttribNotConsumed) { |
Mark Lobodzinski | 510e20d | 2016-02-11 09:26:16 -0700 | [diff] [blame] | 10861 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 10862 | "location 0 not consumed by VS"); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 10863 | |
Chris Forbes | de136e0 | 2015-05-25 11:13:28 +1200 | [diff] [blame] | 10864 | ASSERT_NO_FATAL_FAILURE(InitState()); |
Tobin Ehlis | c9ac2b6 | 2015-09-11 12:57:55 -0600 | [diff] [blame] | 10865 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
Chris Forbes | de136e0 | 2015-05-25 11:13:28 +1200 | [diff] [blame] | 10866 | |
| 10867 | VkVertexInputBindingDescription input_binding; |
| 10868 | memset(&input_binding, 0, sizeof(input_binding)); |
| 10869 | |
| 10870 | VkVertexInputAttributeDescription input_attrib; |
| 10871 | memset(&input_attrib, 0, sizeof(input_attrib)); |
| 10872 | input_attrib.format = VK_FORMAT_R32_SFLOAT; |
| 10873 | |
| 10874 | char const *vsSource = |
Chris Forbes | 3846771 | 2016-04-04 17:28:05 +1200 | [diff] [blame] | 10875 | "#version 450\n" |
Chris Forbes | de136e0 | 2015-05-25 11:13:28 +1200 | [diff] [blame] | 10876 | "\n" |
Tony Barbour | e804d20 | 2016-01-05 13:37:45 -0700 | [diff] [blame] | 10877 | "out gl_PerVertex {\n" |
| 10878 | " vec4 gl_Position;\n" |
| 10879 | "};\n" |
Chris Forbes | de136e0 | 2015-05-25 11:13:28 +1200 | [diff] [blame] | 10880 | "void main(){\n" |
| 10881 | " gl_Position = vec4(1);\n" |
| 10882 | "}\n"; |
| 10883 | char const *fsSource = |
Chris Forbes | 3846771 | 2016-04-04 17:28:05 +1200 | [diff] [blame] | 10884 | "#version 450\n" |
Chris Forbes | de136e0 | 2015-05-25 11:13:28 +1200 | [diff] [blame] | 10885 | "\n" |
| 10886 | "layout(location=0) out vec4 color;\n" |
| 10887 | "void main(){\n" |
| 10888 | " color = vec4(1);\n" |
| 10889 | "}\n"; |
| 10890 | |
Courtney Goeltzenleuchter | d263550 | 2015-10-21 17:08:06 -0600 | [diff] [blame] | 10891 | VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this); |
| 10892 | VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this); |
Chris Forbes | de136e0 | 2015-05-25 11:13:28 +1200 | [diff] [blame] | 10893 | |
| 10894 | VkPipelineObj pipe(m_device); |
Chia-I Wu | 08accc6 | 2015-07-07 11:50:03 +0800 | [diff] [blame] | 10895 | pipe.AddColorAttachment(); |
Chris Forbes | de136e0 | 2015-05-25 11:13:28 +1200 | [diff] [blame] | 10896 | pipe.AddShader(&vs); |
| 10897 | pipe.AddShader(&fs); |
| 10898 | |
| 10899 | pipe.AddVertexInputBindings(&input_binding, 1); |
| 10900 | pipe.AddVertexInputAttribs(&input_attrib, 1); |
| 10901 | |
Chris Forbes | de136e0 | 2015-05-25 11:13:28 +1200 | [diff] [blame] | 10902 | VkDescriptorSetObj descriptorSet(m_device); |
| 10903 | descriptorSet.AppendDummy(); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 10904 | descriptorSet.CreateVKDescriptorSet(m_commandBuffer); |
Chris Forbes | de136e0 | 2015-05-25 11:13:28 +1200 | [diff] [blame] | 10905 | |
Tony Barbour | 5781e8f | 2015-08-04 16:23:11 -0600 | [diff] [blame] | 10906 | pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass()); |
Chris Forbes | de136e0 | 2015-05-25 11:13:28 +1200 | [diff] [blame] | 10907 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 10908 | m_errorMonitor->VerifyFound(); |
Chris Forbes | de136e0 | 2015-05-25 11:13:28 +1200 | [diff] [blame] | 10909 | } |
| 10910 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 10911 | TEST_F(VkLayerTest, CreatePipelineAttribLocationMismatch) { |
Mark Lobodzinski | 510e20d | 2016-02-11 09:26:16 -0700 | [diff] [blame] | 10912 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 10913 | "location 0 not consumed by VS"); |
Chris Forbes | 7d83cd5 | 2016-01-15 11:32:03 +1300 | [diff] [blame] | 10914 | |
| 10915 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 10916 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 10917 | |
| 10918 | VkVertexInputBindingDescription input_binding; |
| 10919 | memset(&input_binding, 0, sizeof(input_binding)); |
| 10920 | |
| 10921 | VkVertexInputAttributeDescription input_attrib; |
| 10922 | memset(&input_attrib, 0, sizeof(input_attrib)); |
| 10923 | input_attrib.format = VK_FORMAT_R32_SFLOAT; |
| 10924 | |
| 10925 | char const *vsSource = |
Chris Forbes | 3846771 | 2016-04-04 17:28:05 +1200 | [diff] [blame] | 10926 | "#version 450\n" |
Chris Forbes | 7d83cd5 | 2016-01-15 11:32:03 +1300 | [diff] [blame] | 10927 | "\n" |
| 10928 | "layout(location=1) in float x;\n" |
| 10929 | "out gl_PerVertex {\n" |
| 10930 | " vec4 gl_Position;\n" |
| 10931 | "};\n" |
| 10932 | "void main(){\n" |
| 10933 | " gl_Position = vec4(x);\n" |
| 10934 | "}\n"; |
| 10935 | char const *fsSource = |
Chris Forbes | 3846771 | 2016-04-04 17:28:05 +1200 | [diff] [blame] | 10936 | "#version 450\n" |
Chris Forbes | 7d83cd5 | 2016-01-15 11:32:03 +1300 | [diff] [blame] | 10937 | "\n" |
| 10938 | "layout(location=0) out vec4 color;\n" |
| 10939 | "void main(){\n" |
| 10940 | " color = vec4(1);\n" |
| 10941 | "}\n"; |
| 10942 | |
| 10943 | VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this); |
| 10944 | VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this); |
| 10945 | |
| 10946 | VkPipelineObj pipe(m_device); |
| 10947 | pipe.AddColorAttachment(); |
| 10948 | pipe.AddShader(&vs); |
| 10949 | pipe.AddShader(&fs); |
| 10950 | |
| 10951 | pipe.AddVertexInputBindings(&input_binding, 1); |
| 10952 | pipe.AddVertexInputAttribs(&input_attrib, 1); |
| 10953 | |
| 10954 | VkDescriptorSetObj descriptorSet(m_device); |
| 10955 | descriptorSet.AppendDummy(); |
| 10956 | descriptorSet.CreateVKDescriptorSet(m_commandBuffer); |
| 10957 | |
| 10958 | pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass()); |
| 10959 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 10960 | m_errorMonitor->VerifyFound(); |
Chris Forbes | 7d83cd5 | 2016-01-15 11:32:03 +1300 | [diff] [blame] | 10961 | } |
| 10962 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 10963 | TEST_F(VkLayerTest, CreatePipelineAttribNotProvided) { |
| 10964 | m_errorMonitor->SetDesiredFailureMsg( |
| 10965 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 10966 | "VS consumes input at location 0 but not provided"); |
| 10967 | |
Chris Forbes | 62e8e50 | 2015-05-25 11:13:29 +1200 | [diff] [blame] | 10968 | ASSERT_NO_FATAL_FAILURE(InitState()); |
Tobin Ehlis | c9ac2b6 | 2015-09-11 12:57:55 -0600 | [diff] [blame] | 10969 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
Chris Forbes | 62e8e50 | 2015-05-25 11:13:29 +1200 | [diff] [blame] | 10970 | |
| 10971 | char const *vsSource = |
Chris Forbes | 3846771 | 2016-04-04 17:28:05 +1200 | [diff] [blame] | 10972 | "#version 450\n" |
Chris Forbes | 62e8e50 | 2015-05-25 11:13:29 +1200 | [diff] [blame] | 10973 | "\n" |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 10974 | "layout(location=0) in vec4 x;\n" /* not provided */ |
Tony Barbour | e804d20 | 2016-01-05 13:37:45 -0700 | [diff] [blame] | 10975 | "out gl_PerVertex {\n" |
| 10976 | " vec4 gl_Position;\n" |
| 10977 | "};\n" |
Chris Forbes | 62e8e50 | 2015-05-25 11:13:29 +1200 | [diff] [blame] | 10978 | "void main(){\n" |
| 10979 | " gl_Position = x;\n" |
| 10980 | "}\n"; |
| 10981 | char const *fsSource = |
Chris Forbes | 3846771 | 2016-04-04 17:28:05 +1200 | [diff] [blame] | 10982 | "#version 450\n" |
Chris Forbes | 62e8e50 | 2015-05-25 11:13:29 +1200 | [diff] [blame] | 10983 | "\n" |
| 10984 | "layout(location=0) out vec4 color;\n" |
| 10985 | "void main(){\n" |
| 10986 | " color = vec4(1);\n" |
| 10987 | "}\n"; |
| 10988 | |
Courtney Goeltzenleuchter | d263550 | 2015-10-21 17:08:06 -0600 | [diff] [blame] | 10989 | VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this); |
| 10990 | VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this); |
Chris Forbes | 62e8e50 | 2015-05-25 11:13:29 +1200 | [diff] [blame] | 10991 | |
| 10992 | VkPipelineObj pipe(m_device); |
Chia-I Wu | 08accc6 | 2015-07-07 11:50:03 +0800 | [diff] [blame] | 10993 | pipe.AddColorAttachment(); |
Chris Forbes | 62e8e50 | 2015-05-25 11:13:29 +1200 | [diff] [blame] | 10994 | pipe.AddShader(&vs); |
| 10995 | pipe.AddShader(&fs); |
| 10996 | |
Chris Forbes | 62e8e50 | 2015-05-25 11:13:29 +1200 | [diff] [blame] | 10997 | VkDescriptorSetObj descriptorSet(m_device); |
| 10998 | descriptorSet.AppendDummy(); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 10999 | descriptorSet.CreateVKDescriptorSet(m_commandBuffer); |
Chris Forbes | 62e8e50 | 2015-05-25 11:13:29 +1200 | [diff] [blame] | 11000 | |
Tony Barbour | 5781e8f | 2015-08-04 16:23:11 -0600 | [diff] [blame] | 11001 | pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass()); |
Chris Forbes | 62e8e50 | 2015-05-25 11:13:29 +1200 | [diff] [blame] | 11002 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 11003 | m_errorMonitor->VerifyFound(); |
Chris Forbes | 62e8e50 | 2015-05-25 11:13:29 +1200 | [diff] [blame] | 11004 | } |
| 11005 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 11006 | TEST_F(VkLayerTest, CreatePipelineAttribTypeMismatch) { |
| 11007 | m_errorMonitor->SetDesiredFailureMsg( |
| 11008 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 11009 | "location 0 does not match VS input type"); |
| 11010 | |
Chris Forbes | c97d98e | 2015-05-25 11:13:31 +1200 | [diff] [blame] | 11011 | ASSERT_NO_FATAL_FAILURE(InitState()); |
Tobin Ehlis | c9ac2b6 | 2015-09-11 12:57:55 -0600 | [diff] [blame] | 11012 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
Chris Forbes | c97d98e | 2015-05-25 11:13:31 +1200 | [diff] [blame] | 11013 | |
| 11014 | VkVertexInputBindingDescription input_binding; |
| 11015 | memset(&input_binding, 0, sizeof(input_binding)); |
| 11016 | |
| 11017 | VkVertexInputAttributeDescription input_attrib; |
| 11018 | memset(&input_attrib, 0, sizeof(input_attrib)); |
| 11019 | input_attrib.format = VK_FORMAT_R32_SFLOAT; |
| 11020 | |
| 11021 | char const *vsSource = |
Chris Forbes | 3846771 | 2016-04-04 17:28:05 +1200 | [diff] [blame] | 11022 | "#version 450\n" |
Chris Forbes | c97d98e | 2015-05-25 11:13:31 +1200 | [diff] [blame] | 11023 | "\n" |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 11024 | "layout(location=0) in int x;\n" /* attrib provided float */ |
Tony Barbour | e804d20 | 2016-01-05 13:37:45 -0700 | [diff] [blame] | 11025 | "out gl_PerVertex {\n" |
| 11026 | " vec4 gl_Position;\n" |
| 11027 | "};\n" |
Chris Forbes | c97d98e | 2015-05-25 11:13:31 +1200 | [diff] [blame] | 11028 | "void main(){\n" |
| 11029 | " gl_Position = vec4(x);\n" |
| 11030 | "}\n"; |
| 11031 | char const *fsSource = |
Chris Forbes | 3846771 | 2016-04-04 17:28:05 +1200 | [diff] [blame] | 11032 | "#version 450\n" |
Chris Forbes | c97d98e | 2015-05-25 11:13:31 +1200 | [diff] [blame] | 11033 | "\n" |
| 11034 | "layout(location=0) out vec4 color;\n" |
| 11035 | "void main(){\n" |
| 11036 | " color = vec4(1);\n" |
| 11037 | "}\n"; |
| 11038 | |
Courtney Goeltzenleuchter | d263550 | 2015-10-21 17:08:06 -0600 | [diff] [blame] | 11039 | VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this); |
| 11040 | VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this); |
Chris Forbes | c97d98e | 2015-05-25 11:13:31 +1200 | [diff] [blame] | 11041 | |
| 11042 | VkPipelineObj pipe(m_device); |
Chia-I Wu | 08accc6 | 2015-07-07 11:50:03 +0800 | [diff] [blame] | 11043 | pipe.AddColorAttachment(); |
Chris Forbes | c97d98e | 2015-05-25 11:13:31 +1200 | [diff] [blame] | 11044 | pipe.AddShader(&vs); |
| 11045 | pipe.AddShader(&fs); |
| 11046 | |
| 11047 | pipe.AddVertexInputBindings(&input_binding, 1); |
| 11048 | pipe.AddVertexInputAttribs(&input_attrib, 1); |
| 11049 | |
Chris Forbes | c97d98e | 2015-05-25 11:13:31 +1200 | [diff] [blame] | 11050 | VkDescriptorSetObj descriptorSet(m_device); |
| 11051 | descriptorSet.AppendDummy(); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 11052 | descriptorSet.CreateVKDescriptorSet(m_commandBuffer); |
Chris Forbes | c97d98e | 2015-05-25 11:13:31 +1200 | [diff] [blame] | 11053 | |
Tony Barbour | 5781e8f | 2015-08-04 16:23:11 -0600 | [diff] [blame] | 11054 | pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass()); |
Chris Forbes | c97d98e | 2015-05-25 11:13:31 +1200 | [diff] [blame] | 11055 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 11056 | m_errorMonitor->VerifyFound(); |
Chris Forbes | c97d98e | 2015-05-25 11:13:31 +1200 | [diff] [blame] | 11057 | } |
| 11058 | |
Chris Forbes | c68b43c | 2016-04-06 11:18:47 +1200 | [diff] [blame] | 11059 | TEST_F(VkLayerTest, CreatePipelineDuplicateStage) { |
| 11060 | m_errorMonitor->SetDesiredFailureMsg( |
| 11061 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 11062 | "Multiple shaders provided for stage VK_SHADER_STAGE_VERTEX_BIT"); |
| 11063 | |
| 11064 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 11065 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 11066 | |
| 11067 | char const *vsSource = |
| 11068 | "#version 450\n" |
| 11069 | "\n" |
| 11070 | "out gl_PerVertex {\n" |
| 11071 | " vec4 gl_Position;\n" |
| 11072 | "};\n" |
| 11073 | "void main(){\n" |
| 11074 | " gl_Position = vec4(1);\n" |
| 11075 | "}\n"; |
| 11076 | char const *fsSource = |
| 11077 | "#version 450\n" |
| 11078 | "\n" |
| 11079 | "layout(location=0) out vec4 color;\n" |
| 11080 | "void main(){\n" |
| 11081 | " color = vec4(1);\n" |
| 11082 | "}\n"; |
| 11083 | |
| 11084 | VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this); |
| 11085 | VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this); |
| 11086 | |
| 11087 | VkPipelineObj pipe(m_device); |
| 11088 | pipe.AddColorAttachment(); |
| 11089 | pipe.AddShader(&vs); |
| 11090 | pipe.AddShader(&vs); |
| 11091 | pipe.AddShader(&fs); |
| 11092 | |
| 11093 | VkDescriptorSetObj descriptorSet(m_device); |
| 11094 | descriptorSet.AppendDummy(); |
| 11095 | descriptorSet.CreateVKDescriptorSet(m_commandBuffer); |
| 11096 | |
| 11097 | pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass()); |
| 11098 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 11099 | m_errorMonitor->VerifyFound(); |
Chris Forbes | c68b43c | 2016-04-06 11:18:47 +1200 | [diff] [blame] | 11100 | } |
| 11101 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 11102 | TEST_F(VkLayerTest, CreatePipelineAttribMatrixType) { |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 11103 | m_errorMonitor->ExpectSuccess(); |
Chris Forbes | 2682b24 | 2015-11-24 11:13:14 +1300 | [diff] [blame] | 11104 | |
| 11105 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 11106 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 11107 | |
| 11108 | VkVertexInputBindingDescription input_binding; |
| 11109 | memset(&input_binding, 0, sizeof(input_binding)); |
| 11110 | |
| 11111 | VkVertexInputAttributeDescription input_attribs[2]; |
| 11112 | memset(input_attribs, 0, sizeof(input_attribs)); |
| 11113 | |
| 11114 | for (int i = 0; i < 2; i++) { |
| 11115 | input_attribs[i].format = VK_FORMAT_R32G32B32A32_SFLOAT; |
| 11116 | input_attribs[i].location = i; |
| 11117 | } |
| 11118 | |
| 11119 | char const *vsSource = |
Chris Forbes | 3846771 | 2016-04-04 17:28:05 +1200 | [diff] [blame] | 11120 | "#version 450\n" |
Chris Forbes | 2682b24 | 2015-11-24 11:13:14 +1300 | [diff] [blame] | 11121 | "\n" |
| 11122 | "layout(location=0) in mat2x4 x;\n" |
Tony Barbour | e804d20 | 2016-01-05 13:37:45 -0700 | [diff] [blame] | 11123 | "out gl_PerVertex {\n" |
| 11124 | " vec4 gl_Position;\n" |
| 11125 | "};\n" |
Chris Forbes | 2682b24 | 2015-11-24 11:13:14 +1300 | [diff] [blame] | 11126 | "void main(){\n" |
| 11127 | " gl_Position = x[0] + x[1];\n" |
| 11128 | "}\n"; |
| 11129 | char const *fsSource = |
Chris Forbes | 3846771 | 2016-04-04 17:28:05 +1200 | [diff] [blame] | 11130 | "#version 450\n" |
Chris Forbes | 2682b24 | 2015-11-24 11:13:14 +1300 | [diff] [blame] | 11131 | "\n" |
| 11132 | "layout(location=0) out vec4 color;\n" |
| 11133 | "void main(){\n" |
| 11134 | " color = vec4(1);\n" |
| 11135 | "}\n"; |
| 11136 | |
| 11137 | VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this); |
| 11138 | VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this); |
| 11139 | |
| 11140 | VkPipelineObj pipe(m_device); |
| 11141 | pipe.AddColorAttachment(); |
| 11142 | pipe.AddShader(&vs); |
| 11143 | pipe.AddShader(&fs); |
| 11144 | |
| 11145 | pipe.AddVertexInputBindings(&input_binding, 1); |
| 11146 | pipe.AddVertexInputAttribs(input_attribs, 2); |
| 11147 | |
| 11148 | VkDescriptorSetObj descriptorSet(m_device); |
| 11149 | descriptorSet.AppendDummy(); |
| 11150 | descriptorSet.CreateVKDescriptorSet(m_commandBuffer); |
| 11151 | |
| 11152 | pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass()); |
| 11153 | |
| 11154 | /* expect success */ |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 11155 | m_errorMonitor->VerifyNotFound(); |
Chris Forbes | 2682b24 | 2015-11-24 11:13:14 +1300 | [diff] [blame] | 11156 | } |
| 11157 | |
Chris Forbes | 2682b24 | 2015-11-24 11:13:14 +1300 | [diff] [blame] | 11158 | TEST_F(VkLayerTest, CreatePipelineAttribArrayType) |
| 11159 | { |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 11160 | m_errorMonitor->ExpectSuccess(); |
Chris Forbes | 2682b24 | 2015-11-24 11:13:14 +1300 | [diff] [blame] | 11161 | |
| 11162 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 11163 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 11164 | |
| 11165 | VkVertexInputBindingDescription input_binding; |
| 11166 | memset(&input_binding, 0, sizeof(input_binding)); |
| 11167 | |
| 11168 | VkVertexInputAttributeDescription input_attribs[2]; |
| 11169 | memset(input_attribs, 0, sizeof(input_attribs)); |
| 11170 | |
| 11171 | for (int i = 0; i < 2; i++) { |
| 11172 | input_attribs[i].format = VK_FORMAT_R32G32B32A32_SFLOAT; |
| 11173 | input_attribs[i].location = i; |
| 11174 | } |
| 11175 | |
| 11176 | char const *vsSource = |
Chris Forbes | 3846771 | 2016-04-04 17:28:05 +1200 | [diff] [blame] | 11177 | "#version 450\n" |
Chris Forbes | 2682b24 | 2015-11-24 11:13:14 +1300 | [diff] [blame] | 11178 | "\n" |
| 11179 | "layout(location=0) in vec4 x[2];\n" |
Tony Barbour | e804d20 | 2016-01-05 13:37:45 -0700 | [diff] [blame] | 11180 | "out gl_PerVertex {\n" |
| 11181 | " vec4 gl_Position;\n" |
| 11182 | "};\n" |
Chris Forbes | 2682b24 | 2015-11-24 11:13:14 +1300 | [diff] [blame] | 11183 | "void main(){\n" |
| 11184 | " gl_Position = x[0] + x[1];\n" |
| 11185 | "}\n"; |
| 11186 | char const *fsSource = |
Chris Forbes | 3846771 | 2016-04-04 17:28:05 +1200 | [diff] [blame] | 11187 | "#version 450\n" |
Chris Forbes | 2682b24 | 2015-11-24 11:13:14 +1300 | [diff] [blame] | 11188 | "\n" |
| 11189 | "layout(location=0) out vec4 color;\n" |
| 11190 | "void main(){\n" |
| 11191 | " color = vec4(1);\n" |
| 11192 | "}\n"; |
| 11193 | |
| 11194 | VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this); |
| 11195 | VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this); |
| 11196 | |
| 11197 | VkPipelineObj pipe(m_device); |
| 11198 | pipe.AddColorAttachment(); |
| 11199 | pipe.AddShader(&vs); |
| 11200 | pipe.AddShader(&fs); |
| 11201 | |
| 11202 | pipe.AddVertexInputBindings(&input_binding, 1); |
| 11203 | pipe.AddVertexInputAttribs(input_attribs, 2); |
| 11204 | |
| 11205 | VkDescriptorSetObj descriptorSet(m_device); |
| 11206 | descriptorSet.AppendDummy(); |
| 11207 | descriptorSet.CreateVKDescriptorSet(m_commandBuffer); |
| 11208 | |
| 11209 | pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass()); |
| 11210 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 11211 | m_errorMonitor->VerifyNotFound(); |
Chris Forbes | 2682b24 | 2015-11-24 11:13:14 +1300 | [diff] [blame] | 11212 | } |
Chris Forbes | 2682b24 | 2015-11-24 11:13:14 +1300 | [diff] [blame] | 11213 | |
Chris Forbes | 4ea14fc | 2016-04-04 18:52:54 +1200 | [diff] [blame] | 11214 | TEST_F(VkLayerTest, CreatePipelineSimplePositive) |
| 11215 | { |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 11216 | m_errorMonitor->ExpectSuccess(); |
Chris Forbes | 4ea14fc | 2016-04-04 18:52:54 +1200 | [diff] [blame] | 11217 | |
| 11218 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 11219 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 11220 | |
| 11221 | char const *vsSource = |
| 11222 | "#version 450\n" |
| 11223 | "out gl_PerVertex {\n" |
| 11224 | " vec4 gl_Position;\n" |
| 11225 | "};\n" |
| 11226 | "void main(){\n" |
| 11227 | " gl_Position = vec4(0);\n" |
| 11228 | "}\n"; |
| 11229 | char const *fsSource = |
| 11230 | "#version 450\n" |
| 11231 | "\n" |
| 11232 | "layout(location=0) out vec4 color;\n" |
| 11233 | "void main(){\n" |
| 11234 | " color = vec4(1);\n" |
| 11235 | "}\n"; |
| 11236 | |
| 11237 | VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this); |
| 11238 | VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this); |
| 11239 | |
| 11240 | VkPipelineObj pipe(m_device); |
| 11241 | pipe.AddColorAttachment(); |
| 11242 | pipe.AddShader(&vs); |
| 11243 | pipe.AddShader(&fs); |
| 11244 | |
| 11245 | VkDescriptorSetObj descriptorSet(m_device); |
| 11246 | descriptorSet.AppendDummy(); |
| 11247 | descriptorSet.CreateVKDescriptorSet(m_commandBuffer); |
| 11248 | |
| 11249 | pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass()); |
| 11250 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 11251 | m_errorMonitor->VerifyNotFound(); |
Chris Forbes | 4ea14fc | 2016-04-04 18:52:54 +1200 | [diff] [blame] | 11252 | } |
| 11253 | |
Chris Forbes | 912c919 | 2016-04-05 17:50:35 +1200 | [diff] [blame] | 11254 | TEST_F(VkLayerTest, CreatePipelineRelaxedTypeMatch) |
| 11255 | { |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 11256 | m_errorMonitor->ExpectSuccess(); |
Chris Forbes | 912c919 | 2016-04-05 17:50:35 +1200 | [diff] [blame] | 11257 | |
| 11258 | // VK 1.0.8 Specification, 14.1.3 "Additionally,..." block |
| 11259 | |
| 11260 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 11261 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 11262 | |
| 11263 | char const *vsSource = |
| 11264 | "#version 450\n" |
| 11265 | "out gl_PerVertex {\n" |
| 11266 | " vec4 gl_Position;\n" |
| 11267 | "};\n" |
| 11268 | "layout(location=0) out vec3 x;\n" |
| 11269 | "layout(location=1) out ivec3 y;\n" |
| 11270 | "layout(location=2) out vec3 z;\n" |
| 11271 | "void main(){\n" |
| 11272 | " gl_Position = vec4(0);\n" |
| 11273 | " x = vec3(0); y = ivec3(0); z = vec3(0);\n" |
| 11274 | "}\n"; |
| 11275 | char const *fsSource = |
| 11276 | "#version 450\n" |
| 11277 | "\n" |
| 11278 | "layout(location=0) out vec4 color;\n" |
| 11279 | "layout(location=0) in float x;\n" |
| 11280 | "layout(location=1) flat in int y;\n" |
| 11281 | "layout(location=2) in vec2 z;\n" |
| 11282 | "void main(){\n" |
| 11283 | " color = vec4(1 + x + y + z.x);\n" |
| 11284 | "}\n"; |
| 11285 | |
| 11286 | VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this); |
| 11287 | VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this); |
| 11288 | |
| 11289 | VkPipelineObj pipe(m_device); |
| 11290 | pipe.AddColorAttachment(); |
| 11291 | pipe.AddShader(&vs); |
| 11292 | pipe.AddShader(&fs); |
| 11293 | |
| 11294 | VkDescriptorSetObj descriptorSet(m_device); |
| 11295 | descriptorSet.AppendDummy(); |
| 11296 | descriptorSet.CreateVKDescriptorSet(m_commandBuffer); |
| 11297 | |
Mike Stroyan | 255e958 | 2016-06-24 09:49:32 -0600 | [diff] [blame] | 11298 | VkResult err = VK_SUCCESS; |
| 11299 | err = |
| 11300 | pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass()); |
| 11301 | ASSERT_VK_SUCCESS(err); |
| 11302 | |
Chris Forbes | 912c919 | 2016-04-05 17:50:35 +1200 | [diff] [blame] | 11303 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 11304 | m_errorMonitor->VerifyNotFound(); |
Chris Forbes | 912c919 | 2016-04-05 17:50:35 +1200 | [diff] [blame] | 11305 | } |
| 11306 | |
Chris Forbes | 4ea14fc | 2016-04-04 18:52:54 +1200 | [diff] [blame] | 11307 | TEST_F(VkLayerTest, CreatePipelineTessPerVertex) |
| 11308 | { |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 11309 | m_errorMonitor->ExpectSuccess(); |
Chris Forbes | 4ea14fc | 2016-04-04 18:52:54 +1200 | [diff] [blame] | 11310 | |
| 11311 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 11312 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 11313 | |
Chris Forbes | c1e852d | 2016-04-04 19:26:42 +1200 | [diff] [blame] | 11314 | if (!m_device->phy().features().tessellationShader) { |
| 11315 | printf("Device does not support tessellation shaders; skipped.\n"); |
| 11316 | return; |
| 11317 | } |
| 11318 | |
Chris Forbes | 4ea14fc | 2016-04-04 18:52:54 +1200 | [diff] [blame] | 11319 | char const *vsSource = |
| 11320 | "#version 450\n" |
| 11321 | "void main(){}\n"; |
| 11322 | char const *tcsSource = |
| 11323 | "#version 450\n" |
| 11324 | "layout(location=0) out int x[];\n" |
| 11325 | "layout(vertices=3) out;\n" |
| 11326 | "void main(){\n" |
| 11327 | " gl_TessLevelOuter[0] = gl_TessLevelOuter[1] = gl_TessLevelOuter[2] = 1;\n" |
| 11328 | " gl_TessLevelInner[0] = 1;\n" |
| 11329 | " x[gl_InvocationID] = gl_InvocationID;\n" |
| 11330 | "}\n"; |
| 11331 | char const *tesSource = |
| 11332 | "#version 450\n" |
| 11333 | "layout(triangles, equal_spacing, cw) in;\n" |
| 11334 | "layout(location=0) in int x[];\n" |
| 11335 | "out gl_PerVertex { vec4 gl_Position; };\n" |
| 11336 | "void main(){\n" |
| 11337 | " gl_Position.xyz = gl_TessCoord;\n" |
| 11338 | " gl_Position.w = x[0] + x[1] + x[2];\n" |
| 11339 | "}\n"; |
| 11340 | char const *fsSource = |
| 11341 | "#version 450\n" |
| 11342 | "layout(location=0) out vec4 color;\n" |
| 11343 | "void main(){\n" |
| 11344 | " color = vec4(1);\n" |
| 11345 | "}\n"; |
| 11346 | |
| 11347 | VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this); |
| 11348 | VkShaderObj tcs(m_device, tcsSource, VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT, this); |
| 11349 | VkShaderObj tes(m_device, tesSource, VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT, this); |
| 11350 | VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this); |
| 11351 | |
| 11352 | VkPipelineInputAssemblyStateCreateInfo iasci{ |
| 11353 | VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO, |
| 11354 | nullptr, |
| 11355 | 0, |
| 11356 | VK_PRIMITIVE_TOPOLOGY_PATCH_LIST, |
| 11357 | VK_FALSE}; |
| 11358 | |
Chris Forbes | b4cacb6 | 2016-04-04 19:15:00 +1200 | [diff] [blame] | 11359 | VkPipelineTessellationStateCreateInfo tsci{ |
| 11360 | VK_STRUCTURE_TYPE_PIPELINE_TESSELLATION_STATE_CREATE_INFO, |
| 11361 | nullptr, |
| 11362 | 0, |
| 11363 | 3}; |
| 11364 | |
Chris Forbes | 4ea14fc | 2016-04-04 18:52:54 +1200 | [diff] [blame] | 11365 | VkPipelineObj pipe(m_device); |
| 11366 | pipe.SetInputAssembly(&iasci); |
Chris Forbes | b4cacb6 | 2016-04-04 19:15:00 +1200 | [diff] [blame] | 11367 | pipe.SetTessellation(&tsci); |
Chris Forbes | 4ea14fc | 2016-04-04 18:52:54 +1200 | [diff] [blame] | 11368 | pipe.AddColorAttachment(); |
| 11369 | pipe.AddShader(&vs); |
| 11370 | pipe.AddShader(&tcs); |
| 11371 | pipe.AddShader(&tes); |
| 11372 | pipe.AddShader(&fs); |
| 11373 | |
| 11374 | VkDescriptorSetObj descriptorSet(m_device); |
| 11375 | descriptorSet.AppendDummy(); |
| 11376 | descriptorSet.CreateVKDescriptorSet(m_commandBuffer); |
| 11377 | |
| 11378 | pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass()); |
| 11379 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 11380 | m_errorMonitor->VerifyNotFound(); |
Chris Forbes | 4ea14fc | 2016-04-04 18:52:54 +1200 | [diff] [blame] | 11381 | } |
| 11382 | |
Chris Forbes | a0ab815 | 2016-04-20 13:34:27 +1200 | [diff] [blame] | 11383 | TEST_F(VkLayerTest, CreatePipelineGeometryInputBlockPositive) |
| 11384 | { |
| 11385 | m_errorMonitor->ExpectSuccess(); |
| 11386 | |
| 11387 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 11388 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 11389 | |
| 11390 | if (!m_device->phy().features().geometryShader) { |
| 11391 | printf("Device does not support geometry shaders; skipped.\n"); |
| 11392 | return; |
| 11393 | } |
| 11394 | |
| 11395 | char const *vsSource = |
| 11396 | "#version 450\n" |
| 11397 | "layout(location=0) out VertexData { vec4 x; } vs_out;\n" |
| 11398 | "void main(){\n" |
| 11399 | " vs_out.x = vec4(1);\n" |
| 11400 | "}\n"; |
| 11401 | char const *gsSource = |
| 11402 | "#version 450\n" |
| 11403 | "layout(triangles) in;\n" |
| 11404 | "layout(triangle_strip, max_vertices=3) out;\n" |
| 11405 | "layout(location=0) in VertexData { vec4 x; } gs_in[];\n" |
| 11406 | "out gl_PerVertex { vec4 gl_Position; };\n" |
| 11407 | "void main() {\n" |
| 11408 | " gl_Position = gs_in[0].x;\n" |
| 11409 | " EmitVertex();\n" |
| 11410 | "}\n"; |
| 11411 | char const *fsSource = |
| 11412 | "#version 450\n" |
| 11413 | "layout(location=0) out vec4 color;\n" |
| 11414 | "void main(){\n" |
| 11415 | " color = vec4(1);\n" |
| 11416 | "}\n"; |
| 11417 | |
| 11418 | VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this); |
| 11419 | VkShaderObj gs(m_device, gsSource, VK_SHADER_STAGE_GEOMETRY_BIT, this); |
| 11420 | VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this); |
| 11421 | |
| 11422 | VkPipelineObj pipe(m_device); |
| 11423 | pipe.AddColorAttachment(); |
| 11424 | pipe.AddShader(&vs); |
| 11425 | pipe.AddShader(&gs); |
| 11426 | pipe.AddShader(&fs); |
| 11427 | |
| 11428 | VkDescriptorSetObj descriptorSet(m_device); |
| 11429 | descriptorSet.AppendDummy(); |
| 11430 | descriptorSet.CreateVKDescriptorSet(m_commandBuffer); |
| 11431 | |
| 11432 | pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass()); |
| 11433 | |
| 11434 | m_errorMonitor->VerifyNotFound(); |
| 11435 | } |
| 11436 | |
Chris Forbes | a0193bc | 2016-04-04 19:19:47 +1200 | [diff] [blame] | 11437 | TEST_F(VkLayerTest, CreatePipelineTessPatchDecorationMismatch) |
| 11438 | { |
| 11439 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 11440 | "is per-vertex in tessellation control shader stage " |
| 11441 | "but per-patch in tessellation evaluation shader stage"); |
| 11442 | |
| 11443 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 11444 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 11445 | |
Chris Forbes | c1e852d | 2016-04-04 19:26:42 +1200 | [diff] [blame] | 11446 | if (!m_device->phy().features().tessellationShader) { |
| 11447 | printf("Device does not support tessellation shaders; skipped.\n"); |
| 11448 | return; |
| 11449 | } |
| 11450 | |
Chris Forbes | a0193bc | 2016-04-04 19:19:47 +1200 | [diff] [blame] | 11451 | char const *vsSource = |
| 11452 | "#version 450\n" |
| 11453 | "void main(){}\n"; |
| 11454 | char const *tcsSource = |
| 11455 | "#version 450\n" |
| 11456 | "layout(location=0) out int x[];\n" |
| 11457 | "layout(vertices=3) out;\n" |
| 11458 | "void main(){\n" |
| 11459 | " gl_TessLevelOuter[0] = gl_TessLevelOuter[1] = gl_TessLevelOuter[2] = 1;\n" |
| 11460 | " gl_TessLevelInner[0] = 1;\n" |
| 11461 | " x[gl_InvocationID] = gl_InvocationID;\n" |
| 11462 | "}\n"; |
| 11463 | char const *tesSource = |
| 11464 | "#version 450\n" |
| 11465 | "layout(triangles, equal_spacing, cw) in;\n" |
| 11466 | "layout(location=0) patch in int x;\n" |
| 11467 | "out gl_PerVertex { vec4 gl_Position; };\n" |
| 11468 | "void main(){\n" |
| 11469 | " gl_Position.xyz = gl_TessCoord;\n" |
| 11470 | " gl_Position.w = x;\n" |
| 11471 | "}\n"; |
| 11472 | char const *fsSource = |
| 11473 | "#version 450\n" |
| 11474 | "layout(location=0) out vec4 color;\n" |
| 11475 | "void main(){\n" |
| 11476 | " color = vec4(1);\n" |
| 11477 | "}\n"; |
| 11478 | |
| 11479 | VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this); |
| 11480 | VkShaderObj tcs(m_device, tcsSource, VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT, this); |
| 11481 | VkShaderObj tes(m_device, tesSource, VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT, this); |
| 11482 | VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this); |
| 11483 | |
| 11484 | VkPipelineInputAssemblyStateCreateInfo iasci{ |
| 11485 | VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO, |
| 11486 | nullptr, |
| 11487 | 0, |
| 11488 | VK_PRIMITIVE_TOPOLOGY_PATCH_LIST, |
| 11489 | VK_FALSE}; |
| 11490 | |
| 11491 | VkPipelineTessellationStateCreateInfo tsci{ |
| 11492 | VK_STRUCTURE_TYPE_PIPELINE_TESSELLATION_STATE_CREATE_INFO, |
| 11493 | nullptr, |
| 11494 | 0, |
| 11495 | 3}; |
| 11496 | |
| 11497 | VkPipelineObj pipe(m_device); |
| 11498 | pipe.SetInputAssembly(&iasci); |
| 11499 | pipe.SetTessellation(&tsci); |
| 11500 | pipe.AddColorAttachment(); |
| 11501 | pipe.AddShader(&vs); |
| 11502 | pipe.AddShader(&tcs); |
| 11503 | pipe.AddShader(&tes); |
| 11504 | pipe.AddShader(&fs); |
| 11505 | |
| 11506 | VkDescriptorSetObj descriptorSet(m_device); |
| 11507 | descriptorSet.AppendDummy(); |
| 11508 | descriptorSet.CreateVKDescriptorSet(m_commandBuffer); |
| 11509 | |
| 11510 | pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass()); |
| 11511 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 11512 | m_errorMonitor->VerifyFound(); |
Chris Forbes | a0193bc | 2016-04-04 19:19:47 +1200 | [diff] [blame] | 11513 | } |
| 11514 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 11515 | TEST_F(VkLayerTest, CreatePipelineAttribBindingConflict) { |
| 11516 | m_errorMonitor->SetDesiredFailureMsg( |
| 11517 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 11518 | "Duplicate vertex input binding descriptions for binding 0"); |
| 11519 | |
Chris Forbes | 280ba2c | 2015-06-12 11:16:41 +1200 | [diff] [blame] | 11520 | ASSERT_NO_FATAL_FAILURE(InitState()); |
Tobin Ehlis | c9ac2b6 | 2015-09-11 12:57:55 -0600 | [diff] [blame] | 11521 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
Chris Forbes | 280ba2c | 2015-06-12 11:16:41 +1200 | [diff] [blame] | 11522 | |
| 11523 | /* Two binding descriptions for binding 0 */ |
| 11524 | VkVertexInputBindingDescription input_bindings[2]; |
| 11525 | memset(input_bindings, 0, sizeof(input_bindings)); |
| 11526 | |
| 11527 | VkVertexInputAttributeDescription input_attrib; |
| 11528 | memset(&input_attrib, 0, sizeof(input_attrib)); |
| 11529 | input_attrib.format = VK_FORMAT_R32_SFLOAT; |
| 11530 | |
| 11531 | char const *vsSource = |
Chris Forbes | 3846771 | 2016-04-04 17:28:05 +1200 | [diff] [blame] | 11532 | "#version 450\n" |
Chris Forbes | 280ba2c | 2015-06-12 11:16:41 +1200 | [diff] [blame] | 11533 | "\n" |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 11534 | "layout(location=0) in float x;\n" /* attrib provided float */ |
Tony Barbour | e804d20 | 2016-01-05 13:37:45 -0700 | [diff] [blame] | 11535 | "out gl_PerVertex {\n" |
| 11536 | " vec4 gl_Position;\n" |
| 11537 | "};\n" |
Chris Forbes | 280ba2c | 2015-06-12 11:16:41 +1200 | [diff] [blame] | 11538 | "void main(){\n" |
| 11539 | " gl_Position = vec4(x);\n" |
| 11540 | "}\n"; |
| 11541 | char const *fsSource = |
Chris Forbes | 3846771 | 2016-04-04 17:28:05 +1200 | [diff] [blame] | 11542 | "#version 450\n" |
Chris Forbes | 280ba2c | 2015-06-12 11:16:41 +1200 | [diff] [blame] | 11543 | "\n" |
| 11544 | "layout(location=0) out vec4 color;\n" |
| 11545 | "void main(){\n" |
| 11546 | " color = vec4(1);\n" |
| 11547 | "}\n"; |
| 11548 | |
Courtney Goeltzenleuchter | d263550 | 2015-10-21 17:08:06 -0600 | [diff] [blame] | 11549 | VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this); |
| 11550 | VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this); |
Chris Forbes | 280ba2c | 2015-06-12 11:16:41 +1200 | [diff] [blame] | 11551 | |
| 11552 | VkPipelineObj pipe(m_device); |
Chia-I Wu | 08accc6 | 2015-07-07 11:50:03 +0800 | [diff] [blame] | 11553 | pipe.AddColorAttachment(); |
Chris Forbes | 280ba2c | 2015-06-12 11:16:41 +1200 | [diff] [blame] | 11554 | pipe.AddShader(&vs); |
| 11555 | pipe.AddShader(&fs); |
| 11556 | |
| 11557 | pipe.AddVertexInputBindings(input_bindings, 2); |
| 11558 | pipe.AddVertexInputAttribs(&input_attrib, 1); |
| 11559 | |
Chris Forbes | 280ba2c | 2015-06-12 11:16:41 +1200 | [diff] [blame] | 11560 | VkDescriptorSetObj descriptorSet(m_device); |
| 11561 | descriptorSet.AppendDummy(); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 11562 | descriptorSet.CreateVKDescriptorSet(m_commandBuffer); |
Chris Forbes | 280ba2c | 2015-06-12 11:16:41 +1200 | [diff] [blame] | 11563 | |
Tony Barbour | 5781e8f | 2015-08-04 16:23:11 -0600 | [diff] [blame] | 11564 | pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass()); |
Chris Forbes | 280ba2c | 2015-06-12 11:16:41 +1200 | [diff] [blame] | 11565 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 11566 | m_errorMonitor->VerifyFound(); |
Chris Forbes | 280ba2c | 2015-06-12 11:16:41 +1200 | [diff] [blame] | 11567 | } |
Chris Forbes | 8f68b56 | 2015-05-25 11:13:32 +1200 | [diff] [blame] | 11568 | |
Chris Forbes | 35efec7 | 2016-04-21 14:32:08 +1200 | [diff] [blame] | 11569 | TEST_F(VkLayerTest, CreatePipeline64BitAttributesPositive) { |
| 11570 | m_errorMonitor->ExpectSuccess(); |
| 11571 | |
| 11572 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 11573 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 11574 | |
Chris Forbes | 91cf3a8 | 2016-06-28 17:51:35 +1200 | [diff] [blame] | 11575 | if (!m_device->phy().features().shaderFloat64) { |
Chris Forbes | 35efec7 | 2016-04-21 14:32:08 +1200 | [diff] [blame] | 11576 | printf("Device does not support 64bit vertex attributes; skipped.\n"); |
| 11577 | return; |
| 11578 | } |
| 11579 | |
| 11580 | VkVertexInputBindingDescription input_bindings[1]; |
| 11581 | memset(input_bindings, 0, sizeof(input_bindings)); |
| 11582 | |
| 11583 | VkVertexInputAttributeDescription input_attribs[4]; |
| 11584 | memset(input_attribs, 0, sizeof(input_attribs)); |
| 11585 | input_attribs[0].location = 0; |
| 11586 | input_attribs[0].offset = 0; |
| 11587 | input_attribs[0].format = VK_FORMAT_R64G64B64A64_SFLOAT; |
| 11588 | input_attribs[1].location = 2; |
| 11589 | input_attribs[1].offset = 32; |
| 11590 | input_attribs[1].format = VK_FORMAT_R64G64B64A64_SFLOAT; |
| 11591 | input_attribs[2].location = 4; |
| 11592 | input_attribs[2].offset = 64; |
| 11593 | input_attribs[2].format = VK_FORMAT_R64G64B64A64_SFLOAT; |
| 11594 | input_attribs[3].location = 6; |
| 11595 | input_attribs[3].offset = 96; |
| 11596 | input_attribs[3].format = VK_FORMAT_R64G64B64A64_SFLOAT; |
| 11597 | |
| 11598 | char const *vsSource = |
| 11599 | "#version 450\n" |
| 11600 | "\n" |
| 11601 | "layout(location=0) in dmat4 x;\n" |
| 11602 | "out gl_PerVertex {\n" |
| 11603 | " vec4 gl_Position;\n" |
| 11604 | "};\n" |
| 11605 | "void main(){\n" |
| 11606 | " gl_Position = vec4(x[0][0]);\n" |
| 11607 | "}\n"; |
| 11608 | char const *fsSource = |
| 11609 | "#version 450\n" |
| 11610 | "\n" |
| 11611 | "layout(location=0) out vec4 color;\n" |
| 11612 | "void main(){\n" |
| 11613 | " color = vec4(1);\n" |
| 11614 | "}\n"; |
| 11615 | |
| 11616 | VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this); |
| 11617 | VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this); |
| 11618 | |
| 11619 | VkPipelineObj pipe(m_device); |
| 11620 | pipe.AddColorAttachment(); |
| 11621 | pipe.AddShader(&vs); |
| 11622 | pipe.AddShader(&fs); |
| 11623 | |
| 11624 | pipe.AddVertexInputBindings(input_bindings, 1); |
| 11625 | pipe.AddVertexInputAttribs(input_attribs, 4); |
| 11626 | |
| 11627 | VkDescriptorSetObj descriptorSet(m_device); |
| 11628 | descriptorSet.AppendDummy(); |
| 11629 | descriptorSet.CreateVKDescriptorSet(m_commandBuffer); |
| 11630 | |
| 11631 | pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass()); |
| 11632 | |
| 11633 | m_errorMonitor->VerifyNotFound(); |
| 11634 | } |
| 11635 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 11636 | TEST_F(VkLayerTest, CreatePipelineFragmentOutputNotWritten) { |
Courtney Goeltzenleuchter | 7415d5a | 2015-12-09 15:48:16 -0700 | [diff] [blame] | 11637 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 11638 | "Attachment 0 not written by FS"); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 11639 | |
Chris Forbes | 4d6d1e5 | 2015-05-25 11:13:40 +1200 | [diff] [blame] | 11640 | ASSERT_NO_FATAL_FAILURE(InitState()); |
Chris Forbes | 4d6d1e5 | 2015-05-25 11:13:40 +1200 | [diff] [blame] | 11641 | |
| 11642 | char const *vsSource = |
Chris Forbes | 3846771 | 2016-04-04 17:28:05 +1200 | [diff] [blame] | 11643 | "#version 450\n" |
Chris Forbes | 4d6d1e5 | 2015-05-25 11:13:40 +1200 | [diff] [blame] | 11644 | "\n" |
Tony Barbour | e804d20 | 2016-01-05 13:37:45 -0700 | [diff] [blame] | 11645 | "out gl_PerVertex {\n" |
| 11646 | " vec4 gl_Position;\n" |
| 11647 | "};\n" |
Chris Forbes | 4d6d1e5 | 2015-05-25 11:13:40 +1200 | [diff] [blame] | 11648 | "void main(){\n" |
| 11649 | " gl_Position = vec4(1);\n" |
| 11650 | "}\n"; |
| 11651 | char const *fsSource = |
Chris Forbes | 3846771 | 2016-04-04 17:28:05 +1200 | [diff] [blame] | 11652 | "#version 450\n" |
Chris Forbes | 4d6d1e5 | 2015-05-25 11:13:40 +1200 | [diff] [blame] | 11653 | "\n" |
| 11654 | "void main(){\n" |
| 11655 | "}\n"; |
| 11656 | |
Courtney Goeltzenleuchter | d263550 | 2015-10-21 17:08:06 -0600 | [diff] [blame] | 11657 | VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this); |
| 11658 | VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this); |
Chris Forbes | 4d6d1e5 | 2015-05-25 11:13:40 +1200 | [diff] [blame] | 11659 | |
| 11660 | VkPipelineObj pipe(m_device); |
| 11661 | pipe.AddShader(&vs); |
| 11662 | pipe.AddShader(&fs); |
| 11663 | |
Chia-I Wu | 08accc6 | 2015-07-07 11:50:03 +0800 | [diff] [blame] | 11664 | /* set up CB 0, not written */ |
| 11665 | pipe.AddColorAttachment(); |
| 11666 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
Chris Forbes | 4d6d1e5 | 2015-05-25 11:13:40 +1200 | [diff] [blame] | 11667 | |
Chris Forbes | 4d6d1e5 | 2015-05-25 11:13:40 +1200 | [diff] [blame] | 11668 | VkDescriptorSetObj descriptorSet(m_device); |
| 11669 | descriptorSet.AppendDummy(); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 11670 | descriptorSet.CreateVKDescriptorSet(m_commandBuffer); |
Chris Forbes | 4d6d1e5 | 2015-05-25 11:13:40 +1200 | [diff] [blame] | 11671 | |
Tony Barbour | 5781e8f | 2015-08-04 16:23:11 -0600 | [diff] [blame] | 11672 | pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass()); |
Chris Forbes | 4d6d1e5 | 2015-05-25 11:13:40 +1200 | [diff] [blame] | 11673 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 11674 | m_errorMonitor->VerifyFound(); |
Chris Forbes | 4d6d1e5 | 2015-05-25 11:13:40 +1200 | [diff] [blame] | 11675 | } |
| 11676 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 11677 | TEST_F(VkLayerTest, CreatePipelineFragmentOutputNotConsumed) { |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 11678 | m_errorMonitor->SetDesiredFailureMsg( |
Mark Lobodzinski | 510e20d | 2016-02-11 09:26:16 -0700 | [diff] [blame] | 11679 | VK_DEBUG_REPORT_WARNING_BIT_EXT, |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 11680 | "FS writes to output location 1 with no matching attachment"); |
| 11681 | |
Chris Forbes | f3fffaa | 2015-05-25 11:13:43 +1200 | [diff] [blame] | 11682 | ASSERT_NO_FATAL_FAILURE(InitState()); |
Chris Forbes | f3fffaa | 2015-05-25 11:13:43 +1200 | [diff] [blame] | 11683 | |
| 11684 | char const *vsSource = |
Chris Forbes | 3846771 | 2016-04-04 17:28:05 +1200 | [diff] [blame] | 11685 | "#version 450\n" |
Chris Forbes | f3fffaa | 2015-05-25 11:13:43 +1200 | [diff] [blame] | 11686 | "\n" |
Tony Barbour | e804d20 | 2016-01-05 13:37:45 -0700 | [diff] [blame] | 11687 | "out gl_PerVertex {\n" |
| 11688 | " vec4 gl_Position;\n" |
| 11689 | "};\n" |
Chris Forbes | f3fffaa | 2015-05-25 11:13:43 +1200 | [diff] [blame] | 11690 | "void main(){\n" |
| 11691 | " gl_Position = vec4(1);\n" |
| 11692 | "}\n"; |
| 11693 | char const *fsSource = |
Chris Forbes | 3846771 | 2016-04-04 17:28:05 +1200 | [diff] [blame] | 11694 | "#version 450\n" |
Chris Forbes | f3fffaa | 2015-05-25 11:13:43 +1200 | [diff] [blame] | 11695 | "\n" |
| 11696 | "layout(location=0) out vec4 x;\n" |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 11697 | "layout(location=1) out vec4 y;\n" /* no matching attachment for this */ |
Chris Forbes | f3fffaa | 2015-05-25 11:13:43 +1200 | [diff] [blame] | 11698 | "void main(){\n" |
| 11699 | " x = vec4(1);\n" |
| 11700 | " y = vec4(1);\n" |
| 11701 | "}\n"; |
| 11702 | |
Courtney Goeltzenleuchter | d263550 | 2015-10-21 17:08:06 -0600 | [diff] [blame] | 11703 | VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this); |
| 11704 | VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this); |
Chris Forbes | f3fffaa | 2015-05-25 11:13:43 +1200 | [diff] [blame] | 11705 | |
| 11706 | VkPipelineObj pipe(m_device); |
| 11707 | pipe.AddShader(&vs); |
| 11708 | pipe.AddShader(&fs); |
| 11709 | |
Chia-I Wu | 08accc6 | 2015-07-07 11:50:03 +0800 | [diff] [blame] | 11710 | /* set up CB 0, not written */ |
| 11711 | pipe.AddColorAttachment(); |
| 11712 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
Chris Forbes | f3fffaa | 2015-05-25 11:13:43 +1200 | [diff] [blame] | 11713 | /* FS writes CB 1, but we don't configure it */ |
| 11714 | |
Chris Forbes | f3fffaa | 2015-05-25 11:13:43 +1200 | [diff] [blame] | 11715 | VkDescriptorSetObj descriptorSet(m_device); |
| 11716 | descriptorSet.AppendDummy(); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 11717 | descriptorSet.CreateVKDescriptorSet(m_commandBuffer); |
Chris Forbes | f3fffaa | 2015-05-25 11:13:43 +1200 | [diff] [blame] | 11718 | |
Tony Barbour | 5781e8f | 2015-08-04 16:23:11 -0600 | [diff] [blame] | 11719 | pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass()); |
Chris Forbes | f3fffaa | 2015-05-25 11:13:43 +1200 | [diff] [blame] | 11720 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 11721 | m_errorMonitor->VerifyFound(); |
Chris Forbes | f3fffaa | 2015-05-25 11:13:43 +1200 | [diff] [blame] | 11722 | } |
| 11723 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 11724 | TEST_F(VkLayerTest, CreatePipelineFragmentOutputTypeMismatch) { |
Courtney Goeltzenleuchter | 7415d5a | 2015-12-09 15:48:16 -0700 | [diff] [blame] | 11725 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 11726 | "does not match FS output type"); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 11727 | |
Chris Forbes | a36d69e | 2015-05-25 11:13:44 +1200 | [diff] [blame] | 11728 | ASSERT_NO_FATAL_FAILURE(InitState()); |
Chris Forbes | a36d69e | 2015-05-25 11:13:44 +1200 | [diff] [blame] | 11729 | |
| 11730 | char const *vsSource = |
Chris Forbes | 3846771 | 2016-04-04 17:28:05 +1200 | [diff] [blame] | 11731 | "#version 450\n" |
Chris Forbes | a36d69e | 2015-05-25 11:13:44 +1200 | [diff] [blame] | 11732 | "\n" |
Tony Barbour | e804d20 | 2016-01-05 13:37:45 -0700 | [diff] [blame] | 11733 | "out gl_PerVertex {\n" |
| 11734 | " vec4 gl_Position;\n" |
| 11735 | "};\n" |
Chris Forbes | a36d69e | 2015-05-25 11:13:44 +1200 | [diff] [blame] | 11736 | "void main(){\n" |
| 11737 | " gl_Position = vec4(1);\n" |
| 11738 | "}\n"; |
| 11739 | char const *fsSource = |
Chris Forbes | 3846771 | 2016-04-04 17:28:05 +1200 | [diff] [blame] | 11740 | "#version 450\n" |
Chris Forbes | a36d69e | 2015-05-25 11:13:44 +1200 | [diff] [blame] | 11741 | "\n" |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 11742 | "layout(location=0) out ivec4 x;\n" /* not UNORM */ |
Chris Forbes | a36d69e | 2015-05-25 11:13:44 +1200 | [diff] [blame] | 11743 | "void main(){\n" |
| 11744 | " x = ivec4(1);\n" |
| 11745 | "}\n"; |
| 11746 | |
Courtney Goeltzenleuchter | d263550 | 2015-10-21 17:08:06 -0600 | [diff] [blame] | 11747 | VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this); |
| 11748 | VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this); |
Chris Forbes | a36d69e | 2015-05-25 11:13:44 +1200 | [diff] [blame] | 11749 | |
| 11750 | VkPipelineObj pipe(m_device); |
| 11751 | pipe.AddShader(&vs); |
| 11752 | pipe.AddShader(&fs); |
| 11753 | |
Chia-I Wu | 08accc6 | 2015-07-07 11:50:03 +0800 | [diff] [blame] | 11754 | /* set up CB 0; type is UNORM by default */ |
| 11755 | pipe.AddColorAttachment(); |
| 11756 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
Chris Forbes | a36d69e | 2015-05-25 11:13:44 +1200 | [diff] [blame] | 11757 | |
Chris Forbes | a36d69e | 2015-05-25 11:13:44 +1200 | [diff] [blame] | 11758 | VkDescriptorSetObj descriptorSet(m_device); |
| 11759 | descriptorSet.AppendDummy(); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 11760 | descriptorSet.CreateVKDescriptorSet(m_commandBuffer); |
Chris Forbes | a36d69e | 2015-05-25 11:13:44 +1200 | [diff] [blame] | 11761 | |
Tony Barbour | 5781e8f | 2015-08-04 16:23:11 -0600 | [diff] [blame] | 11762 | pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass()); |
Chris Forbes | a36d69e | 2015-05-25 11:13:44 +1200 | [diff] [blame] | 11763 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 11764 | m_errorMonitor->VerifyFound(); |
Chris Forbes | a36d69e | 2015-05-25 11:13:44 +1200 | [diff] [blame] | 11765 | } |
Chris Forbes | 7b1b893 | 2015-06-05 14:43:36 +1200 | [diff] [blame] | 11766 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 11767 | TEST_F(VkLayerTest, CreatePipelineUniformBlockNotProvided) { |
Courtney Goeltzenleuchter | 7415d5a | 2015-12-09 15:48:16 -0700 | [diff] [blame] | 11768 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 11769 | "not declared in pipeline layout"); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 11770 | |
Chris Forbes | 556c76c | 2015-08-14 12:04:59 +1200 | [diff] [blame] | 11771 | ASSERT_NO_FATAL_FAILURE(InitState()); |
Chris Forbes | 556c76c | 2015-08-14 12:04:59 +1200 | [diff] [blame] | 11772 | |
| 11773 | char const *vsSource = |
Chris Forbes | 3846771 | 2016-04-04 17:28:05 +1200 | [diff] [blame] | 11774 | "#version 450\n" |
Chris Forbes | 556c76c | 2015-08-14 12:04:59 +1200 | [diff] [blame] | 11775 | "\n" |
Tony Barbour | e804d20 | 2016-01-05 13:37:45 -0700 | [diff] [blame] | 11776 | "out gl_PerVertex {\n" |
| 11777 | " vec4 gl_Position;\n" |
| 11778 | "};\n" |
Chris Forbes | 556c76c | 2015-08-14 12:04:59 +1200 | [diff] [blame] | 11779 | "void main(){\n" |
| 11780 | " gl_Position = vec4(1);\n" |
| 11781 | "}\n"; |
| 11782 | char const *fsSource = |
Chris Forbes | 3846771 | 2016-04-04 17:28:05 +1200 | [diff] [blame] | 11783 | "#version 450\n" |
Chris Forbes | 556c76c | 2015-08-14 12:04:59 +1200 | [diff] [blame] | 11784 | "\n" |
| 11785 | "layout(location=0) out vec4 x;\n" |
| 11786 | "layout(set=0) layout(binding=0) uniform foo { int x; int y; } bar;\n" |
| 11787 | "void main(){\n" |
| 11788 | " x = vec4(bar.y);\n" |
| 11789 | "}\n"; |
| 11790 | |
Courtney Goeltzenleuchter | d263550 | 2015-10-21 17:08:06 -0600 | [diff] [blame] | 11791 | VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this); |
| 11792 | VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this); |
Chris Forbes | 556c76c | 2015-08-14 12:04:59 +1200 | [diff] [blame] | 11793 | |
Chris Forbes | 556c76c | 2015-08-14 12:04:59 +1200 | [diff] [blame] | 11794 | VkPipelineObj pipe(m_device); |
| 11795 | pipe.AddShader(&vs); |
| 11796 | pipe.AddShader(&fs); |
| 11797 | |
| 11798 | /* set up CB 0; type is UNORM by default */ |
| 11799 | pipe.AddColorAttachment(); |
| 11800 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 11801 | |
| 11802 | VkDescriptorSetObj descriptorSet(m_device); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 11803 | descriptorSet.CreateVKDescriptorSet(m_commandBuffer); |
Chris Forbes | 556c76c | 2015-08-14 12:04:59 +1200 | [diff] [blame] | 11804 | |
| 11805 | pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass()); |
| 11806 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 11807 | m_errorMonitor->VerifyFound(); |
Chris Forbes | 556c76c | 2015-08-14 12:04:59 +1200 | [diff] [blame] | 11808 | } |
| 11809 | |
Chris Forbes | 5c59e90 | 2016-02-26 16:56:09 +1300 | [diff] [blame] | 11810 | TEST_F(VkLayerTest, CreatePipelinePushConstantsNotInLayout) { |
| 11811 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 11812 | "not declared in layout"); |
| 11813 | |
| 11814 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 11815 | |
| 11816 | char const *vsSource = |
| 11817 | "#version 450\n" |
Chris Forbes | 5c59e90 | 2016-02-26 16:56:09 +1300 | [diff] [blame] | 11818 | "\n" |
| 11819 | "layout(push_constant, std430) uniform foo { float x; } consts;\n" |
| 11820 | "out gl_PerVertex {\n" |
| 11821 | " vec4 gl_Position;\n" |
| 11822 | "};\n" |
| 11823 | "void main(){\n" |
| 11824 | " gl_Position = vec4(consts.x);\n" |
| 11825 | "}\n"; |
| 11826 | char const *fsSource = |
| 11827 | "#version 450\n" |
Chris Forbes | 5c59e90 | 2016-02-26 16:56:09 +1300 | [diff] [blame] | 11828 | "\n" |
| 11829 | "layout(location=0) out vec4 x;\n" |
| 11830 | "void main(){\n" |
| 11831 | " x = vec4(1);\n" |
| 11832 | "}\n"; |
| 11833 | |
| 11834 | VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this); |
| 11835 | VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this); |
| 11836 | |
| 11837 | VkPipelineObj pipe(m_device); |
| 11838 | pipe.AddShader(&vs); |
| 11839 | pipe.AddShader(&fs); |
| 11840 | |
| 11841 | /* set up CB 0; type is UNORM by default */ |
| 11842 | pipe.AddColorAttachment(); |
| 11843 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 11844 | |
| 11845 | VkDescriptorSetObj descriptorSet(m_device); |
| 11846 | descriptorSet.CreateVKDescriptorSet(m_commandBuffer); |
| 11847 | |
| 11848 | pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass()); |
| 11849 | |
| 11850 | /* should have generated an error -- no push constant ranges provided! */ |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 11851 | m_errorMonitor->VerifyFound(); |
Chris Forbes | 5c59e90 | 2016-02-26 16:56:09 +1300 | [diff] [blame] | 11852 | } |
| 11853 | |
Chris Forbes | 10eb9ae | 2016-05-31 16:09:42 +1200 | [diff] [blame] | 11854 | TEST_F(VkLayerTest, CreateComputePipelineMissingDescriptor) { |
| 11855 | m_errorMonitor->SetDesiredFailureMsg( |
| 11856 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 11857 | "Shader uses descriptor slot 0.0"); |
| 11858 | |
| 11859 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 11860 | |
| 11861 | char const *csSource = |
| 11862 | "#version 450\n" |
| 11863 | "\n" |
| 11864 | "layout(local_size_x=1) in;\n" |
| 11865 | "layout(set=0, binding=0) buffer block { vec4 x; };\n" |
| 11866 | "void main(){\n" |
| 11867 | " x = vec4(1);\n" |
| 11868 | "}\n"; |
| 11869 | |
| 11870 | VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this); |
| 11871 | |
| 11872 | VkDescriptorSetObj descriptorSet(m_device); |
| 11873 | descriptorSet.CreateVKDescriptorSet(m_commandBuffer); |
| 11874 | |
| 11875 | VkComputePipelineCreateInfo cpci = { |
| 11876 | VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO, |
| 11877 | nullptr, 0, { |
| 11878 | VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, |
| 11879 | nullptr, 0, VK_SHADER_STAGE_COMPUTE_BIT, |
| 11880 | cs.handle(), "main", nullptr |
| 11881 | }, |
| 11882 | descriptorSet.GetPipelineLayout(), |
| 11883 | VK_NULL_HANDLE, -1 |
| 11884 | }; |
| 11885 | |
| 11886 | VkPipeline pipe; |
| 11887 | VkResult err = vkCreateComputePipelines( |
| 11888 | m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe); |
| 11889 | |
| 11890 | m_errorMonitor->VerifyFound(); |
| 11891 | |
| 11892 | if (err == VK_SUCCESS) { |
| 11893 | vkDestroyPipeline(m_device->device(), pipe, nullptr); |
| 11894 | } |
| 11895 | } |
| 11896 | |
| 11897 | TEST_F(VkLayerTest, CreateComputePipelineMissingDescriptorUnusedPositive) { |
| 11898 | m_errorMonitor->ExpectSuccess(); |
| 11899 | |
| 11900 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 11901 | |
| 11902 | char const *csSource = |
| 11903 | "#version 450\n" |
| 11904 | "\n" |
| 11905 | "layout(local_size_x=1) in;\n" |
| 11906 | "layout(set=0, binding=0) buffer block { vec4 x; };\n" |
| 11907 | "void main(){\n" |
| 11908 | " // x is not used.\n" |
| 11909 | "}\n"; |
| 11910 | |
| 11911 | VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this); |
| 11912 | |
| 11913 | VkDescriptorSetObj descriptorSet(m_device); |
| 11914 | descriptorSet.CreateVKDescriptorSet(m_commandBuffer); |
| 11915 | |
| 11916 | VkComputePipelineCreateInfo cpci = { |
| 11917 | VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO, |
| 11918 | nullptr, 0, { |
| 11919 | VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, |
| 11920 | nullptr, 0, VK_SHADER_STAGE_COMPUTE_BIT, |
| 11921 | cs.handle(), "main", nullptr |
| 11922 | }, |
| 11923 | descriptorSet.GetPipelineLayout(), |
| 11924 | VK_NULL_HANDLE, -1 |
| 11925 | }; |
| 11926 | |
| 11927 | VkPipeline pipe; |
| 11928 | VkResult err = vkCreateComputePipelines( |
| 11929 | m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe); |
| 11930 | |
| 11931 | m_errorMonitor->VerifyNotFound(); |
| 11932 | |
| 11933 | if (err == VK_SUCCESS) { |
| 11934 | vkDestroyPipeline(m_device->device(), pipe, nullptr); |
| 11935 | } |
| 11936 | } |
| 11937 | |
Mark Lobodzinski | 209b529 | 2015-09-17 09:44:05 -0600 | [diff] [blame] | 11938 | #endif // SHADER_CHECKER_TESTS |
| 11939 | |
| 11940 | #if DEVICE_LIMITS_TESTS |
Mark Young | c48c4c1 | 2016-04-11 14:26:49 -0600 | [diff] [blame] | 11941 | TEST_F(VkLayerTest, CreateImageLimitsViolationMaxWidth) { |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 11942 | m_errorMonitor->SetDesiredFailureMsg( |
| 11943 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 11944 | "CreateImage extents exceed allowable limits for format"); |
Mark Lobodzinski | 6f2274e | 2015-09-22 09:33:21 -0600 | [diff] [blame] | 11945 | |
| 11946 | ASSERT_NO_FATAL_FAILURE(InitState()); |
Mark Lobodzinski | 6f2274e | 2015-09-22 09:33:21 -0600 | [diff] [blame] | 11947 | |
| 11948 | // Create an image |
| 11949 | VkImage image; |
| 11950 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 11951 | const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM; |
| 11952 | const int32_t tex_width = 32; |
| 11953 | const int32_t tex_height = 32; |
Mark Lobodzinski | 6f2274e | 2015-09-22 09:33:21 -0600 | [diff] [blame] | 11954 | |
| 11955 | VkImageCreateInfo image_create_info = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 11956 | image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO; |
| 11957 | image_create_info.pNext = NULL; |
| 11958 | image_create_info.imageType = VK_IMAGE_TYPE_2D; |
| 11959 | image_create_info.format = tex_format; |
| 11960 | image_create_info.extent.width = tex_width; |
Mark Lobodzinski | 6f2274e | 2015-09-22 09:33:21 -0600 | [diff] [blame] | 11961 | image_create_info.extent.height = tex_height; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 11962 | image_create_info.extent.depth = 1; |
| 11963 | image_create_info.mipLevels = 1; |
| 11964 | image_create_info.arrayLayers = 1; |
| 11965 | image_create_info.samples = VK_SAMPLE_COUNT_1_BIT; |
| 11966 | image_create_info.tiling = VK_IMAGE_TILING_LINEAR; |
| 11967 | image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT; |
| 11968 | image_create_info.flags = 0; |
Mark Lobodzinski | 6f2274e | 2015-09-22 09:33:21 -0600 | [diff] [blame] | 11969 | |
| 11970 | // Introduce error by sending down a bogus width extent |
| 11971 | image_create_info.extent.width = 65536; |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 11972 | vkCreateImage(m_device->device(), &image_create_info, NULL, &image); |
Mark Lobodzinski | 6f2274e | 2015-09-22 09:33:21 -0600 | [diff] [blame] | 11973 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 11974 | m_errorMonitor->VerifyFound(); |
Mark Lobodzinski | 6f2274e | 2015-09-22 09:33:21 -0600 | [diff] [blame] | 11975 | } |
| 11976 | |
Mark Young | c48c4c1 | 2016-04-11 14:26:49 -0600 | [diff] [blame] | 11977 | TEST_F(VkLayerTest, CreateImageLimitsViolationMinWidth) { |
| 11978 | m_errorMonitor->SetDesiredFailureMsg( |
| 11979 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 11980 | "CreateImage extents is 0 for at least one required dimension"); |
| 11981 | |
| 11982 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 11983 | |
| 11984 | // Create an image |
| 11985 | VkImage image; |
| 11986 | |
| 11987 | const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM; |
| 11988 | const int32_t tex_width = 32; |
| 11989 | const int32_t tex_height = 32; |
| 11990 | |
| 11991 | VkImageCreateInfo image_create_info = {}; |
| 11992 | image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO; |
| 11993 | image_create_info.pNext = NULL; |
| 11994 | image_create_info.imageType = VK_IMAGE_TYPE_2D; |
| 11995 | image_create_info.format = tex_format; |
| 11996 | image_create_info.extent.width = tex_width; |
| 11997 | image_create_info.extent.height = tex_height; |
| 11998 | image_create_info.extent.depth = 1; |
| 11999 | image_create_info.mipLevels = 1; |
| 12000 | image_create_info.arrayLayers = 1; |
| 12001 | image_create_info.samples = VK_SAMPLE_COUNT_1_BIT; |
| 12002 | image_create_info.tiling = VK_IMAGE_TILING_LINEAR; |
| 12003 | image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT; |
| 12004 | image_create_info.flags = 0; |
| 12005 | |
| 12006 | // Introduce error by sending down a bogus width extent |
| 12007 | image_create_info.extent.width = 0; |
| 12008 | vkCreateImage(m_device->device(), &image_create_info, NULL, &image); |
| 12009 | |
| 12010 | m_errorMonitor->VerifyFound(); |
| 12011 | } |
Mark Lobodzinski | 209b529 | 2015-09-17 09:44:05 -0600 | [diff] [blame] | 12012 | #endif // DEVICE_LIMITS_TESTS |
Chris Forbes | a36d69e | 2015-05-25 11:13:44 +1200 | [diff] [blame] | 12013 | |
Tobin Ehlis | cde0889 | 2015-09-22 10:11:37 -0600 | [diff] [blame] | 12014 | #if IMAGE_TESTS |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12015 | TEST_F(VkLayerTest, InvalidImageView) { |
| 12016 | VkResult err; |
Tobin Ehlis | cde0889 | 2015-09-22 10:11:37 -0600 | [diff] [blame] | 12017 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12018 | m_errorMonitor->SetDesiredFailureMsg( |
| 12019 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 12020 | "vkCreateImageView called with baseMipLevel 10 "); |
| 12021 | |
Tobin Ehlis | cde0889 | 2015-09-22 10:11:37 -0600 | [diff] [blame] | 12022 | ASSERT_NO_FATAL_FAILURE(InitState()); |
Tobin Ehlis | cde0889 | 2015-09-22 10:11:37 -0600 | [diff] [blame] | 12023 | |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12024 | // Create an image and try to create a view with bad baseMipLevel |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12025 | VkImage image; |
Tobin Ehlis | cde0889 | 2015-09-22 10:11:37 -0600 | [diff] [blame] | 12026 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12027 | const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM; |
| 12028 | const int32_t tex_width = 32; |
| 12029 | const int32_t tex_height = 32; |
Tobin Ehlis | cde0889 | 2015-09-22 10:11:37 -0600 | [diff] [blame] | 12030 | |
| 12031 | VkImageCreateInfo image_create_info = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12032 | image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO; |
| 12033 | image_create_info.pNext = NULL; |
| 12034 | image_create_info.imageType = VK_IMAGE_TYPE_2D; |
| 12035 | image_create_info.format = tex_format; |
| 12036 | image_create_info.extent.width = tex_width; |
| 12037 | image_create_info.extent.height = tex_height; |
| 12038 | image_create_info.extent.depth = 1; |
| 12039 | image_create_info.mipLevels = 1; |
| 12040 | image_create_info.arrayLayers = 1; |
| 12041 | image_create_info.samples = VK_SAMPLE_COUNT_1_BIT; |
| 12042 | image_create_info.tiling = VK_IMAGE_TILING_LINEAR; |
| 12043 | image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT; |
| 12044 | image_create_info.flags = 0; |
Tobin Ehlis | cde0889 | 2015-09-22 10:11:37 -0600 | [diff] [blame] | 12045 | |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 12046 | err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image); |
Tobin Ehlis | cde0889 | 2015-09-22 10:11:37 -0600 | [diff] [blame] | 12047 | ASSERT_VK_SUCCESS(err); |
| 12048 | |
| 12049 | VkImageViewCreateInfo image_view_create_info = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12050 | image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO; |
| 12051 | image_view_create_info.image = image; |
| 12052 | image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D; |
| 12053 | image_view_create_info.format = tex_format; |
| 12054 | image_view_create_info.subresourceRange.layerCount = 1; |
| 12055 | image_view_create_info.subresourceRange.baseMipLevel = 10; // cause an error |
| 12056 | image_view_create_info.subresourceRange.levelCount = 1; |
| 12057 | image_view_create_info.subresourceRange.aspectMask = |
| 12058 | VK_IMAGE_ASPECT_COLOR_BIT; |
Tobin Ehlis | cde0889 | 2015-09-22 10:11:37 -0600 | [diff] [blame] | 12059 | |
| 12060 | VkImageView view; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12061 | err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, |
| 12062 | &view); |
Tobin Ehlis | cde0889 | 2015-09-22 10:11:37 -0600 | [diff] [blame] | 12063 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 12064 | m_errorMonitor->VerifyFound(); |
Tony Barbour | df4c004 | 2016-06-01 15:55:43 -0600 | [diff] [blame] | 12065 | vkDestroyImage(m_device->device(), image, NULL); |
Tobin Ehlis | cde0889 | 2015-09-22 10:11:37 -0600 | [diff] [blame] | 12066 | } |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12067 | |
Mark Young | d339ba3 | 2016-05-30 13:28:35 -0600 | [diff] [blame] | 12068 | TEST_F(VkLayerTest, CreateImageViewNoMemoryBoundToImage) { |
| 12069 | VkResult err; |
| 12070 | |
| 12071 | m_errorMonitor->SetDesiredFailureMsg( |
| 12072 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 12073 | "vkCreateImageView called with invalid memory "); |
| 12074 | |
| 12075 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 12076 | |
| 12077 | // Create an image and try to create a view with no memory backing the image |
| 12078 | VkImage image; |
| 12079 | |
| 12080 | const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM; |
| 12081 | const int32_t tex_width = 32; |
| 12082 | const int32_t tex_height = 32; |
| 12083 | |
| 12084 | VkImageCreateInfo image_create_info = {}; |
| 12085 | image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO; |
| 12086 | image_create_info.pNext = NULL; |
| 12087 | image_create_info.imageType = VK_IMAGE_TYPE_2D; |
| 12088 | image_create_info.format = tex_format; |
| 12089 | image_create_info.extent.width = tex_width; |
| 12090 | image_create_info.extent.height = tex_height; |
| 12091 | image_create_info.extent.depth = 1; |
| 12092 | image_create_info.mipLevels = 1; |
| 12093 | image_create_info.arrayLayers = 1; |
| 12094 | image_create_info.samples = VK_SAMPLE_COUNT_1_BIT; |
| 12095 | image_create_info.tiling = VK_IMAGE_TILING_LINEAR; |
| 12096 | image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT; |
| 12097 | image_create_info.flags = 0; |
| 12098 | |
| 12099 | err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image); |
| 12100 | ASSERT_VK_SUCCESS(err); |
| 12101 | |
| 12102 | VkImageViewCreateInfo image_view_create_info = {}; |
| 12103 | image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO; |
| 12104 | image_view_create_info.image = image; |
| 12105 | image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D; |
| 12106 | image_view_create_info.format = tex_format; |
| 12107 | image_view_create_info.subresourceRange.layerCount = 1; |
| 12108 | image_view_create_info.subresourceRange.baseMipLevel = 0; |
| 12109 | image_view_create_info.subresourceRange.levelCount = 1; |
| 12110 | image_view_create_info.subresourceRange.aspectMask = |
| 12111 | VK_IMAGE_ASPECT_COLOR_BIT; |
| 12112 | |
| 12113 | VkImageView view; |
| 12114 | err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, |
| 12115 | &view); |
| 12116 | |
| 12117 | m_errorMonitor->VerifyFound(); |
| 12118 | vkDestroyImage(m_device->device(), image, NULL); |
| 12119 | // If last error is success, it still created the view, so delete it. |
| 12120 | if (err == VK_SUCCESS) { |
| 12121 | vkDestroyImageView(m_device->device(), view, NULL); |
| 12122 | } |
| 12123 | |
| 12124 | } |
| 12125 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12126 | TEST_F(VkLayerTest, InvalidImageViewAspect) { |
Tobin Ehlis | 1f567a2 | 2016-05-25 16:15:18 -0600 | [diff] [blame] | 12127 | TEST_DESCRIPTION( |
| 12128 | "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] | 12129 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12130 | "vkCreateImageView: Color image " |
| 12131 | "formats must have ONLY the " |
| 12132 | "VK_IMAGE_ASPECT_COLOR_BIT set"); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 12133 | |
Mark Lobodzinski | dc86b85 | 2015-10-23 14:20:31 -0600 | [diff] [blame] | 12134 | ASSERT_NO_FATAL_FAILURE(InitState()); |
Mark Lobodzinski | dc86b85 | 2015-10-23 14:20:31 -0600 | [diff] [blame] | 12135 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12136 | const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM; |
Tobin Ehlis | 1f567a2 | 2016-05-25 16:15:18 -0600 | [diff] [blame] | 12137 | VkImageObj image(m_device); |
| 12138 | image.init(32, 32, tex_format, VK_IMAGE_USAGE_SAMPLED_BIT, |
| 12139 | VK_IMAGE_TILING_LINEAR, 0); |
| 12140 | ASSERT_TRUE(image.initialized()); |
Mark Lobodzinski | dc86b85 | 2015-10-23 14:20:31 -0600 | [diff] [blame] | 12141 | |
| 12142 | VkImageViewCreateInfo image_view_create_info = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12143 | image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO; |
Tobin Ehlis | 1f567a2 | 2016-05-25 16:15:18 -0600 | [diff] [blame] | 12144 | image_view_create_info.image = image.handle(); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12145 | image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D; |
| 12146 | image_view_create_info.format = tex_format; |
| 12147 | image_view_create_info.subresourceRange.baseMipLevel = 0; |
| 12148 | image_view_create_info.subresourceRange.levelCount = 1; |
| 12149 | // Cause an error by setting an invalid image aspect |
| 12150 | image_view_create_info.subresourceRange.aspectMask = |
| 12151 | VK_IMAGE_ASPECT_METADATA_BIT; |
Mark Lobodzinski | dc86b85 | 2015-10-23 14:20:31 -0600 | [diff] [blame] | 12152 | |
| 12153 | VkImageView view; |
Tobin Ehlis | 1f567a2 | 2016-05-25 16:15:18 -0600 | [diff] [blame] | 12154 | vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view); |
Mark Lobodzinski | dc86b85 | 2015-10-23 14:20:31 -0600 | [diff] [blame] | 12155 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 12156 | m_errorMonitor->VerifyFound(); |
Mark Lobodzinski | dc86b85 | 2015-10-23 14:20:31 -0600 | [diff] [blame] | 12157 | } |
| 12158 | |
Mark Lobodzinski | db11763 | 2016-03-31 10:45:56 -0600 | [diff] [blame] | 12159 | TEST_F(VkLayerTest, CopyImageLayerCountMismatch) { |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12160 | VkResult err; |
| 12161 | bool pass; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12162 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12163 | m_errorMonitor->SetDesiredFailureMsg( |
| 12164 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Mark Lobodzinski | db11763 | 2016-03-31 10:45:56 -0600 | [diff] [blame] | 12165 | "vkCmdCopyImage: number of layers in source and destination subresources for pRegions"); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 12166 | |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12167 | ASSERT_NO_FATAL_FAILURE(InitState()); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12168 | |
| 12169 | // Create two images of different types and try to copy between them |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12170 | VkImage srcImage; |
| 12171 | VkImage dstImage; |
| 12172 | VkDeviceMemory srcMem; |
| 12173 | VkDeviceMemory destMem; |
| 12174 | VkMemoryRequirements memReqs; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12175 | |
| 12176 | VkImageCreateInfo image_create_info = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12177 | image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO; |
| 12178 | image_create_info.pNext = NULL; |
| 12179 | image_create_info.imageType = VK_IMAGE_TYPE_2D; |
| 12180 | image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM; |
| 12181 | image_create_info.extent.width = 32; |
| 12182 | image_create_info.extent.height = 32; |
| 12183 | image_create_info.extent.depth = 1; |
| 12184 | image_create_info.mipLevels = 1; |
Mark Lobodzinski | db11763 | 2016-03-31 10:45:56 -0600 | [diff] [blame] | 12185 | image_create_info.arrayLayers = 4; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12186 | image_create_info.samples = VK_SAMPLE_COUNT_1_BIT; |
| 12187 | image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL; |
| 12188 | image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT; |
| 12189 | image_create_info.flags = 0; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12190 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12191 | err = |
| 12192 | vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12193 | ASSERT_VK_SUCCESS(err); |
| 12194 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12195 | err = |
| 12196 | vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12197 | ASSERT_VK_SUCCESS(err); |
| 12198 | |
| 12199 | // Allocate memory |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 12200 | VkMemoryAllocateInfo memAlloc = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12201 | memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO; |
| 12202 | memAlloc.pNext = NULL; |
| 12203 | memAlloc.allocationSize = 0; |
| 12204 | memAlloc.memoryTypeIndex = 0; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12205 | |
Courtney Goeltzenleuchter | 06d8947 | 2015-10-20 16:40:38 -0600 | [diff] [blame] | 12206 | vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12207 | memAlloc.allocationSize = memReqs.size; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12208 | pass = |
| 12209 | m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0); |
Courtney Goeltzenleuchter | 1d2f0dd | 2015-10-22 11:03:31 -0600 | [diff] [blame] | 12210 | ASSERT_TRUE(pass); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 12211 | err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12212 | ASSERT_VK_SUCCESS(err); |
| 12213 | |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 12214 | vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12215 | memAlloc.allocationSize = memReqs.size; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12216 | pass = |
| 12217 | m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12218 | ASSERT_VK_SUCCESS(err); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 12219 | err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12220 | ASSERT_VK_SUCCESS(err); |
| 12221 | |
| 12222 | err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0); |
| 12223 | ASSERT_VK_SUCCESS(err); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 12224 | err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12225 | ASSERT_VK_SUCCESS(err); |
| 12226 | |
| 12227 | BeginCommandBuffer(); |
| 12228 | VkImageCopy copyRegion; |
Chia-I Wu | ab83a0e | 2015-10-27 19:00:15 +0800 | [diff] [blame] | 12229 | copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12230 | copyRegion.srcSubresource.mipLevel = 0; |
Courtney Goeltzenleuchter | 8367ce0 | 2015-10-16 09:46:00 -0600 | [diff] [blame] | 12231 | copyRegion.srcSubresource.baseArrayLayer = 0; |
Mark Lobodzinski | db11763 | 2016-03-31 10:45:56 -0600 | [diff] [blame] | 12232 | copyRegion.srcSubresource.layerCount = 1; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12233 | copyRegion.srcOffset.x = 0; |
| 12234 | copyRegion.srcOffset.y = 0; |
| 12235 | copyRegion.srcOffset.z = 0; |
Chia-I Wu | ab83a0e | 2015-10-27 19:00:15 +0800 | [diff] [blame] | 12236 | copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 12237 | copyRegion.dstSubresource.mipLevel = 0; |
| 12238 | copyRegion.dstSubresource.baseArrayLayer = 0; |
Mark Lobodzinski | db11763 | 2016-03-31 10:45:56 -0600 | [diff] [blame] | 12239 | // Introduce failure by forcing the dst layerCount to differ from src |
| 12240 | copyRegion.dstSubresource.layerCount = 3; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 12241 | copyRegion.dstOffset.x = 0; |
| 12242 | copyRegion.dstOffset.y = 0; |
| 12243 | copyRegion.dstOffset.z = 0; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12244 | copyRegion.extent.width = 1; |
| 12245 | copyRegion.extent.height = 1; |
| 12246 | copyRegion.extent.depth = 1; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12247 | m_commandBuffer->CopyImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, |
| 12248 | VK_IMAGE_LAYOUT_GENERAL, 1, ©Region); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12249 | EndCommandBuffer(); |
| 12250 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 12251 | m_errorMonitor->VerifyFound(); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12252 | |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 12253 | vkDestroyImage(m_device->device(), srcImage, NULL); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 12254 | vkDestroyImage(m_device->device(), dstImage, NULL); |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 12255 | vkFreeMemory(m_device->device(), srcMem, NULL); |
| 12256 | vkFreeMemory(m_device->device(), destMem, NULL); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12257 | } |
| 12258 | |
Tony Barbour | d667364 | 2016-05-05 14:46:39 -0600 | [diff] [blame] | 12259 | TEST_F(VkLayerTest, ImageLayerUnsupportedFormat) { |
| 12260 | |
| 12261 | TEST_DESCRIPTION("Creating images with unsuported formats "); |
| 12262 | |
| 12263 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 12264 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 12265 | VkImageObj image(m_device); |
| 12266 | image.init(128, 128, VK_FORMAT_B8G8R8A8_UNORM, |
| 12267 | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | |
| 12268 | VK_IMAGE_USAGE_TRANSFER_DST_BIT, |
| 12269 | VK_IMAGE_TILING_OPTIMAL, 0); |
| 12270 | ASSERT_TRUE(image.initialized()); |
| 12271 | |
Mark Lobodzinski | ba5c686 | 2016-05-17 08:14:00 -0600 | [diff] [blame] | 12272 | // Create image with unsupported format - Expect FORMAT_UNSUPPORTED |
| 12273 | VkImageCreateInfo image_create_info; |
| 12274 | image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO; |
| 12275 | image_create_info.pNext = NULL; |
| 12276 | image_create_info.imageType = VK_IMAGE_TYPE_2D; |
| 12277 | image_create_info.format = VK_FORMAT_UNDEFINED; |
| 12278 | image_create_info.extent.width = 32; |
| 12279 | image_create_info.extent.height = 32; |
| 12280 | image_create_info.extent.depth = 1; |
| 12281 | image_create_info.mipLevels = 1; |
| 12282 | image_create_info.arrayLayers = 1; |
| 12283 | image_create_info.samples = VK_SAMPLE_COUNT_1_BIT; |
| 12284 | image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL; |
| 12285 | image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT; |
| 12286 | image_create_info.flags = 0; |
| 12287 | |
| 12288 | m_errorMonitor->SetDesiredFailureMsg( |
| 12289 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 12290 | "vkCreateImage: VkFormat for image must not be VK_FORMAT_UNDEFINED"); |
| 12291 | |
| 12292 | VkImage localImage; |
| 12293 | vkCreateImage(m_device->handle(), &image_create_info, NULL, &localImage); |
| 12294 | m_errorMonitor->VerifyFound(); |
| 12295 | |
Tony Barbour | d667364 | 2016-05-05 14:46:39 -0600 | [diff] [blame] | 12296 | VkFormat unsupported = VK_FORMAT_UNDEFINED; |
Mark Lobodzinski | ba5c686 | 2016-05-17 08:14:00 -0600 | [diff] [blame] | 12297 | // Look for a format that is COMPLETELY unsupported with this hardware |
Tony Barbour | d667364 | 2016-05-05 14:46:39 -0600 | [diff] [blame] | 12298 | for (int f = VK_FORMAT_BEGIN_RANGE; f <= VK_FORMAT_END_RANGE; f++) { |
| 12299 | VkFormat format = static_cast<VkFormat>(f); |
| 12300 | VkFormatProperties fProps = m_device->format_properties(format); |
| 12301 | if (format != VK_FORMAT_UNDEFINED && fProps.linearTilingFeatures == 0 && |
| 12302 | fProps.optimalTilingFeatures == 0) { |
| 12303 | unsupported = format; |
| 12304 | break; |
| 12305 | } |
| 12306 | } |
Mark Lobodzinski | ba5c686 | 2016-05-17 08:14:00 -0600 | [diff] [blame] | 12307 | |
Tony Barbour | d667364 | 2016-05-05 14:46:39 -0600 | [diff] [blame] | 12308 | if (unsupported != VK_FORMAT_UNDEFINED) { |
Tony Barbour | d667364 | 2016-05-05 14:46:39 -0600 | [diff] [blame] | 12309 | image_create_info.format = unsupported; |
Tony Barbour | d667364 | 2016-05-05 14:46:39 -0600 | [diff] [blame] | 12310 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Mark Lobodzinski | ba5c686 | 2016-05-17 08:14:00 -0600 | [diff] [blame] | 12311 | "is an unsupported format"); |
Tony Barbour | d667364 | 2016-05-05 14:46:39 -0600 | [diff] [blame] | 12312 | |
Mark Lobodzinski | ba5c686 | 2016-05-17 08:14:00 -0600 | [diff] [blame] | 12313 | vkCreateImage(m_device->handle(), &image_create_info, NULL, &localImage); |
Tony Barbour | d667364 | 2016-05-05 14:46:39 -0600 | [diff] [blame] | 12314 | m_errorMonitor->VerifyFound(); |
| 12315 | } |
| 12316 | } |
| 12317 | |
| 12318 | TEST_F(VkLayerTest, ImageLayerViewTests) { |
| 12319 | VkResult ret; |
| 12320 | TEST_DESCRIPTION("Passing bad parameters to CreateImageView"); |
| 12321 | |
| 12322 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 12323 | |
| 12324 | VkImageObj image(m_device); |
| 12325 | image.init(128, 128, VK_FORMAT_B8G8R8A8_UNORM, |
| 12326 | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | |
| 12327 | VK_IMAGE_USAGE_TRANSFER_DST_BIT, |
| 12328 | VK_IMAGE_TILING_OPTIMAL, 0); |
| 12329 | ASSERT_TRUE(image.initialized()); |
| 12330 | |
| 12331 | VkImageView imgView; |
| 12332 | VkImageViewCreateInfo imgViewInfo = {}; |
| 12333 | imgViewInfo.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO; |
| 12334 | imgViewInfo.image = image.handle(); |
| 12335 | imgViewInfo.viewType = VK_IMAGE_VIEW_TYPE_2D; |
| 12336 | imgViewInfo.format = VK_FORMAT_B8G8R8A8_UNORM; |
| 12337 | imgViewInfo.subresourceRange.layerCount = 1; |
| 12338 | imgViewInfo.subresourceRange.baseMipLevel = 0; |
| 12339 | imgViewInfo.subresourceRange.levelCount = 1; |
| 12340 | imgViewInfo.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; |
| 12341 | |
| 12342 | m_errorMonitor->SetDesiredFailureMsg( |
| 12343 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 12344 | "vkCreateImageView called with baseMipLevel"); |
| 12345 | // View can't have baseMipLevel >= image's mipLevels - Expect |
| 12346 | // VIEW_CREATE_ERROR |
| 12347 | imgViewInfo.subresourceRange.baseMipLevel = 1; |
| 12348 | vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView); |
| 12349 | m_errorMonitor->VerifyFound(); |
| 12350 | imgViewInfo.subresourceRange.baseMipLevel = 0; |
| 12351 | |
| 12352 | m_errorMonitor->SetDesiredFailureMsg( |
| 12353 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 12354 | "vkCreateImageView called with baseArrayLayer"); |
| 12355 | // View can't have baseArrayLayer >= image's arraySize - Expect |
| 12356 | // VIEW_CREATE_ERROR |
| 12357 | imgViewInfo.subresourceRange.baseArrayLayer = 1; |
| 12358 | vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView); |
| 12359 | m_errorMonitor->VerifyFound(); |
| 12360 | imgViewInfo.subresourceRange.baseArrayLayer = 0; |
| 12361 | |
| 12362 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 12363 | "vkCreateImageView called with 0 in " |
| 12364 | "pCreateInfo->subresourceRange." |
| 12365 | "levelCount"); |
| 12366 | // View's levelCount can't be 0 - Expect VIEW_CREATE_ERROR |
| 12367 | imgViewInfo.subresourceRange.levelCount = 0; |
| 12368 | vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView); |
| 12369 | m_errorMonitor->VerifyFound(); |
| 12370 | imgViewInfo.subresourceRange.levelCount = 1; |
| 12371 | |
| 12372 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 12373 | "vkCreateImageView called with 0 in " |
| 12374 | "pCreateInfo->subresourceRange." |
| 12375 | "layerCount"); |
| 12376 | // View's layerCount can't be 0 - Expect VIEW_CREATE_ERROR |
| 12377 | imgViewInfo.subresourceRange.layerCount = 0; |
| 12378 | vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView); |
| 12379 | m_errorMonitor->VerifyFound(); |
| 12380 | imgViewInfo.subresourceRange.layerCount = 1; |
| 12381 | |
| 12382 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 12383 | "but both must be color formats"); |
| 12384 | // Can't use depth format for view into color image - Expect INVALID_FORMAT |
| 12385 | imgViewInfo.format = VK_FORMAT_D24_UNORM_S8_UINT; |
| 12386 | vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView); |
| 12387 | m_errorMonitor->VerifyFound(); |
| 12388 | imgViewInfo.format = VK_FORMAT_B8G8R8A8_UNORM; |
| 12389 | |
| 12390 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 12391 | "Formats MUST be IDENTICAL unless " |
| 12392 | "VK_IMAGE_CREATE_MUTABLE_FORMAT BIT " |
| 12393 | "was set on image creation."); |
| 12394 | // Same compatibility class but no MUTABLE_FORMAT bit - Expect |
| 12395 | // VIEW_CREATE_ERROR |
| 12396 | imgViewInfo.format = VK_FORMAT_B8G8R8A8_UINT; |
| 12397 | vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView); |
| 12398 | m_errorMonitor->VerifyFound(); |
| 12399 | imgViewInfo.format = VK_FORMAT_B8G8R8A8_UNORM; |
| 12400 | |
| 12401 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 12402 | "can support ImageViews with " |
| 12403 | "differing formats but they must be " |
| 12404 | "in the same compatibility class."); |
| 12405 | // Have MUTABLE_FORMAT bit but not in same compatibility class - Expect |
| 12406 | // VIEW_CREATE_ERROR |
| 12407 | VkImageCreateInfo mutImgInfo = image.create_info(); |
| 12408 | VkImage mutImage; |
| 12409 | mutImgInfo.format = VK_FORMAT_R8_UINT; |
| 12410 | assert( |
| 12411 | m_device->format_properties(VK_FORMAT_R8_UINT).optimalTilingFeatures & |
| 12412 | VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT); |
| 12413 | mutImgInfo.flags = VK_IMAGE_CREATE_MUTABLE_FORMAT_BIT; |
| 12414 | mutImgInfo.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT; |
| 12415 | ret = vkCreateImage(m_device->handle(), &mutImgInfo, NULL, &mutImage); |
| 12416 | ASSERT_VK_SUCCESS(ret); |
| 12417 | imgViewInfo.image = mutImage; |
| 12418 | vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView); |
| 12419 | m_errorMonitor->VerifyFound(); |
| 12420 | imgViewInfo.image = image.handle(); |
| 12421 | vkDestroyImage(m_device->handle(), mutImage, NULL); |
| 12422 | } |
| 12423 | |
| 12424 | TEST_F(VkLayerTest, MiscImageLayerTests) { |
| 12425 | |
| 12426 | TEST_DESCRIPTION("Image layer tests that don't belong elsewhare"); |
| 12427 | |
| 12428 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 12429 | |
| 12430 | VkImageObj image(m_device); |
| 12431 | image.init(128, 128, VK_FORMAT_B8G8R8A8_UNORM, |
| 12432 | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | |
| 12433 | VK_IMAGE_USAGE_TRANSFER_DST_BIT, |
| 12434 | VK_IMAGE_TILING_OPTIMAL, 0); |
| 12435 | ASSERT_TRUE(image.initialized()); |
| 12436 | |
| 12437 | m_errorMonitor->SetDesiredFailureMsg( |
| 12438 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 12439 | "number of layers in image subresource is zero"); |
| 12440 | vk_testing::Buffer buffer; |
| 12441 | VkMemoryPropertyFlags reqs = 0; |
| 12442 | buffer.init_as_src(*m_device, 128 * 128 * 4, reqs); |
| 12443 | VkBufferImageCopy region = {}; |
| 12444 | region.bufferRowLength = 128; |
| 12445 | region.bufferImageHeight = 128; |
| 12446 | region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; |
| 12447 | // layerCount can't be 0 - Expect MISMATCHED_IMAGE_ASPECT |
| 12448 | region.imageSubresource.layerCount = 0; |
| 12449 | region.imageExtent.height = 4; |
| 12450 | region.imageExtent.width = 4; |
| 12451 | region.imageExtent.depth = 1; |
| 12452 | m_commandBuffer->BeginCommandBuffer(); |
| 12453 | vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), |
| 12454 | image.handle(), VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, |
| 12455 | 1, ®ion); |
| 12456 | m_errorMonitor->VerifyFound(); |
| 12457 | region.imageSubresource.layerCount = 1; |
| 12458 | |
| 12459 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 12460 | "aspectMasks for each region must " |
| 12461 | "specify only COLOR or DEPTH or " |
| 12462 | "STENCIL"); |
| 12463 | // Expect MISMATCHED_IMAGE_ASPECT |
| 12464 | region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_METADATA_BIT; |
| 12465 | vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), |
| 12466 | image.handle(), VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, |
| 12467 | 1, ®ion); |
| 12468 | m_errorMonitor->VerifyFound(); |
| 12469 | region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; |
| 12470 | |
| 12471 | m_errorMonitor->SetDesiredFailureMsg( |
| 12472 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 12473 | "If the format of srcImage is a depth, stencil, depth stencil or " |
| 12474 | "integer-based format then filter must be VK_FILTER_NEAREST"); |
| 12475 | // Expect INVALID_FILTER |
| 12476 | VkImageObj intImage1(m_device); |
| 12477 | intImage1.init(128, 128, VK_FORMAT_R8_UINT, |
| 12478 | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, |
| 12479 | 0); |
| 12480 | VkImageObj intImage2(m_device); |
| 12481 | intImage2.init(128, 128, VK_FORMAT_R8_UINT, |
| 12482 | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, |
| 12483 | 0); |
| 12484 | VkImageBlit blitRegion = {}; |
| 12485 | blitRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; |
| 12486 | blitRegion.srcSubresource.baseArrayLayer = 0; |
| 12487 | blitRegion.srcSubresource.layerCount = 1; |
| 12488 | blitRegion.srcSubresource.mipLevel = 0; |
| 12489 | blitRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; |
| 12490 | blitRegion.dstSubresource.baseArrayLayer = 0; |
| 12491 | blitRegion.dstSubresource.layerCount = 1; |
| 12492 | blitRegion.dstSubresource.mipLevel = 0; |
| 12493 | |
| 12494 | vkCmdBlitImage(m_commandBuffer->GetBufferHandle(), intImage1.handle(), |
| 12495 | intImage1.layout(), intImage2.handle(), intImage2.layout(), |
| 12496 | 16, &blitRegion, VK_FILTER_LINEAR); |
| 12497 | m_errorMonitor->VerifyFound(); |
| 12498 | |
| 12499 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 12500 | "called with 0 in ppMemoryBarriers"); |
| 12501 | VkImageMemoryBarrier img_barrier; |
| 12502 | img_barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER; |
| 12503 | img_barrier.pNext = NULL; |
| 12504 | img_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT; |
| 12505 | img_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT; |
| 12506 | img_barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL; |
| 12507 | img_barrier.newLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL; |
| 12508 | img_barrier.image = image.handle(); |
| 12509 | img_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED; |
| 12510 | img_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED; |
| 12511 | img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; |
| 12512 | img_barrier.subresourceRange.baseArrayLayer = 0; |
| 12513 | img_barrier.subresourceRange.baseMipLevel = 0; |
| 12514 | // layerCount should not be 0 - Expect INVALID_IMAGE_RESOURCE |
| 12515 | img_barrier.subresourceRange.layerCount = 0; |
| 12516 | img_barrier.subresourceRange.levelCount = 1; |
| 12517 | vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), |
| 12518 | VK_PIPELINE_STAGE_HOST_BIT, |
| 12519 | VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0, nullptr, 0, |
| 12520 | nullptr, 1, &img_barrier); |
| 12521 | m_errorMonitor->VerifyFound(); |
| 12522 | img_barrier.subresourceRange.layerCount = 1; |
| 12523 | } |
| 12524 | |
| 12525 | TEST_F(VkLayerTest, ImageFormatLimits) { |
| 12526 | |
| 12527 | TEST_DESCRIPTION("Exceed the limits of image format "); |
| 12528 | |
| 12529 | m_errorMonitor->SetDesiredFailureMsg( |
| 12530 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 12531 | "CreateImage extents exceed allowable limits for format"); |
| 12532 | VkImageCreateInfo image_create_info = {}; |
| 12533 | image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO; |
| 12534 | image_create_info.pNext = NULL; |
| 12535 | image_create_info.imageType = VK_IMAGE_TYPE_2D; |
| 12536 | image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM; |
| 12537 | image_create_info.extent.width = 32; |
| 12538 | image_create_info.extent.height = 32; |
| 12539 | image_create_info.extent.depth = 1; |
| 12540 | image_create_info.mipLevels = 1; |
| 12541 | image_create_info.arrayLayers = 1; |
| 12542 | image_create_info.samples = VK_SAMPLE_COUNT_1_BIT; |
| 12543 | image_create_info.tiling = VK_IMAGE_TILING_LINEAR; |
| 12544 | image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT; |
| 12545 | image_create_info.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED; |
| 12546 | image_create_info.flags = 0; |
| 12547 | |
| 12548 | VkImage nullImg; |
| 12549 | VkImageFormatProperties imgFmtProps; |
| 12550 | vkGetPhysicalDeviceImageFormatProperties( |
| 12551 | gpu(), image_create_info.format, image_create_info.imageType, |
| 12552 | image_create_info.tiling, image_create_info.usage, |
| 12553 | image_create_info.flags, &imgFmtProps); |
| 12554 | image_create_info.extent.depth = imgFmtProps.maxExtent.depth + 1; |
| 12555 | // Expect INVALID_FORMAT_LIMITS_VIOLATION |
| 12556 | vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg); |
| 12557 | m_errorMonitor->VerifyFound(); |
| 12558 | image_create_info.extent.depth = 1; |
| 12559 | |
| 12560 | m_errorMonitor->SetDesiredFailureMsg( |
| 12561 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 12562 | "exceeds allowable maximum supported by format of"); |
| 12563 | image_create_info.mipLevels = imgFmtProps.maxMipLevels + 1; |
| 12564 | // Expect INVALID_FORMAT_LIMITS_VIOLATION |
| 12565 | vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg); |
| 12566 | m_errorMonitor->VerifyFound(); |
| 12567 | image_create_info.mipLevels = 1; |
| 12568 | |
| 12569 | m_errorMonitor->SetDesiredFailureMsg( |
| 12570 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 12571 | "exceeds allowable maximum supported by format of"); |
| 12572 | image_create_info.arrayLayers = imgFmtProps.maxArrayLayers + 1; |
| 12573 | // Expect INVALID_FORMAT_LIMITS_VIOLATION |
| 12574 | vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg); |
| 12575 | m_errorMonitor->VerifyFound(); |
| 12576 | image_create_info.arrayLayers = 1; |
| 12577 | |
| 12578 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 12579 | "is not supported by format"); |
| 12580 | int samples = imgFmtProps.sampleCounts >> 1; |
| 12581 | image_create_info.samples = (VkSampleCountFlagBits)samples; |
| 12582 | // Expect INVALID_FORMAT_LIMITS_VIOLATION |
| 12583 | vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg); |
| 12584 | m_errorMonitor->VerifyFound(); |
| 12585 | image_create_info.samples = VK_SAMPLE_COUNT_1_BIT; |
| 12586 | |
| 12587 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 12588 | "pCreateInfo->initialLayout, must be " |
| 12589 | "VK_IMAGE_LAYOUT_UNDEFINED or " |
| 12590 | "VK_IMAGE_LAYOUT_PREINITIALIZED"); |
| 12591 | image_create_info.initialLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL; |
| 12592 | // Expect INVALID_LAYOUT |
| 12593 | vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg); |
| 12594 | m_errorMonitor->VerifyFound(); |
| 12595 | image_create_info.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED; |
| 12596 | } |
| 12597 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12598 | TEST_F(VkLayerTest, CopyImageFormatSizeMismatch) { |
Karl Schultz | bdb7595 | 2016-04-19 11:36:49 -0600 | [diff] [blame] | 12599 | VkResult err; |
| 12600 | bool pass; |
| 12601 | |
| 12602 | // Create color images with different format sizes and try to copy between them |
| 12603 | m_errorMonitor->SetDesiredFailureMsg( |
| 12604 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 12605 | "vkCmdCopyImage called with unmatched source and dest image format sizes"); |
| 12606 | |
| 12607 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 12608 | |
| 12609 | // Create two images of different types and try to copy between them |
| 12610 | VkImage srcImage; |
| 12611 | VkImage dstImage; |
| 12612 | VkDeviceMemory srcMem; |
| 12613 | VkDeviceMemory destMem; |
| 12614 | VkMemoryRequirements memReqs; |
| 12615 | |
| 12616 | VkImageCreateInfo image_create_info = {}; |
| 12617 | image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO; |
| 12618 | image_create_info.pNext = NULL; |
| 12619 | image_create_info.imageType = VK_IMAGE_TYPE_2D; |
| 12620 | image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM; |
| 12621 | image_create_info.extent.width = 32; |
| 12622 | image_create_info.extent.height = 32; |
| 12623 | image_create_info.extent.depth = 1; |
| 12624 | image_create_info.mipLevels = 1; |
| 12625 | image_create_info.arrayLayers = 1; |
| 12626 | image_create_info.samples = VK_SAMPLE_COUNT_1_BIT; |
| 12627 | image_create_info.tiling = VK_IMAGE_TILING_LINEAR; |
| 12628 | image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT; |
| 12629 | image_create_info.flags = 0; |
| 12630 | |
| 12631 | err = |
| 12632 | vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage); |
| 12633 | ASSERT_VK_SUCCESS(err); |
| 12634 | |
| 12635 | image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT; |
| 12636 | // Introduce failure by creating second image with a different-sized format. |
| 12637 | image_create_info.format = VK_FORMAT_R5G5B5A1_UNORM_PACK16; |
| 12638 | |
| 12639 | err = |
| 12640 | vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage); |
| 12641 | ASSERT_VK_SUCCESS(err); |
| 12642 | |
| 12643 | // Allocate memory |
| 12644 | VkMemoryAllocateInfo memAlloc = {}; |
| 12645 | memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO; |
| 12646 | memAlloc.pNext = NULL; |
| 12647 | memAlloc.allocationSize = 0; |
| 12648 | memAlloc.memoryTypeIndex = 0; |
| 12649 | |
| 12650 | vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs); |
| 12651 | memAlloc.allocationSize = memReqs.size; |
| 12652 | pass = |
| 12653 | m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0); |
| 12654 | ASSERT_TRUE(pass); |
| 12655 | err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem); |
| 12656 | ASSERT_VK_SUCCESS(err); |
| 12657 | |
| 12658 | vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs); |
| 12659 | memAlloc.allocationSize = memReqs.size; |
| 12660 | pass = |
| 12661 | m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0); |
| 12662 | ASSERT_TRUE(pass); |
| 12663 | err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem); |
| 12664 | ASSERT_VK_SUCCESS(err); |
| 12665 | |
| 12666 | err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0); |
| 12667 | ASSERT_VK_SUCCESS(err); |
| 12668 | err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0); |
| 12669 | ASSERT_VK_SUCCESS(err); |
| 12670 | |
| 12671 | BeginCommandBuffer(); |
| 12672 | VkImageCopy copyRegion; |
| 12673 | copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; |
| 12674 | copyRegion.srcSubresource.mipLevel = 0; |
| 12675 | copyRegion.srcSubresource.baseArrayLayer = 0; |
| 12676 | copyRegion.srcSubresource.layerCount = 0; |
| 12677 | copyRegion.srcOffset.x = 0; |
| 12678 | copyRegion.srcOffset.y = 0; |
| 12679 | copyRegion.srcOffset.z = 0; |
| 12680 | copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; |
| 12681 | copyRegion.dstSubresource.mipLevel = 0; |
| 12682 | copyRegion.dstSubresource.baseArrayLayer = 0; |
| 12683 | copyRegion.dstSubresource.layerCount = 0; |
| 12684 | copyRegion.dstOffset.x = 0; |
| 12685 | copyRegion.dstOffset.y = 0; |
| 12686 | copyRegion.dstOffset.z = 0; |
| 12687 | copyRegion.extent.width = 1; |
| 12688 | copyRegion.extent.height = 1; |
| 12689 | copyRegion.extent.depth = 1; |
| 12690 | m_commandBuffer->CopyImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, |
| 12691 | VK_IMAGE_LAYOUT_GENERAL, 1, ©Region); |
| 12692 | EndCommandBuffer(); |
| 12693 | |
| 12694 | m_errorMonitor->VerifyFound(); |
| 12695 | |
| 12696 | vkDestroyImage(m_device->device(), srcImage, NULL); |
| 12697 | vkDestroyImage(m_device->device(), dstImage, NULL); |
| 12698 | vkFreeMemory(m_device->device(), srcMem, NULL); |
| 12699 | vkFreeMemory(m_device->device(), destMem, NULL); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12700 | } |
| 12701 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12702 | TEST_F(VkLayerTest, CopyImageDepthStencilFormatMismatch) { |
| 12703 | VkResult err; |
| 12704 | bool pass; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12705 | |
Mark Lobodzinski | db11763 | 2016-03-31 10:45:56 -0600 | [diff] [blame] | 12706 | // 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] | 12707 | m_errorMonitor->SetDesiredFailureMsg( |
| 12708 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Mark Lobodzinski | db11763 | 2016-03-31 10:45:56 -0600 | [diff] [blame] | 12709 | "vkCmdCopyImage called with unmatched source and dest image depth"); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 12710 | |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12711 | ASSERT_NO_FATAL_FAILURE(InitState()); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12712 | |
| 12713 | // Create two images of different types and try to copy between them |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12714 | VkImage srcImage; |
| 12715 | VkImage dstImage; |
| 12716 | VkDeviceMemory srcMem; |
| 12717 | VkDeviceMemory destMem; |
| 12718 | VkMemoryRequirements memReqs; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12719 | |
| 12720 | VkImageCreateInfo image_create_info = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12721 | image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO; |
| 12722 | image_create_info.pNext = NULL; |
| 12723 | image_create_info.imageType = VK_IMAGE_TYPE_2D; |
| 12724 | image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM; |
| 12725 | image_create_info.extent.width = 32; |
| 12726 | image_create_info.extent.height = 32; |
| 12727 | image_create_info.extent.depth = 1; |
| 12728 | image_create_info.mipLevels = 1; |
| 12729 | image_create_info.arrayLayers = 1; |
| 12730 | image_create_info.samples = VK_SAMPLE_COUNT_1_BIT; |
| 12731 | image_create_info.tiling = VK_IMAGE_TILING_LINEAR; |
| 12732 | image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT; |
| 12733 | image_create_info.flags = 0; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12734 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12735 | err = |
| 12736 | vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12737 | ASSERT_VK_SUCCESS(err); |
| 12738 | |
Karl Schultz | bdb7595 | 2016-04-19 11:36:49 -0600 | [diff] [blame] | 12739 | image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT; |
| 12740 | |
Mark Lobodzinski | db11763 | 2016-03-31 10:45:56 -0600 | [diff] [blame] | 12741 | // Introduce failure by creating second image with a depth/stencil format |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12742 | image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL; |
Mark Lobodzinski | db11763 | 2016-03-31 10:45:56 -0600 | [diff] [blame] | 12743 | image_create_info.format = VK_FORMAT_D24_UNORM_S8_UINT; |
| 12744 | image_create_info.usage = VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12745 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12746 | err = |
| 12747 | vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12748 | ASSERT_VK_SUCCESS(err); |
| 12749 | |
| 12750 | // Allocate memory |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 12751 | VkMemoryAllocateInfo memAlloc = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12752 | memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO; |
| 12753 | memAlloc.pNext = NULL; |
| 12754 | memAlloc.allocationSize = 0; |
| 12755 | memAlloc.memoryTypeIndex = 0; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12756 | |
Courtney Goeltzenleuchter | 06d8947 | 2015-10-20 16:40:38 -0600 | [diff] [blame] | 12757 | vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12758 | memAlloc.allocationSize = memReqs.size; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12759 | pass = |
| 12760 | m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0); |
Courtney Goeltzenleuchter | 1d2f0dd | 2015-10-22 11:03:31 -0600 | [diff] [blame] | 12761 | ASSERT_TRUE(pass); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 12762 | err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12763 | ASSERT_VK_SUCCESS(err); |
| 12764 | |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 12765 | vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12766 | memAlloc.allocationSize = memReqs.size; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12767 | pass = |
| 12768 | m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0); |
Courtney Goeltzenleuchter | 1d2f0dd | 2015-10-22 11:03:31 -0600 | [diff] [blame] | 12769 | ASSERT_TRUE(pass); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 12770 | err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12771 | ASSERT_VK_SUCCESS(err); |
| 12772 | |
| 12773 | err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0); |
| 12774 | ASSERT_VK_SUCCESS(err); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 12775 | err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12776 | ASSERT_VK_SUCCESS(err); |
| 12777 | |
| 12778 | BeginCommandBuffer(); |
| 12779 | VkImageCopy copyRegion; |
Chia-I Wu | ab83a0e | 2015-10-27 19:00:15 +0800 | [diff] [blame] | 12780 | copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12781 | copyRegion.srcSubresource.mipLevel = 0; |
Courtney Goeltzenleuchter | 8367ce0 | 2015-10-16 09:46:00 -0600 | [diff] [blame] | 12782 | copyRegion.srcSubresource.baseArrayLayer = 0; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 12783 | copyRegion.srcSubresource.layerCount = 0; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12784 | copyRegion.srcOffset.x = 0; |
| 12785 | copyRegion.srcOffset.y = 0; |
| 12786 | copyRegion.srcOffset.z = 0; |
Chia-I Wu | ab83a0e | 2015-10-27 19:00:15 +0800 | [diff] [blame] | 12787 | copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 12788 | copyRegion.dstSubresource.mipLevel = 0; |
| 12789 | copyRegion.dstSubresource.baseArrayLayer = 0; |
| 12790 | copyRegion.dstSubresource.layerCount = 0; |
| 12791 | copyRegion.dstOffset.x = 0; |
| 12792 | copyRegion.dstOffset.y = 0; |
| 12793 | copyRegion.dstOffset.z = 0; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12794 | copyRegion.extent.width = 1; |
| 12795 | copyRegion.extent.height = 1; |
| 12796 | copyRegion.extent.depth = 1; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12797 | m_commandBuffer->CopyImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, |
| 12798 | VK_IMAGE_LAYOUT_GENERAL, 1, ©Region); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12799 | EndCommandBuffer(); |
| 12800 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 12801 | m_errorMonitor->VerifyFound(); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12802 | |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 12803 | vkDestroyImage(m_device->device(), srcImage, NULL); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 12804 | vkDestroyImage(m_device->device(), dstImage, NULL); |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 12805 | vkFreeMemory(m_device->device(), srcMem, NULL); |
| 12806 | vkFreeMemory(m_device->device(), destMem, NULL); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12807 | } |
| 12808 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12809 | TEST_F(VkLayerTest, ResolveImageLowSampleCount) { |
| 12810 | VkResult err; |
| 12811 | bool pass; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12812 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12813 | m_errorMonitor->SetDesiredFailureMsg( |
| 12814 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 12815 | "vkCmdResolveImage called with source sample count less than 2."); |
| 12816 | |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12817 | ASSERT_NO_FATAL_FAILURE(InitState()); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12818 | |
| 12819 | // 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] | 12820 | VkImage srcImage; |
| 12821 | VkImage dstImage; |
| 12822 | VkDeviceMemory srcMem; |
| 12823 | VkDeviceMemory destMem; |
| 12824 | VkMemoryRequirements memReqs; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12825 | |
| 12826 | VkImageCreateInfo image_create_info = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12827 | image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO; |
| 12828 | image_create_info.pNext = NULL; |
| 12829 | image_create_info.imageType = VK_IMAGE_TYPE_2D; |
| 12830 | image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM; |
| 12831 | image_create_info.extent.width = 32; |
| 12832 | image_create_info.extent.height = 1; |
| 12833 | image_create_info.extent.depth = 1; |
| 12834 | image_create_info.mipLevels = 1; |
| 12835 | image_create_info.arrayLayers = 1; |
| 12836 | image_create_info.samples = VK_SAMPLE_COUNT_1_BIT; |
| 12837 | image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL; |
| 12838 | image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT; |
| 12839 | image_create_info.flags = 0; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12840 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12841 | err = |
| 12842 | vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12843 | ASSERT_VK_SUCCESS(err); |
| 12844 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12845 | image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12846 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12847 | err = |
| 12848 | vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12849 | ASSERT_VK_SUCCESS(err); |
| 12850 | |
| 12851 | // Allocate memory |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 12852 | VkMemoryAllocateInfo memAlloc = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12853 | memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO; |
| 12854 | memAlloc.pNext = NULL; |
| 12855 | memAlloc.allocationSize = 0; |
| 12856 | memAlloc.memoryTypeIndex = 0; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12857 | |
Courtney Goeltzenleuchter | 06d8947 | 2015-10-20 16:40:38 -0600 | [diff] [blame] | 12858 | vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12859 | memAlloc.allocationSize = memReqs.size; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12860 | pass = |
| 12861 | m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0); |
Courtney Goeltzenleuchter | 1d2f0dd | 2015-10-22 11:03:31 -0600 | [diff] [blame] | 12862 | ASSERT_TRUE(pass); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 12863 | err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12864 | ASSERT_VK_SUCCESS(err); |
| 12865 | |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 12866 | vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12867 | memAlloc.allocationSize = memReqs.size; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12868 | pass = |
| 12869 | m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0); |
Courtney Goeltzenleuchter | 1d2f0dd | 2015-10-22 11:03:31 -0600 | [diff] [blame] | 12870 | ASSERT_TRUE(pass); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 12871 | err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12872 | ASSERT_VK_SUCCESS(err); |
| 12873 | |
| 12874 | err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0); |
| 12875 | ASSERT_VK_SUCCESS(err); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 12876 | err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12877 | ASSERT_VK_SUCCESS(err); |
| 12878 | |
| 12879 | BeginCommandBuffer(); |
| 12880 | // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest? |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12881 | // VK_IMAGE_LAYOUT_UNDEFINED = 0, |
| 12882 | // VK_IMAGE_LAYOUT_GENERAL = 1, |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12883 | VkImageResolve resolveRegion; |
Chia-I Wu | ab83a0e | 2015-10-27 19:00:15 +0800 | [diff] [blame] | 12884 | resolveRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12885 | resolveRegion.srcSubresource.mipLevel = 0; |
Courtney Goeltzenleuchter | 8367ce0 | 2015-10-16 09:46:00 -0600 | [diff] [blame] | 12886 | resolveRegion.srcSubresource.baseArrayLayer = 0; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 12887 | resolveRegion.srcSubresource.layerCount = 0; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12888 | resolveRegion.srcOffset.x = 0; |
| 12889 | resolveRegion.srcOffset.y = 0; |
| 12890 | resolveRegion.srcOffset.z = 0; |
Chia-I Wu | ab83a0e | 2015-10-27 19:00:15 +0800 | [diff] [blame] | 12891 | resolveRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 12892 | resolveRegion.dstSubresource.mipLevel = 0; |
| 12893 | resolveRegion.dstSubresource.baseArrayLayer = 0; |
| 12894 | resolveRegion.dstSubresource.layerCount = 0; |
| 12895 | resolveRegion.dstOffset.x = 0; |
| 12896 | resolveRegion.dstOffset.y = 0; |
| 12897 | resolveRegion.dstOffset.z = 0; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12898 | resolveRegion.extent.width = 1; |
| 12899 | resolveRegion.extent.height = 1; |
| 12900 | resolveRegion.extent.depth = 1; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12901 | m_commandBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, |
| 12902 | VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12903 | EndCommandBuffer(); |
| 12904 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 12905 | m_errorMonitor->VerifyFound(); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12906 | |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 12907 | vkDestroyImage(m_device->device(), srcImage, NULL); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 12908 | vkDestroyImage(m_device->device(), dstImage, NULL); |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 12909 | vkFreeMemory(m_device->device(), srcMem, NULL); |
| 12910 | vkFreeMemory(m_device->device(), destMem, NULL); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12911 | } |
| 12912 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12913 | TEST_F(VkLayerTest, ResolveImageHighSampleCount) { |
| 12914 | VkResult err; |
| 12915 | bool pass; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12916 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12917 | m_errorMonitor->SetDesiredFailureMsg( |
| 12918 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 12919 | "vkCmdResolveImage called with dest sample count greater than 1."); |
| 12920 | |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12921 | ASSERT_NO_FATAL_FAILURE(InitState()); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12922 | |
Chris Forbes | a753069 | 2016-05-08 12:35:39 +1200 | [diff] [blame] | 12923 | // 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] | 12924 | VkImage srcImage; |
| 12925 | VkImage dstImage; |
| 12926 | VkDeviceMemory srcMem; |
| 12927 | VkDeviceMemory destMem; |
| 12928 | VkMemoryRequirements memReqs; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12929 | |
| 12930 | VkImageCreateInfo image_create_info = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12931 | image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO; |
| 12932 | image_create_info.pNext = NULL; |
| 12933 | image_create_info.imageType = VK_IMAGE_TYPE_2D; |
| 12934 | image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM; |
| 12935 | image_create_info.extent.width = 32; |
| 12936 | image_create_info.extent.height = 1; |
| 12937 | image_create_info.extent.depth = 1; |
| 12938 | image_create_info.mipLevels = 1; |
| 12939 | image_create_info.arrayLayers = 1; |
Chris Forbes | a753069 | 2016-05-08 12:35:39 +1200 | [diff] [blame] | 12940 | image_create_info.samples = VK_SAMPLE_COUNT_4_BIT; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12941 | image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL; |
| 12942 | // Note: Some implementations expect color attachment usage for any |
| 12943 | // multisample surface |
| 12944 | image_create_info.usage = |
| 12945 | VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_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 | // Note: Some implementations expect color attachment usage for any |
| 12953 | // multisample surface |
| 12954 | image_create_info.usage = |
| 12955 | VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12956 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12957 | err = |
| 12958 | vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12959 | ASSERT_VK_SUCCESS(err); |
| 12960 | |
| 12961 | // Allocate memory |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 12962 | VkMemoryAllocateInfo memAlloc = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12963 | memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO; |
| 12964 | memAlloc.pNext = NULL; |
| 12965 | memAlloc.allocationSize = 0; |
| 12966 | memAlloc.memoryTypeIndex = 0; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12967 | |
Courtney Goeltzenleuchter | 06d8947 | 2015-10-20 16:40:38 -0600 | [diff] [blame] | 12968 | vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12969 | memAlloc.allocationSize = memReqs.size; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12970 | pass = |
| 12971 | m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0); |
Courtney Goeltzenleuchter | 1d2f0dd | 2015-10-22 11:03:31 -0600 | [diff] [blame] | 12972 | ASSERT_TRUE(pass); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 12973 | err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12974 | ASSERT_VK_SUCCESS(err); |
| 12975 | |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 12976 | vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12977 | memAlloc.allocationSize = memReqs.size; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12978 | pass = |
| 12979 | m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0); |
Courtney Goeltzenleuchter | 1d2f0dd | 2015-10-22 11:03:31 -0600 | [diff] [blame] | 12980 | ASSERT_TRUE(pass); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 12981 | err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12982 | ASSERT_VK_SUCCESS(err); |
| 12983 | |
| 12984 | err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0); |
| 12985 | ASSERT_VK_SUCCESS(err); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 12986 | err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12987 | ASSERT_VK_SUCCESS(err); |
| 12988 | |
| 12989 | BeginCommandBuffer(); |
| 12990 | // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest? |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12991 | // VK_IMAGE_LAYOUT_UNDEFINED = 0, |
| 12992 | // VK_IMAGE_LAYOUT_GENERAL = 1, |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12993 | VkImageResolve resolveRegion; |
Chia-I Wu | ab83a0e | 2015-10-27 19:00:15 +0800 | [diff] [blame] | 12994 | resolveRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12995 | resolveRegion.srcSubresource.mipLevel = 0; |
Courtney Goeltzenleuchter | 8367ce0 | 2015-10-16 09:46:00 -0600 | [diff] [blame] | 12996 | resolveRegion.srcSubresource.baseArrayLayer = 0; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 12997 | resolveRegion.srcSubresource.layerCount = 0; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12998 | resolveRegion.srcOffset.x = 0; |
| 12999 | resolveRegion.srcOffset.y = 0; |
| 13000 | resolveRegion.srcOffset.z = 0; |
Chia-I Wu | ab83a0e | 2015-10-27 19:00:15 +0800 | [diff] [blame] | 13001 | resolveRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 13002 | resolveRegion.dstSubresource.mipLevel = 0; |
| 13003 | resolveRegion.dstSubresource.baseArrayLayer = 0; |
| 13004 | resolveRegion.dstSubresource.layerCount = 0; |
| 13005 | resolveRegion.dstOffset.x = 0; |
| 13006 | resolveRegion.dstOffset.y = 0; |
| 13007 | resolveRegion.dstOffset.z = 0; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 13008 | resolveRegion.extent.width = 1; |
| 13009 | resolveRegion.extent.height = 1; |
| 13010 | resolveRegion.extent.depth = 1; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 13011 | m_commandBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, |
| 13012 | VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 13013 | EndCommandBuffer(); |
| 13014 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 13015 | m_errorMonitor->VerifyFound(); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 13016 | |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 13017 | vkDestroyImage(m_device->device(), srcImage, NULL); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 13018 | vkDestroyImage(m_device->device(), dstImage, NULL); |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 13019 | vkFreeMemory(m_device->device(), srcMem, NULL); |
| 13020 | vkFreeMemory(m_device->device(), destMem, NULL); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 13021 | } |
| 13022 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 13023 | TEST_F(VkLayerTest, ResolveImageFormatMismatch) { |
| 13024 | VkResult err; |
| 13025 | bool pass; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 13026 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 13027 | m_errorMonitor->SetDesiredFailureMsg( |
| 13028 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 13029 | "vkCmdResolveImage called with unmatched source and dest formats."); |
| 13030 | |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 13031 | ASSERT_NO_FATAL_FAILURE(InitState()); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 13032 | |
| 13033 | // Create two images of different types and try to copy between them |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 13034 | VkImage srcImage; |
| 13035 | VkImage dstImage; |
| 13036 | VkDeviceMemory srcMem; |
| 13037 | VkDeviceMemory destMem; |
| 13038 | VkMemoryRequirements memReqs; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 13039 | |
| 13040 | VkImageCreateInfo image_create_info = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 13041 | image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO; |
| 13042 | image_create_info.pNext = NULL; |
| 13043 | image_create_info.imageType = VK_IMAGE_TYPE_2D; |
| 13044 | image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM; |
| 13045 | image_create_info.extent.width = 32; |
| 13046 | image_create_info.extent.height = 1; |
| 13047 | image_create_info.extent.depth = 1; |
| 13048 | image_create_info.mipLevels = 1; |
| 13049 | image_create_info.arrayLayers = 1; |
| 13050 | image_create_info.samples = VK_SAMPLE_COUNT_2_BIT; |
| 13051 | image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL; |
| 13052 | // Note: Some implementations expect color attachment usage for any |
| 13053 | // multisample surface |
| 13054 | image_create_info.usage = |
| 13055 | VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT; |
| 13056 | image_create_info.flags = 0; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 13057 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 13058 | err = |
| 13059 | vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 13060 | ASSERT_VK_SUCCESS(err); |
| 13061 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 13062 | // Set format to something other than source image |
| 13063 | image_create_info.format = VK_FORMAT_R32_SFLOAT; |
| 13064 | // Note: Some implementations expect color attachment usage for any |
| 13065 | // multisample surface |
| 13066 | image_create_info.usage = |
| 13067 | VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT; |
| 13068 | image_create_info.samples = VK_SAMPLE_COUNT_1_BIT; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 13069 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 13070 | err = |
| 13071 | vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 13072 | ASSERT_VK_SUCCESS(err); |
| 13073 | |
| 13074 | // Allocate memory |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 13075 | VkMemoryAllocateInfo memAlloc = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 13076 | memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO; |
| 13077 | memAlloc.pNext = NULL; |
| 13078 | memAlloc.allocationSize = 0; |
| 13079 | memAlloc.memoryTypeIndex = 0; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 13080 | |
Courtney Goeltzenleuchter | 06d8947 | 2015-10-20 16:40:38 -0600 | [diff] [blame] | 13081 | vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 13082 | memAlloc.allocationSize = memReqs.size; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 13083 | pass = |
| 13084 | m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0); |
Courtney Goeltzenleuchter | 1d2f0dd | 2015-10-22 11:03:31 -0600 | [diff] [blame] | 13085 | ASSERT_TRUE(pass); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 13086 | err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 13087 | ASSERT_VK_SUCCESS(err); |
| 13088 | |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 13089 | vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 13090 | memAlloc.allocationSize = memReqs.size; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 13091 | pass = |
| 13092 | m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0); |
Courtney Goeltzenleuchter | 1d2f0dd | 2015-10-22 11:03:31 -0600 | [diff] [blame] | 13093 | ASSERT_TRUE(pass); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 13094 | err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 13095 | ASSERT_VK_SUCCESS(err); |
| 13096 | |
| 13097 | err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0); |
| 13098 | ASSERT_VK_SUCCESS(err); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 13099 | err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 13100 | ASSERT_VK_SUCCESS(err); |
| 13101 | |
| 13102 | BeginCommandBuffer(); |
| 13103 | // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest? |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 13104 | // VK_IMAGE_LAYOUT_UNDEFINED = 0, |
| 13105 | // VK_IMAGE_LAYOUT_GENERAL = 1, |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 13106 | VkImageResolve resolveRegion; |
Chia-I Wu | ab83a0e | 2015-10-27 19:00:15 +0800 | [diff] [blame] | 13107 | resolveRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 13108 | resolveRegion.srcSubresource.mipLevel = 0; |
Courtney Goeltzenleuchter | 8367ce0 | 2015-10-16 09:46:00 -0600 | [diff] [blame] | 13109 | resolveRegion.srcSubresource.baseArrayLayer = 0; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 13110 | resolveRegion.srcSubresource.layerCount = 0; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 13111 | resolveRegion.srcOffset.x = 0; |
| 13112 | resolveRegion.srcOffset.y = 0; |
| 13113 | resolveRegion.srcOffset.z = 0; |
Chia-I Wu | ab83a0e | 2015-10-27 19:00:15 +0800 | [diff] [blame] | 13114 | resolveRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 13115 | resolveRegion.dstSubresource.mipLevel = 0; |
| 13116 | resolveRegion.dstSubresource.baseArrayLayer = 0; |
| 13117 | resolveRegion.dstSubresource.layerCount = 0; |
| 13118 | resolveRegion.dstOffset.x = 0; |
| 13119 | resolveRegion.dstOffset.y = 0; |
| 13120 | resolveRegion.dstOffset.z = 0; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 13121 | resolveRegion.extent.width = 1; |
| 13122 | resolveRegion.extent.height = 1; |
| 13123 | resolveRegion.extent.depth = 1; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 13124 | m_commandBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, |
| 13125 | VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 13126 | EndCommandBuffer(); |
| 13127 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 13128 | m_errorMonitor->VerifyFound(); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 13129 | |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 13130 | vkDestroyImage(m_device->device(), srcImage, NULL); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 13131 | vkDestroyImage(m_device->device(), dstImage, NULL); |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 13132 | vkFreeMemory(m_device->device(), srcMem, NULL); |
| 13133 | vkFreeMemory(m_device->device(), destMem, NULL); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 13134 | } |
| 13135 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 13136 | TEST_F(VkLayerTest, ResolveImageTypeMismatch) { |
| 13137 | VkResult err; |
| 13138 | bool pass; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 13139 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 13140 | m_errorMonitor->SetDesiredFailureMsg( |
| 13141 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 13142 | "vkCmdResolveImage called with unmatched source and dest image types."); |
| 13143 | |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 13144 | ASSERT_NO_FATAL_FAILURE(InitState()); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 13145 | |
| 13146 | // Create two images of different types and try to copy between them |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 13147 | VkImage srcImage; |
| 13148 | VkImage dstImage; |
| 13149 | VkDeviceMemory srcMem; |
| 13150 | VkDeviceMemory destMem; |
| 13151 | VkMemoryRequirements memReqs; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 13152 | |
| 13153 | VkImageCreateInfo image_create_info = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 13154 | image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO; |
| 13155 | image_create_info.pNext = NULL; |
| 13156 | image_create_info.imageType = VK_IMAGE_TYPE_2D; |
| 13157 | image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM; |
| 13158 | image_create_info.extent.width = 32; |
| 13159 | image_create_info.extent.height = 1; |
| 13160 | image_create_info.extent.depth = 1; |
| 13161 | image_create_info.mipLevels = 1; |
| 13162 | image_create_info.arrayLayers = 1; |
| 13163 | image_create_info.samples = VK_SAMPLE_COUNT_2_BIT; |
| 13164 | image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL; |
| 13165 | // Note: Some implementations expect color attachment usage for any |
| 13166 | // multisample surface |
| 13167 | image_create_info.usage = |
| 13168 | VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT; |
| 13169 | image_create_info.flags = 0; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 13170 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 13171 | err = |
| 13172 | vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 13173 | ASSERT_VK_SUCCESS(err); |
| 13174 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 13175 | image_create_info.imageType = VK_IMAGE_TYPE_1D; |
| 13176 | // Note: Some implementations expect color attachment usage for any |
| 13177 | // multisample surface |
| 13178 | image_create_info.usage = |
| 13179 | VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT; |
| 13180 | image_create_info.samples = VK_SAMPLE_COUNT_1_BIT; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 13181 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 13182 | err = |
| 13183 | vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 13184 | ASSERT_VK_SUCCESS(err); |
| 13185 | |
| 13186 | // Allocate memory |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 13187 | VkMemoryAllocateInfo memAlloc = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 13188 | memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO; |
| 13189 | memAlloc.pNext = NULL; |
| 13190 | memAlloc.allocationSize = 0; |
| 13191 | memAlloc.memoryTypeIndex = 0; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 13192 | |
Courtney Goeltzenleuchter | 06d8947 | 2015-10-20 16:40:38 -0600 | [diff] [blame] | 13193 | vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 13194 | memAlloc.allocationSize = memReqs.size; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 13195 | pass = |
| 13196 | m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0); |
Courtney Goeltzenleuchter | 1d2f0dd | 2015-10-22 11:03:31 -0600 | [diff] [blame] | 13197 | ASSERT_TRUE(pass); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 13198 | err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 13199 | ASSERT_VK_SUCCESS(err); |
| 13200 | |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 13201 | vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 13202 | memAlloc.allocationSize = memReqs.size; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 13203 | pass = |
| 13204 | m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0); |
Courtney Goeltzenleuchter | 1d2f0dd | 2015-10-22 11:03:31 -0600 | [diff] [blame] | 13205 | ASSERT_TRUE(pass); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 13206 | err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 13207 | ASSERT_VK_SUCCESS(err); |
| 13208 | |
| 13209 | err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0); |
| 13210 | ASSERT_VK_SUCCESS(err); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 13211 | err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 13212 | ASSERT_VK_SUCCESS(err); |
| 13213 | |
| 13214 | BeginCommandBuffer(); |
| 13215 | // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest? |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 13216 | // VK_IMAGE_LAYOUT_UNDEFINED = 0, |
| 13217 | // VK_IMAGE_LAYOUT_GENERAL = 1, |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 13218 | VkImageResolve resolveRegion; |
Chia-I Wu | ab83a0e | 2015-10-27 19:00:15 +0800 | [diff] [blame] | 13219 | resolveRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 13220 | resolveRegion.srcSubresource.mipLevel = 0; |
Courtney Goeltzenleuchter | 8367ce0 | 2015-10-16 09:46:00 -0600 | [diff] [blame] | 13221 | resolveRegion.srcSubresource.baseArrayLayer = 0; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 13222 | resolveRegion.srcSubresource.layerCount = 0; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 13223 | resolveRegion.srcOffset.x = 0; |
| 13224 | resolveRegion.srcOffset.y = 0; |
| 13225 | resolveRegion.srcOffset.z = 0; |
Chia-I Wu | ab83a0e | 2015-10-27 19:00:15 +0800 | [diff] [blame] | 13226 | resolveRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 13227 | resolveRegion.dstSubresource.mipLevel = 0; |
| 13228 | resolveRegion.dstSubresource.baseArrayLayer = 0; |
| 13229 | resolveRegion.dstSubresource.layerCount = 0; |
| 13230 | resolveRegion.dstOffset.x = 0; |
| 13231 | resolveRegion.dstOffset.y = 0; |
| 13232 | resolveRegion.dstOffset.z = 0; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 13233 | resolveRegion.extent.width = 1; |
| 13234 | resolveRegion.extent.height = 1; |
| 13235 | resolveRegion.extent.depth = 1; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 13236 | m_commandBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, |
| 13237 | VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 13238 | EndCommandBuffer(); |
| 13239 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 13240 | m_errorMonitor->VerifyFound(); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 13241 | |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 13242 | vkDestroyImage(m_device->device(), srcImage, NULL); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 13243 | vkDestroyImage(m_device->device(), dstImage, NULL); |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 13244 | vkFreeMemory(m_device->device(), srcMem, NULL); |
| 13245 | vkFreeMemory(m_device->device(), destMem, NULL); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 13246 | } |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 13247 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 13248 | TEST_F(VkLayerTest, DepthStencilImageViewWithColorAspectBitError) { |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 13249 | // 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] | 13250 | // to using a DS format, then cause it to hit error due to COLOR_BIT not |
| 13251 | // set in aspect |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 13252 | // The image format check comes 2nd in validation so we trigger it first, |
| 13253 | // 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] | 13254 | VkResult err; |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 13255 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 13256 | m_errorMonitor->SetDesiredFailureMsg( |
| 13257 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 13258 | "Combination depth/stencil image formats can have only the "); |
| 13259 | |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 13260 | ASSERT_NO_FATAL_FAILURE(InitState()); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 13261 | |
Chia-I Wu | 1b99bb2 | 2015-10-27 19:25:11 +0800 | [diff] [blame] | 13262 | VkDescriptorPoolSize ds_type_count = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 13263 | ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE; |
| 13264 | ds_type_count.descriptorCount = 1; |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 13265 | |
| 13266 | VkDescriptorPoolCreateInfo ds_pool_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 13267 | ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO; |
| 13268 | ds_pool_ci.pNext = NULL; |
| 13269 | ds_pool_ci.maxSets = 1; |
| 13270 | ds_pool_ci.poolSizeCount = 1; |
| 13271 | ds_pool_ci.pPoolSizes = &ds_type_count; |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 13272 | |
| 13273 | VkDescriptorPool ds_pool; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 13274 | err = |
| 13275 | vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool); |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 13276 | ASSERT_VK_SUCCESS(err); |
| 13277 | |
| 13278 | VkDescriptorSetLayoutBinding dsl_binding = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 13279 | dsl_binding.binding = 0; |
| 13280 | dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE; |
| 13281 | dsl_binding.descriptorCount = 1; |
| 13282 | dsl_binding.stageFlags = VK_SHADER_STAGE_ALL; |
| 13283 | dsl_binding.pImmutableSamplers = NULL; |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 13284 | |
| 13285 | VkDescriptorSetLayoutCreateInfo ds_layout_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 13286 | ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO; |
| 13287 | ds_layout_ci.pNext = NULL; |
| 13288 | ds_layout_ci.bindingCount = 1; |
| 13289 | ds_layout_ci.pBindings = &dsl_binding; |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 13290 | VkDescriptorSetLayout ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 13291 | err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, |
| 13292 | &ds_layout); |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 13293 | ASSERT_VK_SUCCESS(err); |
| 13294 | |
| 13295 | VkDescriptorSet descriptorSet; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 13296 | VkDescriptorSetAllocateInfo alloc_info = {}; |
Chia-I Wu | 00ce540 | 2015-11-10 16:21:09 +0800 | [diff] [blame] | 13297 | alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO; |
Jon Ashburn | f19916e | 2016-01-11 13:12:43 -0700 | [diff] [blame] | 13298 | alloc_info.descriptorSetCount = 1; |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 13299 | alloc_info.descriptorPool = ds_pool; |
| 13300 | alloc_info.pSetLayouts = &ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 13301 | err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, |
| 13302 | &descriptorSet); |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 13303 | ASSERT_VK_SUCCESS(err); |
| 13304 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 13305 | VkImage image_bad; |
| 13306 | VkImage image_good; |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 13307 | // One bad format and one good format for Color attachment |
Tobin Ehlis | 269f032 | 2016-05-25 16:24:21 -0600 | [diff] [blame] | 13308 | const VkFormat tex_format_bad = VK_FORMAT_D24_UNORM_S8_UINT; |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 13309 | const VkFormat tex_format_good = VK_FORMAT_B8G8R8A8_UNORM; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 13310 | const int32_t tex_width = 32; |
| 13311 | const int32_t tex_height = 32; |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 13312 | |
| 13313 | VkImageCreateInfo image_create_info = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 13314 | image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO; |
| 13315 | image_create_info.pNext = NULL; |
| 13316 | image_create_info.imageType = VK_IMAGE_TYPE_2D; |
| 13317 | image_create_info.format = tex_format_bad; |
| 13318 | image_create_info.extent.width = tex_width; |
| 13319 | image_create_info.extent.height = tex_height; |
| 13320 | image_create_info.extent.depth = 1; |
| 13321 | image_create_info.mipLevels = 1; |
| 13322 | image_create_info.arrayLayers = 1; |
| 13323 | image_create_info.samples = VK_SAMPLE_COUNT_1_BIT; |
| 13324 | image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL; |
| 13325 | image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT | |
| 13326 | VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT; |
| 13327 | image_create_info.flags = 0; |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 13328 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 13329 | err = |
| 13330 | vkCreateImage(m_device->device(), &image_create_info, NULL, &image_bad); |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 13331 | ASSERT_VK_SUCCESS(err); |
| 13332 | image_create_info.format = tex_format_good; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 13333 | image_create_info.usage = |
| 13334 | VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT; |
| 13335 | err = vkCreateImage(m_device->device(), &image_create_info, NULL, |
| 13336 | &image_good); |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 13337 | ASSERT_VK_SUCCESS(err); |
| 13338 | |
| 13339 | VkImageViewCreateInfo image_view_create_info = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 13340 | image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO; |
| 13341 | image_view_create_info.image = image_bad; |
| 13342 | image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D; |
| 13343 | image_view_create_info.format = tex_format_bad; |
| 13344 | image_view_create_info.subresourceRange.baseArrayLayer = 0; |
| 13345 | image_view_create_info.subresourceRange.baseMipLevel = 0; |
| 13346 | image_view_create_info.subresourceRange.layerCount = 1; |
| 13347 | image_view_create_info.subresourceRange.levelCount = 1; |
| 13348 | image_view_create_info.subresourceRange.aspectMask = |
| 13349 | VK_IMAGE_ASPECT_COLOR_BIT; |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 13350 | |
| 13351 | VkImageView view; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 13352 | err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, |
| 13353 | &view); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 13354 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 13355 | m_errorMonitor->VerifyFound(); |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 13356 | |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 13357 | vkDestroyImage(m_device->device(), image_bad, NULL); |
| 13358 | vkDestroyImage(m_device->device(), image_good, NULL); |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 13359 | vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL); |
| 13360 | vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL); |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 13361 | } |
Tobin Ehlis | 6e23d77 | 2016-05-19 11:08:34 -0600 | [diff] [blame] | 13362 | |
| 13363 | TEST_F(VkLayerTest, ClearImageErrors) { |
| 13364 | TEST_DESCRIPTION("Call ClearColorImage w/ a depth|stencil image and " |
| 13365 | "ClearDepthStencilImage with a color image."); |
| 13366 | |
| 13367 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 13368 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 13369 | |
| 13370 | // Renderpass is started here so end it as Clear cmds can't be in renderpass |
| 13371 | BeginCommandBuffer(); |
| 13372 | m_commandBuffer->EndRenderPass(); |
| 13373 | |
| 13374 | // Color image |
| 13375 | VkClearColorValue clear_color; |
| 13376 | memset(clear_color.uint32, 0, sizeof(uint32_t) * 4); |
| 13377 | VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT; |
| 13378 | const VkFormat color_format = VK_FORMAT_B8G8R8A8_UNORM; |
| 13379 | const int32_t img_width = 32; |
| 13380 | const int32_t img_height = 32; |
| 13381 | VkImageCreateInfo image_create_info = {}; |
| 13382 | image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO; |
| 13383 | image_create_info.pNext = NULL; |
| 13384 | image_create_info.imageType = VK_IMAGE_TYPE_2D; |
| 13385 | image_create_info.format = color_format; |
| 13386 | image_create_info.extent.width = img_width; |
| 13387 | image_create_info.extent.height = img_height; |
| 13388 | image_create_info.extent.depth = 1; |
| 13389 | image_create_info.mipLevels = 1; |
| 13390 | image_create_info.arrayLayers = 1; |
| 13391 | image_create_info.samples = VK_SAMPLE_COUNT_1_BIT; |
| 13392 | image_create_info.tiling = VK_IMAGE_TILING_LINEAR; |
| 13393 | image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT; |
| 13394 | |
| 13395 | vk_testing::Image color_image; |
| 13396 | color_image.init(*m_device, (const VkImageCreateInfo &)image_create_info, |
| 13397 | reqs); |
| 13398 | |
| 13399 | const VkImageSubresourceRange color_range = |
| 13400 | vk_testing::Image::subresource_range(image_create_info, |
| 13401 | VK_IMAGE_ASPECT_COLOR_BIT); |
| 13402 | |
| 13403 | // Depth/Stencil image |
| 13404 | VkClearDepthStencilValue clear_value = {0}; |
| 13405 | reqs = 0; // don't need HOST_VISIBLE DS image |
| 13406 | VkImageCreateInfo ds_image_create_info = vk_testing::Image::create_info(); |
| 13407 | ds_image_create_info.imageType = VK_IMAGE_TYPE_2D; |
| 13408 | ds_image_create_info.format = VK_FORMAT_D24_UNORM_S8_UINT; |
| 13409 | ds_image_create_info.extent.width = 64; |
| 13410 | ds_image_create_info.extent.height = 64; |
| 13411 | ds_image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL; |
| 13412 | ds_image_create_info.usage = VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT; |
| 13413 | |
| 13414 | vk_testing::Image ds_image; |
| 13415 | ds_image.init(*m_device, (const VkImageCreateInfo &)ds_image_create_info, |
| 13416 | reqs); |
| 13417 | |
| 13418 | const VkImageSubresourceRange ds_range = |
| 13419 | vk_testing::Image::subresource_range(ds_image_create_info, |
| 13420 | VK_IMAGE_ASPECT_DEPTH_BIT); |
| 13421 | |
| 13422 | m_errorMonitor->SetDesiredFailureMsg( |
| 13423 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 13424 | "vkCmdClearColorImage called with depth/stencil image."); |
| 13425 | |
| 13426 | vkCmdClearColorImage(m_commandBuffer->GetBufferHandle(), ds_image.handle(), |
| 13427 | VK_IMAGE_LAYOUT_GENERAL, &clear_color, 1, |
| 13428 | &color_range); |
| 13429 | |
| 13430 | m_errorMonitor->VerifyFound(); |
| 13431 | |
Tony Barbour | 26434b9 | 2016-06-02 09:43:50 -0600 | [diff] [blame] | 13432 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 13433 | "vkCmdClearColorImage called with " |
| 13434 | "image created without " |
| 13435 | "VK_IMAGE_USAGE_TRANSFER_DST_BIT"); |
| 13436 | |
| 13437 | vkCmdClearColorImage(m_commandBuffer->GetBufferHandle(), ds_image.handle(), |
| 13438 | VK_IMAGE_LAYOUT_GENERAL, &clear_color, 1, |
| 13439 | &color_range); |
| 13440 | |
| 13441 | m_errorMonitor->VerifyFound(); |
| 13442 | |
Tobin Ehlis | 6e23d77 | 2016-05-19 11:08:34 -0600 | [diff] [blame] | 13443 | // Call CmdClearDepthStencilImage with color image |
| 13444 | m_errorMonitor->SetDesiredFailureMsg( |
| 13445 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 13446 | "vkCmdClearDepthStencilImage called without a depth/stencil image."); |
| 13447 | |
| 13448 | vkCmdClearDepthStencilImage( |
| 13449 | m_commandBuffer->GetBufferHandle(), color_image.handle(), |
| 13450 | VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL, &clear_value, 1, |
| 13451 | &ds_range); |
| 13452 | |
| 13453 | m_errorMonitor->VerifyFound(); |
| 13454 | } |
Tobin Ehlis | cde0889 | 2015-09-22 10:11:37 -0600 | [diff] [blame] | 13455 | #endif // IMAGE_TESTS |
| 13456 | |
Tony Barbour | 300a608 | 2015-04-07 13:44:53 -0600 | [diff] [blame] | 13457 | int main(int argc, char **argv) { |
| 13458 | int result; |
| 13459 | |
Cody Northrop | 8e54a40 | 2016-03-08 22:25:52 -0700 | [diff] [blame] | 13460 | #ifdef ANDROID |
| 13461 | int vulkanSupport = InitVulkan(); |
| 13462 | if (vulkanSupport == 0) |
| 13463 | return 1; |
| 13464 | #endif |
| 13465 | |
Tony Barbour | 300a608 | 2015-04-07 13:44:53 -0600 | [diff] [blame] | 13466 | ::testing::InitGoogleTest(&argc, argv); |
Tony Barbour | 6918cd5 | 2015-04-09 12:58:51 -0600 | [diff] [blame] | 13467 | VkTestFramework::InitArgs(&argc, argv); |
Tony Barbour | 300a608 | 2015-04-07 13:44:53 -0600 | [diff] [blame] | 13468 | |
| 13469 | ::testing::AddGlobalTestEnvironment(new TestEnvironment); |
| 13470 | |
| 13471 | result = RUN_ALL_TESTS(); |
| 13472 | |
Tony Barbour | 6918cd5 | 2015-04-09 12:58:51 -0600 | [diff] [blame] | 13473 | VkTestFramework::Finish(); |
Tony Barbour | 300a608 | 2015-04-07 13:44:53 -0600 | [diff] [blame] | 13474 | return result; |
| 13475 | } |