Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2015-2016 The Khronos Group Inc. |
| 3 | * Copyright (c) 2015-2016 Valve Corporation |
| 4 | * Copyright (c) 2015-2016 LunarG, Inc. |
Michael Lentine | 0a369f6 | 2016-02-03 16:51:46 -0600 | [diff] [blame] | 5 | * Copyright (c) 2015-2016 Google, Inc. |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6 | * |
Jon Ashburn | 3ebf125 | 2016-04-19 11:30:31 -0600 | [diff] [blame] | 7 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 8 | * you may not use this file except in compliance with the License. |
| 9 | * You may obtain a copy of the License at |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 10 | * |
Jon Ashburn | 3ebf125 | 2016-04-19 11:30:31 -0600 | [diff] [blame] | 11 | * http://www.apache.org/licenses/LICENSE-2.0 |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12 | * |
| 13 | * Author: Chia-I Wu <olvaffe@gmail.com> |
| 14 | * Author: Chris Forbes <chrisf@ijw.co.nz> |
| 15 | * Author: Courtney Goeltzenleuchter <courtney@LunarG.com> |
| 16 | * Author: Mark Lobodzinski <mark@lunarg.com> |
| 17 | * Author: Mike Stroyan <mike@LunarG.com> |
| 18 | * Author: Tobin Ehlis <tobine@google.com> |
| 19 | * Author: Tony Barbour <tony@LunarG.com> |
| 20 | */ |
Tony Barbour | 65c48b3 | 2015-11-17 10:02:56 -0700 | [diff] [blame] | 21 | |
Cody Northrop | 8e54a40 | 2016-03-08 22:25:52 -0700 | [diff] [blame] | 22 | #ifdef ANDROID |
| 23 | #include "vulkan_wrapper.h" |
| 24 | #else |
David Pinedo | 9316d3b | 2015-11-06 12:54:48 -0700 | [diff] [blame] | 25 | #include <vulkan/vulkan.h> |
Cody Northrop | 8e54a40 | 2016-03-08 22:25:52 -0700 | [diff] [blame] | 26 | #endif |
Courtney Goeltzenleuchter | 58f3eff | 2015-10-07 13:28:58 -0600 | [diff] [blame] | 27 | #include "test_common.h" |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 28 | #include "vkrenderframework.h" |
Tobin Ehlis | a0cb02e | 2015-07-03 10:15:26 -0600 | [diff] [blame] | 29 | #include "vk_layer_config.h" |
Jon Ashburn | 7fa7e22 | 2016-02-02 12:08:10 -0700 | [diff] [blame] | 30 | #include "icd-spv.h" |
Tony Barbour | 300a608 | 2015-04-07 13:44:53 -0600 | [diff] [blame] | 31 | |
Mark Lobodzinski | 3780e14 | 2015-05-14 15:08:13 -0500 | [diff] [blame] | 32 | #define GLM_FORCE_RADIANS |
| 33 | #include "glm/glm.hpp" |
| 34 | #include <glm/gtc/matrix_transform.hpp> |
| 35 | |
Dustin Graves | ffa90fa | 2016-05-06 11:20:38 -0600 | [diff] [blame] | 36 | #define PARAMETER_VALIDATION_TESTS 1 |
Tobin Ehlis | 0788f52 | 2015-05-26 16:11:58 -0600 | [diff] [blame] | 37 | #define MEM_TRACKER_TESTS 1 |
| 38 | #define OBJ_TRACKER_TESTS 1 |
| 39 | #define DRAW_STATE_TESTS 1 |
| 40 | #define THREADING_TESTS 1 |
Chris Forbes | 9f7ff63 | 2015-05-25 11:13:08 +1200 | [diff] [blame] | 41 | #define SHADER_CHECKER_TESTS 1 |
Mark Lobodzinski | 209b529 | 2015-09-17 09:44:05 -0600 | [diff] [blame] | 42 | #define DEVICE_LIMITS_TESTS 1 |
Tobin Ehlis | cde0889 | 2015-09-22 10:11:37 -0600 | [diff] [blame] | 43 | #define IMAGE_TESTS 1 |
Tobin Ehlis | 0788f52 | 2015-05-26 16:11:58 -0600 | [diff] [blame] | 44 | |
Mark Lobodzinski | 3780e14 | 2015-05-14 15:08:13 -0500 | [diff] [blame] | 45 | //-------------------------------------------------------------------------------------- |
| 46 | // Mesh and VertexFormat Data |
| 47 | //-------------------------------------------------------------------------------------- |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 48 | struct Vertex { |
| 49 | float posX, posY, posZ, posW; // Position data |
| 50 | float r, g, b, a; // Color |
Mark Lobodzinski | 3780e14 | 2015-05-14 15:08:13 -0500 | [diff] [blame] | 51 | }; |
| 52 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 53 | #define XYZ1(_x_, _y_, _z_) (_x_), (_y_), (_z_), 1.f |
Mark Lobodzinski | 3780e14 | 2015-05-14 15:08:13 -0500 | [diff] [blame] | 54 | |
| 55 | typedef enum _BsoFailSelect { |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 56 | BsoFailNone = 0x00000000, |
| 57 | BsoFailLineWidth = 0x00000001, |
| 58 | BsoFailDepthBias = 0x00000002, |
| 59 | BsoFailViewport = 0x00000004, |
| 60 | BsoFailScissor = 0x00000008, |
| 61 | BsoFailBlend = 0x00000010, |
| 62 | BsoFailDepthBounds = 0x00000020, |
| 63 | BsoFailStencilReadMask = 0x00000040, |
| 64 | BsoFailStencilWriteMask = 0x00000080, |
| 65 | BsoFailStencilReference = 0x00000100, |
Mark Mueller | d491441 | 2016-06-13 17:52:06 -0600 | [diff] [blame] | 66 | BsoFailCmdClearAttachments = 0x00000200, |
Mark Lobodzinski | 3780e14 | 2015-05-14 15:08:13 -0500 | [diff] [blame] | 67 | } BsoFailSelect; |
| 68 | |
| 69 | struct vktriangle_vs_uniform { |
| 70 | // Must start with MVP |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 71 | float mvp[4][4]; |
| 72 | float position[3][4]; |
| 73 | float color[3][4]; |
Mark Lobodzinski | 3780e14 | 2015-05-14 15:08:13 -0500 | [diff] [blame] | 74 | }; |
| 75 | |
Mark Lobodzinski | 75a97e6 | 2015-06-02 09:41:30 -0500 | [diff] [blame] | 76 | static const char bindStateVertShaderText[] = |
Chris Forbes | 7b34280 | 2016-04-07 13:20:10 +1200 | [diff] [blame] | 77 | "#version 450\n" |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 78 | "vec2 vertices[3];\n" |
| 79 | "out gl_PerVertex {\n" |
| 80 | " vec4 gl_Position;\n" |
| 81 | "};\n" |
| 82 | "void main() {\n" |
| 83 | " vertices[0] = vec2(-1.0, -1.0);\n" |
| 84 | " vertices[1] = vec2( 1.0, -1.0);\n" |
| 85 | " vertices[2] = vec2( 0.0, 1.0);\n" |
| 86 | " gl_Position = vec4(vertices[gl_VertexIndex % 3], 0.0, 1.0);\n" |
| 87 | "}\n"; |
Mark Lobodzinski | 3780e14 | 2015-05-14 15:08:13 -0500 | [diff] [blame] | 88 | |
Mark Lobodzinski | 75a97e6 | 2015-06-02 09:41:30 -0500 | [diff] [blame] | 89 | static const char bindStateFragShaderText[] = |
Chris Forbes | 7b34280 | 2016-04-07 13:20:10 +1200 | [diff] [blame] | 90 | "#version 450\n" |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 91 | "\n" |
| 92 | "layout(location = 0) out vec4 uFragColor;\n" |
| 93 | "void main(){\n" |
| 94 | " uFragColor = vec4(0,1,0,1);\n" |
| 95 | "}\n"; |
Mark Lobodzinski | 3780e14 | 2015-05-14 15:08:13 -0500 | [diff] [blame] | 96 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 97 | static VKAPI_ATTR VkBool32 VKAPI_CALL |
| 98 | myDbgFunc(VkFlags msgFlags, VkDebugReportObjectTypeEXT objType, |
| 99 | uint64_t srcObject, size_t location, int32_t msgCode, |
| 100 | const char *pLayerPrefix, const char *pMsg, void *pUserData); |
Tony Barbour | 300a608 | 2015-04-07 13:44:53 -0600 | [diff] [blame] | 101 | |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 102 | // ******************************************************** |
| 103 | // ErrorMonitor Usage: |
| 104 | // |
| 105 | // Call SetDesiredFailureMsg with a string to be compared against all |
| 106 | // encountered log messages. Passing NULL will match all log messages. |
| 107 | // logMsg will return true for skipCall only if msg is matched or NULL. |
| 108 | // |
| 109 | // Call DesiredMsgFound to determine if the desired failure message |
| 110 | // was encountered. |
| 111 | |
Tony Barbour | 300a608 | 2015-04-07 13:44:53 -0600 | [diff] [blame] | 112 | class ErrorMonitor { |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 113 | public: |
| 114 | ErrorMonitor() { |
Mike Stroyan | 4268d1f | 2015-07-13 14:45:35 -0600 | [diff] [blame] | 115 | test_platform_thread_create_mutex(&m_mutex); |
| 116 | test_platform_thread_lock_mutex(&m_mutex); |
Mark Lobodzinski | 510e20d | 2016-02-11 09:26:16 -0700 | [diff] [blame] | 117 | m_msgFlags = VK_DEBUG_REPORT_INFORMATION_BIT_EXT; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 118 | m_bailout = NULL; |
Mike Stroyan | 4268d1f | 2015-07-13 14:45:35 -0600 | [diff] [blame] | 119 | test_platform_thread_unlock_mutex(&m_mutex); |
Tony Barbour | 300a608 | 2015-04-07 13:44:53 -0600 | [diff] [blame] | 120 | } |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 121 | |
Dustin Graves | 4845814 | 2016-04-29 16:11:55 -0600 | [diff] [blame] | 122 | ~ErrorMonitor() { test_platform_thread_delete_mutex(&m_mutex); } |
| 123 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 124 | void SetDesiredFailureMsg(VkFlags msgFlags, const char *msgString) { |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 125 | // also discard all collected messages to this point |
Mike Stroyan | 4268d1f | 2015-07-13 14:45:35 -0600 | [diff] [blame] | 126 | test_platform_thread_lock_mutex(&m_mutex); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 127 | m_failureMsg.clear(); |
| 128 | m_otherMsgs.clear(); |
| 129 | m_desiredMsg = msgString; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 130 | m_msgFound = VK_FALSE; |
| 131 | m_msgFlags = msgFlags; |
Mike Stroyan | 4268d1f | 2015-07-13 14:45:35 -0600 | [diff] [blame] | 132 | test_platform_thread_unlock_mutex(&m_mutex); |
Tony Barbour | 300a608 | 2015-04-07 13:44:53 -0600 | [diff] [blame] | 133 | } |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 134 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 135 | VkBool32 CheckForDesiredMsg(VkFlags msgFlags, const char *msgString) { |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 136 | VkBool32 result = VK_FALSE; |
Mike Stroyan | 4268d1f | 2015-07-13 14:45:35 -0600 | [diff] [blame] | 137 | test_platform_thread_lock_mutex(&m_mutex); |
Mike Stroyan | accf769 | 2015-05-12 16:00:45 -0600 | [diff] [blame] | 138 | if (m_bailout != NULL) { |
| 139 | *m_bailout = true; |
| 140 | } |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 141 | string errorString(msgString); |
| 142 | if (msgFlags & m_msgFlags) { |
| 143 | if (errorString.find(m_desiredMsg) != string::npos) { |
Chris Forbes | c7b8ad7 | 2016-04-04 18:50:38 +1200 | [diff] [blame] | 144 | if (m_msgFound) { /* if multiple matches, don't lose all but the last! */ |
| 145 | m_otherMsgs.push_back(m_failureMsg); |
| 146 | } |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 147 | m_failureMsg = errorString; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 148 | m_msgFound = VK_TRUE; |
| 149 | result = VK_TRUE; |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 150 | } else { |
| 151 | m_otherMsgs.push_back(errorString); |
| 152 | } |
| 153 | } |
Mike Stroyan | 4268d1f | 2015-07-13 14:45:35 -0600 | [diff] [blame] | 154 | test_platform_thread_unlock_mutex(&m_mutex); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 155 | return result; |
Mike Stroyan | accf769 | 2015-05-12 16:00:45 -0600 | [diff] [blame] | 156 | } |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 157 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 158 | vector<string> GetOtherFailureMsgs(void) { return m_otherMsgs; } |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 159 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 160 | string GetFailureMsg(void) { return m_failureMsg; } |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 161 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 162 | VkBool32 DesiredMsgFound(void) { return m_msgFound; } |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 163 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 164 | void SetBailout(bool *bailout) { m_bailout = bailout; } |
Tony Barbour | 300a608 | 2015-04-07 13:44:53 -0600 | [diff] [blame] | 165 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 166 | void DumpFailureMsgs(void) { |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 167 | vector<string> otherMsgs = GetOtherFailureMsgs(); |
| 168 | cout << "Other error messages logged for this test were:" << endl; |
| 169 | for (auto iter = otherMsgs.begin(); iter != otherMsgs.end(); iter++) { |
| 170 | cout << " " << *iter << endl; |
| 171 | } |
| 172 | } |
| 173 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 174 | /* helpers */ |
| 175 | |
| 176 | void ExpectSuccess() { |
| 177 | // match anything |
| 178 | SetDesiredFailureMsg(~0u, ""); |
| 179 | } |
| 180 | |
| 181 | void VerifyFound() { |
| 182 | // Not seeing the desired message is a failure. /Before/ throwing, dump |
| 183 | // any other messages. |
| 184 | if (!DesiredMsgFound()) { |
| 185 | DumpFailureMsgs(); |
| 186 | FAIL() << "Did not receive expected error '" << m_desiredMsg << "'"; |
| 187 | } |
| 188 | } |
| 189 | |
| 190 | void VerifyNotFound() { |
| 191 | // ExpectSuccess() configured us to match anything. Any error is a |
| 192 | // failure. |
| 193 | if (DesiredMsgFound()) { |
| 194 | DumpFailureMsgs(); |
| 195 | FAIL() << "Expected to succeed but got error: " << GetFailureMsg(); |
| 196 | } |
| 197 | } |
| 198 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 199 | private: |
| 200 | VkFlags m_msgFlags; |
| 201 | string m_desiredMsg; |
| 202 | string m_failureMsg; |
| 203 | vector<string> m_otherMsgs; |
Mike Stroyan | 4268d1f | 2015-07-13 14:45:35 -0600 | [diff] [blame] | 204 | test_platform_thread_mutex m_mutex; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 205 | bool *m_bailout; |
| 206 | VkBool32 m_msgFound; |
Tony Barbour | 300a608 | 2015-04-07 13:44:53 -0600 | [diff] [blame] | 207 | }; |
Mark Lobodzinski | 3780e14 | 2015-05-14 15:08:13 -0500 | [diff] [blame] | 208 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 209 | static VKAPI_ATTR VkBool32 VKAPI_CALL |
| 210 | myDbgFunc(VkFlags msgFlags, VkDebugReportObjectTypeEXT objType, |
| 211 | uint64_t srcObject, size_t location, int32_t msgCode, |
| 212 | const char *pLayerPrefix, const char *pMsg, void *pUserData) { |
| 213 | if (msgFlags & |
Mark Lobodzinski | 510e20d | 2016-02-11 09:26:16 -0700 | [diff] [blame] | 214 | (VK_DEBUG_REPORT_WARNING_BIT_EXT | VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 215 | VK_DEBUG_REPORT_ERROR_BIT_EXT)) { |
Tony Barbour | 0b4d956 | 2015-04-09 10:48:04 -0600 | [diff] [blame] | 216 | ErrorMonitor *errMonitor = (ErrorMonitor *)pUserData; |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 217 | return errMonitor->CheckForDesiredMsg(msgFlags, pMsg); |
Tony Barbour | 0b4d956 | 2015-04-09 10:48:04 -0600 | [diff] [blame] | 218 | } |
Courtney Goeltzenleuchter | 0664083 | 2015-09-04 13:52:24 -0600 | [diff] [blame] | 219 | return false; |
Tony Barbour | 300a608 | 2015-04-07 13:44:53 -0600 | [diff] [blame] | 220 | } |
Mark Lobodzinski | 3780e14 | 2015-05-14 15:08:13 -0500 | [diff] [blame] | 221 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 222 | class VkLayerTest : public VkRenderFramework { |
| 223 | public: |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 224 | VkResult BeginCommandBuffer(VkCommandBufferObj &commandBuffer); |
| 225 | VkResult EndCommandBuffer(VkCommandBufferObj &commandBuffer); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 226 | void VKTriangleTest(const char *vertShaderText, const char *fragShaderText, |
| 227 | BsoFailSelect failMask); |
| 228 | void GenericDrawPreparation(VkCommandBufferObj *commandBuffer, |
| 229 | VkPipelineObj &pipelineobj, |
| 230 | VkDescriptorSetObj &descriptorSet, |
| 231 | BsoFailSelect failMask); |
| 232 | void GenericDrawPreparation(VkPipelineObj &pipelineobj, |
| 233 | VkDescriptorSetObj &descriptorSet, |
| 234 | BsoFailSelect failMask) { |
| 235 | GenericDrawPreparation(m_commandBuffer, pipelineobj, descriptorSet, |
| 236 | failMask); |
| 237 | } |
Tony Barbour | 300a608 | 2015-04-07 13:44:53 -0600 | [diff] [blame] | 238 | |
Tony Barbour | fe3351b | 2015-07-28 10:17:20 -0600 | [diff] [blame] | 239 | /* Convenience functions that use built-in command buffer */ |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 240 | VkResult BeginCommandBuffer() { |
| 241 | return BeginCommandBuffer(*m_commandBuffer); |
| 242 | } |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 243 | VkResult EndCommandBuffer() { return EndCommandBuffer(*m_commandBuffer); } |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 244 | void Draw(uint32_t vertexCount, uint32_t instanceCount, |
| 245 | uint32_t firstVertex, uint32_t firstInstance) { |
| 246 | m_commandBuffer->Draw(vertexCount, instanceCount, firstVertex, |
| 247 | firstInstance); |
| 248 | } |
| 249 | void DrawIndexed(uint32_t indexCount, uint32_t instanceCount, |
| 250 | uint32_t firstIndex, int32_t vertexOffset, |
| 251 | uint32_t firstInstance) { |
| 252 | m_commandBuffer->DrawIndexed(indexCount, instanceCount, firstIndex, |
| 253 | vertexOffset, firstInstance); |
| 254 | } |
Mark Lobodzinski | cf0ae75 | 2016-06-23 10:02:24 -0600 | [diff] [blame] | 255 | void QueueCommandBuffer() { m_commandBuffer->QueueCommandBuffer(); } |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 256 | void QueueCommandBuffer(const VkFence &fence) { |
| 257 | m_commandBuffer->QueueCommandBuffer(fence); |
| 258 | } |
| 259 | void BindVertexBuffer(VkConstantBufferObj *vertexBuffer, |
| 260 | VkDeviceSize offset, uint32_t binding) { |
| 261 | m_commandBuffer->BindVertexBuffer(vertexBuffer, offset, binding); |
| 262 | } |
| 263 | void BindIndexBuffer(VkIndexBufferObj *indexBuffer, VkDeviceSize offset) { |
| 264 | m_commandBuffer->BindIndexBuffer(indexBuffer, offset); |
| 265 | } |
| 266 | |
| 267 | protected: |
| 268 | ErrorMonitor *m_errorMonitor; |
Ian Elliott | 2c1daf5 | 2016-05-12 09:41:46 -0600 | [diff] [blame] | 269 | bool m_enableWSI; |
Tony Barbour | 300a608 | 2015-04-07 13:44:53 -0600 | [diff] [blame] | 270 | |
| 271 | virtual void SetUp() { |
Courtney Goeltzenleuchter | cd69eee | 2015-07-06 09:10:47 -0600 | [diff] [blame] | 272 | std::vector<const char *> instance_layer_names; |
| 273 | std::vector<const char *> device_layer_names; |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 274 | std::vector<const char *> instance_extension_names; |
| 275 | std::vector<const char *> device_extension_names; |
Tony Barbour | 3fdff9e | 2015-04-23 12:55:36 -0600 | [diff] [blame] | 276 | |
Courtney Goeltzenleuchter | 7415d5a | 2015-12-09 15:48:16 -0700 | [diff] [blame] | 277 | instance_extension_names.push_back(VK_EXT_DEBUG_REPORT_EXTENSION_NAME); |
Courtney Goeltzenleuchter | c2b06fe | 2015-06-16 15:59:11 -0600 | [diff] [blame] | 278 | /* |
| 279 | * Since CreateDbgMsgCallback is an instance level extension call |
| 280 | * any extension / layer that utilizes that feature also needs |
| 281 | * to be enabled at create instance time. |
| 282 | */ |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 283 | // Use Threading layer first to protect others from |
| 284 | // ThreadCommandBufferCollision test |
Courtney Goeltzenleuchter | 7688532 | 2016-02-06 17:11:22 -0700 | [diff] [blame] | 285 | instance_layer_names.push_back("VK_LAYER_GOOGLE_threading"); |
Tobin Ehlis | 24aab04 | 2016-03-24 10:54:18 -0600 | [diff] [blame] | 286 | instance_layer_names.push_back("VK_LAYER_LUNARG_parameter_validation"); |
Michael Lentine | 03107b4 | 2015-12-11 10:49:51 -0800 | [diff] [blame] | 287 | instance_layer_names.push_back("VK_LAYER_LUNARG_object_tracker"); |
Tobin Ehlis | c96f806 | 2016-03-09 16:12:48 -0700 | [diff] [blame] | 288 | instance_layer_names.push_back("VK_LAYER_LUNARG_core_validation"); |
Michael Lentine | 03107b4 | 2015-12-11 10:49:51 -0800 | [diff] [blame] | 289 | instance_layer_names.push_back("VK_LAYER_LUNARG_image"); |
Ian Elliott | e48a138 | 2016-04-28 14:22:58 -0600 | [diff] [blame] | 290 | instance_layer_names.push_back("VK_LAYER_LUNARG_swapchain"); |
Dustin Graves | eaa78cd | 2016-01-26 16:30:22 -0700 | [diff] [blame] | 291 | instance_layer_names.push_back("VK_LAYER_GOOGLE_unique_objects"); |
Courtney Goeltzenleuchter | d971b61 | 2015-06-17 20:51:59 -0600 | [diff] [blame] | 292 | |
Courtney Goeltzenleuchter | 7688532 | 2016-02-06 17:11:22 -0700 | [diff] [blame] | 293 | device_layer_names.push_back("VK_LAYER_GOOGLE_threading"); |
Tobin Ehlis | 24aab04 | 2016-03-24 10:54:18 -0600 | [diff] [blame] | 294 | device_layer_names.push_back("VK_LAYER_LUNARG_parameter_validation"); |
Michael Lentine | 03107b4 | 2015-12-11 10:49:51 -0800 | [diff] [blame] | 295 | device_layer_names.push_back("VK_LAYER_LUNARG_object_tracker"); |
Tobin Ehlis | c96f806 | 2016-03-09 16:12:48 -0700 | [diff] [blame] | 296 | device_layer_names.push_back("VK_LAYER_LUNARG_core_validation"); |
Michael Lentine | 03107b4 | 2015-12-11 10:49:51 -0800 | [diff] [blame] | 297 | device_layer_names.push_back("VK_LAYER_LUNARG_image"); |
Ian Elliott | e48a138 | 2016-04-28 14:22:58 -0600 | [diff] [blame] | 298 | device_layer_names.push_back("VK_LAYER_LUNARG_swapchain"); |
Dustin Graves | eaa78cd | 2016-01-26 16:30:22 -0700 | [diff] [blame] | 299 | device_layer_names.push_back("VK_LAYER_GOOGLE_unique_objects"); |
Tony Barbour | 300a608 | 2015-04-07 13:44:53 -0600 | [diff] [blame] | 300 | |
Ian Elliott | 2c1daf5 | 2016-05-12 09:41:46 -0600 | [diff] [blame] | 301 | if (m_enableWSI) { |
| 302 | instance_extension_names.push_back(VK_KHR_SURFACE_EXTENSION_NAME); |
| 303 | device_extension_names.push_back(VK_KHR_SWAPCHAIN_EXTENSION_NAME); |
| 304 | #ifdef NEED_TO_TEST_THIS_ON_PLATFORM |
| 305 | #if defined(VK_USE_PLATFORM_ANDROID_KHR) |
| 306 | instance_extension_names.push_back(VK_KHR_ANDROID_SURFACE_EXTENSION_NAME); |
| 307 | #endif // VK_USE_PLATFORM_ANDROID_KHR |
| 308 | #if defined(VK_USE_PLATFORM_MIR_KHR) |
| 309 | instance_extension_names.push_back(VK_KHR_MIR_SURFACE_EXTENSION_NAME); |
| 310 | #endif // VK_USE_PLATFORM_MIR_KHR |
| 311 | #if defined(VK_USE_PLATFORM_WAYLAND_KHR) |
| 312 | instance_extension_names.push_back(VK_KHR_WAYLAND_SURFACE_EXTENSION_NAME); |
| 313 | #endif // VK_USE_PLATFORM_WAYLAND_KHR |
| 314 | #if defined(VK_USE_PLATFORM_WIN32_KHR) |
| 315 | instance_extension_names.push_back(VK_KHR_WIN32_SURFACE_EXTENSION_NAME); |
| 316 | #endif // VK_USE_PLATFORM_WIN32_KHR |
| 317 | #endif // NEED_TO_TEST_THIS_ON_PLATFORM |
| 318 | #if defined(VK_USE_PLATFORM_XCB_KHR) |
| 319 | instance_extension_names.push_back(VK_KHR_XCB_SURFACE_EXTENSION_NAME); |
| 320 | #elif defined(VK_USE_PLATFORM_XLIB_KHR) |
| 321 | instance_extension_names.push_back(VK_KHR_XLIB_SURFACE_EXTENSION_NAME); |
| 322 | #endif // VK_USE_PLATFORM_XLIB_KHR |
| 323 | } |
| 324 | |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 325 | this->app_info.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO; |
Tony Barbour | 300a608 | 2015-04-07 13:44:53 -0600 | [diff] [blame] | 326 | this->app_info.pNext = NULL; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 327 | this->app_info.pApplicationName = "layer_tests"; |
| 328 | this->app_info.applicationVersion = 1; |
Tony Barbour | 300a608 | 2015-04-07 13:44:53 -0600 | [diff] [blame] | 329 | this->app_info.pEngineName = "unittest"; |
| 330 | this->app_info.engineVersion = 1; |
Jon Ashburn | c5012ff | 2016-03-22 13:57:46 -0600 | [diff] [blame] | 331 | this->app_info.apiVersion = VK_API_VERSION_1_0; |
Tony Barbour | 300a608 | 2015-04-07 13:44:53 -0600 | [diff] [blame] | 332 | |
Tony Barbour | 15524c3 | 2015-04-29 17:34:29 -0600 | [diff] [blame] | 333 | m_errorMonitor = new ErrorMonitor; |
Courtney Goeltzenleuchter | cd69eee | 2015-07-06 09:10:47 -0600 | [diff] [blame] | 334 | InitFramework(instance_layer_names, device_layer_names, |
| 335 | instance_extension_names, device_extension_names, |
| 336 | myDbgFunc, m_errorMonitor); |
Tony Barbour | 300a608 | 2015-04-07 13:44:53 -0600 | [diff] [blame] | 337 | } |
| 338 | |
| 339 | virtual void TearDown() { |
| 340 | // Clean up resources before we reset |
Tony Barbour | 300a608 | 2015-04-07 13:44:53 -0600 | [diff] [blame] | 341 | ShutdownFramework(); |
Tony Barbour | 0b4d956 | 2015-04-09 10:48:04 -0600 | [diff] [blame] | 342 | delete m_errorMonitor; |
Tony Barbour | 300a608 | 2015-04-07 13:44:53 -0600 | [diff] [blame] | 343 | } |
Ian Elliott | 2c1daf5 | 2016-05-12 09:41:46 -0600 | [diff] [blame] | 344 | |
| 345 | VkLayerTest() { |
| 346 | m_enableWSI = false; |
| 347 | } |
Tony Barbour | 300a608 | 2015-04-07 13:44:53 -0600 | [diff] [blame] | 348 | }; |
Mark Lobodzinski | 3780e14 | 2015-05-14 15:08:13 -0500 | [diff] [blame] | 349 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 350 | VkResult VkLayerTest::BeginCommandBuffer(VkCommandBufferObj &commandBuffer) { |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 351 | VkResult result; |
Tony Barbour | 300a608 | 2015-04-07 13:44:53 -0600 | [diff] [blame] | 352 | |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 353 | result = commandBuffer.BeginCommandBuffer(); |
Tony Barbour | 300a608 | 2015-04-07 13:44:53 -0600 | [diff] [blame] | 354 | |
| 355 | /* |
| 356 | * For render test all drawing happens in a single render pass |
| 357 | * on a single command buffer. |
| 358 | */ |
Chris Forbes | 76a5eeb | 2015-06-16 14:05:59 +1200 | [diff] [blame] | 359 | if (VK_SUCCESS == result && renderPass()) { |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 360 | commandBuffer.BeginRenderPass(renderPassBeginInfo()); |
Tony Barbour | 300a608 | 2015-04-07 13:44:53 -0600 | [diff] [blame] | 361 | } |
| 362 | |
| 363 | return result; |
| 364 | } |
| 365 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 366 | VkResult VkLayerTest::EndCommandBuffer(VkCommandBufferObj &commandBuffer) { |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 367 | VkResult result; |
Tony Barbour | 300a608 | 2015-04-07 13:44:53 -0600 | [diff] [blame] | 368 | |
Chris Forbes | 76a5eeb | 2015-06-16 14:05:59 +1200 | [diff] [blame] | 369 | if (renderPass()) { |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 370 | commandBuffer.EndRenderPass(); |
Chris Forbes | 76a5eeb | 2015-06-16 14:05:59 +1200 | [diff] [blame] | 371 | } |
Tony Barbour | 300a608 | 2015-04-07 13:44:53 -0600 | [diff] [blame] | 372 | |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 373 | result = commandBuffer.EndCommandBuffer(); |
Tony Barbour | 300a608 | 2015-04-07 13:44:53 -0600 | [diff] [blame] | 374 | |
| 375 | return result; |
| 376 | } |
| 377 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 378 | void VkLayerTest::VKTriangleTest(const char *vertShaderText, |
| 379 | const char *fragShaderText, |
| 380 | BsoFailSelect failMask) { |
Mark Lobodzinski | 3780e14 | 2015-05-14 15:08:13 -0500 | [diff] [blame] | 381 | // Create identity matrix |
| 382 | int i; |
| 383 | struct vktriangle_vs_uniform data; |
| 384 | |
| 385 | glm::mat4 Projection = glm::mat4(1.0f); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 386 | glm::mat4 View = glm::mat4(1.0f); |
| 387 | glm::mat4 Model = glm::mat4(1.0f); |
| 388 | glm::mat4 MVP = Projection * View * Model; |
Mark Lobodzinski | 3780e14 | 2015-05-14 15:08:13 -0500 | [diff] [blame] | 389 | const int matrixSize = sizeof(MVP); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 390 | const int bufSize = sizeof(vktriangle_vs_uniform) / sizeof(float); |
Mark Lobodzinski | 3780e14 | 2015-05-14 15:08:13 -0500 | [diff] [blame] | 391 | |
| 392 | memcpy(&data.mvp, &MVP[0][0], matrixSize); |
| 393 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 394 | static const Vertex tri_data[] = { |
| 395 | {XYZ1(-1, -1, 0), XYZ1(1.f, 0.f, 0.f)}, |
| 396 | {XYZ1(1, -1, 0), XYZ1(0.f, 1.f, 0.f)}, |
| 397 | {XYZ1(0, 1, 0), XYZ1(0.f, 0.f, 1.f)}, |
Mark Lobodzinski | 3780e14 | 2015-05-14 15:08:13 -0500 | [diff] [blame] | 398 | }; |
| 399 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 400 | for (i = 0; i < 3; i++) { |
Mark Lobodzinski | 3780e14 | 2015-05-14 15:08:13 -0500 | [diff] [blame] | 401 | data.position[i][0] = tri_data[i].posX; |
| 402 | data.position[i][1] = tri_data[i].posY; |
| 403 | data.position[i][2] = tri_data[i].posZ; |
| 404 | data.position[i][3] = tri_data[i].posW; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 405 | data.color[i][0] = tri_data[i].r; |
| 406 | data.color[i][1] = tri_data[i].g; |
| 407 | data.color[i][2] = tri_data[i].b; |
| 408 | data.color[i][3] = tri_data[i].a; |
Mark Lobodzinski | 3780e14 | 2015-05-14 15:08:13 -0500 | [diff] [blame] | 409 | } |
| 410 | |
| 411 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 412 | ASSERT_NO_FATAL_FAILURE(InitViewport()); |
| 413 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 414 | VkConstantBufferObj constantBuffer(m_device, bufSize * 2, sizeof(float), |
| 415 | (const void *)&data); |
Mark Lobodzinski | 3780e14 | 2015-05-14 15:08:13 -0500 | [diff] [blame] | 416 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 417 | VkShaderObj vs(m_device, vertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this); |
| 418 | VkShaderObj ps(m_device, fragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, |
| 419 | this); |
Mark Lobodzinski | 3780e14 | 2015-05-14 15:08:13 -0500 | [diff] [blame] | 420 | |
| 421 | VkPipelineObj pipelineobj(m_device); |
Chia-I Wu | 08accc6 | 2015-07-07 11:50:03 +0800 | [diff] [blame] | 422 | pipelineobj.AddColorAttachment(); |
Mark Lobodzinski | 3780e14 | 2015-05-14 15:08:13 -0500 | [diff] [blame] | 423 | pipelineobj.AddShader(&vs); |
| 424 | pipelineobj.AddShader(&ps); |
Courtney Goeltzenleuchter | 507ba97 | 2015-09-30 16:16:57 -0600 | [diff] [blame] | 425 | if (failMask & BsoFailLineWidth) { |
| 426 | pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_LINE_WIDTH); |
Tobin Ehlis | 7a1d235 | 2016-03-28 11:18:19 -0600 | [diff] [blame] | 427 | VkPipelineInputAssemblyStateCreateInfo ia_state = {}; |
| 428 | ia_state.sType = |
| 429 | VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO; |
| 430 | ia_state.topology = VK_PRIMITIVE_TOPOLOGY_LINE_LIST; |
| 431 | pipelineobj.SetInputAssembly(&ia_state); |
Courtney Goeltzenleuchter | 507ba97 | 2015-09-30 16:16:57 -0600 | [diff] [blame] | 432 | } |
| 433 | if (failMask & BsoFailDepthBias) { |
| 434 | pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_DEPTH_BIAS); |
Tobin Ehlis | 7a1d235 | 2016-03-28 11:18:19 -0600 | [diff] [blame] | 435 | VkPipelineRasterizationStateCreateInfo rs_state = {}; |
| 436 | rs_state.sType = |
| 437 | VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO; |
| 438 | rs_state.depthBiasEnable = VK_TRUE; |
Mark Young | 7394fdd | 2016-03-31 14:56:43 -0600 | [diff] [blame] | 439 | rs_state.lineWidth = 1.0f; |
Tobin Ehlis | 7a1d235 | 2016-03-28 11:18:19 -0600 | [diff] [blame] | 440 | pipelineobj.SetRasterization(&rs_state); |
Courtney Goeltzenleuchter | 507ba97 | 2015-09-30 16:16:57 -0600 | [diff] [blame] | 441 | } |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 442 | // Viewport and scissors must stay in synch or other errors will occur than |
| 443 | // the ones we want |
Courtney Goeltzenleuchter | 507ba97 | 2015-09-30 16:16:57 -0600 | [diff] [blame] | 444 | if (failMask & BsoFailViewport) { |
| 445 | pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_VIEWPORT); |
Tobin Ehlis | d332f28 | 2015-10-02 11:00:56 -0600 | [diff] [blame] | 446 | m_viewports.clear(); |
| 447 | m_scissors.clear(); |
Courtney Goeltzenleuchter | 507ba97 | 2015-09-30 16:16:57 -0600 | [diff] [blame] | 448 | } |
| 449 | if (failMask & BsoFailScissor) { |
| 450 | pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_SCISSOR); |
Tobin Ehlis | d332f28 | 2015-10-02 11:00:56 -0600 | [diff] [blame] | 451 | m_scissors.clear(); |
| 452 | m_viewports.clear(); |
Courtney Goeltzenleuchter | 507ba97 | 2015-09-30 16:16:57 -0600 | [diff] [blame] | 453 | } |
| 454 | if (failMask & BsoFailBlend) { |
| 455 | pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_BLEND_CONSTANTS); |
Tobin Ehlis | 7a1d235 | 2016-03-28 11:18:19 -0600 | [diff] [blame] | 456 | VkPipelineColorBlendAttachmentState att_state = {}; |
| 457 | att_state.dstAlphaBlendFactor = VK_BLEND_FACTOR_CONSTANT_COLOR; |
| 458 | att_state.blendEnable = VK_TRUE; |
| 459 | pipelineobj.AddColorAttachment(0, &att_state); |
Courtney Goeltzenleuchter | 507ba97 | 2015-09-30 16:16:57 -0600 | [diff] [blame] | 460 | } |
| 461 | if (failMask & BsoFailDepthBounds) { |
| 462 | pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_DEPTH_BOUNDS); |
| 463 | } |
| 464 | if (failMask & BsoFailStencilReadMask) { |
| 465 | pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_STENCIL_COMPARE_MASK); |
| 466 | } |
| 467 | if (failMask & BsoFailStencilWriteMask) { |
| 468 | pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_STENCIL_WRITE_MASK); |
| 469 | } |
| 470 | if (failMask & BsoFailStencilReference) { |
| 471 | pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_STENCIL_REFERENCE); |
| 472 | } |
Mark Lobodzinski | 3780e14 | 2015-05-14 15:08:13 -0500 | [diff] [blame] | 473 | |
| 474 | VkDescriptorSetObj descriptorSet(m_device); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 475 | descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, |
| 476 | constantBuffer); |
Mark Lobodzinski | 3780e14 | 2015-05-14 15:08:13 -0500 | [diff] [blame] | 477 | |
| 478 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
Tony Barbour | fe3351b | 2015-07-28 10:17:20 -0600 | [diff] [blame] | 479 | ASSERT_VK_SUCCESS(BeginCommandBuffer()); |
Mark Lobodzinski | 3780e14 | 2015-05-14 15:08:13 -0500 | [diff] [blame] | 480 | |
Tony Barbour | fe3351b | 2015-07-28 10:17:20 -0600 | [diff] [blame] | 481 | GenericDrawPreparation(pipelineobj, descriptorSet, failMask); |
Mark Lobodzinski | 3780e14 | 2015-05-14 15:08:13 -0500 | [diff] [blame] | 482 | |
| 483 | // render triangle |
Courtney Goeltzenleuchter | 08c2637 | 2015-09-23 12:31:50 -0600 | [diff] [blame] | 484 | Draw(3, 1, 0, 0); |
Mark Lobodzinski | 3780e14 | 2015-05-14 15:08:13 -0500 | [diff] [blame] | 485 | |
Mark Mueller | d491441 | 2016-06-13 17:52:06 -0600 | [diff] [blame] | 486 | if (failMask & BsoFailCmdClearAttachments) { |
| 487 | VkClearAttachment color_attachment = {}; |
| 488 | color_attachment.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; |
| 489 | color_attachment.colorAttachment = 1; // Someone who knew what they were doing would use 0 for the index; |
| 490 | VkClearRect clear_rect = {{{0, 0}, {static_cast<uint32_t>(m_width), static_cast<uint32_t>(m_height)}}, 0, 0}; |
| 491 | |
| 492 | vkCmdClearAttachments(m_commandBuffer->GetBufferHandle(), 1, |
| 493 | &color_attachment, 1, &clear_rect); |
| 494 | } |
| 495 | |
Mark Lobodzinski | 3780e14 | 2015-05-14 15:08:13 -0500 | [diff] [blame] | 496 | // finalize recording of the command buffer |
Tony Barbour | fe3351b | 2015-07-28 10:17:20 -0600 | [diff] [blame] | 497 | EndCommandBuffer(); |
Mark Lobodzinski | 3780e14 | 2015-05-14 15:08:13 -0500 | [diff] [blame] | 498 | |
Tony Barbour | fe3351b | 2015-07-28 10:17:20 -0600 | [diff] [blame] | 499 | QueueCommandBuffer(); |
Mark Lobodzinski | 3780e14 | 2015-05-14 15:08:13 -0500 | [diff] [blame] | 500 | } |
| 501 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 502 | void VkLayerTest::GenericDrawPreparation(VkCommandBufferObj *commandBuffer, |
| 503 | VkPipelineObj &pipelineobj, |
| 504 | VkDescriptorSetObj &descriptorSet, |
| 505 | BsoFailSelect failMask) { |
Mark Lobodzinski | 3780e14 | 2015-05-14 15:08:13 -0500 | [diff] [blame] | 506 | if (m_depthStencil->Initialized()) { |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 507 | commandBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color, |
| 508 | m_stencil_clear_color, m_depthStencil); |
Mark Lobodzinski | 3780e14 | 2015-05-14 15:08:13 -0500 | [diff] [blame] | 509 | } else { |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 510 | commandBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color, |
| 511 | m_stencil_clear_color, NULL); |
Mark Lobodzinski | 3780e14 | 2015-05-14 15:08:13 -0500 | [diff] [blame] | 512 | } |
| 513 | |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 514 | commandBuffer->PrepareAttachments(); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 515 | // Make sure depthWriteEnable is set so that Depth fail test will work |
| 516 | // correctly |
| 517 | // Make sure stencilTestEnable is set so that Stencil fail test will work |
| 518 | // correctly |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 519 | VkStencilOpState stencil = {}; |
Chia-I Wu | 1b99bb2 | 2015-10-27 19:25:11 +0800 | [diff] [blame] | 520 | stencil.failOp = VK_STENCIL_OP_KEEP; |
| 521 | stencil.passOp = VK_STENCIL_OP_KEEP; |
| 522 | stencil.depthFailOp = VK_STENCIL_OP_KEEP; |
| 523 | stencil.compareOp = VK_COMPARE_OP_NEVER; |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 524 | |
| 525 | VkPipelineDepthStencilStateCreateInfo ds_ci = {}; |
| 526 | ds_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DEPTH_STENCIL_STATE_CREATE_INFO; |
Courtney Goeltzenleuchter | 507ba97 | 2015-09-30 16:16:57 -0600 | [diff] [blame] | 527 | ds_ci.pNext = NULL; |
| 528 | ds_ci.depthTestEnable = VK_FALSE; |
| 529 | ds_ci.depthWriteEnable = VK_TRUE; |
| 530 | ds_ci.depthCompareOp = VK_COMPARE_OP_NEVER; |
| 531 | ds_ci.depthBoundsTestEnable = VK_FALSE; |
Tobin Ehlis | 7a1d235 | 2016-03-28 11:18:19 -0600 | [diff] [blame] | 532 | if (failMask & BsoFailDepthBounds) { |
| 533 | ds_ci.depthBoundsTestEnable = VK_TRUE; |
Tobin Ehlis | 21c8835 | 2016-05-26 06:15:45 -0600 | [diff] [blame] | 534 | ds_ci.maxDepthBounds = 0.0f; |
| 535 | ds_ci.minDepthBounds = 0.0f; |
Tobin Ehlis | 7a1d235 | 2016-03-28 11:18:19 -0600 | [diff] [blame] | 536 | } |
Courtney Goeltzenleuchter | 507ba97 | 2015-09-30 16:16:57 -0600 | [diff] [blame] | 537 | ds_ci.stencilTestEnable = VK_TRUE; |
| 538 | ds_ci.front = stencil; |
| 539 | ds_ci.back = stencil; |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 540 | |
Tobin Ehlis | 4bf96d1 | 2015-06-25 11:58:41 -0600 | [diff] [blame] | 541 | pipelineobj.SetDepthStencil(&ds_ci); |
Tobin Ehlis | d332f28 | 2015-10-02 11:00:56 -0600 | [diff] [blame] | 542 | pipelineobj.SetViewport(m_viewports); |
| 543 | pipelineobj.SetScissor(m_scissors); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 544 | descriptorSet.CreateVKDescriptorSet(commandBuffer); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 545 | VkResult err = pipelineobj.CreateVKPipeline( |
| 546 | descriptorSet.GetPipelineLayout(), renderPass()); |
Cody Northrop | 29a08f2 | 2015-08-27 10:20:35 -0600 | [diff] [blame] | 547 | ASSERT_VK_SUCCESS(err); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 548 | commandBuffer->BindPipeline(pipelineobj); |
| 549 | commandBuffer->BindDescriptorSet(descriptorSet); |
Mark Lobodzinski | 3780e14 | 2015-05-14 15:08:13 -0500 | [diff] [blame] | 550 | } |
| 551 | |
Ian Elliott | 2c1daf5 | 2016-05-12 09:41:46 -0600 | [diff] [blame] | 552 | class VkWsiEnabledLayerTest : public VkLayerTest { |
| 553 | public: |
| 554 | protected: |
| 555 | VkWsiEnabledLayerTest() { |
| 556 | m_enableWSI = true; |
| 557 | } |
| 558 | }; |
| 559 | |
Mark Lobodzinski | 3780e14 | 2015-05-14 15:08:13 -0500 | [diff] [blame] | 560 | // ******************************************************************************************************************** |
| 561 | // ******************************************************************************************************************** |
| 562 | // ******************************************************************************************************************** |
| 563 | // ******************************************************************************************************************** |
Dustin Graves | ffa90fa | 2016-05-06 11:20:38 -0600 | [diff] [blame] | 564 | #if PARAMETER_VALIDATION_TESTS |
| 565 | TEST_F(VkLayerTest, RequiredParameter) { |
| 566 | TEST_DESCRIPTION("Specify VK_NULL_HANDLE, NULL, and 0 for required handle, " |
| 567 | "pointer, array, and array count parameters"); |
| 568 | |
| 569 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 570 | |
| 571 | m_errorMonitor->SetDesiredFailureMsg( |
| 572 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 573 | "required parameter pFeatures specified as NULL"); |
| 574 | // Specify NULL for a pointer to a handle |
| 575 | // Expected to trigger an error with |
| 576 | // parameter_validation::validate_required_pointer |
| 577 | vkGetPhysicalDeviceFeatures(gpu(), NULL); |
| 578 | m_errorMonitor->VerifyFound(); |
| 579 | |
| 580 | m_errorMonitor->SetDesiredFailureMsg( |
| 581 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Dustin Graves | a4bb8c1 | 2016-05-16 17:22:51 -0600 | [diff] [blame] | 582 | "required parameter pQueueFamilyPropertyCount specified as NULL"); |
Dustin Graves | ffa90fa | 2016-05-06 11:20:38 -0600 | [diff] [blame] | 583 | // Specify NULL for pointer to array count |
| 584 | // Expected to trigger an error with parameter_validation::validate_array |
Dustin Graves | a4bb8c1 | 2016-05-16 17:22:51 -0600 | [diff] [blame] | 585 | vkGetPhysicalDeviceQueueFamilyProperties(gpu(), NULL, NULL); |
Dustin Graves | ffa90fa | 2016-05-06 11:20:38 -0600 | [diff] [blame] | 586 | m_errorMonitor->VerifyFound(); |
| 587 | |
| 588 | m_errorMonitor->SetDesiredFailureMsg( |
| 589 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 590 | "parameter viewportCount must be greater than 0"); |
| 591 | // Specify 0 for a required array count |
| 592 | // Expected to trigger an error with parameter_validation::validate_array |
| 593 | VkViewport view_port = {}; |
| 594 | m_commandBuffer->SetViewport(0, 0, &view_port); |
| 595 | m_errorMonitor->VerifyFound(); |
| 596 | |
| 597 | m_errorMonitor->SetDesiredFailureMsg( |
| 598 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 599 | "required parameter pViewports specified as NULL"); |
| 600 | // Specify NULL for a required array |
| 601 | // Expected to trigger an error with parameter_validation::validate_array |
| 602 | m_commandBuffer->SetViewport(0, 1, NULL); |
| 603 | m_errorMonitor->VerifyFound(); |
| 604 | |
| 605 | m_errorMonitor->SetDesiredFailureMsg( |
| 606 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 607 | "required parameter memory specified as VK_NULL_HANDLE"); |
| 608 | // Specify VK_NULL_HANDLE for a required handle |
| 609 | // Expected to trigger an error with |
| 610 | // parameter_validation::validate_required_handle |
| 611 | vkUnmapMemory(device(), VK_NULL_HANDLE); |
| 612 | m_errorMonitor->VerifyFound(); |
| 613 | |
| 614 | m_errorMonitor->SetDesiredFailureMsg( |
| 615 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 616 | "required parameter pFences[0] specified as VK_NULL_HANDLE"); |
| 617 | // Specify VK_NULL_HANDLE for a required handle array entry |
| 618 | // Expected to trigger an error with |
| 619 | // parameter_validation::validate_required_handle_array |
| 620 | VkFence fence = VK_NULL_HANDLE; |
| 621 | vkResetFences(device(), 1, &fence); |
| 622 | m_errorMonitor->VerifyFound(); |
| 623 | |
| 624 | m_errorMonitor->SetDesiredFailureMsg( |
| 625 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 626 | "required parameter pAllocateInfo specified as NULL"); |
| 627 | // Specify NULL for a required struct pointer |
| 628 | // Expected to trigger an error with |
| 629 | // parameter_validation::validate_struct_type |
| 630 | VkDeviceMemory memory = VK_NULL_HANDLE; |
| 631 | vkAllocateMemory(device(), NULL, NULL, &memory); |
| 632 | m_errorMonitor->VerifyFound(); |
| 633 | |
| 634 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 635 | "value of faceMask must not be 0"); |
| 636 | // Specify 0 for a required VkFlags parameter |
| 637 | // Expected to trigger an error with parameter_validation::validate_flags |
| 638 | m_commandBuffer->SetStencilReference(0, 0); |
| 639 | m_errorMonitor->VerifyFound(); |
| 640 | |
| 641 | m_errorMonitor->SetDesiredFailureMsg( |
| 642 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 643 | "value of pSubmits[i].pWaitDstStageMask[0] must not be 0"); |
| 644 | // Specify 0 for a required VkFlags array entry |
| 645 | // Expected to trigger an error with |
| 646 | // parameter_validation::validate_flags_array |
| 647 | VkSemaphore semaphore = VK_NULL_HANDLE; |
| 648 | VkPipelineStageFlags stageFlags = 0; |
| 649 | VkSubmitInfo submitInfo = {}; |
| 650 | submitInfo.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO; |
| 651 | submitInfo.waitSemaphoreCount = 1; |
| 652 | submitInfo.pWaitSemaphores = &semaphore; |
| 653 | submitInfo.pWaitDstStageMask = &stageFlags; |
| 654 | vkQueueSubmit(m_device->m_queue, 1, &submitInfo, VK_NULL_HANDLE); |
| 655 | m_errorMonitor->VerifyFound(); |
| 656 | } |
Dustin Graves | c99cf5a | 2016-05-09 14:40:29 -0600 | [diff] [blame] | 657 | |
Dustin Graves | fce74c0 | 2016-05-10 11:42:58 -0600 | [diff] [blame] | 658 | TEST_F(VkLayerTest, ReservedParameter) { |
| 659 | TEST_DESCRIPTION("Specify a non-zero value for a reserved parameter"); |
| 660 | |
| 661 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 662 | |
| 663 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 664 | " must be 0"); |
| 665 | // Specify 0 for a reserved VkFlags parameter |
| 666 | // Expected to trigger an error with |
| 667 | // parameter_validation::validate_reserved_flags |
| 668 | VkEvent event_handle = VK_NULL_HANDLE; |
| 669 | VkEventCreateInfo event_info = {}; |
| 670 | event_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO; |
| 671 | event_info.flags = 1; |
| 672 | vkCreateEvent(device(), &event_info, NULL, &event_handle); |
| 673 | m_errorMonitor->VerifyFound(); |
| 674 | } |
| 675 | |
Dustin Graves | c99cf5a | 2016-05-09 14:40:29 -0600 | [diff] [blame] | 676 | TEST_F(VkLayerTest, InvalidStructSType) { |
| 677 | TEST_DESCRIPTION("Specify an invalid VkStructureType for a Vulkan " |
| 678 | "structure's sType field"); |
| 679 | |
| 680 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 681 | |
| 682 | m_errorMonitor->SetDesiredFailureMsg( |
| 683 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 684 | "parameter pAllocateInfo->sType must be"); |
| 685 | // Zero struct memory, effectively setting sType to |
| 686 | // VK_STRUCTURE_TYPE_APPLICATION_INFO |
| 687 | // Expected to trigger an error with |
| 688 | // parameter_validation::validate_struct_type |
| 689 | VkMemoryAllocateInfo alloc_info = {}; |
| 690 | VkDeviceMemory memory = VK_NULL_HANDLE; |
| 691 | vkAllocateMemory(device(), &alloc_info, NULL, &memory); |
| 692 | m_errorMonitor->VerifyFound(); |
| 693 | |
| 694 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 695 | "parameter pSubmits[0].sType must be"); |
| 696 | // Zero struct memory, effectively setting sType to |
| 697 | // VK_STRUCTURE_TYPE_APPLICATION_INFO |
| 698 | // Expected to trigger an error with |
| 699 | // parameter_validation::validate_struct_type_array |
| 700 | VkSubmitInfo submit_info = {}; |
| 701 | vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE); |
| 702 | m_errorMonitor->VerifyFound(); |
| 703 | } |
| 704 | |
| 705 | TEST_F(VkLayerTest, InvalidStructPNext) { |
| 706 | TEST_DESCRIPTION( |
| 707 | "Specify an invalid value for a Vulkan structure's pNext field"); |
| 708 | |
| 709 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 710 | |
| 711 | m_errorMonitor->SetDesiredFailureMsg( |
| 712 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 713 | "value of pAllocateInfo->pNext must be NULL"); |
| 714 | // Set VkMemoryAllocateInfo::pNext to a non-NULL value, when pNext must be |
| 715 | // NULL |
| 716 | // Expected to trigger an error with |
| 717 | // parameter_validation::validate_struct_pnext |
| 718 | VkDeviceMemory memory = VK_NULL_HANDLE; |
| 719 | // Zero-initialization will provide the correct sType |
| 720 | VkApplicationInfo app_info = {}; |
Dustin Graves | 47b6cba | 2016-05-10 17:34:38 -0600 | [diff] [blame] | 721 | VkMemoryAllocateInfo memory_alloc_info = {}; |
| 722 | memory_alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO; |
| 723 | memory_alloc_info.pNext = &app_info; |
| 724 | vkAllocateMemory(device(), &memory_alloc_info, NULL, &memory); |
Dustin Graves | c99cf5a | 2016-05-09 14:40:29 -0600 | [diff] [blame] | 725 | m_errorMonitor->VerifyFound(); |
| 726 | |
Dustin Graves | 47b6cba | 2016-05-10 17:34:38 -0600 | [diff] [blame] | 727 | m_errorMonitor->SetDesiredFailureMsg( |
| 728 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 729 | " chain includes a structure with unexpected VkStructureType "); |
| 730 | // Set VkGraphicsPipelineCreateInfo::VkPipelineRasterizationStateCreateInfo::pNext to an invalid structure, when pNext is allowed to be a non-NULL value |
| 731 | // Expected to trigger an error with |
| 732 | // parameter_validation::validate_struct_pnext |
| 733 | VkDescriptorPoolSize ds_type_count = {}; |
| 734 | ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 735 | ds_type_count.descriptorCount = 1; |
| 736 | |
| 737 | VkDescriptorPoolCreateInfo ds_pool_ci = {}; |
| 738 | ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO; |
| 739 | ds_pool_ci.pNext = NULL; |
| 740 | ds_pool_ci.maxSets = 1; |
| 741 | ds_pool_ci.poolSizeCount = 1; |
| 742 | ds_pool_ci.pPoolSizes = &ds_type_count; |
| 743 | |
| 744 | VkDescriptorPool ds_pool; |
| 745 | VkResult err = |
| 746 | vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool); |
| 747 | ASSERT_VK_SUCCESS(err); |
| 748 | |
| 749 | VkDescriptorSetLayoutBinding dsl_binding = {}; |
| 750 | dsl_binding.binding = 0; |
| 751 | dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 752 | dsl_binding.descriptorCount = 1; |
| 753 | dsl_binding.stageFlags = VK_SHADER_STAGE_ALL; |
| 754 | dsl_binding.pImmutableSamplers = NULL; |
| 755 | |
| 756 | VkDescriptorSetLayoutCreateInfo ds_layout_ci = {}; |
| 757 | ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO; |
| 758 | ds_layout_ci.pNext = NULL; |
| 759 | ds_layout_ci.bindingCount = 1; |
| 760 | ds_layout_ci.pBindings = &dsl_binding; |
| 761 | |
| 762 | VkDescriptorSetLayout ds_layout; |
| 763 | err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, |
| 764 | &ds_layout); |
| 765 | ASSERT_VK_SUCCESS(err); |
| 766 | |
| 767 | VkDescriptorSet descriptorSet; |
| 768 | VkDescriptorSetAllocateInfo ds_alloc_info = {}; |
| 769 | ds_alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO; |
| 770 | ds_alloc_info.descriptorSetCount = 1; |
| 771 | ds_alloc_info.descriptorPool = ds_pool; |
| 772 | ds_alloc_info.pSetLayouts = &ds_layout; |
| 773 | err = vkAllocateDescriptorSets(m_device->device(), &ds_alloc_info, |
| 774 | &descriptorSet); |
| 775 | ASSERT_VK_SUCCESS(err); |
| 776 | |
| 777 | VkPipelineLayoutCreateInfo pipeline_layout_ci = {}; |
| 778 | pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO; |
| 779 | pipeline_layout_ci.setLayoutCount = 1; |
| 780 | pipeline_layout_ci.pSetLayouts = &ds_layout; |
| 781 | |
| 782 | VkPipelineLayout pipeline_layout; |
| 783 | err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, |
| 784 | &pipeline_layout); |
| 785 | ASSERT_VK_SUCCESS(err); |
| 786 | |
| 787 | VkViewport vp = {}; // Just need dummy vp to point to |
| 788 | VkRect2D sc = {}; // dummy scissor to point to |
| 789 | |
| 790 | VkPipelineViewportStateCreateInfo vp_state_ci = {}; |
| 791 | vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO; |
| 792 | vp_state_ci.scissorCount = 1; |
| 793 | vp_state_ci.pScissors = ≻ |
| 794 | vp_state_ci.viewportCount = 1; |
| 795 | vp_state_ci.pViewports = &vp; |
| 796 | |
| 797 | VkPipelineRasterizationStateCreateInfo rs_state_ci = {}; |
| 798 | rs_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO; |
| 799 | rs_state_ci.polygonMode = VK_POLYGON_MODE_FILL; |
| 800 | rs_state_ci.cullMode = VK_CULL_MODE_BACK_BIT; |
| 801 | rs_state_ci.frontFace = VK_FRONT_FACE_COUNTER_CLOCKWISE; |
| 802 | rs_state_ci.depthClampEnable = VK_FALSE; |
| 803 | rs_state_ci.rasterizerDiscardEnable = VK_FALSE; |
| 804 | rs_state_ci.depthBiasEnable = VK_FALSE; |
| 805 | |
| 806 | VkGraphicsPipelineCreateInfo gp_ci = {}; |
| 807 | gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO; |
| 808 | gp_ci.pViewportState = &vp_state_ci; |
| 809 | gp_ci.pRasterizationState = &rs_state_ci; |
| 810 | gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT; |
| 811 | gp_ci.layout = pipeline_layout; |
| 812 | gp_ci.renderPass = renderPass(); |
| 813 | |
| 814 | VkPipelineCacheCreateInfo pc_ci = {}; |
| 815 | pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO; |
| 816 | pc_ci.initialDataSize = 0; |
| 817 | pc_ci.pInitialData = 0; |
| 818 | |
| 819 | VkPipeline pipeline; |
| 820 | VkPipelineCache pipelineCache; |
| 821 | |
| 822 | err = |
| 823 | vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache); |
| 824 | ASSERT_VK_SUCCESS(err); |
| 825 | |
| 826 | // Set VkPipelineRasterizationStateCreateInfo::pNext to an invalid value |
| 827 | VkApplicationInfo invalid_pnext_struct = {}; |
| 828 | rs_state_ci.pNext = &invalid_pnext_struct; |
| 829 | |
| 830 | vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, |
| 831 | &gp_ci, NULL, &pipeline); |
| 832 | m_errorMonitor->VerifyFound(); |
Tony Barbour | df4c004 | 2016-06-01 15:55:43 -0600 | [diff] [blame] | 833 | vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL); |
| 834 | vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL); |
| 835 | vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL); |
| 836 | vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL); |
| 837 | |
Dustin Graves | c99cf5a | 2016-05-09 14:40:29 -0600 | [diff] [blame] | 838 | } |
Dustin Graves | 5d33d53 | 2016-05-09 16:21:12 -0600 | [diff] [blame] | 839 | |
| 840 | TEST_F(VkLayerTest, UnrecognizedValue) { |
| 841 | TEST_DESCRIPTION( |
| 842 | "Specify unrecognized Vulkan enumeration, flags, and VkBool32 values"); |
| 843 | |
| 844 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 845 | |
| 846 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 847 | "does not fall within the begin..end " |
| 848 | "range of the core VkFormat " |
| 849 | "enumeration tokens"); |
| 850 | // Specify an invalid VkFormat value |
| 851 | // Expected to trigger an error with |
| 852 | // parameter_validation::validate_ranged_enum |
| 853 | VkFormatProperties format_properties; |
| 854 | vkGetPhysicalDeviceFormatProperties(gpu(), static_cast<VkFormat>(8000), |
| 855 | &format_properties); |
| 856 | m_errorMonitor->VerifyFound(); |
| 857 | |
| 858 | m_errorMonitor->SetDesiredFailureMsg( |
| 859 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 860 | "contains flag bits that are not recognized members of"); |
| 861 | // Specify an invalid VkFlags bitmask value |
| 862 | // Expected to trigger an error with parameter_validation::validate_flags |
| 863 | VkImageFormatProperties image_format_properties; |
| 864 | vkGetPhysicalDeviceImageFormatProperties( |
| 865 | gpu(), VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_TYPE_2D, |
| 866 | VK_IMAGE_TILING_OPTIMAL, static_cast<VkImageUsageFlags>(1 << 25), 0, |
| 867 | &image_format_properties); |
| 868 | m_errorMonitor->VerifyFound(); |
| 869 | |
| 870 | m_errorMonitor->SetDesiredFailureMsg( |
| 871 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 872 | "contains flag bits that are not recognized members of"); |
| 873 | // Specify an invalid VkFlags array entry |
| 874 | // Expected to trigger an error with |
| 875 | // parameter_validation::validate_flags_array |
| 876 | VkSemaphore semaphore = VK_NULL_HANDLE; |
| 877 | VkPipelineStageFlags stage_flags = |
| 878 | static_cast<VkPipelineStageFlags>(1 << 25); |
| 879 | VkSubmitInfo submit_info = {}; |
| 880 | submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO; |
| 881 | submit_info.waitSemaphoreCount = 1; |
| 882 | submit_info.pWaitSemaphores = &semaphore; |
| 883 | submit_info.pWaitDstStageMask = &stage_flags; |
| 884 | vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE); |
| 885 | m_errorMonitor->VerifyFound(); |
| 886 | |
| 887 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, |
| 888 | "is neither VK_TRUE nor VK_FALSE"); |
| 889 | // Specify an invalid VkBool32 value |
| 890 | // Expected to trigger a warning with |
| 891 | // parameter_validation::validate_bool32 |
| 892 | VkSampler sampler = VK_NULL_HANDLE; |
| 893 | VkSamplerCreateInfo sampler_info = {}; |
| 894 | sampler_info.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO; |
| 895 | sampler_info.pNext = NULL; |
| 896 | sampler_info.magFilter = VK_FILTER_NEAREST; |
| 897 | sampler_info.minFilter = VK_FILTER_NEAREST; |
| 898 | sampler_info.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST; |
| 899 | sampler_info.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE; |
| 900 | sampler_info.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE; |
| 901 | sampler_info.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE; |
| 902 | sampler_info.mipLodBias = 1.0; |
| 903 | sampler_info.maxAnisotropy = 1; |
| 904 | sampler_info.compareEnable = VK_FALSE; |
| 905 | sampler_info.compareOp = VK_COMPARE_OP_NEVER; |
| 906 | sampler_info.minLod = 1.0; |
| 907 | sampler_info.maxLod = 1.0; |
| 908 | sampler_info.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE; |
| 909 | sampler_info.unnormalizedCoordinates = VK_FALSE; |
| 910 | // Not VK_TRUE or VK_FALSE |
| 911 | sampler_info.anisotropyEnable = 3; |
| 912 | vkCreateSampler(m_device->device(), &sampler_info, NULL, &sampler); |
| 913 | m_errorMonitor->VerifyFound(); |
| 914 | } |
Dustin Graves | fce74c0 | 2016-05-10 11:42:58 -0600 | [diff] [blame] | 915 | |
| 916 | TEST_F(VkLayerTest, FailedReturnValue) { |
| 917 | TEST_DESCRIPTION("Check for a message describing a VkResult failure code"); |
| 918 | |
| 919 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 920 | |
Dustin Graves | 13c1e2b | 2016-05-16 15:31:02 -0600 | [diff] [blame] | 921 | // Find an unsupported image format |
| 922 | VkFormat unsupported = VK_FORMAT_UNDEFINED; |
| 923 | for (int f = VK_FORMAT_BEGIN_RANGE; f <= VK_FORMAT_END_RANGE; f++) { |
| 924 | VkFormat format = static_cast<VkFormat>(f); |
| 925 | VkFormatProperties fProps = m_device->format_properties(format); |
| 926 | if (format != VK_FORMAT_UNDEFINED && fProps.linearTilingFeatures == 0 && |
| 927 | fProps.optimalTilingFeatures == 0) { |
| 928 | unsupported = format; |
| 929 | break; |
| 930 | } |
| 931 | } |
| 932 | |
| 933 | if (unsupported != VK_FORMAT_UNDEFINED) { |
| 934 | m_errorMonitor->SetDesiredFailureMsg( |
| 935 | VK_DEBUG_REPORT_WARNING_BIT_EXT, |
| 936 | "the requested format is not supported on this device"); |
| 937 | // Specify an unsupported VkFormat value to generate a |
| 938 | // VK_ERROR_FORMAT_NOT_SUPPORTED return code |
| 939 | // Expected to trigger a warning from |
| 940 | // parameter_validation::validate_result |
| 941 | VkImageFormatProperties image_format_properties; |
| 942 | VkResult err = vkGetPhysicalDeviceImageFormatProperties( |
| 943 | gpu(), unsupported, VK_IMAGE_TYPE_2D, VK_IMAGE_TILING_OPTIMAL, |
| 944 | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, 0, &image_format_properties); |
| 945 | ASSERT_TRUE(err == VK_ERROR_FORMAT_NOT_SUPPORTED); |
| 946 | m_errorMonitor->VerifyFound(); |
| 947 | } |
Dustin Graves | fce74c0 | 2016-05-10 11:42:58 -0600 | [diff] [blame] | 948 | } |
Mark Lobodzinski | e090fef | 2016-06-09 17:04:56 -0600 | [diff] [blame] | 949 | |
| 950 | TEST_F(VkLayerTest, UpdateBufferAlignment) { |
| 951 | TEST_DESCRIPTION("Check alignment parameters for vkCmdUpdateBuffer"); |
| 952 | uint32_t updateData[] = { 1, 2, 3, 4, 5, 6, 7, 8 }; |
| 953 | |
| 954 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 955 | |
| 956 | VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT; |
| 957 | vk_testing::Buffer buffer; |
| 958 | buffer.init_as_dst(*m_device, (VkDeviceSize)20, reqs); |
| 959 | |
| 960 | BeginCommandBuffer(); |
| 961 | // Introduce failure by using dstOffset that is not multiple of 4 |
| 962 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 963 | " is not a multiple of 4"); |
| 964 | m_commandBuffer->UpdateBuffer(buffer.handle(), 1, 4, updateData); |
| 965 | m_errorMonitor->VerifyFound(); |
| 966 | |
| 967 | // Introduce failure by using dataSize that is not multiple of 4 |
| 968 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 969 | " is not a multiple of 4"); |
| 970 | m_commandBuffer->UpdateBuffer(buffer.handle(), 0, 6, updateData); |
| 971 | m_errorMonitor->VerifyFound(); |
| 972 | |
| 973 | // Introduce failure by using dataSize that is < 0 |
| 974 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 975 | "must be greater than zero and less than or equal to 65536"); |
| 976 | m_commandBuffer->UpdateBuffer(buffer.handle(), 0, -44, updateData); |
| 977 | m_errorMonitor->VerifyFound(); |
| 978 | |
| 979 | // Introduce failure by using dataSize that is > 65536 |
| 980 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 981 | "must be greater than zero and less than or equal to 65536"); |
| 982 | m_commandBuffer->UpdateBuffer(buffer.handle(), 0, 80000, updateData); |
| 983 | m_errorMonitor->VerifyFound(); |
| 984 | |
| 985 | EndCommandBuffer(); |
| 986 | } |
| 987 | |
| 988 | TEST_F(VkLayerTest, FillBufferAlignment) { |
| 989 | TEST_DESCRIPTION("Check alignment parameters for vkCmdFillBuffer"); |
| 990 | |
| 991 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 992 | |
| 993 | VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT; |
| 994 | vk_testing::Buffer buffer; |
| 995 | buffer.init_as_dst(*m_device, (VkDeviceSize)20, reqs); |
| 996 | |
| 997 | BeginCommandBuffer(); |
| 998 | |
| 999 | // Introduce failure by using dstOffset that is not multiple of 4 |
| 1000 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 1001 | " is not a multiple of 4"); |
| 1002 | m_commandBuffer->FillBuffer(buffer.handle(), 1, 4, 0x11111111); |
| 1003 | m_errorMonitor->VerifyFound(); |
| 1004 | |
| 1005 | // Introduce failure by using size that is not multiple of 4 |
| 1006 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 1007 | " is not a multiple of 4"); |
| 1008 | m_commandBuffer->FillBuffer(buffer.handle(), 0, 6, 0x11111111); |
| 1009 | m_errorMonitor->VerifyFound(); |
| 1010 | |
| 1011 | // Introduce failure by using size that is zero |
| 1012 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 1013 | "must be greater than zero"); |
| 1014 | m_commandBuffer->FillBuffer(buffer.handle(), 0, 0, 0x11111111); |
| 1015 | m_errorMonitor->VerifyFound(); |
| 1016 | |
| 1017 | EndCommandBuffer(); |
| 1018 | } |
Dustin Graves | ffa90fa | 2016-05-06 11:20:38 -0600 | [diff] [blame] | 1019 | #endif // PARAMETER_VALIDATION_TESTS |
| 1020 | |
Tobin Ehlis | 0788f52 | 2015-05-26 16:11:58 -0600 | [diff] [blame] | 1021 | #if MEM_TRACKER_TESTS |
Tobin Ehlis | 8fab656 | 2015-12-01 09:57:09 -0700 | [diff] [blame] | 1022 | #if 0 |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 1023 | TEST_F(VkLayerTest, CallResetCommandBufferBeforeCompletion) |
Mark Lobodzinski | ccb2b04 | 2015-05-19 10:28:29 -0500 | [diff] [blame] | 1024 | { |
| 1025 | vk_testing::Fence testFence; |
Mark Lobodzinski | ccb2b04 | 2015-05-19 10:28:29 -0500 | [diff] [blame] | 1026 | VkFenceCreateInfo fenceInfo = {}; |
| 1027 | fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO; |
| 1028 | fenceInfo.pNext = NULL; |
| 1029 | fenceInfo.flags = 0; |
| 1030 | |
Courtney Goeltzenleuchter | 7415d5a | 2015-12-09 15:48:16 -0700 | [diff] [blame] | 1031 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Resetting CB"); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 1032 | |
Mark Lobodzinski | ccb2b04 | 2015-05-19 10:28:29 -0500 | [diff] [blame] | 1033 | ASSERT_NO_FATAL_FAILURE(InitState()); |
Tony Barbour | c1eb1a5 | 2015-07-20 13:00:10 -0600 | [diff] [blame] | 1034 | |
| 1035 | VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT; |
| 1036 | vk_testing::Buffer buffer; |
| 1037 | buffer.init_as_dst(*m_device, (VkDeviceSize)20, reqs); |
Mark Lobodzinski | ccb2b04 | 2015-05-19 10:28:29 -0500 | [diff] [blame] | 1038 | |
Tony Barbour | fe3351b | 2015-07-28 10:17:20 -0600 | [diff] [blame] | 1039 | BeginCommandBuffer(); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 1040 | m_commandBuffer->FillBuffer(buffer.handle(), 0, 4, 0x11111111); |
Tony Barbour | fe3351b | 2015-07-28 10:17:20 -0600 | [diff] [blame] | 1041 | EndCommandBuffer(); |
Mark Lobodzinski | ccb2b04 | 2015-05-19 10:28:29 -0500 | [diff] [blame] | 1042 | |
| 1043 | testFence.init(*m_device, fenceInfo); |
| 1044 | |
| 1045 | // Bypass framework since it does the waits automatically |
| 1046 | VkResult err = VK_SUCCESS; |
Courtney Goeltzenleuchter | 806c700 | 2015-10-27 11:22:14 -0600 | [diff] [blame] | 1047 | VkSubmitInfo submit_info; |
Chia-I Wu | f9be13c | 2015-10-26 20:37:06 +0800 | [diff] [blame] | 1048 | submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO; |
| 1049 | submit_info.pNext = NULL; |
Chia-I Wu | d50a7d7 | 2015-10-26 20:48:51 +0800 | [diff] [blame] | 1050 | submit_info.waitSemaphoreCount = 0; |
Courtney Goeltzenleuchter | 806c700 | 2015-10-27 11:22:14 -0600 | [diff] [blame] | 1051 | submit_info.pWaitSemaphores = NULL; |
Jon Ashburn | 7f9716c | 2015-12-30 16:42:50 -0700 | [diff] [blame] | 1052 | submit_info.pWaitDstStageMask = NULL; |
Chia-I Wu | d50a7d7 | 2015-10-26 20:48:51 +0800 | [diff] [blame] | 1053 | submit_info.commandBufferCount = 1; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 1054 | submit_info.pCommandBuffers = &m_commandBuffer->handle(); |
Chia-I Wu | d50a7d7 | 2015-10-26 20:48:51 +0800 | [diff] [blame] | 1055 | submit_info.signalSemaphoreCount = 0; |
Courtney Goeltzenleuchter | 806c700 | 2015-10-27 11:22:14 -0600 | [diff] [blame] | 1056 | submit_info.pSignalSemaphores = NULL; |
Courtney Goeltzenleuchter | 646b907 | 2015-10-20 18:04:07 -0600 | [diff] [blame] | 1057 | |
| 1058 | err = vkQueueSubmit( m_device->m_queue, 1, &submit_info, testFence.handle()); |
Mark Lobodzinski | ccb2b04 | 2015-05-19 10:28:29 -0500 | [diff] [blame] | 1059 | ASSERT_VK_SUCCESS( err ); |
| 1060 | |
Mark Lobodzinski | ccb2b04 | 2015-05-19 10:28:29 -0500 | [diff] [blame] | 1061 | // Introduce failure by calling begin again before checking fence |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 1062 | vkResetCommandBuffer(m_commandBuffer->handle(), 0); |
Mark Lobodzinski | ccb2b04 | 2015-05-19 10:28:29 -0500 | [diff] [blame] | 1063 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 1064 | m_errorMonitor->VerifyFound(); |
Mark Lobodzinski | ccb2b04 | 2015-05-19 10:28:29 -0500 | [diff] [blame] | 1065 | } |
| 1066 | |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 1067 | TEST_F(VkLayerTest, CallBeginCommandBufferBeforeCompletion) |
Mark Lobodzinski | ccb2b04 | 2015-05-19 10:28:29 -0500 | [diff] [blame] | 1068 | { |
| 1069 | vk_testing::Fence testFence; |
Mark Lobodzinski | ccb2b04 | 2015-05-19 10:28:29 -0500 | [diff] [blame] | 1070 | VkFenceCreateInfo fenceInfo = {}; |
| 1071 | fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO; |
| 1072 | fenceInfo.pNext = NULL; |
| 1073 | fenceInfo.flags = 0; |
| 1074 | |
Courtney Goeltzenleuchter | 7415d5a | 2015-12-09 15:48:16 -0700 | [diff] [blame] | 1075 | 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] | 1076 | |
Mark Lobodzinski | ccb2b04 | 2015-05-19 10:28:29 -0500 | [diff] [blame] | 1077 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 1078 | ASSERT_NO_FATAL_FAILURE(InitViewport()); |
| 1079 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 1080 | |
Tony Barbour | fe3351b | 2015-07-28 10:17:20 -0600 | [diff] [blame] | 1081 | BeginCommandBuffer(); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 1082 | 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] | 1083 | EndCommandBuffer(); |
Mark Lobodzinski | ccb2b04 | 2015-05-19 10:28:29 -0500 | [diff] [blame] | 1084 | |
| 1085 | testFence.init(*m_device, fenceInfo); |
| 1086 | |
| 1087 | // Bypass framework since it does the waits automatically |
| 1088 | VkResult err = VK_SUCCESS; |
Courtney Goeltzenleuchter | 806c700 | 2015-10-27 11:22:14 -0600 | [diff] [blame] | 1089 | VkSubmitInfo submit_info; |
Chia-I Wu | f9be13c | 2015-10-26 20:37:06 +0800 | [diff] [blame] | 1090 | submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO; |
| 1091 | submit_info.pNext = NULL; |
Chia-I Wu | d50a7d7 | 2015-10-26 20:48:51 +0800 | [diff] [blame] | 1092 | submit_info.waitSemaphoreCount = 0; |
Courtney Goeltzenleuchter | 806c700 | 2015-10-27 11:22:14 -0600 | [diff] [blame] | 1093 | submit_info.pWaitSemaphores = NULL; |
Jon Ashburn | 7f9716c | 2015-12-30 16:42:50 -0700 | [diff] [blame] | 1094 | submit_info.pWaitDstStageMask = NULL; |
Chia-I Wu | d50a7d7 | 2015-10-26 20:48:51 +0800 | [diff] [blame] | 1095 | submit_info.commandBufferCount = 1; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 1096 | submit_info.pCommandBuffers = &m_commandBuffer->handle(); |
Chia-I Wu | d50a7d7 | 2015-10-26 20:48:51 +0800 | [diff] [blame] | 1097 | submit_info.signalSemaphoreCount = 0; |
Courtney Goeltzenleuchter | 806c700 | 2015-10-27 11:22:14 -0600 | [diff] [blame] | 1098 | submit_info.pSignalSemaphores = NULL; |
Courtney Goeltzenleuchter | 646b907 | 2015-10-20 18:04:07 -0600 | [diff] [blame] | 1099 | |
| 1100 | err = vkQueueSubmit( m_device->m_queue, 1, &submit_info, testFence.handle()); |
Mark Lobodzinski | ccb2b04 | 2015-05-19 10:28:29 -0500 | [diff] [blame] | 1101 | ASSERT_VK_SUCCESS( err ); |
| 1102 | |
Jon Ashburn | f19916e | 2016-01-11 13:12:43 -0700 | [diff] [blame] | 1103 | VkCommandBufferInheritanceInfo hinfo = {}; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 1104 | VkCommandBufferBeginInfo info = {}; |
| 1105 | info.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT; |
| 1106 | info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO; |
Mark Lobodzinski | 5fcc421 | 2015-09-14 17:43:42 -0600 | [diff] [blame] | 1107 | info.renderPass = VK_NULL_HANDLE; |
| 1108 | info.subpass = 0; |
| 1109 | info.framebuffer = VK_NULL_HANDLE; |
Chia-I Wu | b8d47ae | 2015-11-11 10:18:12 +0800 | [diff] [blame] | 1110 | info.occlusionQueryEnable = VK_FALSE; |
| 1111 | info.queryFlags = 0; |
| 1112 | info.pipelineStatistics = 0; |
Mark Lobodzinski | 5fcc421 | 2015-09-14 17:43:42 -0600 | [diff] [blame] | 1113 | |
| 1114 | // Introduce failure by calling BCB again before checking fence |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 1115 | vkBeginCommandBuffer(m_commandBuffer->handle(), &info); |
Mark Lobodzinski | ccb2b04 | 2015-05-19 10:28:29 -0500 | [diff] [blame] | 1116 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 1117 | m_errorMonitor->VerifyFound(); |
Mark Lobodzinski | ccb2b04 | 2015-05-19 10:28:29 -0500 | [diff] [blame] | 1118 | } |
Tobin Ehlis | 8fab656 | 2015-12-01 09:57:09 -0700 | [diff] [blame] | 1119 | #endif |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 1120 | |
Mark Lobodzinski | 152fe25 | 2016-05-03 16:49:15 -0600 | [diff] [blame] | 1121 | // This is a positive test. No failures are expected. |
| 1122 | TEST_F(VkLayerTest, TestAliasedMemoryTracking) { |
| 1123 | VkResult err; |
| 1124 | bool pass; |
| 1125 | |
| 1126 | TEST_DESCRIPTION("Create a buffer, allocate memory, bind memory, destroy " |
| 1127 | "the buffer, create an image, and bind the same memory to " |
| 1128 | "it"); |
| 1129 | |
| 1130 | m_errorMonitor->ExpectSuccess(); |
| 1131 | |
| 1132 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 1133 | |
| 1134 | VkBuffer buffer; |
| 1135 | VkImage image; |
| 1136 | VkDeviceMemory mem; |
| 1137 | VkMemoryRequirements mem_reqs; |
| 1138 | |
| 1139 | VkBufferCreateInfo buf_info = {}; |
| 1140 | buf_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO; |
| 1141 | buf_info.pNext = NULL; |
| 1142 | buf_info.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT; |
| 1143 | buf_info.size = 256; |
| 1144 | buf_info.queueFamilyIndexCount = 0; |
| 1145 | buf_info.pQueueFamilyIndices = NULL; |
| 1146 | buf_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE; |
| 1147 | buf_info.flags = 0; |
| 1148 | err = vkCreateBuffer(m_device->device(), &buf_info, NULL, &buffer); |
| 1149 | ASSERT_VK_SUCCESS(err); |
| 1150 | |
| 1151 | vkGetBufferMemoryRequirements(m_device->device(), buffer, &mem_reqs); |
| 1152 | |
| 1153 | VkMemoryAllocateInfo alloc_info = {}; |
| 1154 | alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO; |
| 1155 | alloc_info.pNext = NULL; |
| 1156 | alloc_info.memoryTypeIndex = 0; |
| 1157 | |
| 1158 | // Ensure memory is big enough for both bindings |
| 1159 | alloc_info.allocationSize = 0x10000; |
| 1160 | |
| 1161 | pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &alloc_info, |
| 1162 | VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT); |
| 1163 | if (!pass) { |
| 1164 | vkDestroyBuffer(m_device->device(), buffer, NULL); |
| 1165 | return; |
| 1166 | } |
| 1167 | |
| 1168 | err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem); |
| 1169 | ASSERT_VK_SUCCESS(err); |
| 1170 | |
| 1171 | uint8_t *pData; |
| 1172 | err = vkMapMemory(m_device->device(), mem, 0, mem_reqs.size, 0, |
| 1173 | (void **)&pData); |
| 1174 | ASSERT_VK_SUCCESS(err); |
| 1175 | |
Mark Lobodzinski | 2abefa9 | 2016-05-05 11:45:57 -0600 | [diff] [blame] | 1176 | memset(pData, 0xCADECADE, static_cast<size_t>(mem_reqs.size)); |
Mark Lobodzinski | 152fe25 | 2016-05-03 16:49:15 -0600 | [diff] [blame] | 1177 | |
| 1178 | vkUnmapMemory(m_device->device(), mem); |
| 1179 | |
| 1180 | err = vkBindBufferMemory(m_device->device(), buffer, mem, 0); |
| 1181 | ASSERT_VK_SUCCESS(err); |
| 1182 | |
| 1183 | // NOW, destroy the buffer. Obviously, the resource no longer occupies this |
| 1184 | // memory. In fact, it was never used by the GPU. |
| 1185 | // Just be be sure, wait for idle. |
| 1186 | vkDestroyBuffer(m_device->device(), buffer, NULL); |
| 1187 | vkDeviceWaitIdle(m_device->device()); |
| 1188 | |
| 1189 | VkImageCreateInfo image_create_info = {}; |
| 1190 | image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO; |
| 1191 | image_create_info.pNext = NULL; |
| 1192 | image_create_info.imageType = VK_IMAGE_TYPE_2D; |
| 1193 | image_create_info.format = VK_FORMAT_R8G8B8A8_UNORM; |
| 1194 | image_create_info.extent.width = 64; |
| 1195 | image_create_info.extent.height = 64; |
| 1196 | image_create_info.extent.depth = 1; |
| 1197 | image_create_info.mipLevels = 1; |
| 1198 | image_create_info.arrayLayers = 1; |
| 1199 | image_create_info.samples = VK_SAMPLE_COUNT_1_BIT; |
| 1200 | image_create_info.tiling = VK_IMAGE_TILING_LINEAR; |
| 1201 | image_create_info.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED; |
| 1202 | image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT; |
| 1203 | image_create_info.queueFamilyIndexCount = 0; |
| 1204 | image_create_info.pQueueFamilyIndices = NULL; |
| 1205 | image_create_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE; |
| 1206 | image_create_info.flags = 0; |
| 1207 | |
| 1208 | VkMemoryAllocateInfo mem_alloc = {}; |
| 1209 | mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO; |
| 1210 | mem_alloc.pNext = NULL; |
| 1211 | mem_alloc.allocationSize = 0; |
| 1212 | mem_alloc.memoryTypeIndex = 0; |
| 1213 | |
| 1214 | /* Create a mappable image. It will be the texture if linear images are ok |
| 1215 | * to be textures or it will be the staging image if they are not. |
| 1216 | */ |
| 1217 | err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image); |
| 1218 | ASSERT_VK_SUCCESS(err); |
| 1219 | |
| 1220 | vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs); |
| 1221 | |
| 1222 | mem_alloc.allocationSize = mem_reqs.size; |
| 1223 | |
| 1224 | pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, |
| 1225 | VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT); |
| 1226 | if (!pass) { |
| 1227 | vkDestroyImage(m_device->device(), image, NULL); |
| 1228 | return; |
| 1229 | } |
| 1230 | |
Tobin Ehlis | 077ded3 | 2016-05-12 17:39:13 -0600 | [diff] [blame] | 1231 | // VALIDATION FAILURE: |
Mark Lobodzinski | 152fe25 | 2016-05-03 16:49:15 -0600 | [diff] [blame] | 1232 | err = vkBindImageMemory(m_device->device(), image, mem, 0); |
| 1233 | ASSERT_VK_SUCCESS(err); |
| 1234 | |
| 1235 | m_errorMonitor->VerifyNotFound(); |
| 1236 | |
Tony Barbour | df4c004 | 2016-06-01 15:55:43 -0600 | [diff] [blame] | 1237 | vkFreeMemory(m_device->device(), mem, NULL); |
Mark Lobodzinski | 152fe25 | 2016-05-03 16:49:15 -0600 | [diff] [blame] | 1238 | vkDestroyBuffer(m_device->device(), buffer, NULL); |
| 1239 | vkDestroyImage(m_device->device(), image, NULL); |
| 1240 | } |
| 1241 | |
Tobin Ehlis | f11be98 | 2016-05-11 13:52:53 -0600 | [diff] [blame] | 1242 | TEST_F(VkLayerTest, InvalidMemoryAliasing) { |
| 1243 | TEST_DESCRIPTION("Create a buffer and image, allocate memory, and bind the " |
| 1244 | "buffer and image to memory such that they will alias."); |
| 1245 | VkResult err; |
| 1246 | bool pass; |
| 1247 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 1248 | |
Tobin Ehlis | 077ded3 | 2016-05-12 17:39:13 -0600 | [diff] [blame] | 1249 | VkBuffer buffer, buffer2; |
Tobin Ehlis | f11be98 | 2016-05-11 13:52:53 -0600 | [diff] [blame] | 1250 | VkImage image; |
| 1251 | VkDeviceMemory mem; // buffer will be bound first |
| 1252 | VkDeviceMemory mem_img; // image bound first |
Tobin Ehlis | 077ded3 | 2016-05-12 17:39:13 -0600 | [diff] [blame] | 1253 | VkMemoryRequirements buff_mem_reqs, img_mem_reqs; |
Tobin Ehlis | f11be98 | 2016-05-11 13:52:53 -0600 | [diff] [blame] | 1254 | |
| 1255 | VkBufferCreateInfo buf_info = {}; |
| 1256 | buf_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO; |
| 1257 | buf_info.pNext = NULL; |
| 1258 | buf_info.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT; |
| 1259 | buf_info.size = 256; |
| 1260 | buf_info.queueFamilyIndexCount = 0; |
| 1261 | buf_info.pQueueFamilyIndices = NULL; |
| 1262 | buf_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE; |
| 1263 | buf_info.flags = 0; |
| 1264 | err = vkCreateBuffer(m_device->device(), &buf_info, NULL, &buffer); |
| 1265 | ASSERT_VK_SUCCESS(err); |
| 1266 | |
Tobin Ehlis | 077ded3 | 2016-05-12 17:39:13 -0600 | [diff] [blame] | 1267 | vkGetBufferMemoryRequirements(m_device->device(), buffer, &buff_mem_reqs); |
Tobin Ehlis | f11be98 | 2016-05-11 13:52:53 -0600 | [diff] [blame] | 1268 | |
| 1269 | VkImageCreateInfo image_create_info = {}; |
| 1270 | image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO; |
| 1271 | image_create_info.pNext = NULL; |
| 1272 | image_create_info.imageType = VK_IMAGE_TYPE_2D; |
| 1273 | image_create_info.format = VK_FORMAT_R8G8B8A8_UNORM; |
| 1274 | image_create_info.extent.width = 64; |
| 1275 | image_create_info.extent.height = 64; |
| 1276 | image_create_info.extent.depth = 1; |
| 1277 | image_create_info.mipLevels = 1; |
| 1278 | image_create_info.arrayLayers = 1; |
| 1279 | image_create_info.samples = VK_SAMPLE_COUNT_1_BIT; |
| 1280 | image_create_info.tiling = VK_IMAGE_TILING_LINEAR; |
| 1281 | image_create_info.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED; |
| 1282 | image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT; |
| 1283 | image_create_info.queueFamilyIndexCount = 0; |
| 1284 | image_create_info.pQueueFamilyIndices = NULL; |
| 1285 | image_create_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE; |
| 1286 | image_create_info.flags = 0; |
| 1287 | |
Tobin Ehlis | f11be98 | 2016-05-11 13:52:53 -0600 | [diff] [blame] | 1288 | err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image); |
| 1289 | ASSERT_VK_SUCCESS(err); |
| 1290 | |
Tobin Ehlis | 077ded3 | 2016-05-12 17:39:13 -0600 | [diff] [blame] | 1291 | vkGetImageMemoryRequirements(m_device->device(), image, &img_mem_reqs); |
| 1292 | |
| 1293 | VkMemoryAllocateInfo alloc_info = {}; |
| 1294 | alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO; |
| 1295 | alloc_info.pNext = NULL; |
| 1296 | alloc_info.memoryTypeIndex = 0; |
| 1297 | // Ensure memory is big enough for both bindings |
| 1298 | alloc_info.allocationSize = buff_mem_reqs.size + img_mem_reqs.size; |
| 1299 | pass = m_device->phy().set_memory_type( |
| 1300 | buff_mem_reqs.memoryTypeBits | img_mem_reqs.memoryTypeBits, &alloc_info, |
| 1301 | VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT); |
Tobin Ehlis | f11be98 | 2016-05-11 13:52:53 -0600 | [diff] [blame] | 1302 | if (!pass) { |
Tobin Ehlis | 077ded3 | 2016-05-12 17:39:13 -0600 | [diff] [blame] | 1303 | vkDestroyBuffer(m_device->device(), buffer, NULL); |
Tobin Ehlis | f11be98 | 2016-05-11 13:52:53 -0600 | [diff] [blame] | 1304 | vkDestroyImage(m_device->device(), image, NULL); |
| 1305 | return; |
| 1306 | } |
Tobin Ehlis | 077ded3 | 2016-05-12 17:39:13 -0600 | [diff] [blame] | 1307 | err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem); |
| 1308 | ASSERT_VK_SUCCESS(err); |
| 1309 | err = vkBindBufferMemory(m_device->device(), buffer, mem, 0); |
| 1310 | ASSERT_VK_SUCCESS(err); |
| 1311 | |
Tobin Ehlis | f11be98 | 2016-05-11 13:52:53 -0600 | [diff] [blame] | 1312 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 1313 | " is aliased with buffer 0x"); |
Tobin Ehlis | 077ded3 | 2016-05-12 17:39:13 -0600 | [diff] [blame] | 1314 | // VALIDATION FAILURE due to image mapping overlapping buffer mapping |
Tobin Ehlis | f11be98 | 2016-05-11 13:52:53 -0600 | [diff] [blame] | 1315 | err = vkBindImageMemory(m_device->device(), image, mem, 0); |
| 1316 | m_errorMonitor->VerifyFound(); |
| 1317 | |
| 1318 | // Now correctly bind image to second mem allocation before incorrectly |
Tobin Ehlis | 077ded3 | 2016-05-12 17:39:13 -0600 | [diff] [blame] | 1319 | // aliasing buffer2 |
| 1320 | err = vkCreateBuffer(m_device->device(), &buf_info, NULL, &buffer2); |
| 1321 | ASSERT_VK_SUCCESS(err); |
Tobin Ehlis | f11be98 | 2016-05-11 13:52:53 -0600 | [diff] [blame] | 1322 | err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem_img); |
| 1323 | ASSERT_VK_SUCCESS(err); |
| 1324 | err = vkBindImageMemory(m_device->device(), image, mem_img, 0); |
| 1325 | ASSERT_VK_SUCCESS(err); |
| 1326 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 1327 | " is aliased with image 0x"); |
Tobin Ehlis | 077ded3 | 2016-05-12 17:39:13 -0600 | [diff] [blame] | 1328 | err = vkBindBufferMemory(m_device->device(), buffer2, mem_img, 0); |
Tobin Ehlis | f11be98 | 2016-05-11 13:52:53 -0600 | [diff] [blame] | 1329 | m_errorMonitor->VerifyFound(); |
| 1330 | |
| 1331 | vkDestroyBuffer(m_device->device(), buffer, NULL); |
Tobin Ehlis | 077ded3 | 2016-05-12 17:39:13 -0600 | [diff] [blame] | 1332 | vkDestroyBuffer(m_device->device(), buffer2, NULL); |
Tobin Ehlis | f11be98 | 2016-05-11 13:52:53 -0600 | [diff] [blame] | 1333 | vkDestroyImage(m_device->device(), image, NULL); |
| 1334 | vkFreeMemory(m_device->device(), mem, NULL); |
| 1335 | vkFreeMemory(m_device->device(), mem_img, NULL); |
| 1336 | } |
| 1337 | |
Tobin Ehlis | 3537252 | 2016-05-12 08:32:31 -0600 | [diff] [blame] | 1338 | TEST_F(VkLayerTest, InvalidMemoryMapping) { |
| 1339 | TEST_DESCRIPTION("Attempt to map memory in a number of incorrect ways"); |
| 1340 | VkResult err; |
| 1341 | bool pass; |
| 1342 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 1343 | |
| 1344 | VkBuffer buffer; |
| 1345 | VkDeviceMemory mem; |
| 1346 | VkMemoryRequirements mem_reqs; |
| 1347 | |
| 1348 | VkBufferCreateInfo buf_info = {}; |
| 1349 | buf_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO; |
| 1350 | buf_info.pNext = NULL; |
| 1351 | buf_info.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT; |
| 1352 | buf_info.size = 256; |
| 1353 | buf_info.queueFamilyIndexCount = 0; |
| 1354 | buf_info.pQueueFamilyIndices = NULL; |
| 1355 | buf_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE; |
| 1356 | buf_info.flags = 0; |
| 1357 | err = vkCreateBuffer(m_device->device(), &buf_info, NULL, &buffer); |
| 1358 | ASSERT_VK_SUCCESS(err); |
| 1359 | |
| 1360 | vkGetBufferMemoryRequirements(m_device->device(), buffer, &mem_reqs); |
| 1361 | VkMemoryAllocateInfo alloc_info = {}; |
| 1362 | alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO; |
| 1363 | alloc_info.pNext = NULL; |
| 1364 | alloc_info.memoryTypeIndex = 0; |
| 1365 | |
| 1366 | // Ensure memory is big enough for both bindings |
| 1367 | static const VkDeviceSize allocation_size = 0x10000; |
| 1368 | alloc_info.allocationSize = allocation_size; |
| 1369 | pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &alloc_info, |
| 1370 | VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT); |
| 1371 | if (!pass) { |
| 1372 | vkDestroyBuffer(m_device->device(), buffer, NULL); |
| 1373 | return; |
| 1374 | } |
| 1375 | err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem); |
| 1376 | ASSERT_VK_SUCCESS(err); |
| 1377 | |
| 1378 | uint8_t *pData; |
| 1379 | // Attempt to map memory size 0 is invalid |
| 1380 | m_errorMonitor->SetDesiredFailureMsg( |
| 1381 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 1382 | "VkMapMemory: Attempting to map memory range of size zero"); |
| 1383 | err = vkMapMemory(m_device->device(), mem, 0, 0, 0, (void **)&pData); |
| 1384 | m_errorMonitor->VerifyFound(); |
| 1385 | // Map memory twice |
| 1386 | err = vkMapMemory(m_device->device(), mem, 0, mem_reqs.size, 0, |
| 1387 | (void **)&pData); |
| 1388 | ASSERT_VK_SUCCESS(err); |
| 1389 | m_errorMonitor->SetDesiredFailureMsg( |
| 1390 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 1391 | "VkMapMemory: Attempting to map memory on an already-mapped object "); |
| 1392 | err = vkMapMemory(m_device->device(), mem, 0, mem_reqs.size, 0, |
| 1393 | (void **)&pData); |
| 1394 | m_errorMonitor->VerifyFound(); |
| 1395 | |
| 1396 | // Unmap the memory to avoid re-map error |
| 1397 | vkUnmapMemory(m_device->device(), mem); |
| 1398 | // overstep allocation with VK_WHOLE_SIZE |
| 1399 | m_errorMonitor->SetDesiredFailureMsg( |
| 1400 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 1401 | " with size of VK_WHOLE_SIZE oversteps total array size 0x"); |
| 1402 | err = vkMapMemory(m_device->device(), mem, allocation_size + 1, |
| 1403 | VK_WHOLE_SIZE, 0, (void **)&pData); |
| 1404 | m_errorMonitor->VerifyFound(); |
| 1405 | // overstep allocation w/o VK_WHOLE_SIZE |
| 1406 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 1407 | " oversteps total array size 0x"); |
| 1408 | err = vkMapMemory(m_device->device(), mem, 1, allocation_size, 0, |
| 1409 | (void **)&pData); |
| 1410 | m_errorMonitor->VerifyFound(); |
| 1411 | // Now error due to unmapping memory that's not mapped |
| 1412 | m_errorMonitor->SetDesiredFailureMsg( |
| 1413 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 1414 | "Unmapping Memory without memory being mapped: "); |
| 1415 | vkUnmapMemory(m_device->device(), mem); |
| 1416 | m_errorMonitor->VerifyFound(); |
| 1417 | // Now map memory and cause errors due to flushing invalid ranges |
| 1418 | err = vkMapMemory(m_device->device(), mem, 16, VK_WHOLE_SIZE, 0, |
| 1419 | (void **)&pData); |
| 1420 | ASSERT_VK_SUCCESS(err); |
| 1421 | VkMappedMemoryRange mmr = {}; |
Chris Forbes | 3aec089 | 2016-06-13 10:29:26 +1200 | [diff] [blame] | 1422 | mmr.sType = VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE; |
Tobin Ehlis | 3537252 | 2016-05-12 08:32:31 -0600 | [diff] [blame] | 1423 | mmr.memory = mem; |
| 1424 | mmr.offset = 15; // Error b/c offset less than offset of mapped mem |
| 1425 | m_errorMonitor->SetDesiredFailureMsg( |
| 1426 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 1427 | ") is less than Memory Object's offset ("); |
| 1428 | vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr); |
| 1429 | m_errorMonitor->VerifyFound(); |
| 1430 | // Now flush range that oversteps mapped range |
| 1431 | vkUnmapMemory(m_device->device(), mem); |
| 1432 | err = vkMapMemory(m_device->device(), mem, 0, 256, 0, (void **)&pData); |
| 1433 | ASSERT_VK_SUCCESS(err); |
| 1434 | mmr.offset = 16; |
| 1435 | mmr.size = 256; // flushing bounds (272) exceed mapped bounds (256) |
| 1436 | m_errorMonitor->SetDesiredFailureMsg( |
| 1437 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 1438 | ") exceeds the Memory Object's upper-bound ("); |
| 1439 | vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr); |
| 1440 | m_errorMonitor->VerifyFound(); |
| 1441 | |
| 1442 | pass = |
| 1443 | m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &alloc_info, |
| 1444 | VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT, |
| 1445 | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT); |
| 1446 | if (!pass) { |
| 1447 | vkFreeMemory(m_device->device(), mem, NULL); |
| 1448 | vkDestroyBuffer(m_device->device(), buffer, NULL); |
| 1449 | return; |
| 1450 | } |
| 1451 | // TODO : If we can get HOST_VISIBLE w/o HOST_COHERENT we can test cases of |
| 1452 | // MEMTRACK_INVALID_MAP in validateAndCopyNoncoherentMemoryToDriver() |
| 1453 | |
| 1454 | vkDestroyBuffer(m_device->device(), buffer, NULL); |
| 1455 | vkFreeMemory(m_device->device(), mem, NULL); |
| 1456 | } |
| 1457 | |
Ian Elliott | 1c32c77 | 2016-04-28 14:47:13 -0600 | [diff] [blame] | 1458 | TEST_F(VkLayerTest, EnableWsiBeforeUse) { |
| 1459 | VkResult err; |
| 1460 | bool pass; |
| 1461 | |
Ian Elliott | 489eec0 | 2016-05-05 14:12:44 -0600 | [diff] [blame] | 1462 | // FIXME: After we turn on this code for non-Linux platforms, uncomment the |
| 1463 | // following declaration (which is temporarily being moved below): |
| 1464 | // VkSurfaceKHR surface = VK_NULL_HANDLE; |
Ian Elliott | 1c32c77 | 2016-04-28 14:47:13 -0600 | [diff] [blame] | 1465 | VkSwapchainKHR swapchain = VK_NULL_HANDLE; |
| 1466 | VkSwapchainCreateInfoKHR swapchain_create_info = {}; |
| 1467 | uint32_t swapchain_image_count = 0; |
| 1468 | // VkImage swapchain_images[1] = {VK_NULL_HANDLE}; |
| 1469 | uint32_t image_index = 0; |
| 1470 | // VkPresentInfoKHR present_info = {}; |
| 1471 | |
| 1472 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 1473 | |
Ian Elliott | 3f06ce5 | 2016-04-29 14:46:21 -0600 | [diff] [blame] | 1474 | #ifdef NEED_TO_TEST_THIS_ON_PLATFORM |
| 1475 | #if defined(VK_USE_PLATFORM_ANDROID_KHR) |
| 1476 | // Use the functions from the VK_KHR_android_surface extension without |
| 1477 | // enabling that extension: |
| 1478 | |
| 1479 | // Create a surface: |
| 1480 | VkAndroidSurfaceCreateInfoKHR android_create_info = {}; |
Ian Elliott | 3f06ce5 | 2016-04-29 14:46:21 -0600 | [diff] [blame] | 1481 | m_errorMonitor->SetDesiredFailureMsg( |
| 1482 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 1483 | "extension was not enabled for this"); |
| 1484 | err = vkCreateAndroidSurfaceKHR(instance(), &android_create_info, NULL, |
| 1485 | &surface); |
| 1486 | pass = (err != VK_SUCCESS); |
| 1487 | ASSERT_TRUE(pass); |
| 1488 | m_errorMonitor->VerifyFound(); |
| 1489 | #endif // VK_USE_PLATFORM_ANDROID_KHR |
| 1490 | |
| 1491 | |
| 1492 | #if defined(VK_USE_PLATFORM_MIR_KHR) |
| 1493 | // Use the functions from the VK_KHR_mir_surface extension without enabling |
| 1494 | // that extension: |
| 1495 | |
| 1496 | // Create a surface: |
| 1497 | VkMirSurfaceCreateInfoKHR mir_create_info = {}; |
Ian Elliott | 3f06ce5 | 2016-04-29 14:46:21 -0600 | [diff] [blame] | 1498 | m_errorMonitor->SetDesiredFailureMsg( |
| 1499 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 1500 | "extension was not enabled for this"); |
| 1501 | err = vkCreateMirSurfaceKHR(instance(), &mir_create_info, NULL, &surface); |
| 1502 | pass = (err != VK_SUCCESS); |
| 1503 | ASSERT_TRUE(pass); |
| 1504 | m_errorMonitor->VerifyFound(); |
| 1505 | |
| 1506 | // Tell whether an mir_connection supports presentation: |
| 1507 | MirConnection *mir_connection = NULL; |
| 1508 | m_errorMonitor->SetDesiredFailureMsg( |
| 1509 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 1510 | "extension was not enabled for this"); |
| 1511 | vkGetPhysicalDeviceMirPresentationSupportKHR(gpu(), 0, mir_connection, |
| 1512 | visual_id); |
| 1513 | m_errorMonitor->VerifyFound(); |
| 1514 | #endif // VK_USE_PLATFORM_MIR_KHR |
| 1515 | |
| 1516 | |
| 1517 | #if defined(VK_USE_PLATFORM_WAYLAND_KHR) |
| 1518 | // Use the functions from the VK_KHR_wayland_surface extension without |
| 1519 | // enabling that extension: |
| 1520 | |
| 1521 | // Create a surface: |
| 1522 | VkWaylandSurfaceCreateInfoKHR wayland_create_info = {}; |
Ian Elliott | 3f06ce5 | 2016-04-29 14:46:21 -0600 | [diff] [blame] | 1523 | m_errorMonitor->SetDesiredFailureMsg( |
| 1524 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 1525 | "extension was not enabled for this"); |
| 1526 | err = vkCreateWaylandSurfaceKHR(instance(), &wayland_create_info, NULL, |
| 1527 | &surface); |
| 1528 | pass = (err != VK_SUCCESS); |
| 1529 | ASSERT_TRUE(pass); |
| 1530 | m_errorMonitor->VerifyFound(); |
| 1531 | |
| 1532 | // Tell whether an wayland_display supports presentation: |
| 1533 | struct wl_display wayland_display = {}; |
| 1534 | m_errorMonitor->SetDesiredFailureMsg( |
| 1535 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 1536 | "extension was not enabled for this"); |
| 1537 | vkGetPhysicalDeviceWaylandPresentationSupportKHR(gpu(), 0, |
| 1538 | &wayland_display); |
| 1539 | m_errorMonitor->VerifyFound(); |
| 1540 | #endif // VK_USE_PLATFORM_WAYLAND_KHR |
Ian Elliott | 489eec0 | 2016-05-05 14:12:44 -0600 | [diff] [blame] | 1541 | #endif // NEED_TO_TEST_THIS_ON_PLATFORM |
Ian Elliott | 3f06ce5 | 2016-04-29 14:46:21 -0600 | [diff] [blame] | 1542 | |
| 1543 | |
| 1544 | #if defined(VK_USE_PLATFORM_WIN32_KHR) |
Ian Elliott | 489eec0 | 2016-05-05 14:12:44 -0600 | [diff] [blame] | 1545 | // FIXME: REMOVE THIS HERE, AND UNCOMMENT ABOVE, WHEN THIS TEST HAS BEEN PORTED |
| 1546 | // TO NON-LINUX PLATFORMS: |
| 1547 | VkSurfaceKHR surface = VK_NULL_HANDLE; |
Ian Elliott | 3f06ce5 | 2016-04-29 14:46:21 -0600 | [diff] [blame] | 1548 | // Use the functions from the VK_KHR_win32_surface extension without |
| 1549 | // enabling that extension: |
| 1550 | |
| 1551 | // Create a surface: |
| 1552 | VkWin32SurfaceCreateInfoKHR win32_create_info = {}; |
Ian Elliott | 3f06ce5 | 2016-04-29 14:46:21 -0600 | [diff] [blame] | 1553 | m_errorMonitor->SetDesiredFailureMsg( |
| 1554 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 1555 | "extension was not enabled for this"); |
| 1556 | err = vkCreateWin32SurfaceKHR(instance(), &win32_create_info, NULL, |
| 1557 | &surface); |
| 1558 | pass = (err != VK_SUCCESS); |
| 1559 | ASSERT_TRUE(pass); |
| 1560 | m_errorMonitor->VerifyFound(); |
| 1561 | |
| 1562 | // Tell whether win32 supports presentation: |
Ian Elliott | 3f06ce5 | 2016-04-29 14:46:21 -0600 | [diff] [blame] | 1563 | m_errorMonitor->SetDesiredFailureMsg( |
| 1564 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 1565 | "extension was not enabled for this"); |
Ian Elliott | 489eec0 | 2016-05-05 14:12:44 -0600 | [diff] [blame] | 1566 | vkGetPhysicalDeviceWin32PresentationSupportKHR(gpu(), 0); |
Ian Elliott | 3f06ce5 | 2016-04-29 14:46:21 -0600 | [diff] [blame] | 1567 | m_errorMonitor->VerifyFound(); |
Ian Elliott | 489eec0 | 2016-05-05 14:12:44 -0600 | [diff] [blame] | 1568 | // Set this (for now, until all platforms are supported and tested): |
| 1569 | #define NEED_TO_TEST_THIS_ON_PLATFORM |
| 1570 | #endif // VK_USE_PLATFORM_WIN32_KHR |
Ian Elliott | 3f06ce5 | 2016-04-29 14:46:21 -0600 | [diff] [blame] | 1571 | |
| 1572 | |
Ian Elliott | 1c32c77 | 2016-04-28 14:47:13 -0600 | [diff] [blame] | 1573 | #if defined(VK_USE_PLATFORM_XCB_KHR) |
Ian Elliott | 489eec0 | 2016-05-05 14:12:44 -0600 | [diff] [blame] | 1574 | // FIXME: REMOVE THIS HERE, AND UNCOMMENT ABOVE, WHEN THIS TEST HAS BEEN PORTED |
| 1575 | // TO NON-LINUX PLATFORMS: |
| 1576 | VkSurfaceKHR surface = VK_NULL_HANDLE; |
Ian Elliott | 1c32c77 | 2016-04-28 14:47:13 -0600 | [diff] [blame] | 1577 | // Use the functions from the VK_KHR_xcb_surface extension without enabling |
| 1578 | // that extension: |
| 1579 | |
| 1580 | // Create a surface: |
| 1581 | VkXcbSurfaceCreateInfoKHR xcb_create_info = {}; |
Ian Elliott | 1c32c77 | 2016-04-28 14:47:13 -0600 | [diff] [blame] | 1582 | m_errorMonitor->SetDesiredFailureMsg( |
| 1583 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 1584 | "extension was not enabled for this"); |
| 1585 | err = vkCreateXcbSurfaceKHR(instance(), &xcb_create_info, NULL, &surface); |
| 1586 | pass = (err != VK_SUCCESS); |
| 1587 | ASSERT_TRUE(pass); |
| 1588 | m_errorMonitor->VerifyFound(); |
| 1589 | |
| 1590 | // Tell whether an xcb_visualid_t supports presentation: |
Ian Elliott | 3f06ce5 | 2016-04-29 14:46:21 -0600 | [diff] [blame] | 1591 | xcb_connection_t *xcb_connection = NULL; |
Ian Elliott | 1c32c77 | 2016-04-28 14:47:13 -0600 | [diff] [blame] | 1592 | xcb_visualid_t visual_id = 0; |
| 1593 | m_errorMonitor->SetDesiredFailureMsg( |
| 1594 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 1595 | "extension was not enabled for this"); |
Ian Elliott | 3f06ce5 | 2016-04-29 14:46:21 -0600 | [diff] [blame] | 1596 | vkGetPhysicalDeviceXcbPresentationSupportKHR(gpu(), 0, xcb_connection, |
Ian Elliott | 1c32c77 | 2016-04-28 14:47:13 -0600 | [diff] [blame] | 1597 | visual_id); |
| 1598 | m_errorMonitor->VerifyFound(); |
Ian Elliott | 489eec0 | 2016-05-05 14:12:44 -0600 | [diff] [blame] | 1599 | // Set this (for now, until all platforms are supported and tested): |
| 1600 | #define NEED_TO_TEST_THIS_ON_PLATFORM |
Ian Elliott | 1c32c77 | 2016-04-28 14:47:13 -0600 | [diff] [blame] | 1601 | #endif // VK_USE_PLATFORM_XCB_KHR |
| 1602 | |
| 1603 | |
Ian Elliott | 1263081 | 2016-04-29 14:35:43 -0600 | [diff] [blame] | 1604 | #if defined(VK_USE_PLATFORM_XLIB_KHR) |
| 1605 | // Use the functions from the VK_KHR_xlib_surface extension without enabling |
| 1606 | // that extension: |
| 1607 | |
| 1608 | // Create a surface: |
| 1609 | VkXlibSurfaceCreateInfoKHR xlib_create_info = {}; |
Ian Elliott | 1263081 | 2016-04-29 14:35:43 -0600 | [diff] [blame] | 1610 | m_errorMonitor->SetDesiredFailureMsg( |
| 1611 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 1612 | "extension was not enabled for this"); |
| 1613 | err = vkCreateXlibSurfaceKHR(instance(), &xlib_create_info, NULL, &surface); |
| 1614 | pass = (err != VK_SUCCESS); |
| 1615 | ASSERT_TRUE(pass); |
| 1616 | m_errorMonitor->VerifyFound(); |
| 1617 | |
| 1618 | // Tell whether an Xlib VisualID supports presentation: |
| 1619 | Display *dpy = NULL; |
| 1620 | VisualID visual = 0; |
| 1621 | m_errorMonitor->SetDesiredFailureMsg( |
| 1622 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 1623 | "extension was not enabled for this"); |
| 1624 | vkGetPhysicalDeviceXlibPresentationSupportKHR(gpu(), 0, dpy, visual); |
| 1625 | m_errorMonitor->VerifyFound(); |
Ian Elliott | 489eec0 | 2016-05-05 14:12:44 -0600 | [diff] [blame] | 1626 | // Set this (for now, until all platforms are supported and tested): |
| 1627 | #define NEED_TO_TEST_THIS_ON_PLATFORM |
Ian Elliott | 1263081 | 2016-04-29 14:35:43 -0600 | [diff] [blame] | 1628 | #endif // VK_USE_PLATFORM_XLIB_KHR |
| 1629 | |
| 1630 | |
Ian Elliott | 1c32c77 | 2016-04-28 14:47:13 -0600 | [diff] [blame] | 1631 | // Use the functions from the VK_KHR_surface extension without enabling |
| 1632 | // that extension: |
| 1633 | |
Ian Elliott | 489eec0 | 2016-05-05 14:12:44 -0600 | [diff] [blame] | 1634 | #ifdef NEED_TO_TEST_THIS_ON_PLATFORM |
Ian Elliott | 1c32c77 | 2016-04-28 14:47:13 -0600 | [diff] [blame] | 1635 | // Destroy a surface: |
| 1636 | m_errorMonitor->SetDesiredFailureMsg( |
| 1637 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 1638 | "extension was not enabled for this"); |
| 1639 | vkDestroySurfaceKHR(instance(), surface, NULL); |
| 1640 | m_errorMonitor->VerifyFound(); |
| 1641 | |
| 1642 | // Check if surface supports presentation: |
| 1643 | VkBool32 supported = false; |
| 1644 | m_errorMonitor->SetDesiredFailureMsg( |
| 1645 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 1646 | "extension was not enabled for this"); |
| 1647 | err = vkGetPhysicalDeviceSurfaceSupportKHR(gpu(), 0, surface, &supported); |
| 1648 | pass = (err != VK_SUCCESS); |
| 1649 | ASSERT_TRUE(pass); |
| 1650 | m_errorMonitor->VerifyFound(); |
| 1651 | |
| 1652 | // Check surface capabilities: |
| 1653 | VkSurfaceCapabilitiesKHR capabilities = {}; |
| 1654 | m_errorMonitor->SetDesiredFailureMsg( |
| 1655 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 1656 | "extension was not enabled for this"); |
| 1657 | err = vkGetPhysicalDeviceSurfaceCapabilitiesKHR(gpu(), surface, |
| 1658 | &capabilities); |
| 1659 | pass = (err != VK_SUCCESS); |
| 1660 | ASSERT_TRUE(pass); |
| 1661 | m_errorMonitor->VerifyFound(); |
| 1662 | |
| 1663 | // Check surface formats: |
| 1664 | uint32_t format_count = 0; |
| 1665 | VkSurfaceFormatKHR *formats = NULL; |
| 1666 | m_errorMonitor->SetDesiredFailureMsg( |
| 1667 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 1668 | "extension was not enabled for this"); |
| 1669 | err = vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, |
| 1670 | &format_count, formats); |
| 1671 | pass = (err != VK_SUCCESS); |
| 1672 | ASSERT_TRUE(pass); |
| 1673 | m_errorMonitor->VerifyFound(); |
| 1674 | |
| 1675 | // Check surface present modes: |
| 1676 | uint32_t present_mode_count = 0; |
| 1677 | VkSurfaceFormatKHR *present_modes = NULL; |
| 1678 | m_errorMonitor->SetDesiredFailureMsg( |
| 1679 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 1680 | "extension was not enabled for this"); |
| 1681 | err = vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, |
| 1682 | &present_mode_count, present_modes); |
| 1683 | pass = (err != VK_SUCCESS); |
| 1684 | ASSERT_TRUE(pass); |
| 1685 | m_errorMonitor->VerifyFound(); |
Ian Elliott | 489eec0 | 2016-05-05 14:12:44 -0600 | [diff] [blame] | 1686 | #endif // NEED_TO_TEST_THIS_ON_PLATFORM |
Ian Elliott | 1c32c77 | 2016-04-28 14:47:13 -0600 | [diff] [blame] | 1687 | |
| 1688 | |
| 1689 | // Use the functions from the VK_KHR_swapchain extension without enabling |
| 1690 | // that extension: |
| 1691 | |
| 1692 | // Create a swapchain: |
| 1693 | m_errorMonitor->SetDesiredFailureMsg( |
| 1694 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 1695 | "extension was not enabled for this"); |
| 1696 | swapchain_create_info.sType = VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR; |
| 1697 | swapchain_create_info.pNext = NULL; |
Ian Elliott | 1c32c77 | 2016-04-28 14:47:13 -0600 | [diff] [blame] | 1698 | err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, |
| 1699 | NULL, &swapchain); |
| 1700 | pass = (err != VK_SUCCESS); |
| 1701 | ASSERT_TRUE(pass); |
| 1702 | m_errorMonitor->VerifyFound(); |
| 1703 | |
| 1704 | // Get the images from the swapchain: |
| 1705 | m_errorMonitor->SetDesiredFailureMsg( |
| 1706 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 1707 | "extension was not enabled for this"); |
| 1708 | err = vkGetSwapchainImagesKHR(m_device->device(), swapchain, |
| 1709 | &swapchain_image_count, NULL); |
| 1710 | pass = (err != VK_SUCCESS); |
| 1711 | ASSERT_TRUE(pass); |
| 1712 | m_errorMonitor->VerifyFound(); |
| 1713 | |
| 1714 | // Try to acquire an image: |
| 1715 | m_errorMonitor->SetDesiredFailureMsg( |
| 1716 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 1717 | "extension was not enabled for this"); |
| 1718 | err = vkAcquireNextImageKHR(m_device->device(), swapchain, 0, |
| 1719 | VK_NULL_HANDLE, VK_NULL_HANDLE, &image_index); |
| 1720 | pass = (err != VK_SUCCESS); |
| 1721 | ASSERT_TRUE(pass); |
| 1722 | m_errorMonitor->VerifyFound(); |
| 1723 | |
| 1724 | // Try to present an image: |
Ian Elliott | 2c1daf5 | 2016-05-12 09:41:46 -0600 | [diff] [blame] | 1725 | // |
| 1726 | // NOTE: Currently can't test this because a real swapchain is needed (as |
| 1727 | // opposed to the fake one we created) in order for the layer to lookup the |
| 1728 | // VkDevice used to enable the extension: |
Ian Elliott | 1c32c77 | 2016-04-28 14:47:13 -0600 | [diff] [blame] | 1729 | |
| 1730 | // Destroy the swapchain: |
| 1731 | m_errorMonitor->SetDesiredFailureMsg( |
| 1732 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 1733 | "extension was not enabled for this"); |
| 1734 | vkDestroySwapchainKHR(m_device->device(), swapchain, NULL); |
| 1735 | m_errorMonitor->VerifyFound(); |
| 1736 | } |
| 1737 | |
Ian Elliott | 2c1daf5 | 2016-05-12 09:41:46 -0600 | [diff] [blame] | 1738 | TEST_F(VkWsiEnabledLayerTest, TestEnabledWsi) { |
Ian Elliott | 2c1daf5 | 2016-05-12 09:41:46 -0600 | [diff] [blame] | 1739 | |
Dustin Graves | 6c6d898 | 2016-05-17 10:09:21 -0600 | [diff] [blame] | 1740 | #if defined(VK_USE_PLATFORM_XCB_KHR) |
Ian Elliott | 2c1daf5 | 2016-05-12 09:41:46 -0600 | [diff] [blame] | 1741 | VkSurfaceKHR surface = VK_NULL_HANDLE; |
Mark Lobodzinski | 085d27a | 2016-05-17 09:34:26 -0600 | [diff] [blame] | 1742 | |
Mark Lobodzinski | 085d27a | 2016-05-17 09:34:26 -0600 | [diff] [blame] | 1743 | VkResult err; |
| 1744 | bool pass; |
Ian Elliott | 2c1daf5 | 2016-05-12 09:41:46 -0600 | [diff] [blame] | 1745 | VkSwapchainKHR swapchain = VK_NULL_HANDLE; |
| 1746 | VkSwapchainCreateInfoKHR swapchain_create_info = {}; |
Mark Lobodzinski | 085d27a | 2016-05-17 09:34:26 -0600 | [diff] [blame] | 1747 | // uint32_t swapchain_image_count = 0; |
| 1748 | // VkImage swapchain_images[1] = {VK_NULL_HANDLE}; |
| 1749 | // uint32_t image_index = 0; |
| 1750 | // VkPresentInfoKHR present_info = {}; |
Ian Elliott | 2c1daf5 | 2016-05-12 09:41:46 -0600 | [diff] [blame] | 1751 | |
| 1752 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 1753 | |
| 1754 | // Use the create function from one of the VK_KHR_*_surface extension in |
| 1755 | // order to create a surface, testing all known errors in the process, |
| 1756 | // before successfully creating a surface: |
| 1757 | // First, try to create a surface without a VkXcbSurfaceCreateInfoKHR: |
Mark Lobodzinski | 085d27a | 2016-05-17 09:34:26 -0600 | [diff] [blame] | 1758 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 1759 | "called with NULL pointer"); |
Ian Elliott | 2c1daf5 | 2016-05-12 09:41:46 -0600 | [diff] [blame] | 1760 | err = vkCreateXcbSurfaceKHR(instance(), NULL, NULL, &surface); |
| 1761 | pass = (err != VK_SUCCESS); |
| 1762 | ASSERT_TRUE(pass); |
| 1763 | m_errorMonitor->VerifyFound(); |
| 1764 | |
| 1765 | // Next, try to create a surface with the wrong |
| 1766 | // VkXcbSurfaceCreateInfoKHR::sType: |
| 1767 | VkXcbSurfaceCreateInfoKHR xcb_create_info = {}; |
| 1768 | xcb_create_info.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO; |
Mark Lobodzinski | 085d27a | 2016-05-17 09:34:26 -0600 | [diff] [blame] | 1769 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 1770 | "called with the wrong value for"); |
Ian Elliott | 2c1daf5 | 2016-05-12 09:41:46 -0600 | [diff] [blame] | 1771 | err = vkCreateXcbSurfaceKHR(instance(), &xcb_create_info, NULL, &surface); |
| 1772 | pass = (err != VK_SUCCESS); |
| 1773 | ASSERT_TRUE(pass); |
| 1774 | m_errorMonitor->VerifyFound(); |
| 1775 | |
Ian Elliott | 2c1daf5 | 2016-05-12 09:41:46 -0600 | [diff] [blame] | 1776 | // Create a native window, and then correctly create a surface: |
| 1777 | xcb_connection_t *connection; |
| 1778 | xcb_screen_t *screen; |
| 1779 | xcb_window_t xcb_window; |
| 1780 | xcb_intern_atom_reply_t *atom_wm_delete_window; |
| 1781 | |
| 1782 | const xcb_setup_t *setup; |
| 1783 | xcb_screen_iterator_t iter; |
| 1784 | int scr; |
| 1785 | uint32_t value_mask, value_list[32]; |
| 1786 | int width = 1; |
| 1787 | int height = 1; |
| 1788 | |
| 1789 | connection = xcb_connect(NULL, &scr); |
| 1790 | ASSERT_TRUE(connection != NULL); |
| 1791 | setup = xcb_get_setup(connection); |
| 1792 | iter = xcb_setup_roots_iterator(setup); |
| 1793 | while (scr-- > 0) |
| 1794 | xcb_screen_next(&iter); |
| 1795 | screen = iter.data; |
| 1796 | |
| 1797 | xcb_window = xcb_generate_id(connection); |
| 1798 | |
| 1799 | value_mask = XCB_CW_BACK_PIXEL | XCB_CW_EVENT_MASK; |
| 1800 | value_list[0] = screen->black_pixel; |
| 1801 | value_list[1] = XCB_EVENT_MASK_KEY_RELEASE | XCB_EVENT_MASK_EXPOSURE | |
| 1802 | XCB_EVENT_MASK_STRUCTURE_NOTIFY; |
| 1803 | |
| 1804 | xcb_create_window(connection, XCB_COPY_FROM_PARENT, xcb_window, |
| 1805 | screen->root, 0, 0, width, height, 0, |
| 1806 | XCB_WINDOW_CLASS_INPUT_OUTPUT, screen->root_visual, |
| 1807 | value_mask, value_list); |
| 1808 | |
| 1809 | /* Magic code that will send notification when window is destroyed */ |
| 1810 | xcb_intern_atom_cookie_t cookie = |
| 1811 | xcb_intern_atom(connection, 1, 12, "WM_PROTOCOLS"); |
| 1812 | xcb_intern_atom_reply_t *reply = |
| 1813 | xcb_intern_atom_reply(connection, cookie, 0); |
| 1814 | |
| 1815 | xcb_intern_atom_cookie_t cookie2 = |
| 1816 | xcb_intern_atom(connection, 0, 16, "WM_DELETE_WINDOW"); |
Mark Lobodzinski | 085d27a | 2016-05-17 09:34:26 -0600 | [diff] [blame] | 1817 | atom_wm_delete_window = xcb_intern_atom_reply(connection, cookie2, 0); |
Ian Elliott | 2c1daf5 | 2016-05-12 09:41:46 -0600 | [diff] [blame] | 1818 | xcb_change_property(connection, XCB_PROP_MODE_REPLACE, xcb_window, |
| 1819 | (*reply).atom, 4, 32, 1, |
| 1820 | &(*atom_wm_delete_window).atom); |
| 1821 | free(reply); |
| 1822 | |
| 1823 | xcb_map_window(connection, xcb_window); |
| 1824 | |
| 1825 | // Force the x/y coordinates to 100,100 results are identical in consecutive |
| 1826 | // runs |
| 1827 | const uint32_t coords[] = {100, 100}; |
| 1828 | xcb_configure_window(connection, xcb_window, |
| 1829 | XCB_CONFIG_WINDOW_X | XCB_CONFIG_WINDOW_Y, coords); |
| 1830 | |
Ian Elliott | 2c1daf5 | 2016-05-12 09:41:46 -0600 | [diff] [blame] | 1831 | // Finally, try to correctly create a surface: |
| 1832 | xcb_create_info.sType = VK_STRUCTURE_TYPE_XCB_SURFACE_CREATE_INFO_KHR; |
| 1833 | xcb_create_info.pNext = NULL; |
| 1834 | xcb_create_info.flags = 0; |
| 1835 | xcb_create_info.connection = connection; |
| 1836 | xcb_create_info.window = xcb_window; |
| 1837 | err = vkCreateXcbSurfaceKHR(instance(), &xcb_create_info, NULL, &surface); |
| 1838 | pass = (err == VK_SUCCESS); |
| 1839 | ASSERT_TRUE(pass); |
| 1840 | |
Ian Elliott | 2c1daf5 | 2016-05-12 09:41:46 -0600 | [diff] [blame] | 1841 | // Check if surface supports presentation: |
| 1842 | |
| 1843 | // 1st, do so without having queried the queue families: |
| 1844 | VkBool32 supported = false; |
| 1845 | // TODO: Get the following error to come out: |
| 1846 | m_errorMonitor->SetDesiredFailureMsg( |
| 1847 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 1848 | "called before calling the vkGetPhysicalDeviceQueueFamilyProperties " |
| 1849 | "function"); |
| 1850 | err = vkGetPhysicalDeviceSurfaceSupportKHR(gpu(), 0, surface, &supported); |
| 1851 | pass = (err != VK_SUCCESS); |
Mark Lobodzinski | 085d27a | 2016-05-17 09:34:26 -0600 | [diff] [blame] | 1852 | // ASSERT_TRUE(pass); |
| 1853 | // m_errorMonitor->VerifyFound(); |
Ian Elliott | 2c1daf5 | 2016-05-12 09:41:46 -0600 | [diff] [blame] | 1854 | |
| 1855 | // Next, query a queue family index that's too large: |
| 1856 | m_errorMonitor->SetDesiredFailureMsg( |
| 1857 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 1858 | "called with a queueFamilyIndex that is too large"); |
Mark Lobodzinski | 085d27a | 2016-05-17 09:34:26 -0600 | [diff] [blame] | 1859 | err = vkGetPhysicalDeviceSurfaceSupportKHR(gpu(), 100000, surface, |
| 1860 | &supported); |
Ian Elliott | 2c1daf5 | 2016-05-12 09:41:46 -0600 | [diff] [blame] | 1861 | pass = (err != VK_SUCCESS); |
| 1862 | ASSERT_TRUE(pass); |
| 1863 | m_errorMonitor->VerifyFound(); |
| 1864 | |
| 1865 | // Finally, do so correctly: |
Mark Lobodzinski | 085d27a | 2016-05-17 09:34:26 -0600 | [diff] [blame] | 1866 | // FIXME: THIS ISN'T CORRECT--MUST QUERY UNTIL WE FIND A QUEUE FAMILY THAT'S |
| 1867 | // SUPPORTED |
Ian Elliott | 2c1daf5 | 2016-05-12 09:41:46 -0600 | [diff] [blame] | 1868 | err = vkGetPhysicalDeviceSurfaceSupportKHR(gpu(), 0, surface, &supported); |
| 1869 | pass = (err == VK_SUCCESS); |
| 1870 | ASSERT_TRUE(pass); |
| 1871 | |
Ian Elliott | 2c1daf5 | 2016-05-12 09:41:46 -0600 | [diff] [blame] | 1872 | // Before proceeding, try to create a swapchain without having called |
| 1873 | // vkGetPhysicalDeviceSurfaceCapabilitiesKHR(): |
| 1874 | swapchain_create_info.sType = VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR; |
| 1875 | swapchain_create_info.pNext = NULL; |
| 1876 | swapchain_create_info.flags = 0; |
| 1877 | m_errorMonitor->SetDesiredFailureMsg( |
| 1878 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 1879 | "called before calling vkGetPhysicalDeviceSurfaceCapabilitiesKHR()."); |
Mark Lobodzinski | 085d27a | 2016-05-17 09:34:26 -0600 | [diff] [blame] | 1880 | err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, |
| 1881 | &swapchain); |
Ian Elliott | 2c1daf5 | 2016-05-12 09:41:46 -0600 | [diff] [blame] | 1882 | pass = (err != VK_SUCCESS); |
| 1883 | ASSERT_TRUE(pass); |
| 1884 | m_errorMonitor->VerifyFound(); |
| 1885 | |
Ian Elliott | 2c1daf5 | 2016-05-12 09:41:46 -0600 | [diff] [blame] | 1886 | // Get the surface capabilities: |
| 1887 | VkSurfaceCapabilitiesKHR surface_capabilities; |
| 1888 | |
| 1889 | // Do so correctly (only error logged by this entrypoint is if the |
| 1890 | // extension isn't enabled): |
| 1891 | err = vkGetPhysicalDeviceSurfaceCapabilitiesKHR(gpu(), surface, |
| 1892 | &surface_capabilities); |
| 1893 | pass = (err == VK_SUCCESS); |
| 1894 | ASSERT_TRUE(pass); |
| 1895 | |
Ian Elliott | 2c1daf5 | 2016-05-12 09:41:46 -0600 | [diff] [blame] | 1896 | // Get the surface formats: |
| 1897 | uint32_t surface_format_count; |
| 1898 | |
| 1899 | // First, try without a pointer to surface_format_count: |
Mark Lobodzinski | 085d27a | 2016-05-17 09:34:26 -0600 | [diff] [blame] | 1900 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 1901 | "called with NULL pointer"); |
Ian Elliott | 2c1daf5 | 2016-05-12 09:41:46 -0600 | [diff] [blame] | 1902 | vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, NULL, NULL); |
| 1903 | pass = (err == VK_SUCCESS); |
| 1904 | ASSERT_TRUE(pass); |
| 1905 | m_errorMonitor->VerifyFound(); |
| 1906 | |
| 1907 | // Next, call with a non-NULL pSurfaceFormats, even though we haven't |
| 1908 | // correctly done a 1st try (to get the count): |
| 1909 | m_errorMonitor->SetDesiredFailureMsg( |
| 1910 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 1911 | "but no prior positive value has been seen for"); |
| 1912 | surface_format_count = 0; |
| 1913 | vkGetPhysicalDeviceSurfaceFormatsKHR( |
Mark Lobodzinski | 085d27a | 2016-05-17 09:34:26 -0600 | [diff] [blame] | 1914 | gpu(), surface, &surface_format_count, |
| 1915 | (VkSurfaceFormatKHR *)&surface_format_count); |
Ian Elliott | 2c1daf5 | 2016-05-12 09:41:46 -0600 | [diff] [blame] | 1916 | pass = (err == VK_SUCCESS); |
| 1917 | ASSERT_TRUE(pass); |
| 1918 | m_errorMonitor->VerifyFound(); |
| 1919 | |
| 1920 | // 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] | 1921 | vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &surface_format_count, |
| 1922 | NULL); |
Ian Elliott | 2c1daf5 | 2016-05-12 09:41:46 -0600 | [diff] [blame] | 1923 | pass = (err == VK_SUCCESS); |
| 1924 | ASSERT_TRUE(pass); |
| 1925 | |
| 1926 | // Allocate memory for the correct number of VkSurfaceFormatKHR's: |
Mark Lobodzinski | 085d27a | 2016-05-17 09:34:26 -0600 | [diff] [blame] | 1927 | VkSurfaceFormatKHR *surface_formats = (VkSurfaceFormatKHR *)malloc( |
| 1928 | surface_format_count * sizeof(VkSurfaceFormatKHR)); |
Ian Elliott | 2c1daf5 | 2016-05-12 09:41:46 -0600 | [diff] [blame] | 1929 | |
| 1930 | // Next, do a 2nd try with surface_format_count being set too high: |
| 1931 | surface_format_count += 5; |
Mark Lobodzinski | 085d27a | 2016-05-17 09:34:26 -0600 | [diff] [blame] | 1932 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 1933 | "that is greater than the value"); |
| 1934 | vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &surface_format_count, |
Ian Elliott | 2c1daf5 | 2016-05-12 09:41:46 -0600 | [diff] [blame] | 1935 | surface_formats); |
| 1936 | pass = (err == VK_SUCCESS); |
| 1937 | ASSERT_TRUE(pass); |
| 1938 | m_errorMonitor->VerifyFound(); |
| 1939 | |
| 1940 | // Finally, do a correct 1st and 2nd try: |
Mark Lobodzinski | 085d27a | 2016-05-17 09:34:26 -0600 | [diff] [blame] | 1941 | vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &surface_format_count, |
| 1942 | NULL); |
Ian Elliott | 2c1daf5 | 2016-05-12 09:41:46 -0600 | [diff] [blame] | 1943 | pass = (err == VK_SUCCESS); |
| 1944 | ASSERT_TRUE(pass); |
Mark Lobodzinski | 085d27a | 2016-05-17 09:34:26 -0600 | [diff] [blame] | 1945 | vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &surface_format_count, |
Ian Elliott | 2c1daf5 | 2016-05-12 09:41:46 -0600 | [diff] [blame] | 1946 | surface_formats); |
| 1947 | pass = (err == VK_SUCCESS); |
| 1948 | ASSERT_TRUE(pass); |
| 1949 | |
Ian Elliott | 2c1daf5 | 2016-05-12 09:41:46 -0600 | [diff] [blame] | 1950 | // Get the surface present modes: |
| 1951 | uint32_t surface_present_mode_count; |
| 1952 | |
| 1953 | // First, try without a pointer to surface_format_count: |
Mark Lobodzinski | 085d27a | 2016-05-17 09:34:26 -0600 | [diff] [blame] | 1954 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 1955 | "called with NULL pointer"); |
Ian Elliott | 2c1daf5 | 2016-05-12 09:41:46 -0600 | [diff] [blame] | 1956 | vkGetPhysicalDeviceSurfacePresentModesKHR(gpu(), surface, NULL, NULL); |
| 1957 | pass = (err == VK_SUCCESS); |
| 1958 | ASSERT_TRUE(pass); |
| 1959 | m_errorMonitor->VerifyFound(); |
| 1960 | |
| 1961 | // Next, call with a non-NULL VkPresentModeKHR, even though we haven't |
| 1962 | // correctly done a 1st try (to get the count): |
| 1963 | m_errorMonitor->SetDesiredFailureMsg( |
| 1964 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 1965 | "but no prior positive value has been seen for"); |
| 1966 | surface_present_mode_count = 0; |
| 1967 | vkGetPhysicalDeviceSurfacePresentModesKHR( |
Mark Lobodzinski | 085d27a | 2016-05-17 09:34:26 -0600 | [diff] [blame] | 1968 | gpu(), surface, &surface_present_mode_count, |
| 1969 | (VkPresentModeKHR *)&surface_present_mode_count); |
Ian Elliott | 2c1daf5 | 2016-05-12 09:41:46 -0600 | [diff] [blame] | 1970 | pass = (err == VK_SUCCESS); |
| 1971 | ASSERT_TRUE(pass); |
| 1972 | m_errorMonitor->VerifyFound(); |
| 1973 | |
| 1974 | // 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] | 1975 | vkGetPhysicalDeviceSurfacePresentModesKHR( |
| 1976 | gpu(), surface, &surface_present_mode_count, NULL); |
Ian Elliott | 2c1daf5 | 2016-05-12 09:41:46 -0600 | [diff] [blame] | 1977 | pass = (err == VK_SUCCESS); |
| 1978 | ASSERT_TRUE(pass); |
| 1979 | |
| 1980 | // Allocate memory for the correct number of VkSurfaceFormatKHR's: |
Mark Lobodzinski | 085d27a | 2016-05-17 09:34:26 -0600 | [diff] [blame] | 1981 | VkPresentModeKHR *surface_present_modes = (VkPresentModeKHR *)malloc( |
| 1982 | surface_present_mode_count * sizeof(VkPresentModeKHR)); |
Ian Elliott | 2c1daf5 | 2016-05-12 09:41:46 -0600 | [diff] [blame] | 1983 | |
| 1984 | // Next, do a 2nd try with surface_format_count being set too high: |
| 1985 | surface_present_mode_count += 5; |
Mark Lobodzinski | 085d27a | 2016-05-17 09:34:26 -0600 | [diff] [blame] | 1986 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 1987 | "that is greater than the value"); |
| 1988 | vkGetPhysicalDeviceSurfacePresentModesKHR( |
| 1989 | gpu(), surface, &surface_present_mode_count, surface_present_modes); |
Ian Elliott | 2c1daf5 | 2016-05-12 09:41:46 -0600 | [diff] [blame] | 1990 | pass = (err == VK_SUCCESS); |
| 1991 | ASSERT_TRUE(pass); |
| 1992 | m_errorMonitor->VerifyFound(); |
| 1993 | |
| 1994 | // Finally, do a correct 1st and 2nd try: |
Mark Lobodzinski | 085d27a | 2016-05-17 09:34:26 -0600 | [diff] [blame] | 1995 | vkGetPhysicalDeviceSurfacePresentModesKHR( |
| 1996 | gpu(), surface, &surface_present_mode_count, NULL); |
Ian Elliott | 2c1daf5 | 2016-05-12 09:41:46 -0600 | [diff] [blame] | 1997 | pass = (err == VK_SUCCESS); |
| 1998 | ASSERT_TRUE(pass); |
Mark Lobodzinski | 085d27a | 2016-05-17 09:34:26 -0600 | [diff] [blame] | 1999 | vkGetPhysicalDeviceSurfacePresentModesKHR( |
| 2000 | gpu(), surface, &surface_present_mode_count, surface_present_modes); |
Ian Elliott | 2c1daf5 | 2016-05-12 09:41:46 -0600 | [diff] [blame] | 2001 | pass = (err == VK_SUCCESS); |
| 2002 | ASSERT_TRUE(pass); |
| 2003 | |
Ian Elliott | 2c1daf5 | 2016-05-12 09:41:46 -0600 | [diff] [blame] | 2004 | // Create a swapchain: |
| 2005 | |
| 2006 | // First, try without a pointer to swapchain_create_info: |
Mark Lobodzinski | 085d27a | 2016-05-17 09:34:26 -0600 | [diff] [blame] | 2007 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 2008 | "called with NULL pointer"); |
Ian Elliott | 2c1daf5 | 2016-05-12 09:41:46 -0600 | [diff] [blame] | 2009 | err = vkCreateSwapchainKHR(m_device->device(), NULL, NULL, &swapchain); |
| 2010 | pass = (err != VK_SUCCESS); |
| 2011 | ASSERT_TRUE(pass); |
| 2012 | m_errorMonitor->VerifyFound(); |
| 2013 | |
| 2014 | // Next, call with a non-NULL swapchain_create_info, that has the wrong |
| 2015 | // sType: |
| 2016 | swapchain_create_info.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO; |
Mark Lobodzinski | 085d27a | 2016-05-17 09:34:26 -0600 | [diff] [blame] | 2017 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 2018 | "called with the wrong value for"); |
| 2019 | err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, |
| 2020 | &swapchain); |
Ian Elliott | 2c1daf5 | 2016-05-12 09:41:46 -0600 | [diff] [blame] | 2021 | pass = (err != VK_SUCCESS); |
| 2022 | ASSERT_TRUE(pass); |
| 2023 | m_errorMonitor->VerifyFound(); |
| 2024 | |
| 2025 | // Next, call with a NULL swapchain pointer: |
| 2026 | swapchain_create_info.sType = VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR; |
| 2027 | swapchain_create_info.pNext = NULL; |
| 2028 | swapchain_create_info.flags = 0; |
Mark Lobodzinski | 085d27a | 2016-05-17 09:34:26 -0600 | [diff] [blame] | 2029 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 2030 | "called with NULL pointer"); |
| 2031 | err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, |
| 2032 | NULL); |
Ian Elliott | 2c1daf5 | 2016-05-12 09:41:46 -0600 | [diff] [blame] | 2033 | pass = (err != VK_SUCCESS); |
| 2034 | ASSERT_TRUE(pass); |
| 2035 | m_errorMonitor->VerifyFound(); |
| 2036 | |
Mark Lobodzinski | 085d27a | 2016-05-17 09:34:26 -0600 | [diff] [blame] | 2037 | // TODO: Enhance swapchain layer so that |
| 2038 | // swapchain_create_info.queueFamilyIndexCount is checked against something? |
Ian Elliott | 2c1daf5 | 2016-05-12 09:41:46 -0600 | [diff] [blame] | 2039 | |
| 2040 | // Next, call with a queue family index that's too large: |
| 2041 | uint32_t queueFamilyIndex[2] = {100000, 0}; |
| 2042 | swapchain_create_info.imageSharingMode = VK_SHARING_MODE_CONCURRENT; |
| 2043 | swapchain_create_info.queueFamilyIndexCount = 2; |
| 2044 | swapchain_create_info.pQueueFamilyIndices = queueFamilyIndex; |
| 2045 | m_errorMonitor->SetDesiredFailureMsg( |
| 2046 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 2047 | "called with a queueFamilyIndex that is too large"); |
Mark Lobodzinski | 085d27a | 2016-05-17 09:34:26 -0600 | [diff] [blame] | 2048 | err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, |
| 2049 | &swapchain); |
Ian Elliott | 2c1daf5 | 2016-05-12 09:41:46 -0600 | [diff] [blame] | 2050 | pass = (err != VK_SUCCESS); |
| 2051 | ASSERT_TRUE(pass); |
| 2052 | m_errorMonitor->VerifyFound(); |
| 2053 | |
| 2054 | // Next, call a queueFamilyIndexCount that's too small for CONCURRENT: |
| 2055 | swapchain_create_info.imageSharingMode = VK_SHARING_MODE_CONCURRENT; |
| 2056 | swapchain_create_info.queueFamilyIndexCount = 1; |
| 2057 | m_errorMonitor->SetDesiredFailureMsg( |
| 2058 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 2059 | "but with a bad value(s) for pCreateInfo->queueFamilyIndexCount or " |
| 2060 | "pCreateInfo->pQueueFamilyIndices)."); |
Mark Lobodzinski | 085d27a | 2016-05-17 09:34:26 -0600 | [diff] [blame] | 2061 | err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, |
| 2062 | &swapchain); |
Ian Elliott | 2c1daf5 | 2016-05-12 09:41:46 -0600 | [diff] [blame] | 2063 | pass = (err != VK_SUCCESS); |
| 2064 | ASSERT_TRUE(pass); |
| 2065 | m_errorMonitor->VerifyFound(); |
| 2066 | |
| 2067 | // Next, call with an invalid imageSharingMode: |
| 2068 | swapchain_create_info.imageSharingMode = VK_SHARING_MODE_MAX_ENUM; |
| 2069 | swapchain_create_info.queueFamilyIndexCount = 1; |
| 2070 | m_errorMonitor->SetDesiredFailureMsg( |
| 2071 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 2072 | "called with a non-supported pCreateInfo->imageSharingMode (i.e."); |
Mark Lobodzinski | 085d27a | 2016-05-17 09:34:26 -0600 | [diff] [blame] | 2073 | err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, |
| 2074 | &swapchain); |
Ian Elliott | 2c1daf5 | 2016-05-12 09:41:46 -0600 | [diff] [blame] | 2075 | pass = (err != VK_SUCCESS); |
| 2076 | ASSERT_TRUE(pass); |
| 2077 | m_errorMonitor->VerifyFound(); |
| 2078 | // Fix for the future: |
Mark Lobodzinski | 085d27a | 2016-05-17 09:34:26 -0600 | [diff] [blame] | 2079 | // FIXME: THIS ISN'T CORRECT--MUST QUERY UNTIL WE FIND A QUEUE FAMILY THAT'S |
| 2080 | // SUPPORTED |
Ian Elliott | 2c1daf5 | 2016-05-12 09:41:46 -0600 | [diff] [blame] | 2081 | swapchain_create_info.queueFamilyIndexCount = 0; |
| 2082 | queueFamilyIndex[0] = 0; |
| 2083 | swapchain_create_info.imageSharingMode = VK_SHARING_MODE_EXCLUSIVE; |
| 2084 | |
Mark Lobodzinski | 085d27a | 2016-05-17 09:34:26 -0600 | [diff] [blame] | 2085 | // TODO: CONTINUE TESTING VALIDATION OF vkCreateSwapchainKHR() ... |
Ian Elliott | 2c1daf5 | 2016-05-12 09:41:46 -0600 | [diff] [blame] | 2086 | // Get the images from a swapchain: |
Ian Elliott | 2c1daf5 | 2016-05-12 09:41:46 -0600 | [diff] [blame] | 2087 | // Acquire an image from a swapchain: |
Ian Elliott | 2c1daf5 | 2016-05-12 09:41:46 -0600 | [diff] [blame] | 2088 | // Present an image to a swapchain: |
Ian Elliott | 2c1daf5 | 2016-05-12 09:41:46 -0600 | [diff] [blame] | 2089 | // Destroy the swapchain: |
| 2090 | |
Mark Lobodzinski | 085d27a | 2016-05-17 09:34:26 -0600 | [diff] [blame] | 2091 | // TODOs: |
| 2092 | // |
| 2093 | // - Try destroying the device without first destroying the swapchain |
| 2094 | // |
| 2095 | // - Try destroying the device without first destroying the surface |
| 2096 | // |
| 2097 | // - Try destroying the surface without first destroying the swapchain |
Ian Elliott | 2c1daf5 | 2016-05-12 09:41:46 -0600 | [diff] [blame] | 2098 | |
| 2099 | // Destroy the surface: |
| 2100 | vkDestroySurfaceKHR(instance(), surface, NULL); |
| 2101 | |
Ian Elliott | 2c1daf5 | 2016-05-12 09:41:46 -0600 | [diff] [blame] | 2102 | // Tear down the window: |
| 2103 | xcb_destroy_window(connection, xcb_window); |
| 2104 | xcb_disconnect(connection); |
| 2105 | |
| 2106 | #else // VK_USE_PLATFORM_XCB_KHR |
Mark Lobodzinski | 085d27a | 2016-05-17 09:34:26 -0600 | [diff] [blame] | 2107 | return; |
Ian Elliott | 2c1daf5 | 2016-05-12 09:41:46 -0600 | [diff] [blame] | 2108 | #endif // VK_USE_PLATFORM_XCB_KHR |
| 2109 | } |
| 2110 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 2111 | TEST_F(VkLayerTest, MapMemWithoutHostVisibleBit) { |
| 2112 | VkResult err; |
| 2113 | bool pass; |
Mark Lobodzinski | 3780e14 | 2015-05-14 15:08:13 -0500 | [diff] [blame] | 2114 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 2115 | m_errorMonitor->SetDesiredFailureMsg( |
| 2116 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 2117 | "Mapping Memory without VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT"); |
| 2118 | |
Mark Lobodzinski | 3780e14 | 2015-05-14 15:08:13 -0500 | [diff] [blame] | 2119 | ASSERT_NO_FATAL_FAILURE(InitState()); |
Mark Lobodzinski | 3780e14 | 2015-05-14 15:08:13 -0500 | [diff] [blame] | 2120 | |
| 2121 | // 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] | 2122 | VkImage image; |
| 2123 | VkDeviceMemory mem; |
| 2124 | VkMemoryRequirements mem_reqs; |
Mark Lobodzinski | 3780e14 | 2015-05-14 15:08:13 -0500 | [diff] [blame] | 2125 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 2126 | const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM; |
| 2127 | const int32_t tex_width = 32; |
| 2128 | const int32_t tex_height = 32; |
Mark Lobodzinski | 3780e14 | 2015-05-14 15:08:13 -0500 | [diff] [blame] | 2129 | |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 2130 | VkImageCreateInfo image_create_info = {}; |
| 2131 | image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 2132 | image_create_info.pNext = NULL; |
| 2133 | image_create_info.imageType = VK_IMAGE_TYPE_2D; |
| 2134 | image_create_info.format = tex_format; |
| 2135 | image_create_info.extent.width = tex_width; |
| 2136 | image_create_info.extent.height = tex_height; |
| 2137 | image_create_info.extent.depth = 1; |
| 2138 | image_create_info.mipLevels = 1; |
| 2139 | image_create_info.arrayLayers = 1; |
| 2140 | image_create_info.samples = VK_SAMPLE_COUNT_1_BIT; |
| 2141 | image_create_info.tiling = VK_IMAGE_TILING_LINEAR; |
| 2142 | image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT; |
| 2143 | image_create_info.flags = 0; |
Mark Lobodzinski | 5fcc421 | 2015-09-14 17:43:42 -0600 | [diff] [blame] | 2144 | |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 2145 | VkMemoryAllocateInfo mem_alloc = {}; |
Chia-I Wu | 00ce540 | 2015-11-10 16:21:09 +0800 | [diff] [blame] | 2146 | mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 2147 | mem_alloc.pNext = NULL; |
| 2148 | mem_alloc.allocationSize = 0; |
| 2149 | // Introduce failure, do NOT set memProps to |
| 2150 | // VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT |
| 2151 | mem_alloc.memoryTypeIndex = 1; |
Mark Lobodzinski | 3780e14 | 2015-05-14 15:08:13 -0500 | [diff] [blame] | 2152 | |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 2153 | err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image); |
Mark Lobodzinski | 3780e14 | 2015-05-14 15:08:13 -0500 | [diff] [blame] | 2154 | ASSERT_VK_SUCCESS(err); |
| 2155 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 2156 | vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs); |
Mark Lobodzinski | 3780e14 | 2015-05-14 15:08:13 -0500 | [diff] [blame] | 2157 | |
Mark Lobodzinski | 2306535 | 2015-05-29 09:32:35 -0500 | [diff] [blame] | 2158 | mem_alloc.allocationSize = mem_reqs.size; |
Mark Lobodzinski | 3780e14 | 2015-05-14 15:08:13 -0500 | [diff] [blame] | 2159 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 2160 | pass = |
| 2161 | m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0, |
| 2162 | VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT); |
| 2163 | if (!pass) { // If we can't find any unmappable memory this test doesn't |
| 2164 | // make sense |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 2165 | vkDestroyImage(m_device->device(), image, NULL); |
Tony Barbour | 02fdc7d | 2015-08-04 16:13:01 -0600 | [diff] [blame] | 2166 | return; |
Mike Stroyan | d1c84a5 | 2015-08-18 14:40:24 -0600 | [diff] [blame] | 2167 | } |
Mike Stroyan | 713b2d7 | 2015-08-04 10:49:29 -0600 | [diff] [blame] | 2168 | |
Mark Lobodzinski | 3780e14 | 2015-05-14 15:08:13 -0500 | [diff] [blame] | 2169 | // allocate memory |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 2170 | err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem); |
Mark Lobodzinski | 3780e14 | 2015-05-14 15:08:13 -0500 | [diff] [blame] | 2171 | ASSERT_VK_SUCCESS(err); |
| 2172 | |
| 2173 | // Try to bind free memory that has been freed |
Tony Barbour | 67e9915 | 2015-07-10 14:10:27 -0600 | [diff] [blame] | 2174 | err = vkBindImageMemory(m_device->device(), image, mem, 0); |
Mark Lobodzinski | 3780e14 | 2015-05-14 15:08:13 -0500 | [diff] [blame] | 2175 | ASSERT_VK_SUCCESS(err); |
| 2176 | |
| 2177 | // Map memory as if to initialize the image |
| 2178 | void *mappedAddress = NULL; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 2179 | err = vkMapMemory(m_device->device(), mem, 0, VK_WHOLE_SIZE, 0, |
| 2180 | &mappedAddress); |
Mark Lobodzinski | 3780e14 | 2015-05-14 15:08:13 -0500 | [diff] [blame] | 2181 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 2182 | m_errorMonitor->VerifyFound(); |
Mike Stroyan | d1c84a5 | 2015-08-18 14:40:24 -0600 | [diff] [blame] | 2183 | |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 2184 | vkDestroyImage(m_device->device(), image, NULL); |
Tony Barbour | df4c004 | 2016-06-01 15:55:43 -0600 | [diff] [blame] | 2185 | vkFreeMemory(m_device->device(), mem, NULL); |
Mark Lobodzinski | 3780e14 | 2015-05-14 15:08:13 -0500 | [diff] [blame] | 2186 | } |
| 2187 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 2188 | TEST_F(VkLayerTest, RebindMemory) { |
| 2189 | VkResult err; |
| 2190 | bool pass; |
Mark Lobodzinski | 944aab1 | 2015-06-05 13:59:04 -0500 | [diff] [blame] | 2191 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 2192 | m_errorMonitor->SetDesiredFailureMsg( |
| 2193 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 2194 | "which has already been bound to mem object"); |
| 2195 | |
Mark Lobodzinski | 944aab1 | 2015-06-05 13:59:04 -0500 | [diff] [blame] | 2196 | ASSERT_NO_FATAL_FAILURE(InitState()); |
Mark Lobodzinski | 944aab1 | 2015-06-05 13:59:04 -0500 | [diff] [blame] | 2197 | |
| 2198 | // 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] | 2199 | VkImage image; |
| 2200 | VkDeviceMemory mem1; |
| 2201 | VkDeviceMemory mem2; |
| 2202 | VkMemoryRequirements mem_reqs; |
Mark Lobodzinski | 944aab1 | 2015-06-05 13:59:04 -0500 | [diff] [blame] | 2203 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 2204 | const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM; |
| 2205 | const int32_t tex_width = 32; |
| 2206 | const int32_t tex_height = 32; |
Mark Lobodzinski | 944aab1 | 2015-06-05 13:59:04 -0500 | [diff] [blame] | 2207 | |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 2208 | VkImageCreateInfo image_create_info = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 2209 | image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO; |
| 2210 | image_create_info.pNext = NULL; |
| 2211 | image_create_info.imageType = VK_IMAGE_TYPE_2D; |
| 2212 | image_create_info.format = tex_format; |
| 2213 | image_create_info.extent.width = tex_width; |
| 2214 | image_create_info.extent.height = tex_height; |
| 2215 | image_create_info.extent.depth = 1; |
| 2216 | image_create_info.mipLevels = 1; |
| 2217 | image_create_info.arrayLayers = 1; |
| 2218 | image_create_info.samples = VK_SAMPLE_COUNT_1_BIT; |
| 2219 | image_create_info.tiling = VK_IMAGE_TILING_LINEAR; |
| 2220 | image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT; |
| 2221 | image_create_info.flags = 0; |
Mark Lobodzinski | 944aab1 | 2015-06-05 13:59:04 -0500 | [diff] [blame] | 2222 | |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 2223 | VkMemoryAllocateInfo mem_alloc = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 2224 | mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO; |
| 2225 | mem_alloc.pNext = NULL; |
| 2226 | mem_alloc.allocationSize = 0; |
| 2227 | mem_alloc.memoryTypeIndex = 0; |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 2228 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 2229 | // Introduce failure, do NOT set memProps to |
| 2230 | // VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 2231 | mem_alloc.memoryTypeIndex = 1; |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 2232 | err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image); |
Mark Lobodzinski | 944aab1 | 2015-06-05 13:59:04 -0500 | [diff] [blame] | 2233 | ASSERT_VK_SUCCESS(err); |
| 2234 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 2235 | vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs); |
Mark Lobodzinski | 944aab1 | 2015-06-05 13:59:04 -0500 | [diff] [blame] | 2236 | |
| 2237 | mem_alloc.allocationSize = mem_reqs.size; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 2238 | pass = |
| 2239 | m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0); |
Courtney Goeltzenleuchter | 1d2f0dd | 2015-10-22 11:03:31 -0600 | [diff] [blame] | 2240 | ASSERT_TRUE(pass); |
Mark Lobodzinski | 944aab1 | 2015-06-05 13:59:04 -0500 | [diff] [blame] | 2241 | |
| 2242 | // allocate 2 memory objects |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 2243 | err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem1); |
Mark Lobodzinski | 944aab1 | 2015-06-05 13:59:04 -0500 | [diff] [blame] | 2244 | ASSERT_VK_SUCCESS(err); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 2245 | err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem2); |
Mark Lobodzinski | 944aab1 | 2015-06-05 13:59:04 -0500 | [diff] [blame] | 2246 | ASSERT_VK_SUCCESS(err); |
| 2247 | |
| 2248 | // Bind first memory object to Image object |
Tony Barbour | 67e9915 | 2015-07-10 14:10:27 -0600 | [diff] [blame] | 2249 | err = vkBindImageMemory(m_device->device(), image, mem1, 0); |
Mark Lobodzinski | 944aab1 | 2015-06-05 13:59:04 -0500 | [diff] [blame] | 2250 | ASSERT_VK_SUCCESS(err); |
| 2251 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 2252 | // Introduce validation failure, try to bind a different memory object to |
| 2253 | // the same image object |
Tony Barbour | 67e9915 | 2015-07-10 14:10:27 -0600 | [diff] [blame] | 2254 | err = vkBindImageMemory(m_device->device(), image, mem2, 0); |
Mark Lobodzinski | 944aab1 | 2015-06-05 13:59:04 -0500 | [diff] [blame] | 2255 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 2256 | m_errorMonitor->VerifyFound(); |
Mike Stroyan | d1c84a5 | 2015-08-18 14:40:24 -0600 | [diff] [blame] | 2257 | |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 2258 | vkDestroyImage(m_device->device(), image, NULL); |
| 2259 | vkFreeMemory(m_device->device(), mem1, NULL); |
| 2260 | vkFreeMemory(m_device->device(), mem2, NULL); |
Mark Lobodzinski | 944aab1 | 2015-06-05 13:59:04 -0500 | [diff] [blame] | 2261 | } |
Mark Lobodzinski | 3780e14 | 2015-05-14 15:08:13 -0500 | [diff] [blame] | 2262 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 2263 | TEST_F(VkLayerTest, SubmitSignaledFence) { |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 2264 | vk_testing::Fence testFence; |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 2265 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 2266 | m_errorMonitor->SetDesiredFailureMsg( |
| 2267 | VK_DEBUG_REPORT_ERROR_BIT_EXT, "submitted in SIGNALED state. Fences " |
| 2268 | "must be reset before being submitted"); |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 2269 | |
| 2270 | VkFenceCreateInfo fenceInfo = {}; |
Tony Barbour | 0b4d956 | 2015-04-09 10:48:04 -0600 | [diff] [blame] | 2271 | fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO; |
| 2272 | fenceInfo.pNext = NULL; |
| 2273 | fenceInfo.flags = VK_FENCE_CREATE_SIGNALED_BIT; |
Tony Barbour | 300a608 | 2015-04-07 13:44:53 -0600 | [diff] [blame] | 2274 | |
Tony Barbour | 300a608 | 2015-04-07 13:44:53 -0600 | [diff] [blame] | 2275 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 2276 | ASSERT_NO_FATAL_FAILURE(InitViewport()); |
| 2277 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 2278 | |
Tony Barbour | fe3351b | 2015-07-28 10:17:20 -0600 | [diff] [blame] | 2279 | BeginCommandBuffer(); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 2280 | m_commandBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color, |
| 2281 | m_stencil_clear_color, NULL); |
Tony Barbour | fe3351b | 2015-07-28 10:17:20 -0600 | [diff] [blame] | 2282 | EndCommandBuffer(); |
Tony Barbour | 300a608 | 2015-04-07 13:44:53 -0600 | [diff] [blame] | 2283 | |
| 2284 | testFence.init(*m_device, fenceInfo); |
Mark Lobodzinski | 5fcc421 | 2015-09-14 17:43:42 -0600 | [diff] [blame] | 2285 | |
Courtney Goeltzenleuchter | 806c700 | 2015-10-27 11:22:14 -0600 | [diff] [blame] | 2286 | VkSubmitInfo submit_info; |
Chia-I Wu | f9be13c | 2015-10-26 20:37:06 +0800 | [diff] [blame] | 2287 | submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO; |
| 2288 | submit_info.pNext = NULL; |
Chia-I Wu | d50a7d7 | 2015-10-26 20:48:51 +0800 | [diff] [blame] | 2289 | submit_info.waitSemaphoreCount = 0; |
Courtney Goeltzenleuchter | 806c700 | 2015-10-27 11:22:14 -0600 | [diff] [blame] | 2290 | submit_info.pWaitSemaphores = NULL; |
Jon Ashburn | 7f9716c | 2015-12-30 16:42:50 -0700 | [diff] [blame] | 2291 | submit_info.pWaitDstStageMask = NULL; |
Chia-I Wu | d50a7d7 | 2015-10-26 20:48:51 +0800 | [diff] [blame] | 2292 | submit_info.commandBufferCount = 1; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 2293 | submit_info.pCommandBuffers = &m_commandBuffer->handle(); |
Chia-I Wu | d50a7d7 | 2015-10-26 20:48:51 +0800 | [diff] [blame] | 2294 | submit_info.signalSemaphoreCount = 0; |
Courtney Goeltzenleuchter | 806c700 | 2015-10-27 11:22:14 -0600 | [diff] [blame] | 2295 | submit_info.pSignalSemaphores = NULL; |
Courtney Goeltzenleuchter | 646b907 | 2015-10-20 18:04:07 -0600 | [diff] [blame] | 2296 | |
| 2297 | vkQueueSubmit(m_device->m_queue, 1, &submit_info, testFence.handle()); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 2298 | vkQueueWaitIdle(m_device->m_queue); |
Mark Lobodzinski | 5fcc421 | 2015-09-14 17:43:42 -0600 | [diff] [blame] | 2299 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 2300 | m_errorMonitor->VerifyFound(); |
Tony Barbour | 0b4d956 | 2015-04-09 10:48:04 -0600 | [diff] [blame] | 2301 | } |
Tobin Ehlis | aff7ae9 | 2016-04-18 15:45:20 -0600 | [diff] [blame] | 2302 | // This is a positive test. We used to expect error in this case but spec now |
| 2303 | // allows it |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 2304 | TEST_F(VkLayerTest, ResetUnsignaledFence) { |
Tobin Ehlis | aff7ae9 | 2016-04-18 15:45:20 -0600 | [diff] [blame] | 2305 | m_errorMonitor->ExpectSuccess(); |
Tony Barbour | 0b4d956 | 2015-04-09 10:48:04 -0600 | [diff] [blame] | 2306 | vk_testing::Fence testFence; |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 2307 | VkFenceCreateInfo fenceInfo = {}; |
Tony Barbour | 0b4d956 | 2015-04-09 10:48:04 -0600 | [diff] [blame] | 2308 | fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO; |
| 2309 | fenceInfo.pNext = NULL; |
| 2310 | |
Tony Barbour | 0b4d956 | 2015-04-09 10:48:04 -0600 | [diff] [blame] | 2311 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 2312 | testFence.init(*m_device, fenceInfo); |
Chia-I Wu | d9e8e82 | 2015-07-03 11:45:55 +0800 | [diff] [blame] | 2313 | VkFence fences[1] = {testFence.handle()}; |
Tobin Ehlis | aff7ae9 | 2016-04-18 15:45:20 -0600 | [diff] [blame] | 2314 | VkResult result = vkResetFences(m_device->device(), 1, fences); |
| 2315 | ASSERT_VK_SUCCESS(result); |
Tony Barbour | 300a608 | 2015-04-07 13:44:53 -0600 | [diff] [blame] | 2316 | |
Tobin Ehlis | aff7ae9 | 2016-04-18 15:45:20 -0600 | [diff] [blame] | 2317 | m_errorMonitor->VerifyNotFound(); |
Tony Barbour | 300a608 | 2015-04-07 13:44:53 -0600 | [diff] [blame] | 2318 | } |
Tobin Ehlis | 41376e1 | 2015-07-03 08:45:14 -0600 | [diff] [blame] | 2319 | |
Chris Forbes | e70b7d3 | 2016-06-15 15:49:12 +1200 | [diff] [blame] | 2320 | #if 0 |
| 2321 | TEST_F(VkLayerTest, LongFenceChain) |
| 2322 | { |
| 2323 | m_errorMonitor->ExpectSuccess(); |
| 2324 | |
| 2325 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 2326 | VkResult err; |
| 2327 | |
| 2328 | std::vector<VkFence> fences; |
| 2329 | |
| 2330 | const int chainLength = 32768; |
| 2331 | |
| 2332 | for (int i = 0; i < chainLength; i++) { |
| 2333 | VkFenceCreateInfo fci = { VK_STRUCTURE_TYPE_FENCE_CREATE_INFO, nullptr, 0 }; |
| 2334 | VkFence fence; |
| 2335 | err = vkCreateFence(m_device->device(), &fci, nullptr, &fence); |
| 2336 | ASSERT_VK_SUCCESS(err); |
| 2337 | |
| 2338 | fences.push_back(fence); |
| 2339 | |
| 2340 | VkSubmitInfo si = { VK_STRUCTURE_TYPE_SUBMIT_INFO, nullptr, 0, nullptr, nullptr, |
| 2341 | 0, nullptr, 0, nullptr }; |
| 2342 | err = vkQueueSubmit(m_device->m_queue, 1, &si, fence); |
| 2343 | ASSERT_VK_SUCCESS(err); |
| 2344 | |
| 2345 | } |
| 2346 | |
| 2347 | // BOOM, stack overflow. |
| 2348 | vkWaitForFences(m_device->device(), 1, &fences.back(), VK_TRUE, UINT64_MAX); |
| 2349 | |
| 2350 | for (auto fence : fences) |
| 2351 | vkDestroyFence(m_device->device(), fence, nullptr); |
| 2352 | |
| 2353 | m_errorMonitor->VerifyNotFound(); |
| 2354 | } |
| 2355 | #endif |
| 2356 | |
Chris Forbes | 18127d1 | 2016-06-08 16:52:28 +1200 | [diff] [blame] | 2357 | TEST_F(VkLayerTest, CommandBufferSimultaneousUseSync) |
| 2358 | { |
| 2359 | m_errorMonitor->ExpectSuccess(); |
| 2360 | |
| 2361 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 2362 | VkResult err; |
| 2363 | |
| 2364 | // Record (empty!) command buffer that can be submitted multiple times |
| 2365 | // simultaneously. |
| 2366 | VkCommandBufferBeginInfo cbbi = { |
| 2367 | VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO, nullptr, |
| 2368 | VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT, nullptr |
| 2369 | }; |
| 2370 | m_commandBuffer->BeginCommandBuffer(&cbbi); |
| 2371 | m_commandBuffer->EndCommandBuffer(); |
| 2372 | |
| 2373 | VkFenceCreateInfo fci = { VK_STRUCTURE_TYPE_FENCE_CREATE_INFO, nullptr, 0 }; |
| 2374 | VkFence fence; |
| 2375 | err = vkCreateFence(m_device->device(), &fci, nullptr, &fence); |
| 2376 | ASSERT_VK_SUCCESS(err); |
| 2377 | |
| 2378 | VkSemaphoreCreateInfo sci = { VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO, nullptr, 0 }; |
| 2379 | VkSemaphore s1, s2; |
| 2380 | err = vkCreateSemaphore(m_device->device(), &sci, nullptr, &s1); |
| 2381 | ASSERT_VK_SUCCESS(err); |
| 2382 | err = vkCreateSemaphore(m_device->device(), &sci, nullptr, &s2); |
| 2383 | ASSERT_VK_SUCCESS(err); |
| 2384 | |
| 2385 | // Submit CB once signaling s1, with fence so we can roll forward to its retirement. |
| 2386 | VkSubmitInfo si = { VK_STRUCTURE_TYPE_SUBMIT_INFO, nullptr, 0, nullptr, nullptr, |
| 2387 | 1, &m_commandBuffer->handle(), 1, &s1 }; |
| 2388 | err = vkQueueSubmit(m_device->m_queue, 1, &si, fence); |
| 2389 | ASSERT_VK_SUCCESS(err); |
| 2390 | |
| 2391 | // Submit CB again, signaling s2. |
| 2392 | si.pSignalSemaphores = &s2; |
| 2393 | err = vkQueueSubmit(m_device->m_queue, 1, &si, VK_NULL_HANDLE); |
| 2394 | ASSERT_VK_SUCCESS(err); |
| 2395 | |
| 2396 | // Wait for fence. |
| 2397 | err = vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX); |
| 2398 | ASSERT_VK_SUCCESS(err); |
| 2399 | |
| 2400 | // CB is still in flight from second submission, but semaphore s1 is no |
| 2401 | // longer in flight. delete it. |
| 2402 | vkDestroySemaphore(m_device->device(), s1, nullptr); |
| 2403 | |
| 2404 | m_errorMonitor->VerifyNotFound(); |
| 2405 | |
| 2406 | // Force device idle and clean up remaining objects |
| 2407 | vkDeviceWaitIdle(m_device->device()); |
| 2408 | vkDestroySemaphore(m_device->device(), s2, nullptr); |
| 2409 | vkDestroyFence(m_device->device(), fence, nullptr); |
| 2410 | } |
| 2411 | |
Chris Forbes | 4e44c91 | 2016-06-16 10:20:00 +1200 | [diff] [blame] | 2412 | TEST_F(VkLayerTest, FenceCreateSignaledWaitHandling) |
| 2413 | { |
| 2414 | m_errorMonitor->ExpectSuccess(); |
| 2415 | |
| 2416 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 2417 | VkResult err; |
| 2418 | |
| 2419 | // A fence created signaled |
| 2420 | VkFenceCreateInfo fci1 = { VK_STRUCTURE_TYPE_FENCE_CREATE_INFO, nullptr, VK_FENCE_CREATE_SIGNALED_BIT }; |
| 2421 | VkFence f1; |
| 2422 | err = vkCreateFence(m_device->device(), &fci1, nullptr, &f1); |
| 2423 | ASSERT_VK_SUCCESS(err); |
| 2424 | |
| 2425 | // A fence created not |
| 2426 | VkFenceCreateInfo fci2 = { VK_STRUCTURE_TYPE_FENCE_CREATE_INFO, nullptr, 0 }; |
| 2427 | VkFence f2; |
| 2428 | err = vkCreateFence(m_device->device(), &fci2, nullptr, &f2); |
| 2429 | ASSERT_VK_SUCCESS(err); |
| 2430 | |
| 2431 | // Submit the unsignaled fence |
| 2432 | VkSubmitInfo si = { VK_STRUCTURE_TYPE_SUBMIT_INFO, nullptr, 0, nullptr, nullptr, |
| 2433 | 0, nullptr, 0, nullptr }; |
| 2434 | err = vkQueueSubmit(m_device->m_queue, 1, &si, f2); |
| 2435 | |
| 2436 | // Wait on both fences, with signaled first. |
| 2437 | VkFence fences[] = { f1, f2 }; |
| 2438 | vkWaitForFences(m_device->device(), 2, fences, VK_TRUE, UINT64_MAX); |
| 2439 | |
| 2440 | // Should have both retired! |
| 2441 | vkDestroyFence(m_device->device(), f1, nullptr); |
| 2442 | vkDestroyFence(m_device->device(), f2, nullptr); |
| 2443 | |
| 2444 | m_errorMonitor->VerifyNotFound(); |
| 2445 | } |
| 2446 | |
Tobin Ehlis | 41376e1 | 2015-07-03 08:45:14 -0600 | [diff] [blame] | 2447 | TEST_F(VkLayerTest, InvalidUsageBits) |
| 2448 | { |
Tony Barbour | f92621a | 2016-05-02 14:28:12 -0600 | [diff] [blame] | 2449 | TEST_DESCRIPTION( |
Karl Schultz | b5bc11e | 2016-05-04 08:36:08 -0600 | [diff] [blame] | 2450 | "Specify wrong usage for image then create conflicting view of image " |
Tony Barbour | f92621a | 2016-05-02 14:28:12 -0600 | [diff] [blame] | 2451 | "Initialize buffer with wrong usage then perform copy expecting errors " |
| 2452 | "from both the image and the buffer (2 calls)"); |
Courtney Goeltzenleuchter | 7415d5a | 2015-12-09 15:48:16 -0700 | [diff] [blame] | 2453 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 2454 | "Invalid usage flag for image "); |
Tobin Ehlis | 41376e1 | 2015-07-03 08:45:14 -0600 | [diff] [blame] | 2455 | |
| 2456 | ASSERT_NO_FATAL_FAILURE(InitState()); |
Tony Barbour | f92621a | 2016-05-02 14:28:12 -0600 | [diff] [blame] | 2457 | VkImageObj image(m_device); |
| 2458 | // Initialize image with USAGE_INPUT_ATTACHMENT |
Tobin Ehlis | 8b313c0 | 2016-05-25 15:01:52 -0600 | [diff] [blame] | 2459 | image.init(128, 128, VK_FORMAT_D24_UNORM_S8_UINT, |
Karl Schultz | b5bc11e | 2016-05-04 08:36:08 -0600 | [diff] [blame] | 2460 | VK_IMAGE_USAGE_INPUT_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0); |
| 2461 | ASSERT_TRUE(image.initialized()); |
Tobin Ehlis | 41376e1 | 2015-07-03 08:45:14 -0600 | [diff] [blame] | 2462 | |
Tony Barbour | f92621a | 2016-05-02 14:28:12 -0600 | [diff] [blame] | 2463 | VkImageView dsv; |
| 2464 | VkImageViewCreateInfo dsvci = {}; |
| 2465 | dsvci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO; |
| 2466 | dsvci.image = image.handle(); |
| 2467 | dsvci.viewType = VK_IMAGE_VIEW_TYPE_2D; |
| 2468 | dsvci.format = VK_FORMAT_D32_SFLOAT_S8_UINT; |
| 2469 | dsvci.subresourceRange.layerCount = 1; |
| 2470 | dsvci.subresourceRange.baseMipLevel = 0; |
| 2471 | dsvci.subresourceRange.levelCount = 1; |
| 2472 | dsvci.subresourceRange.aspectMask = |
| 2473 | VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT; |
Tobin Ehlis | 41376e1 | 2015-07-03 08:45:14 -0600 | [diff] [blame] | 2474 | |
Tony Barbour | f92621a | 2016-05-02 14:28:12 -0600 | [diff] [blame] | 2475 | // Create a view with depth / stencil aspect for image with different usage |
| 2476 | vkCreateImageView(m_device->device(), &dsvci, NULL, &dsv); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 2477 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 2478 | m_errorMonitor->VerifyFound(); |
Tony Barbour | f92621a | 2016-05-02 14:28:12 -0600 | [diff] [blame] | 2479 | |
| 2480 | // Initialize buffer with TRANSFER_DST usage |
| 2481 | vk_testing::Buffer buffer; |
| 2482 | VkMemoryPropertyFlags reqs = 0; |
| 2483 | buffer.init_as_dst(*m_device, 128 * 128, reqs); |
| 2484 | VkBufferImageCopy region = {}; |
| 2485 | region.bufferRowLength = 128; |
| 2486 | region.bufferImageHeight = 128; |
| 2487 | region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; |
| 2488 | region.imageSubresource.layerCount = 1; |
| 2489 | region.imageExtent.height = 16; |
| 2490 | region.imageExtent.width = 16; |
| 2491 | region.imageExtent.depth = 1; |
| 2492 | |
| 2493 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 2494 | "Invalid usage flag for buffer "); |
| 2495 | // Buffer usage not set to TRANSFER_SRC and image usage not set to |
| 2496 | // TRANSFER_DST |
| 2497 | BeginCommandBuffer(); |
| 2498 | vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), |
| 2499 | image.handle(), VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, |
| 2500 | 1, ®ion); |
| 2501 | m_errorMonitor->VerifyFound(); |
| 2502 | |
| 2503 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 2504 | "Invalid usage flag for image "); |
| 2505 | vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), |
| 2506 | image.handle(), VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, |
| 2507 | 1, ®ion); |
| 2508 | m_errorMonitor->VerifyFound(); |
Tobin Ehlis | 41376e1 | 2015-07-03 08:45:14 -0600 | [diff] [blame] | 2509 | } |
Mark Lobodzinski | 209b529 | 2015-09-17 09:44:05 -0600 | [diff] [blame] | 2510 | #endif // MEM_TRACKER_TESTS |
| 2511 | |
Tobin Ehlis | 4bf96d1 | 2015-06-25 11:58:41 -0600 | [diff] [blame] | 2512 | #if OBJ_TRACKER_TESTS |
Mark Lobodzinski | fc5cc66 | 2016-05-02 17:17:41 -0600 | [diff] [blame] | 2513 | |
| 2514 | TEST_F(VkLayerTest, LeakAnObject) { |
| 2515 | VkResult err; |
| 2516 | |
| 2517 | TEST_DESCRIPTION( |
| 2518 | "Create a fence and destroy its device without first destroying the fence."); |
| 2519 | |
| 2520 | // Note that we have to create a new device since destroying the |
| 2521 | // framework's device causes Teardown() to fail and just calling Teardown |
| 2522 | // will destroy the errorMonitor. |
| 2523 | |
| 2524 | m_errorMonitor->SetDesiredFailureMsg( |
| 2525 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 2526 | "OBJ ERROR : VK_DEBUG_REPORT_OBJECT_TYPE_FENCE_EXT object"); |
| 2527 | |
| 2528 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 2529 | |
| 2530 | const std::vector<VkQueueFamilyProperties> queue_props = |
| 2531 | m_device->queue_props; |
| 2532 | std::vector<VkDeviceQueueCreateInfo> queue_info; |
| 2533 | queue_info.reserve(queue_props.size()); |
| 2534 | std::vector<std::vector<float>> queue_priorities; |
| 2535 | for (uint32_t i = 0; i < (uint32_t)queue_props.size(); i++) { |
| 2536 | VkDeviceQueueCreateInfo qi = {}; |
| 2537 | qi.sType = VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO; |
| 2538 | qi.pNext = NULL; |
| 2539 | qi.queueFamilyIndex = i; |
| 2540 | qi.queueCount = queue_props[i].queueCount; |
| 2541 | queue_priorities.emplace_back(qi.queueCount, 0.0f); |
| 2542 | qi.pQueuePriorities = queue_priorities[i].data(); |
| 2543 | queue_info.push_back(qi); |
| 2544 | } |
| 2545 | |
| 2546 | std::vector<const char *> device_layer_names; |
| 2547 | std::vector<const char *> device_extension_names; |
| 2548 | device_layer_names.push_back("VK_LAYER_GOOGLE_threading"); |
| 2549 | device_layer_names.push_back("VK_LAYER_LUNARG_parameter_validation"); |
| 2550 | device_layer_names.push_back("VK_LAYER_LUNARG_object_tracker"); |
| 2551 | device_layer_names.push_back("VK_LAYER_LUNARG_core_validation"); |
Mark Lobodzinski | fc5cc66 | 2016-05-02 17:17:41 -0600 | [diff] [blame] | 2552 | device_layer_names.push_back("VK_LAYER_LUNARG_image"); |
| 2553 | device_layer_names.push_back("VK_LAYER_GOOGLE_unique_objects"); |
| 2554 | |
| 2555 | // The sacrificial device object |
| 2556 | VkDevice testDevice; |
| 2557 | VkDeviceCreateInfo device_create_info = {}; |
| 2558 | auto features = m_device->phy().features(); |
| 2559 | device_create_info.sType = VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO; |
| 2560 | device_create_info.pNext = NULL; |
| 2561 | device_create_info.queueCreateInfoCount = queue_info.size(); |
| 2562 | device_create_info.pQueueCreateInfos = queue_info.data(); |
| 2563 | device_create_info.enabledLayerCount = device_layer_names.size(); |
| 2564 | device_create_info.ppEnabledLayerNames = device_layer_names.data(); |
| 2565 | device_create_info.pEnabledFeatures = &features; |
| 2566 | err = vkCreateDevice(gpu(), &device_create_info, NULL, &testDevice); |
| 2567 | ASSERT_VK_SUCCESS(err); |
| 2568 | |
| 2569 | VkFence fence; |
| 2570 | VkFenceCreateInfo fence_create_info = {}; |
| 2571 | fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO; |
| 2572 | fence_create_info.pNext = NULL; |
| 2573 | fence_create_info.flags = 0; |
| 2574 | err = vkCreateFence(testDevice, &fence_create_info, NULL, &fence); |
| 2575 | ASSERT_VK_SUCCESS(err); |
| 2576 | |
| 2577 | // Induce failure by not calling vkDestroyFence |
| 2578 | vkDestroyDevice(testDevice, NULL); |
| 2579 | m_errorMonitor->VerifyFound(); |
| 2580 | } |
| 2581 | |
| 2582 | TEST_F(VkLayerTest, InvalidCommandPoolConsistency) { |
| 2583 | |
| 2584 | TEST_DESCRIPTION("Allocate command buffers from one command pool and " |
| 2585 | "attempt to delete them from another."); |
| 2586 | |
| 2587 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 2588 | "FreeCommandBuffers is attempting to free Command Buffer"); |
| 2589 | |
| 2590 | VkCommandPool command_pool_one; |
| 2591 | VkCommandPool command_pool_two; |
| 2592 | |
| 2593 | VkCommandPoolCreateInfo pool_create_info{}; |
| 2594 | pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO; |
| 2595 | pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_; |
| 2596 | pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT; |
| 2597 | |
| 2598 | vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, |
| 2599 | &command_pool_one); |
| 2600 | |
| 2601 | vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, |
| 2602 | &command_pool_two); |
| 2603 | |
| 2604 | VkCommandBuffer command_buffer[9]; |
| 2605 | VkCommandBufferAllocateInfo command_buffer_allocate_info{}; |
| 2606 | command_buffer_allocate_info.sType = |
| 2607 | VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO; |
| 2608 | command_buffer_allocate_info.commandPool = command_pool_one; |
| 2609 | command_buffer_allocate_info.commandBufferCount = 9; |
| 2610 | command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY; |
| 2611 | vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, |
| 2612 | command_buffer); |
| 2613 | |
| 2614 | vkFreeCommandBuffers(m_device->device(), command_pool_two, 4, |
| 2615 | &command_buffer[3]); |
| 2616 | |
| 2617 | m_errorMonitor->VerifyFound(); |
| 2618 | |
| 2619 | vkDestroyCommandPool(m_device->device(), command_pool_one, NULL); |
| 2620 | vkDestroyCommandPool(m_device->device(), command_pool_two, NULL); |
| 2621 | } |
| 2622 | |
| 2623 | TEST_F(VkLayerTest, InvalidDescriptorPoolConsistency) { |
| 2624 | VkResult err; |
| 2625 | |
| 2626 | TEST_DESCRIPTION("Allocate descriptor sets from one DS pool and " |
| 2627 | "attempt to delete them from another."); |
| 2628 | |
| 2629 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 2630 | "FreeDescriptorSets is attempting to free descriptorSet"); |
| 2631 | |
| 2632 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 2633 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 2634 | |
| 2635 | VkDescriptorPoolSize ds_type_count = {}; |
| 2636 | ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLER; |
| 2637 | ds_type_count.descriptorCount = 1; |
| 2638 | |
| 2639 | VkDescriptorPoolCreateInfo ds_pool_ci = {}; |
| 2640 | ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO; |
| 2641 | ds_pool_ci.pNext = NULL; |
| 2642 | ds_pool_ci.flags = 0; |
| 2643 | ds_pool_ci.maxSets = 1; |
| 2644 | ds_pool_ci.poolSizeCount = 1; |
| 2645 | ds_pool_ci.pPoolSizes = &ds_type_count; |
| 2646 | |
| 2647 | VkDescriptorPool ds_pool_one; |
| 2648 | err = |
| 2649 | vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool_one); |
| 2650 | ASSERT_VK_SUCCESS(err); |
| 2651 | |
| 2652 | // Create a second descriptor pool |
| 2653 | VkDescriptorPool ds_pool_two; |
| 2654 | err = |
| 2655 | vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool_two); |
| 2656 | ASSERT_VK_SUCCESS(err); |
| 2657 | |
| 2658 | VkDescriptorSetLayoutBinding dsl_binding = {}; |
| 2659 | dsl_binding.binding = 0; |
| 2660 | dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER; |
| 2661 | dsl_binding.descriptorCount = 1; |
| 2662 | dsl_binding.stageFlags = VK_SHADER_STAGE_ALL; |
| 2663 | dsl_binding.pImmutableSamplers = NULL; |
| 2664 | |
| 2665 | VkDescriptorSetLayoutCreateInfo ds_layout_ci = {}; |
| 2666 | ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO; |
| 2667 | ds_layout_ci.pNext = NULL; |
| 2668 | ds_layout_ci.bindingCount = 1; |
| 2669 | ds_layout_ci.pBindings = &dsl_binding; |
| 2670 | |
| 2671 | VkDescriptorSetLayout ds_layout; |
| 2672 | err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, |
| 2673 | &ds_layout); |
| 2674 | ASSERT_VK_SUCCESS(err); |
| 2675 | |
| 2676 | VkDescriptorSet descriptorSet; |
| 2677 | VkDescriptorSetAllocateInfo alloc_info = {}; |
| 2678 | alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO; |
| 2679 | alloc_info.descriptorSetCount = 1; |
| 2680 | alloc_info.descriptorPool = ds_pool_one; |
| 2681 | alloc_info.pSetLayouts = &ds_layout; |
| 2682 | err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, |
| 2683 | &descriptorSet); |
| 2684 | ASSERT_VK_SUCCESS(err); |
| 2685 | |
| 2686 | err = vkFreeDescriptorSets(m_device->device(), ds_pool_two, 1, &descriptorSet); |
| 2687 | |
| 2688 | m_errorMonitor->VerifyFound(); |
| 2689 | |
| 2690 | vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL); |
| 2691 | vkDestroyDescriptorPool(m_device->device(), ds_pool_one, NULL); |
| 2692 | vkDestroyDescriptorPool(m_device->device(), ds_pool_two, NULL); |
| 2693 | } |
| 2694 | |
| 2695 | TEST_F(VkLayerTest, CreateUnknownObject) { |
| 2696 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 2697 | "Invalid VkImage Object "); |
| 2698 | |
| 2699 | TEST_DESCRIPTION( |
| 2700 | "Pass an invalid image object handle into a Vulkan API call."); |
| 2701 | |
| 2702 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 2703 | |
| 2704 | // Pass bogus handle into GetImageMemoryRequirements |
| 2705 | VkMemoryRequirements mem_reqs; |
| 2706 | uint64_t fakeImageHandle = 0xCADECADE; |
| 2707 | VkImage fauxImage = reinterpret_cast<VkImage &>(fakeImageHandle); |
| 2708 | |
| 2709 | vkGetImageMemoryRequirements(m_device->device(), fauxImage, &mem_reqs); |
| 2710 | |
| 2711 | m_errorMonitor->VerifyFound(); |
| 2712 | } |
| 2713 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 2714 | TEST_F(VkLayerTest, PipelineNotBound) { |
| 2715 | VkResult err; |
Tobin Ehlis | c9ac2b6 | 2015-09-11 12:57:55 -0600 | [diff] [blame] | 2716 | |
Mark Lobodzinski | fc5cc66 | 2016-05-02 17:17:41 -0600 | [diff] [blame] | 2717 | TEST_DESCRIPTION( |
| 2718 | "Pass in an invalid pipeline object handle into a Vulkan API call."); |
| 2719 | |
Courtney Goeltzenleuchter | 7415d5a | 2015-12-09 15:48:16 -0700 | [diff] [blame] | 2720 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 2721 | "Invalid VkPipeline Object "); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 2722 | |
Tobin Ehlis | c9ac2b6 | 2015-09-11 12:57:55 -0600 | [diff] [blame] | 2723 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 2724 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
Tobin Ehlis | c9ac2b6 | 2015-09-11 12:57:55 -0600 | [diff] [blame] | 2725 | |
Chia-I Wu | 1b99bb2 | 2015-10-27 19:25:11 +0800 | [diff] [blame] | 2726 | VkDescriptorPoolSize ds_type_count = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 2727 | ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 2728 | ds_type_count.descriptorCount = 1; |
Tobin Ehlis | c9ac2b6 | 2015-09-11 12:57:55 -0600 | [diff] [blame] | 2729 | |
| 2730 | VkDescriptorPoolCreateInfo ds_pool_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 2731 | ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO; |
| 2732 | ds_pool_ci.pNext = NULL; |
| 2733 | ds_pool_ci.maxSets = 1; |
| 2734 | ds_pool_ci.poolSizeCount = 1; |
| 2735 | ds_pool_ci.pPoolSizes = &ds_type_count; |
Tobin Ehlis | c9ac2b6 | 2015-09-11 12:57:55 -0600 | [diff] [blame] | 2736 | |
| 2737 | VkDescriptorPool ds_pool; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 2738 | err = |
| 2739 | vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool); |
Tobin Ehlis | c9ac2b6 | 2015-09-11 12:57:55 -0600 | [diff] [blame] | 2740 | ASSERT_VK_SUCCESS(err); |
| 2741 | |
| 2742 | VkDescriptorSetLayoutBinding dsl_binding = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 2743 | dsl_binding.binding = 0; |
| 2744 | dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 2745 | dsl_binding.descriptorCount = 1; |
| 2746 | dsl_binding.stageFlags = VK_SHADER_STAGE_ALL; |
| 2747 | dsl_binding.pImmutableSamplers = NULL; |
Tobin Ehlis | c9ac2b6 | 2015-09-11 12:57:55 -0600 | [diff] [blame] | 2748 | |
| 2749 | VkDescriptorSetLayoutCreateInfo ds_layout_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 2750 | ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO; |
| 2751 | ds_layout_ci.pNext = NULL; |
| 2752 | ds_layout_ci.bindingCount = 1; |
| 2753 | ds_layout_ci.pBindings = &dsl_binding; |
Tobin Ehlis | c9ac2b6 | 2015-09-11 12:57:55 -0600 | [diff] [blame] | 2754 | |
| 2755 | VkDescriptorSetLayout ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 2756 | err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, |
| 2757 | &ds_layout); |
Tobin Ehlis | c9ac2b6 | 2015-09-11 12:57:55 -0600 | [diff] [blame] | 2758 | ASSERT_VK_SUCCESS(err); |
| 2759 | |
| 2760 | VkDescriptorSet descriptorSet; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 2761 | VkDescriptorSetAllocateInfo alloc_info = {}; |
Chia-I Wu | 00ce540 | 2015-11-10 16:21:09 +0800 | [diff] [blame] | 2762 | alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO; |
Jon Ashburn | f19916e | 2016-01-11 13:12:43 -0700 | [diff] [blame] | 2763 | alloc_info.descriptorSetCount = 1; |
Courtney Goeltzenleuchter | bee18a9 | 2015-10-23 14:21:05 -0600 | [diff] [blame] | 2764 | alloc_info.descriptorPool = ds_pool; |
| 2765 | alloc_info.pSetLayouts = &ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 2766 | err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, |
| 2767 | &descriptorSet); |
Tobin Ehlis | c9ac2b6 | 2015-09-11 12:57:55 -0600 | [diff] [blame] | 2768 | ASSERT_VK_SUCCESS(err); |
| 2769 | |
| 2770 | VkPipelineLayoutCreateInfo pipeline_layout_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 2771 | pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO; |
| 2772 | pipeline_layout_ci.pNext = NULL; |
| 2773 | pipeline_layout_ci.setLayoutCount = 1; |
| 2774 | pipeline_layout_ci.pSetLayouts = &ds_layout; |
Tobin Ehlis | c9ac2b6 | 2015-09-11 12:57:55 -0600 | [diff] [blame] | 2775 | |
| 2776 | VkPipelineLayout pipeline_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 2777 | err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, |
| 2778 | &pipeline_layout); |
Tobin Ehlis | c9ac2b6 | 2015-09-11 12:57:55 -0600 | [diff] [blame] | 2779 | ASSERT_VK_SUCCESS(err); |
| 2780 | |
Mark Young | ad77905 | 2016-01-06 14:26:04 -0700 | [diff] [blame] | 2781 | VkPipeline badPipeline = (VkPipeline)((size_t)0xbaadb1be); |
Tobin Ehlis | c9ac2b6 | 2015-09-11 12:57:55 -0600 | [diff] [blame] | 2782 | |
| 2783 | BeginCommandBuffer(); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 2784 | vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), |
| 2785 | VK_PIPELINE_BIND_POINT_GRAPHICS, badPipeline); |
Tobin Ehlis | c9ac2b6 | 2015-09-11 12:57:55 -0600 | [diff] [blame] | 2786 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 2787 | m_errorMonitor->VerifyFound(); |
Mike Stroyan | d1c84a5 | 2015-08-18 14:40:24 -0600 | [diff] [blame] | 2788 | |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 2789 | vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL); |
| 2790 | vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL); |
| 2791 | vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL); |
Tobin Ehlis | ec59830 | 2015-09-15 15:02:17 -0600 | [diff] [blame] | 2792 | } |
Mike Stroyan | 80fc6c3 | 2016-06-20 15:42:29 -0600 | [diff] [blame] | 2793 | |
Mark Lobodzinski | bc18576 | 2016-06-15 16:28:53 -0600 | [diff] [blame] | 2794 | TEST_F(VkLayerTest, BindImageInvalidMemoryType) { |
| 2795 | VkResult err; |
| 2796 | |
| 2797 | TEST_DESCRIPTION("Test validation check for an invalid memory type index " |
| 2798 | "during bind[Buffer|Image]Memory time"); |
| 2799 | |
Mark Lobodzinski | bc18576 | 2016-06-15 16:28:53 -0600 | [diff] [blame] | 2800 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 2801 | |
| 2802 | // Create an image, allocate memory, set a bad typeIndex and then try to |
| 2803 | // bind it |
| 2804 | VkImage image; |
| 2805 | VkDeviceMemory mem; |
| 2806 | VkMemoryRequirements mem_reqs; |
| 2807 | const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM; |
| 2808 | const int32_t tex_width = 32; |
| 2809 | const int32_t tex_height = 32; |
| 2810 | |
| 2811 | VkImageCreateInfo image_create_info = {}; |
| 2812 | image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO; |
| 2813 | image_create_info.pNext = NULL; |
| 2814 | image_create_info.imageType = VK_IMAGE_TYPE_2D; |
| 2815 | image_create_info.format = tex_format; |
| 2816 | image_create_info.extent.width = tex_width; |
| 2817 | image_create_info.extent.height = tex_height; |
| 2818 | image_create_info.extent.depth = 1; |
| 2819 | image_create_info.mipLevels = 1; |
| 2820 | image_create_info.arrayLayers = 1; |
| 2821 | image_create_info.samples = VK_SAMPLE_COUNT_1_BIT; |
| 2822 | image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL; |
| 2823 | image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT; |
| 2824 | image_create_info.flags = 0; |
| 2825 | |
| 2826 | VkMemoryAllocateInfo mem_alloc = {}; |
| 2827 | mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO; |
| 2828 | mem_alloc.pNext = NULL; |
| 2829 | mem_alloc.allocationSize = 0; |
| 2830 | mem_alloc.memoryTypeIndex = 0; |
| 2831 | |
| 2832 | err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image); |
| 2833 | ASSERT_VK_SUCCESS(err); |
| 2834 | |
| 2835 | vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs); |
| 2836 | mem_alloc.allocationSize = mem_reqs.size; |
Mike Stroyan | 80fc6c3 | 2016-06-20 15:42:29 -0600 | [diff] [blame] | 2837 | |
| 2838 | // Introduce Failure, select invalid TypeIndex |
| 2839 | VkPhysicalDeviceMemoryProperties memory_info; |
| 2840 | |
| 2841 | vkGetPhysicalDeviceMemoryProperties(gpu(), &memory_info); |
| 2842 | unsigned int i; |
| 2843 | for (i = 0; i < memory_info.memoryTypeCount; i++) { |
| 2844 | if ((mem_reqs.memoryTypeBits & (1 << i)) == 0) { |
| 2845 | mem_alloc.memoryTypeIndex = i; |
| 2846 | break; |
| 2847 | } |
| 2848 | } |
| 2849 | if (i >= memory_info.memoryTypeCount) { |
| 2850 | printf("No invalid memory type index could be found; skipped.\n"); |
| 2851 | vkDestroyImage(m_device->device(), image, NULL); |
| 2852 | return; |
| 2853 | } |
| 2854 | |
| 2855 | m_errorMonitor->SetDesiredFailureMsg( |
| 2856 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 2857 | "for this object type are not compatible with the memory"); |
Mark Lobodzinski | bc18576 | 2016-06-15 16:28:53 -0600 | [diff] [blame] | 2858 | |
| 2859 | err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem); |
| 2860 | ASSERT_VK_SUCCESS(err); |
| 2861 | |
| 2862 | err = vkBindImageMemory(m_device->device(), image, mem, 0); |
| 2863 | (void)err; |
| 2864 | |
| 2865 | m_errorMonitor->VerifyFound(); |
| 2866 | |
| 2867 | vkDestroyImage(m_device->device(), image, NULL); |
| 2868 | vkFreeMemory(m_device->device(), mem, NULL); |
| 2869 | } |
Mike Stroyan | 80fc6c3 | 2016-06-20 15:42:29 -0600 | [diff] [blame] | 2870 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 2871 | TEST_F(VkLayerTest, BindInvalidMemory) { |
| 2872 | VkResult err; |
| 2873 | bool pass; |
Tobin Ehlis | ec59830 | 2015-09-15 15:02:17 -0600 | [diff] [blame] | 2874 | |
Courtney Goeltzenleuchter | 7415d5a | 2015-12-09 15:48:16 -0700 | [diff] [blame] | 2875 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 2876 | "Invalid VkDeviceMemory Object "); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 2877 | |
Tobin Ehlis | ec59830 | 2015-09-15 15:02:17 -0600 | [diff] [blame] | 2878 | ASSERT_NO_FATAL_FAILURE(InitState()); |
Tobin Ehlis | ec59830 | 2015-09-15 15:02:17 -0600 | [diff] [blame] | 2879 | |
| 2880 | // 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] | 2881 | VkImage image; |
| 2882 | VkDeviceMemory mem; |
| 2883 | VkMemoryRequirements mem_reqs; |
Tobin Ehlis | ec59830 | 2015-09-15 15:02:17 -0600 | [diff] [blame] | 2884 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 2885 | const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM; |
| 2886 | const int32_t tex_width = 32; |
| 2887 | const int32_t tex_height = 32; |
Tobin Ehlis | ec59830 | 2015-09-15 15:02:17 -0600 | [diff] [blame] | 2888 | |
| 2889 | VkImageCreateInfo image_create_info = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 2890 | image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO; |
| 2891 | image_create_info.pNext = NULL; |
| 2892 | image_create_info.imageType = VK_IMAGE_TYPE_2D; |
| 2893 | image_create_info.format = tex_format; |
| 2894 | image_create_info.extent.width = tex_width; |
| 2895 | image_create_info.extent.height = tex_height; |
| 2896 | image_create_info.extent.depth = 1; |
| 2897 | image_create_info.mipLevels = 1; |
| 2898 | image_create_info.arrayLayers = 1; |
| 2899 | image_create_info.samples = VK_SAMPLE_COUNT_1_BIT; |
| 2900 | image_create_info.tiling = VK_IMAGE_TILING_LINEAR; |
| 2901 | image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT; |
| 2902 | image_create_info.flags = 0; |
Tobin Ehlis | ec59830 | 2015-09-15 15:02:17 -0600 | [diff] [blame] | 2903 | |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 2904 | VkMemoryAllocateInfo mem_alloc = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 2905 | mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO; |
| 2906 | mem_alloc.pNext = NULL; |
| 2907 | mem_alloc.allocationSize = 0; |
| 2908 | mem_alloc.memoryTypeIndex = 0; |
Tobin Ehlis | ec59830 | 2015-09-15 15:02:17 -0600 | [diff] [blame] | 2909 | |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 2910 | err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image); |
Tobin Ehlis | ec59830 | 2015-09-15 15:02:17 -0600 | [diff] [blame] | 2911 | ASSERT_VK_SUCCESS(err); |
| 2912 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 2913 | vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs); |
Tobin Ehlis | ec59830 | 2015-09-15 15:02:17 -0600 | [diff] [blame] | 2914 | |
| 2915 | mem_alloc.allocationSize = mem_reqs.size; |
| 2916 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 2917 | pass = |
| 2918 | m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0); |
Courtney Goeltzenleuchter | 1d2f0dd | 2015-10-22 11:03:31 -0600 | [diff] [blame] | 2919 | ASSERT_TRUE(pass); |
Tobin Ehlis | ec59830 | 2015-09-15 15:02:17 -0600 | [diff] [blame] | 2920 | |
| 2921 | // allocate memory |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 2922 | err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem); |
Tobin Ehlis | ec59830 | 2015-09-15 15:02:17 -0600 | [diff] [blame] | 2923 | ASSERT_VK_SUCCESS(err); |
| 2924 | |
| 2925 | // Introduce validation failure, free memory before binding |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 2926 | vkFreeMemory(m_device->device(), mem, NULL); |
Tobin Ehlis | ec59830 | 2015-09-15 15:02:17 -0600 | [diff] [blame] | 2927 | |
| 2928 | // Try to bind free memory that has been freed |
| 2929 | err = vkBindImageMemory(m_device->device(), image, mem, 0); |
| 2930 | // This may very well return an error. |
| 2931 | (void)err; |
| 2932 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 2933 | m_errorMonitor->VerifyFound(); |
Mike Stroyan | d1c84a5 | 2015-08-18 14:40:24 -0600 | [diff] [blame] | 2934 | |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 2935 | vkDestroyImage(m_device->device(), image, NULL); |
Tobin Ehlis | ec59830 | 2015-09-15 15:02:17 -0600 | [diff] [blame] | 2936 | } |
| 2937 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 2938 | TEST_F(VkLayerTest, BindMemoryToDestroyedObject) { |
| 2939 | VkResult err; |
| 2940 | bool pass; |
Tobin Ehlis | ec59830 | 2015-09-15 15:02:17 -0600 | [diff] [blame] | 2941 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 2942 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 2943 | "Invalid VkImage Object "); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 2944 | |
Tobin Ehlis | ec59830 | 2015-09-15 15:02:17 -0600 | [diff] [blame] | 2945 | ASSERT_NO_FATAL_FAILURE(InitState()); |
Tobin Ehlis | ec59830 | 2015-09-15 15:02:17 -0600 | [diff] [blame] | 2946 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 2947 | // Create an image object, allocate memory, destroy the object and then try |
| 2948 | // to bind it |
| 2949 | VkImage image; |
| 2950 | VkDeviceMemory mem; |
| 2951 | VkMemoryRequirements mem_reqs; |
Tobin Ehlis | ec59830 | 2015-09-15 15:02:17 -0600 | [diff] [blame] | 2952 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 2953 | const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM; |
| 2954 | const int32_t tex_width = 32; |
| 2955 | const int32_t tex_height = 32; |
Tobin Ehlis | ec59830 | 2015-09-15 15:02:17 -0600 | [diff] [blame] | 2956 | |
| 2957 | VkImageCreateInfo image_create_info = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 2958 | image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO; |
| 2959 | image_create_info.pNext = NULL; |
| 2960 | image_create_info.imageType = VK_IMAGE_TYPE_2D; |
| 2961 | image_create_info.format = tex_format; |
| 2962 | image_create_info.extent.width = tex_width; |
| 2963 | image_create_info.extent.height = tex_height; |
| 2964 | image_create_info.extent.depth = 1; |
| 2965 | image_create_info.mipLevels = 1; |
| 2966 | image_create_info.arrayLayers = 1; |
| 2967 | image_create_info.samples = VK_SAMPLE_COUNT_1_BIT; |
| 2968 | image_create_info.tiling = VK_IMAGE_TILING_LINEAR; |
| 2969 | image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT; |
| 2970 | image_create_info.flags = 0; |
Tobin Ehlis | ec59830 | 2015-09-15 15:02:17 -0600 | [diff] [blame] | 2971 | |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 2972 | VkMemoryAllocateInfo mem_alloc = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 2973 | mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO; |
| 2974 | mem_alloc.pNext = NULL; |
| 2975 | mem_alloc.allocationSize = 0; |
| 2976 | mem_alloc.memoryTypeIndex = 0; |
Tobin Ehlis | ec59830 | 2015-09-15 15:02:17 -0600 | [diff] [blame] | 2977 | |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 2978 | err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image); |
Tobin Ehlis | ec59830 | 2015-09-15 15:02:17 -0600 | [diff] [blame] | 2979 | ASSERT_VK_SUCCESS(err); |
| 2980 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 2981 | vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs); |
Tobin Ehlis | ec59830 | 2015-09-15 15:02:17 -0600 | [diff] [blame] | 2982 | |
| 2983 | mem_alloc.allocationSize = mem_reqs.size; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 2984 | pass = |
| 2985 | m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0); |
Courtney Goeltzenleuchter | 1d2f0dd | 2015-10-22 11:03:31 -0600 | [diff] [blame] | 2986 | ASSERT_TRUE(pass); |
Tobin Ehlis | ec59830 | 2015-09-15 15:02:17 -0600 | [diff] [blame] | 2987 | |
| 2988 | // Allocate memory |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 2989 | err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem); |
Tobin Ehlis | ec59830 | 2015-09-15 15:02:17 -0600 | [diff] [blame] | 2990 | ASSERT_VK_SUCCESS(err); |
| 2991 | |
| 2992 | // Introduce validation failure, destroy Image object before binding |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 2993 | vkDestroyImage(m_device->device(), image, NULL); |
Tobin Ehlis | ec59830 | 2015-09-15 15:02:17 -0600 | [diff] [blame] | 2994 | ASSERT_VK_SUCCESS(err); |
| 2995 | |
| 2996 | // Now Try to bind memory to this destroyed object |
| 2997 | err = vkBindImageMemory(m_device->device(), image, mem, 0); |
| 2998 | // This may very well return an error. |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 2999 | (void)err; |
Tobin Ehlis | ec59830 | 2015-09-15 15:02:17 -0600 | [diff] [blame] | 3000 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 3001 | m_errorMonitor->VerifyFound(); |
Mike Stroyan | d1c84a5 | 2015-08-18 14:40:24 -0600 | [diff] [blame] | 3002 | |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 3003 | vkFreeMemory(m_device->device(), mem, NULL); |
Tobin Ehlis | c9ac2b6 | 2015-09-11 12:57:55 -0600 | [diff] [blame] | 3004 | } |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 3005 | |
Mark Lobodzinski | 209b529 | 2015-09-17 09:44:05 -0600 | [diff] [blame] | 3006 | #endif // OBJ_TRACKER_TESTS |
| 3007 | |
Tobin Ehlis | 0788f52 | 2015-05-26 16:11:58 -0600 | [diff] [blame] | 3008 | #if DRAW_STATE_TESTS |
Mark Lobodzinski | c808d44 | 2016-04-14 10:57:23 -0600 | [diff] [blame] | 3009 | |
Chris Forbes | 48a5390 | 2016-06-30 11:46:27 +1200 | [diff] [blame] | 3010 | TEST_F(VkLayerTest, RenderPassInitialLayoutUndefined) { |
| 3011 | TEST_DESCRIPTION("Ensure that CmdBeginRenderPass with an attachment's " |
| 3012 | "initialLayout of VK_IMAGE_LAYOUT_UNDEFINED works when " |
| 3013 | "the command buffer has prior knowledge of that " |
| 3014 | "attachment's layout."); |
| 3015 | |
| 3016 | m_errorMonitor->ExpectSuccess(); |
| 3017 | |
| 3018 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 3019 | |
| 3020 | // A renderpass with one color attachment. |
| 3021 | VkAttachmentDescription attachment = { |
| 3022 | 0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_1_BIT, |
| 3023 | VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_STORE, |
| 3024 | VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, |
| 3025 | VK_IMAGE_LAYOUT_UNDEFINED, |
| 3026 | VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL |
| 3027 | }; |
| 3028 | |
| 3029 | VkAttachmentReference att_ref = { |
| 3030 | 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL |
| 3031 | }; |
| 3032 | |
| 3033 | VkSubpassDescription subpass = { |
| 3034 | 0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, |
| 3035 | 1, &att_ref, nullptr, nullptr, 0, nullptr |
| 3036 | }; |
| 3037 | |
| 3038 | VkRenderPassCreateInfo rpci = { |
| 3039 | VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, |
| 3040 | 0, 1, &attachment, 1, &subpass, 0, nullptr |
| 3041 | }; |
| 3042 | |
| 3043 | VkRenderPass rp; |
| 3044 | VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp); |
| 3045 | ASSERT_VK_SUCCESS(err); |
| 3046 | |
| 3047 | // A compatible framebuffer. |
| 3048 | VkImageObj image(m_device); |
| 3049 | image.init(32, 32, VK_FORMAT_R8G8B8A8_UNORM, |
| 3050 | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, |
| 3051 | VK_IMAGE_TILING_OPTIMAL, 0); |
| 3052 | ASSERT_TRUE(image.initialized()); |
| 3053 | |
| 3054 | VkImageViewCreateInfo ivci = { |
| 3055 | VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO, nullptr, |
| 3056 | 0, image.handle(), VK_IMAGE_VIEW_TYPE_2D, VK_FORMAT_R8G8B8A8_UNORM, |
| 3057 | { |
| 3058 | VK_COMPONENT_SWIZZLE_IDENTITY, |
| 3059 | VK_COMPONENT_SWIZZLE_IDENTITY, |
| 3060 | VK_COMPONENT_SWIZZLE_IDENTITY, |
| 3061 | VK_COMPONENT_SWIZZLE_IDENTITY |
| 3062 | }, |
| 3063 | { |
| 3064 | VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1 |
| 3065 | }, |
| 3066 | }; |
| 3067 | VkImageView view; |
| 3068 | err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view); |
| 3069 | ASSERT_VK_SUCCESS(err); |
| 3070 | |
| 3071 | VkFramebufferCreateInfo fci = { |
| 3072 | VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, |
| 3073 | 0, rp, 1, &view, |
| 3074 | 32, 32, 1 |
| 3075 | }; |
| 3076 | VkFramebuffer fb; |
| 3077 | err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb); |
| 3078 | ASSERT_VK_SUCCESS(err); |
| 3079 | |
| 3080 | // Record a single command buffer which uses this renderpass twice. The |
| 3081 | // bug is triggered at the beginning of the second renderpass, when the |
| 3082 | // command buffer already has a layout recorded for the attachment. |
| 3083 | VkRenderPassBeginInfo rpbi = { |
| 3084 | VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO, nullptr, |
Tobin Ehlis | 0f9aa40 | 2016-07-01 08:47:12 -0600 | [diff] [blame] | 3085 | rp, fb, { { 0, 0 } , { 32, 32 } }, |
Chris Forbes | 48a5390 | 2016-06-30 11:46:27 +1200 | [diff] [blame] | 3086 | 0, nullptr |
| 3087 | }; |
| 3088 | BeginCommandBuffer(); |
| 3089 | vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, |
| 3090 | VK_SUBPASS_CONTENTS_INLINE); |
| 3091 | vkCmdEndRenderPass(m_commandBuffer->handle()); |
| 3092 | vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, |
| 3093 | VK_SUBPASS_CONTENTS_INLINE); |
| 3094 | |
| 3095 | m_errorMonitor->VerifyNotFound(); |
| 3096 | |
| 3097 | vkCmdEndRenderPass(m_commandBuffer->handle()); |
| 3098 | EndCommandBuffer(); |
| 3099 | |
| 3100 | vkDestroyFramebuffer(m_device->device(), fb, nullptr); |
| 3101 | vkDestroyRenderPass(m_device->device(), rp, nullptr); |
| 3102 | vkDestroyImageView(m_device->device(), view, nullptr); |
| 3103 | } |
| 3104 | |
Chris Forbes | 51bf7c9 | 2016-06-30 15:22:08 +1200 | [diff] [blame] | 3105 | TEST_F(VkLayerTest, RenderPassSubpassZeroTransitionsApplied) { |
| 3106 | TEST_DESCRIPTION("Ensure that CmdBeginRenderPass applies the layout " |
| 3107 | "transitions for the first subpass"); |
| 3108 | |
| 3109 | m_errorMonitor->ExpectSuccess(); |
| 3110 | |
| 3111 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 3112 | |
| 3113 | // A renderpass with one color attachment. |
| 3114 | VkAttachmentDescription attachment = { |
| 3115 | 0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_1_BIT, |
| 3116 | VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_STORE, |
| 3117 | VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, |
| 3118 | VK_IMAGE_LAYOUT_UNDEFINED, |
| 3119 | VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL |
| 3120 | }; |
| 3121 | |
| 3122 | VkAttachmentReference att_ref = { |
| 3123 | 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL |
| 3124 | }; |
| 3125 | |
| 3126 | VkSubpassDescription subpass = { |
| 3127 | 0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, |
| 3128 | 1, &att_ref, nullptr, nullptr, 0, nullptr |
| 3129 | }; |
| 3130 | |
| 3131 | VkSubpassDependency dep = { |
Chris Forbes | cb4c7ad | 2016-07-06 10:28:18 +1200 | [diff] [blame] | 3132 | 0, 0, VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT, |
| 3133 | VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT, |
Chris Forbes | 51bf7c9 | 2016-06-30 15:22:08 +1200 | [diff] [blame] | 3134 | VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT, |
| 3135 | VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT, |
| 3136 | VK_DEPENDENCY_BY_REGION_BIT |
| 3137 | }; |
| 3138 | |
| 3139 | VkRenderPassCreateInfo rpci = { |
| 3140 | VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, |
| 3141 | 0, 1, &attachment, 1, &subpass, 1, &dep |
| 3142 | }; |
| 3143 | |
| 3144 | VkResult err; |
| 3145 | VkRenderPass rp; |
| 3146 | err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp); |
| 3147 | ASSERT_VK_SUCCESS(err); |
| 3148 | |
| 3149 | // A compatible framebuffer. |
| 3150 | VkImageObj image(m_device); |
| 3151 | image.init(32, 32, VK_FORMAT_R8G8B8A8_UNORM, |
| 3152 | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, |
| 3153 | VK_IMAGE_TILING_OPTIMAL, 0); |
| 3154 | ASSERT_TRUE(image.initialized()); |
| 3155 | |
| 3156 | VkImageViewCreateInfo ivci = { |
| 3157 | VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO, nullptr, |
| 3158 | 0, image.handle(), VK_IMAGE_VIEW_TYPE_2D, VK_FORMAT_R8G8B8A8_UNORM, |
| 3159 | { |
| 3160 | VK_COMPONENT_SWIZZLE_IDENTITY, |
| 3161 | VK_COMPONENT_SWIZZLE_IDENTITY, |
| 3162 | VK_COMPONENT_SWIZZLE_IDENTITY, |
| 3163 | VK_COMPONENT_SWIZZLE_IDENTITY |
| 3164 | }, |
| 3165 | { |
| 3166 | VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1 |
| 3167 | }, |
| 3168 | }; |
| 3169 | VkImageView view; |
| 3170 | err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view); |
| 3171 | ASSERT_VK_SUCCESS(err); |
| 3172 | |
| 3173 | VkFramebufferCreateInfo fci = { |
| 3174 | VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, |
| 3175 | 0, rp, 1, &view, |
| 3176 | 32, 32, 1 |
| 3177 | }; |
| 3178 | VkFramebuffer fb; |
| 3179 | err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb); |
| 3180 | ASSERT_VK_SUCCESS(err); |
| 3181 | |
| 3182 | // Record a single command buffer which issues a pipeline barrier w/ |
| 3183 | // image memory barrier for the attachment. This detects the previously |
| 3184 | // missing tracking of the subpass layout by throwing a validation error |
| 3185 | // if it doesn't occur. |
| 3186 | VkRenderPassBeginInfo rpbi = { |
| 3187 | VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO, nullptr, |
Tobin Ehlis | 0f9aa40 | 2016-07-01 08:47:12 -0600 | [diff] [blame] | 3188 | rp, fb, { { 0, 0 }, { 32, 32 } }, |
Chris Forbes | 51bf7c9 | 2016-06-30 15:22:08 +1200 | [diff] [blame] | 3189 | 0, nullptr |
| 3190 | }; |
| 3191 | BeginCommandBuffer(); |
| 3192 | vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, |
| 3193 | VK_SUBPASS_CONTENTS_INLINE); |
| 3194 | |
| 3195 | VkImageMemoryBarrier imb = { |
| 3196 | VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER, nullptr, |
| 3197 | VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT, |
| 3198 | VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT, |
| 3199 | VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, |
| 3200 | VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, |
| 3201 | VK_QUEUE_FAMILY_IGNORED, VK_QUEUE_FAMILY_IGNORED, |
| 3202 | image.handle(), |
| 3203 | { VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1 } |
| 3204 | }; |
| 3205 | vkCmdPipelineBarrier(m_commandBuffer->handle(), |
Chris Forbes | cb4c7ad | 2016-07-06 10:28:18 +1200 | [diff] [blame] | 3206 | VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT, |
| 3207 | VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT, |
Chris Forbes | 51bf7c9 | 2016-06-30 15:22:08 +1200 | [diff] [blame] | 3208 | VK_DEPENDENCY_BY_REGION_BIT, |
| 3209 | 0, nullptr, 0, nullptr, 1, &imb); |
| 3210 | |
| 3211 | vkCmdEndRenderPass(m_commandBuffer->handle()); |
| 3212 | m_errorMonitor->VerifyNotFound(); |
| 3213 | EndCommandBuffer(); |
| 3214 | |
| 3215 | vkDestroyFramebuffer(m_device->device(), fb, nullptr); |
| 3216 | vkDestroyRenderPass(m_device->device(), rp, nullptr); |
| 3217 | vkDestroyImageView(m_device->device(), view, nullptr); |
| 3218 | } |
| 3219 | |
Chris Forbes | 6b3d3f4 | 2016-06-30 16:09:47 +1200 | [diff] [blame] | 3220 | TEST_F(VkLayerTest, RenderPassTransitionsAttachmentUnused) { |
| 3221 | TEST_DESCRIPTION("Ensure that layout transitions work correctly without " |
| 3222 | "errors, when an attachment reference is " |
| 3223 | "VK_ATTACHMENT_UNUSED"); |
| 3224 | |
| 3225 | m_errorMonitor->ExpectSuccess(); |
| 3226 | |
| 3227 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 3228 | |
| 3229 | // A renderpass with no attachments |
| 3230 | VkAttachmentReference att_ref = { |
| 3231 | VK_ATTACHMENT_UNUSED, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL |
| 3232 | }; |
| 3233 | |
| 3234 | VkSubpassDescription subpass = { |
| 3235 | 0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, |
| 3236 | 1, &att_ref, nullptr, nullptr, 0, nullptr |
| 3237 | }; |
| 3238 | |
| 3239 | VkRenderPassCreateInfo rpci = { |
| 3240 | VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, |
| 3241 | 0, 0, nullptr, 1, &subpass, 0, nullptr |
| 3242 | }; |
| 3243 | |
| 3244 | VkRenderPass rp; |
| 3245 | VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp); |
| 3246 | ASSERT_VK_SUCCESS(err); |
| 3247 | |
| 3248 | // A compatible framebuffer. |
| 3249 | VkFramebufferCreateInfo fci = { |
| 3250 | VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, |
| 3251 | 0, rp, 0, nullptr, |
| 3252 | 32, 32, 1 |
| 3253 | }; |
| 3254 | VkFramebuffer fb; |
| 3255 | err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb); |
| 3256 | ASSERT_VK_SUCCESS(err); |
| 3257 | |
| 3258 | // Record a command buffer which just begins and ends the renderpass. The |
| 3259 | // bug manifests in BeginRenderPass. |
| 3260 | VkRenderPassBeginInfo rpbi = { |
| 3261 | VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO, nullptr, |
Tobin Ehlis | 0f9aa40 | 2016-07-01 08:47:12 -0600 | [diff] [blame] | 3262 | rp, fb, { { 0, 0 }, { 32, 32 } }, |
Chris Forbes | 6b3d3f4 | 2016-06-30 16:09:47 +1200 | [diff] [blame] | 3263 | 0, nullptr |
| 3264 | }; |
| 3265 | BeginCommandBuffer(); |
| 3266 | vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, |
| 3267 | VK_SUBPASS_CONTENTS_INLINE); |
| 3268 | vkCmdEndRenderPass(m_commandBuffer->handle()); |
| 3269 | m_errorMonitor->VerifyNotFound(); |
| 3270 | EndCommandBuffer(); |
| 3271 | |
| 3272 | vkDestroyFramebuffer(m_device->device(), fb, nullptr); |
| 3273 | vkDestroyRenderPass(m_device->device(), rp, nullptr); |
| 3274 | } |
| 3275 | |
Mark Lobodzinski | ce7eee7 | 2016-06-14 16:33:29 -0600 | [diff] [blame] | 3276 | // This is a positive test. No errors are expected. |
| 3277 | TEST_F(VkLayerTest, StencilLoadOp) { |
| 3278 | TEST_DESCRIPTION("Create a stencil-only attachment with a LOAD_OP set to " |
| 3279 | "CLEAR. stencil[Load|Store]Op used to be ignored."); |
| 3280 | VkResult result = VK_SUCCESS; |
| 3281 | VkImageFormatProperties formatProps; |
| 3282 | vkGetPhysicalDeviceImageFormatProperties( |
| 3283 | gpu(), VK_FORMAT_D24_UNORM_S8_UINT, VK_IMAGE_TYPE_2D, |
| 3284 | VK_IMAGE_TILING_OPTIMAL, VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT | |
| 3285 | VK_IMAGE_USAGE_TRANSFER_SRC_BIT, |
| 3286 | 0, &formatProps); |
| 3287 | if (formatProps.maxExtent.width < 100 || formatProps.maxExtent.height < 100) { |
| 3288 | return; |
| 3289 | } |
| 3290 | |
| 3291 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 3292 | VkFormat depth_stencil_fmt = VK_FORMAT_D24_UNORM_S8_UINT; |
| 3293 | m_depthStencil->Init(m_device, 100, 100, depth_stencil_fmt, |
| 3294 | VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT | |
| 3295 | VK_IMAGE_USAGE_TRANSFER_SRC_BIT); |
| 3296 | VkAttachmentDescription att = {}; |
| 3297 | VkAttachmentReference ref = {}; |
| 3298 | att.format = depth_stencil_fmt; |
| 3299 | att.loadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE; |
| 3300 | att.storeOp = VK_ATTACHMENT_STORE_OP_DONT_CARE; |
| 3301 | att.stencilLoadOp = VK_ATTACHMENT_LOAD_OP_CLEAR; |
| 3302 | att.stencilStoreOp = VK_ATTACHMENT_STORE_OP_STORE; |
| 3303 | att.initialLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL; |
| 3304 | att.finalLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL; |
| 3305 | |
| 3306 | VkClearValue clear; |
| 3307 | clear.depthStencil.depth = 1.0; |
| 3308 | clear.depthStencil.stencil = 0; |
| 3309 | ref.attachment = 0; |
| 3310 | ref.layout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL; |
| 3311 | |
| 3312 | VkSubpassDescription subpass = {}; |
| 3313 | subpass.pipelineBindPoint = VK_PIPELINE_BIND_POINT_GRAPHICS; |
| 3314 | subpass.flags = 0; |
| 3315 | subpass.inputAttachmentCount = 0; |
| 3316 | subpass.pInputAttachments = NULL; |
| 3317 | subpass.colorAttachmentCount = 0; |
| 3318 | subpass.pColorAttachments = NULL; |
| 3319 | subpass.pResolveAttachments = NULL; |
| 3320 | subpass.pDepthStencilAttachment = &ref; |
| 3321 | subpass.preserveAttachmentCount = 0; |
| 3322 | subpass.pPreserveAttachments = NULL; |
| 3323 | |
| 3324 | VkRenderPass rp; |
| 3325 | VkRenderPassCreateInfo rp_info = {}; |
| 3326 | rp_info.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO; |
| 3327 | rp_info.attachmentCount = 1; |
| 3328 | rp_info.pAttachments = &att; |
| 3329 | rp_info.subpassCount = 1; |
| 3330 | rp_info.pSubpasses = &subpass; |
| 3331 | result = vkCreateRenderPass(device(), &rp_info, NULL, &rp); |
| 3332 | ASSERT_VK_SUCCESS(result); |
| 3333 | |
| 3334 | VkImageView *depthView = m_depthStencil->BindInfo(); |
| 3335 | VkFramebufferCreateInfo fb_info = {}; |
| 3336 | fb_info.sType = VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO; |
| 3337 | fb_info.pNext = NULL; |
| 3338 | fb_info.renderPass = rp; |
| 3339 | fb_info.attachmentCount = 1; |
| 3340 | fb_info.pAttachments = depthView; |
| 3341 | fb_info.width = 100; |
| 3342 | fb_info.height = 100; |
| 3343 | fb_info.layers = 1; |
| 3344 | VkFramebuffer fb; |
| 3345 | result = vkCreateFramebuffer(device(), &fb_info, NULL, &fb); |
| 3346 | ASSERT_VK_SUCCESS(result); |
| 3347 | |
| 3348 | |
| 3349 | VkRenderPassBeginInfo rpbinfo = {}; |
| 3350 | rpbinfo.clearValueCount = 1; |
| 3351 | rpbinfo.pClearValues = &clear; |
| 3352 | rpbinfo.pNext = NULL; |
| 3353 | rpbinfo.renderPass = rp; |
| 3354 | rpbinfo.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO; |
| 3355 | rpbinfo.renderArea.extent.width = 100; |
| 3356 | rpbinfo.renderArea.extent.height = 100; |
| 3357 | rpbinfo.renderArea.offset.x = 0; |
| 3358 | rpbinfo.renderArea.offset.y = 0; |
| 3359 | rpbinfo.framebuffer = fb; |
| 3360 | |
| 3361 | VkFence fence = {}; |
| 3362 | VkFenceCreateInfo fence_ci = {}; |
| 3363 | fence_ci.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO; |
| 3364 | fence_ci.pNext = nullptr; |
| 3365 | fence_ci.flags = 0; |
| 3366 | result = vkCreateFence(m_device->device(), &fence_ci, nullptr, &fence); |
| 3367 | ASSERT_VK_SUCCESS(result); |
| 3368 | |
| 3369 | |
| 3370 | m_commandBuffer->BeginCommandBuffer(); |
| 3371 | m_commandBuffer->BeginRenderPass(rpbinfo); |
| 3372 | m_commandBuffer->EndRenderPass(); |
| 3373 | m_commandBuffer->EndCommandBuffer(); |
| 3374 | m_commandBuffer->QueueCommandBuffer(fence); |
| 3375 | |
| 3376 | VkImageObj destImage(m_device); |
| 3377 | destImage.init(100, 100, depth_stencil_fmt, |
| 3378 | VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT | |
| 3379 | VK_IMAGE_USAGE_TRANSFER_DST_BIT, |
| 3380 | VK_IMAGE_TILING_OPTIMAL, 0); |
| 3381 | VkImageMemoryBarrier barrier = {}; |
| 3382 | VkImageSubresourceRange range; |
| 3383 | barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER; |
| 3384 | barrier.srcAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT | |
| 3385 | VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT; |
| 3386 | barrier.dstAccessMask = VK_ACCESS_TRANSFER_READ_BIT | |
| 3387 | VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_READ_BIT; |
| 3388 | barrier.oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL; |
| 3389 | barrier.newLayout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL; |
| 3390 | barrier.image = m_depthStencil->handle(); |
| 3391 | range.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT; |
| 3392 | range.baseMipLevel = 0; |
| 3393 | range.levelCount = 1; |
| 3394 | range.baseArrayLayer = 0; |
| 3395 | range.layerCount = 1; |
| 3396 | barrier.subresourceRange = range; |
| 3397 | vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX); |
| 3398 | VkCommandBufferObj cmdbuf(m_device, m_commandPool); |
| 3399 | cmdbuf.BeginCommandBuffer(); |
| 3400 | cmdbuf.PipelineBarrier(VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, |
| 3401 | VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, nullptr, 0, |
| 3402 | nullptr, 1, &barrier); |
| 3403 | barrier.srcAccessMask = 0; |
| 3404 | barrier.oldLayout = VK_IMAGE_LAYOUT_UNDEFINED; |
| 3405 | barrier.newLayout = VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL; |
| 3406 | barrier.image = destImage.handle(); |
| 3407 | barrier.dstAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT | |
| 3408 | VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT; |
| 3409 | cmdbuf.PipelineBarrier(VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, |
| 3410 | VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, nullptr, 0, |
| 3411 | nullptr, 1, &barrier); |
| 3412 | VkImageCopy cregion; |
| 3413 | cregion.srcSubresource.aspectMask = |
| 3414 | VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT; |
| 3415 | cregion.srcSubresource.mipLevel = 0; |
| 3416 | cregion.srcSubresource.baseArrayLayer = 0; |
| 3417 | cregion.srcSubresource.layerCount = 1; |
| 3418 | cregion.srcOffset.x = 0; |
| 3419 | cregion.srcOffset.y = 0; |
| 3420 | cregion.srcOffset.z = 0; |
| 3421 | cregion.dstSubresource.aspectMask = |
| 3422 | VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT; |
| 3423 | cregion.dstSubresource.mipLevel = 0; |
| 3424 | cregion.dstSubresource.baseArrayLayer = 0; |
| 3425 | cregion.dstSubresource.layerCount = 1; |
| 3426 | cregion.dstOffset.x = 0; |
| 3427 | cregion.dstOffset.y = 0; |
| 3428 | cregion.dstOffset.z = 0; |
| 3429 | cregion.extent.width = 100; |
| 3430 | cregion.extent.height = 100; |
| 3431 | cregion.extent.depth = 1; |
| 3432 | cmdbuf.CopyImage(m_depthStencil->handle(), |
| 3433 | VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, destImage.handle(), |
| 3434 | VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &cregion); |
| 3435 | cmdbuf.EndCommandBuffer(); |
| 3436 | |
| 3437 | VkSubmitInfo submit_info; |
| 3438 | submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO; |
| 3439 | submit_info.pNext = NULL; |
| 3440 | submit_info.waitSemaphoreCount = 0; |
| 3441 | submit_info.pWaitSemaphores = NULL; |
| 3442 | submit_info.pWaitDstStageMask = NULL; |
| 3443 | submit_info.commandBufferCount = 1; |
| 3444 | submit_info.pCommandBuffers = &cmdbuf.handle(); |
| 3445 | submit_info.signalSemaphoreCount = 0; |
| 3446 | submit_info.pSignalSemaphores = NULL; |
| 3447 | |
| 3448 | m_errorMonitor->ExpectSuccess(); |
| 3449 | vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE); |
| 3450 | m_errorMonitor->VerifyNotFound(); |
| 3451 | |
Mark Lobodzinski | d0440da | 2016-06-17 15:10:03 -0600 | [diff] [blame] | 3452 | vkQueueWaitIdle(m_device->m_queue); |
Mark Lobodzinski | ce7eee7 | 2016-06-14 16:33:29 -0600 | [diff] [blame] | 3453 | vkDestroyFence(m_device->device(), fence, nullptr); |
| 3454 | vkDestroyRenderPass(m_device->device(), rp, nullptr); |
| 3455 | vkDestroyFramebuffer(m_device->device(), fb, nullptr); |
| 3456 | } |
| 3457 | |
Mark Lobodzinski | 6d17b9f | 2016-06-16 13:21:38 -0600 | [diff] [blame] | 3458 | TEST_F(VkLayerTest, UnusedPreserveAttachment) { |
| 3459 | TEST_DESCRIPTION("Create a framebuffer where a subpass has a preserve " |
| 3460 | "attachment reference of VK_ATTACHMENT_UNUSED"); |
| 3461 | |
| 3462 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 3463 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 3464 | |
| 3465 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 3466 | "must not be VK_ATTACHMENT_UNUSED"); |
| 3467 | |
| 3468 | VkAttachmentReference color_attach = {}; |
| 3469 | color_attach.layout = VK_IMAGE_LAYOUT_GENERAL; |
| 3470 | color_attach.attachment = 0; |
| 3471 | uint32_t preserve_attachment = VK_ATTACHMENT_UNUSED; |
| 3472 | VkSubpassDescription subpass = {}; |
| 3473 | subpass.colorAttachmentCount = 1; |
| 3474 | subpass.pColorAttachments = &color_attach; |
| 3475 | subpass.preserveAttachmentCount = 1; |
| 3476 | subpass.pPreserveAttachments = &preserve_attachment; |
| 3477 | |
| 3478 | VkRenderPassCreateInfo rpci = {}; |
| 3479 | rpci.subpassCount = 1; |
| 3480 | rpci.pSubpasses = &subpass; |
| 3481 | rpci.attachmentCount = 1; |
| 3482 | VkAttachmentDescription attach_desc = {}; |
| 3483 | attach_desc.format = VK_FORMAT_UNDEFINED; |
| 3484 | rpci.pAttachments = &attach_desc; |
| 3485 | rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO; |
| 3486 | VkRenderPass rp; |
Mark Lobodzinski | a4feeeb | 2016-06-17 12:00:46 -0600 | [diff] [blame] | 3487 | VkResult result = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp); |
Mark Lobodzinski | 6d17b9f | 2016-06-16 13:21:38 -0600 | [diff] [blame] | 3488 | |
| 3489 | m_errorMonitor->VerifyFound(); |
| 3490 | |
Mark Lobodzinski | a4feeeb | 2016-06-17 12:00:46 -0600 | [diff] [blame] | 3491 | if (result == VK_SUCCESS) { |
| 3492 | vkDestroyRenderPass(m_device->device(), rp, NULL); |
| 3493 | } |
Mark Lobodzinski | 6d17b9f | 2016-06-16 13:21:38 -0600 | [diff] [blame] | 3494 | } |
| 3495 | |
Chris Forbes | c538974 | 2016-06-29 11:49:23 +1200 | [diff] [blame] | 3496 | TEST_F(VkLayerTest, CreateRenderPassResolveRequiresColorMsaa) { |
Chris Forbes | 6655bb3 | 2016-07-01 18:27:30 +1200 | [diff] [blame] | 3497 | TEST_DESCRIPTION("Ensure that CreateRenderPass produces a validation error " |
| 3498 | "when the source of a subpass multisample resolve " |
| 3499 | "does not have multiple samples."); |
| 3500 | |
Chris Forbes | c538974 | 2016-06-29 11:49:23 +1200 | [diff] [blame] | 3501 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 3502 | |
| 3503 | m_errorMonitor->SetDesiredFailureMsg( |
| 3504 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Chris Forbes | 6655bb3 | 2016-07-01 18:27:30 +1200 | [diff] [blame] | 3505 | "Subpass 0 requests multisample resolve from attachment 0 which has " |
| 3506 | "VK_SAMPLE_COUNT_1_BIT"); |
Chris Forbes | c538974 | 2016-06-29 11:49:23 +1200 | [diff] [blame] | 3507 | |
| 3508 | VkAttachmentDescription attachments[] = { |
| 3509 | { |
| 3510 | 0, VK_FORMAT_R8G8B8A8_UNORM, |
| 3511 | VK_SAMPLE_COUNT_1_BIT, |
| 3512 | VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, |
| 3513 | VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, |
| 3514 | VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, |
| 3515 | VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL |
| 3516 | }, |
| 3517 | { |
| 3518 | 0, VK_FORMAT_R8G8B8A8_UNORM, |
| 3519 | VK_SAMPLE_COUNT_1_BIT, |
| 3520 | VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, |
| 3521 | VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, |
| 3522 | VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, |
| 3523 | VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL |
| 3524 | }, |
| 3525 | }; |
| 3526 | |
| 3527 | VkAttachmentReference color = { |
| 3528 | 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, |
| 3529 | }; |
| 3530 | |
| 3531 | VkAttachmentReference resolve = { |
| 3532 | 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, |
| 3533 | }; |
| 3534 | |
| 3535 | VkSubpassDescription subpass = { |
| 3536 | 0, VK_PIPELINE_BIND_POINT_GRAPHICS, |
| 3537 | 0, nullptr, |
| 3538 | 1, &color, |
| 3539 | &resolve, |
| 3540 | nullptr, |
| 3541 | 0, nullptr |
| 3542 | }; |
| 3543 | |
| 3544 | VkRenderPassCreateInfo rpci = { |
| 3545 | VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, |
| 3546 | 0, 2, attachments, 1, &subpass, 0, nullptr |
| 3547 | }; |
| 3548 | |
| 3549 | VkRenderPass rp; |
| 3550 | VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp); |
| 3551 | |
| 3552 | m_errorMonitor->VerifyFound(); |
| 3553 | |
| 3554 | if (err == VK_SUCCESS) |
| 3555 | vkDestroyRenderPass(m_device->device(), rp, nullptr); |
| 3556 | } |
| 3557 | |
| 3558 | TEST_F(VkLayerTest, CreateRenderPassResolveRequiresSingleSampleDest) { |
Chris Forbes | 6655bb3 | 2016-07-01 18:27:30 +1200 | [diff] [blame] | 3559 | TEST_DESCRIPTION("Ensure CreateRenderPass produces a validation error " |
| 3560 | "when a subpass multisample resolve operation is " |
| 3561 | "requested, and the destination of that resolve has " |
| 3562 | "multiple samples."); |
| 3563 | |
Chris Forbes | c538974 | 2016-06-29 11:49:23 +1200 | [diff] [blame] | 3564 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 3565 | |
| 3566 | m_errorMonitor->SetDesiredFailureMsg( |
| 3567 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 3568 | "Subpass 0 requests multisample resolve into attachment 1, which " |
| 3569 | "must have VK_SAMPLE_COUNT_1_BIT but has VK_SAMPLE_COUNT_4_BIT"); |
| 3570 | |
| 3571 | VkAttachmentDescription attachments[] = { |
| 3572 | { |
| 3573 | 0, VK_FORMAT_R8G8B8A8_UNORM, |
| 3574 | VK_SAMPLE_COUNT_4_BIT, |
| 3575 | VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, |
| 3576 | VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, |
| 3577 | VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, |
| 3578 | VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL |
| 3579 | }, |
| 3580 | { |
| 3581 | 0, VK_FORMAT_R8G8B8A8_UNORM, |
| 3582 | VK_SAMPLE_COUNT_4_BIT, |
| 3583 | VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, |
| 3584 | VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, |
| 3585 | VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, |
| 3586 | VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL |
| 3587 | }, |
| 3588 | }; |
| 3589 | |
| 3590 | VkAttachmentReference color = { |
| 3591 | 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, |
| 3592 | }; |
| 3593 | |
| 3594 | VkAttachmentReference resolve = { |
| 3595 | 1, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, |
| 3596 | }; |
| 3597 | |
| 3598 | VkSubpassDescription subpass = { |
| 3599 | 0, VK_PIPELINE_BIND_POINT_GRAPHICS, |
| 3600 | 0, nullptr, |
| 3601 | 1, &color, |
| 3602 | &resolve, |
| 3603 | nullptr, |
| 3604 | 0, nullptr |
| 3605 | }; |
| 3606 | |
| 3607 | VkRenderPassCreateInfo rpci = { |
| 3608 | VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, |
| 3609 | 0, 2, attachments, 1, &subpass, 0, nullptr |
| 3610 | }; |
| 3611 | |
| 3612 | VkRenderPass rp; |
| 3613 | VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp); |
| 3614 | |
| 3615 | m_errorMonitor->VerifyFound(); |
| 3616 | |
| 3617 | if (err == VK_SUCCESS) |
| 3618 | vkDestroyRenderPass(m_device->device(), rp, nullptr); |
| 3619 | } |
| 3620 | |
Chris Forbes | 3f128ef | 2016-06-29 14:58:53 +1200 | [diff] [blame] | 3621 | TEST_F(VkLayerTest, CreateRenderPassSubpassSampleCountConsistency) { |
Chris Forbes | 6655bb3 | 2016-07-01 18:27:30 +1200 | [diff] [blame] | 3622 | TEST_DESCRIPTION("Ensure CreateRenderPass produces a validation error " |
| 3623 | "when the color and depth attachments used by a subpass " |
| 3624 | "have inconsistent sample counts"); |
| 3625 | |
Chris Forbes | 3f128ef | 2016-06-29 14:58:53 +1200 | [diff] [blame] | 3626 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 3627 | |
| 3628 | m_errorMonitor->SetDesiredFailureMsg( |
| 3629 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 3630 | "Subpass 0 attempts to render to attachments with inconsistent sample counts"); |
| 3631 | |
| 3632 | VkAttachmentDescription attachments[] = { |
| 3633 | { |
| 3634 | 0, VK_FORMAT_R8G8B8A8_UNORM, |
| 3635 | VK_SAMPLE_COUNT_1_BIT, |
| 3636 | VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, |
| 3637 | VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, |
| 3638 | VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, |
| 3639 | VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL |
| 3640 | }, |
| 3641 | { |
| 3642 | 0, VK_FORMAT_R8G8B8A8_UNORM, |
| 3643 | VK_SAMPLE_COUNT_4_BIT, |
| 3644 | VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, |
| 3645 | VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, |
| 3646 | VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, |
| 3647 | VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL |
| 3648 | }, |
| 3649 | }; |
| 3650 | |
| 3651 | VkAttachmentReference color[] = { |
| 3652 | { |
| 3653 | 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, |
| 3654 | }, |
| 3655 | { |
| 3656 | 1, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, |
| 3657 | }, |
| 3658 | }; |
| 3659 | |
| 3660 | VkSubpassDescription subpass = { |
| 3661 | 0, VK_PIPELINE_BIND_POINT_GRAPHICS, |
| 3662 | 0, nullptr, |
| 3663 | 2, color, |
| 3664 | nullptr, |
| 3665 | nullptr, |
| 3666 | 0, nullptr |
| 3667 | }; |
| 3668 | |
| 3669 | VkRenderPassCreateInfo rpci = { |
| 3670 | VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, |
| 3671 | 0, 2, attachments, 1, &subpass, 0, nullptr |
| 3672 | }; |
| 3673 | |
| 3674 | VkRenderPass rp; |
| 3675 | VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp); |
| 3676 | |
| 3677 | m_errorMonitor->VerifyFound(); |
| 3678 | |
| 3679 | if (err == VK_SUCCESS) |
| 3680 | vkDestroyRenderPass(m_device->device(), rp, nullptr); |
| 3681 | } |
| 3682 | |
Tobin Ehlis | 2545e6f | 2016-06-22 10:42:19 -0600 | [diff] [blame] | 3683 | TEST_F(VkLayerTest, FramebufferCreateErrors) { |
| 3684 | TEST_DESCRIPTION("Hit errors when attempting to create a framebuffer :\n" |
| 3685 | " 1. Mismatch between fb & renderPass attachmentCount\n" |
Tobin Ehlis | d3bb23a | 2016-06-22 13:34:46 -0600 | [diff] [blame] | 3686 | " 2. Use a color image as depthStencil attachment\n" |
Tobin Ehlis | 77d717c | 2016-06-22 14:19:19 -0600 | [diff] [blame] | 3687 | " 3. Mismatch fb & renderPass attachment formats\n" |
Tobin Ehlis | 6cfda64 | 2016-06-22 16:12:58 -0600 | [diff] [blame] | 3688 | " 4. Mismatch fb & renderPass attachment #samples\n" |
Tobin Ehlis | 27f2ae8 | 2016-06-23 07:36:57 -0600 | [diff] [blame] | 3689 | " 5. FB attachment w/ non-1 mip-levels\n" |
Tobin Ehlis | b1f303b | 2016-06-23 08:19:55 -0600 | [diff] [blame] | 3690 | " 6. FB attachment where dimensions don't match\n" |
Tobin Ehlis | 08d4b5e | 2016-06-23 08:52:39 -0600 | [diff] [blame] | 3691 | " 7. FB attachment w/o identity swizzle\n" |
| 3692 | " 8. FB dimensions exceed physical device limits\n"); |
Mark Lobodzinski | 6d17b9f | 2016-06-16 13:21:38 -0600 | [diff] [blame] | 3693 | |
| 3694 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 3695 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 3696 | |
| 3697 | m_errorMonitor->SetDesiredFailureMsg( |
| 3698 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Tobin Ehlis | 2545e6f | 2016-06-22 10:42:19 -0600 | [diff] [blame] | 3699 | "vkCreateFramebuffer(): VkFramebufferCreateInfo attachmentCount of 2 " |
| 3700 | "does not match attachmentCount of 1 of "); |
Mark Lobodzinski | 6d17b9f | 2016-06-16 13:21:38 -0600 | [diff] [blame] | 3701 | |
Tobin Ehlis | 2545e6f | 2016-06-22 10:42:19 -0600 | [diff] [blame] | 3702 | // Create a renderPass with a single color attachment |
Mark Lobodzinski | 6d17b9f | 2016-06-16 13:21:38 -0600 | [diff] [blame] | 3703 | VkAttachmentReference attach = {}; |
| 3704 | attach.layout = VK_IMAGE_LAYOUT_GENERAL; |
| 3705 | VkSubpassDescription subpass = {}; |
Tobin Ehlis | 2545e6f | 2016-06-22 10:42:19 -0600 | [diff] [blame] | 3706 | subpass.pColorAttachments = &attach; |
Mark Lobodzinski | 6d17b9f | 2016-06-16 13:21:38 -0600 | [diff] [blame] | 3707 | VkRenderPassCreateInfo rpci = {}; |
| 3708 | rpci.subpassCount = 1; |
| 3709 | rpci.pSubpasses = &subpass; |
| 3710 | rpci.attachmentCount = 1; |
| 3711 | VkAttachmentDescription attach_desc = {}; |
Tobin Ehlis | d3bb23a | 2016-06-22 13:34:46 -0600 | [diff] [blame] | 3712 | attach_desc.format = VK_FORMAT_B8G8R8A8_UNORM; |
Tobin Ehlis | 77d717c | 2016-06-22 14:19:19 -0600 | [diff] [blame] | 3713 | attach_desc.samples = VK_SAMPLE_COUNT_1_BIT; |
Mark Lobodzinski | 6d17b9f | 2016-06-16 13:21:38 -0600 | [diff] [blame] | 3714 | rpci.pAttachments = &attach_desc; |
| 3715 | rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO; |
| 3716 | VkRenderPass rp; |
| 3717 | VkResult err = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp); |
| 3718 | ASSERT_VK_SUCCESS(err); |
| 3719 | |
Tobin Ehlis | 2545e6f | 2016-06-22 10:42:19 -0600 | [diff] [blame] | 3720 | VkImageView ivs[2]; |
| 3721 | ivs[0] = m_renderTargets[0]->targetView(VK_FORMAT_B8G8R8A8_UNORM); |
| 3722 | ivs[1] = m_renderTargets[0]->targetView(VK_FORMAT_B8G8R8A8_UNORM); |
Mark Lobodzinski | 6d17b9f | 2016-06-16 13:21:38 -0600 | [diff] [blame] | 3723 | VkFramebufferCreateInfo fb_info = {}; |
| 3724 | fb_info.sType = VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO; |
| 3725 | fb_info.pNext = NULL; |
| 3726 | fb_info.renderPass = rp; |
Tobin Ehlis | 2545e6f | 2016-06-22 10:42:19 -0600 | [diff] [blame] | 3727 | // Set mis-matching attachmentCount |
| 3728 | fb_info.attachmentCount = 2; |
| 3729 | fb_info.pAttachments = ivs; |
Mark Lobodzinski | 6d17b9f | 2016-06-16 13:21:38 -0600 | [diff] [blame] | 3730 | fb_info.width = 100; |
| 3731 | fb_info.height = 100; |
| 3732 | fb_info.layers = 1; |
| 3733 | |
| 3734 | VkFramebuffer fb; |
| 3735 | err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb); |
| 3736 | |
| 3737 | m_errorMonitor->VerifyFound(); |
Mark Lobodzinski | 6d17b9f | 2016-06-16 13:21:38 -0600 | [diff] [blame] | 3738 | if (err == VK_SUCCESS) { |
| 3739 | vkDestroyFramebuffer(m_device->device(), fb, NULL); |
| 3740 | } |
| 3741 | vkDestroyRenderPass(m_device->device(), rp, NULL); |
Tobin Ehlis | 2545e6f | 2016-06-22 10:42:19 -0600 | [diff] [blame] | 3742 | |
| 3743 | // Create a renderPass with a depth-stencil attachment created with |
| 3744 | // IMAGE_USAGE_COLOR_ATTACHMENT |
| 3745 | // Add our color attachment to pDepthStencilAttachment |
| 3746 | subpass.pDepthStencilAttachment = &attach; |
| 3747 | subpass.pColorAttachments = NULL; |
| 3748 | VkRenderPass rp_ds; |
| 3749 | err = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp_ds); |
| 3750 | ASSERT_VK_SUCCESS(err); |
| 3751 | // Set correct attachment count, but attachment has COLOR usage bit set |
| 3752 | fb_info.attachmentCount = 1; |
| 3753 | fb_info.renderPass = rp_ds; |
| 3754 | |
| 3755 | m_errorMonitor->SetDesiredFailureMsg( |
| 3756 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 3757 | " conflicts with the image's IMAGE_USAGE flags "); |
| 3758 | err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb); |
| 3759 | |
| 3760 | m_errorMonitor->VerifyFound(); |
| 3761 | if (err == VK_SUCCESS) { |
| 3762 | vkDestroyFramebuffer(m_device->device(), fb, NULL); |
| 3763 | } |
| 3764 | vkDestroyRenderPass(m_device->device(), rp_ds, NULL); |
Tobin Ehlis | d3bb23a | 2016-06-22 13:34:46 -0600 | [diff] [blame] | 3765 | |
| 3766 | // Create new renderpass with alternate attachment format from fb |
| 3767 | attach_desc.format = VK_FORMAT_R8G8B8A8_UNORM; |
| 3768 | subpass.pDepthStencilAttachment = NULL; |
| 3769 | subpass.pColorAttachments = &attach; |
| 3770 | err = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp); |
| 3771 | ASSERT_VK_SUCCESS(err); |
| 3772 | |
| 3773 | // Cause error due to mis-matched formats between rp & fb |
| 3774 | // rp attachment 0 now has RGBA8 but corresponding fb attach is BGRA8 |
| 3775 | fb_info.renderPass = rp; |
| 3776 | m_errorMonitor->SetDesiredFailureMsg( |
| 3777 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 3778 | " has format of VK_FORMAT_B8G8R8A8_UNORM that does not match "); |
| 3779 | err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb); |
| 3780 | |
| 3781 | m_errorMonitor->VerifyFound(); |
| 3782 | if (err == VK_SUCCESS) { |
| 3783 | vkDestroyFramebuffer(m_device->device(), fb, NULL); |
| 3784 | } |
Tobin Ehlis | 77d717c | 2016-06-22 14:19:19 -0600 | [diff] [blame] | 3785 | vkDestroyRenderPass(m_device->device(), rp, NULL); |
| 3786 | |
| 3787 | // Create new renderpass with alternate sample count from fb |
| 3788 | attach_desc.format = VK_FORMAT_B8G8R8A8_UNORM; |
| 3789 | attach_desc.samples = VK_SAMPLE_COUNT_4_BIT; |
| 3790 | err = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp); |
| 3791 | ASSERT_VK_SUCCESS(err); |
| 3792 | |
| 3793 | // Cause error due to mis-matched sample count between rp & fb |
| 3794 | fb_info.renderPass = rp; |
| 3795 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 3796 | " has VK_SAMPLE_COUNT_1_BIT samples " |
| 3797 | "that do not match the " |
| 3798 | "VK_SAMPLE_COUNT_4_BIT "); |
| 3799 | err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb); |
| 3800 | |
| 3801 | m_errorMonitor->VerifyFound(); |
| 3802 | if (err == VK_SUCCESS) { |
| 3803 | vkDestroyFramebuffer(m_device->device(), fb, NULL); |
| 3804 | } |
Tobin Ehlis | d3bb23a | 2016-06-22 13:34:46 -0600 | [diff] [blame] | 3805 | |
| 3806 | vkDestroyRenderPass(m_device->device(), rp, NULL); |
Tobin Ehlis | 6cfda64 | 2016-06-22 16:12:58 -0600 | [diff] [blame] | 3807 | |
| 3808 | // Create a custom imageView with non-1 mip levels |
| 3809 | VkImageObj image(m_device); |
| 3810 | image.init(128, 128, VK_FORMAT_B8G8R8A8_UNORM, |
| 3811 | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0); |
| 3812 | ASSERT_TRUE(image.initialized()); |
| 3813 | |
| 3814 | VkImageView view; |
| 3815 | VkImageViewCreateInfo ivci = {}; |
| 3816 | ivci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO; |
| 3817 | ivci.image = image.handle(); |
| 3818 | ivci.viewType = VK_IMAGE_VIEW_TYPE_2D; |
| 3819 | ivci.format = VK_FORMAT_B8G8R8A8_UNORM; |
| 3820 | ivci.subresourceRange.layerCount = 1; |
| 3821 | ivci.subresourceRange.baseMipLevel = 0; |
| 3822 | // Set level count 2 (only 1 is allowed for FB attachment) |
| 3823 | ivci.subresourceRange.levelCount = 2; |
| 3824 | ivci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; |
| 3825 | err = vkCreateImageView(m_device->device(), &ivci, NULL, &view); |
| 3826 | ASSERT_VK_SUCCESS(err); |
| 3827 | // Re-create renderpass to have matching sample count |
| 3828 | attach_desc.samples = VK_SAMPLE_COUNT_1_BIT; |
| 3829 | err = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp); |
| 3830 | ASSERT_VK_SUCCESS(err); |
| 3831 | |
| 3832 | fb_info.renderPass = rp; |
| 3833 | fb_info.pAttachments = &view; |
| 3834 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 3835 | " has mip levelCount of 2 but only "); |
| 3836 | err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb); |
| 3837 | |
| 3838 | m_errorMonitor->VerifyFound(); |
| 3839 | if (err == VK_SUCCESS) { |
| 3840 | vkDestroyFramebuffer(m_device->device(), fb, NULL); |
| 3841 | } |
Tobin Ehlis | 6cfda64 | 2016-06-22 16:12:58 -0600 | [diff] [blame] | 3842 | vkDestroyImageView(m_device->device(), view, NULL); |
Tobin Ehlis | 27f2ae8 | 2016-06-23 07:36:57 -0600 | [diff] [blame] | 3843 | // Update view to original color buffer and grow FB dimensions too big |
| 3844 | fb_info.pAttachments = ivs; |
| 3845 | fb_info.height = 1024; |
| 3846 | fb_info.width = 1024; |
| 3847 | fb_info.layers = 2; |
| 3848 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 3849 | " Attachment dimensions must be at " |
| 3850 | "least as large. "); |
| 3851 | err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb); |
| 3852 | |
| 3853 | m_errorMonitor->VerifyFound(); |
| 3854 | if (err == VK_SUCCESS) { |
| 3855 | vkDestroyFramebuffer(m_device->device(), fb, NULL); |
| 3856 | } |
Tobin Ehlis | b1f303b | 2016-06-23 08:19:55 -0600 | [diff] [blame] | 3857 | // Create view attachment with non-identity swizzle |
| 3858 | ivci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO; |
| 3859 | ivci.image = image.handle(); |
| 3860 | ivci.viewType = VK_IMAGE_VIEW_TYPE_2D; |
| 3861 | ivci.format = VK_FORMAT_B8G8R8A8_UNORM; |
| 3862 | ivci.subresourceRange.layerCount = 1; |
| 3863 | ivci.subresourceRange.baseMipLevel = 0; |
| 3864 | ivci.subresourceRange.levelCount = 1; |
| 3865 | ivci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; |
| 3866 | ivci.components.r = VK_COMPONENT_SWIZZLE_G; |
| 3867 | ivci.components.g = VK_COMPONENT_SWIZZLE_R; |
| 3868 | ivci.components.b = VK_COMPONENT_SWIZZLE_A; |
| 3869 | ivci.components.a = VK_COMPONENT_SWIZZLE_B; |
| 3870 | err = vkCreateImageView(m_device->device(), &ivci, NULL, &view); |
| 3871 | ASSERT_VK_SUCCESS(err); |
| 3872 | |
| 3873 | fb_info.pAttachments = &view; |
| 3874 | fb_info.height = 100; |
| 3875 | fb_info.width = 100; |
| 3876 | fb_info.layers = 1; |
| 3877 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 3878 | " has non-identy swizzle. All " |
| 3879 | "framebuffer attachments must have " |
| 3880 | "been created with the identity " |
| 3881 | "swizzle. "); |
| 3882 | err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb); |
| 3883 | |
| 3884 | m_errorMonitor->VerifyFound(); |
| 3885 | if (err == VK_SUCCESS) { |
| 3886 | vkDestroyFramebuffer(m_device->device(), fb, NULL); |
| 3887 | } |
| 3888 | vkDestroyImageView(m_device->device(), view, NULL); |
Tobin Ehlis | 08d4b5e | 2016-06-23 08:52:39 -0600 | [diff] [blame] | 3889 | // Request fb that exceeds max dimensions |
| 3890 | // reset attachment to color attachment |
| 3891 | fb_info.pAttachments = ivs; |
| 3892 | fb_info.width = m_device->props.limits.maxFramebufferWidth + 1; |
| 3893 | fb_info.height = m_device->props.limits.maxFramebufferHeight + 1; |
| 3894 | fb_info.layers = m_device->props.limits.maxFramebufferLayers + 1; |
| 3895 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 3896 | " Requested VkFramebufferCreateInfo " |
| 3897 | "dimensions exceed physical device " |
| 3898 | "limits. "); |
| 3899 | err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb); |
| 3900 | |
| 3901 | m_errorMonitor->VerifyFound(); |
| 3902 | if (err == VK_SUCCESS) { |
| 3903 | vkDestroyFramebuffer(m_device->device(), fb, NULL); |
| 3904 | } |
Tobin Ehlis | 27f2ae8 | 2016-06-23 07:36:57 -0600 | [diff] [blame] | 3905 | |
Tobin Ehlis | 6cfda64 | 2016-06-22 16:12:58 -0600 | [diff] [blame] | 3906 | vkDestroyRenderPass(m_device->device(), rp, NULL); |
Mark Lobodzinski | 6d17b9f | 2016-06-16 13:21:38 -0600 | [diff] [blame] | 3907 | } |
| 3908 | |
Mark Lobodzinski | c808d44 | 2016-04-14 10:57:23 -0600 | [diff] [blame] | 3909 | // This is a positive test. No errors should be generated. |
Michael Lentine | 860b0fe | 2016-05-20 10:14:00 -0500 | [diff] [blame] | 3910 | TEST_F(VkLayerTest, WaitEventThenSet) { |
| 3911 | TEST_DESCRIPTION( |
| 3912 | "Wait on a event then set it after the wait has been submitted."); |
| 3913 | |
Michael Lentine | 860b0fe | 2016-05-20 10:14:00 -0500 | [diff] [blame] | 3914 | m_errorMonitor->ExpectSuccess(); |
| 3915 | |
| 3916 | VkEvent event; |
| 3917 | VkEventCreateInfo event_create_info{}; |
| 3918 | event_create_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO; |
| 3919 | vkCreateEvent(m_device->device(), &event_create_info, nullptr, &event); |
| 3920 | |
| 3921 | VkCommandPool command_pool; |
| 3922 | VkCommandPoolCreateInfo pool_create_info{}; |
| 3923 | pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO; |
| 3924 | pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_; |
| 3925 | pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT; |
| 3926 | vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, |
| 3927 | &command_pool); |
| 3928 | |
| 3929 | VkCommandBuffer command_buffer; |
| 3930 | VkCommandBufferAllocateInfo command_buffer_allocate_info{}; |
| 3931 | command_buffer_allocate_info.sType = |
| 3932 | VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO; |
| 3933 | command_buffer_allocate_info.commandPool = command_pool; |
| 3934 | command_buffer_allocate_info.commandBufferCount = 1; |
| 3935 | command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY; |
| 3936 | vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, |
| 3937 | &command_buffer); |
| 3938 | |
| 3939 | VkQueue queue = VK_NULL_HANDLE; |
| 3940 | vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, |
Tony Barbour | fe302c0 | 2016-06-06 13:05:19 -0600 | [diff] [blame] | 3941 | 0, &queue); |
Michael Lentine | 860b0fe | 2016-05-20 10:14:00 -0500 | [diff] [blame] | 3942 | |
| 3943 | { |
| 3944 | VkCommandBufferBeginInfo begin_info{}; |
| 3945 | begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO; |
| 3946 | vkBeginCommandBuffer(command_buffer, &begin_info); |
| 3947 | |
| 3948 | vkCmdWaitEvents(command_buffer, 1, &event, VK_PIPELINE_STAGE_HOST_BIT, |
| 3949 | VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, nullptr, 0, |
| 3950 | nullptr, 0, nullptr); |
| 3951 | vkCmdResetEvent(command_buffer, event, |
| 3952 | VK_PIPELINE_STAGE_ALL_COMMANDS_BIT); |
| 3953 | vkEndCommandBuffer(command_buffer); |
| 3954 | } |
| 3955 | { |
| 3956 | VkSubmitInfo submit_info{}; |
| 3957 | submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO; |
| 3958 | submit_info.commandBufferCount = 1; |
| 3959 | submit_info.pCommandBuffers = &command_buffer; |
| 3960 | submit_info.signalSemaphoreCount = 0; |
| 3961 | submit_info.pSignalSemaphores = nullptr; |
| 3962 | vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE); |
| 3963 | } |
| 3964 | { vkSetEvent(m_device->device(), event); } |
| 3965 | |
| 3966 | vkQueueWaitIdle(queue); |
| 3967 | |
| 3968 | vkDestroyEvent(m_device->device(), event, nullptr); |
| 3969 | vkFreeCommandBuffers(m_device->device(), command_pool, 1, &command_buffer); |
| 3970 | vkDestroyCommandPool(m_device->device(), command_pool, NULL); |
| 3971 | |
| 3972 | m_errorMonitor->VerifyNotFound(); |
| 3973 | } |
Michael Lentine | 5627e69 | 2016-05-20 17:45:02 -0500 | [diff] [blame] | 3974 | // This is a positive test. No errors should be generated. |
| 3975 | TEST_F(VkLayerTest, QueryAndCopyMultipleCommandBuffers) { |
| 3976 | TEST_DESCRIPTION( |
| 3977 | "Issue a query and copy from it on a second command buffer."); |
| 3978 | |
| 3979 | if ((m_device->queue_props.empty()) || |
| 3980 | (m_device->queue_props[0].queueCount < 2)) |
| 3981 | return; |
| 3982 | |
| 3983 | m_errorMonitor->ExpectSuccess(); |
| 3984 | |
| 3985 | VkQueryPool query_pool; |
| 3986 | VkQueryPoolCreateInfo query_pool_create_info{}; |
| 3987 | query_pool_create_info.sType = VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO; |
| 3988 | query_pool_create_info.queryType = VK_QUERY_TYPE_TIMESTAMP; |
| 3989 | query_pool_create_info.queryCount = 1; |
| 3990 | vkCreateQueryPool(m_device->device(), &query_pool_create_info, nullptr, |
| 3991 | &query_pool); |
| 3992 | |
| 3993 | VkCommandPool command_pool; |
| 3994 | VkCommandPoolCreateInfo pool_create_info{}; |
| 3995 | pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO; |
| 3996 | pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_; |
| 3997 | pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT; |
| 3998 | vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, |
| 3999 | &command_pool); |
| 4000 | |
| 4001 | VkCommandBuffer command_buffer[2]; |
| 4002 | VkCommandBufferAllocateInfo command_buffer_allocate_info{}; |
| 4003 | command_buffer_allocate_info.sType = |
| 4004 | VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO; |
| 4005 | command_buffer_allocate_info.commandPool = command_pool; |
| 4006 | command_buffer_allocate_info.commandBufferCount = 2; |
| 4007 | command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY; |
| 4008 | vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, |
| 4009 | command_buffer); |
| 4010 | |
| 4011 | VkQueue queue = VK_NULL_HANDLE; |
| 4012 | vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, |
| 4013 | 1, &queue); |
| 4014 | |
| 4015 | uint32_t qfi = 0; |
| 4016 | VkBufferCreateInfo buff_create_info = {}; |
| 4017 | buff_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO; |
| 4018 | buff_create_info.size = 1024; |
| 4019 | buff_create_info.usage = VK_BUFFER_USAGE_TRANSFER_DST_BIT; |
| 4020 | buff_create_info.queueFamilyIndexCount = 1; |
| 4021 | buff_create_info.pQueueFamilyIndices = &qfi; |
| 4022 | |
| 4023 | VkResult err; |
| 4024 | VkBuffer buffer; |
| 4025 | err = vkCreateBuffer(m_device->device(), &buff_create_info, NULL, &buffer); |
| 4026 | ASSERT_VK_SUCCESS(err); |
| 4027 | VkMemoryAllocateInfo mem_alloc = {}; |
| 4028 | mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO; |
| 4029 | mem_alloc.pNext = NULL; |
| 4030 | mem_alloc.allocationSize = 1024; |
| 4031 | mem_alloc.memoryTypeIndex = 0; |
| 4032 | |
| 4033 | VkMemoryRequirements memReqs; |
| 4034 | vkGetBufferMemoryRequirements(m_device->device(), buffer, &memReqs); |
| 4035 | bool pass = |
| 4036 | m_device->phy().set_memory_type(memReqs.memoryTypeBits, &mem_alloc, 0); |
| 4037 | if (!pass) { |
| 4038 | vkDestroyBuffer(m_device->device(), buffer, NULL); |
| 4039 | return; |
| 4040 | } |
| 4041 | |
| 4042 | VkDeviceMemory mem; |
| 4043 | err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem); |
| 4044 | ASSERT_VK_SUCCESS(err); |
| 4045 | err = vkBindBufferMemory(m_device->device(), buffer, mem, 0); |
| 4046 | ASSERT_VK_SUCCESS(err); |
| 4047 | |
| 4048 | { |
| 4049 | VkCommandBufferBeginInfo begin_info{}; |
| 4050 | begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO; |
| 4051 | vkBeginCommandBuffer(command_buffer[0], &begin_info); |
| 4052 | |
| 4053 | vkCmdResetQueryPool(command_buffer[0], query_pool, 0, 1); |
| 4054 | vkCmdWriteTimestamp(command_buffer[0], |
| 4055 | VK_PIPELINE_STAGE_ALL_GRAPHICS_BIT, query_pool, 0); |
| 4056 | |
| 4057 | vkEndCommandBuffer(command_buffer[0]); |
| 4058 | |
| 4059 | vkBeginCommandBuffer(command_buffer[1], &begin_info); |
| 4060 | |
| 4061 | vkCmdCopyQueryPoolResults(command_buffer[1], query_pool, 0, 1, buffer, |
| 4062 | 0, 0, 0); |
| 4063 | |
| 4064 | vkEndCommandBuffer(command_buffer[1]); |
| 4065 | } |
| 4066 | { |
| 4067 | VkSubmitInfo submit_info{}; |
| 4068 | submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO; |
| 4069 | submit_info.commandBufferCount = 2; |
| 4070 | submit_info.pCommandBuffers = command_buffer; |
| 4071 | submit_info.signalSemaphoreCount = 0; |
| 4072 | submit_info.pSignalSemaphores = nullptr; |
| 4073 | vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE); |
| 4074 | } |
| 4075 | |
| 4076 | vkQueueWaitIdle(queue); |
| 4077 | |
| 4078 | vkDestroyQueryPool(m_device->device(), query_pool, nullptr); |
| 4079 | vkFreeCommandBuffers(m_device->device(), command_pool, 2, command_buffer); |
| 4080 | vkDestroyCommandPool(m_device->device(), command_pool, NULL); |
Tony Barbour | df4c004 | 2016-06-01 15:55:43 -0600 | [diff] [blame] | 4081 | vkDestroyBuffer(m_device->device(), buffer, NULL); |
| 4082 | vkFreeMemory(m_device->device(), mem, NULL); |
Michael Lentine | 5627e69 | 2016-05-20 17:45:02 -0500 | [diff] [blame] | 4083 | |
| 4084 | m_errorMonitor->VerifyNotFound(); |
| 4085 | } |
Michael Lentine | 860b0fe | 2016-05-20 10:14:00 -0500 | [diff] [blame] | 4086 | |
| 4087 | TEST_F(VkLayerTest, ResetEventThenSet) { |
| 4088 | TEST_DESCRIPTION( |
| 4089 | "Reset an event then set it after the reset has been submitted."); |
| 4090 | |
Michael Lentine | 860b0fe | 2016-05-20 10:14:00 -0500 | [diff] [blame] | 4091 | m_errorMonitor->ExpectSuccess(); |
| 4092 | |
| 4093 | VkEvent event; |
| 4094 | VkEventCreateInfo event_create_info{}; |
| 4095 | event_create_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO; |
| 4096 | vkCreateEvent(m_device->device(), &event_create_info, nullptr, &event); |
| 4097 | |
| 4098 | VkCommandPool command_pool; |
| 4099 | VkCommandPoolCreateInfo pool_create_info{}; |
| 4100 | pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO; |
| 4101 | pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_; |
| 4102 | pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT; |
| 4103 | vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, |
| 4104 | &command_pool); |
| 4105 | |
| 4106 | VkCommandBuffer command_buffer; |
| 4107 | VkCommandBufferAllocateInfo command_buffer_allocate_info{}; |
| 4108 | command_buffer_allocate_info.sType = |
| 4109 | VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO; |
| 4110 | command_buffer_allocate_info.commandPool = command_pool; |
| 4111 | command_buffer_allocate_info.commandBufferCount = 1; |
| 4112 | command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY; |
| 4113 | vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, |
| 4114 | &command_buffer); |
| 4115 | |
| 4116 | VkQueue queue = VK_NULL_HANDLE; |
| 4117 | vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, |
Tony Barbour | fe302c0 | 2016-06-06 13:05:19 -0600 | [diff] [blame] | 4118 | 0, &queue); |
Michael Lentine | 860b0fe | 2016-05-20 10:14:00 -0500 | [diff] [blame] | 4119 | |
| 4120 | { |
| 4121 | VkCommandBufferBeginInfo begin_info{}; |
| 4122 | begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO; |
| 4123 | vkBeginCommandBuffer(command_buffer, &begin_info); |
| 4124 | |
| 4125 | vkCmdResetEvent(command_buffer, event, |
| 4126 | VK_PIPELINE_STAGE_ALL_COMMANDS_BIT); |
| 4127 | vkCmdWaitEvents(command_buffer, 1, &event, |
| 4128 | VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, |
| 4129 | VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, nullptr, 0, |
| 4130 | nullptr, 0, nullptr); |
| 4131 | vkEndCommandBuffer(command_buffer); |
| 4132 | } |
| 4133 | { |
| 4134 | VkSubmitInfo submit_info{}; |
| 4135 | submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO; |
| 4136 | submit_info.commandBufferCount = 1; |
| 4137 | submit_info.pCommandBuffers = &command_buffer; |
| 4138 | submit_info.signalSemaphoreCount = 0; |
| 4139 | submit_info.pSignalSemaphores = nullptr; |
| 4140 | vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE); |
| 4141 | } |
| 4142 | { |
| 4143 | m_errorMonitor->SetDesiredFailureMsg( |
| 4144 | VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot call vkSetEvent() on event " |
| 4145 | "0x1 that is already in use by a " |
| 4146 | "command buffer."); |
| 4147 | vkSetEvent(m_device->device(), event); |
| 4148 | m_errorMonitor->VerifyFound(); |
| 4149 | } |
| 4150 | |
| 4151 | vkQueueWaitIdle(queue); |
| 4152 | |
| 4153 | vkDestroyEvent(m_device->device(), event, nullptr); |
| 4154 | vkFreeCommandBuffers(m_device->device(), command_pool, 1, &command_buffer); |
| 4155 | vkDestroyCommandPool(m_device->device(), command_pool, NULL); |
| 4156 | } |
| 4157 | |
| 4158 | // This is a positive test. No errors should be generated. |
Tobin Ehlis | 0bb263b | 2016-05-10 12:13:02 -0600 | [diff] [blame] | 4159 | TEST_F(VkLayerTest, TwoFencesThreeFrames) { |
| 4160 | TEST_DESCRIPTION("Two command buffers with two separate fences are each " |
| 4161 | "run through a Submit & WaitForFences cycle 3 times. This " |
| 4162 | "previously revealed a bug so running this positive test " |
| 4163 | "to prevent a regression."); |
| 4164 | m_errorMonitor->ExpectSuccess(); |
| 4165 | |
| 4166 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 4167 | VkQueue queue = VK_NULL_HANDLE; |
| 4168 | vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, |
| 4169 | 0, &queue); |
| 4170 | |
| 4171 | static const uint32_t NUM_OBJECTS = 2; |
| 4172 | static const uint32_t NUM_FRAMES = 3; |
| 4173 | VkCommandBuffer cmd_buffers[NUM_OBJECTS] = {}; |
| 4174 | VkFence fences[NUM_OBJECTS] = {}; |
| 4175 | |
| 4176 | VkCommandPool cmd_pool; |
| 4177 | VkCommandPoolCreateInfo cmd_pool_ci = {}; |
| 4178 | cmd_pool_ci.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO; |
| 4179 | cmd_pool_ci.queueFamilyIndex = m_device->graphics_queue_node_index_; |
| 4180 | cmd_pool_ci.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT; |
| 4181 | VkResult err = vkCreateCommandPool(m_device->device(), &cmd_pool_ci, |
| 4182 | nullptr, &cmd_pool); |
| 4183 | ASSERT_VK_SUCCESS(err); |
| 4184 | |
| 4185 | VkCommandBufferAllocateInfo cmd_buf_info = {}; |
| 4186 | cmd_buf_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO; |
| 4187 | cmd_buf_info.commandPool = cmd_pool; |
| 4188 | cmd_buf_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY; |
| 4189 | cmd_buf_info.commandBufferCount = 1; |
| 4190 | |
| 4191 | VkFenceCreateInfo fence_ci = {}; |
| 4192 | fence_ci.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO; |
| 4193 | fence_ci.pNext = nullptr; |
| 4194 | fence_ci.flags = 0; |
| 4195 | |
| 4196 | for (uint32_t i = 0; i < NUM_OBJECTS; ++i) { |
| 4197 | err = vkAllocateCommandBuffers(m_device->device(), &cmd_buf_info, |
| 4198 | &cmd_buffers[i]); |
| 4199 | ASSERT_VK_SUCCESS(err); |
| 4200 | err = vkCreateFence(m_device->device(), &fence_ci, nullptr, &fences[i]); |
| 4201 | ASSERT_VK_SUCCESS(err); |
| 4202 | } |
| 4203 | |
| 4204 | for (uint32_t frame = 0; frame < NUM_FRAMES; ++frame) { |
Tobin Ehlis | f902516 | 2016-05-26 06:55:21 -0600 | [diff] [blame] | 4205 | for (uint32_t obj = 0; obj < NUM_OBJECTS; ++obj) { |
| 4206 | // Create empty cmd buffer |
| 4207 | VkCommandBufferBeginInfo cmdBufBeginDesc = {}; |
| 4208 | cmdBufBeginDesc.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO; |
Tobin Ehlis | 0bb263b | 2016-05-10 12:13:02 -0600 | [diff] [blame] | 4209 | |
Tobin Ehlis | f902516 | 2016-05-26 06:55:21 -0600 | [diff] [blame] | 4210 | err = vkBeginCommandBuffer(cmd_buffers[obj], &cmdBufBeginDesc); |
| 4211 | ASSERT_VK_SUCCESS(err); |
| 4212 | err = vkEndCommandBuffer(cmd_buffers[obj]); |
| 4213 | ASSERT_VK_SUCCESS(err); |
Tobin Ehlis | 0bb263b | 2016-05-10 12:13:02 -0600 | [diff] [blame] | 4214 | |
Tobin Ehlis | f902516 | 2016-05-26 06:55:21 -0600 | [diff] [blame] | 4215 | VkSubmitInfo submit_info = {}; |
| 4216 | submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO; |
| 4217 | submit_info.commandBufferCount = 1; |
| 4218 | submit_info.pCommandBuffers = &cmd_buffers[obj]; |
| 4219 | // Submit cmd buffer and wait for fence |
| 4220 | err = vkQueueSubmit(queue, 1, &submit_info, fences[obj]); |
| 4221 | ASSERT_VK_SUCCESS(err); |
| 4222 | err = vkWaitForFences(m_device->device(), 1, &fences[obj], VK_TRUE, |
| 4223 | UINT64_MAX); |
| 4224 | ASSERT_VK_SUCCESS(err); |
| 4225 | err = vkResetFences(m_device->device(), 1, &fences[obj]); |
| 4226 | ASSERT_VK_SUCCESS(err); |
| 4227 | } |
Tobin Ehlis | 0bb263b | 2016-05-10 12:13:02 -0600 | [diff] [blame] | 4228 | } |
| 4229 | m_errorMonitor->VerifyNotFound(); |
Tony Barbour | df4c004 | 2016-06-01 15:55:43 -0600 | [diff] [blame] | 4230 | vkDestroyCommandPool(m_device->device(), cmd_pool, NULL); |
| 4231 | for (uint32_t i = 0; i < NUM_OBJECTS; ++i) { |
| 4232 | vkDestroyFence(m_device->device(), fences[i], nullptr); |
| 4233 | } |
Tobin Ehlis | 0bb263b | 2016-05-10 12:13:02 -0600 | [diff] [blame] | 4234 | } |
| 4235 | // This is a positive test. No errors should be generated. |
Mark Lobodzinski | c808d44 | 2016-04-14 10:57:23 -0600 | [diff] [blame] | 4236 | TEST_F(VkLayerTest, TwoQueueSubmitsSeparateQueuesWithSemaphoreAndOneFenceQWI) { |
| 4237 | |
| 4238 | TEST_DESCRIPTION("Two command buffers, each in a separate QueueSubmit call " |
| 4239 | "submitted on separate queues followed by a QueueWaitIdle."); |
| 4240 | |
Dustin Graves | 4845814 | 2016-04-29 16:11:55 -0600 | [diff] [blame] | 4241 | if ((m_device->queue_props.empty()) || |
| 4242 | (m_device->queue_props[0].queueCount < 2)) |
Tony Barbour | dc18b26 | 2016-04-22 14:49:48 -0600 | [diff] [blame] | 4243 | return; |
| 4244 | |
Mark Lobodzinski | c808d44 | 2016-04-14 10:57:23 -0600 | [diff] [blame] | 4245 | m_errorMonitor->ExpectSuccess(); |
| 4246 | |
| 4247 | VkSemaphore semaphore; |
| 4248 | VkSemaphoreCreateInfo semaphore_create_info{}; |
| 4249 | semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO; |
| 4250 | vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, |
| 4251 | &semaphore); |
| 4252 | |
| 4253 | VkCommandPool command_pool; |
| 4254 | VkCommandPoolCreateInfo pool_create_info{}; |
| 4255 | pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO; |
| 4256 | pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_; |
| 4257 | pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT; |
| 4258 | vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, |
| 4259 | &command_pool); |
| 4260 | |
| 4261 | VkCommandBuffer command_buffer[2]; |
| 4262 | VkCommandBufferAllocateInfo command_buffer_allocate_info{}; |
| 4263 | command_buffer_allocate_info.sType = |
| 4264 | VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO; |
| 4265 | command_buffer_allocate_info.commandPool = command_pool; |
| 4266 | command_buffer_allocate_info.commandBufferCount = 2; |
| 4267 | command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY; |
| 4268 | vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, |
| 4269 | command_buffer); |
| 4270 | |
| 4271 | VkQueue queue = VK_NULL_HANDLE; |
| 4272 | vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, |
| 4273 | 1, &queue); |
| 4274 | |
| 4275 | { |
| 4276 | VkCommandBufferBeginInfo begin_info{}; |
| 4277 | begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO; |
| 4278 | vkBeginCommandBuffer(command_buffer[0], &begin_info); |
| 4279 | |
| 4280 | vkCmdPipelineBarrier(command_buffer[0], |
| 4281 | VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, |
| 4282 | VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, nullptr, |
| 4283 | 0, nullptr, 0, nullptr); |
| 4284 | |
| 4285 | VkViewport viewport{}; |
| 4286 | viewport.maxDepth = 1.0f; |
| 4287 | viewport.minDepth = 0.0f; |
| 4288 | viewport.width = 512; |
| 4289 | viewport.height = 512; |
| 4290 | viewport.x = 0; |
| 4291 | viewport.y = 0; |
| 4292 | vkCmdSetViewport(command_buffer[0], 0, 1, &viewport); |
| 4293 | vkEndCommandBuffer(command_buffer[0]); |
| 4294 | } |
| 4295 | { |
| 4296 | VkCommandBufferBeginInfo begin_info{}; |
| 4297 | begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO; |
| 4298 | vkBeginCommandBuffer(command_buffer[1], &begin_info); |
| 4299 | |
| 4300 | VkViewport viewport{}; |
| 4301 | viewport.maxDepth = 1.0f; |
| 4302 | viewport.minDepth = 0.0f; |
| 4303 | viewport.width = 512; |
| 4304 | viewport.height = 512; |
| 4305 | viewport.x = 0; |
| 4306 | viewport.y = 0; |
| 4307 | vkCmdSetViewport(command_buffer[1], 0, 1, &viewport); |
| 4308 | vkEndCommandBuffer(command_buffer[1]); |
| 4309 | } |
| 4310 | { |
| 4311 | VkSubmitInfo submit_info{}; |
| 4312 | submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO; |
| 4313 | submit_info.commandBufferCount = 1; |
| 4314 | submit_info.pCommandBuffers = &command_buffer[0]; |
| 4315 | submit_info.signalSemaphoreCount = 1; |
| 4316 | submit_info.pSignalSemaphores = &semaphore; |
| 4317 | vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE); |
| 4318 | } |
| 4319 | { |
| 4320 | VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT}; |
| 4321 | VkSubmitInfo submit_info{}; |
| 4322 | submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO; |
| 4323 | submit_info.commandBufferCount = 1; |
| 4324 | submit_info.pCommandBuffers = &command_buffer[1]; |
| 4325 | submit_info.waitSemaphoreCount = 1; |
| 4326 | submit_info.pWaitSemaphores = &semaphore; |
| 4327 | submit_info.pWaitDstStageMask = flags; |
| 4328 | vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE); |
| 4329 | } |
| 4330 | |
| 4331 | vkQueueWaitIdle(m_device->m_queue); |
| 4332 | |
| 4333 | vkDestroySemaphore(m_device->device(), semaphore, nullptr); |
| 4334 | vkFreeCommandBuffers(m_device->device(), command_pool, 2, |
| 4335 | &command_buffer[0]); |
| 4336 | vkDestroyCommandPool(m_device->device(), command_pool, NULL); |
| 4337 | |
| 4338 | m_errorMonitor->VerifyNotFound(); |
| 4339 | } |
| 4340 | |
| 4341 | // This is a positive test. No errors should be generated. |
| 4342 | TEST_F(VkLayerTest, TwoQueueSubmitsSeparateQueuesWithSemaphoreAndOneFenceQWIFence) { |
| 4343 | |
| 4344 | TEST_DESCRIPTION("Two command buffers, each in a separate QueueSubmit call " |
| 4345 | "submitted on separate queues, the second having a fence" |
| 4346 | "followed by a QueueWaitIdle."); |
| 4347 | |
Dustin Graves | 4845814 | 2016-04-29 16:11:55 -0600 | [diff] [blame] | 4348 | if ((m_device->queue_props.empty()) || |
| 4349 | (m_device->queue_props[0].queueCount < 2)) |
Tony Barbour | dc18b26 | 2016-04-22 14:49:48 -0600 | [diff] [blame] | 4350 | return; |
| 4351 | |
Mark Lobodzinski | c808d44 | 2016-04-14 10:57:23 -0600 | [diff] [blame] | 4352 | m_errorMonitor->ExpectSuccess(); |
| 4353 | |
| 4354 | VkFence fence; |
| 4355 | VkFenceCreateInfo fence_create_info{}; |
| 4356 | fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO; |
| 4357 | vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence); |
| 4358 | |
| 4359 | VkSemaphore semaphore; |
| 4360 | VkSemaphoreCreateInfo semaphore_create_info{}; |
| 4361 | semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO; |
| 4362 | vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, |
| 4363 | &semaphore); |
| 4364 | |
| 4365 | VkCommandPool command_pool; |
| 4366 | VkCommandPoolCreateInfo pool_create_info{}; |
| 4367 | pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO; |
| 4368 | pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_; |
| 4369 | pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT; |
| 4370 | vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, |
| 4371 | &command_pool); |
| 4372 | |
| 4373 | VkCommandBuffer command_buffer[2]; |
| 4374 | VkCommandBufferAllocateInfo command_buffer_allocate_info{}; |
| 4375 | command_buffer_allocate_info.sType = |
| 4376 | VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO; |
| 4377 | command_buffer_allocate_info.commandPool = command_pool; |
| 4378 | command_buffer_allocate_info.commandBufferCount = 2; |
| 4379 | command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY; |
| 4380 | vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, |
| 4381 | command_buffer); |
| 4382 | |
| 4383 | VkQueue queue = VK_NULL_HANDLE; |
| 4384 | vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, |
| 4385 | 1, &queue); |
| 4386 | |
| 4387 | { |
| 4388 | VkCommandBufferBeginInfo begin_info{}; |
| 4389 | begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO; |
| 4390 | vkBeginCommandBuffer(command_buffer[0], &begin_info); |
| 4391 | |
| 4392 | vkCmdPipelineBarrier(command_buffer[0], |
| 4393 | VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, |
| 4394 | VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, nullptr, |
| 4395 | 0, nullptr, 0, nullptr); |
| 4396 | |
| 4397 | VkViewport viewport{}; |
| 4398 | viewport.maxDepth = 1.0f; |
| 4399 | viewport.minDepth = 0.0f; |
| 4400 | viewport.width = 512; |
| 4401 | viewport.height = 512; |
| 4402 | viewport.x = 0; |
| 4403 | viewport.y = 0; |
| 4404 | vkCmdSetViewport(command_buffer[0], 0, 1, &viewport); |
| 4405 | vkEndCommandBuffer(command_buffer[0]); |
| 4406 | } |
| 4407 | { |
| 4408 | VkCommandBufferBeginInfo begin_info{}; |
| 4409 | begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO; |
| 4410 | vkBeginCommandBuffer(command_buffer[1], &begin_info); |
| 4411 | |
| 4412 | VkViewport viewport{}; |
| 4413 | viewport.maxDepth = 1.0f; |
| 4414 | viewport.minDepth = 0.0f; |
| 4415 | viewport.width = 512; |
| 4416 | viewport.height = 512; |
| 4417 | viewport.x = 0; |
| 4418 | viewport.y = 0; |
| 4419 | vkCmdSetViewport(command_buffer[1], 0, 1, &viewport); |
| 4420 | vkEndCommandBuffer(command_buffer[1]); |
| 4421 | } |
| 4422 | { |
| 4423 | VkSubmitInfo submit_info{}; |
| 4424 | submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO; |
| 4425 | submit_info.commandBufferCount = 1; |
| 4426 | submit_info.pCommandBuffers = &command_buffer[0]; |
| 4427 | submit_info.signalSemaphoreCount = 1; |
| 4428 | submit_info.pSignalSemaphores = &semaphore; |
| 4429 | vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE); |
| 4430 | } |
| 4431 | { |
| 4432 | VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT}; |
| 4433 | VkSubmitInfo submit_info{}; |
| 4434 | submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO; |
| 4435 | submit_info.commandBufferCount = 1; |
| 4436 | submit_info.pCommandBuffers = &command_buffer[1]; |
| 4437 | submit_info.waitSemaphoreCount = 1; |
| 4438 | submit_info.pWaitSemaphores = &semaphore; |
| 4439 | submit_info.pWaitDstStageMask = flags; |
| 4440 | vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence); |
| 4441 | } |
| 4442 | |
| 4443 | vkQueueWaitIdle(m_device->m_queue); |
| 4444 | |
| 4445 | vkDestroyFence(m_device->device(), fence, nullptr); |
| 4446 | vkDestroySemaphore(m_device->device(), semaphore, nullptr); |
| 4447 | vkFreeCommandBuffers(m_device->device(), command_pool, 2, |
| 4448 | &command_buffer[0]); |
| 4449 | vkDestroyCommandPool(m_device->device(), command_pool, NULL); |
| 4450 | |
| 4451 | m_errorMonitor->VerifyNotFound(); |
| 4452 | } |
| 4453 | |
| 4454 | // This is a positive test. No errors should be generated. |
| 4455 | TEST_F(VkLayerTest, |
| 4456 | TwoQueueSubmitsSeparateQueuesWithSemaphoreAndOneFenceTwoWFF) { |
| 4457 | |
| 4458 | TEST_DESCRIPTION( |
| 4459 | "Two command buffers, each in a separate QueueSubmit call " |
| 4460 | "submitted on separate queues, the second having a fence" |
| 4461 | "followed by two consecutive WaitForFences calls on the same fence."); |
| 4462 | |
Dustin Graves | 4845814 | 2016-04-29 16:11:55 -0600 | [diff] [blame] | 4463 | if ((m_device->queue_props.empty()) || |
| 4464 | (m_device->queue_props[0].queueCount < 2)) |
Tony Barbour | dc18b26 | 2016-04-22 14:49:48 -0600 | [diff] [blame] | 4465 | return; |
| 4466 | |
Mark Lobodzinski | c808d44 | 2016-04-14 10:57:23 -0600 | [diff] [blame] | 4467 | m_errorMonitor->ExpectSuccess(); |
| 4468 | |
| 4469 | VkFence fence; |
| 4470 | VkFenceCreateInfo fence_create_info{}; |
| 4471 | fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO; |
| 4472 | vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence); |
| 4473 | |
| 4474 | VkSemaphore semaphore; |
| 4475 | VkSemaphoreCreateInfo semaphore_create_info{}; |
| 4476 | semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO; |
| 4477 | vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, |
| 4478 | &semaphore); |
| 4479 | |
| 4480 | VkCommandPool command_pool; |
| 4481 | VkCommandPoolCreateInfo pool_create_info{}; |
| 4482 | pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO; |
| 4483 | pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_; |
| 4484 | pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT; |
| 4485 | vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, |
| 4486 | &command_pool); |
| 4487 | |
| 4488 | VkCommandBuffer command_buffer[2]; |
| 4489 | VkCommandBufferAllocateInfo command_buffer_allocate_info{}; |
| 4490 | command_buffer_allocate_info.sType = |
| 4491 | VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO; |
| 4492 | command_buffer_allocate_info.commandPool = command_pool; |
| 4493 | command_buffer_allocate_info.commandBufferCount = 2; |
| 4494 | command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY; |
| 4495 | vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, |
| 4496 | command_buffer); |
| 4497 | |
| 4498 | VkQueue queue = VK_NULL_HANDLE; |
| 4499 | vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, |
| 4500 | 1, &queue); |
| 4501 | |
| 4502 | { |
| 4503 | VkCommandBufferBeginInfo begin_info{}; |
| 4504 | begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO; |
| 4505 | vkBeginCommandBuffer(command_buffer[0], &begin_info); |
| 4506 | |
| 4507 | vkCmdPipelineBarrier(command_buffer[0], |
| 4508 | VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, |
| 4509 | VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, nullptr, |
| 4510 | 0, nullptr, 0, nullptr); |
| 4511 | |
| 4512 | VkViewport viewport{}; |
| 4513 | viewport.maxDepth = 1.0f; |
| 4514 | viewport.minDepth = 0.0f; |
| 4515 | viewport.width = 512; |
| 4516 | viewport.height = 512; |
| 4517 | viewport.x = 0; |
| 4518 | viewport.y = 0; |
| 4519 | vkCmdSetViewport(command_buffer[0], 0, 1, &viewport); |
| 4520 | vkEndCommandBuffer(command_buffer[0]); |
| 4521 | } |
| 4522 | { |
| 4523 | VkCommandBufferBeginInfo begin_info{}; |
| 4524 | begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO; |
| 4525 | vkBeginCommandBuffer(command_buffer[1], &begin_info); |
| 4526 | |
| 4527 | VkViewport viewport{}; |
| 4528 | viewport.maxDepth = 1.0f; |
| 4529 | viewport.minDepth = 0.0f; |
| 4530 | viewport.width = 512; |
| 4531 | viewport.height = 512; |
| 4532 | viewport.x = 0; |
| 4533 | viewport.y = 0; |
| 4534 | vkCmdSetViewport(command_buffer[1], 0, 1, &viewport); |
| 4535 | vkEndCommandBuffer(command_buffer[1]); |
| 4536 | } |
| 4537 | { |
| 4538 | VkSubmitInfo submit_info{}; |
| 4539 | submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO; |
| 4540 | submit_info.commandBufferCount = 1; |
| 4541 | submit_info.pCommandBuffers = &command_buffer[0]; |
| 4542 | submit_info.signalSemaphoreCount = 1; |
| 4543 | submit_info.pSignalSemaphores = &semaphore; |
| 4544 | vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE); |
| 4545 | } |
| 4546 | { |
| 4547 | VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT}; |
| 4548 | VkSubmitInfo submit_info{}; |
| 4549 | submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO; |
| 4550 | submit_info.commandBufferCount = 1; |
| 4551 | submit_info.pCommandBuffers = &command_buffer[1]; |
| 4552 | submit_info.waitSemaphoreCount = 1; |
| 4553 | submit_info.pWaitSemaphores = &semaphore; |
| 4554 | submit_info.pWaitDstStageMask = flags; |
| 4555 | vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence); |
| 4556 | } |
| 4557 | |
| 4558 | vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX); |
| 4559 | vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX); |
| 4560 | |
| 4561 | vkDestroyFence(m_device->device(), fence, nullptr); |
| 4562 | vkDestroySemaphore(m_device->device(), semaphore, nullptr); |
| 4563 | vkFreeCommandBuffers(m_device->device(), command_pool, 2, |
| 4564 | &command_buffer[0]); |
| 4565 | vkDestroyCommandPool(m_device->device(), command_pool, NULL); |
| 4566 | |
| 4567 | m_errorMonitor->VerifyNotFound(); |
| 4568 | } |
| 4569 | |
Chris Forbes | 0f8126b | 2016-06-20 17:48:22 +1200 | [diff] [blame] | 4570 | #if 0 |
| 4571 | TEST_F(VkLayerTest, TwoQueuesEnsureCorrectRetirementWithWorkStolen) { |
| 4572 | if ((m_device->queue_props.empty()) || |
| 4573 | (m_device->queue_props[0].queueCount < 2)) { |
| 4574 | printf("Test requires two queues, skipping\n"); |
| 4575 | return; |
| 4576 | } |
| 4577 | |
| 4578 | VkResult err; |
| 4579 | |
| 4580 | m_errorMonitor->ExpectSuccess(); |
| 4581 | |
| 4582 | VkQueue q0 = m_device->m_queue; |
| 4583 | VkQueue q1 = nullptr; |
| 4584 | vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &q1); |
| 4585 | ASSERT_NE(q1, nullptr); |
| 4586 | |
| 4587 | // An (empty) command buffer. We must have work in the first submission -- |
| 4588 | // the layer treats unfenced work differently from fenced work. |
| 4589 | VkCommandPoolCreateInfo cpci = { VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO, nullptr, 0, 0 }; |
| 4590 | VkCommandPool pool; |
| 4591 | err = vkCreateCommandPool(m_device->device(), &cpci, nullptr, &pool); |
| 4592 | ASSERT_VK_SUCCESS(err); |
| 4593 | VkCommandBufferAllocateInfo cbai = { VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO, nullptr, |
| 4594 | pool, VK_COMMAND_BUFFER_LEVEL_PRIMARY, 1 |
| 4595 | }; |
| 4596 | VkCommandBuffer cb; |
| 4597 | err = vkAllocateCommandBuffers(m_device->device(), &cbai, &cb); |
| 4598 | ASSERT_VK_SUCCESS(err); |
| 4599 | VkCommandBufferBeginInfo cbbi = { VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO, nullptr, |
| 4600 | 0, nullptr |
| 4601 | }; |
| 4602 | err = vkBeginCommandBuffer(cb, &cbbi); |
| 4603 | ASSERT_VK_SUCCESS(err); |
| 4604 | err = vkEndCommandBuffer(cb); |
| 4605 | ASSERT_VK_SUCCESS(err); |
| 4606 | |
| 4607 | // A semaphore |
| 4608 | VkSemaphoreCreateInfo sci = { VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO, nullptr, 0 }; |
| 4609 | VkSemaphore s; |
| 4610 | err = vkCreateSemaphore(m_device->device(), &sci, nullptr, &s); |
| 4611 | ASSERT_VK_SUCCESS(err); |
| 4612 | |
| 4613 | // First submission, to q0 |
| 4614 | VkSubmitInfo s0 = { |
| 4615 | VK_STRUCTURE_TYPE_SUBMIT_INFO, nullptr, |
| 4616 | 0, nullptr, nullptr, |
| 4617 | 1, &cb, |
| 4618 | 1, &s |
| 4619 | }; |
| 4620 | |
| 4621 | err = vkQueueSubmit(q0, 1, &s0, VK_NULL_HANDLE); |
| 4622 | ASSERT_VK_SUCCESS(err); |
| 4623 | |
| 4624 | // Second submission, to q1, waiting on s |
| 4625 | VkFlags waitmask = VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT; // doesn't really matter what this value is. |
| 4626 | VkSubmitInfo s1 = { |
| 4627 | VK_STRUCTURE_TYPE_SUBMIT_INFO, nullptr, |
| 4628 | 1, &s, &waitmask, |
| 4629 | 0, nullptr, |
| 4630 | 0, nullptr |
| 4631 | }; |
| 4632 | |
| 4633 | err = vkQueueSubmit(q1, 1, &s1, VK_NULL_HANDLE); |
| 4634 | ASSERT_VK_SUCCESS(err); |
| 4635 | |
| 4636 | // Wait for q0 idle |
| 4637 | err = vkQueueWaitIdle(q0); |
| 4638 | ASSERT_VK_SUCCESS(err); |
| 4639 | |
| 4640 | // Command buffer should have been completed (it was on q0); reset the pool. |
| 4641 | vkFreeCommandBuffers(m_device->device(), pool, 1, &cb); |
| 4642 | |
| 4643 | m_errorMonitor->VerifyNotFound(); |
| 4644 | |
| 4645 | // Force device completely idle and clean up resources |
| 4646 | vkDeviceWaitIdle(m_device->device()); |
| 4647 | vkDestroyCommandPool(m_device->device(), pool, nullptr); |
| 4648 | vkDestroySemaphore(m_device->device(), s, nullptr); |
| 4649 | } |
| 4650 | #endif |
| 4651 | |
Mark Lobodzinski | c808d44 | 2016-04-14 10:57:23 -0600 | [diff] [blame] | 4652 | // This is a positive test. No errors should be generated. |
| 4653 | TEST_F(VkLayerTest, TwoQueueSubmitsSeparateQueuesWithSemaphoreAndOneFence) { |
| 4654 | |
| 4655 | TEST_DESCRIPTION("Two command buffers, each in a separate QueueSubmit call " |
| 4656 | "submitted on separate queues, the second having a fence, " |
| 4657 | "followed by a WaitForFences call."); |
| 4658 | |
Dustin Graves | 4845814 | 2016-04-29 16:11:55 -0600 | [diff] [blame] | 4659 | if ((m_device->queue_props.empty()) || |
| 4660 | (m_device->queue_props[0].queueCount < 2)) |
Tony Barbour | dc18b26 | 2016-04-22 14:49:48 -0600 | [diff] [blame] | 4661 | return; |
| 4662 | |
Mark Lobodzinski | c808d44 | 2016-04-14 10:57:23 -0600 | [diff] [blame] | 4663 | m_errorMonitor->ExpectSuccess(); |
| 4664 | |
| 4665 | VkFence fence; |
| 4666 | VkFenceCreateInfo fence_create_info{}; |
| 4667 | fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO; |
| 4668 | vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence); |
| 4669 | |
| 4670 | VkSemaphore semaphore; |
| 4671 | VkSemaphoreCreateInfo semaphore_create_info{}; |
| 4672 | semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO; |
| 4673 | vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, |
| 4674 | &semaphore); |
| 4675 | |
| 4676 | VkCommandPool command_pool; |
| 4677 | VkCommandPoolCreateInfo pool_create_info{}; |
| 4678 | pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO; |
| 4679 | pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_; |
| 4680 | pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT; |
| 4681 | vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, |
| 4682 | &command_pool); |
| 4683 | |
| 4684 | VkCommandBuffer command_buffer[2]; |
| 4685 | VkCommandBufferAllocateInfo command_buffer_allocate_info{}; |
| 4686 | command_buffer_allocate_info.sType = |
| 4687 | VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO; |
| 4688 | command_buffer_allocate_info.commandPool = command_pool; |
| 4689 | command_buffer_allocate_info.commandBufferCount = 2; |
| 4690 | command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY; |
| 4691 | vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, |
| 4692 | command_buffer); |
| 4693 | |
| 4694 | VkQueue queue = VK_NULL_HANDLE; |
| 4695 | vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, |
| 4696 | 1, &queue); |
| 4697 | |
| 4698 | |
| 4699 | { |
| 4700 | VkCommandBufferBeginInfo begin_info{}; |
| 4701 | begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO; |
| 4702 | vkBeginCommandBuffer(command_buffer[0], &begin_info); |
| 4703 | |
| 4704 | vkCmdPipelineBarrier(command_buffer[0], |
| 4705 | VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, |
| 4706 | VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, nullptr, |
| 4707 | 0, nullptr, 0, nullptr); |
| 4708 | |
| 4709 | VkViewport viewport{}; |
| 4710 | viewport.maxDepth = 1.0f; |
| 4711 | viewport.minDepth = 0.0f; |
| 4712 | viewport.width = 512; |
| 4713 | viewport.height = 512; |
| 4714 | viewport.x = 0; |
| 4715 | viewport.y = 0; |
| 4716 | vkCmdSetViewport(command_buffer[0], 0, 1, &viewport); |
| 4717 | vkEndCommandBuffer(command_buffer[0]); |
| 4718 | } |
| 4719 | { |
| 4720 | VkCommandBufferBeginInfo begin_info{}; |
| 4721 | begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO; |
| 4722 | vkBeginCommandBuffer(command_buffer[1], &begin_info); |
| 4723 | |
| 4724 | VkViewport viewport{}; |
| 4725 | viewport.maxDepth = 1.0f; |
| 4726 | viewport.minDepth = 0.0f; |
| 4727 | viewport.width = 512; |
| 4728 | viewport.height = 512; |
| 4729 | viewport.x = 0; |
| 4730 | viewport.y = 0; |
| 4731 | vkCmdSetViewport(command_buffer[1], 0, 1, &viewport); |
| 4732 | vkEndCommandBuffer(command_buffer[1]); |
| 4733 | } |
| 4734 | { |
| 4735 | VkSubmitInfo submit_info{}; |
| 4736 | submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO; |
| 4737 | submit_info.commandBufferCount = 1; |
| 4738 | submit_info.pCommandBuffers = &command_buffer[0]; |
| 4739 | submit_info.signalSemaphoreCount = 1; |
| 4740 | submit_info.pSignalSemaphores = &semaphore; |
| 4741 | vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE); |
| 4742 | } |
| 4743 | { |
| 4744 | VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT}; |
| 4745 | VkSubmitInfo submit_info{}; |
| 4746 | submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO; |
| 4747 | submit_info.commandBufferCount = 1; |
| 4748 | submit_info.pCommandBuffers = &command_buffer[1]; |
| 4749 | submit_info.waitSemaphoreCount = 1; |
| 4750 | submit_info.pWaitSemaphores = &semaphore; |
| 4751 | submit_info.pWaitDstStageMask = flags; |
| 4752 | vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence); |
| 4753 | } |
| 4754 | |
| 4755 | vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX); |
| 4756 | |
| 4757 | vkDestroyFence(m_device->device(), fence, nullptr); |
| 4758 | vkDestroySemaphore(m_device->device(), semaphore, nullptr); |
| 4759 | vkFreeCommandBuffers(m_device->device(), command_pool, 2, |
| 4760 | &command_buffer[0]); |
| 4761 | vkDestroyCommandPool(m_device->device(), command_pool, NULL); |
| 4762 | |
| 4763 | m_errorMonitor->VerifyNotFound(); |
| 4764 | } |
| 4765 | |
| 4766 | // This is a positive test. No errors should be generated. |
| 4767 | TEST_F(VkLayerTest, TwoQueueSubmitsOneQueueWithSemaphoreAndOneFence) { |
| 4768 | |
| 4769 | TEST_DESCRIPTION("Two command buffers, each in a separate QueueSubmit call " |
| 4770 | "on the same queue, sharing a signal/wait semaphore, the " |
| 4771 | "second having a fence, " |
| 4772 | "followed by a WaitForFences call."); |
| 4773 | |
| 4774 | m_errorMonitor->ExpectSuccess(); |
| 4775 | |
| 4776 | VkFence fence; |
| 4777 | VkFenceCreateInfo fence_create_info{}; |
| 4778 | fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO; |
| 4779 | vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence); |
| 4780 | |
| 4781 | VkSemaphore semaphore; |
| 4782 | VkSemaphoreCreateInfo semaphore_create_info{}; |
| 4783 | semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO; |
| 4784 | vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, |
| 4785 | &semaphore); |
| 4786 | |
| 4787 | VkCommandPool command_pool; |
| 4788 | VkCommandPoolCreateInfo pool_create_info{}; |
| 4789 | pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO; |
| 4790 | pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_; |
| 4791 | pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT; |
| 4792 | vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, |
| 4793 | &command_pool); |
| 4794 | |
| 4795 | VkCommandBuffer command_buffer[2]; |
| 4796 | VkCommandBufferAllocateInfo command_buffer_allocate_info{}; |
| 4797 | command_buffer_allocate_info.sType = |
| 4798 | VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO; |
| 4799 | command_buffer_allocate_info.commandPool = command_pool; |
| 4800 | command_buffer_allocate_info.commandBufferCount = 2; |
| 4801 | command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY; |
| 4802 | vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, |
| 4803 | command_buffer); |
| 4804 | |
| 4805 | { |
| 4806 | VkCommandBufferBeginInfo begin_info{}; |
| 4807 | begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO; |
| 4808 | vkBeginCommandBuffer(command_buffer[0], &begin_info); |
| 4809 | |
| 4810 | vkCmdPipelineBarrier(command_buffer[0], |
| 4811 | VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, |
| 4812 | VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, nullptr, |
| 4813 | 0, nullptr, 0, nullptr); |
| 4814 | |
| 4815 | VkViewport viewport{}; |
| 4816 | viewport.maxDepth = 1.0f; |
| 4817 | viewport.minDepth = 0.0f; |
| 4818 | viewport.width = 512; |
| 4819 | viewport.height = 512; |
| 4820 | viewport.x = 0; |
| 4821 | viewport.y = 0; |
| 4822 | vkCmdSetViewport(command_buffer[0], 0, 1, &viewport); |
| 4823 | vkEndCommandBuffer(command_buffer[0]); |
| 4824 | } |
| 4825 | { |
| 4826 | VkCommandBufferBeginInfo begin_info{}; |
| 4827 | begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO; |
| 4828 | vkBeginCommandBuffer(command_buffer[1], &begin_info); |
| 4829 | |
| 4830 | VkViewport viewport{}; |
| 4831 | viewport.maxDepth = 1.0f; |
| 4832 | viewport.minDepth = 0.0f; |
| 4833 | viewport.width = 512; |
| 4834 | viewport.height = 512; |
| 4835 | viewport.x = 0; |
| 4836 | viewport.y = 0; |
| 4837 | vkCmdSetViewport(command_buffer[1], 0, 1, &viewport); |
| 4838 | vkEndCommandBuffer(command_buffer[1]); |
| 4839 | } |
| 4840 | { |
| 4841 | VkSubmitInfo submit_info{}; |
| 4842 | submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO; |
| 4843 | submit_info.commandBufferCount = 1; |
| 4844 | submit_info.pCommandBuffers = &command_buffer[0]; |
| 4845 | submit_info.signalSemaphoreCount = 1; |
| 4846 | submit_info.pSignalSemaphores = &semaphore; |
| 4847 | vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE); |
| 4848 | } |
| 4849 | { |
| 4850 | VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT}; |
| 4851 | VkSubmitInfo submit_info{}; |
| 4852 | submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO; |
| 4853 | submit_info.commandBufferCount = 1; |
| 4854 | submit_info.pCommandBuffers = &command_buffer[1]; |
| 4855 | submit_info.waitSemaphoreCount = 1; |
| 4856 | submit_info.pWaitSemaphores = &semaphore; |
| 4857 | submit_info.pWaitDstStageMask = flags; |
| 4858 | vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence); |
| 4859 | } |
| 4860 | |
| 4861 | vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX); |
| 4862 | |
| 4863 | vkDestroyFence(m_device->device(), fence, nullptr); |
| 4864 | vkDestroySemaphore(m_device->device(), semaphore, nullptr); |
| 4865 | vkFreeCommandBuffers(m_device->device(), command_pool, 2, |
| 4866 | &command_buffer[0]); |
| 4867 | vkDestroyCommandPool(m_device->device(), command_pool, NULL); |
| 4868 | |
| 4869 | m_errorMonitor->VerifyNotFound(); |
| 4870 | } |
| 4871 | |
| 4872 | // This is a positive test. No errors should be generated. |
| 4873 | TEST_F(VkLayerTest, TwoQueueSubmitsOneQueueNullQueueSubmitWithFence) { |
| 4874 | |
| 4875 | TEST_DESCRIPTION( |
| 4876 | "Two command buffers, each in a separate QueueSubmit call " |
| 4877 | "on the same queue, no fences, followed by a third QueueSubmit with NO " |
| 4878 | "SubmitInfos but with a fence, followed by a WaitForFences call."); |
| 4879 | |
| 4880 | m_errorMonitor->ExpectSuccess(); |
| 4881 | |
| 4882 | VkFence fence; |
| 4883 | VkFenceCreateInfo fence_create_info{}; |
| 4884 | fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO; |
| 4885 | vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence); |
| 4886 | |
| 4887 | VkCommandPool command_pool; |
| 4888 | VkCommandPoolCreateInfo pool_create_info{}; |
| 4889 | pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO; |
| 4890 | pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_; |
| 4891 | pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT; |
| 4892 | vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, |
| 4893 | &command_pool); |
| 4894 | |
| 4895 | VkCommandBuffer command_buffer[2]; |
| 4896 | VkCommandBufferAllocateInfo command_buffer_allocate_info{}; |
| 4897 | command_buffer_allocate_info.sType = |
| 4898 | VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO; |
| 4899 | command_buffer_allocate_info.commandPool = command_pool; |
| 4900 | command_buffer_allocate_info.commandBufferCount = 2; |
| 4901 | command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY; |
| 4902 | vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, |
| 4903 | command_buffer); |
| 4904 | |
| 4905 | { |
| 4906 | VkCommandBufferBeginInfo begin_info{}; |
| 4907 | begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO; |
| 4908 | vkBeginCommandBuffer(command_buffer[0], &begin_info); |
| 4909 | |
| 4910 | vkCmdPipelineBarrier(command_buffer[0], |
| 4911 | VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, |
| 4912 | VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, nullptr, |
| 4913 | 0, nullptr, 0, nullptr); |
| 4914 | |
| 4915 | VkViewport viewport{}; |
| 4916 | viewport.maxDepth = 1.0f; |
| 4917 | viewport.minDepth = 0.0f; |
| 4918 | viewport.width = 512; |
| 4919 | viewport.height = 512; |
| 4920 | viewport.x = 0; |
| 4921 | viewport.y = 0; |
| 4922 | vkCmdSetViewport(command_buffer[0], 0, 1, &viewport); |
| 4923 | vkEndCommandBuffer(command_buffer[0]); |
| 4924 | } |
| 4925 | { |
| 4926 | VkCommandBufferBeginInfo begin_info{}; |
| 4927 | begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO; |
| 4928 | vkBeginCommandBuffer(command_buffer[1], &begin_info); |
| 4929 | |
| 4930 | VkViewport viewport{}; |
| 4931 | viewport.maxDepth = 1.0f; |
| 4932 | viewport.minDepth = 0.0f; |
| 4933 | viewport.width = 512; |
| 4934 | viewport.height = 512; |
| 4935 | viewport.x = 0; |
| 4936 | viewport.y = 0; |
| 4937 | vkCmdSetViewport(command_buffer[1], 0, 1, &viewport); |
| 4938 | vkEndCommandBuffer(command_buffer[1]); |
| 4939 | } |
| 4940 | { |
| 4941 | VkSubmitInfo submit_info{}; |
| 4942 | submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO; |
| 4943 | submit_info.commandBufferCount = 1; |
| 4944 | submit_info.pCommandBuffers = &command_buffer[0]; |
| 4945 | submit_info.signalSemaphoreCount = 0; |
| 4946 | submit_info.pSignalSemaphores = VK_NULL_HANDLE; |
| 4947 | vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE); |
| 4948 | } |
| 4949 | { |
| 4950 | VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT}; |
| 4951 | VkSubmitInfo submit_info{}; |
| 4952 | submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO; |
| 4953 | submit_info.commandBufferCount = 1; |
| 4954 | submit_info.pCommandBuffers = &command_buffer[1]; |
| 4955 | submit_info.waitSemaphoreCount = 0; |
| 4956 | submit_info.pWaitSemaphores = VK_NULL_HANDLE; |
| 4957 | submit_info.pWaitDstStageMask = flags; |
| 4958 | vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE); |
| 4959 | } |
| 4960 | |
| 4961 | vkQueueSubmit(m_device->m_queue, 0, NULL, fence); |
| 4962 | |
Mike Stroyan | cd1c3e5 | 2016-06-21 09:20:01 -0600 | [diff] [blame] | 4963 | VkResult err = |
| 4964 | vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX); |
| 4965 | ASSERT_VK_SUCCESS(err); |
Mark Lobodzinski | c808d44 | 2016-04-14 10:57:23 -0600 | [diff] [blame] | 4966 | |
| 4967 | vkDestroyFence(m_device->device(), fence, nullptr); |
| 4968 | vkFreeCommandBuffers(m_device->device(), command_pool, 2, |
| 4969 | &command_buffer[0]); |
| 4970 | vkDestroyCommandPool(m_device->device(), command_pool, NULL); |
| 4971 | |
| 4972 | m_errorMonitor->VerifyNotFound(); |
| 4973 | } |
| 4974 | |
| 4975 | // This is a positive test. No errors should be generated. |
| 4976 | TEST_F(VkLayerTest, TwoQueueSubmitsOneQueueOneFence) { |
| 4977 | |
| 4978 | TEST_DESCRIPTION("Two command buffers, each in a separate QueueSubmit call " |
| 4979 | "on the same queue, the second having a fence, followed " |
| 4980 | "by a WaitForFences call."); |
| 4981 | |
| 4982 | m_errorMonitor->ExpectSuccess(); |
| 4983 | |
| 4984 | VkFence fence; |
| 4985 | VkFenceCreateInfo fence_create_info{}; |
| 4986 | fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO; |
| 4987 | vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence); |
| 4988 | |
| 4989 | VkCommandPool command_pool; |
| 4990 | VkCommandPoolCreateInfo pool_create_info{}; |
| 4991 | pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO; |
| 4992 | pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_; |
| 4993 | pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT; |
| 4994 | vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, |
| 4995 | &command_pool); |
| 4996 | |
| 4997 | VkCommandBuffer command_buffer[2]; |
| 4998 | VkCommandBufferAllocateInfo command_buffer_allocate_info{}; |
| 4999 | command_buffer_allocate_info.sType = |
| 5000 | VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO; |
| 5001 | command_buffer_allocate_info.commandPool = command_pool; |
| 5002 | command_buffer_allocate_info.commandBufferCount = 2; |
| 5003 | command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY; |
| 5004 | vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, |
| 5005 | command_buffer); |
| 5006 | |
| 5007 | { |
| 5008 | VkCommandBufferBeginInfo begin_info{}; |
| 5009 | begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO; |
| 5010 | vkBeginCommandBuffer(command_buffer[0], &begin_info); |
| 5011 | |
| 5012 | vkCmdPipelineBarrier(command_buffer[0], |
| 5013 | VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, |
| 5014 | VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, nullptr, |
| 5015 | 0, nullptr, 0, nullptr); |
| 5016 | |
| 5017 | VkViewport viewport{}; |
| 5018 | viewport.maxDepth = 1.0f; |
| 5019 | viewport.minDepth = 0.0f; |
| 5020 | viewport.width = 512; |
| 5021 | viewport.height = 512; |
| 5022 | viewport.x = 0; |
| 5023 | viewport.y = 0; |
| 5024 | vkCmdSetViewport(command_buffer[0], 0, 1, &viewport); |
| 5025 | vkEndCommandBuffer(command_buffer[0]); |
| 5026 | } |
| 5027 | { |
| 5028 | VkCommandBufferBeginInfo begin_info{}; |
| 5029 | begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO; |
| 5030 | vkBeginCommandBuffer(command_buffer[1], &begin_info); |
| 5031 | |
| 5032 | VkViewport viewport{}; |
| 5033 | viewport.maxDepth = 1.0f; |
| 5034 | viewport.minDepth = 0.0f; |
| 5035 | viewport.width = 512; |
| 5036 | viewport.height = 512; |
| 5037 | viewport.x = 0; |
| 5038 | viewport.y = 0; |
| 5039 | vkCmdSetViewport(command_buffer[1], 0, 1, &viewport); |
| 5040 | vkEndCommandBuffer(command_buffer[1]); |
| 5041 | } |
| 5042 | { |
| 5043 | VkSubmitInfo submit_info{}; |
| 5044 | submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO; |
| 5045 | submit_info.commandBufferCount = 1; |
| 5046 | submit_info.pCommandBuffers = &command_buffer[0]; |
| 5047 | submit_info.signalSemaphoreCount = 0; |
| 5048 | submit_info.pSignalSemaphores = VK_NULL_HANDLE; |
| 5049 | vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE); |
| 5050 | } |
| 5051 | { |
| 5052 | VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT}; |
| 5053 | VkSubmitInfo submit_info{}; |
| 5054 | submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO; |
| 5055 | submit_info.commandBufferCount = 1; |
| 5056 | submit_info.pCommandBuffers = &command_buffer[1]; |
| 5057 | submit_info.waitSemaphoreCount = 0; |
| 5058 | submit_info.pWaitSemaphores = VK_NULL_HANDLE; |
| 5059 | submit_info.pWaitDstStageMask = flags; |
| 5060 | vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence); |
| 5061 | } |
| 5062 | |
| 5063 | vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX); |
| 5064 | |
| 5065 | vkDestroyFence(m_device->device(), fence, nullptr); |
| 5066 | vkFreeCommandBuffers(m_device->device(), command_pool, 2, |
| 5067 | &command_buffer[0]); |
| 5068 | vkDestroyCommandPool(m_device->device(), command_pool, NULL); |
| 5069 | |
| 5070 | m_errorMonitor->VerifyNotFound(); |
| 5071 | } |
| 5072 | |
| 5073 | // This is a positive test. No errors should be generated. |
| 5074 | TEST_F(VkLayerTest, TwoSubmitInfosWithSemaphoreOneQueueSubmitsOneFence) { |
| 5075 | |
| 5076 | TEST_DESCRIPTION( |
| 5077 | "Two command buffers each in a separate SubmitInfo sent in a single " |
| 5078 | "QueueSubmit call followed by a WaitForFences call."); |
| 5079 | |
| 5080 | m_errorMonitor->ExpectSuccess(); |
| 5081 | |
| 5082 | VkFence fence; |
| 5083 | VkFenceCreateInfo fence_create_info{}; |
| 5084 | fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO; |
| 5085 | vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence); |
| 5086 | |
| 5087 | VkSemaphore semaphore; |
| 5088 | VkSemaphoreCreateInfo semaphore_create_info{}; |
| 5089 | semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO; |
| 5090 | vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, |
| 5091 | &semaphore); |
| 5092 | |
| 5093 | VkCommandPool command_pool; |
| 5094 | VkCommandPoolCreateInfo pool_create_info{}; |
| 5095 | pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO; |
| 5096 | pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_; |
| 5097 | pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT; |
| 5098 | vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, |
| 5099 | &command_pool); |
| 5100 | |
| 5101 | VkCommandBuffer command_buffer[2]; |
| 5102 | VkCommandBufferAllocateInfo command_buffer_allocate_info{}; |
| 5103 | command_buffer_allocate_info.sType = |
| 5104 | VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO; |
| 5105 | command_buffer_allocate_info.commandPool = command_pool; |
| 5106 | command_buffer_allocate_info.commandBufferCount = 2; |
| 5107 | command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY; |
| 5108 | vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, |
| 5109 | command_buffer); |
| 5110 | |
| 5111 | { |
| 5112 | VkCommandBufferBeginInfo begin_info{}; |
| 5113 | begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO; |
| 5114 | vkBeginCommandBuffer(command_buffer[0], &begin_info); |
| 5115 | |
| 5116 | vkCmdPipelineBarrier(command_buffer[0], |
| 5117 | VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, |
| 5118 | VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, nullptr, |
| 5119 | 0, nullptr, 0, nullptr); |
| 5120 | |
| 5121 | VkViewport viewport{}; |
| 5122 | viewport.maxDepth = 1.0f; |
| 5123 | viewport.minDepth = 0.0f; |
| 5124 | viewport.width = 512; |
| 5125 | viewport.height = 512; |
| 5126 | viewport.x = 0; |
| 5127 | viewport.y = 0; |
| 5128 | vkCmdSetViewport(command_buffer[0], 0, 1, &viewport); |
| 5129 | vkEndCommandBuffer(command_buffer[0]); |
| 5130 | } |
| 5131 | { |
| 5132 | VkCommandBufferBeginInfo begin_info{}; |
| 5133 | begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO; |
| 5134 | vkBeginCommandBuffer(command_buffer[1], &begin_info); |
| 5135 | |
| 5136 | VkViewport viewport{}; |
| 5137 | viewport.maxDepth = 1.0f; |
| 5138 | viewport.minDepth = 0.0f; |
| 5139 | viewport.width = 512; |
| 5140 | viewport.height = 512; |
| 5141 | viewport.x = 0; |
| 5142 | viewport.y = 0; |
| 5143 | vkCmdSetViewport(command_buffer[1], 0, 1, &viewport); |
| 5144 | vkEndCommandBuffer(command_buffer[1]); |
| 5145 | } |
| 5146 | { |
| 5147 | VkSubmitInfo submit_info[2]; |
| 5148 | VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT}; |
| 5149 | |
| 5150 | submit_info[0].sType = VK_STRUCTURE_TYPE_SUBMIT_INFO; |
| 5151 | submit_info[0].pNext = NULL; |
| 5152 | submit_info[0].commandBufferCount = 1; |
| 5153 | submit_info[0].pCommandBuffers = &command_buffer[0]; |
| 5154 | submit_info[0].signalSemaphoreCount = 1; |
| 5155 | submit_info[0].pSignalSemaphores = &semaphore; |
| 5156 | submit_info[0].waitSemaphoreCount = 0; |
| 5157 | submit_info[0].pWaitSemaphores = NULL; |
| 5158 | submit_info[0].pWaitDstStageMask = 0; |
| 5159 | |
| 5160 | submit_info[1].sType = VK_STRUCTURE_TYPE_SUBMIT_INFO; |
| 5161 | submit_info[1].pNext = NULL; |
| 5162 | submit_info[1].commandBufferCount = 1; |
| 5163 | submit_info[1].pCommandBuffers = &command_buffer[1]; |
| 5164 | submit_info[1].waitSemaphoreCount = 1; |
| 5165 | submit_info[1].pWaitSemaphores = &semaphore; |
| 5166 | submit_info[1].pWaitDstStageMask = flags; |
| 5167 | submit_info[1].signalSemaphoreCount = 0; |
| 5168 | submit_info[1].pSignalSemaphores = NULL; |
| 5169 | vkQueueSubmit(m_device->m_queue, 2, &submit_info[0], fence); |
| 5170 | } |
| 5171 | |
| 5172 | vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX); |
| 5173 | |
| 5174 | vkDestroyFence(m_device->device(), fence, nullptr); |
| 5175 | vkFreeCommandBuffers(m_device->device(), command_pool, 2, |
| 5176 | &command_buffer[0]); |
| 5177 | vkDestroyCommandPool(m_device->device(), command_pool, NULL); |
Tony Barbour | df4c004 | 2016-06-01 15:55:43 -0600 | [diff] [blame] | 5178 | vkDestroySemaphore(m_device->device(), semaphore, nullptr); |
Mark Lobodzinski | c808d44 | 2016-04-14 10:57:23 -0600 | [diff] [blame] | 5179 | |
| 5180 | m_errorMonitor->VerifyNotFound(); |
| 5181 | } |
| 5182 | |
Tobin Ehlis | b1a8799 | 2016-05-25 16:42:47 -0600 | [diff] [blame] | 5183 | TEST_F(VkLayerTest, DynamicDepthBiasNotBound) { |
Tobin Ehlis | a5200ef | 2016-05-03 10:34:08 -0600 | [diff] [blame] | 5184 | TEST_DESCRIPTION( |
Tobin Ehlis | b1a8799 | 2016-05-25 16:42:47 -0600 | [diff] [blame] | 5185 | "Run a simple draw calls to validate failure when Depth Bias dynamic " |
| 5186 | "state is required but not correctly bound."); |
| 5187 | |
| 5188 | // Dynamic depth bias |
| 5189 | m_errorMonitor->SetDesiredFailureMsg( |
| 5190 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 5191 | "Dynamic depth bias state not set for this command buffer"); |
| 5192 | VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, |
| 5193 | BsoFailDepthBias); |
| 5194 | m_errorMonitor->VerifyFound(); |
| 5195 | } |
| 5196 | |
| 5197 | TEST_F(VkLayerTest, DynamicLineWidthNotBound) { |
| 5198 | TEST_DESCRIPTION( |
| 5199 | "Run a simple draw calls to validate failure when Line Width dynamic " |
| 5200 | "state is required but not correctly bound."); |
Tobin Ehlis | a5200ef | 2016-05-03 10:34:08 -0600 | [diff] [blame] | 5201 | |
| 5202 | // Dynamic line width |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5203 | m_errorMonitor->SetDesiredFailureMsg( |
| 5204 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 5205 | "Dynamic line width state not set for this command buffer"); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5206 | VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, |
| 5207 | BsoFailLineWidth); |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 5208 | m_errorMonitor->VerifyFound(); |
Tobin Ehlis | b1a8799 | 2016-05-25 16:42:47 -0600 | [diff] [blame] | 5209 | } |
| 5210 | |
| 5211 | TEST_F(VkLayerTest, DynamicViewportNotBound) { |
| 5212 | TEST_DESCRIPTION( |
| 5213 | "Run a simple draw calls to validate failure when Viewport dynamic " |
| 5214 | "state is required but not correctly bound."); |
| 5215 | |
Tobin Ehlis | a5200ef | 2016-05-03 10:34:08 -0600 | [diff] [blame] | 5216 | // Dynamic viewport state |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5217 | m_errorMonitor->SetDesiredFailureMsg( |
| 5218 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 5219 | "Dynamic viewport state not set for this command buffer"); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5220 | VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, |
| 5221 | BsoFailViewport); |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 5222 | m_errorMonitor->VerifyFound(); |
Tobin Ehlis | b1a8799 | 2016-05-25 16:42:47 -0600 | [diff] [blame] | 5223 | } |
| 5224 | |
| 5225 | TEST_F(VkLayerTest, DynamicScissorNotBound) { |
| 5226 | TEST_DESCRIPTION( |
| 5227 | "Run a simple draw calls to validate failure when Scissor dynamic " |
| 5228 | "state is required but not correctly bound."); |
| 5229 | |
Tobin Ehlis | a5200ef | 2016-05-03 10:34:08 -0600 | [diff] [blame] | 5230 | // Dynamic scissor state |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5231 | m_errorMonitor->SetDesiredFailureMsg( |
| 5232 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 5233 | "Dynamic scissor state not set for this command buffer"); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5234 | VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, |
| 5235 | BsoFailScissor); |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 5236 | m_errorMonitor->VerifyFound(); |
Tobin Ehlis | b1a8799 | 2016-05-25 16:42:47 -0600 | [diff] [blame] | 5237 | } |
| 5238 | |
Tobin Ehlis | 21c8835 | 2016-05-26 06:15:45 -0600 | [diff] [blame] | 5239 | TEST_F(VkLayerTest, DynamiBlendConstantsNotBound) { |
Tobin Ehlis | b1a8799 | 2016-05-25 16:42:47 -0600 | [diff] [blame] | 5240 | TEST_DESCRIPTION( |
Tobin Ehlis | 21c8835 | 2016-05-26 06:15:45 -0600 | [diff] [blame] | 5241 | "Run a simple draw calls to validate failure when Blend Constants " |
| 5242 | "dynamic state is required but not correctly bound."); |
| 5243 | // Dynamic blend constant state |
| 5244 | m_errorMonitor->SetDesiredFailureMsg( |
| 5245 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 5246 | "Dynamic blend constants state not set for this command buffer"); |
| 5247 | VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, |
| 5248 | BsoFailBlend); |
| 5249 | m_errorMonitor->VerifyFound(); |
| 5250 | } |
| 5251 | |
| 5252 | TEST_F(VkLayerTest, DynamicDepthBoundsNotBound) { |
| 5253 | TEST_DESCRIPTION( |
| 5254 | "Run a simple draw calls to validate failure when Depth Bounds dynamic " |
Tobin Ehlis | b1a8799 | 2016-05-25 16:42:47 -0600 | [diff] [blame] | 5255 | "state is required but not correctly bound."); |
Tobin Ehlis | 21c8835 | 2016-05-26 06:15:45 -0600 | [diff] [blame] | 5256 | if (!m_device->phy().features().depthBounds) { |
| 5257 | printf("Device does not support depthBounds test; skipped.\n"); |
| 5258 | return; |
| 5259 | } |
| 5260 | // Dynamic depth bounds |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5261 | m_errorMonitor->SetDesiredFailureMsg( |
| 5262 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 5263 | "Dynamic depth bounds state not set for this command buffer"); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5264 | VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, |
| 5265 | BsoFailDepthBounds); |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 5266 | m_errorMonitor->VerifyFound(); |
Tobin Ehlis | b1a8799 | 2016-05-25 16:42:47 -0600 | [diff] [blame] | 5267 | } |
| 5268 | |
| 5269 | TEST_F(VkLayerTest, DynamicStencilReadNotBound) { |
| 5270 | TEST_DESCRIPTION( |
| 5271 | "Run a simple draw calls to validate failure when Stencil Read dynamic " |
| 5272 | "state is required but not correctly bound."); |
Tobin Ehlis | a5200ef | 2016-05-03 10:34:08 -0600 | [diff] [blame] | 5273 | // Dynamic stencil read mask |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5274 | m_errorMonitor->SetDesiredFailureMsg( |
| 5275 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 5276 | "Dynamic stencil read mask state not set for this command buffer"); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5277 | VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, |
| 5278 | BsoFailStencilReadMask); |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 5279 | m_errorMonitor->VerifyFound(); |
Tobin Ehlis | b1a8799 | 2016-05-25 16:42:47 -0600 | [diff] [blame] | 5280 | } |
| 5281 | |
| 5282 | TEST_F(VkLayerTest, DynamicStencilWriteNotBound) { |
| 5283 | TEST_DESCRIPTION( |
| 5284 | "Run a simple draw calls to validate failure when Stencil Write dynamic" |
| 5285 | " state is required but not correctly bound."); |
Tobin Ehlis | a5200ef | 2016-05-03 10:34:08 -0600 | [diff] [blame] | 5286 | // Dynamic stencil write mask |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5287 | m_errorMonitor->SetDesiredFailureMsg( |
| 5288 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 5289 | "Dynamic stencil write mask state not set for this command buffer"); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5290 | VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, |
| 5291 | BsoFailStencilWriteMask); |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 5292 | m_errorMonitor->VerifyFound(); |
Tobin Ehlis | b1a8799 | 2016-05-25 16:42:47 -0600 | [diff] [blame] | 5293 | } |
| 5294 | |
| 5295 | TEST_F(VkLayerTest, DynamicStencilRefNotBound) { |
| 5296 | TEST_DESCRIPTION( |
| 5297 | "Run a simple draw calls to validate failure when Stencil Ref dynamic " |
| 5298 | "state is required but not correctly bound."); |
Tobin Ehlis | a5200ef | 2016-05-03 10:34:08 -0600 | [diff] [blame] | 5299 | // Dynamic stencil reference |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5300 | m_errorMonitor->SetDesiredFailureMsg( |
| 5301 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 5302 | "Dynamic stencil reference state not set for this command buffer"); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5303 | VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, |
| 5304 | BsoFailStencilReference); |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 5305 | m_errorMonitor->VerifyFound(); |
Tobin Ehlis | 963a404 | 2015-09-29 08:18:34 -0600 | [diff] [blame] | 5306 | } |
| 5307 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5308 | TEST_F(VkLayerTest, CommandBufferTwoSubmits) { |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5309 | m_errorMonitor->SetDesiredFailureMsg( |
| 5310 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 5311 | "was begun w/ VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT set, but has " |
| 5312 | "been submitted"); |
Tobin Ehlis | 59278bf | 2015-08-18 07:10:58 -0600 | [diff] [blame] | 5313 | |
Tobin Ehlis | 59278bf | 2015-08-18 07:10:58 -0600 | [diff] [blame] | 5314 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 5315 | ASSERT_NO_FATAL_FAILURE(InitViewport()); |
| 5316 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 5317 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5318 | // We luck out b/c by default the framework creates CB w/ the |
| 5319 | // VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT set |
Tobin Ehlis | 59278bf | 2015-08-18 07:10:58 -0600 | [diff] [blame] | 5320 | BeginCommandBuffer(); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5321 | m_commandBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color, |
| 5322 | m_stencil_clear_color, NULL); |
Tobin Ehlis | 59278bf | 2015-08-18 07:10:58 -0600 | [diff] [blame] | 5323 | EndCommandBuffer(); |
| 5324 | |
Tobin Ehlis | 59278bf | 2015-08-18 07:10:58 -0600 | [diff] [blame] | 5325 | // Bypass framework since it does the waits automatically |
| 5326 | VkResult err = VK_SUCCESS; |
Courtney Goeltzenleuchter | 806c700 | 2015-10-27 11:22:14 -0600 | [diff] [blame] | 5327 | VkSubmitInfo submit_info; |
Chia-I Wu | f9be13c | 2015-10-26 20:37:06 +0800 | [diff] [blame] | 5328 | submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO; |
| 5329 | submit_info.pNext = NULL; |
Chia-I Wu | d50a7d7 | 2015-10-26 20:48:51 +0800 | [diff] [blame] | 5330 | submit_info.waitSemaphoreCount = 0; |
Courtney Goeltzenleuchter | 806c700 | 2015-10-27 11:22:14 -0600 | [diff] [blame] | 5331 | submit_info.pWaitSemaphores = NULL; |
Jon Ashburn | 7f9716c | 2015-12-30 16:42:50 -0700 | [diff] [blame] | 5332 | submit_info.pWaitDstStageMask = NULL; |
Chia-I Wu | d50a7d7 | 2015-10-26 20:48:51 +0800 | [diff] [blame] | 5333 | submit_info.commandBufferCount = 1; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 5334 | submit_info.pCommandBuffers = &m_commandBuffer->handle(); |
Chia-I Wu | d50a7d7 | 2015-10-26 20:48:51 +0800 | [diff] [blame] | 5335 | submit_info.signalSemaphoreCount = 0; |
Courtney Goeltzenleuchter | 806c700 | 2015-10-27 11:22:14 -0600 | [diff] [blame] | 5336 | submit_info.pSignalSemaphores = NULL; |
| 5337 | |
Chris Forbes | 40028e2 | 2016-06-13 09:59:34 +1200 | [diff] [blame] | 5338 | err = vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5339 | ASSERT_VK_SUCCESS(err); |
Tobin Ehlis | 59278bf | 2015-08-18 07:10:58 -0600 | [diff] [blame] | 5340 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5341 | // Cause validation error by re-submitting cmd buffer that should only be |
| 5342 | // submitted once |
Chris Forbes | 40028e2 | 2016-06-13 09:59:34 +1200 | [diff] [blame] | 5343 | err = vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE); |
Tobin Ehlis | 59278bf | 2015-08-18 07:10:58 -0600 | [diff] [blame] | 5344 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 5345 | m_errorMonitor->VerifyFound(); |
Tobin Ehlis | 59278bf | 2015-08-18 07:10:58 -0600 | [diff] [blame] | 5346 | } |
| 5347 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5348 | TEST_F(VkLayerTest, AllocDescriptorFromEmptyPool) { |
Tobin Ehlis | f93f1e3 | 2015-10-20 16:16:04 -0600 | [diff] [blame] | 5349 | // Initiate Draw w/o a PSO bound |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5350 | VkResult err; |
Tobin Ehlis | f93f1e3 | 2015-10-20 16:16:04 -0600 | [diff] [blame] | 5351 | |
Courtney Goeltzenleuchter | 7415d5a | 2015-12-09 15:48:16 -0700 | [diff] [blame] | 5352 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5353 | "Unable to allocate 1 descriptors of " |
| 5354 | "type " |
| 5355 | "VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER "); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 5356 | |
Tobin Ehlis | f93f1e3 | 2015-10-20 16:16:04 -0600 | [diff] [blame] | 5357 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 5358 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
Tobin Ehlis | f93f1e3 | 2015-10-20 16:16:04 -0600 | [diff] [blame] | 5359 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5360 | // Create Pool w/ 1 Sampler descriptor, but try to alloc Uniform Buffer |
| 5361 | // descriptor from it |
Chia-I Wu | 1b99bb2 | 2015-10-27 19:25:11 +0800 | [diff] [blame] | 5362 | VkDescriptorPoolSize ds_type_count = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5363 | ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLER; |
| 5364 | ds_type_count.descriptorCount = 1; |
Tobin Ehlis | f93f1e3 | 2015-10-20 16:16:04 -0600 | [diff] [blame] | 5365 | |
| 5366 | VkDescriptorPoolCreateInfo ds_pool_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5367 | ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO; |
| 5368 | ds_pool_ci.pNext = NULL; |
| 5369 | ds_pool_ci.flags = 0; |
| 5370 | ds_pool_ci.maxSets = 1; |
| 5371 | ds_pool_ci.poolSizeCount = 1; |
| 5372 | ds_pool_ci.pPoolSizes = &ds_type_count; |
Tobin Ehlis | f93f1e3 | 2015-10-20 16:16:04 -0600 | [diff] [blame] | 5373 | |
| 5374 | VkDescriptorPool ds_pool; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5375 | err = |
| 5376 | vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool); |
Tobin Ehlis | f93f1e3 | 2015-10-20 16:16:04 -0600 | [diff] [blame] | 5377 | ASSERT_VK_SUCCESS(err); |
| 5378 | |
| 5379 | VkDescriptorSetLayoutBinding dsl_binding = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5380 | dsl_binding.binding = 0; |
| 5381 | dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 5382 | dsl_binding.descriptorCount = 1; |
| 5383 | dsl_binding.stageFlags = VK_SHADER_STAGE_ALL; |
| 5384 | dsl_binding.pImmutableSamplers = NULL; |
Tobin Ehlis | f93f1e3 | 2015-10-20 16:16:04 -0600 | [diff] [blame] | 5385 | |
| 5386 | VkDescriptorSetLayoutCreateInfo ds_layout_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5387 | ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO; |
| 5388 | ds_layout_ci.pNext = NULL; |
| 5389 | ds_layout_ci.bindingCount = 1; |
| 5390 | ds_layout_ci.pBindings = &dsl_binding; |
Tobin Ehlis | f93f1e3 | 2015-10-20 16:16:04 -0600 | [diff] [blame] | 5391 | |
| 5392 | VkDescriptorSetLayout ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5393 | err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, |
| 5394 | &ds_layout); |
Tobin Ehlis | f93f1e3 | 2015-10-20 16:16:04 -0600 | [diff] [blame] | 5395 | ASSERT_VK_SUCCESS(err); |
| 5396 | |
| 5397 | VkDescriptorSet descriptorSet; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 5398 | VkDescriptorSetAllocateInfo alloc_info = {}; |
Chia-I Wu | 00ce540 | 2015-11-10 16:21:09 +0800 | [diff] [blame] | 5399 | alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO; |
Jon Ashburn | f19916e | 2016-01-11 13:12:43 -0700 | [diff] [blame] | 5400 | alloc_info.descriptorSetCount = 1; |
Courtney Goeltzenleuchter | bee18a9 | 2015-10-23 14:21:05 -0600 | [diff] [blame] | 5401 | alloc_info.descriptorPool = ds_pool; |
| 5402 | alloc_info.pSetLayouts = &ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5403 | err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, |
| 5404 | &descriptorSet); |
Tobin Ehlis | f93f1e3 | 2015-10-20 16:16:04 -0600 | [diff] [blame] | 5405 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 5406 | m_errorMonitor->VerifyFound(); |
Tobin Ehlis | f93f1e3 | 2015-10-20 16:16:04 -0600 | [diff] [blame] | 5407 | |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 5408 | vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL); |
| 5409 | vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL); |
Tobin Ehlis | f93f1e3 | 2015-10-20 16:16:04 -0600 | [diff] [blame] | 5410 | } |
| 5411 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5412 | TEST_F(VkLayerTest, FreeDescriptorFromOneShotPool) { |
| 5413 | VkResult err; |
Tobin Ehlis | e735c69 | 2015-10-08 13:13:50 -0600 | [diff] [blame] | 5414 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5415 | m_errorMonitor->SetDesiredFailureMsg( |
| 5416 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 5417 | "It is invalid to call vkFreeDescriptorSets() with a pool created " |
| 5418 | "without setting VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT."); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 5419 | |
Tobin Ehlis | e735c69 | 2015-10-08 13:13:50 -0600 | [diff] [blame] | 5420 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 5421 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
Tobin Ehlis | e735c69 | 2015-10-08 13:13:50 -0600 | [diff] [blame] | 5422 | |
Chia-I Wu | 1b99bb2 | 2015-10-27 19:25:11 +0800 | [diff] [blame] | 5423 | VkDescriptorPoolSize ds_type_count = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5424 | ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 5425 | ds_type_count.descriptorCount = 1; |
Tobin Ehlis | e735c69 | 2015-10-08 13:13:50 -0600 | [diff] [blame] | 5426 | |
| 5427 | VkDescriptorPoolCreateInfo ds_pool_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5428 | ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO; |
| 5429 | ds_pool_ci.pNext = NULL; |
| 5430 | ds_pool_ci.maxSets = 1; |
| 5431 | ds_pool_ci.poolSizeCount = 1; |
| 5432 | ds_pool_ci.flags = 0; |
| 5433 | // Not specifying VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT means |
| 5434 | // app can only call vkResetDescriptorPool on this pool.; |
| 5435 | ds_pool_ci.pPoolSizes = &ds_type_count; |
Tobin Ehlis | e735c69 | 2015-10-08 13:13:50 -0600 | [diff] [blame] | 5436 | |
| 5437 | VkDescriptorPool ds_pool; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5438 | err = |
| 5439 | vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool); |
Tobin Ehlis | e735c69 | 2015-10-08 13:13:50 -0600 | [diff] [blame] | 5440 | ASSERT_VK_SUCCESS(err); |
| 5441 | |
| 5442 | VkDescriptorSetLayoutBinding dsl_binding = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5443 | dsl_binding.binding = 0; |
| 5444 | dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 5445 | dsl_binding.descriptorCount = 1; |
| 5446 | dsl_binding.stageFlags = VK_SHADER_STAGE_ALL; |
| 5447 | dsl_binding.pImmutableSamplers = NULL; |
Tobin Ehlis | e735c69 | 2015-10-08 13:13:50 -0600 | [diff] [blame] | 5448 | |
| 5449 | VkDescriptorSetLayoutCreateInfo ds_layout_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5450 | ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO; |
| 5451 | ds_layout_ci.pNext = NULL; |
| 5452 | ds_layout_ci.bindingCount = 1; |
| 5453 | ds_layout_ci.pBindings = &dsl_binding; |
Tobin Ehlis | e735c69 | 2015-10-08 13:13:50 -0600 | [diff] [blame] | 5454 | |
| 5455 | VkDescriptorSetLayout ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5456 | err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, |
| 5457 | &ds_layout); |
Tobin Ehlis | e735c69 | 2015-10-08 13:13:50 -0600 | [diff] [blame] | 5458 | ASSERT_VK_SUCCESS(err); |
| 5459 | |
| 5460 | VkDescriptorSet descriptorSet; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 5461 | VkDescriptorSetAllocateInfo alloc_info = {}; |
Chia-I Wu | 00ce540 | 2015-11-10 16:21:09 +0800 | [diff] [blame] | 5462 | alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO; |
Jon Ashburn | f19916e | 2016-01-11 13:12:43 -0700 | [diff] [blame] | 5463 | alloc_info.descriptorSetCount = 1; |
Courtney Goeltzenleuchter | bee18a9 | 2015-10-23 14:21:05 -0600 | [diff] [blame] | 5464 | alloc_info.descriptorPool = ds_pool; |
| 5465 | alloc_info.pSetLayouts = &ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5466 | err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, |
| 5467 | &descriptorSet); |
Tobin Ehlis | e735c69 | 2015-10-08 13:13:50 -0600 | [diff] [blame] | 5468 | ASSERT_VK_SUCCESS(err); |
| 5469 | |
| 5470 | err = vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptorSet); |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 5471 | m_errorMonitor->VerifyFound(); |
Tobin Ehlis | e735c69 | 2015-10-08 13:13:50 -0600 | [diff] [blame] | 5472 | |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 5473 | vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL); |
| 5474 | vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL); |
Tobin Ehlis | e735c69 | 2015-10-08 13:13:50 -0600 | [diff] [blame] | 5475 | } |
| 5476 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5477 | TEST_F(VkLayerTest, InvalidDescriptorPool) { |
Karl Schultz | bdb7595 | 2016-04-19 11:36:49 -0600 | [diff] [blame] | 5478 | // Attempt to clear Descriptor Pool with bad object. |
| 5479 | // ObjectTracker should catch this. |
| 5480 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 5481 | "Invalid VkDescriptorPool Object 0xbaad6001"); |
Mark Lobodzinski | 02bf89d | 2016-05-10 14:45:13 -0600 | [diff] [blame] | 5482 | uint64_t fake_pool_handle = 0xbaad6001; |
| 5483 | VkDescriptorPool bad_pool = reinterpret_cast<VkDescriptorPool &>(fake_pool_handle); |
| 5484 | vkResetDescriptorPool(device(), bad_pool, 0); |
Karl Schultz | bdb7595 | 2016-04-19 11:36:49 -0600 | [diff] [blame] | 5485 | m_errorMonitor->VerifyFound(); |
Tobin Ehlis | 49eb23d | 2015-05-22 12:38:55 -0600 | [diff] [blame] | 5486 | } |
| 5487 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5488 | TEST_F(VkLayerTest, InvalidDescriptorSet) { |
Karl Schultz | bdb7595 | 2016-04-19 11:36:49 -0600 | [diff] [blame] | 5489 | // Attempt to bind an invalid Descriptor Set to a valid Command Buffer |
| 5490 | // ObjectTracker should catch this. |
Tobin Ehlis | 49eb23d | 2015-05-22 12:38:55 -0600 | [diff] [blame] | 5491 | // Create a valid cmd buffer |
Karl Schultz | bdb7595 | 2016-04-19 11:36:49 -0600 | [diff] [blame] | 5492 | // call vkCmdBindDescriptorSets w/ false Descriptor Set |
Mark Lobodzinski | 02bf89d | 2016-05-10 14:45:13 -0600 | [diff] [blame] | 5493 | |
| 5494 | uint64_t fake_set_handle = 0xbaad6001; |
| 5495 | VkDescriptorSet bad_set = reinterpret_cast<VkDescriptorSet &>(fake_set_handle); |
Karl Schultz | bdb7595 | 2016-04-19 11:36:49 -0600 | [diff] [blame] | 5496 | VkResult err; |
| 5497 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 5498 | "Invalid VkDescriptorSet Object 0xbaad6001"); |
| 5499 | |
| 5500 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 5501 | |
| 5502 | VkDescriptorSetLayoutBinding layout_bindings[1] = {}; |
| 5503 | layout_bindings[0].binding = 0; |
| 5504 | layout_bindings[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 5505 | layout_bindings[0].descriptorCount = 1; |
| 5506 | layout_bindings[0].stageFlags = VK_SHADER_STAGE_VERTEX_BIT; |
| 5507 | layout_bindings[0].pImmutableSamplers = NULL; |
| 5508 | |
| 5509 | VkDescriptorSetLayout descriptor_set_layout; |
| 5510 | VkDescriptorSetLayoutCreateInfo dslci = {}; |
| 5511 | dslci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO; |
| 5512 | dslci.pNext = NULL; |
| 5513 | dslci.bindingCount = 1; |
| 5514 | dslci.pBindings = layout_bindings; |
| 5515 | err = vkCreateDescriptorSetLayout(device(), &dslci, NULL, &descriptor_set_layout); |
Karl Schultz | 5cb2111 | 2016-04-21 17:17:40 -0600 | [diff] [blame] | 5516 | ASSERT_VK_SUCCESS(err); |
Karl Schultz | bdb7595 | 2016-04-19 11:36:49 -0600 | [diff] [blame] | 5517 | |
| 5518 | VkPipelineLayout pipeline_layout; |
| 5519 | VkPipelineLayoutCreateInfo plci = {}; |
| 5520 | plci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO; |
| 5521 | plci.pNext = NULL; |
| 5522 | plci.setLayoutCount = 1; |
| 5523 | plci.pSetLayouts = &descriptor_set_layout; |
| 5524 | err = vkCreatePipelineLayout(device(), &plci, NULL, &pipeline_layout); |
Karl Schultz | 5cb2111 | 2016-04-21 17:17:40 -0600 | [diff] [blame] | 5525 | ASSERT_VK_SUCCESS(err); |
Karl Schultz | bdb7595 | 2016-04-19 11:36:49 -0600 | [diff] [blame] | 5526 | |
| 5527 | BeginCommandBuffer(); |
| 5528 | vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, |
Mark Lobodzinski | 02bf89d | 2016-05-10 14:45:13 -0600 | [diff] [blame] | 5529 | pipeline_layout, 0, 1, &bad_set, 0, NULL); |
Karl Schultz | bdb7595 | 2016-04-19 11:36:49 -0600 | [diff] [blame] | 5530 | m_errorMonitor->VerifyFound(); |
| 5531 | EndCommandBuffer(); |
| 5532 | vkDestroyPipelineLayout(device(), pipeline_layout, NULL); |
| 5533 | vkDestroyDescriptorSetLayout(device(), descriptor_set_layout, NULL); |
Tobin Ehlis | 49eb23d | 2015-05-22 12:38:55 -0600 | [diff] [blame] | 5534 | } |
| 5535 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5536 | TEST_F(VkLayerTest, InvalidDescriptorSetLayout) { |
Karl Schultz | bdb7595 | 2016-04-19 11:36:49 -0600 | [diff] [blame] | 5537 | // Attempt to create a Pipeline Layout with an invalid Descriptor Set Layout. |
| 5538 | // ObjectTracker should catch this. |
Mark Lobodzinski | 02bf89d | 2016-05-10 14:45:13 -0600 | [diff] [blame] | 5539 | uint64_t fake_layout_handle = 0xbaad6001; |
| 5540 | VkDescriptorSetLayout bad_layout = reinterpret_cast<VkDescriptorSetLayout &>(fake_layout_handle); |
Karl Schultz | bdb7595 | 2016-04-19 11:36:49 -0600 | [diff] [blame] | 5541 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 5542 | "Invalid VkDescriptorSetLayout Object 0xbaad6001"); |
| 5543 | |
| 5544 | VkPipelineLayout pipeline_layout; |
| 5545 | VkPipelineLayoutCreateInfo plci = {}; |
| 5546 | plci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO; |
| 5547 | plci.pNext = NULL; |
| 5548 | plci.setLayoutCount = 1; |
| 5549 | plci.pSetLayouts = &bad_layout; |
| 5550 | vkCreatePipelineLayout(device(), &plci, NULL, &pipeline_layout); |
| 5551 | |
| 5552 | m_errorMonitor->VerifyFound(); |
Tobin Ehlis | 49eb23d | 2015-05-22 12:38:55 -0600 | [diff] [blame] | 5553 | } |
| 5554 | |
Mark Mueller | d491441 | 2016-06-13 17:52:06 -0600 | [diff] [blame] | 5555 | TEST_F(VkLayerTest, WriteDescriptorSetIntegrityCheck) { |
| 5556 | TEST_DESCRIPTION("This test verifies some requirements of chapter 13.2.3 of the Vulkan Spec " |
| 5557 | "1) A uniform buffer update must have a valid buffer index." |
| 5558 | "2) When using an array of descriptors in a single WriteDescriptor," |
| 5559 | " the descriptor types and stageflags must all be the same." |
| 5560 | "3) Immutable Sampler state must match across descriptors"); |
| 5561 | |
| 5562 | const char *invalid_BufferInfo_ErrorMessage = |
| 5563 | "vkUpdateDescriptorSets: if pDescriptorWrites[0].descriptorType is VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, " |
| 5564 | "VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC or " |
| 5565 | "VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC, pDescriptorWrites[0].pBufferInfo must not be NULL"; |
| 5566 | const char *stateFlag_ErrorMessage = |
Mark Mueller | 5c838ce | 2016-06-16 09:54:29 -0600 | [diff] [blame] | 5567 | "Attempting write update to descriptor set "; |
Mark Mueller | d491441 | 2016-06-13 17:52:06 -0600 | [diff] [blame] | 5568 | const char *immutable_ErrorMessage = |
Mark Mueller | 5c838ce | 2016-06-16 09:54:29 -0600 | [diff] [blame] | 5569 | "Attempting write update to descriptor set "; |
Mark Mueller | d491441 | 2016-06-13 17:52:06 -0600 | [diff] [blame] | 5570 | |
Mark Mueller | d491441 | 2016-06-13 17:52:06 -0600 | [diff] [blame] | 5571 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_BufferInfo_ErrorMessage); |
| 5572 | |
| 5573 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 5574 | VkDescriptorPoolSize ds_type_count[4] = {}; |
| 5575 | ds_type_count[0].type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 5576 | ds_type_count[0].descriptorCount = 1; |
| 5577 | ds_type_count[1].type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER; |
| 5578 | ds_type_count[1].descriptorCount = 1; |
| 5579 | ds_type_count[2].type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER; |
| 5580 | ds_type_count[2].descriptorCount = 1; |
| 5581 | ds_type_count[3].type = VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT; |
| 5582 | ds_type_count[3].descriptorCount = 1; |
| 5583 | |
| 5584 | VkDescriptorPoolCreateInfo ds_pool_ci = {}; |
| 5585 | ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO; |
| 5586 | ds_pool_ci.maxSets = 1; |
| 5587 | ds_pool_ci.poolSizeCount = sizeof(ds_type_count) / sizeof(VkDescriptorPoolSize); |
| 5588 | ds_pool_ci.pPoolSizes = ds_type_count; |
| 5589 | |
| 5590 | VkDescriptorPool ds_pool; |
| 5591 | VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool); |
| 5592 | ASSERT_VK_SUCCESS(err); |
| 5593 | |
Mark Mueller | b989672 | 2016-06-16 09:54:29 -0600 | [diff] [blame] | 5594 | VkDescriptorSetLayoutBinding layout_binding[3] = {}; |
Mark Mueller | d491441 | 2016-06-13 17:52:06 -0600 | [diff] [blame] | 5595 | layout_binding[0].binding = 0; |
| 5596 | layout_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 5597 | layout_binding[0].descriptorCount = 1; |
| 5598 | layout_binding[0].stageFlags = VK_SHADER_STAGE_ALL; |
| 5599 | layout_binding[0].pImmutableSamplers = NULL; |
| 5600 | |
| 5601 | layout_binding[1].binding = 1; |
| 5602 | layout_binding[1].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER; |
| 5603 | layout_binding[1].descriptorCount = 1; |
| 5604 | layout_binding[1].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT; |
| 5605 | layout_binding[1].pImmutableSamplers = NULL; |
| 5606 | |
| 5607 | VkSamplerCreateInfo sampler_ci = {}; |
| 5608 | sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO; |
| 5609 | sampler_ci.pNext = NULL; |
| 5610 | sampler_ci.magFilter = VK_FILTER_NEAREST; |
| 5611 | sampler_ci.minFilter = VK_FILTER_NEAREST; |
| 5612 | sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST; |
| 5613 | sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE; |
| 5614 | sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE; |
| 5615 | sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE; |
| 5616 | sampler_ci.mipLodBias = 1.0; |
| 5617 | sampler_ci.anisotropyEnable = VK_FALSE; |
| 5618 | sampler_ci.maxAnisotropy = 1; |
| 5619 | sampler_ci.compareEnable = VK_FALSE; |
| 5620 | sampler_ci.compareOp = VK_COMPARE_OP_NEVER; |
| 5621 | sampler_ci.minLod = 1.0; |
| 5622 | sampler_ci.maxLod = 1.0; |
| 5623 | sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE; |
| 5624 | sampler_ci.unnormalizedCoordinates = VK_FALSE; |
| 5625 | VkSampler sampler; |
| 5626 | |
| 5627 | err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler); |
| 5628 | ASSERT_VK_SUCCESS(err); |
| 5629 | |
| 5630 | layout_binding[2].binding = 2; |
| 5631 | layout_binding[2].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER; |
| 5632 | layout_binding[2].descriptorCount = 1; |
| 5633 | layout_binding[2].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT; |
| 5634 | layout_binding[2].pImmutableSamplers = static_cast<VkSampler *>(&sampler); |
| 5635 | |
Mark Mueller | d491441 | 2016-06-13 17:52:06 -0600 | [diff] [blame] | 5636 | VkDescriptorSetLayoutCreateInfo ds_layout_ci = {}; |
| 5637 | ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO; |
| 5638 | ds_layout_ci.bindingCount = sizeof(layout_binding) / sizeof(VkDescriptorSetLayoutBinding); |
| 5639 | ds_layout_ci.pBindings = layout_binding; |
| 5640 | VkDescriptorSetLayout ds_layout; |
| 5641 | err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout); |
| 5642 | ASSERT_VK_SUCCESS(err); |
| 5643 | |
| 5644 | VkDescriptorSetAllocateInfo alloc_info = {}; |
| 5645 | alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO; |
| 5646 | alloc_info.descriptorSetCount = 1; |
| 5647 | alloc_info.descriptorPool = ds_pool; |
| 5648 | alloc_info.pSetLayouts = &ds_layout; |
| 5649 | VkDescriptorSet descriptorSet; |
| 5650 | err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet); |
| 5651 | ASSERT_VK_SUCCESS(err); |
| 5652 | |
| 5653 | VkPipelineLayoutCreateInfo pipeline_layout_ci = {}; |
| 5654 | pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO; |
| 5655 | pipeline_layout_ci.pNext = NULL; |
| 5656 | pipeline_layout_ci.setLayoutCount = 1; |
| 5657 | pipeline_layout_ci.pSetLayouts = &ds_layout; |
| 5658 | |
| 5659 | VkPipelineLayout pipeline_layout; |
| 5660 | err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout); |
| 5661 | ASSERT_VK_SUCCESS(err); |
| 5662 | |
Mark Mueller | 5c838ce | 2016-06-16 09:54:29 -0600 | [diff] [blame] | 5663 | VkWriteDescriptorSet descriptor_write = {}; |
Mark Mueller | d491441 | 2016-06-13 17:52:06 -0600 | [diff] [blame] | 5664 | descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET; |
| 5665 | descriptor_write.dstSet = descriptorSet; |
| 5666 | descriptor_write.dstBinding = 0; |
| 5667 | descriptor_write.descriptorCount = 1; |
| 5668 | descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 5669 | |
Mark Mueller | 5c838ce | 2016-06-16 09:54:29 -0600 | [diff] [blame] | 5670 | // 1) The uniform buffer is intentionally invalid here |
Mark Mueller | d491441 | 2016-06-13 17:52:06 -0600 | [diff] [blame] | 5671 | vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL); |
| 5672 | m_errorMonitor->VerifyFound(); |
| 5673 | |
| 5674 | // Create a buffer to update the descriptor with |
| 5675 | uint32_t qfi = 0; |
| 5676 | VkBufferCreateInfo buffCI = {}; |
| 5677 | buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO; |
| 5678 | buffCI.size = 1024; |
| 5679 | buffCI.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT; |
| 5680 | buffCI.queueFamilyIndexCount = 1; |
| 5681 | buffCI.pQueueFamilyIndices = &qfi; |
| 5682 | |
| 5683 | VkBuffer dyub; |
| 5684 | err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &dyub); |
| 5685 | ASSERT_VK_SUCCESS(err); |
| 5686 | VkDescriptorBufferInfo buffInfo = {}; |
| 5687 | buffInfo.buffer = dyub; |
| 5688 | buffInfo.offset = 0; |
| 5689 | buffInfo.range = 1024; |
| 5690 | |
| 5691 | descriptor_write.pBufferInfo = &buffInfo; |
| 5692 | descriptor_write.descriptorCount = 2; |
| 5693 | |
Mark Mueller | 5c838ce | 2016-06-16 09:54:29 -0600 | [diff] [blame] | 5694 | // 2) The stateFlags don't match between the first and second descriptor |
Mark Mueller | d491441 | 2016-06-13 17:52:06 -0600 | [diff] [blame] | 5695 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, stateFlag_ErrorMessage); |
| 5696 | vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL); |
| 5697 | m_errorMonitor->VerifyFound(); |
| 5698 | |
Mark Mueller | 5c838ce | 2016-06-16 09:54:29 -0600 | [diff] [blame] | 5699 | // 3) The second descriptor has a null_ptr pImmutableSamplers and |
| 5700 | // the third descriptor contains an immutable sampler |
Mark Mueller | d491441 | 2016-06-13 17:52:06 -0600 | [diff] [blame] | 5701 | descriptor_write.dstBinding = 1; |
| 5702 | descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER; |
Mark Mueller | 5c838ce | 2016-06-16 09:54:29 -0600 | [diff] [blame] | 5703 | |
| 5704 | |
| 5705 | // Make pImageInfo index non-null to avoid complaints of it missing |
| 5706 | VkDescriptorImageInfo imageInfo = {}; |
| 5707 | imageInfo.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL; |
| 5708 | descriptor_write.pImageInfo = &imageInfo; |
Mark Mueller | d491441 | 2016-06-13 17:52:06 -0600 | [diff] [blame] | 5709 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, immutable_ErrorMessage); |
| 5710 | vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL); |
| 5711 | m_errorMonitor->VerifyFound(); |
| 5712 | |
Mark Mueller | d491441 | 2016-06-13 17:52:06 -0600 | [diff] [blame] | 5713 | vkDestroyBuffer(m_device->device(), dyub, NULL); |
| 5714 | vkDestroySampler(m_device->device(), sampler, NULL); |
| 5715 | vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL); |
| 5716 | vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL); |
| 5717 | vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL); |
| 5718 | } |
| 5719 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5720 | TEST_F(VkLayerTest, InvalidPipeline) { |
Karl Schultz | bdb7595 | 2016-04-19 11:36:49 -0600 | [diff] [blame] | 5721 | // Attempt to bind an invalid Pipeline to a valid Command Buffer |
| 5722 | // ObjectTracker should catch this. |
Tobin Ehlis | 49eb23d | 2015-05-22 12:38:55 -0600 | [diff] [blame] | 5723 | // Create a valid cmd buffer |
| 5724 | // call vkCmdBindPipeline w/ false Pipeline |
Mark Lobodzinski | 02bf89d | 2016-05-10 14:45:13 -0600 | [diff] [blame] | 5725 | uint64_t fake_pipeline_handle = 0xbaad6001; |
| 5726 | VkPipeline bad_pipeline = reinterpret_cast<VkPipeline &>(fake_pipeline_handle); |
Karl Schultz | bdb7595 | 2016-04-19 11:36:49 -0600 | [diff] [blame] | 5727 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 5728 | "Invalid VkPipeline Object 0xbaad6001"); |
| 5729 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 5730 | BeginCommandBuffer(); |
| 5731 | vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), |
| 5732 | VK_PIPELINE_BIND_POINT_GRAPHICS, bad_pipeline); |
| 5733 | m_errorMonitor->VerifyFound(); |
Tobin Ehlis | b8b6b27 | 2016-05-02 13:26:06 -0600 | [diff] [blame] | 5734 | // Now issue a draw call with no pipeline bound |
| 5735 | m_errorMonitor->SetDesiredFailureMsg( |
| 5736 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 5737 | "At Draw/Dispatch time no valid VkPipeline is bound!"); |
Tony Barbour | df4c004 | 2016-06-01 15:55:43 -0600 | [diff] [blame] | 5738 | |
Tobin Ehlis | b8b6b27 | 2016-05-02 13:26:06 -0600 | [diff] [blame] | 5739 | BeginCommandBuffer(); |
| 5740 | Draw(1, 0, 0, 0); |
| 5741 | m_errorMonitor->VerifyFound(); |
| 5742 | // Finally same check once more but with Dispatch/Compute |
| 5743 | m_errorMonitor->SetDesiredFailureMsg( |
| 5744 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 5745 | "At Draw/Dispatch time no valid VkPipeline is bound!"); |
Tobin Ehlis | b8b6b27 | 2016-05-02 13:26:06 -0600 | [diff] [blame] | 5746 | BeginCommandBuffer(); |
| 5747 | vkCmdDispatch(m_commandBuffer->GetBufferHandle(), 0, 0, 0); |
| 5748 | m_errorMonitor->VerifyFound(); |
Tobin Ehlis | 49eb23d | 2015-05-22 12:38:55 -0600 | [diff] [blame] | 5749 | } |
| 5750 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5751 | TEST_F(VkLayerTest, DescriptorSetNotUpdated) { |
| 5752 | // Create and update CommandBuffer then call QueueSubmit w/o calling End on |
| 5753 | // CommandBuffer |
| 5754 | VkResult err; |
Tobin Ehlis | 7d1a711 | 2015-05-27 14:32:28 -0600 | [diff] [blame] | 5755 | |
Mark Lobodzinski | 510e20d | 2016-02-11 09:26:16 -0700 | [diff] [blame] | 5756 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5757 | " bound but it was never updated. "); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 5758 | |
Tobin Ehlis | 7d1a711 | 2015-05-27 14:32:28 -0600 | [diff] [blame] | 5759 | ASSERT_NO_FATAL_FAILURE(InitState()); |
Mike Stroyan | 713b2d7 | 2015-08-04 10:49:29 -0600 | [diff] [blame] | 5760 | ASSERT_NO_FATAL_FAILURE(InitViewport()); |
| 5761 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
Chia-I Wu | 1b99bb2 | 2015-10-27 19:25:11 +0800 | [diff] [blame] | 5762 | VkDescriptorPoolSize ds_type_count = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5763 | ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 5764 | ds_type_count.descriptorCount = 1; |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 5765 | |
| 5766 | VkDescriptorPoolCreateInfo ds_pool_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5767 | ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO; |
| 5768 | ds_pool_ci.pNext = NULL; |
| 5769 | ds_pool_ci.maxSets = 1; |
| 5770 | ds_pool_ci.poolSizeCount = 1; |
| 5771 | ds_pool_ci.pPoolSizes = &ds_type_count; |
Mike Stroyan | 713b2d7 | 2015-08-04 10:49:29 -0600 | [diff] [blame] | 5772 | |
Tobin Ehlis | 7d1a711 | 2015-05-27 14:32:28 -0600 | [diff] [blame] | 5773 | VkDescriptorPool ds_pool; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5774 | err = |
| 5775 | vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool); |
Tobin Ehlis | 7d1a711 | 2015-05-27 14:32:28 -0600 | [diff] [blame] | 5776 | ASSERT_VK_SUCCESS(err); |
Tobin Ehlis | 7d1a711 | 2015-05-27 14:32:28 -0600 | [diff] [blame] | 5777 | |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 5778 | VkDescriptorSetLayoutBinding dsl_binding = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5779 | dsl_binding.binding = 0; |
| 5780 | dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 5781 | dsl_binding.descriptorCount = 1; |
| 5782 | dsl_binding.stageFlags = VK_SHADER_STAGE_ALL; |
| 5783 | dsl_binding.pImmutableSamplers = NULL; |
Tobin Ehlis | 7d1a711 | 2015-05-27 14:32:28 -0600 | [diff] [blame] | 5784 | |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 5785 | VkDescriptorSetLayoutCreateInfo ds_layout_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5786 | ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO; |
| 5787 | ds_layout_ci.pNext = NULL; |
| 5788 | ds_layout_ci.bindingCount = 1; |
| 5789 | ds_layout_ci.pBindings = &dsl_binding; |
Tobin Ehlis | 7d1a711 | 2015-05-27 14:32:28 -0600 | [diff] [blame] | 5790 | VkDescriptorSetLayout ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5791 | err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, |
| 5792 | &ds_layout); |
Tobin Ehlis | 7d1a711 | 2015-05-27 14:32:28 -0600 | [diff] [blame] | 5793 | ASSERT_VK_SUCCESS(err); |
| 5794 | |
| 5795 | VkDescriptorSet descriptorSet; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 5796 | VkDescriptorSetAllocateInfo alloc_info = {}; |
Chia-I Wu | 00ce540 | 2015-11-10 16:21:09 +0800 | [diff] [blame] | 5797 | alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO; |
Jon Ashburn | f19916e | 2016-01-11 13:12:43 -0700 | [diff] [blame] | 5798 | alloc_info.descriptorSetCount = 1; |
Courtney Goeltzenleuchter | bee18a9 | 2015-10-23 14:21:05 -0600 | [diff] [blame] | 5799 | alloc_info.descriptorPool = ds_pool; |
| 5800 | alloc_info.pSetLayouts = &ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5801 | err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, |
| 5802 | &descriptorSet); |
Tobin Ehlis | 7d1a711 | 2015-05-27 14:32:28 -0600 | [diff] [blame] | 5803 | ASSERT_VK_SUCCESS(err); |
| 5804 | |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 5805 | VkPipelineLayoutCreateInfo pipeline_layout_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5806 | pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO; |
| 5807 | pipeline_layout_ci.pNext = NULL; |
| 5808 | pipeline_layout_ci.setLayoutCount = 1; |
| 5809 | pipeline_layout_ci.pSetLayouts = &ds_layout; |
Tobin Ehlis | 7d1a711 | 2015-05-27 14:32:28 -0600 | [diff] [blame] | 5810 | |
| 5811 | VkPipelineLayout pipeline_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5812 | err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, |
| 5813 | &pipeline_layout); |
Tobin Ehlis | 7d1a711 | 2015-05-27 14:32:28 -0600 | [diff] [blame] | 5814 | ASSERT_VK_SUCCESS(err); |
| 5815 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5816 | VkShaderObj vs(m_device, bindStateVertShaderText, |
| 5817 | VK_SHADER_STAGE_VERTEX_BIT, this); |
Karl Schultz | bdb7595 | 2016-04-19 11:36:49 -0600 | [diff] [blame] | 5818 | // 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] | 5819 | // on more devices |
| 5820 | VkShaderObj fs(m_device, bindStateFragShaderText, |
| 5821 | VK_SHADER_STAGE_FRAGMENT_BIT, this); |
Tobin Ehlis | 7d1a711 | 2015-05-27 14:32:28 -0600 | [diff] [blame] | 5822 | |
Tony Barbour | c95e4ac | 2015-08-04 17:05:26 -0600 | [diff] [blame] | 5823 | VkPipelineObj pipe(m_device); |
| 5824 | pipe.AddShader(&vs); |
Tony Barbour | 1c94d37 | 2015-08-06 11:21:08 -0600 | [diff] [blame] | 5825 | pipe.AddShader(&fs); |
Mark Young | c89c631 | 2016-03-31 16:03:20 -0600 | [diff] [blame] | 5826 | pipe.AddColorAttachment(); |
Tony Barbour | c95e4ac | 2015-08-04 17:05:26 -0600 | [diff] [blame] | 5827 | pipe.CreateVKPipeline(pipeline_layout, renderPass()); |
Tony Barbour | fe3351b | 2015-07-28 10:17:20 -0600 | [diff] [blame] | 5828 | |
| 5829 | BeginCommandBuffer(); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5830 | vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), |
| 5831 | VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle()); |
| 5832 | vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), |
| 5833 | VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, |
| 5834 | 1, &descriptorSet, 0, NULL); |
Tobin Ehlis | 7d1a711 | 2015-05-27 14:32:28 -0600 | [diff] [blame] | 5835 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 5836 | m_errorMonitor->VerifyFound(); |
Mike Stroyan | d1c84a5 | 2015-08-18 14:40:24 -0600 | [diff] [blame] | 5837 | |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 5838 | vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL); |
| 5839 | vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL); |
| 5840 | vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL); |
Tobin Ehlis | af1f3a4 | 2015-06-25 15:46:59 -0600 | [diff] [blame] | 5841 | } |
| 5842 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5843 | TEST_F(VkLayerTest, InvalidBufferViewObject) { |
Tobin Ehlis | ba31cab | 2015-11-02 15:24:32 -0700 | [diff] [blame] | 5844 | // Create a single TEXEL_BUFFER descriptor and send it an invalid bufferView |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5845 | VkResult err; |
Tobin Ehlis | ba31cab | 2015-11-02 15:24:32 -0700 | [diff] [blame] | 5846 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5847 | m_errorMonitor->SetDesiredFailureMsg( |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 5848 | VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attempted write update to texel buffer " |
| 5849 | "descriptor with invalid buffer view"); |
Tobin Ehlis | ba31cab | 2015-11-02 15:24:32 -0700 | [diff] [blame] | 5850 | |
| 5851 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 5852 | VkDescriptorPoolSize ds_type_count = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5853 | ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER; |
| 5854 | ds_type_count.descriptorCount = 1; |
Tobin Ehlis | ba31cab | 2015-11-02 15:24:32 -0700 | [diff] [blame] | 5855 | |
| 5856 | VkDescriptorPoolCreateInfo ds_pool_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5857 | ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO; |
| 5858 | ds_pool_ci.pNext = NULL; |
| 5859 | ds_pool_ci.maxSets = 1; |
| 5860 | ds_pool_ci.poolSizeCount = 1; |
| 5861 | ds_pool_ci.pPoolSizes = &ds_type_count; |
Tobin Ehlis | ba31cab | 2015-11-02 15:24:32 -0700 | [diff] [blame] | 5862 | |
| 5863 | VkDescriptorPool ds_pool; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5864 | err = |
| 5865 | vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool); |
Tobin Ehlis | ba31cab | 2015-11-02 15:24:32 -0700 | [diff] [blame] | 5866 | ASSERT_VK_SUCCESS(err); |
| 5867 | |
| 5868 | VkDescriptorSetLayoutBinding dsl_binding = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5869 | dsl_binding.binding = 0; |
| 5870 | dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER; |
| 5871 | dsl_binding.descriptorCount = 1; |
| 5872 | dsl_binding.stageFlags = VK_SHADER_STAGE_ALL; |
| 5873 | dsl_binding.pImmutableSamplers = NULL; |
Tobin Ehlis | ba31cab | 2015-11-02 15:24:32 -0700 | [diff] [blame] | 5874 | |
| 5875 | VkDescriptorSetLayoutCreateInfo ds_layout_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5876 | ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO; |
| 5877 | ds_layout_ci.pNext = NULL; |
| 5878 | ds_layout_ci.bindingCount = 1; |
| 5879 | ds_layout_ci.pBindings = &dsl_binding; |
Tobin Ehlis | ba31cab | 2015-11-02 15:24:32 -0700 | [diff] [blame] | 5880 | VkDescriptorSetLayout ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5881 | err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, |
| 5882 | &ds_layout); |
Tobin Ehlis | ba31cab | 2015-11-02 15:24:32 -0700 | [diff] [blame] | 5883 | ASSERT_VK_SUCCESS(err); |
| 5884 | |
| 5885 | VkDescriptorSet descriptorSet; |
| 5886 | VkDescriptorSetAllocateInfo alloc_info = {}; |
Chia-I Wu | 00ce540 | 2015-11-10 16:21:09 +0800 | [diff] [blame] | 5887 | alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO; |
Jon Ashburn | f19916e | 2016-01-11 13:12:43 -0700 | [diff] [blame] | 5888 | alloc_info.descriptorSetCount = 1; |
Tobin Ehlis | ba31cab | 2015-11-02 15:24:32 -0700 | [diff] [blame] | 5889 | alloc_info.descriptorPool = ds_pool; |
| 5890 | alloc_info.pSetLayouts = &ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5891 | err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, |
| 5892 | &descriptorSet); |
Tobin Ehlis | ba31cab | 2015-11-02 15:24:32 -0700 | [diff] [blame] | 5893 | ASSERT_VK_SUCCESS(err); |
| 5894 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5895 | VkBufferView view = |
| 5896 | (VkBufferView)((size_t)0xbaadbeef); // invalid bufferView object |
Tobin Ehlis | ba31cab | 2015-11-02 15:24:32 -0700 | [diff] [blame] | 5897 | VkWriteDescriptorSet descriptor_write; |
| 5898 | memset(&descriptor_write, 0, sizeof(descriptor_write)); |
| 5899 | descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET; |
| 5900 | descriptor_write.dstSet = descriptorSet; |
| 5901 | descriptor_write.dstBinding = 0; |
| 5902 | descriptor_write.descriptorCount = 1; |
| 5903 | descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER; |
| 5904 | descriptor_write.pTexelBufferView = &view; |
| 5905 | |
| 5906 | vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL); |
| 5907 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 5908 | m_errorMonitor->VerifyFound(); |
Tobin Ehlis | ba31cab | 2015-11-02 15:24:32 -0700 | [diff] [blame] | 5909 | |
| 5910 | vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL); |
| 5911 | vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL); |
| 5912 | } |
| 5913 | |
Mark Young | d339ba3 | 2016-05-30 13:28:35 -0600 | [diff] [blame] | 5914 | TEST_F(VkLayerTest, CreateBufferViewNoMemoryBoundToBuffer) { |
| 5915 | TEST_DESCRIPTION("Attempt to create a buffer view with a buffer that has" |
| 5916 | " no memory bound to it."); |
| 5917 | |
| 5918 | VkResult err; |
| 5919 | m_errorMonitor->SetDesiredFailureMsg( |
| 5920 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 5921 | "vkCreateBufferView called with invalid memory "); |
| 5922 | |
| 5923 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 5924 | |
| 5925 | // Create a buffer with no bound memory and then attempt to create |
| 5926 | // a buffer view. |
| 5927 | VkBufferCreateInfo buff_ci = {}; |
| 5928 | buff_ci.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO; |
| 5929 | buff_ci.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT; |
| 5930 | buff_ci.size = 256; |
| 5931 | buff_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE; |
| 5932 | VkBuffer buffer; |
| 5933 | err = vkCreateBuffer(m_device->device(), &buff_ci, NULL, &buffer); |
| 5934 | ASSERT_VK_SUCCESS(err); |
| 5935 | |
| 5936 | VkBufferViewCreateInfo buff_view_ci = {}; |
| 5937 | buff_view_ci.sType = VK_STRUCTURE_TYPE_BUFFER_VIEW_CREATE_INFO; |
| 5938 | buff_view_ci.buffer = buffer; |
| 5939 | buff_view_ci.format = VK_FORMAT_R8_UNORM; |
| 5940 | buff_view_ci.range = VK_WHOLE_SIZE; |
| 5941 | VkBufferView buff_view; |
| 5942 | err = |
| 5943 | vkCreateBufferView(m_device->device(), &buff_view_ci, NULL, &buff_view); |
| 5944 | |
| 5945 | m_errorMonitor->VerifyFound(); |
| 5946 | vkDestroyBuffer(m_device->device(), buffer, NULL); |
| 5947 | // If last error is success, it still created the view, so delete it. |
| 5948 | if (err == VK_SUCCESS) { |
| 5949 | vkDestroyBufferView(m_device->device(), buff_view, NULL); |
| 5950 | } |
| 5951 | } |
| 5952 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5953 | TEST_F(VkLayerTest, InvalidDynamicOffsetCases) { |
| 5954 | // Create a descriptorSet w/ dynamic descriptor and then hit 3 offset error |
| 5955 | // cases: |
Tobin Ehlis | f658505 | 2015-12-17 11:48:42 -0700 | [diff] [blame] | 5956 | // 1. No dynamicOffset supplied |
| 5957 | // 2. Too many dynamicOffsets supplied |
| 5958 | // 3. Dynamic offset oversteps buffer being updated |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5959 | VkResult err; |
Courtney Goeltzenleuchter | 7415d5a | 2015-12-09 15:48:16 -0700 | [diff] [blame] | 5960 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5961 | " requires 1 dynamicOffsets, but only " |
| 5962 | "0 dynamicOffsets are left in " |
| 5963 | "pDynamicOffsets "); |
Tobin Ehlis | 49f903e | 2015-11-04 13:30:34 -0700 | [diff] [blame] | 5964 | |
| 5965 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 5966 | ASSERT_NO_FATAL_FAILURE(InitViewport()); |
| 5967 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 5968 | |
| 5969 | VkDescriptorPoolSize ds_type_count = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5970 | ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC; |
| 5971 | ds_type_count.descriptorCount = 1; |
Tobin Ehlis | 49f903e | 2015-11-04 13:30:34 -0700 | [diff] [blame] | 5972 | |
| 5973 | VkDescriptorPoolCreateInfo ds_pool_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5974 | ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO; |
| 5975 | ds_pool_ci.pNext = NULL; |
| 5976 | ds_pool_ci.maxSets = 1; |
| 5977 | ds_pool_ci.poolSizeCount = 1; |
| 5978 | ds_pool_ci.pPoolSizes = &ds_type_count; |
Tobin Ehlis | 49f903e | 2015-11-04 13:30:34 -0700 | [diff] [blame] | 5979 | |
| 5980 | VkDescriptorPool ds_pool; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5981 | err = |
| 5982 | vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool); |
Tobin Ehlis | 49f903e | 2015-11-04 13:30:34 -0700 | [diff] [blame] | 5983 | ASSERT_VK_SUCCESS(err); |
| 5984 | |
| 5985 | VkDescriptorSetLayoutBinding dsl_binding = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5986 | dsl_binding.binding = 0; |
| 5987 | dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC; |
| 5988 | dsl_binding.descriptorCount = 1; |
| 5989 | dsl_binding.stageFlags = VK_SHADER_STAGE_ALL; |
| 5990 | dsl_binding.pImmutableSamplers = NULL; |
Tobin Ehlis | 49f903e | 2015-11-04 13:30:34 -0700 | [diff] [blame] | 5991 | |
| 5992 | VkDescriptorSetLayoutCreateInfo ds_layout_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5993 | ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO; |
| 5994 | ds_layout_ci.pNext = NULL; |
| 5995 | ds_layout_ci.bindingCount = 1; |
| 5996 | ds_layout_ci.pBindings = &dsl_binding; |
Tobin Ehlis | 49f903e | 2015-11-04 13:30:34 -0700 | [diff] [blame] | 5997 | VkDescriptorSetLayout ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5998 | err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, |
| 5999 | &ds_layout); |
Tobin Ehlis | 49f903e | 2015-11-04 13:30:34 -0700 | [diff] [blame] | 6000 | ASSERT_VK_SUCCESS(err); |
| 6001 | |
| 6002 | VkDescriptorSet descriptorSet; |
| 6003 | VkDescriptorSetAllocateInfo alloc_info = {}; |
Chia-I Wu | 00ce540 | 2015-11-10 16:21:09 +0800 | [diff] [blame] | 6004 | alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO; |
Jon Ashburn | f19916e | 2016-01-11 13:12:43 -0700 | [diff] [blame] | 6005 | alloc_info.descriptorSetCount = 1; |
Tobin Ehlis | 49f903e | 2015-11-04 13:30:34 -0700 | [diff] [blame] | 6006 | alloc_info.descriptorPool = ds_pool; |
| 6007 | alloc_info.pSetLayouts = &ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6008 | err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, |
| 6009 | &descriptorSet); |
Tobin Ehlis | 49f903e | 2015-11-04 13:30:34 -0700 | [diff] [blame] | 6010 | ASSERT_VK_SUCCESS(err); |
| 6011 | |
| 6012 | VkPipelineLayoutCreateInfo pipeline_layout_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6013 | pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO; |
| 6014 | pipeline_layout_ci.pNext = NULL; |
| 6015 | pipeline_layout_ci.setLayoutCount = 1; |
| 6016 | pipeline_layout_ci.pSetLayouts = &ds_layout; |
Tobin Ehlis | 49f903e | 2015-11-04 13:30:34 -0700 | [diff] [blame] | 6017 | |
| 6018 | VkPipelineLayout pipeline_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6019 | err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, |
| 6020 | &pipeline_layout); |
Tobin Ehlis | 49f903e | 2015-11-04 13:30:34 -0700 | [diff] [blame] | 6021 | ASSERT_VK_SUCCESS(err); |
| 6022 | |
| 6023 | // Create a buffer to update the descriptor with |
| 6024 | uint32_t qfi = 0; |
| 6025 | VkBufferCreateInfo buffCI = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6026 | buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO; |
| 6027 | buffCI.size = 1024; |
| 6028 | buffCI.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT; |
| 6029 | buffCI.queueFamilyIndexCount = 1; |
| 6030 | buffCI.pQueueFamilyIndices = &qfi; |
Tobin Ehlis | 49f903e | 2015-11-04 13:30:34 -0700 | [diff] [blame] | 6031 | |
| 6032 | VkBuffer dyub; |
| 6033 | err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &dyub); |
| 6034 | ASSERT_VK_SUCCESS(err); |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 6035 | // Allocate memory and bind to buffer so we can make it to the appropriate |
| 6036 | // error |
| 6037 | VkMemoryAllocateInfo mem_alloc = {}; |
| 6038 | mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO; |
| 6039 | mem_alloc.pNext = NULL; |
| 6040 | mem_alloc.allocationSize = 1024; |
Chris Forbes | b6116cc | 2016-05-08 11:39:59 +1200 | [diff] [blame] | 6041 | mem_alloc.memoryTypeIndex = 0; |
| 6042 | |
| 6043 | VkMemoryRequirements memReqs; |
| 6044 | vkGetBufferMemoryRequirements(m_device->device(), dyub, &memReqs); |
| 6045 | bool pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &mem_alloc, |
| 6046 | 0); |
| 6047 | if (!pass) { |
| 6048 | vkDestroyBuffer(m_device->device(), dyub, NULL); |
| 6049 | return; |
| 6050 | } |
| 6051 | |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 6052 | VkDeviceMemory mem; |
| 6053 | err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem); |
| 6054 | ASSERT_VK_SUCCESS(err); |
| 6055 | err = vkBindBufferMemory(m_device->device(), dyub, mem, 0); |
| 6056 | ASSERT_VK_SUCCESS(err); |
Tobin Ehlis | 49f903e | 2015-11-04 13:30:34 -0700 | [diff] [blame] | 6057 | // Correctly update descriptor to avoid "NOT_UPDATED" error |
| 6058 | VkDescriptorBufferInfo buffInfo = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6059 | buffInfo.buffer = dyub; |
| 6060 | buffInfo.offset = 0; |
| 6061 | buffInfo.range = 1024; |
Tobin Ehlis | 49f903e | 2015-11-04 13:30:34 -0700 | [diff] [blame] | 6062 | |
| 6063 | VkWriteDescriptorSet descriptor_write; |
| 6064 | memset(&descriptor_write, 0, sizeof(descriptor_write)); |
| 6065 | descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET; |
| 6066 | descriptor_write.dstSet = descriptorSet; |
| 6067 | descriptor_write.dstBinding = 0; |
| 6068 | descriptor_write.descriptorCount = 1; |
| 6069 | descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC; |
| 6070 | descriptor_write.pBufferInfo = &buffInfo; |
| 6071 | |
| 6072 | vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL); |
| 6073 | |
| 6074 | BeginCommandBuffer(); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6075 | vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), |
| 6076 | VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, |
| 6077 | 1, &descriptorSet, 0, NULL); |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 6078 | m_errorMonitor->VerifyFound(); |
Tobin Ehlis | f658505 | 2015-12-17 11:48:42 -0700 | [diff] [blame] | 6079 | uint32_t pDynOff[2] = {512, 756}; |
| 6080 | // 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] | 6081 | m_errorMonitor->SetDesiredFailureMsg( |
| 6082 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Tobin Ehlis | f658505 | 2015-12-17 11:48:42 -0700 | [diff] [blame] | 6083 | "Attempting to bind 1 descriptorSets with 1 dynamic descriptors, but "); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6084 | vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), |
| 6085 | VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, |
| 6086 | 1, &descriptorSet, 2, pDynOff); |
Chris Forbes | 7b34280 | 2016-04-07 13:20:10 +1200 | [diff] [blame] | 6087 | m_errorMonitor->VerifyFound(); |
Tobin Ehlis | f658505 | 2015-12-17 11:48:42 -0700 | [diff] [blame] | 6088 | // Finally cause error due to dynamicOffset being too big |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 6089 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 6090 | " dynamic offset 512 combined with " |
| 6091 | "offset 0 and range 1024 that " |
| 6092 | "oversteps the buffer size of 1024"); |
Tobin Ehlis | f658505 | 2015-12-17 11:48:42 -0700 | [diff] [blame] | 6093 | // Create PSO to be used for draw-time errors below |
| 6094 | char const *vsSource = |
Chris Forbes | 7b34280 | 2016-04-07 13:20:10 +1200 | [diff] [blame] | 6095 | "#version 450\n" |
Tobin Ehlis | f658505 | 2015-12-17 11:48:42 -0700 | [diff] [blame] | 6096 | "\n" |
Tony Barbour | e804d20 | 2016-01-05 13:37:45 -0700 | [diff] [blame] | 6097 | "out gl_PerVertex { \n" |
| 6098 | " vec4 gl_Position;\n" |
| 6099 | "};\n" |
Tobin Ehlis | f658505 | 2015-12-17 11:48:42 -0700 | [diff] [blame] | 6100 | "void main(){\n" |
| 6101 | " gl_Position = vec4(1);\n" |
| 6102 | "}\n"; |
| 6103 | char const *fsSource = |
Chris Forbes | 7b34280 | 2016-04-07 13:20:10 +1200 | [diff] [blame] | 6104 | "#version 450\n" |
Tobin Ehlis | f658505 | 2015-12-17 11:48:42 -0700 | [diff] [blame] | 6105 | "\n" |
| 6106 | "layout(location=0) out vec4 x;\n" |
| 6107 | "layout(set=0) layout(binding=0) uniform foo { int x; int y; } bar;\n" |
| 6108 | "void main(){\n" |
| 6109 | " x = vec4(bar.y);\n" |
| 6110 | "}\n"; |
| 6111 | VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this); |
| 6112 | VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this); |
| 6113 | VkPipelineObj pipe(m_device); |
| 6114 | pipe.AddShader(&vs); |
| 6115 | pipe.AddShader(&fs); |
| 6116 | pipe.AddColorAttachment(); |
| 6117 | pipe.CreateVKPipeline(pipeline_layout, renderPass()); |
| 6118 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6119 | vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), |
| 6120 | VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle()); |
| 6121 | // This update should succeed, but offset size of 512 will overstep buffer |
| 6122 | // /w range 1024 & size 1024 |
| 6123 | vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), |
| 6124 | VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, |
| 6125 | 1, &descriptorSet, 1, pDynOff); |
Tobin Ehlis | f658505 | 2015-12-17 11:48:42 -0700 | [diff] [blame] | 6126 | Draw(1, 0, 0, 0); |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 6127 | m_errorMonitor->VerifyFound(); |
Tobin Ehlis | 49f903e | 2015-11-04 13:30:34 -0700 | [diff] [blame] | 6128 | |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 6129 | vkDestroyBuffer(m_device->device(), dyub, NULL); |
Tobin Ehlis | 512098e | 2016-05-05 09:06:12 -0600 | [diff] [blame] | 6130 | vkFreeMemory(m_device->device(), mem, NULL); |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 6131 | |
Tobin Ehlis | 49f903e | 2015-11-04 13:30:34 -0700 | [diff] [blame] | 6132 | vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL); |
Tony Barbour | df4c004 | 2016-06-01 15:55:43 -0600 | [diff] [blame] | 6133 | vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL); |
Tobin Ehlis | 49f903e | 2015-11-04 13:30:34 -0700 | [diff] [blame] | 6134 | vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL); |
| 6135 | } |
| 6136 | |
Tobin Ehlis | 3a23b6a | 2016-02-17 10:35:18 -0700 | [diff] [blame] | 6137 | TEST_F(VkLayerTest, InvalidPushConstants) { |
Tobin Ehlis | 3a23b6a | 2016-02-17 10:35:18 -0700 | [diff] [blame] | 6138 | VkResult err; |
Tobin Ehlis | 3a23b6a | 2016-02-17 10:35:18 -0700 | [diff] [blame] | 6139 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 6140 | ASSERT_NO_FATAL_FAILURE(InitViewport()); |
| 6141 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 6142 | |
Karl Schultz | fc8eaf1 | 2016-05-06 13:56:42 -0600 | [diff] [blame] | 6143 | VkPipelineLayout pipeline_layout; |
Tobin Ehlis | 3a23b6a | 2016-02-17 10:35:18 -0700 | [diff] [blame] | 6144 | VkPushConstantRange pc_range = {}; |
Tobin Ehlis | 3a23b6a | 2016-02-17 10:35:18 -0700 | [diff] [blame] | 6145 | VkPipelineLayoutCreateInfo pipeline_layout_ci = {}; |
| 6146 | pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO; |
| 6147 | pipeline_layout_ci.pushConstantRangeCount = 1; |
| 6148 | pipeline_layout_ci.pPushConstantRanges = &pc_range; |
| 6149 | |
Karl Schultz | fc8eaf1 | 2016-05-06 13:56:42 -0600 | [diff] [blame] | 6150 | // |
| 6151 | // Check for invalid push constant ranges in pipeline layouts. |
| 6152 | // |
| 6153 | struct PipelineLayoutTestCase { |
Karl Schultz | c81037d | 2016-05-12 08:11:23 -0600 | [diff] [blame] | 6154 | VkPushConstantRange const range; |
Karl Schultz | fc8eaf1 | 2016-05-06 13:56:42 -0600 | [diff] [blame] | 6155 | char const *msg; |
| 6156 | }; |
Tobin Ehlis | 3a23b6a | 2016-02-17 10:35:18 -0700 | [diff] [blame] | 6157 | |
Karl Schultz | c81037d | 2016-05-12 08:11:23 -0600 | [diff] [blame] | 6158 | const uint32_t too_big = m_device->props.limits.maxPushConstantsSize + 0x4; |
| 6159 | const std::array<PipelineLayoutTestCase, 10> range_tests = {{ |
| 6160 | {{VK_SHADER_STAGE_VERTEX_BIT, 0, 0}, |
| 6161 | "vkCreatePipelineLayout() call has push constants index 0 with " |
| 6162 | "size 0."}, |
| 6163 | {{VK_SHADER_STAGE_VERTEX_BIT, 0, 1}, |
| 6164 | "vkCreatePipelineLayout() call has push constants index 0 with " |
| 6165 | "size 1."}, |
| 6166 | {{VK_SHADER_STAGE_VERTEX_BIT, 1, 1}, |
| 6167 | "vkCreatePipelineLayout() call has push constants index 0 with " |
| 6168 | "size 1."}, |
| 6169 | {{VK_SHADER_STAGE_VERTEX_BIT, 1, 0}, |
| 6170 | "vkCreatePipelineLayout() call has push constants index 0 with " |
| 6171 | "size 0."}, |
| 6172 | {{VK_SHADER_STAGE_VERTEX_BIT, 1, 4}, |
| 6173 | "vkCreatePipelineLayout() call has push constants index 0 with " |
| 6174 | "offset 1. Offset must"}, |
| 6175 | {{VK_SHADER_STAGE_VERTEX_BIT, 0, too_big}, |
| 6176 | "vkCreatePipelineLayout() call has push constants index 0 " |
| 6177 | "with offset "}, |
| 6178 | {{VK_SHADER_STAGE_VERTEX_BIT, too_big, too_big}, |
| 6179 | "vkCreatePipelineLayout() call has push constants " |
| 6180 | "index 0 with offset "}, |
| 6181 | {{VK_SHADER_STAGE_VERTEX_BIT, too_big, 0}, |
| 6182 | "vkCreatePipelineLayout() call has push constants index 0 " |
| 6183 | "with offset "}, |
| 6184 | {{VK_SHADER_STAGE_VERTEX_BIT, 0xFFFFFFF0, 0x00000020}, |
| 6185 | "vkCreatePipelineLayout() call has push " |
| 6186 | "constants index 0 with offset "}, |
| 6187 | {{VK_SHADER_STAGE_VERTEX_BIT, 0x00000020, 0xFFFFFFF0}, |
| 6188 | "vkCreatePipelineLayout() call has push " |
| 6189 | "constants index 0 with offset "}, |
Karl Schultz | fc8eaf1 | 2016-05-06 13:56:42 -0600 | [diff] [blame] | 6190 | }}; |
| 6191 | |
| 6192 | // Check for invalid offset and size |
Karl Schultz | c81037d | 2016-05-12 08:11:23 -0600 | [diff] [blame] | 6193 | for (const auto &iter : range_tests) { |
| 6194 | pc_range = iter.range; |
Karl Schultz | fc8eaf1 | 2016-05-06 13:56:42 -0600 | [diff] [blame] | 6195 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 6196 | iter.msg); |
| 6197 | err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, |
| 6198 | NULL, &pipeline_layout); |
| 6199 | m_errorMonitor->VerifyFound(); |
| 6200 | if (VK_SUCCESS == err) { |
| 6201 | vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL); |
| 6202 | } |
| 6203 | } |
| 6204 | |
| 6205 | // Check for invalid stage flag |
| 6206 | pc_range.offset = 0; |
| 6207 | pc_range.size = 16; |
| 6208 | pc_range.stageFlags = 0; |
Tobin Ehlis | 3a23b6a | 2016-02-17 10:35:18 -0700 | [diff] [blame] | 6209 | m_errorMonitor->SetDesiredFailureMsg( |
| 6210 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Karl Schultz | fc8eaf1 | 2016-05-06 13:56:42 -0600 | [diff] [blame] | 6211 | "vkCreatePipelineLayout() call has no stageFlags set."); |
Tobin Ehlis | 3a23b6a | 2016-02-17 10:35:18 -0700 | [diff] [blame] | 6212 | err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, |
| 6213 | &pipeline_layout); |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 6214 | m_errorMonitor->VerifyFound(); |
Karl Schultz | fc8eaf1 | 2016-05-06 13:56:42 -0600 | [diff] [blame] | 6215 | if (VK_SUCCESS == err) { |
| 6216 | vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL); |
| 6217 | } |
| 6218 | |
| 6219 | // Check for overlapping ranges |
Karl Schultz | c81037d | 2016-05-12 08:11:23 -0600 | [diff] [blame] | 6220 | const uint32_t ranges_per_test = 5; |
Karl Schultz | fc8eaf1 | 2016-05-06 13:56:42 -0600 | [diff] [blame] | 6221 | struct OverlappingRangeTestCase { |
Karl Schultz | c81037d | 2016-05-12 08:11:23 -0600 | [diff] [blame] | 6222 | VkPushConstantRange const ranges[ranges_per_test]; |
Karl Schultz | fc8eaf1 | 2016-05-06 13:56:42 -0600 | [diff] [blame] | 6223 | char const *msg; |
| 6224 | }; |
| 6225 | |
Karl Schultz | c81037d | 2016-05-12 08:11:23 -0600 | [diff] [blame] | 6226 | const std::array<OverlappingRangeTestCase, 5> overlapping_range_tests = { |
Karl Schultz | fc8eaf1 | 2016-05-06 13:56:42 -0600 | [diff] [blame] | 6227 | {{{{VK_SHADER_STAGE_VERTEX_BIT, 0, 4}, |
| 6228 | {VK_SHADER_STAGE_VERTEX_BIT, 0, 4}, |
| 6229 | {VK_SHADER_STAGE_VERTEX_BIT, 0, 4}, |
| 6230 | {VK_SHADER_STAGE_VERTEX_BIT, 0, 4}, |
| 6231 | {VK_SHADER_STAGE_VERTEX_BIT, 0, 4}}, |
| 6232 | "vkCreatePipelineLayout() call has push constants with overlapping " |
| 6233 | "ranges: 0:[0, 4), 1:[0, 4)"}, |
| 6234 | { |
| 6235 | {{VK_SHADER_STAGE_VERTEX_BIT, 0, 4}, |
| 6236 | {VK_SHADER_STAGE_VERTEX_BIT, 4, 4}, |
| 6237 | {VK_SHADER_STAGE_VERTEX_BIT, 8, 4}, |
| 6238 | {VK_SHADER_STAGE_VERTEX_BIT, 12, 8}, |
| 6239 | {VK_SHADER_STAGE_VERTEX_BIT, 16, 4}}, |
| 6240 | "vkCreatePipelineLayout() call has push constants with " |
| 6241 | "overlapping " |
| 6242 | "ranges: 3:[12, 20), 4:[16, 20)", |
| 6243 | }, |
| 6244 | { |
| 6245 | {{VK_SHADER_STAGE_VERTEX_BIT, 16, 4}, |
| 6246 | {VK_SHADER_STAGE_VERTEX_BIT, 12, 8}, |
| 6247 | {VK_SHADER_STAGE_VERTEX_BIT, 8, 4}, |
| 6248 | {VK_SHADER_STAGE_VERTEX_BIT, 4, 4}, |
| 6249 | {VK_SHADER_STAGE_VERTEX_BIT, 0, 4}}, |
| 6250 | "vkCreatePipelineLayout() call has push constants with " |
| 6251 | "overlapping " |
| 6252 | "ranges: 0:[16, 20), 1:[12, 20)", |
| 6253 | }, |
| 6254 | { |
| 6255 | {{VK_SHADER_STAGE_VERTEX_BIT, 16, 4}, |
| 6256 | {VK_SHADER_STAGE_VERTEX_BIT, 8, 4}, |
| 6257 | {VK_SHADER_STAGE_VERTEX_BIT, 4, 4}, |
| 6258 | {VK_SHADER_STAGE_VERTEX_BIT, 12, 8}, |
| 6259 | {VK_SHADER_STAGE_VERTEX_BIT, 0, 4}}, |
| 6260 | "vkCreatePipelineLayout() call has push constants with " |
| 6261 | "overlapping " |
| 6262 | "ranges: 0:[16, 20), 3:[12, 20)", |
| 6263 | }, |
| 6264 | { |
| 6265 | {{VK_SHADER_STAGE_VERTEX_BIT, 16, 4}, |
| 6266 | {VK_SHADER_STAGE_VERTEX_BIT, 32, 4}, |
| 6267 | {VK_SHADER_STAGE_VERTEX_BIT, 4, 96}, |
| 6268 | {VK_SHADER_STAGE_VERTEX_BIT, 40, 8}, |
| 6269 | {VK_SHADER_STAGE_VERTEX_BIT, 52, 4}}, |
| 6270 | "vkCreatePipelineLayout() call has push constants with " |
| 6271 | "overlapping " |
| 6272 | "ranges: 0:[16, 20), 2:[4, 100)", |
| 6273 | }}}; |
Karl Schultz | fc8eaf1 | 2016-05-06 13:56:42 -0600 | [diff] [blame] | 6274 | |
Karl Schultz | c81037d | 2016-05-12 08:11:23 -0600 | [diff] [blame] | 6275 | for (const auto &iter : overlapping_range_tests) { |
Karl Schultz | fc8eaf1 | 2016-05-06 13:56:42 -0600 | [diff] [blame] | 6276 | pipeline_layout_ci.pPushConstantRanges = iter.ranges; |
Karl Schultz | c81037d | 2016-05-12 08:11:23 -0600 | [diff] [blame] | 6277 | pipeline_layout_ci.pushConstantRangeCount = ranges_per_test; |
| 6278 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, |
Karl Schultz | fc8eaf1 | 2016-05-06 13:56:42 -0600 | [diff] [blame] | 6279 | iter.msg); |
| 6280 | err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, |
| 6281 | NULL, &pipeline_layout); |
| 6282 | m_errorMonitor->VerifyFound(); |
| 6283 | if (VK_SUCCESS == err) { |
| 6284 | vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL); |
| 6285 | } |
| 6286 | } |
| 6287 | |
| 6288 | // 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] | 6289 | const std::array<OverlappingRangeTestCase, 2> overlapping_range_tests_pos = |
| 6290 | {{{{{VK_SHADER_STAGE_VERTEX_BIT, 0, 4}, |
| 6291 | {VK_SHADER_STAGE_VERTEX_BIT, 4, 4}, |
| 6292 | {VK_SHADER_STAGE_VERTEX_BIT, 8, 4}, |
| 6293 | {VK_SHADER_STAGE_VERTEX_BIT, 12, 4}, |
| 6294 | {VK_SHADER_STAGE_VERTEX_BIT, 16, 4}}, |
| 6295 | ""}, |
| 6296 | {{{VK_SHADER_STAGE_VERTEX_BIT, 92, 24}, |
| 6297 | {VK_SHADER_STAGE_VERTEX_BIT, 80, 4}, |
| 6298 | {VK_SHADER_STAGE_VERTEX_BIT, 64, 8}, |
| 6299 | {VK_SHADER_STAGE_VERTEX_BIT, 4, 16}, |
| 6300 | {VK_SHADER_STAGE_VERTEX_BIT, 0, 4}}, |
| 6301 | ""}}}; |
| 6302 | for (const auto &iter : overlapping_range_tests_pos) { |
Karl Schultz | fc8eaf1 | 2016-05-06 13:56:42 -0600 | [diff] [blame] | 6303 | pipeline_layout_ci.pPushConstantRanges = iter.ranges; |
| 6304 | m_errorMonitor->ExpectSuccess(); |
| 6305 | err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, |
| 6306 | NULL, &pipeline_layout); |
| 6307 | m_errorMonitor->VerifyNotFound(); |
| 6308 | if (VK_SUCCESS == err) { |
| 6309 | vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL); |
| 6310 | } |
| 6311 | } |
| 6312 | |
| 6313 | // |
| 6314 | // CmdPushConstants tests |
| 6315 | // |
Karl Schultz | c81037d | 2016-05-12 08:11:23 -0600 | [diff] [blame] | 6316 | const uint8_t dummy_values[100] = {}; |
Karl Schultz | fc8eaf1 | 2016-05-06 13:56:42 -0600 | [diff] [blame] | 6317 | |
| 6318 | // 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] | 6319 | const std::array<PipelineLayoutTestCase, 16> cmd_range_tests = {{ |
| 6320 | {{VK_SHADER_STAGE_VERTEX_BIT, 0, 0}, |
| 6321 | "vkCmdPushConstants() call has push constants with size 0. Size " |
| 6322 | "must be greater than zero and a multiple of 4."}, |
| 6323 | {{VK_SHADER_STAGE_VERTEX_BIT, 0, 1}, |
| 6324 | "vkCmdPushConstants() call has push constants with size 1. Size " |
| 6325 | "must be greater than zero and a multiple of 4."}, |
| 6326 | {{VK_SHADER_STAGE_VERTEX_BIT, 1, 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, 0}, |
| 6330 | "vkCmdPushConstants() call has push constants with offset 1. " |
| 6331 | "Offset must be a multiple of 4."}, |
| 6332 | {{VK_SHADER_STAGE_VERTEX_BIT, 1, 4}, |
| 6333 | "vkCmdPushConstants() call has push constants with offset 1. " |
| 6334 | "Offset must be a multiple of 4."}, |
| 6335 | {{VK_SHADER_STAGE_VERTEX_BIT, 0, 20}, |
| 6336 | "vkCmdPushConstants() Push constant range [0, 20) with stageFlags = " |
| 6337 | "0x1 not within flag-matching ranges in pipeline layout"}, |
| 6338 | {{VK_SHADER_STAGE_VERTEX_BIT, 60, 8}, |
| 6339 | "vkCmdPushConstants() Push constant range [60, 68) with stageFlags = " |
| 6340 | "0x1 not within flag-matching ranges in pipeline layout"}, |
| 6341 | {{VK_SHADER_STAGE_VERTEX_BIT, 76, 8}, |
| 6342 | "vkCmdPushConstants() Push constant range [76, 84) with stageFlags = " |
| 6343 | "0x1 not within flag-matching ranges in pipeline layout"}, |
| 6344 | {{VK_SHADER_STAGE_VERTEX_BIT, 0, 80}, |
| 6345 | "vkCmdPushConstants() Push constant range [0, 80) with stageFlags = " |
| 6346 | "0x1 not within flag-matching ranges in pipeline layout"}, |
| 6347 | {{VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT, 0, 4}, |
| 6348 | "vkCmdPushConstants() stageFlags = 0x2 do not match the stageFlags in " |
| 6349 | "any of the ranges in pipeline layout"}, |
| 6350 | {{VK_SHADER_STAGE_VERTEX_BIT | VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT, |
| 6351 | 0, 16}, |
| 6352 | "vkCmdPushConstants() stageFlags = 0x3 do not match the stageFlags in " |
| 6353 | "any of the ranges in pipeline layout"}, |
| 6354 | {{VK_SHADER_STAGE_VERTEX_BIT, 0, too_big}, |
Karl Schultz | fc8eaf1 | 2016-05-06 13:56:42 -0600 | [diff] [blame] | 6355 | "vkCmdPushConstants() call has push constants with offset "}, |
Karl Schultz | c81037d | 2016-05-12 08:11:23 -0600 | [diff] [blame] | 6356 | {{VK_SHADER_STAGE_VERTEX_BIT, too_big, too_big}, |
Karl Schultz | fc8eaf1 | 2016-05-06 13:56:42 -0600 | [diff] [blame] | 6357 | "vkCmdPushConstants() call has push constants with offset "}, |
Karl Schultz | c81037d | 2016-05-12 08:11:23 -0600 | [diff] [blame] | 6358 | {{VK_SHADER_STAGE_VERTEX_BIT, too_big, 0}, |
Karl Schultz | fc8eaf1 | 2016-05-06 13:56:42 -0600 | [diff] [blame] | 6359 | "vkCmdPushConstants() call has push constants with offset "}, |
Karl Schultz | c81037d | 2016-05-12 08:11:23 -0600 | [diff] [blame] | 6360 | {{VK_SHADER_STAGE_VERTEX_BIT, 0xFFFFFFF0, 0x00000020}, |
Karl Schultz | fc8eaf1 | 2016-05-06 13:56:42 -0600 | [diff] [blame] | 6361 | "vkCmdPushConstants() call has push constants with offset "}, |
Karl Schultz | c81037d | 2016-05-12 08:11:23 -0600 | [diff] [blame] | 6362 | {{VK_SHADER_STAGE_VERTEX_BIT, 0x00000020, 0xFFFFFFF0}, |
Karl Schultz | fc8eaf1 | 2016-05-06 13:56:42 -0600 | [diff] [blame] | 6363 | "vkCmdPushConstants() call has push constants with offset "}, |
| 6364 | }}; |
| 6365 | |
| 6366 | // Two ranges for testing robustness |
Karl Schultz | c81037d | 2016-05-12 08:11:23 -0600 | [diff] [blame] | 6367 | const VkPushConstantRange pc_range2[] = { |
Karl Schultz | fc8eaf1 | 2016-05-06 13:56:42 -0600 | [diff] [blame] | 6368 | {VK_SHADER_STAGE_VERTEX_BIT, 64, 16}, |
Karl Schultz | c81037d | 2016-05-12 08:11:23 -0600 | [diff] [blame] | 6369 | {VK_SHADER_STAGE_VERTEX_BIT, 0, 16}, |
Karl Schultz | fc8eaf1 | 2016-05-06 13:56:42 -0600 | [diff] [blame] | 6370 | }; |
Karl Schultz | c81037d | 2016-05-12 08:11:23 -0600 | [diff] [blame] | 6371 | pipeline_layout_ci.pushConstantRangeCount = |
| 6372 | sizeof(pc_range2) / sizeof(VkPushConstantRange); |
Karl Schultz | fc8eaf1 | 2016-05-06 13:56:42 -0600 | [diff] [blame] | 6373 | pipeline_layout_ci.pPushConstantRanges = pc_range2; |
Tobin Ehlis | 3a23b6a | 2016-02-17 10:35:18 -0700 | [diff] [blame] | 6374 | err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, |
| 6375 | &pipeline_layout); |
| 6376 | ASSERT_VK_SUCCESS(err); |
| 6377 | BeginCommandBuffer(); |
Karl Schultz | c81037d | 2016-05-12 08:11:23 -0600 | [diff] [blame] | 6378 | for (const auto &iter : cmd_range_tests) { |
Karl Schultz | fc8eaf1 | 2016-05-06 13:56:42 -0600 | [diff] [blame] | 6379 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 6380 | iter.msg); |
| 6381 | vkCmdPushConstants(m_commandBuffer->GetBufferHandle(), pipeline_layout, |
Karl Schultz | c81037d | 2016-05-12 08:11:23 -0600 | [diff] [blame] | 6382 | iter.range.stageFlags, iter.range.offset, |
| 6383 | iter.range.size, dummy_values); |
Karl Schultz | fc8eaf1 | 2016-05-06 13:56:42 -0600 | [diff] [blame] | 6384 | m_errorMonitor->VerifyFound(); |
| 6385 | } |
| 6386 | |
| 6387 | // Check for invalid stage flag |
| 6388 | m_errorMonitor->SetDesiredFailureMsg( |
| 6389 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 6390 | "vkCmdPushConstants() call has no stageFlags set."); |
| 6391 | vkCmdPushConstants(m_commandBuffer->GetBufferHandle(), pipeline_layout, 0, |
Karl Schultz | c81037d | 2016-05-12 08:11:23 -0600 | [diff] [blame] | 6392 | 0, 16, dummy_values); |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 6393 | m_errorMonitor->VerifyFound(); |
Karl Schultz | c81037d | 2016-05-12 08:11:23 -0600 | [diff] [blame] | 6394 | EndCommandBuffer(); |
| 6395 | vkResetCommandBuffer(m_commandBuffer->GetBufferHandle(), 0); |
| 6396 | vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL); |
Karl Schultz | fc8eaf1 | 2016-05-06 13:56:42 -0600 | [diff] [blame] | 6397 | |
Karl Schultz | c81037d | 2016-05-12 08:11:23 -0600 | [diff] [blame] | 6398 | // overlapping range tests with cmd |
| 6399 | const std::array<PipelineLayoutTestCase, 3> cmd_overlap_tests = {{ |
| 6400 | {{VK_SHADER_STAGE_VERTEX_BIT, 0, 20}, |
| 6401 | "vkCmdPushConstants() Push constant range [0, 20) with stageFlags = " |
| 6402 | "0x1 not within flag-matching ranges in pipeline layout"}, |
| 6403 | {{VK_SHADER_STAGE_VERTEX_BIT, 16, 4}, |
| 6404 | "vkCmdPushConstants() Push constant range [16, 20) with stageFlags = " |
| 6405 | "0x1 not within flag-matching ranges in pipeline layout"}, |
| 6406 | {{VK_SHADER_STAGE_VERTEX_BIT, 40, 16}, |
| 6407 | "vkCmdPushConstants() Push constant range [40, 56) with stageFlags = " |
| 6408 | "0x1 not within flag-matching ranges in pipeline layout"}, |
| 6409 | }}; |
| 6410 | const VkPushConstantRange pc_range3[] = { |
| 6411 | {VK_SHADER_STAGE_VERTEX_BIT, 20, 16}, |
| 6412 | {VK_SHADER_STAGE_VERTEX_BIT, 0, 16}, |
| 6413 | {VK_SHADER_STAGE_VERTEX_BIT, 0, 4}, |
| 6414 | {VK_SHADER_STAGE_VERTEX_BIT, 44, 8}, |
| 6415 | {VK_SHADER_STAGE_VERTEX_BIT, 80, 12}, |
| 6416 | {VK_SHADER_STAGE_VERTEX_BIT, 36, 8}, |
| 6417 | {VK_SHADER_STAGE_VERTEX_BIT, 56, 28}, |
| 6418 | }; |
| 6419 | pipeline_layout_ci.pushConstantRangeCount = |
| 6420 | sizeof(pc_range3) / sizeof(VkPushConstantRange); |
| 6421 | pipeline_layout_ci.pPushConstantRanges = pc_range3; |
| 6422 | err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, |
| 6423 | &pipeline_layout); |
| 6424 | ASSERT_VK_SUCCESS(err); |
| 6425 | BeginCommandBuffer(); |
| 6426 | for (const auto &iter : cmd_overlap_tests) { |
| 6427 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 6428 | iter.msg); |
| 6429 | vkCmdPushConstants(m_commandBuffer->GetBufferHandle(), pipeline_layout, |
| 6430 | iter.range.stageFlags, iter.range.offset, |
| 6431 | iter.range.size, dummy_values); |
| 6432 | m_errorMonitor->VerifyFound(); |
| 6433 | } |
| 6434 | EndCommandBuffer(); |
| 6435 | vkResetCommandBuffer(m_commandBuffer->GetBufferHandle(), 0); |
| 6436 | vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL); |
| 6437 | |
| 6438 | // positive overlapping range tests with cmd |
| 6439 | const std::array<PipelineLayoutTestCase, 4> cmd_overlap_tests_pos = {{ |
| 6440 | {{VK_SHADER_STAGE_VERTEX_BIT, 0, 16}, ""}, |
| 6441 | {{VK_SHADER_STAGE_VERTEX_BIT, 0, 4}, ""}, |
| 6442 | {{VK_SHADER_STAGE_VERTEX_BIT, 20, 12}, ""}, |
| 6443 | {{VK_SHADER_STAGE_VERTEX_BIT, 56, 36}, ""}, |
| 6444 | }}; |
| 6445 | const VkPushConstantRange pc_range4[] = { |
| 6446 | {VK_SHADER_STAGE_VERTEX_BIT, 0, 64}, |
| 6447 | {VK_SHADER_STAGE_VERTEX_BIT, 20, 16}, |
| 6448 | {VK_SHADER_STAGE_VERTEX_BIT, 0, 16}, |
| 6449 | {VK_SHADER_STAGE_VERTEX_BIT, 0, 4}, |
| 6450 | {VK_SHADER_STAGE_VERTEX_BIT, 44, 8}, |
| 6451 | {VK_SHADER_STAGE_VERTEX_BIT, 80, 12}, |
| 6452 | {VK_SHADER_STAGE_VERTEX_BIT, 36, 8}, |
| 6453 | {VK_SHADER_STAGE_VERTEX_BIT, 56, 28}, |
| 6454 | }; |
| 6455 | pipeline_layout_ci.pushConstantRangeCount = |
| 6456 | sizeof(pc_range4) / sizeof(VkPushConstantRange); |
| 6457 | pipeline_layout_ci.pPushConstantRanges = pc_range4; |
| 6458 | err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, |
| 6459 | &pipeline_layout); |
| 6460 | ASSERT_VK_SUCCESS(err); |
| 6461 | BeginCommandBuffer(); |
| 6462 | for (const auto &iter : cmd_overlap_tests_pos) { |
| 6463 | m_errorMonitor->ExpectSuccess(); |
| 6464 | vkCmdPushConstants(m_commandBuffer->GetBufferHandle(), pipeline_layout, |
| 6465 | iter.range.stageFlags, iter.range.offset, |
| 6466 | iter.range.size, dummy_values); |
| 6467 | m_errorMonitor->VerifyNotFound(); |
| 6468 | } |
| 6469 | EndCommandBuffer(); |
| 6470 | vkResetCommandBuffer(m_commandBuffer->GetBufferHandle(), 0); |
Tobin Ehlis | 3a23b6a | 2016-02-17 10:35:18 -0700 | [diff] [blame] | 6471 | vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL); |
| 6472 | } |
| 6473 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6474 | TEST_F(VkLayerTest, DescriptorSetCompatibility) { |
Tobin Ehlis | 559c638 | 2015-11-05 09:52:49 -0700 | [diff] [blame] | 6475 | // Test various desriptorSet errors with bad binding combinations |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6476 | VkResult err; |
Tobin Ehlis | 559c638 | 2015-11-05 09:52:49 -0700 | [diff] [blame] | 6477 | |
| 6478 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 6479 | ASSERT_NO_FATAL_FAILURE(InitViewport()); |
| 6480 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 6481 | |
Mike Stroyan | b8a6100 | 2016-06-20 16:00:28 -0600 | [diff] [blame] | 6482 | const VkFormat tex_format = VK_FORMAT_R8G8B8A8_UNORM; |
| 6483 | VkImageTiling tiling; |
| 6484 | VkFormatProperties format_properties; |
| 6485 | vkGetPhysicalDeviceFormatProperties(gpu(), tex_format, &format_properties); |
| 6486 | if (format_properties.linearTilingFeatures & |
| 6487 | VK_FORMAT_FEATURE_STORAGE_IMAGE_BIT) { |
| 6488 | tiling = VK_IMAGE_TILING_LINEAR; |
| 6489 | } else if (format_properties.optimalTilingFeatures & |
| 6490 | VK_FORMAT_FEATURE_STORAGE_IMAGE_BIT) { |
| 6491 | tiling = VK_IMAGE_TILING_OPTIMAL; |
| 6492 | } else { |
| 6493 | printf("Device does not support VK_FORMAT_FEATURE_STORAGE_IMAGE_BIT; " |
| 6494 | "skipped.\n"); |
| 6495 | return; |
| 6496 | } |
| 6497 | |
Tobin Ehlis | 559c638 | 2015-11-05 09:52:49 -0700 | [diff] [blame] | 6498 | static const uint32_t NUM_DESCRIPTOR_TYPES = 5; |
| 6499 | VkDescriptorPoolSize ds_type_count[NUM_DESCRIPTOR_TYPES] = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6500 | ds_type_count[0].type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 6501 | ds_type_count[0].descriptorCount = 10; |
| 6502 | ds_type_count[1].type = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE; |
| 6503 | ds_type_count[1].descriptorCount = 2; |
| 6504 | ds_type_count[2].type = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE; |
| 6505 | ds_type_count[2].descriptorCount = 2; |
| 6506 | ds_type_count[3].type = VK_DESCRIPTOR_TYPE_SAMPLER; |
| 6507 | ds_type_count[3].descriptorCount = 5; |
| 6508 | // TODO : LunarG ILO driver currently asserts in desc.c w/ INPUT_ATTACHMENT |
| 6509 | // type |
| 6510 | // ds_type_count[4].type = VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT; |
| 6511 | ds_type_count[4].type = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER; |
| 6512 | ds_type_count[4].descriptorCount = 2; |
Tobin Ehlis | 559c638 | 2015-11-05 09:52:49 -0700 | [diff] [blame] | 6513 | |
| 6514 | VkDescriptorPoolCreateInfo ds_pool_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6515 | ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO; |
| 6516 | ds_pool_ci.pNext = NULL; |
| 6517 | ds_pool_ci.maxSets = 5; |
| 6518 | ds_pool_ci.poolSizeCount = NUM_DESCRIPTOR_TYPES; |
| 6519 | ds_pool_ci.pPoolSizes = ds_type_count; |
Tobin Ehlis | 559c638 | 2015-11-05 09:52:49 -0700 | [diff] [blame] | 6520 | |
| 6521 | VkDescriptorPool ds_pool; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6522 | err = |
| 6523 | vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool); |
Tobin Ehlis | 559c638 | 2015-11-05 09:52:49 -0700 | [diff] [blame] | 6524 | ASSERT_VK_SUCCESS(err); |
| 6525 | |
| 6526 | static const uint32_t MAX_DS_TYPES_IN_LAYOUT = 2; |
| 6527 | VkDescriptorSetLayoutBinding dsl_binding[MAX_DS_TYPES_IN_LAYOUT] = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6528 | dsl_binding[0].binding = 0; |
| 6529 | dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 6530 | dsl_binding[0].descriptorCount = 5; |
| 6531 | dsl_binding[0].stageFlags = VK_SHADER_STAGE_ALL; |
| 6532 | dsl_binding[0].pImmutableSamplers = NULL; |
Tobin Ehlis | 559c638 | 2015-11-05 09:52:49 -0700 | [diff] [blame] | 6533 | |
Tobin Ehlis | 8fab656 | 2015-12-01 09:57:09 -0700 | [diff] [blame] | 6534 | // Create layout identical to set0 layout but w/ different stageFlags |
| 6535 | VkDescriptorSetLayoutBinding dsl_fs_stage_only = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6536 | dsl_fs_stage_only.binding = 0; |
| 6537 | dsl_fs_stage_only.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 6538 | dsl_fs_stage_only.descriptorCount = 5; |
| 6539 | dsl_fs_stage_only.stageFlags = |
| 6540 | VK_SHADER_STAGE_FRAGMENT_BIT; // Different stageFlags to cause error at |
| 6541 | // bind time |
| 6542 | dsl_fs_stage_only.pImmutableSamplers = NULL; |
Tobin Ehlis | 559c638 | 2015-11-05 09:52:49 -0700 | [diff] [blame] | 6543 | VkDescriptorSetLayoutCreateInfo ds_layout_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6544 | ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO; |
| 6545 | ds_layout_ci.pNext = NULL; |
| 6546 | ds_layout_ci.bindingCount = 1; |
| 6547 | ds_layout_ci.pBindings = dsl_binding; |
Tobin Ehlis | 559c638 | 2015-11-05 09:52:49 -0700 | [diff] [blame] | 6548 | static const uint32_t NUM_LAYOUTS = 4; |
| 6549 | VkDescriptorSetLayout ds_layout[NUM_LAYOUTS] = {}; |
Tobin Ehlis | 8fab656 | 2015-12-01 09:57:09 -0700 | [diff] [blame] | 6550 | VkDescriptorSetLayout ds_layout_fs_only = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6551 | // Create 4 unique layouts for full pipelineLayout, and 1 special fs-only |
| 6552 | // layout for error case |
| 6553 | err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, |
| 6554 | &ds_layout[0]); |
Tobin Ehlis | 559c638 | 2015-11-05 09:52:49 -0700 | [diff] [blame] | 6555 | ASSERT_VK_SUCCESS(err); |
Jon Ashburn | 6e23c1f | 2015-12-30 18:01:16 -0700 | [diff] [blame] | 6556 | ds_layout_ci.pBindings = &dsl_fs_stage_only; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6557 | err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, |
| 6558 | &ds_layout_fs_only); |
Tobin Ehlis | 8fab656 | 2015-12-01 09:57:09 -0700 | [diff] [blame] | 6559 | ASSERT_VK_SUCCESS(err); |
Tobin Ehlis | 559c638 | 2015-11-05 09:52:49 -0700 | [diff] [blame] | 6560 | dsl_binding[0].binding = 0; |
| 6561 | dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE; |
Tobin Ehlis | 8fab656 | 2015-12-01 09:57:09 -0700 | [diff] [blame] | 6562 | dsl_binding[0].descriptorCount = 2; |
Mike Stroyan | 9c70cdb | 2016-01-06 14:14:17 -0700 | [diff] [blame] | 6563 | dsl_binding[1].binding = 1; |
| 6564 | dsl_binding[1].descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE; |
| 6565 | dsl_binding[1].descriptorCount = 2; |
| 6566 | dsl_binding[1].stageFlags = VK_SHADER_STAGE_ALL; |
| 6567 | dsl_binding[1].pImmutableSamplers = NULL; |
Jon Ashburn | 6e23c1f | 2015-12-30 18:01:16 -0700 | [diff] [blame] | 6568 | ds_layout_ci.pBindings = dsl_binding; |
Tobin Ehlis | 559c638 | 2015-11-05 09:52:49 -0700 | [diff] [blame] | 6569 | ds_layout_ci.bindingCount = 2; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6570 | err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, |
| 6571 | &ds_layout[1]); |
Tobin Ehlis | 559c638 | 2015-11-05 09:52:49 -0700 | [diff] [blame] | 6572 | ASSERT_VK_SUCCESS(err); |
| 6573 | dsl_binding[0].binding = 0; |
| 6574 | dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER; |
Tobin Ehlis | 8fab656 | 2015-12-01 09:57:09 -0700 | [diff] [blame] | 6575 | dsl_binding[0].descriptorCount = 5; |
Tobin Ehlis | 559c638 | 2015-11-05 09:52:49 -0700 | [diff] [blame] | 6576 | ds_layout_ci.bindingCount = 1; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6577 | err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, |
| 6578 | &ds_layout[2]); |
Tobin Ehlis | 559c638 | 2015-11-05 09:52:49 -0700 | [diff] [blame] | 6579 | ASSERT_VK_SUCCESS(err); |
| 6580 | dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER; |
Tobin Ehlis | 8fab656 | 2015-12-01 09:57:09 -0700 | [diff] [blame] | 6581 | dsl_binding[0].descriptorCount = 2; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6582 | err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, |
| 6583 | &ds_layout[3]); |
Tobin Ehlis | 559c638 | 2015-11-05 09:52:49 -0700 | [diff] [blame] | 6584 | ASSERT_VK_SUCCESS(err); |
| 6585 | |
| 6586 | static const uint32_t NUM_SETS = 4; |
| 6587 | VkDescriptorSet descriptorSet[NUM_SETS] = {}; |
| 6588 | VkDescriptorSetAllocateInfo alloc_info = {}; |
Tobin Ehlis | 8fab656 | 2015-12-01 09:57:09 -0700 | [diff] [blame] | 6589 | alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO; |
Jon Ashburn | f19916e | 2016-01-11 13:12:43 -0700 | [diff] [blame] | 6590 | alloc_info.descriptorSetCount = NUM_LAYOUTS; |
Tobin Ehlis | 559c638 | 2015-11-05 09:52:49 -0700 | [diff] [blame] | 6591 | alloc_info.descriptorPool = ds_pool; |
| 6592 | alloc_info.pSetLayouts = ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6593 | err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, |
| 6594 | descriptorSet); |
Tobin Ehlis | 559c638 | 2015-11-05 09:52:49 -0700 | [diff] [blame] | 6595 | ASSERT_VK_SUCCESS(err); |
Tobin Ehlis | 8fab656 | 2015-12-01 09:57:09 -0700 | [diff] [blame] | 6596 | VkDescriptorSet ds0_fs_only = {}; |
Jon Ashburn | f19916e | 2016-01-11 13:12:43 -0700 | [diff] [blame] | 6597 | alloc_info.descriptorSetCount = 1; |
Tobin Ehlis | 8fab656 | 2015-12-01 09:57:09 -0700 | [diff] [blame] | 6598 | alloc_info.pSetLayouts = &ds_layout_fs_only; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6599 | err = |
| 6600 | vkAllocateDescriptorSets(m_device->device(), &alloc_info, &ds0_fs_only); |
Tobin Ehlis | 8fab656 | 2015-12-01 09:57:09 -0700 | [diff] [blame] | 6601 | ASSERT_VK_SUCCESS(err); |
Tobin Ehlis | 559c638 | 2015-11-05 09:52:49 -0700 | [diff] [blame] | 6602 | |
| 6603 | VkPipelineLayoutCreateInfo pipeline_layout_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6604 | pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO; |
| 6605 | pipeline_layout_ci.pNext = NULL; |
| 6606 | pipeline_layout_ci.setLayoutCount = NUM_LAYOUTS; |
| 6607 | pipeline_layout_ci.pSetLayouts = ds_layout; |
Tobin Ehlis | 559c638 | 2015-11-05 09:52:49 -0700 | [diff] [blame] | 6608 | |
| 6609 | VkPipelineLayout pipeline_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6610 | err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, |
| 6611 | &pipeline_layout); |
Tobin Ehlis | 559c638 | 2015-11-05 09:52:49 -0700 | [diff] [blame] | 6612 | ASSERT_VK_SUCCESS(err); |
Tobin Ehlis | 8fab656 | 2015-12-01 09:57:09 -0700 | [diff] [blame] | 6613 | // Create pipelineLayout with only one setLayout |
| 6614 | pipeline_layout_ci.setLayoutCount = 1; |
| 6615 | VkPipelineLayout single_pipe_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6616 | err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, |
| 6617 | &single_pipe_layout); |
Tobin Ehlis | 8fab656 | 2015-12-01 09:57:09 -0700 | [diff] [blame] | 6618 | ASSERT_VK_SUCCESS(err); |
| 6619 | // Create pipelineLayout with 2 descriptor setLayout at index 0 |
| 6620 | pipeline_layout_ci.pSetLayouts = &ds_layout[3]; |
| 6621 | VkPipelineLayout pipe_layout_one_desc; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6622 | err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, |
| 6623 | &pipe_layout_one_desc); |
Tobin Ehlis | 8fab656 | 2015-12-01 09:57:09 -0700 | [diff] [blame] | 6624 | ASSERT_VK_SUCCESS(err); |
| 6625 | // Create pipelineLayout with 5 SAMPLER descriptor setLayout at index 0 |
| 6626 | pipeline_layout_ci.pSetLayouts = &ds_layout[2]; |
| 6627 | VkPipelineLayout pipe_layout_five_samp; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6628 | err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, |
| 6629 | &pipe_layout_five_samp); |
Tobin Ehlis | 8fab656 | 2015-12-01 09:57:09 -0700 | [diff] [blame] | 6630 | ASSERT_VK_SUCCESS(err); |
| 6631 | // Create pipelineLayout with UB type, but stageFlags for FS only |
| 6632 | pipeline_layout_ci.pSetLayouts = &ds_layout_fs_only; |
| 6633 | VkPipelineLayout pipe_layout_fs_only; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6634 | err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, |
| 6635 | &pipe_layout_fs_only); |
Tobin Ehlis | 8fab656 | 2015-12-01 09:57:09 -0700 | [diff] [blame] | 6636 | ASSERT_VK_SUCCESS(err); |
| 6637 | // Create pipelineLayout w/ incompatible set0 layout, but set1 is fine |
| 6638 | VkDescriptorSetLayout pl_bad_s0[2] = {}; |
| 6639 | pl_bad_s0[0] = ds_layout_fs_only; |
| 6640 | pl_bad_s0[1] = ds_layout[1]; |
| 6641 | pipeline_layout_ci.setLayoutCount = 2; |
| 6642 | pipeline_layout_ci.pSetLayouts = pl_bad_s0; |
| 6643 | VkPipelineLayout pipe_layout_bad_set0; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6644 | err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, |
| 6645 | &pipe_layout_bad_set0); |
Tobin Ehlis | 8fab656 | 2015-12-01 09:57:09 -0700 | [diff] [blame] | 6646 | ASSERT_VK_SUCCESS(err); |
Tobin Ehlis | 559c638 | 2015-11-05 09:52:49 -0700 | [diff] [blame] | 6647 | |
| 6648 | // Create a buffer to update the descriptor with |
| 6649 | uint32_t qfi = 0; |
| 6650 | VkBufferCreateInfo buffCI = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6651 | buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO; |
| 6652 | buffCI.size = 1024; |
| 6653 | buffCI.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT; |
| 6654 | buffCI.queueFamilyIndexCount = 1; |
| 6655 | buffCI.pQueueFamilyIndices = &qfi; |
Tobin Ehlis | 559c638 | 2015-11-05 09:52:49 -0700 | [diff] [blame] | 6656 | |
| 6657 | VkBuffer dyub; |
| 6658 | err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &dyub); |
| 6659 | ASSERT_VK_SUCCESS(err); |
| 6660 | // Correctly update descriptor to avoid "NOT_UPDATED" error |
| 6661 | static const uint32_t NUM_BUFFS = 5; |
| 6662 | VkDescriptorBufferInfo buffInfo[NUM_BUFFS] = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6663 | for (uint32_t i = 0; i < NUM_BUFFS; ++i) { |
Tobin Ehlis | 559c638 | 2015-11-05 09:52:49 -0700 | [diff] [blame] | 6664 | buffInfo[i].buffer = dyub; |
| 6665 | buffInfo[i].offset = 0; |
| 6666 | buffInfo[i].range = 1024; |
| 6667 | } |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6668 | VkImage image; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6669 | const int32_t tex_width = 32; |
| 6670 | const int32_t tex_height = 32; |
Tobin Ehlis | 8fab656 | 2015-12-01 09:57:09 -0700 | [diff] [blame] | 6671 | VkImageCreateInfo image_create_info = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6672 | image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO; |
| 6673 | image_create_info.pNext = NULL; |
| 6674 | image_create_info.imageType = VK_IMAGE_TYPE_2D; |
| 6675 | image_create_info.format = tex_format; |
| 6676 | image_create_info.extent.width = tex_width; |
| 6677 | image_create_info.extent.height = tex_height; |
| 6678 | image_create_info.extent.depth = 1; |
| 6679 | image_create_info.mipLevels = 1; |
| 6680 | image_create_info.arrayLayers = 1; |
| 6681 | image_create_info.samples = VK_SAMPLE_COUNT_1_BIT; |
Mike Stroyan | b8a6100 | 2016-06-20 16:00:28 -0600 | [diff] [blame] | 6682 | image_create_info.tiling = tiling; |
| 6683 | image_create_info.usage = |
| 6684 | VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_STORAGE_BIT; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6685 | image_create_info.flags = 0; |
Tobin Ehlis | 8fab656 | 2015-12-01 09:57:09 -0700 | [diff] [blame] | 6686 | err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image); |
| 6687 | ASSERT_VK_SUCCESS(err); |
Tobin Ehlis | 559c638 | 2015-11-05 09:52:49 -0700 | [diff] [blame] | 6688 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6689 | VkMemoryRequirements memReqs; |
| 6690 | VkDeviceMemory imageMem; |
| 6691 | bool pass; |
Mike Stroyan | 9c70cdb | 2016-01-06 14:14:17 -0700 | [diff] [blame] | 6692 | VkMemoryAllocateInfo memAlloc = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6693 | memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO; |
| 6694 | memAlloc.pNext = NULL; |
| 6695 | memAlloc.allocationSize = 0; |
| 6696 | memAlloc.memoryTypeIndex = 0; |
Mike Stroyan | 9c70cdb | 2016-01-06 14:14:17 -0700 | [diff] [blame] | 6697 | vkGetImageMemoryRequirements(m_device->device(), image, &memReqs); |
| 6698 | memAlloc.allocationSize = memReqs.size; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6699 | pass = |
| 6700 | m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0); |
Mike Stroyan | 9c70cdb | 2016-01-06 14:14:17 -0700 | [diff] [blame] | 6701 | ASSERT_TRUE(pass); |
| 6702 | err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &imageMem); |
| 6703 | ASSERT_VK_SUCCESS(err); |
| 6704 | err = vkBindImageMemory(m_device->device(), image, imageMem, 0); |
| 6705 | ASSERT_VK_SUCCESS(err); |
| 6706 | |
Tobin Ehlis | 8fab656 | 2015-12-01 09:57:09 -0700 | [diff] [blame] | 6707 | VkImageViewCreateInfo image_view_create_info = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6708 | image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO; |
| 6709 | image_view_create_info.image = image; |
| 6710 | image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D; |
| 6711 | image_view_create_info.format = tex_format; |
| 6712 | image_view_create_info.subresourceRange.layerCount = 1; |
| 6713 | image_view_create_info.subresourceRange.baseMipLevel = 0; |
| 6714 | image_view_create_info.subresourceRange.levelCount = 1; |
| 6715 | image_view_create_info.subresourceRange.aspectMask = |
| 6716 | VK_IMAGE_ASPECT_COLOR_BIT; |
Tobin Ehlis | 559c638 | 2015-11-05 09:52:49 -0700 | [diff] [blame] | 6717 | |
Tobin Ehlis | 8fab656 | 2015-12-01 09:57:09 -0700 | [diff] [blame] | 6718 | VkImageView view; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6719 | err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, |
| 6720 | &view); |
Tobin Ehlis | 8fab656 | 2015-12-01 09:57:09 -0700 | [diff] [blame] | 6721 | ASSERT_VK_SUCCESS(err); |
Tobin Ehlis | 991d45a | 2016-01-06 08:48:41 -0700 | [diff] [blame] | 6722 | VkDescriptorImageInfo imageInfo[4] = {}; |
Tobin Ehlis | 8fab656 | 2015-12-01 09:57:09 -0700 | [diff] [blame] | 6723 | imageInfo[0].imageView = view; |
| 6724 | imageInfo[0].imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL; |
| 6725 | imageInfo[1].imageView = view; |
| 6726 | imageInfo[1].imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL; |
Tobin Ehlis | 991d45a | 2016-01-06 08:48:41 -0700 | [diff] [blame] | 6727 | imageInfo[2].imageView = view; |
| 6728 | imageInfo[2].imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL; |
| 6729 | imageInfo[3].imageView = view; |
| 6730 | imageInfo[3].imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL; |
Tobin Ehlis | 8fab656 | 2015-12-01 09:57:09 -0700 | [diff] [blame] | 6731 | |
| 6732 | static const uint32_t NUM_SET_UPDATES = 3; |
| 6733 | VkWriteDescriptorSet descriptor_write[NUM_SET_UPDATES] = {}; |
| 6734 | descriptor_write[0].sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET; |
| 6735 | descriptor_write[0].dstSet = descriptorSet[0]; |
| 6736 | descriptor_write[0].dstBinding = 0; |
| 6737 | descriptor_write[0].descriptorCount = 5; |
| 6738 | descriptor_write[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 6739 | descriptor_write[0].pBufferInfo = buffInfo; |
| 6740 | descriptor_write[1].sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET; |
| 6741 | descriptor_write[1].dstSet = descriptorSet[1]; |
| 6742 | descriptor_write[1].dstBinding = 0; |
| 6743 | descriptor_write[1].descriptorCount = 2; |
| 6744 | descriptor_write[1].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE; |
| 6745 | descriptor_write[1].pImageInfo = imageInfo; |
| 6746 | descriptor_write[2].sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET; |
| 6747 | descriptor_write[2].dstSet = descriptorSet[1]; |
| 6748 | descriptor_write[2].dstBinding = 1; |
| 6749 | descriptor_write[2].descriptorCount = 2; |
| 6750 | descriptor_write[2].descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE; |
Tobin Ehlis | 991d45a | 2016-01-06 08:48:41 -0700 | [diff] [blame] | 6751 | descriptor_write[2].pImageInfo = &imageInfo[2]; |
Tobin Ehlis | 8fab656 | 2015-12-01 09:57:09 -0700 | [diff] [blame] | 6752 | |
| 6753 | vkUpdateDescriptorSets(m_device->device(), 3, descriptor_write, 0, NULL); |
Tobin Ehlis | 559c638 | 2015-11-05 09:52:49 -0700 | [diff] [blame] | 6754 | |
Tobin Ehlis | 8845283 | 2015-12-03 09:40:56 -0700 | [diff] [blame] | 6755 | // Create PSO to be used for draw-time errors below |
| 6756 | char const *vsSource = |
Chris Forbes | 7b34280 | 2016-04-07 13:20:10 +1200 | [diff] [blame] | 6757 | "#version 450\n" |
Tobin Ehlis | 8845283 | 2015-12-03 09:40:56 -0700 | [diff] [blame] | 6758 | "\n" |
Tony Barbour | e804d20 | 2016-01-05 13:37:45 -0700 | [diff] [blame] | 6759 | "out gl_PerVertex {\n" |
| 6760 | " vec4 gl_Position;\n" |
| 6761 | "};\n" |
Tobin Ehlis | 8845283 | 2015-12-03 09:40:56 -0700 | [diff] [blame] | 6762 | "void main(){\n" |
| 6763 | " gl_Position = vec4(1);\n" |
| 6764 | "}\n"; |
| 6765 | char const *fsSource = |
Chris Forbes | 7b34280 | 2016-04-07 13:20:10 +1200 | [diff] [blame] | 6766 | "#version 450\n" |
Tobin Ehlis | 8845283 | 2015-12-03 09:40:56 -0700 | [diff] [blame] | 6767 | "\n" |
| 6768 | "layout(location=0) out vec4 x;\n" |
| 6769 | "layout(set=0) layout(binding=0) uniform foo { int x; int y; } bar;\n" |
| 6770 | "void main(){\n" |
| 6771 | " x = vec4(bar.y);\n" |
| 6772 | "}\n"; |
| 6773 | VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this); |
| 6774 | VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this); |
Tobin Ehlis | 559c638 | 2015-11-05 09:52:49 -0700 | [diff] [blame] | 6775 | VkPipelineObj pipe(m_device); |
| 6776 | pipe.AddShader(&vs); |
| 6777 | pipe.AddShader(&fs); |
Tobin Ehlis | 8845283 | 2015-12-03 09:40:56 -0700 | [diff] [blame] | 6778 | pipe.AddColorAttachment(); |
| 6779 | pipe.CreateVKPipeline(pipe_layout_fs_only, renderPass()); |
Tobin Ehlis | 559c638 | 2015-11-05 09:52:49 -0700 | [diff] [blame] | 6780 | |
| 6781 | BeginCommandBuffer(); |
Tobin Ehlis | 8845283 | 2015-12-03 09:40:56 -0700 | [diff] [blame] | 6782 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6783 | vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), |
| 6784 | VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle()); |
| 6785 | // NOTE : I believe LunarG ilo driver has bug (LX#189) that requires binding |
| 6786 | // of PSO |
| 6787 | // here before binding DSs. Otherwise we assert in cmd_copy_dset_data() of |
| 6788 | // cmd_pipeline.c |
| 6789 | // due to the fact that cmd_alloc_dset_data() has not been called in |
| 6790 | // cmd_bind_graphics_pipeline() |
| 6791 | // TODO : Want to cause various binding incompatibility issues here to test |
| 6792 | // DrawState |
Tobin Ehlis | 559c638 | 2015-11-05 09:52:49 -0700 | [diff] [blame] | 6793 | // First cause various verify_layout_compatibility() fails |
| 6794 | // Second disturb early and late sets and verify INFO msgs |
Tobin Ehlis | 8fab656 | 2015-12-01 09:57:09 -0700 | [diff] [blame] | 6795 | // verify_set_layout_compatibility fail cases: |
| 6796 | // 1. invalid VkPipelineLayout (layout) passed into vkCmdBindDescriptorSets |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6797 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 6798 | " due to: invalid VkPipelineLayout "); |
| 6799 | vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), |
| 6800 | VK_PIPELINE_BIND_POINT_GRAPHICS, |
| 6801 | (VkPipelineLayout)((size_t)0xbaadb1be), 0, 1, |
| 6802 | &descriptorSet[0], 0, NULL); |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 6803 | m_errorMonitor->VerifyFound(); |
| 6804 | |
Tobin Ehlis | 8fab656 | 2015-12-01 09:57:09 -0700 | [diff] [blame] | 6805 | // 2. layoutIndex exceeds # of layouts in layout |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6806 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 6807 | " attempting to bind set to index 1"); |
| 6808 | vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), |
| 6809 | VK_PIPELINE_BIND_POINT_GRAPHICS, single_pipe_layout, |
| 6810 | 0, 2, &descriptorSet[0], 0, NULL); |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 6811 | m_errorMonitor->VerifyFound(); |
| 6812 | |
Tobin Ehlis | 8fab656 | 2015-12-01 09:57:09 -0700 | [diff] [blame] | 6813 | vkDestroyPipelineLayout(m_device->device(), single_pipe_layout, NULL); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6814 | // 3. Pipeline setLayout[0] has 2 descriptors, but set being bound has 5 |
| 6815 | // descriptors |
| 6816 | m_errorMonitor->SetDesiredFailureMsg( |
| 6817 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Tobin Ehlis | 2d9deec | 2016-04-21 14:19:26 -0600 | [diff] [blame] | 6818 | " has 2 descriptors, but DescriptorSetLayout "); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6819 | vkCmdBindDescriptorSets( |
| 6820 | m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, |
| 6821 | pipe_layout_one_desc, 0, 1, &descriptorSet[0], 0, NULL); |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 6822 | m_errorMonitor->VerifyFound(); |
| 6823 | |
Tobin Ehlis | 8fab656 | 2015-12-01 09:57:09 -0700 | [diff] [blame] | 6824 | vkDestroyPipelineLayout(m_device->device(), pipe_layout_one_desc, NULL); |
| 6825 | // 4. same # of descriptors but mismatch in type |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6826 | m_errorMonitor->SetDesiredFailureMsg( |
| 6827 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Tobin Ehlis | 2d9deec | 2016-04-21 14:19:26 -0600 | [diff] [blame] | 6828 | " is type 'VK_DESCRIPTOR_TYPE_SAMPLER' but binding "); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6829 | vkCmdBindDescriptorSets( |
| 6830 | m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, |
| 6831 | pipe_layout_five_samp, 0, 1, &descriptorSet[0], 0, NULL); |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 6832 | m_errorMonitor->VerifyFound(); |
| 6833 | |
Tobin Ehlis | 8fab656 | 2015-12-01 09:57:09 -0700 | [diff] [blame] | 6834 | vkDestroyPipelineLayout(m_device->device(), pipe_layout_five_samp, NULL); |
| 6835 | // 5. same # of descriptors but mismatch in stageFlags |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6836 | m_errorMonitor->SetDesiredFailureMsg( |
| 6837 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Tobin Ehlis | 2d9deec | 2016-04-21 14:19:26 -0600 | [diff] [blame] | 6838 | " has stageFlags 16 but binding 0 for DescriptorSetLayout "); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6839 | vkCmdBindDescriptorSets( |
| 6840 | m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, |
| 6841 | pipe_layout_fs_only, 0, 1, &descriptorSet[0], 0, NULL); |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 6842 | m_errorMonitor->VerifyFound(); |
| 6843 | |
Tobin Ehlis | 8fab656 | 2015-12-01 09:57:09 -0700 | [diff] [blame] | 6844 | // Cause INFO messages due to disturbing previously bound Sets |
| 6845 | // First bind sets 0 & 1 |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6846 | vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), |
| 6847 | VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, |
| 6848 | 2, &descriptorSet[0], 0, NULL); |
Tobin Ehlis | 8fab656 | 2015-12-01 09:57:09 -0700 | [diff] [blame] | 6849 | // 1. Disturb bound set0 by re-binding set1 w/ updated pipelineLayout |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6850 | m_errorMonitor->SetDesiredFailureMsg( |
Mark Lobodzinski | 510e20d | 2016-02-11 09:26:16 -0700 | [diff] [blame] | 6851 | VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6852 | " previously bound as set #0 was disturbed "); |
| 6853 | vkCmdBindDescriptorSets( |
| 6854 | m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, |
| 6855 | pipe_layout_bad_set0, 1, 1, &descriptorSet[1], 0, NULL); |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 6856 | m_errorMonitor->VerifyFound(); |
| 6857 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6858 | vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), |
| 6859 | VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, |
| 6860 | 2, &descriptorSet[0], 0, NULL); |
Tobin Ehlis | 8fab656 | 2015-12-01 09:57:09 -0700 | [diff] [blame] | 6861 | // 2. Disturb set after last bound set |
Mark Lobodzinski | 510e20d | 2016-02-11 09:26:16 -0700 | [diff] [blame] | 6862 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6863 | " newly bound as set #0 so set #1 and " |
| 6864 | "any subsequent sets were disturbed "); |
| 6865 | vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), |
| 6866 | VK_PIPELINE_BIND_POINT_GRAPHICS, |
| 6867 | pipe_layout_fs_only, 0, 1, &ds0_fs_only, 0, NULL); |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 6868 | m_errorMonitor->VerifyFound(); |
| 6869 | |
Tobin Ehlis | 8845283 | 2015-12-03 09:40:56 -0700 | [diff] [blame] | 6870 | // Cause draw-time errors due to PSO incompatibilities |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6871 | // 1. Error due to not binding required set (we actually use same code as |
| 6872 | // above to disturb set0) |
| 6873 | vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), |
| 6874 | VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, |
| 6875 | 2, &descriptorSet[0], 0, NULL); |
| 6876 | vkCmdBindDescriptorSets( |
| 6877 | m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, |
| 6878 | pipe_layout_bad_set0, 1, 1, &descriptorSet[1], 0, NULL); |
| 6879 | m_errorMonitor->SetDesiredFailureMsg( |
| 6880 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 6881 | " uses set #0 but that set is not bound."); |
Tobin Ehlis | 8845283 | 2015-12-03 09:40:56 -0700 | [diff] [blame] | 6882 | Draw(1, 0, 0, 0); |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 6883 | m_errorMonitor->VerifyFound(); |
| 6884 | |
Tobin Ehlis | 991d45a | 2016-01-06 08:48:41 -0700 | [diff] [blame] | 6885 | vkDestroyPipelineLayout(m_device->device(), pipe_layout_bad_set0, NULL); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6886 | // 2. Error due to bound set not being compatible with PSO's |
| 6887 | // VkPipelineLayout (diff stageFlags in this case) |
| 6888 | vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), |
| 6889 | VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, |
| 6890 | 2, &descriptorSet[0], 0, NULL); |
| 6891 | m_errorMonitor->SetDesiredFailureMsg( |
| 6892 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 6893 | " bound as set #0 is not compatible with "); |
Tobin Ehlis | 8845283 | 2015-12-03 09:40:56 -0700 | [diff] [blame] | 6894 | Draw(1, 0, 0, 0); |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 6895 | m_errorMonitor->VerifyFound(); |
| 6896 | |
Tobin Ehlis | 8fab656 | 2015-12-01 09:57:09 -0700 | [diff] [blame] | 6897 | // Remaining clean-up |
| 6898 | vkDestroyPipelineLayout(m_device->device(), pipe_layout_fs_only, NULL); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6899 | for (uint32_t i = 0; i < NUM_LAYOUTS; ++i) { |
Tobin Ehlis | 8fab656 | 2015-12-01 09:57:09 -0700 | [diff] [blame] | 6900 | vkDestroyDescriptorSetLayout(m_device->device(), ds_layout[i], NULL); |
| 6901 | } |
| 6902 | vkDestroyDescriptorSetLayout(m_device->device(), ds_layout_fs_only, NULL); |
Tobin Ehlis | 9bfd449 | 2016-05-05 15:09:11 -0600 | [diff] [blame] | 6903 | vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &ds0_fs_only); |
| 6904 | vkFreeDescriptorSets(m_device->device(), ds_pool, NUM_SETS, descriptorSet); |
Tobin Ehlis | 8fab656 | 2015-12-01 09:57:09 -0700 | [diff] [blame] | 6905 | vkDestroyBuffer(m_device->device(), dyub, NULL); |
Tobin Ehlis | 559c638 | 2015-11-05 09:52:49 -0700 | [diff] [blame] | 6906 | vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL); |
| 6907 | vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL); |
Tony Barbour | df4c004 | 2016-06-01 15:55:43 -0600 | [diff] [blame] | 6908 | vkFreeMemory(m_device->device(), imageMem, NULL); |
| 6909 | vkDestroyImage(m_device->device(), image, NULL); |
| 6910 | vkDestroyImageView(m_device->device(), view, NULL); |
Tobin Ehlis | 559c638 | 2015-11-05 09:52:49 -0700 | [diff] [blame] | 6911 | } |
Tobin Ehlis | 559c638 | 2015-11-05 09:52:49 -0700 | [diff] [blame] | 6912 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6913 | TEST_F(VkLayerTest, NoBeginCommandBuffer) { |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 6914 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6915 | m_errorMonitor->SetDesiredFailureMsg( |
| 6916 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 6917 | "You must call vkBeginCommandBuffer() before this call to "); |
Tobin Ehlis | af1f3a4 | 2015-06-25 15:46:59 -0600 | [diff] [blame] | 6918 | |
| 6919 | ASSERT_NO_FATAL_FAILURE(InitState()); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 6920 | VkCommandBufferObj commandBuffer(m_device, m_commandPool); |
Tobin Ehlis | af1f3a4 | 2015-06-25 15:46:59 -0600 | [diff] [blame] | 6921 | // Call EndCommandBuffer() w/o calling BeginCommandBuffer() |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 6922 | vkEndCommandBuffer(commandBuffer.GetBufferHandle()); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 6923 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 6924 | m_errorMonitor->VerifyFound(); |
Tobin Ehlis | af1f3a4 | 2015-06-25 15:46:59 -0600 | [diff] [blame] | 6925 | } |
| 6926 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6927 | TEST_F(VkLayerTest, SecondaryCommandBufferNullRenderpass) { |
| 6928 | VkResult err; |
| 6929 | VkCommandBuffer draw_cmd; |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 6930 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6931 | m_errorMonitor->SetDesiredFailureMsg( |
| 6932 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Tobin Ehlis | 61b36f3 | 2015-12-16 08:19:42 -0700 | [diff] [blame] | 6933 | " must specify a valid renderpass parameter."); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 6934 | |
Mark Lobodzinski | d9139a6 | 2015-08-04 16:24:20 -0600 | [diff] [blame] | 6935 | ASSERT_NO_FATAL_FAILURE(InitState()); |
Mark Lobodzinski | d9139a6 | 2015-08-04 16:24:20 -0600 | [diff] [blame] | 6936 | |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 6937 | VkCommandBufferAllocateInfo cmd = {}; |
Chia-I Wu | 00ce540 | 2015-11-10 16:21:09 +0800 | [diff] [blame] | 6938 | cmd.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO; |
Cody Northrop | b456970 | 2015-08-04 17:35:57 -0600 | [diff] [blame] | 6939 | cmd.pNext = NULL; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 6940 | cmd.commandPool = m_commandPool; |
| 6941 | cmd.level = VK_COMMAND_BUFFER_LEVEL_SECONDARY; |
Jon Ashburn | f19916e | 2016-01-11 13:12:43 -0700 | [diff] [blame] | 6942 | cmd.commandBufferCount = 1; |
Cody Northrop | b456970 | 2015-08-04 17:35:57 -0600 | [diff] [blame] | 6943 | |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 6944 | err = vkAllocateCommandBuffers(m_device->device(), &cmd, &draw_cmd); |
Mike Stroyan | d1c84a5 | 2015-08-18 14:40:24 -0600 | [diff] [blame] | 6945 | ASSERT_VK_SUCCESS(err); |
Mark Lobodzinski | d9139a6 | 2015-08-04 16:24:20 -0600 | [diff] [blame] | 6946 | |
| 6947 | // Force the failure by not setting the Renderpass and Framebuffer fields |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 6948 | VkCommandBufferBeginInfo cmd_buf_info = {}; |
Jon Ashburn | f19916e | 2016-01-11 13:12:43 -0700 | [diff] [blame] | 6949 | VkCommandBufferInheritanceInfo cmd_buf_hinfo = {}; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 6950 | cmd_buf_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO; |
Cody Northrop | b456970 | 2015-08-04 17:35:57 -0600 | [diff] [blame] | 6951 | cmd_buf_info.pNext = NULL; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6952 | cmd_buf_info.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT | |
| 6953 | VK_COMMAND_BUFFER_USAGE_RENDER_PASS_CONTINUE_BIT; |
Jon Ashburn | f19916e | 2016-01-11 13:12:43 -0700 | [diff] [blame] | 6954 | cmd_buf_info.pInheritanceInfo = &cmd_buf_hinfo; |
Mark Lobodzinski | d9139a6 | 2015-08-04 16:24:20 -0600 | [diff] [blame] | 6955 | |
| 6956 | // The error should be caught by validation of the BeginCommandBuffer call |
| 6957 | vkBeginCommandBuffer(draw_cmd, &cmd_buf_info); |
| 6958 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 6959 | m_errorMonitor->VerifyFound(); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 6960 | vkFreeCommandBuffers(m_device->device(), m_commandPool, 1, &draw_cmd); |
Mark Lobodzinski | d9139a6 | 2015-08-04 16:24:20 -0600 | [diff] [blame] | 6961 | } |
| 6962 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6963 | TEST_F(VkLayerTest, CommandBufferResetErrors) { |
Tobin Ehlis | ac0ef84 | 2015-12-14 13:46:38 -0700 | [diff] [blame] | 6964 | // Cause error due to Begin while recording CB |
| 6965 | // Then cause 2 errors for attempting to reset CB w/o having |
| 6966 | // VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT set for the pool from |
| 6967 | // which CBs were allocated. Note that this bit is off by default. |
Courtney Goeltzenleuchter | 7415d5a | 2015-12-09 15:48:16 -0700 | [diff] [blame] | 6968 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6969 | "Cannot call Begin on CB"); |
Tobin Ehlis | ac0ef84 | 2015-12-14 13:46:38 -0700 | [diff] [blame] | 6970 | |
| 6971 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 6972 | |
| 6973 | // Calls AllocateCommandBuffers |
| 6974 | VkCommandBufferObj commandBuffer(m_device, m_commandPool); |
| 6975 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6976 | // Force the failure by setting the Renderpass and Framebuffer fields with |
| 6977 | // (fake) data |
Tobin Ehlis | ac0ef84 | 2015-12-14 13:46:38 -0700 | [diff] [blame] | 6978 | VkCommandBufferBeginInfo cmd_buf_info = {}; |
Jon Ashburn | f19916e | 2016-01-11 13:12:43 -0700 | [diff] [blame] | 6979 | VkCommandBufferInheritanceInfo cmd_buf_hinfo = {}; |
Tobin Ehlis | ac0ef84 | 2015-12-14 13:46:38 -0700 | [diff] [blame] | 6980 | cmd_buf_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO; |
| 6981 | cmd_buf_info.pNext = NULL; |
| 6982 | cmd_buf_info.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT; |
Jon Ashburn | f19916e | 2016-01-11 13:12:43 -0700 | [diff] [blame] | 6983 | cmd_buf_info.pInheritanceInfo = &cmd_buf_hinfo; |
Tobin Ehlis | ac0ef84 | 2015-12-14 13:46:38 -0700 | [diff] [blame] | 6984 | |
| 6985 | // Begin CB to transition to recording state |
| 6986 | vkBeginCommandBuffer(commandBuffer.GetBufferHandle(), &cmd_buf_info); |
| 6987 | // Can't re-begin. This should trigger error |
| 6988 | vkBeginCommandBuffer(commandBuffer.GetBufferHandle(), &cmd_buf_info); |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 6989 | m_errorMonitor->VerifyFound(); |
| 6990 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6991 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 6992 | "Attempt to reset command buffer "); |
Tobin Ehlis | ac0ef84 | 2015-12-14 13:46:38 -0700 | [diff] [blame] | 6993 | VkCommandBufferResetFlags flags = 0; // Don't care about flags for this test |
| 6994 | // Reset attempt will trigger error due to incorrect CommandPool state |
| 6995 | vkResetCommandBuffer(commandBuffer.GetBufferHandle(), flags); |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 6996 | m_errorMonitor->VerifyFound(); |
| 6997 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6998 | m_errorMonitor->SetDesiredFailureMsg( |
| 6999 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 7000 | " attempts to implicitly reset cmdBuffer created from "); |
Tobin Ehlis | ac0ef84 | 2015-12-14 13:46:38 -0700 | [diff] [blame] | 7001 | // Transition CB to RECORDED state |
| 7002 | vkEndCommandBuffer(commandBuffer.GetBufferHandle()); |
| 7003 | // Now attempting to Begin will implicitly reset, which triggers error |
| 7004 | vkBeginCommandBuffer(commandBuffer.GetBufferHandle(), &cmd_buf_info); |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 7005 | m_errorMonitor->VerifyFound(); |
Tobin Ehlis | ac0ef84 | 2015-12-14 13:46:38 -0700 | [diff] [blame] | 7006 | } |
| 7007 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7008 | TEST_F(VkLayerTest, InvalidPipelineCreateState) { |
Tobin Ehlis | af1f3a4 | 2015-06-25 15:46:59 -0600 | [diff] [blame] | 7009 | // Attempt to Create Gfx Pipeline w/o a VS |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7010 | VkResult err; |
Tobin Ehlis | af1f3a4 | 2015-06-25 15:46:59 -0600 | [diff] [blame] | 7011 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7012 | m_errorMonitor->SetDesiredFailureMsg( |
| 7013 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 7014 | "Invalid Pipeline CreateInfo State: Vtx Shader required"); |
| 7015 | |
Tobin Ehlis | af1f3a4 | 2015-06-25 15:46:59 -0600 | [diff] [blame] | 7016 | ASSERT_NO_FATAL_FAILURE(InitState()); |
Tobin Ehlis | c9ac2b6 | 2015-09-11 12:57:55 -0600 | [diff] [blame] | 7017 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
Mark Lobodzinski | 209b529 | 2015-09-17 09:44:05 -0600 | [diff] [blame] | 7018 | |
Chia-I Wu | 1b99bb2 | 2015-10-27 19:25:11 +0800 | [diff] [blame] | 7019 | VkDescriptorPoolSize ds_type_count = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7020 | ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 7021 | ds_type_count.descriptorCount = 1; |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 7022 | |
| 7023 | VkDescriptorPoolCreateInfo ds_pool_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7024 | ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO; |
| 7025 | ds_pool_ci.pNext = NULL; |
| 7026 | ds_pool_ci.maxSets = 1; |
| 7027 | ds_pool_ci.poolSizeCount = 1; |
| 7028 | ds_pool_ci.pPoolSizes = &ds_type_count; |
Mark Lobodzinski | 209b529 | 2015-09-17 09:44:05 -0600 | [diff] [blame] | 7029 | |
Tobin Ehlis | af1f3a4 | 2015-06-25 15:46:59 -0600 | [diff] [blame] | 7030 | VkDescriptorPool ds_pool; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7031 | err = |
| 7032 | vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool); |
Tobin Ehlis | af1f3a4 | 2015-06-25 15:46:59 -0600 | [diff] [blame] | 7033 | ASSERT_VK_SUCCESS(err); |
| 7034 | |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 7035 | VkDescriptorSetLayoutBinding dsl_binding = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7036 | dsl_binding.binding = 0; |
| 7037 | dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 7038 | dsl_binding.descriptorCount = 1; |
| 7039 | dsl_binding.stageFlags = VK_SHADER_STAGE_ALL; |
| 7040 | dsl_binding.pImmutableSamplers = NULL; |
Tobin Ehlis | af1f3a4 | 2015-06-25 15:46:59 -0600 | [diff] [blame] | 7041 | |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 7042 | VkDescriptorSetLayoutCreateInfo ds_layout_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7043 | ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO; |
| 7044 | ds_layout_ci.pNext = NULL; |
| 7045 | ds_layout_ci.bindingCount = 1; |
| 7046 | ds_layout_ci.pBindings = &dsl_binding; |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 7047 | |
Tobin Ehlis | af1f3a4 | 2015-06-25 15:46:59 -0600 | [diff] [blame] | 7048 | VkDescriptorSetLayout ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7049 | err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, |
| 7050 | &ds_layout); |
Tobin Ehlis | af1f3a4 | 2015-06-25 15:46:59 -0600 | [diff] [blame] | 7051 | ASSERT_VK_SUCCESS(err); |
| 7052 | |
| 7053 | VkDescriptorSet descriptorSet; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 7054 | VkDescriptorSetAllocateInfo alloc_info = {}; |
Chia-I Wu | 00ce540 | 2015-11-10 16:21:09 +0800 | [diff] [blame] | 7055 | alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO; |
Jon Ashburn | f19916e | 2016-01-11 13:12:43 -0700 | [diff] [blame] | 7056 | alloc_info.descriptorSetCount = 1; |
Courtney Goeltzenleuchter | bee18a9 | 2015-10-23 14:21:05 -0600 | [diff] [blame] | 7057 | alloc_info.descriptorPool = ds_pool; |
| 7058 | alloc_info.pSetLayouts = &ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7059 | err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, |
| 7060 | &descriptorSet); |
Tobin Ehlis | af1f3a4 | 2015-06-25 15:46:59 -0600 | [diff] [blame] | 7061 | ASSERT_VK_SUCCESS(err); |
| 7062 | |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 7063 | VkPipelineLayoutCreateInfo pipeline_layout_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7064 | pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO; |
| 7065 | pipeline_layout_ci.setLayoutCount = 1; |
| 7066 | pipeline_layout_ci.pSetLayouts = &ds_layout; |
Tobin Ehlis | af1f3a4 | 2015-06-25 15:46:59 -0600 | [diff] [blame] | 7067 | |
| 7068 | VkPipelineLayout pipeline_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7069 | err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, |
| 7070 | &pipeline_layout); |
Tobin Ehlis | af1f3a4 | 2015-06-25 15:46:59 -0600 | [diff] [blame] | 7071 | ASSERT_VK_SUCCESS(err); |
| 7072 | |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 7073 | VkViewport vp = {}; // Just need dummy vp to point to |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7074 | VkRect2D sc = {}; // dummy scissor to point to |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 7075 | |
| 7076 | VkPipelineViewportStateCreateInfo vp_state_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7077 | vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO; |
| 7078 | vp_state_ci.scissorCount = 1; |
| 7079 | vp_state_ci.pScissors = ≻ |
| 7080 | vp_state_ci.viewportCount = 1; |
| 7081 | vp_state_ci.pViewports = &vp; |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 7082 | |
Karl Schultz | dfdb8d4 | 2016-03-08 10:30:21 -0700 | [diff] [blame] | 7083 | VkPipelineRasterizationStateCreateInfo rs_state_ci = {}; |
| 7084 | rs_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO; |
| 7085 | rs_state_ci.polygonMode = VK_POLYGON_MODE_FILL; |
| 7086 | rs_state_ci.cullMode = VK_CULL_MODE_BACK_BIT; |
| 7087 | rs_state_ci.frontFace = VK_FRONT_FACE_COUNTER_CLOCKWISE; |
| 7088 | rs_state_ci.depthClampEnable = VK_FALSE; |
| 7089 | rs_state_ci.rasterizerDiscardEnable = VK_FALSE; |
| 7090 | rs_state_ci.depthBiasEnable = VK_FALSE; |
| 7091 | |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 7092 | VkGraphicsPipelineCreateInfo gp_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7093 | gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO; |
| 7094 | gp_ci.pViewportState = &vp_state_ci; |
Karl Schultz | dfdb8d4 | 2016-03-08 10:30:21 -0700 | [diff] [blame] | 7095 | gp_ci.pRasterizationState = &rs_state_ci; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7096 | gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT; |
| 7097 | gp_ci.layout = pipeline_layout; |
| 7098 | gp_ci.renderPass = renderPass(); |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 7099 | |
| 7100 | VkPipelineCacheCreateInfo pc_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7101 | pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO; |
| 7102 | pc_ci.initialDataSize = 0; |
| 7103 | pc_ci.pInitialData = 0; |
Tobin Ehlis | af1f3a4 | 2015-06-25 15:46:59 -0600 | [diff] [blame] | 7104 | |
| 7105 | VkPipeline pipeline; |
Jon Ashburn | c669cc6 | 2015-07-09 15:02:25 -0600 | [diff] [blame] | 7106 | VkPipelineCache pipelineCache; |
| 7107 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7108 | err = |
| 7109 | vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache); |
Jon Ashburn | c669cc6 | 2015-07-09 15:02:25 -0600 | [diff] [blame] | 7110 | ASSERT_VK_SUCCESS(err); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7111 | err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, |
| 7112 | &gp_ci, NULL, &pipeline); |
Tobin Ehlis | 7d1a711 | 2015-05-27 14:32:28 -0600 | [diff] [blame] | 7113 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 7114 | m_errorMonitor->VerifyFound(); |
Mike Stroyan | d1c84a5 | 2015-08-18 14:40:24 -0600 | [diff] [blame] | 7115 | |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 7116 | vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL); |
| 7117 | vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL); |
| 7118 | vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL); |
| 7119 | vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL); |
Tobin Ehlis | af1f3a4 | 2015-06-25 15:46:59 -0600 | [diff] [blame] | 7120 | } |
Tobin Ehlis | 912df02 | 2015-09-17 08:46:18 -0600 | [diff] [blame] | 7121 | /*// TODO : This test should be good, but needs Tess support in compiler to run |
| 7122 | TEST_F(VkLayerTest, InvalidPatchControlPoints) |
| 7123 | { |
| 7124 | // Attempt to Create Gfx Pipeline w/o a VS |
Tobin Ehlis | 912df02 | 2015-09-17 08:46:18 -0600 | [diff] [blame] | 7125 | VkResult err; |
Tobin Ehlis | af1f3a4 | 2015-06-25 15:46:59 -0600 | [diff] [blame] | 7126 | |
Courtney Goeltzenleuchter | 7415d5a | 2015-12-09 15:48:16 -0700 | [diff] [blame] | 7127 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7128 | "Invalid Pipeline CreateInfo State: VK_PRIMITIVE_TOPOLOGY_PATCH |
| 7129 | primitive "); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 7130 | |
Tobin Ehlis | 912df02 | 2015-09-17 08:46:18 -0600 | [diff] [blame] | 7131 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 7132 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
Tobin Ehlis | 912df02 | 2015-09-17 08:46:18 -0600 | [diff] [blame] | 7133 | |
Chia-I Wu | 1b99bb2 | 2015-10-27 19:25:11 +0800 | [diff] [blame] | 7134 | VkDescriptorPoolSize ds_type_count = {}; |
Tobin Ehlis | 912df02 | 2015-09-17 08:46:18 -0600 | [diff] [blame] | 7135 | ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
Chia-I Wu | d50a7d7 | 2015-10-26 20:48:51 +0800 | [diff] [blame] | 7136 | ds_type_count.descriptorCount = 1; |
Tobin Ehlis | 912df02 | 2015-09-17 08:46:18 -0600 | [diff] [blame] | 7137 | |
| 7138 | VkDescriptorPoolCreateInfo ds_pool_ci = {}; |
| 7139 | ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO; |
| 7140 | ds_pool_ci.pNext = NULL; |
Chia-I Wu | 1b99bb2 | 2015-10-27 19:25:11 +0800 | [diff] [blame] | 7141 | ds_pool_ci.poolSizeCount = 1; |
| 7142 | ds_pool_ci.pPoolSizes = &ds_type_count; |
Tobin Ehlis | 912df02 | 2015-09-17 08:46:18 -0600 | [diff] [blame] | 7143 | |
| 7144 | VkDescriptorPool ds_pool; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7145 | err = vkCreateDescriptorPool(m_device->device(), |
| 7146 | 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] | 7147 | ASSERT_VK_SUCCESS(err); |
| 7148 | |
| 7149 | VkDescriptorSetLayoutBinding dsl_binding = {}; |
Chia-I Wu | d46e6ae | 2015-10-31 00:31:16 +0800 | [diff] [blame] | 7150 | dsl_binding.binding = 0; |
Tobin Ehlis | 912df02 | 2015-09-17 08:46:18 -0600 | [diff] [blame] | 7151 | dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
Chia-I Wu | 0212448 | 2015-11-06 06:42:02 +0800 | [diff] [blame] | 7152 | dsl_binding.descriptorCount = 1; |
Tobin Ehlis | 912df02 | 2015-09-17 08:46:18 -0600 | [diff] [blame] | 7153 | dsl_binding.stageFlags = VK_SHADER_STAGE_ALL; |
| 7154 | dsl_binding.pImmutableSamplers = NULL; |
| 7155 | |
| 7156 | VkDescriptorSetLayoutCreateInfo ds_layout_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7157 | ds_layout_ci.sType = |
| 7158 | VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO; |
Tobin Ehlis | 912df02 | 2015-09-17 08:46:18 -0600 | [diff] [blame] | 7159 | ds_layout_ci.pNext = NULL; |
Chia-I Wu | d50a7d7 | 2015-10-26 20:48:51 +0800 | [diff] [blame] | 7160 | ds_layout_ci.bindingCount = 1; |
Jon Ashburn | 6e23c1f | 2015-12-30 18:01:16 -0700 | [diff] [blame] | 7161 | ds_layout_ci.pBindings = &dsl_binding; |
Tobin Ehlis | 912df02 | 2015-09-17 08:46:18 -0600 | [diff] [blame] | 7162 | |
| 7163 | VkDescriptorSetLayout ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7164 | err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, |
| 7165 | &ds_layout); |
Tobin Ehlis | 912df02 | 2015-09-17 08:46:18 -0600 | [diff] [blame] | 7166 | ASSERT_VK_SUCCESS(err); |
| 7167 | |
| 7168 | VkDescriptorSet descriptorSet; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7169 | err = vkAllocateDescriptorSets(m_device->device(), ds_pool, |
| 7170 | VK_DESCRIPTOR_SET_USAGE_NON_FREE, 1, &ds_layout, &descriptorSet); |
Tobin Ehlis | 912df02 | 2015-09-17 08:46:18 -0600 | [diff] [blame] | 7171 | ASSERT_VK_SUCCESS(err); |
| 7172 | |
| 7173 | VkPipelineLayoutCreateInfo pipeline_layout_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7174 | pipeline_layout_ci.sType = |
| 7175 | VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO; |
Tobin Ehlis | 912df02 | 2015-09-17 08:46:18 -0600 | [diff] [blame] | 7176 | pipeline_layout_ci.pNext = NULL; |
Chia-I Wu | d50a7d7 | 2015-10-26 20:48:51 +0800 | [diff] [blame] | 7177 | pipeline_layout_ci.setLayoutCount = 1; |
Tobin Ehlis | 912df02 | 2015-09-17 08:46:18 -0600 | [diff] [blame] | 7178 | pipeline_layout_ci.pSetLayouts = &ds_layout; |
| 7179 | |
| 7180 | VkPipelineLayout pipeline_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7181 | err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, |
| 7182 | &pipeline_layout); |
Tobin Ehlis | 912df02 | 2015-09-17 08:46:18 -0600 | [diff] [blame] | 7183 | ASSERT_VK_SUCCESS(err); |
| 7184 | |
| 7185 | VkPipelineShaderStageCreateInfo shaderStages[3]; |
| 7186 | memset(&shaderStages, 0, 3 * sizeof(VkPipelineShaderStageCreateInfo)); |
| 7187 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7188 | VkShaderObj vs(m_device,bindStateVertShaderText,VK_SHADER_STAGE_VERTEX_BIT, |
| 7189 | this); |
Tobin Ehlis | 912df02 | 2015-09-17 08:46:18 -0600 | [diff] [blame] | 7190 | // 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] | 7191 | VkShaderObj |
| 7192 | tc(m_device,bindStateVertShaderText,VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT, |
| 7193 | this); |
| 7194 | VkShaderObj |
| 7195 | te(m_device,bindStateVertShaderText,VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT, |
| 7196 | this); |
Tobin Ehlis | 912df02 | 2015-09-17 08:46:18 -0600 | [diff] [blame] | 7197 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7198 | shaderStages[0].sType = |
| 7199 | VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO; |
Courtney Goeltzenleuchter | d263550 | 2015-10-21 17:08:06 -0600 | [diff] [blame] | 7200 | shaderStages[0].stage = VK_SHADER_STAGE_VERTEX_BIT; |
Tobin Ehlis | 912df02 | 2015-09-17 08:46:18 -0600 | [diff] [blame] | 7201 | shaderStages[0].shader = vs.handle(); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7202 | shaderStages[1].sType = |
| 7203 | VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO; |
Courtney Goeltzenleuchter | d263550 | 2015-10-21 17:08:06 -0600 | [diff] [blame] | 7204 | shaderStages[1].stage = VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT; |
Tobin Ehlis | 912df02 | 2015-09-17 08:46:18 -0600 | [diff] [blame] | 7205 | shaderStages[1].shader = tc.handle(); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7206 | shaderStages[2].sType = |
| 7207 | VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO; |
Courtney Goeltzenleuchter | d263550 | 2015-10-21 17:08:06 -0600 | [diff] [blame] | 7208 | shaderStages[2].stage = VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT; |
Tobin Ehlis | 912df02 | 2015-09-17 08:46:18 -0600 | [diff] [blame] | 7209 | shaderStages[2].shader = te.handle(); |
| 7210 | |
| 7211 | VkPipelineInputAssemblyStateCreateInfo iaCI = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7212 | iaCI.sType = |
| 7213 | VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO; |
Chia-I Wu | 515eb8f | 2015-10-31 00:31:16 +0800 | [diff] [blame] | 7214 | iaCI.topology = VK_PRIMITIVE_TOPOLOGY_PATCH_LIST; |
Tobin Ehlis | 912df02 | 2015-09-17 08:46:18 -0600 | [diff] [blame] | 7215 | |
| 7216 | VkPipelineTessellationStateCreateInfo tsCI = {}; |
| 7217 | tsCI.sType = VK_STRUCTURE_TYPE_PIPELINE_TESSELLATION_STATE_CREATE_INFO; |
| 7218 | tsCI.patchControlPoints = 0; // This will cause an error |
| 7219 | |
| 7220 | VkGraphicsPipelineCreateInfo gp_ci = {}; |
| 7221 | gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO; |
| 7222 | gp_ci.pNext = NULL; |
| 7223 | gp_ci.stageCount = 3; |
| 7224 | gp_ci.pStages = shaderStages; |
| 7225 | gp_ci.pVertexInputState = NULL; |
| 7226 | gp_ci.pInputAssemblyState = &iaCI; |
| 7227 | gp_ci.pTessellationState = &tsCI; |
| 7228 | gp_ci.pViewportState = NULL; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 7229 | gp_ci.pRasterizationState = NULL; |
Tobin Ehlis | 912df02 | 2015-09-17 08:46:18 -0600 | [diff] [blame] | 7230 | gp_ci.pMultisampleState = NULL; |
| 7231 | gp_ci.pDepthStencilState = NULL; |
| 7232 | gp_ci.pColorBlendState = NULL; |
| 7233 | gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT; |
| 7234 | gp_ci.layout = pipeline_layout; |
| 7235 | gp_ci.renderPass = renderPass(); |
| 7236 | |
| 7237 | VkPipelineCacheCreateInfo pc_ci = {}; |
| 7238 | pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO; |
| 7239 | pc_ci.pNext = NULL; |
| 7240 | pc_ci.initialSize = 0; |
| 7241 | pc_ci.initialData = 0; |
| 7242 | pc_ci.maxSize = 0; |
| 7243 | |
| 7244 | VkPipeline pipeline; |
| 7245 | VkPipelineCache pipelineCache; |
| 7246 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7247 | err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, |
| 7248 | &pipelineCache); |
Tobin Ehlis | 912df02 | 2015-09-17 08:46:18 -0600 | [diff] [blame] | 7249 | ASSERT_VK_SUCCESS(err); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7250 | err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, |
| 7251 | &gp_ci, NULL, &pipeline); |
Tobin Ehlis | 912df02 | 2015-09-17 08:46:18 -0600 | [diff] [blame] | 7252 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 7253 | m_errorMonitor->VerifyFound(); |
Mike Stroyan | d1c84a5 | 2015-08-18 14:40:24 -0600 | [diff] [blame] | 7254 | |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 7255 | vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL); |
| 7256 | vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL); |
| 7257 | vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL); |
| 7258 | vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL); |
Tobin Ehlis | 912df02 | 2015-09-17 08:46:18 -0600 | [diff] [blame] | 7259 | } |
| 7260 | */ |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 7261 | // Set scissor and viewport counts to different numbers |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7262 | TEST_F(VkLayerTest, PSOViewportScissorCountMismatch) { |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7263 | VkResult err; |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 7264 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7265 | m_errorMonitor->SetDesiredFailureMsg( |
| 7266 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 7267 | "Gfx Pipeline viewport count (1) must match scissor count (0)."); |
| 7268 | |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 7269 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 7270 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 7271 | |
Chia-I Wu | 1b99bb2 | 2015-10-27 19:25:11 +0800 | [diff] [blame] | 7272 | VkDescriptorPoolSize ds_type_count = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7273 | ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 7274 | ds_type_count.descriptorCount = 1; |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 7275 | |
| 7276 | VkDescriptorPoolCreateInfo ds_pool_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7277 | ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO; |
| 7278 | ds_pool_ci.maxSets = 1; |
| 7279 | ds_pool_ci.poolSizeCount = 1; |
| 7280 | ds_pool_ci.pPoolSizes = &ds_type_count; |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 7281 | |
| 7282 | VkDescriptorPool ds_pool; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7283 | err = |
| 7284 | vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool); |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 7285 | ASSERT_VK_SUCCESS(err); |
| 7286 | |
| 7287 | VkDescriptorSetLayoutBinding dsl_binding = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7288 | dsl_binding.binding = 0; |
| 7289 | dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 7290 | dsl_binding.descriptorCount = 1; |
| 7291 | dsl_binding.stageFlags = VK_SHADER_STAGE_ALL; |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 7292 | |
| 7293 | VkDescriptorSetLayoutCreateInfo ds_layout_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7294 | ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO; |
| 7295 | ds_layout_ci.bindingCount = 1; |
| 7296 | ds_layout_ci.pBindings = &dsl_binding; |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 7297 | |
| 7298 | VkDescriptorSetLayout ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7299 | err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, |
| 7300 | &ds_layout); |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 7301 | ASSERT_VK_SUCCESS(err); |
| 7302 | |
| 7303 | VkDescriptorSet descriptorSet; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 7304 | VkDescriptorSetAllocateInfo alloc_info = {}; |
Chia-I Wu | 00ce540 | 2015-11-10 16:21:09 +0800 | [diff] [blame] | 7305 | alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO; |
Jon Ashburn | f19916e | 2016-01-11 13:12:43 -0700 | [diff] [blame] | 7306 | alloc_info.descriptorSetCount = 1; |
Courtney Goeltzenleuchter | bee18a9 | 2015-10-23 14:21:05 -0600 | [diff] [blame] | 7307 | alloc_info.descriptorPool = ds_pool; |
| 7308 | alloc_info.pSetLayouts = &ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7309 | err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, |
| 7310 | &descriptorSet); |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 7311 | ASSERT_VK_SUCCESS(err); |
| 7312 | |
| 7313 | VkPipelineLayoutCreateInfo pipeline_layout_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7314 | pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO; |
| 7315 | pipeline_layout_ci.setLayoutCount = 1; |
| 7316 | pipeline_layout_ci.pSetLayouts = &ds_layout; |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 7317 | |
| 7318 | VkPipelineLayout pipeline_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7319 | err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, |
| 7320 | &pipeline_layout); |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 7321 | ASSERT_VK_SUCCESS(err); |
| 7322 | |
| 7323 | VkViewport vp = {}; // Just need dummy vp to point to |
| 7324 | |
| 7325 | VkPipelineViewportStateCreateInfo vp_state_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7326 | vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO; |
| 7327 | vp_state_ci.scissorCount = 0; |
| 7328 | vp_state_ci.viewportCount = 1; // Count mismatch should cause error |
| 7329 | vp_state_ci.pViewports = &vp; |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 7330 | |
Karl Schultz | dfdb8d4 | 2016-03-08 10:30:21 -0700 | [diff] [blame] | 7331 | VkPipelineRasterizationStateCreateInfo rs_state_ci = {}; |
| 7332 | rs_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO; |
| 7333 | rs_state_ci.polygonMode = VK_POLYGON_MODE_FILL; |
| 7334 | rs_state_ci.cullMode = VK_CULL_MODE_BACK_BIT; |
| 7335 | rs_state_ci.frontFace = VK_FRONT_FACE_COUNTER_CLOCKWISE; |
| 7336 | rs_state_ci.depthClampEnable = VK_FALSE; |
| 7337 | rs_state_ci.rasterizerDiscardEnable = VK_FALSE; |
| 7338 | rs_state_ci.depthBiasEnable = VK_FALSE; |
| 7339 | |
Cody Northrop | eb3a6c1 | 2015-10-05 14:44:45 -0600 | [diff] [blame] | 7340 | VkPipelineShaderStageCreateInfo shaderStages[2]; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7341 | memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo)); |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 7342 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7343 | VkShaderObj vs(m_device, bindStateVertShaderText, |
| 7344 | VK_SHADER_STAGE_VERTEX_BIT, this); |
| 7345 | VkShaderObj fs(m_device, bindStateFragShaderText, |
| 7346 | VK_SHADER_STAGE_FRAGMENT_BIT, |
Karl Schultz | bdb7595 | 2016-04-19 11:36:49 -0600 | [diff] [blame] | 7347 | this); // We shouldn't need a fragment shader |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7348 | // but add it to be able to run on more devices |
Chia-I Wu | 28e0691 | 2015-10-31 00:31:16 +0800 | [diff] [blame] | 7349 | shaderStages[0] = vs.GetStageCreateInfo(); |
| 7350 | shaderStages[1] = fs.GetStageCreateInfo(); |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 7351 | |
| 7352 | VkGraphicsPipelineCreateInfo gp_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7353 | gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO; |
| 7354 | gp_ci.stageCount = 2; |
| 7355 | gp_ci.pStages = shaderStages; |
| 7356 | gp_ci.pViewportState = &vp_state_ci; |
Karl Schultz | dfdb8d4 | 2016-03-08 10:30:21 -0700 | [diff] [blame] | 7357 | gp_ci.pRasterizationState = &rs_state_ci; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7358 | gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT; |
| 7359 | gp_ci.layout = pipeline_layout; |
| 7360 | gp_ci.renderPass = renderPass(); |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 7361 | |
| 7362 | VkPipelineCacheCreateInfo pc_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7363 | pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO; |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 7364 | |
| 7365 | VkPipeline pipeline; |
| 7366 | VkPipelineCache pipelineCache; |
| 7367 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7368 | err = |
| 7369 | vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache); |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 7370 | ASSERT_VK_SUCCESS(err); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7371 | err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, |
| 7372 | &gp_ci, NULL, &pipeline); |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 7373 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 7374 | m_errorMonitor->VerifyFound(); |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 7375 | |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 7376 | vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL); |
| 7377 | vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL); |
| 7378 | vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL); |
| 7379 | vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL); |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 7380 | } |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7381 | // Don't set viewport state in PSO. This is an error b/c we always need this |
| 7382 | // state |
Tobin Ehlis | d332f28 | 2015-10-02 11:00:56 -0600 | [diff] [blame] | 7383 | // 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] | 7384 | TEST_F(VkLayerTest, PSOViewportStateNotSet) { |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 7385 | // Attempt to Create Gfx Pipeline w/o a VS |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7386 | VkResult err; |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 7387 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7388 | m_errorMonitor->SetDesiredFailureMsg( |
| 7389 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 7390 | "Gfx Pipeline pViewportState is null. Even if "); |
| 7391 | |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 7392 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 7393 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 7394 | |
Chia-I Wu | 1b99bb2 | 2015-10-27 19:25:11 +0800 | [diff] [blame] | 7395 | VkDescriptorPoolSize ds_type_count = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7396 | ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 7397 | ds_type_count.descriptorCount = 1; |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 7398 | |
| 7399 | VkDescriptorPoolCreateInfo ds_pool_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7400 | ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO; |
| 7401 | ds_pool_ci.maxSets = 1; |
| 7402 | ds_pool_ci.poolSizeCount = 1; |
| 7403 | ds_pool_ci.pPoolSizes = &ds_type_count; |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 7404 | |
| 7405 | VkDescriptorPool ds_pool; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7406 | err = |
| 7407 | vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool); |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 7408 | ASSERT_VK_SUCCESS(err); |
| 7409 | |
| 7410 | VkDescriptorSetLayoutBinding dsl_binding = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7411 | dsl_binding.binding = 0; |
| 7412 | dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 7413 | dsl_binding.descriptorCount = 1; |
| 7414 | dsl_binding.stageFlags = VK_SHADER_STAGE_ALL; |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 7415 | |
| 7416 | VkDescriptorSetLayoutCreateInfo ds_layout_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7417 | ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO; |
| 7418 | ds_layout_ci.bindingCount = 1; |
| 7419 | ds_layout_ci.pBindings = &dsl_binding; |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 7420 | |
| 7421 | VkDescriptorSetLayout ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7422 | err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, |
| 7423 | &ds_layout); |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 7424 | ASSERT_VK_SUCCESS(err); |
| 7425 | |
| 7426 | VkDescriptorSet descriptorSet; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 7427 | VkDescriptorSetAllocateInfo alloc_info = {}; |
Chia-I Wu | 00ce540 | 2015-11-10 16:21:09 +0800 | [diff] [blame] | 7428 | alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO; |
Jon Ashburn | f19916e | 2016-01-11 13:12:43 -0700 | [diff] [blame] | 7429 | alloc_info.descriptorSetCount = 1; |
Courtney Goeltzenleuchter | bee18a9 | 2015-10-23 14:21:05 -0600 | [diff] [blame] | 7430 | alloc_info.descriptorPool = ds_pool; |
| 7431 | alloc_info.pSetLayouts = &ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7432 | err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, |
| 7433 | &descriptorSet); |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 7434 | ASSERT_VK_SUCCESS(err); |
| 7435 | |
| 7436 | VkPipelineLayoutCreateInfo pipeline_layout_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7437 | pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO; |
| 7438 | pipeline_layout_ci.setLayoutCount = 1; |
| 7439 | pipeline_layout_ci.pSetLayouts = &ds_layout; |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 7440 | |
| 7441 | VkPipelineLayout pipeline_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7442 | err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, |
| 7443 | &pipeline_layout); |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 7444 | ASSERT_VK_SUCCESS(err); |
| 7445 | |
| 7446 | VkDynamicState sc_state = VK_DYNAMIC_STATE_SCISSOR; |
| 7447 | // Set scissor as dynamic to avoid second error |
| 7448 | VkPipelineDynamicStateCreateInfo dyn_state_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7449 | dyn_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO; |
| 7450 | dyn_state_ci.dynamicStateCount = 1; |
| 7451 | dyn_state_ci.pDynamicStates = &sc_state; |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 7452 | |
Cody Northrop | eb3a6c1 | 2015-10-05 14:44:45 -0600 | [diff] [blame] | 7453 | VkPipelineShaderStageCreateInfo shaderStages[2]; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7454 | memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo)); |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 7455 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7456 | VkShaderObj vs(m_device, bindStateVertShaderText, |
| 7457 | VK_SHADER_STAGE_VERTEX_BIT, this); |
| 7458 | VkShaderObj fs(m_device, bindStateFragShaderText, |
| 7459 | VK_SHADER_STAGE_FRAGMENT_BIT, |
Karl Schultz | bdb7595 | 2016-04-19 11:36:49 -0600 | [diff] [blame] | 7460 | this); // We shouldn't need a fragment shader |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7461 | // but add it to be able to run on more devices |
Chia-I Wu | 28e0691 | 2015-10-31 00:31:16 +0800 | [diff] [blame] | 7462 | shaderStages[0] = vs.GetStageCreateInfo(); |
| 7463 | shaderStages[1] = fs.GetStageCreateInfo(); |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 7464 | |
Karl Schultz | dfdb8d4 | 2016-03-08 10:30:21 -0700 | [diff] [blame] | 7465 | |
| 7466 | VkPipelineRasterizationStateCreateInfo rs_state_ci = {}; |
| 7467 | rs_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO; |
| 7468 | rs_state_ci.polygonMode = VK_POLYGON_MODE_FILL; |
| 7469 | rs_state_ci.cullMode = VK_CULL_MODE_BACK_BIT; |
| 7470 | rs_state_ci.frontFace = VK_FRONT_FACE_COUNTER_CLOCKWISE; |
| 7471 | rs_state_ci.depthClampEnable = VK_FALSE; |
| 7472 | rs_state_ci.rasterizerDiscardEnable = VK_FALSE; |
| 7473 | rs_state_ci.depthBiasEnable = VK_FALSE; |
| 7474 | |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 7475 | VkGraphicsPipelineCreateInfo gp_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7476 | gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO; |
| 7477 | gp_ci.stageCount = 2; |
| 7478 | gp_ci.pStages = shaderStages; |
Karl Schultz | dfdb8d4 | 2016-03-08 10:30:21 -0700 | [diff] [blame] | 7479 | gp_ci.pRasterizationState = &rs_state_ci; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7480 | gp_ci.pViewportState = NULL; // Not setting VP state w/o dynamic vp state |
| 7481 | // should cause validation error |
| 7482 | gp_ci.pDynamicState = &dyn_state_ci; |
| 7483 | gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT; |
| 7484 | gp_ci.layout = pipeline_layout; |
| 7485 | gp_ci.renderPass = renderPass(); |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 7486 | |
| 7487 | VkPipelineCacheCreateInfo pc_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7488 | pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO; |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 7489 | |
| 7490 | VkPipeline pipeline; |
| 7491 | VkPipelineCache pipelineCache; |
| 7492 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7493 | err = |
| 7494 | vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache); |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 7495 | ASSERT_VK_SUCCESS(err); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7496 | err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, |
| 7497 | &gp_ci, NULL, &pipeline); |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 7498 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 7499 | m_errorMonitor->VerifyFound(); |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 7500 | |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 7501 | vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL); |
| 7502 | vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL); |
| 7503 | vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL); |
| 7504 | vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL); |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 7505 | } |
| 7506 | // Create PSO w/o non-zero viewportCount but no viewport data |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7507 | // Then run second test where dynamic scissor count doesn't match PSO scissor |
| 7508 | // count |
| 7509 | TEST_F(VkLayerTest, PSOViewportCountWithoutDataAndDynScissorMismatch) { |
| 7510 | VkResult err; |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 7511 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7512 | m_errorMonitor->SetDesiredFailureMsg( |
| 7513 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 7514 | "Gfx Pipeline viewportCount is 1, but pViewports is NULL. "); |
| 7515 | |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 7516 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 7517 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 7518 | |
Chia-I Wu | 1b99bb2 | 2015-10-27 19:25:11 +0800 | [diff] [blame] | 7519 | VkDescriptorPoolSize ds_type_count = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7520 | ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 7521 | ds_type_count.descriptorCount = 1; |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 7522 | |
| 7523 | VkDescriptorPoolCreateInfo ds_pool_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7524 | ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO; |
| 7525 | ds_pool_ci.maxSets = 1; |
| 7526 | ds_pool_ci.poolSizeCount = 1; |
| 7527 | ds_pool_ci.pPoolSizes = &ds_type_count; |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 7528 | |
| 7529 | VkDescriptorPool ds_pool; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7530 | err = |
| 7531 | vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool); |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 7532 | ASSERT_VK_SUCCESS(err); |
| 7533 | |
| 7534 | VkDescriptorSetLayoutBinding dsl_binding = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7535 | dsl_binding.binding = 0; |
| 7536 | dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 7537 | dsl_binding.descriptorCount = 1; |
| 7538 | dsl_binding.stageFlags = VK_SHADER_STAGE_ALL; |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 7539 | |
| 7540 | VkDescriptorSetLayoutCreateInfo ds_layout_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7541 | ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO; |
| 7542 | ds_layout_ci.bindingCount = 1; |
| 7543 | ds_layout_ci.pBindings = &dsl_binding; |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 7544 | |
| 7545 | VkDescriptorSetLayout ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7546 | err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, |
| 7547 | &ds_layout); |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 7548 | ASSERT_VK_SUCCESS(err); |
| 7549 | |
| 7550 | VkDescriptorSet descriptorSet; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 7551 | VkDescriptorSetAllocateInfo alloc_info = {}; |
Chia-I Wu | 00ce540 | 2015-11-10 16:21:09 +0800 | [diff] [blame] | 7552 | alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO; |
Jon Ashburn | f19916e | 2016-01-11 13:12:43 -0700 | [diff] [blame] | 7553 | alloc_info.descriptorSetCount = 1; |
Courtney Goeltzenleuchter | bee18a9 | 2015-10-23 14:21:05 -0600 | [diff] [blame] | 7554 | alloc_info.descriptorPool = ds_pool; |
| 7555 | alloc_info.pSetLayouts = &ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7556 | err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, |
| 7557 | &descriptorSet); |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 7558 | ASSERT_VK_SUCCESS(err); |
| 7559 | |
| 7560 | VkPipelineLayoutCreateInfo pipeline_layout_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7561 | pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO; |
| 7562 | pipeline_layout_ci.setLayoutCount = 1; |
| 7563 | pipeline_layout_ci.pSetLayouts = &ds_layout; |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 7564 | |
| 7565 | VkPipelineLayout pipeline_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7566 | err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, |
| 7567 | &pipeline_layout); |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 7568 | ASSERT_VK_SUCCESS(err); |
| 7569 | |
| 7570 | VkPipelineViewportStateCreateInfo vp_state_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7571 | vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO; |
| 7572 | vp_state_ci.viewportCount = 1; |
| 7573 | vp_state_ci.pViewports = NULL; // Null vp w/ count of 1 should cause error |
| 7574 | vp_state_ci.scissorCount = 1; |
| 7575 | vp_state_ci.pScissors = |
| 7576 | NULL; // Scissor is dynamic (below) so this won't cause error |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 7577 | |
| 7578 | VkDynamicState sc_state = VK_DYNAMIC_STATE_SCISSOR; |
| 7579 | // Set scissor as dynamic to avoid that error |
| 7580 | VkPipelineDynamicStateCreateInfo dyn_state_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7581 | dyn_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO; |
| 7582 | dyn_state_ci.dynamicStateCount = 1; |
| 7583 | dyn_state_ci.pDynamicStates = &sc_state; |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 7584 | |
Cody Northrop | eb3a6c1 | 2015-10-05 14:44:45 -0600 | [diff] [blame] | 7585 | VkPipelineShaderStageCreateInfo shaderStages[2]; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7586 | memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo)); |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 7587 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7588 | VkShaderObj vs(m_device, bindStateVertShaderText, |
| 7589 | VK_SHADER_STAGE_VERTEX_BIT, this); |
| 7590 | VkShaderObj fs(m_device, bindStateFragShaderText, |
| 7591 | VK_SHADER_STAGE_FRAGMENT_BIT, |
Karl Schultz | bdb7595 | 2016-04-19 11:36:49 -0600 | [diff] [blame] | 7592 | this); // We shouldn't need a fragment shader |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7593 | // but add it to be able to run on more devices |
Chia-I Wu | 28e0691 | 2015-10-31 00:31:16 +0800 | [diff] [blame] | 7594 | shaderStages[0] = vs.GetStageCreateInfo(); |
| 7595 | shaderStages[1] = fs.GetStageCreateInfo(); |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 7596 | |
Cody Northrop | f6622dc | 2015-10-06 10:33:21 -0600 | [diff] [blame] | 7597 | VkPipelineVertexInputStateCreateInfo vi_ci = {}; |
| 7598 | vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO; |
| 7599 | vi_ci.pNext = nullptr; |
Chia-I Wu | d50a7d7 | 2015-10-26 20:48:51 +0800 | [diff] [blame] | 7600 | vi_ci.vertexBindingDescriptionCount = 0; |
Cody Northrop | f6622dc | 2015-10-06 10:33:21 -0600 | [diff] [blame] | 7601 | vi_ci.pVertexBindingDescriptions = nullptr; |
Chia-I Wu | d50a7d7 | 2015-10-26 20:48:51 +0800 | [diff] [blame] | 7602 | vi_ci.vertexAttributeDescriptionCount = 0; |
Cody Northrop | f6622dc | 2015-10-06 10:33:21 -0600 | [diff] [blame] | 7603 | vi_ci.pVertexAttributeDescriptions = nullptr; |
| 7604 | |
| 7605 | VkPipelineInputAssemblyStateCreateInfo ia_ci = {}; |
| 7606 | ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO; |
| 7607 | ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP; |
| 7608 | |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 7609 | VkPipelineRasterizationStateCreateInfo rs_ci = {}; |
Chia-I Wu | 1b99bb2 | 2015-10-27 19:25:11 +0800 | [diff] [blame] | 7610 | rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO; |
Cody Northrop | f6622dc | 2015-10-06 10:33:21 -0600 | [diff] [blame] | 7611 | rs_ci.pNext = nullptr; |
| 7612 | |
Mark Young | c89c631 | 2016-03-31 16:03:20 -0600 | [diff] [blame] | 7613 | VkPipelineColorBlendAttachmentState att = {}; |
| 7614 | att.blendEnable = VK_FALSE; |
| 7615 | att.colorWriteMask = 0xf; |
| 7616 | |
Cody Northrop | f6622dc | 2015-10-06 10:33:21 -0600 | [diff] [blame] | 7617 | VkPipelineColorBlendStateCreateInfo cb_ci = {}; |
| 7618 | cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO; |
| 7619 | cb_ci.pNext = nullptr; |
Mark Young | c89c631 | 2016-03-31 16:03:20 -0600 | [diff] [blame] | 7620 | cb_ci.attachmentCount = 1; |
| 7621 | cb_ci.pAttachments = &att; |
Cody Northrop | f6622dc | 2015-10-06 10:33:21 -0600 | [diff] [blame] | 7622 | |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 7623 | VkGraphicsPipelineCreateInfo gp_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7624 | gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO; |
| 7625 | gp_ci.stageCount = 2; |
| 7626 | gp_ci.pStages = shaderStages; |
| 7627 | gp_ci.pVertexInputState = &vi_ci; |
| 7628 | gp_ci.pInputAssemblyState = &ia_ci; |
| 7629 | gp_ci.pViewportState = &vp_state_ci; |
| 7630 | gp_ci.pRasterizationState = &rs_ci; |
| 7631 | gp_ci.pColorBlendState = &cb_ci; |
| 7632 | gp_ci.pDynamicState = &dyn_state_ci; |
| 7633 | gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT; |
| 7634 | gp_ci.layout = pipeline_layout; |
| 7635 | gp_ci.renderPass = renderPass(); |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 7636 | |
| 7637 | VkPipelineCacheCreateInfo pc_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7638 | pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO; |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 7639 | |
| 7640 | VkPipeline pipeline; |
| 7641 | VkPipelineCache pipelineCache; |
| 7642 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7643 | err = |
| 7644 | vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache); |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 7645 | ASSERT_VK_SUCCESS(err); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7646 | err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, |
| 7647 | &gp_ci, NULL, &pipeline); |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 7648 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 7649 | m_errorMonitor->VerifyFound(); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 7650 | |
Tobin Ehlis | d332f28 | 2015-10-02 11:00:56 -0600 | [diff] [blame] | 7651 | // 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] | 7652 | // First need to successfully create the PSO from above by setting |
| 7653 | // pViewports |
| 7654 | m_errorMonitor->SetDesiredFailureMsg( |
| 7655 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 7656 | "Dynamic scissorCount from vkCmdSetScissor() is 2, but PSO " |
| 7657 | "scissorCount is 1. These counts must match."); |
| 7658 | |
| 7659 | VkViewport vp = {}; // Just need dummy vp to point to |
| 7660 | vp_state_ci.pViewports = &vp; |
| 7661 | err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, |
| 7662 | &gp_ci, NULL, &pipeline); |
| 7663 | ASSERT_VK_SUCCESS(err); |
| 7664 | BeginCommandBuffer(); |
| 7665 | vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), |
| 7666 | VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline); |
| 7667 | VkRect2D scissors[2] = {}; // don't care about data |
| 7668 | // Count of 2 doesn't match PSO count of 1 |
| 7669 | vkCmdSetScissor(m_commandBuffer->GetBufferHandle(), 0, 2, scissors); |
| 7670 | Draw(1, 0, 0, 0); |
| 7671 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 7672 | m_errorMonitor->VerifyFound(); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7673 | |
| 7674 | vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL); |
| 7675 | vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL); |
| 7676 | vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL); |
| 7677 | vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL); |
Tony Barbour | df4c004 | 2016-06-01 15:55:43 -0600 | [diff] [blame] | 7678 | vkDestroyPipeline(m_device->device(), pipeline, NULL); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7679 | } |
| 7680 | // Create PSO w/o non-zero scissorCount but no scissor data |
| 7681 | // Then run second test where dynamic viewportCount doesn't match PSO |
| 7682 | // viewportCount |
| 7683 | TEST_F(VkLayerTest, PSOScissorCountWithoutDataAndDynViewportMismatch) { |
| 7684 | VkResult err; |
| 7685 | |
| 7686 | m_errorMonitor->SetDesiredFailureMsg( |
| 7687 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 7688 | "Gfx Pipeline scissorCount is 1, but pScissors is NULL. "); |
| 7689 | |
| 7690 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 7691 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 7692 | |
| 7693 | VkDescriptorPoolSize ds_type_count = {}; |
| 7694 | ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 7695 | ds_type_count.descriptorCount = 1; |
| 7696 | |
| 7697 | VkDescriptorPoolCreateInfo ds_pool_ci = {}; |
| 7698 | ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO; |
| 7699 | ds_pool_ci.maxSets = 1; |
| 7700 | ds_pool_ci.poolSizeCount = 1; |
| 7701 | ds_pool_ci.pPoolSizes = &ds_type_count; |
| 7702 | |
| 7703 | VkDescriptorPool ds_pool; |
| 7704 | err = |
| 7705 | vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool); |
| 7706 | ASSERT_VK_SUCCESS(err); |
| 7707 | |
| 7708 | VkDescriptorSetLayoutBinding dsl_binding = {}; |
| 7709 | dsl_binding.binding = 0; |
| 7710 | dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 7711 | dsl_binding.descriptorCount = 1; |
| 7712 | dsl_binding.stageFlags = VK_SHADER_STAGE_ALL; |
| 7713 | |
| 7714 | VkDescriptorSetLayoutCreateInfo ds_layout_ci = {}; |
| 7715 | ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO; |
| 7716 | ds_layout_ci.bindingCount = 1; |
| 7717 | ds_layout_ci.pBindings = &dsl_binding; |
| 7718 | |
| 7719 | VkDescriptorSetLayout ds_layout; |
| 7720 | err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, |
| 7721 | &ds_layout); |
| 7722 | ASSERT_VK_SUCCESS(err); |
| 7723 | |
| 7724 | VkDescriptorSet descriptorSet; |
| 7725 | VkDescriptorSetAllocateInfo alloc_info = {}; |
| 7726 | alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO; |
| 7727 | alloc_info.descriptorSetCount = 1; |
| 7728 | alloc_info.descriptorPool = ds_pool; |
| 7729 | alloc_info.pSetLayouts = &ds_layout; |
| 7730 | err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, |
| 7731 | &descriptorSet); |
| 7732 | ASSERT_VK_SUCCESS(err); |
| 7733 | |
| 7734 | VkPipelineLayoutCreateInfo pipeline_layout_ci = {}; |
| 7735 | pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO; |
| 7736 | pipeline_layout_ci.setLayoutCount = 1; |
| 7737 | pipeline_layout_ci.pSetLayouts = &ds_layout; |
| 7738 | |
| 7739 | VkPipelineLayout pipeline_layout; |
| 7740 | err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, |
| 7741 | &pipeline_layout); |
| 7742 | ASSERT_VK_SUCCESS(err); |
| 7743 | |
| 7744 | VkPipelineViewportStateCreateInfo vp_state_ci = {}; |
| 7745 | vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO; |
| 7746 | vp_state_ci.scissorCount = 1; |
| 7747 | vp_state_ci.pScissors = |
| 7748 | NULL; // Null scissor w/ count of 1 should cause error |
| 7749 | vp_state_ci.viewportCount = 1; |
| 7750 | vp_state_ci.pViewports = |
| 7751 | NULL; // vp is dynamic (below) so this won't cause error |
| 7752 | |
| 7753 | VkDynamicState vp_state = VK_DYNAMIC_STATE_VIEWPORT; |
| 7754 | // Set scissor as dynamic to avoid that error |
| 7755 | VkPipelineDynamicStateCreateInfo dyn_state_ci = {}; |
| 7756 | dyn_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO; |
| 7757 | dyn_state_ci.dynamicStateCount = 1; |
| 7758 | dyn_state_ci.pDynamicStates = &vp_state; |
| 7759 | |
| 7760 | VkPipelineShaderStageCreateInfo shaderStages[2]; |
| 7761 | memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo)); |
| 7762 | |
| 7763 | VkShaderObj vs(m_device, bindStateVertShaderText, |
| 7764 | VK_SHADER_STAGE_VERTEX_BIT, this); |
| 7765 | VkShaderObj fs(m_device, bindStateFragShaderText, |
| 7766 | VK_SHADER_STAGE_FRAGMENT_BIT, |
Karl Schultz | bdb7595 | 2016-04-19 11:36:49 -0600 | [diff] [blame] | 7767 | this); // We shouldn't need a fragment shader |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7768 | // but add it to be able to run on more devices |
| 7769 | shaderStages[0] = vs.GetStageCreateInfo(); |
| 7770 | shaderStages[1] = fs.GetStageCreateInfo(); |
| 7771 | |
| 7772 | VkPipelineVertexInputStateCreateInfo vi_ci = {}; |
| 7773 | vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO; |
| 7774 | vi_ci.pNext = nullptr; |
| 7775 | vi_ci.vertexBindingDescriptionCount = 0; |
| 7776 | vi_ci.pVertexBindingDescriptions = nullptr; |
| 7777 | vi_ci.vertexAttributeDescriptionCount = 0; |
| 7778 | vi_ci.pVertexAttributeDescriptions = nullptr; |
| 7779 | |
| 7780 | VkPipelineInputAssemblyStateCreateInfo ia_ci = {}; |
| 7781 | ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO; |
| 7782 | ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP; |
| 7783 | |
| 7784 | VkPipelineRasterizationStateCreateInfo rs_ci = {}; |
| 7785 | rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO; |
| 7786 | rs_ci.pNext = nullptr; |
| 7787 | |
Mark Young | c89c631 | 2016-03-31 16:03:20 -0600 | [diff] [blame] | 7788 | VkPipelineColorBlendAttachmentState att = {}; |
| 7789 | att.blendEnable = VK_FALSE; |
| 7790 | att.colorWriteMask = 0xf; |
| 7791 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7792 | VkPipelineColorBlendStateCreateInfo cb_ci = {}; |
| 7793 | cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO; |
| 7794 | cb_ci.pNext = nullptr; |
Mark Young | c89c631 | 2016-03-31 16:03:20 -0600 | [diff] [blame] | 7795 | cb_ci.attachmentCount = 1; |
| 7796 | cb_ci.pAttachments = &att; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7797 | |
| 7798 | VkGraphicsPipelineCreateInfo gp_ci = {}; |
| 7799 | gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO; |
| 7800 | gp_ci.stageCount = 2; |
| 7801 | gp_ci.pStages = shaderStages; |
| 7802 | gp_ci.pVertexInputState = &vi_ci; |
| 7803 | gp_ci.pInputAssemblyState = &ia_ci; |
| 7804 | gp_ci.pViewportState = &vp_state_ci; |
| 7805 | gp_ci.pRasterizationState = &rs_ci; |
| 7806 | gp_ci.pColorBlendState = &cb_ci; |
| 7807 | gp_ci.pDynamicState = &dyn_state_ci; |
| 7808 | gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT; |
| 7809 | gp_ci.layout = pipeline_layout; |
| 7810 | gp_ci.renderPass = renderPass(); |
| 7811 | |
| 7812 | VkPipelineCacheCreateInfo pc_ci = {}; |
| 7813 | pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO; |
| 7814 | |
| 7815 | VkPipeline pipeline; |
| 7816 | VkPipelineCache pipelineCache; |
| 7817 | |
| 7818 | err = |
| 7819 | vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache); |
| 7820 | ASSERT_VK_SUCCESS(err); |
| 7821 | err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, |
| 7822 | &gp_ci, NULL, &pipeline); |
| 7823 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 7824 | m_errorMonitor->VerifyFound(); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7825 | |
| 7826 | // Now hit second fail case where we set scissor w/ different count than PSO |
| 7827 | // First need to successfully create the PSO from above by setting |
| 7828 | // pViewports |
| 7829 | m_errorMonitor->SetDesiredFailureMsg( |
| 7830 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 7831 | "Dynamic viewportCount from vkCmdSetViewport() is 2, but PSO " |
| 7832 | "viewportCount is 1. These counts must match."); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 7833 | |
Tobin Ehlis | d332f28 | 2015-10-02 11:00:56 -0600 | [diff] [blame] | 7834 | VkRect2D sc = {}; // Just need dummy vp to point to |
| 7835 | vp_state_ci.pScissors = ≻ |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7836 | err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, |
| 7837 | &gp_ci, NULL, &pipeline); |
Tobin Ehlis | d332f28 | 2015-10-02 11:00:56 -0600 | [diff] [blame] | 7838 | ASSERT_VK_SUCCESS(err); |
| 7839 | BeginCommandBuffer(); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7840 | vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), |
| 7841 | VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline); |
Tobin Ehlis | d332f28 | 2015-10-02 11:00:56 -0600 | [diff] [blame] | 7842 | VkViewport viewports[2] = {}; // don't care about data |
| 7843 | // Count of 2 doesn't match PSO count of 1 |
Jon Ashburn | 19d3bf1 | 2015-12-30 14:06:55 -0700 | [diff] [blame] | 7844 | vkCmdSetViewport(m_commandBuffer->GetBufferHandle(), 0, 2, viewports); |
Tobin Ehlis | d332f28 | 2015-10-02 11:00:56 -0600 | [diff] [blame] | 7845 | Draw(1, 0, 0, 0); |
| 7846 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 7847 | m_errorMonitor->VerifyFound(); |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 7848 | |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 7849 | vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL); |
| 7850 | vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL); |
| 7851 | vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL); |
| 7852 | vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL); |
Tony Barbour | df4c004 | 2016-06-01 15:55:43 -0600 | [diff] [blame] | 7853 | vkDestroyPipeline(m_device->device(), pipeline, NULL); |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 7854 | } |
| 7855 | |
Mark Young | 7394fdd | 2016-03-31 14:56:43 -0600 | [diff] [blame] | 7856 | TEST_F(VkLayerTest, PSOLineWidthInvalid) { |
| 7857 | VkResult err; |
| 7858 | |
| 7859 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Mark Young | 4710795 | 2016-05-02 15:59:55 -0600 | [diff] [blame] | 7860 | "Attempt to set lineWidth to -1"); |
Mark Young | 7394fdd | 2016-03-31 14:56:43 -0600 | [diff] [blame] | 7861 | |
| 7862 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 7863 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 7864 | |
| 7865 | VkDescriptorPoolSize ds_type_count = {}; |
| 7866 | ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 7867 | ds_type_count.descriptorCount = 1; |
| 7868 | |
| 7869 | VkDescriptorPoolCreateInfo ds_pool_ci = {}; |
| 7870 | ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO; |
| 7871 | ds_pool_ci.maxSets = 1; |
| 7872 | ds_pool_ci.poolSizeCount = 1; |
| 7873 | ds_pool_ci.pPoolSizes = &ds_type_count; |
| 7874 | |
| 7875 | VkDescriptorPool ds_pool; |
| 7876 | err = |
| 7877 | vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool); |
| 7878 | ASSERT_VK_SUCCESS(err); |
| 7879 | |
| 7880 | VkDescriptorSetLayoutBinding dsl_binding = {}; |
| 7881 | dsl_binding.binding = 0; |
| 7882 | dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 7883 | dsl_binding.descriptorCount = 1; |
| 7884 | dsl_binding.stageFlags = VK_SHADER_STAGE_ALL; |
| 7885 | |
| 7886 | VkDescriptorSetLayoutCreateInfo ds_layout_ci = {}; |
| 7887 | ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO; |
| 7888 | ds_layout_ci.bindingCount = 1; |
| 7889 | ds_layout_ci.pBindings = &dsl_binding; |
| 7890 | |
| 7891 | VkDescriptorSetLayout ds_layout; |
| 7892 | err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, |
| 7893 | &ds_layout); |
| 7894 | ASSERT_VK_SUCCESS(err); |
| 7895 | |
| 7896 | VkDescriptorSet descriptorSet; |
| 7897 | VkDescriptorSetAllocateInfo alloc_info = {}; |
| 7898 | alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO; |
| 7899 | alloc_info.descriptorSetCount = 1; |
| 7900 | alloc_info.descriptorPool = ds_pool; |
| 7901 | alloc_info.pSetLayouts = &ds_layout; |
| 7902 | err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, |
| 7903 | &descriptorSet); |
| 7904 | ASSERT_VK_SUCCESS(err); |
| 7905 | |
| 7906 | VkPipelineLayoutCreateInfo pipeline_layout_ci = {}; |
| 7907 | pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO; |
| 7908 | pipeline_layout_ci.setLayoutCount = 1; |
| 7909 | pipeline_layout_ci.pSetLayouts = &ds_layout; |
| 7910 | |
| 7911 | VkPipelineLayout pipeline_layout; |
| 7912 | err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, |
| 7913 | &pipeline_layout); |
| 7914 | ASSERT_VK_SUCCESS(err); |
| 7915 | |
| 7916 | VkPipelineViewportStateCreateInfo vp_state_ci = {}; |
| 7917 | vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO; |
| 7918 | vp_state_ci.scissorCount = 1; |
| 7919 | vp_state_ci.pScissors = NULL; |
| 7920 | vp_state_ci.viewportCount = 1; |
| 7921 | vp_state_ci.pViewports = NULL; |
| 7922 | |
| 7923 | VkDynamicState dynamic_states[3] = {VK_DYNAMIC_STATE_VIEWPORT, |
| 7924 | VK_DYNAMIC_STATE_SCISSOR, |
| 7925 | VK_DYNAMIC_STATE_LINE_WIDTH}; |
| 7926 | // Set scissor as dynamic to avoid that error |
| 7927 | VkPipelineDynamicStateCreateInfo dyn_state_ci = {}; |
| 7928 | dyn_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO; |
| 7929 | dyn_state_ci.dynamicStateCount = 2; |
| 7930 | dyn_state_ci.pDynamicStates = dynamic_states; |
| 7931 | |
| 7932 | VkPipelineShaderStageCreateInfo shaderStages[2]; |
| 7933 | memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo)); |
| 7934 | |
| 7935 | VkShaderObj vs(m_device, bindStateVertShaderText, |
| 7936 | VK_SHADER_STAGE_VERTEX_BIT, this); |
| 7937 | VkShaderObj fs(m_device, bindStateFragShaderText, |
| 7938 | VK_SHADER_STAGE_FRAGMENT_BIT, |
| 7939 | this); // TODO - We shouldn't need a fragment shader |
| 7940 | // but add it to be able to run on more devices |
| 7941 | shaderStages[0] = vs.GetStageCreateInfo(); |
| 7942 | shaderStages[1] = fs.GetStageCreateInfo(); |
| 7943 | |
| 7944 | VkPipelineVertexInputStateCreateInfo vi_ci = {}; |
| 7945 | vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO; |
| 7946 | vi_ci.pNext = nullptr; |
| 7947 | vi_ci.vertexBindingDescriptionCount = 0; |
| 7948 | vi_ci.pVertexBindingDescriptions = nullptr; |
| 7949 | vi_ci.vertexAttributeDescriptionCount = 0; |
| 7950 | vi_ci.pVertexAttributeDescriptions = nullptr; |
| 7951 | |
| 7952 | VkPipelineInputAssemblyStateCreateInfo ia_ci = {}; |
| 7953 | ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO; |
| 7954 | ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP; |
| 7955 | |
| 7956 | VkPipelineRasterizationStateCreateInfo rs_ci = {}; |
| 7957 | rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO; |
| 7958 | rs_ci.pNext = nullptr; |
| 7959 | |
Mark Young | 4710795 | 2016-05-02 15:59:55 -0600 | [diff] [blame] | 7960 | // Check too low (line width of -1.0f). |
| 7961 | rs_ci.lineWidth = -1.0f; |
Mark Young | 7394fdd | 2016-03-31 14:56:43 -0600 | [diff] [blame] | 7962 | |
| 7963 | VkPipelineColorBlendAttachmentState att = {}; |
| 7964 | att.blendEnable = VK_FALSE; |
| 7965 | att.colorWriteMask = 0xf; |
| 7966 | |
| 7967 | VkPipelineColorBlendStateCreateInfo cb_ci = {}; |
| 7968 | cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO; |
| 7969 | cb_ci.pNext = nullptr; |
| 7970 | cb_ci.attachmentCount = 1; |
| 7971 | cb_ci.pAttachments = &att; |
| 7972 | |
| 7973 | VkGraphicsPipelineCreateInfo gp_ci = {}; |
| 7974 | gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO; |
| 7975 | gp_ci.stageCount = 2; |
| 7976 | gp_ci.pStages = shaderStages; |
| 7977 | gp_ci.pVertexInputState = &vi_ci; |
| 7978 | gp_ci.pInputAssemblyState = &ia_ci; |
| 7979 | gp_ci.pViewportState = &vp_state_ci; |
| 7980 | gp_ci.pRasterizationState = &rs_ci; |
| 7981 | gp_ci.pColorBlendState = &cb_ci; |
| 7982 | gp_ci.pDynamicState = &dyn_state_ci; |
| 7983 | gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT; |
| 7984 | gp_ci.layout = pipeline_layout; |
| 7985 | gp_ci.renderPass = renderPass(); |
| 7986 | |
| 7987 | VkPipelineCacheCreateInfo pc_ci = {}; |
| 7988 | pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO; |
| 7989 | |
| 7990 | VkPipeline pipeline; |
| 7991 | VkPipelineCache pipelineCache; |
| 7992 | |
| 7993 | err = |
| 7994 | vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache); |
| 7995 | ASSERT_VK_SUCCESS(err); |
| 7996 | err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, |
| 7997 | &gp_ci, NULL, &pipeline); |
| 7998 | |
| 7999 | m_errorMonitor->VerifyFound(); |
Tony Barbour | df4c004 | 2016-06-01 15:55:43 -0600 | [diff] [blame] | 8000 | vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL); |
Mark Young | 7394fdd | 2016-03-31 14:56:43 -0600 | [diff] [blame] | 8001 | |
| 8002 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 8003 | "Attempt to set lineWidth to 65536"); |
| 8004 | |
| 8005 | // Check too high (line width of 65536.0f). |
| 8006 | rs_ci.lineWidth = 65536.0f; |
| 8007 | |
| 8008 | err = |
| 8009 | vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache); |
| 8010 | ASSERT_VK_SUCCESS(err); |
| 8011 | err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, |
| 8012 | &gp_ci, NULL, &pipeline); |
| 8013 | |
| 8014 | m_errorMonitor->VerifyFound(); |
Tony Barbour | df4c004 | 2016-06-01 15:55:43 -0600 | [diff] [blame] | 8015 | vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL); |
Mark Young | 7394fdd | 2016-03-31 14:56:43 -0600 | [diff] [blame] | 8016 | |
| 8017 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Mark Young | 4710795 | 2016-05-02 15:59:55 -0600 | [diff] [blame] | 8018 | "Attempt to set lineWidth to -1"); |
Mark Young | 7394fdd | 2016-03-31 14:56:43 -0600 | [diff] [blame] | 8019 | |
| 8020 | dyn_state_ci.dynamicStateCount = 3; |
| 8021 | |
| 8022 | rs_ci.lineWidth = 1.0f; |
| 8023 | |
| 8024 | err = |
| 8025 | vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache); |
| 8026 | ASSERT_VK_SUCCESS(err); |
| 8027 | err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, |
| 8028 | &gp_ci, NULL, &pipeline); |
| 8029 | BeginCommandBuffer(); |
| 8030 | vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), |
| 8031 | VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline); |
| 8032 | |
| 8033 | // Check too low with dynamic setting. |
Mark Young | 4710795 | 2016-05-02 15:59:55 -0600 | [diff] [blame] | 8034 | vkCmdSetLineWidth(m_commandBuffer->GetBufferHandle(), -1.0f); |
Mark Young | 7394fdd | 2016-03-31 14:56:43 -0600 | [diff] [blame] | 8035 | m_errorMonitor->VerifyFound(); |
| 8036 | |
| 8037 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 8038 | "Attempt to set lineWidth to 65536"); |
| 8039 | |
| 8040 | // Check too high with dynamic setting. |
| 8041 | vkCmdSetLineWidth(m_commandBuffer->GetBufferHandle(), 65536.0f); |
| 8042 | m_errorMonitor->VerifyFound(); |
| 8043 | EndCommandBuffer(); |
| 8044 | |
| 8045 | vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL); |
| 8046 | vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL); |
| 8047 | vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL); |
| 8048 | vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL); |
Tony Barbour | df4c004 | 2016-06-01 15:55:43 -0600 | [diff] [blame] | 8049 | vkDestroyPipeline(m_device->device(), pipeline, NULL); |
Mark Young | 7394fdd | 2016-03-31 14:56:43 -0600 | [diff] [blame] | 8050 | } |
| 8051 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8052 | TEST_F(VkLayerTest, NullRenderPass) { |
Tobin Ehlis | 98aa0ed | 2015-06-25 16:27:19 -0600 | [diff] [blame] | 8053 | // Bind a NULL RenderPass |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8054 | m_errorMonitor->SetDesiredFailureMsg( |
| 8055 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 8056 | "You cannot use a NULL RenderPass object in vkCmdBeginRenderPass()"); |
Tobin Ehlis | 98aa0ed | 2015-06-25 16:27:19 -0600 | [diff] [blame] | 8057 | |
| 8058 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 8059 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
Tobin Ehlis | 98aa0ed | 2015-06-25 16:27:19 -0600 | [diff] [blame] | 8060 | |
Tony Barbour | fe3351b | 2015-07-28 10:17:20 -0600 | [diff] [blame] | 8061 | BeginCommandBuffer(); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8062 | // Don't care about RenderPass handle b/c error should be flagged before |
| 8063 | // that |
| 8064 | vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), NULL, |
| 8065 | VK_SUBPASS_CONTENTS_INLINE); |
Tobin Ehlis | 98aa0ed | 2015-06-25 16:27:19 -0600 | [diff] [blame] | 8066 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 8067 | m_errorMonitor->VerifyFound(); |
Tobin Ehlis | 98aa0ed | 2015-06-25 16:27:19 -0600 | [diff] [blame] | 8068 | } |
| 8069 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8070 | TEST_F(VkLayerTest, RenderPassWithinRenderPass) { |
Tobin Ehlis | af1f3a4 | 2015-06-25 15:46:59 -0600 | [diff] [blame] | 8071 | // Bind a BeginRenderPass within an active RenderPass |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8072 | m_errorMonitor->SetDesiredFailureMsg( |
| 8073 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 8074 | "It is invalid to issue this call inside an active render pass"); |
Tobin Ehlis | af1f3a4 | 2015-06-25 15:46:59 -0600 | [diff] [blame] | 8075 | |
| 8076 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 8077 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
Tobin Ehlis | af1f3a4 | 2015-06-25 15:46:59 -0600 | [diff] [blame] | 8078 | |
Tony Barbour | fe3351b | 2015-07-28 10:17:20 -0600 | [diff] [blame] | 8079 | BeginCommandBuffer(); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8080 | // Just create a dummy Renderpass that's non-NULL so we can get to the |
| 8081 | // proper error |
Chris Forbes | 38ae7c4 | 2016-06-21 20:51:44 +1200 | [diff] [blame] | 8082 | vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &m_renderPassBeginInfo, |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8083 | VK_SUBPASS_CONTENTS_INLINE); |
Tobin Ehlis | af1f3a4 | 2015-06-25 15:46:59 -0600 | [diff] [blame] | 8084 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 8085 | m_errorMonitor->VerifyFound(); |
Tobin Ehlis | 49eb23d | 2015-05-22 12:38:55 -0600 | [diff] [blame] | 8086 | } |
| 8087 | |
Chris Forbes | 2eeabe3 | 2016-06-21 20:52:34 +1200 | [diff] [blame] | 8088 | TEST_F(VkLayerTest, RenderPassSecondaryCommandBuffersMultipleTimes) { |
| 8089 | m_errorMonitor->ExpectSuccess(); |
| 8090 | |
| 8091 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 8092 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 8093 | |
| 8094 | BeginCommandBuffer(); // framework implicitly begins the renderpass. |
| 8095 | vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle()); // end implicit. |
| 8096 | |
| 8097 | vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &m_renderPassBeginInfo, |
| 8098 | VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS); |
| 8099 | vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle()); |
| 8100 | m_errorMonitor->VerifyNotFound(); |
| 8101 | vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &m_renderPassBeginInfo, |
| 8102 | VK_SUBPASS_CONTENTS_INLINE); |
| 8103 | m_errorMonitor->VerifyNotFound(); |
| 8104 | vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle()); |
| 8105 | m_errorMonitor->VerifyNotFound(); |
| 8106 | |
| 8107 | m_commandBuffer->EndCommandBuffer(); |
| 8108 | m_errorMonitor->VerifyNotFound(); |
| 8109 | } |
| 8110 | |
Tobin Ehlis | 5a1c033 | 2016-05-31 13:59:26 -0600 | [diff] [blame] | 8111 | TEST_F(VkLayerTest, RenderPassClearOpMismatch) { |
| 8112 | TEST_DESCRIPTION("Begin a renderPass where clearValueCount is less than" |
| 8113 | "the number of renderPass attachments that use loadOp" |
| 8114 | "VK_ATTACHMENT_LOAD_OP_CLEAR."); |
| 8115 | |
| 8116 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 8117 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 8118 | |
| 8119 | // Create a renderPass with a single attachment that uses loadOp CLEAR |
| 8120 | VkAttachmentReference attach = {}; |
| 8121 | attach.layout = VK_IMAGE_LAYOUT_GENERAL; |
| 8122 | VkSubpassDescription subpass = {}; |
| 8123 | subpass.inputAttachmentCount = 1; |
| 8124 | subpass.pInputAttachments = &attach; |
| 8125 | VkRenderPassCreateInfo rpci = {}; |
| 8126 | rpci.subpassCount = 1; |
| 8127 | rpci.pSubpasses = &subpass; |
| 8128 | rpci.attachmentCount = 1; |
| 8129 | VkAttachmentDescription attach_desc = {}; |
| 8130 | attach_desc.format = VK_FORMAT_UNDEFINED; |
| 8131 | // Set loadOp to CLEAR |
| 8132 | attach_desc.loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR; |
| 8133 | rpci.pAttachments = &attach_desc; |
| 8134 | rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO; |
| 8135 | VkRenderPass rp; |
| 8136 | vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp); |
| 8137 | |
| 8138 | VkCommandBufferInheritanceInfo hinfo = {}; |
| 8139 | hinfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO; |
| 8140 | hinfo.renderPass = VK_NULL_HANDLE; |
| 8141 | hinfo.subpass = 0; |
| 8142 | hinfo.framebuffer = VK_NULL_HANDLE; |
| 8143 | hinfo.occlusionQueryEnable = VK_FALSE; |
| 8144 | hinfo.queryFlags = 0; |
| 8145 | hinfo.pipelineStatistics = 0; |
| 8146 | VkCommandBufferBeginInfo info = {}; |
| 8147 | info.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT; |
| 8148 | info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO; |
| 8149 | info.pInheritanceInfo = &hinfo; |
| 8150 | |
| 8151 | vkBeginCommandBuffer(m_commandBuffer->handle(), &info); |
| 8152 | VkRenderPassBeginInfo rp_begin = {}; |
| 8153 | rp_begin.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO; |
| 8154 | rp_begin.pNext = NULL; |
| 8155 | rp_begin.renderPass = renderPass(); |
| 8156 | rp_begin.framebuffer = framebuffer(); |
| 8157 | rp_begin.clearValueCount = 0; // Should be 1 |
| 8158 | |
| 8159 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 8160 | " has a clearValueCount of 0 but the " |
| 8161 | "actual number of attachments in " |
| 8162 | "renderPass "); |
| 8163 | |
| 8164 | vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &rp_begin, |
| 8165 | VK_SUBPASS_CONTENTS_INLINE); |
| 8166 | |
| 8167 | m_errorMonitor->VerifyFound(); |
Mark Lobodzinski | 5c70ebd | 2016-06-09 13:45:00 -0600 | [diff] [blame] | 8168 | |
| 8169 | vkDestroyRenderPass(m_device->device(), rp, NULL); |
Tobin Ehlis | 5a1c033 | 2016-05-31 13:59:26 -0600 | [diff] [blame] | 8170 | } |
| 8171 | |
Cody Northrop | 3bb4d96 | 2016-05-09 16:15:57 -0600 | [diff] [blame] | 8172 | TEST_F(VkLayerTest, EndCommandBufferWithinRenderPass) { |
| 8173 | |
| 8174 | TEST_DESCRIPTION("End a command buffer with an active render pass"); |
| 8175 | |
| 8176 | m_errorMonitor->SetDesiredFailureMsg( |
| 8177 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 8178 | "It is invalid to issue this call inside an active render pass"); |
| 8179 | |
| 8180 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 8181 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 8182 | |
| 8183 | // The framework's BeginCommandBuffer calls CreateRenderPass |
| 8184 | BeginCommandBuffer(); |
| 8185 | |
| 8186 | // Call directly into vkEndCommandBuffer instead of the |
| 8187 | // the framework's EndCommandBuffer, which inserts a |
| 8188 | // vkEndRenderPass |
| 8189 | vkEndCommandBuffer(m_commandBuffer->GetBufferHandle()); |
| 8190 | |
| 8191 | m_errorMonitor->VerifyFound(); |
| 8192 | |
| 8193 | // TODO: Add test for VK_COMMAND_BUFFER_LEVEL_SECONDARY |
| 8194 | // TODO: Add test for VK_COMMAND_BUFFER_USAGE_RENDER_PASS_CONTINUE_BIT |
| 8195 | } |
| 8196 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8197 | TEST_F(VkLayerTest, FillBufferWithinRenderPass) { |
Mark Lobodzinski | d563950 | 2015-09-24 09:51:47 -0600 | [diff] [blame] | 8198 | // Call CmdFillBuffer within an active renderpass |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8199 | m_errorMonitor->SetDesiredFailureMsg( |
| 8200 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 8201 | "It is invalid to issue this call inside an active render pass"); |
Mark Lobodzinski | d563950 | 2015-09-24 09:51:47 -0600 | [diff] [blame] | 8202 | |
| 8203 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 8204 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
Mark Lobodzinski | d563950 | 2015-09-24 09:51:47 -0600 | [diff] [blame] | 8205 | |
| 8206 | // Renderpass is started here |
| 8207 | BeginCommandBuffer(); |
| 8208 | |
| 8209 | VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 8210 | vk_testing::Buffer dstBuffer; |
| 8211 | dstBuffer.init_as_dst(*m_device, (VkDeviceSize)1024, reqs); |
Mark Lobodzinski | d563950 | 2015-09-24 09:51:47 -0600 | [diff] [blame] | 8212 | |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 8213 | m_commandBuffer->FillBuffer(dstBuffer.handle(), 0, 4, 0x11111111); |
Mark Lobodzinski | d563950 | 2015-09-24 09:51:47 -0600 | [diff] [blame] | 8214 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 8215 | m_errorMonitor->VerifyFound(); |
Mark Lobodzinski | d563950 | 2015-09-24 09:51:47 -0600 | [diff] [blame] | 8216 | } |
| 8217 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8218 | TEST_F(VkLayerTest, UpdateBufferWithinRenderPass) { |
Mark Lobodzinski | d563950 | 2015-09-24 09:51:47 -0600 | [diff] [blame] | 8219 | // Call CmdUpdateBuffer within an active renderpass |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8220 | m_errorMonitor->SetDesiredFailureMsg( |
| 8221 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 8222 | "It is invalid to issue this call inside an active render pass"); |
Mark Lobodzinski | d563950 | 2015-09-24 09:51:47 -0600 | [diff] [blame] | 8223 | |
| 8224 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 8225 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
Mark Lobodzinski | d563950 | 2015-09-24 09:51:47 -0600 | [diff] [blame] | 8226 | |
| 8227 | // Renderpass is started here |
| 8228 | BeginCommandBuffer(); |
| 8229 | |
| 8230 | VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 8231 | vk_testing::Buffer dstBuffer; |
| 8232 | dstBuffer.init_as_dst(*m_device, (VkDeviceSize)1024, reqs); |
Mark Lobodzinski | d563950 | 2015-09-24 09:51:47 -0600 | [diff] [blame] | 8233 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8234 | VkDeviceSize dstOffset = 0; |
| 8235 | VkDeviceSize dataSize = 1024; |
| 8236 | const uint32_t *pData = NULL; |
Mark Lobodzinski | d563950 | 2015-09-24 09:51:47 -0600 | [diff] [blame] | 8237 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8238 | vkCmdUpdateBuffer(m_commandBuffer->GetBufferHandle(), dstBuffer.handle(), |
| 8239 | dstOffset, dataSize, pData); |
Mark Lobodzinski | d563950 | 2015-09-24 09:51:47 -0600 | [diff] [blame] | 8240 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 8241 | m_errorMonitor->VerifyFound(); |
Mark Lobodzinski | d563950 | 2015-09-24 09:51:47 -0600 | [diff] [blame] | 8242 | } |
| 8243 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8244 | TEST_F(VkLayerTest, ClearColorImageWithinRenderPass) { |
Mark Lobodzinski | d563950 | 2015-09-24 09:51:47 -0600 | [diff] [blame] | 8245 | // Call CmdClearColorImage within an active RenderPass |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8246 | m_errorMonitor->SetDesiredFailureMsg( |
| 8247 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 8248 | "It is invalid to issue this call inside an active render pass"); |
Mark Lobodzinski | d563950 | 2015-09-24 09:51:47 -0600 | [diff] [blame] | 8249 | |
| 8250 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 8251 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
Mark Lobodzinski | d563950 | 2015-09-24 09:51:47 -0600 | [diff] [blame] | 8252 | |
| 8253 | // Renderpass is started here |
| 8254 | BeginCommandBuffer(); |
| 8255 | |
Michael Lentine | 0a369f6 | 2016-02-03 16:51:46 -0600 | [diff] [blame] | 8256 | VkClearColorValue clear_color; |
| 8257 | memset(clear_color.uint32, 0, sizeof(uint32_t) * 4); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8258 | VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT; |
| 8259 | const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM; |
| 8260 | const int32_t tex_width = 32; |
| 8261 | const int32_t tex_height = 32; |
| 8262 | VkImageCreateInfo image_create_info = {}; |
| 8263 | image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO; |
| 8264 | image_create_info.pNext = NULL; |
| 8265 | image_create_info.imageType = VK_IMAGE_TYPE_2D; |
| 8266 | image_create_info.format = tex_format; |
| 8267 | image_create_info.extent.width = tex_width; |
| 8268 | image_create_info.extent.height = tex_height; |
| 8269 | image_create_info.extent.depth = 1; |
| 8270 | image_create_info.mipLevels = 1; |
| 8271 | image_create_info.arrayLayers = 1; |
| 8272 | image_create_info.samples = VK_SAMPLE_COUNT_1_BIT; |
| 8273 | image_create_info.tiling = VK_IMAGE_TILING_LINEAR; |
| 8274 | image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT; |
Mark Lobodzinski | d563950 | 2015-09-24 09:51:47 -0600 | [diff] [blame] | 8275 | |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 8276 | vk_testing::Image dstImage; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8277 | dstImage.init(*m_device, (const VkImageCreateInfo &)image_create_info, |
| 8278 | reqs); |
Mark Lobodzinski | d563950 | 2015-09-24 09:51:47 -0600 | [diff] [blame] | 8279 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8280 | const VkImageSubresourceRange range = vk_testing::Image::subresource_range( |
| 8281 | image_create_info, VK_IMAGE_ASPECT_COLOR_BIT); |
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 | vkCmdClearColorImage(m_commandBuffer->GetBufferHandle(), dstImage.handle(), |
| 8284 | VK_IMAGE_LAYOUT_GENERAL, &clear_color, 1, &range); |
Mark Lobodzinski | d563950 | 2015-09-24 09:51:47 -0600 | [diff] [blame] | 8285 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 8286 | m_errorMonitor->VerifyFound(); |
Mark Lobodzinski | d563950 | 2015-09-24 09:51:47 -0600 | [diff] [blame] | 8287 | } |
| 8288 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8289 | TEST_F(VkLayerTest, ClearDepthStencilImageWithinRenderPass) { |
Mark Lobodzinski | d563950 | 2015-09-24 09:51:47 -0600 | [diff] [blame] | 8290 | // Call CmdClearDepthStencilImage within an active RenderPass |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8291 | m_errorMonitor->SetDesiredFailureMsg( |
| 8292 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 8293 | "It is invalid to issue this call inside an active render pass"); |
Mark Lobodzinski | d563950 | 2015-09-24 09:51:47 -0600 | [diff] [blame] | 8294 | |
| 8295 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 8296 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
Mark Lobodzinski | d563950 | 2015-09-24 09:51:47 -0600 | [diff] [blame] | 8297 | |
| 8298 | // Renderpass is started here |
| 8299 | BeginCommandBuffer(); |
| 8300 | |
| 8301 | VkClearDepthStencilValue clear_value = {0}; |
Dustin Graves | a2e5c94 | 2016-02-11 18:28:06 -0700 | [diff] [blame] | 8302 | VkMemoryPropertyFlags reqs = 0; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8303 | VkImageCreateInfo image_create_info = vk_testing::Image::create_info(); |
| 8304 | image_create_info.imageType = VK_IMAGE_TYPE_2D; |
| 8305 | image_create_info.format = VK_FORMAT_D24_UNORM_S8_UINT; |
| 8306 | image_create_info.extent.width = 64; |
| 8307 | image_create_info.extent.height = 64; |
| 8308 | image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL; |
| 8309 | image_create_info.usage = VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT; |
Mark Lobodzinski | d563950 | 2015-09-24 09:51:47 -0600 | [diff] [blame] | 8310 | |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 8311 | vk_testing::Image dstImage; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8312 | dstImage.init(*m_device, (const VkImageCreateInfo &)image_create_info, |
| 8313 | reqs); |
Mark Lobodzinski | d563950 | 2015-09-24 09:51:47 -0600 | [diff] [blame] | 8314 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8315 | const VkImageSubresourceRange range = vk_testing::Image::subresource_range( |
| 8316 | image_create_info, VK_IMAGE_ASPECT_DEPTH_BIT); |
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 | vkCmdClearDepthStencilImage( |
| 8319 | m_commandBuffer->GetBufferHandle(), dstImage.handle(), |
| 8320 | VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL, &clear_value, 1, |
| 8321 | &range); |
Mark Lobodzinski | d563950 | 2015-09-24 09:51:47 -0600 | [diff] [blame] | 8322 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 8323 | m_errorMonitor->VerifyFound(); |
Mark Lobodzinski | d563950 | 2015-09-24 09:51:47 -0600 | [diff] [blame] | 8324 | } |
| 8325 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8326 | TEST_F(VkLayerTest, ClearColorAttachmentsOutsideRenderPass) { |
Courtney Goeltzenleuchter | c9323e0 | 2015-10-15 16:51:05 -0600 | [diff] [blame] | 8327 | // Call CmdClearAttachmentss outside of an active RenderPass |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8328 | VkResult err; |
Mark Lobodzinski | d563950 | 2015-09-24 09:51:47 -0600 | [diff] [blame] | 8329 | |
Courtney Goeltzenleuchter | 7415d5a | 2015-12-09 15:48:16 -0700 | [diff] [blame] | 8330 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8331 | "vkCmdClearAttachments: This call " |
| 8332 | "must be issued inside an active " |
| 8333 | "render pass"); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 8334 | |
Mark Lobodzinski | d563950 | 2015-09-24 09:51:47 -0600 | [diff] [blame] | 8335 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 8336 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
Mark Lobodzinski | d563950 | 2015-09-24 09:51:47 -0600 | [diff] [blame] | 8337 | |
| 8338 | // Start no RenderPass |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 8339 | err = m_commandBuffer->BeginCommandBuffer(); |
Mark Lobodzinski | d563950 | 2015-09-24 09:51:47 -0600 | [diff] [blame] | 8340 | ASSERT_VK_SUCCESS(err); |
| 8341 | |
Courtney Goeltzenleuchter | c9323e0 | 2015-10-15 16:51:05 -0600 | [diff] [blame] | 8342 | VkClearAttachment color_attachment; |
| 8343 | color_attachment.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; |
| 8344 | color_attachment.clearValue.color.float32[0] = 0; |
| 8345 | color_attachment.clearValue.color.float32[1] = 0; |
| 8346 | color_attachment.clearValue.color.float32[2] = 0; |
| 8347 | color_attachment.clearValue.color.float32[3] = 0; |
| 8348 | color_attachment.colorAttachment = 0; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8349 | VkClearRect clear_rect = {{{0, 0}, {32, 32}}}; |
| 8350 | vkCmdClearAttachments(m_commandBuffer->GetBufferHandle(), 1, |
| 8351 | &color_attachment, 1, &clear_rect); |
Mark Lobodzinski | d563950 | 2015-09-24 09:51:47 -0600 | [diff] [blame] | 8352 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 8353 | m_errorMonitor->VerifyFound(); |
Mark Lobodzinski | d563950 | 2015-09-24 09:51:47 -0600 | [diff] [blame] | 8354 | } |
| 8355 | |
Karl Schultz | 9e66a29 | 2016-04-21 15:57:51 -0600 | [diff] [blame] | 8356 | TEST_F(VkLayerTest, BufferMemoryBarrierNoBuffer) { |
| 8357 | // Try to add a buffer memory barrier with no buffer. |
| 8358 | m_errorMonitor->SetDesiredFailureMsg( |
| 8359 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 8360 | "required parameter pBufferMemoryBarriers[i].buffer specified as VK_NULL_HANDLE"); |
| 8361 | |
| 8362 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 8363 | BeginCommandBuffer(); |
| 8364 | |
| 8365 | VkBufferMemoryBarrier buf_barrier = {}; |
| 8366 | buf_barrier.sType = VK_STRUCTURE_TYPE_BUFFER_MEMORY_BARRIER; |
| 8367 | buf_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT; |
| 8368 | buf_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT; |
| 8369 | buf_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED; |
| 8370 | buf_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED; |
| 8371 | buf_barrier.buffer = VK_NULL_HANDLE; |
| 8372 | buf_barrier.offset = 0; |
| 8373 | buf_barrier.size = VK_WHOLE_SIZE; |
| 8374 | vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), |
| 8375 | VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, |
| 8376 | 0, 0, nullptr, 1, &buf_barrier, 0, nullptr); |
| 8377 | |
| 8378 | m_errorMonitor->VerifyFound(); |
| 8379 | } |
| 8380 | |
Tony Barbour | 7fd5c0f | 2016-05-03 16:11:53 -0600 | [diff] [blame] | 8381 | TEST_F(VkLayerTest, InvalidBarriers) { |
| 8382 | TEST_DESCRIPTION("A variety of ways to get VK_INVALID_BARRIER "); |
| 8383 | |
| 8384 | m_errorMonitor->SetDesiredFailureMsg( |
| 8385 | VK_DEBUG_REPORT_ERROR_BIT_EXT, "Barriers cannot be set during subpass"); |
| 8386 | |
| 8387 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 8388 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 8389 | |
| 8390 | VkMemoryBarrier mem_barrier = {}; |
| 8391 | mem_barrier.sType = VK_STRUCTURE_TYPE_MEMORY_BARRIER; |
| 8392 | mem_barrier.pNext = NULL; |
| 8393 | mem_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT; |
| 8394 | mem_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT; |
| 8395 | BeginCommandBuffer(); |
| 8396 | // BeginCommandBuffer() starts a render pass |
| 8397 | vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), |
| 8398 | VK_PIPELINE_STAGE_HOST_BIT, |
| 8399 | VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 1, |
| 8400 | &mem_barrier, 0, nullptr, 0, nullptr); |
| 8401 | m_errorMonitor->VerifyFound(); |
| 8402 | |
| 8403 | m_errorMonitor->SetDesiredFailureMsg( |
| 8404 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 8405 | "Image Layout cannot be transitioned to UNDEFINED"); |
| 8406 | VkImageObj image(m_device); |
| 8407 | image.init(128, 128, VK_FORMAT_B8G8R8A8_UNORM, |
| 8408 | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0); |
| 8409 | ASSERT_TRUE(image.initialized()); |
| 8410 | VkImageMemoryBarrier img_barrier = {}; |
| 8411 | img_barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER; |
| 8412 | img_barrier.pNext = NULL; |
| 8413 | img_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT; |
| 8414 | img_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT; |
| 8415 | img_barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL; |
| 8416 | // New layout can't be UNDEFINED |
| 8417 | img_barrier.newLayout = VK_IMAGE_LAYOUT_UNDEFINED; |
| 8418 | img_barrier.image = image.handle(); |
| 8419 | img_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED; |
| 8420 | img_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED; |
| 8421 | img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; |
| 8422 | img_barrier.subresourceRange.baseArrayLayer = 0; |
| 8423 | img_barrier.subresourceRange.baseMipLevel = 0; |
| 8424 | img_barrier.subresourceRange.layerCount = 1; |
| 8425 | img_barrier.subresourceRange.levelCount = 1; |
| 8426 | vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), |
| 8427 | VK_PIPELINE_STAGE_HOST_BIT, |
| 8428 | VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0, nullptr, 0, |
| 8429 | nullptr, 1, &img_barrier); |
| 8430 | m_errorMonitor->VerifyFound(); |
| 8431 | img_barrier.newLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL; |
| 8432 | |
| 8433 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 8434 | "Subresource must have the sum of the " |
| 8435 | "baseArrayLayer"); |
| 8436 | // baseArrayLayer + layerCount must be <= image's arrayLayers |
| 8437 | img_barrier.subresourceRange.baseArrayLayer = 1; |
| 8438 | vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), |
| 8439 | VK_PIPELINE_STAGE_HOST_BIT, |
| 8440 | VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0, nullptr, 0, |
| 8441 | nullptr, 1, &img_barrier); |
| 8442 | m_errorMonitor->VerifyFound(); |
| 8443 | img_barrier.subresourceRange.baseArrayLayer = 0; |
| 8444 | |
| 8445 | m_errorMonitor->SetDesiredFailureMsg( |
| 8446 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 8447 | "Subresource must have the sum of the baseMipLevel"); |
| 8448 | // baseMipLevel + levelCount must be <= image's mipLevels |
| 8449 | img_barrier.subresourceRange.baseMipLevel = 1; |
| 8450 | vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), |
| 8451 | VK_PIPELINE_STAGE_HOST_BIT, |
| 8452 | VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0, nullptr, 0, |
| 8453 | nullptr, 1, &img_barrier); |
| 8454 | m_errorMonitor->VerifyFound(); |
| 8455 | img_barrier.subresourceRange.baseMipLevel = 0; |
| 8456 | |
| 8457 | m_errorMonitor->SetDesiredFailureMsg( |
| 8458 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 8459 | "Buffer Barriers cannot be used during a render pass"); |
| 8460 | vk_testing::Buffer buffer; |
| 8461 | buffer.init(*m_device, 256); |
| 8462 | VkBufferMemoryBarrier buf_barrier = {}; |
| 8463 | buf_barrier.sType = VK_STRUCTURE_TYPE_BUFFER_MEMORY_BARRIER; |
| 8464 | buf_barrier.pNext = NULL; |
| 8465 | buf_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT; |
| 8466 | buf_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT; |
| 8467 | buf_barrier.buffer = buffer.handle(); |
| 8468 | buf_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED; |
| 8469 | buf_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED; |
| 8470 | buf_barrier.offset = 0; |
| 8471 | buf_barrier.size = VK_WHOLE_SIZE; |
| 8472 | // Can't send buffer barrier during a render pass |
| 8473 | vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), |
| 8474 | VK_PIPELINE_STAGE_HOST_BIT, |
| 8475 | VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0, nullptr, 1, |
| 8476 | &buf_barrier, 0, nullptr); |
| 8477 | m_errorMonitor->VerifyFound(); |
| 8478 | vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle()); |
| 8479 | |
| 8480 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 8481 | "which is not less than total size"); |
| 8482 | buf_barrier.offset = 257; |
| 8483 | // Offset greater than total size |
| 8484 | vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), |
| 8485 | VK_PIPELINE_STAGE_HOST_BIT, |
| 8486 | VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0, nullptr, 1, |
| 8487 | &buf_barrier, 0, nullptr); |
| 8488 | m_errorMonitor->VerifyFound(); |
| 8489 | buf_barrier.offset = 0; |
| 8490 | |
| 8491 | m_errorMonitor->SetDesiredFailureMsg( |
| 8492 | VK_DEBUG_REPORT_ERROR_BIT_EXT, "whose sum is greater than total size"); |
| 8493 | buf_barrier.size = 257; |
| 8494 | // Size greater than total size |
| 8495 | vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), |
| 8496 | VK_PIPELINE_STAGE_HOST_BIT, |
| 8497 | VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0, nullptr, 1, |
| 8498 | &buf_barrier, 0, nullptr); |
| 8499 | m_errorMonitor->VerifyFound(); |
| 8500 | buf_barrier.size = VK_WHOLE_SIZE; |
| 8501 | |
| 8502 | m_errorMonitor->SetDesiredFailureMsg( |
| 8503 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 8504 | "Image is a depth and stencil format and thus must " |
| 8505 | "have both VK_IMAGE_ASPECT_DEPTH_BIT and " |
| 8506 | "VK_IMAGE_ASPECT_STENCIL_BIT set."); |
| 8507 | VkDepthStencilObj ds_image(m_device); |
| 8508 | ds_image.Init(m_device, 128, 128, VK_FORMAT_D24_UNORM_S8_UINT); |
| 8509 | ASSERT_TRUE(ds_image.initialized()); |
| 8510 | img_barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL; |
| 8511 | img_barrier.newLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL; |
| 8512 | img_barrier.image = ds_image.handle(); |
| 8513 | // Leave aspectMask at COLOR on purpose |
| 8514 | vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), |
| 8515 | VK_PIPELINE_STAGE_HOST_BIT, |
| 8516 | VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0, nullptr, 0, |
| 8517 | nullptr, 1, &img_barrier); |
| 8518 | m_errorMonitor->VerifyFound(); |
| 8519 | } |
| 8520 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8521 | TEST_F(VkLayerTest, IdxBufferAlignmentError) { |
Tobin Ehlis | c4c2318 | 2015-09-17 12:24:13 -0600 | [diff] [blame] | 8522 | // Bind a BeginRenderPass within an active RenderPass |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8523 | VkResult err; |
Tobin Ehlis | c4c2318 | 2015-09-17 12:24:13 -0600 | [diff] [blame] | 8524 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8525 | m_errorMonitor->SetDesiredFailureMsg( |
| 8526 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 8527 | "vkCmdBindIndexBuffer() offset (0x7) does not fall on "); |
| 8528 | |
Tobin Ehlis | c4c2318 | 2015-09-17 12:24:13 -0600 | [diff] [blame] | 8529 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 8530 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
Tobin Ehlis | c4c2318 | 2015-09-17 12:24:13 -0600 | [diff] [blame] | 8531 | uint32_t qfi = 0; |
| 8532 | VkBufferCreateInfo buffCI = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8533 | buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO; |
| 8534 | buffCI.size = 1024; |
| 8535 | buffCI.usage = VK_BUFFER_USAGE_INDEX_BUFFER_BIT; |
| 8536 | buffCI.queueFamilyIndexCount = 1; |
| 8537 | buffCI.pQueueFamilyIndices = &qfi; |
Tobin Ehlis | c4c2318 | 2015-09-17 12:24:13 -0600 | [diff] [blame] | 8538 | |
| 8539 | VkBuffer ib; |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 8540 | err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &ib); |
Tobin Ehlis | c4c2318 | 2015-09-17 12:24:13 -0600 | [diff] [blame] | 8541 | ASSERT_VK_SUCCESS(err); |
| 8542 | |
| 8543 | BeginCommandBuffer(); |
| 8544 | ASSERT_VK_SUCCESS(err); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8545 | // vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), |
| 8546 | // VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle()); |
Tobin Ehlis | c4c2318 | 2015-09-17 12:24:13 -0600 | [diff] [blame] | 8547 | // 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] | 8548 | vkCmdBindIndexBuffer(m_commandBuffer->GetBufferHandle(), ib, 7, |
| 8549 | VK_INDEX_TYPE_UINT16); |
Tobin Ehlis | c4c2318 | 2015-09-17 12:24:13 -0600 | [diff] [blame] | 8550 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 8551 | m_errorMonitor->VerifyFound(); |
Mike Stroyan | d1c84a5 | 2015-08-18 14:40:24 -0600 | [diff] [blame] | 8552 | |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 8553 | vkDestroyBuffer(m_device->device(), ib, NULL); |
Tobin Ehlis | c4c2318 | 2015-09-17 12:24:13 -0600 | [diff] [blame] | 8554 | } |
| 8555 | |
Mark Lobodzinski | 52a6e7d | 2016-02-25 15:09:52 -0700 | [diff] [blame] | 8556 | TEST_F(VkLayerTest, InvalidQueueFamilyIndex) { |
| 8557 | // Create an out-of-range queueFamilyIndex |
| 8558 | m_errorMonitor->SetDesiredFailureMsg( |
| 8559 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Dustin Graves | de62853 | 2016-04-21 16:30:17 -0600 | [diff] [blame] | 8560 | "vkCreateBuffer: pCreateInfo->pQueueFamilyIndices[0] (777) must be one " |
| 8561 | "of the indices specified when the device was created, via the " |
| 8562 | "VkDeviceQueueCreateInfo structure."); |
Mark Lobodzinski | 52a6e7d | 2016-02-25 15:09:52 -0700 | [diff] [blame] | 8563 | |
| 8564 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 8565 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 8566 | VkBufferCreateInfo buffCI = {}; |
| 8567 | buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO; |
| 8568 | buffCI.size = 1024; |
| 8569 | buffCI.usage = VK_BUFFER_USAGE_INDEX_BUFFER_BIT; |
| 8570 | buffCI.queueFamilyIndexCount = 1; |
| 8571 | // Introduce failure by specifying invalid queue_family_index |
| 8572 | uint32_t qfi = 777; |
| 8573 | buffCI.pQueueFamilyIndices = &qfi; |
Tobin Ehlis | 24aab04 | 2016-03-24 10:54:18 -0600 | [diff] [blame] | 8574 | buffCI.sharingMode = VK_SHARING_MODE_CONCURRENT; // qfi only matters in CONCURRENT mode |
Mark Lobodzinski | 52a6e7d | 2016-02-25 15:09:52 -0700 | [diff] [blame] | 8575 | |
| 8576 | VkBuffer ib; |
| 8577 | vkCreateBuffer(m_device->device(), &buffCI, NULL, &ib); |
| 8578 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 8579 | m_errorMonitor->VerifyFound(); |
Tony Barbour | df4c004 | 2016-06-01 15:55:43 -0600 | [diff] [blame] | 8580 | vkDestroyBuffer(m_device->device(), ib, NULL); |
Mark Lobodzinski | 52a6e7d | 2016-02-25 15:09:52 -0700 | [diff] [blame] | 8581 | } |
| 8582 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8583 | TEST_F(VkLayerTest, ExecuteCommandsPrimaryCB) { |
| 8584 | // Attempt vkCmdExecuteCommands w/ a primary cmd buffer (should only be |
| 8585 | // secondary) |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 8586 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8587 | m_errorMonitor->SetDesiredFailureMsg( |
| 8588 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 8589 | "vkCmdExecuteCommands() called w/ Primary Cmd Buffer "); |
Tobin Ehlis | 4b34ddc | 2015-09-17 14:18:16 -0600 | [diff] [blame] | 8590 | |
| 8591 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 8592 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
Tobin Ehlis | 4b34ddc | 2015-09-17 14:18:16 -0600 | [diff] [blame] | 8593 | |
| 8594 | BeginCommandBuffer(); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8595 | // ASSERT_VK_SUCCESS(err); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 8596 | VkCommandBuffer primCB = m_commandBuffer->GetBufferHandle(); |
| 8597 | vkCmdExecuteCommands(m_commandBuffer->GetBufferHandle(), 1, &primCB); |
Tobin Ehlis | 4b34ddc | 2015-09-17 14:18:16 -0600 | [diff] [blame] | 8598 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 8599 | m_errorMonitor->VerifyFound(); |
Tobin Ehlis | 4b34ddc | 2015-09-17 14:18:16 -0600 | [diff] [blame] | 8600 | } |
| 8601 | |
Tobin Ehlis | 17826bd | 2016-05-25 11:12:50 -0600 | [diff] [blame] | 8602 | TEST_F(VkLayerTest, DSUsageBitsErrors) { |
| 8603 | TEST_DESCRIPTION("Attempt to update descriptor sets for images and buffers " |
| 8604 | "that do not have correct usage bits sets."); |
| 8605 | VkResult err; |
| 8606 | |
| 8607 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 8608 | VkDescriptorPoolSize ds_type_count[VK_DESCRIPTOR_TYPE_RANGE_SIZE] = {}; |
| 8609 | for (uint32_t i = 0; i < VK_DESCRIPTOR_TYPE_RANGE_SIZE; ++i) { |
| 8610 | ds_type_count[i].type = VkDescriptorType(i); |
| 8611 | ds_type_count[i].descriptorCount = 1; |
| 8612 | } |
| 8613 | VkDescriptorPoolCreateInfo ds_pool_ci = {}; |
| 8614 | ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO; |
| 8615 | ds_pool_ci.pNext = NULL; |
| 8616 | ds_pool_ci.maxSets = VK_DESCRIPTOR_TYPE_RANGE_SIZE; |
| 8617 | ds_pool_ci.poolSizeCount = VK_DESCRIPTOR_TYPE_RANGE_SIZE; |
| 8618 | ds_pool_ci.pPoolSizes = ds_type_count; |
| 8619 | |
| 8620 | VkDescriptorPool ds_pool; |
| 8621 | err = |
| 8622 | vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool); |
| 8623 | ASSERT_VK_SUCCESS(err); |
| 8624 | |
| 8625 | // Create 10 layouts where each has a single descriptor of different type |
| 8626 | VkDescriptorSetLayoutBinding dsl_binding[VK_DESCRIPTOR_TYPE_RANGE_SIZE] = |
| 8627 | {}; |
| 8628 | for (uint32_t i = 0; i < VK_DESCRIPTOR_TYPE_RANGE_SIZE; ++i) { |
| 8629 | dsl_binding[i].binding = 0; |
| 8630 | dsl_binding[i].descriptorType = VkDescriptorType(i); |
| 8631 | dsl_binding[i].descriptorCount = 1; |
| 8632 | dsl_binding[i].stageFlags = VK_SHADER_STAGE_ALL; |
| 8633 | dsl_binding[i].pImmutableSamplers = NULL; |
| 8634 | } |
| 8635 | |
| 8636 | VkDescriptorSetLayoutCreateInfo ds_layout_ci = {}; |
| 8637 | ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO; |
| 8638 | ds_layout_ci.pNext = NULL; |
| 8639 | ds_layout_ci.bindingCount = 1; |
| 8640 | VkDescriptorSetLayout ds_layouts[VK_DESCRIPTOR_TYPE_RANGE_SIZE]; |
| 8641 | for (uint32_t i = 0; i < VK_DESCRIPTOR_TYPE_RANGE_SIZE; ++i) { |
| 8642 | ds_layout_ci.pBindings = dsl_binding + i; |
| 8643 | err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, |
| 8644 | NULL, ds_layouts + i); |
| 8645 | ASSERT_VK_SUCCESS(err); |
| 8646 | } |
| 8647 | VkDescriptorSet descriptor_sets[VK_DESCRIPTOR_TYPE_RANGE_SIZE] = {}; |
| 8648 | VkDescriptorSetAllocateInfo alloc_info = {}; |
| 8649 | alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO; |
| 8650 | alloc_info.descriptorSetCount = VK_DESCRIPTOR_TYPE_RANGE_SIZE; |
| 8651 | alloc_info.descriptorPool = ds_pool; |
| 8652 | alloc_info.pSetLayouts = ds_layouts; |
| 8653 | err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, |
| 8654 | descriptor_sets); |
| 8655 | ASSERT_VK_SUCCESS(err); |
| 8656 | |
| 8657 | // Create a buffer & bufferView to be used for invalid updates |
| 8658 | VkBufferCreateInfo buff_ci = {}; |
| 8659 | buff_ci.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO; |
| 8660 | // This usage is not valid for any descriptor type |
| 8661 | buff_ci.usage = VK_BUFFER_USAGE_TRANSFER_SRC_BIT; |
| 8662 | buff_ci.size = 256; |
| 8663 | buff_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE; |
| 8664 | VkBuffer buffer; |
| 8665 | err = vkCreateBuffer(m_device->device(), &buff_ci, NULL, &buffer); |
| 8666 | ASSERT_VK_SUCCESS(err); |
| 8667 | |
| 8668 | VkBufferViewCreateInfo buff_view_ci = {}; |
| 8669 | buff_view_ci.sType = VK_STRUCTURE_TYPE_BUFFER_VIEW_CREATE_INFO; |
| 8670 | buff_view_ci.buffer = buffer; |
| 8671 | buff_view_ci.format = VK_FORMAT_R8_UNORM; |
| 8672 | buff_view_ci.range = VK_WHOLE_SIZE; |
| 8673 | VkBufferView buff_view; |
| 8674 | err = |
| 8675 | vkCreateBufferView(m_device->device(), &buff_view_ci, NULL, &buff_view); |
| 8676 | ASSERT_VK_SUCCESS(err); |
| 8677 | |
| 8678 | // Create an image to be used for invalid updates |
| 8679 | VkImageCreateInfo image_ci = {}; |
| 8680 | image_ci.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO; |
| 8681 | image_ci.imageType = VK_IMAGE_TYPE_2D; |
| 8682 | image_ci.format = VK_FORMAT_R8G8B8A8_UNORM; |
| 8683 | image_ci.extent.width = 64; |
| 8684 | image_ci.extent.height = 64; |
| 8685 | image_ci.extent.depth = 1; |
| 8686 | image_ci.mipLevels = 1; |
| 8687 | image_ci.arrayLayers = 1; |
| 8688 | image_ci.samples = VK_SAMPLE_COUNT_1_BIT; |
| 8689 | image_ci.tiling = VK_IMAGE_TILING_LINEAR; |
| 8690 | image_ci.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED; |
| 8691 | // This usage is not valid for any descriptor type |
| 8692 | image_ci.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT; |
| 8693 | image_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE; |
| 8694 | VkImage image; |
| 8695 | err = vkCreateImage(m_device->device(), &image_ci, NULL, &image); |
| 8696 | ASSERT_VK_SUCCESS(err); |
| 8697 | // Bind memory to image |
| 8698 | VkMemoryRequirements mem_reqs; |
| 8699 | VkDeviceMemory image_mem; |
| 8700 | bool pass; |
| 8701 | VkMemoryAllocateInfo mem_alloc = {}; |
| 8702 | mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO; |
| 8703 | mem_alloc.pNext = NULL; |
| 8704 | mem_alloc.allocationSize = 0; |
| 8705 | mem_alloc.memoryTypeIndex = 0; |
| 8706 | vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs); |
| 8707 | mem_alloc.allocationSize = mem_reqs.size; |
| 8708 | pass = |
| 8709 | m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0); |
| 8710 | ASSERT_TRUE(pass); |
| 8711 | err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &image_mem); |
| 8712 | ASSERT_VK_SUCCESS(err); |
| 8713 | err = vkBindImageMemory(m_device->device(), image, image_mem, 0); |
| 8714 | ASSERT_VK_SUCCESS(err); |
| 8715 | // Now create view for image |
| 8716 | VkImageViewCreateInfo image_view_ci = {}; |
| 8717 | image_view_ci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO; |
| 8718 | image_view_ci.image = image; |
| 8719 | image_view_ci.format = VK_FORMAT_R8G8B8A8_UNORM; |
| 8720 | image_view_ci.viewType = VK_IMAGE_VIEW_TYPE_2D; |
| 8721 | image_view_ci.subresourceRange.layerCount = 1; |
| 8722 | image_view_ci.subresourceRange.baseArrayLayer = 0; |
| 8723 | image_view_ci.subresourceRange.levelCount = 1; |
| 8724 | image_view_ci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; |
| 8725 | VkImageView image_view; |
| 8726 | err = vkCreateImageView(m_device->device(), &image_view_ci, NULL, |
| 8727 | &image_view); |
| 8728 | ASSERT_VK_SUCCESS(err); |
| 8729 | |
| 8730 | VkDescriptorBufferInfo buff_info = {}; |
| 8731 | buff_info.buffer = buffer; |
| 8732 | VkDescriptorImageInfo img_info = {}; |
| 8733 | img_info.imageView = image_view; |
| 8734 | VkWriteDescriptorSet descriptor_write = {}; |
| 8735 | descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET; |
| 8736 | descriptor_write.dstBinding = 0; |
| 8737 | descriptor_write.descriptorCount = 1; |
| 8738 | descriptor_write.pTexelBufferView = &buff_view; |
| 8739 | descriptor_write.pBufferInfo = &buff_info; |
| 8740 | descriptor_write.pImageInfo = &img_info; |
| 8741 | |
| 8742 | // These error messages align with VkDescriptorType struct |
| 8743 | const char *error_msgs[] = { |
| 8744 | "", // placeholder, no error for SAMPLER descriptor |
| 8745 | " does not have VK_IMAGE_USAGE_SAMPLED_BIT set.", |
| 8746 | " does not have VK_IMAGE_USAGE_SAMPLED_BIT set.", |
| 8747 | " does not have VK_IMAGE_USAGE_STORAGE_BIT set.", |
| 8748 | " does not have VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT set.", |
| 8749 | " does not have VK_BUFFER_USAGE_STORAGE_TEXEL_BUFFER_BIT set.", |
| 8750 | " does not have VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT set.", |
| 8751 | " does not have VK_BUFFER_USAGE_STORAGE_BUFFER_BIT set.", |
| 8752 | " does not have VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT set.", |
| 8753 | " does not have VK_BUFFER_USAGE_STORAGE_BUFFER_BIT set.", |
| 8754 | " does not have VK_IMAGE_USAGE_INPUT_ATTACHMENT_BIT set."}; |
| 8755 | // Start loop at 1 as SAMPLER desc type has no usage bit error |
| 8756 | for (uint32_t i = 1; i < VK_DESCRIPTOR_TYPE_RANGE_SIZE; ++i) { |
| 8757 | descriptor_write.descriptorType = VkDescriptorType(i); |
| 8758 | descriptor_write.dstSet = descriptor_sets[i]; |
| 8759 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 8760 | error_msgs[i]); |
| 8761 | |
| 8762 | vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, |
| 8763 | NULL); |
| 8764 | |
| 8765 | m_errorMonitor->VerifyFound(); |
| 8766 | vkDestroyDescriptorSetLayout(m_device->device(), ds_layouts[i], NULL); |
| 8767 | } |
| 8768 | vkDestroyDescriptorSetLayout(m_device->device(), ds_layouts[0], NULL); |
| 8769 | vkDestroyImage(m_device->device(), image, NULL); |
Tony Barbour | df4c004 | 2016-06-01 15:55:43 -0600 | [diff] [blame] | 8770 | vkFreeMemory(m_device->device(), image_mem, NULL); |
Tobin Ehlis | 17826bd | 2016-05-25 11:12:50 -0600 | [diff] [blame] | 8771 | vkDestroyImageView(m_device->device(), image_view, NULL); |
| 8772 | vkDestroyBuffer(m_device->device(), buffer, NULL); |
| 8773 | vkDestroyBufferView(m_device->device(), buff_view, NULL); |
| 8774 | vkFreeDescriptorSets(m_device->device(), ds_pool, |
| 8775 | VK_DESCRIPTOR_TYPE_RANGE_SIZE, descriptor_sets); |
| 8776 | vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL); |
| 8777 | } |
| 8778 | |
Tobin Ehlis | 585f66d | 2016-07-01 18:23:58 -0600 | [diff] [blame] | 8779 | TEST_F(VkLayerTest, DSBufferInfoErrors) { |
| 8780 | TEST_DESCRIPTION( |
| 8781 | "Attempt to update buffer descriptor set that has incorrect " |
| 8782 | "parameters in VkDescriptorBufferInfo struct. This includes:\n" |
| 8783 | "1. offset value greater than buffer size\n" |
| 8784 | "2. range value of 0\n" |
| 8785 | "3. range value greater than buffer (size - offset)"); |
| 8786 | VkResult err; |
| 8787 | |
| 8788 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 8789 | VkDescriptorPoolSize ds_type_count = {}; |
| 8790 | ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 8791 | ds_type_count.descriptorCount = 1; |
| 8792 | |
| 8793 | VkDescriptorPoolCreateInfo ds_pool_ci = {}; |
| 8794 | ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO; |
| 8795 | ds_pool_ci.pNext = NULL; |
| 8796 | ds_pool_ci.maxSets = 1; |
| 8797 | ds_pool_ci.poolSizeCount = 1; |
| 8798 | ds_pool_ci.pPoolSizes = &ds_type_count; |
| 8799 | |
| 8800 | VkDescriptorPool ds_pool; |
| 8801 | err = |
| 8802 | vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool); |
| 8803 | ASSERT_VK_SUCCESS(err); |
| 8804 | |
| 8805 | // Create layout with single uniform buffer descriptor |
| 8806 | VkDescriptorSetLayoutBinding dsl_binding = {}; |
| 8807 | dsl_binding.binding = 0; |
| 8808 | dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 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 a buffer to be used for invalid updates |
| 8834 | VkBufferCreateInfo buff_ci = {}; |
| 8835 | buff_ci.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO; |
| 8836 | buff_ci.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT; |
| 8837 | buff_ci.size = 256; |
| 8838 | buff_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE; |
| 8839 | VkBuffer buffer; |
| 8840 | err = vkCreateBuffer(m_device->device(), &buff_ci, NULL, &buffer); |
| 8841 | ASSERT_VK_SUCCESS(err); |
| 8842 | // Have to bind memory to buffer before descriptor update |
| 8843 | VkMemoryAllocateInfo mem_alloc = {}; |
| 8844 | mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO; |
| 8845 | mem_alloc.pNext = NULL; |
| 8846 | mem_alloc.allocationSize = 256; |
| 8847 | mem_alloc.memoryTypeIndex = 0; |
| 8848 | |
| 8849 | VkMemoryRequirements mem_reqs; |
| 8850 | vkGetBufferMemoryRequirements(m_device->device(), buffer, &mem_reqs); |
| 8851 | bool pass = |
| 8852 | m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0); |
| 8853 | if (!pass) { |
| 8854 | vkDestroyBuffer(m_device->device(), buffer, NULL); |
| 8855 | return; |
| 8856 | } |
| 8857 | |
| 8858 | VkDeviceMemory mem; |
| 8859 | err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem); |
| 8860 | ASSERT_VK_SUCCESS(err); |
| 8861 | err = vkBindBufferMemory(m_device->device(), buffer, mem, 0); |
| 8862 | ASSERT_VK_SUCCESS(err); |
| 8863 | |
| 8864 | VkDescriptorBufferInfo buff_info = {}; |
| 8865 | buff_info.buffer = buffer; |
| 8866 | // First make offset 1 larger than buffer size |
| 8867 | buff_info.offset = 257; |
| 8868 | buff_info.range = VK_WHOLE_SIZE; |
| 8869 | VkWriteDescriptorSet descriptor_write = {}; |
| 8870 | descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET; |
| 8871 | descriptor_write.dstBinding = 0; |
| 8872 | descriptor_write.descriptorCount = 1; |
| 8873 | descriptor_write.pTexelBufferView = nullptr; |
| 8874 | descriptor_write.pBufferInfo = &buff_info; |
| 8875 | descriptor_write.pImageInfo = nullptr; |
| 8876 | |
| 8877 | descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 8878 | descriptor_write.dstSet = descriptor_set; |
| 8879 | m_errorMonitor->SetDesiredFailureMsg( |
| 8880 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 8881 | " offset of 257 is greater than buffer "); |
| 8882 | |
| 8883 | vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL); |
| 8884 | |
| 8885 | m_errorMonitor->VerifyFound(); |
| 8886 | // Now cause error due to range of 0 |
| 8887 | buff_info.offset = 0; |
| 8888 | buff_info.range = 0; |
| 8889 | m_errorMonitor->SetDesiredFailureMsg( |
| 8890 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 8891 | " range is not VK_WHOLE_SIZE and is zero, which is not allowed."); |
| 8892 | |
| 8893 | vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL); |
| 8894 | |
| 8895 | m_errorMonitor->VerifyFound(); |
| 8896 | // Now cause error due to range exceeding buffer size - offset |
| 8897 | buff_info.offset = 128; |
| 8898 | buff_info.range = 200; |
| 8899 | m_errorMonitor->SetDesiredFailureMsg( |
| 8900 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 8901 | " range is 200 which is greater than buffer size "); |
| 8902 | |
| 8903 | vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL); |
| 8904 | |
| 8905 | m_errorMonitor->VerifyFound(); |
Mark Lobodzinski | 4bb5409 | 2016-07-06 14:27:19 -0600 | [diff] [blame^] | 8906 | vkFreeMemory(m_device->device(), mem, NULL); |
Tobin Ehlis | 585f66d | 2016-07-01 18:23:58 -0600 | [diff] [blame] | 8907 | vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL); |
| 8908 | vkDestroyBuffer(m_device->device(), buffer, NULL); |
| 8909 | vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptor_set); |
| 8910 | vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL); |
| 8911 | } |
| 8912 | |
Tobin Ehlis | 2fc296b | 2016-06-15 14:05:27 -0600 | [diff] [blame] | 8913 | TEST_F(VkLayerTest, DSAspectBitsErrors) { |
| 8914 | // TODO : Initially only catching case where DEPTH & STENCIL aspect bits |
| 8915 | // are set, but could expand this test to hit more cases. |
| 8916 | TEST_DESCRIPTION("Attempt to update descriptor sets for images " |
| 8917 | "that do not have correct aspect bits sets."); |
| 8918 | VkResult err; |
| 8919 | |
| 8920 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 8921 | VkDescriptorPoolSize ds_type_count = {}; |
| 8922 | ds_type_count.type = VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT; |
| 8923 | ds_type_count.descriptorCount = 1; |
| 8924 | |
| 8925 | VkDescriptorPoolCreateInfo ds_pool_ci = {}; |
| 8926 | ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO; |
| 8927 | ds_pool_ci.pNext = NULL; |
| 8928 | ds_pool_ci.maxSets = 5; |
| 8929 | ds_pool_ci.poolSizeCount = 1; |
| 8930 | ds_pool_ci.pPoolSizes = &ds_type_count; |
| 8931 | |
| 8932 | VkDescriptorPool ds_pool; |
| 8933 | err = |
| 8934 | vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool); |
| 8935 | ASSERT_VK_SUCCESS(err); |
| 8936 | |
| 8937 | VkDescriptorSetLayoutBinding dsl_binding = {}; |
| 8938 | dsl_binding.binding = 0; |
| 8939 | dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT; |
| 8940 | dsl_binding.descriptorCount = 1; |
| 8941 | dsl_binding.stageFlags = VK_SHADER_STAGE_ALL; |
| 8942 | dsl_binding.pImmutableSamplers = NULL; |
| 8943 | |
| 8944 | VkDescriptorSetLayoutCreateInfo ds_layout_ci = {}; |
| 8945 | ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO; |
| 8946 | ds_layout_ci.pNext = NULL; |
| 8947 | ds_layout_ci.bindingCount = 1; |
| 8948 | ds_layout_ci.pBindings = &dsl_binding; |
| 8949 | VkDescriptorSetLayout ds_layout; |
| 8950 | err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, |
| 8951 | &ds_layout); |
| 8952 | ASSERT_VK_SUCCESS(err); |
| 8953 | |
| 8954 | VkDescriptorSet descriptor_set = {}; |
| 8955 | VkDescriptorSetAllocateInfo alloc_info = {}; |
| 8956 | alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO; |
| 8957 | alloc_info.descriptorSetCount = 1; |
| 8958 | alloc_info.descriptorPool = ds_pool; |
| 8959 | alloc_info.pSetLayouts = &ds_layout; |
| 8960 | err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, |
| 8961 | &descriptor_set); |
| 8962 | ASSERT_VK_SUCCESS(err); |
| 8963 | |
| 8964 | // Create an image to be used for invalid updates |
| 8965 | VkImageCreateInfo image_ci = {}; |
| 8966 | image_ci.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO; |
| 8967 | image_ci.imageType = VK_IMAGE_TYPE_2D; |
| 8968 | image_ci.format = VK_FORMAT_D24_UNORM_S8_UINT; |
| 8969 | image_ci.extent.width = 64; |
| 8970 | image_ci.extent.height = 64; |
| 8971 | image_ci.extent.depth = 1; |
| 8972 | image_ci.mipLevels = 1; |
| 8973 | image_ci.arrayLayers = 1; |
| 8974 | image_ci.samples = VK_SAMPLE_COUNT_1_BIT; |
| 8975 | image_ci.tiling = VK_IMAGE_TILING_LINEAR; |
| 8976 | image_ci.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED; |
| 8977 | image_ci.usage = VK_IMAGE_USAGE_SAMPLED_BIT; |
| 8978 | image_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE; |
| 8979 | VkImage image; |
| 8980 | err = vkCreateImage(m_device->device(), &image_ci, NULL, &image); |
| 8981 | ASSERT_VK_SUCCESS(err); |
| 8982 | // Bind memory to image |
| 8983 | VkMemoryRequirements mem_reqs; |
| 8984 | VkDeviceMemory image_mem; |
| 8985 | bool pass; |
| 8986 | VkMemoryAllocateInfo mem_alloc = {}; |
| 8987 | mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO; |
| 8988 | mem_alloc.pNext = NULL; |
| 8989 | mem_alloc.allocationSize = 0; |
| 8990 | mem_alloc.memoryTypeIndex = 0; |
| 8991 | vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs); |
| 8992 | mem_alloc.allocationSize = mem_reqs.size; |
| 8993 | pass = |
| 8994 | m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0); |
| 8995 | ASSERT_TRUE(pass); |
| 8996 | err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &image_mem); |
| 8997 | ASSERT_VK_SUCCESS(err); |
| 8998 | err = vkBindImageMemory(m_device->device(), image, image_mem, 0); |
| 8999 | ASSERT_VK_SUCCESS(err); |
| 9000 | // Now create view for image |
| 9001 | VkImageViewCreateInfo image_view_ci = {}; |
| 9002 | image_view_ci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO; |
| 9003 | image_view_ci.image = image; |
| 9004 | image_view_ci.format = VK_FORMAT_D24_UNORM_S8_UINT; |
| 9005 | image_view_ci.viewType = VK_IMAGE_VIEW_TYPE_2D; |
| 9006 | image_view_ci.subresourceRange.layerCount = 1; |
| 9007 | image_view_ci.subresourceRange.baseArrayLayer = 0; |
| 9008 | image_view_ci.subresourceRange.levelCount = 1; |
| 9009 | // Setting both depth & stencil aspect bits is illegal for descriptor |
| 9010 | image_view_ci.subresourceRange.aspectMask = |
| 9011 | VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT; |
| 9012 | |
| 9013 | VkImageView image_view; |
| 9014 | err = vkCreateImageView(m_device->device(), &image_view_ci, NULL, |
| 9015 | &image_view); |
| 9016 | ASSERT_VK_SUCCESS(err); |
| 9017 | |
| 9018 | VkDescriptorImageInfo img_info = {}; |
| 9019 | img_info.imageView = image_view; |
| 9020 | VkWriteDescriptorSet descriptor_write = {}; |
| 9021 | descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET; |
| 9022 | descriptor_write.dstBinding = 0; |
| 9023 | descriptor_write.descriptorCount = 1; |
| 9024 | descriptor_write.pTexelBufferView = NULL; |
| 9025 | descriptor_write.pBufferInfo = NULL; |
| 9026 | descriptor_write.pImageInfo = &img_info; |
| 9027 | descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT; |
| 9028 | descriptor_write.dstSet = descriptor_set; |
| 9029 | const char *error_msg = " please only set either VK_IMAGE_ASPECT_DEPTH_BIT " |
| 9030 | "or VK_IMAGE_ASPECT_STENCIL_BIT "; |
| 9031 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 9032 | error_msg); |
| 9033 | |
| 9034 | vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL); |
| 9035 | |
| 9036 | m_errorMonitor->VerifyFound(); |
| 9037 | vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL); |
| 9038 | vkDestroyImage(m_device->device(), image, NULL); |
| 9039 | vkFreeMemory(m_device->device(), image_mem, NULL); |
| 9040 | vkDestroyImageView(m_device->device(), image_view, NULL); |
| 9041 | vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptor_set); |
| 9042 | vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL); |
| 9043 | } |
| 9044 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9045 | TEST_F(VkLayerTest, DSTypeMismatch) { |
Tobin Ehlis | 49eb23d | 2015-05-22 12:38:55 -0600 | [diff] [blame] | 9046 | // 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] | 9047 | VkResult err; |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 9048 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9049 | m_errorMonitor->SetDesiredFailureMsg( |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 9050 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 9051 | " binding #0 with type VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER but update " |
| 9052 | "type is VK_DESCRIPTOR_TYPE_SAMPLER"); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 9053 | |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 9054 | ASSERT_NO_FATAL_FAILURE(InitState()); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9055 | // VkDescriptorSetObj descriptorSet(m_device); |
Chia-I Wu | 1b99bb2 | 2015-10-27 19:25:11 +0800 | [diff] [blame] | 9056 | VkDescriptorPoolSize ds_type_count = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9057 | ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 9058 | ds_type_count.descriptorCount = 1; |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 9059 | |
| 9060 | VkDescriptorPoolCreateInfo ds_pool_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9061 | ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO; |
| 9062 | ds_pool_ci.pNext = NULL; |
| 9063 | ds_pool_ci.maxSets = 1; |
| 9064 | ds_pool_ci.poolSizeCount = 1; |
| 9065 | ds_pool_ci.pPoolSizes = &ds_type_count; |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 9066 | |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 9067 | VkDescriptorPool ds_pool; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9068 | err = |
| 9069 | vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool); |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 9070 | ASSERT_VK_SUCCESS(err); |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 9071 | VkDescriptorSetLayoutBinding dsl_binding = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9072 | dsl_binding.binding = 0; |
| 9073 | dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 9074 | dsl_binding.descriptorCount = 1; |
| 9075 | dsl_binding.stageFlags = VK_SHADER_STAGE_ALL; |
| 9076 | dsl_binding.pImmutableSamplers = NULL; |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 9077 | |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 9078 | VkDescriptorSetLayoutCreateInfo ds_layout_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9079 | ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO; |
| 9080 | ds_layout_ci.pNext = NULL; |
| 9081 | ds_layout_ci.bindingCount = 1; |
| 9082 | ds_layout_ci.pBindings = &dsl_binding; |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 9083 | |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 9084 | VkDescriptorSetLayout ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9085 | err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, |
| 9086 | &ds_layout); |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 9087 | ASSERT_VK_SUCCESS(err); |
| 9088 | |
| 9089 | VkDescriptorSet descriptorSet; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 9090 | VkDescriptorSetAllocateInfo alloc_info = {}; |
Chia-I Wu | 00ce540 | 2015-11-10 16:21:09 +0800 | [diff] [blame] | 9091 | alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO; |
Jon Ashburn | f19916e | 2016-01-11 13:12:43 -0700 | [diff] [blame] | 9092 | alloc_info.descriptorSetCount = 1; |
Courtney Goeltzenleuchter | bee18a9 | 2015-10-23 14:21:05 -0600 | [diff] [blame] | 9093 | alloc_info.descriptorPool = ds_pool; |
| 9094 | alloc_info.pSetLayouts = &ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9095 | err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, |
| 9096 | &descriptorSet); |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 9097 | ASSERT_VK_SUCCESS(err); |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 9098 | |
Tobin Ehlis | 30db8f8 | 2016-05-05 08:19:48 -0600 | [diff] [blame] | 9099 | VkSamplerCreateInfo sampler_ci = {}; |
| 9100 | sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO; |
| 9101 | sampler_ci.pNext = NULL; |
| 9102 | sampler_ci.magFilter = VK_FILTER_NEAREST; |
| 9103 | sampler_ci.minFilter = VK_FILTER_NEAREST; |
| 9104 | sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST; |
| 9105 | sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE; |
| 9106 | sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE; |
| 9107 | sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE; |
| 9108 | sampler_ci.mipLodBias = 1.0; |
| 9109 | sampler_ci.anisotropyEnable = VK_FALSE; |
| 9110 | sampler_ci.maxAnisotropy = 1; |
| 9111 | sampler_ci.compareEnable = VK_FALSE; |
| 9112 | sampler_ci.compareOp = VK_COMPARE_OP_NEVER; |
| 9113 | sampler_ci.minLod = 1.0; |
| 9114 | sampler_ci.maxLod = 1.0; |
| 9115 | sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE; |
| 9116 | sampler_ci.unnormalizedCoordinates = VK_FALSE; |
| 9117 | VkSampler sampler; |
| 9118 | err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler); |
| 9119 | ASSERT_VK_SUCCESS(err); |
| 9120 | |
| 9121 | VkDescriptorImageInfo info = {}; |
| 9122 | info.sampler = sampler; |
Chia-I Wu | 9d00ed7 | 2015-05-25 16:27:55 +0800 | [diff] [blame] | 9123 | |
| 9124 | VkWriteDescriptorSet descriptor_write; |
| 9125 | memset(&descriptor_write, 0, sizeof(descriptor_write)); |
| 9126 | descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 9127 | descriptor_write.dstSet = descriptorSet; |
Chia-I Wu | d50a7d7 | 2015-10-26 20:48:51 +0800 | [diff] [blame] | 9128 | descriptor_write.descriptorCount = 1; |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 9129 | // This is a mismatched type for the layout which expects BUFFER |
Chia-I Wu | 9d00ed7 | 2015-05-25 16:27:55 +0800 | [diff] [blame] | 9130 | descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER; |
Courtney Goeltzenleuchter | 4cb6d92 | 2015-10-23 13:38:14 -0600 | [diff] [blame] | 9131 | descriptor_write.pImageInfo = &info; |
Chia-I Wu | 9d00ed7 | 2015-05-25 16:27:55 +0800 | [diff] [blame] | 9132 | |
| 9133 | vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL); |
| 9134 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 9135 | m_errorMonitor->VerifyFound(); |
Mike Stroyan | d1c84a5 | 2015-08-18 14:40:24 -0600 | [diff] [blame] | 9136 | |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 9137 | vkDestroySampler(m_device->device(), sampler, NULL); |
| 9138 | vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL); |
| 9139 | vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL); |
Tobin Ehlis | 49eb23d | 2015-05-22 12:38:55 -0600 | [diff] [blame] | 9140 | } |
| 9141 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9142 | TEST_F(VkLayerTest, DSUpdateOutOfBounds) { |
Tobin Ehlis | 49eb23d | 2015-05-22 12:38:55 -0600 | [diff] [blame] | 9143 | // For overlapping Update, have arrayIndex exceed that of layout |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9144 | VkResult err; |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 9145 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9146 | m_errorMonitor->SetDesiredFailureMsg( |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 9147 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 9148 | " binding #0 with 1 total descriptors but update of 1 descriptors " |
| 9149 | "starting at binding offset of 0 combined with update array element " |
| 9150 | "offset of 1 oversteps the size of this descriptor set."); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 9151 | |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 9152 | ASSERT_NO_FATAL_FAILURE(InitState()); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9153 | // VkDescriptorSetObj descriptorSet(m_device); |
Chia-I Wu | 1b99bb2 | 2015-10-27 19:25:11 +0800 | [diff] [blame] | 9154 | VkDescriptorPoolSize ds_type_count = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9155 | ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 9156 | ds_type_count.descriptorCount = 1; |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 9157 | |
| 9158 | VkDescriptorPoolCreateInfo ds_pool_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9159 | ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO; |
| 9160 | ds_pool_ci.pNext = NULL; |
| 9161 | ds_pool_ci.maxSets = 1; |
| 9162 | ds_pool_ci.poolSizeCount = 1; |
| 9163 | ds_pool_ci.pPoolSizes = &ds_type_count; |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 9164 | |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 9165 | VkDescriptorPool ds_pool; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9166 | err = |
| 9167 | vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool); |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 9168 | ASSERT_VK_SUCCESS(err); |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 9169 | |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 9170 | VkDescriptorSetLayoutBinding dsl_binding = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9171 | dsl_binding.binding = 0; |
| 9172 | dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 9173 | dsl_binding.descriptorCount = 1; |
| 9174 | dsl_binding.stageFlags = VK_SHADER_STAGE_ALL; |
| 9175 | dsl_binding.pImmutableSamplers = NULL; |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 9176 | |
| 9177 | VkDescriptorSetLayoutCreateInfo ds_layout_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9178 | ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO; |
| 9179 | ds_layout_ci.pNext = NULL; |
| 9180 | ds_layout_ci.bindingCount = 1; |
| 9181 | ds_layout_ci.pBindings = &dsl_binding; |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 9182 | |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 9183 | VkDescriptorSetLayout ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9184 | err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, |
| 9185 | &ds_layout); |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 9186 | ASSERT_VK_SUCCESS(err); |
| 9187 | |
| 9188 | VkDescriptorSet descriptorSet; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 9189 | VkDescriptorSetAllocateInfo alloc_info = {}; |
Chia-I Wu | 00ce540 | 2015-11-10 16:21:09 +0800 | [diff] [blame] | 9190 | alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO; |
Jon Ashburn | f19916e | 2016-01-11 13:12:43 -0700 | [diff] [blame] | 9191 | alloc_info.descriptorSetCount = 1; |
Courtney Goeltzenleuchter | bee18a9 | 2015-10-23 14:21:05 -0600 | [diff] [blame] | 9192 | alloc_info.descriptorPool = ds_pool; |
| 9193 | alloc_info.pSetLayouts = &ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9194 | err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, |
| 9195 | &descriptorSet); |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 9196 | ASSERT_VK_SUCCESS(err); |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 9197 | |
Tobin Ehlis | 30db8f8 | 2016-05-05 08:19:48 -0600 | [diff] [blame] | 9198 | // Correctly update descriptor to avoid "NOT_UPDATED" error |
| 9199 | VkDescriptorBufferInfo buff_info = {}; |
| 9200 | buff_info.buffer = |
| 9201 | VkBuffer(0); // Don't care about buffer handle for this test |
| 9202 | buff_info.offset = 0; |
| 9203 | buff_info.range = 1024; |
Chia-I Wu | 9d00ed7 | 2015-05-25 16:27:55 +0800 | [diff] [blame] | 9204 | |
| 9205 | VkWriteDescriptorSet descriptor_write; |
| 9206 | memset(&descriptor_write, 0, sizeof(descriptor_write)); |
| 9207 | descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 9208 | descriptor_write.dstSet = descriptorSet; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9209 | descriptor_write.dstArrayElement = |
| 9210 | 1; /* This index out of bounds for the update */ |
Chia-I Wu | d50a7d7 | 2015-10-26 20:48:51 +0800 | [diff] [blame] | 9211 | descriptor_write.descriptorCount = 1; |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 9212 | descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 9213 | descriptor_write.pBufferInfo = &buff_info; |
Chia-I Wu | 9d00ed7 | 2015-05-25 16:27:55 +0800 | [diff] [blame] | 9214 | |
| 9215 | vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL); |
| 9216 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 9217 | m_errorMonitor->VerifyFound(); |
Mike Stroyan | d1c84a5 | 2015-08-18 14:40:24 -0600 | [diff] [blame] | 9218 | |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 9219 | vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL); |
| 9220 | vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL); |
Tobin Ehlis | 49eb23d | 2015-05-22 12:38:55 -0600 | [diff] [blame] | 9221 | } |
| 9222 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9223 | TEST_F(VkLayerTest, InvalidDSUpdateIndex) { |
| 9224 | // Create layout w/ count of 1 and attempt update to that layout w/ binding |
| 9225 | // index 2 |
| 9226 | VkResult err; |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 9227 | |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 9228 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 9229 | " does not have binding 2."); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 9230 | |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 9231 | ASSERT_NO_FATAL_FAILURE(InitState()); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9232 | // VkDescriptorSetObj descriptorSet(m_device); |
Chia-I Wu | 1b99bb2 | 2015-10-27 19:25:11 +0800 | [diff] [blame] | 9233 | VkDescriptorPoolSize ds_type_count = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9234 | ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 9235 | ds_type_count.descriptorCount = 1; |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 9236 | |
| 9237 | VkDescriptorPoolCreateInfo ds_pool_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9238 | ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO; |
| 9239 | ds_pool_ci.pNext = NULL; |
| 9240 | ds_pool_ci.maxSets = 1; |
| 9241 | ds_pool_ci.poolSizeCount = 1; |
| 9242 | ds_pool_ci.pPoolSizes = &ds_type_count; |
Courtney Goeltzenleuchter | fe908d3 | 2015-09-16 16:12:45 -0600 | [diff] [blame] | 9243 | |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 9244 | VkDescriptorPool ds_pool; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9245 | err = |
| 9246 | vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool); |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 9247 | ASSERT_VK_SUCCESS(err); |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 9248 | |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 9249 | VkDescriptorSetLayoutBinding dsl_binding = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9250 | dsl_binding.binding = 0; |
| 9251 | dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 9252 | dsl_binding.descriptorCount = 1; |
| 9253 | dsl_binding.stageFlags = VK_SHADER_STAGE_ALL; |
| 9254 | dsl_binding.pImmutableSamplers = NULL; |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 9255 | |
| 9256 | VkDescriptorSetLayoutCreateInfo ds_layout_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9257 | ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO; |
| 9258 | ds_layout_ci.pNext = NULL; |
| 9259 | ds_layout_ci.bindingCount = 1; |
| 9260 | ds_layout_ci.pBindings = &dsl_binding; |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 9261 | VkDescriptorSetLayout ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9262 | err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, |
| 9263 | &ds_layout); |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 9264 | ASSERT_VK_SUCCESS(err); |
| 9265 | |
| 9266 | VkDescriptorSet descriptorSet; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 9267 | VkDescriptorSetAllocateInfo alloc_info = {}; |
Chia-I Wu | 00ce540 | 2015-11-10 16:21:09 +0800 | [diff] [blame] | 9268 | alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO; |
Jon Ashburn | f19916e | 2016-01-11 13:12:43 -0700 | [diff] [blame] | 9269 | alloc_info.descriptorSetCount = 1; |
Courtney Goeltzenleuchter | bee18a9 | 2015-10-23 14:21:05 -0600 | [diff] [blame] | 9270 | alloc_info.descriptorPool = ds_pool; |
| 9271 | alloc_info.pSetLayouts = &ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9272 | err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, |
| 9273 | &descriptorSet); |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 9274 | ASSERT_VK_SUCCESS(err); |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 9275 | |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 9276 | VkSamplerCreateInfo sampler_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9277 | sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO; |
| 9278 | sampler_ci.pNext = NULL; |
| 9279 | sampler_ci.magFilter = VK_FILTER_NEAREST; |
| 9280 | sampler_ci.minFilter = VK_FILTER_NEAREST; |
| 9281 | sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST; |
| 9282 | sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE; |
| 9283 | sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE; |
| 9284 | sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE; |
| 9285 | sampler_ci.mipLodBias = 1.0; |
| 9286 | sampler_ci.anisotropyEnable = VK_FALSE; |
| 9287 | sampler_ci.maxAnisotropy = 1; |
| 9288 | sampler_ci.compareEnable = VK_FALSE; |
| 9289 | sampler_ci.compareOp = VK_COMPARE_OP_NEVER; |
| 9290 | sampler_ci.minLod = 1.0; |
| 9291 | sampler_ci.maxLod = 1.0; |
| 9292 | sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE; |
| 9293 | sampler_ci.unnormalizedCoordinates = VK_FALSE; |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 9294 | |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 9295 | VkSampler sampler; |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 9296 | err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler); |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 9297 | ASSERT_VK_SUCCESS(err); |
Chia-I Wu | 9d00ed7 | 2015-05-25 16:27:55 +0800 | [diff] [blame] | 9298 | |
Courtney Goeltzenleuchter | 4cb6d92 | 2015-10-23 13:38:14 -0600 | [diff] [blame] | 9299 | VkDescriptorImageInfo info = {}; |
| 9300 | info.sampler = sampler; |
Chia-I Wu | 9d00ed7 | 2015-05-25 16:27:55 +0800 | [diff] [blame] | 9301 | |
| 9302 | VkWriteDescriptorSet descriptor_write; |
| 9303 | memset(&descriptor_write, 0, sizeof(descriptor_write)); |
| 9304 | descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 9305 | descriptor_write.dstSet = descriptorSet; |
| 9306 | descriptor_write.dstBinding = 2; |
Chia-I Wu | d50a7d7 | 2015-10-26 20:48:51 +0800 | [diff] [blame] | 9307 | descriptor_write.descriptorCount = 1; |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 9308 | // 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] | 9309 | descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER; |
Courtney Goeltzenleuchter | 4cb6d92 | 2015-10-23 13:38:14 -0600 | [diff] [blame] | 9310 | descriptor_write.pImageInfo = &info; |
Chia-I Wu | 9d00ed7 | 2015-05-25 16:27:55 +0800 | [diff] [blame] | 9311 | |
| 9312 | vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL); |
| 9313 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 9314 | m_errorMonitor->VerifyFound(); |
Mike Stroyan | d1c84a5 | 2015-08-18 14:40:24 -0600 | [diff] [blame] | 9315 | |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 9316 | vkDestroySampler(m_device->device(), sampler, NULL); |
| 9317 | vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL); |
| 9318 | vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL); |
Tobin Ehlis | 49eb23d | 2015-05-22 12:38:55 -0600 | [diff] [blame] | 9319 | } |
| 9320 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9321 | TEST_F(VkLayerTest, InvalidDSUpdateStruct) { |
| 9322 | // Call UpdateDS w/ struct type other than valid VK_STRUCTUR_TYPE_UPDATE_* |
| 9323 | // types |
| 9324 | VkResult err; |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 9325 | |
Courtney Goeltzenleuchter | 7415d5a | 2015-12-09 15:48:16 -0700 | [diff] [blame] | 9326 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Tobin Ehlis | 660bcdc | 2016-05-17 10:39:46 -0600 | [diff] [blame] | 9327 | ".sType must be VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET"); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 9328 | |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 9329 | ASSERT_NO_FATAL_FAILURE(InitState()); |
Mark Lobodzinski | 209b529 | 2015-09-17 09:44:05 -0600 | [diff] [blame] | 9330 | |
Chia-I Wu | 1b99bb2 | 2015-10-27 19:25:11 +0800 | [diff] [blame] | 9331 | VkDescriptorPoolSize ds_type_count = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9332 | ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 9333 | ds_type_count.descriptorCount = 1; |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 9334 | |
| 9335 | VkDescriptorPoolCreateInfo ds_pool_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9336 | ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO; |
| 9337 | ds_pool_ci.pNext = NULL; |
| 9338 | ds_pool_ci.maxSets = 1; |
| 9339 | ds_pool_ci.poolSizeCount = 1; |
| 9340 | ds_pool_ci.pPoolSizes = &ds_type_count; |
Courtney Goeltzenleuchter | fe908d3 | 2015-09-16 16:12:45 -0600 | [diff] [blame] | 9341 | |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 9342 | VkDescriptorPool ds_pool; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9343 | err = |
| 9344 | vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool); |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 9345 | ASSERT_VK_SUCCESS(err); |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 9346 | VkDescriptorSetLayoutBinding dsl_binding = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9347 | dsl_binding.binding = 0; |
| 9348 | dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 9349 | dsl_binding.descriptorCount = 1; |
| 9350 | dsl_binding.stageFlags = VK_SHADER_STAGE_ALL; |
| 9351 | dsl_binding.pImmutableSamplers = NULL; |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 9352 | |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 9353 | VkDescriptorSetLayoutCreateInfo ds_layout_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9354 | ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO; |
| 9355 | ds_layout_ci.pNext = NULL; |
| 9356 | ds_layout_ci.bindingCount = 1; |
| 9357 | ds_layout_ci.pBindings = &dsl_binding; |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 9358 | |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 9359 | VkDescriptorSetLayout ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9360 | err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, |
| 9361 | &ds_layout); |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 9362 | ASSERT_VK_SUCCESS(err); |
| 9363 | |
| 9364 | VkDescriptorSet descriptorSet; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 9365 | VkDescriptorSetAllocateInfo alloc_info = {}; |
Chia-I Wu | 00ce540 | 2015-11-10 16:21:09 +0800 | [diff] [blame] | 9366 | alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO; |
Jon Ashburn | f19916e | 2016-01-11 13:12:43 -0700 | [diff] [blame] | 9367 | alloc_info.descriptorSetCount = 1; |
Courtney Goeltzenleuchter | bee18a9 | 2015-10-23 14:21:05 -0600 | [diff] [blame] | 9368 | alloc_info.descriptorPool = ds_pool; |
| 9369 | alloc_info.pSetLayouts = &ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9370 | err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, |
| 9371 | &descriptorSet); |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 9372 | ASSERT_VK_SUCCESS(err); |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 9373 | |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 9374 | VkSamplerCreateInfo sampler_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9375 | sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO; |
| 9376 | sampler_ci.pNext = NULL; |
| 9377 | sampler_ci.magFilter = VK_FILTER_NEAREST; |
| 9378 | sampler_ci.minFilter = VK_FILTER_NEAREST; |
| 9379 | sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST; |
| 9380 | sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE; |
| 9381 | sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE; |
| 9382 | sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE; |
| 9383 | sampler_ci.mipLodBias = 1.0; |
| 9384 | sampler_ci.anisotropyEnable = VK_FALSE; |
| 9385 | sampler_ci.maxAnisotropy = 1; |
| 9386 | sampler_ci.compareEnable = VK_FALSE; |
| 9387 | sampler_ci.compareOp = VK_COMPARE_OP_NEVER; |
| 9388 | sampler_ci.minLod = 1.0; |
| 9389 | sampler_ci.maxLod = 1.0; |
| 9390 | sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE; |
| 9391 | sampler_ci.unnormalizedCoordinates = VK_FALSE; |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 9392 | VkSampler sampler; |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 9393 | err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler); |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 9394 | ASSERT_VK_SUCCESS(err); |
Chia-I Wu | 9d00ed7 | 2015-05-25 16:27:55 +0800 | [diff] [blame] | 9395 | |
Courtney Goeltzenleuchter | 4cb6d92 | 2015-10-23 13:38:14 -0600 | [diff] [blame] | 9396 | VkDescriptorImageInfo info = {}; |
| 9397 | info.sampler = sampler; |
Chia-I Wu | 9d00ed7 | 2015-05-25 16:27:55 +0800 | [diff] [blame] | 9398 | |
| 9399 | VkWriteDescriptorSet descriptor_write; |
| 9400 | memset(&descriptor_write, 0, sizeof(descriptor_write)); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9401 | descriptor_write.sType = |
| 9402 | (VkStructureType)0x99999999; /* Intentionally broken struct type */ |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 9403 | descriptor_write.dstSet = descriptorSet; |
Chia-I Wu | d50a7d7 | 2015-10-26 20:48:51 +0800 | [diff] [blame] | 9404 | descriptor_write.descriptorCount = 1; |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 9405 | // 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] | 9406 | descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER; |
Courtney Goeltzenleuchter | 4cb6d92 | 2015-10-23 13:38:14 -0600 | [diff] [blame] | 9407 | descriptor_write.pImageInfo = &info; |
Chia-I Wu | 9d00ed7 | 2015-05-25 16:27:55 +0800 | [diff] [blame] | 9408 | |
| 9409 | vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL); |
| 9410 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 9411 | m_errorMonitor->VerifyFound(); |
Mike Stroyan | d1c84a5 | 2015-08-18 14:40:24 -0600 | [diff] [blame] | 9412 | |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 9413 | vkDestroySampler(m_device->device(), sampler, NULL); |
| 9414 | vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL); |
| 9415 | vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL); |
Tobin Ehlis | 49eb23d | 2015-05-22 12:38:55 -0600 | [diff] [blame] | 9416 | } |
| 9417 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9418 | TEST_F(VkLayerTest, SampleDescriptorUpdateError) { |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 9419 | // Create a single Sampler descriptor and send it an invalid Sampler |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9420 | VkResult err; |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 9421 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9422 | m_errorMonitor->SetDesiredFailureMsg( |
| 9423 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 9424 | "Attempted write update to sampler descriptor with invalid sampler"); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 9425 | |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 9426 | ASSERT_NO_FATAL_FAILURE(InitState()); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9427 | // TODO : Farm Descriptor setup code to helper function(s) to reduce copied |
| 9428 | // code |
Chia-I Wu | 1b99bb2 | 2015-10-27 19:25:11 +0800 | [diff] [blame] | 9429 | VkDescriptorPoolSize ds_type_count = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9430 | ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLER; |
| 9431 | ds_type_count.descriptorCount = 1; |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 9432 | |
| 9433 | VkDescriptorPoolCreateInfo ds_pool_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9434 | ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO; |
| 9435 | ds_pool_ci.pNext = NULL; |
| 9436 | ds_pool_ci.maxSets = 1; |
| 9437 | ds_pool_ci.poolSizeCount = 1; |
| 9438 | ds_pool_ci.pPoolSizes = &ds_type_count; |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 9439 | |
| 9440 | VkDescriptorPool ds_pool; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9441 | err = |
| 9442 | vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool); |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 9443 | ASSERT_VK_SUCCESS(err); |
| 9444 | |
| 9445 | VkDescriptorSetLayoutBinding dsl_binding = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9446 | dsl_binding.binding = 0; |
| 9447 | dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER; |
| 9448 | dsl_binding.descriptorCount = 1; |
| 9449 | dsl_binding.stageFlags = VK_SHADER_STAGE_ALL; |
| 9450 | dsl_binding.pImmutableSamplers = NULL; |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 9451 | |
| 9452 | VkDescriptorSetLayoutCreateInfo ds_layout_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9453 | ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO; |
| 9454 | ds_layout_ci.pNext = NULL; |
| 9455 | ds_layout_ci.bindingCount = 1; |
| 9456 | ds_layout_ci.pBindings = &dsl_binding; |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 9457 | VkDescriptorSetLayout ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9458 | err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, |
| 9459 | &ds_layout); |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 9460 | ASSERT_VK_SUCCESS(err); |
| 9461 | |
| 9462 | VkDescriptorSet descriptorSet; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 9463 | VkDescriptorSetAllocateInfo alloc_info = {}; |
Chia-I Wu | 00ce540 | 2015-11-10 16:21:09 +0800 | [diff] [blame] | 9464 | alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO; |
Jon Ashburn | f19916e | 2016-01-11 13:12:43 -0700 | [diff] [blame] | 9465 | alloc_info.descriptorSetCount = 1; |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 9466 | alloc_info.descriptorPool = ds_pool; |
| 9467 | alloc_info.pSetLayouts = &ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9468 | err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, |
| 9469 | &descriptorSet); |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 9470 | ASSERT_VK_SUCCESS(err); |
| 9471 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9472 | VkSampler sampler = |
| 9473 | (VkSampler)((size_t)0xbaadbeef); // Sampler with invalid handle |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 9474 | |
| 9475 | VkDescriptorImageInfo descriptor_info; |
| 9476 | memset(&descriptor_info, 0, sizeof(VkDescriptorImageInfo)); |
| 9477 | descriptor_info.sampler = sampler; |
| 9478 | |
| 9479 | VkWriteDescriptorSet descriptor_write; |
| 9480 | memset(&descriptor_write, 0, sizeof(descriptor_write)); |
| 9481 | descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 9482 | descriptor_write.dstSet = descriptorSet; |
| 9483 | descriptor_write.dstBinding = 0; |
Chia-I Wu | d50a7d7 | 2015-10-26 20:48:51 +0800 | [diff] [blame] | 9484 | descriptor_write.descriptorCount = 1; |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 9485 | descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER; |
| 9486 | descriptor_write.pImageInfo = &descriptor_info; |
| 9487 | |
| 9488 | vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL); |
| 9489 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 9490 | m_errorMonitor->VerifyFound(); |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 9491 | |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 9492 | vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL); |
| 9493 | vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL); |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 9494 | } |
| 9495 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9496 | TEST_F(VkLayerTest, ImageViewDescriptorUpdateError) { |
| 9497 | // Create a single combined Image/Sampler descriptor and send it an invalid |
| 9498 | // imageView |
| 9499 | VkResult err; |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 9500 | |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 9501 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 9502 | "Attempted write update to combined " |
| 9503 | "image sampler descriptor failed due " |
Tobin Ehlis | 63c4b8a | 2016-05-09 10:29:34 -0600 | [diff] [blame] | 9504 | "to: Invalid VkImageView:"); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 9505 | |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 9506 | ASSERT_NO_FATAL_FAILURE(InitState()); |
Chia-I Wu | 1b99bb2 | 2015-10-27 19:25:11 +0800 | [diff] [blame] | 9507 | VkDescriptorPoolSize ds_type_count = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9508 | ds_type_count.type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER; |
| 9509 | ds_type_count.descriptorCount = 1; |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 9510 | |
| 9511 | VkDescriptorPoolCreateInfo ds_pool_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9512 | ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO; |
| 9513 | ds_pool_ci.pNext = NULL; |
| 9514 | ds_pool_ci.maxSets = 1; |
| 9515 | ds_pool_ci.poolSizeCount = 1; |
| 9516 | ds_pool_ci.pPoolSizes = &ds_type_count; |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 9517 | |
| 9518 | VkDescriptorPool ds_pool; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9519 | err = |
| 9520 | vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool); |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 9521 | ASSERT_VK_SUCCESS(err); |
| 9522 | |
| 9523 | VkDescriptorSetLayoutBinding dsl_binding = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9524 | dsl_binding.binding = 0; |
| 9525 | dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER; |
| 9526 | dsl_binding.descriptorCount = 1; |
| 9527 | dsl_binding.stageFlags = VK_SHADER_STAGE_ALL; |
| 9528 | dsl_binding.pImmutableSamplers = NULL; |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 9529 | |
| 9530 | VkDescriptorSetLayoutCreateInfo ds_layout_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9531 | ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO; |
| 9532 | ds_layout_ci.pNext = NULL; |
| 9533 | ds_layout_ci.bindingCount = 1; |
| 9534 | ds_layout_ci.pBindings = &dsl_binding; |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 9535 | VkDescriptorSetLayout ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9536 | err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, |
| 9537 | &ds_layout); |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 9538 | ASSERT_VK_SUCCESS(err); |
| 9539 | |
| 9540 | VkDescriptorSet descriptorSet; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 9541 | VkDescriptorSetAllocateInfo alloc_info = {}; |
Chia-I Wu | 00ce540 | 2015-11-10 16:21:09 +0800 | [diff] [blame] | 9542 | alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO; |
Jon Ashburn | f19916e | 2016-01-11 13:12:43 -0700 | [diff] [blame] | 9543 | alloc_info.descriptorSetCount = 1; |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 9544 | alloc_info.descriptorPool = ds_pool; |
| 9545 | alloc_info.pSetLayouts = &ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9546 | err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, |
| 9547 | &descriptorSet); |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 9548 | ASSERT_VK_SUCCESS(err); |
| 9549 | |
| 9550 | VkSamplerCreateInfo sampler_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9551 | sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO; |
| 9552 | sampler_ci.pNext = NULL; |
| 9553 | sampler_ci.magFilter = VK_FILTER_NEAREST; |
| 9554 | sampler_ci.minFilter = VK_FILTER_NEAREST; |
| 9555 | sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST; |
| 9556 | sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE; |
| 9557 | sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE; |
| 9558 | sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE; |
| 9559 | sampler_ci.mipLodBias = 1.0; |
| 9560 | sampler_ci.anisotropyEnable = VK_FALSE; |
| 9561 | sampler_ci.maxAnisotropy = 1; |
| 9562 | sampler_ci.compareEnable = VK_FALSE; |
| 9563 | sampler_ci.compareOp = VK_COMPARE_OP_NEVER; |
| 9564 | sampler_ci.minLod = 1.0; |
| 9565 | sampler_ci.maxLod = 1.0; |
| 9566 | sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE; |
| 9567 | sampler_ci.unnormalizedCoordinates = VK_FALSE; |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 9568 | |
| 9569 | VkSampler sampler; |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 9570 | err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler); |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 9571 | ASSERT_VK_SUCCESS(err); |
| 9572 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9573 | VkImageView view = |
| 9574 | (VkImageView)((size_t)0xbaadbeef); // invalid imageView object |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 9575 | |
| 9576 | VkDescriptorImageInfo descriptor_info; |
| 9577 | memset(&descriptor_info, 0, sizeof(VkDescriptorImageInfo)); |
| 9578 | descriptor_info.sampler = sampler; |
| 9579 | descriptor_info.imageView = view; |
| 9580 | |
| 9581 | VkWriteDescriptorSet descriptor_write; |
| 9582 | memset(&descriptor_write, 0, sizeof(descriptor_write)); |
| 9583 | descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 9584 | descriptor_write.dstSet = descriptorSet; |
| 9585 | descriptor_write.dstBinding = 0; |
Chia-I Wu | d50a7d7 | 2015-10-26 20:48:51 +0800 | [diff] [blame] | 9586 | descriptor_write.descriptorCount = 1; |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 9587 | descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER; |
| 9588 | descriptor_write.pImageInfo = &descriptor_info; |
| 9589 | |
| 9590 | vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL); |
| 9591 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 9592 | m_errorMonitor->VerifyFound(); |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 9593 | |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 9594 | vkDestroySampler(m_device->device(), sampler, NULL); |
| 9595 | vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL); |
| 9596 | vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL); |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 9597 | } |
| 9598 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9599 | TEST_F(VkLayerTest, CopyDescriptorUpdateErrors) { |
| 9600 | // Create DS w/ layout of 2 types, write update 1 and attempt to copy-update |
| 9601 | // into the other |
| 9602 | VkResult err; |
Tobin Ehlis | 04356f9 | 2015-10-27 16:35:27 -0600 | [diff] [blame] | 9603 | |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 9604 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 9605 | " binding #1 with type " |
| 9606 | "VK_DESCRIPTOR_TYPE_SAMPLER. Types do " |
| 9607 | "not match."); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 9608 | |
Tobin Ehlis | 04356f9 | 2015-10-27 16:35:27 -0600 | [diff] [blame] | 9609 | ASSERT_NO_FATAL_FAILURE(InitState()); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9610 | // VkDescriptorSetObj descriptorSet(m_device); |
Chia-I Wu | 1b99bb2 | 2015-10-27 19:25:11 +0800 | [diff] [blame] | 9611 | VkDescriptorPoolSize ds_type_count[2] = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9612 | ds_type_count[0].type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 9613 | ds_type_count[0].descriptorCount = 1; |
| 9614 | ds_type_count[1].type = VK_DESCRIPTOR_TYPE_SAMPLER; |
| 9615 | ds_type_count[1].descriptorCount = 1; |
Tobin Ehlis | 04356f9 | 2015-10-27 16:35:27 -0600 | [diff] [blame] | 9616 | |
| 9617 | VkDescriptorPoolCreateInfo ds_pool_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9618 | ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO; |
| 9619 | ds_pool_ci.pNext = NULL; |
| 9620 | ds_pool_ci.maxSets = 1; |
| 9621 | ds_pool_ci.poolSizeCount = 2; |
| 9622 | ds_pool_ci.pPoolSizes = ds_type_count; |
Tobin Ehlis | 04356f9 | 2015-10-27 16:35:27 -0600 | [diff] [blame] | 9623 | |
| 9624 | VkDescriptorPool ds_pool; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9625 | err = |
| 9626 | vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool); |
Tobin Ehlis | 04356f9 | 2015-10-27 16:35:27 -0600 | [diff] [blame] | 9627 | ASSERT_VK_SUCCESS(err); |
| 9628 | VkDescriptorSetLayoutBinding dsl_binding[2] = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9629 | dsl_binding[0].binding = 0; |
| 9630 | dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 9631 | dsl_binding[0].descriptorCount = 1; |
| 9632 | dsl_binding[0].stageFlags = VK_SHADER_STAGE_ALL; |
| 9633 | dsl_binding[0].pImmutableSamplers = NULL; |
| 9634 | dsl_binding[1].binding = 1; |
| 9635 | dsl_binding[1].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER; |
| 9636 | dsl_binding[1].descriptorCount = 1; |
| 9637 | dsl_binding[1].stageFlags = VK_SHADER_STAGE_ALL; |
| 9638 | dsl_binding[1].pImmutableSamplers = NULL; |
Tobin Ehlis | 04356f9 | 2015-10-27 16:35:27 -0600 | [diff] [blame] | 9639 | |
| 9640 | VkDescriptorSetLayoutCreateInfo ds_layout_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9641 | ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO; |
| 9642 | ds_layout_ci.pNext = NULL; |
| 9643 | ds_layout_ci.bindingCount = 2; |
| 9644 | ds_layout_ci.pBindings = dsl_binding; |
Tobin Ehlis | 04356f9 | 2015-10-27 16:35:27 -0600 | [diff] [blame] | 9645 | |
| 9646 | VkDescriptorSetLayout ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9647 | err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, |
| 9648 | &ds_layout); |
Tobin Ehlis | 04356f9 | 2015-10-27 16:35:27 -0600 | [diff] [blame] | 9649 | ASSERT_VK_SUCCESS(err); |
| 9650 | |
| 9651 | VkDescriptorSet descriptorSet; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 9652 | VkDescriptorSetAllocateInfo alloc_info = {}; |
Chia-I Wu | 00ce540 | 2015-11-10 16:21:09 +0800 | [diff] [blame] | 9653 | alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO; |
Jon Ashburn | f19916e | 2016-01-11 13:12:43 -0700 | [diff] [blame] | 9654 | alloc_info.descriptorSetCount = 1; |
Tobin Ehlis | 04356f9 | 2015-10-27 16:35:27 -0600 | [diff] [blame] | 9655 | alloc_info.descriptorPool = ds_pool; |
| 9656 | alloc_info.pSetLayouts = &ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9657 | err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, |
| 9658 | &descriptorSet); |
Tobin Ehlis | 04356f9 | 2015-10-27 16:35:27 -0600 | [diff] [blame] | 9659 | ASSERT_VK_SUCCESS(err); |
| 9660 | |
| 9661 | VkSamplerCreateInfo sampler_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9662 | sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO; |
| 9663 | sampler_ci.pNext = NULL; |
| 9664 | sampler_ci.magFilter = VK_FILTER_NEAREST; |
| 9665 | sampler_ci.minFilter = VK_FILTER_NEAREST; |
| 9666 | sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST; |
| 9667 | sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE; |
| 9668 | sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE; |
| 9669 | sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE; |
| 9670 | sampler_ci.mipLodBias = 1.0; |
| 9671 | sampler_ci.anisotropyEnable = VK_FALSE; |
| 9672 | sampler_ci.maxAnisotropy = 1; |
| 9673 | sampler_ci.compareEnable = VK_FALSE; |
| 9674 | sampler_ci.compareOp = VK_COMPARE_OP_NEVER; |
| 9675 | sampler_ci.minLod = 1.0; |
| 9676 | sampler_ci.maxLod = 1.0; |
| 9677 | sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE; |
| 9678 | sampler_ci.unnormalizedCoordinates = VK_FALSE; |
Tobin Ehlis | 04356f9 | 2015-10-27 16:35:27 -0600 | [diff] [blame] | 9679 | |
| 9680 | VkSampler sampler; |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 9681 | err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler); |
Tobin Ehlis | 04356f9 | 2015-10-27 16:35:27 -0600 | [diff] [blame] | 9682 | ASSERT_VK_SUCCESS(err); |
| 9683 | |
| 9684 | VkDescriptorImageInfo info = {}; |
| 9685 | info.sampler = sampler; |
| 9686 | |
| 9687 | VkWriteDescriptorSet descriptor_write; |
| 9688 | memset(&descriptor_write, 0, sizeof(VkWriteDescriptorSet)); |
| 9689 | descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 9690 | descriptor_write.dstSet = descriptorSet; |
| 9691 | descriptor_write.dstBinding = 1; // SAMPLER binding from layout above |
Chia-I Wu | d50a7d7 | 2015-10-26 20:48:51 +0800 | [diff] [blame] | 9692 | descriptor_write.descriptorCount = 1; |
Tobin Ehlis | 04356f9 | 2015-10-27 16:35:27 -0600 | [diff] [blame] | 9693 | descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER; |
| 9694 | descriptor_write.pImageInfo = &info; |
| 9695 | // This write update should succeed |
| 9696 | vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL); |
| 9697 | // Now perform a copy update that fails due to type mismatch |
| 9698 | VkCopyDescriptorSet copy_ds_update; |
| 9699 | memset(©_ds_update, 0, sizeof(VkCopyDescriptorSet)); |
| 9700 | copy_ds_update.sType = VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET; |
| 9701 | copy_ds_update.srcSet = descriptorSet; |
Mark Young | 2992748 | 2016-05-04 14:38:51 -0600 | [diff] [blame] | 9702 | copy_ds_update.srcBinding = 1; // Copy from SAMPLER binding |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 9703 | copy_ds_update.dstSet = descriptorSet; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9704 | copy_ds_update.dstBinding = 0; // ERROR : copy to UNIFORM binding |
Chia-I Wu | d50a7d7 | 2015-10-26 20:48:51 +0800 | [diff] [blame] | 9705 | copy_ds_update.descriptorCount = 1; // copy 1 descriptor |
Tobin Ehlis | 04356f9 | 2015-10-27 16:35:27 -0600 | [diff] [blame] | 9706 | vkUpdateDescriptorSets(m_device->device(), 0, NULL, 1, ©_ds_update); |
| 9707 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 9708 | m_errorMonitor->VerifyFound(); |
Tobin Ehlis | 04356f9 | 2015-10-27 16:35:27 -0600 | [diff] [blame] | 9709 | // 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] | 9710 | m_errorMonitor->SetDesiredFailureMsg( |
| 9711 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 9712 | " does not have copy update src binding of 3."); |
Tobin Ehlis | 04356f9 | 2015-10-27 16:35:27 -0600 | [diff] [blame] | 9713 | memset(©_ds_update, 0, sizeof(VkCopyDescriptorSet)); |
| 9714 | copy_ds_update.sType = VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET; |
| 9715 | copy_ds_update.srcSet = descriptorSet; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9716 | copy_ds_update.srcBinding = |
| 9717 | 3; // ERROR : Invalid binding for matching layout |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 9718 | copy_ds_update.dstSet = descriptorSet; |
| 9719 | copy_ds_update.dstBinding = 0; |
Mark Young | 2992748 | 2016-05-04 14:38:51 -0600 | [diff] [blame] | 9720 | copy_ds_update.descriptorCount = 1; // Copy 1 descriptor |
Tobin Ehlis | 04356f9 | 2015-10-27 16:35:27 -0600 | [diff] [blame] | 9721 | vkUpdateDescriptorSets(m_device->device(), 0, NULL, 1, ©_ds_update); |
| 9722 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 9723 | m_errorMonitor->VerifyFound(); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 9724 | |
Tobin Ehlis | 04356f9 | 2015-10-27 16:35:27 -0600 | [diff] [blame] | 9725 | // 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] | 9726 | m_errorMonitor->SetDesiredFailureMsg( |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 9727 | VK_DEBUG_REPORT_ERROR_BIT_EXT, " binding#1 with offset index of 1 plus " |
| 9728 | "update array offset of 0 and update of " |
| 9729 | "5 descriptors oversteps total number " |
| 9730 | "of descriptors in set: 2."); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 9731 | |
Tobin Ehlis | 04356f9 | 2015-10-27 16:35:27 -0600 | [diff] [blame] | 9732 | memset(©_ds_update, 0, sizeof(VkCopyDescriptorSet)); |
| 9733 | copy_ds_update.sType = VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET; |
| 9734 | copy_ds_update.srcSet = descriptorSet; |
| 9735 | copy_ds_update.srcBinding = 1; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 9736 | copy_ds_update.dstSet = descriptorSet; |
| 9737 | copy_ds_update.dstBinding = 0; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9738 | copy_ds_update.descriptorCount = |
| 9739 | 5; // ERROR copy 5 descriptors (out of bounds for layout) |
Tobin Ehlis | 04356f9 | 2015-10-27 16:35:27 -0600 | [diff] [blame] | 9740 | vkUpdateDescriptorSets(m_device->device(), 0, NULL, 1, ©_ds_update); |
| 9741 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 9742 | m_errorMonitor->VerifyFound(); |
Tobin Ehlis | 04356f9 | 2015-10-27 16:35:27 -0600 | [diff] [blame] | 9743 | |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 9744 | vkDestroySampler(m_device->device(), sampler, NULL); |
| 9745 | vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL); |
| 9746 | vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL); |
Tobin Ehlis | 04356f9 | 2015-10-27 16:35:27 -0600 | [diff] [blame] | 9747 | } |
| 9748 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9749 | TEST_F(VkLayerTest, NumSamplesMismatch) { |
| 9750 | // Create CommandBuffer where MSAA samples doesn't match RenderPass |
| 9751 | // sampleCount |
| 9752 | VkResult err; |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 9753 | |
Courtney Goeltzenleuchter | 7415d5a | 2015-12-09 15:48:16 -0700 | [diff] [blame] | 9754 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9755 | "Num samples mismatch! "); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 9756 | |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 9757 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 9758 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
Chia-I Wu | 1b99bb2 | 2015-10-27 19:25:11 +0800 | [diff] [blame] | 9759 | VkDescriptorPoolSize ds_type_count = {}; |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 9760 | ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
Chia-I Wu | d50a7d7 | 2015-10-26 20:48:51 +0800 | [diff] [blame] | 9761 | ds_type_count.descriptorCount = 1; |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 9762 | |
| 9763 | VkDescriptorPoolCreateInfo ds_pool_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9764 | ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO; |
| 9765 | ds_pool_ci.pNext = NULL; |
| 9766 | ds_pool_ci.maxSets = 1; |
| 9767 | ds_pool_ci.poolSizeCount = 1; |
| 9768 | ds_pool_ci.pPoolSizes = &ds_type_count; |
Courtney Goeltzenleuchter | fe908d3 | 2015-09-16 16:12:45 -0600 | [diff] [blame] | 9769 | |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 9770 | VkDescriptorPool ds_pool; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9771 | err = |
| 9772 | vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool); |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 9773 | ASSERT_VK_SUCCESS(err); |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 9774 | |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 9775 | VkDescriptorSetLayoutBinding dsl_binding = {}; |
Chia-I Wu | d46e6ae | 2015-10-31 00:31:16 +0800 | [diff] [blame] | 9776 | dsl_binding.binding = 0; |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 9777 | dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
Chia-I Wu | 0212448 | 2015-11-06 06:42:02 +0800 | [diff] [blame] | 9778 | dsl_binding.descriptorCount = 1; |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 9779 | dsl_binding.stageFlags = VK_SHADER_STAGE_ALL; |
| 9780 | dsl_binding.pImmutableSamplers = NULL; |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 9781 | |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 9782 | VkDescriptorSetLayoutCreateInfo ds_layout_ci = {}; |
| 9783 | ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO; |
| 9784 | ds_layout_ci.pNext = NULL; |
Chia-I Wu | d50a7d7 | 2015-10-26 20:48:51 +0800 | [diff] [blame] | 9785 | ds_layout_ci.bindingCount = 1; |
Jon Ashburn | 6e23c1f | 2015-12-30 18:01:16 -0700 | [diff] [blame] | 9786 | ds_layout_ci.pBindings = &dsl_binding; |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 9787 | |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 9788 | VkDescriptorSetLayout ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9789 | err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, |
| 9790 | &ds_layout); |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 9791 | ASSERT_VK_SUCCESS(err); |
| 9792 | |
| 9793 | VkDescriptorSet descriptorSet; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 9794 | VkDescriptorSetAllocateInfo alloc_info = {}; |
Chia-I Wu | 00ce540 | 2015-11-10 16:21:09 +0800 | [diff] [blame] | 9795 | alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO; |
Jon Ashburn | f19916e | 2016-01-11 13:12:43 -0700 | [diff] [blame] | 9796 | alloc_info.descriptorSetCount = 1; |
Courtney Goeltzenleuchter | bee18a9 | 2015-10-23 14:21:05 -0600 | [diff] [blame] | 9797 | alloc_info.descriptorPool = ds_pool; |
| 9798 | alloc_info.pSetLayouts = &ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9799 | err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, |
| 9800 | &descriptorSet); |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 9801 | ASSERT_VK_SUCCESS(err); |
| 9802 | |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 9803 | VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9804 | pipe_ms_state_ci.sType = |
| 9805 | VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO; |
| 9806 | pipe_ms_state_ci.pNext = NULL; |
| 9807 | pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_4_BIT; |
| 9808 | pipe_ms_state_ci.sampleShadingEnable = 0; |
| 9809 | pipe_ms_state_ci.minSampleShading = 1.0; |
| 9810 | pipe_ms_state_ci.pSampleMask = NULL; |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 9811 | |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 9812 | VkPipelineLayoutCreateInfo pipeline_layout_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9813 | pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO; |
| 9814 | pipeline_layout_ci.pNext = NULL; |
| 9815 | pipeline_layout_ci.setLayoutCount = 1; |
| 9816 | pipeline_layout_ci.pSetLayouts = &ds_layout; |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 9817 | |
| 9818 | VkPipelineLayout pipeline_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9819 | err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, |
| 9820 | &pipeline_layout); |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 9821 | ASSERT_VK_SUCCESS(err); |
| 9822 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9823 | VkShaderObj vs(m_device, bindStateVertShaderText, |
| 9824 | VK_SHADER_STAGE_VERTEX_BIT, this); |
| 9825 | VkShaderObj fs(m_device, bindStateFragShaderText, |
| 9826 | VK_SHADER_STAGE_FRAGMENT_BIT, |
Karl Schultz | bdb7595 | 2016-04-19 11:36:49 -0600 | [diff] [blame] | 9827 | this); // We shouldn't need a fragment shader |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9828 | // but add it to be able to run on more devices |
Tony Barbour | 62e1a5b | 2015-08-06 10:16:07 -0600 | [diff] [blame] | 9829 | VkPipelineObj pipe(m_device); |
| 9830 | pipe.AddShader(&vs); |
Tony Barbour | 1c94d37 | 2015-08-06 11:21:08 -0600 | [diff] [blame] | 9831 | pipe.AddShader(&fs); |
Mark Young | c89c631 | 2016-03-31 16:03:20 -0600 | [diff] [blame] | 9832 | pipe.AddColorAttachment(); |
Tony Barbour | 62e1a5b | 2015-08-06 10:16:07 -0600 | [diff] [blame] | 9833 | pipe.SetMSAA(&pipe_ms_state_ci); |
| 9834 | pipe.CreateVKPipeline(pipeline_layout, renderPass()); |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 9835 | |
Tony Barbour | fe3351b | 2015-07-28 10:17:20 -0600 | [diff] [blame] | 9836 | BeginCommandBuffer(); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9837 | vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), |
| 9838 | VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle()); |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 9839 | |
Mark Young | 2992748 | 2016-05-04 14:38:51 -0600 | [diff] [blame] | 9840 | // Render triangle (the error should trigger on the attempt to draw). |
| 9841 | Draw(3, 1, 0, 0); |
| 9842 | |
| 9843 | // Finalize recording of the command buffer |
| 9844 | EndCommandBuffer(); |
| 9845 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 9846 | m_errorMonitor->VerifyFound(); |
Mike Stroyan | d1c84a5 | 2015-08-18 14:40:24 -0600 | [diff] [blame] | 9847 | |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 9848 | vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL); |
| 9849 | vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL); |
| 9850 | vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL); |
Tobin Ehlis | 49eb23d | 2015-05-22 12:38:55 -0600 | [diff] [blame] | 9851 | } |
Mark Young | 2992748 | 2016-05-04 14:38:51 -0600 | [diff] [blame] | 9852 | |
Tobin Ehlis | 85aa15a | 2016-06-15 10:52:37 -0600 | [diff] [blame] | 9853 | TEST_F(VkLayerTest, RenderPassIncompatible) { |
| 9854 | TEST_DESCRIPTION("Hit RenderPass incompatible cases. " |
| 9855 | "Initial case is drawing with an active renderpass that's " |
| 9856 | "not compatible with the bound PSO's creation renderpass"); |
| 9857 | VkResult err; |
| 9858 | |
| 9859 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 9860 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 9861 | |
| 9862 | VkDescriptorSetLayoutBinding dsl_binding = {}; |
| 9863 | dsl_binding.binding = 0; |
| 9864 | dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 9865 | dsl_binding.descriptorCount = 1; |
| 9866 | dsl_binding.stageFlags = VK_SHADER_STAGE_ALL; |
| 9867 | dsl_binding.pImmutableSamplers = NULL; |
| 9868 | |
| 9869 | VkDescriptorSetLayoutCreateInfo ds_layout_ci = {}; |
| 9870 | ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO; |
| 9871 | ds_layout_ci.pNext = NULL; |
| 9872 | ds_layout_ci.bindingCount = 1; |
| 9873 | ds_layout_ci.pBindings = &dsl_binding; |
| 9874 | |
| 9875 | VkDescriptorSetLayout ds_layout; |
| 9876 | err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, |
| 9877 | &ds_layout); |
| 9878 | ASSERT_VK_SUCCESS(err); |
| 9879 | |
| 9880 | VkPipelineLayoutCreateInfo pipeline_layout_ci = {}; |
| 9881 | pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO; |
| 9882 | pipeline_layout_ci.pNext = NULL; |
| 9883 | pipeline_layout_ci.setLayoutCount = 1; |
| 9884 | pipeline_layout_ci.pSetLayouts = &ds_layout; |
| 9885 | |
| 9886 | VkPipelineLayout pipeline_layout; |
| 9887 | err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, |
| 9888 | &pipeline_layout); |
| 9889 | ASSERT_VK_SUCCESS(err); |
| 9890 | |
| 9891 | VkShaderObj vs(m_device, bindStateVertShaderText, |
| 9892 | VK_SHADER_STAGE_VERTEX_BIT, this); |
| 9893 | VkShaderObj fs(m_device, bindStateFragShaderText, |
| 9894 | VK_SHADER_STAGE_FRAGMENT_BIT, |
| 9895 | this); // We shouldn't need a fragment shader |
| 9896 | // but add it to be able to run on more devices |
| 9897 | // Create a renderpass that will be incompatible with default renderpass |
| 9898 | VkAttachmentReference attach = {}; |
| 9899 | attach.layout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL; |
| 9900 | VkAttachmentReference color_att = {}; |
| 9901 | color_att.layout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL; |
| 9902 | VkSubpassDescription subpass = {}; |
| 9903 | subpass.inputAttachmentCount = 1; |
| 9904 | subpass.pInputAttachments = &attach; |
| 9905 | subpass.colorAttachmentCount = 1; |
| 9906 | subpass.pColorAttachments = &color_att; |
| 9907 | VkRenderPassCreateInfo rpci = {}; |
| 9908 | rpci.subpassCount = 1; |
| 9909 | rpci.pSubpasses = &subpass; |
| 9910 | rpci.attachmentCount = 1; |
| 9911 | VkAttachmentDescription attach_desc = {}; |
| 9912 | attach_desc.samples = VK_SAMPLE_COUNT_1_BIT; |
Cody Northrop | bd16af1 | 2016-06-21 09:25:48 -0600 | [diff] [blame] | 9913 | // Format incompatible with PSO RP color attach format B8G8R8A8_UNORM |
| 9914 | attach_desc.format = VK_FORMAT_R8G8B8A8_UNORM; |
Tobin Ehlis | 85aa15a | 2016-06-15 10:52:37 -0600 | [diff] [blame] | 9915 | rpci.pAttachments = &attach_desc; |
| 9916 | rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO; |
| 9917 | VkRenderPass rp; |
| 9918 | vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp); |
| 9919 | VkPipelineObj pipe(m_device); |
| 9920 | pipe.AddShader(&vs); |
| 9921 | pipe.AddShader(&fs); |
| 9922 | pipe.AddColorAttachment(); |
| 9923 | VkViewport view_port = {}; |
| 9924 | m_viewports.push_back(view_port); |
| 9925 | pipe.SetViewport(m_viewports); |
| 9926 | VkRect2D rect = {}; |
| 9927 | m_scissors.push_back(rect); |
| 9928 | pipe.SetScissor(m_scissors); |
| 9929 | pipe.CreateVKPipeline(pipeline_layout, renderPass()); |
| 9930 | |
| 9931 | VkCommandBufferInheritanceInfo cbii = {}; |
| 9932 | cbii.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO; |
| 9933 | cbii.renderPass = rp; |
| 9934 | cbii.subpass = 0; |
| 9935 | VkCommandBufferBeginInfo cbbi = {}; |
| 9936 | cbbi.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO; |
| 9937 | cbbi.pInheritanceInfo = &cbii; |
| 9938 | vkBeginCommandBuffer(m_commandBuffer->handle(), &cbbi); |
| 9939 | VkRenderPassBeginInfo rpbi = {}; |
| 9940 | rpbi.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO; |
| 9941 | rpbi.framebuffer = m_framebuffer; |
| 9942 | rpbi.renderPass = rp; |
| 9943 | vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &rpbi, |
| 9944 | VK_SUBPASS_CONTENTS_INLINE); |
| 9945 | vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), |
| 9946 | VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle()); |
| 9947 | |
| 9948 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 9949 | " is incompatible w/ gfx pipeline "); |
| 9950 | // Render triangle (the error should trigger on the attempt to draw). |
| 9951 | Draw(3, 1, 0, 0); |
| 9952 | |
| 9953 | // Finalize recording of the command buffer |
| 9954 | EndCommandBuffer(); |
| 9955 | |
| 9956 | m_errorMonitor->VerifyFound(); |
| 9957 | |
| 9958 | vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL); |
| 9959 | vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL); |
| 9960 | vkDestroyRenderPass(m_device->device(), rp, NULL); |
| 9961 | } |
| 9962 | |
Mark Young | c89c631 | 2016-03-31 16:03:20 -0600 | [diff] [blame] | 9963 | TEST_F(VkLayerTest, NumBlendAttachMismatch) { |
| 9964 | // Create Pipeline where the number of blend attachments doesn't match the |
| 9965 | // number of color attachments. In this case, we don't add any color |
| 9966 | // blend attachments even though we have a color attachment. |
| 9967 | VkResult err; |
| 9968 | |
| 9969 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Mark Young | 2992748 | 2016-05-04 14:38:51 -0600 | [diff] [blame] | 9970 | "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] | 9971 | |
| 9972 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 9973 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 9974 | VkDescriptorPoolSize ds_type_count = {}; |
| 9975 | ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 9976 | ds_type_count.descriptorCount = 1; |
| 9977 | |
| 9978 | VkDescriptorPoolCreateInfo ds_pool_ci = {}; |
| 9979 | ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO; |
| 9980 | ds_pool_ci.pNext = NULL; |
| 9981 | ds_pool_ci.maxSets = 1; |
| 9982 | ds_pool_ci.poolSizeCount = 1; |
| 9983 | ds_pool_ci.pPoolSizes = &ds_type_count; |
| 9984 | |
| 9985 | VkDescriptorPool ds_pool; |
| 9986 | err = |
| 9987 | vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool); |
| 9988 | ASSERT_VK_SUCCESS(err); |
| 9989 | |
| 9990 | VkDescriptorSetLayoutBinding dsl_binding = {}; |
| 9991 | dsl_binding.binding = 0; |
| 9992 | dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 9993 | dsl_binding.descriptorCount = 1; |
| 9994 | dsl_binding.stageFlags = VK_SHADER_STAGE_ALL; |
| 9995 | dsl_binding.pImmutableSamplers = NULL; |
| 9996 | |
| 9997 | VkDescriptorSetLayoutCreateInfo ds_layout_ci = {}; |
| 9998 | ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO; |
| 9999 | ds_layout_ci.pNext = NULL; |
| 10000 | ds_layout_ci.bindingCount = 1; |
| 10001 | ds_layout_ci.pBindings = &dsl_binding; |
| 10002 | |
| 10003 | VkDescriptorSetLayout ds_layout; |
| 10004 | err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, |
| 10005 | &ds_layout); |
| 10006 | ASSERT_VK_SUCCESS(err); |
| 10007 | |
| 10008 | VkDescriptorSet descriptorSet; |
| 10009 | VkDescriptorSetAllocateInfo alloc_info = {}; |
| 10010 | alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO; |
| 10011 | alloc_info.descriptorSetCount = 1; |
| 10012 | alloc_info.descriptorPool = ds_pool; |
| 10013 | alloc_info.pSetLayouts = &ds_layout; |
| 10014 | err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, |
| 10015 | &descriptorSet); |
| 10016 | ASSERT_VK_SUCCESS(err); |
| 10017 | |
| 10018 | VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {}; |
| 10019 | pipe_ms_state_ci.sType = |
| 10020 | VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO; |
| 10021 | pipe_ms_state_ci.pNext = NULL; |
| 10022 | pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT; |
| 10023 | pipe_ms_state_ci.sampleShadingEnable = 0; |
| 10024 | pipe_ms_state_ci.minSampleShading = 1.0; |
| 10025 | pipe_ms_state_ci.pSampleMask = NULL; |
| 10026 | |
| 10027 | VkPipelineLayoutCreateInfo pipeline_layout_ci = {}; |
| 10028 | pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO; |
| 10029 | pipeline_layout_ci.pNext = NULL; |
| 10030 | pipeline_layout_ci.setLayoutCount = 1; |
| 10031 | pipeline_layout_ci.pSetLayouts = &ds_layout; |
| 10032 | |
| 10033 | VkPipelineLayout pipeline_layout; |
| 10034 | err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, |
| 10035 | &pipeline_layout); |
| 10036 | ASSERT_VK_SUCCESS(err); |
| 10037 | |
| 10038 | VkShaderObj vs(m_device, bindStateVertShaderText, |
| 10039 | VK_SHADER_STAGE_VERTEX_BIT, this); |
| 10040 | VkShaderObj fs(m_device, bindStateFragShaderText, |
| 10041 | VK_SHADER_STAGE_FRAGMENT_BIT, |
Karl Schultz | bdb7595 | 2016-04-19 11:36:49 -0600 | [diff] [blame] | 10042 | this); // We shouldn't need a fragment shader |
Mark Young | c89c631 | 2016-03-31 16:03:20 -0600 | [diff] [blame] | 10043 | // but add it to be able to run on more devices |
| 10044 | VkPipelineObj pipe(m_device); |
| 10045 | pipe.AddShader(&vs); |
| 10046 | pipe.AddShader(&fs); |
| 10047 | pipe.SetMSAA(&pipe_ms_state_ci); |
| 10048 | pipe.CreateVKPipeline(pipeline_layout, renderPass()); |
| 10049 | |
| 10050 | BeginCommandBuffer(); |
| 10051 | vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), |
| 10052 | VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle()); |
| 10053 | |
Mark Young | 2992748 | 2016-05-04 14:38:51 -0600 | [diff] [blame] | 10054 | // Render triangle (the error should trigger on the attempt to draw). |
| 10055 | Draw(3, 1, 0, 0); |
| 10056 | |
| 10057 | // Finalize recording of the command buffer |
| 10058 | EndCommandBuffer(); |
| 10059 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 10060 | m_errorMonitor->VerifyFound(); |
Mark Young | c89c631 | 2016-03-31 16:03:20 -0600 | [diff] [blame] | 10061 | |
| 10062 | vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL); |
| 10063 | vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL); |
| 10064 | vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL); |
| 10065 | } |
Mark Young | 2992748 | 2016-05-04 14:38:51 -0600 | [diff] [blame] | 10066 | |
Mark Mueller | d491441 | 2016-06-13 17:52:06 -0600 | [diff] [blame] | 10067 | TEST_F(VkLayerTest, MissingClearAttachment) { |
| 10068 | TEST_DESCRIPTION("Points to a wrong colorAttachment index in a VkClearAttachment " |
| 10069 | "structure passed to vkCmdClearAttachments"); |
| 10070 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 10071 | "vkCmdClearAttachments() attachment index 1 not found in attachment " |
| 10072 | "reference array of active subpass 0"); |
| 10073 | |
| 10074 | VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailCmdClearAttachments); |
| 10075 | m_errorMonitor->VerifyFound(); |
| 10076 | } |
| 10077 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 10078 | TEST_F(VkLayerTest, ClearCmdNoDraw) { |
| 10079 | // Create CommandBuffer where we add ClearCmd for FB Color attachment prior |
| 10080 | // to issuing a Draw |
| 10081 | VkResult err; |
Tobin Ehlis | 53eddda | 2015-07-01 16:46:13 -0600 | [diff] [blame] | 10082 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 10083 | m_errorMonitor->SetDesiredFailureMsg( |
Tony Barbour | 7e56d30 | 2016-03-02 15:12:01 -0700 | [diff] [blame] | 10084 | VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 10085 | "vkCmdClearAttachments() issued on CB object "); |
| 10086 | |
Tobin Ehlis | 53eddda | 2015-07-01 16:46:13 -0600 | [diff] [blame] | 10087 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 10088 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 10089 | |
Chia-I Wu | 1b99bb2 | 2015-10-27 19:25:11 +0800 | [diff] [blame] | 10090 | VkDescriptorPoolSize ds_type_count = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 10091 | ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 10092 | ds_type_count.descriptorCount = 1; |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 10093 | |
| 10094 | VkDescriptorPoolCreateInfo ds_pool_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 10095 | ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO; |
| 10096 | ds_pool_ci.pNext = NULL; |
| 10097 | ds_pool_ci.maxSets = 1; |
| 10098 | ds_pool_ci.poolSizeCount = 1; |
| 10099 | ds_pool_ci.pPoolSizes = &ds_type_count; |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 10100 | |
Tobin Ehlis | 53eddda | 2015-07-01 16:46:13 -0600 | [diff] [blame] | 10101 | VkDescriptorPool ds_pool; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 10102 | err = |
| 10103 | vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool); |
Tobin Ehlis | 53eddda | 2015-07-01 16:46:13 -0600 | [diff] [blame] | 10104 | ASSERT_VK_SUCCESS(err); |
| 10105 | |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 10106 | VkDescriptorSetLayoutBinding dsl_binding = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 10107 | dsl_binding.binding = 0; |
| 10108 | dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 10109 | dsl_binding.descriptorCount = 1; |
| 10110 | dsl_binding.stageFlags = VK_SHADER_STAGE_ALL; |
| 10111 | dsl_binding.pImmutableSamplers = NULL; |
Tobin Ehlis | 53eddda | 2015-07-01 16:46:13 -0600 | [diff] [blame] | 10112 | |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 10113 | VkDescriptorSetLayoutCreateInfo ds_layout_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 10114 | ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO; |
| 10115 | ds_layout_ci.pNext = NULL; |
| 10116 | ds_layout_ci.bindingCount = 1; |
| 10117 | ds_layout_ci.pBindings = &dsl_binding; |
Mark Lobodzinski | 209b529 | 2015-09-17 09:44:05 -0600 | [diff] [blame] | 10118 | |
Tobin Ehlis | 53eddda | 2015-07-01 16:46:13 -0600 | [diff] [blame] | 10119 | VkDescriptorSetLayout ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 10120 | err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, |
| 10121 | &ds_layout); |
Tobin Ehlis | 53eddda | 2015-07-01 16:46:13 -0600 | [diff] [blame] | 10122 | ASSERT_VK_SUCCESS(err); |
| 10123 | |
| 10124 | VkDescriptorSet descriptorSet; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 10125 | VkDescriptorSetAllocateInfo alloc_info = {}; |
Chia-I Wu | 00ce540 | 2015-11-10 16:21:09 +0800 | [diff] [blame] | 10126 | alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO; |
Jon Ashburn | f19916e | 2016-01-11 13:12:43 -0700 | [diff] [blame] | 10127 | alloc_info.descriptorSetCount = 1; |
Courtney Goeltzenleuchter | bee18a9 | 2015-10-23 14:21:05 -0600 | [diff] [blame] | 10128 | alloc_info.descriptorPool = ds_pool; |
| 10129 | alloc_info.pSetLayouts = &ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 10130 | err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, |
| 10131 | &descriptorSet); |
Tobin Ehlis | 53eddda | 2015-07-01 16:46:13 -0600 | [diff] [blame] | 10132 | ASSERT_VK_SUCCESS(err); |
| 10133 | |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 10134 | VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 10135 | pipe_ms_state_ci.sType = |
| 10136 | VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO; |
| 10137 | pipe_ms_state_ci.pNext = NULL; |
| 10138 | pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_4_BIT; |
| 10139 | pipe_ms_state_ci.sampleShadingEnable = 0; |
| 10140 | pipe_ms_state_ci.minSampleShading = 1.0; |
| 10141 | pipe_ms_state_ci.pSampleMask = NULL; |
Tobin Ehlis | 53eddda | 2015-07-01 16:46:13 -0600 | [diff] [blame] | 10142 | |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 10143 | VkPipelineLayoutCreateInfo pipeline_layout_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 10144 | pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO; |
| 10145 | pipeline_layout_ci.pNext = NULL; |
| 10146 | pipeline_layout_ci.setLayoutCount = 1; |
| 10147 | pipeline_layout_ci.pSetLayouts = &ds_layout; |
Tobin Ehlis | 53eddda | 2015-07-01 16:46:13 -0600 | [diff] [blame] | 10148 | |
| 10149 | VkPipelineLayout pipeline_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 10150 | err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, |
| 10151 | &pipeline_layout); |
Tobin Ehlis | 53eddda | 2015-07-01 16:46:13 -0600 | [diff] [blame] | 10152 | ASSERT_VK_SUCCESS(err); |
Mark Lobodzinski | 209b529 | 2015-09-17 09:44:05 -0600 | [diff] [blame] | 10153 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 10154 | VkShaderObj vs(m_device, bindStateVertShaderText, |
| 10155 | VK_SHADER_STAGE_VERTEX_BIT, this); |
Karl Schultz | bdb7595 | 2016-04-19 11:36:49 -0600 | [diff] [blame] | 10156 | // 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] | 10157 | // on more devices |
| 10158 | VkShaderObj fs(m_device, bindStateFragShaderText, |
| 10159 | VK_SHADER_STAGE_FRAGMENT_BIT, this); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 10160 | |
Tony Barbour | 62e1a5b | 2015-08-06 10:16:07 -0600 | [diff] [blame] | 10161 | VkPipelineObj pipe(m_device); |
| 10162 | pipe.AddShader(&vs); |
Tony Barbour | 1c94d37 | 2015-08-06 11:21:08 -0600 | [diff] [blame] | 10163 | pipe.AddShader(&fs); |
Tony Barbour | 62e1a5b | 2015-08-06 10:16:07 -0600 | [diff] [blame] | 10164 | pipe.SetMSAA(&pipe_ms_state_ci); |
| 10165 | pipe.CreateVKPipeline(pipeline_layout, renderPass()); |
Tony Barbour | fe3351b | 2015-07-28 10:17:20 -0600 | [diff] [blame] | 10166 | |
| 10167 | BeginCommandBuffer(); |
Tobin Ehlis | 53eddda | 2015-07-01 16:46:13 -0600 | [diff] [blame] | 10168 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 10169 | // Main thing we care about for this test is that the VkImage obj we're |
| 10170 | // clearing matches Color Attachment of FB |
Tobin Ehlis | 53eddda | 2015-07-01 16:46:13 -0600 | [diff] [blame] | 10171 | // Also pass down other dummy params to keep driver and paramchecker happy |
Courtney Goeltzenleuchter | c9323e0 | 2015-10-15 16:51:05 -0600 | [diff] [blame] | 10172 | VkClearAttachment color_attachment; |
| 10173 | color_attachment.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; |
| 10174 | color_attachment.clearValue.color.float32[0] = 1.0; |
| 10175 | color_attachment.clearValue.color.float32[1] = 1.0; |
| 10176 | color_attachment.clearValue.color.float32[2] = 1.0; |
| 10177 | color_attachment.clearValue.color.float32[3] = 1.0; |
| 10178 | color_attachment.colorAttachment = 0; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 10179 | VkClearRect clear_rect = { |
| 10180 | {{0, 0}, {(uint32_t)m_width, (uint32_t)m_height}}}; |
Tobin Ehlis | 53eddda | 2015-07-01 16:46:13 -0600 | [diff] [blame] | 10181 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 10182 | vkCmdClearAttachments(m_commandBuffer->GetBufferHandle(), 1, |
| 10183 | &color_attachment, 1, &clear_rect); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 10184 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 10185 | m_errorMonitor->VerifyFound(); |
Mike Stroyan | d1c84a5 | 2015-08-18 14:40:24 -0600 | [diff] [blame] | 10186 | |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 10187 | vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL); |
| 10188 | vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL); |
| 10189 | vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL); |
Tobin Ehlis | 53eddda | 2015-07-01 16:46:13 -0600 | [diff] [blame] | 10190 | } |
| 10191 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 10192 | TEST_F(VkLayerTest, VtxBufferBadIndex) { |
| 10193 | VkResult err; |
Tobin Ehlis | 502480b | 2015-06-24 15:53:07 -0600 | [diff] [blame] | 10194 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 10195 | m_errorMonitor->SetDesiredFailureMsg( |
Mark Lobodzinski | 510e20d | 2016-02-11 09:26:16 -0700 | [diff] [blame] | 10196 | VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, |
Mark Lobodzinski | dfcd9b6 | 2015-12-14 15:14:10 -0700 | [diff] [blame] | 10197 | "but no vertex buffers are attached to this Pipeline State Object"); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 10198 | |
Tobin Ehlis | 502480b | 2015-06-24 15:53:07 -0600 | [diff] [blame] | 10199 | ASSERT_NO_FATAL_FAILURE(InitState()); |
Tobin Ehlis | d332f28 | 2015-10-02 11:00:56 -0600 | [diff] [blame] | 10200 | ASSERT_NO_FATAL_FAILURE(InitViewport()); |
Tobin Ehlis | 502480b | 2015-06-24 15:53:07 -0600 | [diff] [blame] | 10201 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 10202 | |
Chia-I Wu | 1b99bb2 | 2015-10-27 19:25:11 +0800 | [diff] [blame] | 10203 | VkDescriptorPoolSize ds_type_count = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 10204 | ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 10205 | ds_type_count.descriptorCount = 1; |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 10206 | |
| 10207 | VkDescriptorPoolCreateInfo ds_pool_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 10208 | ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO; |
| 10209 | ds_pool_ci.pNext = NULL; |
| 10210 | ds_pool_ci.maxSets = 1; |
| 10211 | ds_pool_ci.poolSizeCount = 1; |
| 10212 | ds_pool_ci.pPoolSizes = &ds_type_count; |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 10213 | |
Courtney Goeltzenleuchter | fe908d3 | 2015-09-16 16:12:45 -0600 | [diff] [blame] | 10214 | VkDescriptorPool ds_pool; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 10215 | err = |
| 10216 | vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool); |
Tobin Ehlis | 502480b | 2015-06-24 15:53:07 -0600 | [diff] [blame] | 10217 | ASSERT_VK_SUCCESS(err); |
| 10218 | |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 10219 | VkDescriptorSetLayoutBinding dsl_binding = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 10220 | dsl_binding.binding = 0; |
| 10221 | dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 10222 | dsl_binding.descriptorCount = 1; |
| 10223 | dsl_binding.stageFlags = VK_SHADER_STAGE_ALL; |
| 10224 | dsl_binding.pImmutableSamplers = NULL; |
Tobin Ehlis | 502480b | 2015-06-24 15:53:07 -0600 | [diff] [blame] | 10225 | |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 10226 | VkDescriptorSetLayoutCreateInfo ds_layout_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 10227 | ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO; |
| 10228 | ds_layout_ci.pNext = NULL; |
| 10229 | ds_layout_ci.bindingCount = 1; |
| 10230 | ds_layout_ci.pBindings = &dsl_binding; |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 10231 | |
Tobin Ehlis | 502480b | 2015-06-24 15:53:07 -0600 | [diff] [blame] | 10232 | VkDescriptorSetLayout ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 10233 | err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, |
| 10234 | &ds_layout); |
Tobin Ehlis | 502480b | 2015-06-24 15:53:07 -0600 | [diff] [blame] | 10235 | ASSERT_VK_SUCCESS(err); |
| 10236 | |
| 10237 | VkDescriptorSet descriptorSet; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 10238 | VkDescriptorSetAllocateInfo alloc_info = {}; |
Chia-I Wu | 00ce540 | 2015-11-10 16:21:09 +0800 | [diff] [blame] | 10239 | alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO; |
Jon Ashburn | f19916e | 2016-01-11 13:12:43 -0700 | [diff] [blame] | 10240 | alloc_info.descriptorSetCount = 1; |
Courtney Goeltzenleuchter | bee18a9 | 2015-10-23 14:21:05 -0600 | [diff] [blame] | 10241 | alloc_info.descriptorPool = ds_pool; |
| 10242 | alloc_info.pSetLayouts = &ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 10243 | err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, |
| 10244 | &descriptorSet); |
Tobin Ehlis | 502480b | 2015-06-24 15:53:07 -0600 | [diff] [blame] | 10245 | ASSERT_VK_SUCCESS(err); |
| 10246 | |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 10247 | VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 10248 | pipe_ms_state_ci.sType = |
| 10249 | VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO; |
| 10250 | pipe_ms_state_ci.pNext = NULL; |
| 10251 | pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT; |
| 10252 | pipe_ms_state_ci.sampleShadingEnable = 0; |
| 10253 | pipe_ms_state_ci.minSampleShading = 1.0; |
| 10254 | pipe_ms_state_ci.pSampleMask = NULL; |
Tobin Ehlis | 502480b | 2015-06-24 15:53:07 -0600 | [diff] [blame] | 10255 | |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 10256 | VkPipelineLayoutCreateInfo pipeline_layout_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 10257 | pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO; |
| 10258 | pipeline_layout_ci.pNext = NULL; |
| 10259 | pipeline_layout_ci.setLayoutCount = 1; |
| 10260 | pipeline_layout_ci.pSetLayouts = &ds_layout; |
| 10261 | VkPipelineLayout pipeline_layout; |
Tobin Ehlis | 502480b | 2015-06-24 15:53:07 -0600 | [diff] [blame] | 10262 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 10263 | err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, |
| 10264 | &pipeline_layout); |
Tobin Ehlis | 502480b | 2015-06-24 15:53:07 -0600 | [diff] [blame] | 10265 | ASSERT_VK_SUCCESS(err); |
| 10266 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 10267 | VkShaderObj vs(m_device, bindStateVertShaderText, |
| 10268 | VK_SHADER_STAGE_VERTEX_BIT, this); |
| 10269 | VkShaderObj fs(m_device, bindStateFragShaderText, |
| 10270 | VK_SHADER_STAGE_FRAGMENT_BIT, |
Karl Schultz | bdb7595 | 2016-04-19 11:36:49 -0600 | [diff] [blame] | 10271 | this); // We shouldn't need a fragment shader |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 10272 | // but add it to be able to run on more devices |
Tony Barbour | 62e1a5b | 2015-08-06 10:16:07 -0600 | [diff] [blame] | 10273 | VkPipelineObj pipe(m_device); |
| 10274 | pipe.AddShader(&vs); |
Tony Barbour | 1c94d37 | 2015-08-06 11:21:08 -0600 | [diff] [blame] | 10275 | pipe.AddShader(&fs); |
Mark Young | c89c631 | 2016-03-31 16:03:20 -0600 | [diff] [blame] | 10276 | pipe.AddColorAttachment(); |
Tony Barbour | 62e1a5b | 2015-08-06 10:16:07 -0600 | [diff] [blame] | 10277 | pipe.SetMSAA(&pipe_ms_state_ci); |
Tobin Ehlis | d332f28 | 2015-10-02 11:00:56 -0600 | [diff] [blame] | 10278 | pipe.SetViewport(m_viewports); |
| 10279 | pipe.SetScissor(m_scissors); |
Tony Barbour | 62e1a5b | 2015-08-06 10:16:07 -0600 | [diff] [blame] | 10280 | pipe.CreateVKPipeline(pipeline_layout, renderPass()); |
Tony Barbour | fe3351b | 2015-07-28 10:17:20 -0600 | [diff] [blame] | 10281 | |
| 10282 | BeginCommandBuffer(); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 10283 | vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), |
| 10284 | VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle()); |
Tobin Ehlis | f7bf450 | 2015-09-09 15:12:35 -0600 | [diff] [blame] | 10285 | // Don't care about actual data, just need to get to draw to flag error |
| 10286 | static const float vbo_data[3] = {1.f, 0.f, 1.f}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 10287 | VkConstantBufferObj vbo(m_device, sizeof(vbo_data), sizeof(float), |
| 10288 | (const void *)&vbo_data); |
Tobin Ehlis | f7bf450 | 2015-09-09 15:12:35 -0600 | [diff] [blame] | 10289 | 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] | 10290 | Draw(1, 0, 0, 0); |
Tobin Ehlis | 502480b | 2015-06-24 15:53:07 -0600 | [diff] [blame] | 10291 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 10292 | m_errorMonitor->VerifyFound(); |
Mike Stroyan | d1c84a5 | 2015-08-18 14:40:24 -0600 | [diff] [blame] | 10293 | |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 10294 | vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL); |
| 10295 | vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL); |
| 10296 | vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL); |
Tobin Ehlis | 502480b | 2015-06-24 15:53:07 -0600 | [diff] [blame] | 10297 | } |
Tobin Ehlis | c555a3c | 2016-05-04 14:08:34 -0600 | [diff] [blame] | 10298 | // INVALID_IMAGE_LAYOUT tests (one other case is hit by MapMemWithoutHostVisibleBit and not here) |
| 10299 | TEST_F(VkLayerTest, InvalidImageLayout) { |
| 10300 | TEST_DESCRIPTION("Hit all possible validation checks associated with the " |
| 10301 | "DRAWSTATE_INVALID_IMAGE_LAYOUT enum. Generally these involve having" |
| 10302 | "images in the wrong layout when they're copied or transitioned."); |
| 10303 | // 3 in ValidateCmdBufImageLayouts |
| 10304 | // * -1 Attempt to submit cmd buf w/ deleted image |
| 10305 | // * -2 Cmd buf submit of image w/ layout not matching first use w/ subresource |
| 10306 | // * -3 Cmd buf submit of image w/ layout not matching first use w/o subresource |
| 10307 | m_errorMonitor->SetDesiredFailureMsg( |
| 10308 | VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, |
| 10309 | "Layout for input image should be TRANSFER_SRC_OPTIMAL instead of GENERAL."); |
| 10310 | |
| 10311 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 10312 | // Create src & dst images to use for copy operations |
| 10313 | VkImage src_image; |
| 10314 | VkImage dst_image; |
| 10315 | |
| 10316 | const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM; |
| 10317 | const int32_t tex_width = 32; |
| 10318 | const int32_t tex_height = 32; |
| 10319 | |
| 10320 | VkImageCreateInfo image_create_info = {}; |
| 10321 | image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO; |
| 10322 | image_create_info.pNext = NULL; |
| 10323 | image_create_info.imageType = VK_IMAGE_TYPE_2D; |
| 10324 | image_create_info.format = tex_format; |
| 10325 | image_create_info.extent.width = tex_width; |
| 10326 | image_create_info.extent.height = tex_height; |
| 10327 | image_create_info.extent.depth = 1; |
| 10328 | image_create_info.mipLevels = 1; |
| 10329 | image_create_info.arrayLayers = 4; |
| 10330 | image_create_info.samples = VK_SAMPLE_COUNT_1_BIT; |
| 10331 | image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL; |
| 10332 | image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT; |
| 10333 | image_create_info.flags = 0; |
| 10334 | |
| 10335 | VkResult err = vkCreateImage(m_device->device(), &image_create_info, NULL, &src_image); |
| 10336 | ASSERT_VK_SUCCESS(err); |
| 10337 | err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dst_image); |
| 10338 | ASSERT_VK_SUCCESS(err); |
| 10339 | |
| 10340 | BeginCommandBuffer(); |
| 10341 | VkImageCopy copyRegion; |
| 10342 | copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; |
| 10343 | copyRegion.srcSubresource.mipLevel = 0; |
| 10344 | copyRegion.srcSubresource.baseArrayLayer = 0; |
| 10345 | copyRegion.srcSubresource.layerCount = 1; |
| 10346 | copyRegion.srcOffset.x = 0; |
| 10347 | copyRegion.srcOffset.y = 0; |
| 10348 | copyRegion.srcOffset.z = 0; |
| 10349 | copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; |
| 10350 | copyRegion.dstSubresource.mipLevel = 0; |
| 10351 | copyRegion.dstSubresource.baseArrayLayer = 0; |
| 10352 | copyRegion.dstSubresource.layerCount = 1; |
| 10353 | copyRegion.dstOffset.x = 0; |
| 10354 | copyRegion.dstOffset.y = 0; |
| 10355 | copyRegion.dstOffset.z = 0; |
| 10356 | copyRegion.extent.width = 1; |
| 10357 | copyRegion.extent.height = 1; |
| 10358 | copyRegion.extent.depth = 1; |
| 10359 | m_commandBuffer->CopyImage(src_image, VK_IMAGE_LAYOUT_GENERAL, dst_image, VK_IMAGE_LAYOUT_GENERAL, 1, ©Region); |
| 10360 | m_errorMonitor->VerifyFound(); |
| 10361 | // Now cause error due to src image layout changing |
| 10362 | m_errorMonitor->SetDesiredFailureMsg( |
| 10363 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 10364 | "Cannot copy from an image whose source layout is VK_IMAGE_LAYOUT_UNDEFINED and doesn't match the current layout VK_IMAGE_LAYOUT_GENERAL."); |
| 10365 | m_commandBuffer->CopyImage(src_image, VK_IMAGE_LAYOUT_UNDEFINED, dst_image, VK_IMAGE_LAYOUT_GENERAL, 1, ©Region); |
| 10366 | m_errorMonitor->VerifyFound(); |
| 10367 | // Final src error is due to bad layout type |
| 10368 | m_errorMonitor->SetDesiredFailureMsg( |
| 10369 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 10370 | "Layout for input image is VK_IMAGE_LAYOUT_UNDEFINED but can only be TRANSFER_SRC_OPTIMAL or GENERAL."); |
| 10371 | m_commandBuffer->CopyImage(src_image, VK_IMAGE_LAYOUT_UNDEFINED, dst_image, VK_IMAGE_LAYOUT_GENERAL, 1, ©Region); |
| 10372 | m_errorMonitor->VerifyFound(); |
| 10373 | // Now verify same checks for dst |
| 10374 | m_errorMonitor->SetDesiredFailureMsg( |
| 10375 | VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, |
| 10376 | "Layout for output image should be TRANSFER_DST_OPTIMAL instead of GENERAL."); |
| 10377 | m_commandBuffer->CopyImage(src_image, VK_IMAGE_LAYOUT_GENERAL, dst_image, VK_IMAGE_LAYOUT_GENERAL, 1, ©Region); |
| 10378 | m_errorMonitor->VerifyFound(); |
| 10379 | // Now cause error due to src image layout changing |
| 10380 | m_errorMonitor->SetDesiredFailureMsg( |
| 10381 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 10382 | "Cannot copy from an image whose dest layout is VK_IMAGE_LAYOUT_UNDEFINED and doesn't match the current layout VK_IMAGE_LAYOUT_GENERAL."); |
| 10383 | m_commandBuffer->CopyImage(src_image, VK_IMAGE_LAYOUT_GENERAL, dst_image, VK_IMAGE_LAYOUT_UNDEFINED, 1, ©Region); |
| 10384 | m_errorMonitor->VerifyFound(); |
| 10385 | m_errorMonitor->SetDesiredFailureMsg( |
| 10386 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 10387 | "Layout for output image is VK_IMAGE_LAYOUT_UNDEFINED but can only be TRANSFER_DST_OPTIMAL or GENERAL."); |
| 10388 | m_commandBuffer->CopyImage(src_image, VK_IMAGE_LAYOUT_GENERAL, dst_image, VK_IMAGE_LAYOUT_UNDEFINED, 1, ©Region); |
| 10389 | m_errorMonitor->VerifyFound(); |
| 10390 | // Now cause error due to bad image layout transition in PipelineBarrier |
| 10391 | VkImageMemoryBarrier image_barrier[1] = {}; |
| 10392 | image_barrier[0].oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL; |
| 10393 | image_barrier[0].image = src_image; |
| 10394 | image_barrier[0].subresourceRange.layerCount = 2; |
| 10395 | image_barrier[0].subresourceRange.levelCount = 2; |
| 10396 | image_barrier[0].subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; |
| 10397 | m_errorMonitor->SetDesiredFailureMsg( |
| 10398 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 10399 | "You cannot transition the layout from VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL when current layout is VK_IMAGE_LAYOUT_GENERAL."); |
| 10400 | vkCmdPipelineBarrier(m_commandBuffer->handle(), VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, NULL, 0, NULL, 1, image_barrier); |
| 10401 | m_errorMonitor->VerifyFound(); |
| 10402 | |
| 10403 | // Finally some layout errors at RenderPass create time |
| 10404 | // Just hacking in specific state to get to the errors we want so don't copy this unless you know what you're doing. |
| 10405 | VkAttachmentReference attach = {}; |
| 10406 | // perf warning for GENERAL layout w/ non-DS input attachment |
| 10407 | attach.layout = VK_IMAGE_LAYOUT_GENERAL; |
| 10408 | VkSubpassDescription subpass = {}; |
| 10409 | subpass.inputAttachmentCount = 1; |
| 10410 | subpass.pInputAttachments = &attach; |
| 10411 | VkRenderPassCreateInfo rpci = {}; |
| 10412 | rpci.subpassCount = 1; |
| 10413 | rpci.pSubpasses = &subpass; |
| 10414 | rpci.attachmentCount = 1; |
| 10415 | VkAttachmentDescription attach_desc = {}; |
| 10416 | attach_desc.format = VK_FORMAT_UNDEFINED; |
| 10417 | rpci.pAttachments = &attach_desc; |
Tobin Ehlis | 1efce02 | 2016-05-11 10:40:34 -0600 | [diff] [blame] | 10418 | rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO; |
Tobin Ehlis | c555a3c | 2016-05-04 14:08:34 -0600 | [diff] [blame] | 10419 | VkRenderPass rp; |
| 10420 | m_errorMonitor->SetDesiredFailureMsg( |
| 10421 | VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, |
| 10422 | "Layout for input attachment is GENERAL but should be READ_ONLY_OPTIMAL."); |
| 10423 | vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp); |
| 10424 | m_errorMonitor->VerifyFound(); |
| 10425 | // error w/ non-general layout |
| 10426 | attach.layout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL; |
| 10427 | |
| 10428 | m_errorMonitor->SetDesiredFailureMsg( |
| 10429 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 10430 | "Layout for input attachment is VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL but can only be READ_ONLY_OPTIMAL or GENERAL."); |
| 10431 | vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp); |
| 10432 | m_errorMonitor->VerifyFound(); |
| 10433 | subpass.inputAttachmentCount = 0; |
| 10434 | subpass.colorAttachmentCount = 1; |
| 10435 | subpass.pColorAttachments = &attach; |
| 10436 | attach.layout = VK_IMAGE_LAYOUT_GENERAL; |
| 10437 | // perf warning for GENERAL layout on color attachment |
| 10438 | m_errorMonitor->SetDesiredFailureMsg( |
| 10439 | VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, |
| 10440 | "Layout for color attachment is GENERAL but should be COLOR_ATTACHMENT_OPTIMAL."); |
| 10441 | vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp); |
| 10442 | m_errorMonitor->VerifyFound(); |
| 10443 | // error w/ non-color opt or GENERAL layout for color attachment |
| 10444 | attach.layout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL; |
| 10445 | m_errorMonitor->SetDesiredFailureMsg( |
| 10446 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 10447 | "Layout for color attachment is VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL but can only be COLOR_ATTACHMENT_OPTIMAL or GENERAL."); |
| 10448 | vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp); |
| 10449 | m_errorMonitor->VerifyFound(); |
| 10450 | subpass.colorAttachmentCount = 0; |
| 10451 | subpass.pDepthStencilAttachment = &attach; |
| 10452 | attach.layout = VK_IMAGE_LAYOUT_GENERAL; |
| 10453 | // perf warning for GENERAL layout on DS attachment |
| 10454 | m_errorMonitor->SetDesiredFailureMsg( |
| 10455 | VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, |
| 10456 | "Layout for depth attachment is GENERAL but should be DEPTH_STENCIL_ATTACHMENT_OPTIMAL."); |
| 10457 | vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp); |
| 10458 | m_errorMonitor->VerifyFound(); |
| 10459 | // error w/ non-ds opt or GENERAL layout for color attachment |
| 10460 | attach.layout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL; |
| 10461 | m_errorMonitor->SetDesiredFailureMsg( |
| 10462 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 10463 | "Layout for depth attachment is VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL but can only be DEPTH_STENCIL_ATTACHMENT_OPTIMAL or GENERAL."); |
| 10464 | vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp); |
| 10465 | m_errorMonitor->VerifyFound(); |
Tobin Ehlis | 1efce02 | 2016-05-11 10:40:34 -0600 | [diff] [blame] | 10466 | // For this error we need a valid renderpass so create default one |
| 10467 | attach.layout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL; |
| 10468 | attach.attachment = 0; |
| 10469 | attach_desc.format = VK_FORMAT_D24_UNORM_S8_UINT; |
| 10470 | attach_desc.samples = VK_SAMPLE_COUNT_1_BIT; |
| 10471 | attach_desc.storeOp = VK_ATTACHMENT_STORE_OP_STORE; |
| 10472 | attach_desc.stencilLoadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE; |
| 10473 | attach_desc.stencilStoreOp = VK_ATTACHMENT_STORE_OP_DONT_CARE; |
| 10474 | // Can't do a CLEAR load on READ_ONLY initialLayout |
| 10475 | attach_desc.loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR; |
| 10476 | attach_desc.initialLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL; |
| 10477 | attach_desc.finalLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL; |
| 10478 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 10479 | " with invalid first layout " |
| 10480 | "VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_" |
| 10481 | "ONLY_OPTIMAL"); |
| 10482 | vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp); |
| 10483 | m_errorMonitor->VerifyFound(); |
Tobin Ehlis | c555a3c | 2016-05-04 14:08:34 -0600 | [diff] [blame] | 10484 | |
| 10485 | vkDestroyImage(m_device->device(), src_image, NULL); |
| 10486 | vkDestroyImage(m_device->device(), dst_image, NULL); |
| 10487 | } |
Mark Lobodzinski | 209b529 | 2015-09-17 09:44:05 -0600 | [diff] [blame] | 10488 | #endif // DRAW_STATE_TESTS |
| 10489 | |
Tobin Ehlis | 0788f52 | 2015-05-26 16:11:58 -0600 | [diff] [blame] | 10490 | #if THREADING_TESTS |
Mike Stroyan | accf769 | 2015-05-12 16:00:45 -0600 | [diff] [blame] | 10491 | #if GTEST_IS_THREADSAFE |
| 10492 | struct thread_data_struct { |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 10493 | VkCommandBuffer commandBuffer; |
Mike Stroyan | accf769 | 2015-05-12 16:00:45 -0600 | [diff] [blame] | 10494 | VkEvent event; |
| 10495 | bool bailout; |
| 10496 | }; |
| 10497 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 10498 | extern "C" void *AddToCommandBuffer(void *arg) { |
| 10499 | struct thread_data_struct *data = (struct thread_data_struct *)arg; |
Mike Stroyan | accf769 | 2015-05-12 16:00:45 -0600 | [diff] [blame] | 10500 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 10501 | for (int i = 0; i < 10000; i++) { |
| 10502 | vkCmdSetEvent(data->commandBuffer, data->event, |
| 10503 | VK_PIPELINE_STAGE_ALL_COMMANDS_BIT); |
Mike Stroyan | accf769 | 2015-05-12 16:00:45 -0600 | [diff] [blame] | 10504 | if (data->bailout) { |
| 10505 | break; |
| 10506 | } |
| 10507 | } |
| 10508 | return NULL; |
| 10509 | } |
| 10510 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 10511 | TEST_F(VkLayerTest, ThreadCommandBufferCollision) { |
Mike Stroyan | 4268d1f | 2015-07-13 14:45:35 -0600 | [diff] [blame] | 10512 | test_platform_thread thread; |
Mike Stroyan | accf769 | 2015-05-12 16:00:45 -0600 | [diff] [blame] | 10513 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 10514 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 10515 | "THREADING ERROR"); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 10516 | |
Mike Stroyan | accf769 | 2015-05-12 16:00:45 -0600 | [diff] [blame] | 10517 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 10518 | ASSERT_NO_FATAL_FAILURE(InitViewport()); |
| 10519 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 10520 | |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 10521 | // Calls AllocateCommandBuffers |
| 10522 | VkCommandBufferObj commandBuffer(m_device, m_commandPool); |
Mark Lobodzinski | 5495d13 | 2015-09-30 16:19:16 -0600 | [diff] [blame] | 10523 | |
| 10524 | // Avoid creating RenderPass |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 10525 | commandBuffer.BeginCommandBuffer(); |
Mike Stroyan | accf769 | 2015-05-12 16:00:45 -0600 | [diff] [blame] | 10526 | |
| 10527 | VkEventCreateInfo event_info; |
| 10528 | VkEvent event; |
Mike Stroyan | accf769 | 2015-05-12 16:00:45 -0600 | [diff] [blame] | 10529 | VkResult err; |
| 10530 | |
| 10531 | memset(&event_info, 0, sizeof(event_info)); |
| 10532 | event_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO; |
| 10533 | |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 10534 | err = vkCreateEvent(device(), &event_info, NULL, &event); |
Mike Stroyan | accf769 | 2015-05-12 16:00:45 -0600 | [diff] [blame] | 10535 | ASSERT_VK_SUCCESS(err); |
| 10536 | |
Mike Stroyan | accf769 | 2015-05-12 16:00:45 -0600 | [diff] [blame] | 10537 | err = vkResetEvent(device(), event); |
| 10538 | ASSERT_VK_SUCCESS(err); |
| 10539 | |
| 10540 | struct thread_data_struct data; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 10541 | data.commandBuffer = commandBuffer.GetBufferHandle(); |
Mike Stroyan | accf769 | 2015-05-12 16:00:45 -0600 | [diff] [blame] | 10542 | data.event = event; |
| 10543 | data.bailout = false; |
| 10544 | m_errorMonitor->SetBailout(&data.bailout); |
| 10545 | // Add many entries to command buffer from another thread. |
Mike Stroyan | 4268d1f | 2015-07-13 14:45:35 -0600 | [diff] [blame] | 10546 | test_platform_thread_create(&thread, AddToCommandBuffer, (void *)&data); |
Mike Stroyan | accf769 | 2015-05-12 16:00:45 -0600 | [diff] [blame] | 10547 | // Add many entries to command buffer from this thread at the same time. |
| 10548 | AddToCommandBuffer(&data); |
Mark Lobodzinski | 5495d13 | 2015-09-30 16:19:16 -0600 | [diff] [blame] | 10549 | |
Mike Stroyan | 4268d1f | 2015-07-13 14:45:35 -0600 | [diff] [blame] | 10550 | test_platform_thread_join(thread, NULL); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 10551 | commandBuffer.EndCommandBuffer(); |
Mike Stroyan | accf769 | 2015-05-12 16:00:45 -0600 | [diff] [blame] | 10552 | |
Mike Stroyan | 10b8cb7 | 2016-01-22 15:22:03 -0700 | [diff] [blame] | 10553 | m_errorMonitor->SetBailout(NULL); |
| 10554 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 10555 | m_errorMonitor->VerifyFound(); |
Mike Stroyan | accf769 | 2015-05-12 16:00:45 -0600 | [diff] [blame] | 10556 | |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 10557 | vkDestroyEvent(device(), event, NULL); |
Mike Stroyan | accf769 | 2015-05-12 16:00:45 -0600 | [diff] [blame] | 10558 | } |
Mark Lobodzinski | 209b529 | 2015-09-17 09:44:05 -0600 | [diff] [blame] | 10559 | #endif // GTEST_IS_THREADSAFE |
| 10560 | #endif // THREADING_TESTS |
| 10561 | |
Chris Forbes | 9f7ff63 | 2015-05-25 11:13:08 +1200 | [diff] [blame] | 10562 | #if SHADER_CHECKER_TESTS |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 10563 | TEST_F(VkLayerTest, InvalidSPIRVCodeSize) { |
Courtney Goeltzenleuchter | 7415d5a | 2015-12-09 15:48:16 -0700 | [diff] [blame] | 10564 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Chris Forbes | b4afd0f | 2016-04-04 10:48:35 +1200 | [diff] [blame] | 10565 | "Invalid SPIR-V header"); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 10566 | |
Courtney Goeltzenleuchter | 00c52b2 | 2015-09-16 12:58:29 -0600 | [diff] [blame] | 10567 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 10568 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 10569 | |
Courtney Goeltzenleuchter | 00c52b2 | 2015-09-16 12:58:29 -0600 | [diff] [blame] | 10570 | VkShaderModule module; |
| 10571 | VkShaderModuleCreateInfo moduleCreateInfo; |
| 10572 | struct icd_spv_header spv; |
| 10573 | |
| 10574 | spv.magic = ICD_SPV_MAGIC; |
| 10575 | spv.version = ICD_SPV_VERSION; |
| 10576 | spv.gen_magic = 0; |
| 10577 | |
| 10578 | moduleCreateInfo.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO; |
| 10579 | moduleCreateInfo.pNext = NULL; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 10580 | moduleCreateInfo.pCode = (const uint32_t *)&spv; |
Courtney Goeltzenleuchter | 00c52b2 | 2015-09-16 12:58:29 -0600 | [diff] [blame] | 10581 | moduleCreateInfo.codeSize = 4; |
| 10582 | moduleCreateInfo.flags = 0; |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 10583 | vkCreateShaderModule(m_device->device(), &moduleCreateInfo, NULL, &module); |
Courtney Goeltzenleuchter | 00c52b2 | 2015-09-16 12:58:29 -0600 | [diff] [blame] | 10584 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 10585 | m_errorMonitor->VerifyFound(); |
Courtney Goeltzenleuchter | 00c52b2 | 2015-09-16 12:58:29 -0600 | [diff] [blame] | 10586 | } |
| 10587 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 10588 | TEST_F(VkLayerTest, InvalidSPIRVMagic) { |
Courtney Goeltzenleuchter | 7415d5a | 2015-12-09 15:48:16 -0700 | [diff] [blame] | 10589 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Chris Forbes | b4afd0f | 2016-04-04 10:48:35 +1200 | [diff] [blame] | 10590 | "Invalid SPIR-V magic number"); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 10591 | |
Courtney Goeltzenleuchter | 00c52b2 | 2015-09-16 12:58:29 -0600 | [diff] [blame] | 10592 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 10593 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 10594 | |
Courtney Goeltzenleuchter | 00c52b2 | 2015-09-16 12:58:29 -0600 | [diff] [blame] | 10595 | VkShaderModule module; |
| 10596 | VkShaderModuleCreateInfo moduleCreateInfo; |
| 10597 | struct icd_spv_header spv; |
| 10598 | |
| 10599 | spv.magic = ~ICD_SPV_MAGIC; |
| 10600 | spv.version = ICD_SPV_VERSION; |
| 10601 | spv.gen_magic = 0; |
| 10602 | |
| 10603 | moduleCreateInfo.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO; |
| 10604 | moduleCreateInfo.pNext = NULL; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 10605 | moduleCreateInfo.pCode = (const uint32_t *)&spv; |
Courtney Goeltzenleuchter | 00c52b2 | 2015-09-16 12:58:29 -0600 | [diff] [blame] | 10606 | moduleCreateInfo.codeSize = sizeof(spv) + 10; |
| 10607 | moduleCreateInfo.flags = 0; |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 10608 | vkCreateShaderModule(m_device->device(), &moduleCreateInfo, NULL, &module); |
Courtney Goeltzenleuchter | 00c52b2 | 2015-09-16 12:58:29 -0600 | [diff] [blame] | 10609 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 10610 | m_errorMonitor->VerifyFound(); |
Courtney Goeltzenleuchter | 00c52b2 | 2015-09-16 12:58:29 -0600 | [diff] [blame] | 10611 | } |
| 10612 | |
Chris Forbes | b4afd0f | 2016-04-04 10:48:35 +1200 | [diff] [blame] | 10613 | #if 0 |
| 10614 | // Not currently covered by SPIRV-Tools validator |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 10615 | TEST_F(VkLayerTest, InvalidSPIRVVersion) { |
Courtney Goeltzenleuchter | 7415d5a | 2015-12-09 15:48:16 -0700 | [diff] [blame] | 10616 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Chris Forbes | b4afd0f | 2016-04-04 10:48:35 +1200 | [diff] [blame] | 10617 | "Invalid SPIR-V header"); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 10618 | |
Courtney Goeltzenleuchter | 00c52b2 | 2015-09-16 12:58:29 -0600 | [diff] [blame] | 10619 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 10620 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 10621 | |
Courtney Goeltzenleuchter | 00c52b2 | 2015-09-16 12:58:29 -0600 | [diff] [blame] | 10622 | VkShaderModule module; |
| 10623 | VkShaderModuleCreateInfo moduleCreateInfo; |
| 10624 | struct icd_spv_header spv; |
| 10625 | |
| 10626 | spv.magic = ICD_SPV_MAGIC; |
| 10627 | spv.version = ~ICD_SPV_VERSION; |
| 10628 | spv.gen_magic = 0; |
| 10629 | |
| 10630 | moduleCreateInfo.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO; |
| 10631 | moduleCreateInfo.pNext = NULL; |
| 10632 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 10633 | moduleCreateInfo.pCode = (const uint32_t *)&spv; |
Courtney Goeltzenleuchter | 00c52b2 | 2015-09-16 12:58:29 -0600 | [diff] [blame] | 10634 | moduleCreateInfo.codeSize = sizeof(spv) + 10; |
| 10635 | moduleCreateInfo.flags = 0; |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 10636 | vkCreateShaderModule(m_device->device(), &moduleCreateInfo, NULL, &module); |
Courtney Goeltzenleuchter | 00c52b2 | 2015-09-16 12:58:29 -0600 | [diff] [blame] | 10637 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 10638 | m_errorMonitor->VerifyFound(); |
Courtney Goeltzenleuchter | 00c52b2 | 2015-09-16 12:58:29 -0600 | [diff] [blame] | 10639 | } |
Chris Forbes | b4afd0f | 2016-04-04 10:48:35 +1200 | [diff] [blame] | 10640 | #endif |
Courtney Goeltzenleuchter | 00c52b2 | 2015-09-16 12:58:29 -0600 | [diff] [blame] | 10641 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 10642 | TEST_F(VkLayerTest, CreatePipelineVertexOutputNotConsumed) { |
Mark Lobodzinski | 510e20d | 2016-02-11 09:26:16 -0700 | [diff] [blame] | 10643 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 10644 | "not consumed by fragment shader"); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 10645 | |
Chris Forbes | 9f7ff63 | 2015-05-25 11:13:08 +1200 | [diff] [blame] | 10646 | ASSERT_NO_FATAL_FAILURE(InitState()); |
Tobin Ehlis | c9ac2b6 | 2015-09-11 12:57:55 -0600 | [diff] [blame] | 10647 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
Chris Forbes | 9f7ff63 | 2015-05-25 11:13:08 +1200 | [diff] [blame] | 10648 | |
| 10649 | char const *vsSource = |
Chris Forbes | 3846771 | 2016-04-04 17:28:05 +1200 | [diff] [blame] | 10650 | "#version 450\n" |
Chris Forbes | 9f7ff63 | 2015-05-25 11:13:08 +1200 | [diff] [blame] | 10651 | "\n" |
| 10652 | "layout(location=0) out float x;\n" |
Tony Barbour | e804d20 | 2016-01-05 13:37:45 -0700 | [diff] [blame] | 10653 | "out gl_PerVertex {\n" |
| 10654 | " vec4 gl_Position;\n" |
| 10655 | "};\n" |
Chris Forbes | 9f7ff63 | 2015-05-25 11:13:08 +1200 | [diff] [blame] | 10656 | "void main(){\n" |
| 10657 | " gl_Position = vec4(1);\n" |
| 10658 | " x = 0;\n" |
| 10659 | "}\n"; |
| 10660 | char const *fsSource = |
Chris Forbes | 3846771 | 2016-04-04 17:28:05 +1200 | [diff] [blame] | 10661 | "#version 450\n" |
Chris Forbes | 9f7ff63 | 2015-05-25 11:13:08 +1200 | [diff] [blame] | 10662 | "\n" |
| 10663 | "layout(location=0) out vec4 color;\n" |
| 10664 | "void main(){\n" |
| 10665 | " color = vec4(1);\n" |
| 10666 | "}\n"; |
| 10667 | |
Courtney Goeltzenleuchter | d263550 | 2015-10-21 17:08:06 -0600 | [diff] [blame] | 10668 | VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this); |
| 10669 | VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this); |
Chris Forbes | 9f7ff63 | 2015-05-25 11:13:08 +1200 | [diff] [blame] | 10670 | |
| 10671 | VkPipelineObj pipe(m_device); |
Chia-I Wu | 08accc6 | 2015-07-07 11:50:03 +0800 | [diff] [blame] | 10672 | pipe.AddColorAttachment(); |
Chris Forbes | 9f7ff63 | 2015-05-25 11:13:08 +1200 | [diff] [blame] | 10673 | pipe.AddShader(&vs); |
| 10674 | pipe.AddShader(&fs); |
| 10675 | |
Chris Forbes | 9f7ff63 | 2015-05-25 11:13:08 +1200 | [diff] [blame] | 10676 | VkDescriptorSetObj descriptorSet(m_device); |
| 10677 | descriptorSet.AppendDummy(); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 10678 | descriptorSet.CreateVKDescriptorSet(m_commandBuffer); |
Chris Forbes | 9f7ff63 | 2015-05-25 11:13:08 +1200 | [diff] [blame] | 10679 | |
Tony Barbour | 5781e8f | 2015-08-04 16:23:11 -0600 | [diff] [blame] | 10680 | pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass()); |
Chris Forbes | 9f7ff63 | 2015-05-25 11:13:08 +1200 | [diff] [blame] | 10681 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 10682 | m_errorMonitor->VerifyFound(); |
Chris Forbes | 9f7ff63 | 2015-05-25 11:13:08 +1200 | [diff] [blame] | 10683 | } |
Chris Forbes | 9f7ff63 | 2015-05-25 11:13:08 +1200 | [diff] [blame] | 10684 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 10685 | TEST_F(VkLayerTest, CreatePipelineFragmentInputNotProvided) { |
Courtney Goeltzenleuchter | 7415d5a | 2015-12-09 15:48:16 -0700 | [diff] [blame] | 10686 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 10687 | "not written by vertex shader"); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 10688 | |
Chris Forbes | 59cb88d | 2015-05-25 11:13:13 +1200 | [diff] [blame] | 10689 | ASSERT_NO_FATAL_FAILURE(InitState()); |
Tobin Ehlis | c9ac2b6 | 2015-09-11 12:57:55 -0600 | [diff] [blame] | 10690 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
Chris Forbes | 59cb88d | 2015-05-25 11:13:13 +1200 | [diff] [blame] | 10691 | |
| 10692 | char const *vsSource = |
Chris Forbes | 3846771 | 2016-04-04 17:28:05 +1200 | [diff] [blame] | 10693 | "#version 450\n" |
Chris Forbes | 59cb88d | 2015-05-25 11:13:13 +1200 | [diff] [blame] | 10694 | "\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 | 59cb88d | 2015-05-25 11:13:13 +1200 | [diff] [blame] | 10698 | "void main(){\n" |
| 10699 | " gl_Position = vec4(1);\n" |
| 10700 | "}\n"; |
| 10701 | char const *fsSource = |
Chris Forbes | 3846771 | 2016-04-04 17:28:05 +1200 | [diff] [blame] | 10702 | "#version 450\n" |
Chris Forbes | 59cb88d | 2015-05-25 11:13:13 +1200 | [diff] [blame] | 10703 | "\n" |
| 10704 | "layout(location=0) in float x;\n" |
| 10705 | "layout(location=0) out vec4 color;\n" |
| 10706 | "void main(){\n" |
| 10707 | " color = vec4(x);\n" |
| 10708 | "}\n"; |
| 10709 | |
Courtney Goeltzenleuchter | d263550 | 2015-10-21 17:08:06 -0600 | [diff] [blame] | 10710 | VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this); |
| 10711 | VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this); |
Chris Forbes | 59cb88d | 2015-05-25 11:13:13 +1200 | [diff] [blame] | 10712 | |
| 10713 | VkPipelineObj pipe(m_device); |
Chia-I Wu | 08accc6 | 2015-07-07 11:50:03 +0800 | [diff] [blame] | 10714 | pipe.AddColorAttachment(); |
Chris Forbes | 59cb88d | 2015-05-25 11:13:13 +1200 | [diff] [blame] | 10715 | pipe.AddShader(&vs); |
| 10716 | pipe.AddShader(&fs); |
| 10717 | |
Chris Forbes | 59cb88d | 2015-05-25 11:13:13 +1200 | [diff] [blame] | 10718 | VkDescriptorSetObj descriptorSet(m_device); |
| 10719 | descriptorSet.AppendDummy(); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 10720 | descriptorSet.CreateVKDescriptorSet(m_commandBuffer); |
Chris Forbes | 59cb88d | 2015-05-25 11:13:13 +1200 | [diff] [blame] | 10721 | |
Tony Barbour | 5781e8f | 2015-08-04 16:23:11 -0600 | [diff] [blame] | 10722 | pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass()); |
Chris Forbes | 59cb88d | 2015-05-25 11:13:13 +1200 | [diff] [blame] | 10723 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 10724 | m_errorMonitor->VerifyFound(); |
Chris Forbes | 59cb88d | 2015-05-25 11:13:13 +1200 | [diff] [blame] | 10725 | } |
| 10726 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 10727 | TEST_F(VkLayerTest, CreatePipelineFragmentInputNotProvidedInBlock) { |
Chris Forbes | a3e85f6 | 2016-01-15 14:53:11 +1300 | [diff] [blame] | 10728 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 10729 | "not written by vertex shader"); |
Chris Forbes | a3e85f6 | 2016-01-15 14:53:11 +1300 | [diff] [blame] | 10730 | |
| 10731 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 10732 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 10733 | |
| 10734 | char const *vsSource = |
Chris Forbes | 3846771 | 2016-04-04 17:28:05 +1200 | [diff] [blame] | 10735 | "#version 450\n" |
Chris Forbes | a3e85f6 | 2016-01-15 14:53:11 +1300 | [diff] [blame] | 10736 | "\n" |
| 10737 | "out gl_PerVertex {\n" |
| 10738 | " vec4 gl_Position;\n" |
| 10739 | "};\n" |
| 10740 | "void main(){\n" |
| 10741 | " gl_Position = vec4(1);\n" |
| 10742 | "}\n"; |
| 10743 | char const *fsSource = |
| 10744 | "#version 450\n" |
Chris Forbes | a3e85f6 | 2016-01-15 14:53:11 +1300 | [diff] [blame] | 10745 | "\n" |
| 10746 | "in block { layout(location=0) float x; } ins;\n" |
| 10747 | "layout(location=0) out vec4 color;\n" |
| 10748 | "void main(){\n" |
| 10749 | " color = vec4(ins.x);\n" |
| 10750 | "}\n"; |
| 10751 | |
| 10752 | VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this); |
| 10753 | VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this); |
| 10754 | |
| 10755 | VkPipelineObj pipe(m_device); |
| 10756 | pipe.AddColorAttachment(); |
| 10757 | pipe.AddShader(&vs); |
| 10758 | pipe.AddShader(&fs); |
| 10759 | |
| 10760 | VkDescriptorSetObj descriptorSet(m_device); |
| 10761 | descriptorSet.AppendDummy(); |
| 10762 | descriptorSet.CreateVKDescriptorSet(m_commandBuffer); |
| 10763 | |
| 10764 | pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass()); |
| 10765 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 10766 | m_errorMonitor->VerifyFound(); |
Chris Forbes | a3e85f6 | 2016-01-15 14:53:11 +1300 | [diff] [blame] | 10767 | } |
| 10768 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 10769 | TEST_F(VkLayerTest, CreatePipelineVsFsTypeMismatchArraySize) { |
Chris Forbes | 0036fd1 | 2016-01-26 14:19:49 +1300 | [diff] [blame] | 10770 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Chris Forbes | e992882 | 2016-02-17 14:44:52 +1300 | [diff] [blame] | 10771 | "Type mismatch on location 0.0: 'ptr to " |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 10772 | "output arr[2] of float32' vs 'ptr to " |
| 10773 | "input arr[3] of float32'"); |
Chris Forbes | 0036fd1 | 2016-01-26 14:19:49 +1300 | [diff] [blame] | 10774 | |
| 10775 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 10776 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 10777 | |
| 10778 | char const *vsSource = |
Chris Forbes | 3846771 | 2016-04-04 17:28:05 +1200 | [diff] [blame] | 10779 | "#version 450\n" |
Chris Forbes | 0036fd1 | 2016-01-26 14:19:49 +1300 | [diff] [blame] | 10780 | "\n" |
| 10781 | "layout(location=0) out float x[2];\n" |
| 10782 | "out gl_PerVertex {\n" |
| 10783 | " vec4 gl_Position;\n" |
| 10784 | "};\n" |
| 10785 | "void main(){\n" |
| 10786 | " x[0] = 0; x[1] = 0;\n" |
| 10787 | " gl_Position = vec4(1);\n" |
| 10788 | "}\n"; |
| 10789 | char const *fsSource = |
Chris Forbes | 3846771 | 2016-04-04 17:28:05 +1200 | [diff] [blame] | 10790 | "#version 450\n" |
Chris Forbes | 0036fd1 | 2016-01-26 14:19:49 +1300 | [diff] [blame] | 10791 | "\n" |
| 10792 | "layout(location=0) in float x[3];\n" |
| 10793 | "layout(location=0) out vec4 color;\n" |
| 10794 | "void main(){\n" |
| 10795 | " color = vec4(x[0] + x[1] + x[2]);\n" |
| 10796 | "}\n"; |
| 10797 | |
| 10798 | VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this); |
| 10799 | VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this); |
| 10800 | |
| 10801 | VkPipelineObj pipe(m_device); |
| 10802 | pipe.AddColorAttachment(); |
| 10803 | pipe.AddShader(&vs); |
| 10804 | pipe.AddShader(&fs); |
| 10805 | |
| 10806 | VkDescriptorSetObj descriptorSet(m_device); |
| 10807 | descriptorSet.AppendDummy(); |
| 10808 | descriptorSet.CreateVKDescriptorSet(m_commandBuffer); |
| 10809 | |
| 10810 | pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass()); |
| 10811 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 10812 | m_errorMonitor->VerifyFound(); |
Chris Forbes | 0036fd1 | 2016-01-26 14:19:49 +1300 | [diff] [blame] | 10813 | } |
| 10814 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 10815 | TEST_F(VkLayerTest, CreatePipelineVsFsTypeMismatch) { |
Courtney Goeltzenleuchter | 7415d5a | 2015-12-09 15:48:16 -0700 | [diff] [blame] | 10816 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 10817 | "Type mismatch on location 0"); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 10818 | |
Chris Forbes | b56af56 | 2015-05-25 11:13:17 +1200 | [diff] [blame] | 10819 | ASSERT_NO_FATAL_FAILURE(InitState()); |
Tobin Ehlis | c9ac2b6 | 2015-09-11 12:57:55 -0600 | [diff] [blame] | 10820 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
Chris Forbes | b56af56 | 2015-05-25 11:13:17 +1200 | [diff] [blame] | 10821 | |
| 10822 | char const *vsSource = |
Chris Forbes | 3846771 | 2016-04-04 17:28:05 +1200 | [diff] [blame] | 10823 | "#version 450\n" |
Chris Forbes | b56af56 | 2015-05-25 11:13:17 +1200 | [diff] [blame] | 10824 | "\n" |
| 10825 | "layout(location=0) out int x;\n" |
Tony Barbour | e804d20 | 2016-01-05 13:37:45 -0700 | [diff] [blame] | 10826 | "out gl_PerVertex {\n" |
| 10827 | " vec4 gl_Position;\n" |
| 10828 | "};\n" |
Chris Forbes | b56af56 | 2015-05-25 11:13:17 +1200 | [diff] [blame] | 10829 | "void main(){\n" |
| 10830 | " x = 0;\n" |
| 10831 | " gl_Position = vec4(1);\n" |
| 10832 | "}\n"; |
| 10833 | char const *fsSource = |
Chris Forbes | 3846771 | 2016-04-04 17:28:05 +1200 | [diff] [blame] | 10834 | "#version 450\n" |
Chris Forbes | b56af56 | 2015-05-25 11:13:17 +1200 | [diff] [blame] | 10835 | "\n" |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 10836 | "layout(location=0) in float x;\n" /* VS writes int */ |
Chris Forbes | b56af56 | 2015-05-25 11:13:17 +1200 | [diff] [blame] | 10837 | "layout(location=0) out vec4 color;\n" |
| 10838 | "void main(){\n" |
| 10839 | " color = vec4(x);\n" |
| 10840 | "}\n"; |
| 10841 | |
Courtney Goeltzenleuchter | d263550 | 2015-10-21 17:08:06 -0600 | [diff] [blame] | 10842 | VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this); |
| 10843 | VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this); |
Chris Forbes | b56af56 | 2015-05-25 11:13:17 +1200 | [diff] [blame] | 10844 | |
| 10845 | VkPipelineObj pipe(m_device); |
Chia-I Wu | 08accc6 | 2015-07-07 11:50:03 +0800 | [diff] [blame] | 10846 | pipe.AddColorAttachment(); |
Chris Forbes | b56af56 | 2015-05-25 11:13:17 +1200 | [diff] [blame] | 10847 | pipe.AddShader(&vs); |
| 10848 | pipe.AddShader(&fs); |
| 10849 | |
Chris Forbes | b56af56 | 2015-05-25 11:13:17 +1200 | [diff] [blame] | 10850 | VkDescriptorSetObj descriptorSet(m_device); |
| 10851 | descriptorSet.AppendDummy(); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 10852 | descriptorSet.CreateVKDescriptorSet(m_commandBuffer); |
Chris Forbes | b56af56 | 2015-05-25 11:13:17 +1200 | [diff] [blame] | 10853 | |
Tony Barbour | 5781e8f | 2015-08-04 16:23:11 -0600 | [diff] [blame] | 10854 | pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass()); |
Chris Forbes | b56af56 | 2015-05-25 11:13:17 +1200 | [diff] [blame] | 10855 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 10856 | m_errorMonitor->VerifyFound(); |
Chris Forbes | b56af56 | 2015-05-25 11:13:17 +1200 | [diff] [blame] | 10857 | } |
| 10858 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 10859 | TEST_F(VkLayerTest, CreatePipelineVsFsTypeMismatchInBlock) { |
Chris Forbes | a3e85f6 | 2016-01-15 14:53:11 +1300 | [diff] [blame] | 10860 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 10861 | "Type mismatch on location 0"); |
Chris Forbes | a3e85f6 | 2016-01-15 14:53:11 +1300 | [diff] [blame] | 10862 | |
| 10863 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 10864 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 10865 | |
| 10866 | char const *vsSource = |
| 10867 | "#version 450\n" |
Chris Forbes | a3e85f6 | 2016-01-15 14:53:11 +1300 | [diff] [blame] | 10868 | "\n" |
| 10869 | "out block { layout(location=0) int x; } outs;\n" |
| 10870 | "out gl_PerVertex {\n" |
| 10871 | " vec4 gl_Position;\n" |
| 10872 | "};\n" |
| 10873 | "void main(){\n" |
| 10874 | " outs.x = 0;\n" |
| 10875 | " gl_Position = vec4(1);\n" |
| 10876 | "}\n"; |
| 10877 | char const *fsSource = |
| 10878 | "#version 450\n" |
Chris Forbes | a3e85f6 | 2016-01-15 14:53:11 +1300 | [diff] [blame] | 10879 | "\n" |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 10880 | "in block { layout(location=0) float x; } ins;\n" /* VS writes int */ |
Chris Forbes | a3e85f6 | 2016-01-15 14:53:11 +1300 | [diff] [blame] | 10881 | "layout(location=0) out vec4 color;\n" |
| 10882 | "void main(){\n" |
| 10883 | " color = vec4(ins.x);\n" |
| 10884 | "}\n"; |
| 10885 | |
| 10886 | VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this); |
| 10887 | VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this); |
| 10888 | |
| 10889 | VkPipelineObj pipe(m_device); |
| 10890 | pipe.AddColorAttachment(); |
| 10891 | pipe.AddShader(&vs); |
| 10892 | pipe.AddShader(&fs); |
| 10893 | |
| 10894 | VkDescriptorSetObj descriptorSet(m_device); |
| 10895 | descriptorSet.AppendDummy(); |
| 10896 | descriptorSet.CreateVKDescriptorSet(m_commandBuffer); |
| 10897 | |
| 10898 | pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass()); |
| 10899 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 10900 | m_errorMonitor->VerifyFound(); |
Chris Forbes | e992882 | 2016-02-17 14:44:52 +1300 | [diff] [blame] | 10901 | } |
| 10902 | |
| 10903 | TEST_F(VkLayerTest, CreatePipelineVsFsMismatchByLocation) { |
| 10904 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 10905 | "location 0.0 which is not written by vertex shader"); |
| 10906 | |
| 10907 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 10908 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 10909 | |
| 10910 | char const *vsSource = |
| 10911 | "#version 450\n" |
Chris Forbes | e992882 | 2016-02-17 14:44:52 +1300 | [diff] [blame] | 10912 | "\n" |
| 10913 | "out block { layout(location=1) float x; } outs;\n" |
| 10914 | "out gl_PerVertex {\n" |
| 10915 | " vec4 gl_Position;\n" |
| 10916 | "};\n" |
| 10917 | "void main(){\n" |
| 10918 | " outs.x = 0;\n" |
| 10919 | " gl_Position = vec4(1);\n" |
| 10920 | "}\n"; |
| 10921 | char const *fsSource = |
| 10922 | "#version 450\n" |
Chris Forbes | e992882 | 2016-02-17 14:44:52 +1300 | [diff] [blame] | 10923 | "\n" |
| 10924 | "in block { layout(location=0) float x; } ins;\n" |
| 10925 | "layout(location=0) out vec4 color;\n" |
| 10926 | "void main(){\n" |
| 10927 | " color = vec4(ins.x);\n" |
| 10928 | "}\n"; |
| 10929 | |
| 10930 | VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this); |
| 10931 | VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this); |
| 10932 | |
| 10933 | VkPipelineObj pipe(m_device); |
| 10934 | pipe.AddColorAttachment(); |
| 10935 | pipe.AddShader(&vs); |
| 10936 | pipe.AddShader(&fs); |
| 10937 | |
| 10938 | VkDescriptorSetObj descriptorSet(m_device); |
| 10939 | descriptorSet.AppendDummy(); |
| 10940 | descriptorSet.CreateVKDescriptorSet(m_commandBuffer); |
| 10941 | |
| 10942 | pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass()); |
| 10943 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 10944 | m_errorMonitor->VerifyFound(); |
Chris Forbes | e992882 | 2016-02-17 14:44:52 +1300 | [diff] [blame] | 10945 | } |
| 10946 | |
| 10947 | TEST_F(VkLayerTest, CreatePipelineVsFsMismatchByComponent) { |
| 10948 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 10949 | "location 0.1 which is not written by vertex shader"); |
| 10950 | |
| 10951 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 10952 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 10953 | |
| 10954 | char const *vsSource = |
| 10955 | "#version 450\n" |
Chris Forbes | e992882 | 2016-02-17 14:44:52 +1300 | [diff] [blame] | 10956 | "\n" |
| 10957 | "out block { layout(location=0, component=0) float x; } outs;\n" |
| 10958 | "out gl_PerVertex {\n" |
| 10959 | " vec4 gl_Position;\n" |
| 10960 | "};\n" |
| 10961 | "void main(){\n" |
| 10962 | " outs.x = 0;\n" |
| 10963 | " gl_Position = vec4(1);\n" |
| 10964 | "}\n"; |
| 10965 | char const *fsSource = |
| 10966 | "#version 450\n" |
Chris Forbes | e992882 | 2016-02-17 14:44:52 +1300 | [diff] [blame] | 10967 | "\n" |
| 10968 | "in block { layout(location=0, component=1) float x; } ins;\n" |
| 10969 | "layout(location=0) out vec4 color;\n" |
| 10970 | "void main(){\n" |
| 10971 | " color = vec4(ins.x);\n" |
| 10972 | "}\n"; |
| 10973 | |
| 10974 | VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this); |
| 10975 | VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this); |
| 10976 | |
| 10977 | VkPipelineObj pipe(m_device); |
| 10978 | pipe.AddColorAttachment(); |
| 10979 | pipe.AddShader(&vs); |
| 10980 | pipe.AddShader(&fs); |
| 10981 | |
| 10982 | VkDescriptorSetObj descriptorSet(m_device); |
| 10983 | descriptorSet.AppendDummy(); |
| 10984 | descriptorSet.CreateVKDescriptorSet(m_commandBuffer); |
| 10985 | |
| 10986 | pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass()); |
| 10987 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 10988 | m_errorMonitor->VerifyFound(); |
Chris Forbes | a3e85f6 | 2016-01-15 14:53:11 +1300 | [diff] [blame] | 10989 | } |
| 10990 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 10991 | TEST_F(VkLayerTest, CreatePipelineAttribNotConsumed) { |
Mark Lobodzinski | 510e20d | 2016-02-11 09:26:16 -0700 | [diff] [blame] | 10992 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 10993 | "location 0 not consumed by VS"); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 10994 | |
Chris Forbes | de136e0 | 2015-05-25 11:13:28 +1200 | [diff] [blame] | 10995 | ASSERT_NO_FATAL_FAILURE(InitState()); |
Tobin Ehlis | c9ac2b6 | 2015-09-11 12:57:55 -0600 | [diff] [blame] | 10996 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
Chris Forbes | de136e0 | 2015-05-25 11:13:28 +1200 | [diff] [blame] | 10997 | |
| 10998 | VkVertexInputBindingDescription input_binding; |
| 10999 | memset(&input_binding, 0, sizeof(input_binding)); |
| 11000 | |
| 11001 | VkVertexInputAttributeDescription input_attrib; |
| 11002 | memset(&input_attrib, 0, sizeof(input_attrib)); |
| 11003 | input_attrib.format = VK_FORMAT_R32_SFLOAT; |
| 11004 | |
| 11005 | char const *vsSource = |
Chris Forbes | 3846771 | 2016-04-04 17:28:05 +1200 | [diff] [blame] | 11006 | "#version 450\n" |
Chris Forbes | de136e0 | 2015-05-25 11:13:28 +1200 | [diff] [blame] | 11007 | "\n" |
Tony Barbour | e804d20 | 2016-01-05 13:37:45 -0700 | [diff] [blame] | 11008 | "out gl_PerVertex {\n" |
| 11009 | " vec4 gl_Position;\n" |
| 11010 | "};\n" |
Chris Forbes | de136e0 | 2015-05-25 11:13:28 +1200 | [diff] [blame] | 11011 | "void main(){\n" |
| 11012 | " gl_Position = vec4(1);\n" |
| 11013 | "}\n"; |
| 11014 | char const *fsSource = |
Chris Forbes | 3846771 | 2016-04-04 17:28:05 +1200 | [diff] [blame] | 11015 | "#version 450\n" |
Chris Forbes | de136e0 | 2015-05-25 11:13:28 +1200 | [diff] [blame] | 11016 | "\n" |
| 11017 | "layout(location=0) out vec4 color;\n" |
| 11018 | "void main(){\n" |
| 11019 | " color = vec4(1);\n" |
| 11020 | "}\n"; |
| 11021 | |
Courtney Goeltzenleuchter | d263550 | 2015-10-21 17:08:06 -0600 | [diff] [blame] | 11022 | VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this); |
| 11023 | VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this); |
Chris Forbes | de136e0 | 2015-05-25 11:13:28 +1200 | [diff] [blame] | 11024 | |
| 11025 | VkPipelineObj pipe(m_device); |
Chia-I Wu | 08accc6 | 2015-07-07 11:50:03 +0800 | [diff] [blame] | 11026 | pipe.AddColorAttachment(); |
Chris Forbes | de136e0 | 2015-05-25 11:13:28 +1200 | [diff] [blame] | 11027 | pipe.AddShader(&vs); |
| 11028 | pipe.AddShader(&fs); |
| 11029 | |
| 11030 | pipe.AddVertexInputBindings(&input_binding, 1); |
| 11031 | pipe.AddVertexInputAttribs(&input_attrib, 1); |
| 11032 | |
Chris Forbes | de136e0 | 2015-05-25 11:13:28 +1200 | [diff] [blame] | 11033 | VkDescriptorSetObj descriptorSet(m_device); |
| 11034 | descriptorSet.AppendDummy(); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 11035 | descriptorSet.CreateVKDescriptorSet(m_commandBuffer); |
Chris Forbes | de136e0 | 2015-05-25 11:13:28 +1200 | [diff] [blame] | 11036 | |
Tony Barbour | 5781e8f | 2015-08-04 16:23:11 -0600 | [diff] [blame] | 11037 | pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass()); |
Chris Forbes | de136e0 | 2015-05-25 11:13:28 +1200 | [diff] [blame] | 11038 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 11039 | m_errorMonitor->VerifyFound(); |
Chris Forbes | de136e0 | 2015-05-25 11:13:28 +1200 | [diff] [blame] | 11040 | } |
| 11041 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 11042 | TEST_F(VkLayerTest, CreatePipelineAttribLocationMismatch) { |
Mark Lobodzinski | 510e20d | 2016-02-11 09:26:16 -0700 | [diff] [blame] | 11043 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 11044 | "location 0 not consumed by VS"); |
Chris Forbes | 7d83cd5 | 2016-01-15 11:32:03 +1300 | [diff] [blame] | 11045 | |
| 11046 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 11047 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 11048 | |
| 11049 | VkVertexInputBindingDescription input_binding; |
| 11050 | memset(&input_binding, 0, sizeof(input_binding)); |
| 11051 | |
| 11052 | VkVertexInputAttributeDescription input_attrib; |
| 11053 | memset(&input_attrib, 0, sizeof(input_attrib)); |
| 11054 | input_attrib.format = VK_FORMAT_R32_SFLOAT; |
| 11055 | |
| 11056 | char const *vsSource = |
Chris Forbes | 3846771 | 2016-04-04 17:28:05 +1200 | [diff] [blame] | 11057 | "#version 450\n" |
Chris Forbes | 7d83cd5 | 2016-01-15 11:32:03 +1300 | [diff] [blame] | 11058 | "\n" |
| 11059 | "layout(location=1) in float x;\n" |
| 11060 | "out gl_PerVertex {\n" |
| 11061 | " vec4 gl_Position;\n" |
| 11062 | "};\n" |
| 11063 | "void main(){\n" |
| 11064 | " gl_Position = vec4(x);\n" |
| 11065 | "}\n"; |
| 11066 | char const *fsSource = |
Chris Forbes | 3846771 | 2016-04-04 17:28:05 +1200 | [diff] [blame] | 11067 | "#version 450\n" |
Chris Forbes | 7d83cd5 | 2016-01-15 11:32:03 +1300 | [diff] [blame] | 11068 | "\n" |
| 11069 | "layout(location=0) out vec4 color;\n" |
| 11070 | "void main(){\n" |
| 11071 | " color = vec4(1);\n" |
| 11072 | "}\n"; |
| 11073 | |
| 11074 | VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this); |
| 11075 | VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this); |
| 11076 | |
| 11077 | VkPipelineObj pipe(m_device); |
| 11078 | pipe.AddColorAttachment(); |
| 11079 | pipe.AddShader(&vs); |
| 11080 | pipe.AddShader(&fs); |
| 11081 | |
| 11082 | pipe.AddVertexInputBindings(&input_binding, 1); |
| 11083 | pipe.AddVertexInputAttribs(&input_attrib, 1); |
| 11084 | |
| 11085 | VkDescriptorSetObj descriptorSet(m_device); |
| 11086 | descriptorSet.AppendDummy(); |
| 11087 | descriptorSet.CreateVKDescriptorSet(m_commandBuffer); |
| 11088 | |
| 11089 | pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass()); |
| 11090 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 11091 | m_errorMonitor->VerifyFound(); |
Chris Forbes | 7d83cd5 | 2016-01-15 11:32:03 +1300 | [diff] [blame] | 11092 | } |
| 11093 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 11094 | TEST_F(VkLayerTest, CreatePipelineAttribNotProvided) { |
| 11095 | m_errorMonitor->SetDesiredFailureMsg( |
| 11096 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 11097 | "VS consumes input at location 0 but not provided"); |
| 11098 | |
Chris Forbes | 62e8e50 | 2015-05-25 11:13:29 +1200 | [diff] [blame] | 11099 | ASSERT_NO_FATAL_FAILURE(InitState()); |
Tobin Ehlis | c9ac2b6 | 2015-09-11 12:57:55 -0600 | [diff] [blame] | 11100 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
Chris Forbes | 62e8e50 | 2015-05-25 11:13:29 +1200 | [diff] [blame] | 11101 | |
| 11102 | char const *vsSource = |
Chris Forbes | 3846771 | 2016-04-04 17:28:05 +1200 | [diff] [blame] | 11103 | "#version 450\n" |
Chris Forbes | 62e8e50 | 2015-05-25 11:13:29 +1200 | [diff] [blame] | 11104 | "\n" |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 11105 | "layout(location=0) in vec4 x;\n" /* not provided */ |
Tony Barbour | e804d20 | 2016-01-05 13:37:45 -0700 | [diff] [blame] | 11106 | "out gl_PerVertex {\n" |
| 11107 | " vec4 gl_Position;\n" |
| 11108 | "};\n" |
Chris Forbes | 62e8e50 | 2015-05-25 11:13:29 +1200 | [diff] [blame] | 11109 | "void main(){\n" |
| 11110 | " gl_Position = x;\n" |
| 11111 | "}\n"; |
| 11112 | char const *fsSource = |
Chris Forbes | 3846771 | 2016-04-04 17:28:05 +1200 | [diff] [blame] | 11113 | "#version 450\n" |
Chris Forbes | 62e8e50 | 2015-05-25 11:13:29 +1200 | [diff] [blame] | 11114 | "\n" |
| 11115 | "layout(location=0) out vec4 color;\n" |
| 11116 | "void main(){\n" |
| 11117 | " color = vec4(1);\n" |
| 11118 | "}\n"; |
| 11119 | |
Courtney Goeltzenleuchter | d263550 | 2015-10-21 17:08:06 -0600 | [diff] [blame] | 11120 | VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this); |
| 11121 | VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this); |
Chris Forbes | 62e8e50 | 2015-05-25 11:13:29 +1200 | [diff] [blame] | 11122 | |
| 11123 | VkPipelineObj pipe(m_device); |
Chia-I Wu | 08accc6 | 2015-07-07 11:50:03 +0800 | [diff] [blame] | 11124 | pipe.AddColorAttachment(); |
Chris Forbes | 62e8e50 | 2015-05-25 11:13:29 +1200 | [diff] [blame] | 11125 | pipe.AddShader(&vs); |
| 11126 | pipe.AddShader(&fs); |
| 11127 | |
Chris Forbes | 62e8e50 | 2015-05-25 11:13:29 +1200 | [diff] [blame] | 11128 | VkDescriptorSetObj descriptorSet(m_device); |
| 11129 | descriptorSet.AppendDummy(); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 11130 | descriptorSet.CreateVKDescriptorSet(m_commandBuffer); |
Chris Forbes | 62e8e50 | 2015-05-25 11:13:29 +1200 | [diff] [blame] | 11131 | |
Tony Barbour | 5781e8f | 2015-08-04 16:23:11 -0600 | [diff] [blame] | 11132 | pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass()); |
Chris Forbes | 62e8e50 | 2015-05-25 11:13:29 +1200 | [diff] [blame] | 11133 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 11134 | m_errorMonitor->VerifyFound(); |
Chris Forbes | 62e8e50 | 2015-05-25 11:13:29 +1200 | [diff] [blame] | 11135 | } |
| 11136 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 11137 | TEST_F(VkLayerTest, CreatePipelineAttribTypeMismatch) { |
| 11138 | m_errorMonitor->SetDesiredFailureMsg( |
| 11139 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 11140 | "location 0 does not match VS input type"); |
| 11141 | |
Chris Forbes | c97d98e | 2015-05-25 11:13:31 +1200 | [diff] [blame] | 11142 | ASSERT_NO_FATAL_FAILURE(InitState()); |
Tobin Ehlis | c9ac2b6 | 2015-09-11 12:57:55 -0600 | [diff] [blame] | 11143 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
Chris Forbes | c97d98e | 2015-05-25 11:13:31 +1200 | [diff] [blame] | 11144 | |
| 11145 | VkVertexInputBindingDescription input_binding; |
| 11146 | memset(&input_binding, 0, sizeof(input_binding)); |
| 11147 | |
| 11148 | VkVertexInputAttributeDescription input_attrib; |
| 11149 | memset(&input_attrib, 0, sizeof(input_attrib)); |
| 11150 | input_attrib.format = VK_FORMAT_R32_SFLOAT; |
| 11151 | |
| 11152 | char const *vsSource = |
Chris Forbes | 3846771 | 2016-04-04 17:28:05 +1200 | [diff] [blame] | 11153 | "#version 450\n" |
Chris Forbes | c97d98e | 2015-05-25 11:13:31 +1200 | [diff] [blame] | 11154 | "\n" |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 11155 | "layout(location=0) in int x;\n" /* attrib provided float */ |
Tony Barbour | e804d20 | 2016-01-05 13:37:45 -0700 | [diff] [blame] | 11156 | "out gl_PerVertex {\n" |
| 11157 | " vec4 gl_Position;\n" |
| 11158 | "};\n" |
Chris Forbes | c97d98e | 2015-05-25 11:13:31 +1200 | [diff] [blame] | 11159 | "void main(){\n" |
| 11160 | " gl_Position = vec4(x);\n" |
| 11161 | "}\n"; |
| 11162 | char const *fsSource = |
Chris Forbes | 3846771 | 2016-04-04 17:28:05 +1200 | [diff] [blame] | 11163 | "#version 450\n" |
Chris Forbes | c97d98e | 2015-05-25 11:13:31 +1200 | [diff] [blame] | 11164 | "\n" |
| 11165 | "layout(location=0) out vec4 color;\n" |
| 11166 | "void main(){\n" |
| 11167 | " color = vec4(1);\n" |
| 11168 | "}\n"; |
| 11169 | |
Courtney Goeltzenleuchter | d263550 | 2015-10-21 17:08:06 -0600 | [diff] [blame] | 11170 | VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this); |
| 11171 | VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this); |
Chris Forbes | c97d98e | 2015-05-25 11:13:31 +1200 | [diff] [blame] | 11172 | |
| 11173 | VkPipelineObj pipe(m_device); |
Chia-I Wu | 08accc6 | 2015-07-07 11:50:03 +0800 | [diff] [blame] | 11174 | pipe.AddColorAttachment(); |
Chris Forbes | c97d98e | 2015-05-25 11:13:31 +1200 | [diff] [blame] | 11175 | pipe.AddShader(&vs); |
| 11176 | pipe.AddShader(&fs); |
| 11177 | |
| 11178 | pipe.AddVertexInputBindings(&input_binding, 1); |
| 11179 | pipe.AddVertexInputAttribs(&input_attrib, 1); |
| 11180 | |
Chris Forbes | c97d98e | 2015-05-25 11:13:31 +1200 | [diff] [blame] | 11181 | VkDescriptorSetObj descriptorSet(m_device); |
| 11182 | descriptorSet.AppendDummy(); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 11183 | descriptorSet.CreateVKDescriptorSet(m_commandBuffer); |
Chris Forbes | c97d98e | 2015-05-25 11:13:31 +1200 | [diff] [blame] | 11184 | |
Tony Barbour | 5781e8f | 2015-08-04 16:23:11 -0600 | [diff] [blame] | 11185 | pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass()); |
Chris Forbes | c97d98e | 2015-05-25 11:13:31 +1200 | [diff] [blame] | 11186 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 11187 | m_errorMonitor->VerifyFound(); |
Chris Forbes | c97d98e | 2015-05-25 11:13:31 +1200 | [diff] [blame] | 11188 | } |
| 11189 | |
Chris Forbes | c68b43c | 2016-04-06 11:18:47 +1200 | [diff] [blame] | 11190 | TEST_F(VkLayerTest, CreatePipelineDuplicateStage) { |
| 11191 | m_errorMonitor->SetDesiredFailureMsg( |
| 11192 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 11193 | "Multiple shaders provided for stage VK_SHADER_STAGE_VERTEX_BIT"); |
| 11194 | |
| 11195 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 11196 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 11197 | |
| 11198 | char const *vsSource = |
| 11199 | "#version 450\n" |
| 11200 | "\n" |
| 11201 | "out gl_PerVertex {\n" |
| 11202 | " vec4 gl_Position;\n" |
| 11203 | "};\n" |
| 11204 | "void main(){\n" |
| 11205 | " gl_Position = vec4(1);\n" |
| 11206 | "}\n"; |
| 11207 | char const *fsSource = |
| 11208 | "#version 450\n" |
| 11209 | "\n" |
| 11210 | "layout(location=0) out vec4 color;\n" |
| 11211 | "void main(){\n" |
| 11212 | " color = vec4(1);\n" |
| 11213 | "}\n"; |
| 11214 | |
| 11215 | VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this); |
| 11216 | VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this); |
| 11217 | |
| 11218 | VkPipelineObj pipe(m_device); |
| 11219 | pipe.AddColorAttachment(); |
| 11220 | pipe.AddShader(&vs); |
| 11221 | pipe.AddShader(&vs); |
| 11222 | pipe.AddShader(&fs); |
| 11223 | |
| 11224 | VkDescriptorSetObj descriptorSet(m_device); |
| 11225 | descriptorSet.AppendDummy(); |
| 11226 | descriptorSet.CreateVKDescriptorSet(m_commandBuffer); |
| 11227 | |
| 11228 | pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass()); |
| 11229 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 11230 | m_errorMonitor->VerifyFound(); |
Chris Forbes | c68b43c | 2016-04-06 11:18:47 +1200 | [diff] [blame] | 11231 | } |
| 11232 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 11233 | TEST_F(VkLayerTest, CreatePipelineAttribMatrixType) { |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 11234 | m_errorMonitor->ExpectSuccess(); |
Chris Forbes | 2682b24 | 2015-11-24 11:13:14 +1300 | [diff] [blame] | 11235 | |
| 11236 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 11237 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 11238 | |
| 11239 | VkVertexInputBindingDescription input_binding; |
| 11240 | memset(&input_binding, 0, sizeof(input_binding)); |
| 11241 | |
| 11242 | VkVertexInputAttributeDescription input_attribs[2]; |
| 11243 | memset(input_attribs, 0, sizeof(input_attribs)); |
| 11244 | |
| 11245 | for (int i = 0; i < 2; i++) { |
| 11246 | input_attribs[i].format = VK_FORMAT_R32G32B32A32_SFLOAT; |
| 11247 | input_attribs[i].location = i; |
| 11248 | } |
| 11249 | |
| 11250 | char const *vsSource = |
Chris Forbes | 3846771 | 2016-04-04 17:28:05 +1200 | [diff] [blame] | 11251 | "#version 450\n" |
Chris Forbes | 2682b24 | 2015-11-24 11:13:14 +1300 | [diff] [blame] | 11252 | "\n" |
| 11253 | "layout(location=0) in mat2x4 x;\n" |
Tony Barbour | e804d20 | 2016-01-05 13:37:45 -0700 | [diff] [blame] | 11254 | "out gl_PerVertex {\n" |
| 11255 | " vec4 gl_Position;\n" |
| 11256 | "};\n" |
Chris Forbes | 2682b24 | 2015-11-24 11:13:14 +1300 | [diff] [blame] | 11257 | "void main(){\n" |
| 11258 | " gl_Position = x[0] + x[1];\n" |
| 11259 | "}\n"; |
| 11260 | char const *fsSource = |
Chris Forbes | 3846771 | 2016-04-04 17:28:05 +1200 | [diff] [blame] | 11261 | "#version 450\n" |
Chris Forbes | 2682b24 | 2015-11-24 11:13:14 +1300 | [diff] [blame] | 11262 | "\n" |
| 11263 | "layout(location=0) out vec4 color;\n" |
| 11264 | "void main(){\n" |
| 11265 | " color = vec4(1);\n" |
| 11266 | "}\n"; |
| 11267 | |
| 11268 | VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this); |
| 11269 | VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this); |
| 11270 | |
| 11271 | VkPipelineObj pipe(m_device); |
| 11272 | pipe.AddColorAttachment(); |
| 11273 | pipe.AddShader(&vs); |
| 11274 | pipe.AddShader(&fs); |
| 11275 | |
| 11276 | pipe.AddVertexInputBindings(&input_binding, 1); |
| 11277 | pipe.AddVertexInputAttribs(input_attribs, 2); |
| 11278 | |
| 11279 | VkDescriptorSetObj descriptorSet(m_device); |
| 11280 | descriptorSet.AppendDummy(); |
| 11281 | descriptorSet.CreateVKDescriptorSet(m_commandBuffer); |
| 11282 | |
| 11283 | pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass()); |
| 11284 | |
| 11285 | /* expect success */ |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 11286 | m_errorMonitor->VerifyNotFound(); |
Chris Forbes | 2682b24 | 2015-11-24 11:13:14 +1300 | [diff] [blame] | 11287 | } |
| 11288 | |
Chris Forbes | 2682b24 | 2015-11-24 11:13:14 +1300 | [diff] [blame] | 11289 | TEST_F(VkLayerTest, CreatePipelineAttribArrayType) |
| 11290 | { |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 11291 | m_errorMonitor->ExpectSuccess(); |
Chris Forbes | 2682b24 | 2015-11-24 11:13:14 +1300 | [diff] [blame] | 11292 | |
| 11293 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 11294 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 11295 | |
| 11296 | VkVertexInputBindingDescription input_binding; |
| 11297 | memset(&input_binding, 0, sizeof(input_binding)); |
| 11298 | |
| 11299 | VkVertexInputAttributeDescription input_attribs[2]; |
| 11300 | memset(input_attribs, 0, sizeof(input_attribs)); |
| 11301 | |
| 11302 | for (int i = 0; i < 2; i++) { |
| 11303 | input_attribs[i].format = VK_FORMAT_R32G32B32A32_SFLOAT; |
| 11304 | input_attribs[i].location = i; |
| 11305 | } |
| 11306 | |
| 11307 | char const *vsSource = |
Chris Forbes | 3846771 | 2016-04-04 17:28:05 +1200 | [diff] [blame] | 11308 | "#version 450\n" |
Chris Forbes | 2682b24 | 2015-11-24 11:13:14 +1300 | [diff] [blame] | 11309 | "\n" |
| 11310 | "layout(location=0) in vec4 x[2];\n" |
Tony Barbour | e804d20 | 2016-01-05 13:37:45 -0700 | [diff] [blame] | 11311 | "out gl_PerVertex {\n" |
| 11312 | " vec4 gl_Position;\n" |
| 11313 | "};\n" |
Chris Forbes | 2682b24 | 2015-11-24 11:13:14 +1300 | [diff] [blame] | 11314 | "void main(){\n" |
| 11315 | " gl_Position = x[0] + x[1];\n" |
| 11316 | "}\n"; |
| 11317 | char const *fsSource = |
Chris Forbes | 3846771 | 2016-04-04 17:28:05 +1200 | [diff] [blame] | 11318 | "#version 450\n" |
Chris Forbes | 2682b24 | 2015-11-24 11:13:14 +1300 | [diff] [blame] | 11319 | "\n" |
| 11320 | "layout(location=0) out vec4 color;\n" |
| 11321 | "void main(){\n" |
| 11322 | " color = vec4(1);\n" |
| 11323 | "}\n"; |
| 11324 | |
| 11325 | VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this); |
| 11326 | VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this); |
| 11327 | |
| 11328 | VkPipelineObj pipe(m_device); |
| 11329 | pipe.AddColorAttachment(); |
| 11330 | pipe.AddShader(&vs); |
| 11331 | pipe.AddShader(&fs); |
| 11332 | |
| 11333 | pipe.AddVertexInputBindings(&input_binding, 1); |
| 11334 | pipe.AddVertexInputAttribs(input_attribs, 2); |
| 11335 | |
| 11336 | VkDescriptorSetObj descriptorSet(m_device); |
| 11337 | descriptorSet.AppendDummy(); |
| 11338 | descriptorSet.CreateVKDescriptorSet(m_commandBuffer); |
| 11339 | |
| 11340 | pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass()); |
| 11341 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 11342 | m_errorMonitor->VerifyNotFound(); |
Chris Forbes | 2682b24 | 2015-11-24 11:13:14 +1300 | [diff] [blame] | 11343 | } |
Chris Forbes | 2682b24 | 2015-11-24 11:13:14 +1300 | [diff] [blame] | 11344 | |
Chris Forbes | 4ea14fc | 2016-04-04 18:52:54 +1200 | [diff] [blame] | 11345 | TEST_F(VkLayerTest, CreatePipelineSimplePositive) |
| 11346 | { |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 11347 | m_errorMonitor->ExpectSuccess(); |
Chris Forbes | 4ea14fc | 2016-04-04 18:52:54 +1200 | [diff] [blame] | 11348 | |
| 11349 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 11350 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 11351 | |
| 11352 | char const *vsSource = |
| 11353 | "#version 450\n" |
| 11354 | "out gl_PerVertex {\n" |
| 11355 | " vec4 gl_Position;\n" |
| 11356 | "};\n" |
| 11357 | "void main(){\n" |
| 11358 | " gl_Position = vec4(0);\n" |
| 11359 | "}\n"; |
| 11360 | char const *fsSource = |
| 11361 | "#version 450\n" |
| 11362 | "\n" |
| 11363 | "layout(location=0) out vec4 color;\n" |
| 11364 | "void main(){\n" |
| 11365 | " color = vec4(1);\n" |
| 11366 | "}\n"; |
| 11367 | |
| 11368 | VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this); |
| 11369 | VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this); |
| 11370 | |
| 11371 | VkPipelineObj pipe(m_device); |
| 11372 | pipe.AddColorAttachment(); |
| 11373 | pipe.AddShader(&vs); |
| 11374 | pipe.AddShader(&fs); |
| 11375 | |
| 11376 | VkDescriptorSetObj descriptorSet(m_device); |
| 11377 | descriptorSet.AppendDummy(); |
| 11378 | descriptorSet.CreateVKDescriptorSet(m_commandBuffer); |
| 11379 | |
| 11380 | pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass()); |
| 11381 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 11382 | m_errorMonitor->VerifyNotFound(); |
Chris Forbes | 4ea14fc | 2016-04-04 18:52:54 +1200 | [diff] [blame] | 11383 | } |
| 11384 | |
Chris Forbes | 912c919 | 2016-04-05 17:50:35 +1200 | [diff] [blame] | 11385 | TEST_F(VkLayerTest, CreatePipelineRelaxedTypeMatch) |
| 11386 | { |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 11387 | m_errorMonitor->ExpectSuccess(); |
Chris Forbes | 912c919 | 2016-04-05 17:50:35 +1200 | [diff] [blame] | 11388 | |
| 11389 | // VK 1.0.8 Specification, 14.1.3 "Additionally,..." block |
| 11390 | |
| 11391 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 11392 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 11393 | |
| 11394 | char const *vsSource = |
| 11395 | "#version 450\n" |
| 11396 | "out gl_PerVertex {\n" |
| 11397 | " vec4 gl_Position;\n" |
| 11398 | "};\n" |
| 11399 | "layout(location=0) out vec3 x;\n" |
| 11400 | "layout(location=1) out ivec3 y;\n" |
| 11401 | "layout(location=2) out vec3 z;\n" |
| 11402 | "void main(){\n" |
| 11403 | " gl_Position = vec4(0);\n" |
| 11404 | " x = vec3(0); y = ivec3(0); z = vec3(0);\n" |
| 11405 | "}\n"; |
| 11406 | char const *fsSource = |
| 11407 | "#version 450\n" |
| 11408 | "\n" |
| 11409 | "layout(location=0) out vec4 color;\n" |
| 11410 | "layout(location=0) in float x;\n" |
| 11411 | "layout(location=1) flat in int y;\n" |
| 11412 | "layout(location=2) in vec2 z;\n" |
| 11413 | "void main(){\n" |
| 11414 | " color = vec4(1 + x + y + z.x);\n" |
| 11415 | "}\n"; |
| 11416 | |
| 11417 | VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this); |
| 11418 | VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this); |
| 11419 | |
| 11420 | VkPipelineObj pipe(m_device); |
| 11421 | pipe.AddColorAttachment(); |
| 11422 | pipe.AddShader(&vs); |
| 11423 | pipe.AddShader(&fs); |
| 11424 | |
| 11425 | VkDescriptorSetObj descriptorSet(m_device); |
| 11426 | descriptorSet.AppendDummy(); |
| 11427 | descriptorSet.CreateVKDescriptorSet(m_commandBuffer); |
| 11428 | |
Mike Stroyan | 255e958 | 2016-06-24 09:49:32 -0600 | [diff] [blame] | 11429 | VkResult err = VK_SUCCESS; |
| 11430 | err = |
| 11431 | pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass()); |
| 11432 | ASSERT_VK_SUCCESS(err); |
| 11433 | |
Chris Forbes | 912c919 | 2016-04-05 17:50:35 +1200 | [diff] [blame] | 11434 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 11435 | m_errorMonitor->VerifyNotFound(); |
Chris Forbes | 912c919 | 2016-04-05 17:50:35 +1200 | [diff] [blame] | 11436 | } |
| 11437 | |
Chris Forbes | 4ea14fc | 2016-04-04 18:52:54 +1200 | [diff] [blame] | 11438 | TEST_F(VkLayerTest, CreatePipelineTessPerVertex) |
| 11439 | { |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 11440 | m_errorMonitor->ExpectSuccess(); |
Chris Forbes | 4ea14fc | 2016-04-04 18:52:54 +1200 | [diff] [blame] | 11441 | |
| 11442 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 11443 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 11444 | |
Chris Forbes | c1e852d | 2016-04-04 19:26:42 +1200 | [diff] [blame] | 11445 | if (!m_device->phy().features().tessellationShader) { |
| 11446 | printf("Device does not support tessellation shaders; skipped.\n"); |
| 11447 | return; |
| 11448 | } |
| 11449 | |
Chris Forbes | 4ea14fc | 2016-04-04 18:52:54 +1200 | [diff] [blame] | 11450 | char const *vsSource = |
| 11451 | "#version 450\n" |
| 11452 | "void main(){}\n"; |
| 11453 | char const *tcsSource = |
| 11454 | "#version 450\n" |
| 11455 | "layout(location=0) out int x[];\n" |
| 11456 | "layout(vertices=3) out;\n" |
| 11457 | "void main(){\n" |
| 11458 | " gl_TessLevelOuter[0] = gl_TessLevelOuter[1] = gl_TessLevelOuter[2] = 1;\n" |
| 11459 | " gl_TessLevelInner[0] = 1;\n" |
| 11460 | " x[gl_InvocationID] = gl_InvocationID;\n" |
| 11461 | "}\n"; |
| 11462 | char const *tesSource = |
| 11463 | "#version 450\n" |
| 11464 | "layout(triangles, equal_spacing, cw) in;\n" |
| 11465 | "layout(location=0) in int x[];\n" |
| 11466 | "out gl_PerVertex { vec4 gl_Position; };\n" |
| 11467 | "void main(){\n" |
| 11468 | " gl_Position.xyz = gl_TessCoord;\n" |
| 11469 | " gl_Position.w = x[0] + x[1] + x[2];\n" |
| 11470 | "}\n"; |
| 11471 | char const *fsSource = |
| 11472 | "#version 450\n" |
| 11473 | "layout(location=0) out vec4 color;\n" |
| 11474 | "void main(){\n" |
| 11475 | " color = vec4(1);\n" |
| 11476 | "}\n"; |
| 11477 | |
| 11478 | VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this); |
| 11479 | VkShaderObj tcs(m_device, tcsSource, VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT, this); |
| 11480 | VkShaderObj tes(m_device, tesSource, VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT, this); |
| 11481 | VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this); |
| 11482 | |
| 11483 | VkPipelineInputAssemblyStateCreateInfo iasci{ |
| 11484 | VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO, |
| 11485 | nullptr, |
| 11486 | 0, |
| 11487 | VK_PRIMITIVE_TOPOLOGY_PATCH_LIST, |
| 11488 | VK_FALSE}; |
| 11489 | |
Chris Forbes | b4cacb6 | 2016-04-04 19:15:00 +1200 | [diff] [blame] | 11490 | VkPipelineTessellationStateCreateInfo tsci{ |
| 11491 | VK_STRUCTURE_TYPE_PIPELINE_TESSELLATION_STATE_CREATE_INFO, |
| 11492 | nullptr, |
| 11493 | 0, |
| 11494 | 3}; |
| 11495 | |
Chris Forbes | 4ea14fc | 2016-04-04 18:52:54 +1200 | [diff] [blame] | 11496 | VkPipelineObj pipe(m_device); |
| 11497 | pipe.SetInputAssembly(&iasci); |
Chris Forbes | b4cacb6 | 2016-04-04 19:15:00 +1200 | [diff] [blame] | 11498 | pipe.SetTessellation(&tsci); |
Chris Forbes | 4ea14fc | 2016-04-04 18:52:54 +1200 | [diff] [blame] | 11499 | pipe.AddColorAttachment(); |
| 11500 | pipe.AddShader(&vs); |
| 11501 | pipe.AddShader(&tcs); |
| 11502 | pipe.AddShader(&tes); |
| 11503 | pipe.AddShader(&fs); |
| 11504 | |
| 11505 | VkDescriptorSetObj descriptorSet(m_device); |
| 11506 | descriptorSet.AppendDummy(); |
| 11507 | descriptorSet.CreateVKDescriptorSet(m_commandBuffer); |
| 11508 | |
| 11509 | pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass()); |
| 11510 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 11511 | m_errorMonitor->VerifyNotFound(); |
Chris Forbes | 4ea14fc | 2016-04-04 18:52:54 +1200 | [diff] [blame] | 11512 | } |
| 11513 | |
Chris Forbes | a0ab815 | 2016-04-20 13:34:27 +1200 | [diff] [blame] | 11514 | TEST_F(VkLayerTest, CreatePipelineGeometryInputBlockPositive) |
| 11515 | { |
| 11516 | m_errorMonitor->ExpectSuccess(); |
| 11517 | |
| 11518 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 11519 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 11520 | |
| 11521 | if (!m_device->phy().features().geometryShader) { |
| 11522 | printf("Device does not support geometry shaders; skipped.\n"); |
| 11523 | return; |
| 11524 | } |
| 11525 | |
| 11526 | char const *vsSource = |
| 11527 | "#version 450\n" |
| 11528 | "layout(location=0) out VertexData { vec4 x; } vs_out;\n" |
| 11529 | "void main(){\n" |
| 11530 | " vs_out.x = vec4(1);\n" |
| 11531 | "}\n"; |
| 11532 | char const *gsSource = |
| 11533 | "#version 450\n" |
| 11534 | "layout(triangles) in;\n" |
| 11535 | "layout(triangle_strip, max_vertices=3) out;\n" |
| 11536 | "layout(location=0) in VertexData { vec4 x; } gs_in[];\n" |
| 11537 | "out gl_PerVertex { vec4 gl_Position; };\n" |
| 11538 | "void main() {\n" |
| 11539 | " gl_Position = gs_in[0].x;\n" |
| 11540 | " EmitVertex();\n" |
| 11541 | "}\n"; |
| 11542 | char const *fsSource = |
| 11543 | "#version 450\n" |
| 11544 | "layout(location=0) out vec4 color;\n" |
| 11545 | "void main(){\n" |
| 11546 | " color = vec4(1);\n" |
| 11547 | "}\n"; |
| 11548 | |
| 11549 | VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this); |
| 11550 | VkShaderObj gs(m_device, gsSource, VK_SHADER_STAGE_GEOMETRY_BIT, this); |
| 11551 | VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this); |
| 11552 | |
| 11553 | VkPipelineObj pipe(m_device); |
| 11554 | pipe.AddColorAttachment(); |
| 11555 | pipe.AddShader(&vs); |
| 11556 | pipe.AddShader(&gs); |
| 11557 | pipe.AddShader(&fs); |
| 11558 | |
| 11559 | VkDescriptorSetObj descriptorSet(m_device); |
| 11560 | descriptorSet.AppendDummy(); |
| 11561 | descriptorSet.CreateVKDescriptorSet(m_commandBuffer); |
| 11562 | |
| 11563 | pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass()); |
| 11564 | |
| 11565 | m_errorMonitor->VerifyNotFound(); |
| 11566 | } |
| 11567 | |
Chris Forbes | a0193bc | 2016-04-04 19:19:47 +1200 | [diff] [blame] | 11568 | TEST_F(VkLayerTest, CreatePipelineTessPatchDecorationMismatch) |
| 11569 | { |
| 11570 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 11571 | "is per-vertex in tessellation control shader stage " |
| 11572 | "but per-patch in tessellation evaluation shader stage"); |
| 11573 | |
| 11574 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 11575 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 11576 | |
Chris Forbes | c1e852d | 2016-04-04 19:26:42 +1200 | [diff] [blame] | 11577 | if (!m_device->phy().features().tessellationShader) { |
| 11578 | printf("Device does not support tessellation shaders; skipped.\n"); |
| 11579 | return; |
| 11580 | } |
| 11581 | |
Chris Forbes | a0193bc | 2016-04-04 19:19:47 +1200 | [diff] [blame] | 11582 | char const *vsSource = |
| 11583 | "#version 450\n" |
| 11584 | "void main(){}\n"; |
| 11585 | char const *tcsSource = |
| 11586 | "#version 450\n" |
| 11587 | "layout(location=0) out int x[];\n" |
| 11588 | "layout(vertices=3) out;\n" |
| 11589 | "void main(){\n" |
| 11590 | " gl_TessLevelOuter[0] = gl_TessLevelOuter[1] = gl_TessLevelOuter[2] = 1;\n" |
| 11591 | " gl_TessLevelInner[0] = 1;\n" |
| 11592 | " x[gl_InvocationID] = gl_InvocationID;\n" |
| 11593 | "}\n"; |
| 11594 | char const *tesSource = |
| 11595 | "#version 450\n" |
| 11596 | "layout(triangles, equal_spacing, cw) in;\n" |
| 11597 | "layout(location=0) patch in int x;\n" |
| 11598 | "out gl_PerVertex { vec4 gl_Position; };\n" |
| 11599 | "void main(){\n" |
| 11600 | " gl_Position.xyz = gl_TessCoord;\n" |
| 11601 | " gl_Position.w = x;\n" |
| 11602 | "}\n"; |
| 11603 | char const *fsSource = |
| 11604 | "#version 450\n" |
| 11605 | "layout(location=0) out vec4 color;\n" |
| 11606 | "void main(){\n" |
| 11607 | " color = vec4(1);\n" |
| 11608 | "}\n"; |
| 11609 | |
| 11610 | VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this); |
| 11611 | VkShaderObj tcs(m_device, tcsSource, VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT, this); |
| 11612 | VkShaderObj tes(m_device, tesSource, VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT, this); |
| 11613 | VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this); |
| 11614 | |
| 11615 | VkPipelineInputAssemblyStateCreateInfo iasci{ |
| 11616 | VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO, |
| 11617 | nullptr, |
| 11618 | 0, |
| 11619 | VK_PRIMITIVE_TOPOLOGY_PATCH_LIST, |
| 11620 | VK_FALSE}; |
| 11621 | |
| 11622 | VkPipelineTessellationStateCreateInfo tsci{ |
| 11623 | VK_STRUCTURE_TYPE_PIPELINE_TESSELLATION_STATE_CREATE_INFO, |
| 11624 | nullptr, |
| 11625 | 0, |
| 11626 | 3}; |
| 11627 | |
| 11628 | VkPipelineObj pipe(m_device); |
| 11629 | pipe.SetInputAssembly(&iasci); |
| 11630 | pipe.SetTessellation(&tsci); |
| 11631 | pipe.AddColorAttachment(); |
| 11632 | pipe.AddShader(&vs); |
| 11633 | pipe.AddShader(&tcs); |
| 11634 | pipe.AddShader(&tes); |
| 11635 | pipe.AddShader(&fs); |
| 11636 | |
| 11637 | VkDescriptorSetObj descriptorSet(m_device); |
| 11638 | descriptorSet.AppendDummy(); |
| 11639 | descriptorSet.CreateVKDescriptorSet(m_commandBuffer); |
| 11640 | |
| 11641 | pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass()); |
| 11642 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 11643 | m_errorMonitor->VerifyFound(); |
Chris Forbes | a0193bc | 2016-04-04 19:19:47 +1200 | [diff] [blame] | 11644 | } |
| 11645 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 11646 | TEST_F(VkLayerTest, CreatePipelineAttribBindingConflict) { |
| 11647 | m_errorMonitor->SetDesiredFailureMsg( |
| 11648 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 11649 | "Duplicate vertex input binding descriptions for binding 0"); |
| 11650 | |
Chris Forbes | 280ba2c | 2015-06-12 11:16:41 +1200 | [diff] [blame] | 11651 | ASSERT_NO_FATAL_FAILURE(InitState()); |
Tobin Ehlis | c9ac2b6 | 2015-09-11 12:57:55 -0600 | [diff] [blame] | 11652 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
Chris Forbes | 280ba2c | 2015-06-12 11:16:41 +1200 | [diff] [blame] | 11653 | |
| 11654 | /* Two binding descriptions for binding 0 */ |
| 11655 | VkVertexInputBindingDescription input_bindings[2]; |
| 11656 | memset(input_bindings, 0, sizeof(input_bindings)); |
| 11657 | |
| 11658 | VkVertexInputAttributeDescription input_attrib; |
| 11659 | memset(&input_attrib, 0, sizeof(input_attrib)); |
| 11660 | input_attrib.format = VK_FORMAT_R32_SFLOAT; |
| 11661 | |
| 11662 | char const *vsSource = |
Chris Forbes | 3846771 | 2016-04-04 17:28:05 +1200 | [diff] [blame] | 11663 | "#version 450\n" |
Chris Forbes | 280ba2c | 2015-06-12 11:16:41 +1200 | [diff] [blame] | 11664 | "\n" |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 11665 | "layout(location=0) in float x;\n" /* attrib provided float */ |
Tony Barbour | e804d20 | 2016-01-05 13:37:45 -0700 | [diff] [blame] | 11666 | "out gl_PerVertex {\n" |
| 11667 | " vec4 gl_Position;\n" |
| 11668 | "};\n" |
Chris Forbes | 280ba2c | 2015-06-12 11:16:41 +1200 | [diff] [blame] | 11669 | "void main(){\n" |
| 11670 | " gl_Position = vec4(x);\n" |
| 11671 | "}\n"; |
| 11672 | char const *fsSource = |
Chris Forbes | 3846771 | 2016-04-04 17:28:05 +1200 | [diff] [blame] | 11673 | "#version 450\n" |
Chris Forbes | 280ba2c | 2015-06-12 11:16:41 +1200 | [diff] [blame] | 11674 | "\n" |
| 11675 | "layout(location=0) out vec4 color;\n" |
| 11676 | "void main(){\n" |
| 11677 | " color = vec4(1);\n" |
| 11678 | "}\n"; |
| 11679 | |
Courtney Goeltzenleuchter | d263550 | 2015-10-21 17:08:06 -0600 | [diff] [blame] | 11680 | VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this); |
| 11681 | VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this); |
Chris Forbes | 280ba2c | 2015-06-12 11:16:41 +1200 | [diff] [blame] | 11682 | |
| 11683 | VkPipelineObj pipe(m_device); |
Chia-I Wu | 08accc6 | 2015-07-07 11:50:03 +0800 | [diff] [blame] | 11684 | pipe.AddColorAttachment(); |
Chris Forbes | 280ba2c | 2015-06-12 11:16:41 +1200 | [diff] [blame] | 11685 | pipe.AddShader(&vs); |
| 11686 | pipe.AddShader(&fs); |
| 11687 | |
| 11688 | pipe.AddVertexInputBindings(input_bindings, 2); |
| 11689 | pipe.AddVertexInputAttribs(&input_attrib, 1); |
| 11690 | |
Chris Forbes | 280ba2c | 2015-06-12 11:16:41 +1200 | [diff] [blame] | 11691 | VkDescriptorSetObj descriptorSet(m_device); |
| 11692 | descriptorSet.AppendDummy(); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 11693 | descriptorSet.CreateVKDescriptorSet(m_commandBuffer); |
Chris Forbes | 280ba2c | 2015-06-12 11:16:41 +1200 | [diff] [blame] | 11694 | |
Tony Barbour | 5781e8f | 2015-08-04 16:23:11 -0600 | [diff] [blame] | 11695 | pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass()); |
Chris Forbes | 280ba2c | 2015-06-12 11:16:41 +1200 | [diff] [blame] | 11696 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 11697 | m_errorMonitor->VerifyFound(); |
Chris Forbes | 280ba2c | 2015-06-12 11:16:41 +1200 | [diff] [blame] | 11698 | } |
Chris Forbes | 8f68b56 | 2015-05-25 11:13:32 +1200 | [diff] [blame] | 11699 | |
Chris Forbes | 35efec7 | 2016-04-21 14:32:08 +1200 | [diff] [blame] | 11700 | TEST_F(VkLayerTest, CreatePipeline64BitAttributesPositive) { |
| 11701 | m_errorMonitor->ExpectSuccess(); |
| 11702 | |
| 11703 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 11704 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 11705 | |
Chris Forbes | 91cf3a8 | 2016-06-28 17:51:35 +1200 | [diff] [blame] | 11706 | if (!m_device->phy().features().shaderFloat64) { |
Chris Forbes | 35efec7 | 2016-04-21 14:32:08 +1200 | [diff] [blame] | 11707 | printf("Device does not support 64bit vertex attributes; skipped.\n"); |
| 11708 | return; |
| 11709 | } |
| 11710 | |
| 11711 | VkVertexInputBindingDescription input_bindings[1]; |
| 11712 | memset(input_bindings, 0, sizeof(input_bindings)); |
| 11713 | |
| 11714 | VkVertexInputAttributeDescription input_attribs[4]; |
| 11715 | memset(input_attribs, 0, sizeof(input_attribs)); |
| 11716 | input_attribs[0].location = 0; |
| 11717 | input_attribs[0].offset = 0; |
| 11718 | input_attribs[0].format = VK_FORMAT_R64G64B64A64_SFLOAT; |
| 11719 | input_attribs[1].location = 2; |
| 11720 | input_attribs[1].offset = 32; |
| 11721 | input_attribs[1].format = VK_FORMAT_R64G64B64A64_SFLOAT; |
| 11722 | input_attribs[2].location = 4; |
| 11723 | input_attribs[2].offset = 64; |
| 11724 | input_attribs[2].format = VK_FORMAT_R64G64B64A64_SFLOAT; |
| 11725 | input_attribs[3].location = 6; |
| 11726 | input_attribs[3].offset = 96; |
| 11727 | input_attribs[3].format = VK_FORMAT_R64G64B64A64_SFLOAT; |
| 11728 | |
| 11729 | char const *vsSource = |
| 11730 | "#version 450\n" |
| 11731 | "\n" |
| 11732 | "layout(location=0) in dmat4 x;\n" |
| 11733 | "out gl_PerVertex {\n" |
| 11734 | " vec4 gl_Position;\n" |
| 11735 | "};\n" |
| 11736 | "void main(){\n" |
| 11737 | " gl_Position = vec4(x[0][0]);\n" |
| 11738 | "}\n"; |
| 11739 | char const *fsSource = |
| 11740 | "#version 450\n" |
| 11741 | "\n" |
| 11742 | "layout(location=0) out vec4 color;\n" |
| 11743 | "void main(){\n" |
| 11744 | " color = vec4(1);\n" |
| 11745 | "}\n"; |
| 11746 | |
| 11747 | VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this); |
| 11748 | VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this); |
| 11749 | |
| 11750 | VkPipelineObj pipe(m_device); |
| 11751 | pipe.AddColorAttachment(); |
| 11752 | pipe.AddShader(&vs); |
| 11753 | pipe.AddShader(&fs); |
| 11754 | |
| 11755 | pipe.AddVertexInputBindings(input_bindings, 1); |
| 11756 | pipe.AddVertexInputAttribs(input_attribs, 4); |
| 11757 | |
| 11758 | VkDescriptorSetObj descriptorSet(m_device); |
| 11759 | descriptorSet.AppendDummy(); |
| 11760 | descriptorSet.CreateVKDescriptorSet(m_commandBuffer); |
| 11761 | |
| 11762 | pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass()); |
| 11763 | |
| 11764 | m_errorMonitor->VerifyNotFound(); |
| 11765 | } |
| 11766 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 11767 | TEST_F(VkLayerTest, CreatePipelineFragmentOutputNotWritten) { |
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 | "Attachment 0 not written by FS"); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 11770 | |
Chris Forbes | 4d6d1e5 | 2015-05-25 11:13:40 +1200 | [diff] [blame] | 11771 | ASSERT_NO_FATAL_FAILURE(InitState()); |
Chris Forbes | 4d6d1e5 | 2015-05-25 11:13:40 +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 | 4d6d1e5 | 2015-05-25 11:13:40 +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 | 4d6d1e5 | 2015-05-25 11:13:40 +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 | 4d6d1e5 | 2015-05-25 11:13:40 +1200 | [diff] [blame] | 11784 | "\n" |
| 11785 | "void main(){\n" |
| 11786 | "}\n"; |
| 11787 | |
Courtney Goeltzenleuchter | d263550 | 2015-10-21 17:08:06 -0600 | [diff] [blame] | 11788 | VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this); |
| 11789 | VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this); |
Chris Forbes | 4d6d1e5 | 2015-05-25 11:13:40 +1200 | [diff] [blame] | 11790 | |
| 11791 | VkPipelineObj pipe(m_device); |
| 11792 | pipe.AddShader(&vs); |
| 11793 | pipe.AddShader(&fs); |
| 11794 | |
Chia-I Wu | 08accc6 | 2015-07-07 11:50:03 +0800 | [diff] [blame] | 11795 | /* set up CB 0, not written */ |
| 11796 | pipe.AddColorAttachment(); |
| 11797 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
Chris Forbes | 4d6d1e5 | 2015-05-25 11:13:40 +1200 | [diff] [blame] | 11798 | |
Chris Forbes | 4d6d1e5 | 2015-05-25 11:13:40 +1200 | [diff] [blame] | 11799 | VkDescriptorSetObj descriptorSet(m_device); |
| 11800 | descriptorSet.AppendDummy(); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 11801 | descriptorSet.CreateVKDescriptorSet(m_commandBuffer); |
Chris Forbes | 4d6d1e5 | 2015-05-25 11:13:40 +1200 | [diff] [blame] | 11802 | |
Tony Barbour | 5781e8f | 2015-08-04 16:23:11 -0600 | [diff] [blame] | 11803 | pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass()); |
Chris Forbes | 4d6d1e5 | 2015-05-25 11:13:40 +1200 | [diff] [blame] | 11804 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 11805 | m_errorMonitor->VerifyFound(); |
Chris Forbes | 4d6d1e5 | 2015-05-25 11:13:40 +1200 | [diff] [blame] | 11806 | } |
| 11807 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 11808 | TEST_F(VkLayerTest, CreatePipelineFragmentOutputNotConsumed) { |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 11809 | m_errorMonitor->SetDesiredFailureMsg( |
Mark Lobodzinski | 510e20d | 2016-02-11 09:26:16 -0700 | [diff] [blame] | 11810 | VK_DEBUG_REPORT_WARNING_BIT_EXT, |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 11811 | "FS writes to output location 1 with no matching attachment"); |
| 11812 | |
Chris Forbes | f3fffaa | 2015-05-25 11:13:43 +1200 | [diff] [blame] | 11813 | ASSERT_NO_FATAL_FAILURE(InitState()); |
Chris Forbes | f3fffaa | 2015-05-25 11:13:43 +1200 | [diff] [blame] | 11814 | |
| 11815 | char const *vsSource = |
Chris Forbes | 3846771 | 2016-04-04 17:28:05 +1200 | [diff] [blame] | 11816 | "#version 450\n" |
Chris Forbes | f3fffaa | 2015-05-25 11:13:43 +1200 | [diff] [blame] | 11817 | "\n" |
Tony Barbour | e804d20 | 2016-01-05 13:37:45 -0700 | [diff] [blame] | 11818 | "out gl_PerVertex {\n" |
| 11819 | " vec4 gl_Position;\n" |
| 11820 | "};\n" |
Chris Forbes | f3fffaa | 2015-05-25 11:13:43 +1200 | [diff] [blame] | 11821 | "void main(){\n" |
| 11822 | " gl_Position = vec4(1);\n" |
| 11823 | "}\n"; |
| 11824 | char const *fsSource = |
Chris Forbes | 3846771 | 2016-04-04 17:28:05 +1200 | [diff] [blame] | 11825 | "#version 450\n" |
Chris Forbes | f3fffaa | 2015-05-25 11:13:43 +1200 | [diff] [blame] | 11826 | "\n" |
| 11827 | "layout(location=0) out vec4 x;\n" |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 11828 | "layout(location=1) out vec4 y;\n" /* no matching attachment for this */ |
Chris Forbes | f3fffaa | 2015-05-25 11:13:43 +1200 | [diff] [blame] | 11829 | "void main(){\n" |
| 11830 | " x = vec4(1);\n" |
| 11831 | " y = vec4(1);\n" |
| 11832 | "}\n"; |
| 11833 | |
Courtney Goeltzenleuchter | d263550 | 2015-10-21 17:08:06 -0600 | [diff] [blame] | 11834 | VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this); |
| 11835 | VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this); |
Chris Forbes | f3fffaa | 2015-05-25 11:13:43 +1200 | [diff] [blame] | 11836 | |
| 11837 | VkPipelineObj pipe(m_device); |
| 11838 | pipe.AddShader(&vs); |
| 11839 | pipe.AddShader(&fs); |
| 11840 | |
Chia-I Wu | 08accc6 | 2015-07-07 11:50:03 +0800 | [diff] [blame] | 11841 | /* set up CB 0, not written */ |
| 11842 | pipe.AddColorAttachment(); |
| 11843 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
Chris Forbes | f3fffaa | 2015-05-25 11:13:43 +1200 | [diff] [blame] | 11844 | /* FS writes CB 1, but we don't configure it */ |
| 11845 | |
Chris Forbes | f3fffaa | 2015-05-25 11:13:43 +1200 | [diff] [blame] | 11846 | VkDescriptorSetObj descriptorSet(m_device); |
| 11847 | descriptorSet.AppendDummy(); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 11848 | descriptorSet.CreateVKDescriptorSet(m_commandBuffer); |
Chris Forbes | f3fffaa | 2015-05-25 11:13:43 +1200 | [diff] [blame] | 11849 | |
Tony Barbour | 5781e8f | 2015-08-04 16:23:11 -0600 | [diff] [blame] | 11850 | pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass()); |
Chris Forbes | f3fffaa | 2015-05-25 11:13:43 +1200 | [diff] [blame] | 11851 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 11852 | m_errorMonitor->VerifyFound(); |
Chris Forbes | f3fffaa | 2015-05-25 11:13:43 +1200 | [diff] [blame] | 11853 | } |
| 11854 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 11855 | TEST_F(VkLayerTest, CreatePipelineFragmentOutputTypeMismatch) { |
Courtney Goeltzenleuchter | 7415d5a | 2015-12-09 15:48:16 -0700 | [diff] [blame] | 11856 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 11857 | "does not match FS output type"); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 11858 | |
Chris Forbes | a36d69e | 2015-05-25 11:13:44 +1200 | [diff] [blame] | 11859 | ASSERT_NO_FATAL_FAILURE(InitState()); |
Chris Forbes | a36d69e | 2015-05-25 11:13:44 +1200 | [diff] [blame] | 11860 | |
| 11861 | char const *vsSource = |
Chris Forbes | 3846771 | 2016-04-04 17:28:05 +1200 | [diff] [blame] | 11862 | "#version 450\n" |
Chris Forbes | a36d69e | 2015-05-25 11:13:44 +1200 | [diff] [blame] | 11863 | "\n" |
Tony Barbour | e804d20 | 2016-01-05 13:37:45 -0700 | [diff] [blame] | 11864 | "out gl_PerVertex {\n" |
| 11865 | " vec4 gl_Position;\n" |
| 11866 | "};\n" |
Chris Forbes | a36d69e | 2015-05-25 11:13:44 +1200 | [diff] [blame] | 11867 | "void main(){\n" |
| 11868 | " gl_Position = vec4(1);\n" |
| 11869 | "}\n"; |
| 11870 | char const *fsSource = |
Chris Forbes | 3846771 | 2016-04-04 17:28:05 +1200 | [diff] [blame] | 11871 | "#version 450\n" |
Chris Forbes | a36d69e | 2015-05-25 11:13:44 +1200 | [diff] [blame] | 11872 | "\n" |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 11873 | "layout(location=0) out ivec4 x;\n" /* not UNORM */ |
Chris Forbes | a36d69e | 2015-05-25 11:13:44 +1200 | [diff] [blame] | 11874 | "void main(){\n" |
| 11875 | " x = ivec4(1);\n" |
| 11876 | "}\n"; |
| 11877 | |
Courtney Goeltzenleuchter | d263550 | 2015-10-21 17:08:06 -0600 | [diff] [blame] | 11878 | VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this); |
| 11879 | VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this); |
Chris Forbes | a36d69e | 2015-05-25 11:13:44 +1200 | [diff] [blame] | 11880 | |
| 11881 | VkPipelineObj pipe(m_device); |
| 11882 | pipe.AddShader(&vs); |
| 11883 | pipe.AddShader(&fs); |
| 11884 | |
Chia-I Wu | 08accc6 | 2015-07-07 11:50:03 +0800 | [diff] [blame] | 11885 | /* set up CB 0; type is UNORM by default */ |
| 11886 | pipe.AddColorAttachment(); |
| 11887 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
Chris Forbes | a36d69e | 2015-05-25 11:13:44 +1200 | [diff] [blame] | 11888 | |
Chris Forbes | a36d69e | 2015-05-25 11:13:44 +1200 | [diff] [blame] | 11889 | VkDescriptorSetObj descriptorSet(m_device); |
| 11890 | descriptorSet.AppendDummy(); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 11891 | descriptorSet.CreateVKDescriptorSet(m_commandBuffer); |
Chris Forbes | a36d69e | 2015-05-25 11:13:44 +1200 | [diff] [blame] | 11892 | |
Tony Barbour | 5781e8f | 2015-08-04 16:23:11 -0600 | [diff] [blame] | 11893 | pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass()); |
Chris Forbes | a36d69e | 2015-05-25 11:13:44 +1200 | [diff] [blame] | 11894 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 11895 | m_errorMonitor->VerifyFound(); |
Chris Forbes | a36d69e | 2015-05-25 11:13:44 +1200 | [diff] [blame] | 11896 | } |
Chris Forbes | 7b1b893 | 2015-06-05 14:43:36 +1200 | [diff] [blame] | 11897 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 11898 | TEST_F(VkLayerTest, CreatePipelineUniformBlockNotProvided) { |
Courtney Goeltzenleuchter | 7415d5a | 2015-12-09 15:48:16 -0700 | [diff] [blame] | 11899 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 11900 | "not declared in pipeline layout"); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 11901 | |
Chris Forbes | 556c76c | 2015-08-14 12:04:59 +1200 | [diff] [blame] | 11902 | ASSERT_NO_FATAL_FAILURE(InitState()); |
Chris Forbes | 556c76c | 2015-08-14 12:04:59 +1200 | [diff] [blame] | 11903 | |
| 11904 | char const *vsSource = |
Chris Forbes | 3846771 | 2016-04-04 17:28:05 +1200 | [diff] [blame] | 11905 | "#version 450\n" |
Chris Forbes | 556c76c | 2015-08-14 12:04:59 +1200 | [diff] [blame] | 11906 | "\n" |
Tony Barbour | e804d20 | 2016-01-05 13:37:45 -0700 | [diff] [blame] | 11907 | "out gl_PerVertex {\n" |
| 11908 | " vec4 gl_Position;\n" |
| 11909 | "};\n" |
Chris Forbes | 556c76c | 2015-08-14 12:04:59 +1200 | [diff] [blame] | 11910 | "void main(){\n" |
| 11911 | " gl_Position = vec4(1);\n" |
| 11912 | "}\n"; |
| 11913 | char const *fsSource = |
Chris Forbes | 3846771 | 2016-04-04 17:28:05 +1200 | [diff] [blame] | 11914 | "#version 450\n" |
Chris Forbes | 556c76c | 2015-08-14 12:04:59 +1200 | [diff] [blame] | 11915 | "\n" |
| 11916 | "layout(location=0) out vec4 x;\n" |
| 11917 | "layout(set=0) layout(binding=0) uniform foo { int x; int y; } bar;\n" |
| 11918 | "void main(){\n" |
| 11919 | " x = vec4(bar.y);\n" |
| 11920 | "}\n"; |
| 11921 | |
Courtney Goeltzenleuchter | d263550 | 2015-10-21 17:08:06 -0600 | [diff] [blame] | 11922 | VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this); |
| 11923 | VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this); |
Chris Forbes | 556c76c | 2015-08-14 12:04:59 +1200 | [diff] [blame] | 11924 | |
Chris Forbes | 556c76c | 2015-08-14 12:04:59 +1200 | [diff] [blame] | 11925 | VkPipelineObj pipe(m_device); |
| 11926 | pipe.AddShader(&vs); |
| 11927 | pipe.AddShader(&fs); |
| 11928 | |
| 11929 | /* set up CB 0; type is UNORM by default */ |
| 11930 | pipe.AddColorAttachment(); |
| 11931 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 11932 | |
| 11933 | VkDescriptorSetObj descriptorSet(m_device); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 11934 | descriptorSet.CreateVKDescriptorSet(m_commandBuffer); |
Chris Forbes | 556c76c | 2015-08-14 12:04:59 +1200 | [diff] [blame] | 11935 | |
| 11936 | pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass()); |
| 11937 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 11938 | m_errorMonitor->VerifyFound(); |
Chris Forbes | 556c76c | 2015-08-14 12:04:59 +1200 | [diff] [blame] | 11939 | } |
| 11940 | |
Chris Forbes | 5c59e90 | 2016-02-26 16:56:09 +1300 | [diff] [blame] | 11941 | TEST_F(VkLayerTest, CreatePipelinePushConstantsNotInLayout) { |
| 11942 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 11943 | "not declared in layout"); |
| 11944 | |
| 11945 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 11946 | |
| 11947 | char const *vsSource = |
| 11948 | "#version 450\n" |
Chris Forbes | 5c59e90 | 2016-02-26 16:56:09 +1300 | [diff] [blame] | 11949 | "\n" |
| 11950 | "layout(push_constant, std430) uniform foo { float x; } consts;\n" |
| 11951 | "out gl_PerVertex {\n" |
| 11952 | " vec4 gl_Position;\n" |
| 11953 | "};\n" |
| 11954 | "void main(){\n" |
| 11955 | " gl_Position = vec4(consts.x);\n" |
| 11956 | "}\n"; |
| 11957 | char const *fsSource = |
| 11958 | "#version 450\n" |
Chris Forbes | 5c59e90 | 2016-02-26 16:56:09 +1300 | [diff] [blame] | 11959 | "\n" |
| 11960 | "layout(location=0) out vec4 x;\n" |
| 11961 | "void main(){\n" |
| 11962 | " x = vec4(1);\n" |
| 11963 | "}\n"; |
| 11964 | |
| 11965 | VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this); |
| 11966 | VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this); |
| 11967 | |
| 11968 | VkPipelineObj pipe(m_device); |
| 11969 | pipe.AddShader(&vs); |
| 11970 | pipe.AddShader(&fs); |
| 11971 | |
| 11972 | /* set up CB 0; type is UNORM by default */ |
| 11973 | pipe.AddColorAttachment(); |
| 11974 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 11975 | |
| 11976 | VkDescriptorSetObj descriptorSet(m_device); |
| 11977 | descriptorSet.CreateVKDescriptorSet(m_commandBuffer); |
| 11978 | |
| 11979 | pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass()); |
| 11980 | |
| 11981 | /* should have generated an error -- no push constant ranges provided! */ |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 11982 | m_errorMonitor->VerifyFound(); |
Chris Forbes | 5c59e90 | 2016-02-26 16:56:09 +1300 | [diff] [blame] | 11983 | } |
| 11984 | |
Chris Forbes | 10eb9ae | 2016-05-31 16:09:42 +1200 | [diff] [blame] | 11985 | TEST_F(VkLayerTest, CreateComputePipelineMissingDescriptor) { |
| 11986 | m_errorMonitor->SetDesiredFailureMsg( |
| 11987 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 11988 | "Shader uses descriptor slot 0.0"); |
| 11989 | |
| 11990 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 11991 | |
| 11992 | char const *csSource = |
| 11993 | "#version 450\n" |
| 11994 | "\n" |
| 11995 | "layout(local_size_x=1) in;\n" |
| 11996 | "layout(set=0, binding=0) buffer block { vec4 x; };\n" |
| 11997 | "void main(){\n" |
| 11998 | " x = vec4(1);\n" |
| 11999 | "}\n"; |
| 12000 | |
| 12001 | VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this); |
| 12002 | |
| 12003 | VkDescriptorSetObj descriptorSet(m_device); |
| 12004 | descriptorSet.CreateVKDescriptorSet(m_commandBuffer); |
| 12005 | |
| 12006 | VkComputePipelineCreateInfo cpci = { |
| 12007 | VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO, |
| 12008 | nullptr, 0, { |
| 12009 | VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, |
| 12010 | nullptr, 0, VK_SHADER_STAGE_COMPUTE_BIT, |
| 12011 | cs.handle(), "main", nullptr |
| 12012 | }, |
| 12013 | descriptorSet.GetPipelineLayout(), |
| 12014 | VK_NULL_HANDLE, -1 |
| 12015 | }; |
| 12016 | |
| 12017 | VkPipeline pipe; |
| 12018 | VkResult err = vkCreateComputePipelines( |
| 12019 | m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe); |
| 12020 | |
| 12021 | m_errorMonitor->VerifyFound(); |
| 12022 | |
| 12023 | if (err == VK_SUCCESS) { |
| 12024 | vkDestroyPipeline(m_device->device(), pipe, nullptr); |
| 12025 | } |
| 12026 | } |
| 12027 | |
| 12028 | TEST_F(VkLayerTest, CreateComputePipelineMissingDescriptorUnusedPositive) { |
| 12029 | m_errorMonitor->ExpectSuccess(); |
| 12030 | |
| 12031 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 12032 | |
| 12033 | char const *csSource = |
| 12034 | "#version 450\n" |
| 12035 | "\n" |
| 12036 | "layout(local_size_x=1) in;\n" |
| 12037 | "layout(set=0, binding=0) buffer block { vec4 x; };\n" |
| 12038 | "void main(){\n" |
| 12039 | " // x is not used.\n" |
| 12040 | "}\n"; |
| 12041 | |
| 12042 | VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this); |
| 12043 | |
| 12044 | VkDescriptorSetObj descriptorSet(m_device); |
| 12045 | descriptorSet.CreateVKDescriptorSet(m_commandBuffer); |
| 12046 | |
| 12047 | VkComputePipelineCreateInfo cpci = { |
| 12048 | VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO, |
| 12049 | nullptr, 0, { |
| 12050 | VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, |
| 12051 | nullptr, 0, VK_SHADER_STAGE_COMPUTE_BIT, |
| 12052 | cs.handle(), "main", nullptr |
| 12053 | }, |
| 12054 | descriptorSet.GetPipelineLayout(), |
| 12055 | VK_NULL_HANDLE, -1 |
| 12056 | }; |
| 12057 | |
| 12058 | VkPipeline pipe; |
| 12059 | VkResult err = vkCreateComputePipelines( |
| 12060 | m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe); |
| 12061 | |
| 12062 | m_errorMonitor->VerifyNotFound(); |
| 12063 | |
| 12064 | if (err == VK_SUCCESS) { |
| 12065 | vkDestroyPipeline(m_device->device(), pipe, nullptr); |
| 12066 | } |
| 12067 | } |
| 12068 | |
Mark Lobodzinski | 209b529 | 2015-09-17 09:44:05 -0600 | [diff] [blame] | 12069 | #endif // SHADER_CHECKER_TESTS |
| 12070 | |
| 12071 | #if DEVICE_LIMITS_TESTS |
Mark Young | c48c4c1 | 2016-04-11 14:26:49 -0600 | [diff] [blame] | 12072 | TEST_F(VkLayerTest, CreateImageLimitsViolationMaxWidth) { |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12073 | m_errorMonitor->SetDesiredFailureMsg( |
| 12074 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 12075 | "CreateImage extents exceed allowable limits for format"); |
Mark Lobodzinski | 6f2274e | 2015-09-22 09:33:21 -0600 | [diff] [blame] | 12076 | |
| 12077 | ASSERT_NO_FATAL_FAILURE(InitState()); |
Mark Lobodzinski | 6f2274e | 2015-09-22 09:33:21 -0600 | [diff] [blame] | 12078 | |
| 12079 | // Create an image |
| 12080 | VkImage image; |
| 12081 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12082 | const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM; |
| 12083 | const int32_t tex_width = 32; |
| 12084 | const int32_t tex_height = 32; |
Mark Lobodzinski | 6f2274e | 2015-09-22 09:33:21 -0600 | [diff] [blame] | 12085 | |
| 12086 | VkImageCreateInfo image_create_info = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12087 | image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO; |
| 12088 | image_create_info.pNext = NULL; |
| 12089 | image_create_info.imageType = VK_IMAGE_TYPE_2D; |
| 12090 | image_create_info.format = tex_format; |
| 12091 | image_create_info.extent.width = tex_width; |
Mark Lobodzinski | 6f2274e | 2015-09-22 09:33:21 -0600 | [diff] [blame] | 12092 | image_create_info.extent.height = tex_height; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12093 | image_create_info.extent.depth = 1; |
| 12094 | image_create_info.mipLevels = 1; |
| 12095 | image_create_info.arrayLayers = 1; |
| 12096 | image_create_info.samples = VK_SAMPLE_COUNT_1_BIT; |
| 12097 | image_create_info.tiling = VK_IMAGE_TILING_LINEAR; |
| 12098 | image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT; |
| 12099 | image_create_info.flags = 0; |
Mark Lobodzinski | 6f2274e | 2015-09-22 09:33:21 -0600 | [diff] [blame] | 12100 | |
| 12101 | // Introduce error by sending down a bogus width extent |
| 12102 | image_create_info.extent.width = 65536; |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 12103 | vkCreateImage(m_device->device(), &image_create_info, NULL, &image); |
Mark Lobodzinski | 6f2274e | 2015-09-22 09:33:21 -0600 | [diff] [blame] | 12104 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 12105 | m_errorMonitor->VerifyFound(); |
Mark Lobodzinski | 6f2274e | 2015-09-22 09:33:21 -0600 | [diff] [blame] | 12106 | } |
| 12107 | |
Mark Young | c48c4c1 | 2016-04-11 14:26:49 -0600 | [diff] [blame] | 12108 | TEST_F(VkLayerTest, CreateImageLimitsViolationMinWidth) { |
| 12109 | m_errorMonitor->SetDesiredFailureMsg( |
| 12110 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 12111 | "CreateImage extents is 0 for at least one required dimension"); |
| 12112 | |
| 12113 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 12114 | |
| 12115 | // Create an image |
| 12116 | VkImage image; |
| 12117 | |
| 12118 | const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM; |
| 12119 | const int32_t tex_width = 32; |
| 12120 | const int32_t tex_height = 32; |
| 12121 | |
| 12122 | VkImageCreateInfo image_create_info = {}; |
| 12123 | image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO; |
| 12124 | image_create_info.pNext = NULL; |
| 12125 | image_create_info.imageType = VK_IMAGE_TYPE_2D; |
| 12126 | image_create_info.format = tex_format; |
| 12127 | image_create_info.extent.width = tex_width; |
| 12128 | image_create_info.extent.height = tex_height; |
| 12129 | image_create_info.extent.depth = 1; |
| 12130 | image_create_info.mipLevels = 1; |
| 12131 | image_create_info.arrayLayers = 1; |
| 12132 | image_create_info.samples = VK_SAMPLE_COUNT_1_BIT; |
| 12133 | image_create_info.tiling = VK_IMAGE_TILING_LINEAR; |
| 12134 | image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT; |
| 12135 | image_create_info.flags = 0; |
| 12136 | |
| 12137 | // Introduce error by sending down a bogus width extent |
| 12138 | image_create_info.extent.width = 0; |
| 12139 | vkCreateImage(m_device->device(), &image_create_info, NULL, &image); |
| 12140 | |
| 12141 | m_errorMonitor->VerifyFound(); |
| 12142 | } |
Mark Lobodzinski | 209b529 | 2015-09-17 09:44:05 -0600 | [diff] [blame] | 12143 | #endif // DEVICE_LIMITS_TESTS |
Chris Forbes | a36d69e | 2015-05-25 11:13:44 +1200 | [diff] [blame] | 12144 | |
Tobin Ehlis | cde0889 | 2015-09-22 10:11:37 -0600 | [diff] [blame] | 12145 | #if IMAGE_TESTS |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12146 | TEST_F(VkLayerTest, InvalidImageView) { |
| 12147 | VkResult err; |
Tobin Ehlis | cde0889 | 2015-09-22 10:11:37 -0600 | [diff] [blame] | 12148 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12149 | m_errorMonitor->SetDesiredFailureMsg( |
| 12150 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 12151 | "vkCreateImageView called with baseMipLevel 10 "); |
| 12152 | |
Tobin Ehlis | cde0889 | 2015-09-22 10:11:37 -0600 | [diff] [blame] | 12153 | ASSERT_NO_FATAL_FAILURE(InitState()); |
Tobin Ehlis | cde0889 | 2015-09-22 10:11:37 -0600 | [diff] [blame] | 12154 | |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12155 | // Create an image and try to create a view with bad baseMipLevel |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12156 | VkImage image; |
Tobin Ehlis | cde0889 | 2015-09-22 10:11:37 -0600 | [diff] [blame] | 12157 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12158 | const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM; |
| 12159 | const int32_t tex_width = 32; |
| 12160 | const int32_t tex_height = 32; |
Tobin Ehlis | cde0889 | 2015-09-22 10:11:37 -0600 | [diff] [blame] | 12161 | |
| 12162 | VkImageCreateInfo image_create_info = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12163 | image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO; |
| 12164 | image_create_info.pNext = NULL; |
| 12165 | image_create_info.imageType = VK_IMAGE_TYPE_2D; |
| 12166 | image_create_info.format = tex_format; |
| 12167 | image_create_info.extent.width = tex_width; |
| 12168 | image_create_info.extent.height = tex_height; |
| 12169 | image_create_info.extent.depth = 1; |
| 12170 | image_create_info.mipLevels = 1; |
| 12171 | image_create_info.arrayLayers = 1; |
| 12172 | image_create_info.samples = VK_SAMPLE_COUNT_1_BIT; |
| 12173 | image_create_info.tiling = VK_IMAGE_TILING_LINEAR; |
| 12174 | image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT; |
| 12175 | image_create_info.flags = 0; |
Tobin Ehlis | cde0889 | 2015-09-22 10:11:37 -0600 | [diff] [blame] | 12176 | |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 12177 | err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image); |
Tobin Ehlis | cde0889 | 2015-09-22 10:11:37 -0600 | [diff] [blame] | 12178 | ASSERT_VK_SUCCESS(err); |
| 12179 | |
| 12180 | VkImageViewCreateInfo image_view_create_info = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12181 | image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO; |
| 12182 | image_view_create_info.image = image; |
| 12183 | image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D; |
| 12184 | image_view_create_info.format = tex_format; |
| 12185 | image_view_create_info.subresourceRange.layerCount = 1; |
| 12186 | image_view_create_info.subresourceRange.baseMipLevel = 10; // cause an error |
| 12187 | image_view_create_info.subresourceRange.levelCount = 1; |
| 12188 | image_view_create_info.subresourceRange.aspectMask = |
| 12189 | VK_IMAGE_ASPECT_COLOR_BIT; |
Tobin Ehlis | cde0889 | 2015-09-22 10:11:37 -0600 | [diff] [blame] | 12190 | |
| 12191 | VkImageView view; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12192 | err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, |
| 12193 | &view); |
Tobin Ehlis | cde0889 | 2015-09-22 10:11:37 -0600 | [diff] [blame] | 12194 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 12195 | m_errorMonitor->VerifyFound(); |
Tony Barbour | df4c004 | 2016-06-01 15:55:43 -0600 | [diff] [blame] | 12196 | vkDestroyImage(m_device->device(), image, NULL); |
Tobin Ehlis | cde0889 | 2015-09-22 10:11:37 -0600 | [diff] [blame] | 12197 | } |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12198 | |
Mark Young | d339ba3 | 2016-05-30 13:28:35 -0600 | [diff] [blame] | 12199 | TEST_F(VkLayerTest, CreateImageViewNoMemoryBoundToImage) { |
| 12200 | VkResult err; |
| 12201 | |
| 12202 | m_errorMonitor->SetDesiredFailureMsg( |
| 12203 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 12204 | "vkCreateImageView called with invalid memory "); |
| 12205 | |
| 12206 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 12207 | |
| 12208 | // Create an image and try to create a view with no memory backing the image |
| 12209 | VkImage image; |
| 12210 | |
| 12211 | const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM; |
| 12212 | const int32_t tex_width = 32; |
| 12213 | const int32_t tex_height = 32; |
| 12214 | |
| 12215 | VkImageCreateInfo image_create_info = {}; |
| 12216 | image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO; |
| 12217 | image_create_info.pNext = NULL; |
| 12218 | image_create_info.imageType = VK_IMAGE_TYPE_2D; |
| 12219 | image_create_info.format = tex_format; |
| 12220 | image_create_info.extent.width = tex_width; |
| 12221 | image_create_info.extent.height = tex_height; |
| 12222 | image_create_info.extent.depth = 1; |
| 12223 | image_create_info.mipLevels = 1; |
| 12224 | image_create_info.arrayLayers = 1; |
| 12225 | image_create_info.samples = VK_SAMPLE_COUNT_1_BIT; |
| 12226 | image_create_info.tiling = VK_IMAGE_TILING_LINEAR; |
| 12227 | image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT; |
| 12228 | image_create_info.flags = 0; |
| 12229 | |
| 12230 | err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image); |
| 12231 | ASSERT_VK_SUCCESS(err); |
| 12232 | |
| 12233 | VkImageViewCreateInfo image_view_create_info = {}; |
| 12234 | image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO; |
| 12235 | image_view_create_info.image = image; |
| 12236 | image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D; |
| 12237 | image_view_create_info.format = tex_format; |
| 12238 | image_view_create_info.subresourceRange.layerCount = 1; |
| 12239 | image_view_create_info.subresourceRange.baseMipLevel = 0; |
| 12240 | image_view_create_info.subresourceRange.levelCount = 1; |
| 12241 | image_view_create_info.subresourceRange.aspectMask = |
| 12242 | VK_IMAGE_ASPECT_COLOR_BIT; |
| 12243 | |
| 12244 | VkImageView view; |
| 12245 | err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, |
| 12246 | &view); |
| 12247 | |
| 12248 | m_errorMonitor->VerifyFound(); |
| 12249 | vkDestroyImage(m_device->device(), image, NULL); |
| 12250 | // If last error is success, it still created the view, so delete it. |
| 12251 | if (err == VK_SUCCESS) { |
| 12252 | vkDestroyImageView(m_device->device(), view, NULL); |
| 12253 | } |
| 12254 | |
| 12255 | } |
| 12256 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12257 | TEST_F(VkLayerTest, InvalidImageViewAspect) { |
Tobin Ehlis | 1f567a2 | 2016-05-25 16:15:18 -0600 | [diff] [blame] | 12258 | TEST_DESCRIPTION( |
| 12259 | "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] | 12260 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12261 | "vkCreateImageView: Color image " |
| 12262 | "formats must have ONLY the " |
| 12263 | "VK_IMAGE_ASPECT_COLOR_BIT set"); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 12264 | |
Mark Lobodzinski | dc86b85 | 2015-10-23 14:20:31 -0600 | [diff] [blame] | 12265 | ASSERT_NO_FATAL_FAILURE(InitState()); |
Mark Lobodzinski | dc86b85 | 2015-10-23 14:20:31 -0600 | [diff] [blame] | 12266 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12267 | const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM; |
Tobin Ehlis | 1f567a2 | 2016-05-25 16:15:18 -0600 | [diff] [blame] | 12268 | VkImageObj image(m_device); |
| 12269 | image.init(32, 32, tex_format, VK_IMAGE_USAGE_SAMPLED_BIT, |
| 12270 | VK_IMAGE_TILING_LINEAR, 0); |
| 12271 | ASSERT_TRUE(image.initialized()); |
Mark Lobodzinski | dc86b85 | 2015-10-23 14:20:31 -0600 | [diff] [blame] | 12272 | |
| 12273 | VkImageViewCreateInfo image_view_create_info = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12274 | image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO; |
Tobin Ehlis | 1f567a2 | 2016-05-25 16:15:18 -0600 | [diff] [blame] | 12275 | image_view_create_info.image = image.handle(); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12276 | image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D; |
| 12277 | image_view_create_info.format = tex_format; |
| 12278 | image_view_create_info.subresourceRange.baseMipLevel = 0; |
| 12279 | image_view_create_info.subresourceRange.levelCount = 1; |
| 12280 | // Cause an error by setting an invalid image aspect |
| 12281 | image_view_create_info.subresourceRange.aspectMask = |
| 12282 | VK_IMAGE_ASPECT_METADATA_BIT; |
Mark Lobodzinski | dc86b85 | 2015-10-23 14:20:31 -0600 | [diff] [blame] | 12283 | |
| 12284 | VkImageView view; |
Tobin Ehlis | 1f567a2 | 2016-05-25 16:15:18 -0600 | [diff] [blame] | 12285 | vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view); |
Mark Lobodzinski | dc86b85 | 2015-10-23 14:20:31 -0600 | [diff] [blame] | 12286 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 12287 | m_errorMonitor->VerifyFound(); |
Mark Lobodzinski | dc86b85 | 2015-10-23 14:20:31 -0600 | [diff] [blame] | 12288 | } |
| 12289 | |
Mark Lobodzinski | db11763 | 2016-03-31 10:45:56 -0600 | [diff] [blame] | 12290 | TEST_F(VkLayerTest, CopyImageLayerCountMismatch) { |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12291 | VkResult err; |
| 12292 | bool pass; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12293 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12294 | m_errorMonitor->SetDesiredFailureMsg( |
| 12295 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Mark Lobodzinski | db11763 | 2016-03-31 10:45:56 -0600 | [diff] [blame] | 12296 | "vkCmdCopyImage: number of layers in source and destination subresources for pRegions"); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 12297 | |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12298 | ASSERT_NO_FATAL_FAILURE(InitState()); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12299 | |
| 12300 | // Create two images of different types and try to copy between them |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12301 | VkImage srcImage; |
| 12302 | VkImage dstImage; |
| 12303 | VkDeviceMemory srcMem; |
| 12304 | VkDeviceMemory destMem; |
| 12305 | VkMemoryRequirements memReqs; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12306 | |
| 12307 | VkImageCreateInfo image_create_info = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12308 | image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO; |
| 12309 | image_create_info.pNext = NULL; |
| 12310 | image_create_info.imageType = VK_IMAGE_TYPE_2D; |
| 12311 | image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM; |
| 12312 | image_create_info.extent.width = 32; |
| 12313 | image_create_info.extent.height = 32; |
| 12314 | image_create_info.extent.depth = 1; |
| 12315 | image_create_info.mipLevels = 1; |
Mark Lobodzinski | db11763 | 2016-03-31 10:45:56 -0600 | [diff] [blame] | 12316 | image_create_info.arrayLayers = 4; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12317 | image_create_info.samples = VK_SAMPLE_COUNT_1_BIT; |
| 12318 | image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL; |
| 12319 | image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT; |
| 12320 | image_create_info.flags = 0; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12321 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12322 | err = |
| 12323 | vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12324 | ASSERT_VK_SUCCESS(err); |
| 12325 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12326 | err = |
| 12327 | vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12328 | ASSERT_VK_SUCCESS(err); |
| 12329 | |
| 12330 | // Allocate memory |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 12331 | VkMemoryAllocateInfo memAlloc = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12332 | memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO; |
| 12333 | memAlloc.pNext = NULL; |
| 12334 | memAlloc.allocationSize = 0; |
| 12335 | memAlloc.memoryTypeIndex = 0; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12336 | |
Courtney Goeltzenleuchter | 06d8947 | 2015-10-20 16:40:38 -0600 | [diff] [blame] | 12337 | vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12338 | memAlloc.allocationSize = memReqs.size; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12339 | pass = |
| 12340 | m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0); |
Courtney Goeltzenleuchter | 1d2f0dd | 2015-10-22 11:03:31 -0600 | [diff] [blame] | 12341 | ASSERT_TRUE(pass); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 12342 | err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12343 | ASSERT_VK_SUCCESS(err); |
| 12344 | |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 12345 | vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12346 | memAlloc.allocationSize = memReqs.size; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12347 | pass = |
| 12348 | m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12349 | ASSERT_VK_SUCCESS(err); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 12350 | err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12351 | ASSERT_VK_SUCCESS(err); |
| 12352 | |
| 12353 | err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0); |
| 12354 | ASSERT_VK_SUCCESS(err); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 12355 | err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12356 | ASSERT_VK_SUCCESS(err); |
| 12357 | |
| 12358 | BeginCommandBuffer(); |
| 12359 | VkImageCopy copyRegion; |
Chia-I Wu | ab83a0e | 2015-10-27 19:00:15 +0800 | [diff] [blame] | 12360 | copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12361 | copyRegion.srcSubresource.mipLevel = 0; |
Courtney Goeltzenleuchter | 8367ce0 | 2015-10-16 09:46:00 -0600 | [diff] [blame] | 12362 | copyRegion.srcSubresource.baseArrayLayer = 0; |
Mark Lobodzinski | db11763 | 2016-03-31 10:45:56 -0600 | [diff] [blame] | 12363 | copyRegion.srcSubresource.layerCount = 1; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12364 | copyRegion.srcOffset.x = 0; |
| 12365 | copyRegion.srcOffset.y = 0; |
| 12366 | copyRegion.srcOffset.z = 0; |
Chia-I Wu | ab83a0e | 2015-10-27 19:00:15 +0800 | [diff] [blame] | 12367 | copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 12368 | copyRegion.dstSubresource.mipLevel = 0; |
| 12369 | copyRegion.dstSubresource.baseArrayLayer = 0; |
Mark Lobodzinski | db11763 | 2016-03-31 10:45:56 -0600 | [diff] [blame] | 12370 | // Introduce failure by forcing the dst layerCount to differ from src |
| 12371 | copyRegion.dstSubresource.layerCount = 3; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 12372 | copyRegion.dstOffset.x = 0; |
| 12373 | copyRegion.dstOffset.y = 0; |
| 12374 | copyRegion.dstOffset.z = 0; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12375 | copyRegion.extent.width = 1; |
| 12376 | copyRegion.extent.height = 1; |
| 12377 | copyRegion.extent.depth = 1; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12378 | m_commandBuffer->CopyImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, |
| 12379 | VK_IMAGE_LAYOUT_GENERAL, 1, ©Region); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12380 | EndCommandBuffer(); |
| 12381 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 12382 | m_errorMonitor->VerifyFound(); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12383 | |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 12384 | vkDestroyImage(m_device->device(), srcImage, NULL); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 12385 | vkDestroyImage(m_device->device(), dstImage, NULL); |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 12386 | vkFreeMemory(m_device->device(), srcMem, NULL); |
| 12387 | vkFreeMemory(m_device->device(), destMem, NULL); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12388 | } |
| 12389 | |
Tony Barbour | d667364 | 2016-05-05 14:46:39 -0600 | [diff] [blame] | 12390 | TEST_F(VkLayerTest, ImageLayerUnsupportedFormat) { |
| 12391 | |
| 12392 | TEST_DESCRIPTION("Creating images with unsuported formats "); |
| 12393 | |
| 12394 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 12395 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 12396 | VkImageObj image(m_device); |
| 12397 | image.init(128, 128, VK_FORMAT_B8G8R8A8_UNORM, |
| 12398 | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | |
| 12399 | VK_IMAGE_USAGE_TRANSFER_DST_BIT, |
| 12400 | VK_IMAGE_TILING_OPTIMAL, 0); |
| 12401 | ASSERT_TRUE(image.initialized()); |
| 12402 | |
Mark Lobodzinski | ba5c686 | 2016-05-17 08:14:00 -0600 | [diff] [blame] | 12403 | // Create image with unsupported format - Expect FORMAT_UNSUPPORTED |
| 12404 | VkImageCreateInfo image_create_info; |
| 12405 | image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO; |
| 12406 | image_create_info.pNext = NULL; |
| 12407 | image_create_info.imageType = VK_IMAGE_TYPE_2D; |
| 12408 | image_create_info.format = VK_FORMAT_UNDEFINED; |
| 12409 | image_create_info.extent.width = 32; |
| 12410 | image_create_info.extent.height = 32; |
| 12411 | image_create_info.extent.depth = 1; |
| 12412 | image_create_info.mipLevels = 1; |
| 12413 | image_create_info.arrayLayers = 1; |
| 12414 | image_create_info.samples = VK_SAMPLE_COUNT_1_BIT; |
| 12415 | image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL; |
| 12416 | image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT; |
| 12417 | image_create_info.flags = 0; |
| 12418 | |
| 12419 | m_errorMonitor->SetDesiredFailureMsg( |
| 12420 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 12421 | "vkCreateImage: VkFormat for image must not be VK_FORMAT_UNDEFINED"); |
| 12422 | |
| 12423 | VkImage localImage; |
| 12424 | vkCreateImage(m_device->handle(), &image_create_info, NULL, &localImage); |
| 12425 | m_errorMonitor->VerifyFound(); |
| 12426 | |
Tony Barbour | d667364 | 2016-05-05 14:46:39 -0600 | [diff] [blame] | 12427 | VkFormat unsupported = VK_FORMAT_UNDEFINED; |
Mark Lobodzinski | ba5c686 | 2016-05-17 08:14:00 -0600 | [diff] [blame] | 12428 | // Look for a format that is COMPLETELY unsupported with this hardware |
Tony Barbour | d667364 | 2016-05-05 14:46:39 -0600 | [diff] [blame] | 12429 | for (int f = VK_FORMAT_BEGIN_RANGE; f <= VK_FORMAT_END_RANGE; f++) { |
| 12430 | VkFormat format = static_cast<VkFormat>(f); |
| 12431 | VkFormatProperties fProps = m_device->format_properties(format); |
| 12432 | if (format != VK_FORMAT_UNDEFINED && fProps.linearTilingFeatures == 0 && |
| 12433 | fProps.optimalTilingFeatures == 0) { |
| 12434 | unsupported = format; |
| 12435 | break; |
| 12436 | } |
| 12437 | } |
Mark Lobodzinski | ba5c686 | 2016-05-17 08:14:00 -0600 | [diff] [blame] | 12438 | |
Tony Barbour | d667364 | 2016-05-05 14:46:39 -0600 | [diff] [blame] | 12439 | if (unsupported != VK_FORMAT_UNDEFINED) { |
Tony Barbour | d667364 | 2016-05-05 14:46:39 -0600 | [diff] [blame] | 12440 | image_create_info.format = unsupported; |
Tony Barbour | d667364 | 2016-05-05 14:46:39 -0600 | [diff] [blame] | 12441 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Mark Lobodzinski | ba5c686 | 2016-05-17 08:14:00 -0600 | [diff] [blame] | 12442 | "is an unsupported format"); |
Tony Barbour | d667364 | 2016-05-05 14:46:39 -0600 | [diff] [blame] | 12443 | |
Mark Lobodzinski | ba5c686 | 2016-05-17 08:14:00 -0600 | [diff] [blame] | 12444 | vkCreateImage(m_device->handle(), &image_create_info, NULL, &localImage); |
Tony Barbour | d667364 | 2016-05-05 14:46:39 -0600 | [diff] [blame] | 12445 | m_errorMonitor->VerifyFound(); |
| 12446 | } |
| 12447 | } |
| 12448 | |
| 12449 | TEST_F(VkLayerTest, ImageLayerViewTests) { |
| 12450 | VkResult ret; |
| 12451 | TEST_DESCRIPTION("Passing bad parameters to CreateImageView"); |
| 12452 | |
| 12453 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 12454 | |
| 12455 | VkImageObj image(m_device); |
| 12456 | image.init(128, 128, VK_FORMAT_B8G8R8A8_UNORM, |
| 12457 | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | |
| 12458 | VK_IMAGE_USAGE_TRANSFER_DST_BIT, |
| 12459 | VK_IMAGE_TILING_OPTIMAL, 0); |
| 12460 | ASSERT_TRUE(image.initialized()); |
| 12461 | |
| 12462 | VkImageView imgView; |
| 12463 | VkImageViewCreateInfo imgViewInfo = {}; |
| 12464 | imgViewInfo.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO; |
| 12465 | imgViewInfo.image = image.handle(); |
| 12466 | imgViewInfo.viewType = VK_IMAGE_VIEW_TYPE_2D; |
| 12467 | imgViewInfo.format = VK_FORMAT_B8G8R8A8_UNORM; |
| 12468 | imgViewInfo.subresourceRange.layerCount = 1; |
| 12469 | imgViewInfo.subresourceRange.baseMipLevel = 0; |
| 12470 | imgViewInfo.subresourceRange.levelCount = 1; |
| 12471 | imgViewInfo.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; |
| 12472 | |
| 12473 | m_errorMonitor->SetDesiredFailureMsg( |
| 12474 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 12475 | "vkCreateImageView called with baseMipLevel"); |
| 12476 | // View can't have baseMipLevel >= image's mipLevels - Expect |
| 12477 | // VIEW_CREATE_ERROR |
| 12478 | imgViewInfo.subresourceRange.baseMipLevel = 1; |
| 12479 | vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView); |
| 12480 | m_errorMonitor->VerifyFound(); |
| 12481 | imgViewInfo.subresourceRange.baseMipLevel = 0; |
| 12482 | |
| 12483 | m_errorMonitor->SetDesiredFailureMsg( |
| 12484 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 12485 | "vkCreateImageView called with baseArrayLayer"); |
| 12486 | // View can't have baseArrayLayer >= image's arraySize - Expect |
| 12487 | // VIEW_CREATE_ERROR |
| 12488 | imgViewInfo.subresourceRange.baseArrayLayer = 1; |
| 12489 | vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView); |
| 12490 | m_errorMonitor->VerifyFound(); |
| 12491 | imgViewInfo.subresourceRange.baseArrayLayer = 0; |
| 12492 | |
| 12493 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 12494 | "vkCreateImageView called with 0 in " |
| 12495 | "pCreateInfo->subresourceRange." |
| 12496 | "levelCount"); |
| 12497 | // View's levelCount can't be 0 - Expect VIEW_CREATE_ERROR |
| 12498 | imgViewInfo.subresourceRange.levelCount = 0; |
| 12499 | vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView); |
| 12500 | m_errorMonitor->VerifyFound(); |
| 12501 | imgViewInfo.subresourceRange.levelCount = 1; |
| 12502 | |
| 12503 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 12504 | "vkCreateImageView called with 0 in " |
| 12505 | "pCreateInfo->subresourceRange." |
| 12506 | "layerCount"); |
| 12507 | // View's layerCount can't be 0 - Expect VIEW_CREATE_ERROR |
| 12508 | imgViewInfo.subresourceRange.layerCount = 0; |
| 12509 | vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView); |
| 12510 | m_errorMonitor->VerifyFound(); |
| 12511 | imgViewInfo.subresourceRange.layerCount = 1; |
| 12512 | |
| 12513 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 12514 | "but both must be color formats"); |
| 12515 | // Can't use depth format for view into color image - Expect INVALID_FORMAT |
| 12516 | imgViewInfo.format = VK_FORMAT_D24_UNORM_S8_UINT; |
| 12517 | vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView); |
| 12518 | m_errorMonitor->VerifyFound(); |
| 12519 | imgViewInfo.format = VK_FORMAT_B8G8R8A8_UNORM; |
| 12520 | |
| 12521 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 12522 | "Formats MUST be IDENTICAL unless " |
| 12523 | "VK_IMAGE_CREATE_MUTABLE_FORMAT BIT " |
| 12524 | "was set on image creation."); |
| 12525 | // Same compatibility class but no MUTABLE_FORMAT bit - Expect |
| 12526 | // VIEW_CREATE_ERROR |
| 12527 | imgViewInfo.format = VK_FORMAT_B8G8R8A8_UINT; |
| 12528 | vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView); |
| 12529 | m_errorMonitor->VerifyFound(); |
| 12530 | imgViewInfo.format = VK_FORMAT_B8G8R8A8_UNORM; |
| 12531 | |
| 12532 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 12533 | "can support ImageViews with " |
| 12534 | "differing formats but they must be " |
| 12535 | "in the same compatibility class."); |
| 12536 | // Have MUTABLE_FORMAT bit but not in same compatibility class - Expect |
| 12537 | // VIEW_CREATE_ERROR |
| 12538 | VkImageCreateInfo mutImgInfo = image.create_info(); |
| 12539 | VkImage mutImage; |
| 12540 | mutImgInfo.format = VK_FORMAT_R8_UINT; |
| 12541 | assert( |
| 12542 | m_device->format_properties(VK_FORMAT_R8_UINT).optimalTilingFeatures & |
| 12543 | VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT); |
| 12544 | mutImgInfo.flags = VK_IMAGE_CREATE_MUTABLE_FORMAT_BIT; |
| 12545 | mutImgInfo.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT; |
| 12546 | ret = vkCreateImage(m_device->handle(), &mutImgInfo, NULL, &mutImage); |
| 12547 | ASSERT_VK_SUCCESS(ret); |
| 12548 | imgViewInfo.image = mutImage; |
| 12549 | vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView); |
| 12550 | m_errorMonitor->VerifyFound(); |
| 12551 | imgViewInfo.image = image.handle(); |
| 12552 | vkDestroyImage(m_device->handle(), mutImage, NULL); |
| 12553 | } |
| 12554 | |
| 12555 | TEST_F(VkLayerTest, MiscImageLayerTests) { |
| 12556 | |
| 12557 | TEST_DESCRIPTION("Image layer tests that don't belong elsewhare"); |
| 12558 | |
| 12559 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 12560 | |
| 12561 | VkImageObj image(m_device); |
| 12562 | image.init(128, 128, VK_FORMAT_B8G8R8A8_UNORM, |
| 12563 | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | |
| 12564 | VK_IMAGE_USAGE_TRANSFER_DST_BIT, |
| 12565 | VK_IMAGE_TILING_OPTIMAL, 0); |
| 12566 | ASSERT_TRUE(image.initialized()); |
| 12567 | |
| 12568 | m_errorMonitor->SetDesiredFailureMsg( |
| 12569 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 12570 | "number of layers in image subresource is zero"); |
| 12571 | vk_testing::Buffer buffer; |
| 12572 | VkMemoryPropertyFlags reqs = 0; |
| 12573 | buffer.init_as_src(*m_device, 128 * 128 * 4, reqs); |
| 12574 | VkBufferImageCopy region = {}; |
| 12575 | region.bufferRowLength = 128; |
| 12576 | region.bufferImageHeight = 128; |
| 12577 | region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; |
| 12578 | // layerCount can't be 0 - Expect MISMATCHED_IMAGE_ASPECT |
| 12579 | region.imageSubresource.layerCount = 0; |
| 12580 | region.imageExtent.height = 4; |
| 12581 | region.imageExtent.width = 4; |
| 12582 | region.imageExtent.depth = 1; |
| 12583 | m_commandBuffer->BeginCommandBuffer(); |
| 12584 | vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), |
| 12585 | image.handle(), VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, |
| 12586 | 1, ®ion); |
| 12587 | m_errorMonitor->VerifyFound(); |
| 12588 | region.imageSubresource.layerCount = 1; |
| 12589 | |
| 12590 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 12591 | "aspectMasks for each region must " |
| 12592 | "specify only COLOR or DEPTH or " |
| 12593 | "STENCIL"); |
| 12594 | // Expect MISMATCHED_IMAGE_ASPECT |
| 12595 | region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_METADATA_BIT; |
| 12596 | vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), |
| 12597 | image.handle(), VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, |
| 12598 | 1, ®ion); |
| 12599 | m_errorMonitor->VerifyFound(); |
| 12600 | region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; |
| 12601 | |
| 12602 | m_errorMonitor->SetDesiredFailureMsg( |
| 12603 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 12604 | "If the format of srcImage is a depth, stencil, depth stencil or " |
| 12605 | "integer-based format then filter must be VK_FILTER_NEAREST"); |
| 12606 | // Expect INVALID_FILTER |
| 12607 | VkImageObj intImage1(m_device); |
| 12608 | intImage1.init(128, 128, VK_FORMAT_R8_UINT, |
| 12609 | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, |
| 12610 | 0); |
| 12611 | VkImageObj intImage2(m_device); |
| 12612 | intImage2.init(128, 128, VK_FORMAT_R8_UINT, |
| 12613 | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, |
| 12614 | 0); |
| 12615 | VkImageBlit blitRegion = {}; |
| 12616 | blitRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; |
| 12617 | blitRegion.srcSubresource.baseArrayLayer = 0; |
| 12618 | blitRegion.srcSubresource.layerCount = 1; |
| 12619 | blitRegion.srcSubresource.mipLevel = 0; |
| 12620 | blitRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; |
| 12621 | blitRegion.dstSubresource.baseArrayLayer = 0; |
| 12622 | blitRegion.dstSubresource.layerCount = 1; |
| 12623 | blitRegion.dstSubresource.mipLevel = 0; |
| 12624 | |
| 12625 | vkCmdBlitImage(m_commandBuffer->GetBufferHandle(), intImage1.handle(), |
| 12626 | intImage1.layout(), intImage2.handle(), intImage2.layout(), |
| 12627 | 16, &blitRegion, VK_FILTER_LINEAR); |
| 12628 | m_errorMonitor->VerifyFound(); |
| 12629 | |
| 12630 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 12631 | "called with 0 in ppMemoryBarriers"); |
| 12632 | VkImageMemoryBarrier img_barrier; |
| 12633 | img_barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER; |
| 12634 | img_barrier.pNext = NULL; |
| 12635 | img_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT; |
| 12636 | img_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT; |
| 12637 | img_barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL; |
| 12638 | img_barrier.newLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL; |
| 12639 | img_barrier.image = image.handle(); |
| 12640 | img_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED; |
| 12641 | img_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED; |
| 12642 | img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; |
| 12643 | img_barrier.subresourceRange.baseArrayLayer = 0; |
| 12644 | img_barrier.subresourceRange.baseMipLevel = 0; |
| 12645 | // layerCount should not be 0 - Expect INVALID_IMAGE_RESOURCE |
| 12646 | img_barrier.subresourceRange.layerCount = 0; |
| 12647 | img_barrier.subresourceRange.levelCount = 1; |
| 12648 | vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), |
| 12649 | VK_PIPELINE_STAGE_HOST_BIT, |
| 12650 | VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0, nullptr, 0, |
| 12651 | nullptr, 1, &img_barrier); |
| 12652 | m_errorMonitor->VerifyFound(); |
| 12653 | img_barrier.subresourceRange.layerCount = 1; |
| 12654 | } |
| 12655 | |
| 12656 | TEST_F(VkLayerTest, ImageFormatLimits) { |
| 12657 | |
| 12658 | TEST_DESCRIPTION("Exceed the limits of image format "); |
| 12659 | |
| 12660 | m_errorMonitor->SetDesiredFailureMsg( |
| 12661 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 12662 | "CreateImage extents exceed allowable limits for format"); |
| 12663 | VkImageCreateInfo image_create_info = {}; |
| 12664 | image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO; |
| 12665 | image_create_info.pNext = NULL; |
| 12666 | image_create_info.imageType = VK_IMAGE_TYPE_2D; |
| 12667 | image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM; |
| 12668 | image_create_info.extent.width = 32; |
| 12669 | image_create_info.extent.height = 32; |
| 12670 | image_create_info.extent.depth = 1; |
| 12671 | image_create_info.mipLevels = 1; |
| 12672 | image_create_info.arrayLayers = 1; |
| 12673 | image_create_info.samples = VK_SAMPLE_COUNT_1_BIT; |
| 12674 | image_create_info.tiling = VK_IMAGE_TILING_LINEAR; |
| 12675 | image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT; |
| 12676 | image_create_info.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED; |
| 12677 | image_create_info.flags = 0; |
| 12678 | |
| 12679 | VkImage nullImg; |
| 12680 | VkImageFormatProperties imgFmtProps; |
| 12681 | vkGetPhysicalDeviceImageFormatProperties( |
| 12682 | gpu(), image_create_info.format, image_create_info.imageType, |
| 12683 | image_create_info.tiling, image_create_info.usage, |
| 12684 | image_create_info.flags, &imgFmtProps); |
| 12685 | image_create_info.extent.depth = imgFmtProps.maxExtent.depth + 1; |
| 12686 | // Expect INVALID_FORMAT_LIMITS_VIOLATION |
| 12687 | vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg); |
| 12688 | m_errorMonitor->VerifyFound(); |
| 12689 | image_create_info.extent.depth = 1; |
| 12690 | |
| 12691 | m_errorMonitor->SetDesiredFailureMsg( |
| 12692 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 12693 | "exceeds allowable maximum supported by format of"); |
| 12694 | image_create_info.mipLevels = imgFmtProps.maxMipLevels + 1; |
| 12695 | // Expect INVALID_FORMAT_LIMITS_VIOLATION |
| 12696 | vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg); |
| 12697 | m_errorMonitor->VerifyFound(); |
| 12698 | image_create_info.mipLevels = 1; |
| 12699 | |
| 12700 | m_errorMonitor->SetDesiredFailureMsg( |
| 12701 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 12702 | "exceeds allowable maximum supported by format of"); |
| 12703 | image_create_info.arrayLayers = imgFmtProps.maxArrayLayers + 1; |
| 12704 | // Expect INVALID_FORMAT_LIMITS_VIOLATION |
| 12705 | vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg); |
| 12706 | m_errorMonitor->VerifyFound(); |
| 12707 | image_create_info.arrayLayers = 1; |
| 12708 | |
| 12709 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 12710 | "is not supported by format"); |
| 12711 | int samples = imgFmtProps.sampleCounts >> 1; |
| 12712 | image_create_info.samples = (VkSampleCountFlagBits)samples; |
| 12713 | // Expect INVALID_FORMAT_LIMITS_VIOLATION |
| 12714 | vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg); |
| 12715 | m_errorMonitor->VerifyFound(); |
| 12716 | image_create_info.samples = VK_SAMPLE_COUNT_1_BIT; |
| 12717 | |
| 12718 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 12719 | "pCreateInfo->initialLayout, must be " |
| 12720 | "VK_IMAGE_LAYOUT_UNDEFINED or " |
| 12721 | "VK_IMAGE_LAYOUT_PREINITIALIZED"); |
| 12722 | image_create_info.initialLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL; |
| 12723 | // Expect INVALID_LAYOUT |
| 12724 | vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg); |
| 12725 | m_errorMonitor->VerifyFound(); |
| 12726 | image_create_info.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED; |
| 12727 | } |
| 12728 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12729 | TEST_F(VkLayerTest, CopyImageFormatSizeMismatch) { |
Karl Schultz | bdb7595 | 2016-04-19 11:36:49 -0600 | [diff] [blame] | 12730 | VkResult err; |
| 12731 | bool pass; |
| 12732 | |
| 12733 | // Create color images with different format sizes and try to copy between them |
| 12734 | m_errorMonitor->SetDesiredFailureMsg( |
| 12735 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 12736 | "vkCmdCopyImage called with unmatched source and dest image format sizes"); |
| 12737 | |
| 12738 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 12739 | |
| 12740 | // Create two images of different types and try to copy between them |
| 12741 | VkImage srcImage; |
| 12742 | VkImage dstImage; |
| 12743 | VkDeviceMemory srcMem; |
| 12744 | VkDeviceMemory destMem; |
| 12745 | VkMemoryRequirements memReqs; |
| 12746 | |
| 12747 | VkImageCreateInfo image_create_info = {}; |
| 12748 | image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO; |
| 12749 | image_create_info.pNext = NULL; |
| 12750 | image_create_info.imageType = VK_IMAGE_TYPE_2D; |
| 12751 | image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM; |
| 12752 | image_create_info.extent.width = 32; |
| 12753 | image_create_info.extent.height = 32; |
| 12754 | image_create_info.extent.depth = 1; |
| 12755 | image_create_info.mipLevels = 1; |
| 12756 | image_create_info.arrayLayers = 1; |
| 12757 | image_create_info.samples = VK_SAMPLE_COUNT_1_BIT; |
| 12758 | image_create_info.tiling = VK_IMAGE_TILING_LINEAR; |
| 12759 | image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT; |
| 12760 | image_create_info.flags = 0; |
| 12761 | |
| 12762 | err = |
| 12763 | vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage); |
| 12764 | ASSERT_VK_SUCCESS(err); |
| 12765 | |
| 12766 | image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT; |
| 12767 | // Introduce failure by creating second image with a different-sized format. |
| 12768 | image_create_info.format = VK_FORMAT_R5G5B5A1_UNORM_PACK16; |
| 12769 | |
| 12770 | err = |
| 12771 | vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage); |
| 12772 | ASSERT_VK_SUCCESS(err); |
| 12773 | |
| 12774 | // Allocate memory |
| 12775 | VkMemoryAllocateInfo memAlloc = {}; |
| 12776 | memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO; |
| 12777 | memAlloc.pNext = NULL; |
| 12778 | memAlloc.allocationSize = 0; |
| 12779 | memAlloc.memoryTypeIndex = 0; |
| 12780 | |
| 12781 | vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs); |
| 12782 | memAlloc.allocationSize = memReqs.size; |
| 12783 | pass = |
| 12784 | m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0); |
| 12785 | ASSERT_TRUE(pass); |
| 12786 | err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem); |
| 12787 | ASSERT_VK_SUCCESS(err); |
| 12788 | |
| 12789 | vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs); |
| 12790 | memAlloc.allocationSize = memReqs.size; |
| 12791 | pass = |
| 12792 | m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0); |
| 12793 | ASSERT_TRUE(pass); |
| 12794 | err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem); |
| 12795 | ASSERT_VK_SUCCESS(err); |
| 12796 | |
| 12797 | err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0); |
| 12798 | ASSERT_VK_SUCCESS(err); |
| 12799 | err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0); |
| 12800 | ASSERT_VK_SUCCESS(err); |
| 12801 | |
| 12802 | BeginCommandBuffer(); |
| 12803 | VkImageCopy copyRegion; |
| 12804 | copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; |
| 12805 | copyRegion.srcSubresource.mipLevel = 0; |
| 12806 | copyRegion.srcSubresource.baseArrayLayer = 0; |
| 12807 | copyRegion.srcSubresource.layerCount = 0; |
| 12808 | copyRegion.srcOffset.x = 0; |
| 12809 | copyRegion.srcOffset.y = 0; |
| 12810 | copyRegion.srcOffset.z = 0; |
| 12811 | copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; |
| 12812 | copyRegion.dstSubresource.mipLevel = 0; |
| 12813 | copyRegion.dstSubresource.baseArrayLayer = 0; |
| 12814 | copyRegion.dstSubresource.layerCount = 0; |
| 12815 | copyRegion.dstOffset.x = 0; |
| 12816 | copyRegion.dstOffset.y = 0; |
| 12817 | copyRegion.dstOffset.z = 0; |
| 12818 | copyRegion.extent.width = 1; |
| 12819 | copyRegion.extent.height = 1; |
| 12820 | copyRegion.extent.depth = 1; |
| 12821 | m_commandBuffer->CopyImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, |
| 12822 | VK_IMAGE_LAYOUT_GENERAL, 1, ©Region); |
| 12823 | EndCommandBuffer(); |
| 12824 | |
| 12825 | m_errorMonitor->VerifyFound(); |
| 12826 | |
| 12827 | vkDestroyImage(m_device->device(), srcImage, NULL); |
| 12828 | vkDestroyImage(m_device->device(), dstImage, NULL); |
| 12829 | vkFreeMemory(m_device->device(), srcMem, NULL); |
| 12830 | vkFreeMemory(m_device->device(), destMem, NULL); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12831 | } |
| 12832 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12833 | TEST_F(VkLayerTest, CopyImageDepthStencilFormatMismatch) { |
| 12834 | VkResult err; |
| 12835 | bool pass; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12836 | |
Mark Lobodzinski | db11763 | 2016-03-31 10:45:56 -0600 | [diff] [blame] | 12837 | // 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] | 12838 | m_errorMonitor->SetDesiredFailureMsg( |
| 12839 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Mark Lobodzinski | db11763 | 2016-03-31 10:45:56 -0600 | [diff] [blame] | 12840 | "vkCmdCopyImage called with unmatched source and dest image depth"); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 12841 | |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12842 | ASSERT_NO_FATAL_FAILURE(InitState()); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12843 | |
| 12844 | // Create two images of different types and try to copy between them |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12845 | VkImage srcImage; |
| 12846 | VkImage dstImage; |
| 12847 | VkDeviceMemory srcMem; |
| 12848 | VkDeviceMemory destMem; |
| 12849 | VkMemoryRequirements memReqs; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12850 | |
| 12851 | VkImageCreateInfo image_create_info = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12852 | image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO; |
| 12853 | image_create_info.pNext = NULL; |
| 12854 | image_create_info.imageType = VK_IMAGE_TYPE_2D; |
| 12855 | image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM; |
| 12856 | image_create_info.extent.width = 32; |
| 12857 | image_create_info.extent.height = 32; |
| 12858 | image_create_info.extent.depth = 1; |
| 12859 | image_create_info.mipLevels = 1; |
| 12860 | image_create_info.arrayLayers = 1; |
| 12861 | image_create_info.samples = VK_SAMPLE_COUNT_1_BIT; |
| 12862 | image_create_info.tiling = VK_IMAGE_TILING_LINEAR; |
| 12863 | image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT; |
| 12864 | image_create_info.flags = 0; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12865 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12866 | err = |
| 12867 | vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12868 | ASSERT_VK_SUCCESS(err); |
| 12869 | |
Karl Schultz | bdb7595 | 2016-04-19 11:36:49 -0600 | [diff] [blame] | 12870 | image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT; |
| 12871 | |
Mark Lobodzinski | db11763 | 2016-03-31 10:45:56 -0600 | [diff] [blame] | 12872 | // Introduce failure by creating second image with a depth/stencil format |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12873 | image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL; |
Mark Lobodzinski | db11763 | 2016-03-31 10:45:56 -0600 | [diff] [blame] | 12874 | image_create_info.format = VK_FORMAT_D24_UNORM_S8_UINT; |
| 12875 | image_create_info.usage = VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12876 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12877 | err = |
| 12878 | vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12879 | ASSERT_VK_SUCCESS(err); |
| 12880 | |
| 12881 | // Allocate memory |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 12882 | VkMemoryAllocateInfo memAlloc = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12883 | memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO; |
| 12884 | memAlloc.pNext = NULL; |
| 12885 | memAlloc.allocationSize = 0; |
| 12886 | memAlloc.memoryTypeIndex = 0; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12887 | |
Courtney Goeltzenleuchter | 06d8947 | 2015-10-20 16:40:38 -0600 | [diff] [blame] | 12888 | vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12889 | memAlloc.allocationSize = memReqs.size; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12890 | pass = |
| 12891 | m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0); |
Courtney Goeltzenleuchter | 1d2f0dd | 2015-10-22 11:03:31 -0600 | [diff] [blame] | 12892 | ASSERT_TRUE(pass); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 12893 | err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12894 | ASSERT_VK_SUCCESS(err); |
| 12895 | |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 12896 | vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12897 | memAlloc.allocationSize = memReqs.size; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12898 | pass = |
| 12899 | m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0); |
Courtney Goeltzenleuchter | 1d2f0dd | 2015-10-22 11:03:31 -0600 | [diff] [blame] | 12900 | ASSERT_TRUE(pass); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 12901 | err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12902 | ASSERT_VK_SUCCESS(err); |
| 12903 | |
| 12904 | err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0); |
| 12905 | ASSERT_VK_SUCCESS(err); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 12906 | err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12907 | ASSERT_VK_SUCCESS(err); |
| 12908 | |
| 12909 | BeginCommandBuffer(); |
| 12910 | VkImageCopy copyRegion; |
Chia-I Wu | ab83a0e | 2015-10-27 19:00:15 +0800 | [diff] [blame] | 12911 | copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12912 | copyRegion.srcSubresource.mipLevel = 0; |
Courtney Goeltzenleuchter | 8367ce0 | 2015-10-16 09:46:00 -0600 | [diff] [blame] | 12913 | copyRegion.srcSubresource.baseArrayLayer = 0; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 12914 | copyRegion.srcSubresource.layerCount = 0; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12915 | copyRegion.srcOffset.x = 0; |
| 12916 | copyRegion.srcOffset.y = 0; |
| 12917 | copyRegion.srcOffset.z = 0; |
Chia-I Wu | ab83a0e | 2015-10-27 19:00:15 +0800 | [diff] [blame] | 12918 | copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 12919 | copyRegion.dstSubresource.mipLevel = 0; |
| 12920 | copyRegion.dstSubresource.baseArrayLayer = 0; |
| 12921 | copyRegion.dstSubresource.layerCount = 0; |
| 12922 | copyRegion.dstOffset.x = 0; |
| 12923 | copyRegion.dstOffset.y = 0; |
| 12924 | copyRegion.dstOffset.z = 0; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12925 | copyRegion.extent.width = 1; |
| 12926 | copyRegion.extent.height = 1; |
| 12927 | copyRegion.extent.depth = 1; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12928 | m_commandBuffer->CopyImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, |
| 12929 | VK_IMAGE_LAYOUT_GENERAL, 1, ©Region); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12930 | EndCommandBuffer(); |
| 12931 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 12932 | m_errorMonitor->VerifyFound(); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12933 | |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 12934 | vkDestroyImage(m_device->device(), srcImage, NULL); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 12935 | vkDestroyImage(m_device->device(), dstImage, NULL); |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 12936 | vkFreeMemory(m_device->device(), srcMem, NULL); |
| 12937 | vkFreeMemory(m_device->device(), destMem, NULL); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12938 | } |
| 12939 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12940 | TEST_F(VkLayerTest, ResolveImageLowSampleCount) { |
| 12941 | VkResult err; |
| 12942 | bool pass; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12943 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12944 | m_errorMonitor->SetDesiredFailureMsg( |
| 12945 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 12946 | "vkCmdResolveImage called with source sample count less than 2."); |
| 12947 | |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12948 | ASSERT_NO_FATAL_FAILURE(InitState()); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12949 | |
| 12950 | // 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] | 12951 | VkImage srcImage; |
| 12952 | VkImage dstImage; |
| 12953 | VkDeviceMemory srcMem; |
| 12954 | VkDeviceMemory destMem; |
| 12955 | VkMemoryRequirements memReqs; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12956 | |
| 12957 | VkImageCreateInfo image_create_info = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12958 | image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO; |
| 12959 | image_create_info.pNext = NULL; |
| 12960 | image_create_info.imageType = VK_IMAGE_TYPE_2D; |
| 12961 | image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM; |
| 12962 | image_create_info.extent.width = 32; |
| 12963 | image_create_info.extent.height = 1; |
| 12964 | image_create_info.extent.depth = 1; |
| 12965 | image_create_info.mipLevels = 1; |
| 12966 | image_create_info.arrayLayers = 1; |
| 12967 | image_create_info.samples = VK_SAMPLE_COUNT_1_BIT; |
| 12968 | image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL; |
| 12969 | image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT; |
| 12970 | image_create_info.flags = 0; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12971 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12972 | err = |
| 12973 | vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12974 | ASSERT_VK_SUCCESS(err); |
| 12975 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12976 | image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12977 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12978 | err = |
| 12979 | vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12980 | ASSERT_VK_SUCCESS(err); |
| 12981 | |
| 12982 | // Allocate memory |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 12983 | VkMemoryAllocateInfo memAlloc = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12984 | memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO; |
| 12985 | memAlloc.pNext = NULL; |
| 12986 | memAlloc.allocationSize = 0; |
| 12987 | memAlloc.memoryTypeIndex = 0; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12988 | |
Courtney Goeltzenleuchter | 06d8947 | 2015-10-20 16:40:38 -0600 | [diff] [blame] | 12989 | vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12990 | memAlloc.allocationSize = memReqs.size; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12991 | pass = |
| 12992 | m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0); |
Courtney Goeltzenleuchter | 1d2f0dd | 2015-10-22 11:03:31 -0600 | [diff] [blame] | 12993 | ASSERT_TRUE(pass); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 12994 | err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12995 | ASSERT_VK_SUCCESS(err); |
| 12996 | |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 12997 | vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12998 | memAlloc.allocationSize = memReqs.size; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12999 | pass = |
| 13000 | m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0); |
Courtney Goeltzenleuchter | 1d2f0dd | 2015-10-22 11:03:31 -0600 | [diff] [blame] | 13001 | ASSERT_TRUE(pass); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 13002 | err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 13003 | ASSERT_VK_SUCCESS(err); |
| 13004 | |
| 13005 | err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0); |
| 13006 | ASSERT_VK_SUCCESS(err); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 13007 | err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 13008 | ASSERT_VK_SUCCESS(err); |
| 13009 | |
| 13010 | BeginCommandBuffer(); |
| 13011 | // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest? |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 13012 | // VK_IMAGE_LAYOUT_UNDEFINED = 0, |
| 13013 | // VK_IMAGE_LAYOUT_GENERAL = 1, |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 13014 | VkImageResolve resolveRegion; |
Chia-I Wu | ab83a0e | 2015-10-27 19:00:15 +0800 | [diff] [blame] | 13015 | resolveRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 13016 | resolveRegion.srcSubresource.mipLevel = 0; |
Courtney Goeltzenleuchter | 8367ce0 | 2015-10-16 09:46:00 -0600 | [diff] [blame] | 13017 | resolveRegion.srcSubresource.baseArrayLayer = 0; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 13018 | resolveRegion.srcSubresource.layerCount = 0; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 13019 | resolveRegion.srcOffset.x = 0; |
| 13020 | resolveRegion.srcOffset.y = 0; |
| 13021 | resolveRegion.srcOffset.z = 0; |
Chia-I Wu | ab83a0e | 2015-10-27 19:00:15 +0800 | [diff] [blame] | 13022 | resolveRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 13023 | resolveRegion.dstSubresource.mipLevel = 0; |
| 13024 | resolveRegion.dstSubresource.baseArrayLayer = 0; |
| 13025 | resolveRegion.dstSubresource.layerCount = 0; |
| 13026 | resolveRegion.dstOffset.x = 0; |
| 13027 | resolveRegion.dstOffset.y = 0; |
| 13028 | resolveRegion.dstOffset.z = 0; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 13029 | resolveRegion.extent.width = 1; |
| 13030 | resolveRegion.extent.height = 1; |
| 13031 | resolveRegion.extent.depth = 1; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 13032 | m_commandBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, |
| 13033 | VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 13034 | EndCommandBuffer(); |
| 13035 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 13036 | m_errorMonitor->VerifyFound(); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 13037 | |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 13038 | vkDestroyImage(m_device->device(), srcImage, NULL); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 13039 | vkDestroyImage(m_device->device(), dstImage, NULL); |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 13040 | vkFreeMemory(m_device->device(), srcMem, NULL); |
| 13041 | vkFreeMemory(m_device->device(), destMem, NULL); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 13042 | } |
| 13043 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 13044 | TEST_F(VkLayerTest, ResolveImageHighSampleCount) { |
| 13045 | VkResult err; |
| 13046 | bool pass; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 13047 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 13048 | m_errorMonitor->SetDesiredFailureMsg( |
| 13049 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 13050 | "vkCmdResolveImage called with dest sample count greater than 1."); |
| 13051 | |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 13052 | ASSERT_NO_FATAL_FAILURE(InitState()); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 13053 | |
Chris Forbes | a753069 | 2016-05-08 12:35:39 +1200 | [diff] [blame] | 13054 | // 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] | 13055 | VkImage srcImage; |
| 13056 | VkImage dstImage; |
| 13057 | VkDeviceMemory srcMem; |
| 13058 | VkDeviceMemory destMem; |
| 13059 | VkMemoryRequirements memReqs; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 13060 | |
| 13061 | VkImageCreateInfo image_create_info = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 13062 | image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO; |
| 13063 | image_create_info.pNext = NULL; |
| 13064 | image_create_info.imageType = VK_IMAGE_TYPE_2D; |
| 13065 | image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM; |
| 13066 | image_create_info.extent.width = 32; |
| 13067 | image_create_info.extent.height = 1; |
| 13068 | image_create_info.extent.depth = 1; |
| 13069 | image_create_info.mipLevels = 1; |
| 13070 | image_create_info.arrayLayers = 1; |
Chris Forbes | a753069 | 2016-05-08 12:35:39 +1200 | [diff] [blame] | 13071 | image_create_info.samples = VK_SAMPLE_COUNT_4_BIT; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 13072 | image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL; |
| 13073 | // Note: Some implementations expect color attachment usage for any |
| 13074 | // multisample surface |
| 13075 | image_create_info.usage = |
| 13076 | VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT; |
| 13077 | image_create_info.flags = 0; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 13078 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 13079 | err = |
| 13080 | vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 13081 | ASSERT_VK_SUCCESS(err); |
| 13082 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 13083 | // Note: Some implementations expect color attachment usage for any |
| 13084 | // multisample surface |
| 13085 | image_create_info.usage = |
| 13086 | VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 13087 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 13088 | err = |
| 13089 | vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 13090 | ASSERT_VK_SUCCESS(err); |
| 13091 | |
| 13092 | // Allocate memory |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 13093 | VkMemoryAllocateInfo memAlloc = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 13094 | memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO; |
| 13095 | memAlloc.pNext = NULL; |
| 13096 | memAlloc.allocationSize = 0; |
| 13097 | memAlloc.memoryTypeIndex = 0; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 13098 | |
Courtney Goeltzenleuchter | 06d8947 | 2015-10-20 16:40:38 -0600 | [diff] [blame] | 13099 | vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 13100 | memAlloc.allocationSize = memReqs.size; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 13101 | pass = |
| 13102 | m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0); |
Courtney Goeltzenleuchter | 1d2f0dd | 2015-10-22 11:03:31 -0600 | [diff] [blame] | 13103 | ASSERT_TRUE(pass); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 13104 | err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 13105 | ASSERT_VK_SUCCESS(err); |
| 13106 | |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 13107 | vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 13108 | memAlloc.allocationSize = memReqs.size; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 13109 | pass = |
| 13110 | m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0); |
Courtney Goeltzenleuchter | 1d2f0dd | 2015-10-22 11:03:31 -0600 | [diff] [blame] | 13111 | ASSERT_TRUE(pass); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 13112 | err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 13113 | ASSERT_VK_SUCCESS(err); |
| 13114 | |
| 13115 | err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0); |
| 13116 | ASSERT_VK_SUCCESS(err); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 13117 | err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 13118 | ASSERT_VK_SUCCESS(err); |
| 13119 | |
| 13120 | BeginCommandBuffer(); |
| 13121 | // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest? |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 13122 | // VK_IMAGE_LAYOUT_UNDEFINED = 0, |
| 13123 | // VK_IMAGE_LAYOUT_GENERAL = 1, |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 13124 | VkImageResolve resolveRegion; |
Chia-I Wu | ab83a0e | 2015-10-27 19:00:15 +0800 | [diff] [blame] | 13125 | resolveRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 13126 | resolveRegion.srcSubresource.mipLevel = 0; |
Courtney Goeltzenleuchter | 8367ce0 | 2015-10-16 09:46:00 -0600 | [diff] [blame] | 13127 | resolveRegion.srcSubresource.baseArrayLayer = 0; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 13128 | resolveRegion.srcSubresource.layerCount = 0; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 13129 | resolveRegion.srcOffset.x = 0; |
| 13130 | resolveRegion.srcOffset.y = 0; |
| 13131 | resolveRegion.srcOffset.z = 0; |
Chia-I Wu | ab83a0e | 2015-10-27 19:00:15 +0800 | [diff] [blame] | 13132 | resolveRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 13133 | resolveRegion.dstSubresource.mipLevel = 0; |
| 13134 | resolveRegion.dstSubresource.baseArrayLayer = 0; |
| 13135 | resolveRegion.dstSubresource.layerCount = 0; |
| 13136 | resolveRegion.dstOffset.x = 0; |
| 13137 | resolveRegion.dstOffset.y = 0; |
| 13138 | resolveRegion.dstOffset.z = 0; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 13139 | resolveRegion.extent.width = 1; |
| 13140 | resolveRegion.extent.height = 1; |
| 13141 | resolveRegion.extent.depth = 1; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 13142 | m_commandBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, |
| 13143 | VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 13144 | EndCommandBuffer(); |
| 13145 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 13146 | m_errorMonitor->VerifyFound(); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 13147 | |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 13148 | vkDestroyImage(m_device->device(), srcImage, NULL); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 13149 | vkDestroyImage(m_device->device(), dstImage, NULL); |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 13150 | vkFreeMemory(m_device->device(), srcMem, NULL); |
| 13151 | vkFreeMemory(m_device->device(), destMem, NULL); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 13152 | } |
| 13153 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 13154 | TEST_F(VkLayerTest, ResolveImageFormatMismatch) { |
| 13155 | VkResult err; |
| 13156 | bool pass; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 13157 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 13158 | m_errorMonitor->SetDesiredFailureMsg( |
| 13159 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 13160 | "vkCmdResolveImage called with unmatched source and dest formats."); |
| 13161 | |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 13162 | ASSERT_NO_FATAL_FAILURE(InitState()); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 13163 | |
| 13164 | // Create two images of different types and try to copy between them |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 13165 | VkImage srcImage; |
| 13166 | VkImage dstImage; |
| 13167 | VkDeviceMemory srcMem; |
| 13168 | VkDeviceMemory destMem; |
| 13169 | VkMemoryRequirements memReqs; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 13170 | |
| 13171 | VkImageCreateInfo image_create_info = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 13172 | image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO; |
| 13173 | image_create_info.pNext = NULL; |
| 13174 | image_create_info.imageType = VK_IMAGE_TYPE_2D; |
| 13175 | image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM; |
| 13176 | image_create_info.extent.width = 32; |
| 13177 | image_create_info.extent.height = 1; |
| 13178 | image_create_info.extent.depth = 1; |
| 13179 | image_create_info.mipLevels = 1; |
| 13180 | image_create_info.arrayLayers = 1; |
| 13181 | image_create_info.samples = VK_SAMPLE_COUNT_2_BIT; |
| 13182 | image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL; |
| 13183 | // Note: Some implementations expect color attachment usage for any |
| 13184 | // multisample surface |
| 13185 | image_create_info.usage = |
| 13186 | VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT; |
| 13187 | image_create_info.flags = 0; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 13188 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 13189 | err = |
| 13190 | vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 13191 | ASSERT_VK_SUCCESS(err); |
| 13192 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 13193 | // Set format to something other than source image |
| 13194 | image_create_info.format = VK_FORMAT_R32_SFLOAT; |
| 13195 | // Note: Some implementations expect color attachment usage for any |
| 13196 | // multisample surface |
| 13197 | image_create_info.usage = |
| 13198 | VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT; |
| 13199 | image_create_info.samples = VK_SAMPLE_COUNT_1_BIT; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 13200 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 13201 | err = |
| 13202 | vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 13203 | ASSERT_VK_SUCCESS(err); |
| 13204 | |
| 13205 | // Allocate memory |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 13206 | VkMemoryAllocateInfo memAlloc = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 13207 | memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO; |
| 13208 | memAlloc.pNext = NULL; |
| 13209 | memAlloc.allocationSize = 0; |
| 13210 | memAlloc.memoryTypeIndex = 0; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 13211 | |
Courtney Goeltzenleuchter | 06d8947 | 2015-10-20 16:40:38 -0600 | [diff] [blame] | 13212 | vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 13213 | memAlloc.allocationSize = memReqs.size; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 13214 | pass = |
| 13215 | m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0); |
Courtney Goeltzenleuchter | 1d2f0dd | 2015-10-22 11:03:31 -0600 | [diff] [blame] | 13216 | ASSERT_TRUE(pass); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 13217 | err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 13218 | ASSERT_VK_SUCCESS(err); |
| 13219 | |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 13220 | vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 13221 | memAlloc.allocationSize = memReqs.size; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 13222 | pass = |
| 13223 | m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0); |
Courtney Goeltzenleuchter | 1d2f0dd | 2015-10-22 11:03:31 -0600 | [diff] [blame] | 13224 | ASSERT_TRUE(pass); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 13225 | err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 13226 | ASSERT_VK_SUCCESS(err); |
| 13227 | |
| 13228 | err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0); |
| 13229 | ASSERT_VK_SUCCESS(err); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 13230 | err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 13231 | ASSERT_VK_SUCCESS(err); |
| 13232 | |
| 13233 | BeginCommandBuffer(); |
| 13234 | // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest? |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 13235 | // VK_IMAGE_LAYOUT_UNDEFINED = 0, |
| 13236 | // VK_IMAGE_LAYOUT_GENERAL = 1, |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 13237 | VkImageResolve resolveRegion; |
Chia-I Wu | ab83a0e | 2015-10-27 19:00:15 +0800 | [diff] [blame] | 13238 | resolveRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 13239 | resolveRegion.srcSubresource.mipLevel = 0; |
Courtney Goeltzenleuchter | 8367ce0 | 2015-10-16 09:46:00 -0600 | [diff] [blame] | 13240 | resolveRegion.srcSubresource.baseArrayLayer = 0; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 13241 | resolveRegion.srcSubresource.layerCount = 0; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 13242 | resolveRegion.srcOffset.x = 0; |
| 13243 | resolveRegion.srcOffset.y = 0; |
| 13244 | resolveRegion.srcOffset.z = 0; |
Chia-I Wu | ab83a0e | 2015-10-27 19:00:15 +0800 | [diff] [blame] | 13245 | resolveRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 13246 | resolveRegion.dstSubresource.mipLevel = 0; |
| 13247 | resolveRegion.dstSubresource.baseArrayLayer = 0; |
| 13248 | resolveRegion.dstSubresource.layerCount = 0; |
| 13249 | resolveRegion.dstOffset.x = 0; |
| 13250 | resolveRegion.dstOffset.y = 0; |
| 13251 | resolveRegion.dstOffset.z = 0; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 13252 | resolveRegion.extent.width = 1; |
| 13253 | resolveRegion.extent.height = 1; |
| 13254 | resolveRegion.extent.depth = 1; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 13255 | m_commandBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, |
| 13256 | VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 13257 | EndCommandBuffer(); |
| 13258 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 13259 | m_errorMonitor->VerifyFound(); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 13260 | |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 13261 | vkDestroyImage(m_device->device(), srcImage, NULL); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 13262 | vkDestroyImage(m_device->device(), dstImage, NULL); |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 13263 | vkFreeMemory(m_device->device(), srcMem, NULL); |
| 13264 | vkFreeMemory(m_device->device(), destMem, NULL); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 13265 | } |
| 13266 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 13267 | TEST_F(VkLayerTest, ResolveImageTypeMismatch) { |
| 13268 | VkResult err; |
| 13269 | bool pass; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 13270 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 13271 | m_errorMonitor->SetDesiredFailureMsg( |
| 13272 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 13273 | "vkCmdResolveImage called with unmatched source and dest image types."); |
| 13274 | |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 13275 | ASSERT_NO_FATAL_FAILURE(InitState()); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 13276 | |
| 13277 | // Create two images of different types and try to copy between them |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 13278 | VkImage srcImage; |
| 13279 | VkImage dstImage; |
| 13280 | VkDeviceMemory srcMem; |
| 13281 | VkDeviceMemory destMem; |
| 13282 | VkMemoryRequirements memReqs; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 13283 | |
| 13284 | VkImageCreateInfo image_create_info = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 13285 | image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO; |
| 13286 | image_create_info.pNext = NULL; |
| 13287 | image_create_info.imageType = VK_IMAGE_TYPE_2D; |
| 13288 | image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM; |
| 13289 | image_create_info.extent.width = 32; |
| 13290 | image_create_info.extent.height = 1; |
| 13291 | image_create_info.extent.depth = 1; |
| 13292 | image_create_info.mipLevels = 1; |
| 13293 | image_create_info.arrayLayers = 1; |
| 13294 | image_create_info.samples = VK_SAMPLE_COUNT_2_BIT; |
| 13295 | image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL; |
| 13296 | // Note: Some implementations expect color attachment usage for any |
| 13297 | // multisample surface |
| 13298 | image_create_info.usage = |
| 13299 | VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT; |
| 13300 | image_create_info.flags = 0; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 13301 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 13302 | err = |
| 13303 | vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 13304 | ASSERT_VK_SUCCESS(err); |
| 13305 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 13306 | image_create_info.imageType = VK_IMAGE_TYPE_1D; |
| 13307 | // Note: Some implementations expect color attachment usage for any |
| 13308 | // multisample surface |
| 13309 | image_create_info.usage = |
| 13310 | VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT; |
| 13311 | image_create_info.samples = VK_SAMPLE_COUNT_1_BIT; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 13312 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 13313 | err = |
| 13314 | vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 13315 | ASSERT_VK_SUCCESS(err); |
| 13316 | |
| 13317 | // Allocate memory |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 13318 | VkMemoryAllocateInfo memAlloc = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 13319 | memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO; |
| 13320 | memAlloc.pNext = NULL; |
| 13321 | memAlloc.allocationSize = 0; |
| 13322 | memAlloc.memoryTypeIndex = 0; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 13323 | |
Courtney Goeltzenleuchter | 06d8947 | 2015-10-20 16:40:38 -0600 | [diff] [blame] | 13324 | vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 13325 | memAlloc.allocationSize = memReqs.size; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 13326 | pass = |
| 13327 | m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0); |
Courtney Goeltzenleuchter | 1d2f0dd | 2015-10-22 11:03:31 -0600 | [diff] [blame] | 13328 | ASSERT_TRUE(pass); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 13329 | err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 13330 | ASSERT_VK_SUCCESS(err); |
| 13331 | |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 13332 | vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 13333 | memAlloc.allocationSize = memReqs.size; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 13334 | pass = |
| 13335 | m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0); |
Courtney Goeltzenleuchter | 1d2f0dd | 2015-10-22 11:03:31 -0600 | [diff] [blame] | 13336 | ASSERT_TRUE(pass); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 13337 | err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 13338 | ASSERT_VK_SUCCESS(err); |
| 13339 | |
| 13340 | err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0); |
| 13341 | ASSERT_VK_SUCCESS(err); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 13342 | err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 13343 | ASSERT_VK_SUCCESS(err); |
| 13344 | |
| 13345 | BeginCommandBuffer(); |
| 13346 | // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest? |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 13347 | // VK_IMAGE_LAYOUT_UNDEFINED = 0, |
| 13348 | // VK_IMAGE_LAYOUT_GENERAL = 1, |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 13349 | VkImageResolve resolveRegion; |
Chia-I Wu | ab83a0e | 2015-10-27 19:00:15 +0800 | [diff] [blame] | 13350 | resolveRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 13351 | resolveRegion.srcSubresource.mipLevel = 0; |
Courtney Goeltzenleuchter | 8367ce0 | 2015-10-16 09:46:00 -0600 | [diff] [blame] | 13352 | resolveRegion.srcSubresource.baseArrayLayer = 0; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 13353 | resolveRegion.srcSubresource.layerCount = 0; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 13354 | resolveRegion.srcOffset.x = 0; |
| 13355 | resolveRegion.srcOffset.y = 0; |
| 13356 | resolveRegion.srcOffset.z = 0; |
Chia-I Wu | ab83a0e | 2015-10-27 19:00:15 +0800 | [diff] [blame] | 13357 | resolveRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 13358 | resolveRegion.dstSubresource.mipLevel = 0; |
| 13359 | resolveRegion.dstSubresource.baseArrayLayer = 0; |
| 13360 | resolveRegion.dstSubresource.layerCount = 0; |
| 13361 | resolveRegion.dstOffset.x = 0; |
| 13362 | resolveRegion.dstOffset.y = 0; |
| 13363 | resolveRegion.dstOffset.z = 0; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 13364 | resolveRegion.extent.width = 1; |
| 13365 | resolveRegion.extent.height = 1; |
| 13366 | resolveRegion.extent.depth = 1; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 13367 | m_commandBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, |
| 13368 | VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 13369 | EndCommandBuffer(); |
| 13370 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 13371 | m_errorMonitor->VerifyFound(); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 13372 | |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 13373 | vkDestroyImage(m_device->device(), srcImage, NULL); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 13374 | vkDestroyImage(m_device->device(), dstImage, NULL); |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 13375 | vkFreeMemory(m_device->device(), srcMem, NULL); |
| 13376 | vkFreeMemory(m_device->device(), destMem, NULL); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 13377 | } |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 13378 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 13379 | TEST_F(VkLayerTest, DepthStencilImageViewWithColorAspectBitError) { |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 13380 | // 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] | 13381 | // to using a DS format, then cause it to hit error due to COLOR_BIT not |
| 13382 | // set in aspect |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 13383 | // The image format check comes 2nd in validation so we trigger it first, |
| 13384 | // 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] | 13385 | VkResult err; |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 13386 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 13387 | m_errorMonitor->SetDesiredFailureMsg( |
| 13388 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 13389 | "Combination depth/stencil image formats can have only the "); |
| 13390 | |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 13391 | ASSERT_NO_FATAL_FAILURE(InitState()); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 13392 | |
Chia-I Wu | 1b99bb2 | 2015-10-27 19:25:11 +0800 | [diff] [blame] | 13393 | VkDescriptorPoolSize ds_type_count = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 13394 | ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE; |
| 13395 | ds_type_count.descriptorCount = 1; |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 13396 | |
| 13397 | VkDescriptorPoolCreateInfo ds_pool_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 13398 | ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO; |
| 13399 | ds_pool_ci.pNext = NULL; |
| 13400 | ds_pool_ci.maxSets = 1; |
| 13401 | ds_pool_ci.poolSizeCount = 1; |
| 13402 | ds_pool_ci.pPoolSizes = &ds_type_count; |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 13403 | |
| 13404 | VkDescriptorPool ds_pool; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 13405 | err = |
| 13406 | vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool); |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 13407 | ASSERT_VK_SUCCESS(err); |
| 13408 | |
| 13409 | VkDescriptorSetLayoutBinding dsl_binding = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 13410 | dsl_binding.binding = 0; |
| 13411 | dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE; |
| 13412 | dsl_binding.descriptorCount = 1; |
| 13413 | dsl_binding.stageFlags = VK_SHADER_STAGE_ALL; |
| 13414 | dsl_binding.pImmutableSamplers = NULL; |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 13415 | |
| 13416 | VkDescriptorSetLayoutCreateInfo ds_layout_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 13417 | ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO; |
| 13418 | ds_layout_ci.pNext = NULL; |
| 13419 | ds_layout_ci.bindingCount = 1; |
| 13420 | ds_layout_ci.pBindings = &dsl_binding; |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 13421 | VkDescriptorSetLayout ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 13422 | err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, |
| 13423 | &ds_layout); |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 13424 | ASSERT_VK_SUCCESS(err); |
| 13425 | |
| 13426 | VkDescriptorSet descriptorSet; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 13427 | VkDescriptorSetAllocateInfo alloc_info = {}; |
Chia-I Wu | 00ce540 | 2015-11-10 16:21:09 +0800 | [diff] [blame] | 13428 | alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO; |
Jon Ashburn | f19916e | 2016-01-11 13:12:43 -0700 | [diff] [blame] | 13429 | alloc_info.descriptorSetCount = 1; |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 13430 | alloc_info.descriptorPool = ds_pool; |
| 13431 | alloc_info.pSetLayouts = &ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 13432 | err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, |
| 13433 | &descriptorSet); |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 13434 | ASSERT_VK_SUCCESS(err); |
| 13435 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 13436 | VkImage image_bad; |
| 13437 | VkImage image_good; |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 13438 | // One bad format and one good format for Color attachment |
Tobin Ehlis | 269f032 | 2016-05-25 16:24:21 -0600 | [diff] [blame] | 13439 | const VkFormat tex_format_bad = VK_FORMAT_D24_UNORM_S8_UINT; |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 13440 | const VkFormat tex_format_good = VK_FORMAT_B8G8R8A8_UNORM; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 13441 | const int32_t tex_width = 32; |
| 13442 | const int32_t tex_height = 32; |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 13443 | |
| 13444 | VkImageCreateInfo image_create_info = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 13445 | image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO; |
| 13446 | image_create_info.pNext = NULL; |
| 13447 | image_create_info.imageType = VK_IMAGE_TYPE_2D; |
| 13448 | image_create_info.format = tex_format_bad; |
| 13449 | image_create_info.extent.width = tex_width; |
| 13450 | image_create_info.extent.height = tex_height; |
| 13451 | image_create_info.extent.depth = 1; |
| 13452 | image_create_info.mipLevels = 1; |
| 13453 | image_create_info.arrayLayers = 1; |
| 13454 | image_create_info.samples = VK_SAMPLE_COUNT_1_BIT; |
| 13455 | image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL; |
| 13456 | image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT | |
| 13457 | VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT; |
| 13458 | image_create_info.flags = 0; |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 13459 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 13460 | err = |
| 13461 | vkCreateImage(m_device->device(), &image_create_info, NULL, &image_bad); |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 13462 | ASSERT_VK_SUCCESS(err); |
| 13463 | image_create_info.format = tex_format_good; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 13464 | image_create_info.usage = |
| 13465 | VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT; |
| 13466 | err = vkCreateImage(m_device->device(), &image_create_info, NULL, |
| 13467 | &image_good); |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 13468 | ASSERT_VK_SUCCESS(err); |
| 13469 | |
| 13470 | VkImageViewCreateInfo image_view_create_info = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 13471 | image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO; |
| 13472 | image_view_create_info.image = image_bad; |
| 13473 | image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D; |
| 13474 | image_view_create_info.format = tex_format_bad; |
| 13475 | image_view_create_info.subresourceRange.baseArrayLayer = 0; |
| 13476 | image_view_create_info.subresourceRange.baseMipLevel = 0; |
| 13477 | image_view_create_info.subresourceRange.layerCount = 1; |
| 13478 | image_view_create_info.subresourceRange.levelCount = 1; |
| 13479 | image_view_create_info.subresourceRange.aspectMask = |
| 13480 | VK_IMAGE_ASPECT_COLOR_BIT; |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 13481 | |
| 13482 | VkImageView view; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 13483 | err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, |
| 13484 | &view); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 13485 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 13486 | m_errorMonitor->VerifyFound(); |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 13487 | |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 13488 | vkDestroyImage(m_device->device(), image_bad, NULL); |
| 13489 | vkDestroyImage(m_device->device(), image_good, NULL); |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 13490 | vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL); |
| 13491 | vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL); |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 13492 | } |
Tobin Ehlis | 6e23d77 | 2016-05-19 11:08:34 -0600 | [diff] [blame] | 13493 | |
| 13494 | TEST_F(VkLayerTest, ClearImageErrors) { |
| 13495 | TEST_DESCRIPTION("Call ClearColorImage w/ a depth|stencil image and " |
| 13496 | "ClearDepthStencilImage with a color image."); |
| 13497 | |
| 13498 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 13499 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 13500 | |
| 13501 | // Renderpass is started here so end it as Clear cmds can't be in renderpass |
| 13502 | BeginCommandBuffer(); |
| 13503 | m_commandBuffer->EndRenderPass(); |
| 13504 | |
| 13505 | // Color image |
| 13506 | VkClearColorValue clear_color; |
| 13507 | memset(clear_color.uint32, 0, sizeof(uint32_t) * 4); |
| 13508 | VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT; |
| 13509 | const VkFormat color_format = VK_FORMAT_B8G8R8A8_UNORM; |
| 13510 | const int32_t img_width = 32; |
| 13511 | const int32_t img_height = 32; |
| 13512 | VkImageCreateInfo image_create_info = {}; |
| 13513 | image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO; |
| 13514 | image_create_info.pNext = NULL; |
| 13515 | image_create_info.imageType = VK_IMAGE_TYPE_2D; |
| 13516 | image_create_info.format = color_format; |
| 13517 | image_create_info.extent.width = img_width; |
| 13518 | image_create_info.extent.height = img_height; |
| 13519 | image_create_info.extent.depth = 1; |
| 13520 | image_create_info.mipLevels = 1; |
| 13521 | image_create_info.arrayLayers = 1; |
| 13522 | image_create_info.samples = VK_SAMPLE_COUNT_1_BIT; |
| 13523 | image_create_info.tiling = VK_IMAGE_TILING_LINEAR; |
| 13524 | image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT; |
| 13525 | |
| 13526 | vk_testing::Image color_image; |
| 13527 | color_image.init(*m_device, (const VkImageCreateInfo &)image_create_info, |
| 13528 | reqs); |
| 13529 | |
| 13530 | const VkImageSubresourceRange color_range = |
| 13531 | vk_testing::Image::subresource_range(image_create_info, |
| 13532 | VK_IMAGE_ASPECT_COLOR_BIT); |
| 13533 | |
| 13534 | // Depth/Stencil image |
| 13535 | VkClearDepthStencilValue clear_value = {0}; |
| 13536 | reqs = 0; // don't need HOST_VISIBLE DS image |
| 13537 | VkImageCreateInfo ds_image_create_info = vk_testing::Image::create_info(); |
| 13538 | ds_image_create_info.imageType = VK_IMAGE_TYPE_2D; |
| 13539 | ds_image_create_info.format = VK_FORMAT_D24_UNORM_S8_UINT; |
| 13540 | ds_image_create_info.extent.width = 64; |
| 13541 | ds_image_create_info.extent.height = 64; |
| 13542 | ds_image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL; |
| 13543 | ds_image_create_info.usage = VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT; |
| 13544 | |
| 13545 | vk_testing::Image ds_image; |
| 13546 | ds_image.init(*m_device, (const VkImageCreateInfo &)ds_image_create_info, |
| 13547 | reqs); |
| 13548 | |
| 13549 | const VkImageSubresourceRange ds_range = |
| 13550 | vk_testing::Image::subresource_range(ds_image_create_info, |
| 13551 | VK_IMAGE_ASPECT_DEPTH_BIT); |
| 13552 | |
| 13553 | m_errorMonitor->SetDesiredFailureMsg( |
| 13554 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 13555 | "vkCmdClearColorImage called with depth/stencil image."); |
| 13556 | |
| 13557 | vkCmdClearColorImage(m_commandBuffer->GetBufferHandle(), ds_image.handle(), |
| 13558 | VK_IMAGE_LAYOUT_GENERAL, &clear_color, 1, |
| 13559 | &color_range); |
| 13560 | |
| 13561 | m_errorMonitor->VerifyFound(); |
| 13562 | |
Tony Barbour | 26434b9 | 2016-06-02 09:43:50 -0600 | [diff] [blame] | 13563 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 13564 | "vkCmdClearColorImage called with " |
| 13565 | "image created without " |
| 13566 | "VK_IMAGE_USAGE_TRANSFER_DST_BIT"); |
| 13567 | |
| 13568 | vkCmdClearColorImage(m_commandBuffer->GetBufferHandle(), ds_image.handle(), |
| 13569 | VK_IMAGE_LAYOUT_GENERAL, &clear_color, 1, |
| 13570 | &color_range); |
| 13571 | |
| 13572 | m_errorMonitor->VerifyFound(); |
| 13573 | |
Tobin Ehlis | 6e23d77 | 2016-05-19 11:08:34 -0600 | [diff] [blame] | 13574 | // Call CmdClearDepthStencilImage with color image |
| 13575 | m_errorMonitor->SetDesiredFailureMsg( |
| 13576 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 13577 | "vkCmdClearDepthStencilImage called without a depth/stencil image."); |
| 13578 | |
| 13579 | vkCmdClearDepthStencilImage( |
| 13580 | m_commandBuffer->GetBufferHandle(), color_image.handle(), |
| 13581 | VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL, &clear_value, 1, |
| 13582 | &ds_range); |
| 13583 | |
| 13584 | m_errorMonitor->VerifyFound(); |
| 13585 | } |
Tobin Ehlis | cde0889 | 2015-09-22 10:11:37 -0600 | [diff] [blame] | 13586 | #endif // IMAGE_TESTS |
| 13587 | |
Tony Barbour | 300a608 | 2015-04-07 13:44:53 -0600 | [diff] [blame] | 13588 | int main(int argc, char **argv) { |
| 13589 | int result; |
| 13590 | |
Cody Northrop | 8e54a40 | 2016-03-08 22:25:52 -0700 | [diff] [blame] | 13591 | #ifdef ANDROID |
| 13592 | int vulkanSupport = InitVulkan(); |
| 13593 | if (vulkanSupport == 0) |
| 13594 | return 1; |
| 13595 | #endif |
| 13596 | |
Tony Barbour | 300a608 | 2015-04-07 13:44:53 -0600 | [diff] [blame] | 13597 | ::testing::InitGoogleTest(&argc, argv); |
Tony Barbour | 6918cd5 | 2015-04-09 12:58:51 -0600 | [diff] [blame] | 13598 | VkTestFramework::InitArgs(&argc, argv); |
Tony Barbour | 300a608 | 2015-04-07 13:44:53 -0600 | [diff] [blame] | 13599 | |
| 13600 | ::testing::AddGlobalTestEnvironment(new TestEnvironment); |
| 13601 | |
| 13602 | result = RUN_ALL_TESTS(); |
| 13603 | |
Tony Barbour | 6918cd5 | 2015-04-09 12:58:51 -0600 | [diff] [blame] | 13604 | VkTestFramework::Finish(); |
Tony Barbour | 300a608 | 2015-04-07 13:44:53 -0600 | [diff] [blame] | 13605 | return result; |
| 13606 | } |